本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}