Exemple #1
0
float snormal (float mean, float sdev)
/* ------------------------------------------------------------------------- *
 * Provide a single random number, Normal(mean, sdev). 
 * ------------------------------------------------------------------------- */
{
  return (float) GD((double) mean, (double) sdev);
}
Exemple #2
0
double dnormal (double mean, double sdev)
/* ------------------------------------------------------------------------- *
 * Provide a single random number, Normal(mean, sdev). 
 * ------------------------------------------------------------------------- */
{
  return GD(mean, sdev);
}
Exemple #3
0
void testRandom(unsigned int const n)
{
	srand(time(0));
	std::vector<uint64_t> V(n);
	for ( uint64_t i = 0; i <n; ++i )
		V[i] = rand();

	::libmaus::timing::RealTimeClock rtc; 
	
	rtc.start();
	CountPut CP;
	::libmaus::gamma::GammaEncoder< CountPut > GCP(CP);	
	for ( uint64_t i = 0; i < n; ++i )
		GCP.encode(V[i]);
	GCP.flush();
	double const cencsecs = rtc.getElapsedSeconds();
	std::cerr << "[V] count encoded " << n << " numbers in time " << cencsecs 
		<< " rate " << (n / cencsecs)/(1000*1000) << " m/s"
		<< " output words " << CP.cnt
		<< std::endl;
	
	VectorPut<uint64_t> VP;
	rtc.start();
	::libmaus::gamma::GammaEncoder< VectorPut<uint64_t> > GE(VP);	
	for ( uint64_t i = 0; i < n; ++i )
		GE.encode(V[i]);
	GE.flush();
	double const encsecs = rtc.getElapsedSeconds();
	std::cerr << "[V] encoded " << n << " numbers to dyn growing vector in time " << encsecs 
		<< " rate " << (n / encsecs)/(1000*1000) << " m/s"
		<< std::endl;

	rtc.start();
	VectorGet<uint64_t> VG(VP.begin());
	::libmaus::gamma::GammaDecoder < VectorGet<uint64_t> > GD(VG);
	bool ok = true;
	for ( uint64_t i = 0; ok && i < n; ++i )
	{
		uint64_t const v = GD.decode();
		ok = ok && (v==V[i]);
		if ( ! ok )
		{
			std::cerr << "expected " << V[i] << " got " << v << std::endl;
		}
	}
	double const decsecs = rtc.getElapsedSeconds();
	std::cerr << "[V] decoded " << n << " numbers in time " << decsecs
		<< " rate " << (n / decsecs)/(1000*1000) << " m/s"
		<< std::endl;
	
	if ( ok )
	{
		std::cout << "Test of gamma coding with " << n << " random numbers ok." << std::endl;
	}
	else
	{
		std::cout << "Test of gamma coding with " << n << " random numbers failed." << std::endl;
	}
}
Exemple #4
0
void svnormal (integer n, float mean, float sdev, float* x, integer incx)
/* ------------------------------------------------------------------------- *
 * Randomize vector x, Normal(mean, sdev).
 * ------------------------------------------------------------------------- */
{
  register integer i;
  
  x += (incx<0) ? (-n+1)*incx : 0;

  for (i=0; i<n; i++) x[i*incx] = (float) GD ((double) mean, (double) sdev);
}
Exemple #5
0
void dvnormal (integer n, double mean, double sdev, double* x, integer incx)
/* ------------------------------------------------------------------------- *
 * Randomize vector x, Normal(mean, sdev).
 * ------------------------------------------------------------------------- */
{
  register integer i;
  
  x += (incx<0) ? (-n+1)*incx : 0;

  for (i=0; i<n; i++) x[i*incx] = GD (mean, sdev);
}
	void PostureIKSolver::solve()
	{
		lineSearchStepSize = initStepSize;
		if(initSolve){
			initSolve = false;
			GoalConstIterator gi = getGoalConstIterator();
			while(!gi.end()){
				gi.next();
				countGoal++;
			}
			zh::Skeleton::BoneIterator bi = mSkel -> getBoneIterator();
			while(!bi.end()){
				bi.next();
				countBone++;
			}
			gredient.setDimension(countBone * 3 + 3);
		}
		snapshot(0);
		/*zh::Skeleton::BoneIterator bi = mSkel->getBoneIterator();
		if(!bi.end()){
			Bone* bone = bi.next();
			//bone ->setPosition(zh::Vector3(100,0,0));
			//bone->rotate(Quat(3.14/4,3.14/4,3.14/4,3.14/4).normalize());
			Quat tmp(0,0,0,3.14/4);
			tmp = tmp.exp();
			tmp = tmp.normalize();
			bone ->setOrientation(bone->getOrientation()*tmp);
		}*/
		//restoreSnapshot(1);
		/*while(!bi.end()){
			Bone* bone = bi.next();
			Quat tmp(0,0,0,3.14/4);
			bone ->setOrientation(bone->getOrientation()*tmp.exp());
		}*/
		//restoreSnapshot(1);
		GD();
		zh::Skeleton::BoneIterator bi = mSkel -> getBoneIterator();
		int counter = 0;
		if(!bi.end()){
			Bone* bone = bi.next();
			if(!this ->findBone(bone->getId())){
				bone ->setPosition(shot[0].rootPosition);
				bone ->setOrientation(shot[0].rotation[counter]);
			}
			counter++;
		}
		while(!bi.end()){
			Bone* bone = bi.next();
			if(!this ->findBone(bone->getId())){
				bone ->setOrientation(shot[0].rotation[counter]);
			}
			counter++;
		}
	}
void MpView::NewDataSet (int dataset_index, int graph_index)
{
    if (dataset_index < 0) return;

    for (MpViewGraphMap::iterator i = Graphs.begin(); i != Graphs.end(); ++i) {
        int grf = i->first;
        if (dataset_index == i->second.iset
                && (graph_index < 0 || graph_index == grf)) {
            MpViewGraphData *G = &GD(grf);
            if (DataSetExists(dataset_index)) {
                switch (G->DS().GetDataType()) {
                case MpViewDataSet::a_EmptySet:
                    // nothing to do
                    break;
                case MpViewDataSet::a_Matrix:
                    NewMatrix(G);
                    break;
                case MpViewDataSet::a_Matrix3d:
                    NewVolume(G);
                    break;
                case MpViewDataSet::a_ComplexMatrix:
                    NewComplexMatrix(G,G->DS().C);
                    break;
                case MpViewDataSet::a_Scene:
                    NewScene(G);
                    break;
                case MpViewDataSet::a_XYZSet:
                    NewXYZSet(G);
                    break;
                case MpViewDataSet::a_Image:
                    cerr<<"MpView::NewDataSet: IMAGE - can't happen"<<endl;
                    break;
                default:
                    cerr<<"MpView::NewDataSet: found illegal data set type" << endl;
                    break;
                }
            } else {
                // data set doesn't exist (e.g. was deleted) -> unlink
                G->iset = -1;
            }
        }
    }
}
Exemple #8
0
void testLow()
{
	unsigned int const n = 127;
	VectorPut<uint64_t> VP;
	::libmaus::gamma::GammaEncoder< VectorPut<uint64_t> > GE(VP);	
	for ( uint64_t i = 0; i < n; ++i )
		GE.encode(i);
	GE.flush();
	
	VectorGet<uint64_t> VG(VP.begin());
	::libmaus::gamma::GammaDecoder < VectorGet<uint64_t> > GD(VG);
	bool ok = true;
	for ( uint64_t i = 0; ok && i < n; ++i )
		ok = ok && ( GD.decode() == i );

	if ( ok )
	{
		std::cout << "Test of gamma coding with numbers up to 126 ok." << std::endl;
	}
	else
	{
		std::cout << "Test of gamma coding with numbers up to 126 failed." << std::endl;
	}
}
Exemple #9
0
			bool get(uint64_t i) const
			{
				assert ( i < n );

				uint64_t const block = i / blocksize;
				i -= block*blocksize;

				uint64_t const blockptr = getBlockPointer(block);
				uint64_t const wordoff = (blockptr / (8*sizeof(uint64_t)));
				uint64_t const bitoff = blockptr % (8*sizeof(uint64_t));

				::libmaus2::util::GetObject<uint64_t const *> GO(data.begin() + wordoff);
				::libmaus2::gamma::GammaDecoder < ::libmaus2::util::GetObject<uint64_t const *> > GD(GO);
				if ( bitoff )
					GD.decodeWord(bitoff);

				GD.decodeWord(rankaccbits); // 1 bit accumulator
				bool sym = GD.decodeWord(1);

				uint64_t rl = GD.decode()+1;

				while ( i >= rl )
				{
					i -= rl;
					sym = ! sym;
					rl = GD.decode()+1;
				}

				return sym;
			}
Exemple #10
0
void testgammarl()
{
	srand(time(0));
	unsigned int n = 128*1024*1024;
	unsigned int n2 = 64*1024*1024;
	std::vector<uint64_t> V (n);
	std::vector<uint64_t> V2 (n2);
	std::vector<uint64_t> Vcat;
	unsigned int const albits = 3;
	uint64_t const almask = (1ull << albits)-1;
	
	for ( uint64_t i = 0; i < V.size(); ++i )
	{
		V[i]  = rand() & almask;
		Vcat.push_back(V[i]);
	}
	for ( uint64_t i = 0; i < V2.size(); ++i )
	{
		V2[i] = rand() & almask;
		Vcat.push_back(V2[i]);
	}

	std::string const fn("tmpfile");
	std::string const fn2("tmpfile2");
	std::string const fn3("tmpfile3");
	::libmaus::util::TempFileRemovalContainer::setup();
	::libmaus::util::TempFileRemovalContainer::addTempFile(fn);
	::libmaus::util::TempFileRemovalContainer::addTempFile(fn2);
	::libmaus::util::TempFileRemovalContainer::addTempFile(fn3);

	::libmaus::gamma::GammaRLEncoder GE(fn,albits,V.size(),256*1024);	
	for ( uint64_t i = 0; i < V.size(); ++i )
		GE.encode(V[i]);
	GE.flush();

	::libmaus::gamma::GammaRLEncoder GE2(fn2,albits,V2.size(),256*1024);
	for ( uint64_t i = 0; i < V2.size(); ++i )
		GE2.encode(V2[i]);
	GE2.flush();

	#if 0
	::libmaus::huffman::IndexDecoderData IDD(fn);
	for ( uint64_t i = 0; i < IDD.numentries+1; ++i )
		std::cerr << IDD.readEntry(i) << std::endl;	
	#endif

	::libmaus::gamma::GammaRLDecoder GD(std::vector<std::string>(1,fn));
	assert ( GD.getN() == n );

	for ( uint64_t i = 0; i < n; ++i )
		assert ( GD.decode() == static_cast<int64_t>(V[i]) );
	
	uint64_t const off = n / 2 + 1031;
	::libmaus::gamma::GammaRLDecoder GD2(std::vector<std::string>(1,fn),off);
	for ( uint64_t i = off; i < n; ++i )
		assert ( GD2.decode() == static_cast<int64_t>(V[i]) );
		
	std::vector<std::string> fnv;
	fnv.push_back(fn);
	fnv.push_back(fn2);
	::libmaus::gamma::GammaRLEncoder::concatenate(fnv,fn3);
	
	for ( uint64_t off = 0; off < Vcat.size(); off += 18521 )
	{
		::libmaus::gamma::GammaRLDecoder GD3(std::vector<std::string>(1,fn3),off);	
		assert ( GD3.getN() == Vcat.size() );
		
		for ( uint64_t i = 0; i < std::min(static_cast<uint64_t>(1024ull),Vcat.size()-off); ++i )
			assert ( GD3.decode() == static_cast<int64_t>(Vcat[off+i]) );
	}

	remove ( fn.c_str() );
	remove ( fn2.c_str() );
	remove ( fn3.c_str() );	
}
Exemple #11
0
fmat GD(const fmat& X, const fmat& Y) {
    return GD(X, Y, ALPHA);
}
Exemple #12
0
 { "NPCFRAMERATE",      NPCFRAMERATE,         0,             0 },
 { "NPCHALTRATE",       NPCHALTRATE,          0,             0 },
 { "NPCDRAWTYPE",       NPCDRAWTYPE,          0,             0 },
 { "NPCHP",             NPCHP,                0,             0 },
 { "NPCID",             NPCID,                0,             0 },
 { "NPCDP",             NPCDP,                0,             0 },
 { "NPCWDP",            NPCWDP,               0,             0 },
 { "NPCOTILE",          NPCOTILE,             0,             0 },
 { "NPCENEMY",          NPCENEMY,             0,             0 },
 { "NPCWEAPON",         NPCWEAPON,            0,             0 },
 { "NPCITEMSET",        NPCITEMSET,           0,             0 },
 { "NPCCSET",           NPCCSET,              0,             0 },
 { "NPCBOSSPAL",        NPCBOSSPAL,           0,             0 },
 { "NPCBGSFX",          NPCBGSFX,             0,             0 },
 { "NPCCOUNT",          NPCCOUNT,             0,             0 },
 { "GD",                GD(0),              256,             0 },
 { "SDD",               SDD,                  0,             0 },
 { "GDD",               GDD,                  0,             0 },
 { "SDDD",              SDDD,                 0,             0 },
 { "SCRDOORD",          SCRDOORD,             0,             0 },
 { "GAMEDEATHS",        GAMEDEATHS,           0,             0 },
 { "GAMECHEAT",         GAMECHEAT,            0,             0 },
 { "GAMETIME",          GAMETIME,             0,             0 },
 { "GAMEHASPLAYED",     GAMEHASPLAYED,        0,             0 },
 { "GAMETIMEVALID",     GAMETIMEVALID,        0,             0 },
 { "GAMEGUYCOUNT",      GAMEGUYCOUNT,         0,             0 },
 { "GAMECONTSCR",       GAMECONTSCR,          0,             0 },
 { "GAMECONTDMAP",      GAMECONTDMAP,         0,             0 },
 { "GAMECOUNTERD",      GAMECOUNTERD,         0,             0 },
 { "GAMEMCOUNTERD",     GAMEMCOUNTERD,        0,             0 },
 { "GAMEDCOUNTERD",     GAMEDCOUNTERD,        0,             0 },
Exemple #13
0
// Gradient descent clásico / en tanda.
fmat GD(const fmat& X, const fmat& Y, double alpha) {
    fmat Theta = zeros<fmat>(X.n_cols, Y.n_cols);
    return GD(X, Y, alpha, Theta, GD_IT);
}
Exemple #14
0
			uint64_t inverseSelect1(uint64_t i, unsigned int & rsym) const
			{
				assert ( i < n );

				uint64_t const block = i / blocksize;
				i -= block*blocksize;

				uint64_t const blockptr = getBlockPointer(block);
				uint64_t const wordoff = (blockptr / (8*sizeof(uint64_t)));
				uint64_t const bitoff = blockptr % (8*sizeof(uint64_t));

				::libmaus2::util::GetObject<uint64_t const *> GO(data.begin() + wordoff);
				::libmaus2::gamma::GammaDecoder < ::libmaus2::util::GetObject<uint64_t const *> > GD(GO);
				if ( bitoff )
					GD.decodeWord(bitoff);

				uint64_t r = GD.decodeWord(rankaccbits); // 1 bit accumulator
				bool sym = GD.decodeWord(1);

				uint64_t rl = GD.decode()+1;

				while ( i >= rl )
				{
					if ( sym )
						r += rl;

					i -= rl;
					sym = ! sym;
					rl = GD.decode()+1;
				}

				rsym = sym;

				if ( sym )
					return r+i+1;
				else
					return r;
			}
Exemple #15
0
			uint64_t rankm1(uint64_t i) const
			{
				assert ( i <= n );

				uint64_t const block = i / blocksize;
				i -= block*blocksize;

				uint64_t const blockptr = getBlockPointer(block);
				uint64_t const wordoff = (blockptr / (8*sizeof(uint64_t)));
				uint64_t const bitoff = blockptr % (8*sizeof(uint64_t));

				::libmaus2::util::GetObject<uint64_t const *> GO(data.begin() + wordoff);
				::libmaus2::gamma::GammaDecoder < ::libmaus2::util::GetObject<uint64_t const *> > GD(GO);
				if ( bitoff )
					GD.decodeWord(bitoff);

				uint64_t r = GD.decodeWord(rankaccbits); // 1 bit accumulator
				bool sym = GD.decodeWord(1);

				uint64_t rl = GD.decode()+1;

				// std::cerr << "sym=" << sym << " rl=" << rl << std::endl;

				while ( i >= rl )
				{
					if ( sym )
						r += rl;

					i -= rl;
					sym = ! sym;
					rl = GD.decode()+1;

					// std::cerr << "sym=" << sym << " rl=" << rl << std::endl;
				}

				if ( sym )
					return r+i;
				else
					return r;
			}
    uint64_t rankm1(uint64_t i) const
    {
        assert ( i < n );

        uint64_t const block = i / blocksize;
        i -= block*blocksize;

        uint64_t const blockptr = getBlockPointer(block);
        uint64_t const byteoff = (blockptr / (8*sizeof(uint64_t)))*8;
        uint64_t const bitoff = blockptr % (8*sizeof(uint64_t));

        in.clear();
        in.seekg(baseoffset + byteoff);

        ::libmaus::aio::SynchronousGenericInput<uint64_t> SGI(in,8,std::numeric_limits<uint64_t>::max(),false /* checkmod */);
        ::libmaus::gamma::GammaDecoder < ::libmaus::aio::SynchronousGenericInput<uint64_t> > GD(SGI);
        if ( bitoff )
            GD.decodeWord(bitoff);

        uint64_t r = GD.decodeWord(rankaccbits); // 1 bit accumulator
        bool sym = GD.decodeWord(1);

        uint64_t rl = GD.decode()+1;

        // std::cerr << "sym=" << sym << " rl=" << rl << std::endl;

        while ( i >= rl )
        {
            if ( sym )
                r += rl;

            i -= rl;
            sym = ! sym;
            rl = GD.decode()+1;

            // std::cerr << "sym=" << sym << " rl=" << rl << std::endl;
        }

        if ( sym )
            return r+i;
        else
            return r;
    }
Exemple #17
0
			bool decodeBlock()
			{
				while ( FBO.file < index.Vfn.size() && FBO.block >= index.blocksPerFile[FBO.file] )
				{
					FBO.file++;
					FBO.block = 0;
					FBO.blockoffset = 0; // check this if we change the file format
					FBO.offset = 0;
					openFile();
				}
				if ( FBO.file == index.Vfn.size() )
				{
					PSGI.reset();
					PISI.reset();
					return false;
				}

				libmaus2::gamma::GammaDecoder< libmaus2::aio::SynchronousGenericInput<uint64_t> > GD(*PSGI);
				uint64_t const bs = GD.decode() + 1;
				B.ensureSize(bs);
				for ( uint64_t i = 0; i < bs; ++i )
					B[i] = GD.decode();

				pa = B.begin();
				pc = B.begin();
				pe = B.begin() + bs;

				FBO.block += 1;

				return true;
			}