coopihc.inference.LinearGaussianContinuous.LinearGaussianContinuous
- class LinearGaussianContinuous(*args, **kwargs)[source]
Bases:
coopihc.inference.BaseInferenceEngine.BaseInferenceEngine
An Inference Engine that handles a continuous Gaussian Belief. It assumes a Gaussian prior and a Gaussian likelihood.
Expectations of the engine
This inference engine expects the agent to have in its internal state:
The mean matrix of the belief, stored as ‘belief-mu’
The covariance matrix of the belief, stored as ‘belief-sigma’
The new observation, stored as ‘y’
The covariance matrix associated with the observation, stored as ‘Sigma_0’
Inference
This engine uses the observation to update the beliefs (which has been computed from previous observations).
To do so, a Gaussian noisy observation model is assumed, where x is the latest mean matrix of the belief.
\[\begin{align} p(y|x) \sim \mathcal{N}(x, \Sigma_0) \end{align}\]If the initial prior (belief probability) is Gaussian as well, then the posterior will remain Gaussian (because we are only applying linear operations to Gaussians, Gaussianity is preserved). So the posterior after t-1 observations has the following form, where \((\mu(t-1), \Sigma(t-1))\) are respectively the mean and covariance matrices of the beliefs.
\[\begin{align} p(x(t-1)) \sim \mathcal{N}(\mu(t-1), \Sigma(t-1)) \end{align}\]On each new observation, the mean and covariance matrices are updated like so:
\[\begin{split}\begin{align} p(x(t) | y, x(t-1)) \sim \mathcal{N}(\Sigma(t) \left[ \Sigma_0^{-1}y + \Sigma(t-1) \mu(t-1) \right], \Sigma(t)) \\ \Sigma(t) = (\Sigma_0^{-1} + \Sigma(t-1)^{-1})^{-1} \end{align}\end{split}\]Render
—- plot mode:
This engine will plot mean beliefs on the task axis and the covariance beliefs on the agent axis, plotted as confidence intervals (bars for 1D and ellipses for 2D).
Example files
coopihczoo.eye.users
Methods
add observation
Bind function to the engine with a given name.
Draw confidence ellipsis.
Compute confidence interval.
Apply this decorator to use self.agent_observation as default value to infer from if agent_observation = None
Draw beliefs of dimension 'dim' on axis 'ax'.
infer
Draws the beliefs (mean value and ellipsis or confidence intervals according to dimension).
reset _summary_
Attributes
The agent's last action
host
The last observation.
role
The current agent state
unwrapped
- add_observation(observation)
add observation
Add an observation to a buffer. If the buffer does not exist, create a naive buffer. The buffer has a size given by buffer length
- Parameters
observation (
State
) – observation produced by an engine
- bind(func, as_name=None)
Bind function to the engine with a given name. If as_name is None, then the func name is used.
- Parameters
func (function) – function to bind
as_name (string, optional) – name of resulting method, defaults to None
- Returns
bound method
- Return type
method
- confidence_ellipse(mu, covariance, ax, n_std=2.0, facecolor='#d1dcf0', edgecolor='b', **kwargs)[source]
Draw confidence ellipsis. See Matplotlib documentation for source. Computing eigenvalues directly should lead to code that is more readily understandable.
- Parameters
mu (numpy.ndarray) – mean matrix
cov (numpy.ndarray) – covariance matrix
ax (matplotlib object) – axis
n_std (float, optional) – size of the confidence interval in std, defaults to 2.0
facecolor (str, optional) – fill color, defaults to “#d1dcf0”
edgecolor (str, optional) – frontier color, defaults to “b”
- confidence_interval(mu, cov, ax, n_std=2.0, color='b', **kwargs)[source]
Compute confidence interval. For the Gaussian case like here, this is straightforward
- Parameters
mu (numpy.ndarray) – mean matrix
cov (numpy.ndarray) – covariance matrix
ax (matplotlib object) – axis
n_std (float, optional) – size of the confidence interval in std, defaults to 2.0
color (str, optional) – color of the CI, defaults to “b”
- default_value()
Apply this decorator to use self.agent_observation as default value to infer from if agent_observation = None
- draw_beliefs(ax, dim)[source]
Draw beliefs of dimension ‘dim’ on axis ‘ax’.
- Parameters
ax (matplotlib object) – axis
dim (int) – dimension of data
- render(mode='text', ax_user=None, ax_assistant=None, ax_task=None)[source]
Draws the beliefs (mean value and ellipsis or confidence intervals according to dimension).
- reset(random=True)
reset _summary_
Empty the buffer
- Parameters
random (bool, optional) – whether to randomize parameters internal to the inference engine. This is provided in case of subclass the BaseInferenceEngine, defaults to True.