Skip to content
This repository has been archived by the owner on May 11, 2023. It is now read-only.

Commit

Permalink
Added empty connection schema to enable prime spiking neuron pools.
Browse files Browse the repository at this point in the history
  • Loading branch information
okozelsk committed Jul 13, 2020
1 parent 4adc83c commit 1fd7fc5
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 41 deletions.
78 changes: 52 additions & 26 deletions Demo/DemoConsoleApp/SM/SMDemoSettings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<demo dataFolder=".\\Data" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SMDemoSettings.xsd">


<!--
Here StateMachine achieves 80.77% accuracy. It is a bit worse than the best accuracy 81.4% achieved by the algorithm
called COTE referenced at the dataset's home site:
Expand Down Expand Up @@ -131,7 +132,6 @@
</stateMachine>
</case>


<!--
This demo case demonstrates successful use of the pure analog ESN reservoir for the fast and accurate classifications enabled by
the new ability of the analog neurons to fire a spike, input resampling and transformation.
Expand Down Expand Up @@ -258,10 +258,15 @@
</stateMachine>
</case>


<!--
This demo case demonstrates use of transformed input field together with a simple ESN reservoir.
Following configuration of the StateMachine achieves 95.00% accuracy on verification data, slightly better than the best algorithm
called BOSS, referenced at the dataset's home site:
This sample demonstrates the power of the more advanced StateMachne capabilities. Here is used possibility to
unify the amplitude of input patter data, as well as the possibility to directly connect fast-reacting analog neurons
with spiking neurons and thus create a reservoir with sufficient memory and proper ability to provide good data for
generalization at readout layer. Proper mutual cooperation of analog and spiking neurons is enabled by the novel ability of analog
neuron to fire a spike.
Following advanced (but still straightforward) configuration of the StateMachine achieves 100% accuracy, better than the best
algorithm called BOSS, referenced at the dataset's home site:
"Anthony Bagnall, Jason Lines, William Vickers and Eamonn Keogh, The UEA & UCR Time Series Classification Repository, www.timeseriesclassification.com"
https://timeseriesclassification.com/description.php?Dataset=BeetleFly.
MPEG-7 CE Shape-1 Part B is a database of binary images developed for testing MPEG-7 shape descriptors, and is available free online.
Expand All @@ -270,59 +275,77 @@
We have extracted the outlines of these images and mapped them into 1-D series of distances to the centre.
Beetle/Fly is the problem of distinguishing between an outline of a beetle and a fly.
-->
<case name="Classification task BeetleFly: Simple pure ESN reservoir generating FiringFadingSum predictors, one Identity neuron as a classifier (Resilient trainer)">
<case name="Classification task BeetleFly: Combined ESNxLSM reservoir generating FiringFadingSum predictors, one Identity neuron as a classifier (Resilient trainer)">
<samples trainingData="BeetleFly_train.csv" verificationData="BeetleFly_verify.csv"/>
<stateMachine randomizerSeek="0">
<neuralPreprocessor>
<neuralPreprocessor predictorsReductionRatio="0">
<inputEncoder>
<feedingPatterned slices="1" bidir="false">
<unification unifyAmplitude="false" detrend="false">
<feedingPatterned slices="1" bidir="true">
<unification unifyAmplitude="true" detrend="false">
<resampling signalBeginThreshold="0" signalEndThreshold="0" uniformTimeScale="true" targetTimePoints="Auto"/>
</unification>
</feedingPatterned>
<varyingFields routeToReadout="true">
<varyingFields routeToReadout="false">
<externalFields>
<field name="Dist">
<field name="DistanceFromCenter">
<realFeature standardize="true" keepReserve="true"/>
</field>
</externalFields>
<transformedFields>
<field name="Diff">
<diff fieldName="Dist" interval="1"/>
</field>
</transformedFields>
</varyingFields>
</inputEncoder>
<reservoirStructures>
<reservoirStructure name="MainCfg">
<pools>
<pool name="PureESN">
<proportions dimX="6" dimY="6" dimZ="5"/>
<pool name="AnalogESNPool">
<proportions dimX="128" dimY="1" dimZ="1"/>
<neuronGroups>
<analogGroup name="TanH-grp" firingThreshold="0.00125" relShare="1">
<analogGroup name="Analog-grp" relShare="1" firingThreshold="0.01" thresholdMaxRefDeepness="4">
<activationTanH/>
</analogGroup>
</neuronGroups>
<interconnection>
<randomSchema density="0.1" avgDistance="NA" allowSelfConnection="true" constantNumOfConnections="false"/>
</interconnection>
</pool>
<pool name="SpikingPrimePool">
<proportions dimX="64" dimY="1" dimZ="1"/>
<neuronGroups>
<spikingGroup name="Spiking-grp" relShare="1">
<activationLeakyIF refractoryPeriods="0"/>
<homogenousExcitability excitatoryStrength="0.8" inputRatio="0" inhibitoryRatio="0.25"/>
</spikingGroup>
</neuronGroups>
<interconnection>
<emptySchema/>
</interconnection>
</pool>
<pool name="SpikingLSMPool">
<proportions dimX="128" dimY="1" dimZ="1"/>
<neuronGroups>
<spikingGroup name="Spiking-grp" relShare="1">
<activationLeakyIF refractoryPeriods="0"/>
<homogenousExcitability excitatoryStrength="0.8" inputRatio="0" inhibitoryRatio="0.1"/>
</spikingGroup>
</neuronGroups>
<interconnection>
<randomSchema density="0.1" avgDistance="NA" allowSelfConnection="false" constantNumOfConnections="false"/>
</interconnection>
</pool>
</pools>
<interPoolConnections>
<interPoolConnection targetPool="SpikingPrimePool" targetConnDensity="1" sourcePool="AnalogESNPool" sourceConnDensity="0.25"/>
<interPoolConnection targetPool="SpikingLSMPool" targetConnDensity="1" sourcePool="SpikingPrimePool" sourceConnDensity="0.25"/>
</interPoolConnections>
</reservoirStructure>
</reservoirStructures>
<reservoirInstances>
<reservoirInstance name="Main" reservoirStructure="MainCfg">
<inputConnections>
<connection inputFieldName="Diff" analogTargetDensity="0.25" poolName="PureESN"/>
<connection inputFieldName="DistanceFromCenter" poolName="AnalogESNPool" analogTargetDensity="1"/>
</inputConnections>
<synapse>
<analogTarget>
<input maxDelay="0" delayMethod="Random">
<analogSource>
<weight min="0" max="2.5"/>
</analogSource>
</input>
<indifferent maxDelay="0" delayMethod="Random"/>
<indifferent maxDelay="16"/>
</analogTarget>
</synapse>
<predictors activation="false"
Expand All @@ -333,6 +356,9 @@
firingMWAvg="false"
firingCount="false"
firingBinPattern="false">
<params>
<firingFadingSum strength="0.001"/>
</params>
</predictors>
</reservoirInstance>
</reservoirInstances>
Expand All @@ -345,7 +371,7 @@
<networks>
<ff>
<activationIdentity/>
<resPropTrainer attempts="5" attemptEpochs="200"/>
<resPropTrainer attempts="5" attemptEpochs="500"/>
</ff>
</networks>
</classification>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public override bool ContainsOnlyDefaults
/// </summary>
protected override void Check()
{
if (Ratio < 0 || Ratio > 1)
if (Ratio <= 0 || Ratio > 1)
{
throw new ArgumentException($"Invalid Ratio {Ratio.ToString(CultureInfo.InvariantCulture)}. Ratio must be GE to 0 and LE to 1.", "Ratio");
throw new ArgumentException($"Invalid Ratio {Ratio.ToString(CultureInfo.InvariantCulture)}. Ratio must be GT 0 and LE to 1.", "Ratio");
}
if (Repetitions < 1)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using System.Globalization;
using System.Xml.Linq;

namespace RCNet.Neural.Network.SM.Preprocessing.Reservoir.Pool
{
/// <summary>
/// Class contains configuration of the Empty schema of pool's neurons interconnection (ensures no internal pool connections)
/// </summary>
[Serializable]
public class EmptySchemaSettings : RCNetBaseSettings, IInterconnSchemaSettings
{
//Constants
/// <summary>
/// Name of the associated xsd type
/// </summary>
public const string XsdTypeName = "PoolInterconnectionEmptySchemaType";

//Constructors
/// <summary>
/// Creates an initialized instance
/// </summary>
public EmptySchemaSettings()
{
Check();
return;
}

/// <summary>
/// The deep copy constructor
/// </summary>
/// <param name="source">Source instance</param>
public EmptySchemaSettings(EmptySchemaSettings source)
: this()
{
return;
}

/// <summary>
/// Creates an initialized instance.
/// </summary>
/// <param name="elem">Xml element containing the initialization settings</param>
public EmptySchemaSettings(XElement elem)
{
//Validation
XElement settingsElem = Validate(elem, XsdTypeName);
Check();
return;
}

//Properties
/// <summary>
/// Specifies whether the connections of this schema will replace existing connections
/// </summary>
public bool ReplaceExistingConnections { get { return false; } }

/// <summary>
/// Number of applications of this schema
/// </summary>
public int Repetitions { get { return 1; } }

/// <summary>
/// Identifies settings containing only default values
/// </summary>
public override bool ContainsOnlyDefaults
{
get
{
return true;
}
}

//Methods
/// <summary>
/// Checks consistency
/// </summary>
protected override void Check()
{
return;
}

/// <summary>
/// Creates the deep copy instance of this instance
/// </summary>
public override RCNetBaseSettings DeepClone()
{
return new EmptySchemaSettings(this);
}

/// <summary>
/// Generates xml element containing the settings.
/// </summary>
/// <param name="rootElemName">Name to be used as a name of the root element.</param>
/// <param name="suppressDefaults">Specifies whether to ommit optional nodes having set default values</param>
/// <returns>XElement containing the settings</returns>
public override XElement GetXml(string rootElemName, bool suppressDefaults)
{
XElement rootElem = new XElement(rootElemName);
Validate(rootElem, XsdTypeName);
return rootElem;
}

/// <summary>
/// Generates default named xml element containing the settings.
/// </summary>
/// <param name="suppressDefaults">Specifies whether to ommit optional nodes having set default values</param>
/// <returns>XElement containing the settings</returns>
public override XElement GetXml(bool suppressDefaults)
{
return GetXml("emptySchema", suppressDefaults);
}

}//EmptySchemaSettings

}//Namespace
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public InterconnSettings(XElement elem)
{
SchemaCfgCollection.Add(new ChainSchemaSettings(schemaElem));
}
else if (schemaElem.Name.LocalName == "emptySchema")
{
SchemaCfgCollection.Add(new EmptySchemaSettings(schemaElem));
}
else
{
//Ignore
Expand All @@ -111,7 +115,14 @@ protected override void Check()
{
if (SchemaCfgCollection.Count == 0)
{
throw new ArgumentException($"At least one interconnection schema must be specified.", "SchemaCfgCollection");
throw new InvalidOperationException($"At least one interconnection schema must be specified.");
}
foreach(IInterconnSchemaSettings schema in SchemaCfgCollection)
{
if(schema.GetType() == typeof(EmptySchemaSettings) && SchemaCfgCollection.Count > 1)
{
throw new InvalidOperationException($"No other schema specification is allowed together with EmptySchema.");
}
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ public override bool ContainsOnlyDefaults
/// </summary>
protected override void Check()
{
if (Density < 0 || Density > 1)
if (Density <= 0 || Density > 1)
{
throw new ArgumentException($"Invalid Density {Density.ToString(CultureInfo.InvariantCulture)}. Density must be GE to 0 and LE to 1.", "Density");
throw new ArgumentException($"Invalid Density {Density.ToString(CultureInfo.InvariantCulture)}. Density must be GT 0 and LE to 1.", "Density");
}
if (AvgDistance < 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,12 @@ Random rand
//Apply defined schemas
foreach (object connSchema in StructureCfg.PoolsCfg.PoolCfgCollection[poolID].InterconnectionCfg.SchemaCfgCollection)
{
if (connSchema.GetType() == typeof(RandomSchemaSettings))
if (connSchema.GetType() == typeof(EmptySchemaSettings))
{
//No interconnection
break;
}
else if (connSchema.GetType() == typeof(RandomSchemaSettings))
{
ConnectRandomSchema(poolID, rand, (RandomSchemaSettings)connSchema);
}
Expand Down
1 change: 1 addition & 0 deletions RCNet/RCNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<Compile Include="Neural\Network\SM\Preprocessing\Neuron\SpikingInputNeuron.cs" />
<Compile Include="Neural\Network\SM\Preprocessing\Reservoir\InputConnSettings.cs" />
<Compile Include="Neural\Network\SM\Preprocessing\Reservoir\InputConnsSettings.cs" />
<Compile Include="Neural\Network\SM\Preprocessing\Reservoir\Pool\EmptySchemaSettings.cs" />
<Compile Include="Neural\Network\SM\Preprocessing\Reservoir\Pool\NeuronGroup\INeuronGroupSettings.cs" />
<Compile Include="Neural\Network\SM\Preprocessing\Reservoir\Pool\NeuronGroup\HomogenousExcitabilitySettings.cs" />
<Compile Include="Neural\Network\SM\Preprocessing\Reservoir\ReservoirStat.cs" />
Expand Down
Loading

0 comments on commit 1fd7fc5

Please sign in to comment.