예제 #1
0
/**
 * Compute the Kramer-Mesner matrix.
 *
 * Precondition: t < k
 */
KramerMesnerMatrix computeKMMatrix(const Group& G, unsigned int t, unsigned int k) {
	std::vector<KMBuilderOutput> builderOutputs;			// stores the relevant data for k = 2 onwards
	Matrix A;
	
	for (int i = 2; i <= k; i++) {
		boost::scoped_ptr<KMBuilder> builder;
		
		// Get orbit representatives of (i - 1)-subsets
		std::vector<Subset> orbitReps;
		if (i == 2) {
			// As it is the first time, we have to compute the orbit representatives of singleton subsets...
			Subset pointsRemaining = generateX(G.getNumPoints());
			while (!pointsRemaining.empty()) {
				typedef OrbitSet<Permutation, unsigned long>::const_iterator OrbitSetIterator;
				
				unsigned long point = *(pointsRemaining.begin());	// A new representative...
				Subset singletonSet = makeSingletonSet(point);		// ...as a set
				orbitReps.push_back(singletonSet);
				
				// Compute the orbit of the point, and remove it from the remaining points
				OrbitSet<Permutation, unsigned long> orbit = G.orbit(point, Transversal::TrivialAction());
				for (OrbitSetIterator it = orbit.begin(); it != orbit.end(); it++) {
					pointsRemaining.erase(pointsRemaining.find(*it));
				}
			}
			
			builder.reset(new KMBuilder(G, i, orbitReps));
		} else {
			// We get them from what we computed earlier
			KMBuilderOutput& input = builderOutputs[i - 3];
			orbitReps = input.getNewReps();
			
			builder.reset(new KMBuilder(G, i, orbitReps, input.getPrunerData()));
		}
		
		KMBuilderOutput builderOutput = builder->build();
		builderOutputs.push_back(builderOutput);
		
		// From the identity that A[t][k] = A[t][s] * A[s][k] / combinat(k - t, k - s) for any s
		// between t and k, we get the following:
		if (i == t + 1) {
			assignMatrix(A, builderOutput.getNewMatrix());
		} else if (i > t + 1) {
			assignMatrix(A, matrixMultiply(A, builderOutput.getNewMatrix()));
			scalarDivide(i - t, A);
		}
	}
	
	return KramerMesnerMatrix(G, builderOutputs[t - 2].getNewReps(), builderOutputs[k - 2].getNewReps(), A);
}
예제 #2
0
파일: bot_3.cpp 프로젝트: antgar/rtype_cpp
Bot::Bot(int id) : AEntity(id), _health(50), _y(0)
{
  _timerShoot = new Timer(true);
  _sprite = "sprite1.png";
  _name = _sprite;
  _type = E_BOT;
  addSystem(C_HEALTH);
  addSystem(C_POSITION);
  addSystem(C_HITBOX);
  generateX();
  generateY();
  dynamic_cast<SystemPos*>(_systemManager->getSystemByComponent(C_POSITION))->update(_x, _y);
  dynamic_cast<SystemHitbox*>(_systemManager->getSystemByComponent(C_HITBOX))->update(refreshHitbox());
}
예제 #3
0
    Mahalanobis TogersonMetricLearner::learnMetric() {

        dim = getVectorDim();
        sampleCount = getSampleCount();


        int iIdx = selectI();

        mat B = generateB(iIdx);
        mat X = generateX();
        mat Y = generateY(B);
        mat Z = generateZ(X, Y);
        mat A = Z.t() * Z;

        // normalize it for convenience
        A = 1 / A(0, 0) * A;

        return Mahalanobis(A);

    }
예제 #4
0
파일: zadanie.c 프로젝트: shnek/MOwNiT
void runMyProgram(int N, FILE *output1, FILE *output2){
	double A[3*N];
	double X[N];

	generateTridag(N, A);

	generateX(N, X);
	fprintf(output1, "%i, ", N);
	fprintf(output2, "%i, ", N);
	GSLRunMyProgram(N, A, X, output1);
	double L[3*N];
	double U[3*N];
	zeroTridag(N, L);
	zeroTridag(N, U);
	clock_t startTime = clock();
	decompose(N, A, L, U);
	solveLU(N, L, U, X);
	fprintf(output2, "%f\n", 1000*(double)(clock()-startTime)/(double)(CLOCKS_PER_SEC));
	// printX(N, X);	

}
예제 #5
0
//## Operation: nextValue%36B6D4CD036C
//	********************************************************************************
//
//	Name: RetCode nextValue(Float *pValue)
//
//	Description: Returns the next value of the Uniform distribution.
//
//	Output parameters: Float *pValue;  //next number generated.
//
//	Returns: Zero - successful
//	         Otherwise - error
//
//	********************************************************************************
RetCode BaseGen::nextValue (Float *pValue)
{
  //## begin BaseGen::nextValue%36B6D4CD036C.body preserve=yes
	Int j;
	Float nextNumber;
	Float uniform;

	j = (Int) ((__int64)lenVector * pY[indVector] / moduleY);
	nextNumber = ((Float)pV[j]) / moduleX;
	uniform = nextNumber * (maxValue - minValue) + minValue;
	pV[j] = pX[indVector];
	indVector++;
	if (indVector >= lenVector)
	{
		generateX();
		generateY();
		indVector = 0;
	}
	*pValue = uniform;

	return SCH_SUCCESS;
  //## end BaseGen::nextValue%36B6D4CD036C.body
}
예제 #6
0
//## Operation: BaseGen%36B6DB4B02FE
//	********************************************************************************
//
//	Name: BaseGen(Ulong seed = 78562, Float minVal = 0, Float maxVal = 1)
//
//	Description: Non-default constructor - requires the initial seed and range to generate the random variables.
//
//	Input parameters: Ulong seed;       //seed to begin the random number generation
//	                  Float minVal = 0; //lower boundary of the range
//	                  Float maxVal = 1; //upper boundary of the range
//
//	Returns: none
//
//	Remarks: The seed value must be: 0 <= seed <= MAX_WORD; and minVal < maxVal.
//
//	********************************************************************************
BaseGen::BaseGen (Ulong seed, Float minVal, Float maxVal)
  //## begin BaseGen::BaseGen%36B6DB4B02FE.hasinit preserve=no
      : firstSeedX(seed),
        firstSeedY(78562),
        incrementX(1),
        incrementY(1),
        lenVector(100),
        maxValue(maxVal),
        minValue(minVal),
        moduleX(0x10000000),
        moduleY(0x04000000),
        multiplierX(5),
        multiplierY(9)
  //## end BaseGen::BaseGen%36B6DB4B02FE.hasinit
  //## begin BaseGen::BaseGen%36B6DB4B02FE.initialization preserve=yes
  //## end BaseGen::BaseGen%36B6DB4B02FE.initialization
{
  //## begin BaseGen::BaseGen%36B6DB4B02FE.body preserve=yes
	RetCode rc = SCH_SUCCESS;
	Int i;

	if ((firstSeedX < 0) || (firstSeedX > MAX_WORD) || (minValue >= maxValue))
	{
		rc = SCH_INVALID_PARAMETER;
	}

	if (rc == SCH_SUCCESS)
	{
		pX = new Ulong [lenVector];
		if (pX == NULL)
		{
			rc = SCH_ALLOCATION_ERROR;
		}
	}

	if (rc == SCH_SUCCESS)
	{
		pY = new Ulong [lenVector];
		if (pY == NULL)
		{
			rc = SCH_ALLOCATION_ERROR;
		}
	}

	if (rc == SCH_SUCCESS)
	{
		pV = new Ulong [lenVector];
		if (pV == NULL)
		{
			rc = SCH_ALLOCATION_ERROR;
		}
	}

	if (rc != SCH_SUCCESS)
	{
		throw SchException (rc);
	}

	for (i=0; i<lenVector; i++)
	{
		pX[i] = 0;
		pY[i] = 0;
		pV[i] = 0;
	}

	// Initialize: generating the first numbers
	nextSeedX = firstSeedX;
	nextSeedY = firstSeedY;
	generateX();
	generateY();
	indVector = 0;
	for (i=0; i<lenVector; i++)
	{
		pV[i] = pX[i];
	}
	generateX();

  //## end BaseGen::BaseGen%36B6DB4B02FE.body
}