# Path: pyglm/components/weights.py
# class ConstantWeightModel(Component):
#     def __init__(self, model):
#         """ Initialize the filtered stim model
#         """
#         self.model = model
#         N = model['N']
# 
#         prms = model['network']['weight']
#         self.value = prms['value']
#         
#         # Define weight matrix
#         self.W = self.value * T.ones((N,N))
# 
#         # Define log probability
#         self.log_p = T.constant(0.0)
# 
#     def get_state(self):
#         return {'W': self.W}


import scipy.optimize as opt
from pyglm.utils.packvec import *
from components.graph import CompleteGraphModel
from pyglm.components.weights import ConstantWeightModel
""" Fit a Network GLM with MAP estimation. For some models, the log posterior
    is concave and has a unique maximum.
"""



def map_estimate(network_glm, x0=None):
    """
    Compute the maximum a posterior parameter estimate using Theano to compute
    gradients of the log probability.
    """
    N = network_glm.model['N']
    network = network_glm.network

    # Make sure the network is a complete adjacency matrix with constant weights
    # and basis function impulse responses
    if not isinstance(network.graph, CompleteGraphModel):
        raise Exception("MAP inference can only be performed with the complete graph model.")

# Path: pyglm/components/weights.py
# class ConstantWeightModel(Component):
#     def __init__(self, model):
#         """ Initialize the filtered stim model
#         """
#         self.model = model
#         N = model['N']
# 
#         prms = model['network']['weight']
#         self.value = prms['value']
#         
#         # Define weight matrix
#         self.W = self.value * T.ones((N,N))
# 
#         # Define log probability
#         self.log_p = T.constant(0.0)
# 
#     def get_state(self):
#         return {'W': self.W}


# Path: pyglm/inference/map.py
import scipy.optimize as opt
from pyglm.utils.packvec import *
from components.graph import CompleteGraphModel
from pyglm.components.weights import ConstantWeightModel

""" Fit a Network GLM with MAP estimation. For some models, the log posterior
    is concave and has a unique maximum.
"""



def map_estimate(network_glm, x0=None):
    """
    Compute the maximum a posterior parameter estimate using Theano to compute
    gradients of the log probability.
    """
    N = network_glm.model['N']
    network = network_glm.network

    # Make sure the network is a complete adjacency matrix with constant weights
    # and basis function impulse responses
    if not isinstance(network.graph, CompleteGraphModel):
        raise Exception("MAP inference can only be performed with the complete graph model.")

    if not isinstance(network.weights, ConstantWeightModel):