Exemple #1
0
CModel* CModel::Shotgun(gsl_rng * stream, FILE* logfile)
{
	int nmodels = 0;
	int ntotalmodels = 0;
	CModel* p = this;
	
	if(NULL==p->Next)
	{
		return(NULL);
	}
	while(NULL!=p->Next)
	{
		nmodels += p->Next->notStudied;
		ntotalmodels++;
		p = p->Next;
	}
	printf("Models in list [%d] not studied [%d]\n",ntotalmodels,nmodels);
	fprintf(logfile,"\t%d\t%d\n",ntotalmodels,nmodels);
	
	if(0==nmodels)
	{
		return(NULL);
	}
	double* w = new double[nmodels];
	p = this;
	nmodels = 0;
	while(NULL!=p->Next)
	{
		if(p->Next->notStudied)
		{
			w[nmodels] = p->Next->laplace;
			nmodels++;
		}
		p = p->Next;
	}
	
	double* cumw = NormalizeWeightsShotgun(w,nmodels);
	int chosenmodel = WeightedSamplingShotgun(nmodels,cumw,stream);
	delete[] cumw; cumw = NULL;
	delete[] w; w = NULL;
	
	p = this;
	nmodels = 0;
	while(NULL!=p->Next)
	{
		if(p->Next->notStudied)
		{
			if(nmodels==chosenmodel)
			{
				p->Next->notStudied = 0;
				return(p->Next);
			}
			nmodels++;
		}
		p = p->Next;
	}
	return(NULL);
}
Exemple #2
0
CRegression* CRegression::Shotgun(gsl_rng * stream,int& nPmodels,int& nPtotalmodels)
{
	int nmodels = 0;
	int ntotalmodels = 0;
	CRegression* p = this;
	
	if(NULL==p->Next)
	{
		return(NULL);
	}
	while(NULL!=p->Next)
	{
		if(p->Next->notStudied)
		{
			nmodels++;
		}
		ntotalmodels++;
		p = p->Next;
	}
	
	nPmodels = nmodels;
	nPtotalmodels = ntotalmodels;

	if(0==nmodels)
	{
		return(NULL);
	}
	double* w = new double[nmodels];
	p = this;
	nmodels = 0;
	while(NULL!=p->Next)
	{
		if(p->Next->notStudied)
		{
			w[nmodels] = p->Next->Weight;
			nmodels++;
		}
		p = p->Next;
	}
	
	double* cumw = NormalizeWeightsShotgun(w,nmodels);
	int chosenmodel = WeightedSamplingShotgun(nmodels,cumw,stream);
	delete[] cumw; cumw = NULL;
	delete[] w; w = NULL;
	
	p = this;
	nmodels = 0;
	while(NULL!=p->Next)
	{
		if(p->Next->notStudied)
		{
			if(nmodels==chosenmodel)
			{
				p->Next->notStudied = 0;
				return(p->Next);
			}
			nmodels++;
		}
		p = p->Next;
	}
	return(NULL);
}