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

Commit

Permalink
The redesign of the Readout Layer, introduction of the Cluster Chain …
Browse files Browse the repository at this point in the history
…as the standard computation unit for the Readout Unit and One Takes All group. Enhanced data bundle folderization. Enhanced and revised code comments.
  • Loading branch information
okozelsk committed Jan 3, 2021
1 parent aa671e1 commit 4c97a0d
Show file tree
Hide file tree
Showing 377 changed files with 14,342 additions and 11,979 deletions.
70 changes: 34 additions & 36 deletions Demo/DemoConsoleApp/Examples/ExampleBase.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System;
using Demo.DemoConsoleApp.Log;
using Demo.DemoConsoleApp.Log;
using RCNet.CsvTools;
using RCNet.Neural.Data;
using RCNet.Neural.Network.NonRecurrent;
using RCNet.Neural.Network.SM;
using RCNet.Neural.Network.SM.Preprocessing;
using RCNet.Neural.Network.SM.Preprocessing.Input;
using RCNet.Neural.Network.SM.Readout;


namespace Demo.DemoConsoleApp.Examples
{
/// <summary>
/// Base class of the implemented examples
/// Implements the base class of the examples.
/// </summary>
public class ExampleBase
{
Expand All @@ -28,10 +28,10 @@ protected ExampleBase()
//Methods
//Event handlers
/// <summary>
/// Displays information about the verification progress.
/// Displays an information about the verification progress.
/// </summary>
/// <param name="totalNumOfInputs">Total number of inputs to be processed</param>
/// <param name="numOfProcessedInputs">Number of processed inputs</param>
/// <param name="totalNumOfInputs">The total number of inputs to be processed.</param>
/// <param name="numOfProcessedInputs">The number of already processed inputs.</param>
protected void OnVerificationProgressChanged(int totalNumOfInputs, int numOfProcessedInputs)
{
//Display progress
Expand All @@ -43,15 +43,15 @@ protected void OnVerificationProgressChanged(int totalNumOfInputs, int numOfProc
}

/// <summary>
/// Displays information about the preprocessing progress and at the end displays important NeuralPreprocessor's statistics.
/// Displays an information about the preprocessing progress and at the end displays important NeuralPreprocessor's statistics.
/// </summary>
/// <param name="totalNumOfInputs">Total number of inputs to be processed</param>
/// <param name="numOfProcessedInputs">Number of processed inputs</param>
/// <param name="finalPreprocessingOverview">Final overview of the preprocessing phase</param>
/// <param name="totalNumOfInputs">The total number of inputs to be processed.</param>
/// <param name="numOfProcessedInputs">The number of already processed inputs.</param>
/// <param name="finalPreprocessingOverview">The final overview of the preprocessing.</param>
protected void OnPreprocessingProgressChanged(int totalNumOfInputs,
int numOfProcessedInputs,
NeuralPreprocessor.PreprocessingOverview finalPreprocessingOverview
)
int numOfProcessedInputs,
NeuralPreprocessor.PreprocessingOverview finalPreprocessingOverview
)
{
if (finalPreprocessingOverview == null)
{
Expand All @@ -72,39 +72,38 @@ NeuralPreprocessor.PreprocessingOverview finalPreprocessingOverview
}

/// <summary>
/// Displays information about the readout unit regression progress.
/// Displays information about the build process progress.
/// </summary>
/// <param name="buildingState">Current state of the regression process</param>
/// <param name="foundBetter">Indicates that the best readout unit was changed as a result of the performed epoch</param>
protected void OnRegressionEpochDone(TrainedNetworkBuilder.BuildingState buildingState, bool foundBetter)
/// <param name="buildProgress">The current state of the build process.</param>
/// <param name="foundBetter">Indicates that the best network so far was found during the last performed epoch.</param>
protected void OnEpochDone(TNRNetBuilder.BuildProgress buildProgress, bool foundBetter)
{
int reportEpochsInterval = 5;
//Progress info
if (foundBetter ||
(buildingState.Epoch % reportEpochsInterval) == 0 ||
buildingState.Epoch == buildingState.MaxEpochs ||
(buildingState.Epoch == 1 && buildingState.RegrAttemptNumber == 1)
(buildProgress.Epoch % reportEpochsInterval) == 0 ||
buildProgress.Epoch == buildProgress.MaxEpochs ||
(buildProgress.Epoch == 1 && buildProgress.AttemptNumber == 1)
)
{
//Build progress report message
string progressText = buildingState.GetProgressInfo(4);
string progressText = buildProgress.GetInfo(4);
//Report the progress
_log.Write(progressText, !(buildingState.Epoch == 1 && buildingState.RegrAttemptNumber == 1));
_log.Write(progressText, !(buildProgress.Epoch == 1 && buildProgress.AttemptNumber == 1));
}
return;
}

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

/// <summary>
/// Loads given file and executes StateMachine verification.
/// This version of function requires configured NeuralPreprocessor.
/// Loads the specified file and executes the StateMachine verification.
/// </summary>
/// <param name="stateMachine">Instance of StateMachine to be trained</param>
/// <param name="verificationDataFileName">Name of the csv file containing verification data</param>
/// <param name="omittedInputVector">Remaining input vector from training phase (relevant only in case of continuous feeding of the input)</param>
/// <param name="predictionInputVector">Returned vector to be used for next prediction (relevant only in case of continuous feeding of the input)</param>
/// <param name="stateMachine">An instance of StateMachine to be verified.</param>
/// <param name="verificationDataFileName">The name of the csv file containing the verification data.</param>
/// <param name="omittedInputVector">Remaining input vector from training phase (relevant only in case of continuous feeding of the input).</param>
/// <param name="predictionInputVector">The vector to be used for next prediction (relevant only in case of continuous feeding of the input).</param>
protected void VerifyStateMachine(StateMachine stateMachine, string verificationDataFileName, double[] omittedInputVector, out double[] predictionInputVector)
{
//Load csv data
Expand All @@ -175,7 +173,7 @@ protected void VerifyStateMachine(StateMachine stateMachine, string verification
//Continuous input feeding
//Last known input values from training (predictionInputVector) must be pushed into the reservoirs to keep time series continuity
//(first input data in verification.csv is output of the last data in training.csv)
double[] tmp = stateMachine.Compute(omittedInputVector);
double[] tmp = stateMachine.Compute(omittedInputVector, out ReadoutLayer.ReadoutData readoutData);
//Load verification data and get new predictionInputVector for final prediction
verificationData = VectorBundle.Load(verificationCsvData,
stateMachine.Config.NeuralPreprocessorCfg.InputEncoderCfg.VaryingFieldsCfg.ExternalFieldsCfg.GetFieldNames(),
Expand Down
20 changes: 11 additions & 9 deletions Demo/DemoConsoleApp/Examples/FFNetBoolAlg.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
using System;
using System.Globalization;
using RCNet.Neural.Activation;
using RCNet.Neural.Activation;
using RCNet.Neural.Data;
using RCNet.Neural.Network.NonRecurrent.FF;
using System;
using System.Globalization;

namespace Demo.DemoConsoleApp.Examples
{
/// <summary>
/// This "Hello world" example shows how to use implemented FF network as the independent component.
/// It trains the multilayer Feed Forward network to solve AND, OR and XOR.
/// Trains a multilayer Feed Forward network to solve AND, OR and XOR.
/// </summary>
/// <remarks>
/// This "Hello world" example shows how to use the feed forward network component independently.
/// </remarks>
public class FFNetBoolAlg : ExampleBase
{
/// <summary>
/// Creates training data.
/// Input vector contains 0/1 combination and output vector contains appropriate results of the AND, OR and XOR operation
/// Creates the training data.
/// Input vector contains 0/1 combination and output vector contains appropriate results of the AND, OR and XOR operation.
/// </summary>
private VectorBundle CreateTrainingData()
{
Expand Down Expand Up @@ -48,7 +50,7 @@ public void Run()
//Training
_log.Write("Training");
_log.Write("--------");
//Create trainer instance
//Create the trainer instance
RPropTrainer trainer = new RPropTrainer(ffNet,
trainingData.InputVectorCollection,
trainingData.OutputVectorCollection,
Expand All @@ -63,7 +65,7 @@ public void Run()
_log.Write(string.Empty);

//Training is done
//Display network computation results
//Display the network computation results
_log.Write("Trained network computations:");
_log.Write("-----------------------------");
foreach (double[] input in trainingData.InputVectorCollection)
Expand Down
10 changes: 5 additions & 5 deletions Demo/DemoConsoleApp/Examples/LibrasClassificationESNDesigner.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System;
using RCNet.Neural.Activation;
using RCNet.Neural.Activation;
using RCNet.Neural.Data.Filter;
using RCNet.Neural.Network.NonRecurrent;
using RCNet.Neural.Network.SM;
using RCNet.Neural.Network.SM.Preprocessing;
using RCNet.Neural.Network.SM.Preprocessing.Input;
using RCNet.Neural.Network.SM.Preprocessing.Neuron.Predictor;
using RCNet.Neural.Network.SM.Readout;
using System;

namespace Demo.DemoConsoleApp.Examples
{
/// <summary>
/// Example code shows how to setup StateMachine as a pure ESN for multivariate timeseries classification using StateMachineDesigner.
/// Example code shows how to use StateMachineDesigner and setup StateMachine as a pure ESN for multivariate timeseries classification.
/// Example uses LibrasMovement_train.csv and LibrasMovement_verify.csv from ./Data subfolder.
/// The dataset is from "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=Libras
Expand Down Expand Up @@ -44,9 +44,9 @@ public void Run()
);
//Simplified readout layer configuration
ReadoutLayerSettings readoutCfg = StateMachineDesigner.CreateClassificationReadoutCfg(new CrossvalidationSettings(0.0825d, CrossvalidationSettings.AutoFolds, 1),
StateMachineDesigner.CreateSingleLayerRegrNet(new AFAnalogIdentitySettings(), 5, 400),
StateMachineDesigner.CreateSingleLayerFFNetCfg(new AFAnalogIdentitySettings(), 5, 400),
1,
"Hand movement",
new NetworkClusterSecondLevelCompSettings(new CrossvalidationSettings(0.25d, CrossvalidationSettings.AutoFolds, 2), StateMachineDesigner.CreateMultiLayerRegrNet(10, new AFAnalogLeakyReLUSettings(), 1, 5, 400)),
"curved swing",
"horizontal swing",
"vertical swing",
Expand Down
Loading

0 comments on commit 4c97a0d

Please sign in to comment.