How can I reconstruct the input using an SDR?

Hi!

I have been trying to find a way so I can reconstruct the input signal out of the SDRs that it generates, but I haven’t found it so far. I mean, using the method SpatialPooler.compute(), I can get the SDR that represents the given input within the HTM model: is there any way of going the opposite direction? I’m mostly interested about using modified SDRs: I mean, I might get two SDRs and do the OR operation with them, and then, try to reconstruct the input that would generate such an ORed SDR.

I understand that in any case, such a reconstruction might not be perfect, and there could be some extra/missing bit.

Is there any direct way of doing this? In case there isn’t, how can I get the connected proximal sinapses of a column of the SpatialPooler?

Thanks a lot!

3 Likes

Are you trying to do this in order to classify predictions? If so, watch this:

Also maybe this:

2 Likes

Hi and thanks for your answer!

No, I’m not using predictions (yet). Anyway, I watched the videos and what I would like to do is what is said in the first video at 52:43-53:01

I’m working using words as inputs, which become (sparse) binary arrays using the encoder, which in turn are converted into SDRs. I want to modify one SDR somehow (mostly creating a new SDR by ORing several SDRs, using masks…) and then I would like to get the input(s) (the binary array) that would generate such an SDR. As I see it, I would like to get all the input bits which have a connected sinapsis with any of the active columns (represented by the SDR). If possible, I would like to get the connections and their precedences.

I’m doing this because, As I have a (big but) finite list of possible inputs, I would like to somehow rank the inputs (which are words converted into bit arrays), listing first the word that is “closest” to the given SDR, then the second, and so on…

I’m now trying to use a method of the SpatialPooler class that might help: getConnectedSynapses.

This is mostly what I want to do. I was trying to make the HTM model work “backwards” from the SDR to the input. So one possibility (unless there is anything better) could be checking all the active columns in the SDR, and taking all the input bits with a connected synapse to any of those active columns.

However, I don’t know how to use this method, since the result is an ndarray of floats (I was expecting booleans). Most of the values are 0.0, but then, most of the non-zero values are values extremely close to 0.0, such as 4.94e-324.

How should I use the getConnectedSynapses?

Thanks!

What encoder? Did you build your own?

What you’re asking for is temporal pooling. NuPIC does not do temporal pooling, it is a research area. Currently NuPIC can export predicted cells, which can be decoded into an input which is the predicted value. But there is no way to extract all the sequences a spatial input (or a series of spatial inputs) might have been observed within.

1 Like

Yes, it is my own encoder for Spanish (not finished yet).

I’m not 100% sure, but I don’t think I’m talking about temporal pooling. I just want to “go backwards” somehow, but not in time. What I want to do is going backwards in the sense that I start with an SDR and I come out with a single input. I know that I cannot reconstruct the input without some errors. But I don’t care that much, since I will use that reconstructed input to match any of the possible (“true”) inputs.

In other words, I want to answer the question: if I have an SDR, which (of a pool of) input(s) could have produced it? And I suppose that the question might be answered if I’m able to get all the input bits which have connected synapses with the active columns (represented by the SDR). I simply don’t know how to do that :grinning:

Thanks!

Ok, that makes sense. To get the bits you want, I think you want to call getPredictiveCells on the TM, then convert into column indices with columnForCell.

2 Likes

Hmmm… I don’t think so. Why “predictive”? I don’t want (so far) to predict anything. I have an SDR (which I have somehow modified), and I want to get the input that would generate that (current) SDR, nothing else.

I mean, if the SpatialPooler methods getConnectedSynapses or getPermanence would work as I expected them to do, I could have already done it. But don’t seem to work (well, I’m quite sure they do, simply I don’t understand what they do).

Thanks!

I’m confused about what you are doing because you’re changing an SDR that the spatial pooler created. Why would you do that?

I’m telling you that I would change the SDR, because otherwise, the simple answer to my question is: the SDR is produced by the input which produced it :slight_smile:

Since those SDRs are the representation of words, I’m planning to do “something” with them: either ORing, ANDing, masking the bits… And I would like to know what’s the result of such an operation. I know that those operations will return a new SDR, but, what do they mean? That’s why I need to go “backwards” and calculate the input from the SDR.

I found this, which might be what you want:

1 Like

That seems to be what I would like to do :slightly_smiling_face: However, I fail at point 3:

3. For every synapse in that column that has permanence >= permThreshold Do:

since I have never seen a single column (not even among the active ones) that would have any permanence >= permThreshold. I imagine that I’m doing something wrong, but I cannot figure out what.

For anyone reading, we are discussing this here: How to use the method SpatialPooler.getPermanence? - #4 by rhyolight

1 Like

In this paper:

Mnatzaganian, J., Fokoué, E. y Kudithipudi, D. (2017).
A Mathematical Formalization of Hierarchical Temporal Memory’s Spatial Pooler.
Frontiers in Robotics and AI, 3, 59. https://doi.org/10.3389/frobt.2016.00081

They reconstruct the input. I gave for granted that they used a similar procedure to the one I want to use, but I might be wrong. Do you know how did they manage to reconstruct the input?

2 posts were split to a new topic: Retrieving things stored in memory in HTM

I’m reading up on your old thread.
+1 I’m also interested, https://github.com/htm-community/nupic.cpp/issues/12
Esp in the “native” way, without CLAClassifier.

  • If you don’t mind classifier: you can train it on (input, SDR) and use it for the transition SDR->input.
  • If you mind, like I, the biological approach is top down compute, it used to be implemented in the Py repo. Might be not that difficult to implement for some Encoders & SP. I’d join the activity to do that.