API reference¶
Everything below is importable from the top-level felcu package.
Solver¶
felcu.solve_fe_coefficients ¶
solve_fe_coefficients(problem: str, *, method: str = 'sobolev', matrix: ndarray | Sequence[Sequence[complex]] | None = None, sigma_min: float | None = None, sigma_max: float | None = None, gap: tuple[float, float] | None = None, spectral_kind: str = 'auto', eta: float | None = None, target_error: float = 1e-12, error_metric: str = 'linf', m: int | None = None, m_values: Sequence[int] | int | None = None, lambdas: Sequence[float] | None = None, sobolev_w: float | None = None, sobolev_r: float | None = None, order_fit: int | None = None, fit_oversample: int | None = None, val_n: int = 4001, selection: str = 'smallest_alpha', hermitian_tol: float = 1e-12) -> FourierExtensionResult
Compute Fourier-extension LCU block-encoding coefficients.
The fit is centred on the spectrum: with mu and delta the
centre and half-width of the fitted set, tau = pi / (eta delta) and
f(H) = g(tau (H - mu I)) (result.mu, result.tau). Singular
values are fitted through the Hermitian dilation of the matrix, whose
spectrum is symmetric, so mu = 0 and the series is odd.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
str
|
One of |
required |
method
|
str
|
Coefficient-selection strategy (see
:func:
The explicit methods do not support the two-interval fit of
inversion on an indefinite interval or on singular values, and for
definite inversion, square root and logarithm need
|
'sobolev'
|
matrix
|
ndarray | Sequence[Sequence[complex]] | None
|
Square matrix whose spectral information drives the fitting. Mutually exclusive with sigma_min / sigma_max / gap; one of the two is required. |
None
|
sigma_min
|
float | None
|
Spectral interval: eigenvalue or singular-value bounds, per spectral_kind. |
None
|
sigma_max
|
float | None
|
Spectral interval: eigenvalue or singular-value bounds, per spectral_kind. |
None
|
gap
|
tuple[float, float] | None
|
For inversion on an indefinite eigenvalue interval
( |
None
|
spectral_kind
|
str
|
Which spectral data the bounds (or matrix) describe.
|
'auto'
|
eta
|
float | None
|
Fourier-extension parameter (must exceed 1). Computed automatically
when omitted; see :func: |
None
|
target_error
|
float
|
Desired approximation error. |
1e-12
|
error_metric
|
str
|
|
'linf'
|
m
|
int | None
|
Fixed Fourier truncation order; overrides m_values. |
None
|
m_values
|
Sequence[int] | int | None
|
Candidate truncation orders to search over. |
None
|
lambdas
|
Sequence[float] | None
|
Grid of regularisation strengths |
None
|
sobolev_w
|
float | None
|
Order w of the H_r^w regulariser, which weights the k-th Fourier
mode by |
None
|
sobolev_r
|
float | None
|
Scale r of the H_r^w regulariser, with |
None
|
order_fit
|
int | None
|
Number of derivative orders included in the fit system: |
None
|
fit_oversample
|
int | None
|
Oversampling factor for the Gauss quadrature grid. Defaults to
|
None
|
val_n
|
int
|
Number of validation points. |
4001
|
selection
|
str
|
|
'smallest_alpha'
|
hermitian_tol
|
float
|
Tolerance for the Hermitian test. |
1e-12
|
Returns:
| Type | Description |
|---|---|
FourierExtensionResult
|
The selected result; |
felcu.compute_fe_coefficients ¶
compute_fe_coefficients(*args, **kwargs) -> tuple[float, np.ndarray, np.ndarray]
Convenience wrapper; returns (a0, ak, bk) directly.
Takes the same arguments as :func:solve_fe_coefficients and discards
everything but the coefficients. Use :func:solve_fe_coefficients
when you also need tau, the achieved error, or whether the fit
converged.
Returns:
| Name | Type | Description |
|---|---|---|
a0 |
float
|
Constant term. |
ak, bk : numpy.ndarray
|
Sine and cosine coefficients (copies), each of length |
Result¶
felcu.FourierExtensionResult
dataclass
¶
Result of a Fourier-extension coefficient computation.
Returned by :func:~felcu.solve_fe_coefficients. The fitted series is
g(x) = a0 + sum_k ak[k-1] sin(kx) + bk[k-1] cos(kx), and the matrix
function is f(H) = g(tau (H - mu I)). For singular values, H
is the Hermitian dilation of the matrix and mu = 0.
Attributes:
| Name | Type | Description |
|---|---|---|
problem |
str
|
|
method |
str
|
Coefficient-selection strategy: |
basis_used |
str
|
|
m |
int
|
Truncation order: the number of harmonics. |
eta |
float
|
Extension parameter; the series was fitted on
|
tau |
float
|
Scale between the matrix spectrum and the fitted variable,
|
mu |
float
|
Centre of the fitted spectrum, which the fit is shifted by: the
midpoint of |
alpha |
float
|
Subnormalisation |
target_error |
float
|
The requested error. |
error_metric |
str
|
|
achieved_error |
float
|
Achieved error in error_metric. |
achieved_l2_error |
float
|
Achieved L2 error on the fitted domain. A side of a two-interval domain that is a single point counts as much as the whole domain. |
achieved_linf_error |
float
|
Achieved maximum pointwise error on the fitted domain. |
converged |
bool
|
Whether achieved_error meets target_error. |
lambda_used |
float or None
|
Sobolev regularisation strength chosen for this |
sobolev_r |
float or None
|
Scale r of the H_r^w regulariser that was used; |
sobolev_w |
float or None
|
Order w of the H_r^w regulariser that was used; |
a0 |
float
|
Constant term. |
ak |
ndarray
|
Sine coefficients, length |
bk |
ndarray
|
Cosine coefficients, length |
complex_coefficients |
ndarray
|
The same series as |
k |
ndarray
|
Harmonic indices |
x_max |
float
|
Outer edge of the fitted domain, |
x_gap |
tuple of float or None
|
For inversion on an indefinite interval or on singular values, the
gap around the pole that the fit leaves free, in the fitted
variable: the fitted set is |
sigma_min, sigma_max |
float
|
Spectral interval used (eigenvalues or singular values, per spectral_kind_used). |
gap |
tuple of float or None
|
Eigenvalue gap |
spectral_kind_used |
str
|
|
matrix_shape |
tuple of int or None
|
Shape of the input matrix, if one was given. |
matrix_is_hermitian |
bool or None
|
Whether the input matrix passed the Hermitian test, if one was given. |
all_results |
tuple of FourierExtensionResult
|
Every candidate tried, sorted by |
all_results
class-attribute
instance-attribute
¶
all_results: tuple[FourierExtensionResult, ...] = ()
coefficients
property
¶
coefficients: ndarray
Coefficients packed as a single vector in the order of basis_used.
[ak] for 'odd_sine', [a0, ak] for 'const_plus_sine',
and [a0, ak, bk] for 'full'.
circuit_coefficients
property
¶
circuit_coefficients: ndarray
Complex coefficients in circuit order, [c_0, 0, c_1, c_{-1}, ..., c_m, c_{-m}].
Length 2m + 2: the zero after c_0 is required by the
compressed circuit. See :func:~felcu.to_circuit_coefficients.
evaluate ¶
evaluate(x: ArrayLike) -> np.ndarray
Evaluate the approximation to f at points x of the original variable.
Applies the scaling for you: this is g(tau (x - mu)), which
approximates f(x) for x in the fitted spectrum. For singular
values mu = 0 and x is a singular value (or its negative, an
eigenvalue of the dilation). To evaluate g itself in the scaled
variable, use :func:~felcu.evaluate_fourier_series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ArrayLike
|
Points, of any shape, at which to approximate |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The approximation, with the same shape as x. |
apply ¶
apply(matrix: ndarray | Sequence[Sequence[complex]], hermitian_tol: float = 1e-12, interval_tol: float = 1e-08) -> np.ndarray
Apply the approximation to a Hermitian matrix: g(tau (H - mu I)) ~ f(H).
Computed classically by eigendecomposition, to check a fit against
an exact f(H). The eigenvalues of matrix must lie in the
fitted spectrum: outside it the series is a periodic extension that
bears no relation to f. They must also lie in the domain of
f, which is checked separately, so the interval slack can never
admit an eigenvalue where f is undefined: they must be positive
for the square root and the logarithm, and nonzero for inversion,
with the sign of the fitted spectrum when that is definite. For a
singular-value fit, pass the Hermitian dilation of the matrix.
Both checks use the eigenvalues as computed in floating point, so a
matrix is accepted exactly when its computed eigenvalues lie in the
fitted spectrum and the domain of f. A matrix that is singular
in exact arithmetic, but whose computed eigenvalues pass both checks,
is nonsingular to working precision, and the result is
g(tau (H - mu I)) for those computed eigenvalues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
ndarray | Sequence[Sequence[complex]]
|
Square Hermitian matrix |
required |
hermitian_tol
|
float
|
Relative tolerance for the Hermitian test. |
1e-12
|
interval_tol
|
float
|
How far, relative to the half-width of the fitted spectrum, an
eigenvalue may stray outside it before it is rejected. At the
edges of an inversion gap it is relative to the edge's distance
from 0 instead, and for a zero-width spectrum |
1e-08
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The matrix |
Raises:
| Type | Description |
|---|---|
ValueError
|
If matrix is not square, not Hermitian, or has an eigenvalue
outside the domain of |
format_circuit_coefficients ¶
format_circuit_coefficients() -> str
:attr:circuit_coefficients as a bare Python list literal, for pasting by hand.
See :func:~felcu.format_circuit_coefficients.
to_dict ¶
to_dict(include_candidates: bool = False) -> dict
Return the result as a JSON-compatible dictionary.
Arrays become lists, complex_coefficients becomes
{"k": [-m..m], "real": [...], "imag": [...]}, and non-finite
floats (tau is infinite for a zero-width interval) become the
strings "inf", "-inf" or "nan". The dictionary also
records format, format_version and felcu_version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_candidates
|
bool
|
Also store :attr: |
False
|
from_dict
classmethod
¶
from_dict(data: dict) -> FourierExtensionResult
Rebuild a result from :meth:to_dict output.
Raises:
| Type | Description |
|---|---|
ValueError
|
If data is not a saved felcu result, has an unsupported
|
to_json ¶
to_json(path: str | Path | None = None, *, indent: int | None = 2, include_candidates: bool = False) -> str
Serialise the result to JSON, and write it to path if given.
The file is standard JSON (no NaN or Infinity literals) and
can be read from any language; floats are written with enough
digits to round-trip exactly. See :meth:to_dict for the layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path | None
|
File to write. If omitted, only the string is returned. |
None
|
indent
|
int | None
|
Indentation passed to :func: |
2
|
include_candidates
|
bool
|
Also store :attr: |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The JSON text. |
Examples:
>>> result.to_json("exp_coefficients.json")
>>> loaded = FourierExtensionResult.from_json("exp_coefficients.json")
from_json
classmethod
¶
from_json(source: str | Path) -> FourierExtensionResult
Load a result saved with :meth:to_json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Path
|
A path to a JSON file, or the JSON text itself. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
As for :meth: |
__init__ ¶
__init__(problem: str, method: str, basis_used: str, m: int, eta: float, tau: float, mu: float, alpha: float, target_error: float, error_metric: str, achieved_error: float, achieved_l2_error: float, achieved_linf_error: float, converged: bool, lambda_used: float | None, sobolev_r: float | None, sobolev_w: float | None, a0: float, ak: ndarray, bk: ndarray, complex_coefficients: ndarray, k: ndarray, x_max: float, x_gap: tuple[float, float] | None, sigma_min: float, sigma_max: float, gap: tuple[float, float] | None, spectral_kind_used: str, matrix_shape: tuple[int, int] | None, matrix_is_hermitian: bool | None, all_results: tuple[FourierExtensionResult, ...] = ()) -> None
felcu.ConvergenceWarning ¶
Bases: UserWarning
No candidate order met the requested target_error.
Issued by :func:~felcu.solve_fe_coefficients, which still returns the
best candidate, with converged=False. Silence it with
warnings.simplefilter("ignore", felcu.ConvergenceWarning).
Evaluating results¶
felcu.evaluate_fourier_series ¶
evaluate_fourier_series(x: ArrayLike, a0: float | complex, ak: Sequence, bk: Sequence) -> np.ndarray
Evaluate the real Fourier series g(x) = a0 + sum_k ak sin(kx) + bk cos(kx).
The sum runs over k = 1, ..., len(ak).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ArrayLike
|
Evaluation points, of any shape. |
required |
a0
|
float | complex
|
Constant term. |
required |
ak
|
Sequence
|
Sine and cosine coefficients, of equal length. Complex values are allowed. |
required |
bk
|
Sequence
|
Sine and cosine coefficients, of equal length. Complex values are allowed. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If ak and bk have different lengths. |
felcu.evaluate_target_function ¶
evaluate_target_function(x: ArrayLike, result: FourierExtensionResult) -> np.ndarray
Evaluate the exact target function for result at points x.
This is the function the series was fitted to, in the scaled variable,
so it can be compared directly with :func:evaluate_fourier_series.
It is g(x) = f(mu + x / tau), not f itself: mu + x / tau,
1 / (mu + x / tau), exp(mu + x / tau), sqrt(mu + x / tau) or
log(mu + x / tau).
If tau is infinite (a zero-width interval), the target is constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ArrayLike
|
Evaluation points in the scaled variable. |
required |
result
|
FourierExtensionResult
|
A result from :func: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Target values, with the same shape as x. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the problem is unknown. |
felcu.fitted_domain_segments ¶
fitted_domain_segments(result: FourierExtensionResult, num: int = 2001) -> list[np.ndarray]
Return x-arrays covering the fitted domain of result.
Use these to plot or check a fit, e.g. by comparing
:func:evaluate_fourier_series with :func:evaluate_target_function
on each segment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
FourierExtensionResult
|
A result from :func: |
required |
num
|
int
|
Number of points. For a double-interval domain, each interval
gets |
2001
|
Returns:
| Type | Description |
|---|---|
list of numpy.ndarray
|
One array spanning |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
felcu.to_complex_coefficients ¶
to_complex_coefficients(a0_or_result: FourierExtensionResult | float | complex, ak: Sequence | None = None, bk: Sequence | None = None) -> np.ndarray
Convert a0, ak, bk to [c_{-m}, ..., c_0, ..., c_m].
The complex coefficients give the same series in exponential form,
g(x) = sum_{k=-m}^{m} c_k exp(i k x), with
c_0 = a0,c_k = (bk[k-1] - i ak[k-1]) / 2fork > 0,c_{-k} = (bk[k-1] + i ak[k-1]) / 2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a0_or_result
|
FourierExtensionResult | float | complex
|
Either a :class: |
required |
ak
|
Sequence | None
|
Sine and cosine coefficients, of equal length. Required unless a result is passed. |
None
|
bk
|
Sequence | None
|
Sine and cosine coefficients, of equal length. Required unless a result is passed. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Complex array of length |
Raises:
| Type | Description |
|---|---|
ValueError
|
If ak or bk is missing, or their lengths differ. |
felcu.to_circuit_coefficients ¶
to_circuit_coefficients(a0_or_result: FourierExtensionResult | float | complex, ak: Sequence | None = None, bk: Sequence | None = None) -> np.ndarray
Convert a0, ak, bk to the circuit order [c_0, 0, c_1, c_{-1}, ..., c_m, c_{-m}].
This is the order the compressed LCU circuit consumes the coefficients
in: c_0, then a zero, then the pairs c_k, c_{-k} for
k = 1, ..., m. The zero pads the 2m + 1 coefficients of
:func:to_complex_coefficients to the 2m + 2 the compressed circuit
requires; it must be kept.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a0_or_result
|
FourierExtensionResult | float | complex
|
As for :func: |
required |
ak
|
FourierExtensionResult | float | complex
|
As for :func: |
required |
bk
|
FourierExtensionResult | float | complex
|
As for :func: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Complex array of length |
Raises:
| Type | Description |
|---|---|
ValueError
|
As for :func: |
felcu.format_circuit_coefficients ¶
format_circuit_coefficients(a0_or_result: FourierExtensionResult | float | complex, ak: Sequence | None = None, bk: Sequence | None = None) -> str
Format the circuit-order coefficients as a bare Python list literal.
For pasting the coefficients somewhere by hand. Code that imports
felcu should use :func:to_circuit_coefficients (or
:attr:FourierExtensionResult.circuit_coefficients) directly instead.
Each entry is written with :func:repr, so the list reproduces
:func:to_circuit_coefficients exactly, including the zero after
c_0 that the compressed circuit requires.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a0_or_result
|
FourierExtensionResult | float | complex
|
As for :func: |
required |
ak
|
FourierExtensionResult | float | complex
|
As for :func: |
required |
bk
|
FourierExtensionResult | float | complex
|
As for :func: |
required |
Returns:
| Type | Description |
|---|---|
str
|
A Python list literal, |
Examples:
>>> print(format_circuit_coefficients(result))
[(2.718...+0j), 0j, (0.5-0.1j), (0.5+0.1j), ...]
Defaults¶
felcu.default_eta ¶
default_eta(problem: str, *, method: str = 'sobolev', matrix: ndarray | Sequence[Sequence[complex]] | None = None, sigma_min: float | None = None, sigma_max: float | None = None, gap: tuple[float, float] | None = None, spectral_kind: str = 'auto', hermitian_tol: float = 1e-12) -> float
Return the default extension parameter eta for the given problem and method.
The series is fitted on [-pi/eta, pi/eta], so eta > 1 sets how
much of the period is left free. With mu and delta the centre
and half-width of the fitted spectrum, the defaults for the
Sobolev-regularised method are
- identity and exponentiation:
2; - inversion on a definite interval, square root and logarithm:
|mu| / delta = (kappa + 1) / (kappa - 1), which puts the pole or branch point at 0 on the periodic boundary (2ifkappa == 1); - inversion on an indefinite interval or on singular values:
1 + (b - a) / (2 delta), with(a, b)the gap around the pole, which leaves the gap and the free part of the period equally wide. For singular values (or a symmetric gap) this is1 + 1/kappa.
The reflected extension always defaults to 2, which maps the
spectral endpoints onto the reflection points and gives the optimal
subnormalisation. Arcsine-Taylor needs eta > 2: it defaults to
3 for identity and exponentiation, and to
min(3, 1 + |mu|/delta) for definite inversion, square root and
logarithm, the
midpoint of the admissible range 2 < eta < 2 |mu|/delta.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
str
|
One of |
required |
method
|
str
|
|
'sobolev'
|
matrix
|
ndarray | Sequence[Sequence[complex]] | None
|
Square matrix to read the spectral interval from. Mutually exclusive with sigma_min / sigma_max / gap. |
None
|
sigma_min
|
float | None
|
Spectral interval bounds. |
None
|
sigma_max
|
float | None
|
Spectral interval bounds. |
None
|
gap
|
tuple[float, float] | None
|
Eigenvalue gap |
None
|
spectral_kind
|
str
|
|
'auto'
|
hermitian_tol
|
float
|
Tolerance for the Hermitian test. |
1e-12
|
Returns:
| Type | Description |
|---|---|
float
|
The default eta. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For inversion, square root and logarithm, if no spectral information is given
or the interval is invalid (see :func: |
Notes
Spectral information is only used for inversion, square root and logarithm; for identity and exponentiation it is ignored.
felcu.default_sobolev_r ¶
default_sobolev_r(problem: str, *, matrix: ndarray | Sequence[Sequence[complex]] | None = None, sigma_min: float | None = None, sigma_max: float | None = None, gap: tuple[float, float] | None = None, spectral_kind: str = 'auto', hermitian_tol: float = 1e-12, eta: float | None = None, sobolev_w: float = 1.0) -> float
Return the default scale r of the H_r^w regulariser for the given problem.
The regulariser weights the k-th Fourier mode by
P_w(r|k|) = sum_{j=0}^{w} (r|k|)^(2j), so
r should match the shortest length scale the fitted function g has
to resolve. The defaults follow the scale-adapted choices of
Brearley, Howarth and Adcock (Sec. VI):
- identity:
r_id = 1, since g is linear; - exponentiation:
r_exp = 1 / (1 + 1/tau), sinceg' = g / tau, which is1 / (1 + eta delta / pi); - inversion:
min(1, d), withdthe distance from the fitted set to the pole in the scaled variable. At the default eta this is the paper'sr_def = min(1, 2 pi / (kappa + 1))for a definite interval andr_indef = min(1, pi / (kappa + 1))for singular values; - square root:
r_sqrt = kappa^(-(2w - 1) / (2w)), which balances the two contributions to the extension's H_r^w norm (kappa^(-1/2)forw = 1); - logarithm:
r_log = kappa^(-(2w - 1) / (2w)) (1 + ln kappa)^(-1/w), the square-root rule with a factor for the logarithm's slower growth (kappa^(-1/2) / (1 + ln kappa)forw = 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
str
|
One of |
required |
matrix
|
ndarray | Sequence[Sequence[complex]] | None
|
Square matrix to read the spectral interval from. Mutually exclusive with sigma_min / sigma_max / gap. |
None
|
sigma_min
|
float | None
|
Spectral interval bounds. |
None
|
sigma_max
|
float | None
|
Spectral interval bounds. |
None
|
gap
|
tuple[float, float] | None
|
Eigenvalue gap |
None
|
spectral_kind
|
str
|
|
'auto'
|
hermitian_tol
|
float
|
Tolerance for the Hermitian test. |
1e-12
|
eta
|
float | None
|
Extension parameter of the fit. Defaults to
:func: |
None
|
sobolev_w
|
float
|
Order w of the regulariser; only the square-root and logarithm rules use it. |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
The default r, which lies in |
Raises:
| Type | Description |
|---|---|
ValueError
|
Except for identity, if no spectral information is given or the interval is invalid. |
felcu.default_m_grid ¶
default_m_grid(m_min: int = 4, m_max: int = 256, count: int = 32, power: float = 2.0) -> np.ndarray
Return a grid of candidate Fourier truncation orders.
The grid is m_min + (m_max - m_min) * t**power for count equally
spaced t in [0, 1], truncated to integers. With power > 1
the grid is denser at small m. This is the default m_values
for :func:~felcu.solve_fe_coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m_min
|
int
|
Smallest and largest order. |
4
|
m_max
|
int
|
Smallest and largest order. |
4
|
count
|
int
|
Number of grid points before duplicates are removed. |
32
|
power
|
float
|
Spacing exponent; |
2.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Sorted unique integer orders. Truncation can merge neighbouring
points, so there may be fewer than count. If |
Raises:
| Type | Description |
|---|---|
ValueError
|
Unless |
felcu.default_lambda_grid ¶
default_lambda_grid(lambda_max: float = 1.0, lambda_min: float = 1e-16, count: int = 12) -> np.ndarray
Return a log-spaced grid of regularisation parameters.
This is the default lambdas for
:func:~felcu.solve_fe_coefficients. The solver sorts the grid
itself and searches beyond it, so the grid only needs to bracket the
answer roughly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lambda_max
|
float
|
Largest and smallest value. |
1.0
|
lambda_min
|
float
|
Largest and smallest value. |
1.0
|
count
|
int
|
Number of values. |
12
|
Returns:
| Type | Description |
|---|---|
ndarray
|
count geometrically spaced values from lambda_max down to lambda_min. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Unless |
Name normalisation¶
felcu.canonical_problem_name ¶
canonical_problem_name(name: str) -> str
Normalise a problem name to 'identity', 'inversion', 'exponentiation', 'square_root' or 'logarithm'.
Matching ignores case and surrounding whitespace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Problem name. Accepted aliases are |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not a recognised problem or alias. |
felcu.canonical_method_name ¶
canonical_method_name(name: str) -> str
Normalise a coefficient-selection method to 'sobolev', 'reflected' or 'arcsine_taylor'.
Matching ignores case and surrounding whitespace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Method name. Accepted aliases are |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not a recognised method or alias. |
felcu.canonical_error_metric ¶
canonical_error_metric(name: str) -> str
Normalise an error-metric name to 'l2' or 'linf'.
Matching ignores case and surrounding whitespace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name. |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not a recognised metric or alias. |