libics.tools.control
kalman
- class libics.tools.control.kalman.KalmanFilter(history_len=10000, initial_estimate=0, initial_covariance=1, **kwargs)
Bases:
objectKalman filter for vectorial data and linear models (TODO: n-dim).
Implementation follows: https://en.wikipedia.org/wiki/Kalman_filter where we distinguish between state, observation, and control space.
- Parameters
- history_lenNone or int
This class records state observations, estimates and covariances at each step. If int, history_len restricts the number of stored steps. If None, the history is unrestricted (may lead to memory issues).
- initial_estimate, initial_covariancefloat or Array[float]
Initial state estimate, and its covariance, respectively.
- process_model, process_covariancefloat or Array[float]
Mapping from previous to subsequent state (between iterations), and its covariance, respectively
- observation_model, observation_covariancefloat or Array[float]
Mapping from state to observation space, and the covariance in observation space, respectively.
- control_modelfloat or Array[float]
Mapping from control to state space.
- Attributes
- state_observationsnp.ndarray(float)
Sequence of observations with dimensions: [iterations, {data}].
- state_estimatesnp.ndarray(float)
Sequence of state estimates with dimensions: [iterations, {data}].
- state_covariancesnp.ndarray(float)
Sequence of state covariances with dimensions: [iterations, {data}, {data}].
Methods
add_observation(observation[, control])Adds an observation iteration.
- add_observation(observation, control=None)
Adds an observation iteration.
- Parameters
- observationfloat or Array[float]
Data in observation space in this iteration.
- controlNone or float or Array[float]
Control value change applied prior to this observation. If None, no control is applied.
- Returns
- state_estimatefloat or Array[float]
Posterior state estimate.
- property control_model
- property observation_covariance
- property observation_model
- property process_covariance
- property process_model
- property state_covariances
- property state_estimates
- property state_observations
pid
- class libics.tools.control.pid.ArrayControlLoop(*args, history_len=None, trg_image=None, init_ctrl_image=None, **kwargs)
Bases:
objectProportional-integral control loop of array-like variables.
- Parameters
- history_lenint or None
int: number of points saved in history. None: unlimited history.
- trg_imagefloat or Array[float]
Initial setpoint. May be changed when running.
- init_ctrl_imagefloat or Array[float]
Initial control value.
Notes
After initialization, the control loop is executed by calling
add_ctrl_step()in each control step.- Attributes
- act_images
- ctrl_images
- dif_images
- err_images
- trg_image
- trg_images
Methods
add_ctrl_step(act_image[, trg_image, step])Adds a measurement step.
Gets the PI-kernel used to calculate the error signal.
remove_steps([steps])Removes given number of steps from history.
set_ctrl_kernel(gain_prop[, ...])Sets feedback parameters for proportional and limited integral gain.
- LOGGER = <Logger libics.tools.control.pid.ArrayControlLoop (WARNING)>
- property act_images
- add_ctrl_step(act_image, trg_image=None, step=None)
Adds a measurement step.
- Parameters
- act_imagefloat or Array[float]
Actual, measured image.
- trg_imagefloat or Array[float]
Sets new current target image. If None, uses
current_trg_image.- stepint or None
If int < 0, removes given number of latest steps (see also
remove_steps()). If int >= 0, removes all later steps and updates the given step. If None, appends a new step.
- property ctrl_images
- property dif_images
- property err_images
- get_ctrl_kernel()
Gets the PI-kernel used to calculate the error signal.
- remove_steps(steps=1)
Removes given number of steps from history.
- set_ctrl_kernel(gain_prop, gain_integr_lim=None, num_integr_lim=25, tau_integr_lim=- 1000000.0)
Sets feedback parameters for proportional and limited integral gain.
For the limited integral control loop, an exponential kernel is used.
- Parameters
- amp_propfloat
Proportional gain.
- gain_integr_limfloat
Limited integral gain at latest step. Exponentially taperes off over characteristic length number of steps towards zero.
- num_integr_limint
Number of steps until limited integral gain is zero.
- tau_integr_limfloat
Exponential characteristic number of steps, i.e. denominator of exponent.
- property trg_image
- property trg_images
- libics.tools.control.pid.ImageControlLoop
- libics.tools.control.pid.get_ctrl_image(old_ctrl_image, err_image, vmin=None, vmax=None)
- libics.tools.control.pid.get_dif_image(act_image, trg_image, offset=None, scale=None)
Calculates the difference between actual and target image.
- Parameters
- act_imageArray[2, float]
Actual image.
- trg_imageArray[2, float]
Target image.
- offset, scale
TODO: rescaling stuff
- Returns
- dif_imageArray[2, float]
Difference image.
- libics.tools.control.pid.get_err_image(dif_images, kernel, vmin=None, vmax=None, mask=None)
Calculates the error signal from a history of difference images.
- Parameters
- dif_imagesArray[3, float]
History of difference images with dimensions: [history_steps, *image_dims].
- kernelArray[1, float]
Weighing gain kernel. Can be used to implement PI control.
- vmin, vmaxfloat
Clipping values.
- maskArray[2, bool]
Error mask.
- Returns
- err_imageArray[2, float]
Error signal image.