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
impl CtrCurve
Sourcepub fn observe(
&mut self,
position: f64,
clicks: u64,
impressions: u64,
) -> Result<(), SerpError>
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.
Sourcepub fn from_observations<I>(observations: I) -> Result<Self, SerpError>
pub fn from_observations<I>(observations: I) -> Result<Self, SerpError>
Build a curve from an iterator of (position, clicks, impressions) observations.
Sourcepub fn impressions_at(&self, position: u32) -> u64
pub fn impressions_at(&self, position: u32) -> u64
Total impressions observed for a bucket, or 0 if the bucket is absent.
Sourcepub fn ctr_at(&self, position: u32) -> Result<f64, SerpError>
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.
Sourcepub fn points(&self) -> Vec<(u32, f64)>
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.
Sourcepub fn project_clicks(
&self,
position: u32,
impressions: u64,
) -> Result<u64, SerpError>
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.
Sourcepub fn projected_click_delta(
&self,
from: u32,
to: u32,
impressions: u64,
) -> Result<i64, SerpError>
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.