Beispiel #1
0
int CStochastic::UniformSampling(int R)
{
	int Index=(double)UniformSampling()*R;
	if(Index>R-1)
		Index=R-1;
	return Index;
}
Beispiel #2
0
double CStochastic::GaussianSampling()
{
	int i;
	double result=0;
	for (i=0;i<12;i++)
		result+=UniformSampling();
	result-=6;
	return result;
}
Beispiel #3
0
int CStochastic::Sampling(double* Density,int NumSamples)
{
	double RandNumber=UniformSampling();
	int i;
	double sum=0;
	for(i=0;i<NumSamples;i++)
	{
		sum+=Density[i];
		if(sum>=RandNumber)
			return i;
	}
	return NumSamples-1;
}
double _findCentroid(SegBox *Sx, SegBox *s0, SegBox *s1, int nsamples, int seedlen){
	int iter1, iter2;
	double costMin = INF;
	/// keep best seeds
	int s0stB, s1stB, s0lenB, s1lenB; //best
	int s0stC, s1stC, s0lenC, s1lenC; //current
	/// make sample set
	UniformSet(Sx, seedlen, nsamples, &ws->U);
	/// start uniform sampling
	for(iter1=0;iter1<ws->U.nSb;iter1++)
	  for(iter2=iter1+1;iter2<ws->U.nSb;iter2++){
		UniformSampling(Sx, s0, s1, seedlen, iter1, iter2, &ws->U);
		if(s0->nSb==0 || s1->nSb==0) continue; // not sufficient
		// copy positions
		s0stC=s0->Sb[0].st; s0lenC=s0->Sb[0].len;
		s1stC=s1->Sb[0].st; s1lenC=s1->Sb[0].len;
		// estimate HMM
		_estimateHMM_k(s0, MINK);
		_estimateHMM_k(s1, MINK);
		// cut point search
		_cps(Sx, s0, s1, YES);
		if(s0->nSb==0 || s1->nSb==0) continue;
		if(costMin > s0->costT + s1->costT){
			// update best seeds
			costMin = s0->costT+s1->costT;
			s0stB=s0stC; s0lenB=s0lenC;
			s1stB=s1stC; s1lenB=s1lenC;
		}//if		
	}//iter1,2	
	if(costMin==INF){
		//fprintf(stderr, "couldn't find good seeds...\n");
		FixedSampling(Sx, s0, s1, seedlen);
		return INF;
	}
	ResetStEd(s0); ResetStEd(s1);
	AddStEd(s0, s0stB, s0lenB);
	AddStEd(s1, s1stB, s1lenB);
	return costMin;
}