Skip to content

Commit 85adc8a

Browse files
committed
Merge pull request #335 from cogmission/prep_v0.6.3
Prep v0.6.3
2 parents 4d446b1 + 6dc3bd8 commit 85adc8a

File tree

18 files changed

+1122
-695
lines changed

18 files changed

+1122
-695
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ apply plugin: 'eclipse'
44
apply plugin: 'signing'
55

66
group = 'org.numenta'
7-
version = '0.6.3'
7+
version = '0.6.4'
88
archivesBaseName = 'htm.java'
99

1010
sourceCompatibility = 1.8
1111
targetCompatibility = 1.8
1212

1313
jar {
1414
manifest {
15-
attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.3'
15+
attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.4'
1616
}
1717
}
1818

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.numenta</groupId>
66
<artifactId>htm.java</artifactId>
7-
<version>0.6.3</version>
7+
<version>0.6.4</version>
88
<name>htm.java</name>
99
<description>The Java version of Numenta's HTM technology</description>
1010

src/main/java/org/numenta/nupic/Parameters.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ public void apply(Object cn) {
474474
Set<KEY> presentKeys = paramMap.keySet();
475475
synchronized (paramMap) {
476476
for (KEY key : presentKeys) {
477+
if(key == KEY.RANDOM) continue;
477478
beanUtil.setSimpleProperty(cn, key.fieldName, getParameterByKey(key));
478479
}
479480
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/* ---------------------------------------------------------------------
2+
* Numenta Platform for Intelligent Computing (NuPIC)
3+
* Copyright (C) 2014, Numenta, Inc. Unless you have an agreement
4+
* with Numenta, Inc., for a separate license for this software code, the
5+
* following terms and conditions apply:
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero Public License version 3 as
9+
* published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
* See the GNU Affero Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero Public License
17+
* along with this program. If not, see http://www.gnu.org/licenses.
18+
*
19+
* http://numenta.org/licenses/
20+
* ---------------------------------------------------------------------
21+
*/
22+
package org.numenta.nupic;
23+
24+
import java.util.Arrays;
25+
import java.util.Collection;
26+
import java.util.List;
27+
import java.util.Set;
28+
import java.util.stream.IntStream;
29+
30+
import org.numenta.nupic.model.Cell;
31+
import org.numenta.nupic.model.Column;
32+
33+
/**
34+
* <p>
35+
* For now, a utility class for convenience operations
36+
* on integer arrays understood to be algorithmic inputs
37+
* and outputs; and conversions to and from canonical objects.
38+
* </p><p>
39+
* Later, this may become the encapsulation of the vectors
40+
* representing SDRs and previously treated as integer arrays.
41+
* </p><p>
42+
* <b>NOTE:</b> <em>Eclipse is not up to date with its leakable resource inspection.
43+
* Streams not derived from channels (i.e. from arrays or lists) do not
44+
* need explicit closing.</em>
45+
* </p>
46+
* <p>
47+
* see here: http://stackoverflow.com/questions/25796118/java-8-streams-and-try-with-resources
48+
* </p>
49+
* @author cogmission
50+
*/
51+
public class SDR {
52+
53+
/**
54+
* Converts a vector of {@link Cell} indexes to {@link Column} indexes.
55+
*
56+
* @param cells the indexes of the cells to convert
57+
* @param cellsPerColumn the defined number of cells per column
58+
* false if not.
59+
* @return the column indexes of the specified cells.
60+
*/
61+
public static int[] asColumnIndices(int[] cells, int cellsPerColumn) {
62+
IntStream op = Arrays.stream(cells);
63+
return op.map(cell -> cell / cellsPerColumn).distinct().toArray();
64+
}
65+
66+
/**
67+
* Converts a vector of {@link Cell} indexes to {@link Column} indexes.
68+
*
69+
* @param cells the indexes of the cells to convert
70+
* @param cellsPerColumn the defined number of cells per column
71+
* false if not.
72+
* @return the column indexes of the specified cells.
73+
*/
74+
public static int[] asColumnIndices(List<Integer> cells, int cellsPerColumn) {
75+
IntStream op = cells.stream().mapToInt(c -> c);
76+
return op.map(cellIdx -> cellIdx / cellsPerColumn).distinct().toArray();
77+
}
78+
79+
/**
80+
* Converts a List of {@link Cell}s to {@link Column} indexes.
81+
*
82+
* @param cells the list of cells to convert
83+
* @param cellsPerColumn the defined number of cells per column
84+
* false if not.
85+
* @return the column indexes of the specified cells.
86+
*/
87+
public static int[] cellsToColumns(List<Cell> cells, int cellsPerColumn) {
88+
IntStream op = cells.stream().mapToInt(c -> c.getIndex());
89+
90+
return op.map(cellIdx -> cellIdx / cellsPerColumn).distinct().toArray();
91+
}
92+
93+
/**
94+
* Converts a Set of {@link Cell}s to {@link Column} indexes.
95+
*
96+
* @param cells the list of cells to convert
97+
* @param cellsPerColumn the defined number of cells per column
98+
*
99+
* @return the column indexes of the specified cells.
100+
*/
101+
public static int[] cellsAsColumnIndices(Set<Cell> cells, int cellsPerColumn) {
102+
return cells.stream().mapToInt(c -> c.getIndex())
103+
.sorted().map(cellIdx -> cellIdx / cellsPerColumn).distinct().toArray();
104+
}
105+
106+
/**
107+
* Converts a {@link Collection} of {@link Cell}s to a list
108+
* of cell indexes.
109+
*
110+
* @param cells
111+
* @return
112+
*/
113+
public static int[] asCellIndices(Collection<Cell> cells) {
114+
return cells.stream().mapToInt(cell -> cell.getIndex()).sorted().toArray();
115+
}
116+
}

src/main/java/org/numenta/nupic/algorithms/TemporalMemory.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,14 @@ public void learnOnSegments(Connections c, Set<DistalDendrite> prevActiveSegment
311311
public void computePredictiveCells(Connections c, ComputeCycle cycle, Set<Cell> activeCells) {
312312
TObjectIntMap<DistalDendrite> numActiveConnectedSynapsesForSegment = new TObjectIntHashMap<>();
313313
TObjectIntMap<DistalDendrite> numActiveSynapsesForSegment = new TObjectIntHashMap<>();
314+
double connectedPermanence = c.getConnectedPermanence();
314315

315316
for(Cell cell : activeCells) {
316317
for(Synapse syn : c.getReceptorSynapses(cell)) {
317318
DistalDendrite segment = (DistalDendrite)syn.getSegment();
318319
double permanence = syn.getPermanence();
319320

320-
if(permanence >= c.getConnectedPermanence()) {
321+
if(permanence >= connectedPermanence) {
321322
numActiveConnectedSynapsesForSegment.adjustOrPutValue(segment, 1, 1);
322323

323324
if(numActiveConnectedSynapsesForSegment.get(segment) >= c.getActivationThreshold()) {
@@ -454,22 +455,6 @@ public Cell getLeastUsedCell(Connections c, List<Cell> columnCells) {
454455
return l.get(randomIdx);
455456
}
456457

457-
/**
458-
* Used locally to return results of column Burst
459-
*/
460-
class BurstResult {
461-
Set<Cell> activeCells;
462-
Set<Cell> winnerCells;
463-
Set<DistalDendrite> learningSegments;
464-
465-
public BurstResult(Set<Cell> activeCells, Set<Cell> winnerCells, Set<DistalDendrite> learningSegments) {
466-
super();
467-
this.activeCells = activeCells;
468-
this.winnerCells = winnerCells;
469-
this.learningSegments = learningSegments;
470-
}
471-
}
472-
473458
/**
474459
* Used locally to return best cell/segment pair
475460
*/

src/main/java/org/numenta/nupic/network/Inference.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
package org.numenta.nupic.network;
2323

2424
import java.util.Map;
25+
import java.util.Set;
2526

27+
import org.numenta.nupic.ComputeCycle;
2628
import org.numenta.nupic.algorithms.CLAClassifier;
2729
import org.numenta.nupic.algorithms.ClassifierResult;
2830
import org.numenta.nupic.algorithms.SpatialPooler;
31+
import org.numenta.nupic.algorithms.TemporalMemory;
2932
import org.numenta.nupic.encoders.Encoder;
33+
import org.numenta.nupic.model.Cell;
3034
import org.numenta.nupic.util.NamedTuple;
3135

3236
import rx.functions.Func1;
@@ -48,6 +52,11 @@ public interface Inference {
4852
* @return
4953
*/
5054
public int getRecordNum();
55+
/**
56+
* Returns the {@link ComputeCycle}
57+
* @return
58+
*/
59+
public ComputeCycle getComputeCycle();
5160
/**
5261
* Returns a custom Object during sequence processing where one or more
5362
* {@link Func1}(s) were added to a {@link Layer} in between algorithmic
@@ -108,20 +117,25 @@ public interface Inference {
108117
* Returns the column activation from a {@link SpatialPooler}
109118
* @return
110119
*/
111-
public int[] getActiveColumns();
120+
public int[] getFeedForwardActiveColumns();
112121
/**
113122
* Returns the column activations in sparse form
114123
* @return
115124
*/
116-
public int[] getSparseActives();
125+
public int[] getFeedForwardSparseActives();
126+
/**
127+
* Returns the column activation from a {@link TemporalMemory}
128+
* @return
129+
*/
130+
public Set<Cell> getActiveCells();
117131
/**
118132
* Returns the predicted output from the last inference cycle.
119133
* @return
120134
*/
121-
public int[] getPreviousPrediction();
135+
public Set<Cell> getPreviousPredictiveCells();
122136
/**
123137
* Returns the currently predicted columns.
124138
* @return
125139
*/
126-
public int[] getPredictedColumns();
140+
public Set<Cell> getPredictiveCells();
127141
}

0 commit comments

Comments
 (0)