Esempio n. 1
0
        public VectorBatch(Matrix <double> vectors)
        {
            _dimension = vectors.ColumnCount;
            _count     = vectors.RowCount;

            if (vectors.EnumerateRows().Any(x => x.Count != _dimension))
            {
                throw new ArgumentException("Caanot create VectorBatch with unequal dimensions.");
            }

            _batch = Matrix <double> .Build.DenseOfMatrix(vectors);
        }
Esempio n. 2
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));
        }