コード例 #1
0
void EventsWidget::scrollTo(double time)
{
	if (events != nullptr) {
		int n = findBestMatch(time);
		tableView->selectRow(n);
		resizeColumnsToContents();
	}
}
コード例 #2
0
ファイル: correlator.cpp プロジェクト: sandsmark/replicode
// extracts rules of the form Target <= {(Src_1,Dt_1),..,(Src_n,Dt_n)}
// for deltaTimes Dt_1 < .. < Dt_n
void Correlator::extract_rules(JacobianRules& rules, uint64_t episode_size)
{
    uint64_t num_calls = episode_size - SLICE_SIZE;
    rules.reserve(num_calls);
    JacobianSlice slice(SLICE_SIZE, LSTMState(32));

    for (int64_t t = num_calls - 1; t >= 0; --t) {
        // perform sensitivity analysis
        corcor.getJacobian(t, t + SLICE_SIZE, slice);
        // the last one is the target
        JacobianRule rule;
        rule.target = findBestMatch(slice.back().begin(), rule.confidence);

        if (rule.confidence < OBJECT_THR) {
            continue;
        }

        // the later objects occurred closer to the target, so iterate in reverse
        JacobianSlice::reverse_iterator it = ++slice.rbegin();
        JacobianSlice::reverse_iterator end = slice.rend();

        for (uint16_t deltaTime = 1; it != end; ++it, ++deltaTime) {
            double match;
            r_code::Code* source = findBestMatch(it->begin(), match);

            // no confidence, no correlation
            if (match >= OBJECT_THR) {
                Source src;
                src.source = source;
                src.deltaTime = deltaTime;
                rule.sources.push_back(src);
                rule.confidence += match;
            }
        }

        if (!rule.sources.empty()) {
            rule.confidence /= rule.sources.size() + 1;

            if (rule.confidence >= RULE_THR) {
                rules.push_back(rule);
            }
        }
    }
}
コード例 #3
0
 QObject *findBestMatch(const QString &type, const QVector<int> &metaTypeId, TypePluginLoader::Options opt)
 {
     if (QObject *const plugin = findBestMatch(type, metaTypeId)) {
         {
             if ((opt & TypePluginLoader::NoDefault) && plugin == mDefaultPlugin.plugin()) {
                 return 0;
             }
             return plugin;
         }
     }
     return 0;
 }
コード例 #4
0
ファイル: ADM_vidAscii.cpp プロジェクト: mean00/avidemux2
/**
 * 
 * @param target
 * @return 
 */
bool AsciiFilter::drawGlyphs(ADMImage *source,ADMImage *target)
{
  int luma;
  uint8_t glyph;
  target->blacken ();
  for(int y=0;y<reducedHeight;y++)
    {      
      for(int x=0;x<reducedWidth;x++)
      {
        glyph=findBestMatch(source,x,y,luma);
        drawOne(glyph,target,x,y,luma);
      }
    }
   return true;
}
コード例 #5
0
ファイル: ocr.c プロジェクト: anndream/anpr-1
char LPROCR_lib_ReadThisChar ( int * cImageRaw, int w, int h, float * score, int aveCharWidth,  int * displayChar, int * error )
{

    int bestMatch;

    int * cImageSS=0 ; // character image scaled to standard h & w


    cImageSS = (int *) malloc ( sizeof(int) * STANDARD_WIDTH * STANDARD_HEIGHT);
    if ( cImageSS == 0 )
    {
        *error = 1;
        *score = 0;
        return (0);
    }


    int sw, sh;
    sw = STANDARD_WIDTH;
    sh = STANDARD_HEIGHT;

    if ( w == 0 || h == 0 ) return(0);

    if ((10*h) / w > 34)  // at 30, some new york chars get turned into ones
    {
        if (  aveCharWidth - w > 2 )
        {
            bestMatch = '1';
            *score = 100000;
            freeMemory (&cImageSS);
            return ((char)bestMatch);
        }
    }


    prepChar(cImageRaw, w, h, cImageSS, error);


    bestMatch  = findBestMatch(cImageSS, sw, sh, displayChar, score);

    freeMemory (&cImageSS);


    return((char)bestMatch);

}
コード例 #6
0
void MetadataDownload::run()
{
    RunProlog();

    MetadataLookup* lookup;
    while ((lookup = moreWork()) != NULL)
    {
        MetadataLookupList list;
        // Go go gadget Metadata Lookup
        if (lookup->GetType() == kMetadataVideo)
        {
            if (lookup->GetSubtype() == kProbableTelevision)
                list = handleTelevision(lookup);
            else if (lookup->GetSubtype() == kProbableMovie)
                list = handleMovie(lookup);
            else
                list = handleVideoUndetermined(lookup);

            if (!list.size() &&
                lookup->GetSubtype() == kUnknownVideo)
            {
                list = handleMovie(lookup);
            }
        }
        else if (lookup->GetType() == kMetadataRecording)
        {
            if (lookup->GetSubtype() == kProbableTelevision)
            {
                if (lookup->GetSeason() > 0 || lookup->GetEpisode() > 0)
                    list = handleTelevision(lookup);
                else if (!lookup->GetSubtitle().isEmpty())
                    list = handleVideoUndetermined(lookup);

                if (!list.size())
                    list = handleRecordingGeneric(lookup);
            }
            else if (lookup->GetSubtype() == kProbableMovie)
            {
                list = handleMovie(lookup);
                if (lookup->GetInetref().isEmpty())
                    list.append(handleRecordingGeneric(lookup));
            }
            else
            {
                list = handleRecordingGeneric(lookup);
                if (lookup->GetInetref().isEmpty())
                    list.append(handleMovie(lookup));
            }
        }
        else if (lookup->GetType() == kMetadataGame)
            list = handleGame(lookup);

        // inform parent we have lookup ready for it
        if (m_parent && list.count() >= 1)
        {
            // If there's only one result, don't bother asking
            // our parent about it, just add it to the back of
            // the queue in kLookupData mode.
            if (list.count() == 1 && list.at(0)->GetStep() == kLookupSearch)
            {
                MetadataLookup *newlookup = list.takeFirst();
                newlookup->SetStep(kLookupData);
                prependLookup(newlookup);
                continue;
            }

            // If we're in automatic mode, we need to make
            // these decisions on our own.  Pass to title match.
            if (list.at(0)->GetAutomatic() && list.count() > 1)
            {
                if (!findBestMatch(list, lookup->GetTitle()))
                    QCoreApplication::postEvent(m_parent,
                        new MetadataLookupFailure(MetadataLookupList() << lookup));
                continue;
            }

            LOG(VB_GENERAL, LOG_INFO,
                QString("Returning Metadata Results: %1 %2 %3")
                    .arg(lookup->GetTitle()).arg(lookup->GetSeason())
                    .arg(lookup->GetEpisode()));
            QCoreApplication::postEvent(m_parent,
                new MetadataLookupEvent(list));
        }
        else
        {
            list.append(lookup);
            QCoreApplication::postEvent(m_parent,
                new MetadataLookupFailure(list));
        }
    }

    RunEpilog();
}
コード例 #7
0
/**
Return the node that is accessible and is closest to the goal Node if the current node is unaccessible.
If the original node is accessible, do nothing.
If there are no accessible coordinates, simply leave the node unchanged.
*/
void AStarGraph::findBestMatch(AStarNode& node, AStarNode& goal) {
	const float scale = BZDBCache::tankRadius;
	float goalCoordinates[2] = {goal.x * scale, goal.y * scale};

	findBestMatch(node, goalCoordinates);
}
コード例 #8
0
ファイル: tex_syn.cpp プロジェクト: scallopedllama/texsyn
SDL_Surface *textureSynthesis(SDL_Surface *inputTexture, int w, int h)
{
	debug("Making output texture\n");						//I_s
	SDL_Surface *outputTexture = createSurface(w, h);

	debug("Generating noise on output texture\n");
	noisify(outputTexture);

	debug("Making output texture Gaussian Pyramid\n");				//G_s
	gauss_pyramid *outPyramid = new gauss_pyramid(outputTexture, -1, false);

	debug("Making input texture Gaussian Pyramid\n");				//G_a
	gauss_pyramid *inPyramid = new gauss_pyramid(inputTexture, outPyramid->getLevels());
	hood_pyramid *inHoodPyramid = new hood_pyramid(inPyramid);

	debug("Beginning texture synthesis...\n");
	int l = 0;
	double totTime = 0;
#ifdef TEX_SYN_USE_MULTIRESOLUTION
	for(l = outPyramid->getLevels() - 1; l >= 0; l--)
	{
#endif
		SDL_Surface *curLevel = outPyramid->getLevel(l);
		int lvlW = curLevel->w, lvlH = curLevel->h;
		debug("\tBeginning work on %d x %d level %d of the output pyramid..\n", lvlW, lvlH, l);

		//do this in scanline order
		for(int y = 0; y < lvlH; y++)
		{
            //for timing the operation
            clock_t start = clock();
			for(int x = 0; x < lvlW; x++)
			{
				verboseDebug("\t\tCalculating color for level %d at (%d, %d)\n", l, x, y);

				//update the display
				dispSurface(curLevel);

				//calculate the color to put here
				Uint32 color = findBestMatch(inHoodPyramid, inPyramid, outPyramid, l, x, y);

				//put that color on the pyramid level
				putPixel(curLevel, x, y, color);
			}
			totTime += ((double)clock() - start) / CLOCKS_PER_SEC;
			if(y % 20 == 0)
            	debug("\t\tTwenty rows done. Average time per row: %f s*\n", totTime / (y + 1));
            	//about the seconds* there, that value is not quite seconds, but it should be close and
            	//consistant in time.
		}

#ifdef TEX_SYN_USE_MULTIRESOLUTION
		//reset the timer every level
		totTime = 0.0;

		//blur the curent level (if it isn't the last)
		if(l > 0)
			gaussianBlur(curLevel);
	}
#endif

	//reconstruct the pyramid
	SDL_Surface *toReturn = outPyramid->reconstructPyramid();

	//free output bitmap
	debug("Cleaning up\n");
	delete outPyramid;
	delete inHoodPyramid;
	delete inPyramid;

	//return it up.
	return toReturn;
}
コード例 #9
0
ファイル: SubRegion.cpp プロジェクト: sarbjit-longia/ahuman
//take input pattern, process it and remember the output
//pattern is array of length InputCount containing the input pattern
bool SubRegion::feedForward( unsigned *pattern, bool memorize, unsigned pLowUsageThreshold )
{
	bool lRetCode = true;
	// CurrentSequence is the single sequence that is being worked on
	// Sequence length is always one.
	currentSequence -> addPattern( pattern );

	if( currentSequence -> complete() ) {
		unsigned int lLearnedIndex;
		double lMatchPrecision;
		BestMatch lBestMatch;
		findBestMatch(*currentSequence, lLearnedIndex, lMatchPrecision);

		lBestMatch.precision = lMatchPrecision;
		lBestMatch.index = lLearnedIndex;

		if( memorize && lBestMatch.precision < 1) { // potentially treat as a new sequence
			int lRetIndex = 0;
			lRetIndex = myRegion.addSequence( *currentSequence );

			if ( -1 ==  lRetIndex ) {
				// New at version 1.4
				// Memory full so add it to the best place we can find
				// But only for a reasonably good match
				// 
				if ( lBestMatch.precision > neocortex.bestMatchPrecision ) {
					myRegion.memory( lBestMatch.index ).increaseFrequency();  
				}
				else {
					int lLowUsageIndex = findLowUsage( pLowUsageThreshold );
					if ( lLowUsageIndex != -1 ) {
						// Replace the memory with the one at the top 
						myRegion.forgetMemory( lLowUsageIndex );
						// Add the new sequence to the top
						lRetIndex = myRegion.addSequence( *currentSequence );
						if ( -1 ==  lRetIndex ) {
							lRetCode = false;
							lBestMatch.index = neocortex.OUTPUT_NONE;
						}
						else {
							lBestMatch.index = (unsigned int) lRetIndex; // this should be the top of memory
						}
					}
					else {
						// Sequence was not added.
						lRetCode = false;
						lBestMatch.index = neocortex.OUTPUT_NONE;
						// Would be nice to log - but we do not have logging in this class right now.
						//std::ostringstream  lLogStream;
						//lLogStream << "Cannot find a low-usage slot for new sequence." << " Memory is full."; //<< std::endl; 
						//cGuiUtils->Log( std::string( lLogStream.str() ) );
					}
				}
			}
			else {
				// Memory already had space for the new sequence (frequency is already set to 1)
				lBestMatch.index = (unsigned int) lRetIndex;
			}
		}
		else {
			if ( memorize && lBestMatch.precision == 1 ) {
				// Match precision is 100%
				myRegion.memory( lBestMatch.index ).increaseFrequency();  
			}
		}

		nameOutput = lBestMatch.index; //index of the best match for the new sequence
		memIndex = lBestMatch.index;   //used in Contextual
		currentSequence -> clear();
	}

	return lRetCode;
}
コード例 #10
0
void evaluateAlignments(struct coordConvRep *ccr) 
/* Figure out if the alignments of the up,mid, and down seqs indicates
that we can shift coordinates. If yes, do conversion otherwise set
error message and ccr->good = FALSE; At first I'm going to be
pretty stringent. They all have to use one of the best scoring
psls to:
   - Line up all on the same strand.
   - Line up in the original order (or reverse if on opposite strand).
   - Line up withing 20% of the original distance from eachother.
*/
{
struct psl *upPsl=NULL,*midPsl=NULL,*downPsl=NULL;
struct possibleCoord *pcList = NULL, *pc=NULL;

if(ccr->upPsl && ccr->midPsl && ccr->downPsl)
    {
    /* Drop the psls that don't have the best score */
    dropNotBest(&ccr->upPsl);
    dropNotBest(&ccr->midPsl);
    dropNotBest(&ccr->downPsl);
    
    for(upPsl=ccr->upPsl; upPsl != NULL; upPsl=upPsl->next)
	{
	for(midPsl=ccr->midPsl; midPsl != NULL; midPsl=midPsl->next)
	    {
	    /* make sure that we're on the same strand and chromosome */
	    if(!(sameString(midPsl->strand,upPsl->strand)) || !(sameString(midPsl->tName, upPsl->tName)))
		continue;
	    for(downPsl=ccr->downPsl; downPsl!=NULL; downPsl=downPsl->next) 
		{
		/* make sure that we're on the same strand and chromosome */
		if(!(sameString(upPsl->strand,downPsl->strand)) || !(sameString(upPsl->tName,downPsl->tName)))
		    continue;
		/* check to make sure we're in the correct relative order */
		if(strstr(upPsl->strand,"+"))
		    {
		    /* make sure that we're in the right realtive order if it is + strand */
		    if( (upPsl->tEnd > midPsl->tStart) || (midPsl->tEnd > downPsl->tStart))
			continue;
		    }
		else if(strstr(upPsl->strand,"-")) 
		    {
		    /* make sure that we're in the right realtive order if it is + strand */
		    if( (downPsl->tStart > midPsl->tEnd) ||  (midPsl->tStart > upPsl->tEnd))
			continue;
		    }
		else 
		    {
		    errAbort("coordConv::evaluateAlignments() - alignment doesn't appear to be on '+' or '-' strand.");
		    }
		
		/* Whew, we've got a candidate, record the distances and add it to our
		   possibleCoord structure */
		AllocVar(pc);
		pc->midPsl = midPsl;
		pc->upPsl = upPsl;
		pc->downPsl = downPsl;
		pc->d1 = abs(upPsl->tStart - midPsl->tStart);
		pc->d2 = abs(midPsl->tStart - downPsl->tStart);
		slSafeAddHead(&pcList,pc);
		pc = NULL;
		}
	    }
	}
    }
else 
    {
#ifdef DEBUG
    FILE *f = mustOpen("bad.fa", "a");
    fprintf(f,"#\n");
    faWriteNext(f,ccr->upSeq->name,ccr->upSeq->dna, ccr->upSeq->size);
    faWriteNext(f,ccr->midSeq->name,ccr->midSeq->dna, ccr->midSeq->size);
    faWriteNext(f,ccr->downSeq->name,ccr->downSeq->dna, ccr->downSeq->size);
    carefulClose(&f);
#endif
    }
pc = findBestMatch(ccr,pcList);
checkPcAndTranslateCoordinates(ccr,pc);
}
コード例 #11
0
void MetadataDownload::run()
{
    MetadataLookup* lookup;
    threadRegister("MetadataDownload");
    while ((lookup = moreWork()) != NULL)
    {
        MetadataLookupList list;
        // Go go gadget Metadata Lookup
        if (lookup->GetType() == VID)
        {
            if (lookup->GetSeason() > 0 || lookup->GetEpisode() > 0)
                list = handleTelevision(lookup);
            else if (!lookup->GetSubtitle().isEmpty())
                list = handleVideoUndetermined(lookup);
            else
                list = handleMovie(lookup);
        }
//        else if (lookup->GetType() == MUSIC)
//            list = handleMusic(lookup);
        else if (lookup->GetType() == GAME)
            list = handleGame(lookup);

        // inform parent we have lookup ready for it
        if (m_parent && list.count() >= 1)
        {
            // If there's only one result, don't bother asking
            // our parent about it, just add it to the back of
            // the queue in GETDATA mode.
            if (list.count() == 1 && list.at(0)->GetStep() == SEARCH)
            {
                MetadataLookup *newlookup = list.takeFirst();
                newlookup->SetStep(GETDATA);
                prependLookup(newlookup);
                continue;
            }

            // If we're in automatic mode, we need to make
            // these decisions on our own.  Pass to title match.
            if (list.at(0)->GetAutomatic() && list.count() > 1)
            {
                if (!findBestMatch(list, lookup->GetTitle()))
                    QCoreApplication::postEvent(m_parent,
                        new MetadataLookupFailure(MetadataLookupList() << lookup));
                continue;
            }

            VERBOSE(VB_GENERAL, QString("Returning Metadata Results: %1 %2 %3")
                    .arg(lookup->GetTitle()).arg(lookup->GetSeason())
                    .arg(lookup->GetEpisode()));
            QCoreApplication::postEvent(m_parent,
                new MetadataLookupEvent(list));
        }
        else
        {
            list.append(lookup);
            QCoreApplication::postEvent(m_parent,
                new MetadataLookupFailure(list));
        }
    }
    threadDeregister();
}
コード例 #12
0
void graphics::InterpolationPlot::changePointsSlot(double x, double y, Qt::MouseButton btn){
    if(btn==Qt::LeftButton){
        int pos = points.findEqualX(x);
        if(pos != -1){
            errormessageBox->setWindowTitle("Punkt existiert schon");
            errormessageBox->setText("An der x-Position, an der Sie einen Punkt hinzufügen wollen,"
                            " existiert bereits ein Punkt.\nSoll dieser Punkt mit den neuen"
                            " Werten überschrieben werden oder soll der neue Punkt verworfen "
                            "werden?");
            QString str= "Damit korrekte Interpolationen durchgeführt werden können, dürfen keine "
                         "zwei Punkte mit dem gleichen x-Wert existieren. Sie haben versucht einen"
                         " Punkt an den folgenden Koordinaten hinzuzufügen (" + QString().setNum(x)
                         + ", " + QString().setNum(y) + "). Dort existiert aber bereits der Punkt ("
                         + QString().setNum(x) + ", " + QString().setNum(points[pos].getY()) + ").";
            errormessageBox->setDetailedText("");
            errormessageBox->setDetailedText(str);
            errormessageBox->setIcon(QMessageBox::Warning);
            QPushButton * tmpButton1 = errormessageBox->addButton(QMessageBox::Discard);
            QPushButton * tmpButton2 = new QPushButton("Überschreiben");
            errormessageBox->addButton(tmpButton2,QMessageBox::ApplyRole);
            errormessageBox->setDefaultButton(tmpButton1);
            errormessageBox->exec();
            if(errormessageBox->clickedButton()==tmpButton2) points[pos].setY(y);
            errormessageBox->removeButton(tmpButton1);
            errormessageBox->removeButton(tmpButton2);
            delete tmpButton1;
            delete tmpButton2;
        }
        else{
            points.append(custom_types::Point(x,y));
            points.sort();
        }
    }else{
        int posBestMatch = findBestMatch(x,y);
        if (posBestMatch != -1){
            points.remove(posBestMatch);
        }else{
            errormessageBox->setWindowTitle("Punkt nicht gefunden");
            errormessageBox->setText("Es konnte kein Punkt in der Nähe ihres Mausklickes "
                            "gefunden werden.\nSoll in einer größeren Umgebung nach "
                            "einem Punkt gesucht werden oder soll der Löschvorgang"
                            " abgebrochen werden?");
            QString str= "Sie haben versucht einen Punkt an den folgenden "
                         "Koordinaten zu löschen (" + QString().setNum(x)
                         + ", " + QString().setNum(y) + ").";
            errormessageBox->setDetailedText("");
            errormessageBox->setIcon(QMessageBox::Warning);
            QPushButton * tmpButton1 = new QPushButton("Abbrechen");
            errormessageBox->addButton(tmpButton1,QMessageBox::DestructiveRole);
            QPushButton * tmpButton2 = errormessageBox->addButton(QMessageBox::Retry);
            errormessageBox->setDefaultButton(tmpButton1);
            QString str2 = str + "\nAktueller Radius: " + QString().setNum(epsilon) + " Pixel.";
            errormessageBox->setDetailedText(str2);
            errormessageBox->exec();
            if(errormessageBox->clickedButton()==tmpButton1){
                errormessageBox->removeButton(tmpButton1);
                errormessageBox->removeButton(tmpButton2);
                delete tmpButton1;
                delete tmpButton2;
                return;
            }
            do{
                epsilon *= 1.5;
                int posBestMatch = findBestMatch(x,y);
                if (posBestMatch != -1){
                    points.remove(posBestMatch);
                    epsilon = 10;
                    break;
                }
                str2 = str + "\nAktueller Radius: " + QString().setNum(epsilon) + " Pixel.";
                errormessageBox->setDetailedText(str2);
                errormessageBox->exec();
                if(errormessageBox->clickedButton()==tmpButton1){
                    errormessageBox->removeButton(tmpButton1);
                    errormessageBox->removeButton(tmpButton2);
                    delete tmpButton1;
                    delete tmpButton2;
                    return;
                }
            }while(true);
            errormessageBox->removeButton(tmpButton1);
            errormessageBox->removeButton(tmpButton2);
            delete tmpButton1;
            delete tmpButton2;
        }
    }
    replot();
}
コード例 #13
0
bool HighlightState::findBestMatch(const std::string &s, HighlightToken &token,
                                   const MatchingParameters &params) const {
    return findBestMatch(s.begin(), s.end(), token, params);
}