From 673454d52b2bae29faa6a27dd5bb2f15a683a474 Mon Sep 17 00:00:00 2001 From: HenryZ16 <1546169856@qq.com> Date: Tue, 25 Jun 2024 06:16:14 -0600 Subject: [PATCH 1/7] change of statistics --- src/components/courses/all/CourseCard.vue | 9 ++++++++- src/composables/global/useArrayUtils.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/components/courses/all/CourseCard.vue b/src/components/courses/all/CourseCard.vue index 1acc67f..9d8e9cf 100644 --- a/src/components/courses/all/CourseCard.vue +++ b/src/components/courses/all/CourseCard.vue @@ -153,6 +153,7 @@ import useCourseCard from "@/composables/courses/all/useCourseCard"; import AvatarContainer from "@/components/users/profile/AvatarContainer"; import { judgeItems, instituteInfo, scoreInfo } from "@/composables/global/useStaticData"; import { averageOf } from "@/composables/global/useArrayUtils"; +import { bayesianAverageOf } from "@/composables/global/useArrayUtils"; import { roundScore, enoughDataThreshold } from "@/composables/global/useParseScore" export default { @@ -184,7 +185,13 @@ export default { let rounded = roundScore(score, this.course["comment_num"]); this.roundedScore.push(rounded); } - this.averageScore = averageOf(this.course.score) * 20; + // Bayes statistics inference + // averageScore = (C * m + Σ(ratings)) / (C + N) + // As of 2024/06/25, 20:01: + // C: Prior Comments Count = 847 + // m: Prior Mean Rating = 3.853896103896104 + // N: Current Comments Count = this.course.score + this.averageScore = bayesianAverageOf(this.course.score, 3.853896103896104, 847) * 20; }, }; diff --git a/src/composables/global/useArrayUtils.js b/src/composables/global/useArrayUtils.js index b0478e6..4ec127a 100644 --- a/src/composables/global/useArrayUtils.js +++ b/src/composables/global/useArrayUtils.js @@ -36,6 +36,20 @@ export function averageOf(arr) { return sumOf(arr) / arr.length } +/** + * Given an array, an prior average and prior count, return the bayesian average of those items. + * @param {Array} arr + * @param {Array} priorAverage + * @param {any} priorCount + * @returns any - The bayesian average of the numbers in the array. + */ +export function bayesianAverageOf(arr, priorAverage, priorCount) { + if (arr.length == 0) { + return 0; + } + return (priorCount * priorAverage + sumOf(arr)) / (priorCount + arr.length) +} + /** * It takes an array of numbers and returns an array of numbers that are the same proportions of the From 335c8670ce21e4c60972037cadeec5200674bd6a Mon Sep 17 00:00:00 2001 From: HenryZ16 <1546169856@qq.com> Date: Fri, 28 Jun 2024 06:08:27 -0600 Subject: [PATCH 2/7] change of the base in the bayesian statistics inference --- src/components/courses/all/CourseCard.vue | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/courses/all/CourseCard.vue b/src/components/courses/all/CourseCard.vue index 9d8e9cf..4b1834b 100644 --- a/src/components/courses/all/CourseCard.vue +++ b/src/components/courses/all/CourseCard.vue @@ -187,11 +187,13 @@ export default { } // Bayes statistics inference // averageScore = (C * m + Σ(ratings)) / (C + N) - // As of 2024/06/25, 20:01: - // C: Prior Comments Count = 847 + // As of 2024/06/25, 20:01, Prior Comments Count = 847 + // Since Prior Comments Count is too large, we just take Prior Comments Count + // as the minimum number of comments required to give a course an average score. + // C: Prior Comments Count = enoughDataThreshold (3 at 2024/6/28) // m: Prior Mean Rating = 3.853896103896104 // N: Current Comments Count = this.course.score - this.averageScore = bayesianAverageOf(this.course.score, 3.853896103896104, 847) * 20; + this.averageScore = bayesianAverageOf(this.course.score, 3.853896103896104, enoughDataThreshold) * 20; }, }; From 404e5a471c51366b3912514fccf9b28fee49f40f Mon Sep 17 00:00:00 2001 From: HenryZ16 <1546169856@qq.com> Date: Fri, 28 Jun 2024 06:35:33 -0600 Subject: [PATCH 3/7] change of parameters in Bayesian statistics inference --- src/components/courses/all/CourseCard.vue | 9 +++++---- src/composables/global/useArrayUtils.js | 7 ++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/courses/all/CourseCard.vue b/src/components/courses/all/CourseCard.vue index 4b1834b..630b515 100644 --- a/src/components/courses/all/CourseCard.vue +++ b/src/components/courses/all/CourseCard.vue @@ -188,12 +188,13 @@ export default { // Bayes statistics inference // averageScore = (C * m + Σ(ratings)) / (C + N) // As of 2024/06/25, 20:01, Prior Comments Count = 847 - // Since Prior Comments Count is too large, we just take Prior Comments Count - // as the minimum number of comments required to give a course an average score. - // C: Prior Comments Count = enoughDataThreshold (3 at 2024/6/28) + // Since Prior Comments Count is too large, we just take Prior Comments Count as 2. + // C: Prior Comments Count = 2 // m: Prior Mean Rating = 3.853896103896104 // N: Current Comments Count = this.course.score - this.averageScore = bayesianAverageOf(this.course.score, 3.853896103896104, enoughDataThreshold) * 20; + // By the way, we set a bar that the course must have at least 8 comments + // and the raw average score at 5 to consider this course as a full score course. + this.averageScore = bayesianAverageOf(this.course.score, 3.853896103896104, 2, 8) * 20; }, }; diff --git a/src/composables/global/useArrayUtils.js b/src/composables/global/useArrayUtils.js index 4ec127a..33440c4 100644 --- a/src/composables/global/useArrayUtils.js +++ b/src/composables/global/useArrayUtils.js @@ -41,12 +41,17 @@ export function averageOf(arr) { * @param {Array} arr * @param {Array} priorAverage * @param {any} priorCount + * @param {any} fullScoreBar - The number of reviews required to consider the average as 5. * @returns any - The bayesian average of the numbers in the array. */ -export function bayesianAverageOf(arr, priorAverage, priorCount) { +export function bayesianAverageOf(arr, priorAverage, priorCount, fullScoreBar) { if (arr.length == 0) { return 0; } + if(averageOf(arr) == 5 && arr.length >= fullScoreBar) { + return 5; + } + return (priorCount * priorAverage + sumOf(arr)) / (priorCount + arr.length) } From 82ca064f072bbc886ff47957ce0d0655d5dede47 Mon Sep 17 00:00:00 2001 From: HenryZ16 <1546169856@qq.com> Date: Fri, 28 Jun 2024 06:37:04 -0600 Subject: [PATCH 4/7] fix --- src/components/courses/all/CourseCard.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/courses/all/CourseCard.vue b/src/components/courses/all/CourseCard.vue index 630b515..d2b9bc6 100644 --- a/src/components/courses/all/CourseCard.vue +++ b/src/components/courses/all/CourseCard.vue @@ -194,7 +194,7 @@ export default { // N: Current Comments Count = this.course.score // By the way, we set a bar that the course must have at least 8 comments // and the raw average score at 5 to consider this course as a full score course. - this.averageScore = bayesianAverageOf(this.course.score, 3.853896103896104, 2, 8) * 20; + this.averageScore = bayesianAverageOf(this.course.score, 3.853896103896104, 1, 8) * 20; }, }; From 2870515bb433f35ace25375b92fd784fd5201b41 Mon Sep 17 00:00:00 2001 From: HenryZ16 <1546169856@qq.com> Date: Fri, 28 Jun 2024 06:39:12 -0600 Subject: [PATCH 5/7] revert --- src/components/courses/all/CourseCard.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/courses/all/CourseCard.vue b/src/components/courses/all/CourseCard.vue index d2b9bc6..630b515 100644 --- a/src/components/courses/all/CourseCard.vue +++ b/src/components/courses/all/CourseCard.vue @@ -194,7 +194,7 @@ export default { // N: Current Comments Count = this.course.score // By the way, we set a bar that the course must have at least 8 comments // and the raw average score at 5 to consider this course as a full score course. - this.averageScore = bayesianAverageOf(this.course.score, 3.853896103896104, 1, 8) * 20; + this.averageScore = bayesianAverageOf(this.course.score, 3.853896103896104, 2, 8) * 20; }, }; From 3770cec1b87736581e3b4e5a90c1ee1690afef6b Mon Sep 17 00:00:00 2001 From: HenryZ16 <1546169856@qq.com> Date: Fri, 28 Jun 2024 06:50:25 -0600 Subject: [PATCH 6/7] adjust parameters --- src/components/courses/all/CourseCard.vue | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/courses/all/CourseCard.vue b/src/components/courses/all/CourseCard.vue index 630b515..17ca144 100644 --- a/src/components/courses/all/CourseCard.vue +++ b/src/components/courses/all/CourseCard.vue @@ -187,14 +187,12 @@ export default { } // Bayes statistics inference // averageScore = (C * m + Σ(ratings)) / (C + N) - // As of 2024/06/25, 20:01, Prior Comments Count = 847 - // Since Prior Comments Count is too large, we just take Prior Comments Count as 2. // C: Prior Comments Count = 2 - // m: Prior Mean Rating = 3.853896103896104 + // m: Prior Mean Rating = 3.19 // N: Current Comments Count = this.course.score // By the way, we set a bar that the course must have at least 8 comments // and the raw average score at 5 to consider this course as a full score course. - this.averageScore = bayesianAverageOf(this.course.score, 3.853896103896104, 2, 8) * 20; + this.averageScore = bayesianAverageOf(this.course.score, 3.19, 2, 8) * 20; }, }; From 4a31e5b1c2a0f28d3b5a2c8dff8c8212ca87f9fb Mon Sep 17 00:00:00 2001 From: HenryZ16 <1546169856@qq.com> Date: Fri, 28 Jun 2024 07:54:45 -0600 Subject: [PATCH 7/7] adjust --- src/components/courses/all/CourseCard.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/courses/all/CourseCard.vue b/src/components/courses/all/CourseCard.vue index 17ca144..337cf0e 100644 --- a/src/components/courses/all/CourseCard.vue +++ b/src/components/courses/all/CourseCard.vue @@ -192,7 +192,7 @@ export default { // N: Current Comments Count = this.course.score // By the way, we set a bar that the course must have at least 8 comments // and the raw average score at 5 to consider this course as a full score course. - this.averageScore = bayesianAverageOf(this.course.score, 3.19, 2, 8) * 20; + this.averageScore = bayesianAverageOf(this.course.score, 4.1, 1, 5) * 20; }, };