public void TestDiscardedDistance()
 {
     // Test with different seed weight
     var distance_s1_s2_discarded = 81.65736f;
     var context = new SimilarityContext ();
     context.AddSeeds (new Seed [] { GetSeed (s1, SimilarityContext.DiscardedWeight) });
     Assert.IsFalse (context.IsEmpty);
     Assert.Less (Math.Abs (distance_s1_s2_discarded - context.Distance (Scms.FromBytes (Bytes (s2))).Average ()), 0.1);
 }
        private SimilarityContext GetSimilarityContext(DateTime after, bool playback)
        {
            var context = new SimilarityContext();

            if (!playback)
            {
                // Manually added songs are the strongest postive signal for what we want
                context.AddSeeds(GetSeeds(
                                     "d.ModificationType = 1 AND d.LastModifiedAt IS NOT NULL AND d.LastModifiedAt > ? ORDER BY d.LastModifiedAt DESC",
                                     after, 4, SimilarityContext.SelectedWeight
                                     ));
            }

            // Played songs are the next strongest postive signal for what we want
            context.AddSeeds(GetSeeds(
                                 "t.LastPlayedStamp IS NOT NULL AND t.LastPlayedStamp > MAX (?, coalesce(d.LastModifiedAt, 0), coalesce(t.LastSkippedStamp, 0)) ORDER BY t.LastPlayedStamp DESC",
                                 after, playback ? 4 : 2, SimilarityContext.PlayedWeight
                                 ));

            if (!playback)
            {
                // Shuffled songs that the user hasn't removed are a decent, positive signal
                context.AddSeeds(GetSeeds(
                                     "s.LastShuffledAt IS NOT NULL AND s.LastShuffledAt > MAX (?, coalesce(t.LastPlayedStamp, 0), coalesce(d.LastModifiedAt, 0), coalesce(t.LastSkippedStamp, 0)) ORDER BY s.LastShuffledAt DESC",
                                     after, 2, SimilarityContext.ShuffledWeight
                                     ));

                // Discarded songs are a strong negative signal for what we want
                context.AddSeeds(GetSeeds(
                                     "d.ModificationType = 0 AND d.LastModifiedAt IS NOT NULL AND d.LastModifiedAt > ? ORDER BY d.LastModifiedAt DESC",
                                     after, 3, SimilarityContext.DiscardedWeight
                                     ));
            }

            // Skipped songs are also a strong negative signal for what we want
            context.AddSeeds(GetSeeds(
                                 "t.LastSkippedStamp IS NOT NULL AND t.LastSkippedStamp > ? ORDER BY t.LastSkippedStamp DESC",
                                 after, playback ? 4 : 2, SimilarityContext.SkippedWeight
                                 ));

            return(context);
        }
        private SimilarityContext GetSimilarityContext(DateTime after, bool playback)
        {
            var context = new SimilarityContext ();

            if (!playback) {
                // Manually added songs are the strongest postive signal for what we want
                context.AddSeeds (GetSeeds (
                    "d.ModificationType = 1 AND d.LastModifiedAt IS NOT NULL AND d.LastModifiedAt > ? ORDER BY d.LastModifiedAt DESC",
                    after, 4, SimilarityContext.SelectedWeight
                ));
            }

            // Played songs are the next strongest postive signal for what we want
            context.AddSeeds (GetSeeds (
                "t.LastPlayedStamp IS NOT NULL AND t.LastPlayedStamp > MAX (?, coalesce(d.LastModifiedAt, 0), coalesce(t.LastSkippedStamp, 0)) ORDER BY t.LastPlayedStamp DESC",
                after, playback ? 4 : 2, SimilarityContext.PlayedWeight
            ));

            if (!playback) {
                // Shuffled songs that the user hasn't removed are a decent, positive signal
                context.AddSeeds (GetSeeds (
                    "s.LastShuffledAt IS NOT NULL AND s.LastShuffledAt > MAX (?, coalesce(t.LastPlayedStamp, 0), coalesce(d.LastModifiedAt, 0), coalesce(t.LastSkippedStamp, 0)) ORDER BY s.LastShuffledAt DESC",
                    after, 2, SimilarityContext.ShuffledWeight
                ));

                // Discarded songs are a strong negative signal for what we want
                context.AddSeeds (GetSeeds (
                    "d.ModificationType = 0 AND d.LastModifiedAt IS NOT NULL AND d.LastModifiedAt > ? ORDER BY d.LastModifiedAt DESC",
                    after, 3, SimilarityContext.DiscardedWeight
                ));
            }

            // Skipped songs are also a strong negative signal for what we want
            context.AddSeeds (GetSeeds (
                "t.LastSkippedStamp IS NOT NULL AND t.LastSkippedStamp > ? ORDER BY t.LastSkippedStamp DESC",
                after, playback ? 4 : 2, SimilarityContext.SkippedWeight
            ));

            return context;
        }
        public void TestShuffledDistances()
        {
            var distance_s1_s2 = 27.21912f;
            var context = new SimilarityContext ();
            context.AddSeeds (new Seed [] { GetSeed (s1, SimilarityContext.ShuffledWeight) });
            Assert.IsFalse (context.IsEmpty);
            Assert.Less (Math.Abs (distance_s1_s2 - context.Distance (Scms.FromBytes (Bytes (s2))).Average ()), 0.1);

            // Add the same seed w/ the same weight; make sure the average is the same
            context.AddSeeds (new Seed [] { GetSeed (s1, SimilarityContext.ShuffledWeight) });
            Assert.Less (Math.Abs (distance_s1_s2 - context.Distance (Scms.FromBytes (Bytes (s2))).Average ()), 0.1);
        }
 public void TestSameDistance()
 {
     var context = new SimilarityContext ();
     context.AddSeeds (new Seed [] { GetSeed (s1, 1.0f) });
     Assert.AreEqual (0f, context.Distance (Scms.FromBytes (Bytes (s1))).Average ());
 }
 public void TestEmptyContext()
 {
     var context = new SimilarityContext ();
     Assert.IsTrue (context.IsEmpty);
     Assert.AreEqual (float.MaxValue, context.Distance (null).Average ());
 }