• Not Exported

    Calculates a normalized confidence score for detected patterns

    Generates a standardized confidence score (0-1) that represents how reliable and significant a detected pattern is. This score is used to filter out noise and prioritize patterns for presentation to users.

    The confidence algorithm incorporates multiple factors:

    1. Base confidence factor (pattern-specific measure of strength)
    2. Diversity factor (how many unique items exhibit the pattern)
    3. Frequency factor (how often the pattern occurs)

    The formula applies different weights to each factor:

    • 60% weight to the base pattern-specific factor
    • 20% weight to the diversity of affected items
    • 20% weight to the frequency of occurrence

    The result is capped at 0.95 to acknowledge inherent uncertainty in all patterns.

    Parameters

    • baseFactor: number

      The primary confidence measure (0-1) specific to the pattern type

    • uniqueItems: number

      Number of unique items (tracks, artists, etc.) exhibiting the pattern

    • occurrences: number

      Total number of times the pattern has been observed

    Returns number

    A normalized confidence score between 0 and 0.95

    // Calculate confidence for an artist aversion pattern
    const skipRatio = 0.85; // User skips 85% of tracks by this artist
    const uniqueTracks = 12; // Pattern observed across 12 different tracks
    const totalSkips = 25; // Total of 25 skip events for this artist

    const confidence = calculateConfidence(skipRatio, uniqueTracks, totalSkips);
    // Returns a value like 0.82 representing high confidence
    function calculateConfidence(
    baseFactor: number,
    uniqueItems: number,
    occurrences: number,
    ): number {
    // More unique items and more occurrences = higher confidence
    const uniqueItemsFactor = Math.min(1, uniqueItems / 10);
    const occurrencesFactor = Math.min(1, occurrences / 20);

    // Combine factors, weighting the base factor most heavily
    return Math.min(
    0.95, // Cap at 0.95
    baseFactor * 0.6 + uniqueItemsFactor * 0.2 + occurrencesFactor * 0.2,
    );
    }