static void Main(string[] args) { string path = AppDomain.CurrentDomain.BaseDirectory + @"friendships.reviews.txt"; string data = System.IO.File.ReadAllText(path); List <User> userList = new List <User>(); int idCounter = 0; Control.UseNativeMKL(); Control.UseMultiThreading(); string[] text = data.Split("\r\n"); for (int i = 0; i < text.Length; i += 5) { User u = new User(idCounter, text[i].Split(" ")[1], text[i + 1].TrimStart("friends: ".ToCharArray()).TrimStart().Split("\t"), text[i + 2].Split("summary: ")[1], text[i + 3].Split("review: ")[1]); userList.Add(u); idCounter++; } Matrix <double> diagonalMatrix; Matrix <double> associationMatrix = FillMatrix(userList, out diagonalMatrix); Matrix <double> laplacianMatrix = diagonalMatrix - associationMatrix; Evd <double> eigen = laplacianMatrix.Evd(Symmetricity.Symmetric); var eigenVectors = eigen.EigenVectors.ToRowArrays(); var sortedVectors = eigenVectors.OrderBy(x => x[1]).ToList(); List <List <double[]> > communities = MaxCutCommunity(9, userList, eigenVectors.ToList()); Classifier classifier = new Classifier(); List <double> reviewScores = new List <double>(); classifier.Classify(userList); Dictionary <User, string> userDic = classifier.WillUsersBuyProduct(userList); Console.ReadKey(); }
static void Main(string[] args) { Control.UseNativeMKL(); Control.UseMultiThreading(); string buyResult = AppDomain.CurrentDomain.BaseDirectory + "buyResult.txt"; string path = AppDomain.CurrentDomain.BaseDirectory + @"friendships.reviews.txt"; string data = System.IO.File.ReadAllText(path); string[] text = data.Split("\r\n"); string pathResults = AppDomain.CurrentDomain.BaseDirectory + @"friendships.reviews.results.txt"; string dataResults = File.ReadAllText(pathResults); string[] textResults = dataResults.Split("\r\n"); WITools tools = new WITools(); List <User> userList = tools.InitUsers(text); //List<double[]> sortedVectors = tools.GetEigenVectors(userList).OrderBy(x => x[1]).ToList(); //List<List<double[]>> communities = tools.MaxCutCommunity(9, sortedVectors); var ev = tools.GetEigenVectors(userList); int index = 0; foreach (User user in userList) { user.SetEV(ev[index]); index++; } tools.AssignCommunities(9, userList); foreach (User user in userList) { Console.WriteLine(user.ToString() + " - IS IN COMMUNITY: " + user.communityID); } Classifier classifier = new Classifier(); classifier.Classify(userList); Dictionary <User, string> userDic = classifier.WillUsersBuyProduct(userList); StreamWriter sw = new StreamWriter(buyResult); int i = 3; foreach (var entry in userDic) { string assertionValue = ""; if (textResults[i].Split("purchase: ")[1] == "yes") { if (userDic[entry.Key] == "Will buy product!") { assertionValue = $"{entry.Key} assertion is CORRECT"; Console.WriteLine($"{entry.Key} assertion is CORRECT"); } else { assertionValue = $"{entry.Key} assertion is NOT CORRECT"; Console.WriteLine($"{entry.Key} assertion is NOT CORRECT"); } } else if (textResults[i].Split("purchase: ")[1] == "no") { if (userDic[entry.Key] == "Will not buy product!") { assertionValue = $"{entry.Key} assertion is CORRECT"; Console.WriteLine($"{entry.Key} assertion is CORRECT"); } else { assertionValue = $"{entry.Key} assertion is NOT CORRECT"; Console.WriteLine($"{entry.Key} assertion is NOT CORRECT"); } } sw.WriteLine(entry.Key + " - " + entry.Key.communityID + " - " + userDic[entry.Key] + " - " + assertionValue); i = i + 8; } Console.ReadKey(); }