public virtual ConcatVector ToNamespaceVector(ConcatVectorNamespace @namespace, IDictionary <int, int> featureMap) { ConcatVector newVector = @namespace.NewVector(); foreach (int i in featureMap.Keys) { string feature = "feat" + i; string sparse = "index" + featureMap[i]; @namespace.SetSparseFeature(newVector, feature, sparse, 1.0); } return(newVector); }
public virtual void TestResizeOnSetComponent(IDictionary <int, int> featureMap1, IDictionary <int, int> featureMap2) { ConcatVectorNamespace @namespace = new ConcatVectorNamespace(); ConcatVector namespace1 = ToNamespaceVector(@namespace, (IDictionary <int, int>)featureMap1); ConcatVector namespace2 = ToNamespaceVector(@namespace, (IDictionary <int, int>)featureMap2); ConcatVector regular1 = ToVector((IDictionary <int, int>)featureMap1); ConcatVector regular2 = ToVector((IDictionary <int, int>)featureMap2); NUnit.Framework.Assert.AreEqual(namespace1.DotProduct(namespace2), 1.0e-5, regular1.DotProduct(regular2)); ConcatVector namespaceSum = namespace1.DeepClone(); namespaceSum.AddVectorInPlace(namespace2, 1.0); ConcatVector regularSum = regular1.DeepClone(); regularSum.AddVectorInPlace(regular2, 1.0); NUnit.Framework.Assert.AreEqual(namespace1.DotProduct(namespaceSum), 1.0e-5, regular1.DotProduct(regularSum)); NUnit.Framework.Assert.AreEqual(namespaceSum.DotProduct(namespace2), 1.0e-5, regularSum.DotProduct(regular2)); }