Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        // method to create a randomly initialized weight matrix
        double[,] CreateRandomMatrix(int dim1, int dim2)
        {
            // initialize matrix with input dimensions
            double[,] output = new double[dim1, dim2];

            // populate output with random elements
            for (int i = 0; i < dim1; i++)
            {
                for (int j = 0; j < dim2; j++)
                {
                    output[i, j] = Prob.Gaussian(WeightInitSTD, 0.0);
                }
            }
            return(output);
        }