本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Double.DenseVector.MapInplace方法的典型用法代码示例。如果您正苦于以下问题:C# DenseVector.MapInplace方法的具体用法?C# DenseVector.MapInplace怎么用?C# DenseVector.MapInplace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MathNet.Numerics.LinearAlgebra.Double.DenseVector
的用法示例。
在下文中一共展示了DenseVector.MapInplace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CenterData
/// <summary>
/// Centers data to have mean zero along axis 0. This is here because
/// nearly all linear models will want their data to be centered.
/// If sample_weight is not None, then the weighted mean of X and y
/// is zero, and not the mean itself
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="fitIntercept"></param>
/// <param name="normalize"></param>
/// <param name="sampleWeight"></param>
internal static CenterDataResult CenterData(
Matrix<double> x,
Matrix<double> y,
bool fitIntercept,
bool normalize = false,
Vector<double> sampleWeight = null)
{
Vector<double> xMean;
Vector<double> yMean = new DenseVector(y.ColumnCount);
Vector<double> xStd;
if (fitIntercept)
{
if (x is SparseMatrix)
{
xMean = DenseVector.Create(x.ColumnCount, i => 0.0);
xStd = DenseVector.Create(x.ColumnCount, i => 1.0);
}
else
{
if (sampleWeight == null)
{
xMean = x.MeanOfEveryColumn();
}
else
{
xMean = x.MulColumnVector(sampleWeight).SumOfEveryColumn().Divide(sampleWeight.Sum());
}
x = x.SubtractRowVector(xMean);
if (normalize)
{
xStd = new DenseVector(x.ColumnCount);
foreach (var row in x.RowEnumerator())
{
xStd.Add(row.Item2.PointwiseMultiply(row.Item2), xStd);
}
xStd.MapInplace(Math.Sqrt);
for (int i = 0; i < xStd.Count; i++)
{
if (xStd[i] == 0)
{
xStd[i] = 1;
}
}
x.DivRowVector(xStd, x);
}
else
{
xStd = DenseVector.Create(x.ColumnCount, i => 1.0);
}
}
if (sampleWeight == null)
{
yMean = y.MeanOfEveryColumn();
}
else
{
yMean = y.MulColumnVector(sampleWeight).SumOfEveryColumn() / sampleWeight.Sum();
}
y = y.Clone();
y = y.SubtractRowVector(yMean);
}
else
{
xMean = DenseVector.Create(x.ColumnCount, i => 0);
xStd = DenseVector.Create(x.ColumnCount, i => 1);
}
return new CenterDataResult { X = x, Y = y, xMean = xMean, yMean = yMean, xStd = xStd };
}