public void SimpleMapping()
    {
        int[] innerArr   = Enumerable.Range(0, 10).ToArray();
        int[] map        = new int[] { 5, 3, 8, 0, 9 };
        var   mappingVec = new MappingVector <int>(innerArr, map);

        int[] expectedArr = new int[] { 5, 3, 8, 0, 9 };
        ConponentwiseEqual(expectedArr, mappingVec);
    }
    public void CopyToTest3()
    {
        int[] innerArr   = Enumerable.Range(0, 10).ToArray();
        int[] map        = new int[] { 5, 3, 8, 0, 9 };
        var   mappingVec = new MappingVector <int>(innerArr, map);

        int[] tgtArr = new int[12];
        mappingVec.CopyTo(tgtArr, 2, 1, 2);

        // Test the segment yields the expected values.
        int[] expectedArr = new int[] { 0, 0, 3, 8, 0, 0, 0, 0, 0, 0, 0, 0 };
        Assert.Equal(expectedArr, tgtArr);
    }
    public void CopyFromTest4()
    {
        int[] innerArr   = Enumerable.Range(0, 10).ToArray();
        int[] map        = new int[] { 5, 3, 8, 0, 9 };
        var   mappingVec = new MappingVector <int>(innerArr, map);

        int[] srcArr = Enumerable.Range(100, 10).ToArray();
        mappingVec.CopyFrom(srcArr, 5, 1, 2);

        // Test the segment yields the expected values.
        int[] expectedInnerArr = new int[] { 0, 1, 2, 105, 4, 5, 6, 7, 106, 9 };
        Assert.Equal(expectedInnerArr, innerArr);
    }
Exemple #4
0
        public void CopyFromTest2()
        {
            int[] innerArr   = Enumerable.Range(0, 10).ToArray();
            int[] map        = new int[] { 5, 3, 8, 0, 9 };
            var   mappingVec = new MappingVector <int>(innerArr, map);

            int[] srcArr = Enumerable.Range(100, 3).ToArray();
            mappingVec.CopyFrom(srcArr, 1);

            // Test the segment yields the expected values.
            int[] expectedInnerArr = new int[] { 102, 1, 2, 100, 4, 5, 6, 7, 101, 9 };
            Compare(expectedInnerArr, innerArr);
        }
    public void CopyFromTest_InvalidCopyOperations()
    {
        int[] innerArr   = Enumerable.Range(0, 10).ToArray();
        int[] map        = new int[] { 5, 3, 8, 0 };
        var   mappingVec = new MappingVector <int>(innerArr, map);

        int[] srcArr = Enumerable.Range(100, 3).ToArray();

        //--- Two param tests.
        // Copy beyond end of vecSeg.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 2));

        // Invalid target index.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, -1));

        //--- Three param tests.

        // Copy length longer than srcArr.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, 4));

        // Invalid source index.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, -1, 1));

        // Invalid length.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, -1));

        // Copy beyond the end of vecSeg.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 2, 3));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 3, 2));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 4, 1));

        // Four param tests.

        // Copy beyond end of srcArr.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, 0, 4));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 1, 0, 3));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 2, 0, 2));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 3, 0, 1));

        // Copy beyond the end of vecSeg.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, 3, 2));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, 2, 3));

        // Invalid source and target indexes.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, -1, 0, 1));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, -1, 1));

        // Invalid length.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, 0, -1));
    }
    public void CopyToTest_InvalidCopyOperations()
    {
        int[] innerArr   = Enumerable.Range(0, 10).ToArray();
        int[] map        = new int[] { 5, 3, 8 };
        var   mappingVec = new MappingVector <int>(innerArr, map);

        int[] tgtArr = new int[12];

        //--- Two param tests.
        // Copy beyond end of tgtArr.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyTo(tgtArr, 10));

        // Invalid target index.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyTo(tgtArr, -1));

        //--- Three param tests.
        // Copy length longer then vecSeg length.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyTo(tgtArr, 0, 4));

        // Invalid target index.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyTo(tgtArr, -1, 1));

        // Invalid length.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyTo(tgtArr, 0, -1));

        // Copy beyond end of tgtArr.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyTo(tgtArr, 11, 2));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyTo(tgtArr, 12, 1));

        //--- Four param tests.
        // Copy beyond end of vecSeg.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyTo(tgtArr, 0, 1, 3));

        // Copy beyond end of tgtArr.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyTo(tgtArr, 11, 1, 2));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyTo(tgtArr, 12, 1, 1));

        // Invalid source and target indexes.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyTo(tgtArr, -1, 0, 1));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyTo(tgtArr, 0, -1, 1));

        // Invalid length.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyTo(tgtArr, 0, 1, -1));
    }
Exemple #7
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;
            }
        }