本文整理汇总了C#中Altaxo.Calc.LinearAlgebra.DoubleVector.GetDotProduct方法的典型用法代码示例。如果您正苦于以下问题:C# DoubleVector.GetDotProduct方法的具体用法?C# DoubleVector.GetDotProduct怎么用?C# DoubleVector.GetDotProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Altaxo.Calc.LinearAlgebra.DoubleVector
的用法示例。
在下文中一共展示了DoubleVector.GetDotProduct方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
///<summary> Minimize the given cost function </summary>
public override DoubleVector Search(DoubleVector x, DoubleVector d, double stp)
{
DoubleVector ret = new DoubleVector(x);
double j = 0;
double delta_d = d.GetDotProduct(d);
double alpha;
do
{
alpha = -GradientEvaluation(ret).GetDotProduct(d) /
d.GetDotProduct(HessianEvaluation(ret) * d);
ret = ret + alpha * d;
j++;
} while ((j < maxIteration) && (alpha * alpha * delta_d > tolerance * tolerance));
return ret;
}
示例2: Search
///<summary> Minimize the given cost function </summary>
public override DoubleVector Search(DoubleVector x, DoubleVector d, double step)
{
DoubleVector ret = new DoubleVector(x);
double j=0;
double eta;
double delta_d = d.GetDotProduct(d);
double alpha = -sigma_0;
double eta_prev = d.GetDotProduct(GradientEvaluation(ret+sigma_0*d));
do
{
eta = d.GetDotProduct(GradientEvaluation(ret));
alpha = alpha*(eta/(eta_prev-eta));
ret = ret + alpha*d;
eta_prev = eta;
j++;
} while ((j<maxIteration) && (alpha*alpha*delta_d > tolerance*tolerance));
return ret;
}
示例3: InitializeMethod
///<summary> Initialize the optimization method </summary>
///<remarks> The use of this function is intended for testing/debugging purposes only </remarks>
public override void InitializeMethod(DoubleVector initialvector)
{
g = GradientEvaluation(initialvector);
// Calculate Diagonal preconditioner
DoubleMatrix h = HessianEvaluation(initialvector);
DoubleMatrix m_inv = new DoubleMatrix(initialvector.Length,initialvector.Length);
for (int i=0; i<initialvector.Length; i++)
m_inv[i,i] = 1/h[i,i];
s = m_inv*g;
DoubleVector d = -s;
delta_new = g.GetDotProduct(d);
restartCounter=0;
/* ------------------------------ */
this.iterationVectors_ = new DoubleVector[endCriteria_.maxIteration+1];
this.iterationVectors_[0] = initialvector;
this.iterationValues_ = new double[endCriteria_.maxIteration+1];
this.iterationValues_[0] = FunctionEvaluation(this.iterationVectors_[0]);
this.iterationGradients_ = new DoubleVector[endCriteria_.maxIteration+1];
this.iterationGradients_[0] = new DoubleVector(g);
this.iterationGradientNorms_ = new double[endCriteria_.maxIteration+1];
this.iterationGradientNorms_[0] = g.GetNorm();
this.iterationDirections_ = new DoubleVector[endCriteria_.maxIteration+1];
this.iterationDirections_[0] = d;
this.iterationTrialSteps_ = new double[endCriteria_.maxIteration+1];
this.iterationTrialSteps_[0] = 1/this.iterationGradientNorms_[0];
}
示例4: IterateMethod
///<summary> Perform a single iteration of the optimization method </summary>
///<remarks> The use of this function is intended for testing/debugging purposes only </remarks>
public override void IterateMethod()
{
DoubleVector d = this.iterationDirections_[endCriteria_.iterationCounter-1];
DoubleVector x = this.iterationVectors_[endCriteria_.iterationCounter-1];
DoubleVector g = this.iterationGradients_[endCriteria_.iterationCounter-1];
double stp = this.iterationTrialSteps_[endCriteria_.iterationCounter-1];
// Shanno-Phua's Formula for Trial Step
if (restartCounter==0 && endCriteria_.iterationCounter>1)
{
double dg = d.GetDotProduct(g);
double dg0 = this.iterationDirections_[endCriteria_.iterationCounter-2].GetDotProduct(
this.iterationGradients_[endCriteria_.iterationCounter-2])/stp;
stp = dg0/dg;
}
delta_mid = g.GetDotProduct(g);
// Conduct line search
x = lineSearchMethod_.Search(x,d,stp);
g = GradientEvaluation(x);
delta_old = delta_new;
delta_mid = g.GetDotProduct(s);
// Calculate Diagonal preconditioner
DoubleMatrix h = HessianEvaluation(x);
DoubleMatrix m_inv = new DoubleMatrix(x.Length,x.Length);
for (int i=0; i<x.Length; i++)
m_inv[i,i] = 1/h[i,i];
s = m_inv*g;
// Calculate Beta
delta_new = g.GetDotProduct(s);
double beta = (delta_new-delta_mid)/delta_old;
// Check for restart conditions
restartCounter++;
if (restartCounter==restartCount || (restartCounter==x.Length && restartCount==0) || beta<=0)
{
restartCount = 0;
beta=0;
}
// Calculate next line search direction
d = -s + beta*d;
this.iterationVectors_[endCriteria_.iterationCounter] = x;
this.iterationValues_[endCriteria_.iterationCounter] = FunctionEvaluation(x);
this.iterationGradients_[endCriteria_.iterationCounter] = g;
this.iterationGradientNorms_[endCriteria_.iterationCounter] = g.GetNorm();
this.iterationDirections_[endCriteria_.iterationCounter] = d;
this.iterationTrialSteps_[endCriteria_.iterationCounter] = stp;
}
示例5: GetDotProduct
public void GetDotProduct()
{
DoubleVector a = new DoubleVector(new double[4]{0,1,2,3});
DoubleVector b = new DoubleVector(new double[4]{4,5,6,7});
Assert.AreEqual(a.GetDotProduct(),14);
Assert.AreEqual(b.GetDotProduct(),126);
Assert.AreEqual(a.GetDotProduct(b),38);
Assert.AreEqual(a.GetDotProduct(b),b.GetDotProduct(a));
}