# Path: pyglm/utils/basis.py
# def create_basis(prms):
#     """ Create a basis for impulse response functions
#     """
#     type = prms['type'].lower()
#     if type == 'exp':
#         basis = create_exp_basis(prms)
#     elif type == 'cosine':
#         basis = create_cosine_basis(prms)
#     elif type == 'gaussian':
#         basis = create_gaussian_basis(prms)
#     elif type == 'identity' or type == 'eye':
#         basis = create_identity_basis(prms)
#     elif type == 'file':
#         if os.path.exists(prms["fname"]):
#             basis = load_basis_from_file(prms['fname'])
#     else:
#         raise Exception("Unrecognized basis type: %s", type)
#     return basis
# 
# Path: pyglm/components/priors.py
# def create_prior(model, **kwargs):
#     typ = model['type'].lower()
#     if typ == 'normal' or \
#        typ == 'gaussian':
#        return Gaussian(model, **kwargs)
#     elif typ == 'categorical':
#        return Categorical(model, **kwargs)
#     elif typ == 'jointcategorical' or \
#          typ == 'joint_categorical':
#        return JointCategorical(model, **kwargs)
#     elif typ == 'spherical_gaussian':
#         return SphericalGaussian(model, **kwargs)
#     elif typ == 'group_lasso' or \
#          typ == 'grouplasso':
#         return GroupLasso(model, **kwargs)
#     elif typ == 'dpp':
#         return DeterminenalPointProcess(model, **kwargs)
#     elif typ == 'dirichlet':
#         return Dirichlet(model)
#     else:
#         raise Exception("Unrecognized prior type: %s" % typ)


import numpy as np
import theano.tensor as T
from component import Component
from pyglm.utils.basis import create_basis
from pyglm.components.priors import create_prior
        from pyglm.components.priors import Categorical, JointCategorical
    def sample(self, acc):
        """
        return a sample of the variables
        """
        # Sample alpha from a Dirichlet prior
        # alpha = np.random.dirichlet(self.alpha0*np.ones(self.R))
        alpha = self.alpha_prior.sample(acc)

        # Sample Y from categorical dist
        Y = np.random.choice(self.R, size=self.N, p=alpha)
        return {str(self.alpha) : alpha,
                str(self.Y) : Y}

class LatentTypeWithTuningCurve(LatentType):
    """
    Extent the basic latent type component to also include tuning curves
    """
    def __init__(self, model, type_model):
        super(LatentTypeWithTuningCurve, self).__init__(model, type_model)

        # Also initialize the tuning curves
        self.mu = self.type_model['mu']
        self.sigma = self.type_model['sigma']

        # Create a basis for the stimulus response
        self.spatial_basis = create_basis(self.type_model['spatial_basis'])
        self.spatial_shape = self.type_model['spatial_shape']
        self.spatial_ndim = len(self.spatial_shape)
        (_,Bx) = self.spatial_basis.shape


# Path: pyglm/utils/basis.py
# def create_basis(prms):
#     """ Create a basis for impulse response functions
#     """
#     type = prms['type'].lower()
#     if type == 'exp':
#         basis = create_exp_basis(prms)
#     elif type == 'cosine':
#         basis = create_cosine_basis(prms)
#     elif type == 'gaussian':
#         basis = create_gaussian_basis(prms)
#     elif type == 'identity' or type == 'eye':
#         basis = create_identity_basis(prms)
#     elif type == 'file':
#         if os.path.exists(prms["fname"]):
#             basis = load_basis_from_file(prms['fname'])
#     else:
#         raise Exception("Unrecognized basis type: %s", type)
#     return basis
# 
# Path: pyglm/components/priors.py
# def create_prior(model, **kwargs):
#     typ = model['type'].lower()
#     if typ == 'normal' or \
#        typ == 'gaussian':
#        return Gaussian(model, **kwargs)
#     elif typ == 'categorical':
#        return Categorical(model, **kwargs)
#     elif typ == 'jointcategorical' or \
#          typ == 'joint_categorical':
#        return JointCategorical(model, **kwargs)
#     elif typ == 'spherical_gaussian':
#         return SphericalGaussian(model, **kwargs)
#     elif typ == 'group_lasso' or \
#          typ == 'grouplasso':
#         return GroupLasso(model, **kwargs)
#     elif typ == 'dpp':
#         return DeterminenalPointProcess(model, **kwargs)
#     elif typ == 'dirichlet':
#         return Dirichlet(model)
#     else:
#         raise Exception("Unrecognized prior type: %s" % typ)


# Path: pyglm/components/latent.py
import numpy as np
import theano.tensor as T
from component import Component
from pyglm.utils.basis import create_basis
from pyglm.components.priors import create_prior
        from pyglm.components.priors import Categorical, JointCategorical

    def sample(self, acc):
        """
        return a sample of the variables
        """
        # Sample alpha from a Dirichlet prior
        # alpha = np.random.dirichlet(self.alpha0*np.ones(self.R))
        alpha = self.alpha_prior.sample(acc)

        # Sample Y from categorical dist
        Y = np.random.choice(self.R, size=self.N, p=alpha)
        return {str(self.alpha) : alpha,
                str(self.Y) : Y}

class LatentTypeWithTuningCurve(LatentType):
    """
    Extent the basic latent type component to also include tuning curves
    """
    def __init__(self, model, type_model):
        super(LatentTypeWithTuningCurve, self).__init__(model, type_model)

        # Also initialize the tuning curves
        self.mu = self.type_model['mu']
        self.sigma = self.type_model['sigma']

        # Create a basis for the stimulus response
        self.spatial_basis = create_basis(self.type_model['spatial_basis'])
        self.spatial_shape = self.type_model['spatial_shape']
        self.spatial_ndim = len(self.spatial_shape)
        (_,Bx) = self.spatial_basis.shape


        self.temporal_basis = create_basis(self.type_model['temporal_basis'])