aspire.optimization package¶
Submodules¶
aspire.optimization.conj_grad module¶
- aspire.optimization.conj_grad.conj_grad(a_fun, b, cg_opt=None, init=None)¶
Conjugate Gradient method to solve the linear system.
This is corresponding to the implemented version in the ASPIRE Matlab package.
- Parameters:
a_fun – A function handle specifying the linear operation x -> Ax. When multiple right-hand sides are supplied, this function takes as input an array of shape (n, p), where n is the number of right-hand sides and p is the dimension of the space.
b – The vector consisting of the right hand side of Ax = b. Again, n different right-hand sides are given by supplying an array of shape (n, p).
cg_opt –
The parameters for the conjugate gradient method, including: max_iter: Maximum number of iterations (default 50). verbose: The extent to which information on progress should be
output to the terminal (default 1).
- iter_callback: If non-empty, specifies a function to be called at
the end of every iteration. In this case, iter_callback must be a function handle taking as single argument the info structure at the current iteration. For information on the info structure, see below (default []).
- preconditioner: If non-empty, specifies a preconditioner to be
used in every iteration as a function handle defining the linear operator x -> Px (default []).
- rel_tolerance: The relative error at which to stop the algorithm,
even if it has not yet reached the maximum number of iterations (default 1e-15).
- store_iterates: Defines whether to store each intermediate results
in the info structure under the x, p and r fields. Since this may require a large amount of memory, this is not recommended (default false).
init – A structure specifying the starting point of the algorithm. This can contain values of x or p that will be used for initialization (default empty).
- Returns:
The output result includes: x: The result of the conjugate gradient method after max_iter iterations
or once the residual norm has decreased below rel_tolerance, relative.
obj: The value of the objective function at the last iteration. info: A structure array containing intermediate information obtained during each iteration. These fields include: - iter: The iteration number. - x (for store_iterates true): The value of x. - r (for store_iterates true): The residual vector. - p (for store_iterates true): The p vector. - res: The square norm of the residual. - obj: The objective function.
- aspire.optimization.conj_grad.fill_struct(obj=None, att_vals=None)¶
Fill object with attributes in a dictionary.
If a struct is not given a new object will be created and filled. If the given struct has a field in att_vals, the original field will stay, unless specified otherwise in overwrite. att_vals is a dictionary with string keys, and for each key: if hasattr(s, key) and key in overwrite:
pass
- else:
setattr(s, key, att_vals[key])
- Parameters:
obj
att_vals
:param overwrite :return: