Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Net
- {
- private Layer[] layers;
- public int InputCount { get; }
- public int OutputCount { get; }
- public Net(int inputCount, params Layer[] layers)
- {
- InputCount = inputCount;
- int prevCount = inputCount;
- this.layers = layers;
- foreach (var layer in layers)
- {
- layer.Init(prevCount);
- prevCount = layer.NeuronCount;
- }
- OutputCount = prevCount;
- Random rnd = new Random();
- foreach (var layer in layers)
- {
- for (int i = 0; i < layer.NeuronCount; i++)
- {
- for (int j = 0; j < layer.PrevLayerNeuronCount; j++)
- {
- layer.Weights[i, j] = rnd.NextDouble();
- }
- }
- }
- }
- public double[] Forward(double[] input)
- {
- if (input.Length != InputCount)
- throw new ArgumentException("неверное кол-во входных параметров", nameof(input));
- double[] output = input;
- foreach (var layer in layers)
- {
- output = layer.Forward(output);
- }
- return output;
- }
- public double[] Backward(double[] output)
- {
- if (output.Length != OutputCount)
- throw new ArgumentException("неверное кол-во входных параметров", nameof(output));
- double[] input = output;
- foreach (var layer in layers.Reverse())
- {
- input = layer.Forward(input);
- }
- return input;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement