Exemple #1
0
        static void Main(string[] args)
        {
            NN nn = new NN(4, 8, 4);

            float[] inputs = new float[] { 0.1f, 0.2f, 0.3f, 0.4f };
            float[] ar     = nn.FeedForward(inputs);
        }
Exemple #2
0
        public Genome(int size)
        {
            Random rnd = new Random();

            weights = new float[size];
            skills  = new int[skillCount];
            for (int i = 0; i < size; i++)
            {
                weights[i] = NN.NextDoubleRange(rnd, -1f, 1f);
            }
        }
Exemple #3
0
        public void Init(Genome g)
        {
            genome = g;
            //TODO color
            //Color col = new Color(0.1f, 0.1f, 0.25f, 1f);
            float size = 0.75f;

            for (int i = 0; i < Genome.skillCount; i++)
            {
                skillsTotal[g.skills[i]]++;
                if (g.skills[i] == 0)
                {
                    foodSkill++;
                    //col.g += 0.2f;
                }
                else if (g.skills[i] == 1)
                {
                    attackSkill++;
                    // col.r += 0.25f;
                }
                else if (g.skills[i] == 2)
                {
                    defSkill++;
                    //col.b += 0.25f;
                }
                else if (g.skills[i] == 3)
                {
                    size += 0.5f;
                }
            }
            nn = new NN(inputsCount, 8, 4);
            for (int i = 0; i < inputsCount; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    nn.layers[0].weights[i, j] = genome.weights[i + j * inputsCount];
                }
            }
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    nn.layers[1].weights[i, j] = genome.weights[i + j * 8 + inputsCount * 8];
                }
            }
        }
Exemple #4
0
        public void Mutate(float value)
        {
            Random rnd = new Random();

            for (int i = 0; i < weights.Length; i++)
            {
                if (NN.NextDoubleRange(rnd, 0, 1f) < 0.1)
                {
                    weights[i] += NN.NextDoubleRange(rnd, -value, value);
                }
            }
            for (int i = 0; i < skillCount; i++)
            {
                if (NN.NextDoubleRange(rnd, 0, 1f) < 0.05)
                {
                    skills[i] = rnd.Next(0, 4);
                }
            }
        }
Exemple #5
0
        public NN(params int[] sizes)
        {
            Random rnd = new Random();

            layers = new Layer[sizes.Length];
            for (int i = 0; i < sizes.Length; i++)
            {
                int nextSize = 0;
                if (i < sizes.Length - 1)
                {
                    nextSize = sizes[i + 1];
                }
                layers[i] = new Layer(sizes[i], nextSize);
                for (int j = 0; j < sizes[i]; j++)
                {
                    for (int k = 0; k < nextSize; k++)
                    {
                        layers[i].weights[j, k] = NN.NextDoubleRange(rnd, -1f, 1f);
                    }
                }
            }
        }