public static double SingleSimilarity(double x, double y)
{
return (10.0 - Math.Abs(x - y)) * 10.0;
}
// 3 values of user preferences, 3 values of movie assessment
public static double Similarity(Tuple<double, double, double> user, Tuple<double, double, double> movie)
{
return (SingleSimilarity(user.Item1, movie.Item1) + SingleSimilarity(user.Item2, movie.Item2) + SingleSimilarity(user.Item3, movie.Item3)) / 3.0;
}
例:
var similarity = Similarity(Tuple.Create(10.0, 0.0, 5.0), Tuple.Create(0.0, 10.0, 5.0));
またはより一般的な方法:
// 3 items (Action, Drama, Cartoon) each of which contain a value for user and movie
public static double Similarity(IEnumerable<Tuple<double, double>> list)
{
return list.Sum(t => SingleSimilarity(t.Item1, t.Item2)) / list.Count();
}
そして例:
var similarity = Similarity(new[] { Tuple.Create(10.0, 0.0), Tuple.Create(0.0, 10.0), Tuple.Create(5.0, 5.0) });
このような場合、結果は 33.(3) になり、練習のようです。