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

A2. Introduction to State Machine

Oldřich Koželský edited this page Jan 18, 2021 · 47 revisions

NeuralPreprocessor and ReadoutLayer are two independent components that can be used separately. StateMachine encapsulates them, ensures proper data flow, and provides a simple API for interacting with the client application.

StateMachine Training and Verification

The methods for StateMachine training and subsequent verification of trained StateMachine accuracy are:

public TrainingResults Train(VectorBundle trainingData, TNRNetBuilder.BuildControllerDelegate controller = null);
public VerificationResults Verify(VectorBundle verificationData);

The following figure shows a typical sequence for preparing an operable and trained StateMachine.

StateMachine Instantiation

First of all, you need to create an instance of the StateMachineSettings class that contains the complete configuration and is required by the StateMachine constructor. How to do it will be described later.

Sample data (VectorBundle)

StateMachine's methods Train and Verify require data sets containing pairs of input and corresponding output data vectors. The VectorBundle class is used to pass a data set. The data is expected in natural form, so it does not have to be modified in any way (normalization, standardization), everything is provided internally by StateMachine. Input and output data vectors are represented by arrays of double (double[]). VectorBundle has two constructors. The first constructor creates an initialized instance and requires a collection of input vectors and a collection of corresponding output vectors. The second constructor creates an empty instance and only requires an estimate of the target number of vector pairs. One vector pair can be added using the AddPair method. All vector pairs from another VectorBundle can be added using the Add method.

public VectorBundle(IEnumerable<double[]> inputVectorCollection, IEnumerable<double[]> outputVectorCollection);
public VectorBundle(int expectedNumOfPairs);
public void AddPair(double[] inputVector, double[] outputVector);
public void Add(VectorBundle data);

StateMachine can work in two basic data modes. The first is called "Continuous Input Feeding" and the second is called "Patterned Input Feeding". In Continuous Input Feeding mode, one vector contains the values of variables at one time point in the time series. In Patterned Input Feeding, one vector contains the data of the whole time series, ie the values of the variables sequentially for all time points of the time series.

Data organization for the Continuous Input Feeding Mode

Data organization for the Patterned Input Feeding Mode

Events handling

Controller

Use a trained StateMachine instance

StateMachine is serializable, so for example, after training, you can serialize the instance and then deserialize and use the trained instance when needed. The methods for serialization and deserialization of StateMachine are:

public void Serialize(Stream stream);
public void Serialize(string fileName);
public static StateMachine Deserialize(Stream stream);
public static StateMachine Deserialize(string fileName);






Links to source code