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

Commit

Permalink
Issue #18 - steady data of the input pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
okozelsk committed Jun 16, 2020
1 parent 7fc872d commit a940c69
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 135 deletions.
245 changes: 122 additions & 123 deletions Demo/DemoConsoleApp/SM/SMDemoSettings.xml
Original file line number Diff line number Diff line change
@@ -1,129 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<demo dataFolder=".\\Data" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SMDemoSettings.xsd">

<!--
This demo case illustrates why and how to define steady data fields in case of patterned feeding.
-->
<case name="Forecast task SteadyMG: pure ESN reservoir generating Activation predictors, MLP as a forecaster (Resilient trainer)">
<samples trainingData="SteadyMG_train.csv" verificationData="SteadyMG_verify.csv"/>
<stateMachine randomizerSeek="0">
<neuralPreprocessor predictorsReductionRatio="0">
<inputEncoder>
<feedingPatterned slices="1" bidir="false" variablesSchema="Sequential">
<unification unifyAmplitude="false" detrend="false">
<resampling signalBeginThreshold="0" signalEndThreshold="0" uniformTimeScale="true" targetTimePoints="Auto"/>
</unification>
<steadyFields>
<field name="tau" routeToReadout="true"/>
</steadyFields>
</feedingPatterned>
<varyingFields routeToReadout="false">
<externalFields>
<field name="MG">
<realFeature />
</field>
</externalFields>
</varyingFields>
</inputEncoder>
<reservoirStructures>
<reservoirStructure name="MainCfg">
<pools>
<pool name="PoolMain">
<proportions dimX="200" dimY="1" dimZ="1"/>
<neuronGroups>
<analogGroup name="TanH-grp" relShare="1">
<activationTanH/>
</analogGroup>
</neuronGroups>
<interconnection>
<randomSchema density="0.1" avgDistance="NA" allowSelfConnection="true"/>
<chainSchema/>
</interconnection>
</pool>
</pools>
</reservoirStructure>
</reservoirStructures>
<reservoirInstances>
<reservoirInstance name="Main" reservoirStructure="MainCfg">
<inputConnections>
<connection inputFieldName="MG" poolName="PoolMain" analogTargetDensity="0.25" signalingRestriction="NoRestriction"/>
</inputConnections>
<synapse>
<analogTarget spectralRadius="0.9999">
<input maxDelay="0">
<analogSource>
<weight min="0" max="1.5"/>
</analogSource>
</input>
<indifferent maxDelay="0"/>
</analogTarget>
</synapse>
<predictors activation="true"
activationSquare="false"
activationFadingSum="false"
activationMWAvg="false"
firingFadingSum="false"
firingMWAvg="false"
firingCount="false"
firingBinPattern="false">
</predictors>
</reservoirInstance>
</reservoirInstances>
</neuralPreprocessor>
<readoutLayer testDataRatio="0.5" folds="Auto" repetitions="1">
<defaultNetworks>
<forecast>
<ff>
<activationIdentity/>
<hiddenLayers>
<layer neurons="10">
<activationLeakyReLU/>
</layer>
<layer neurons="10">
<activationLeakyReLU/>
</layer>
</hiddenLayers>
<resPropTrainer attempts="5" attemptEpochs="1000"/>
</ff>
</forecast>
</defaultNetworks>
<readoutUnits>
<readoutUnit name="MG-with-steady">
<forecast>
<realFeature/>
</forecast>
</readoutUnit>
<readoutUnit name="MG-w/o-steady">
<forecast>
<realFeature/>
</forecast>
</readoutUnit>
</readoutUnits>
</readoutLayer>
<mapper>
<map readoutUnitName="MG-with-steady">
<allowedPredictors>
<predictor name="Activation"/>
</allowedPredictors>
<allowedPools>
<pool reservoirInstanceName="Main" poolName="PoolMain"/>
</allowedPools>
<allowedInputFields>
<field name="tau"/>
</allowedInputFields>
</map>
<map readoutUnitName="MG-w/o-steady">
<allowedPredictors>
<predictor name="Activation"/>
</allowedPredictors>
<allowedPools>
<pool reservoirInstanceName="Main" poolName="PoolMain"/>
</allowedPools>
</map>
</mapper>
</stateMachine>
</case>


<!--
Here StateMachine achieves 71% accuracy. It is clearly worse than the best accuracy 81.4% achieved by the algorithm
Expand Down Expand Up @@ -1306,6 +1183,128 @@
</stateMachine>
</case>

<!--
This demo case illustrates how to define steady data fields in case of patterned feeding.
-->
<case name="Forecast task SteadyMG: pure ESN reservoir generating Activation predictors, MLP as a forecaster (Resilient trainer)">
<samples trainingData="SteadyMG_train.csv" verificationData="SteadyMG_verify.csv"/>
<stateMachine randomizerSeek="0">
<neuralPreprocessor predictorsReductionRatio="0">
<inputEncoder>
<feedingPatterned slices="1" bidir="false" variablesSchema="Sequential">
<unification unifyAmplitude="false" detrend="false">
<resampling signalBeginThreshold="0" signalEndThreshold="0" uniformTimeScale="true" targetTimePoints="Auto"/>
</unification>
<steadyFields>
<field name="tau" routeToReadout="true"/>
</steadyFields>
</feedingPatterned>
<varyingFields routeToReadout="false">
<externalFields>
<field name="MG">
<realFeature />
</field>
</externalFields>
</varyingFields>
</inputEncoder>
<reservoirStructures>
<reservoirStructure name="MainCfg">
<pools>
<pool name="PoolMain">
<proportions dimX="200" dimY="1" dimZ="1"/>
<neuronGroups>
<analogGroup name="TanH-grp" relShare="1">
<activationTanH/>
</analogGroup>
</neuronGroups>
<interconnection>
<randomSchema density="0.1" avgDistance="NA" allowSelfConnection="true"/>
<chainSchema/>
</interconnection>
</pool>
</pools>
</reservoirStructure>
</reservoirStructures>
<reservoirInstances>
<reservoirInstance name="Main" reservoirStructure="MainCfg">
<inputConnections>
<connection inputFieldName="MG" poolName="PoolMain" analogTargetDensity="0.25" signalingRestriction="NoRestriction"/>
</inputConnections>
<synapse>
<analogTarget spectralRadius="0.9999">
<input maxDelay="0">
<analogSource>
<weight min="0" max="1.5"/>
</analogSource>
</input>
<indifferent maxDelay="0"/>
</analogTarget>
</synapse>
<predictors activation="true"
activationSquare="false"
activationFadingSum="false"
activationMWAvg="false"
firingFadingSum="false"
firingMWAvg="false"
firingCount="false"
firingBinPattern="false">
</predictors>
</reservoirInstance>
</reservoirInstances>
</neuralPreprocessor>
<readoutLayer testDataRatio="0.5" folds="Auto" repetitions="1">
<defaultNetworks>
<forecast>
<ff>
<activationIdentity/>
<hiddenLayers>
<layer neurons="10">
<activationLeakyReLU/>
</layer>
<layer neurons="10">
<activationLeakyReLU/>
</layer>
</hiddenLayers>
<resPropTrainer attempts="5" attemptEpochs="1000"/>
</ff>
</forecast>
</defaultNetworks>
<readoutUnits>
<readoutUnit name="MG-with-steady">
<forecast>
<realFeature/>
</forecast>
</readoutUnit>
<readoutUnit name="MG-w/o-steady">
<forecast>
<realFeature/>
</forecast>
</readoutUnit>
</readoutUnits>
</readoutLayer>
<mapper>
<map readoutUnitName="MG-with-steady">
<allowedPredictors>
<predictor name="Activation"/>
</allowedPredictors>
<allowedPools>
<pool reservoirInstanceName="Main" poolName="PoolMain"/>
</allowedPools>
<allowedInputFields>
<field name="tau"/>
</allowedInputFields>
</map>
<map readoutUnitName="MG-w/o-steady">
<allowedPredictors>
<predictor name="Activation"/>
</allowedPredictors>
<allowedPools>
<pool reservoirInstanceName="Main" poolName="PoolMain"/>
</allowedPools>
</map>
</mapper>
</stateMachine>
</case>


</demo>
Expand Down
35 changes: 25 additions & 10 deletions RCNet/Neural/Network/NonRecurrent/TrainedNetworkBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,37 @@ public static bool IsBetter(bool binaryOutput, TrainedNetwork candidate, Trained
{
if (binaryOutput)
{
if (candidate.CombinedBinaryError < currentBest.CombinedBinaryError)
if(candidate.CombinedBinaryError > currentBest.CombinedBinaryError)
{
return false;
}
else if (candidate.CombinedBinaryError < currentBest.CombinedBinaryError)
{
return true;
}
//CombinedBinaryError is the same
else if (candidate.TestingBinErrorStat.BinValErrStat[0].Sum > currentBest.TestingBinErrorStat.BinValErrStat[0].Sum)
{
return false;
}
else if(candidate.TestingBinErrorStat.BinValErrStat[0].Sum < currentBest.TestingBinErrorStat.BinValErrStat[0].Sum)
{
return true;
}
else if (candidate.CombinedBinaryError == currentBest.CombinedBinaryError &&
(candidate.TestingBinErrorStat.BinValErrStat[0].Sum < currentBest.TestingBinErrorStat.BinValErrStat[0].Sum ||
(candidate.TestingBinErrorStat.BinValErrStat[0].Sum == currentBest.TestingBinErrorStat.BinValErrStat[0].Sum && candidate.TrainingBinErrorStat.BinValErrStat[0].Sum < currentBest.TrainingBinErrorStat.BinValErrStat[0].Sum)
))
//CombinedBinaryError is the same
//TestingBinErrorStat.BinValErrStat[0].Sum is the same
else if (candidate.TrainingBinErrorStat.BinValErrStat[0].Sum > currentBest.TrainingBinErrorStat.BinValErrStat[0].Sum)
{
return false;
}
else if (candidate.TrainingBinErrorStat.BinValErrStat[0].Sum < currentBest.TrainingBinErrorStat.BinValErrStat[0].Sum)
{
return true;
}
else if (candidate.CombinedBinaryError == currentBest.CombinedBinaryError &&
candidate.TestingBinErrorStat.BinValErrStat[0].Sum == currentBest.TestingBinErrorStat.BinValErrStat[0].Sum &&
candidate.TrainingBinErrorStat.BinValErrStat[0].Sum == currentBest.TrainingBinErrorStat.BinValErrStat[0].Sum &&
candidate.CombinedPrecisionError < currentBest.CombinedPrecisionError
)
//CombinedBinaryError is the same
//TestingBinErrorStat.BinValErrStat[0].Sum is the same
//TrainingBinErrorStat.BinValErrStat[0].Sum is the same
else if (candidate.CombinedPrecisionError < currentBest.CombinedPrecisionError)
{
return true;
}
Expand Down
19 changes: 19 additions & 0 deletions RCNet/Neural/Network/SM/PM/ReadoutUnitMapSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public override bool ContainsOnlyDefaults


//Methods
/// <summary>
/// Determines whether the predictor's origin is allowed
/// </summary>
/// <param name="resName">Reservoir instance name</param>
/// <param name="poolName">Pool name</param>
private bool IsAllowedPredictorOrigin(string resName, string poolName)
{
if(AllowedPoolsCfg != null)
Expand All @@ -112,6 +117,10 @@ private bool IsAllowedPredictorOrigin(string resName, string poolName)
return false;
}

/// <summary>
/// Determines whether Predictor is allowed
/// </summary>
/// <param name="predictorID">Predictor identificator</param>
private bool IsAllowedPredictorID(PredictorsProvider.PredictorID predictorID)
{
if(AllowedPredictorsCfg != null)
Expand All @@ -121,6 +130,12 @@ private bool IsAllowedPredictorID(PredictorsProvider.PredictorID predictorID)
return false;
}

/// <summary>
/// Determines whether the Predictor's origin and Predictor are both allowed
/// </summary>
/// <param name="resName">Reservoir instance name</param>
/// <param name="poolName">Pool name</param>
/// <param name="predictorID">Predictor identificator</param>
public bool IsAllowedPredictor(string resName, string poolName, PredictorsProvider.PredictorID predictorID)
{
if(IsAllowedPredictorOrigin(resName, poolName))
Expand All @@ -130,6 +145,10 @@ public bool IsAllowedPredictor(string resName, string poolName, PredictorsProvid
return false;
}

/// <summary>
/// Determines whether given input field is allowed
/// </summary>
/// <param name="inputFieldName">Name of the input field</param>
public bool IsAllowedInputField(string inputFieldName)
{
if(AllowedInputFieldsCfg != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,6 @@ public List<PredictorDescriptor> GetInputValuesPredictorsDescriptors()
//Build descriptors
List<PredictorDescriptor> result = new List<PredictorDescriptor>(_routedSteadyFieldIndexCollection.Count + _routedVaryingFieldCollection.Count * NumOfTimePoints);
//Steady fields

foreach(int idx in _routedSteadyFieldIndexCollection)
{
result.Add(new PredictorDescriptor(((FeedingPatternedSettings)_encoderCfg.FeedingCfg).SteadyFieldsCfg.FieldCfgCollection[idx].Name));
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Several examples show how to simply setup State Machine using State Machine Desi
### Data format for the demo application
Input data is standardly located in the Data sub-folder relative to the location of the executable DemoConsoleApp.exe. Data is expected in csv format and data delimiter can be a tab, semicolon or comma character.
* **Continuous feeding regime** requires a standard csv format, where the first line contains the names of the data fields and each next line contains the data. [Here](https://github.com/okozelsk/NET/blob/master/Demo/DemoConsoleApp/Data/TTOO.csv) is an example
* **Patterned feeding regime** requires specific logical csv format without colum names (header). Each data line contains values of repetitive pattern features followed by expected output values at the end. Values of repetitive pattern features can be organized in two ways: groupped [v1(t1),v2(t1),v1(t2),v2(t2),v1(t3),v2(t3)] or sequential [v1(t1),v1(t2),v1(t3),v2(t1),v2(t2),v2(t3)]. [Here](https://github.com/okozelsk/NET/blob/master/Demo/DemoConsoleApp/Data/LibrasMovement.csv) is an example
* **Patterned feeding regime** requires specific logical csv format without colum names (header). Each data line contains values of steady (optional) and repetitive pattern features followed by expected output values at the end. Values of repetitive pattern features can be organized in two ways: groupped [v1(t1),v2(t1),v1(t2),v2(t2),v1(t3),v2(t3)] or sequential [v1(t1),v1(t2),v1(t3),v2(t1),v2(t2),v2(t3)]. [Here](https://github.com/okozelsk/NET/blob/master/Demo/DemoConsoleApp/Data/LibrasMovement.csv) is an example

## Components overview

Expand Down

0 comments on commit a940c69

Please sign in to comment.