Skip to content

chore: Add validation of parameters #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 24, 2025
Merged
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
28 changes: 26 additions & 2 deletions src/routines/initialization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ impl Prior {
Prior::Sobol(points, seed)
}

pub fn get_points(&self) -> usize {
/// Get the number of initial support points
pub fn points(&self) -> usize {
match self {
Prior::Sobol(points, _) => *points,
Prior::Latin(points, _) => *points,
Expand All @@ -42,7 +43,8 @@ impl Prior {
}
}

pub fn get_seed(&self) -> usize {
/// Get the seed used for the random number generator
pub fn seed(&self) -> usize {
match self {
Prior::Sobol(_, seed) => *seed,
Prior::Latin(_, seed) => *seed,
Expand All @@ -62,6 +64,28 @@ impl Default for Prior {

/// This function generates the grid of support points according to the sampler specified in the [Settings]
pub fn sample_space(settings: &Settings) -> Result<Theta> {
// Ensure that the parameter ranges are not infinite
for param in settings.parameters().iter() {
if param.lower.is_infinite() || param.upper.is_infinite() {
bail!(
"Parameter '{}' has infinite bounds: [{}, {}]",
param.name,
param.lower,
param.upper
);
}

// Ensure that the lower bound is less than the upper bound
if param.lower >= param.upper {
bail!(
"Parameter '{}' has invalid bounds: [{}, {}]. Lower bound must be less than upper bound.",
param.name,
param.lower,
param.upper
);
}
}

// Otherwise, parse the sampler type and generate the grid
let prior = match settings.prior() {
Prior::Sobol(points, seed) => sobol::generate(settings.parameters(), *points, *seed)?,
Expand Down
Loading