# 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
# 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 theano
import theano.tensor as T
from pyglm.utils.basis import *
from pyglm.components.component import Component
from pyglm.components.priors import create_prior
        from theano.tensor.signal.conv import conv2d

        # Normalize so that the interpolated basis has volume 1
        if self.imp_model['basis']['norm']:
            ibasis = ibasis / self.imp_model['dt_max']
        # Normalize so that the interpolated basis has unit L1 norm
#         if self.prms['basis']['norm']:
#             ibasis = ibasis / np.tile(np.sum(ibasis,0),[Lt_int,1])
        self.ibasis = theano.shared(value=ibasis)

    def preprocess_data(self, data):
        """ Set the shared memory variables that depend on the data
        """
        ibasis = self.ibasis.get_value()

        # Project the presynaptic spiking onto the basis
        nT,Ns = data["S"].shape
        assert Ns == self.N, "ERROR: Spike train must be (TxN) " \
                             "dimensional where N=%d" % self.N
        fS = convolve_with_basis(data["S"], ibasis)

        # Flatten this manually to be safe
        # (there's surely a way to do this with numpy)
        (nT,Nc,B) = fS.shape
        assert Nc == self.N, "ERROR: Convolution with spike train " \
                             "resulted in incorrect shape: %s" % str(fS.shape)
        data['fS'] = fS

    def set_data(self, data):
        self.ir.set_value(data['fS'])


# 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
# 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/impulse.py
import theano
import theano.tensor as T
from pyglm.utils.basis import *
from pyglm.components.component import Component
from pyglm.components.priors import create_prior
        from theano.tensor.signal.conv import conv2d


        # Normalize so that the interpolated basis has volume 1
        if self.imp_model['basis']['norm']:
            ibasis = ibasis / self.imp_model['dt_max']
        # Normalize so that the interpolated basis has unit L1 norm
#         if self.prms['basis']['norm']:
#             ibasis = ibasis / np.tile(np.sum(ibasis,0),[Lt_int,1])
        self.ibasis = theano.shared(value=ibasis)

    def preprocess_data(self, data):
        """ Set the shared memory variables that depend on the data
        """
        ibasis = self.ibasis.get_value()

        # Project the presynaptic spiking onto the basis
        nT,Ns = data["S"].shape
        assert Ns == self.N, "ERROR: Spike train must be (TxN) " \
                             "dimensional where N=%d" % self.N
        fS = convolve_with_basis(data["S"], ibasis)

        # Flatten this manually to be safe
        # (there's surely a way to do this with numpy)
        (nT,Nc,B) = fS.shape
        assert Nc == self.N, "ERROR: Convolution with spike train " \
                             "resulted in incorrect shape: %s" % str(fS.shape)
        data['fS'] = fS

    def set_data(self, data):
        self.ir.set_value(data['fS'])


class NormalizedBasisImpulses(Component):