public void ReviewersThatHaveReviewedUniqueTitlesShouldNotBeSimilar() { var r1 = ReviewerBuilder.BuildReviewer1(); var r2 = ReviewerBuilder.BuildAReviewerThatReviewedSomethingUnique(); pearsonCorrelationScore = new PearsonCorrelation(r1, r2); Assert.AreEqual(0, pearsonCorrelationScore.Score()); }
private static void RunPearsonCorrelationWithLowScore() { var r1 = ReviewerBuilder.BuildReviewer1(); var r2 = ReviewerBuilder.BuildReviewer2(); var pearsonCorrelation = new PearsonCorrelation(r1, r2); Console.WriteLine("The Pearson Correlation between {0} and {1} is: {2}", r1.Name, r2.Name, pearsonCorrelation.Score()); }
public void TestFile() { UserCorrelation userCorrelation = new PearsonCorrelation(model); UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, userCorrelation, model); Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, userCorrelation); Assert.AreEqual(2, recommender.Recommend("A123", 3).Count); Assert.AreEqual(2, recommender.Recommend("B234", 3).Count); Assert.AreEqual(1, recommender.Recommend("C345", 3).Count); // Make sure this doesn't throw an exception model.Refresh(); }
public void TestBestRating() { List <User> users = new List <User>(4); users.Add(GetUser("test1", 0.1, 0.3)); users.Add(GetUser("test2", 0.2, 0.3, 0.3)); users.Add(GetUser("test3", 0.4, 0.3, 0.5)); users.Add(GetUser("test4", 0.7, 0.3, 0.8)); DataModel dataModel = new GenericDataModel(users); UserCorrelation correlation = new PearsonCorrelation(dataModel); ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation); Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2); IList <RecommendedItem> recommended = recommender.Recommend("test1", 1); Assert.IsNotNull(recommended); Assert.AreEqual(1, recommended.Count); RecommendedItem firstRecommended = recommended[0]; // item one should be recommended because it has a greater rating/score Assert.AreEqual(new GenericItem <String>("2"), firstRecommended.Item); Assert.AreEqual(0.3, firstRecommended.Value, EPSILON); }
public void TwoReviewersWithSomeSimilarReviewsShouldHaveTheSameScoreRegardlessOfOrder() { pearsonCorrelationScore = new PearsonCorrelation(ReviewerBuilder.BuildReviewer7(), ReviewerBuilder.BuildReviewer6()); Assert.AreEqual(0.396, pearsonCorrelationScore.Score()); }
public void SetUp() { pearsonCorrelationScore = new PearsonCorrelation(ReviewerBuilder.BuildReviewer1(), ReviewerBuilder.BuildReviewer2()); }
public void ReviewersThatHaveTheSameTasteShouldHaveAPerfectScore() { var r1 = ReviewerBuilder.BuildReviewer1(); pearsonCorrelationScore = new PearsonCorrelation(r1, r1); Assert.AreEqual(1.0, pearsonCorrelationScore.Score()); }
static void Main(string[] args) { // Specify which files to use. var projectDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName; var pathFiles = Directory.EnumerateFiles(projectDir + @"\DocumentClusteringExample\Samples").ToList(); // Hyper parameters. // This option prevent overfitting on missing words. var replaceMissingValueWithRandomValue = false; var usePCA = false; var numberOfOutputPCA = 100; var distanceFunction = new PearsonCorrelation(); var strategy = ValueStrategy.Freq; var minVectorElements = 2; var freqMin = 2; var minWordCount = 1; var maxWordCount = 3; var minGroupOfWordsLength = 3; var minWordLength = 1; var firstWordMinLength = 1; var lastWordMinLength = 1; var maxComposition = int.MaxValue; var badWords = File.ReadLines(projectDir + @"\DocumentClusteringExample\stop-words-english.txt") .Where(m => !string.IsNullOrWhiteSpace(m)) .ToArray(); var badPatternList = new string[] { }; // Files -> List of expressions (Our dictionary based on files) var expressions = ExtractExpressionFromTextFiles.ExtractExpressions( pathFiles, new ExtractExpressionFromTextFilesOption { BadPatternList = badPatternList, BadWords = badWords, FirstWordMinLength = firstWordMinLength, LastWordMinLength = lastWordMinLength, MaxExpressionComposition = maxComposition, MaxWordCount = maxWordCount, MinGroupOfWordsLength = minGroupOfWordsLength, MinWordCount = minWordCount, MinWordFrequency = freqMin, MinWordLength = minWordLength }); Console.WriteLine("Expressions: " + expressions.Count); // Files -> Vectors var expressionVectorOption = new TextFileToExpressionVectorOption { MinVectorElements = minVectorElements, BadPatternList = badPatternList, MaxWordCount = maxWordCount, MinWordCount = minWordCount, Strategy = strategy, ReplaceMissingValueWithRandomValue = replaceMissingValueWithRandomValue }; List <Tuple <string, double[]> > filesToVector = new List <Tuple <string, double[]> >(); foreach (var pathFile in pathFiles) { filesToVector.Add( new Tuple <string, double[]>( pathFile, TextFileToExpressionVector.GenerateExpressionVector( expressions, pathFile, expressionVectorOption) ) ); } var vectors = filesToVector .Select(m => m.Item2) .ToList(); Console.WriteLine("vectors count: " + vectors.Count); // Remove non-representative vectors for (int i = 0; i < vectors.Count; i++) { var vector = vectors[i]; if (vector.Sum() < minVectorElements) { vectors.RemoveAt(i); pathFiles.RemoveAt(i); i--; } } Console.WriteLine("vectors count (after removing non-representative vectors): " + vectors.Count); // Reduce the vector size with PCA. if (usePCA) { Console.WriteLine("Reducing vector size with PCA"); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); PrincipalComponentAnalysis pca = new PrincipalComponentAnalysis(); pca.NumberOfOutputs = numberOfOutputPCA; var trainingVector = vectors.ToArray(); Shuffle(trainingVector); trainingVector = trainingVector.Take(600).ToArray(); var pcaResult = pca.Learn(trainingVector); var reducedVectorsWithPCA = pcaResult.Transform(vectors.ToArray()); stopwatch.Stop(); Console.WriteLine("PCA duration: " + stopwatch.Elapsed.ToString()); vectors = reducedVectorsWithPCA.ToList(); } // Run HDBSCAN algo. Console.WriteLine("HDBSCAN starting..."); var contraintsList = new List <HdbscanConstraint>(); if (usePCA) { for (int i = 1; i < numberOfOutputPCA; i++) { contraintsList.Add(new HdbscanConstraint(i - 1, i, HdbscanConstraintType.CannotLink)); } } var watch = Stopwatch.StartNew(); var result = HdbscanRunner.Run(new HdbscanParameters { DataSet = vectors.ToArray(), MinPoints = 5, MinClusterSize = 5, DistanceFunction = distanceFunction, Constraints = contraintsList, UseMultipleThread = true }); watch.Stop(); Console.WriteLine("HDBSCAN done " + watch.Elapsed); // Read results. var labels = result.Labels; int n = labels.Max(); Console.WriteLine("\n\n"); int clusterId = 0; for (int iCluster = 1; iCluster <= n; iCluster++) { Dictionary <string, int> categories = new Dictionary <string, int>(); bool anyFound = false; for (int i = 0; i < labels.Length; i++) { if (labels[i] == iCluster) { var fileName = Path.GetFileNameWithoutExtension(pathFiles[i]); var category = fileName.Split('-')[0].Trim(); if (categories.ContainsKey(category)) { var count = categories[category]; categories.Remove(category); categories.Add(category, count + 1); } else { categories.Add(category, 1); } anyFound = true; } } if (anyFound) { clusterId++; Console.WriteLine("Cluster #" + clusterId); Console.WriteLine(); foreach (var category in categories) { Console.WriteLine(category.Key + ": " + category.Value); } Console.ReadLine(); } } Console.WriteLine("Press any key to continue..."); Console.ReadLine(); }
static void Main(string[] args) { DataTable meta_table = createMetaTable(); DataTable distractors_video_table = createDistractorVideoTable(); DataTable distractors_game_table = createDistractorGameTable(); DataTable deaths_table = createDeathsTable(); var QuestionnaireScores = new List <double>(); var video_sound_distractor_percentages = new List <double>(); var video_image_distractor_percentages = new List <double>(); var sound_distractor_percentages = new List <double>(); var image_distractor_percentages = new List <double>(); var avgdistractors = new List <double>(); var aps = new List <double>(); var summs = new List <double>(); var exptype = new List <double>(); var skill_lvl = new List <double>(); var death_remembered_percentages = new List <double>(); var underskill_scores = new List <double>(); var overskill_scores = new List <double>(); var matched_scores = new List <double>(); var focused_scores = new List <double>(); var average_scores = new List <double>(); var detached_scores = new List <double>(); var bronze_scores = new List <double>(); var goldplus_scores = new List <double>(); var bps = new List <double[]>(); int participantID = 0; foreach (String uname in usernames) { participantID++; Experiment exp1 = new Experiment(uname); Console.Out.WriteLine("User: "******"Skill Level: " + exp1.skill_level); Console.Out.WriteLine("Play Style: " + exp1.style); Console.Out.WriteLine("Experiment Type: " + exp1.exp_type); Console.Out.WriteLine("Questionnaire Score: " + exp1.questionnaire_score); Console.Out.WriteLine("number of distractors: "); Console.Out.WriteLine(exp1.video_image_distractor_no + " " + exp1.video_sound_distractor_no + " " + exp1.game_sound_distractor_no + " " + exp1.game_image_distractor_no); Console.Out.WriteLine("distractor remembering percentages:"); Console.Out.WriteLine("video sound distractors: " + exp1.video_sound_distractor_proc); Console.Out.WriteLine("video image distractors: " + exp1.video_image_distractor_proc); Console.Out.WriteLine("game sound distractors: " + exp1.game_sound_distractor_proc); Console.Out.WriteLine("game image distractors: " + exp1.game_image_distractor_proc); Console.Out.WriteLine(""); Console.Out.WriteLine(""); QuestionnaireScores.Add(exp1.questionnaire_score); video_sound_distractor_percentages.Add(exp1.video_sound_distractor_proc); video_image_distractor_percentages.Add(exp1.video_image_distractor_proc); sound_distractor_percentages.Add(exp1.game_sound_distractor_proc); image_distractor_percentages.Add(exp1.game_image_distractor_proc); death_remembered_percentages.Add(exp1.death_remember_proc); double video_avg_proc = (exp1.video_sound_distractor_proc + exp1.video_image_distractor_proc) / 2; double avg_proc = (exp1.game_sound_distractor_proc + exp1.game_image_distractor_proc) / 2; avgdistractors.Add(avg_proc); aps.Add(exp1.moves_per_sec); summs.Add(exp1.summ_no); exptype.Add((int)exp1.exp_type); skill_lvl.Add((int)exp1.skill_level); if (exp1.exp_type == Experiment_Types.UnderSkill) { underskill_scores.Add(exp1.questionnaire_score); } else if (exp1.exp_type == Experiment_Types.Matched) { matched_scores.Add(exp1.questionnaire_score); } else if (exp1.exp_type == Experiment_Types.OverSkill) { overskill_scores.Add(exp1.questionnaire_score); } if (exp1.style == PlayStyle.Focused) { focused_scores.Add(exp1.questionnaire_score); } else if (exp1.style == PlayStyle.Average) { average_scores.Add(exp1.questionnaire_score); } else if (exp1.style == PlayStyle.Detached) { detached_scores.Add(exp1.questionnaire_score); } if (exp1.skill_level == Ranks.Bronze) { bronze_scores.Add(exp1.questionnaire_score); } else { goldplus_scores.Add(exp1.questionnaire_score); } foreach (var item in exp1.game_bandpower) { bps.Add(item); } foreach (var item in exp1.video_bandpower) { bps.Add(item); } // KMeans tr = new KMeans(4); // tr.Learn(exp1.game_bandpower); // Console.Write(tr.ToString()); // Console.ReadKey(); meta_table.Rows.Add(participantID, exp1.skill_level, exp1.style, exp1.exp_type, exp1.questionnaire_score); deaths_table.Rows.Add(participantID, exp1.death_no, exp1.actual_death_no, exp1.death_remember_proc); distractors_video_table.Rows.Add(participantID, exp1.video_sound_distractor_proc, exp1.video_image_distractor_proc, video_avg_proc); distractors_game_table.Rows.Add(participantID, exp1.game_sound_distractor_proc, exp1.game_image_distractor_proc, avg_proc); } var test = new PearsonCorrelation(); test.Similarity(QuestionnaireScores.ToArray(), sound_distractor_percentages.ToArray()); Console.Out.WriteLine("accord.net similarity value: "); Console.Out.WriteLine(test.Similarity(QuestionnaireScores.ToArray(), sound_distractor_percentages.ToArray())); Console.Out.WriteLine(""); Console.Out.WriteLine("correlation questionnaire - sound distractor rememberabce"); Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, sound_distractor_percentages)); Console.Out.WriteLine(""); Console.Out.WriteLine("correlation questionnaire - image distractor rememberabce"); Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, image_distractor_percentages)); Console.Out.WriteLine(""); Console.Out.WriteLine("correlation questionnaire - overall distractor rememberabce"); Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, avgdistractors)); Console.Out.WriteLine(""); Console.Out.WriteLine("correlation questionnaire - moves per second"); Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, aps)); Console.Out.WriteLine(""); Console.Out.WriteLine("correlation questionnaire - number of summ spells"); Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, summs)); Console.Out.WriteLine(""); Console.Out.WriteLine(""); Console.Out.WriteLine("correlation questionnaire - skill"); Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, skill_lvl)); Console.Out.WriteLine(""); Console.Out.WriteLine("correlation questionnaire - death rememberabce"); Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, death_remembered_percentages)); Console.Out.WriteLine(""); var scatter_values = new List <double>(); scatter_values.AddRange(video_sound_distractor_percentages); scatter_values.AddRange(sound_distractor_percentages); double[][] samples = { underskill_scores.ToArray(), matched_scores.ToArray(), overskill_scores.ToArray() }; OneWayAnova anova = new OneWayAnova(samples); // DataGridBox.Show(anova.Table); //Console.ReadKey(); double[][] style_samples = { focused_scores.ToArray(), detached_scores.ToArray(), average_scores.ToArray() }; OneWayAnova style_anova = new OneWayAnova(style_samples); // DataGridBox.Show(style_anova.Table); // Console.ReadKey(); double[][] skill_samples = { bronze_scores.ToArray(), goldplus_scores.ToArray() }; OneWayAnova skill_anova = new OneWayAnova(skill_samples); //DataGridBox.Show(skill_anova.Table); //Console.ReadKey(); String meta_table_file = "D:\\Projects\\Conference Paper\\Tables\\meta_table.xml"; String distractors_video_table_file = "D:\\Projects\\Conference Paper\\Tables\\distractors_video_table.xml"; String distractors_game_table_file = "D:\\Projects\\Conference Paper\\Tables\\distractors_game_table.xml"; String deaths_table_file = "D:\\Projects\\Conference Paper\\Tables\\deaths_table.xml"; StreamWriter metaStreamWriter = new StreamWriter(meta_table_file); StreamWriter distractorsVideoStreamWriter = new StreamWriter(distractors_video_table_file); StreamWriter distractorsGameStreamWriter = new StreamWriter(distractors_game_table_file); StreamWriter deathsStreamWriter = new StreamWriter(deaths_table_file); meta_table.WriteXml(metaStreamWriter); distractors_video_table.WriteXml(distractorsVideoStreamWriter); distractors_game_table.WriteXml(distractorsGameStreamWriter); deaths_table.WriteXml(deathsStreamWriter); Console.ReadKey(); }
protected override void WriteData(ExcelWorksheet worksheet) { Class[] classes = _classStore.Classes.ToArray(); List <double> smellsCountList = new List <double>(); List <double> commentsCountList = new List <double>(); List <double> nonDocCommentsCountList = new List <double>(); List <double> docCommentsCountList = new List <double>(); List <double> badCommentsCountList = new List <double>(); List <double> badNonDocCommentsCountList = new List <double>(); List <double> badDocCommentsCountList = new List <double>(); int rowNumber = 2; foreach (var @class in classes) { worksheet.Cells[rowNumber, 1].Value = @class.FileName; worksheet.Cells[rowNumber, 2].Value = @class.Namespace; worksheet.Cells[rowNumber, 3].Value = @class.Name; worksheet.Cells[rowNumber, 4].Value = @class.SmellsCount; worksheet.Cells[rowNumber, 5].Value = @class.Comments.Count(); worksheet.Cells[rowNumber, 6].Value = @class.Comments.Count(c => c.Type == CommentType.SingleLine); worksheet.Cells[rowNumber, 7].Value = @class.Comments.Count(c => c.Type == CommentType.MultiLine); worksheet.Cells[rowNumber, 8].Value = @class.Comments.Count(c => c.Type == CommentType.SingleLine || c.Type == CommentType.MultiLine); worksheet.Cells[rowNumber, 9].Value = @class.Comments.Count(c => c.Type == CommentType.Doc); worksheet.Cells[rowNumber, 10].Value = @class.Comments.Count(c => c.LocationRelativeToMethod == LocationRelativeToMethod.MethodDescription); worksheet.Cells[rowNumber, 11].Value = @class.Comments.Count(c => c.LocationRelativeToMethod == LocationRelativeToMethod.MethodStart); worksheet.Cells[rowNumber, 12].Value = @class.Comments.Count(c => c.LocationRelativeToMethod == LocationRelativeToMethod.MethodInner); worksheet.Cells[rowNumber, 13].Value = @class.Comments.Count(c => c.LocationRelativeToMethod == LocationRelativeToMethod.MethodEnd); worksheet.Cells[rowNumber, 14].Value = @class.AbstractionSmellsCount; worksheet.Cells[rowNumber, 15].Value = @class.EncapsulationSmellsCount; worksheet.Cells[rowNumber, 16].Value = @class.ModularizationSmellsCount; worksheet.Cells[rowNumber, 17].Value = @class.HierarchySmellsCount; smellsCountList.Add(@class.SmellsCount); commentsCountList.Add(@class.Comments.Count()); nonDocCommentsCountList.Add(@class.Comments.Count(c => c.Type == CommentType.SingleLine || c.Type == CommentType.MultiLine)); docCommentsCountList.Add(@class.Comments.Count(c => c.Type == CommentType.Doc)); badCommentsCountList.Add(@class.Comments.Count(c => c.IsBad() == true)); badNonDocCommentsCountList.Add(@class.Comments.Count(c => c.IsBad() == true && (c.Type == CommentType.SingleLine || c.Type == CommentType.MultiLine))); badDocCommentsCountList.Add(@class.Comments.Count(c => c.IsBad() == true && c.Type == CommentType.Doc)); rowNumber++; } worksheet.Cells["T4"].Value = Math.Round(PearsonCorrelation.Compute(smellsCountList, commentsCountList), 3); worksheet.Cells["U4"].Value = Math.Round(PearsonCorrelation.Compute(smellsCountList, nonDocCommentsCountList), 3); worksheet.Cells["V4"].Value = Math.Round(PearsonCorrelation.Compute(smellsCountList, docCommentsCountList), 3); worksheet.Cells["T8"].Value = Math.Round(PearsonCorrelation.Compute(commentsCountList, classes.Select(c => (double)c.AbstractionSmellsCount).ToList()), 3); worksheet.Cells["U8"].Value = Math.Round(PearsonCorrelation.Compute(commentsCountList, classes.Select(c => (double)c.EncapsulationSmellsCount).ToList()), 3); worksheet.Cells["V8"].Value = Math.Round(PearsonCorrelation.Compute(commentsCountList, classes.Select(c => (double)c.ModularizationSmellsCount).ToList()), 3); worksheet.Cells["W8"].Value = Math.Round(PearsonCorrelation.Compute(commentsCountList, classes.Select(c => (double)c.HierarchySmellsCount).ToList()), 3); worksheet.Cells["T12"].Value = Math.Round(PearsonCorrelation.Compute(smellsCountList, badCommentsCountList), 3); worksheet.Cells["U12"].Value = Math.Round(PearsonCorrelation.Compute(smellsCountList, badNonDocCommentsCountList), 3); worksheet.Cells["V12"].Value = Math.Round(PearsonCorrelation.Compute(smellsCountList, badDocCommentsCountList), 3); worksheet.Cells["T16"].Value = Math.Round(PearsonCorrelation.Compute(badCommentsCountList, classes.Select(c => (double)c.AbstractionSmellsCount).ToList()), 3); worksheet.Cells["U16"].Value = Math.Round(PearsonCorrelation.Compute(badCommentsCountList, classes.Select(c => (double)c.EncapsulationSmellsCount).ToList()), 3); worksheet.Cells["V16"].Value = Math.Round(PearsonCorrelation.Compute(badCommentsCountList, classes.Select(c => (double)c.ModularizationSmellsCount).ToList()), 3); worksheet.Cells["W16"].Value = Math.Round(PearsonCorrelation.Compute(badCommentsCountList, classes.Select(c => (double)c.HierarchySmellsCount).ToList()), 3); }