Skip to content

Commit 3f03ee9

Browse files
committed
more clippy
1 parent ba3c95b commit 3f03ee9

File tree

7 files changed

+51
-35
lines changed

7 files changed

+51
-35
lines changed

src/basis_function/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use nalgebra::{DVector, Scalar};
99
///
1010
/// * `$\vec{x}$` is an independent variable, like time, spatial coordinates and so on,
1111
/// * `$\alpha_j$` are scalar parameter of this function
12+
///
1213
/// The functions must have at least one parameter argument additional ot the location parameter, i.e. a function
1314
/// `$f(\vec{x})$` does not satisfy the trait, but e.g. `$f(\vec{x},\alpha_1)$` does. The function
1415
/// must be vector valued and should produce a vector of the same size as `\vec{x}`. (If you want to
@@ -18,15 +19,20 @@ use nalgebra::{DVector, Scalar};
1819
/// If it is violated, then calculations using the basis function will return errors in the [SeparableModel](crate::model::SeparableModel).
1920
///
2021
/// # Variadic Functions
22+
///
2123
/// Since Rust does not have variadic functions or generics, this trait is implemented for all functions up to
2224
/// a maximum number of arguments. Right now this is implemented for up to 10 arguments.
2325
///
2426
/// # Generic Parameters
27+
///
2528
/// ## Scalar Type
29+
///
2630
/// The functions must have an interface `Fn(&DVector<ScalarType>,ScalarType)-> DVector<ScalarType>`,
2731
/// `Fn(&DVector<ScalarType>,ScalarType,ScalarType)-> DVector<ScalarType>` and so on.
2832
/// All numeric types, including the return value must be of the same scalar type.
33+
///
2934
/// ## ArgList : The argument list
35+
///
3036
/// This type is of no consequence for the user because it will be correctly inferred when
3137
/// passing a function. It is a [nifty trick](https://geo-ant.github.io/blog/2021/rust-traits-and-variadic-functions/)
3238
/// that allows us to implement this trait for functions taking different arguments. Just FYI: The
@@ -42,9 +48,10 @@ where
4248
/// # Arguments
4349
/// * `x`: the vector `$\vec{x}$`
4450
/// * `params`: The parameters `$(\alpha_1,...,\alpha_N)$` as a slice. The slice must have
45-
/// the correct number of arguments for calling the function (no more, no less).
51+
/// the correct number of arguments for calling the function (no more, no less).
4652
///
4753
/// # Effect and Panics
54+
///
4855
/// If the slice has fewer elements than the parameter argument list. If the slice has more element,
4956
/// only the first `$N$` elements are used and dispatched to the parameters in order, i.e.
5057
/// `$\alpha_1$`=`param[0]`, ..., `$\alpha_N$`=`param[N-1]`. Calling eval will result in evaluating

src/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747
//! Lets look at the components of this equation in more detail. The vector valued function
4848
//! `$\vec{f}(\vec{\alpha},\vec{c}) \in \mathbb{C}^{N_{data}}$` is the model we want to fit. It depends on
4949
//! two vector valued parameters:
50+
//!
5051
//! * `$\vec{\alpha}=(\alpha_1,\dots,\alpha_{N_{params}})^T$` is the vector of nonlinear model parameters.
51-
//! We will get back to these later.
52+
//! We will get back to these later.
5253
//! * `$\vec{c}=(c_1,\dots,c_{N_{basis}})^T$` is the vector of coefficients for the basis functions.
53-
//! Those are the linear model parameters.
54+
//! Those are the linear model parameters.
5455
//!
5556
//! Note that we call `$\vec{\alpha}$` the _nonlinear parameters_ and `$\vec{c}$` the _coefficients_ of the model
5657
//! just to make the distinction between the two types of parameters clear. The coefficients are
@@ -349,11 +350,11 @@
349350
//! statement is the following:
350351
//!
351352
//! * We have not only one observation but a set `$\{\vec{y}_s\}$`, `$s=1,...,S$` of
352-
//! observations.
353+
//! observations.
353354
//! * We want to fit the separable nonlinear function `$\vec{f}(\vec{\alpha},\vec{c})$`
354-
//! to all vectors of observations, but in such a way that the linear parameters
355-
//! are allowed to vary with `$s$`, but the nonlinear parameters
356-
//! are the same for the whole dataset.
355+
//! to all vectors of observations, but in such a way that the linear parameters
356+
//! are allowed to vary with `$s$`, but the nonlinear parameters
357+
//! are the same for the whole dataset.
357358
//!
358359
//! This is called global fitting with multiple right hand sides,
359360
//! because the nonlinear parameters are not

src/model/builder/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ pub mod error;
5454
/// **Function Arguments and Output**
5555
///
5656
/// * The first argument of the function must be a reference to a `&DVector` type
57-
/// that accepts the independent variable (the `$\vec{x}$` values) and the other
58-
/// parameters must be scalars that are the nonlinear parameters that the basis
59-
/// function depends on.
57+
/// that accepts the independent variable (the `$\vec{x}$` values) and the other
58+
/// parameters must be scalars that are the nonlinear parameters that the basis
59+
/// function depends on.
6060
///
6161
/// So if we want to model a basis function `$\vec{f_1}(\vec{x},\vec{\alpha})$`
6262
/// where `$\vec{\alpha}=(\alpha_1,\alpha_2)$` we would write the function in Rust as
@@ -129,14 +129,14 @@ pub mod error;
129129
/// ** Rules You Must Abide By **
130130
///
131131
/// * Basis functions must be **nonlinear** in the parameters they take. If they aren't, you can always
132-
/// rewrite the problem so that the linear parameters go in the coefficient vector `$\vec{c}$`. This
133-
/// means that each partial derivative also depend on all the parameters that the basis function depends
134-
/// on.
132+
/// rewrite the problem so that the linear parameters go in the coefficient vector `$\vec{c}$`. This
133+
/// means that each partial derivative also depend on all the parameters that the basis function depends
134+
/// on.
135135
///
136136
/// * Derivatives must take the same parameter arguments *and in the same order* as the original
137-
/// basis function. This means if basis function `$\vec{f}_j$` is given as `$\vec{f}_j(\vec{x},a,b)$`,
138-
/// then the derivatives must also be given with the parameters `$a,b$` in the same order, i.e.
139-
/// `$\partial/\partial a \vec{f}_j(\vec{x},a,b)$`, `$\partial/\partial b \vec{f}_j(\vec{x},a,b)$`.
137+
/// basis function. This means if basis function `$\vec{f}_j$` is given as `$\vec{f}_j(\vec{x},a,b)$`,
138+
/// then the derivatives must also be given with the parameters `$a,b$` in the same order, i.e.
139+
/// `$\partial/\partial a \vec{f}_j(\vec{x},a,b)$`, `$\partial/\partial b \vec{f}_j(\vec{x},a,b)$`.
140140
///
141141
/// **Rules Enforced at Compile Time**
142142
///
@@ -333,8 +333,8 @@ where
333333
/// * The list of parameters must only contain unique names
334334
/// * The list of parameter names must not be empty
335335
/// * Parameter names must not contain a comma. This is a precaution because
336-
/// `&["alpha,beta"]` most likely indicates a typo for `&["alpha","beta"]`. Any other form
337-
/// of punctuation is allowed.
336+
/// `&["alpha,beta"]` most likely indicates a typo for `&["alpha","beta"]`. Any other form
337+
/// of punctuation is allowed.
338338
pub fn new<StrCollection>(parameter_names: StrCollection) -> Self
339339
where
340340
StrCollection: IntoIterator,

src/model/builder/modelfunction_builder/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::model::model_basis_function::ModelBasisFunction;
1616
/// * the model parameters are unique and non-empty
1717
/// * the function parameters are unique, non-empty and a subset of the model params
1818
/// * a derivative is provided for each parameter that the function depends on
19-
/// (all other derivatives are zero, because the function does not depends on other params)
19+
/// (all other derivatives are zero, because the function does not depend on other params)
2020
///
2121
#[doc(hidden)]
2222
pub struct ModelBasisFunctionBuilder<ScalarType>
@@ -38,13 +38,17 @@ where
3838
/// begin constructing a modelfunction for a specific model. The modelfunction must take
3939
/// a subset of the model parameters. This is the first step in creating a function, because
4040
/// the modelfunction must have partial derivatives specified for each parameter it takes.
41+
///
4142
/// # Arguments
43+
///
4244
/// * `model_parameters`: the model parameters of the model to which this function belongs. This is important
43-
/// so the builder understands how the parameters of the function relate to the parameters of the model.
45+
/// so the builder understands how the parameters of the function relate to the parameters of the model.
4446
/// * `function_parameters`: the parameters that the function takes. Those must be in the order
45-
/// of the parameter vector. The paramters must not be empty, nor may they contain duplicates
47+
/// of the parameter vector. The paramters must not be empty, nor may they contain duplicates
4648
/// * `function`: the actual function.
49+
///
4750
/// # Result
51+
///
4852
/// A model builder that can be used to add derivatives.
4953
pub fn new<FuncType, StrCollection, ArgList>(
5054
model_parameters: Vec<String>,
@@ -88,9 +92,9 @@ where
8892
/// Add a derivative for the function with respect to the given parameter.
8993
/// # Arguments
9094
/// * `parameter`: the parameter with respect to which the derivative is taken.
91-
/// The parameter must be inside the set of model parameters. Furthermore the
95+
/// The parameter must be inside the set of model parameters. Furthermore the
9296
/// * `derivative`: the partial derivative of the function with which the
93-
/// builder was created.
97+
/// builder was created.
9498
pub fn partial_deriv<FuncType, ArgList>(mut self, parameter: &str, derivative: FuncType) -> Self
9599
where
96100
FuncType: BasisFunction<ScalarType, ArgList> + 'static,

src/model/detail.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use crate::model::builder::error::ModelBuildError;
99
/// * the set of parameters is not empty
1010
/// * the set of parameters contains only unique elements
1111
/// * any of the parameter names contains a comma. This indicates most likely a typo when giving the parameter list
12+
///
1213
/// # Returns
14+
///
1315
/// Ok if the conditions hold, otherwise an error variant.
1416
pub fn check_parameter_names<StrType>(param_names: &[StrType]) -> Result<(), ModelBuildError>
1517
where
@@ -80,11 +82,13 @@ where
8082
/// of model parameters and dispatch them to our model function
8183
/// # Arguments
8284
/// * `model_parameters`: the parameters that the complete model that this function belongs to
83-
/// depends on
85+
/// depends on
8486
/// * `function_parameters`: the parameters (in right to left order) that the basisfunction depends
85-
/// on. Must be a subset of the model parameters.
87+
/// on. Must be a subset of the model parameters.
8688
/// * `function` a basis function that depends on a number of parameters
89+
///
8790
/// # Result
91+
///
8892
/// Say our model depends on parameters `$\vec{p}=(\alpha,\beta,\gamma)$` and the `function` argument
8993
/// is a basis function `$f(\vec{x},\gamma,\beta)$`. Then calling `create_wrapped_basis_function(&["alpha","beta","gamma"],&["gamma","alpha"],f)`
9094
/// creates a wrapped function `$\tilde{f}(\vec{x},\vec{p})$` which can be called with `$\tilde{f}(\vec{x},\vec{p})=f(\vec{x},\gamma,\beta$`.

src/model/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,11 @@ where
312312
/// # Arguments
313313
///
314314
/// * `derivative_index`: The index of the nonlinear parameter with respect to which
315-
/// partial derivative should be evaluated. We use _zero based indexing_
316-
/// here! Put in more simple terms, say your model has three nonlinear parameters
317-
/// `a,b,c`, so your vector of nonlinear parameters is `$\vec{\alpha} = (a,b,c)$`.
318-
/// Then index 0 requests `$\partial/\partial_a$`, index 1 requests `$\partial/\partial_b$`
319-
/// and index 2 requests `$\partial/\partial_c$`.
315+
/// partial derivative should be evaluated. We use _zero based indexing_
316+
/// here! Put in more simple terms, say your model has three nonlinear parameters
317+
/// `a,b,c`, so your vector of nonlinear parameters is `$\vec{\alpha} = (a,b,c)$`.
318+
/// Then index 0 requests `$\partial/\partial_a$`, index 1 requests `$\partial/\partial_b$`
319+
/// and index 2 requests `$\partial/\partial_c$`.
320320
///
321321
/// # Result
322322
///

src/statistics/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,11 @@ where
224224
/// # Arguments
225225
///
226226
/// * `probability` the confidence level of the confidence interval, expressed
227-
/// as a probability value between 0 and 1. Note that it can't be 0 or 1, but
228-
/// anything in between. Since least squares fitting assumes Gaussian error
229-
/// distributions, we can use the quantiles of the normal distribution to
230-
/// relate this to often used "number of sigmas". For example the probability
231-
/// `$68.3 \% = 0.683$` corresponds to (approximately) `$1\sigma$`.
227+
/// as a probability value between 0 and 1. Note that it can't be 0 or 1, but
228+
/// anything in between. Since least squares fitting assumes Gaussian error
229+
/// distributions, we can use the quantiles of the normal distribution to
230+
/// relate this to often used "number of sigmas". For example the probability
231+
/// `$68.3 \% = 0.683$` corresponds to (approximately) `$1\sigma$`.
232232
///
233233
/// # Returns
234234
///

0 commit comments

Comments
 (0)