Example #1
0
bool EntityInstanceCompare::precede(const EntityInstance &e1, const EntityInstance &e2, const PropertyPrecedeOrderList &s, const EntityInfo &inf)
{
    QVariant a1,a2;
    int t1,t2;
    foreach(PropertyPrecedeOrder so, s){
        a1= e1.get(so.first);
        a2= e2.get(so.first);
        t1= a1.userType();
        if(t1==QMetaType::UnknownType && inf.propertyInfo(so.first).dataType()!=QMetaType::UnknownType){
            t1= inf.propertyInfo(so.first).dataType();
            a1= inf.propertyInfo(so.first).defaultValue();
        }
        t2= a2.userType();
        if(t2==QMetaType::UnknownType && inf.propertyInfo(so.first).dataType()!=QMetaType::UnknownType){
            t2= inf.propertyInfo(so.first).dataType();
            a2= inf.propertyInfo(so.first).defaultValue();
        }
        if(t1== QMetaType::UnknownType && t2== QMetaType::UnknownType) continue;
        if(so.second == def::Ascending){
            if(t1== QMetaType::UnknownType) return true;
            if(t2== QMetaType::UnknownType) return false;
            if(lessThan(a1,a2)) return true;
            else if(greaterThan(a1,a2)) return false;
        }else if(so.second == def::Descending){
            if(t1== QMetaType::UnknownType) return false;
            if(t2== QMetaType::UnknownType) return true;
            if(greaterThan(a1,a2)) return true;
            else if(lessThan(a1,a2)) return false;
        }
    }
Example #2
0
int interseccao(ponto *p, segmento_ptr_pontos s1, segmento_ptr_pontos s2)
{


  GLfloat x1=s1.ponto1->x;
  GLfloat y1=s1.ponto1->y;
  GLfloat x2=s1.ponto2->x;
  GLfloat y2=s1.ponto2->y;
  GLfloat x3=s2.ponto1->x;
  GLfloat y3=s2.ponto1->y;
  GLfloat x4=s2.ponto2->x;
  GLfloat y4=s2.ponto2->y;

  GLfloat denominador = (y4 - y3)*(x2 - x1) - (x4 - x3)*(y2 - y1);

  // sao retas paralelas
  if (equal(denominador, 0.0)) {
  //Debug	printf("PARALLEL\n");
	return PARALLEL;
  }

 
  GLfloat ua = (x4 - x3)*(y1 - y3) - (y4 - y3)*(x1 - x3);
  ua /= denominador;

  GLfloat ub= (x2 - x1)*(y1 - y3) - (y2 - y1)*(x1 - x3);
  ub/= denominador;

  p->x = x1 + ua*(x2 - x1);
  p->y = y1 + ua*(y2 - y1);


  if ((greaterThan(ua, 0.0)) && (lessThan(ua, 1.0))) {
    if ((greaterThan(ub, 0.0)) && (lessThan(ub, 1.0))) {
  //Debug      printf("INSIDE BOTH\n");
      return INSIDE_BOTH;
    }
    else {
  //Debug      printf("INSIDE FIRST\n");
      return INSIDE_FIRST;
    }
  }
  else
    if ((greaterThan(ub, 0.0)) && (lessThan(ub, 1.0))) {
  //Debug      printf("INSIDE SECOND\n");
      return INSIDE_SECOND;
    }
    else {
  //Debug      printf("INSIDE NONE\n");
  //Debug      printf("ua=%f ub=%f\n", ua, ub);
      return INSIDE_NONE;
    }


}
Example #3
0
int main() {

	Time t1(6, 30);
	Time t2(8, 51);

	bool isGreaterThan = greaterThan(t1, t2);
	if (isGreaterThan) cout << "t1 > t2: TRUE" << endl;
	else cout << "t1 > t2: FALSE" << endl;

	bool isLessThan = lessThan(t1, t2);
	if (isLessThan) cout << "t1 < t2: TRUE" << endl;
	else cout << "t1 < t2: FALSE" << endl;

	bool isEqual = equals(t1, t2);
	if (isEqual) cout << "t1 = t2: TRUE" << endl;
	else cout << "t1 = t2: FALSE" << endl;

	Time t3 = addTimes(t1, t2);
	cout << "t3 - minutes: " << t3.getMinutes() << " seconds: " << t3.getSeconds() << endl;

	Time t4 = subtractTimes(t1, t2);
	cout << "t4 - minutes: " << t4.getMinutes() << " seconds: " << t4.getSeconds() << endl;

	return 0;
}
Example #4
0
bool Version::greaterThan(const QString & myVersionStr, const QString & yourVersionStr) {
	VersionThing myVersionThing;
	Version::toVersionThing(myVersionStr,myVersionThing);
	VersionThing yourVersionThing;
	Version::toVersionThing(yourVersionStr,yourVersionThing);
	return greaterThan(myVersionThing,yourVersionThing);
}
Example #5
0
	bool greaterThan(const bignum &bn1, const bignum &bn2)
	{
		//if bases are different, convert the second and re-evaluate
		if (bn1.getBase() != bn2.getBase())
			return greaterThan(bn1, bn2.getConverted(bn1.getBase()));

		if (bn1 == bn2)
			return false;

		if (bn1.isNegative() && !bn2.isNegative())
			return false;

		if (!bn1.isNegative() && bn2.isNegative())
			return true;

		if (bn1.isNegative() && bn2.isNegative())
			return (lessThan(bn1.absolute(), bn2.absolute()));

		if (bn1.getDigitCount() > bn2.getDigitCount())
			return true;

		if (bn1.getDigitCount() < bn2.getDigitCount())
			return false;

		for (int i = bn1.getDigitCount() - 1; i >= 0; i--)
		{
			if (bn1.getDigit(i) > bn2.getDigit(i))
				return true;

			if (bn1.getDigit(i) < bn2.getDigit(i))
				return false;
		}

		return false;
	}
Example #6
0
	bool lessThan(const bignum &bn1, const bignum &bn2)
	{
		if (bn1.getBase() != bn2.getBase())
			return lessThan(bn1, bn2.getConverted(bn1.getBase()));

		if (bn1 == bn2)
			return false;

		if (bn1.isNegative() && !bn2.isNegative())
			return true;

		if (!bn1.isNegative() && bn2.isNegative())
			return false;

		if (bn1.isNegative() && bn2.isNegative())
			return (greaterThan(bn1.absolute(), bn2.absolute()));

		if (bn1.getDigitCount() < bn2.getDigitCount())
			return true;

		if (bn1.getDigitCount() > bn2.getDigitCount())
			return false;

		for (int i = bn1.getDigitCount() - 1; i >= 0; i--)
		{
			if (bn1.getDigit(i) < bn2.getDigit(i))
				return true;

			if (bn1.getDigit(i) > bn2.getDigit(i))
				return false;
		}

		return false;
	}
Example #7
0
string KNN::getPredictedClass(set<docWeighted, docWeightedCmp>& trainExamples){
    
    map<string, double> votes;
    map<string, double> sum;

    int counter = 0;
    for(set<docWeighted>::iterator ex = trainExamples.begin(); ex != trainExamples.end() && counter < K; ex++, counter++){
        string classId = stats->getTrainClass((ex)->docId);
        votes[classId] += 1;//ex->weight;
        sum[classId] += ex->weight;

//        cout<<" k = " << counter << " docID = " << (ex)->docId<< " classe = " <<  classId << "\tsim = " << ex->weight <<endl;
    }
    
    string predictedClass = "";
    double max = 0;
    for(map<string, double>::iterator it = votes.begin(); it != votes.end(); it++){
        if(greaterThan(it->second, max)){
            max = it->second;
            predictedClass = it->first;
        }
        else if(equals(it->second, max) && max > 0.0){

            if(lesserThan(sum[it->first] , sum[predictedClass])){
                max = it->second;
                predictedClass = it->first;
            }
        }
//        cout<<"classe = " << it->first << "\tsim = " << it->second<< " sum = " << sum[it->first] << endl;
    }
//    cout<<"predicter = " << predictedClass << "  -> " << max<<endl;
//    cout<<"====================================="<<endl;
    return predictedClass;
}
Example #8
0
SearchResult Search(const int * const items, const int n_items,
		const int ascending, const int key, const SearchType type,
		int* const index) {
	int i = 0;

	// If key with the matching search type is not found, index will be set to -1
	*index = -1;

	// Assuming if it is descending order (ascending = 0), else ascending order
	if (ascending == 0) {
		i = n_items - 1;
	}

	SearchResult result = NotFound;

	// Descending order is treated as reverse descending by starting from n_items - 1 to 0

	switch (type) {
	case LessThan:
		result = lessThan(items, n_items, ascending, key, type, &index, &i);
		break;

	case LessThanEquals:
		result = lessThan(items, n_items, ascending, key, type, &index, &i);
		if(equals(items, n_items, ascending, key, type, &index, &i) == FoundExact) {
			result = FoundExact;
		}
		break;

	case Equals:
		result = equals(items, n_items, ascending, key, type, &index, &i);
		break;

	case GreaterThan:
		result = greaterThan(items, n_items, ascending, key, type, &index, &i);
		break;

	case GreaterThanEquals:
		result = equals(items, n_items, ascending, key, type, &index, &i);
		if (result == FoundExact) {
			break;
		}
		result = greaterThan(items, n_items, ascending, key, type, &index, &i);
		break;
	}
	return result;
}
Example #9
0
        /*! @brief Return the relative ordering of two Values.
         @param[in] other The Value to be compared with.
         @returns The relative ordering of the two Values. */
        inline bool
        operator >
            (const Value &  other)
        {
            bool    valid = false;
            bool    result = greaterThan(other, valid);

            return (valid && result);
        } // operator >
Example #10
0
bool Version::candidateGreaterThanCurrent(const VersionThing & candidateVersionThing)
{
	VersionThing myVersionThing;
	myVersionThing.majorVersion = majorVersion().toInt();
	myVersionThing.minorVersion = minorVersion().toInt();
	myVersionThing.minorSubVersion = minorSubVersion().toInt();
	myVersionThing.releaseModifier = modifier();

	return greaterThan(myVersionThing, candidateVersionThing); 
}
boolean isBST (tree t, element minKey, element maxKey)
{

    if (emptyTree (t)) {
        return true;
    }
    if (lessThan (root (t), minKey) || greaterThan (root(t), maxKey)) {
        return false;
    }

    return ( isBST(left(t), minKey, root (t)) && isBST(right (t), root (t), maxKey));

}
Example #12
0
void KNN::train(Examples& exs){

	TRACE_V(TAG,"train");
    
    //Maybe we didnt calculate this before...
    stats->calculateIDF();
 
    for(int i = 0; i < exs.getNumberOfNumericalAttibutes(); i++){
        maxv[i] = numeric_limits<double>::min();
        minv[i] = numeric_limits<double>::max();
    }
    
	for(ExampleIterator e = exs.getBegin(); e != exs.getEnd(); e++){
   
        vector<string> textTokens = (e)->getTextTokens();
        vector<int> textFrequencyTokens = (e)->getTextFrequency();
		string exampleClass = (e)->getClass();
        string eId = (e)->getId();
        double docSize = 0.0;

//      cout<<" Tokens categoricos  =  " << tokens.size() << endl;
		for(unsigned int i = 3; i < textTokens.size(); i++){
			int tf = textFrequencyTokens[i-3];
			string termId = textTokens[i];
            
            double tfidf = tf * stats->getIDF(termId);

            docSize += (tfidf * tfidf);

            docWeighted dw(eId, tfidf);
            termDocWset[termId].insert(dw);
		}
        
        vector<double> numTokens = (e)->getNumericalTokens();
       
        for(unsigned int i = 0; i < numTokens.size(); i++){
            if(greaterThan(numTokens[i], maxv[i])){
                maxv[i] = numTokens[i];
            }
            if(lesserThan(numTokens[i], minv[i])){
                minv[i] = numTokens[i];
            }
        }

        exNumTrain[eId] = numTokens;
        exCatTrain[eId] = (e)->getCategoricalTokens();
        
        docTrainSizes[eId] = docSize;
    }

}
void
floatmath::approximateValue(float& value,
							const float& newValue,
							float changeRate,
							const float approximationAccuracy)
{
	float diff = fabs(newValue - value);
	if(diff < approximationAccuracy)
		return;

	if (changeRate > diff)
		changeRate = diff/2;

	(greaterThan(newValue, value, approximationAccuracy))? value+=changeRate : value-=changeRate;
};
Example #14
0
// returns true if:
//   minheap is true and the priority of second < first
//   minheap is false and the priority of second > first
bool heap::rotate(graph_object* first, graph_object* second)
{
  if(minheap)
  {
	if (lessThan(second, first)) // NB: arg order (swapped)
	  return true;
	return false;
  }
  else
  {
	  if(greaterThan(second, first)) // NB: arg order 
		  return true;
	  return false;
  }
}
Example #15
0
Time subtractTimes(Time t1, Time t2) {
	int min, sec;

	if (greaterThan(t1, t2) == true) {
		min = t1.getMinutes() - t2.getMinutes();
		sec = t2.getSeconds() - t2.getSeconds();
	}
	else {
		min = 0;
		sec = 0;
	}

	Time result(min, sec);

	return result;
}
Example #16
0
void solve(std::vector<int> solution, std::vector<std::vector<int> > couples, bool *legal, int n) {
	if (solution.size() == n) {
		int total = couples[solution[0]][0] + couples[solution[0]][1] + couples[solution[1]][1];
		if (couples[solution[solution.size() - 1]][0] + couples[solution[solution.size() - 1]][1] + couples[solution[0]][1] == total) {
			int ** solSet = solutionSet(solution, couples);
			std::string solSetAsStr = solutionSetAsStr(solSet, n, 3);
			if (greaterThan(solSetAsStr, max) && solSetAsStr.length() == 16) max = solSetAsStr;
			return;
		}
	}
	else {
		if (solution.size() == 0) {
			for (int i = 0; i < couples.size(); i++) {
				solution.push_back(i);
				bool *sievedLegal = sieveCouples2(couples[i][0], couples, sieveCouples1(couples[i][0], couples[i][1], couples, legal, couples.size()), couples.size());
				solve(solution, couples, sievedLegal, n);
				solution.erase(solution.begin() + (solution.size() - 1));
			}
		}
		if (solution.size() == 1) {
			for (int i = 0; i < couples.size(); i++) {
				if (legal[i]) {
					if (couples[i][0] < couples[solution[0]][0] + couples[solution[0]][1]) {
						solution.push_back(i);
						bool *sievedLegal = sieveCouples1(couples[i][0], couples[i][1], couples, legal, couples.size());
						solve(solution, couples, sievedLegal, n);
						solution.erase(solution.begin() + (solution.size() - 1));
					}
				}
			}
		}
		if (solution.size() > 1) {
			for (int i = 0; i < couples.size(); i++) {
				if (legal[i]) {
					int total = couples[solution[0]][0] + couples[solution[0]][1] + couples[solution[1]][1];
					if (couples[i][1] + couples[solution[solution.size() - 1]][0] + couples[solution[solution.size() - 1]][1] == total) {
						solution.push_back(i);
						bool *sievedLegal = sieveCouples1(couples[i][0], couples[i][1], couples, legal, couples.size());
						solve(solution, couples, sievedLegal, n);
						solution.erase(solution.begin() + (solution.size() - 1));
					}
				}
			}
		}
	}
}
Example #17
0
ostream& operator << (ostream& out, const constraint& c)
{
    char* fmt = new char[100];

    if(!equal(c.xCoef, 0))
        sprintf(fmt, "%lfx", c.xCoef);

    if(greaterThan(c.yCoef, 0))
        sprintf(fmt, "%s+%lfy", fmt, c.yCoef);

    if(lessThan(c.yCoef, 0))
        sprintf(fmt, "%s-%lfy", fmt, -1*c.yCoef);

    sprintf(fmt, "%s<=%lf", fmt, -1*c.bias);
    out << fmt;

    delete [] fmt;

    return out;
}
Example #18
0
 void Parser::relation() 
 {
     expression();
     if (Cradle::isRelOp(input.getChar())) {
         output.emitLine("MOVE D0,(SP)-");
         switch (input.getChar()) {
             case '=':
                 equals();
                 break;
             case '#':
                 notEquals();
                 break;
             case '<':
                 lessThan();
                 break;
             case '>':
                 greaterThan();
                 break;
         }
         output.emitLine("TST D0");
     }
 }
Example #19
0
ostream& operator << (ostream& out, const TDLP& tdlp)
{
    const constraintSet constraints = tdlp.getConstraint();
    const objFunc func = tdlp.getObjFunc();

    /**
     *  output the constaints
     */
    constConstraintIterator it;
    out << "constraints : " << endl;
    for(it = constraints.begin();it != constraints.end();it++){
        out << *it << endl;
    }

    /**
     * output the objective function
     */
    char* fmt = new char [200];

    sprintf(fmt, "max f= max ");

    if(!equal(func.xCoef, 0))
        sprintf(fmt, "%s%lfx", fmt, func.xCoef);

    if(greaterThan(func.yCoef, 0))
        sprintf(fmt, "%s+%lfy", fmt, func.yCoef);

    if(lessThan(func.yCoef, 0))
        sprintf(fmt, "%s-%lfy", fmt, -1*func.yCoef);

    out << "objective function : " << fmt;

    delete [] fmt;

    return out;
}
Example #20
0
/**
 * @brief TDLP::updateOptimalSolution if c has intersection with the feasible region, then need to update the optimal solution
 *                                    otherwise, the LP has no feasible solution.
 * @param feasibleRegion
 * @param c
 * @param ans
 */
void TDLP::updateOptimalSolution(region& feasibleRegion, constraint& c, solution& ans)
{
    vertexSet optimalCandidateVertex;
    feasibleRegion.intersectOfHalfPlane(c, optimalCandidateVertex);

    size_t size = optimalCandidateVertex.size();

    /**
     * if half plane has no intersection with feasible region and the current optimal vertex is
     * not on the half plane, then the LP has no solution.
     */
    if(size == 0){
        ans.setStatus(noSolution);
        return;
    }

    /**
     * if the number of intersection is one, then the current optimal solution is a point
     */
    if(size == 1){
        double tmp = func.getValue(optimalCandidateVertex[0]);
        ans.setSolution(optimalCandidateVertex[0], tmp, singlePoint);
    }

    /**
     * if the number of intersection is two, then the current optimal solution is a line
     */
    if(size == 2){
        vertex vl(optimalCandidateVertex[0]);
        vertex vr(optimalCandidateVertex[1]);

        double vlFuncValue = func.getValue(vl);
        double vrFuncValue = func.getValue(vr);

        if(equal(vlFuncValue, vrFuncValue)){
            ans.setSolution(edge(vl,vr), vlFuncValue, singleLine);

        }else{
            double maxVal;
            vertex maxVertex;

            if(greaterThan(vlFuncValue, vrFuncValue)){
                maxVal = vlFuncValue;
                maxVertex = vl;
            }
            else{
                maxVal = vrFuncValue;
                maxVertex = vr;
            }

            if(equal(maxVal, ans.getFuncValue())){
                /**
                 * if current optimal value is equal to last optimal value, then the status of last optimal is single line
                 * and current optimal vertex is on that line
                 */
                if(ans.getStatus() == singleLine){
                    edge e(ans.getEdge());
                    if(c.isVertexOnHalfPlane(e.start))
                        ans.setSolution(edge(e.start, maxVertex), maxVal, singleLine);
                    else
                        ans.setSolution(edge(maxVertex, e.end), maxVal, singleLine);
                    return;
                }
            }

            ans.setSolution(maxVertex, maxVal, singlePoint);
        }
    }

    return;
}
Example #21
0
void KNN::test(Examples& exs){

    TRACE_V(TAG,"test");

    //Statistics:
    map<string,unsigned long long> classHits;
    map<string,unsigned long long> classMiss;
    map<string,unsigned long long> mappedDocs;
    map<string,unsigned long long> docsPerClass;
    
    int numExamples = 0;
    for(ExampleIterator it = exs.getBegin(); it != exs.getEnd(); it++){
        numExamples++;
        if(numExamples % 100 == 0)
            cout<<"Evaluated: " << numExamples<<endl;

        Example ex = *it;


        vector<string> textTokens = ex.getTextTokens();	
        vector<int>    textFreqTokens = ex.getTextFrequency();	
        vector<double> numTokens = ex.getNumericalTokens();
        vector<string> catTokens = ex.getCategoricalTokens();

        string eId = ex.getId();
        string classId = ex.getClass();
        
        map<string, double> examplesTestSize;
        //credibility to each class
        if((usingKNNOptimize && !valuesSaved )  || !usingKNNOptimize){
            for(unsigned int i = 3; i < textTokens.size(); i++){
                string termId = textTokens[i];
                int tf = textFreqTokens[i-3];

                for(set<string>::iterator classIt = stats->getClasses().begin(); classIt != stats->getClasses().end(); classIt++) {
                    double tfidf = tf * getContentCredibility(termId, *classIt);
                    examplesTestSize[*classIt] += (tfidf * tfidf);
                }
            }
        }
        map<string, double> similarity;

        if(usingKNNOptimize && valuesSaved){
            similarity = saveValues[eId];
        }
        else{
            for(unsigned int i = 3; i < textTokens.size();i++){
                string termId = textTokens[i];
                int tf = textFreqTokens[1-3];

                for(set<docWeighted, docWeightedCmp>::iterator termIt = termDocWset[termId].begin(); termIt != termDocWset[termId].end(); termIt++){
                    string trainClass = stats-> getTrainClass(termIt->docId);

                    double trainDocSize = docTrainSizes[termIt->docId];
                    double trainTermWeight = termIt->weight;
                    double testTermWeight = tf * getContentCredibility(termId, trainClass);
                    
                    similarity[termIt->docId] +=  ( - ( trainTermWeight / sqrt(trainDocSize)  * testTermWeight / sqrt(examplesTestSize[trainClass]) ));
//                    cout<<"sim = " << similarity[termIt->docId] <<endl;
                }
            }

            //numerical KNN
            for(map<string, vector<double> >::iterator trainIt  = exNumTrain.begin(); trainIt != exNumTrain.end(); trainIt++){
                double dist = 0.0;

                for(unsigned int i = 0; i < numTokens.size(); i++){
                    double a = minMaxNorm(numTokens[i],i);
                    double b = minMaxNorm(exNumTrain[trainIt->first][i],i);
                    double val = (a-b)*(a-b);
                    //double val = (numTokens[i] - exNumTrain[trainIt->first][i]) * ( numTokens[i] - exNumTrain[trainIt->first][i]);
                    //                    cout<<numTokens[i] << " - " <<exNumTrain[trainIt->first][i] <<endl;
                    //                    cout<<"a = " << a << " b = " << b << " val =" << val<<endl;
                    if( greaterThan(dist + val, numeric_limits<double>::max())){
                        //                        cerr<<"OOOOOOOOOOOOOOOPA!!!"<<endl;
                        //                        exit(0);
                        dist = numeric_limits<double>::max() - 1.0;
                        break;
                    }
                    dist += val;
                    //                    cout<<"dist =" << dist<<endl;
                }
                similarity[trainIt->first] += dist;
            }

            //categorical KNN
            for(map<string, vector<string> >::iterator trainIt  = exCatTrain.begin(); trainIt != exCatTrain.end(); trainIt++){
                double dist = 0.0;

                for(unsigned int i = 0; i < catTokens.size(); i++){
                    string trainTok = exCatTrain[trainIt->first][i];
                    string testTok = catTokens[i];

                    double catCred = getCategoricalCredibility(i, testTok, stats->getTrainClass(trainIt->first));
//                    cout<<"catCred = " <<catCred<<endl;
//                    cout<<" i = " << i << "teste = " << testTok<<" treino = " << trainTok<<endl;
                    if(trainTok != testTok){
//                        dist+= 1.0/(catCred+ 1.0) + 1.0;
                        dist+= 1.0/(catCred+ 1.0);
//                        cout<<"dist = " << dist<<endl;
                    }
                }
                similarity[trainIt->first] += dist;
            }
 //               cout<<"class = " << classId << " doc = " << trainIt->first<< " docClass = " << stats->getTrainClass(trainIt->first) << " dist="<<dist<< " 1/dist = " <<1.0/dist<< " sqrt = "<<sqrt(dist)<<endl;
        }

        if(!valuesSaved && usingKNNOptimize){
            saveValues[eId] = similarity;
        }

        //sim of each example in test set
        set<docWeighted, docWeightedCmp> sim;
        for(map<string, double>::iterator testIt = similarity.begin(); testIt != similarity.end(); testIt++){
            
            //calculating graph credibility....if so
            vector<double> graphsCreds(graphsCredibility.size());
            double similarityValue = testIt->second;

//            cout<< " eid = " << eId << " eclass = " << classId << " traindocclass = " << stats->getTrainClass(testIt->first) << " similarit = " << similarityValue<< endl;

            for(unsigned int g = 0 ; g < graphsCredibility.size(); g++){
                double gsim = getGraphCredibility(g, eId, stats->getTrainClass(testIt->first));
                similarityValue /= (0.5+gsim);
            } 
           
            //never change this, it is necessary
            docWeighted dw(testIt->first, similarityValue);
            sim.insert(dw);
        }
        
        string predictedLabel = getPredictedClass(sim);

        computeConfusionMatrix(classId, predictedLabel);

        //        if(io->usingPredictionsFile)
        savePrediction(eId, classId, predictedLabel);

        if(predictedLabel == classId){
            classHits[classId] ++;			
        }
        else{
            classMiss[classId]++;
        }

        mappedDocs[predictedLabel]++;
        docsPerClass[classId]++;
    }
    if(valuesSaved == false){
        valuesSaved = true;
    }
    calculateF1(classHits,classMiss,docsPerClass, mappedDocs);
//    showConfusionMatrix();
}
Example #22
0
void Font::drawText(vec2 pen, vec4 color, const char* text)
{
  uint vertexCount = 0;

  // Realize vertices for glyphs
  {
    const size_t length = std::strlen(text);
    m_vertices.resize(length * 6);

    for (const char* c = text;  *c != '\0'; )
    {
      const uint32 codepoint = utf8::next<const char*>(c, text + length);
      const Glyph* glyph = findGlyph(codepoint);
      if (!glyph)
      {
        glyph = findGlyph(0xfffd);
        if (!glyph)
          continue;
      }

      pen = round(pen);

      if (all(greaterThan(glyph->size, vec2(0.f))))
      {
        const Rect pa(pen + glyph->bearing - vec2(0.5f), glyph->size);
        const Rect ta(glyph->offset + vec2(0.5f), glyph->size);

        m_vertices[vertexCount + 0].texcoord = ta.position;
        m_vertices[vertexCount + 0].position = pa.position;
        m_vertices[vertexCount + 1].texcoord = ta.position + vec2(ta.size.x, 0.f);
        m_vertices[vertexCount + 1].position = pa.position + vec2(pa.size.x, 0.f);
        m_vertices[vertexCount + 2].texcoord = ta.position + ta.size;
        m_vertices[vertexCount + 2].position = pa.position + pa.size;

        m_vertices[vertexCount + 3] = m_vertices[vertexCount + 2];
        m_vertices[vertexCount + 4].texcoord = ta.position + vec2(0.f, ta.size.y);
        m_vertices[vertexCount + 4].position = pa.position + vec2(0.f, pa.size.y);
        m_vertices[vertexCount + 5] = m_vertices[vertexCount + 0];

        vertexCount += 6;
      }

      pen += vec2(glyph->advance, 0.f);
    }
  }

  if (!vertexCount)
    return;

  VertexRange range = m_context.allocateVertices(vertexCount,
                                                 Vertex2ft2fv::format);
  if (range.isEmpty())
  {
    logError("Failed to allocate vertices for text drawing");
    return;
  }

  range.copyFrom(m_vertices.data());

  m_pass.setUniformState(m_colorIndex, color);
  m_pass.apply();

  m_context.render(PrimitiveRange(TRIANGLE_LIST, range));
}
Example #23
0
 inline bool operator > ( const Vector2& vector ) const
 {
     return greaterThan(vector);
 }
Example #24
0
bool SString::lessThan(SString str)
{
   return !greaterThan(str);
}
Example #25
0
bool QUrlInfo::lessThan(const QUrlInfo &i1, const QUrlInfo &i2,
                         int sortBy)
{
    return !greaterThan(i1, i2, sortBy);
}