コード例 #1
0
ファイル: loli.c プロジェクト: IRafita/Permutations
int main (void)
{
    int size, *vector, i;

    size = 5;
    vector = malloc (size * sizeof (int));

    vector[0] = 0;
    vector[1] = 1;
    vector[2] = 2;
    vector[3] = 3;
    vector[4] = 4;
    /*vector[5] = 2;
    vector[6] = 2;*/

    ShowVector (size, vector);


    for (i = 0; i < 10; i++)
    {
        NextPermutation (size, vector);
        ShowVector (size, vector);
    }

    printf ("Altre\n");
    while (!NextPermutationV2 (size, vector))
        ShowVector (size, vector);

    printf ("Un cop acabat\n");
    ShowVector (size, vector);

    free (vector);
    return 0;
}
コード例 #2
0
ファイル: HQuant.c プロジェクト: nlphacker/OpenSpeech
/* Determine global mean and covariance of data in sequence s */
void CalcMeanCov(Sequence seq[], int s)
{
   mean[s] = CreateVector(&dStack,swidth[s]);
   SequenceMean(seq[s],mean[s]);
   if (trace&T_MEAN) {
      printf("Stream %d",s);
      ShowVector(" global mean:\n",mean[s],20);
   }
   switch(ck){
   case INVDIAGC: 
   case DIAGC: 
      cov[s].var = CreateVector(&dStack,swidth[s]);
      SequenceCov(seq[s],ck,cov[s],mean[s]);
      if(trace&T_MEAN) ShowVector("Global variance",cov[s].var,20);
      break;
   case FULLC: 
      cov[s].inv = CreateTriMat(&dStack,swidth[s]);
      SequenceCov(seq[s],ck,cov[s],mean[s]);
      if(trace&T_MEAN) ShowTriMat("Global covariance",cov[s].inv,20,20);
      break;
   case NULLC: 
   default:          
      cov[s].var = NULL;
      if(trace&T_MEAN) printf("Using Euclidean distance\n");      
      break;
   }
}
コード例 #3
0
ファイル: TestBPVector.cpp プロジェクト: ViacheslavN/GIS
void TestInsert()
{
	embDB::TBPVector<int32> vec;
	embDB::TBPVector<int32> vec1;
	embDB::TBPVector<int32> vec3;
	size_t n = 20;
	for (size_t i = 0; i < n; ++i)
	{
		vec.push_back(i);
		vec1.push_back(i);
		vec3.push_back(i);
	}
	ShowVector(vec);
	std::cout << "movel 2 2  " << std::endl;
	vec.movel(2, 2);
	ShowVector(vec);

	std::cout << "mover 0 3 " << std::endl;
	vec1.mover(0, 3);
	ShowVector(vec1);

	std::cout << "mover 3  5 " << std::endl;
	vec3.mover(3, 5);
	ShowVector(vec3);
}
コード例 #4
0
int main()
{
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    vector *node_x, *node_y, *X4coe;
    vector *coe_a, *coe_b;
/*--initialize the variables--*/
    node_x = init_vector(node_x,1);
    node_y = init_vector(node_y,1);
    coe_a = init_vector(coe_a,0);
    coe_b = init_vector(coe_b,0);
    X4coe = change_nodex2X(node_x,X4coe);

/*--calculate the coefficients of polynomial--*/
    calcu_coe_a(coe_a,X4coe,node_y);
    printf("coe_a:\n");
    ShowVector(coe_a);

    calcu_coe_b(coe_b,X4coe,node_y);
    printf("coe_b:\n");
    ShowVector(coe_b);
/*--display the polynomial--*/
    show_polynomial(coe_a,coe_b);
    return 0;
}
コード例 #5
0
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("test.txt","r",stdin);
    //freopen("outin.txt","w",stdout);
    vector *d, *h, *m, *u;
    vector *Xnode, *Ynode;
    double **S;
    double ds_a = 0;
    double ds_b = 98;
    int i;
/*--initialize the vectors--*/
    d = init_vector(d,0);
    h = init_vector(h,0);
    m = init_vector(m,0);
    u = init_vector(m,0);
    Xnode = init_vector(Xnode,1);
    Ynode = init_vector(Ynode,1);
    S = malloc((Xnode->N-1) * sizeof(double*));
/*--calculate every element of every vector--*/
    calcu_h(h,Xnode);
    calcu_d(d,Xnode,Ynode);
    calcu_u(d,u,Xnode);
    printf("\nh\n");
    ShowVector(h);
    printf("\nd\n");
    ShowVector(d);
    printf("\nm\n");
    ShowVector(m);
    printf("\nu\n");
    printf("\nu\n");
    ShowVector(u);
    //ShowVector(X);
    //ShowVector(Y);
/*--using Gauss-Seidel iteration to solve the equation HM=V--*/
    calcu_m(m,d,u,h,Xnode,ds_a,ds_b);
    *(m->value+0) = (3 / *(h->value)) * (*(d->value) - ds_a) - *(m->value+1) / 2;
    *(m->value+Xnode->N - 1) = (3 / *(h->value+Xnode->N - 2)) * (ds_b - *(d->value+Xnode->N - 2)) - *(m->value+Xnode->N - 2) / 2;
    printf("\nm:\n");
    ShowVector(m);
/*--use what have calculated to calculate the coefficient of clamped cubic spline--*/
    calcu_S(S,Ynode,d,h,m);
/*--show the value of coefficients--*/
    for(i = 0; i < Ynode->N-1; i++){
        printf("%lf&\t%lf&\t%lf&\t%lf\n",*(*(S+i)+0),*(*(S+i)+1),*(*(S+i)+2),*(*(S+i)+3));
    }
    return 0;
}
コード例 #6
0
/* CalcCovs: calculate covariance of speech data */
void CalcCovs(void)
{
   int x,y,s,V;
   float meanx,meany,varxy,n;
   Matrix fullMat;
   
   if (totalCount<2)
      HError(2021,"CalcCovs: Only %d speech frames accumulated",totalCount);
   if (trace&T_TOP)
      printf("%ld speech frames accumulated\n", totalCount);
   n = (float)totalCount;     /* to prevent rounding to integer below */
   for (s=1; s<=hset.swidth[0]; s++){  /* For each stream   */
      V = hset.swidth[s];
      for (x=1; x<=V; x++)            /* For each coefficient ... */
         accs[s].meanSum[x] /= n;         /* ... calculate mean */
      for (x=1;x<=V;x++) {
         meanx = accs[s].meanSum[x];      /* ... and [co]variance */
         if (fullcNeeded[s]) {
            for (y=1; y<=x; y++) {
               meany = accs[s].meanSum[y];
               varxy = accs[s].squareSum.inv[x][y]/n - meanx*meany;
               accs[s].squareSum.inv[x][y] =
                  (x != y || varxy > minVar) ? varxy : minVar;    
            }
         }
         else {
            varxy = accs[s].squareSum.var[x]/n - meanx*meanx;
            accs[s].fixed.var[x] = (varxy > minVar) ? varxy :minVar;
         }
      }
      if (fullcNeeded[s]) { /* invert covariance matrix */
         fullMat=CreateMatrix(&gstack,V,V);
         ZeroMatrix(fullMat); 
         CovInvert(accs[s].squareSum.inv,fullMat);
         Mat2Tri(fullMat,accs[s].fixed.inv);
         FreeMatrix(&gstack,fullMat);
      }
      if (trace&T_COVS) {
         printf("Stream %d\n",s);
         if (meanUpdate)
            ShowVector(" Mean Vector ", accs[s].meanSum,12);
         if (fullcNeeded[s]) {
            ShowTriMat(" Covariance Matrix ",accs[s].squareSum.inv,12,12);
         } else
            ShowVector(" Variance Vector ", accs[s].fixed.var,12);
      }
   }
}
コード例 #7
0
ファイル: HVQ.c プロジェクト: deardaniel/PizzaTest
/* PrintTree: Print each node as an entry */
static void PrintTree(VQNode n, CovKind ck)
{
   if (n != NULL) {
      printf("vqidx=%d ids=[%d %d %d]\n",
             n->vqidx,n->nid,n->lid,n->rid);
      ShowVector("Mean",n->mean,10);
      switch(ck){
      case NULLC:
         break;
      case INVDIAGC:
         ShowVector("IVar",(Vector)n->cov.var,10);
         break;
      case FULLC:
         ShowTriMat("ICov",(TriMat)n->cov.inv,10,10);
         break;
      }
      printf("\n");
      PrintTree(n->left,ck);
      PrintTree(n->right,ck);
   }
}
コード例 #8
0
ファイル: loli.c プロジェクト: IRafita/Permuta-2
int main (void)
{
	int s, *v;

	s = 4;
	v = malloc (s * sizeof (int));
	if (!v)
	{
		printf ("Fatal error\n");
		return 1;
	}

	v[0] = 0;
	v[1] = 1;
	v[2] = 1;
	v[3] = 2;

	ShowVector (s, v);

	ParserPermutationDigitToVectorV2notCalc (s, v, 7, 12);

	ShowVector (s, v);
return 0;
}
コード例 #9
0
ファイル: HInit.c プロジェクト: songzhengxuan/kata
/* UpdateCounts: using frames in seg i and alignment in states/mixes */
void UpdateCounts(int segNum, int segLen, IntVec states,IntVec *mixes)
{
   int M=0,i,j,k,s,m,state,last;
   StreamElem *ste;
   MixPDF *mp = NULL;
   WtAcc *wa;
   MuAcc *ma;
   VaAcc *va;
   TrAcc *ta;
   Vector v;
   Observation obs;
   TMixRec *tmRec = NULL;
   float x,y;

   last = 1;  /* last before 1st emitting state must be 1 */
   ta = (TrAcc *)GetHook(hmmLink->transP); 
   for (i=1; i<=segLen; i++){
      state = states[i];
      if (trace&T_CNT)
         printf("  Seg %d -> state %d\n",i,state);
      if (uFlags&(UPMEANS|UPVARS|UPMIXES)){
         obs = GetSegObs(segStore, segNum, i);
         if (hset.hsKind == TIEDHS)
            PrecomputeTMix(&hset, &obs, 50.0, 0);         
         ste = hmmLink->svec[state].info->pdf+1;
         for (s=1; s<=nStreams; s++,ste++){
            if (hset.hsKind==DISCRETEHS){
               m = obs.vq[s]; v = NULL;
            } else {
               v = obs.fv[s]; m = mixes[s][i];
            }
            switch(hset.hsKind){
            case TIEDHS:
               tmRec = &(hset.tmRecs[s]);
               M = tmRec->nMix;
               break;
            case PLAINHS:
            case SHAREDHS:
            case DISCRETEHS:
               M = ste->nMix;
               break;
            }
            if (m<1 || m > M)
               HError(2170,"UpdateCounts: mix/vq idx out of range[%d]",m);
            if (trace&T_CNT)
               printf("   stream %d -> mix %d[%d]\n",s,m,M); 
            /* update mixture weight */
            if (M>1 && (uFlags&UPMIXES)) {
               wa = (WtAcc *)ste->hook;
               wa->occ += 1.0; wa->c[m] += 1.0;
               if (trace&T_CNT)
                  printf("   mix wt -> %.1f\n",wa->c[m]);
            }
            if (hset.hsKind==DISCRETEHS) continue;
            
            /* update state/mixture component */
            switch(hset.hsKind){
            case PLAINHS:
            case SHAREDHS:
               mp = ste->spdf.cpdf[m].mpdf;
               break;
            case TIEDHS:
               mp = tmRec->mixes[m];
               break;
            }
            ma = (MuAcc *)GetHook(mp->mean);
            va = (VaAcc *)GetHook(mp->cov.var);
            ma->occ += 1.0; va->occ += 1.0;
            for (j=1; j<=hset.swidth[s]; j++) {
               x = v[j] - mp->mean[j];
               ma->mu[j] += x;
               if (uFlags&UPVARS)
                  switch(mp->ckind){
                  case DIAGC: 
                     va->cov.var[j] += x*x;
                     break;
                  case FULLC:
                     for (k=1; k<=j; k++){
                        y = v[k]-mp->mean[k];
                        va->cov.inv[j][k] += x*y;
                     }
                     break;
                  default:
                     HError(2124,"UpdateCounts: bad cov kind %d\n",
                            mp->ckind);
                  }                 
            }
            if (trace&T_CNT) {
               ShowVector("   mean ->",ma->mu,6);
               if (uFlags&UPVARS) {
                  if (mp->ckind==DIAGC)
                     ShowVector("   var ->",va->cov.var,6);
                  else
                     ShowTriMat("   cov ->",va->cov.inv,6,6);
               }
               fflush(stdout);
            }
         }
      }
      /* update transition probs */
      if (uFlags&UPTRANS){
         ta->occ[last] += 1.0;
         ta->tran[last][state] += 1.0;
         last = state;
         if (i==segLen){  /* remember final state */
            ta->occ[state] += 1.0;
            ta->tran[state][nStates] += 1.0;
         }
         if (trace&T_CNT) {
            ShowMatrix("   tran ->",ta->tran,6,6);
            fflush(stdout);
         }
      }
   }
}
コード例 #10
0
int main()
{
    freopen("last_experience10.txt","r",stdin);
    //freopen("last_experience_out10.txt","w",stdout);
    //freopen("in.txt","r",stdin);
    /************变量声明区*********************************/
    //h 代表自变量之间的间距。 h_n=x_(n+1)-x(n)
    //d 表示相邻两点之之间的斜率。d_n=(y_(n+1)-y_n)/h_n
    //m 代表在某点处的二次导数值
    //u 代表解m的方程组时等号右边的数。u_n=6(d_(n+1)-d_n)
    vector *d, *h, *m, *u;
    //Xnode, Ynode代表已知点的横、纵坐标值。
    vector *Xnode, *Ynode;
    //S 为二重指针,存储多项式系数。
    double **S;
    //ds_a、ds_b 分别表示左、右端点出的一次导数值
    double ds_a = 0;//-7;
    double ds_b = 0.6274;//0.5;
    //i 控制循环次数
    int i;

    /***----------------initialize the vectors-----------------***/
    d = init_vector(d,0);
    h = init_vector(h,0);
    m = init_vector(m,0);
    u = init_vector(m,0);
    Xnode = init_vector(Xnode,1);
    Ynode = init_vector(Ynode,1);
    ShowVector(Xnode);
    ShowVector(Ynode);
    S = malloc((Xnode->N-1) * sizeof(double*));

    /**------calculate every element of every vector-----**/
    calcu_h(h,Xnode);
    calcu_d(d,Xnode,Ynode);
    calcu_u(d,u,Xnode);
    //输出计算得到的各个数值

    printf("\nh\n");
    ShowVector(h);
    printf("\nd\n");
    ShowVector(d);
    printf("\nm\n");
    ShowVector(m);
    printf("\nu\n");
    printf("\nu\n");
    ShowVector(u);


    /*--using Gauss-Seidel iteration to solve the equation HM=V--*/
    //计算m的数值(除了端点处的之外)
    calcu_m(m,d,u,h,Xnode,ds_a,ds_b);
    //计算第一个和最后一个m值
    *(m->value+0) = (3 / *(h->value)) * (*(d->value) - ds_a) - *(m->value+1) / 2;
    *(m->value+Xnode->N - 1) = (3 / *(h->value+Xnode->N - 2)) * (ds_b - *(d->value+Xnode->N - 2)) - *(m->value+Xnode->N - 2) / 2;
    //输出m数列

    printf("\nm:\n");
    ShowVector(m);


    /*--use what have calculated to calculate the coefficient of clamped cubic spline--*/
    calcu_S(S,Ynode,d,h,m);

    /*--show the value of coefficients--*/
    for(i = 0; i < Ynode->N-1; i++) {
        printf("%lf&\t%lf&\t%lf&\t%lf\n",*(*(S+i)+0),*(*(S+i)+1),*(*(S+i)+2),*(*(S+i)+3));
    }
    return 0;
}
コード例 #11
0
ファイル: Calculate.cpp プロジェクト: wanghj966/coreJava
void main()
{
	double e = 0;
	int n;	//初始节点个数
	
	double * pd_Result = new double [1];		//u(xi)的结果

	//复化梯形法,初始n = 32
	n = 32 ;
	do 
	{	
		n = n*2;
		if ( n > MaxN)
		{
			n = n/2;
			break;
		}		
		delete []pd_Result ;		
		pd_Result = FormulaTrapezia(n,e);
		
	} 
	while( e >= ee);

 	OutPutResult(pd_Result,n);
	cout<<"The number of FormulaTrapezia is "<<n<<"!"<<endl;	
	
	cout<<"The error of FormulaTrapezia is:";
	cout<<setiosflags(ios::scientific)<<setprecision(11)<<e<<endl;
	
	//复Simpson法,初始n = 32
	n = 32 ;
	do 
	{	
		n = n*2;
		if ( n > MaxN)
		{
		n = n/2;
		break;
		}		
		delete []pd_Result ;		
		pd_Result = FormulaSimpson(n,e);	
	} 
	while( e >= ee);


 	OutPutResult(pd_Result,n);
	cout<<"The number of FormulaSimpson is "<<n<<"!"<<endl;	
	
	cout<<"The error of FormulaSimpson is:";
	cout<<setiosflags(ios::scientific)<<setprecision(11)<<e<<endl;
	



	//Gauss积分法
	n = 7;
	
	pd_Result = FormulaGauss(n,e);

  	ShowVector(pd_Result,n);
	cout<<"The error of FormulaGauss is:";
	cout<<setiosflags(ios::scientific)<<setprecision(11)<<e<<endl;	
}