Skip to main content

RankingModel

Struct RankingModel 

Source
pub struct RankingModel<T: Clone + Debug + Eq + Hash + Display + Send + Sync + 'static> {
    pub data: ComparisonMatrix<T>,
    pub scores: Option<HashMap<T, f64>>,
    /* private fields */
}
Expand description

Main ASAP ranking model for inferring scores from pairwise comparisons

Fields§

§data: ComparisonMatrix<T>§scores: Option<HashMap<T, f64>>

Implementations§

Source§

impl<T: Clone + Debug + Eq + Hash + Display + Send + Sync + 'static> RankingModel<T>

Source

pub fn new(items: &[T]) -> Self

Create a new RankingModel with the given items

Source

pub fn new_with_options( items: &[T], approximate: bool, selective_eig: bool, ) -> Self

Create a new RankingModel with custom options

Source

pub fn add_comparison( &mut self, comparison: Comparison<T>, ) -> Result<(), AsapError<T>>

Add a pairwise comparison result

Source

pub fn add_item(&mut self, item: T) -> Result<(), AsapError<T>>

Source

pub fn remove_item(&mut self, item: &T) -> Result<(), AsapError<T>>

Source

pub fn get_ordering(&mut self) -> Result<Vec<T>, AsapError<T>>

Get the items ordered by their inferred scores (highest to lowest)

Source

pub fn get_scores(&mut self) -> Result<HashMap<T, f64>, AsapError<T>>

Get the inferred scores for all items

Source

pub fn suggest_comparisons( &self, max: usize, ) -> Result<Vec<(T, T)>, AsapError<T>>

Suggest the most informative comparisons to perform next

Source

pub fn ranking_confidence(&self) -> Result<f64, AsapError<T>>

Confidence metric calibrated for Bradley-Terry MLE.

Measures two things:

  1. Coverage (50% weight): fraction of items with >= MIN_COMPARISONS_PER_ITEM comparisons. BT needs ~5-10 per item, not N² total.
  2. Discrimination (50% weight): whether scores are spread out enough to distinguish items. Uses coefficient of variation of the BT strengths.
Source

pub fn is_sufficiently_confident( &self, threshold: f64, ) -> Result<bool, AsapError<T>>

Check if the current ranking has sufficient confidence (threshold: 0.0 to 1.0)

Source§

impl<T: Clone + Debug + Eq + Hash + Display + Send + Sync + 'static + Serialize + DeserializeOwned> RankingModel<T>

Source

pub fn to_json(&self) -> Result<String, AsapError<T>>

Source

pub fn from_json(json: &str) -> Result<Self, AsapError<T>>

Source

pub fn save_to_file(&self, path: &str) -> Result<(), AsapError<T>>

Source

pub fn load_from_file(path: &str) -> Result<Self, AsapError<T>>

Trait Implementations§

Source§

impl<'de, T> Deserialize<'de> for RankingModel<T>
where T: Clone + Debug + Eq + Hash + Display + Send + Sync + 'static + DeserializeOwned,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Serialize for RankingModel<T>
where T: Clone + Debug + Eq + Hash + Display + Send + Sync + 'static + Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for RankingModel<T>

§

impl<T> RefUnwindSafe for RankingModel<T>
where T: RefUnwindSafe,

§

impl<T> Send for RankingModel<T>

§

impl<T> Sync for RankingModel<T>

§

impl<T> Unpin for RankingModel<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for RankingModel<T>

§

impl<T> UnwindSafe for RankingModel<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,