Exemplo n.º 1
0
        public FullyConnectedLayer(int neurons, Layer previousLayer, ActivationFunctions.ActivationFunction activation)
            : base(neurons, 1, 1, previousLayer)
        {
            Activation = activation;

            this.weights = new float[Neurons * PreviousLayer.Neurons];
            this.biases  = new float[Neurons];
        }
Exemplo n.º 2
0
        public ConvolutionalLayer(int filterCount, int filterSize, int stride, int zeroPadding, Layer previousLayer, ActivationFunctions.ActivationFunction activation)
            : base(CalculateWidth(filterSize, stride, zeroPadding, previousLayer), CalculateHeight(filterSize, stride, zeroPadding, previousLayer), filterCount, previousLayer)
        {
            Activation = activation;

            FilterSize  = filterSize;
            Stride      = stride;
            ZeroPadding = zeroPadding;

            this.weights = new float[filterCount * filterSize * filterSize * previousLayer.Depth];
            this.biases  = new float[filterCount];
        }
Exemplo n.º 3
0
        private static NeuralNetwork InitializeNeuralNetwork(int seed, ActivationFunctions.ActivationFunction activationFunction)
        {
            Random random = new Random(seed == 0 ? new Random().Next() : seed);

            float RandomWeight() => (float)(random.NextDouble() * 2 - 1);

            InputLayer l0 = new InputLayer(2);

            FullyConnectedLayer l1 = new FullyConnectedLayer(2, l0, activationFunction);

            for (int i = 0; i < l1.Weights; i++)
            {
                l1.SetWeight(i, RandomWeight() * 0.25f);
            }

            FullyConnectedLayer l2 = new FullyConnectedLayer(1, l1, activationFunction);

            for (int i = 0; i < l2.Weights; i++)
            {
                l2.SetWeight(i, RandomWeight() * 0.25f);
            }
            return(new NeuralNetwork(l0, l1, l2));
        }
Exemplo n.º 4
0
 public Dense(int units, ActivationFunctions.ActivationFunction actFunction)
 {
     activationFunction = actFunction;
     outputShape        = new int[] { units, 1 };
 }