use thiserror::Error;
use crate::cc::feature::FType;
use crate::data::Category;
#[derive(Debug, Clone, PartialEq, Error)]
pub enum GivenError {
#[error(
"Provided {ftype_req:?} datum for column {col_ix}, which is {ftype:?}"
)]
InvalidDatumForColumn {
col_ix: usize,
ftype_req: FType,
ftype: FType,
},
#[error("Tried to condition on a 'missing' value in column {col_ix}")]
MissingDatum { col_ix: usize },
#[error("Column index {col_ix} appears in the target")]
ColumnIndexAppearsInTarget { col_ix: usize },
#[error("Index error in given: {0}")]
IndexError(#[from] IndexError),
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum IndexError {
#[error("Asked for row index {row_ix} but there are {n_rows} rows")]
RowIndexOutOfBounds { n_rows: usize, row_ix: usize },
#[error("Asked for column index {col_ix} but there are {n_cols} columns")]
ColumnIndexOutOfBounds { n_cols: usize, col_ix: usize },
#[error("The column '{name}' does not exist in the table.")]
ColumnNameDoesNotExist { name: String },
#[error("The row '{name}' does not exist in the table.")]
RowNameDoesNotExist { name: String },
#[error(
"Provided {ftype_req:?} datum for column {col_ix}, which is {ftype:?}"
)]
InvalidDatumForColumn {
col_ix: usize,
ftype_req: FType,
ftype: FType,
},
#[error("Index not found in column {col_ix} for category {cat:?}")]
CategoryIndexNotFound { col_ix: usize, cat: Category },
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum RowSimError {
#[error("Index error: {0}")]
Index(#[from] IndexError),
#[error("Invalid `wrt` index: {0}")]
WrtColumnIndexOutOfBounds(IndexError),
#[error("If wrt is not None, it must not be empty")]
EmptyWrt,
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum MiError {
#[error("Index error in 'mi' query: {0}")]
IndexError(#[from] IndexError),
#[error("Must request more than zero samples")]
NIsZero,
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum EntropyError {
#[error("No target columns provided")]
NoTargetColumns,
#[error("Index error in entropy query: {0}")]
IndexError(#[from] IndexError),
#[error("Must request more than zero samples")]
NIsZero,
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum InfoPropError {
#[error("no target columns provided")]
NoTargetColumns,
#[error("no predictor columns provided")]
NoPredictorColumns,
#[error("target index error: {0}")]
TargetIndexOutOfBounds(IndexError),
#[error("predictor index error: {0}")]
PredictorIndexOutOfBounds(IndexError),
#[error("Must request more than zero samples")]
NIsZero,
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum ConditionalEntropyError {
#[error("target index error: {0}")]
TargetIndexOutOfBounds(IndexError),
#[error("predictor index error: {0}")]
PredictorIndexOutOfBounds(IndexError),
#[error("predictor {col_ix} appears more than once")]
DuplicatePredictors { col_ix: usize },
#[error("no predictors provided")]
NoPredictorColumns,
#[error("Must request more than zero samples")]
NIsZero,
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum SurprisalError {
#[error("Index error in surprisal query: {0}")]
IndexError(#[from] IndexError),
#[error(
"Requested state index {state_ix} but there are {n_states} states"
)]
StateIndexOutOfBounds { n_states: usize, state_ix: usize },
#[error(
"Provided {ftype_req:?} datum for column {col_ix}, which is {ftype:?}"
)]
InvalidDatumForColumn {
col_ix: usize,
ftype_req: FType,
ftype: FType,
},
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum PredictError {
#[error("Target index error in predict query: {0}")]
IndexError(#[from] IndexError),
#[error("Invalid predict 'given' argument: {0}")]
GivenError(#[from] GivenError),
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum VariabilityError {
#[error("Target index error in predict query: {0}")]
IndexError(#[from] IndexError),
#[error("Invalid predict 'given' argument: {0}")]
GivenError(#[from] GivenError),
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum PredictUncertaintyError {
#[error("Target index error in predict uncertainty query: {0}")]
IndexError(#[from] IndexError),
#[error("Invalid predict uncertainty 'given' argument: {0}")]
GivenError(#[from] GivenError),
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum ColumnMaximumLogPError {
#[error("The state indices used to compute the cache do not match those passed to the function.")]
InvalidStateIndices,
#[error("The column indices used to compute the cache do not match those passed to the function.")]
InvalidColumnIndices,
#[error("The Given conditions used to compute the cache do not match those passed to the function.")]
InvalidGiven,
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum LogpError {
#[error("No target columns provided")]
NoTargets,
#[error(
"There are {ntargets} targets but a row in vals has {nvals} values"
)]
TargetsIndicesAndValuesMismatch { nvals: usize, ntargets: usize },
#[error(
"Provided {ftype_req:?} datum for column {col_ix}, which is {ftype:?}"
)]
InvalidDatumForColumn {
col_ix: usize,
ftype_req: FType,
ftype: FType,
},
#[error("Requested logp of 'missing' datum for column {col_ix}")]
RequestedLogpOfMissing { col_ix: usize },
#[error("Target column index error: {0}")]
TargetIndexOutOfBounds(IndexError),
#[error(
"State index {state_ix} invalid for engine with {n_states} states"
)]
StateIndexOutOfBounds { n_states: usize, state_ix: usize },
#[error("Provided an empty states vector. Use 'None' instead")]
NoStateIndices,
#[error("Invalid logp 'given' argument: {0}")]
GivenError(#[from] GivenError),
#[error("Invalid `col_max_logps` argument: {0}")]
ColumnMaximumLogPError(#[from] ColumnMaximumLogPError),
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum SimulateError {
#[error("No simulate targets provided")]
NoTargets,
#[error("Target column index error: {0}")]
TargetIndexOutOfBounds(IndexError),
#[error(
"State index {state_ix} invalid for engine with {n_states} states"
)]
StateIndexOutOfBounds { n_states: usize, state_ix: usize },
#[error("Provided an empty states vector. Use 'None' instead")]
NoStateIndices,
#[error("Invalid simulate 'given' argument: {0}")]
GivenError(#[from] GivenError),
}