public virtual void TestGetSparseIndex(int sparse1, double sparse1Val, int sparse2, double sparse2Val) { ConcatVector v1 = new ConcatVector(2); ConcatVector v2 = new ConcatVector(2); v1.SetSparseComponent(0, (int)sparse1, sparse1Val); v1.SetSparseComponent(1, (int)sparse2, sparse1Val); v2.SetSparseComponent(0, (int)sparse2, sparse2Val); v2.SetSparseComponent(1, (int)sparse1, sparse2Val); NUnit.Framework.Assert.AreEqual(sparse1, v1.GetSparseIndex(0)); NUnit.Framework.Assert.AreEqual(sparse2, v1.GetSparseIndex(1)); NUnit.Framework.Assert.AreEqual(sparse2, v2.GetSparseIndex(0)); NUnit.Framework.Assert.AreEqual(sparse1, v2.GetSparseIndex(1)); }
/// <summary>This prints out a ConcatVector by mapping to the namespace, to make debugging learning algorithms easier.</summary> /// <param name="vector">the vector to print</param> /// <param name="bw">the output stream to write to</param> /// <exception cref="System.IO.IOException"/> public virtual void DebugVector(ConcatVector vector, BufferedWriter bw) { foreach (string key in featureToIndex.Keys) { bw.Write(key); bw.Write(":\n"); int i = featureToIndex[key]; if (vector.IsComponentSparse(i)) { DebugFeatureValue(key, vector.GetSparseIndex(i), vector, bw); } else { double[] arr = vector.GetDenseComponent(i); for (int j = 0; j < arr.Length; j++) { DebugFeatureValue(key, j, vector, bw); } } } }