iicp-client 0.7.93

Use the open IICP AI mesh from Rust without running a node
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! Opt-in, deterministic-testable `iicp.selection.v1` candidate ordering.

pub fn weighted_v1_index(scores: &[f64], loads: &[f64], random_value: f64) -> usize {
    let weights: Vec<f64> = scores
        .iter()
        .zip(loads)
        .map(|(score, load)| score.max(0.01) / (1.0 + load.clamp(0.0, 1.0)))
        .collect();
    let mut remaining = random_value.clamp(0.0, 0.999_999_999) * weights.iter().sum::<f64>();
    for (index, weight) in weights.iter().enumerate() {
        remaining -= weight;
        if remaining <= 0.0 {
            return index;
        }
    }
    weights.len().saturating_sub(1)
}