本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Double.DenseVector.MinimumIndex方法的典型用法代码示例。如果您正苦于以下问题:C# DenseVector.MinimumIndex方法的具体用法?C# DenseVector.MinimumIndex怎么用?C# DenseVector.MinimumIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MathNet.Numerics.LinearAlgebra.Double.DenseVector
的用法示例。
在下文中一共展示了DenseVector.MinimumIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModificatedDualIteration
//.........这里部分代码省略.........
var nk = kappaValue < _task.dLower[kappaIndex] ? 1 : -1;
var deltaYT =
nk * DenseVector.Create(_task.Jb.Count, i => i == _task.Jb.ToList().IndexOf(kappaIndex) ? 1 : 0)
* DenseMatrix.OfColumnVectors(vectorCollection.ToArray()).Inverse();
var nVector = new DenseVector(_task.A.ColumnCount);
for (int i = 0; i < _task.A.ColumnCount; i++)
{
if (!_task.Jb.Contains(i))
{
nVector[i] = (deltaYT * _task.A.Column(i));
}
}
// Step6
Vector<double> sigmaVector = new DenseVector(_task.A.ColumnCount);
for (int i = 0; i < sigmaVector.Count; i++)
{
if (_task.dLower[i] == _task.dUpper[i])
{
sigmaVector[i] = double.PositiveInfinity;
}
else if (_JNbUpper.Contains(i) && nVector[i] < Eps)
{
sigmaVector[i] = -deltas[i] / nVector[i];
}
else if (_JNbLower.Contains(i) && nVector[i] > Eps)
{
sigmaVector[i] = -deltas[i] / nVector[i];
}
else
{
sigmaVector[i] = double.PositiveInfinity;
}
}
var sigma0 = sigmaVector.Min();
var sigma0Index = sigmaVector.MinimumIndex();
// Step7
if (sigma0 == double.PositiveInfinity)
{
//Logger.Log("Stopped at seventh step");
_stopStep = 7;
return false;
}
// Step8
Vector<double> newDeltas = new DenseVector(_task.A.ColumnCount);
for (int i = 0; i < newDeltas.Count; i++)
{
if (_task.Jb.Contains(i) && i != kappaIndex)
{
newDeltas[i] = 0;
}
else if (i == kappaIndex)
{
newDeltas[i] = sigma0 * nk;
}
else
{
newDeltas[i] = deltas[i] + sigma0 * nVector[i];
}
}
deltas = newDeltas.ToList();
// Step9
_task.Jb[_task.Jb.ToList().IndexOf(kappaIndex)] = sigma0Index;
// Step10
if (nk == 1.0)
{
if (_JNbUpper.Contains(sigma0Index))
{
_JNbUpper[_JNbUpper.IndexOf(sigma0Index)] = kappaIndex;
}
else
{
_JNbUpper.Add(kappaIndex);
}
}
else if (nk == -1.0)
{
if (_JNbUpper.Contains(sigma0Index))
{
_JNbUpper.Remove(sigma0Index);
}
}
_JNbLower.Clear();
for (int i = 0; i < _task.A.ColumnCount; i++)
{
if (!_JNbUpper.Contains(i) && !_task.Jb.Contains(i))
{
_JNbLower.Add(i);
}
}
return true;
}
示例2: Train
public void Train(DenseMatrix X, DenseVector d, DenseVector Kd)
{
int R = X.RowCount;
int N = X.ColumnCount;
int U = 0; //the number of neurons in the structure
var c = new DenseMatrix(R, 1);
var sigma = new DenseMatrix(R, 1);
var Q = new DenseMatrix((R + 1), (R + 1));
var O = new DenseMatrix(1, (R + 1));
var pT_n = new DenseMatrix((R + 1), 1);
double maxPhi = 0;
int maxIndex;
var Psi = new DenseMatrix(N, 1);
Console.WriteLine("Running...");
//for each observation n in X
for (int i = 0; i < N; i++)
{
Console.WriteLine(100*(i/(double) N) + "%");
var x = new DenseVector(R);
X.Column(i, x);
//if there are neurons in structure,
//update structure recursively.
if (U == 0)
{
c = (DenseMatrix) x.ToColumnMatrix();
sigma = new DenseMatrix(R, 1, SigmaZero);
U = 1;
Psi = CalculatePsi(X, c, sigma);
UpdateStructure(X, Psi, d, ref Q, ref O);
pT_n =
(DenseMatrix)
(CalculateGreatPsi((DenseMatrix) x.ToColumnMatrix(), (DenseMatrix) Psi.Row(i).ToRowMatrix()))
.Transpose();
}
else
{
StructureRecurse(X, Psi, d, i, ref Q, ref O, ref pT_n);
}
bool KeepSpinning = true;
while (KeepSpinning)
{
//Calculate the error and if-part criteria
double ee = pT_n.Multiply(O)[0, 0];
double approximationError = Math.Abs(d[i] - ee);
DenseVector Phi;
double SumPhi;
CalculatePhi(x, c, sigma, out Phi, out SumPhi);
maxPhi = Phi.Maximum();
maxIndex = Phi.MaximumIndex();
if (approximationError > delta)
{
if (maxPhi < threshold)
{
var tempSigma = new DenseVector(R);
sigma.Column(maxIndex, tempSigma);
double minSigma = tempSigma.Minimum();
int minIndex = tempSigma.MinimumIndex();
sigma[minIndex, maxIndex] = k_sigma*minSigma;
Psi = CalculatePsi(X, c, sigma);
UpdateStructure(X, Psi, d, ref Q, ref O);
var psi = new DenseVector(Psi.ColumnCount);
Psi.Row(i, psi);
pT_n =
(DenseMatrix)
CalculateGreatPsi((DenseMatrix) x.ToColumnMatrix(), (DenseMatrix) psi.ToRowMatrix())
.Transpose();
}
else
{
//add a new neuron and update strucutre
double distance = 0;
var cTemp = new DenseVector(R);
var sigmaTemp = new DenseVector(R);
//foreach input variable
for (int j = 0; j < R; j++)
{
distance = Math.Abs(x[j] - c[j, 0]);
int distanceIndex = 0;
//foreach neuron past 1
for (int k = 1; k < U; k++)
{
//.........这里部分代码省略.........