public static void copyInto(StatePredictor original, StatePredictor destination)
 {
     original.table.CopyTo(destination.table, 0);
     destination.iterationCount  = original.iterationCount;
     destination.state           = original.state;
     destination.stateSize       = original.stateSize;
     destination.inputSymbolSize = original.inputSymbolSize;
     destination.tableStride     = original.tableStride;
     destination.trainingDepth   = original.trainingDepth;
     original.stateMetrics.CopyTo(destination.stateMetrics, 0);
 }
Beispiel #2
0
        public Couppy(int[] layerStateSizes, int[] layerOutputSizes, Translator translator)
        {
            int layerCount = layerStateSizes.Length;

            this.layerStateSizes = layerStateSizes;

            if (layerOutputSizes.Length != layerCount)
            {
                throw new Exception("Invalid Couppy parameters, layer definitions must have same size.");
            }
            this.layerOutputSizes = layerOutputSizes;

            this.translator = translator;
            int symbolSize = translator.getSymbolCount();

            if (symbolSize != layerOutputSizes[layerCount - 1])
            {
                throw new Exception("Invalid Couppy parameters, final layer output doesn't match translator symbol count.");
            }

            if (symbolSize > 256)
            {
                throw new NotImplementedException("Invalid symbol size, must be between 1 and 256");
            }

            for (int i = 0; i < layerStateSizes.Length - 1; i++)
            {
                if (layerStateSizes[i] > 256)
                {
                    throw new NotImplementedException("Invalid state size, must be between 1 and 256");
                }
            }

            if (layerStateSizes[layerStateSizes.Length - 1] > ushort.MaxValue)
            {
                throw new NotImplementedException("Invalid state size, must be between 1 and 256");
            }

            if (layerCount == 1)
            {
                outputLayer = new RestrictedStatePredictor(symbolSize, symbolSize, layerStateSizes[layerStateSizes.Length - 1]);
            }
            else
            {
                deepLayers    = new StatePredictor[layerStateSizes.Length - 1];
                deepLayers[0] = new StatePredictor(symbolSize, layerOutputSizes[0], layerStateSizes[0]);
                for (int i = 1; i < layerStateSizes.Length - 1; i++)
                {
                    deepLayers[i] = new StatePredictor(layerOutputSizes[i - 1], layerOutputSizes[i], layerStateSizes[i]);
                }
                outputLayer = new RestrictedStatePredictor(layerOutputSizes[layerOutputSizes.Length - 2], layerOutputSizes[layerOutputSizes.Length - 1], layerStateSizes[layerStateSizes.Length - 1]);
            }
        }
Beispiel #3
0
        /*
         * public void printCascade()
         * {
         *  Console.WriteLine("Printing cascade");
         *
         *  int topLayer;
         *  int states;
         *  if (deepLayers != null)
         *  {
         *      topLayer = deepLayers.Length;
         *      states = outputLayer.stateSize;
         *
         *      //Set maximum states to all possible combinations between layers
         *      for (int k = 0; k < deepLayers.Length; k++)
         *          states *= deepLayers[k].stateSize;
         *  }
         *  else
         *  {
         *      topLayer = 0;
         *      states = outputLayer.stateSize;
         *  }
         *
         *  byte single;
         *  byte feed;
         *  int iState;
         *  for (int i = 0; i < states; i++)
         *  {
         *      List<byte> output = new List<byte>();
         *
         *      //Set Cascading States
         *      outputLayer.state = (ushort)(i % outputLayer.stateSize);
         *      iState = i / outputLayer.stateSize;
         *      if (deepLayers != null)
         *      {
         *          for (int k = 0; k < deepLayers.Length; k++)
         *          {
         *              deepLayers[k].state = (byte)(iState % deepLayers[k].stateSize);
         *              iState = iState / deepLayers[k].stateSize;
         *          }
         *      }
         *
         *
         *      if (deepLayers != null)
         *      {
         *          feed = deepLayers[deepLayers.Length - 1].state; //Use last state on last layer
         *          for (int k = deepLayers.Length - 1; k >= 0; k--)
         *          {
         *              deepLayers[k].state = feed;
         *              if (k != 0)
         *                  feed = deepLayers[k].predict(deepLayers[k - 1].state);
         *              else
         *                  feed = deepLayers[k].predict(outputLayer.state);
         *          }
         *      }
         *      else
         *          feed = outputLayer.state;
         *
         *      outputLayer.state = feed;
         *      single = outputLayer.process(0);
         *
         *      if (single == 0)
         *          continue;
         *
         *      output.Add(single);
         *
         *      for (int j = 1; j < 128; j++)
         *      {
         *          if (deepLayers != null)
         *          {
         *              feed = deepLayers[deepLayers.Length - 1].state; //Use last state on last layer
         *              for (int k = deepLayers.Length - 1; k >= 0; k--)
         *              {
         *                  deepLayers[k].state = feed;
         *                  if (k != 0)
         *                      feed = deepLayers[k].predict(deepLayers[k - 1].state);
         *                  else
         *                      feed = deepLayers[k].predict(outputLayer.state);
         *              }
         *          }
         *          else
         *              feed = outputLayer.state;
         *
         *          outputLayer.state = feed;
         *          single = outputLayer.process(output[j - 1]);
         *
         *          //Break if AI prints voidChar
         *          if (single == 0)
         *              break;
         *
         *          output.Add(single);
         *      }
         *
         *
         *      string stateString = "";
         *      iState = i;
         *      stateString += iState % outputLayer.stateSize;
         *      iState = i / outputLayer.stateSize;
         *      if (deepLayers != null)
         *      {
         *          for (int k = 0; k < deepLayers.Length; k++)
         *          {
         *              stateString = iState % deepLayers[k].stateSize + " , " + stateString;
         *              iState = iState / deepLayers[k].stateSize;
         *          }
         *      }
         *      Console.WriteLine(stateString + " : " + translator.symbolToText(output.ToArray()));
         *  }
         * }
         */
        public static void copyInto(Couppy original, Couppy destination)
        {
            RestrictedStatePredictor.copyInto(original.outputLayer, destination.outputLayer);
            if (original.deepLayers != null)
            {
                for (int i = 0; i < original.deepLayers.Length; i++)
                {
                    StatePredictor.copyInto(original.deepLayers[i], destination.deepLayers[i]);
                }
            }
            else
            {
                destination.deepLayers = null;
            }

            original.layerStateSizes.CopyTo(destination.layerStateSizes, 0);
            original.layerOutputSizes.CopyTo(destination.layerOutputSizes, 0);
            destination.name          = original.name;
            destination.trainingDepth = original.trainingDepth;
            destination.translator    = original.translator;
        }