Example #1
0
            public Trainer(Couppy target)
            {
                this.target = target;
                checkLock   = new object();
                threads     = new List <Thread>();
                readLocks   = new List <object>();
                trainLocks  = new List <object>();
                chatBots    = new List <Couppy>();

                dnaLength = target.getDnaLength();
                int steps;

                for (steps = 0; Math.Pow(2, steps) < dnaLength; steps++)
                {
                    ;
                }
                steps++; //include last and first
                trainIntensity             = new int[steps];
                trainSampleCount           = new int[steps];
                trainAccumulatedAccuracies = new double[steps];
                for (int i = 0; i < steps; i++)
                {
                    if (i != steps - 1)
                    {
                        trainIntensity[i] = (int)Math.Pow(2, i);
                    }
                    else
                    {
                        trainIntensity[i] = dnaLength;
                    }
                }
            }
Example #2
0
        public static void leapOverride(Couppy original, Couppy destination, Random rdm, int intensity)
        {
            //Copy original to destination
            Couppy.copyInto(original, destination);
            destination.outputLayer.reset();

            destination.trainingDepth             = original.trainingDepth + 1;
            destination.outputLayer.trainingDepth = original.trainingDepth + 1;
            if (original.deepLayers != null)
            {
                for (int i = 0; i < destination.deepLayers.Length; i++)
                {
                    destination.deepLayers[i].reset();
                    destination.deepLayers[i].trainingDepth = original.deepLayers[i].trainingDepth + 1;
                }
            }

            int changeCount = intensity;

            //Make changes
            int            layer;
            int            index;
            StatePredictor layerPredictor;
            int            dnaLength = original.getDnaLength();

            for (int i = 0; i < changeCount; i++)
            {
                index = rdm.Next(dnaLength);

                layer = -1;
                if (index < original.outputLayer.stateTransitionTable.Length)
                {
                    layer = destination.layerStateSizes.Length - 1;
                }
                else
                {
                    index -= original.outputLayer.stateTransitionTable.Length;
                    for (int k = 0; k < original.deepLayers.Length; k++)
                    {
                        if (index < original.deepLayers[k].table.Length)
                        {
                            layer = k;
                            break;
                        }
                        else
                        {
                            index -= original.deepLayers[k].table.Length;
                        }
                    }
                }

                if (layer == destination.layerStateSizes.Length - 1)
                {
                    destination.outputLayer.stateTransitionTable[index] = (ushort)rdm.Next(destination.outputLayer.stateSize); //New random state at index
                }
                else
                {
                    //Choose random table index for change
                    layerPredictor = destination.deepLayers[layer];

                    //Check if index is output or state
                    if (index % 2 == 0)
                    {
                        layerPredictor.table[index] = (byte)rdm.Next(layerPredictor.outputSymbolSize); //New random output at index
                    }
                    else
                    {
                        layerPredictor.table[index] = (byte)rdm.Next(layerPredictor.stateSize); //New random state at index
                    }
                }
            }
        }