/// <summary> /// Construct a FastAcyclicNetwork with provided network definition data structures. /// </summary> /// <param name="nodeActivationFnArr">Array of neuron activation functions.</param> /// <param name="nodeAuxArgsArr">Array of neuron activation function arguments.</param> /// <param name="connectionArr">Array of connections.</param> /// <param name="layerInfoArr">Array of layer information.</param> /// <param name="outputNodeIdxArr">An array that specifies the index of each output neuron within _activationArr. /// This is necessary because the neurons have been sorted by their depth in the network structure and are therefore /// no longer in their original positions. Note however that the bias and input neurons *are* in their original /// positions as they are defined as being at depth zero.</param> /// <param name="nodeCount">Number of nodes in the network.</param> /// <param name="inputNodeCount">Number of input nodes in the network.</param> /// <param name="outputNodeCount">Number of output nodes in the network.</param> /// <param name="boundedOutput">Indicates that the output values at the output nodes should be bounded to the interval [0,1]</param> public FastAcyclicNetwork(IActivationFunction[] nodeActivationFnArr, double[][] nodeAuxArgsArr, FastConnection[] connectionArr, LayerInfo[] layerInfoArr, int[] outputNodeIdxArr, int nodeCount, int inputNodeCount, int outputNodeCount, bool boundedOutput) { // Store refs to network structure data. _nodeActivationFnArr = nodeActivationFnArr; _nodeAuxArgsArr = nodeAuxArgsArr; _connectionArr = connectionArr; _layerInfoArr = layerInfoArr; // Create working array for node activation signals. _activationArr = new double[nodeCount]; // Wrap a sub-range of the _activationArr that holds the activation values for the input nodes. // Offset is 1 to skip bias neuron (The value at index 1 is the first black box input). _inputSignalArrayWrapper = new SignalArray(_activationArr, 1, inputNodeCount); // Wrap the output nodes. Nodes have been sorted by depth within the network therefore the output // nodes can no longer be guaranteed to be in a contiguous segment at a fixed location. As such their // positions are indicated by outputNodeIdxArr, and so we package up this array with the node signal // array to abstract away the level of indirection described by outputNodeIdxArr. if (boundedOutput) { _outputSignalArrayWrapper = new OutputMappingSignalArray(_activationArr, outputNodeIdxArr); } else { _outputSignalArrayWrapper = new MappingSignalArray(_activationArr, outputNodeIdxArr); } // Store counts for use during activation. _inputNodeCount = inputNodeCount; _inputAndBiasNodeCount = inputNodeCount + 1; _outputNodeCount = outputNodeCount; // Initialise the bias neuron's fixed output value. _activationArr[0] = 1.0; }
/// <summary> /// Construct a FastAcyclicNetwork with provided network definition data structures. /// </summary> /// <param name="nodeActivationFnArr">Array of neuron activation functions.</param> /// <param name="nodeAuxArgsArr">Array of neuron activation function arguments.</param> /// <param name="connectionArr">Array of connections.</param> /// <param name="layerInfoArr">Array of layer information.</param> /// <param name="outputNodeIdxArr">An array that specifies the index of each output neuron within _activationArr. /// This is necessary because the neurons have been sorted by their depth in the network structure and are therefore /// no longer in their original positions. Note however that the bias and input neurons *are* in their original /// positions as they are defined as being at depth zero.</param> /// <param name="nodeCount">Number of nodes in the network.</param> /// <param name="inputNodeCount">Number of input nodes in the network.</param> /// <param name="outputNodeCount">Number of output nodes in the network.</param> public FastAcyclicNetwork(IActivationFunction[] nodeActivationFnArr, double[][] nodeAuxArgsArr, FastConnection[] connectionArr, LayerInfo[] layerInfoArr, int[] outputNodeIdxArr, int nodeCount, int inputNodeCount, int outputNodeCount) { // Store refs to network structrue data. _nodeActivationFnArr = nodeActivationFnArr; _nodeAuxArgsArr = nodeAuxArgsArr; _connectionArr = connectionArr; _layerInfoArr = layerInfoArr; // Create working array for node activation signals. _activationArr = new double[nodeCount]; // Wrap a sub-range of the _activationArr that holds the activation values for the input nodes. // Offset is 1 to skip bias neuron (The value at index 1 is the first black box input). _inputSignalArrayWrapper = new SignalArray(_activationArr, 1, inputNodeCount); // Wrap the output nodes. Nodes have been sorted by depth within the network therefore the output // nodes can no longer be guaranteed to be in a contiguous segment at a fixed location. As such their // positions are indicated by outputNodeIdxArr, and so we package up this array with the node signal // array to abstract away the level of indirection described by outputNodeIdxArr. _outputSignalArrayWrapper = new MappingSignalArray(_activationArr, outputNodeIdxArr); // Store counts for use during activation. _inputNodeCount = inputNodeCount; _inputAndBiasNodeCount = inputNodeCount+1; _outputNodeCount = outputNodeCount; // Initialise the bias neuron's fixed output value. _activationArr[0] = 1.0; }