Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enabling multistep predictions and fixing multiencoder bug #544

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 18 additions & 18 deletions .classpath
Expand Up @@ -3,23 +3,23 @@
<classpathentry kind="src" path="src/jmh/java"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="libs/chutils-1.4.jar" sourcepath="/Users/cogmission/Resources/chutils/chutils-1.4-sources.jar"/>
<classpathentry kind="lib" path="libs/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="libs/jmh-core-1.5.1.jar"/>
<classpathentry kind="lib" path="libs/joda-time-2.5.jar"/>
<classpathentry kind="lib" path="libs/junit-4.11.jar"/>
<classpathentry kind="lib" path="libs/logback-classic-1.1.2.jar"/>
<classpathentry kind="lib" path="libs/logback-core-1.1.2.jar"/>
<classpathentry kind="lib" path="libs/rxjava-1.0.10.jar" sourcepath="/Users/cogmission/Resources/RxJava/rxjava-1.0.10-sources.jar"/>
<classpathentry kind="lib" path="libs/slf4j-api-1.7.10.jar"/>
<classpathentry kind="lib" path="libs/trove-3.1a1.jar" sourcepath="/Users/cogmission/Resources/trove/3.1a1/trove-3.1a1-src.jar"/>
<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"/>
<classpathentry kind="lib" path="libs/objenesis-2.1.jar"/>
<classpathentry kind="lib" path="libs/algorithmfoundry-shade-culled-1.3.jar"/>
<classpathentry kind="lib" path="libs/fst-2.45.jar" sourcepath="/Users/cogmission/git/fast-serialization/src/main/java"/>
<classpathentry kind="lib" path="libs/jackson-annotations-2.4.0.jar"/>
<classpathentry kind="lib" path="libs/jackson-core-2.4.4.jar"/>
<classpathentry kind="lib" path="libs/jackson-databind-2.4.4.jar"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="libs/chutils-1.4.jar" sourcepath="/Users/cogmission/Resources/chutils/chutils-1.4-sources.jar"/>
<classpathentry exported="true" kind="lib" path="libs/hamcrest-core-1.3.jar"/>
<classpathentry exported="true" kind="lib" path="libs/jmh-core-1.5.1.jar"/>
<classpathentry exported="true" kind="lib" path="libs/joda-time-2.5.jar"/>
<classpathentry exported="true" kind="lib" path="libs/junit-4.11.jar"/>
<classpathentry exported="true" kind="lib" path="libs/logback-classic-1.1.2.jar"/>
<classpathentry exported="true" kind="lib" path="libs/logback-core-1.1.2.jar"/>
<classpathentry exported="true" kind="lib" path="libs/rxjava-1.0.10.jar" sourcepath="/Users/cogmission/Resources/RxJava/rxjava-1.0.10-sources.jar"/>
<classpathentry exported="true" kind="lib" path="libs/slf4j-api-1.7.10.jar"/>
<classpathentry exported="true" kind="lib" path="libs/trove-3.1a1.jar" sourcepath="/Users/cogmission/Resources/trove/3.1a1/trove-3.1a1-src.jar"/>
<classpathentry exported="true" 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"/>
<classpathentry exported="true" kind="lib" path="libs/objenesis-2.1.jar"/>
<classpathentry exported="true" kind="lib" path="libs/algorithmfoundry-shade-culled-1.3.jar"/>
<classpathentry exported="true" kind="lib" path="libs/fst-2.45.jar" sourcepath="/Users/cogmission/git/fast-serialization/src/main/java"/>
<classpathentry exported="true" kind="lib" path="libs/jackson-annotations-2.4.0.jar"/>
<classpathentry exported="true" kind="lib" path="libs/jackson-core-2.4.4.jar"/>
<classpathentry exported="true" kind="lib" path="libs/jackson-databind-2.4.4.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
5 changes: 4 additions & 1 deletion Dockerfile
@@ -1,6 +1,9 @@
FROM java:8

RUN wget -q https://services.gradle.org/distributions/gradle-2.12-bin.zip \
ENV http_proxy http://192.168.99.1:53128
ENV https_proxy http://192.168.99.1:53128

RUN wget https://services.gradle.org/distributions/gradle-2.12-bin.zip \
&& unzip -q gradle-2.12-bin.zip -d /opt \
&& rm gradle-2.12-bin.zip

Expand Down
Binary file not shown.
17 changes: 17 additions & 0 deletions gradle.properties
@@ -0,0 +1,17 @@
## Proxy setup
systemProp.proxySet="true"
systemProp.http.keepAlive="true"
systemProp.http.proxyHost=192.168.99.1
systemProp.http.proxyPort=53128
#systemProp.http.proxyUser=y2gh
#systemProp.http.proxyPassword=password
#systemProp.http.nonProxyHosts=local.net|some.host.com

systemProp.https.keepAlive="true"
systemProp.https.proxyHost=192.168.99.1
systemProp.https.proxyPort=53128
#systemProp.https.proxyUser=username
#systemProp.https.proxyPassword=password
#systemProp.https.nonProxyHosts=local.net|some.host.com
## end of proxy setup

18 changes: 18 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Expand Up @@ -4,3 +4,21 @@ distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-bin.zip

## Proxy setup
systemProp.proxySet="true"
systemProp.http.keepAlive="true"
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=53128
#systemProp.http.proxyUser=y2gh
#systemProp.http.proxyPassword=password
#systemProp.http.nonProxyHosts=local.net|some.host.com

systemProp.https.keepAlive="true"
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=53128
#systemProp.https.proxyUser=username
#systemProp.https.proxyPassword=password
#systemProp.https.nonProxyHosts=local.net|some.host.com
## end of proxy setup

18 changes: 18 additions & 0 deletions nb-configuration.xml
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.jdkPlatform>JDK_1.8</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>
8 changes: 5 additions & 3 deletions pom.xml
Expand Up @@ -30,15 +30,17 @@
<timezone>-5</timezone>
</developer>
</developers>

<repositories>
<repositories>
<repository>
<id>repo</id>
<name>htm.java</name>
<url>http://metaware.us/maven3</url>
</repository>
</repositories>




<scm>
<connection>scm:git:git://github.com/numenta/htm.java.git</connection>
<developerConnection>scm:git:git://github.com/numenta/htm.java.git</developerConnection>
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/numenta/nupic/FieldMetaType.java
Expand Up @@ -97,7 +97,13 @@ public <T> T decodeType(String input, Encoder<?> enc) {
case STRING : return (T)input;
case DATETIME : return (T)((DateEncoder)enc).parse(input);
case BOOLEAN : return (T)(Boolean.valueOf(input) == true ? new Double(1) : new Double(0));
case COORD :
case COORD :{
String[] parts = input.split("[\\s]*\\;[\\s]*");
int[] coord =new int[2];
coord[0]=Integer.parseInt(parts[0]);
coord[1]=Integer.parseInt(parts[1]);
return (T)new Tuple(coord, Double.parseDouble(parts[2]));
}
case GEO : {
String[] parts = input.split("[\\s]*\\;[\\s]*");
return (T)new Tuple(Double.parseDouble(parts[0]), Double.parseDouble(parts[1]), Double.parseDouble(parts[2]));
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/numenta/nupic/Parameters.java
Expand Up @@ -138,6 +138,7 @@ public class Parameters implements Persistable {
defaultEncoderParams.put(KEY.ENCODER, "ScalarEncoder");
defaultEncoderParams.put(KEY.FIELD_ENCODING_MAP, Collections.emptyMap());
defaultEncoderParams.put(KEY.AUTO_CLASSIFY, Boolean.FALSE);
defaultEncoderParams.put(KEY.INFERRED_STEPS, new int[]{1});
DEFAULTS_ENCODER = Collections.unmodifiableMap(defaultEncoderParams);
defaultParams.putAll(DEFAULTS_ENCODER);

Expand Down Expand Up @@ -421,6 +422,9 @@ public static enum KEY {

/** Maps encoder input field name to type of classifier to be used for them */
INFERRED_FIELDS("inferredFields", Map.class), // Map<String, Classifier.class>

/** Sets the inference steps */
INFERRED_STEPS("inferenceSteps", int[].class),

// How many bits to use if encoding the respective date fields.
// e.g. Tuple(bits to use:int, radius:double)
Expand Down
Expand Up @@ -164,7 +164,7 @@ public static int bitForCoordinate(int[] coordinate, int n) {
*/
@Override
public void encodeIntoArray(Tuple inputData, int[] output) {
List<int[]> neighs = neighbors((int[])inputData.get(0), (double)inputData.get(1));
List<int[]> neighs = neighbors((int[])inputData.get(0), Math.max((double)inputData.get(1), w));
int[][] neighbors = new int[neighs.size()][];
for(int i = 0;i < neighs.size();i++) neighbors[i] = neighs.get(i);

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/numenta/nupic/network/Layer.java
Expand Up @@ -21,6 +21,7 @@
*/
package org.numenta.nupic.network;

import gnu.trove.list.array.TIntArrayList;
import java.lang.Thread.UncaughtExceptionHandler;
import java.math.BigDecimal;
import java.math.MathContext;
Expand Down Expand Up @@ -1922,6 +1923,7 @@ private void clearSubscriberObserverLists() {
@SuppressWarnings("unchecked")
NamedTuple makeClassifiers(MultiEncoder encoder) {
Map<String, Class<? extends Classifier>> inferredFields = (Map<String, Class<? extends Classifier>>) params.get(KEY.INFERRED_FIELDS);
int[] steps = (int[]) params.get(KEY.INFERRED_STEPS);
if(inferredFields == null || inferredFields.entrySet().size() == 0) {
throw new IllegalStateException(
"KEY.AUTO_CLASSIFY has been set to \"true\", but KEY.INFERRED_FIELDS is null or\n\t" +
Expand All @@ -1930,6 +1932,7 @@ NamedTuple makeClassifiers(MultiEncoder encoder) {
"value in Parameters)."
);
}

String[] names = new String[encoder.getEncoders(encoder).size()];
Classifier[] ca = new Classifier[names.length];
int i = 0;
Expand All @@ -1940,12 +1943,12 @@ NamedTuple makeClassifiers(MultiEncoder encoder) {
LOGGER.info("Not classifying \"" + et.getName() + "\" input field");
}
else if(CLAClassifier.class.isAssignableFrom(fieldClassifier)) {
LOGGER.info("Classifying \"" + et.getName() + "\" input field with CLAClassifier");
ca[i] = new CLAClassifier();
LOGGER.info("Classifying \"" + et.getName() + "\" input field with CLAClassifier");
ca[i] = new CLAClassifier(new TIntArrayList(steps), 0.001, 0.3, 0);
}
else if(SDRClassifier.class.isAssignableFrom(fieldClassifier)) {
LOGGER.info("Classifying \"" + et.getName() + "\" input field with SDRClassifier");
ca[i] = new SDRClassifier();
ca[i] = new SDRClassifier(new TIntArrayList(steps), 0.001, 0.3, 0);
}
else {
throw new IllegalStateException(
Expand Down