Пример #1
0
def createParamBagForPrior(Data,
                           D=0,
                           nu=0,
                           beta=None,
                           m=None,
                           kappa=None,
                           MMat='zero',
                           ECovMat=None,
                           sF=1.0,
                           Prior=None,
                           **kwargs):
    ''' Initialize ParamBag of parameters which specify prior.

    Returns
    -------
    Prior : ParamBag
    '''
    if Data is None:
        D = int(D)
    else:
        D = int(Data.dim)
    nu = np.maximum(nu, D + 2)
    kappa = np.maximum(kappa, 1e-8)
    if beta is None:
        if ECovMat is None or isinstance(ECovMat, str):
            ECovMat = createECovMatFromUserInput(D, Data, ECovMat, sF)
        beta = np.diag(ECovMat) * (nu - 2)
    else:
        if beta.ndim == 0:
            beta = np.asarray([beta], dtype=np.float)
    if m is None:
        if MMat == 'data':
            m = np.sum(Data.X, axis=0)
        else:
            m = np.zeros(D)
    elif m.ndim < 1:
        m = np.asarray([m], dtype=np.float)
    if Prior is None:
        Prior = ParamBag(K=0, D=D)
    assert Prior.D == D
    Prior.setField('nu', nu, dims=None)
    Prior.setField('kappa', kappa, dims=None)
    Prior.setField('m', m, dims=('D'))
    Prior.setField('beta', beta, dims=('D'))
    return Prior
Пример #2
0
    def createPrior(self, Data, nu=0, B=None, ECovMat=None, sF=1.0, **kwargs):
        ''' Initialize Prior ParamBag attribute.

        Post Condition
        ------
        Prior expected covariance matrix set to match provided value.
        '''
        D = self.D
        nu = np.maximum(nu, D + 2)
        if B is None:
            if ECovMat is None or isinstance(ECovMat, str):
                ECovMat = createECovMatFromUserInput(D, Data, ECovMat, sF)
            B = ECovMat * (nu - D - 1)
        else:
            B = as2D(B)
        self.Prior = ParamBag(K=0, D=D)
        self.Prior.setField('nu', nu, dims=None)
        self.Prior.setField('B', B, dims=('D', 'D'))
Пример #3
0
    def createPrior(self,
                    Data,
                    D=None,
                    E=None,
                    nu=0,
                    B=None,
                    M=None,
                    V=None,
                    ECovMat=None,
                    sF=1.0,
                    VMat='eye',
                    sV=1.0,
                    MMat='zero',
                    sM=1.0,
                    **kwargs):
        ''' Initialize Prior ParamBag attribute.

        Post Condition
        ------
        Prior expected covariance matrix set to match provided value.
        '''
        if Data is None:
            if D is None:
                raise ValueError("Need to specify dimension D")
            if E is None:
                raise ValueError("Need to specify dimension E")
        if Data is not None:
            if D is None:
                D = Data.X.shape[1]
            else:
                assert D == Data.X.shape[1]
            if E is None:
                E = Data.Xprev.shape[1]
            else:
                assert E == Data.Xprev.shape[1]

        nu = np.maximum(nu, D + 2)
        if B is None:
            if ECovMat is None or isinstance(ECovMat, str):
                ECovMat = createECovMatFromUserInput(D, Data, ECovMat, sF)
            B = ECovMat * (nu - D - 1)
        B = as2D(B)

        if M is None:
            if MMat == 'zero':
                M = np.zeros((D, E))
            elif MMat == 'eye':
                assert D <= E
                M = sM * np.eye(D)
                M = np.hstack([M, np.zeros((D, E - D))])
                assert M.shape == (D, E)
            else:
                raise ValueError('Unrecognized MMat: %s' % (MMat))
        else:
            M = as2D(M)

        if V is None:
            if VMat == 'eye':
                V = sV * np.eye(E)
            elif VMat == 'same':
                assert D == E
                V = sV * ECovMat
            else:
                raise ValueError('Unrecognized VMat: %s' % (VMat))
        else:
            V = as2D(V)

        self.Prior = ParamBag(K=0, D=D, E=E)
        self.Prior.setField('nu', nu, dims=None)
        self.Prior.setField('B', B, dims=('D', 'D'))
        self.Prior.setField('V', V, dims=('E', 'E'))
        self.Prior.setField('M', M, dims=('D', 'E'))