예제 #1
0
 private void SaveWeightsBiasAndAgeInPocket(NeuralVector winner, Vector <double> weights, double bias, int age)
 {
     _pocket.Winner  = winner;
     _pocket.Weights = weights;
     _pocket.Bias    = bias;
     _pocket.Age     = age;
 }
예제 #2
0
 private void ValidateVectorLength(NeuralVector vector)
 {
     if (vector.Data.Count != _numberOfNeurons)
     {
         throw new InvalidOperationException("Weights or biases dont exist, first teach the network.");
     }
 }
예제 #3
0
        private bool CalculationsAreCompatibile(double calculationResult, NeuralVector perceptronVector)
        {
            if (calculationResult >= 0 && perceptronVector.Class == 1)
            {
                return(true);
            }

            return(calculationResult < 0 && perceptronVector.Class == -1);
        }
예제 #4
0
        public NeuralVector Test(NeuralVector testingVector)
        {
            ValidateVectorLength(testingVector);
            ValidateWeightsAndBiases();

            InitializeOutputs(testingVector.Data);

            var outputVector = CalculateAllOuputs();

            return(new NeuralVector(outputVector));
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
 private double CalculatePerceptronFunction(NeuralVector perceptronVector, Vector <double> weights, double bias)
 {
     return(perceptronVector.Data * weights + bias);
 }
예제 #8
0
 private bool ClassIsCorrectlyClassified(NeuralVector perceptronVector, int classifiedClass)
 {
     return(perceptronVector.Class == classifiedClass);
 }
예제 #9
0
 private void AdjustBias(ref double bias, NeuralVector perceptronVector)
 {
     bias += perceptronVector.Class;
 }
예제 #10
0
 private void AdjustWeights(ref Vector <double> weights, NeuralVector perceptronVector, double learningRate)
 {
     weights += learningRate * perceptronVector.Class * perceptronVector.Data;
 }