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; }
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())) )); }
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)); }
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); }
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)); }
public VectorBatch LeftMultiplyBy(VectorBatch batch) { return(new VectorBatch(batch.AsMatrix().Multiply(_matrix))); }
public VectorBatch TransposeAndLeftMultiplyBy(VectorBatch batch) { return(new VectorBatch(batch.AsMatrix().Multiply(_matrix.Transpose()))); }
public NetworkVector BiasesGradient(VectorBatch outputgradients) { var y = outputgradients.AsMatrix().ColumnSums(); return(new NetworkVector(y)); }
public override VectorBatch Gradient(VectorBatch target, VectorBatch batch) { return(new VectorBatch( target.AsMatrix().Map2((x, y) => 1 / y, batch.AsMatrix()) )); }
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)); }
public override VectorBatch Gradient(VectorBatch target, VectorBatch batch) { return(new VectorBatch(target.AsMatrix() - batch.AsMatrix())); }