I am a newbie to PyMC3 but I was wondering if there is an example of how one would model a full 2D mixture of Gaussian model. In a sense I would like to combine the example from here
You are correct; unfortunately NormalMixture only supports 1D observations at this time. This should be possible in an unmarginalized way by sampling the mixture components from a categorical distribution. This approach, however, will take much longer to mix.
I am a little confused about how to group covariance matrices here is my model, where i create two covariance matrices cov_1 and cov_2. Is this not correct? It should be a 2D mixture of gaussians with two components.
import pandas as pd
import numpy as np
import pymc3 as pm
import matplotlib.pyplot as plt
import seaborn as sns
import theano.tensor as tt
AsTensorError Traceback (most recent call last)
in ()
1 with model:
----> 2 trace = pm.sample(1000, pm.Metropolis())[500::5]
/Users/chirag/anaconda/lib/python3.6/site-packages/pymc3/step_methods/arraystep.py in new(cls, *args, **kwargs)
58 # If we don’t return the instance we have to manually
59 # call init
—> 60 step.init([var], *args, **kwargs)
61 # Hack for creating the class correctly when unpickling.
62 step.__newargs = ([var], ) + args, kwargs
/Users/chirag/anaconda/lib/python3.6/site-packages/theano/compile/pfunc.py in clone_v_get_shared_updates(v, copy_inputs_over)
91 if owner not in clone_d:
92 for i in owner.inputs:
—> 93 clone_v_get_shared_updates(i, copy_inputs_over)
94
95 clone_d[owner] = owner.clone_with_new_inputs(
/Users/chirag/anaconda/lib/python3.6/site-packages/theano/compile/pfunc.py in clone_v_get_shared_updates(v, copy_inputs_over)
91 if owner not in clone_d:
92 for i in owner.inputs:
—> 93 clone_v_get_shared_updates(i, copy_inputs_over)
94
95 clone_d[owner] = owner.clone_with_new_inputs(
/Users/chirag/anaconda/lib/python3.6/site-packages/theano/compile/pfunc.py in clone_v_get_shared_updates(v, copy_inputs_over)
91 if owner not in clone_d:
92 for i in owner.inputs:
—> 93 clone_v_get_shared_updates(i, copy_inputs_over)
94
95 clone_d[owner] = owner.clone_with_new_inputs(
/Users/chirag/anaconda/lib/python3.6/site-packages/theano/compile/pfunc.py in clone_v_get_shared_updates(v, copy_inputs_over)
91 if owner not in clone_d:
92 for i in owner.inputs:
—> 93 clone_v_get_shared_updates(i, copy_inputs_over)
94
95 clone_d[owner] = owner.clone_with_new_inputs(
/Users/chirag/anaconda/lib/python3.6/site-packages/theano/compile/pfunc.py in clone_v_get_shared_updates(v, copy_inputs_over)
91 if owner not in clone_d:
92 for i in owner.inputs:
—> 93 clone_v_get_shared_updates(i, copy_inputs_over)
94
95 clone_d[owner] = owner.clone_with_new_inputs(
/Users/chirag/anaconda/lib/python3.6/site-packages/theano/compile/pfunc.py in clone_v_get_shared_updates(v, copy_inputs_over)
91 if owner not in clone_d:
92 for i in owner.inputs:
—> 93 clone_v_get_shared_updates(i, copy_inputs_over)
94
95 clone_d[owner] = owner.clone_with_new_inputs(
/Users/chirag/anaconda/lib/python3.6/site-packages/theano/compile/pfunc.py in clone_v_get_shared_updates(v, copy_inputs_over)
91 if owner not in clone_d:
92 for i in owner.inputs:
—> 93 clone_v_get_shared_updates(i, copy_inputs_over)
94
95 clone_d[owner] = owner.clone_with_new_inputs(
/Users/chirag/anaconda/lib/python3.6/site-packages/theano/compile/pfunc.py in clone_v_get_shared_updates(v, copy_inputs_over)
91 if owner not in clone_d:
92 for i in owner.inputs:
—> 93 clone_v_get_shared_updates(i, copy_inputs_over)
94
95 clone_d[owner] = owner.clone_with_new_inputs(
/Users/chirag/anaconda/lib/python3.6/site-packages/theano/compile/pfunc.py in clone_v_get_shared_updates(v, copy_inputs_over)
94
95 clone_d[owner] = owner.clone_with_new_inputs(
—> 96 [clone_d[i] for i in owner.inputs], strict=rebuild_strict)
97 for old_o, new_o in zip(owner.outputs, clone_d[owner].outputs):
98 clone_d.setdefault(old_o, new_o)
/Users/chirag/anaconda/lib/python3.6/site-packages/theano/tensor/basic.py in as_tensor_variable(x, name, ndim)
169 if not isinstance(x.type, TensorType):
170 raise AsTensorError(
–> 171 “Variable type field must be a TensorType.”, x, x.type)
172
173 if ndim is None:
AsTensorError: (‘Variable type field must be a TensorType.’, mu0_shared, <theano.gof.type.Generic object at 0x111f763c8>)