Beispiel #1
0
void mixMarkov(vector< vector<int> >& X, int trainingNum, int numOfState, 
        int K, vector<double>& pi, vector< vector<double> >& thetaInit,
        vector< vector< vector<double> > >& thetaTrans) {
    vector < vector< map<int, int> > > sigma;
    vector<double> ll_variables(3);
    vector< vector<double> > condProb(trainingNum);
    initVariable(pi, thetaInit, thetaTrans);
    setSigma(X, sigma, trainingNum);

    estep(X, pi, thetaInit, thetaTrans, condProb);
    
    ll_variables = computeLL(X, thetaInit, thetaTrans);
    
    for (iter = 1; iter<= MAX_ITER; ++iter) {
        mstep(pi, thetaInit, thetaTrans, condProb);
        estep(X, pi, thetaInit, thetaTrans, condProb);
        vector<double> new_ll_variables(3);
        new_ll_variables = computeLL(X, thetaInit, thetaTrans);
        
        //check for convergence
        if (new_ll_variables[0] + new_ll_variables[1] + new_ll_variables[2] - (ll_variables[0] + ll_variables[1] + ll_variables[2]) >TOL ) {
            ll_variables = new_ll_variables; 
        } else {
            break;
        }
    }
}
Beispiel #2
0
/*
 * An implementation of Boyer-Moore algorithm with bad character rule and good suffix rule.
 */
int fastfastBMmatcher(int n, int m){
	int  R[28];
	/*
	 * Zbar[i] is the lenght of the longest suffix of P[1,2,...,i]
	 * matched with a suffix of P[1,2,..,m]
	 */

	int Zbar[MAXM];
	/*
	 * LL[i] is the maximum index smaller than m such that P[i,i+1,..,m]
	 * matched with a suffix of P[1,2,..,LL[i]] such that the char to the left of
	 * of the matched substring of  P[1,2,..,LL[i]] is not equal from P[i-1]
	*/
	int LL[MAXM];
	/*
	 * SL[i] is the length of the longest suffix of P[i,i+1,..,m] that is matched with
	 * a prefix of P[1,2,...,m]
	 */
	int SL[MAXM];
	badCharBackup(m,R);
	int i = 1, j = 0, p = 0, skip = 0;
	memset(Zbar, 0, sizeof(Zbar)); // set everything to 0
	memset(LL,0,sizeof(LL));// set everything to 0
	memset(SL,0, sizeof(SL));// set everything to 0
	computeLL(m, LL, Zbar);
	computeSL(m, SL, Zbar);
	while(i <= n-m+1){
		skip = 0;
		j = m;
		while(j >= 1 && skip == 0){
			if(T[i+j-1] != P[j]){
				p = T[i+j-1]-96;
				skip = max(1, j - R[p]); // skip by the bad character rule;
				if(j!=m){
					if(LL[j+1] !=0){
						skip = max(skip, m - LL[j+1]);// (1) and (2) of the good suffix rule
					} else {
						skip = max(skip, m - SL[j+1]);// (3) and (4) of the good suffix rule
						/*
						 * For more information about the rules, see .... blogpost
						 */
					}
				}
			}
			j--;
		}
		if(skip == 0) return i;
		i = i + skip;
	}
	return -1;
}
Beispiel #3
0
JNIEXPORT jlong JNICALL Java_edu_biu_scapi_primitives_dlog_miracl_MiraclDlogECFp_simultaneousMultiplyFp
  (JNIEnv *env, jobject obj, jlong m, jlongArray elements, jobjectArray exponents){

	  int size = env->GetArrayLength(elements); //number of points
	  jlong* longElements  = env->GetLongArrayElements(elements, 0); //convert JllongArray to long array
	  epoint ** points = (epoint**) calloc(size, sizeof(epoint*)); //create a big array to hold the points
	  big* bigExponents =  (big*) calloc(size, sizeof(big)); //create a big array to hold the exponents
	  int i;
	  epoint *p;
	  jbyteArray exponent;
	  /* convert the accepted parameters to MIRACL parameters*/
	  miracl* mip = (miracl*)m;

	  for(i=0; i<size; i++){
		  points[i] = (epoint*) longElements[i];
		  exponent = (jbyteArray) env->GetObjectArrayElement(exponents, i);
		  bigExponents[i] = byteArrayToMiraclBig(env, mip, exponent);
	  }

	 // p = epoint_init(mip);
	 
	  //ecurve_multn(mip, size, bigExponents, points, p);

	   p = computeLL(mip, points, bigExponents, size, 1);

	  //release the memory
	  for(i=0; i<size; i++){
		  mirkill(bigExponents[i]);
	  }

	  free(points);
	  free(bigExponents);

	  //release jbyte
	  env ->ReleaseLongArrayElements(elements, longElements, 0);

	  return (jlong)p; //return the result
}