Exemplo n.º 1
0
        public override object Clone()
        {
            EvoNet copy = new EvoNet(layers);

            copy.Build();
            for (int i = 0; i < weights.Length; i++)
            {
                copy.weights[i].SetSubMatrix(0, 0, weights[i]);
                copy.b_weights[i].SetSubMatrix(0, 0, b_weights[i]);
            }
            return(copy);
        }
Exemplo n.º 2
0
        public (IGenotype, IGenotype) Crossover(IGenotype partner, XOptions options = default)
        {
            if (!Equals(partner))
            {
                throw new ArgumentException();
            }

            EvoNet offspringX = new EvoNet(layers);
            EvoNet offspringY = new EvoNet(layers);

            offspringX.Build();
            offspringY.Build();

            (float[] offspringX, float[] offspringY)offsprings = (new float[0], new float[0]);
            switch (options.xType)
            {
            case XType.OnePointX:
                offsprings = Reproduction.OnePointX(ToRowMajorArray(), ((EvoNet)partner).ToRowMajorArray());
                break;

            case XType.KPointX:
                offsprings = Reproduction.KPointX(ToRowMajorArray(), ((EvoNet)partner).ToRowMajorArray(), options.kPoints);
                break;
            }

            int gene = 0;

            for (int w = 0; w < weights.Length; w++)
            {
                for (int y = 0; y < weights[w].RowCount; y++)
                {
                    for (int x = 0; x < weights[w].ColumnCount; x++)
                    {
                        offspringX.weights[w][y, x] = offsprings.offspringX[gene];
                        offspringY.weights[w][y, x] = offsprings.offspringY[gene];
                        gene++;
                    }
                }
                for (int x = 0; x < b_weights[w].ColumnCount; x++)
                {
                    offspringX.b_weights[w][0, x] = offsprings.offspringX[gene];
                    offspringY.b_weights[w][0, x] = offsprings.offspringY[gene];
                    gene++;
                }
            }

            return(offspringX, offspringY);
        }
Exemplo n.º 3
0
        public override bool Equals(object obj)
        {
            EvoNet other = obj as EvoNet;

            if (other == null ||
                layers.Count != other.layers.Count)
            {
                return(false);
            }
            for (int i = 0; i < layers.Count; i++)
            {
                if (layers[i].neuronCount != other.layers[i].neuronCount)
                {
                    return(false);
                }
            }
            return(true);
        }