/// <summary>
        /// Constructs a AcyclicNeuralNet with the provided neural net definition parameters.
        /// </summary>
        /// <param name="digraph">Network structure definition.</param>
        /// <param name="weightArr">Connection weights array.</param>
        /// <param name="activationFn">Node activation function.</param>
        public NeuralNetAcyclic(
            DirectedGraphAcyclic digraph,
            double[] weightArr,
            VecFn <double> activationFn)
        {
            // Store refs to network structure data.
            _srcIdArr     = digraph.ConnectionIdArrays._sourceIdArr;
            _tgtIdArr     = digraph.ConnectionIdArrays._targetIdArr;
            _weightArr    = weightArr;
            _layerInfoArr = digraph.LayerArray;

            // Store network activation function.
            _activationFn = activationFn;

            // Store input/output node counts.
            _inputCount     = digraph.InputCount;
            _outputCount    = digraph.OutputCount;
            _totalNodeCount = digraph.TotalNodeCount;

            // Get a working array for node activation signals.
            _activationArr = ArrayPool <double> .Shared.Rent(_totalNodeCount);

            // Wrap a sub-range of the _activationArr that holds the activation values for the input nodes.
            this.InputVector = new VectorSegment <double>(_activationArr, 0, _inputCount);

            // 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 indirection described by outputNodeIdxArr.
            this.OutputVector = new MappingVector <double>(_activationArr, digraph.OutputNodeIdxArr);
        }
示例#2
0
    /// <summary>
    /// Constructs a AcyclicNeuralNet with the provided neural net definition parameters.
    /// </summary>
    /// <param name="digraph">Network structure definition.</param>
    /// <param name="weightArr">Connection weights array.</param>
    /// <param name="activationFn">Node activation function.</param>
    public NeuralNetAcyclicSafe(
        DirectedGraphAcyclic digraph,
        double[] weightArr,
        VecFn <double> activationFn)
    {
        Debug.Assert(digraph.ConnectionIds.GetSourceIdSpan().Length == weightArr.Length);

        // Store refs to network structure data.
        _connIds      = digraph.ConnectionIds;
        _weightArr    = weightArr;
        _layerInfoArr = digraph.LayerArray;

        // Store network activation function.
        _activationFn = activationFn;

        // Store input/output node counts.
        _inputCount  = digraph.InputCount;
        _outputCount = digraph.OutputCount;

        // Create working array for node activation signals.
        _activationArr = new double[digraph.TotalNodeCount];

        // Map the inputs vector to the corresponding segment of node activation values.
        this.Inputs = new Memory <double>(_activationArr, 0, _inputCount);

        // Get an array to act a as a contiguous run of output signals.
        _outputArr   = new double[_outputCount];
        this.Outputs = _outputArr;

        // Store the indexes into _activationArr that give the output signals.
        _outputNodeIdxArr = digraph.OutputNodeIdxArr;
    }
示例#3
0
    /// <summary>
    /// Constructs a AcyclicNeuralNet with the provided neural net definition parameters.
    /// </summary>
    /// <param name="digraph">Network structure definition.</param>
    /// <param name="weightArr">Connection weights array.</param>
    /// <param name="activationFn">Node activation function.</param>
    public NeuralNetAcyclic(
        DirectedGraphAcyclic digraph,
        double[] weightArr,
        VecFn <double> activationFn)
    {
        Debug.Assert(digraph.ConnectionIds.GetSourceIdSpan().Length == weightArr.Length);

        // Store refs to network structure data.
        _connIds      = digraph.ConnectionIds;
        _weightArr    = weightArr;
        _layerInfoArr = digraph.LayerArray;

        // Store network activation function.
        _activationFn = activationFn;

        // Store input/output node counts.
        _inputCount     = digraph.InputCount;
        _outputCount    = digraph.OutputCount;
        _totalNodeCount = digraph.TotalNodeCount;

        // Get a working array for node activations signals and a separate output signal segment on the end.
        // And map the memory segments onto the array.
        _workingArr = ArrayPool <double> .Shared.Rent(_totalNodeCount + _outputCount);

        _activationMem = _workingArr.AsMemory(0, _totalNodeCount);
        _outputMem     = _workingArr.AsMemory(_totalNodeCount, _outputCount);

        // Map the inputs vector to the corresponding segment of node activation values.
        this.Inputs = _activationMem.Slice(0, _inputCount);

        // Use the already defined outputs memory segment.
        this.Outputs = _outputMem;

        // Store the indexes into _activationArr that give the output signals.
        _outputNodeIdxArr = digraph.OutputNodeIdxArr;
    }
 /// <summary>
 /// Constructs a AcyclicNeuralNet with the provided neural net definition parameters.
 /// </summary>
 /// <param name="digraph">Network structure definition.</param>
 /// <param name="activationFn">Node activation function.</param>
 public NeuralNetAcyclic(
     WeightedDirectedGraphAcyclic <double> digraph,
     VecFn <double> activationFn)
     : this(digraph, digraph.WeightArray, activationFn)
 {
 }