Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TM activeCells_ is a SDR #442

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/nupic/algorithms/TemporalMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ static void growSynapses(Connections &connections,
}

static void activatePredictedColumn(
SDR &activeCellsSDR,
SDR &activeCellsSDR,
vector<CellIdx> &winnerCells,
Connections &connections,
Random &rng,
Expand Down Expand Up @@ -543,12 +543,12 @@ void TemporalMemory::activateDendrites(const bool learn,
{
NTA_CHECK( extraActive.size == extra_ );
NTA_CHECK( extraWinners.size == extra_ );
NTA_CHECK( extraActive.dimensions == extraWinners.dimensions);
#ifdef NTA_ASSERTIONS_ON
SDR both(extraActive.dimensions);
both.intersection(extraActive, extraWinners);
NTA_ASSERT(both == extraWinners) << "ExtraWinners must be a subset of ExtraActive";
#endif
NTA_CHECK( extraActive.dimensions == extraWinners.dimensions);
#ifdef NTA_ASSERTIONS_ON
SDR both(extraActive.dimensions);
both.intersection(extraActive, extraWinners);
NTA_ASSERT(both == extraWinners) << "ExtraWinners must be a subset of ExtraActive";
#endif
}
else
{
Expand All @@ -560,12 +560,8 @@ void TemporalMemory::activateDendrites(const bool learn,
if( segmentsValid_ )
return;

#ifdef NTA_ASSERTIONS_ON
for(const auto &active : extraActive.getSparse()) {
NTA_ASSERT( active < extra_ );
}
#endif
activeCells_.concatenate(activeCells_, extraActive);
SDR dendriteInputs({ activeCells_.size + extraActive.size });
dendriteInputs.concatenate(activeCells_.flatten(), extraActive.flatten());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, thank you! I've totally forgot about this problem.


for(const auto &winner : extraWinners.getSparse()) {
NTA_ASSERT( winner < extra_ );
Expand All @@ -578,7 +574,7 @@ void TemporalMemory::activateDendrites(const bool learn,
numActivePotentialSynapsesForSegment_.assign(length, 0);
connections.computeActivity(numActiveConnectedSynapsesForSegment_,
numActivePotentialSynapsesForSegment_,
activeCells_.getSparse());
dendriteInputs.getSparse());

// Active segments, connected synapses.
activeSegments_.clear();
Expand Down
3 changes: 3 additions & 0 deletions src/nupic/types/Sdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ namespace sdr {
SDR::setDenseInplace();
}

Reshape SparseDistributedRepresentation::flatten() const
{ return Reshape(*this, {size} ); }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want Reshape, or a plain SDR {size} + setSparse would do?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work too, but it would copy the data. The Reshape class does not copy data.


bool SparseDistributedRepresentation::operator==(const SparseDistributedRepresentation &sdr) const {
// Check attributes
if( sdr.size != size or dimensions.size() != sdr.dimensions.size() )
Expand Down
4 changes: 4 additions & 0 deletions src/nupic/types/Sdr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ using SDR_sparse_t = std::vector<ElemSparse>;
using SDR_coordinate_t = std::vector<std::vector<UInt>>;
using SDR_callback_t = std::function<void()>;

class Reshape; // Forward Declaration.

/**
* SparseDistributedRepresentation class
* Also known as "SDR" class
Expand Down Expand Up @@ -519,6 +521,8 @@ class SparseDistributedRepresentation : public Serializable
void concatenate(std::vector<const SparseDistributedRepresentation*> inputs,
UInt axis = 0u);

Reshape flatten() const;

/**
* Print a human readable version of the SDR.
*/
Expand Down