pub struct Interval<'domain, T: QuantitativeLimit> { /* private fields */ }Expand description
Interval valuation.
Implementations§
Source§impl<'domain, T: QuantitativeLimit + Copy + Debug + Display + Into<f64> + Add<Output = T> + Sub<Output = T>> Interval<'domain, T>
impl<'domain, T: QuantitativeLimit + Copy + Debug + Display + Into<f64> + Add<Output = T> + Sub<Output = T>> Interval<'domain, T>
Sourcepub fn new(
domain: &'domain Quantitative<T>,
min: T,
max: T,
) -> Result<Self, IntervalError<T>>
pub fn new( domain: &'domain Quantitative<T>, min: T, max: T, ) -> Result<Self, IntervalError<T>>
Creates a new valuation.
§Arguments
domain: A quantitative domain reference.min: Interval min value.max: Interval max value.
§Examples
let domain = Quantitative::new(1, 5).unwrap();
assert!(Interval::new(&domain, 2, 3).is_ok());let domain = Quantitative::new(1.2, 5.7).unwrap();
assert!(Interval::new(&domain, 2.3, 2.7).is_ok());§Errors
IntervalError::InvalidMin: If min < domain inferior limit.
let domain = Quantitative::new(1, 5).unwrap();
assert_eq!(
Interval::new(&domain, 0, 3),
Err(IntervalError::InvalidMin { min: 0, inf: 1 })
);IntervalError::InvalidMax: If max > domain superior limit.
let domain = Quantitative::new(1, 5).unwrap();
assert_eq!(
Interval::new(&domain, 2, 6),
Err(IntervalError::InvalidMax { max: 6, sup: 5 })
);IntervalError::InvalidRange: If min > max.
let domain = Quantitative::new(1, 5).unwrap();
assert_eq!(
Interval::new(&domain, 3, 2),
Err(IntervalError::InvalidRange { min: 3, max: 2 })
);Sourcepub fn value(&self) -> (T, T)
pub fn value(&self) -> (T, T)
Returns valuation values.
§Examples
let domain = Quantitative::new(1, 5).unwrap();
let valuation = Interval::new(&domain, 2, 3).unwrap();
assert_eq!(valuation.value(), (2, 3));let domain = Quantitative::new(1.0, 5.7).unwrap();
let valuation = Interval::new(&domain, 2.0, 3.0).unwrap();
assert_eq!(valuation.value(), (2.0, 3.0));Sourcepub fn domain(&self) -> &'domain Quantitative<T>
pub fn domain(&self) -> &'domain Quantitative<T>
Returns valuation domain.
§Examples
let domain = Quantitative::new(1.0, 5.7).unwrap();
let valuation = Interval::new(&domain, 2.0, 3.0).unwrap();
assert_eq!(*valuation.domain(), domain);Sourcepub fn normalize(&self) -> Interval<'_, f64>
pub fn normalize(&self) -> Interval<'_, f64>
Value normalized in domain 0.0 to 1.0.
Note that the type of value is f64.
§Examples
let domain = Quantitative::new(0.0, 10.0).unwrap();
let valuation = Interval::new(&domain, 2.0, 3.5).unwrap();
let normalized = valuation.normalize();
assert_eq!(normalized.value(), (0.2, 0.35));
assert_eq!(*normalized.domain(), NORMALIZATION_DOMAIN);
let domain = Quantitative::new(-1, 5).unwrap();
let valuation = Interval::new(&domain, 2, 5).unwrap();
let normalized = valuation.normalize();
assert_eq!(normalized.value(), (0.5, 1.0));
assert_eq!(*normalized.domain(), NORMALIZATION_DOMAIN);Source§impl<'domain, T> Interval<'domain, T>
impl<'domain, T> Interval<'domain, T>
Sourcepub fn unification(
&self,
domain: &'domain Qualitative<Trapezoidal>,
) -> Result<Unified<'_>, UnifiedError<'_>>
pub fn unification( &self, domain: &'domain Qualitative<Trapezoidal>, ) -> Result<Unified<'_>, UnifiedError<'_>>
Unification of a Interval valuation in a given domain.
§Arguments
domain: Domain in which perform the unification.
§Examples
let domain = Quantitative::new(0, 7).unwrap();
let unification_domain = qualitative_symmetric_domain!["a", "b", "c", "d", "e"].unwrap();
let valuation = Interval::new(&domain, 5, 6).unwrap();
let unified = valuation.unification(&unification_domain).unwrap();
let measures = unified.measures();
let expected_measures = vec![0.0, 0.0, 0.14, 1.0, 0.43];
for i in 0..(expected_measures.len()) {
assert!(
utilities::math::approx_equal_f32(
measures[i],
expected_measures[i],
2
),
"({}) Value {:.2} vs. Expected {:.2}",
i,
measures[i],
expected_measures[i]
);
}§Errors
UnifiedError::NonBLTSDomain: If domain is a Non-BLTS domain.
let domain = Quantitative::new(0, 7).unwrap();
let unification_domain = qualitative_symmetric_domain!["a", "b", "c", "d"].unwrap();
let valuation = Interval::new(&domain, 5, 6).unwrap();
assert_eq!(
valuation.unification(&unification_domain),
Err(UnifiedError::NonBLTSDomain { domain: &unification_domain })
);Sourcepub fn transform_in_domain(
&self,
domain: &'domain Quantitative<T>,
) -> Interval<'_, T>
pub fn transform_in_domain( &self, domain: &'domain Quantitative<T>, ) -> Interval<'_, T>
Transform a Interval valuation using a different domain.
Note that domain type should be equal to valuation type.
§Arguments
domain: Domain to be used.
§Examples
let domain = Quantitative::new(0, 7).unwrap();
let transform_domain = Quantitative::new(0, 3).unwrap();
let valuation = Interval::new(&domain, 5, 6).unwrap();
let unified = valuation.transform_in_domain(&transform_domain);
assert_eq!(unified.value(), (2, 2));Trait Implementations§
Source§impl<'domain, T: PartialEq + QuantitativeLimit> PartialEq for Interval<'domain, T>
impl<'domain, T: PartialEq + QuantitativeLimit> PartialEq for Interval<'domain, T>
Source§impl<'domain> TryFrom<&Interval<'domain, f32>> for Numeric<'domain, f32>
Generates a Numeric valuation from an &Interval valuation.
impl<'domain> TryFrom<&Interval<'domain, f32>> for Numeric<'domain, f32>
Generates a Numeric
§Examples
let domain = Quantitative::new(0.5_f32, 1.0_f32).unwrap();
let interval = Interval::new(&domain, 0.6, 0.8).unwrap();
let numeric = Numeric::try_from(&interval).unwrap();
let expected = 0.7;
assert!((numeric.value() - expected).abs() < 0.01);Source§impl<'domain> TryFrom<&Interval<'domain, f64>> for Numeric<'domain, f64>
Generates a Numeric valuation from an &Interval valuation.
impl<'domain> TryFrom<&Interval<'domain, f64>> for Numeric<'domain, f64>
Generates a Numeric
§Examples
let domain = Quantitative::new(0.5_f64, 1.0_f64).unwrap();
let interval = Interval::new(&domain, 0.6, 0.8).unwrap();
let numeric = Numeric::try_from(&interval).unwrap();
let expected = 0.7;
assert!((numeric.value() - expected).abs() < 0.01);Source§impl<'domain> TryFrom<&Interval<'domain, i32>> for Numeric<'domain, i32>
Generates a Numeric valuation from an &Interval valuation.
impl<'domain> TryFrom<&Interval<'domain, i32>> for Numeric<'domain, i32>
Generates a Numeric
§Examples
let domain = Quantitative::new(5, 10).unwrap();
let interval = Interval::new(&domain, 6, 8).unwrap();
let numeric = Numeric::try_from(&interval).unwrap();
let expected = 7;
assert_eq!(numeric.value(), expected);Source§impl<'domain, T: QuantitativeLimit + Into<f64> + Add<Output = T> + Sub<Output = T>> TryFrom<&Numeric<'domain, T>> for Interval<'domain, T>
Generates an Interval valuation from a &Numeric valuation.
impl<'domain, T: QuantitativeLimit + Into<f64> + Add<Output = T> + Sub<Output = T>> TryFrom<&Numeric<'domain, T>> for Interval<'domain, T>
Generates an Interval valuation from a &Numeric valuation.
§Examples
let domain = Quantitative::new(5, 10).unwrap();
let numeric = Numeric::new(&domain, 6).unwrap();
let interval = Interval::try_from(&numeric).unwrap();
let expected = (6, 6);
assert_eq!(interval.value(), expected);Source§impl<'domain> TryFrom<Interval<'domain, f32>> for Numeric<'domain, f32>
Generates a Numeric valuation from an Interval valuation.
impl<'domain> TryFrom<Interval<'domain, f32>> for Numeric<'domain, f32>
Generates a Numeric
Wrapper of Numeric::try_from(&Interval
Source§impl<'domain> TryFrom<Interval<'domain, f64>> for Numeric<'domain, f64>
Generates a Numeric valuation from an Interval valuation.
impl<'domain> TryFrom<Interval<'domain, f64>> for Numeric<'domain, f64>
Generates a Numeric
Wrapper of Numeric::try_from(&Interval
Source§impl<'domain> TryFrom<Interval<'domain, i32>> for Numeric<'domain, i32>
Generates a Numeric valuation from an Interval valuation.
impl<'domain> TryFrom<Interval<'domain, i32>> for Numeric<'domain, i32>
Generates a Numeric
Wrapper of Numeric::try_from(&Interval
let domain = Quantitative::new(5, 10).unwrap();
let interval = Interval::new(&domain, 6, 8).unwrap();
let numeric = Numeric::try_from(&interval).unwrap();
let expected = 7;
assert_eq!(numeric.value(), expected);Source§impl<'domain, T: QuantitativeLimit + Into<f64> + Add<Output = T> + Sub<Output = T>> TryFrom<Numeric<'domain, T>> for Interval<'domain, T>
Generates an Interval valuation from a Numeric valuation.
impl<'domain, T: QuantitativeLimit + Into<f64> + Add<Output = T> + Sub<Output = T>> TryFrom<Numeric<'domain, T>> for Interval<'domain, T>
Generates an Interval valuation from a Numeric valuation.
Wrapper of Interval::try_from(&Numeric).