pub struct TrustScores { /* private fields */ }Expand description
Global trust scores, one per peer, plus how the computation went.
Scores are indexed by peer: scores()[i] belongs to peer i. They are non-negative and
add up to 1 (up to floating point rounding).
Implementations§
Source§impl TrustScores
impl TrustScores
Sourcepub fn get(&self, peer: usize) -> Option<f64>
pub fn get(&self, peer: usize) -> Option<f64>
The score of one peer, or None if the index is outside the network.
Sourcepub fn ranking(&self) -> Vec<(usize, f64)>
pub fn ranking(&self) -> Vec<(usize, f64)>
(peer, score) pairs, highest score first. Equal scores keep peer order.
Examples found in repository?
examples/basic.rs (line 21)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let names = ["alice", "bob", "carol", "mallory"];
7
8 // who trusts whom, and how much (weights are relative per truster)
9 let local_trust = [
10 TrustEdge::new(0, 1, 3.0), // alice -> bob
11 TrustEdge::new(0, 2, 1.0), // alice -> carol
12 TrustEdge::new(1, 2, 2.0), // bob -> carol
13 TrustEdge::new(2, 0, 1.0), // carol -> alice
14 TrustEdge::new(3, 3, 9.0), // mallory only vouches for herself
15 ];
16 // alice is trusted from the start
17 let pre_trust = [PreTrust::new(0, 1.0)];
18
19 let result = eigentrust(local_trust, pre_trust)?;
20
21 for (peer, score) in result.ranking() {
22 println!("{:<8} {:.4}", names[peer], score);
23 }
24 println!("converged after {} iterations", result.iterations());
25 Ok(())
26}Sourcepub fn iterations(&self) -> usize
pub fn iterations(&self) -> usize
Power iterations performed.
Examples found in repository?
examples/basic.rs (line 24)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let names = ["alice", "bob", "carol", "mallory"];
7
8 // who trusts whom, and how much (weights are relative per truster)
9 let local_trust = [
10 TrustEdge::new(0, 1, 3.0), // alice -> bob
11 TrustEdge::new(0, 2, 1.0), // alice -> carol
12 TrustEdge::new(1, 2, 2.0), // bob -> carol
13 TrustEdge::new(2, 0, 1.0), // carol -> alice
14 TrustEdge::new(3, 3, 9.0), // mallory only vouches for herself
15 ];
16 // alice is trusted from the start
17 let pre_trust = [PreTrust::new(0, 1.0)];
18
19 let result = eigentrust(local_trust, pre_trust)?;
20
21 for (peer, score) in result.ranking() {
22 println!("{:<8} {:.4}", names[peer], score);
23 }
24 println!("converged after {} iterations", result.iterations());
25 Ok(())
26}Sourcepub fn residual(&self) -> f64
pub fn residual(&self) -> f64
Change between the last two iterations (L2 norm). At most the convergence threshold.
Sourcepub fn into_scores(self) -> Vec<f64>
pub fn into_scores(self) -> Vec<f64>
The scores, indexed by peer.
Trait Implementations§
Source§impl Clone for TrustScores
impl Clone for TrustScores
Source§impl Debug for TrustScores
impl Debug for TrustScores
Source§impl PartialEq for TrustScores
impl PartialEq for TrustScores
impl StructuralPartialEq for TrustScores
Auto Trait Implementations§
impl Freeze for TrustScores
impl RefUnwindSafe for TrustScores
impl Send for TrustScores
impl Sync for TrustScores
impl Unpin for TrustScores
impl UnsafeUnpin for TrustScores
impl UnwindSafe for TrustScores
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more