Exemplo n.º 1
0
void TestRpy(double r, double p, double y) {
    tf::Matrix3x3 m;
    tf::Vector3 v1, v2, v3;
    tf::Quaternion q;
    printf("IN: %f %f %f\n", r, p, y);
    m.setRPY(r, p, y);

    v1 = m.getColumn(0);
    v2 = m.getColumn(1);
    v3 = m.getColumn(2);

    // the rotation matrix, by visual columns
    printf("%f %f %f\n", v1.getX(), v2.getX(), v3.getX());
    printf("%f %f %f\n", v1.getY(), v2.getY(), v3.getY());
    printf("%f %f %f\n", v1.getZ(), v2.getZ(), v3.getZ());

    // the rotation matrix, by matrix[row][column]
    printf("---\n");
    printf("%f %f %f\n", m[0][0], m[0][1], m[0][2]);
    printf("%f %f %f\n", m[1][0], m[1][1], m[1][2]);
    printf("%f %f %f\n", m[2][0], m[2][1], m[2][2]);
    tf::Matrix3x3 mout(v1.getX(), v2.getX(), v3.getX(),
            v1.getY(), v2.getY(), v3.getY(),
            v1.getZ(), v2.getZ(), v3.getZ());

    // the quaternion
    q.setRPY(r, p, y);
    printf("---\n");
    printf("%f %f %f %f\n", q.getX(), q.getY(), q.getZ(), q.getW());

    // check the output rpy
    mout.getRPY(r, p, y);
    printf("---\n");
    printf("OUT: %f %f %f\n", r, p, y);
}
Exemplo n.º 2
0
int
main (int argc, char *argv[])
{
  MINT *a, *b, *c, *d;
  short  h;

  mp_set_memory_functions (NULL, NULL, NULL);
  a = itom (123);
  b = xtom ("DEADBEEF");
  c = itom (0);
  d = itom (0);
  move (a, b);
  madd (a, b, c);
  msub (a, b, c);
  mult (a, b, c);
  mdiv (b, a, c, d);
  sdiv (b, 2, c, &h);
  msqrt (a, c, d);
  pow (b, a, a, c);
  rpow (a, 3, c);
  gcd (a, b, c);
  mcmp (a, b);
  if (argc > 1)
    {
      min (c);
      mout (a);
    }
  mtox (b);
  mfree(a);

  exit (0);
}
Exemplo n.º 3
0
Arquivo: Mmult.c Projeto: 8l/csolve
void mmult(MINT *a, MINT *b, MINT *c)
{
    register  carry,i,j,x;
    register short *aval, *bval;
    short *cval;
    int alen, blen, clen, sign;
#ifdef DEBUG
    if (1) {printf("\n"); mout(a); printf(" * ");mout(b);printf(" = ");}
#endif

    alen = a->len;
    blen = b->len;
    if (alen == 0 || blen == 0) {
	mset(0,c);
	return;
    }

    sign = 1;
    if (alen < 0) { alen = -alen; sign = -1; }
    if (blen < 0) { blen = -blen; sign = -sign; }

    if (alen < blen) {
	i = alen;  alen = blen;  blen = i;
	bval = a->val; aval = b->val;
    }
    else { aval = a->val; bval = b->val; }

    clen = alen+blen;
    valloc(cval, clen);

    if (blen == 1) {
	/*  We eliminate a lot of loop overhead on this common case. */
	x = 0;
	j = bval[0];
	bval = cval;
	for (i=0; i<alen; i++) {
	    x += j * aval[i];
	    bval[i] = x & 077777;
	    x >>= 15;
#if (! INTR)
	    (*PollPtr)();
#endif
	}
	bval[i] = x;
	if (x == 0) clen = i;    /* clen = alen+blen-1 == alen */
    }
Exemplo n.º 4
0
Arquivo: minvtst.c Projeto: 8l/csolve
main(void)
{
	MINT a,b,c;
	MINIT(&a);MINIT(&b);MINIT(&c);
	while ((fputs("a: ",stdout),min(&a) != EOF) &&
	       (fputs("b: ",stdout),min(&b) != EOF)) {
		minvert(&a,&b,&c);
		fputs("c = ",stdout); mout(&c); putchar('\n');
	}
	exit(0);
}
Exemplo n.º 5
0
void TestMatrixDominance() {
    std::stringstream ss;
    printf("---\n");
    std::cout << "Eigen matrix 0,1,2,3,4,5,6,7,8 becomes:\n";
    Eigen::Matrix3d m;
    m << 0, 1, 2, 3, 4, 5, 6, 7, 8;
    printf("%f %f %f\n", m(0, 0), m(0, 1), m(0, 2));
    printf("%f %f %f\n", m(1, 0), m(1, 1), m(1, 2));
    printf("%f %f %f\n", m(2, 0), m(2, 1), m(2, 2));

    printf("---\n");
    std::cout << "Eigen declared column major matrix 0,1,2,3,4,5,6,7,8 becomes:\n";
    MatrixCol3Xd mcol;
    mcol.resize(3, 3);
    mcol << 0, 1, 2, 3, 4, 5, 6, 7, 8;
    printf("%f %f %f\n", mcol(0, 0), mcol(0, 1), mcol(0, 2));
    printf("%f %f %f\n", mcol(1, 0), mcol(1, 1), mcol(1, 2));
    printf("%f %f %f\n", mcol(2, 0), mcol(2, 1), mcol(2, 2));
    ss << mcol;
    std::cout << ss.str();
    printf("\n---\n");
    std::cout << "Eigen declared row major matrix 0,1,2,3,4,5,6,7,8 becomes:\n";

    MatrixRow3Xd mrow;
    mrow.resize(3, 3);
    mrow << 0, 1, 2, 3, 4, 5, 6, 7, 8;
    printf("%f %f %f\n", mrow(0, 0), mrow(0, 1), mrow(0, 2));
    printf("%f %f %f\n", mrow(1, 0), mrow(1, 1), mrow(1, 2));
    printf("%f %f %f\n", mrow(2, 0), mrow(2, 1), mrow(2, 2));
    ss.str("");
    ss << mrow;
    std::cout << ss.str();

    printf("\n---\n");
    std::cout << "tf::matrix 0,1,2,3,4,5,6,7,8 becomes:\n";
    tf::Matrix3x3 mout(0, 1, 2,
            3, 4, 5,
            6, 7, 8);
    printf("%f %f %f\n", mout[0][0], mout[0][1], mout[0][2]);
    printf("%f %f %f\n", mout[1][0], mout[1][1], mout[1][2]);
    printf("%f %f %f\n", mout[2][0], mout[2][1], mout[2][2]);

}
Exemplo n.º 6
0
Arquivo: modtest.c Projeto: 8l/csolve
main(void)
{
	MINT a,b,q,r;

	MINIT(&a); MINIT(&b); MINIT(&q); MINIT(&r);
	while ((fputs("a: ",stdout), min(&a) != EOF) && (fputs("b: ",stdout), min(&b) != EOF)) {
		mdiv(&a,&b,&q,&r);
		mout(&a); putchar('\n');
		mout(&b); putchar('\n');
		mout(&q); putchar('\n');
		mout(&r); putchar('\n');
		mmod(&a,&b,&r);
		mout(&a); putchar('\n');
		mout(&b); putchar('\n');
		mout(&r); putchar('\n');
	}
	exit(0);
}
int main(int argc, char* argv[])
{
	TExeTm ExeTm;
	THash< TStr , CascadeElementV > quotesFiltered;
	double* vol_me;
	uint period = 9 * 3600;   // 9 days because of NIFTY paper

	printf("((((( Starting The Filtering Cascades CODE )))))\n");
	try
	{
		Env = TEnv(argc, argv, TNotify::StdNotify);
		Env.PrepArgs(TStr::Fmt("\nFiltering Memes Cascades. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));

		// ---== Loading Data ==---
		TZipIn ZquotesIn("QuotesPreprocessedData_NIFTY.rar");		///("/agbs/cluster/oaskaris/Data_Preparing_Codes/RESULTS/QuotesPreprocessedData_NIFTY.rar");
		THash< TStr , CascadeElementV > quotes;
		quotes.Load(ZquotesIn);
		printf("Loaded QuotesPreprocessedData_NIFTY has instances: %d\n\n\n",quotes.Len());

		// NIFTY Method for Filtering by Peaks
		uint begin = TSecTm(2008,7,31,0,0,0).GetAbsSecs();
		uint end = TSecTm(2009,10,1,0,0,0).GetAbsSecs();
		TSecTmV memesTimes;
		int bins = (end - begin) / period;
		for(int c=0;c<quotes.Len();c++)
		{
			memesTimes.Clr();
			for(int i=0;i<quotes[c].Len();i++)
			{
				memesTimes.Add(quotes[c][i].time);
			}
			vol_me = Tools::calculateHistOfCascade(memesTimes,begin,period,false);

			// calculating mean and standard deviation
			double mean = 0;
			for(int i=0;i<bins;i++)
			{
				mean += vol_me[i];
			}
			mean /= bins;

			double std = 0;
			for(int i=0;i<bins;i++)
			{
				std += pow(vol_me[i]-mean , 2);
			}
			std = sqrt(std / (bins-1));

			// peak definition by NIFTY: a point is a peak if its volume in 9 days binning is 1 standard deviation higher than the average frequency
			double maxVolume = mean + std;
			int peakCnt = 0;
			for(int i=0;i<bins;i++)
			{
				if(vol_me[i] > maxVolume)
				{
					peakCnt++;
				}
			}
			// if there is more than 5 peaks ignore this quote, since it is not a meme
			if(peakCnt > 5)
			{
				delete[] vol_me;
				continue;
			}

			quotesFiltered.AddDat(quotes.GetKey(c),quotes[c]);
			delete[] vol_me;
		}

		TZipOut mout("QuotesPreprocessedData_NIFTY_FINALFILTERED.rar");
		quotesFiltered.Save(mout);
		printf("Saved QuotesPreprocessedData_NIFTY_FINALFILTERED has instances: %d\n\n\n",quotesFiltered.Len());

		printf("\nThe Meme Filter for plotting had been done successfully.\n");
	}
	catch(exception& ex)
	{
		printf("\nError1 happened, it was: %s\n\n",ex.what());
	}
	catch(TPt<TExcept>& ex)
	{
		printf("\nError2 happened: %s\n\n",ex[0].GetStr().CStr());
	}

	printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
	return 0;
}