本文整理汇总了C#中Vector.CreateVector方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.CreateVector方法的具体用法?C# Vector.CreateVector怎么用?C# Vector.CreateVector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector
的用法示例。
在下文中一共展示了Vector.CreateVector方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Multiply
/// <summary>
/// Multiplies this matrix with a vector and places the results into the result matrix.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If <strong>result.Count != this.RowCount</strong>.</exception>
/// <exception cref="ArgumentException">If <strong>this.ColumnCount != <paramref name="rightSide"/>.Count</strong>.</exception>
public override void Multiply(Vector<Complex32> rightSide, Vector<Complex32> result)
{
if (rightSide == null)
{
throw new ArgumentNullException("rightSide");
}
if (ColumnCount != rightSide.Count)
{
throw new ArgumentException(Resources.ArgumentMatrixDimensions, "rightSide");
}
if (result == null)
{
throw new ArgumentNullException("result");
}
if (RowCount != result.Count)
{
throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result");
}
if (ReferenceEquals(rightSide, result))
{
var tmp = result.CreateVector(result.Count);
Multiply(rightSide, tmp);
tmp.CopyTo(result);
}
else
{
// Clear the result vector
result.Clear();
// Multiply the elements in the vector with the corresponding diagonal element in this.
for (var r = 0; r < Data.Length; r++)
{
result[r] = Data[r] * rightSide[r];
}
}
}
示例2: LeftMultiply
/// <summary>
/// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
/// </summary>
/// <param name="leftSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException">If the result matrix is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If <strong>result.Count != this.ColumnCount</strong>.</exception>
/// <exception cref="ArgumentException">If <strong>this.RowCount != <paramref name="leftSide"/>.Count</strong>.</exception>
public override void LeftMultiply(Vector<double> leftSide, Vector<double> result)
{
if (leftSide == null)
{
throw new ArgumentNullException("leftSide");
}
if (RowCount != leftSide.Count)
{
throw DimensionsDontMatch<ArgumentException>(this, leftSide, "leftSide");
}
if (result == null)
{
throw new ArgumentNullException("result");
}
if (ColumnCount != result.Count)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
}
if (ReferenceEquals(leftSide, result))
{
var tmp = result.CreateVector(result.Count);
LeftMultiply(leftSide, tmp);
tmp.CopyTo(result);
}
else
{
// Clear the result vector
result.Clear();
// Multiply the elements in the vector with the corresponding diagonal element in this.
for (var r = 0; r < _data.Length; r++)
{
result[r] = _data[r] * leftSide[r];
}
}
}
示例3: Subtract
/// <summary>
/// Subtracts another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to subtract from this one.</param>
/// <param name="result">The vector to store the result of the subtraction.</param>
/// <exception cref="ArgumentNullException">If the other vector is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">If the result vector is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception>
public override void Subtract(Vector other, Vector result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (Count != other.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "other");
}
if (Count != result.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
if (ReferenceEquals(this, result) || ReferenceEquals(other, result))
{
var tmp = result.CreateVector(result.Count);
Subtract(other, tmp);
tmp.CopyTo(result);
}
else
{
var rdense = result as DenseVector;
var odense = other as DenseVector;
if (rdense != null && odense != null)
{
CopyTo(result);
Control.LinearAlgebraProvider.AddVectorToScaledVector(rdense.Data, -1.0, odense.Data);
}
else
{
CommonParallel.For(
0,
Data.Length,
index => result[index] = this.Data[index] - other[index]);
}
}
}
示例4: Add
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to add to this one.</param>
/// <param name="result">The vector to store the result of the addition.</param>
/// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException">If the result vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception>
public override void Add(Vector other, Vector result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (this.Count != other.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "other");
}
if (this.Count != result.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
if (ReferenceEquals(this, result) || ReferenceEquals(other, result))
{
var tmp = result.CreateVector(result.Count);
Add(other, tmp);
tmp.CopyTo(result);
}
else
{
this.CopyTo(result);
result.Add(other);
}
}
示例5: Multiply
/// <summary>
/// Multiplies this matrix with a vector and places the results into the result matrix.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If <strong>result.Count != this.RowCount</strong>.</exception>
/// <exception cref="ArgumentException">If <strong>this.ColumnCount != <paramref name="rightSide"/>.Count</strong>.</exception>
public virtual void Multiply(Vector rightSide, Vector result)
{
if (rightSide == null)
{
throw new ArgumentNullException("rightSide");
}
if (ColumnCount != rightSide.Count)
{
throw new ArgumentException(Resources.ArgumentMatrixDimensions, "rightSide");
}
if (result == null)
{
throw new ArgumentNullException("result");
}
if (RowCount != result.Count)
{
throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result");
}
if (ReferenceEquals(rightSide, result))
{
var tmp = result.CreateVector(result.Count);
Multiply(rightSide, tmp);
tmp.CopyTo(result);
}
else
{
CommonParallel.For(
0,
RowCount,
i =>
{
double s = 0;
for (var j = 0; j != ColumnCount; j++)
{
s += At(i, j) * rightSide[j];
}
result[i] = s;
});
}
}
示例6: PointwiseMultiply
/// <summary>
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise multiply with this one.</param>
/// <param name="result">The vector to store the result of the pointwise multiplication.</param>
/// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException">If the result vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception>
public override void PointwiseMultiply(Vector other, Vector result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (other == null)
{
throw new ArgumentNullException("other");
}
if (Count != other.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "other");
}
if (Count != result.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
if (ReferenceEquals(this, result) || ReferenceEquals(other, result))
{
var tmp = result.CreateVector(result.Count);
PointwiseMultiply(other, tmp);
tmp.CopyTo(result);
}
else
{
var dense = result as DenseVector;
if (dense == null)
{
base.PointwiseMultiply(other, result);
}
else
{
CommonParallel.For(
0,
Data.Length,
index => dense.Data[index] = this.Data[index] * other[index]);
}
}
}
示例7: LeftMultiply
/// <summary>
/// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
/// </summary>
/// <param name="leftSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException">If the result matrix is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If <strong>result.Count != this.ColumnCount</strong>.</exception>
/// <exception cref="ArgumentException">If <strong>this.RowCount != <paramref name="leftSide"/>.Count</strong>.</exception>
public virtual void LeftMultiply(Vector leftSide, Vector result)
{
if (leftSide == null)
{
throw new ArgumentNullException("leftSide");
}
if (RowCount != leftSide.Count)
{
throw new ArgumentException(Resources.ArgumentMatrixDimensions, "leftSide");
}
if (result == null)
{
throw new ArgumentNullException("result");
}
if (ColumnCount != result.Count)
{
throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result");
}
if (ReferenceEquals(leftSide, result))
{
var tmp = result.CreateVector(result.Count);
LeftMultiply(leftSide, tmp);
tmp.CopyTo(result);
}
else
{
CommonParallel.For(
0,
RowCount,
j =>
{
double s = 0;
for (var i = 0; i != leftSide.Count; i++)
{
s += leftSide[i] * At(i, j);
}
result[j] = s;
});
}
}
示例8: Solve
/// <summary>
/// Solves a system of linear equations, <b>Ax = b</b>, with A Cholesky factorized.
/// </summary>
/// <param name="input">The right hand side vector, <b>b</b>.</param>
/// <returns>The left hand side <see cref="Vector"/>, <b>x</b>.</returns>
public virtual Vector Solve(Vector input)
{
// Check for proper arguments.
if (input == null)
{
throw new ArgumentNullException("input");
}
var x = input.CreateVector(input.Count);
Solve(input, x);
return x;
}
示例9: Sigmoid
private Vector<double> Sigmoid(Vector<double> v)
{
var ret = v.CreateVector(v.Count);
for (int i = 0; i < v.Count; i++)
{
var a = Math.Exp(v[i]);
a = 1 / a;
a = 1 + a;
a = 1 / a;
ret[i] = a;
}
return ret;
}
示例10: Prepend
private Vector<double> Prepend(double val, Vector<double> v)
{
var ret = v.CreateVector(v.Count + 1);
ret[0] = val;
for (int i = 0; i < v.Count; i++)
{
ret[i + 1] = v[i];
}
return ret;
}
示例11: OneMinusV
private Vector<double> OneMinusV(Vector<double> v)
{
var ret = v.CreateVector(v.Count);
for (int i = 0; i < v.Count; i++)
{
ret[i] = 1 - v[i];
}
return ret;
}