From 7af6c8beaaa84becd33cb2d8e7ba8ee877ecc89e Mon Sep 17 00:00:00 2001 From: cogmission Date: Sun, 16 Oct 2016 17:20:52 -0500 Subject: [PATCH 1/6] fix build file --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index f2bfcf4f..bbb3af74 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ targetCompatibility = 1.8 jar { manifest { - attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.9-SNAPSHOT' + attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.10' } } From b91eae183338fdfd25233fabff266900d903842f Mon Sep 17 00:00:00 2001 From: cogmission Date: Sun, 16 Oct 2016 17:25:56 -0500 Subject: [PATCH 2/6] fix up build files --- build.gradle | 4 ++-- pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index bbb3af74..0072fb6d 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'eclipse' apply plugin: 'signing' group = 'org.numenta' -version = '0.6.10' +version = '0.6.11' archivesBaseName = 'htm.java' sourceCompatibility = 1.8 @@ -12,7 +12,7 @@ targetCompatibility = 1.8 jar { manifest { - attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.10' + attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.11' } } diff --git a/pom.xml b/pom.xml index d1cc2ab1..cfc74f59 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.numenta htm.java - 0.6.10 + 0.6.11 htm.java The Java version of Numenta's HTM technology From 212ac34b22e6c1949a78c6fdcb04ac7b1694b446 Mon Sep 17 00:00:00 2001 From: cogmission Date: Sun, 16 Oct 2016 17:49:37 -0500 Subject: [PATCH 3/6] Add wait time to offset thread handling within JUnit --- src/test/java/org/numenta/nupic/network/NetworkTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/numenta/nupic/network/NetworkTest.java b/src/test/java/org/numenta/nupic/network/NetworkTest.java index 0f4d4026..40880cda 100644 --- a/src/test/java/org/numenta/nupic/network/NetworkTest.java +++ b/src/test/java/org/numenta/nupic/network/NetworkTest.java @@ -450,7 +450,11 @@ public void onNext(Inference inf) { }); network.halt(); - try { network.lookup("r1").lookup("1").getLayerThread().join(3000); }catch(Exception e) { e.printStackTrace(); } + try { + network.lookup("r1").lookup("1").getLayerThread().join(3000); + // Add a little more wait time + Thread.sleep(3000); + }catch(Exception e) { e.printStackTrace(); } network.restart(); Publisher newPub = network.getPublisher(); From bb72e4ce678cc3c58b15a554875b8afc455dfd63 Mon Sep 17 00:00:00 2001 From: cogmission Date: Sun, 16 Oct 2016 18:10:16 -0500 Subject: [PATCH 4/6] Add two tests --- .../nupic/datagen/ResourceLocatorTest.java | 35 +++++++++++++++++++ .../org/numenta/nupic/util/ConditionTest.java | 18 ++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/test/java/org/numenta/nupic/datagen/ResourceLocatorTest.java create mode 100644 src/test/java/org/numenta/nupic/util/ConditionTest.java diff --git a/src/test/java/org/numenta/nupic/datagen/ResourceLocatorTest.java b/src/test/java/org/numenta/nupic/datagen/ResourceLocatorTest.java new file mode 100644 index 00000000..525c6bf8 --- /dev/null +++ b/src/test/java/org/numenta/nupic/datagen/ResourceLocatorTest.java @@ -0,0 +1,35 @@ +package org.numenta.nupic.datagen; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.net.URI; + +import org.junit.Test; + + +public class ResourceLocatorTest { + + @Test + public void testURICreation() { + try { + ResourceLocator.uri("."); + fail(); + }catch(Exception e) { + assertEquals(IllegalStateException.class, e.getClass()); + assertEquals(java.net.MalformedURLException.class, e.getCause().getClass()); + } + + try { + URI uri = ResourceLocator.uri("file:///."); + assertNotNull(uri); + + assertFalse(uri.isOpaque()); + }catch(Exception e) { + fail(); + } + } + +} diff --git a/src/test/java/org/numenta/nupic/util/ConditionTest.java b/src/test/java/org/numenta/nupic/util/ConditionTest.java new file mode 100644 index 00000000..17416f87 --- /dev/null +++ b/src/test/java/org/numenta/nupic/util/ConditionTest.java @@ -0,0 +1,18 @@ +package org.numenta.nupic.util; + +import static org.junit.Assert.*; + +import org.junit.Test; + + +public class ConditionTest { + + @Test + public void testRqwAdapterReturnsFalse() { + Condition.Adapter adapter = new Condition.Adapter<>(); + assertFalse(adapter.eval(1.0d)); + assertFalse(adapter.eval(1)); + assertFalse(adapter.eval(new Object())); + } + +} From 5015a20ce4ae6985199d246e3352685147ddfd33 Mon Sep 17 00:00:00 2001 From: cogmission Date: Sun, 16 Oct 2016 19:08:24 -0500 Subject: [PATCH 5/6] Add new tests to LayerTest --- .../java/org/numenta/nupic/network/Layer.java | 17 +++ .../org/numenta/nupic/network/LayerTest.java | 124 ++++++++++++++++++ 2 files changed, 141 insertions(+) diff --git a/src/main/java/org/numenta/nupic/network/Layer.java b/src/main/java/org/numenta/nupic/network/Layer.java index 71458b78..e8fa3fb2 100644 --- a/src/main/java/org/numenta/nupic/network/Layer.java +++ b/src/main/java/org/numenta/nupic/network/Layer.java @@ -344,6 +344,14 @@ public Layer postDeSerialize() { public void setNetwork(Network network) { this.parentNetwork = network; } + + /** + * Returns the parent {@link Network} + * @return the parent Network; + */ + public Network getNetwork() { + return this.parentNetwork; + } /** * Creates a new {@code Layer} initialized with the specified algorithmic @@ -415,6 +423,15 @@ public CheckPointOp delegateCheckPointCall() { public void setRegion(Region r) { this.parentRegion = r; } + + /** + * Returns the parent {@link Region} + * + * @return the parent Region + */ + public Region getRegion() { + return this.parentRegion; + } /** * Finalizes the initialization in one method call so that side effect diff --git a/src/test/java/org/numenta/nupic/network/LayerTest.java b/src/test/java/org/numenta/nupic/network/LayerTest.java index 80436dea..42d15561 100644 --- a/src/test/java/org/numenta/nupic/network/LayerTest.java +++ b/src/test/java/org/numenta/nupic/network/LayerTest.java @@ -48,6 +48,7 @@ import org.numenta.nupic.algorithms.TemporalMemory; import org.numenta.nupic.datagen.ResourceLocator; import org.numenta.nupic.encoders.MultiEncoder; +import org.numenta.nupic.model.Connections; import org.numenta.nupic.model.SDR; import org.numenta.nupic.network.Layer.FunctionFactory; import org.numenta.nupic.network.sensor.FileSensor; @@ -111,6 +112,129 @@ public void testMasking() { algo_content_mask ^= Layer.CLA_CLASSIFIER; assertEquals(0, algo_content_mask); } + + @Test + public void callsOnClosedLayer() { + Parameters p = NetworkTestHarness.getParameters().copy(); + p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); + p.set(KEY.RANDOM, new UniversalRandom(42)); + + Network n = new Network("AlreadyClosed", p) + .add(Network.createRegion("AlreadyClosed") + .add(Network.createLayer("AlreadyClosed", p))); + + Layer l = n.lookup("AlreadyClosed").lookup("AlreadyClosed"); + l.using(new Connections()); + l.using(p); + + l.close(); + + try { + l.using(new Connections()); + + fail(); // Should fail here, disallowing "using" call on closed layer + }catch(Exception e) { + assertEquals(IllegalStateException.class, e.getClass()); + assertEquals("Layer already \"closed\"", e.getMessage()); + } + + try { + l.using(p); + + fail(); // Should fail here, disallowing "using" call on closed layer + }catch(Exception e) { + assertEquals(IllegalStateException.class, e.getClass()); + assertEquals("Layer already \"closed\"", e.getMessage()); + } + } + + @Test + public void testNoName() { + Parameters p = Parameters.getAllDefaultParameters(); + + try { + new Network("", p) + .add(Network.createRegion("") + .add(Network.createLayer("", p) + .add(Sensor.create( + FileSensor::create, + SensorParams.create( + Keys::path, "", ResourceLocator.path("rec-center-hourly-small.csv")))))); + + fail(); // Fails due to no name... + }catch(Exception e) { + assertEquals(IllegalStateException.class, e.getClass()); + assertEquals("All Networks must have a name. Increases digestion, and overall happiness!", + e.getMessage()); + } + + try { + new Network("Name", p) + .add(Network.createRegion("") + .add(Network.createLayer("", p) + .add(Sensor.create( + FileSensor::create, + SensorParams.create( + Keys::path, "", ResourceLocator.path("rec-center-hourly-small.csv")))))); + + fail(); // Fails due to no name on Region... + }catch(Exception e) { + assertEquals(IllegalArgumentException.class, e.getClass()); + assertEquals("Name may not be null or empty. ...not that anyone here advocates name calling!", + e.getMessage()); + } + + try { + p = NetworkTestHarness.getParameters().copy(); + p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); + p.set(KEY.RANDOM, new UniversalRandom(42)); + + PublisherSupplier supplier = PublisherSupplier.builder() + .addHeader("dayOfWeek") + .addHeader("int") + .addHeader("B").build(); + + Network n = new Network("Name", p) + .add(Network.createRegion("Name") + .add(Network.createLayer("Name", p))); + + Layer l = n.lookup("Name").lookup("Name"); + l.add(Sensor.create( + ObservableSensor::create, + SensorParams.create( + Keys::obs, "", supplier))); + + assertEquals(n, l.getNetwork()); + assertTrue(l.getRegion() != null); + + }catch(Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testAddSensor() { + Parameters p = NetworkTestHarness.getParameters().copy(); + p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); + p.set(KEY.RANDOM, new UniversalRandom(42)); + + try { + new Network("Name", p) + .add(Network.createRegion("") + .add(Network.createLayer("", p) + .add(Sensor.create( + FileSensor::create, + SensorParams.create( + Keys::path, "", ResourceLocator.path("rec-center-hourly-small.csv")))))); + + fail(); // Fails due to no name... + }catch(Exception e) { + e.printStackTrace(); + assertEquals(IllegalStateException.class, e.getClass()); + assertEquals("All Networks must have a name. Increases digestion, and overall happiness!", + e.getMessage()); + } + } @Test public void testGetAllValues() { From 3880652e25d9053eedb73dbba5755bf1e51ccf4d Mon Sep 17 00:00:00 2001 From: cogmission Date: Sun, 16 Oct 2016 19:18:12 -0500 Subject: [PATCH 6/6] fix test --- .../org/numenta/nupic/network/LayerTest.java | 35 ++++--------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/src/test/java/org/numenta/nupic/network/LayerTest.java b/src/test/java/org/numenta/nupic/network/LayerTest.java index 42d15561..313aadfe 100644 --- a/src/test/java/org/numenta/nupic/network/LayerTest.java +++ b/src/test/java/org/numenta/nupic/network/LayerTest.java @@ -183,12 +183,15 @@ public void testNoName() { assertEquals("Name may not be null or empty. ...not that anyone here advocates name calling!", e.getMessage()); } + } + + @Test + public void testAddSensor() { + Parameters p = NetworkTestHarness.getParameters().copy(); + p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); + p.set(KEY.RANDOM, new UniversalRandom(42)); try { - p = NetworkTestHarness.getParameters().copy(); - p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); - p.set(KEY.RANDOM, new UniversalRandom(42)); - PublisherSupplier supplier = PublisherSupplier.builder() .addHeader("dayOfWeek") .addHeader("int") @@ -211,30 +214,6 @@ public void testNoName() { e.printStackTrace(); } } - - @Test - public void testAddSensor() { - Parameters p = NetworkTestHarness.getParameters().copy(); - p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); - p.set(KEY.RANDOM, new UniversalRandom(42)); - - try { - new Network("Name", p) - .add(Network.createRegion("") - .add(Network.createLayer("", p) - .add(Sensor.create( - FileSensor::create, - SensorParams.create( - Keys::path, "", ResourceLocator.path("rec-center-hourly-small.csv")))))); - - fail(); // Fails due to no name... - }catch(Exception e) { - e.printStackTrace(); - assertEquals(IllegalStateException.class, e.getClass()); - assertEquals("All Networks must have a name. Increases digestion, and overall happiness!", - e.getMessage()); - } - } @Test public void testGetAllValues() {