Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
Merge 4f9e776 into 73f8f35
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan51 committed Nov 13, 2014
2 parents 73f8f35 + 4f9e776 commit 3783fa0
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/main/algorithms/Connections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Connections::Connections(CellIdx numCells) : cells_(numCells) {}
Segment Connections::createSegment(const Cell& cell)
{
vector<SegmentData>& segments = cells_[cell.idx].segments;
// TODO: Assert that index will be smaller than max size
Segment segment(segments.size(), cell);

SegmentData segmentData;
Expand All @@ -51,6 +52,7 @@ Synapse Connections::createSynapse(const Segment& segment,
const Cell& cell = segment.cell;

vector<SynapseData>& synapses = cells_[cell.idx].segments[segment.idx].synapses;
// TODO: Assert that index will be smaller than max size
Synapse synapse(synapses.size(), segment);

SynapseData synapseData = {presynapticCell, permanence};
Expand Down Expand Up @@ -198,6 +200,30 @@ vector<Cell> Connections::activeCells(const Activity& activity)
return cells;
}

UInt Connections::numSegments() const
{
UInt num = 0;

for (vector<CellData>::const_iterator cell = cells_.begin(); cell != cells_.end(); cell++) {
num += cell->segments.size();
}

return num;
}

UInt Connections::numSynapses() const
{
UInt num = 0;

for (vector<CellData>::const_iterator cell = cells_.begin(); cell != cells_.end(); cell++) {
for (vector<SegmentData>::const_iterator segment = cell->segments.begin(); segment != cell->segments.end(); segment++) {
num += segment->synapses.size();
}
}

return num;
}

bool Cell::operator==(const Cell &other) const {
return idx == other.idx;
}
Expand Down
20 changes: 18 additions & 2 deletions src/main/algorithms/Connections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ namespace nta
namespace connections
{
typedef UInt32 CellIdx;
typedef Byte SegmentIdx;
typedef Byte SynapseIdx;
typedef unsigned char SegmentIdx;
typedef unsigned char SynapseIdx;
typedef Real32 Permanence;

/**
Expand Down Expand Up @@ -315,6 +315,22 @@ namespace nta
*/
std::vector<Cell> activeCells(const Activity& activity);

// Debugging

/**
Gets the number of segments.
@retval Number of segments.
*/
UInt numSegments() const;

/**
Gets the number of synapses.
@retval Number of synapses.
*/
UInt numSynapses() const;

private:
std::vector<CellData> cells_;
// Mapping (presynaptic cell => synapses) used in forward propagation
Expand Down
26 changes: 26 additions & 0 deletions src/test/unit/algorithms/ConnectionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace nta {
testMostActiveSegmentForCellsNone();
testComputeActivity();
testActiveSegments();
testNumSegments();
testNumSynapses();
}

/**
Expand Down Expand Up @@ -270,6 +272,30 @@ namespace nta {
TESTEQUAL(activeCells[0].idx, 20);
}

/**
* Creates a sample set of connections, and makes sure that we can get the
* correct number of segments.
*/
void ConnectionsTest::testNumSegments()
{
Connections connections(1024);
setupSampleConnections(connections);

TESTEQUAL(connections.numSegments(), 3);
}

/**
* Creates a sample set of connections, and makes sure that we can get the
* correct number of synapses.
*/
void ConnectionsTest::testNumSynapses()
{
Connections connections(1024);
setupSampleConnections(connections);

TESTEQUAL(connections.numSynapses(), 8);
}

void ConnectionsTest::setupSampleConnections(Connections &connections)
{
Segment segment;
Expand Down
2 changes: 2 additions & 0 deletions src/test/unit/algorithms/ConnectionsTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namespace nta
void testComputeActivity();
void testActiveSegments();
void testActiveCells();
void testNumSegments();
void testNumSynapses();

void setupSampleConnections(Connections &connections);
Activity computeSampleActivity(Connections &connections);
Expand Down

0 comments on commit 3783fa0

Please sign in to comment.