示例#1
0
文件: 9x1.c 项目: TresLos/Universitat
int
main ()
{
	int n;
	double *x, *f, *g;
	printf ("\nEntreu les coordenades\n");
	x = HGVM (&n);
	printf ("\nEntreu els valors de la funcio\n");
	f = GVM (n);
	printf ("\nEntreu les derivades\n");
	g = GVM (n);

/* Obte el polinomi desitjat */
	difdivherm (n, &x, &f, &g);

/* Dibuixa el polinomi */
	writeFile (2 * n, 1e-2, -2, 2, x, f);

	FV (x, n);
	FV (f, n);
	return 0;
}
示例#2
0
文件: 2ex.c 项目: TresLos/Universitat
int main (void)
{
	int n;
	double tol = 1e-14;
	double **A, *b;

	for (n = 1; n <= 15; n++)
	{
		A = GMH (n);
		b = GV1 (n, A);

		gauss (n, A, b, tol);
		trisup (n, A, b, tol);

		printf ("%3d:\t%.30le\n", n, Norm (n, b)-1);

		FM (A, n, n);
		FV (b, n);
	}

	return 0;
}
示例#3
0
void CLink::Load(CProfINIFile & SavePF)
  {
  if (1)
    return;
  
  CString Line, V;
  Line=SavePF.RdStr("Links", m_sTag, "");
  if (Line.GetLength()>0)
    {
    int iStart=0;
    int lLink = SafeAtoL(Line.Tokenize(",", iStart));
    //int lDbg  = SafeAtoL(Line.Tokenize(",", iStart));
    int lHold = SafeAtoL(Line.Tokenize(",", iStart));
    V=Line.Tokenize("'", iStart);
    
    //m_bSltDbgOn=lDbg!=0;
    m_State.m_bHold=lHold!=0;

    CFullValue FV(OPC_QUALITY_GOOD);
    StringToVariant(Type(), V, FV, false);
    gs_SlotMngr.AppendChange(eCSD_File, -1, eCSD_Link, m_lLink, -1/*gs_SlotMngr.GetTransactionID()*/, FV, NULL, true);
    }
  };
示例#4
0
int main()
{

    Bayes bn(4, 2); //constract a bayes network with 4 featuers and 2 classes


    std::vector<double> FV(4);

    //Class 0
    FV[0] = 752; FV[1] = 265; FV[2] = 700; FV[3] = 271; bn.learn(FV, 0u);
    FV[0] = 895; FV[1] = 355; FV[2] = 812; FV[3] = 288; bn.learn(FV, 0u);
    FV[0] = 893; FV[1] = 352; FV[2] = 790; FV[3] = 298; bn.learn(FV, 0u);
    FV[0] = 814; FV[1] = 326; FV[2] = 790; FV[3] = 296; bn.learn(FV, 0u);
    FV[0] = 532; FV[1] = 405; FV[2] = 750; FV[3] = 401; bn.learn(FV, 0u);
    FV[0] = 532; FV[1] = 405; FV[2] = 750; FV[3] = 401; bn.learn(FV, 0u);
    FV[0] = 478; FV[1] = 385; FV[2] = 750; FV[3] = 394; bn.learn(FV, 0u);
    FV[0] = 532; FV[1] = 405; FV[2] = 750; FV[3] = 401; bn.learn(FV, 0u);
    FV[0] = 565; FV[1] = 47 ; FV[2] = 710; FV[3] = 142; bn.learn(FV, 0u);
    FV[0] = 689; FV[1] = 127; FV[2] = 955; FV[3] = 162; bn.learn(FV, 0u);

    //Class 1
    FV[0] = 576; FV[1] = 726; FV[2] = 287; FV[3] =719; bn.learn(FV, 1);
    FV[0] = 718; FV[1] = 783; FV[2] = 300; FV[3] =536; bn.learn(FV, 1);
    FV[0] = 859; FV[1] = 724; FV[2] = 270; FV[3] =480; bn.learn(FV, 1);
    FV[0] = 839; FV[1] = 512; FV[2] = 246; FV[3] =657; bn.learn(FV, 1);
    FV[0] = 746; FV[1] = 343; FV[2] = 250; FV[3] =710; bn.learn(FV, 1);
    FV[0] = 660; FV[1] = 527; FV[2] = 272; FV[3] =763; bn.learn(FV, 1);
    FV[0] = 704; FV[1] = 621; FV[2] = 263; FV[3] =713; bn.learn(FV, 1);
    FV[0] = 684; FV[1] = 836; FV[2] = 287; FV[3] =213; bn.learn(FV, 1);
    FV[0] = 678; FV[1] = 800; FV[2] = 377; FV[3] =220; bn.learn(FV, 1);
    FV[0] = 624; FV[1] = 697; FV[2] = 494; FV[3] =238; bn.learn(FV, 1);


    LINFO("Class 0");
    for(uint i=0; i<bn.getNumFeatures(); i++)
      LINFO("Feature %i: mean %f, stddevSq %f", i, bn.getMean(0, i), bn.getStdevSq(0, i));

    LINFO("Class 1");
    for(uint i=0; i<bn.getNumFeatures(); i++)
      LINFO("Feature %i: mean %f, stddevSq %f", i, bn.getMean(1, i), bn.getStdevSq(1, i));

    LINFO("Class 0 frq %i prob %f", bn.getClassFreq(0), bn.getClassProb(0));
    LINFO("Class 1 frq %i prob %f", bn.getClassFreq(1), bn.getClassProb(1));


    //New FV to classify
    FV[0] = 750; FV[1] = 269; FV[2] = 720; FV[3] = 291;
    int cls = bn.classify(FV); //classify a given FV
    LINFO("FV1 belongs to class %i", cls);

    FV[0] = 458; FV[1] = 381; FV[2] = 350; FV[3] = 392;
    cls = bn.classify(FV); //classify a given FV
    LINFO("FV2 belongs to class %i", cls);


    bn.save("Bayes.net");

    bn.load("Bayes.net");

    LINFO("Class 0");
    for(uint i=0; i<bn.getNumFeatures(); i++)
      LINFO("Feature %i: mean %f, stddevSq %f", i, bn.getMean(0, i), bn.getStdevSq(0, i));

    LINFO("Class 1");
    for(uint i=0; i<bn.getNumFeatures(); i++)
      LINFO("Feature %i: mean %f, stddevSq %f", i, bn.getMean(1, i), bn.getStdevSq(1, i));

    LINFO("Class 0 frq %i prob %f", bn.getClassFreq(0), bn.getClassProb(0));
    LINFO("Class 1 frq %i prob %f", bn.getClassFreq(1), bn.getClassProb(1));


    //New FV to classify
    FV[0] = 750; FV[1] = 269; FV[2] = 720; FV[3] = 291;
    cls = bn.classify(FV); //classify a given FV
    LINFO("FV1 belongs to class %i", cls);

    FV[0] = 458; FV[1] = 381; FV[2] = 350; FV[3] = 392;
    cls = bn.classify(FV); //classify a given FV
    LINFO("FV2 belongs to class %i", cls);
}
示例#5
0
文件: Diff.cpp 项目: 6e6f36/DarunGrim
static int _find_middle_snake(const void *a,int aoff,int n,
		const void *b,int boff,int m,
		MatchContext *ctx,
		MiddleSnake *ms)
{
	int delta,odd,mid,d;

	delta=n - m;
	odd=delta & 1;
	mid=(n+m) / 2;
	mid += odd;

	_setv(ctx,1,0,0);
	_setv(ctx,delta - 1,1,n);

	for(d=0; d <= mid; d++)
	{
		int k,x,y;

		if((2 * d - 1) >= ctx->dmax) {
			return ctx->dmax;
		}

		for(k=d; k >= -d; k -= 2) {
			if(k==-d ||(k != d && FV(k - 1)<FV(k+1))) {
				x=FV(k+1);
			} else {
				x=FV(k - 1)+1;
			}
			y=x - k;

			ms->x=x;
			ms->y=y;
			const unsigned char *a0=(const unsigned char *)a+aoff;
			const unsigned char *b0=(const unsigned char *)b+boff;
			while(x<n && y<m && a0[x]==b0[y]) {
				x++; y++;
			}
			_setv(ctx,k,0,x);

			if(odd && k >=(delta -(d - 1)) && k <=(delta +(d - 1))) {
				if(x >= RV(k)) {
					ms->u=x;
					ms->v=y;
					return 2 * d - 1;
				}
			}
		}
		for(k=d; k >= -d; k -= 2) {
			int kr=(n - m)+k;

			if(k==d ||(k != -d && RV(kr - 1)<RV(kr+1))) {
				x=RV(kr - 1);
			} else {
				x=RV(kr+1) - 1;
			}
			y=x - kr;

			ms->u=x;
			ms->v=y;
			const unsigned char *a0=(const unsigned char *)a+aoff;
			const unsigned char *b0=(const unsigned char *)b+boff;
			while(x > 0 && y > 0 && a0[x - 1]==b0[y - 1]) {
				x--; y--;
			}
			_setv(ctx,kr,1,x);

			if(!odd && kr >= -d && kr <= d) {
				if(x <= FV(kr)) {
					ms->x=x;
					ms->y=y;
					return 2 * d;
				}
			}
		}
	}

	errno=EFAULT;

	return -1;
}