# Path: pydlm/base/baseModel.py
# class baseModel:
#     """ The baseModel class that provides the basic model structure for dlm. 
# 
#     Attributes:
#         transition: the transition matrix G
#         evaluation: the evaluation F
#         noiseVar: the variance of the observation noise
#         sysVar: the covariance of the underlying states
#         innovation: the incremnent of the latent covariance W
#         state: the latent states
#         df: the degree of freedom (= number of data points)
#         obs: the expectation of the observation
#         obsVar: the variance of the observation
# 
#     Methods:
#         initializeObservation: initialize the obs and obsVar
#         validation: validate the matrix dimensions are consistent.
#     """
# 
# 
#     # define the components of a baseModel
#     def __init__(self, transition = None, evaluation = None, noiseVar = None, \
#                  sysVar = None, innovation = None, state = None, df = None):
#         self.transition = transition
#         self.evaluation = evaluation
#         self.noiseVar = noiseVar
#         self.sysVar = sysVar
#         self.innovation = innovation
#         self.state = state
#         self.df = df
#         self.obs = None
#         self.obsVar = None
# 
#         # a hidden data field used only for model prediction
#         self.prediction = __model__()
# 
# 
#     # initialize the observation mean and variance
#     def initializeObservation(self):
#         """ Initialize the value of obs and obsVar
# 
#         """
#         self.validation()
#         self.obs = np.dot(self.evaluation, self.state)
#         self.obsVar = np.dot(np.dot(self.evaluation, self.sysVar), self.evaluation.T) \
#                       + self.noiseVar
# 
# 
#     # checking if the dimension matches with each other
#     def validation(self):
#         """ Validate the model components are consistent
# 
#         """
#         # check symmetric
#         tl.checker.checkSymmetry(self.transition)
#         tl.checker.checkSymmetry(self.sysVar)
#         if self.innovation is not None:
#             tl.checker.checkSymmetry(self.innovation)
# 
#         # check wether dimension match
#         tl.checker.checkMatrixDimension(self.transition, self.sysVar)
#         if self.innovation is not None:
#             tl.checker.checkMatrixDimension(self.transition, self.innovation)
#         tl.checker.checkVectorDimension(self.evaluation, self.transition)
#         tl.checker.checkVectorDimension(self.state, self.transition)
# 
# Path: pydlm/modeler/matrixTools.py
# class matrixTools:
#     @staticmethod
#     def matrixAddInDiag(A, B):
#         if A is None:
#             return np.matrix(B)
#         elif B is None:
#             return np.matrix(A)
#         else:
#             (An, Ap) = A.shape
#             (Bn, Bp) = B.shape
# 
#             newMatrixA = np.concatenate((A, np.matrix(np.zeros((An, Bp)))), 1)
#             newMatrixB = np.concatenate((np.matrix(np.zeros((Bn, Ap))), B), 1)
#             return np.concatenate((newMatrixA, newMatrixB), 0)
# 
# 
#     # A + B = (A; B)
#     @staticmethod
#     def matrixAddByRow(A, B):
#         if A is None:
#             return B
#         elif B is None:
#             return A
#         else:
#             return np.concatenate((A, B), 0)
# 
# 
#     # A + B = (A B)
#     @staticmethod
#     def matrixAddByCol(A, B):
#         if A is None:
#             return np.matrix(B)
#         elif B is None:
#             return np.matrix(A)
#         else:
#             return np.concatenate((A, B), 1)
# 
# 
#     @staticmethod
#     def AddTwoVectors(a, b):
#         if a is None:
#             return np.array(b)
#         elif b is None:
#             return np.array(a)
#         else:
#             return np.concatenate((a, b))


import numpy as np
from pydlm.base.baseModel import baseModel
from copy import deepcopy
from pydlm.modeler.matrixTools import matrixTools as mt
        quantities from the components.

        Args:
            noise: the initial guess of the variance of the observation noise.
        """
        if len(self.staticComponents) == 0 and \
           len(self.dynamicComponents) == 0 and \
           len(self.automaticComponents) == 0:

            raise NameError('The model must contain at least' +
                            ' one component')

        # construct transition, evaluation, prior state, prior covariance
        if self._printInfo:
            print('Initializing models...')
        transition = None
        evaluation = None
        state = None
        sysVar = None
        self.discount = np.array([])

        # first construct for the static components
        # the evaluation will be treated separately for static or dynamic
        # as the latter one will change over time
        currentIndex = 0  # used for compute the index
        for i in self.staticComponents:
            comp = self.staticComponents[i]
            transition = mt.matrixAddInDiag(transition, comp.transition)
            evaluation = mt.matrixAddByCol(evaluation,
                                           comp.evaluation)

# Path: pydlm/base/baseModel.py
# class baseModel:
#     """ The baseModel class that provides the basic model structure for dlm. 
# 
#     Attributes:
#         transition: the transition matrix G
#         evaluation: the evaluation F
#         noiseVar: the variance of the observation noise
#         sysVar: the covariance of the underlying states
#         innovation: the incremnent of the latent covariance W
#         state: the latent states
#         df: the degree of freedom (= number of data points)
#         obs: the expectation of the observation
#         obsVar: the variance of the observation
# 
#     Methods:
#         initializeObservation: initialize the obs and obsVar
#         validation: validate the matrix dimensions are consistent.
#     """
# 
# 
#     # define the components of a baseModel
#     def __init__(self, transition = None, evaluation = None, noiseVar = None, \
#                  sysVar = None, innovation = None, state = None, df = None):
#         self.transition = transition
#         self.evaluation = evaluation
#         self.noiseVar = noiseVar
#         self.sysVar = sysVar
#         self.innovation = innovation
#         self.state = state
#         self.df = df
#         self.obs = None
#         self.obsVar = None
# 
#         # a hidden data field used only for model prediction
#         self.prediction = __model__()
# 
# 
#     # initialize the observation mean and variance
#     def initializeObservation(self):
#         """ Initialize the value of obs and obsVar
# 
#         """
#         self.validation()
#         self.obs = np.dot(self.evaluation, self.state)
#         self.obsVar = np.dot(np.dot(self.evaluation, self.sysVar), self.evaluation.T) \
#                       + self.noiseVar
# 
# 
#     # checking if the dimension matches with each other
#     def validation(self):
#         """ Validate the model components are consistent
# 
#         """
#         # check symmetric
#         tl.checker.checkSymmetry(self.transition)
#         tl.checker.checkSymmetry(self.sysVar)
#         if self.innovation is not None:
#             tl.checker.checkSymmetry(self.innovation)
# 
#         # check wether dimension match
#         tl.checker.checkMatrixDimension(self.transition, self.sysVar)
#         if self.innovation is not None:
#             tl.checker.checkMatrixDimension(self.transition, self.innovation)
#         tl.checker.checkVectorDimension(self.evaluation, self.transition)
#         tl.checker.checkVectorDimension(self.state, self.transition)
# 
# Path: pydlm/modeler/matrixTools.py
# class matrixTools:
#     @staticmethod
#     def matrixAddInDiag(A, B):
#         if A is None:
#             return np.matrix(B)
#         elif B is None:
#             return np.matrix(A)
#         else:
#             (An, Ap) = A.shape
#             (Bn, Bp) = B.shape
# 
#             newMatrixA = np.concatenate((A, np.matrix(np.zeros((An, Bp)))), 1)
#             newMatrixB = np.concatenate((np.matrix(np.zeros((Bn, Ap))), B), 1)
#             return np.concatenate((newMatrixA, newMatrixB), 0)
# 
# 
#     # A + B = (A; B)
#     @staticmethod
#     def matrixAddByRow(A, B):
#         if A is None:
#             return B
#         elif B is None:
#             return A
#         else:
#             return np.concatenate((A, B), 0)
# 
# 
#     # A + B = (A B)
#     @staticmethod
#     def matrixAddByCol(A, B):
#         if A is None:
#             return np.matrix(B)
#         elif B is None:
#             return np.matrix(A)
#         else:
#             return np.concatenate((A, B), 1)
# 
# 
#     @staticmethod
#     def AddTwoVectors(a, b):
#         if a is None:
#             return np.array(b)
#         elif b is None:
#             return np.array(a)
#         else:
#             return np.concatenate((a, b))


# Path: pydlm/modeler/builder.py
import numpy as np
from pydlm.base.baseModel import baseModel
from copy import deepcopy
from pydlm.modeler.matrixTools import matrixTools as mt

        quantities from the components.

        Args:
            noise: the initial guess of the variance of the observation noise.
        """
        if len(self.staticComponents) == 0 and \
           len(self.dynamicComponents) == 0 and \
           len(self.automaticComponents) == 0:

            raise NameError('The model must contain at least' +
                            ' one component')

        # construct transition, evaluation, prior state, prior covariance
        if self._printInfo:
            print('Initializing models...')
        transition = None
        evaluation = None
        state = None
        sysVar = None
        self.discount = np.array([])

        # first construct for the static components
        # the evaluation will be treated separately for static or dynamic
        # as the latter one will change over time
        currentIndex = 0  # used for compute the index
        for i in self.staticComponents:
            comp = self.staticComponents[i]
            transition = mt.matrixAddInDiag(transition, comp.transition)
            evaluation = mt.matrixAddByCol(evaluation,
                                           comp.evaluation)

            state = mt.matrixAddByRow(state, comp.meanPrior)