optimatic.utils package¶
Submodules¶
optimatic.utils.differentiate module¶
Numerical differentiation
-
optimatic.utils.differentiate.
central_diff
(f, h, epsilon=0.0001)[source]¶ Calculates the value of \(f^{\prime}(x=h)\) using the central difference method:
\[f^{\prime}(h) \approx \frac{f(h + \epsilon) - f(h - \epsilon)} {2 \epsilon}\]Parameters: - f – The function to differentiate
- h – The value to evaluate the derivative at
- epsilon – The value to use for epsilon
-
optimatic.utils.differentiate.
forward_diff
(f, h, epsilon=0.0001)[source]¶ Calculates the value of \(f^{\prime}(x=h)\) using the foward difference method:
\[f^{\prime}(h) \approx \frac{f(h + \epsilon) - f(h)}{\epsilon}\]Parameters: - f – The function to differentiate
- h – The value to evaluate the derivative at
- epsilon – The value to use for epsilon
optimatic.utils.generate module¶
Methods for generating data to fit using optimisation algorithms
-
optimatic.utils.generate.
random_polynomial
(degree, x, scale=5, noisy=True)[source]¶ Generates a polynomial of the given degree with random coefficients, then adds some noise.
Parameters: - degree – The degree of the polynomial to generate
- x – An array of x values to evaluate the polynomial \(y(x)\) at
- scale – The stdev of the normal distribution from which the parameters wil be sampled
- noisy – Whether or not to add noise to the generated data. If true, noise will be sampled from a normal distribution with stdev scale/2
Return y: The generated data points
Return coefficients: The coefficients of the polynomial