本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Double.DenseVector.SubVector方法的典型用法代码示例。如果您正苦于以下问题:C# DenseVector.SubVector方法的具体用法?C# DenseVector.SubVector怎么用?C# DenseVector.SubVector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MathNet.Numerics.LinearAlgebra.Double.DenseVector
的用法示例。
在下文中一共展示了DenseVector.SubVector方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: transformMoments
public double[] transformMoments(double[] forces)
{
double[] fforce = new double[6];
forces.CopyTo(fforce, 0);
DenseVector forceV = new DenseVector(fforce);
DenseVector tforce = (DenseVector)forceV.SubVector(0, 3);
DenseVector moments = (DenseVector)forceV.SubVector(3, 3);
DenseVectorCrossProduct crs = new DenseVectorCrossProduct(tforce);
moments = (DenseVector)crs.crossProduct(directionalVector).Add(moments);
forceV.SetSubVector(3, 3, moments);
return forceV.Values;
}
示例2: VarianceRatioTest
public void VarianceRatioTest(double[] data, int lag = 1, TimeSeriesType cor = TimeSeriesType.HOM)
{
DenseVector x = new DenseVector(data);
//Mean
double mu = x.Mean();
//Variance for 1st Order Difference
double s1 = (x.SubVector(lag, x.Count - lag) - x.SubVector(0, x.Count - 2)).Variance();
double dLag = lag;
double varvrt = double.NaN;
switch (cor)
{
case TimeSeriesType.HOM:
{
varvrt = 2*(2*dLag - 1)*(dLag - 1)/(3*dLag*x.Count);
break;
}
case TimeSeriesType.HET:
{
varvrt = 0;
double sum2 = 0;
for (int j = 0; j < lag; j++)
{
double sum1a = 0; //(x(j+2:n)-x(j+1:n-1)-mu).^2
double sum1b = 0; //(x(2:n-j)-x(1:n-j-1)-mu).^2;
double sum1 = sum1a*sum1b;
double delta = sum1/(Math.Pow(sum2, 2));
varvrt += 0; //(2*(q(i)-j)/q(i))^2)*delta;
}
break;
}
}
ZScore = (VRatio - 1)/Math.Sqrt(varvrt);
PValue = NormCDF(ZScore);
}
示例3: Run
/// <summary>
/// Run example
/// </summary>
public void Run()
{
// Format vector output to console
var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();
formatProvider.TextInfo.ListSeparator = " ";
// Create new empty vector
var vectorA = new DenseVector(10);
Console.WriteLine(@"Empty vector A");
Console.WriteLine(vectorA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 1. Fill vector by data using indexer []
for (var i = 0; i < vectorA.Count; i++)
{
vectorA[i] = i;
}
Console.WriteLine(@"1. Fill vector by data using indexer []");
Console.WriteLine(vectorA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 2. Fill vector by data using SetValues method
vectorA.SetValues(new[] { 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0 });
Console.WriteLine(@"2. Fill vector by data using SetValues method");
Console.WriteLine(vectorA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 3. Convert Vector to double[]
var data = vectorA.ToArray();
Console.WriteLine(@"3. Convert vector to double array");
for (var i = 0; i < data.Length; i++)
{
Console.Write(data[i].ToString("#0.00\t", formatProvider) + @" ");
}
Console.WriteLine();
Console.WriteLine();
// 4. Convert Vector to column matrix. A matrix based on this vector in column form (one single column)
var columnMatrix = vectorA.ToColumnMatrix();
Console.WriteLine(@"4. Convert vector to column matrix");
Console.WriteLine(columnMatrix.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 5. Convert Vector to row matrix. A matrix based on this vector in row form (one single row)
var rowMatrix = vectorA.ToRowMatrix();
Console.WriteLine(@"5. Convert vector to row matrix");
Console.WriteLine(rowMatrix.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 6. Clone vector
var cloneA = vectorA.Clone();
Console.WriteLine(@"6. Clone vector");
Console.WriteLine(cloneA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 7. Clear vector
cloneA.Clear();
Console.WriteLine(@"7. Clear vector");
Console.WriteLine(cloneA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 8. Copy part of vector into another vector. If you need to copy all data then use CopoTy(vector) method.
vectorA.CopySubVectorTo(cloneA, 3, 3, 4);
Console.WriteLine(@"8. Copy part of vector into another vector");
Console.WriteLine(cloneA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 9. Get part of vector as another vector
var subvector = vectorA.SubVector(0, 5);
Console.WriteLine(@"9. Get subvector");
Console.WriteLine(subvector.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 10. Enumerator usage
Console.WriteLine(@"10. Enumerator usage");
foreach (var value in vectorA)
{
Console.Write(value.ToString("#0.00\t", formatProvider) + @" ");
}
Console.WriteLine();
Console.WriteLine();
// 11. Indexed enumerator usage
Console.WriteLine(@"11. Enumerator usage");
foreach (var value in vectorA.GetIndexedEnumerator())
{
Console.WriteLine(@"Index = {0}; Value = {1}", value.Item1, value.Item2.ToString("#0.00\t", formatProvider));
}
Console.WriteLine();
}
示例4: ComputeJacobianForLine_Numerical
// Computes d(ei)/d(P) for ith line numericaly
public void ComputeJacobianForLine_Numerical(Matrix<double> J, int l, int p0)
{
Vector<double> error_n = new DenseVector(_currentErrorVector.Count);
Vector<double> error_p = new DenseVector(_currentErrorVector.Count);
for(int k = 0; k < DistortionModel.ParametersCount; ++k)
{
double oldK = DistortionModel.Parameters[k];
double k_n = Math.Abs(oldK) > float.Epsilon ? oldK * (1 - NumericalDerivativeStep) : -NumericalDerivativeStep * 0.01;
double k_p = Math.Abs(oldK) > float.Epsilon ? oldK * (1 + NumericalDerivativeStep) : NumericalDerivativeStep * 0.01;
DistortionModel.Parameters[k] = k_n;
UpdateAll(l);
ComputeErrorVector(error_n);
Vector<double> error_n_line = error_n.SubVector(p0, LinePoints[l].Count);
DistortionModel.Parameters[k] = k_p;
UpdateAll(l);
ComputeErrorVector(error_p);
Vector<double> error_p_line = error_p.SubVector(p0, LinePoints[l].Count);
Vector<double> diff_e = (1.0 / (k_p - k_n)) * (error_p_line - error_n_line);
J.SetColumn(k, p0, LinePoints[l].Count, diff_e);
DistortionModel.Parameters[k] = oldK;
// Throw if NaN found in jacobian
bool nanInfFound = diff_e.Exists((e) => { return double.IsNaN(e) || double.IsInfinity(e); });
if(nanInfFound)
{
throw new DivideByZeroException("NaN or Infinity found on jacobian");
}
}
UpdateAll(l);
}