All Bundles
NeuralNetwork
Simple neural network. Input values should be scaled to between 0.0 to 1.0. The tuned network should return outputs between 0.0 to 1.0.
Operations
Code example:
network : NeuralNetwork;
filename := "data/model.dat";
inputs_targets := MatrixReader->LoadSplitMatrices(args[0], 1, 0.8); # 20% test data
# load model
if(args->Size() = 2) {
network := NeuralNetwork->Load(filename);
"Loaded model..."->PrintLine();
"Testing model..."->PrintLine();
tests := inputs_targets[2];
answers := inputs_targets[3];
failures := 0;
each(i : answers) {
answer := answers->Get(i)->ToBool();
predict := network->Query(FloatMatrixRef->New(tests->Get(i)->Get()));
if(predict <> answer) {
failures += 1;
};
};
correct := 100.0 * (1.0 - failures->As(Float) / tests->Size()->As(Float));
System.IO.Standard->Print("Tests: ")->Print(tests->Size())->Print(", correct: ")->SetFloatPrecision(5)->Print(correct)->PrintLine("%");
}
# train and store model
else if(args->Size() = 1) {
"Training model..."->PrintLine();
network := NeuralNetwork->Train(2, inputs_targets[0], 8, 1, inputs_targets[1], 0.01725, 256);
if(inputs_targets <> Nil) {
network->Store(filename);
"Stored model..."->PrintLine();
};
}
Confidence
Query the network's confidence for the give inputs
method : public : Confidence(inputs:FloatMatrixRef) ~ Float
Parameters
Return
Type | Description |
---|
Float | confidence percentage |
Load
Loads network inputs and outputs
function : Load(filename:String) ~ NeuralNetwork
Parameters
Name | Type | Description |
---|
filename | String | file to store to |
Return
Query
Query the network
method : public : Query(inputs:FloatMatrixRef) ~ Bool
Parameters
Return
Type | Description |
---|
Bool | true if activated, false otherwise |
SetActivation
Sets the activation threshold. Activation if output > threshold or < 1.0 - threshold
method : public : SetActivation(threshold:Float, attempts:Int) ~ Nil
Parameters
Name | Type | Description |
---|
threshold | Float | activation threshold default is 0.85 |
attempts | Int | number of activation attempts |
Store
Saves final network inputs and outputs
method : public : Store(filename:String) ~ Bool
Parameters
Name | Type | Description |
---|
filename | String | file to store to |
Return
Type | Description |
---|
Bool | true if successful, false otherwise |
Train
Trains the network
function : Train(input_nodes:Int, inputs:Vector<FloatMatrixRef>, hidden_factor:Int, output_nodes:Int, targets:Vector<FloatMatrixRef>, learning_rate:Float, iterations:Int) ~ NeuralNetwork
Parameters
Name | Type | Description |
---|
input_nodes | Int | number of input nodes |
inputs | Vector<FloatMatrixRef> | : training inputs |
hidden_factor | Int | size of hidden layer, factor of input (i.e. input_nodes * hidden_factor) |
output_nodes | Int | training outputs |
targets | Vector<FloatMatrixRef> | training targets |
learning_rate | Float | learning rate |
iterations | Int | number of training iterations |