Пример #1
0
 /// <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>
 /// <param name="boundedOutput">Indicates that the output values at the output nodes should be bounded to the interval [0,1]</param>
 public AcyclicNeuralNet(
     WeightedAcyclicDirectedGraph <double> digraph,
     VecFnSegment <double> activationFn,
     bool boundedOutput)
     : this(digraph, digraph.WeightArray, activationFn, boundedOutput)
 {
 }
Пример #2
0
        /// <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>
        /// <param name="boundedOutput">Indicates that the output values at the output nodes should be bounded to the interval [0,1]</param>
        public AcyclicNeuralNet(
            WeightedAcyclicDirectedGraph <double> digraph,
            VecFnSegment <double> activationFn,
            bool boundedOutput)
        {
            // Store refs to network structure data.
            _srcIdArr            = digraph.ConnectionIdArrays._sourceIdArr;
            _tgtIdArr            = digraph.ConnectionIdArrays._targetIdArr;
            _weightArr           = digraph.WeightArray;
            _connectionOutputArr = new double[_srcIdArr.Length];

            _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];

            // Wrap a sub-range of the _activationArr that holds the activation values for the input nodes.
            _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.
            var outputVec = new MappingVector <double>(_activationArr, digraph.OutputNodeIdxArr);

            if (boundedOutput)
            {
                _outputVector = new BoundedVector(outputVec);
            }
            else
            {
                _outputVector = outputVec;
            }
        }
 /// <summary>
 /// Write an acyclic directed graph to a stream writer.
 /// </summary>
 /// <param name="digraph">The directed graph to save.</param>
 /// <param name="activationFnName">The single activation function to save with the graph.</param>
 /// <param name="sw">The stream writer to write to.</param>
 public static void Write(WeightedAcyclicDirectedGraph <double> digraph, string activationFnName, StreamWriter sw)
 {
     WriteActivationFunctionsSection(activationFnName, sw);
     WriteNodesSection(digraph, sw);
     WriteConnectionsSection(digraph.ConnectionArray, digraph.WeightArray, sw);
 }
 /// <summary>
 /// Write an acyclic directed graph to a stream.
 /// </summary>
 /// <param name="digraph">The directed graph to save.</param>
 /// <param name="activationFnName">The single activation function to save with the graph.</param>
 /// <param name="strm">The stream to write to.</param>
 public static void Write(WeightedAcyclicDirectedGraph <double> digraph, string activationFnName, Stream strm)
 {
     using (StreamWriter sw = new StreamWriter(strm)) {
         Write(digraph, activationFnName, sw);
     }
 }
 /// <summary>
 /// Save an acyclic directed graph to a file.
 /// </summary>
 /// <param name="digraph">The directed graph to save.</param>
 /// <param name="activationFnName">The single activation function to save with the graph.</param>
 /// <param name="path">The file path to save to.</param>
 public static void Save(WeightedAcyclicDirectedGraph <double> digraph, string activationFnName, string path)
 {
     using (var sw = new StreamWriter(path)) {
         Write(digraph, activationFnName, sw);
     }
 }