pub struct ParameterRange {
pub kind: ParameterKind,
pub min: f64,
pub max: f64,
pub step: Option<f64>,
pub default: f64,
}Expand description
A continuous or discrete range for a single tunable parameter.
When step is Some, the parameter is treated as discrete: values are
quantized to the nearest grid point anchored at min. When step is None
the parameter is treated as continuous and generators fall back to an internal
default step count (typically 20 divisions).
§Examples
use zeph_experiments::{ParameterRange, ParameterKind};
let range = ParameterRange {
kind: ParameterKind::Temperature,
min: 0.0,
max: 1.0,
step: Some(0.1),
default: 0.7,
};
assert!(range.is_valid());
assert_eq!(range.step_count(), Some(11));
assert!((range.clamp(2.0) - 1.0).abs() < f64::EPSILON);
assert!((range.quantize(0.73) - 0.7).abs() < 1e-10);Fields§
§kind: ParameterKindThe parameter this range applies to.
min: f64Minimum value (inclusive).
max: f64Maximum value (inclusive).
step: Option<f64>Discrete step size. None means continuous (generators use a default step count).
default: f64Default (baseline) value, typically read from the current agent config.
Implementations§
Source§impl ParameterRange
impl ParameterRange
Sourcepub fn step_count(&self) -> Option<usize>
pub fn step_count(&self) -> Option<usize>
Number of discrete grid points in this range, or None if step is not set or ≤ 0.
The count is floor((max - min) / step) + 1.
§Examples
use zeph_experiments::{ParameterRange, ParameterKind};
let r = ParameterRange { kind: ParameterKind::Temperature, min: 0.0, max: 1.0, step: Some(0.5), default: 0.5 };
assert_eq!(r.step_count(), Some(3)); // 0.0, 0.5, 1.0
let r_continuous = ParameterRange { step: None, ..r };
assert_eq!(r_continuous.step_count(), None);Sourcepub fn clamp(&self, value: f64) -> f64
pub fn clamp(&self, value: f64) -> f64
Clamp value to [min, max].
§Examples
use zeph_experiments::{ParameterRange, ParameterKind};
let r = ParameterRange { kind: ParameterKind::TopP, min: 0.1, max: 1.0, step: Some(0.1), default: 0.9 };
assert!((r.clamp(2.0) - 1.0).abs() < f64::EPSILON);
assert!((r.clamp(-1.0) - 0.1).abs() < f64::EPSILON);Sourcepub fn contains(&self, value: f64) -> bool
pub fn contains(&self, value: f64) -> bool
Return true if value lies within [min, max] (inclusive).
§Examples
use zeph_experiments::{ParameterRange, ParameterKind};
let r = ParameterRange { kind: ParameterKind::Temperature, min: 0.0, max: 1.0, step: Some(0.1), default: 0.7 };
assert!(r.contains(0.5));
assert!(!r.contains(1.1));Sourcepub fn quantize(&self, value: f64) -> f64
pub fn quantize(&self, value: f64) -> f64
Quantize value to the nearest grid step anchored at min.
Formula: min + ((value - min) / step).round() * step, then clamped to [min, max].
Anchoring at min ensures grid points align to {min, min+step, min+2*step, ...}.
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Return true if this range is internally consistent.
Returns false if min > max, any bound or default is non-finite,
or step is present but non-positive or non-finite.
§Examples
use zeph_experiments::{ParameterRange, ParameterKind};
let valid = ParameterRange { kind: ParameterKind::Temperature, min: 0.0, max: 1.0, step: Some(0.1), default: 0.7 };
assert!(valid.is_valid());
let inverted = ParameterRange { min: 1.0, max: 0.0, ..valid };
assert!(!inverted.is_valid());Trait Implementations§
Source§impl Clone for ParameterRange
impl Clone for ParameterRange
Source§fn clone(&self) -> ParameterRange
fn clone(&self) -> ParameterRange
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ParameterRange
impl Debug for ParameterRange
Source§impl<'de> Deserialize<'de> for ParameterRange
impl<'de> Deserialize<'de> for ParameterRange
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ParameterRange
impl RefUnwindSafe for ParameterRange
impl Send for ParameterRange
impl Sync for ParameterRange
impl Unpin for ParameterRange
impl UnsafeUnpin for ParameterRange
impl UnwindSafe for ParameterRange
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request