public PreceptorLayer(int numOfPreceptors, int prevLayerNumOfPreceptors, Neuron.NormalizedMethod method) { this.numOfPreceptors = numOfPreceptors; preceptors = new Neuron[numOfPreceptors]; for (int i = 0; i < numOfPreceptors; i++) { preceptors[i] = new Neuron(prevLayerNumOfPreceptors, method); } }
public NeuralNetwork(int numOfInputs, int numOfOutputs, int[] numOfHiddens) : base() { this.numOfHiddens = numOfHiddens; this.numOfInputs = numOfInputs; this.numOfOutputs = numOfOutputs; numOfLayers = this.numOfHiddens.Length + 1; layers = new PreceptorLayer[numOfLayers]; int prevNumOfPreceptors = this.numOfInputs; for (int i = 0; i < numOfLayers; i++) { int numOfPreceptors = i < (numOfLayers - 1) ? this.numOfHiddens[i] : this.numOfOutputs; Neuron.NormalizedMethod method = i == (numOfLayers - 1) ? Neuron.NormalizedMethod.SigmoidZeroTo1 : Neuron.NormalizedMethod.HyperTan; layers[i] = new PreceptorLayer(numOfPreceptors, prevNumOfPreceptors, method); numOfFeatures += numOfPreceptors; numOfConnections += prevNumOfPreceptors * numOfPreceptors; prevNumOfPreceptors = numOfPreceptors; } int idx = 0; featureIndex = new FeatureIndex[numOfFeatures]; for (int i = 0; i < numOfLayers; i++) { for (int j = 0; j < layers[i].numOfPreceptors; j++) { featureIndex[idx] = new FeatureIndex(i, j); idx += 1; } } idx = 0; connectionIndex = new ConnectionIndex[numOfConnections]; for (int i = 0; i < numOfLayers; i++) { for (int j = 0; j < layers[i].numOfPreceptors; j++) { for (int w = 0; w < layers[i].preceptors[j].GetNumWeights(); w++) { connectionIndex[idx] = new ConnectionIndex(i, j, w); idx += 1; } } } }