private void SaveWeightsBiasAndAgeInPocket(NeuralVector winner, Vector <double> weights, double bias, int age) { _pocket.Winner = winner; _pocket.Weights = weights; _pocket.Bias = bias; _pocket.Age = age; }
private void ValidateVectorLength(NeuralVector vector) { if (vector.Data.Count != _numberOfNeurons) { throw new InvalidOperationException("Weights or biases dont exist, first teach the network."); } }
private bool CalculationsAreCompatibile(double calculationResult, NeuralVector perceptronVector) { if (calculationResult >= 0 && perceptronVector.Class == 1) { return(true); } return(calculationResult < 0 && perceptronVector.Class == -1); }
public NeuralVector Test(NeuralVector testingVector) { ValidateVectorLength(testingVector); ValidateWeightsAndBiases(); InitializeOutputs(testingVector.Data); var outputVector = CalculateAllOuputs(); return(new NeuralVector(outputVector)); }
private void FillPatternByOutput(NeuralVector outputVector) { var checkBoxes = GetPatternCheckBoxes(); checkBoxes.ForEach(checkBox => checkBox.CheckedChanged -= chBox_CheckedChanged); for (int index = 0; index < checkBoxes.Count; index++) { if (outputVector.Data[index] == 1.0) { checkBoxes[index].CheckState = CheckState.Indeterminate; } else { checkBoxes[index].CheckState = CheckState.Unchecked; } } checkBoxes.ForEach(checkBox => checkBox.CheckedChanged += chBox_CheckedChanged); }
public static Pattern MapToPattern(NeuralVector vector, int lineCount, int columnCount) { var pattern = new Pattern { Lines = new Line[lineCount] }; for (int l = 0; l < lineCount; l++) { pattern.Lines[l] = new Line { Columns = new double[columnCount] }; for (int c = 0; c < columnCount; c++) { pattern.Lines[l].Columns[c] = vector.Data[l * columnCount + c]; } } return(pattern); }
private double CalculatePerceptronFunction(NeuralVector perceptronVector, Vector <double> weights, double bias) { return(perceptronVector.Data * weights + bias); }
private bool ClassIsCorrectlyClassified(NeuralVector perceptronVector, int classifiedClass) { return(perceptronVector.Class == classifiedClass); }
private void AdjustBias(ref double bias, NeuralVector perceptronVector) { bias += perceptronVector.Class; }
private void AdjustWeights(ref Vector <double> weights, NeuralVector perceptronVector, double learningRate) { weights += learningRate * perceptronVector.Class * perceptronVector.Data; }