Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added demonstrate_fixes
Binary file not shown.
69 changes: 69 additions & 0 deletions home-mixer/demonstrate_fixes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
fn main() {
println!("=== Demonstration of Fixes for Ranking Algorithms ===\n");

demonstrate_diversity_fix();
println!("\n-----------------------------------------------------\n");
demonstrate_weighted_scorer_fix();
}

fn demonstrate_diversity_fix() {
println!("1. Author Diversity Scorer Fix");
println!("Scenario: A candidate has a negative score (e.g., -100.0) due to negative signals.");
println!(" It is the 2nd post from the same author, so a decay factor (0.5) applies.");

let score = -100.0;
let multiplier = 0.5;

// Old Logic
let old_score = score * multiplier;

// New Logic
let new_score = if score > 0.0 {
score * multiplier
} else {
score
};

println!("\nInput Score: {}", score);
println!("Diversity Multiplier: {}", multiplier);
println!("Before Fix (Old Logic): {} (BOOSTED! -50 is better than -100)", old_score);
println!("After Fix (New Logic): {} (CORRECT - score remains low)", new_score);
}

fn demonstrate_weighted_scorer_fix() {
println!("2. Weighted Scorer Fix");
println!("Scenario: Comparing scores just above and below zero to check for continuity.");
println!(" Constants: WEIGHTS_SUM=200, NEGATIVE_SCORES_OFFSET=50, NEGATIVE_WEIGHTS_SUM=-100");

let score_neg = -0.001;
let score_pos = 0.001;

// Constants mocking the params module
let weights_sum = 200.0;
let negative_weights_sum = -100.0;
let negative_scores_offset = 50.0;

// Old Logic Function
let old_logic = |s: f64| -> f64 {
if s < 0.0 {
(s + negative_weights_sum) / weights_sum * negative_scores_offset
} else {
s + negative_scores_offset
}
};

// New Logic Function
let new_logic = |s: f64| -> f64 {
s + negative_scores_offset
};

println!("\n-- Before Fix (Discontinuity) --");
println!("Score -0.001 -> {:.4}", old_logic(score_neg));
println!("Score +0.001 -> {:.4}", old_logic(score_pos));
println!("Gap: {:.4} (Huge jump at zero!)", (old_logic(score_pos) - old_logic(score_neg)).abs());

println!("\n-- After Fix (Continuous) --");
println!("Score -0.001 -> {:.4}", new_logic(score_neg));
println!("Score +0.001 -> {:.4}", new_logic(score_pos));
println!("Gap: {:.4} (Smooth transition)", (new_logic(score_pos) - new_logic(score_neg)).abs());
}
8 changes: 7 additions & 1 deletion home-mixer/scorers/author_diversity_scorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ impl Scorer<ScoredPostsQuery, PostCandidate> for AuthorDiversityScorer {
*entry += 1;

let multiplier = self.multiplier(position);
let adjusted_score = candidate.weighted_score.map(|score| score * multiplier);
let adjusted_score = candidate.weighted_score.map(|score| {
if score > 0.0 {
score * multiplier
} else {
score
}
});

let updated = PostCandidate {
score: adjusted_score,
Expand Down
2 changes: 0 additions & 2 deletions home-mixer/scorers/weighted_scorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ impl WeightedScorer {
fn offset_score(combined_score: f64) -> f64 {
if p::WEIGHTS_SUM == 0.0 {
combined_score.max(0.0)
} else if combined_score < 0.0 {
(combined_score + p::NEGATIVE_WEIGHTS_SUM) / p::WEIGHTS_SUM * p::NEGATIVE_SCORES_OFFSET
} else {
combined_score + p::NEGATIVE_SCORES_OFFSET
}
Expand Down