Skip to content

Commit 02e9896

Browse files
mhovdCopilot
andauthored
chore: Add validation of parameters (#136)
* chore: Add validation of parameters Ensures that the parameter ranges are valid prior to initialization * Update src/routines/initialization/mod.rs Co-authored-by: Copilot <[email protected]> * Remove unnecessary check --------- Co-authored-by: Copilot <[email protected]>
1 parent 5ec53b7 commit 02e9896

File tree

1 file changed

+26
-2
lines changed
  • src/routines/initialization

1 file changed

+26
-2
lines changed

src/routines/initialization/mod.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ impl Prior {
3131
Prior::Sobol(points, seed)
3232
}
3333

34-
pub fn get_points(&self) -> usize {
34+
/// Get the number of initial support points
35+
pub fn points(&self) -> usize {
3536
match self {
3637
Prior::Sobol(points, _) => *points,
3738
Prior::Latin(points, _) => *points,
@@ -42,7 +43,8 @@ impl Prior {
4243
}
4344
}
4445

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

6365
/// This function generates the grid of support points according to the sampler specified in the [Settings]
6466
pub fn sample_space(settings: &Settings) -> Result<Theta> {
67+
// Ensure that the parameter ranges are not infinite
68+
for param in settings.parameters().iter() {
69+
if param.lower.is_infinite() || param.upper.is_infinite() {
70+
bail!(
71+
"Parameter '{}' has infinite bounds: [{}, {}]",
72+
param.name,
73+
param.lower,
74+
param.upper
75+
);
76+
}
77+
78+
// Ensure that the lower bound is less than the upper bound
79+
if param.lower >= param.upper {
80+
bail!(
81+
"Parameter '{}' has invalid bounds: [{}, {}]. Lower bound must be less than upper bound.",
82+
param.name,
83+
param.lower,
84+
param.upper
85+
);
86+
}
87+
}
88+
6589
// Otherwise, parse the sampler type and generate the grid
6690
let prior = match settings.prior() {
6791
Prior::Sobol(points, seed) => sobol::generate(settings.parameters(), *points, *seed)?,

0 commit comments

Comments
 (0)