Beispiel #1
0
        public void Process(IBitInput input, IBitOutput output)
        {
            if (input.Length != InputCount)
            {
                throw new Exception("Invalid input bit count");
            }

            if (output.Length != OutputCount)
            {
                throw new Exception("Invalid output bit count");
            }

            int outputCount = OutputCount;

            for (int bitPos = 0; bitPos < outputCount; bitPos++)
            {
                INeuron neuron = neurons[bitPos];
                output[bitPos] = neuron.Process(input);
            }

            //Parallel.For(0, outputCount, bitPos =>
            //{
            //    INeuron neuron = neurons[bitPos];
            //    output[bitPos] = neuron.Process(input);
            //});
        }
Beispiel #2
0
        public void Process(IBitInput input, IBitOutput output)
        {
            if (input.Length != InputCount)
            {
                throw new Exception("Invalid input bit count");
            }

            if (output.Length != OutputCount)
            {
                throw new Exception("Invalid output bit count");
            }

            // Add memory bits to input
            if (Memory != null)
            {
                var inputWithMemory = new BitStorage(input.Length + Memory.Length);

                for (int i = 0; i < input.Length; i++)
                {
                    inputWithMemory[i] = input[i];
                }

                for (int i = 0; i < Memory.Length; i++)
                {
                    inputWithMemory[i + input.Length] = Memory[i];
                }

                input = inputWithMemory;
            }

            BitStorage result = null;

            if (compiled != null)
            {
                result = new BitStorage(OutputCount + (Memory != null ? Memory.Length : 0));
                compiled.Invoke(null, new object[] { input, result });
            }
            else
            {
                foreach (ILevel level in Levels)
                {
                    result = new BitStorage(level.OutputCount);
                    level.Process(input, result);
                    input = result;
                }
            }

            if (result.Length == OutputCount)
            {
                output.Load(result);
            }
            else
            {
                output.Load(result.Copy(0, OutputCount));

                // Update memory
                for (int i = 0; i < Memory.Length; i++)
                {
                    Memory[i] = result[OutputCount + i];
                }
            }
        }
Beispiel #3
0
 public void Process(IBitInput input, IBitOutput output)
 {
     output[0] = Process(input);
 }