Add accessors.

Allow retrieval of the full state, e.g. for persistent storage (cf. MATH-1594).
This commit is contained in:
Gilles Sadowski 2022-01-08 14:52:55 +01:00
parent d35194c995
commit e65ed4ff5b
4 changed files with 62 additions and 2 deletions

View File

@ -143,6 +143,15 @@ public class NeuronString {
return size; return size;
} }
/**
* 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 * Retrieves the features set from the neuron at location
* {@code i} in the map. * {@code i} in the map.

View File

@ -284,6 +284,36 @@ public class NeuronSquareMesh2D
return numberOfColumns; return numberOfColumns;
} }
/**
* 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. * Retrieves the neuron at location {@code (i, j)} in the map.
* The neuron at position {@code (0, 0)} is located at the upper-left * The neuron at position {@code (0, 0)} is located at the upper-left

View File

@ -47,8 +47,10 @@ public class NeuronStringTest {
@Test @Test
public void testSegmentNetwork() { public void testSegmentNetwork() {
final FeatureInitializer[] initArray = {init}; 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; Collection<Neuron> neighbours;
// Neuron 0. // Neuron 0.
@ -92,8 +94,10 @@ public class NeuronStringTest {
@Test @Test
public void testCircleNetwork() { public void testCircleNetwork() {
final FeatureInitializer[] initArray = {init}; 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; Collection<Neuron> neighbours;
// Neuron 0. // Neuron 0.

View File

@ -75,6 +75,23 @@ public class NeuronSquareMesh2DTest {
Assert.assertEquals(3, net.getFeaturesSize()); 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 * Test assumes that the network is