static void printData(int user1, int user2) { int[] users = { user1, user2 }; StrategyContext strategy1 = new StrategyContext(new Euclidian()); StrategyContext strategy2 = new StrategyContext(new Manhattan()); StrategyContext strategy3 = new StrategyContext(new Pearsson()); StrategyContext strategy4 = new StrategyContext(new Cosine(), false); Dictionary <int, Dictionary <int, double> > data = Program.getData(); data = DataParser.filterData(data, users[0], users[1], true); var noDelData = DataParser.filterData(data, users[0], users[1], false); if (data[users[0]].Values.Count == 0) { Console.WriteLine("There's no overlap between users " + user1.ToString() + " and " + user2.ToString()); } else { var tuple = DataParser.splitDictionaries(data); var noDelTuple = DataParser.splitDictionaries(noDelData); Console.WriteLine("User " + users[0].ToString() + " -VS- User " + users[1].ToString()); Console.WriteLine("Euclidian - " + strategy1.algorithm(tuple).ToString()); Console.WriteLine("Manhattan - " + strategy2.algorithm(tuple).ToString()); Console.WriteLine("Pearsson - " + strategy3.algorithm(tuple).ToString()); Console.WriteLine("Cosine - " + strategy4.algorithm(noDelTuple)); Console.WriteLine(); } }
public Tuple <int, List <Neighbor> > NearestNeighbor(Dictionary <int, Dictionary <int, double> > data, int target, double threshold = 0.35, int amount = 3) { List <Neighbor> neighbors = new List <Neighbor>(); var currentThreshold = threshold; if (data.ContainsKey(target)) { foreach (var user in data) { if (user.Key != target) { var filterData = DataParser.splitDictionaries(DataParser.filterData(data, target, user.Key, this.delete)); double result = strategy.algorithm(filterData); var dataaaa = data[target]; if (result > currentThreshold && user.Value.Except(data[target]).Count() > 0) { if (neighbors.Count == amount) { var lowestNeighbor = neighbors.Aggregate((item1, item2) => item1.similarity < item2.similarity ? item1 : item2); neighbors.Remove(lowestNeighbor); neighbors.Add(new Neighbor(user.Key, result, user.Value)); currentThreshold = neighbors.Aggregate((item1, item2) => item1.similarity < item2.similarity ? item1 : item2).similarity; } else { neighbors.Add(new Neighbor(user.Key, result, user.Value)); } } } } return(new Tuple <int, List <Neighbor> >(target, neighbors)); } else { return(new Tuple <int, List <Neighbor> >(target, new List <Neighbor>())); } }
public static void printData(int user1, int user2) { int[] users = { user1, user2 }; StrategyContext strategy1 = new StrategyContext(new Euclidian()); StrategyContext strategy2 = new StrategyContext(new Manhattan()); StrategyContext strategy3 = new StrategyContext(new Pearsson()); var data = DataParser.filterData(DataParser.write2DArray("./userData.data", ","), users[0], users[1], true); var dataNoDel = DataParser.filterData(data, users[0], users[1], false); var tuple = DataParser.splitDictionaries(data); var tupleNoDel = DataParser.splitDictionaries(dataNoDel); ////////////////////// FRONTEND \\\\\\\\\\\\\\\\\\\\\\ Console.WriteLine("User " + users[0].ToString() + " -VS- User " + users[1].ToString()); Console.WriteLine("Euclidian - " + strategy1.algorithm(tuple).ToString()); Console.WriteLine("Manhattan - " + strategy2.algorithm(tuple).ToString()); Console.WriteLine("Pearsson - " + strategy3.algorithm(tupleNoDel).ToString()); Console.WriteLine(); }