Hi,

I’m currently studying nupic code and aiming to write a simple implementation of the HTM theory.

I have some questions.

If you would to provide a rough estimate, how much of the nupic python implementation use the matrix math that are defined in the C++ nupic core?

Is there any heavy matrix math involved in the nupic python implementation?

I know sparse matrices are handy here, but I just couldn’t find some use case in the python code that justifies the math complexity in the C++ nupic core. Of course I’m not a nupic code expert by the way, just want to try to understand better the implementation.

Cheers

As far as I know (I’ve only read the code in TemporalMemory, classifers and the encoders) in NuPIC.core. NuPIC.core tend to use vectors of integers instead of sparse matrix; which is likely a good thing. It reduces random memory access alot and reduces algorithmic complexity by an order.

I see thanks. The implementation is using vectors, however, they are seen/used as sparse matrices in the python code AFAIK.

I’m trying to find out as to how much (very ambiguous here sorry) matrix math is being used in the python code (using the C++ matrix implementation). From what I can tell the C++ matrix implementation (using vectors) is quite complex and at least in the SpatialPooler python implementation, I haven’t seen any serious matrix math in there.

Sorry for the confusion.

I mean, in NuPIC.core, a SDR is expressed as a vector of integers (`std::vector<UInt>`

). But they are not used as indices. They are dense arrays. I guess the reason for uing `UInt`

instead of `bool`

is that C++ optimizes vectors of bools for space. The values are stored as bits in memory and thus requires bit operations to extract. And thus being very slow.

This is the code I use to feed data into a Spatial pooler. (xtensor is basiclly numpy for C++. It is not used in NuPIC.core but I use it to handle ND arrays)

```
xt::xarray<bool> t = some_xtensor_array();
std::vector<UInt> in(t.size());
std::vector<UInt> out(outputSize());
//Copy the data into the array, spatial pooler accepts a dens input
for(size_t i=0;i<t.size();i++)
in[i] = t[i];
sp.compute(in.data(), learn, out.data());
```

Also. It is worth noticing that although most of NuPIC.core operates on dense arrays. **The TemporalMemory is an exception**. It uses indices of active columns as it’s input.

```
xt::xarray<bool> t = some_xtensor_array();
std::vector<UInt> cols = sparsify(t); //sparsify the array, put the indices of on bits into the array
tm.compute(cols.size(), cols.data, learn);
```

1 Like