# Path: pyglm/components/component.py
# class Component(object):
#     """
#     """
#     
#     def __init__(self, model):
#         """ Initialize the component with the parameters from the given model.
#         """
#         pass
#     
#     def get_variables(self):
#         """ Get a dictionary of (name : Theano variable) items for all the
#             symbolic variables associated with this component.
#         """
#         return {}
#     
#     def get_state(self):
#         return {}
# 
#     def preprocess_data(self, data):
#         """ Set the shared memory variables that depend on the data
#         """
#         pass
# 
#     def set_data(self, data):
#         """ Set the shared memory variables that depend on the data
#         """
#         pass
#     
#     def set_hyperparameters(self, model):
#         """ Set hyperparameters of the model
#         """
#         pass
# 
#     def sample(self, acc):
#         """
#         return a sample of the variables
#                 """
#         return {}


import numpy as np
import theano
import theano.tensor as T
    import matplotlib
    import matplotlib.pyplot as plt
    import matplotlib.animation as manimation
from pyglm.components.component import Component
        from theano.sandbox.linalg.ops import Det
    from hips.inference.hmc import hmc

    def set_hyperparameters(self, model):
        """ Set the hyperparameters of the model
        """
        self.sigma.set_value(model['sigma'])

    def sample(self, acc, size=(1,)):
        """ Sample from the prior
                """
        N,D = size

        # TODO: Actually sample a DPP
        # TODO: For now we just run a Markov chain to sample
        L = T.dmatrix('L')
        lp = self.log_p(L)
        glp = T.grad(lp, L)

        f_lp = lambda x: -1.0*lp.eval({L : x.reshape((N,D))})
        f_glp = lambda x: -1.0*glp.eval({L : x.reshape((N,D))}).reshape(N*D)

        # x0 = L1.reshape(N*D)
        x = self.bound.get_value() * np.random.randn(N*D)
        N_smpls = 1000
        for s in np.arange(N_smpls):
            x = hmc(f_lp, f_glp, 0.25, 1, x)

        assert np.all(np.isfinite(x))

        return x.reshape((N,D))


# Path: pyglm/components/component.py
# class Component(object):
#     """
#     """
#     
#     def __init__(self, model):
#         """ Initialize the component with the parameters from the given model.
#         """
#         pass
#     
#     def get_variables(self):
#         """ Get a dictionary of (name : Theano variable) items for all the
#             symbolic variables associated with this component.
#         """
#         return {}
#     
#     def get_state(self):
#         return {}
# 
#     def preprocess_data(self, data):
#         """ Set the shared memory variables that depend on the data
#         """
#         pass
# 
#     def set_data(self, data):
#         """ Set the shared memory variables that depend on the data
#         """
#         pass
#     
#     def set_hyperparameters(self, model):
#         """ Set hyperparameters of the model
#         """
#         pass
# 
#     def sample(self, acc):
#         """
#         return a sample of the variables
#                 """
#         return {}


# Path: pyglm/components/priors.py
import numpy as np
import theano
import theano.tensor as T
    import matplotlib
    import matplotlib.pyplot as plt
    import matplotlib.animation as manimation
from pyglm.components.component import Component
        from theano.sandbox.linalg.ops import Det
    from hips.inference.hmc import hmc


    def set_hyperparameters(self, model):
        """ Set the hyperparameters of the model
        """
        self.sigma.set_value(model['sigma'])

    def sample(self, acc, size=(1,)):
        """ Sample from the prior
                """
        N,D = size

        # TODO: Actually sample a DPP
        # TODO: For now we just run a Markov chain to sample
        L = T.dmatrix('L')
        lp = self.log_p(L)
        glp = T.grad(lp, L)

        f_lp = lambda x: -1.0*lp.eval({L : x.reshape((N,D))})
        f_glp = lambda x: -1.0*glp.eval({L : x.reshape((N,D))}).reshape(N*D)

        # x0 = L1.reshape(N*D)
        x = self.bound.get_value() * np.random.randn(N*D)
        N_smpls = 1000
        for s in np.arange(N_smpls):
            x = hmc(f_lp, f_glp, 0.25, 1, x)

        assert np.all(np.isfinite(x))

        return x.reshape((N,D))


class Dirichlet(Component):