本文整理汇总了C#中Vector.InnerProduct方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.InnerProduct方法的具体用法?C# Vector.InnerProduct怎么用?C# Vector.InnerProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector
的用法示例。
在下文中一共展示了Vector.InnerProduct方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimpleInnerProduct
public void SimpleInnerProduct()
{
Vector vector1 = new Vector(new double[] { 1.0, 2.0, 3.0 });
Vector vector2 = new Vector(new double[] { 4.0, 5.0, 6.0 });
double result = vector1.InnerProduct(vector2);
Assert.AreEqual((1.0 * 4.0) + (2.0 * 5.0) + (3.0 * 6.0), result);
}
示例2: InnerProductRaiseExceptionIfVectorsHaveDifferenteLengths
public void InnerProductRaiseExceptionIfVectorsHaveDifferenteLengths()
{
Vector vector1 = new Vector(new double[] { 1.0, 2.0, 3.0 });
Vector vector2 = new Vector(new double[] { 4.0, 5.0, 6.0, 7.0 });
try
{
vector1.InnerProduct(vector2);
Assert.Fail();
}
catch (Exception ex)
{
Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
Assert.AreEqual("Vectors have different lengths", ex.Message);
}
}
示例3: vector_inner_product_throws_error_when_orientation_is_the_same
public void vector_inner_product_throws_error_when_orientation_is_the_same()
{
var v1 = new Vector<int>(new int[] { 1, 2, 3 }, Orientation.Row
, AdditiveMonoid.IntAdditionMonoid, MultiplicativeMonoid.IntMultiplicationMonoid);
var v2 = new Vector<int>(new int[] { 1, 2, 3 }, Orientation.Row
, AdditiveMonoid.IntAdditionMonoid, MultiplicativeMonoid.IntMultiplicationMonoid);
var ex = Assert.Throws<ArgumentException>(() => v1.InnerProduct(v2));
Assert.That(ex.Message, Is.EqualTo("Vector<T>.InnerProduct - dot product requires a row vector followed by a column vector"));
}
示例4: vector_inner_product_throws_error_when_vectors_have_different_length
public void vector_inner_product_throws_error_when_vectors_have_different_length()
{
var v1 = new Vector<int>(new int[] { 1, 2, 3 }, Orientation.Row
, AdditiveMonoid.IntAdditionMonoid, MultiplicativeMonoid.IntMultiplicationMonoid);
var v2 = new Vector<int>(new int[] { 1, 2, 3, 4 }, Orientation.Column
, AdditiveMonoid.IntAdditionMonoid, MultiplicativeMonoid.IntMultiplicationMonoid);
var ex = Assert.Throws<ArgumentException>(() => v1.InnerProduct(v2));
Assert.That(ex.Message, Is.EqualTo("Vector<T>.InnerProduct - vectors must have equal length"));
}
示例5: vector_created_with_semiring_inner_product_produces_2norm
public void vector_created_with_semiring_inner_product_produces_2norm()
{
var v1 = new Vector<int>(new int[] { 1, 2, 3 }, Orientation.Row
, new SemiRing<int>(AdditiveMonoid.IntAdditionMonoid, MultiplicativeMonoid.IntMultiplicationMonoid));
var v2 = new Vector<int>(new int[] { 1, 2, 3 }, Orientation.Column
, new SemiRing<int>(AdditiveMonoid.IntAdditionMonoid, MultiplicativeMonoid.IntMultiplicationMonoid));
Assert.That(v1.InnerProduct(v2), Is.EqualTo(14));
}