Skip to content

Commit

Permalink
Merge pull request #335 from cogmission/prep_v0.6.3
Browse files Browse the repository at this point in the history
Prep v0.6.3
  • Loading branch information
cogmission committed Oct 23, 2015
2 parents 4d446b1 + 6dc3bd8 commit 85adc8a
Show file tree
Hide file tree
Showing 18 changed files with 1,122 additions and 695 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ apply plugin: 'eclipse'
apply plugin: 'signing'

group = 'org.numenta'
version = '0.6.3'
version = '0.6.4'
archivesBaseName = 'htm.java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

jar {
manifest {
attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.3'
attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.4'
}
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.numenta</groupId>
<artifactId>htm.java</artifactId>
<version>0.6.3</version>
<version>0.6.4</version>
<name>htm.java</name>
<description>The Java version of Numenta's HTM technology</description>

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/numenta/nupic/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ public void apply(Object cn) {
Set<KEY> presentKeys = paramMap.keySet();
synchronized (paramMap) {
for (KEY key : presentKeys) {
if(key == KEY.RANDOM) continue;
beanUtil.setSimpleProperty(cn, key.fieldName, getParameterByKey(key));
}
}
Expand Down
116 changes: 116 additions & 0 deletions src/main/java/org/numenta/nupic/SDR.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/* ---------------------------------------------------------------------
* Numenta Platform for Intelligent Computing (NuPIC)
* Copyright (C) 2014, Numenta, Inc. Unless you have an agreement
* with Numenta, Inc., for a separate license for this software code, the
* following terms and conditions apply:
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero Public License for more details.
*
* You should have received a copy of the GNU Affero Public License
* along with this program. If not, see http://www.gnu.org/licenses.
*
* http://numenta.org/licenses/
* ---------------------------------------------------------------------
*/
package org.numenta.nupic;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.IntStream;

import org.numenta.nupic.model.Cell;
import org.numenta.nupic.model.Column;

/**
* <p>
* For now, a utility class for convenience operations
* on integer arrays understood to be algorithmic inputs
* and outputs; and conversions to and from canonical objects.
* </p><p>
* Later, this may become the encapsulation of the vectors
* representing SDRs and previously treated as integer arrays.
* </p><p>
* <b>NOTE:</b> <em>Eclipse is not up to date with its leakable resource inspection.
* Streams not derived from channels (i.e. from arrays or lists) do not
* need explicit closing.</em>
* </p>
* <p>
* see here: http://stackoverflow.com/questions/25796118/java-8-streams-and-try-with-resources
* </p>
* @author cogmission
*/
public class SDR {

/**
* Converts a vector of {@link Cell} indexes to {@link Column} indexes.
*
* @param cells the indexes of the cells to convert
* @param cellsPerColumn the defined number of cells per column
* false if not.
* @return the column indexes of the specified cells.
*/
public static int[] asColumnIndices(int[] cells, int cellsPerColumn) {
IntStream op = Arrays.stream(cells);
return op.map(cell -> cell / cellsPerColumn).distinct().toArray();
}

/**
* Converts a vector of {@link Cell} indexes to {@link Column} indexes.
*
* @param cells the indexes of the cells to convert
* @param cellsPerColumn the defined number of cells per column
* false if not.
* @return the column indexes of the specified cells.
*/
public static int[] asColumnIndices(List<Integer> cells, int cellsPerColumn) {
IntStream op = cells.stream().mapToInt(c -> c);
return op.map(cellIdx -> cellIdx / cellsPerColumn).distinct().toArray();
}

/**
* Converts a List of {@link Cell}s to {@link Column} indexes.
*
* @param cells the list of cells to convert
* @param cellsPerColumn the defined number of cells per column
* false if not.
* @return the column indexes of the specified cells.
*/
public static int[] cellsToColumns(List<Cell> cells, int cellsPerColumn) {
IntStream op = cells.stream().mapToInt(c -> c.getIndex());

return op.map(cellIdx -> cellIdx / cellsPerColumn).distinct().toArray();
}

/**
* Converts a Set of {@link Cell}s to {@link Column} indexes.
*
* @param cells the list of cells to convert
* @param cellsPerColumn the defined number of cells per column
*
* @return the column indexes of the specified cells.
*/
public static int[] cellsAsColumnIndices(Set<Cell> cells, int cellsPerColumn) {
return cells.stream().mapToInt(c -> c.getIndex())
.sorted().map(cellIdx -> cellIdx / cellsPerColumn).distinct().toArray();
}

/**
* Converts a {@link Collection} of {@link Cell}s to a list
* of cell indexes.
*
* @param cells
* @return
*/
public static int[] asCellIndices(Collection<Cell> cells) {
return cells.stream().mapToInt(cell -> cell.getIndex()).sorted().toArray();
}
}
19 changes: 2 additions & 17 deletions src/main/java/org/numenta/nupic/algorithms/TemporalMemory.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,14 @@ public void learnOnSegments(Connections c, Set<DistalDendrite> prevActiveSegment
public void computePredictiveCells(Connections c, ComputeCycle cycle, Set<Cell> activeCells) {
TObjectIntMap<DistalDendrite> numActiveConnectedSynapsesForSegment = new TObjectIntHashMap<>();
TObjectIntMap<DistalDendrite> numActiveSynapsesForSegment = new TObjectIntHashMap<>();
double connectedPermanence = c.getConnectedPermanence();

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

if(permanence >= c.getConnectedPermanence()) {
if(permanence >= connectedPermanence) {
numActiveConnectedSynapsesForSegment.adjustOrPutValue(segment, 1, 1);

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

/**
* Used locally to return results of column Burst
*/
class BurstResult {
Set<Cell> activeCells;
Set<Cell> winnerCells;
Set<DistalDendrite> learningSegments;

public BurstResult(Set<Cell> activeCells, Set<Cell> winnerCells, Set<DistalDendrite> learningSegments) {
super();
this.activeCells = activeCells;
this.winnerCells = winnerCells;
this.learningSegments = learningSegments;
}
}

/**
* Used locally to return best cell/segment pair
*/
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/org/numenta/nupic/network/Inference.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@
package org.numenta.nupic.network;

import java.util.Map;
import java.util.Set;

import org.numenta.nupic.ComputeCycle;
import org.numenta.nupic.algorithms.CLAClassifier;
import org.numenta.nupic.algorithms.ClassifierResult;
import org.numenta.nupic.algorithms.SpatialPooler;
import org.numenta.nupic.algorithms.TemporalMemory;
import org.numenta.nupic.encoders.Encoder;
import org.numenta.nupic.model.Cell;
import org.numenta.nupic.util.NamedTuple;

import rx.functions.Func1;
Expand All @@ -48,6 +52,11 @@ public interface Inference {
* @return
*/
public int getRecordNum();
/**
* Returns the {@link ComputeCycle}
* @return
*/
public ComputeCycle getComputeCycle();
/**
* Returns a custom Object during sequence processing where one or more
* {@link Func1}(s) were added to a {@link Layer} in between algorithmic
Expand Down Expand Up @@ -108,20 +117,25 @@ public interface Inference {
* Returns the column activation from a {@link SpatialPooler}
* @return
*/
public int[] getActiveColumns();
public int[] getFeedForwardActiveColumns();
/**
* Returns the column activations in sparse form
* @return
*/
public int[] getSparseActives();
public int[] getFeedForwardSparseActives();
/**
* Returns the column activation from a {@link TemporalMemory}
* @return
*/
public Set<Cell> getActiveCells();
/**
* Returns the predicted output from the last inference cycle.
* @return
*/
public int[] getPreviousPrediction();
public Set<Cell> getPreviousPredictiveCells();
/**
* Returns the currently predicted columns.
* @return
*/
public int[] getPredictedColumns();
public Set<Cell> getPredictiveCells();
}
Loading

0 comments on commit 85adc8a

Please sign in to comment.