SlowPointFinder#
- class brainpy.analysis.SlowPointFinder(f_cell, f_type=None, f_loss=None, verbose=True, args=(), inputs=None, t=None, dt=None, target_vars=None, excluded_vars=None, f_loss_batch=None, fun_inputs=None)[source]#
Find fixed/slow points by numerical optimization.
This class can help you:
optimize to find the closest fixed points / slow points
exclude any fixed points whose fixed point loss is above threshold
exclude any non-unique fixed points according to a tolerance
exclude any far-away “outlier” fixed points
- Parameters:
f_cell (
Union[Callable,DynamicalSystem]) – The target of computing the recurrent units.f_type (
str) –The system’s type: continuous system or discrete system.
’continuous’: continuous derivative function, denotes this is a continuous system, or
’discrete’: discrete update function, denotes this is a discrete system.
verbose (
bool) – Whether output the optimization progress.f_loss (
Callable) –The loss function. - If
f_typeis “discrete”, the loss function must receive threearguments, i.e.,
loss(outputs, targets, axis).If
f_typeis “continuous”, the loss function must receive two arguments, i.e.,loss(outputs, axis).
Added in version 2.2.0.
t (
float) –Parameter for
f_cellis instance ofDynamicalSystem. The time to evaluate the fixed points. Default is 0.Added in version 2.2.0.
dt (
float) –Parameter for
f_cellis instance ofDynamicalSystem. The numerical integration step, which can be used when . The default is given by brainpy.math.get_dt().Added in version 2.2.0.
inputs (
Sequence) –Parameter for
f_cellis instance ofDynamicalSystem. Same asinputsinDSRunner.Added in version 2.2.0.
excluded_vars (
Union[Sequence[Variable],Dict[str,Variable]]) –Parameter for
f_cellis instance ofDynamicalSystem. The excluded variables (can be a sequence of Variable instances). These variables will not be included for optimization of fixed points.Added in version 2.2.0.
target_vars (
Dict[str,Variable]) –Parameter for
f_cellis instance ofDynamicalSystem. The target variables (can be a dict of Variable instances). These variables will be included for optimization of fixed points. The candidate points later provided should have same keys as intarget_vars.Added in version 2.2.0.
f_loss_batch (
Callable) –Parameter for
f_cellis instance ofDynamicalSystem. The function to compute the loss.Deprecated since version 2.2.0: Has been removed. Please use
f_lossto set different loss function.fun_inputs (
Callable) –Deprecated since version 2.3.1: Will be removed since version 2.4.0.
- compute_jacobians(points, stack_dict_var=True, plot=False, num_col=4, len_col=3, len_row=2)[source]#
Compute the Jacobian matrices at the points.
- Parameters:
points (
Union[TypeVar(ArrayType,Array,Variable,TrainVar,Array,ndarray),Dict[str,TypeVar(ArrayType,Array,Variable,TrainVar,Array,ndarray)]]) – The fixed points with the shape of (num_point, num_dim).stack_dict_var (
bool) – Stack dictionary variables to calculate Jacobian matrix?plot (
bool) – Plot the decomposition results of the Jacobian matrix.num_col (
int) – The number of the figure column.len_col (
int) – The length of each column.len_row (
int) – The length of each row.
- static decompose_eigenvalues(matrices, sort_by='magnitude', do_compute_lefts=False)[source]#
Compute the eigenvalues of the matrices.
- Parameters:
- Returns:
decompositions (
list) – A list of dictionaries with sorted eigenvalues components: (eigenvalues, right eigenvectors, and left eigenvectors).
- exclude_outliers(tolerance=1.0)[source]#
Exclude points whose closest neighbor is further than threshold.
- Parameters:
tolerance (
float) – Any point whose closest fixed point is greater than tol is an outlier.
- filter_loss(tolerance=1e-05)[source]#
Filter fixed points whose speed larger than a given tolerance.
- Parameters:
tolerance (
float) – Discard fixed points with squared speed larger than this value.
- find_fps_with_gd_method(candidates, tolerance=1e-05, num_batch=100, num_opt=10000, optimizer=None)[source]#
Optimize fixed points with gradient descent methods.
- Parameters:
candidates (
Union[TypeVar(ArrayType,Array,Variable,TrainVar,Array,ndarray),Dict[str,TypeVar(ArrayType,Array,Variable,TrainVar,Array,ndarray)]]) – The array with the shape of (batch size, state dim) of hidden states of RNN to start training for fixed points.tolerance (
Union[float,Dict[str,float]]) – The loss threshold during optimizationnum_opt (
int) – The maximum number of optimization.num_batch (
int) – Print training information during optimization every so often.optimizer (
Optimizer) –The optimizer instance.
Added in version 2.1.2.
- find_fps_with_opt_solver(candidates, opt_solver='BFGS')[source]#
Optimize fixed points with nonlinear optimization solvers.
- keep_unique(tolerance=0.025)[source]#
Filter unique fixed points by choosing a representative within tolerance.
- Parameters:
tolerance (
float) – Tolerance for determination of identical fixed points.
- property losses: ndarray#
Losses of fixed points.
- property opt_losses: ndarray#
The optimization losses.
- property selected_ids: ndarray#
The selected ids of candidate points.