Searching for Roots¶
- dcprogs.likelihood.find_roots(determinant, intervals=None, tolerance=1e-12, **kwargs)¶
Computes roots for each interval.
Parameters: - determinant – A function or functor of a single variable.
- intervals –
A list of items [(a0, b0), ..., (a1, b1)], where (a, b) is the interval over which to look for roots.
If this object is None (default), then uses find_root_intervals() to figure out the intervals.
- tolerance – Tolerance criteria. Used to determine multiplicity.
- kwargs – Passed on to brentq() and find_root_intervals().
Returns: A list of items (root, multiplicity).
Bracketing all Roots¶
- dcprogs.likelihood.find_lower_bound_for_roots(determinant, start=0.0, alpha=2.0, itermax=100)¶
Figures out lower bound for root.
The lower bound is obtained by iteratively checking the lowest eigenvalue \(\epsilon_i^s\) of \(H(s_i)\), where \(s_i\) is the guess at iteration \(i\). If the lowest eigenvalue is smaller than \(s_i\), then \(s_{i+1} = \epsilon_i^s + \alpha(\epsilon_i^s - s_i)\) is created.
Parameters: - det (DeterminantEq) – Function for which to guess bound for lower root.
- start (Number) – Starting point.
- alpha (Number) – Factor from which to determine next best guess.
- itermax (Integer) – Maximum number of iterations before bailing out.
- dcprogs.likelihood.find_upper_bound_for_roots(determinant, start=0.0, alpha=2.0, itermax=100)¶
Figures out upper bound for root.
The upper bound is obtained by iteratively checking the largest eigenvalue \(\epsilon_i^s\) of \(H(s_i)\), where \(s_i\) is the guess at iteration \(i\). If the largest eigenvalue is larger than \(s_i\), then \(s_{i+1} = \epsilon_i^s + \alpha(\epsilon_i^s - s_i)\) is created.
Parameters: - det (DeterminantEq) – Function for which to guess bound for lower root.
- start (Number) – Starting point.
- alpha (Number) – Factor from which to determine next best guess.
- itermax (Integer) – Maximum number of iterations before bailing out.
Finding intervals for each root¶
- dcprogs.likelihood.find_root_intervals(determinant, lower_bound=None, upper_bound=None, tolerance=1e-08)¶
Returns intervals for searching roots.
Finds a set of intervals between lower_bound and upper_bound, each containing a single root.
Parameters: - determinant – DeterminantEq instance for which to guess bound for lower root.
- lower_bound – Number Lower bound of the interval within which to search for roots. If None, the lower bound is determined using find_lower_bound_for_roots().
- upper_bound (Number) – Upper bound of the interval within which to search for roots. If None, the upper bound is determined using find_upper_bound_for_roots().
- tolerance (Number) – Size of the smallest possible intervals. Intervals smaller than this are likely to have multiple roots.
Raises : ArithmeticError when NaN is encountered or when eigenvalue solver fails.
Returns: A list [(a, b), multiplicity], where (a, b) denotes an interval, and multiplicity the multiplicity of the root. All roots with multiplicity\(> 1\) will have a size of tolerance or smaller.
- dcprogs.likelihood.find_root_intervals_brute_force(determinant, resolution=0.1, lower_bound=None, upper_bound=None, tolerance=1e-08)¶
Find intervals for roots using brute force.
Computes all values between lower_bound and upper_bound, for a given resolution. If the determinant changes sign between two values, or if it comes to within tolerance of zero, then the eigenvalues of H are used to determine possible multiplicity.
param determinant: Instance of DeterminantEq for which to find root intervals param Number resolution: Resolution at which to sample interval. param Number lower_bound: Lower bound of interval. If None, then find_lower_bound_for_roots() is called. param Number upper_bound: Upper bound of interval. If None, then find_upper_bound_for_roots() is called. param Number tolerance: Tolerance below which the value of the determinant is considered close to zero. raises: ArithmeticError when NaN is encountered or when eigenvalue solver fails. “
returns: A list [(a, b), multiplicity], where (a, b) denotes an interval, and multiplicity the multiplicity of the root. All roots with multiplicity > 1 will have a size of tolerance or smaller.
Root optimization¶
- dcprogs.likelihood.brentq(function, a, b, xtol=1e-12, rtol=4.440892098e-16, itermax=100)¶
Computes zeros via brentq.
This is the exact same algorithm as scipy.optimize.brentq. Only, the errors and c types have been changed to accomodate DCProgs and protect the innocents.
Parameters: - function (callable) – Function for which to solve \(f(x) = 0\).
- xstart (float) – Beginning of the interval
- xend (float) – End of the interval
- xtol (float) – Tolerance for interval size.
- rtol (float) – Tolerance for interval size. The convergence criteria is an affine function of the root: \(x_{\mathrm{tol}}+r_{\mathrm{tol}} x_{\mathrm{current}} = \frac{|x_a-x_b|}{2}\).
- itermax (int) – maximum number of iterations.
Returns: the tuple (x, iterations, times the function was called)