def setUp(self): SP.random.seed(1) self.n = 4 self.rank = 1 d = SP.rand(self.n) + 1 C0 = dlimix.CSumCF() C0.addCovariance(dlimix.CLowRankCF(self.n, self.rank)) C0.addCovariance(dlimix.CDiagonalCF(self.n)) self.C = dlimix.CFixedDiagonalCF(C0, d) self.name = 'CFixedDiagonalCF' self.n_params = self.C.getNumberParams() params = SP.randn(self.n_params) self.C.setParams(params) """
def setUp(self): SP.random.seed(1) self.n=10 n_dim1=8 n_dim2=12 self.C=dlimix.CSumCF() self.C.addCovariance(dlimix.CCovSqexpARD(n_dim1)); self.C.addCovariance(dlimix.CCovLinearARD(n_dim2)); self.n_dim=self.C.getNumberDimensions() X=SP.rand(self.n,self.n_dim) self.C.setX(X) self.name = 'CSumCF' self.n_params=self.C.getNumberParams() params=SP.exp(SP.randn(self.n_params)) self.C.setParams(params)
def setUp(self): SP.random.seed(1) self.n=10 n_dim2=12 K0 = SP.eye(self.n) self.C=dlimix.CSumCF() #sum of fixed CF and linearARD covar1 = dlimix.CFixedCF(K0) covar2 = dlimix.CCovLinearARD(n_dim2) self.C.addCovariance(covar1) self.C.addCovariance(covar2) self.n_dim=self.C.getNumberDimensions() self.X=SP.rand(self.n,self.n_dim) self.C.setX(self.X) self.name = 'CSumCF' self.n_params=self.C.getNumberParams() params=SP.exp(SP.randn(self.n_params)) self.C.setParams(params)
def setUp(self): SP.random.seed(1) #1. simulate self.settings = {'K': 5, 'N': 100, 'D': 80} self.simulation = self.simulate() N = self.settings['N'] K = self.settings['K'] D = self.settings['D'] #2. setup GP K0 = SP.dot(self.simulation['S'], self.simulation['S'].T) K0[:] = 0 covar1 = dlimix.CFixedCF(K0) covar2 = dlimix.CCovLinearISO(K) covar = dlimix.CSumCF() covar.addCovariance(covar1) covar.addCovariance(covar2) ll = dlimix.CLikNormalIso() #create hyperparm covar_params = SP.array([0.0, 1.0]) lik_params = SP.array([0.1]) hyperparams = dlimix.CGPHyperParams() hyperparams['covar'] = covar_params hyperparams['lik'] = lik_params hyperparams['X'] = self.simulation['X0'] #cretae GP self.gp = dlimix.CGPbase(covar, ll) #set data self.gp.setY(self.simulation['Y']) self.gp.setX(self.simulation['X0']) self.gp.setParams(hyperparams) pass
def _buildTraitCovar(self, trait_covar_type='lowrank_diag', rank=1, fixed_trait_covar=None, jitter=1e-4, d=None): """ Internal functions that builds the trait covariance matrix using the LIMIX framework Args: trait_covar_type: type of covaraince to use. Default 'freeform'. possible values are rank: rank of a possible lowrank component (default 1) fixed_trait_covar: PxP matrix for the (predefined) trait-to-trait covariance matrix if fixed type is used jitter: diagonal contribution added to trait-to-trait covariance matrices for regularization Returns: LIMIX::PCovarianceFunction for Trait covariance matrix vector labelling Cholesky parameters for different initializations """ cov = dlimix.CSumCF() if trait_covar_type == 'freeform': cov.addCovariance(dlimix.CFreeFormCF(self.P)) L = sp.eye(self.P) diag = sp.concatenate([L[i, :(i + 1)] for i in range(self.P)]) elif trait_covar_type == 'fixed': assert fixed_trait_covar is not None, 'VarianceDecomposition:: set fixed_trait_covar' assert fixed_trait_covar.shape[ 0] == self.N, 'VarianceDecomposition:: Incompatible shape for fixed_trait_covar' assert fixed_trait_covar.shape[ 1] == self.N, 'VarianceDecomposition:: Incompatible shape for fixed_trait_covar' cov.addCovariance(dlimix.CFixedCF(fixed_trait_covar)) diag = sp.zeros(1) elif trait_covar_type == 'diag': cov.addCovariance(dlimix.CDiagonalCF(self.P)) diag = sp.ones(self.P) elif trait_covar_type == 'lowrank': cov.addCovariance(dlimix.CLowRankCF(self.P, rank)) diag = sp.zeros(self.P * rank) elif trait_covar_type == 'lowrank_id': cov.addCovariance(dlimix.CLowRankCF(self.P, rank)) cov.addCovariance(dlimix.CFixedCF(sp.eye(self.P))) diag = sp.concatenate([sp.zeros(self.P * rank), sp.ones(1)]) elif trait_covar_type == 'lowrank_diag': cov.addCovariance(dlimix.CLowRankCF(self.P, rank)) cov.addCovariance(dlimix.CDiagonalCF(self.P)) diag = sp.concatenate([sp.zeros(self.P * rank), sp.ones(self.P)]) elif trait_covar_type == 'lowrank_diag1': assert d.shape[0] == self.P, 'dimension mismatch for d' cov1 = dlimix.CSumCF() cov1.addCovariance(dlimix.CLowRankCF(self.P, rank)) cov1.addCovariance(dlimix.CDiagonalCF(self.P)) cov.addCovariance(dlimix.CFixedDiagonalCF(cov1, d)) diag = sp.concatenate([sp.zeros(self.P * rank), sp.ones(self.P)]) elif trait_covar_type == 'freeform1': assert d.shape[0] == self.P, 'dimension mismatch for d' cov.addCovariance( dlimix.CFixedDiagonalCF(dlimix.CFreeFormCF(self.P), d)) L = sp.eye(self.P) diag = sp.concatenate([L[i, :(i + 1)] for i in range(self.P)]) elif trait_covar_type == 'block': cov.addCovariance(dlimix.CFixedCF(sp.ones((self.P, self.P)))) diag = sp.zeros(1) elif trait_covar_type == 'block_id': cov.addCovariance(dlimix.CFixedCF(sp.ones((self.P, self.P)))) cov.addCovariance(dlimix.CFixedCF(sp.eye(self.P))) diag = sp.concatenate([sp.zeros(1), sp.ones(1)]) elif trait_covar_type == 'block_diag': cov.addCovariance(dlimix.CFixedCF(sp.ones((self.P, self.P)))) cov.addCovariance(dlimix.CDiagonalCF(self.P)) diag = sp.concatenate([sp.zeros(1), sp.ones(self.P)]) else: assert True == False, 'VarianceDecomposition:: trait_covar_type not valid' if jitter > 0: _cov = dlimix.CFixedCF(sp.eye(self.P)) _cov.setParams(sp.array([sp.sqrt(jitter)])) _cov.setParamMask(sp.zeros(1)) cov.addCovariance(_cov) return cov, diag