public void testFromCorrelation() { IDataModel dataModel = getDataModel( new long[] { 1, 2, 3 }, new Double?[][] { new double?[] { 1.0, 2.0 }, new double?[] { 2.0, 5.0 }, new double?[] { 3.0, 6.0 }, }); IItemSimilarity otherSimilarity = new PearsonCorrelationSimilarity(dataModel); IItemSimilarity itemSimilarity = new GenericItemSimilarity(otherSimilarity, dataModel); assertCorrelationEquals(1.0, itemSimilarity.ItemSimilarity(0, 0)); assertCorrelationEquals(0.960768922830523, itemSimilarity.ItemSimilarity(0, 1)); }
public void testSimple() { List <GenericItemSimilarity.ItemItemSimilarity> similarities = new List <GenericItemSimilarity.ItemItemSimilarity>(); similarities.Add(new GenericItemSimilarity.ItemItemSimilarity(1, 2, 0.5)); similarities.Add(new GenericItemSimilarity.ItemItemSimilarity(2, 1, 0.6)); similarities.Add(new GenericItemSimilarity.ItemItemSimilarity(1, 1, 0.5)); similarities.Add(new GenericItemSimilarity.ItemItemSimilarity(1, 3, 0.3)); GenericItemSimilarity itemCorrelation = new GenericItemSimilarity(similarities); Assert.AreEqual(1.0, itemCorrelation.ItemSimilarity(1, 1), EPSILON); Assert.AreEqual(0.6, itemCorrelation.ItemSimilarity(1, 2), EPSILON); Assert.AreEqual(0.6, itemCorrelation.ItemSimilarity(2, 1), EPSILON); Assert.AreEqual(0.3, itemCorrelation.ItemSimilarity(1, 3), EPSILON); Assert.True(Double.IsNaN(itemCorrelation.ItemSimilarity(3, 4))); }