当前位置: 首页>>代码示例>>C#>>正文


C# IVector.Mul方法代码示例

本文整理汇总了C#中IVector.Mul方法的典型用法代码示例。如果您正苦于以下问题:C# IVector.Mul方法的具体用法?C# IVector.Mul怎么用?C# IVector.Mul使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IVector的用法示例。


在下文中一共展示了IVector.Mul方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalculateInvertedPseudoGaussian

        private static IMatrix CalculateInvertedPseudoGaussian(IMatrix b, IVector s, IVector y)
        {
            var syNumber = s.Mul(y);

            var syNumberSqr = syNumber.Mul(syNumber);
            var yByNumber = y.Mul(b.Mul(y));
            var ssMatrix = s.OuterMul(s);
            var second = ssMatrix.Mul(syNumber.Sum(yByNumber)).Div(syNumberSqr);

            var ysMatrix = y.OuterMul(s);
            var syMatrix = s.OuterMul(y);
            var third = b.Mul(ysMatrix).Sum(syMatrix.Mul(b)).Div(syNumber);

            return b.Sum(second).Sub(third);
        }
开发者ID:Diover,项目名称:nets,代码行数:15,代码来源:BfgsMethod.cs

示例2: MakeStepGoldstein

        private IVector MakeStepGoldstein(IVector direction, INet net, double currentError, IVector gradient)
        {
            const int maximumNumberOfTry = 50;
            var numberOfTry = 0;
            double error;
            var step = direction.Mul(_alpha); ;
            var c = 0.1;
            var p = _random.NextDouble()*0.3 + 0.3;

            var oldWeights = _weights;
            //can change alpha by minimizing it in f(xk + alpha*direction)
            var threshold = 0.0;
            do
            {
                if (numberOfTry > maximumNumberOfTry || _alpha < 0.00001)
                    break;

                _weights = oldWeights.Sum(step); //x(k+1) = xk + sk
                net.SetWeights(_weights); //content of _weights now shared between net and _weights vector
                error = GetBatchError(net);

                threshold = gradient.Mul(step).Mul(_alpha).Mul(c).GetMod().X;

                _alpha *= p;
                step = direction.Mul(_alpha);
                numberOfTry++;
            } while (error > currentError + threshold);

            if (numberOfTry > maximumNumberOfTry || _alpha < 0.00001)
            {
                _weights = oldWeights;
                net.SetWeights(_weights);
                //will make gradient descent on next step
                _gradient = null;
                _b = Matrix.CreateI(net.WeightsCount, net.WeightsCount, () => new RealNumber(1), () => new RealNumber(0)); //b0
                _alpha = 1.0;
                Console.WriteLine("Reset matrix");
                return null;
            }

            _alpha = 1.0;
            return step;
        }
开发者ID:Diover,项目名称:nets,代码行数:43,代码来源:BackPropagationWithPseudoNeuton.cs

示例3: MakeStep

        private IVector MakeStep(IVector direction, INet net, double currentError)
        {
            const int maximumNumberOfTry = 50;
            var numberOfTry = 0;
            double error;
            var step = direction.Mul(_alpha); ;

            var oldWeights = _weights;
            //can change alpha by minimizing it in f(xk + alpha*direction)
            do
            {
                if (numberOfTry > maximumNumberOfTry || _alpha < 0.000000000001)
                    break;

                _weights = oldWeights.Sum(step); //x(k+1) = xk + sk
                net.SetWeights(_weights); //content of _weights now shared between net and _weights vector
                error = GetBatchError(net);

                _alpha /= 2.1;
                step = direction.Mul(_alpha);
                numberOfTry++;
            } while (error > currentError);

            if (numberOfTry > maximumNumberOfTry || _alpha < 0.000000000001)
            {
                Console.WriteLine("Simple step was performed. Too little alpha: {0:0.#############}.", _alpha);
                //step = direction.Mul(_alpha);
                _weights = oldWeights.Sum(direction.Mul(0.1));
                net.SetWeights(_weights);
                //AddLittleCorrectionToWeights(net.Layers);
                //_gradient = null;
                _alpha = 1.0;
                return null;
            }

            _alpha = 1.0;
            return step;
        }
开发者ID:Diover,项目名称:nets,代码行数:38,代码来源:BackPropagationWithPseudoNeuton.cs

示例4: CalculateStepAndChangeAlpha

        private IVector CalculateStepAndChangeAlpha(IVector direction, Func<IVector, double> f)
        {
            IVector step;
            IVector newX;
            do
            {
                step = direction.Mul(_alpha);
                newX = _x.Sum(step);
                _alpha /= 2.0;
            } while (f(newX) > f(_x));

            _alpha = 1.0;
            _x = newX;
            return step;
        }
开发者ID:Diover,项目名称:nets,代码行数:15,代码来源:BfgsMethod.cs

示例5: Mul

        public IVector Mul(IVector x)
        {
            if(x.Length != Columns)
                throw new ArgumentException("Vector and matrix dimensions are different");

            var result = new Vector(Rows);

            for (int i = 0; i < result.Length; i++)
                result[i] = x.Mul(new Vector(_values[i]));

            return result;
        }
开发者ID:Diover,项目名称:nets,代码行数:12,代码来源:Matrix.cs


注:本文中的IVector.Mul方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。