Пример #1
0
        //Constructor, creates a new Topology based on the types of the Nodes
        public Topology(List <int> points, List <int> memoryDepths)
        {
            adj_M = new TopologyEntry[points.Count];

            for (int i = 0; i < points.Count; i++)
            {                                                                                                           //set the type of all the "rows" according to the parameter
                adj_M[i]       = new TopologyEntry();
                adj_M[i].adj_V = new float[points.Count];
                adj_M[i].layer = points[i];
                if (i < memoryDepths.Count)
                {
                    adj_M[i].memoryDepth = memoryDepths[i];
                }
                else
                {
                    adj_M[i].memoryDepth = 0;
                }
                if (adj_M[i].layer > layerCount)
                {
                    layerCount = adj_M[i].layer;
                }
            }
            layerCount++;
            verify();                                                                                           //verify the shit out of it
        }
Пример #2
0
        public object Clone()
        {
            TopologyEntry ret = new TopologyEntry();

            ret.layer       = layer;
            ret.adj_V       = new float[adj_V.Length];
            ret.memoryDepth = memoryDepth;
            for (int i = 0; i < adj_V.Length; i++)
            {
                ret.adj_V[i] = adj_V[i];
            }
            return(ret);
        }
Пример #3
0
        //Returns the CrossOver of two Topology-s
        public Topology crossOver(Topology otherParent, CrossOverInfo info)
        {
            List <int> points       = new List <int>();
            List <int> memoryDepths = new List <int>();

            foreach (TopologyEntry entry in adj_M)
            {
                points.Add(entry.layer);
                memoryDepths.Add(entry.memoryDepth);
            }
            Topology ret = new Topology(points, memoryDepths);

            for (int i = 0; i < ret.Count; i++)
            {
                TopologyEntry pEntry1 = adj_M[i], pEntry2 = otherParent.adj_M[i];
                bool          batchChoice = info.Rnd > info.crossOverRatio;
                for (int j = 0; j < pEntry1.adj_V.Length; j++)
                {
                    if (float.IsNaN(pEntry1.adj_V[j]) || float.IsNaN(pEntry2.adj_V[j]))
                    {
                        ret.adj_M[i].adj_V[j] = float.NaN;
                    }
                    else
                    {
                        float temp;
                        switch (info.type)
                        {
                        case CrossoverType.AVERAGING:
                            temp = pEntry1.adj_V[j] * info.crossOverRatio + pEntry2.adj_V[j] * (1 - info.crossOverRatio);
                            break;

                        case CrossoverType.SWAPPING:
                            if (info.Rnd > info.crossOverRatio)
                            {
                                temp = pEntry2.adj_V[j];
                            }
                            else
                            {
                                temp = pEntry1.adj_V[j];
                            }
                            break;

                        case CrossoverType.BATCH_SWAPPING:
                            if (batchChoice)
                            {
                                temp = pEntry2.adj_V[j];
                            }
                            else
                            {
                                temp = pEntry1.adj_V[j];
                            }
                            break;

                        default:
                            return(null);
                        }
                        float mutation;
                        if (info.Rnd > info.mutationChance)
                        {
                            mutation = (info.Rnd - 0.5f) * info.mutationStrength * 2f;
                        }
                        else
                        {
                            mutation = 0;
                        }
                        temp = temp + mutation;
                        ret.adj_M[i].adj_V[j] = temp;
                    }
                }
            }
            return(ret);
        }