本文整理汇总了C#中SparseVector类的典型用法代码示例。如果您正苦于以下问题:C# SparseVector类的具体用法?C# SparseVector怎么用?C# SparseVector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SparseVector类属于命名空间,在下文中一共展示了SparseVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanConvertArrayToSparseVector
public void CanConvertArrayToSparseVector()
{
var array = new[] { new Complex(1, 1), new Complex(2, 1), new Complex(3, 1), new Complex(4, 1) };
var vector = new SparseVector(array);
Assert.IsInstanceOf(typeof(SparseVector), vector);
CollectionAssert.AreEqual(array, array);
}
示例2: GetProof
public ExampleSet GetProof(SparseVector x)
{
ExampleSet res = new ExampleSet();
List<ExampleDistancePair> list = new List<ExampleDistancePair>();
foreach (Example e in m_t_set.Examples)
{
list.Add(new ExampleDistancePair(e, SparseVector.Distance(x, e.X)));
}
list.Sort();
int[] votes = new int[m_catnum];
for (int i = 0; i < votes.Length; i++)
{
votes[i] = 0;
}
for (int i = 0; i < this.m_k; i++)
{
ExampleDistancePair pair = list[i];
res.AddExample(pair.Example);
}
return res;
}
示例3: Compute
public double Compute(SparseVector x, SparseVector z)
{
double temp;
temp = ((SparseVector)(x - z)).Magnitude;
return Math.Exp(-sigma * (temp * temp));
}
示例4: CanConvertSparseVectorToArray
public void CanConvertSparseVectorToArray()
{
var vector = new SparseVector(Data);
var array = vector.ToArray();
Assert.IsInstanceOf(typeof(double[]), array);
CollectionAssert.AreEqual(vector, array);
}
示例5: AverageLogFactor
//-- VMP -------------------------------------------------------------------------------------------
/// <summary>
/// Evidence message for VMP
/// </summary>
/// <param name="sample">Incoming message from 'sample'. Must be a proper distribution. If any element is uniform, the result will be uniform.</param>
/// <param name="probsTrue">Incoming message from 'probsTrue'. Must be a proper distribution. If any element is uniform, the result will be uniform.</param>
/// <param name="MeanLog">Buffer 'MeanLog'.</param>
/// <param name="MeanLogOneMinus">Buffer 'MeanLogOneMinus'.</param>
/// <returns>Average of the factor's log-value across the given argument distributions</returns>
/// <remarks><para>
/// The formula for the result is <c>sum_(sample,probsTrue) p(sample,probsTrue) log(factor(sample,probsTrue))</c>.
/// Adding up these values across all factors and variables gives the log-evidence estimate for VMP.
/// </para></remarks>
/// <exception cref="ImproperMessageException"><paramref name="sample"/> is not a proper distribution</exception>
/// <exception cref="ImproperMessageException"><paramref name="probsTrue"/> is not a proper distribution</exception>
public static double AverageLogFactor([Proper] SparseBernoulliListBase sample,
[Proper] SparseBetaList probsTrue, SparseVector MeanLog, SparseVector MeanLogOneMinus)
{
//var MeanLogOneMinus = probsTrue.GetMeanLogOneMinus();
var p = sample.GetProbTrueVector();
var res = p * MeanLog + (1 - p) * MeanLogOneMinus;
return res.Sum();
}
示例6: AddInPlace
/// <summary>
/// Adds each element of vec to corresponding element of addTo vector
/// addTo vector is being changed in place
/// </summary>
public static void AddInPlace(SparseVector<double> addTo, SparseVector<double> vec)
{
foreach (var vecIdx in vec.InnerIdx)
{
var num = addTo.TryGet(vecIdx, 0.0);
addTo[vecIdx] = num + vec[vecIdx];
}
}
示例7: Multiply
public static SparseVector<double> Multiply(double scalar, SparseVector<double> vector)
{
var newVector = vector.DeepClone();
for (int i = 0; i < newVector.InnerDat.Count; i++ )
{
newVector.SetDirect(i, newVector.InnerDat[i] * scalar);
}
return newVector;
}
示例8: CanCallUnaryNegationOperatorOnSparseVector
public void CanCallUnaryNegationOperatorOnSparseVector()
{
var vector = new SparseVector(_data);
var other = -vector;
for (var i = 0; i < _data.Length; i++)
{
Assert.AreEqual(-_data[i], other[i]);
}
}
示例9: AddRowTestAddsRowWithGivenVector
public void AddRowTestAddsRowWithGivenVector()
{
SparseVector v = new SparseVector(TestMatrix.Columns);
v[2] = 5.1f;
TestMatrix.AddRow(v);
float expected = 5.1f;
Assert.AreEqual(expected, TestMatrix[3, 2]);
}
示例10: CreateVector
/// <summary>
/// Creates a new instance of the Vector class.
/// </summary>
/// <param name="data">The array to create this vector from.</param>
/// <returns>The new <c>Vector</c>.</returns>
protected override Vector<double> CreateVector(IList<double> data)
{
var vector = new SparseVector(data.Count);
for (var index = 0; index < data.Count; index++)
{
vector[index] = data[index];
}
return vector;
}
示例11: ConstructorThrowsArgumentNullExceptionIfNullArgumentPassed
public void ConstructorThrowsArgumentNullExceptionIfNullArgumentPassed()
{
// arrange
// act
var sv = new SparseVector<double>(null);
// assert
Assert.Fail("SparseVector ctor must throw ArgumentNullException if null argument passed.");
}
示例12: DivideInPlace
/// <summary>
/// Divides each element of dividee with corresponding element of divisor in place
/// Dividee is being changed
/// </summary>
public static void DivideInPlace(SparseVector<double> dividee, SparseVector<double> divisor)
{
foreach (var divIdx in divisor.InnerIdx)
{
var num = dividee.TryGet(divIdx, 0.0);
if (num < Double.Epsilon)
continue;
dividee[divIdx] = num/divisor[divIdx];
}
}
示例13: CanCreateSparseVectorFromArray
public void CanCreateSparseVectorFromArray()
{
var data = new double[Data.Length];
Array.Copy(Data, data, Data.Length);
var vector = new SparseVector(data);
for (var i = 0; i < data.Length; i++)
{
Assert.AreEqual(data[i], vector[i]);
}
}
示例14: Binary_SVM_SMO
public Binary_SVM_SMO(int n)
{
this.m_NonBound = new List<int>();
this.m_rand = new Random();
this.m_weight = new SparseVector(n);
// foamliu, 2008/12/29, default values
this.m_c = Constants.SVM_C;
this.m_eta = Constants.SVM_Eta;
this.m_tolerance = Constants.SVM_Tolerance;
this.m_epsilon = Constants.SVM_Epsilon;
}
示例15: AddColumnTestAddsColumnWithGivenValue
public void AddColumnTestAddsColumnWithGivenValue()
{
SparseVector expected = new SparseVector(TestMatrix.Rows);
expected[0] = 5.0f;
expected[1] = 5.0f;
expected[2] = 5.0f;
TestMatrix.AddColumn(5.0f);
Assert.IsTrue(expected.ApproximatelyEqual(
TestMatrix.ColumnVector(TestMatrix.Columns - 1)));
}