Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/bimodal_ke/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@ fn main() -> Result<()> {
let mut result = algorithm.fit()?;
result.write_outputs()?;

if let Some(m) = result.metrics() {
println!("{}", m);
}

Ok(())
}
18 changes: 18 additions & 0 deletions src/routines/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,24 @@ impl<E: Equation> NPResult<E> {
tracing::debug!("Covariates written to {:?}", &outputfile.relative_path());
Ok(())
}

/// Get a reference to the predictions, if they have been calculated
pub fn predictions(&self) -> Option<&NPPredictions> {
self.predictions.as_ref()
}

/// Compute prediction metrics, calculating predictions first if needed
///
/// Uses the `idelta` and `tad` values from the current [Settings].
/// Returns `None` if there are no valid observation-prediction pairs.
pub fn metrics(&mut self) -> Option<predictions::PredictionMetrics> {
if self.predictions.is_none() {
let idelta = self.settings.predictions().idelta;
let tad = self.settings.predictions().tad;
self.calculate_predictions(idelta, tad).ok()?;
}
self.predictions.as_ref().and_then(|p| p.metrics())
}
}

pub(crate) fn median(data: &[f64]) -> f64 {
Expand Down
Loading
Loading