示例#1
0
MDArray<double> Shrinkage::combine(MDArray<double> target,MDArray<double> MLE,double lambda)
{
	assert(target.get_shape() == MLE.get_shape());

	//        assert(lambda>=0 && lambda<=1);
	lambda = std::max(lambda, 0.0);
	lambda = std::min(lambda, 1.0);

	return add_matrices(mult_num_to_matrix(target,lambda),mult_num_to_matrix(MLE,1-lambda));
}
示例#2
0
void ParentMap::set(uint h, MDArray<double> & v) {
	vector<uint> & v1 = indices[h];
	uint i = v1.back();
	assert(v.get_shape().size() == 1);
	uint dim = v.get_shape().front();
	uint k = 0;
	for (uint j = i; j < i + dim; j++, k++) {
		*(seq[j]) = v[k];
	}
}
示例#3
0
Shrinkage::Shrinkage(MDArray<double> data, MDArray<double> MLE)
{	
        N=data.get_shape()[0];
        P=data.get_shape()[1];
	assert(MLE.get_shape()[0]==P && MLE.get_shape()[1]==P);
        this->data=data;
        wk=wk_StDM=vec(N,P,P);
        S_MLE=vec(P,P);
        StDM=vec(N,P);
	set_S_MLE(MLE);
}
示例#4
0
Shrinkage::Shrinkage(MDArray<double> data)
{
        N=data.get_shape()[0];
        P=data.get_shape()[1];
        this->data=data;
        wk=wk_StDM=vec(N,P,P);
        S_MLE=vec(P,P);
        StDM=vec(N,P);
	generate_MLE();
}
示例#5
0
void MultinomialDensities::set_parameters(MDArray<double> & cpd)
{
    // Check cpd is right shape
    vector<uint> shape = cpd.get_shape();
    assert(shape[1] == dim);

    this->cpd = cpd;
    this->cpd.normalize();
    // make new MultinomialDensity objects
    _create_densities();
}
示例#6
0
void Shrinkage::generate_wk(MDArray<double> mat,int SDM_type)
{
        int n=mat.get_shape()[0];
        int p=mat.get_shape()[1];
        vector<uint> index;
        double sum,term1,term2;
        MDArray<double> sub_means(get_sub_means(mat));
        for(int i=0;i<p;i++)
                for(int j=0;j<p;j++){
                        sum=0;
                        for(int k=0;k<n;k++){
                                term1=mat.get(k,i)-sub_means[i];
                                term2=mat.get(k,j)-sub_means[j];
                                index=vec((uint)k, (uint)i, (uint)j);
                                if(SDM_type)
                                        wk_StDM[index]=term1*term2;
                                else
                                        wk[index]=term1*term2;
                        }
        }
}