public NetworkState(RecurrentNetwork network, NetworkState last) { this.Network = network; states = new List <object>(); double[] input = new double[network.Layers[0].InputSize]; this.Input = input; double[] output = null; for (int i = 0; i < network.Layers.Count; i++) { Layer layer = network.Layers[i]; output = new double[layer.Size]; if (layer is RecurrentLayer) { RecurrentState lastState = last != null ? (RecurrentState)last.states[i] : null; states.Add(new RecurrentState(input, output, lastState)); } else { states.Add(new FeedForwardState(input, output)); } // The input of the next layer is the output of the last. input = output; } this.Output = output; }
public void FeedForward(RecurrentState state) { double[] weightedSums = state.WeightedSums; Array.Clear(weightedSums, 0, weightedSums.Length); Sum(biasWeights, weightedSums); WeightedInputSum(state.Inputs, inputWeights, weightedSums); WeightedInputSum(state.LastOutputs, internalWeights, weightedSums); OutputFromActivation(weightedSums, state.Outputs); }
public RecurrentState(double[] inputs, double[] outputs, RecurrentState lastState) { Inputs = inputs; Outputs = outputs; if (lastState != null) { LastOutputs = lastState.Outputs; } else { LastOutputs = null;// new double[outputs.Length]; } WeightedSums = new double[outputs.Length]; }
public void FeedForward() { for (int i = 0; i < states.Count; i++) { Layer layer = Network.Layers[i]; if (layer is RecurrentLayer) { RecurrentState state = (RecurrentState)states[i]; ((RecurrentLayer)layer).FeedForward(state); } else { FeedForwardState state = (FeedForwardState)states[i]; ((FeedForwardLayer)layer).FeedForward(state); } } }