Skip to main content

nominal_api_conjure/conjure/objects/scout/compute/api/
custom_curve_fit.rs

1#[derive(
2    Debug,
3    Clone,
4    conjure_object::serde::Serialize,
5    conjure_object::serde::Deserialize,
6    conjure_object::private::DeriveWith
7)]
8#[serde(crate = "conjure_object::serde")]
9#[derive_with(PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[conjure_object::private::staged_builder::staged_builder]
11#[builder(crate = conjure_object::private::staged_builder, update, inline)]
12pub struct CustomCurveFit {
13    #[builder(custom(type = super::StringConstant, convert = Box::new))]
14    #[serde(rename = "formula")]
15    formula: Box<super::StringConstant>,
16    #[builder(
17        default,
18        map(key(type = super::LocalVariableName), value(type = super::CurveFitVariable))
19    )]
20    #[serde(
21        rename = "variables",
22        skip_serializing_if = "std::collections::BTreeMap::is_empty",
23        default
24    )]
25    variables: std::collections::BTreeMap<
26        super::LocalVariableName,
27        super::CurveFitVariable,
28    >,
29    #[builder(
30        default,
31        map(key(type = String, into), value(type = super::DoubleConstant))
32    )]
33    #[serde(
34        rename = "parameters",
35        skip_serializing_if = "std::collections::BTreeMap::is_empty",
36        default
37    )]
38    parameters: std::collections::BTreeMap<String, super::DoubleConstant>,
39}
40impl CustomCurveFit {
41    /// Constructs a new instance of the type.
42    #[inline]
43    pub fn new(formula: super::StringConstant) -> Self {
44        Self::builder().formula(formula).build()
45    }
46    /// A mathematical expression in terms of variable and parameter names, e.g. `a * x + b * sin(x)`.
47    /// Variable names must match keys in the `variables` map; parameter names must match keys in the
48    /// `parameters` map.
49    #[inline]
50    pub fn formula(&self) -> &super::StringConstant {
51        &*self.formula
52    }
53    /// Named input series referenced in the formula. Keys must match the variable names used in the formula expression.
54    #[inline]
55    pub fn variables(
56        &self,
57    ) -> &std::collections::BTreeMap<super::LocalVariableName, super::CurveFitVariable> {
58        &self.variables
59    }
60    /// Named fitting parameters and their initial guesses. Keys must match the parameter names used in
61    /// the formula expression; values are the starting points passed to the optimizer. The target the
62    /// curve is fit against is the `y` of the enclosing curve fit (the timeSeries series values, or the
63    /// scatter `y` series).
64    #[inline]
65    pub fn parameters(
66        &self,
67    ) -> &std::collections::BTreeMap<String, super::DoubleConstant> {
68        &self.parameters
69    }
70}