Add accessors.
Allow retrieval of the full state, e.g. for persistent storage (cf. MATH-1594).
diff --git a/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/oned/NeuronString.java b/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/oned/NeuronString.java
index dcef125..f223c91 100644
--- a/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/oned/NeuronString.java
+++ b/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/oned/NeuronString.java
@@ -144,6 +144,15 @@
}
/**
+ * Indicates whether the line of neurons is wrapped.
+ *
+ * @return {@code true} if the last neuron is linked to the first neuron.
+ */
+ public boolean isWrapped() {
+ return wrap;
+ }
+
+ /**
* Retrieves the features set from the neuron at location
* {@code i} in the map.
*
diff --git a/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/twod/NeuronSquareMesh2D.java b/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/twod/NeuronSquareMesh2D.java
index 4a6b185..92439ee 100644
--- a/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/twod/NeuronSquareMesh2D.java
+++ b/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/twod/NeuronSquareMesh2D.java
@@ -285,6 +285,36 @@
}
/**
+ * Indicates whether the map is wrapped along the first dimension.
+ *
+ * @return {@code true} if the last neuron of a row is linked to
+ * the first neuron of that row.
+ */
+ public boolean isWrappedRow() {
+ return wrapRows;
+ }
+
+ /**
+ * Indicates whether the map is wrapped along the second dimension.
+ *
+ * @return {@code true} if the last neuron of a column is linked to
+ * the first neuron of that column.
+ */
+ public boolean isWrappedColumn() {
+ return wrapColumns;
+ }
+
+ /**
+ * Indicates the {@link SquareNeighbourhood type of connectivity}
+ * between neurons.
+ *
+ * @return the neighbourhood type.
+ */
+ public SquareNeighbourhood getSquareNeighbourhood() {
+ return neighbourhood;
+ }
+
+ /**
* Retrieves the neuron at location {@code (i, j)} in the map.
* The neuron at position {@code (0, 0)} is located at the upper-left
* corner of the map.
diff --git a/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/oned/NeuronStringTest.java b/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/oned/NeuronStringTest.java
index e6aeec0..7069b04 100644
--- a/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/oned/NeuronStringTest.java
+++ b/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/oned/NeuronStringTest.java
@@ -47,8 +47,10 @@
@Test
public void testSegmentNetwork() {
final FeatureInitializer[] initArray = {init};
- final Network net = new NeuronString(4, false, initArray).getNetwork();
+ final NeuronString line = new NeuronString(4, false, initArray);
+ Assert.assertFalse(line.isWrapped());
+ final Network net = line.getNetwork();
Collection<Neuron> neighbours;
// Neuron 0.
@@ -92,8 +94,10 @@
@Test
public void testCircleNetwork() {
final FeatureInitializer[] initArray = {init};
- final Network net = new NeuronString(4, true, initArray).getNetwork();
+ final NeuronString line = new NeuronString(4, true, initArray);
+ Assert.assertTrue(line.isWrapped());
+ final Network net = line.getNetwork();
Collection<Neuron> neighbours;
// Neuron 0.
diff --git a/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/twod/NeuronSquareMesh2DTest.java b/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/twod/NeuronSquareMesh2DTest.java
index 78833d5..a5e721d 100644
--- a/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/twod/NeuronSquareMesh2DTest.java
+++ b/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/twod/NeuronSquareMesh2DTest.java
@@ -75,6 +75,23 @@
Assert.assertEquals(3, net.getFeaturesSize());
}
+ @Test
+ public void testAccessors() {
+ final FeatureInitializer[] initArray = {init};
+ NeuronSquareMesh2D map;
+
+ for (SquareNeighbourhood type : SquareNeighbourhood.values()) {
+ map = new NeuronSquareMesh2D(4, false, 2, true, type, initArray);
+ Assert.assertFalse(map.isWrappedRow());
+ Assert.assertTrue(map.isWrappedColumn());
+ Assert.assertEquals(type, map.getSquareNeighbourhood());
+
+ map = new NeuronSquareMesh2D(3, true, 4, false, type, initArray);
+ Assert.assertTrue(map.isWrappedRow());
+ Assert.assertFalse(map.isWrappedColumn());
+ Assert.assertEquals(type, map.getSquareNeighbourhood());
+ }
+ }
/*
* Test assumes that the network is