本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Double.DenseVector.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# DenseVector.Clear方法的具体用法?C# DenseVector.Clear怎么用?C# DenseVector.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MathNet.Numerics.LinearAlgebra.Double.DenseVector
的用法示例。
在下文中一共展示了DenseVector.Clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: calculateButton_Click
/// <summary>
/// CALCULATE BUTTON CLICK
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void calculateButton_Click(object sender, EventArgs e)
{
_currMethod.AlphaMethod = null;
Vector<double> start = new DenseVector(_varCount);
try
{
var text = startingPointTextBox.Text;
var textValues = text.Split(',');
for (var i = 0; i < _varCount; i++)
{
start[i] = double.Parse(textValues[i]);
}
}
catch (Exception)
{
start.Clear();
}
var fh = new FunctionHolder(_currFunction, start);
_currMethod.Fh = fh;
if (_alphaMethodChosen)
{
_currAlphaMethod.F = fh.AlphaFunction;
_currAlphaMethod.Df = fh.AlphaDiffFunction;
_currMethod.AlphaMethod = _currAlphaMethod;
}
double eps;
try
{
eps = double.Parse(precisionTextBox.Text);
}
catch (Exception)
{
eps = 1e-5;
precisionTextBox.Text = @"1e-5";
}
_currMethod.Eps = eps;
//Делаем сам метод
var sw = Stopwatch.StartNew();
_currMethod.Execute();
sw.Stop();
//Вывод, Двуменрная функция
var coord = _currMethod.Answer;
answerTextBox.Text = @"Answer:" + Environment.NewLine + coord.ToString();
iterationTextBox.Text = Convert.ToString("Iterations: " + _currMethod.IterationCount);
timeTextBox.Text = @"Time (ms):" + Environment.NewLine +((sw.ElapsedMilliseconds == 0) ? ("<1") : (sw.ElapsedMilliseconds.ToString()));
}
示例2: CalculateVGradient
private DenseVector CalculateVGradient()
{
DenseVector vgrad = new DenseVector(V.Count);
vgrad.Clear(); //TODO test if this is necessary
for(int k = 0; k < vgrad.Count; k++)
{
for(int m = 0; m < TrainingInputs.Count; m++)
{
for(int horz = 0; horz < TrainingInputs[m].XSites; horz++)
{
for(int vert = 0; vert < TrainingInputs[m].YSites; vert++)
{
//vgrad[k] = sum over image sites in all images of
//[ sum over image sites of x_i x_j (mu_ij (y))_k] <- vterm
//-
//[dzdv]/[z]
//
//all minus v_k/tau^2
double z = 0;
//x_i
int x = (int)(TrainingOutputs[m][horz,vert])*2 - 1;
//Sum over neighbors of x_i x_j mu_{ij}(y)_k
double vterm = 0;
foreach(Tuple<int,int> j in TrainingInputs[m].GetNeighbors(horz, vert))
{
int jx = (int)(TrainingOutputs[m][j.Item1,j.Item2])*2 - 1;
DenseVector mu;
if(ImageData.IsEarlier(horz,vert,j.Item1,j.Item2))mu = Crosser.Cross(TrainingInputs[m][horz,vert],TrainingInputs[m][j.Item1,j.Item2]);
else mu = Crosser.Cross(TrainingInputs[m][j.Item1,j.Item2], TrainingInputs[m][horz,vert]);
vterm += x * jx * mu[k];
}
vgrad[k] += vterm;
double dzdv = 0;
//h_i(y):
DenseVector h = Transformer.Transform(TrainingInputs[m][horz,vert]);
//Sum over possible x_i
for(int tempx = -1; tempx <= 1; tempx += 2)
{
double logofcoeff = MathWrapper.Log(MathWrapper.Sigma(tempx * W.DotProduct(h)));
double dzdvterm = 0;
//sum over the neighbors
foreach(Tuple<int,int> j in TrainingInputs[m].GetNeighbors(horz,vert))
{
int jx = (int)(TrainingOutputs[m][j.Item1,j.Item2])*2 - 1;
DenseVector mu;
if(ImageData.IsEarlier(horz,vert,j.Item1,j.Item2))mu = Crosser.Cross(TrainingInputs[m][horz,vert],TrainingInputs[m][j.Item1,j.Item2]);
else mu = Crosser.Cross(TrainingInputs[m][j.Item1,j.Item2], TrainingInputs[m][horz,vert]);
logofcoeff += tempx * jx * V.DotProduct(mu);
dzdvterm += tempx * jx * mu[k];
}
double coeff = MathWrapper.Exp(logofcoeff);
z += coeff;
dzdv += coeff * dzdvterm;
if(double.IsNaN(dzdv)||double.IsNaN(z)||double.IsInfinity(dzdv)||double.IsInfinity(z)) throw new NotFiniteNumberException();
}
if(z <= 0d) throw new NotFiniteNumberException();
vgrad[k] -= dzdv/z;
}
}
}
vgrad[k] -= V[k]/(Math.Pow (Tau,2));
}
return vgrad;
}
示例3: materialFlatButton1_Click
/// <summary>
/// Нажатие кнопки "TEST ALL"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void materialFlatButton1_Click(object sender, EventArgs e)
{
var exports = new List<TestExport>(_functions.Count*_methods.Count);
foreach (var function in _functions)
{
ParseFunction(function);
foreach (var method in _methods)
{
_currMethod = method;
_currMethod.AlphaMethod = null;
Vector<double> start = new DenseVector(_varCount);
try
{
var text = startingPointTextBox.Text;
var textValues = text.Split(',');
for (var i = 0; i < _varCount; i++)
{
start[i] = double.Parse(textValues[i]);
}
}
catch (Exception)
{
start.Clear();
}
var fh = new FunctionHolder(_currFunction, start);
_currMethod.Fh = fh;
if (_alphaMethodChosen)
{
_currAlphaMethod.F = fh.AlphaFunction;
_currAlphaMethod.Df = fh.AlphaDiffFunction;
_currMethod.AlphaMethod = _currAlphaMethod;
}
double eps;
try
{
eps = double.Parse(precisionTextBox.Text);
}
catch (Exception)
{
eps = 1e-5;
precisionTextBox.Text = @"1e-5";
}
_currMethod.Eps = eps;
//Делаем сам метод
var sw = Stopwatch.StartNew();
_currMethod.Execute();
sw.Stop();
//Вывод, Двуменрная функция
var coord = _currMethod.Answer;
exports.Add(new TestExport(method.Name,function,coord.ToVectorString(),method.IterationCount.ToString(),sw.ElapsedMilliseconds.ToString(),eps.ToString()));
}
}
var testForm = new TestForm(exports);
_materialSkinManager.AddFormToManage(testForm);
testForm.ShowDialog();
}
示例4: CalculateWGradient
private DenseVector CalculateWGradient()
{
DenseVector wgrad = new DenseVector(W.Count);
wgrad.Clear(); //TODO test if this is necessary
for(int k = 0; k < wgrad.Count; k++)
{
for(int m = 0; m < TrainingInputs.Count; m++)
{
for(int horz = 0; horz < TrainingInputs[m].XSites; horz++)
{
for(int vert = 0; vert < TrainingInputs[m].YSites; vert++)
{
//h_i(y):
DenseVector h = Transformer.Transform(TrainingInputs[m][horz,vert]);
if(double.IsNaN(h[k])) throw new NotFiniteNumberException();
//x_i
int x = (int)(TrainingOutputs[m][horz,vert])*2 - 1;
//sigma term that keeps reappearing
double sig = MathWrapper.Sigma(x * W.DotProduct(h));
//x_i * h_i(y)_k * (1 - sigma(x_i * w^T h_i(y)))
//double old = wgrad[k];
wgrad[k] += x*h[k]*(1 - sig);
if(double.IsNaN(wgrad[k])) throw new NotFiniteNumberException();
//- ((d/(dw_k)) z_i) / z_i
double z = 0;
double dzdw = 0;
//Sum over possible x_i
for(int tempx = -1; tempx <= 1; tempx += 2)
{
double logofcoeff = MathWrapper.Log(MathWrapper.Sigma(tempx * W.DotProduct(h)));
//sum over the neighbors
foreach(Tuple<int,int> j in TrainingInputs[m].GetNeighbors(horz,vert))
{
int jx = (int)(TrainingOutputs[m][j.Item1,j.Item2])*2 - 1;
DenseVector mu;
if(ImageData.IsEarlier(horz,vert,j.Item1,j.Item2))mu = Crosser.Cross(TrainingInputs[m][horz,vert],TrainingInputs[m][j.Item1,j.Item2]);
else mu = Crosser.Cross(TrainingInputs[m][j.Item1,j.Item2], TrainingInputs[m][horz,vert]);
logofcoeff += tempx * jx * V.DotProduct(mu);
}
double coeff = MathWrapper.Exp(logofcoeff);
z += coeff;
double multfactor = (1 - MathWrapper.Sigma (tempx * W.DotProduct(h)));
dzdw += coeff * tempx*h[k]*multfactor;
if(double.IsNaN(dzdw)||double.IsNaN(z)||double.IsInfinity(dzdw)||double.IsInfinity(z)) throw new NotFiniteNumberException();
}
if(z <= 0d) throw new NotFiniteNumberException();
wgrad[k] -= dzdw/z;
if(double.IsNaN(wgrad[k])) throw new NotFiniteNumberException();
if(double.IsInfinity(wgrad[k])) throw new NotFiniteNumberException();
}
}
}
}
return wgrad;
}