Skip to content

Commit

Permalink
Sigmoid transform diversity score (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex0Blackwell authored Oct 16, 2021
1 parent e32aeee commit e764888
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async function on_start() {
const abs_change = Math.abs((abs_max_score + page_score) - (abs_max_score + avg_score));

let diversity_score = max_diversiry_score * (abs_change/(abs_max_score*2));
diversity_score = _sigmoid_transformation(diversity_score)
diversity_score = Math.ceil(diversity_score/5)*5;

UiService.update_ui(normalized_number, political_lean, diversity_score);
Expand All @@ -26,6 +27,10 @@ async function on_start() {
);
}

function _sigmoid_transformation(diversity_score) {
return 100/(1+Math.exp(4 - 0.16*diversity_score))
}

window.onload = function() {
on_start();
}
6 changes: 4 additions & 2 deletions src/services/ui_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ export default class UiService {
1: "This is kind of what you're used to reading, try browsing other websites to hear something new!",
2: "This is a little different from what you normally read, nice work and keep searching!",
3: "This is quite different from your typical reading material, good job finding a new perspective!",
4: "This is drastically different from your typical news articles, excellent work finding new views!"
4: "This is very different from what news articles you normally read, great work finding this page!",
5: "This is drastically different from your typical news articles, excellent work finding new views!"
}

const abs_normalized_num = Math.abs(normalized_number);
const normalized_diversity_score = Math.round(diversity_score/20);
const diversity_response = diversity_response_dict[normalized_diversity_score];

const abs_normalized_num = Math.abs(normalized_number);
const adjective = num_to_ui_dict[abs_normalized_num];
const text = `We have analyzed this text to be ${adjective.toLowerCase()} ${political_lean}. ${diversity_response}`;

Expand Down

0 comments on commit e764888

Please sign in to comment.