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 19, 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 Train and Verify methods require datasets containing vector pairs. Each vector pair consists of an input data vector and a corresponding output data vector. 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. Both methods get a dataset through an instance of the VectorBundle class, where the input and output data vector is represented by double array (double[]). VectorBundle class 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 instance 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 modes of input data processing called "Continuous Input Feeding" and "Patterned Input Feeding".

Continuous Input Feeding Mode

In continuous input mode, one vector pair contains input and output data for one time point of the series, and VectorBundle then represents the time series. It is clear that the order of the vector pairs in the VectorBundle is important. Continuous input mode is used where it is necessary to keep the whole context of the time series to calculate the output. A good example is the prediction of the future price of a stock based on the previous changes of its price over time.

Patterned Input Feeding Mode

In patterned input mode, one vector pair consists of input time series (pattern) and corresponding output data as a result of that time series. Each vector pair represents a case independent on other vector pairs within the VectorBundle. It is clear that the order of the vector pairs within the VectorBundle is not important. Patterned input mode is used where it is not necessary to keep the whole context of the time series to calculate the output. A good example is the recognition of the movement type based on the short sequence of position changes over time.

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