Skip to content

Commit

Permalink
initial push
Browse files Browse the repository at this point in the history
  • Loading branch information
solovyevk committed Oct 27, 2013
1 parent 06f8b44 commit e3918aa
Show file tree
Hide file tree
Showing 18 changed files with 1,276 additions and 6 deletions.
13 changes: 8 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.*
*~
target/*
*.class

# Package Files #
*.jar
*.war
*.ear
bin/
build/
.project
.idea/
*.iml
57 changes: 57 additions & 0 deletions License_Numenta.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
This software is based upon or includes certain works and algorithms related
to hierarchical temporal memory ("HTM") technology published by Numenta Inc.


Numenta holds patent rights related to HTM and the algorithms used in this
software.

Numenta has agreed not to assert its patent rights against
development or use of independent HTM systems, as long as such development
or use is for research purposes only, and not for any commercial or production
use.

Any commercial or production use of HTM technology that infringes on
Numenta's patents will require a commercial license from Numenta.



Based on the foregoing, this software is licensed under the terms below, for
research purposes only and not for any commercial or production use.

Numenta License for Non-Commercial Use:

For
purposes of this license, "commercial or production use" includes training an
HTM network with the intent of later deploying the trained network or
application for commercial or production purposes, and using or permitting
others to use the output from HTM technology for commercial or production
purposes.

Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the disclaimer
below) provided that the following conditions are met:

* Redistributions of source code, including any modifications or derivative
works, must retain the full text of this license and the following disclaimer,
and be subject to the terms and conditions of this license.

* Redistributions in binary form, including any modifications or derivative
works, must reproduce the full text of this license and the following
disclaimer in the documentation and/or other materials provided with the
distribution, and be subject to the terms and conditions of this license.

* Neither the name of Numenta, Inc., Barry Maturkanich, nor the names of other
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT RIGHTS ARE GRANTED BY THIS
LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
htm-visualizer
==============

HTM Cortical Learning Algorithm visualizer in JAVA
Visualization of Hiearchical temporal memory (HTM) cortical learning algorithms (CLA) in JAVA
Implementation is based on Numenta's CLA white paper:
https://www.groksolutions.com/htm-overview/education/HTM_CorticalLearningAlgorithms.pdf

84 changes: 84 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>htm</groupId>
<artifactId>htm-visualizer</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>HTM-CLA Visualizer</name>
<dependencies>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>jar-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifestEntries>
<Main-Class>peacetech.gao.locator.adconversion.ConversionRunner</Main-Class>
<Implementation-Title>${project.description}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
<execution>
<id>distribution-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/distribution.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3 changes: 3 additions & 0 deletions run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
java -classpath "lib\commons-logging-1.1.3.jar;lib\log4j-1.2.9.jar;htm-visualizer.jar" htm.visualizer.Viewer


28 changes: 28 additions & 0 deletions src/main/assembly/distribution.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<assembly>
<id>dist</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>target/${project.build.finalName}.jar</source>
<destName>htm-visualizer.jar</destName>
<fileMode>0644</fileMode>
</file>
<file>
<source>run.bat</source>
<destName>run.bat</destName>
<filtered>true</filtered>
<fileMode>0644</fileMode>
</file>
</files>
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<excludes>
<exclude>htm:htm-visualizer</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
113 changes: 113 additions & 0 deletions src/main/java/htm/model/Cell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* Copyright (c) 2011, Peace Technology, Inc.
* $Author:$
* $Revision:$
* $Date:$
* $NoKeywords$
*/

package htm.model;

import htm.visualizer.utils.CircularArrayList;

public class Cell {

public static final int ACTIVE_STATE = 1;
public static final int LEARN_STATE = 2;

public static final int BEFORE = 1;
public static final int NOW = 0;

/**
* cell will keep a buffer of its last TIME_STEPS output values
*/
private static int TIME_STEPS = 2;

private final Column belongsToColumn;
private final int cellIndex;
/**
* Boolean vector of Cell's active state in time t-n, ..., t-1, t
*/
private CellStateBuffer activeState = new CellStateBuffer();

/**
* Boolean vector of Cell's predictive state in time t-n, ..., t-1, t
*/
private CellStateBuffer predictiveState = new CellStateBuffer();
/**
* learnState(c, i, t) A boolean indicating whether cell i in column c is
* chosen as the cell to learn on.
*/
private CellStateBuffer learnState = new CellStateBuffer();

public Cell(Column belongsToColumn, int cellIndex) {
this.belongsToColumn = belongsToColumn;
this.cellIndex = cellIndex;
}

/*
*Set Learn State in current time Cell.NOW
*/
public void setLearnState(boolean learnState) {
this.learnState.setState(learnState);
}

/**
* Get Learn state in Time
*
* @param time
*/
public boolean getLearnState(int time) {
return this.learnState.get(time);
}

/**
* Set active state
*/
public void setActiveState(boolean activeState) {
this.activeState.setState(activeState);
}

/**
* Get Active state in Time
*
* @param time
*/
public boolean getActiveState(int time) {
return this.activeState.get(time);
}

/**
* Set Predictive state
*/
public void setPredictiveState(boolean predictiveState) {
this.predictiveState.setState(predictiveState);
}

/**
* Get Predictive state in Time
*
* @param time
*/
public boolean getPredictiveState(int time) {
return this.predictiveState.get(time);
}

private static class CellStateBuffer extends CircularArrayList<Boolean>{
public CellStateBuffer() {
super(TIME_STEPS);
for (int i = 0; i < TIME_STEPS; i++) {
this.add(false);
}
}

/**
* Set the current state(time NOW)
*
* @param state
**/
void setState(boolean state){
this.set(NOW, state);
}
}
}
75 changes: 75 additions & 0 deletions src/main/java/htm/model/Column.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Copyright (c) 2011, Peace Technology, Inc.
* $Author:$
* $Revision:$
* $Date:$
* $NoKeywords$
*/

package htm.model;

import htm.visualizer.utils.CircularArrayList;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Column {
public static int CELLS_PER_COLUMN = 3;
private static final int COLUMN_MAX_ACTIVE = 1000;
private final int columnIndex;
private final List<Cell> cells = new ArrayList<Cell>();
private ArrayList<Boolean> activeList = new CircularArrayList<Boolean>(COLUMN_MAX_ACTIVE);

/**
* activeDutyCycle(c) A sliding average representing how often column c has
* been active after inhibition (e.g. over the last 1000 iterations).
*/
private double activeDutyCycle;

public Column(int columnIndex) {
this.columnIndex = columnIndex;
for (int i = 0; i < CELLS_PER_COLUMN; i++) {
cells.add(new Cell(this, i));
}
}

public int getColumnIndex() {
return columnIndex;
}

public List<Cell> getCells() {
return Collections.unmodifiableList(cells);
}

public Cell getCellByIndex(int index){
return cells.get(index);
}

/**
* updateActiveDutyCycle(c) Computes a moving average of how often column c
* has been active after inhibition.
*
* @return
*/
private double updateActiveDutyCycle() {
int totalActive = 0;
for (boolean act : activeList) {
if (act) {
totalActive++;
}
}
this.activeDutyCycle = (double) totalActive / activeList.size();
return activeDutyCycle;
}

public void setActive(boolean active) {
// logger.log(Level.INFO, "activeList" + activeList.size());
activeList.add(0, active);
updateActiveDutyCycle();
}

public boolean isActive() {
return this.activeList.size() > 0 ? activeList.get(0) : false;
}
}
Loading

0 comments on commit e3918aa

Please sign in to comment.