Skip to main content

CtrCurve

Struct CtrCurve 

Source
pub struct CtrCurve { /* private fields */ }
Expand description

A CTR-by-position curve built from observed data.

Positions are stored as whole-number buckets (position 3.4 falls in bucket 3). Each bucket accumulates clicks and impressions, so the curve’s CTR for a bucket is the real pooled rate of the data you fed it, never an assumed constant.

Implementations§

Source§

impl CtrCurve

Source

pub fn new() -> Self

An empty curve.

Source

pub fn observe( &mut self, position: f64, clicks: u64, impressions: u64, ) -> Result<(), SerpError>

Fold one observation into the curve.

Non-finite or sub-1.0 positions are rejected with SerpError::InvalidPosition, and inconsistent rows with SerpError::ClicksExceedImpressions.

Source

pub fn from_observations<I>(observations: I) -> Result<Self, SerpError>
where I: IntoIterator<Item = (f64, u64, u64)>,

Build a curve from an iterator of (position, clicks, impressions) observations.

Source

pub fn len(&self) -> usize

Number of populated position buckets.

Source

pub fn is_empty(&self) -> bool

Whether the curve holds no observations.

Source

pub fn impressions_at(&self, position: u32) -> u64

Total impressions observed for a bucket, or 0 if the bucket is absent.

Source

pub fn ctr_at(&self, position: u32) -> Result<f64, SerpError>

Pooled CTR observed at a whole-number position.

§Errors

SerpError::PositionNotInCurve when nothing was ever observed at that position, and SerpError::NoImpressions when the bucket exists but holds zero impressions. The curve never interpolates or extrapolates: an unobserved position is an error, not a guess.

Source

pub fn points(&self) -> Vec<(u32, f64)>

Every populated bucket as (position, ctr), ascending by position.

Buckets holding zero impressions are skipped, because they have no rate.

Source

pub fn project_clicks( &self, position: u32, impressions: u64, ) -> Result<u64, SerpError>

Clicks you would expect from impressions at position, using this curve.

The result is impressions * ctr_at(position), rounded to the nearest whole click. It is a restatement of your own observed rate at a volume you supply — it is not a forecast, and it says nothing about whether that position is reachable.

§Errors

Propagates the errors of CtrCurve::ctr_at.

Source

pub fn projected_click_delta( &self, from: u32, to: u32, impressions: u64, ) -> Result<i64, SerpError>

Difference in projected clicks between two positions at the same impression volume.

Positive when to earns more than from.

§Errors

Propagates the errors of CtrCurve::ctr_at for either position.

Trait Implementations§

Source§

impl Clone for CtrCurve

Source§

fn clone(&self) -> CtrCurve

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CtrCurve

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CtrCurve

Source§

fn default() -> CtrCurve

Returns the “default value” for a type. Read more
Source§

impl Eq for CtrCurve

Source§

impl PartialEq for CtrCurve

Source§

fn eq(&self, other: &CtrCurve) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CtrCurve

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.