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

Commit 4c97a0d

Browse files
committed
The redesign of the Readout Layer, introduction of the Cluster Chain as the standard computation unit for the Readout Unit and One Takes All group. Enhanced data bundle folderization. Enhanced and revised code comments.
1 parent aa671e1 commit 4c97a0d

377 files changed

Lines changed: 14342 additions & 11979 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Demo/DemoConsoleApp/Examples/ExampleBase.cs

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
using System;
2-
using Demo.DemoConsoleApp.Log;
1+
using Demo.DemoConsoleApp.Log;
32
using RCNet.CsvTools;
43
using RCNet.Neural.Data;
54
using RCNet.Neural.Network.NonRecurrent;
65
using RCNet.Neural.Network.SM;
76
using RCNet.Neural.Network.SM.Preprocessing;
87
using RCNet.Neural.Network.SM.Preprocessing.Input;
8+
using RCNet.Neural.Network.SM.Readout;
99

1010

1111
namespace Demo.DemoConsoleApp.Examples
1212
{
1313
/// <summary>
14-
/// Base class of the implemented examples
14+
/// Implements the base class of the examples.
1515
/// </summary>
1616
public class ExampleBase
1717
{
@@ -28,10 +28,10 @@ protected ExampleBase()
2828
//Methods
2929
//Event handlers
3030
/// <summary>
31-
/// Displays information about the verification progress.
31+
/// Displays an information about the verification progress.
3232
/// </summary>
33-
/// <param name="totalNumOfInputs">Total number of inputs to be processed</param>
34-
/// <param name="numOfProcessedInputs">Number of processed inputs</param>
33+
/// <param name="totalNumOfInputs">The total number of inputs to be processed.</param>
34+
/// <param name="numOfProcessedInputs">The number of already processed inputs.</param>
3535
protected void OnVerificationProgressChanged(int totalNumOfInputs, int numOfProcessedInputs)
3636
{
3737
//Display progress
@@ -43,15 +43,15 @@ protected void OnVerificationProgressChanged(int totalNumOfInputs, int numOfProc
4343
}
4444

4545
/// <summary>
46-
/// Displays information about the preprocessing progress and at the end displays important NeuralPreprocessor's statistics.
46+
/// Displays an information about the preprocessing progress and at the end displays important NeuralPreprocessor's statistics.
4747
/// </summary>
48-
/// <param name="totalNumOfInputs">Total number of inputs to be processed</param>
49-
/// <param name="numOfProcessedInputs">Number of processed inputs</param>
50-
/// <param name="finalPreprocessingOverview">Final overview of the preprocessing phase</param>
48+
/// <param name="totalNumOfInputs">The total number of inputs to be processed.</param>
49+
/// <param name="numOfProcessedInputs">The number of already processed inputs.</param>
50+
/// <param name="finalPreprocessingOverview">The final overview of the preprocessing.</param>
5151
protected void OnPreprocessingProgressChanged(int totalNumOfInputs,
52-
int numOfProcessedInputs,
53-
NeuralPreprocessor.PreprocessingOverview finalPreprocessingOverview
54-
)
52+
int numOfProcessedInputs,
53+
NeuralPreprocessor.PreprocessingOverview finalPreprocessingOverview
54+
)
5555
{
5656
if (finalPreprocessingOverview == null)
5757
{
@@ -72,39 +72,38 @@ NeuralPreprocessor.PreprocessingOverview finalPreprocessingOverview
7272
}
7373

7474
/// <summary>
75-
/// Displays information about the readout unit regression progress.
75+
/// Displays information about the build process progress.
7676
/// </summary>
77-
/// <param name="buildingState">Current state of the regression process</param>
78-
/// <param name="foundBetter">Indicates that the best readout unit was changed as a result of the performed epoch</param>
79-
protected void OnRegressionEpochDone(TrainedNetworkBuilder.BuildingState buildingState, bool foundBetter)
77+
/// <param name="buildProgress">The current state of the build process.</param>
78+
/// <param name="foundBetter">Indicates that the best network so far was found during the last performed epoch.</param>
79+
protected void OnEpochDone(TNRNetBuilder.BuildProgress buildProgress, bool foundBetter)
8080
{
8181
int reportEpochsInterval = 5;
8282
//Progress info
8383
if (foundBetter ||
84-
(buildingState.Epoch % reportEpochsInterval) == 0 ||
85-
buildingState.Epoch == buildingState.MaxEpochs ||
86-
(buildingState.Epoch == 1 && buildingState.RegrAttemptNumber == 1)
84+
(buildProgress.Epoch % reportEpochsInterval) == 0 ||
85+
buildProgress.Epoch == buildProgress.MaxEpochs ||
86+
(buildProgress.Epoch == 1 && buildProgress.AttemptNumber == 1)
8787
)
8888
{
8989
//Build progress report message
90-
string progressText = buildingState.GetProgressInfo(4);
90+
string progressText = buildProgress.GetInfo(4);
9191
//Report the progress
92-
_log.Write(progressText, !(buildingState.Epoch == 1 && buildingState.RegrAttemptNumber == 1));
92+
_log.Write(progressText, !(buildProgress.Epoch == 1 && buildProgress.AttemptNumber == 1));
9393
}
9494
return;
9595
}
9696

9797
/// <summary>
98-
/// Loads given file and executes StateMachine training.
99-
/// This version of function requires configured NeuralPreprocessor.
98+
/// Loads the specified file and executes the StateMachine training.
10099
/// </summary>
101-
/// <param name="stateMachine">Instance of StateMachine to be trained</param>
102-
/// <param name="trainingDataFileName">Name of the csv file containing training data</param>
103-
/// <param name="predictionInputVector">Returned vector to be used for next prediction (relevant only in case of continuous feeding of the input)</param>
100+
/// <param name="stateMachine">An instance of StateMachine to be trained.</param>
101+
/// <param name="trainingDataFileName">The name of the csv file containing the training data.</param>
102+
/// <param name="predictionInputVector">The vector to be used for next prediction (relevant only in case of continuous feeding of the input).</param>
104103
protected void TrainStateMachine(StateMachine stateMachine, string trainingDataFileName, out double[] predictionInputVector)
105104
{
106-
//Register to RegressionEpochDone event
107-
stateMachine.RL.RegressionEpochDone += OnRegressionEpochDone;
105+
//Register to EpochDone event
106+
stateMachine.RL.EpochDone += OnEpochDone;
108107
//Load csv data
109108
CsvDataHolder trainingCsvData = new CsvDataHolder(trainingDataFileName);
110109
//Convert csv data to VectorBundle useable for StateMachine training
@@ -153,13 +152,12 @@ out predictionInputVector
153152
}
154153

155154
/// <summary>
156-
/// Loads given file and executes StateMachine verification.
157-
/// This version of function requires configured NeuralPreprocessor.
155+
/// Loads the specified file and executes the StateMachine verification.
158156
/// </summary>
159-
/// <param name="stateMachine">Instance of StateMachine to be trained</param>
160-
/// <param name="verificationDataFileName">Name of the csv file containing verification data</param>
161-
/// <param name="omittedInputVector">Remaining input vector from training phase (relevant only in case of continuous feeding of the input)</param>
162-
/// <param name="predictionInputVector">Returned vector to be used for next prediction (relevant only in case of continuous feeding of the input)</param>
157+
/// <param name="stateMachine">An instance of StateMachine to be verified.</param>
158+
/// <param name="verificationDataFileName">The name of the csv file containing the verification data.</param>
159+
/// <param name="omittedInputVector">Remaining input vector from training phase (relevant only in case of continuous feeding of the input).</param>
160+
/// <param name="predictionInputVector">The vector to be used for next prediction (relevant only in case of continuous feeding of the input).</param>
163161
protected void VerifyStateMachine(StateMachine stateMachine, string verificationDataFileName, double[] omittedInputVector, out double[] predictionInputVector)
164162
{
165163
//Load csv data
@@ -175,7 +173,7 @@ protected void VerifyStateMachine(StateMachine stateMachine, string verification
175173
//Continuous input feeding
176174
//Last known input values from training (predictionInputVector) must be pushed into the reservoirs to keep time series continuity
177175
//(first input data in verification.csv is output of the last data in training.csv)
178-
double[] tmp = stateMachine.Compute(omittedInputVector);
176+
double[] tmp = stateMachine.Compute(omittedInputVector, out ReadoutLayer.ReadoutData readoutData);
179177
//Load verification data and get new predictionInputVector for final prediction
180178
verificationData = VectorBundle.Load(verificationCsvData,
181179
stateMachine.Config.NeuralPreprocessorCfg.InputEncoderCfg.VaryingFieldsCfg.ExternalFieldsCfg.GetFieldNames(),

Demo/DemoConsoleApp/Examples/FFNetBoolAlg.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
using System;
2-
using System.Globalization;
3-
using RCNet.Neural.Activation;
1+
using RCNet.Neural.Activation;
42
using RCNet.Neural.Data;
53
using RCNet.Neural.Network.NonRecurrent.FF;
4+
using System;
5+
using System.Globalization;
66

77
namespace Demo.DemoConsoleApp.Examples
88
{
99
/// <summary>
10-
/// This "Hello world" example shows how to use implemented FF network as the independent component.
11-
/// It trains the multilayer Feed Forward network to solve AND, OR and XOR.
10+
/// Trains a multilayer Feed Forward network to solve AND, OR and XOR.
1211
/// </summary>
12+
/// <remarks>
13+
/// This "Hello world" example shows how to use the feed forward network component independently.
14+
/// </remarks>
1315
public class FFNetBoolAlg : ExampleBase
1416
{
1517
/// <summary>
16-
/// Creates training data.
17-
/// Input vector contains 0/1 combination and output vector contains appropriate results of the AND, OR and XOR operation
18+
/// Creates the training data.
19+
/// Input vector contains 0/1 combination and output vector contains appropriate results of the AND, OR and XOR operation.
1820
/// </summary>
1921
private VectorBundle CreateTrainingData()
2022
{
@@ -48,7 +50,7 @@ public void Run()
4850
//Training
4951
_log.Write("Training");
5052
_log.Write("--------");
51-
//Create trainer instance
53+
//Create the trainer instance
5254
RPropTrainer trainer = new RPropTrainer(ffNet,
5355
trainingData.InputVectorCollection,
5456
trainingData.OutputVectorCollection,
@@ -63,7 +65,7 @@ public void Run()
6365
_log.Write(string.Empty);
6466

6567
//Training is done
66-
//Display network computation results
68+
//Display the network computation results
6769
_log.Write("Trained network computations:");
6870
_log.Write("-----------------------------");
6971
foreach (double[] input in trainingData.InputVectorCollection)

Demo/DemoConsoleApp/Examples/LibrasClassificationESNDesigner.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
using System;
2-
using RCNet.Neural.Activation;
1+
using RCNet.Neural.Activation;
32
using RCNet.Neural.Data.Filter;
43
using RCNet.Neural.Network.NonRecurrent;
54
using RCNet.Neural.Network.SM;
65
using RCNet.Neural.Network.SM.Preprocessing;
76
using RCNet.Neural.Network.SM.Preprocessing.Input;
87
using RCNet.Neural.Network.SM.Preprocessing.Neuron.Predictor;
98
using RCNet.Neural.Network.SM.Readout;
9+
using System;
1010

1111
namespace Demo.DemoConsoleApp.Examples
1212
{
1313
/// <summary>
14-
/// Example code shows how to setup StateMachine as a pure ESN for multivariate timeseries classification using StateMachineDesigner.
14+
/// Example code shows how to use StateMachineDesigner and setup StateMachine as a pure ESN for multivariate timeseries classification.
1515
/// Example uses LibrasMovement_train.csv and LibrasMovement_verify.csv from ./Data subfolder.
1616
/// The dataset is from "Anthony Bagnall, Jason Lines, William Vickers and Eamonn Keogh, The UEA & UCR Time Series Classification Repository, www.timeseriesclassification.com"
1717
/// https://timeseriesclassification.com/description.php?Dataset=Libras
@@ -44,9 +44,9 @@ public void Run()
4444
);
4545
//Simplified readout layer configuration
4646
ReadoutLayerSettings readoutCfg = StateMachineDesigner.CreateClassificationReadoutCfg(new CrossvalidationSettings(0.0825d, CrossvalidationSettings.AutoFolds, 1),
47-
StateMachineDesigner.CreateSingleLayerRegrNet(new AFAnalogIdentitySettings(), 5, 400),
47+
StateMachineDesigner.CreateSingleLayerFFNetCfg(new AFAnalogIdentitySettings(), 5, 400),
48+
1,
4849
"Hand movement",
49-
new NetworkClusterSecondLevelCompSettings(new CrossvalidationSettings(0.25d, CrossvalidationSettings.AutoFolds, 2), StateMachineDesigner.CreateMultiLayerRegrNet(10, new AFAnalogLeakyReLUSettings(), 1, 5, 400)),
5050
"curved swing",
5151
"horizontal swing",
5252
"vertical swing",

0 commit comments

Comments
 (0)