 # Calculating the sparsity of spatial pooler algorithm

hi every one.I want to calculate the sparsity of data by HTM spatial pooler algorithm (I mean, I want to calculate the input sparsity rate as well as the output sparsity rate of the algorithm and then get the input sparsity ratio to output). For this purpose, I used the number of non-zero sparsity. I also found that the Gini index is also suitable for calculating sparsity, So I decided to use this index to calculate the sparsity of the spatial pooler algorithm. in the Gini index , we have to arrange the vector input / output numbers in order from small to large according to the following formula But we know that the output of the spatial pooler algorithm is a vector of 0 and 1.How do I calculate the Gini index?Is this possible?

Please introduce another suitable information theory index for calculating sparsity

2 Likes

Hi,

Usually sparsity is calculated as the fraction of the vector which is 1’s.
For example if you have the vector: “110000” then the sparsity is 2/6 = 33%.

In a spatial pooler, the output sparsity should be constant (assuming that there are a sufficient number of active inputs).

For an in-depth article about sparse representations and their mathematical properties, Numenta wrote this paper: [1601.00720] How do neurons operate on sparse distributed representations? A mathematical theory of sparsity, neurons and active dendrites

HTH

2 Likes

hi dmac
thanks for your answer, is there any way to calculate spasrsity by gini index?

I don’t know much about the gini index. According to Wikipedia: The Gini coefficient measures the inequality among values of a frequency distribution.

For this task you can measure the binary entropy of the representations. You will also want to divide that entropy by the maximum possible entropy for your system to get a value in the range [0, 1].

If you’re using `htm.core` then the class `htm.bindings.sdr.Metrics` will measure and report the activation frequency distribution and binary entropy.

2 Likes