예제 #1
0
        public override VectorBatch InputGradient(VectorBatch outputgradient)
        {
            if (outputgradient == null || outputgradient.Dimension != NumberOfOutputs)
            {
                throw new ArgumentException("outputgradient may not be null and must have dimension equal to NumberOfNeurons.");
            }

            if (_neuralFunctionDerivative == null)
            {
                return(outputgradient);
            }

            return(new VectorBatch(
                       _inputBatch.AsMatrix().Map2((x, y) => _neuralFunctionDerivative(x, y), _outputBatch.AsMatrix())
                       ));

            //VectorBatch derivative = new VectorBatch(
            //    _inputBatch.AsMatrix().Map2((x, y) => _neuralFunctionDerivative(x, y), _outputBatch.AsMatrix())
            //    );

            //VectorBatch result = new VectorBatch(
            //    derivative.AsMatrix().Map2((x, y) => x * y, outputgradient.AsMatrix() )
            //    );

            //return result;
        }
예제 #2
0
        public override VectorBatch InputGradient(VectorBatch outputgradients)
        {
            if (outputgradients == null || outputgradients.Dimension != NumberOfOutputs)
            {
                throw new ArgumentException("outputgradient may not be null and must have dimension equal to the number of units.");
            }

            return(new VectorBatch(
                       (_output.AsMatrix().Map2((x, y) => x * (1 - x) * y, outputgradients.AsMatrix()))
                       ));
        }
예제 #3
0
        public override double Cost(VectorBatch target, VectorBatch batch)
        {
            _workingVector      = null;
            _workingBatchMatrix = batch.AsMatrix().Map(x => Math.Exp(x));
            Vector <double> sum = _workingBatchMatrix.RowSums();

            _workingBatchMatrix = _workingBatchMatrix.NormalizeRows(1.0);
            _workingBatchMatrix = target.AsMatrix().Map2((x, y) => Math.Log(y) * x, _workingBatchMatrix);

            return(_workingBatchMatrix.RowSums().Sum() / (batch.Count * batch.Dimension));
        }
예제 #4
0
        public override VectorBatch Run(VectorBatch inputbatch)
        {
            _inputVector  = null;
            _inputBatch   = inputbatch;
            _outputVector = null;

            if (_neuralFunction != null)
            {
                _outputBatch = new VectorBatch(inputbatch.AsMatrix().Map(x => _neuralFunction(x)));
            }
            else
            {
                _outputBatch = inputbatch;
            }

            return(_outputBatch);
        }
예제 #5
0
        public override VectorBatch Run(VectorBatch inputbatch)
        {
            if (inputbatch == null || inputbatch.Dimension != _numberOfUnits)
            {
                throw new ArgumentException("inputvalues may not be null and must have dimension equal to the number of units.");
            }

            double          max;
            double          sum;
            Matrix <double> result = Matrix <double> .Build.DenseOfMatrix(inputbatch.AsMatrix());

            foreach (Vector <double> row in result.EnumerateRows())
            {
                max = row.Max();
                row.Map(x => Math.Exp(x - max));

                sum = row.Sum();
                row.Map(x => x / sum);
            }

            return(new VectorBatch(result));
        }
예제 #6
0
 public VectorBatch LeftMultiplyBy(VectorBatch batch)
 {
     return(new VectorBatch(batch.AsMatrix().Multiply(_matrix)));
 }
예제 #7
0
 public VectorBatch TransposeAndLeftMultiplyBy(VectorBatch batch)
 {
     return(new VectorBatch(batch.AsMatrix().Multiply(_matrix.Transpose())));
 }
예제 #8
0
        public NetworkVector BiasesGradient(VectorBatch outputgradients)
        {
            var y = outputgradients.AsMatrix().ColumnSums();

            return(new NetworkVector(y));
        }
예제 #9
0
 public override VectorBatch Gradient(VectorBatch target, VectorBatch batch)
 {
     return(new VectorBatch(
                target.AsMatrix().Map2((x, y) => 1 / y, batch.AsMatrix())
                ));
 }
예제 #10
0
 public override double Cost(VectorBatch target, VectorBatch batch)
 {
     return
         (target.AsMatrix().Map2((x, y) => Math.Log(y) * x, batch.AsMatrix()).RowSums().Sum() / (batch.Count * batch.Dimension));
 }
예제 #11
0
 public override VectorBatch Gradient(VectorBatch target, VectorBatch batch)
 {
     return(new VectorBatch(target.AsMatrix() - batch.AsMatrix()));
 }