예제 #1
0
        // method to shuffle data during training
        void ShuffleData()
        {
            int numShuffles = Inputs.Count();
            int inputCount  = Inputs[0].GetLength(0);
            int outputCount = Outputs[0].GetLength(0);
            int index1;
            int index2;

            double[] tempInput;
            double[] tempOutput;

            for (int i = 0; i < numShuffles; i++)
            {
                tempInput  = new double[inputCount];
                tempOutput = new double[outputCount];
                index1     = Prob.Next(numShuffles);
                index2     = Prob.Next(numShuffles);

                for (int j = 0; j < inputCount; j++)
                {
                    tempInput[j] = trainingInputs[index1][j];
                    trainingInputs[index1][j] = trainingInputs[index2][j];
                    trainingInputs[index2][j] = tempInput[j];
                }
                for (int j = 0; j < outputCount; j++)
                {
                    tempOutput[j] = trainingOutputs[index1][j];
                    trainingOutputs[index1][j] = trainingOutputs[index2][j];
                    trainingOutputs[index2][j] = tempOutput[j];
                }
            }
        }
예제 #2
0
        // method to mutate one weight matrix
        double[,] MutateOneMatrix(double[,] matrix, int numMutations)
        {
            // find dimensions of matrix
            int dim1 = matrix.GetLength(0);
            int dim2 = matrix.GetLength(1);

            // create and populate copied weight matrix
            double[,] output = new double[dim1, dim2];
            for (int i = 0; i < dim1; i++)
            {
                for (int j = 0; j < dim2; j++)
                {
                    output[i, j] = matrix[i, j];
                }
            }

            // for each mutation, randomly select one value and mutate it
            int tempDim1;
            int tempDim2;

            for (int i = 0; i < numMutations; i++)
            {
                tempDim1 = Prob.Next(dim1);
                tempDim2 = Prob.Next(dim2);
                output[tempDim1, tempDim2] += Prob.Gaussian(MutateSTD, 0.0);
            }

            // return mutated matrix
            return(output);
        }