Esempio n. 1
0
 public DataVector(VectorBatch batch)
     : base(batch)
 {
     if (batch.Count != 1)
     {
         throw new ArgumentException("Can create a Vector only from a non-empty, singleton VectorBatch");
     }
 }
Esempio n. 2
0
        protected override VectorBatch _backPropagate(VectorBatch outputGradient)
        {
            VectorBatch inputGradient = _getInputGradient(outputGradient);

            _updateWeights(outputGradient);
            _updateBiases(outputGradient);
            return(inputGradient);
        }
Esempio n. 3
0
        protected override VectorBatch _backPropagate(VectorBatch outputGradient)
        {
            if (outputGradient == null || outputGradient.Dimension != NumberOfOutputs)
            {
                throw new ArgumentException("outputgradient may not be null and must have dimension equal to the number of units.");
            }

            return(VectorBatch.ApplyFunction((x, y) => x * (1 - x) * y, _output, outputGradient));
        }
Esempio n. 4
0
        protected override VectorBatch _trainingRun(VectorBatch input)
        {
            _input = input;

            VectorBatch combination = _weights.ApplyForwards(input);
            VectorBatch output      = combination.AddToEachVector(_biases);

            return(output);
        }
Esempio n. 5
0
 protected override VectorBatch _backPropagate(VectorBatch outputGradient)
 {
     _activationGradient = outputGradient;
     if (_neuralFunction != null)
     {
         _activationGradient = _neuralFunction.BackPropagate(outputGradient);
     }
     return(base._backPropagate(outputGradient));
 }
Esempio n. 6
0
        protected override VectorBatch _trainingRun(VectorBatch input)
        {
            VectorBatch output = base._trainingRun(input);

            if (_neuralFunction != null)
            {
                output = _neuralFunction.Run(output);
            }
            return(output);
        }
Esempio n. 7
0
        protected override VectorBatch _run(VectorBatch inputbatch)
        {
            _input = inputbatch;

            if (_neuralFunction != null)
            {
                _output = VectorBatch.ApplyFunction(x => _neuralFunction(x), _input);
            }
            else
            {
                _output = inputbatch;
            }

            return(_output);
        }
Esempio n. 8
0
        protected override VectorBatch _backPropagate(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);
            }

            VectorBatch derivative = VectorBatch.ApplyFunction((x, y) => _neuralFunctionDerivative(x, y), _input, _output);
            VectorBatch result     = VectorBatch.ApplyFunction((x, y) => x * y, derivative, outputGradient);

            return(result);
        }
Esempio n. 9
0
        protected override VectorBatch _run(VectorBatch inputbatch)
        {
            if (inputbatch == null || inputbatch.Dimension != NumberOfInputs)
            {
                throw new ArgumentException("input may not be null and must have dimension equal to the number of units.");
            }

            _input = inputbatch;

            VectorBatch result = inputbatch.SubractVectorMaxima();

            result = VectorBatch.ApplyFunction(x => Math.Exp(x), result);
            result = result.DivideByComponentSums();

            _output = result;
            return(_output);
        }
Esempio n. 10
0
 protected override VectorBatch _getInputGradient(VectorBatch outputGradient)
 {
     return(_weights.ApplyBackwards(outputGradient));
 }
Esempio n. 11
0
 public SoftMaxUnit(int numberofunits)
     : base(numberofunits, numberofunits)
 {
     _input  = new DataVector(numberofunits);
     _output = new DataVector(numberofunits);
 }
Esempio n. 12
0
 public VectorBatch Run(VectorBatch input)
 {
     return(_run(input));
 }
Esempio n. 13
0
 public VectorBatch ApplyBackwards(VectorBatch vector)
 {
     return(new VectorBatch((Matrix.Multiply(vector, this))));
 }
Esempio n. 14
0
 public VectorBatch ApplyForwards(VectorBatch vector)
 {
     return(new VectorBatch((Matrix.MultiplyByTranspose(vector, this))));
 }
Esempio n. 15
0
        protected override void _updateBiases(VectorBatch outputGradient)
        {
            BiasesVector biasesGradient = new BiasesVector(_activationGradient.SumColumnsAsMatrix());

            _biases = _biases.Add(Strategy.BiasesUpdate(biasesGradient));
        }
Esempio n. 16
0
 public VectorBatch Subtract(VectorBatch other)
 {
     return(new VectorBatch(SubtractMatrices(this, other)));
 }
Esempio n. 17
0
 protected abstract VectorBatch _trainingRun(VectorBatch input);
Esempio n. 18
0
 protected abstract void _updateWeights(VectorBatch outputGradient);
Esempio n. 19
0
 public VectorBatch BackPropagate(VectorBatch outputGradient)
 {
     return(_backPropagate(outputGradient));
 }
Esempio n. 20
0
 protected abstract VectorBatch _run(VectorBatch input);
Esempio n. 21
0
        protected override void _updateWeights(VectorBatch outputGradient)
        {
            WeightsMatrix weightsGradient = WeightsMatrix.FromVectorBatchPair(_input, _activationGradient);

            _weights = _weights.Add(Strategy.WeightsUpdate(weightsGradient));
        }
Esempio n. 22
0
 protected override VectorBatch _run(VectorBatch input)
 {
     _input = input;
     return(_trainingRun(_input));
 }
Esempio n. 23
0
 public static WeightsMatrix FromVectorBatchPair(VectorBatch first, VectorBatch second)
 {
     return(new WeightsMatrix(Matrix.TransposeAndMultiplyBy(second, first)));
 }
Esempio n. 24
0
 protected override VectorBatch _getInputGradient(VectorBatch outputGradient)
 {
     return(base._getInputGradient(_activationGradient));
 }
Esempio n. 25
0
 protected abstract VectorBatch _backPropagate(VectorBatch outputGradient);
Esempio n. 26
0
 protected abstract VectorBatch _getInputGradient(VectorBatch outputGradient);
Esempio n. 27
0
 public static VectorBatch ApplyFunction(Func <double, double> fctn, VectorBatch batch)
 {
     return(new VectorBatch(Matrix.ApplyFunction(fctn, batch)));
 }
Esempio n. 28
0
 protected abstract void _updateBiases(VectorBatch outputGradient);
Esempio n. 29
0
 public static VectorBatch ApplyFunction(Func <double, double, double> fctn, VectorBatch first, VectorBatch second)
 {
     return(new VectorBatch(Matrix.ApplyFunction(fctn, first, second)));
 }