Skip to content

Commit 7f4d8f2

Browse files
authored
Merge pull request #496 from cogmission/sync_tm_dev
Sync tm dev
2 parents 473233d + f4eed8d commit 7f4d8f2

File tree

92 files changed

+3548
-1290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+3548
-1290
lines changed

.classpath

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
77
<classpathentry kind="lib" path="libs/chutils-1.4.jar" sourcepath="/Users/cogmission/Resources/chutils/chutils-1.4-sources.jar"/>
88
<classpathentry kind="lib" path="libs/hamcrest-core-1.3.jar"/>
9-
<classpathentry kind="lib" path="libs/jackson-annotations-2.4.0.jar"/>
10-
<classpathentry kind="lib" path="libs/jackson-core-2.4.4.jar"/>
11-
<classpathentry kind="lib" path="libs/jackson-databind-2.4.4.jar"/>
129
<classpathentry kind="lib" path="libs/jmh-core-1.5.1.jar"/>
1310
<classpathentry kind="lib" path="libs/joda-time-2.5.jar"/>
1411
<classpathentry kind="lib" path="libs/junit-4.11.jar"/>
@@ -20,6 +17,9 @@
2017
<classpathentry kind="lib" path="libs/java-util-1.19.3.jar" sourcepath="/Users/cogmission/.m2/repository/com/cedarsoftware/java-util/1.19.3/java-util-1.19.3-sources.jar"/>
2118
<classpathentry kind="lib" path="libs/objenesis-2.1.jar"/>
2219
<classpathentry kind="lib" path="libs/algorithmfoundry-shade-culled-1.3.jar"/>
23-
<classpathentry kind="lib" path="libs/fst-2.45.jar"/>
20+
<classpathentry kind="lib" path="libs/fst-2.45.jar" sourcepath="/Users/cogmission/git/fast-serialization/src/main/java"/>
21+
<classpathentry kind="lib" path="libs/jackson-annotations-2.4.0.jar"/>
22+
<classpathentry kind="lib" path="libs/jackson-core-2.4.4.jar"/>
23+
<classpathentry kind="lib" path="libs/jackson-databind-2.4.4.jar"/>
2424
<classpathentry kind="output" path="bin"/>
2525
</classpath>

build.gradle

+7-7
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.10-SNAPSHOT'
7+
version = '0.6.9-SNAPSHOT'
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.10-SNAPSHOT'
15+
attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.9-SNAPSHOT'
1616
}
1717
}
1818

@@ -53,11 +53,11 @@ dependencies {
5353
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version:'2.4.4'
5454
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version:'2.4.4'
5555
compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.10'
56-
compile group: 'io.reactivex', name: 'rxjava', version: '1.0.10'
57-
compile group: 'de.ruedigermoeller', name: 'fst', version: '2.45'
58-
compile group: 'com.cedarsoftware', name: 'java-util', version: '1.19.3'
59-
compile group: 'algorithmfoundry', name: 'algorithmfoundry-shade-culled', version:'1.3'
60-
testCompile group: 'junit', name: 'junit', version:'4.11'
56+
compile group: 'io.reactivex', name: 'rxjava', version: '1.0.10'
57+
compile group: 'de.ruedigermoeller', name: 'fst', version: '2.45'
58+
compile group: 'com.cedarsoftware', name: 'java-util', version: '1.19.3'
59+
compile group: 'algorithmfoundry', name: 'algorithmfoundry-shade-culled', version:'1.3'
60+
testCompile group: 'junit', name: 'junit', version:'4.11'
6161
testCompile group: 'ch.qos.logback', name: 'logback-classic', version:'1.1.2'
6262
}
6363

pom.xml

+1-1
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.10-SNAPSHOT</version>
7+
<version>0.6.9-SNAPSHOT</version>
88
<name>htm.java</name>
99
<description>The Java version of Numenta's HTM technology</description>
1010

src/jmh/java/org/numenta/nupic/benchmarks/AbstractAlgorithmBenchmark.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
package org.numenta.nupic.benchmarks;
2424

25-
import org.numenta.nupic.Connections;
2625
import org.numenta.nupic.Parameters;
2726
import org.numenta.nupic.Parameters.KEY;
2827
import org.numenta.nupic.algorithms.SpatialPooler;
2928
import org.numenta.nupic.algorithms.TemporalMemory;
3029
import org.numenta.nupic.encoders.ScalarEncoder;
30+
import org.numenta.nupic.model.Connections;
3131
import org.openjdk.jmh.annotations.Scope;
3232
import org.openjdk.jmh.annotations.Setup;
3333
import org.openjdk.jmh.annotations.State;

src/jmh/java/org/numenta/nupic/benchmarks/TemporalMemoryBenchmark.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import java.util.concurrent.TimeUnit;
2626

27-
import org.numenta.nupic.ComputeCycle;
27+
import org.numenta.nupic.model.ComputeCycle;
2828
import org.numenta.nupic.util.ArrayUtils;
2929
import org.openjdk.jmh.annotations.Benchmark;
3030
import org.openjdk.jmh.annotations.BenchmarkMode;

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

+3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
import org.numenta.nupic.algorithms.TemporalMemory;
3737
import org.numenta.nupic.model.Cell;
3838
import org.numenta.nupic.model.Column;
39+
import org.numenta.nupic.model.ComputeCycle;
3940
import org.numenta.nupic.model.DistalDendrite;
41+
import org.numenta.nupic.model.Connections;
42+
import org.numenta.nupic.model.Persistable;
4043
import org.numenta.nupic.util.ArrayUtils;
4144
import org.numenta.nupic.util.BeanUtil;
4245
import org.numenta.nupic.util.MersenneTwister;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.List;
2727
import java.util.Map;
2828

29-
import org.numenta.nupic.Persistable;
29+
import org.numenta.nupic.model.Persistable;
3030
import org.numenta.nupic.util.ArrayUtils;
3131

3232
import gnu.trove.list.TDoubleList;

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

+3-102
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222

2323
package org.numenta.nupic.algorithms;
2424

25-
import gnu.trove.iterator.TDoubleIterator;
26-
import gnu.trove.list.TDoubleList;
27-
import gnu.trove.list.array.TDoubleArrayList;
28-
import gnu.trove.map.TObjectDoubleMap;
29-
30-
import java.io.IOException;
31-
import java.io.StringWriter;
3225
import java.util.ArrayList;
3326
import java.util.Arrays;
3427
import java.util.List;
@@ -40,14 +33,9 @@
4033
import org.slf4j.Logger;
4134
import org.slf4j.LoggerFactory;
4235

43-
import com.fasterxml.jackson.core.JsonFactory;
44-
import com.fasterxml.jackson.core.JsonGenerator;
45-
import com.fasterxml.jackson.core.JsonProcessingException;
46-
import com.fasterxml.jackson.databind.ObjectMapper;
47-
import com.fasterxml.jackson.databind.SerializationFeature;
48-
import com.fasterxml.jackson.databind.node.ArrayNode;
49-
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
50-
import com.fasterxml.jackson.databind.node.ObjectNode;
36+
import gnu.trove.list.TDoubleList;
37+
import gnu.trove.list.array.TDoubleArrayList;
38+
import gnu.trove.map.TObjectDoubleMap;
5139

5240
/**
5341
* <p>The anomaly likelihood computer.</p>
@@ -607,9 +595,6 @@ public boolean isValidEstimatorParams(NamedTuple params) {
607595
public static class AnomalyParams extends NamedTuple {
608596
private static final long serialVersionUID = 1L;
609597

610-
/** Cached Json formatting. Possible because Objects of this class are immutable */
611-
private ObjectNode cachedNode;
612-
613598
private final Statistic distribution;
614599
private final MovingAverage movingAverage;
615600
private final double[] historicalLikelihoods;
@@ -666,90 +651,6 @@ public int windowSize() {
666651
return windowSize;
667652
}
668653

669-
/**
670-
* Lazily creates and returns a JSON ObjectNode containing this {@code AnomalyParams}' data.
671-
*
672-
* @param factory
673-
* @return
674-
*/
675-
public ObjectNode toJsonNode(JsonNodeFactory factory) {
676-
if(cachedNode == null) {
677-
ObjectNode distribution = factory.objectNode();
678-
distribution.put(KEY_MEAN, this.distribution.mean);
679-
distribution.put(KEY_VARIANCE, this.distribution.variance);
680-
distribution.put(KEY_STDEV, this.distribution.stdev);
681-
682-
double[] historicalLikelihoods = (double[])get(KEY_HIST_LIKE);
683-
ArrayNode historics = factory.arrayNode();
684-
for(double d : historicalLikelihoods) {
685-
historics.add(d);
686-
}
687-
688-
ObjectNode mvgAvg = factory.objectNode();
689-
mvgAvg.put(KEY_WINDOW_SIZE, windowSize);
690-
691-
ArrayNode histVals = factory.arrayNode();
692-
TDoubleList hVals = this.movingAverage.getSlidingWindow();
693-
for(TDoubleIterator it = hVals.iterator();it.hasNext();) {
694-
histVals.add(it.next());
695-
}
696-
mvgAvg.set(KEY_HIST_VALUES, histVals);
697-
mvgAvg.put(KEY_TOTAL, this.movingAverage.getTotal());
698-
699-
cachedNode = factory.objectNode();
700-
cachedNode.set(KEY_DIST, distribution);
701-
cachedNode.set(KEY_HIST_LIKE, historics);
702-
cachedNode.set(KEY_MVG_AVG, mvgAvg);
703-
}
704-
705-
return cachedNode;
706-
}
707-
708-
/**
709-
* Returns the processed Json Node with possible pretty print indentation
710-
* formatting if the flag specified is true.
711-
*
712-
* @param doPrettyPrint
713-
* @return
714-
*/
715-
public String toJson(boolean doPrettyPrint) {
716-
// Create the node factory that gives us nodes.
717-
JsonNodeFactory factory = new JsonNodeFactory(false);
718-
719-
// create a json factory to write the tree node as json. for the example
720-
// we just write to console
721-
JsonFactory jsonFactory = new JsonFactory();
722-
JsonGenerator generator = null;
723-
StringWriter out = new StringWriter();
724-
try {
725-
generator = jsonFactory.createGenerator(out);
726-
}catch(IOException e) {
727-
LOG.error("Error while creating JsonGenerator", e);
728-
}
729-
730-
ObjectMapper mapper = new ObjectMapper();
731-
if(doPrettyPrint) {
732-
mapper.enable(SerializationFeature.INDENT_OUTPUT);
733-
}
734-
try {
735-
mapper.writeTree(generator, toJsonNode(factory));
736-
} catch(JsonProcessingException e) {
737-
LOG.error("Error while writing json", e);
738-
} catch(IOException e) {
739-
LOG.error("Error while writing json", e);
740-
}
741-
742-
return out.getBuffer().toString();
743-
}
744-
745-
/**
746-
* Returns the processed Json Node as a String
747-
* @return
748-
*/
749-
public String toJson() {
750-
return toJson(false);
751-
}
752-
753654
/* (non-Javadoc)
754655
* @see java.lang.Object#hashCode()
755656
*/

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import java.util.Arrays;
2727
import java.util.List;
2828

29-
import org.numenta.nupic.Persistable;
3029
import org.numenta.nupic.algorithms.Anomaly.AveragedAnomalyRecordList;
3130
import org.numenta.nupic.algorithms.AnomalyLikelihood.AnomalyParams;
31+
import org.numenta.nupic.model.Persistable;
3232

3333
/**
3434
* Container class to hold the results of {@link AnomalyLikelihood} estimations

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
package org.numenta.nupic.algorithms;
2424

25-
import org.numenta.nupic.Persistable;
25+
import org.numenta.nupic.model.Persistable;
2626
import org.numenta.nupic.util.ArrayUtils;
2727

2828
import gnu.trove.list.TDoubleList;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.util.List;
2929
import java.util.Map;
3030

31-
import org.numenta.nupic.Persistable;
31+
import org.numenta.nupic.model.Persistable;
3232
import org.numenta.nupic.util.ArrayUtils;
3333
import org.numenta.nupic.util.Deque;
3434
import org.numenta.nupic.util.Tuple;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.Arrays;
44

5-
import org.numenta.nupic.Persistable;
5+
import org.numenta.nupic.model.Persistable;
66

77
import gnu.trove.map.TIntObjectMap;
88
import gnu.trove.map.hash.TIntObjectHashMap;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
package org.numenta.nupic.algorithms;
2424

25-
import org.numenta.nupic.Persistable;
25+
import org.numenta.nupic.model.Persistable;
2626

2727
import gnu.trove.list.TDoubleList;
2828
import gnu.trove.list.array.TDoubleArrayList;

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
import java.util.Map;
3030

3131
import no.uib.cipr.matrix.sparse.FlexCompRowMatrix;
32-
import org.numenta.nupic.Persistable;
32+
33+
import org.numenta.nupic.model.Persistable;
3334
import org.numenta.nupic.util.ArrayUtils;
3435
import org.numenta.nupic.util.Deque;
3536
import org.numenta.nupic.util.Tuple;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package org.numenta.nupic.algorithms;
2424

2525
import org.joda.time.DateTime;
26-
import org.numenta.nupic.Persistable;
26+
import org.numenta.nupic.model.Persistable;
2727

2828
/**
2929
* A sample data point or record consisting of a timestamp, value, and score.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import java.util.Comparator;
2626
import java.util.stream.IntStream;
2727

28-
import org.numenta.nupic.Connections;
29-
import org.numenta.nupic.Persistable;
3028
import org.numenta.nupic.model.Column;
29+
import org.numenta.nupic.model.Connections;
30+
import org.numenta.nupic.model.Persistable;
3131
import org.numenta.nupic.model.Pool;
3232
import org.numenta.nupic.util.ArrayUtils;
3333
import org.numenta.nupic.util.Condition;

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

+1-19
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@
2222

2323
package org.numenta.nupic.algorithms;
2424

25-
import org.numenta.nupic.Persistable;
25+
import org.numenta.nupic.model.Persistable;
2626
import org.numenta.nupic.util.NamedTuple;
2727

28-
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
29-
import com.fasterxml.jackson.databind.node.ObjectNode;
30-
3128
/**
3229
* Container to hold a specific calculation for a statistical data point.
3330
*
@@ -61,21 +58,6 @@ public Statistic(double mean, double variance, double stdev) {
6158
this.entries = new NamedTuple(new String[] { "mean", "variance", "stdev" }, mean, variance, stdev);
6259
}
6360

64-
/**
65-
* Creates and returns a JSON ObjectNode containing this Statistic's data.
66-
*
67-
* @param factory
68-
* @return
69-
*/
70-
public ObjectNode toJson(JsonNodeFactory factory) {
71-
ObjectNode distribution = factory.objectNode();
72-
distribution.put("mean", mean);
73-
distribution.put("variance", variance);
74-
distribution.put("stdev", stdev);
75-
76-
return distribution;
77-
}
78-
7961
@Override
8062
public int hashCode() {
8163
final int prime = 31;

0 commit comments

Comments
 (0)