/** * \brief default main function for focusing */ void FocusWork::main(astro::thread::Thread<FocusWork>& thread) { if (!complete()) { debug(LOG_ERR, DEBUG_LOG, 0, "FocusWork is not completely configured"); focusingstatus(Focusing::FAILED); return; } debug(LOG_DEBUG, DEBUG_LOG, 0, "starting focus process in [%d,%d]", min(), max()); // prepare the set of focus items to base the focus computation on FocusItems focusitems; // prepare for (int step = 0; step < steps(); step++) { // find position unsigned short position = min() + (step * (max() - min())) / (steps() - 1); debug(LOG_DEBUG, DEBUG_LOG, 0, "next position: %hu", position); // move to this position moveto(position); // get an image focusingstatus(Focusing::MEASURING); ccd()->startExposure(exposure()); usleep(1000000 * exposure().exposuretime()); ccd()->wait(); ImagePtr image = ccd()->getImage(); debug(LOG_DEBUG, DEBUG_LOG, 0, "got an image of size %s", image->size().toString().c_str()); // evaluate the image double value = (*evaluator())(image); debug(LOG_DEBUG, DEBUG_LOG, 0, "evaluated to %f", value); // callback with the evaluated image callback(evaluator()->evaluated_image(), position, value); // add the information to a set focusitems.insert(FocusItem(position, value)); } // now solve we need a suitable solver for the method int targetposition = solver()->position(focusitems); if ((targetposition < min()) || (targetposition > max())) { std::string msg = stringprintf( "could not find a focus position: %d", targetposition); debug(LOG_ERR, DEBUG_LOG, 0, "%s", msg.c_str()); focusingstatus(Focusing::FAILED); return; } // move to the final focus position focusingstatus(Focusing::MOVING); moveto(targetposition); focusingstatus(Focusing::FOCUSED); }
FunctionObject* Curry::evaluate(Thread& t, FunctionObject* inObj, const Function::ArgumentVector& args, const vector<bool>& mask, bool dynamicDispatch) { // // Never do partial application on the result of a lambda // expression (its too difficult to archive). Instead do partial // evaluation. The good side is that there will never be more // than one level of indirection in multiple-curried lambda // expressions. the bad side is that there will be more overhead // upfront. // Process* p = t.process(); const Function* F = inObj->function(); const bool apply = !F->isLambda(); try { if (apply) { PartialApplicator evaluator(F, p, &t, args, mask, dynamicDispatch); const FunctionType* rt = evaluator.result()->type(); FunctionObject* outObj = new FunctionObject(rt); outObj->setDependent(inObj); outObj->setFunction(evaluator.result()); return outObj; } else { FunctionSpecializer evaluator(F, p, &t); evaluator.partiallyEvaluate(args, mask); const FunctionType* rt = evaluator.result()->type(); FunctionObject* outObj = new FunctionObject(rt); outObj->setFunction(evaluator.result()); return outObj; } } catch (Exception& e) { ProgramException exc(t); exc.message() = e.message(); exc.message() += " during partial "; exc.message() += (apply ? "application" : "evaluation"); exc.message() += " of "; exc.message() += F->name().c_str(); throw exc; } }
WLCSScorer::score_ptr_type WLCSScorer::score(const sentence_type& __sentence) const { sentence_type sentence; tokenize(__sentence, sentence); double precision_max = 0.0; double recall_max = 0.0; std::auto_ptr<WLCS> wlcs(new WLCS()); for (impl_set_type::const_iterator iter = impl.begin(); iter != impl.end(); ++ iter) { impl_type& evaluator = const_cast<impl_type&>(*(*iter)); const impl_type::value_type value = evaluator(sentence, alpha); if (value.precision > precision_max) { precision_max = value.precision; wlcs->match_hyp = value.match; wlcs->norm_hyp = value.norm_hyp; } if (value.recall > recall_max) { recall_max = value.recall; wlcs->match_ref = value.match; wlcs->norm_ref = value.norm_ref; } } return score_ptr_type(wlcs.release()); }
/** * Tests a single evaluator function from the high-level interface. * * See test_interp2d in this file for usage examples. */ static inline int test_single_high_level( double (*evaluator)(const interp2d_spline*, const double, const double, gsl_interp_accel*, gsl_interp_accel*), int (*evaluator_e)(const interp2d_spline*, const double, const double, gsl_interp_accel*, gsl_interp_accel*, double*), const interp2d_spline* interp, const double x, const double y, gsl_interp_accel* xa, gsl_interp_accel* ya, const double expected_results[], size_t i ) { if (expected_results != NULL) { int failures = 0; int status; double result = evaluator(interp, x, y, xa, ya); gsl_test_abs(result, expected_results[i], 1e-10, "high level %s %d", interp2d_spline_name(interp), i); if (fabs(result - expected_results[i]) > 1e-10) { // test failed failures++; } status = evaluator_e(interp, x, y, xa, ya, &result); if (status != GSL_SUCCESS) { // something went wrong failures++; } else { gsl_test_abs(result, expected_results[i], 1e-10, "high level POSIX %s %d", interp2d_spline_name(interp), i); if (fabs(result - expected_results[i]) > 1e-10) { // test failed - wrong result failures++; } } } else { return 0; } }
/** * Another wrapper function that serves as a drop-in replacement for * interp2d_eval_impl but does not check the bounds. This can be used * for extrapolation. */ static inline int interp2d_eval_impl_no_boundary_check( int (*evaluator)(const void*, const double xa[], const double ya[], const double za[], size_t xsize, size_t ysize, double x, double y, gsl_interp_accel*, gsl_interp_accel*, double* z), const interp2d* interp, const double xarr[], const double yarr[], const double zarr[], const double x, const double y, gsl_interp_accel* xa, gsl_interp_accel* ya, double* result ) { return evaluator(interp->state, xarr, yarr, zarr, interp->xsize, interp->ysize, x, y, xa, ya, result); }
CCombineGenome::CCombineGenome(int* inputData): GAGenome(Initializer, Mutator, Comparator) { evaluator(Evaluator); crossover(Crossover); if (inputData) { ComRuleData* pData = (ComRuleData*)inputData; paths = pData->m_OptimizeInfoMap.size(); std::map<YKString,std::list<OptimizeRule>>::iterator ruleIter = pData->m_OptimizeInfoMap.begin(); m_inputData = inputData; for (int i = 0; ruleIter != pData->m_OptimizeInfoMap.end(); ++ruleIter,++i) { m_indexToGroupMap[i] = ruleIter->first; m_groupToIndexMap[ruleIter->first] = i; } } list = (paths ? new GAListGenome<YK_LLONG> * [paths] : (GAListGenome<YK_LLONG> **)0); for(int i=0; i<paths; i++) { list[i] = new GAListGenome<YK_LLONG>; list[i]->mutator(GAListGenome<YK_LLONG>::SwapMutator); } }
map<string, vector<span>> program_eval::eval(program& prog) { map<string, vector<span>> answer; auto sorted_rules = sort_rules(prog.rules); for (auto rule : sorted_rules) { rule_eval evaluator(answer, document_); auto result = evaluator.eval(*rule); auto it = answer.find(rule->pred.name); if (it == answer.end()) { // Move answer.insert(make_pair(rule->pred.name, move(result))); } else { // Union auto& spans = it->second; vector<span> span_union; span_union.reserve(spans.size() + result.size()); set_union(spans.begin(), spans.end(), result.begin(), result.end(), back_inserter(span_union)); span_union.shrink_to_fit(); spans.swap(span_union); } } return answer; }
RibesScorer::score_ptr_type RibesScorer::score(const sentence_type& __sentence) const { sentence_type sentence; tokenize(__sentence, sentence); std::auto_ptr<Ribes> ribes(new Ribes()); if (! impl.empty()) { ribes->distance = - std::numeric_limits<double>::infinity(); for (impl_set_type::const_iterator iter = impl.begin(); iter != impl.end(); ++ iter) { const impl_type& evaluator = *(*iter); const impl_type::value_type value = evaluator(sentence, order_max, spearman); ribes->distance = std::max(ribes->distance, (value.distance * utils::mathop::pow(value.precision, alpha) * utils::mathop::pow(value.penalty, beta))); } ribes->norm = 1; } return score_ptr_type(ribes.release()); }
ProjectPart::Ptr ProjectInfoGenerator::createProjectPart(const RawProjectPart &rawProjectPart, const ProjectPart::Ptr &templateProjectPart, const ProjectFiles &projectFiles, const QString &partName, ProjectPart::LanguageVersion languageVersion, ProjectPart::LanguageExtensions languageExtensions) { ProjectPart::Ptr part(templateProjectPart->copy()); part->displayName = partName; part->files = projectFiles; part->languageVersion = languageVersion; RawProjectPartFlags flags; ToolChainInfo tcInfo; if (languageVersion <= ProjectPart::LatestCVersion) { flags = rawProjectPart.flagsForC; tcInfo = m_projectUpdateInfo.cToolChainInfo; } // Use Cxx toolchain for C projects without C compiler in kit and for C++ code if (!tcInfo.isValid()) { flags = rawProjectPart.flagsForCxx; tcInfo = m_projectUpdateInfo.cxxToolChainInfo; } // TODO: If no toolchain is set, show a warning ToolChainEvaluator evaluator(*part.data(), flags, tcInfo); evaluator.evaluate(); part->languageExtensions |= languageExtensions; part->updateLanguageFeatures(); return part; }
bool text_symbolizer_helper<FaceManagerT, DetectorT>::next_placement() { if (!placement_->next()) { placement_valid_ = false; return false; } placement_->properties.process(text_, feature_); info_ = &(text_.get_string_info()); if (placement_->properties.orientation) { // https://github.com/mapnik/mapnik/issues/1352 mapnik::evaluate<Feature, value_type> evaluator(feature_); angle_ = boost::apply_visitor( evaluator, *(placement_->properties.orientation)).to_double(); } else { angle_ = 0.0; } finder_ = boost::shared_ptr<placement_finder<DetectorT> >(new placement_finder<DetectorT>(feature_, *placement_, *info_, detector_, dims_)); // boost::make_shared<placement_finder<DetectorT> >(feature_, *placement_, *info_, detector_, dims_); if (writer_.first) finder_->set_collect_extents(true); placement_valid_ = true; return true; }
/* tests a single evaluator function from the high-level interface */ static int test_single_high_level( double (*evaluator)(const gsl_spline2d *, const double, const double, gsl_interp_accel *, gsl_interp_accel *), int (*evaluator_e)(const gsl_spline2d *, const double, const double, gsl_interp_accel *, gsl_interp_accel *, double *), const gsl_spline2d * interp, const double x, const double y, gsl_interp_accel * xa, gsl_interp_accel * ya, const double expected_results[], size_t i) { if (expected_results != NULL) { int status; double result = evaluator(interp, x, y, xa, ya); gsl_test_rel(result, expected_results[i], 1e-10, "high level %s %d", gsl_spline2d_name(interp), i); status = evaluator_e(interp, x, y, xa, ya, &result); if (status == GSL_SUCCESS) { gsl_test_rel(result, expected_results[i], 1e-10, "high level _e %s %d", gsl_spline2d_name(interp), i); } } return 0; }
CDERScorer::score_ptr_type CDERScorer::score(const sentence_type& __sentence) const { sentence_type sentence; tokenize(__sentence, sentence); double score_best = std::numeric_limits<double>::infinity(); std::auto_ptr<CDER> cder(new CDER()); for (impl_set_type::const_iterator iter = impl.begin(); iter != impl.end(); ++ iter) { impl_type& evaluator = const_cast<impl_type&>(*(*iter)); impl_type::value_type value = evaluator(sentence, weights, matcher); if (value.score < score_best) { score_best = value.score; cder->insertion = value.insertion; cder->deletion = value.deletion; cder->substitution = value.substitution; cder->jump = value.jump; } cder->references += evaluator.ref.size(); } if (! impl.empty()) cder->references /= impl.size(); return score_ptr_type(cder.release()); }
void Parser::B(){ switch (scanner.nextToken()) { case T_OPENPAREN: scanner.eatToken(T_OPENPAREN); if (evaluate) ops.push(T_OPENPAREN); A(); scanner.eatToken(T_CLOSEPAREN); if (evaluate) { while (ops.top() != T_OPENPAREN) numbers.push(evaluator(top_pop(ops), top_pop(numbers), top_pop(numbers))); ops.pop(); } break; case T_NUMBER: if (evaluate) numbers.push(scanner.getNumberValue()); scanner.eatToken(T_NUMBER); break; default: parseError(scanner.lineNumber(), scanner.nextToken()); break; } }
void testGeneratedData20() { DataFrame df; generatedData20(df); GreedyStepwiseSearch uut; shared_ptr<ConsistencySubsetEvaluator> evaluator(new ConsistencySubsetEvaluator()); uut.setEvaluator(evaluator); // this has been validated against weka vector<string> result = uut.findSubset(df); CPPUNIT_ASSERT_EQUAL((int)result.size(), 3); // order isn't important here, but easy CPPUNIT_ASSERT_EQUAL(result[0], string("age")); CPPUNIT_ASSERT_EQUAL(result[1], string("elevel")); CPPUNIT_ASSERT_EQUAL(result[2], string("car")); generatedData1000(df); // these results have been validated against weka result = uut.findSubset(df); CPPUNIT_ASSERT_EQUAL((int)result.size(), 5); // order isn't important here, but easy CPPUNIT_ASSERT_EQUAL(result[0], string("salary")); CPPUNIT_ASSERT_EQUAL(result[1], string("commission")); CPPUNIT_ASSERT_EQUAL(result[2], string("elevel")); CPPUNIT_ASSERT_EQUAL(result[3], string("car")); CPPUNIT_ASSERT_EQUAL(result[4], string("zipcode")); }
// Set all the initial values to zero. We do NOT call the initialize method at // this point - initialization must be done explicitly by the user of the // genome (eg when the population is created or reset). If we called the // initializer routine here then we could end up with multiple initializations // and/or calls to dummy initializers (for example when the genome is // created with a dummy initializer and the initializer is assigned later on). BitStringGenome:: BitStringGenome(unsigned int l, GAGenome::Evaluator f, void * u) : GAGenome(UniformInitializer, UniformMutator, Comparator), BitString() { crossover(UniformCrossover); evaluator(f); ud=u; for(int i=0; i<l; i++) *this += 1; }
Evaluator* MultiNetwork::makeEvaluator() const { MultiCombinedEvaluator* multiCombinedEvaluator = new MultiCombinedEvaluator(); for (size_t i = 0; i < subNetworks_.size(); i++) { std::unique_ptr<Evaluator> evaluator(subNetworks_[i]->makeEvaluator()); multiCombinedEvaluator->addEvaluator(std::move(evaluator)); } return multiCombinedEvaluator; }
bool expression_match(const std::string & test, const std::string & expr) { try { return evaluator(expr, test).eval(); } catch(const std::runtime_error & error) { log_warning << "Error evaluating \"" << expr << "\": " << error.what(); return true; } }
bool MediaQueryMatcher::evaluate(const MediaQuerySet* media) { if (!media) return false; OwnPtr<MediaQueryEvaluator> evaluator(prepareEvaluator()); return evaluator && evaluator->eval(media); }
void CGameSpawnConstructor::process_actor (LPCSTR start_level_name) { m_actor = 0; LEVEL_SPAWN_STORAGE::iterator I = m_level_spawns.begin(); LEVEL_SPAWN_STORAGE::iterator E = m_level_spawns.end(); for ( ; I != E; ++I) { if (!(*I)->actor()) continue; Msg ("Actor is on the level %s",*game_graph().header().level(game_graph().vertex((*I)->actor()->m_tGraphID)->level_id()).name()); VERIFY2 (!m_actor,"There must be the SINGLE level with ACTOR!"); m_actor = (*I)->actor(); } R_ASSERT2 (m_actor,"There is no ACTOR spawn point!"); if (!start_level_name) return; if (!xr_strcmp(*actor_level_name(),start_level_name)) return; const CGameGraph::SLevel &level = game_graph().header().level(start_level_name); GameGraph::_GRAPH_ID dest = GameGraph::_GRAPH_ID(-1); GraphEngineSpace::CGameLevelParams evaluator(level.id()); CGraphEngine *graph_engine = xr_new<CGraphEngine>(game_graph().header().vertex_count()); bool failed = !graph_engine->search(game_graph(),m_actor->m_tGraphID,GameGraph::_GRAPH_ID(-1),0,evaluator); if (failed) { Msg ("! Cannot build path via game graph from the current level to the level %s!",start_level_name); float min_dist = flt_max; Fvector current = game_graph().vertex(m_actor->m_tGraphID)->game_point(); GameGraph::_GRAPH_ID n = game_graph().header().vertex_count(); for (GameGraph::_GRAPH_ID i=0; i<n; ++i) { if (game_graph().vertex(i)->level_id() == level.id()) { float distance = game_graph().vertex(i)->game_point().distance_to_sqr(current); if (distance < min_dist) { min_dist = distance; dest = i; } } } if (!game_graph().vertex(dest)) { Msg ("! There is no game vertices on the level %s, cannot jump to the specified level",start_level_name); return; } } else dest = (GameGraph::_GRAPH_ID)evaluator.selected_vertex_id(); m_actor->m_tGraphID = dest; m_actor->m_tNodeID = game_graph().vertex(dest)->level_vertex_id(); m_actor->o_Position = game_graph().vertex(dest)->level_point(); xr_delete (graph_engine); }
PythonFileResource::PythonFileResource(const ParameterValueMap ¶meters) : Component(parameters), path(parameters[PATH]) { PythonEvaluator evaluator(path); if (!(evaluator.exec())) { throw SimpleException(M_PLUGIN_MESSAGE_DOMAIN, "Python file execution failed"); } }
unique_ptr<PositionEvaluator> EvaluatorFactory::evaluator() const { vector<std::unique_ptr<PositionEvaluator>> sub_evaluators; //sub_evaluators.emplace_back(tablebase_evaluator()); sub_evaluators.emplace_back(incremental_evaluator()); sub_evaluators.emplace_back(kingsafety_evaluator()); std::unique_ptr<PositionEvaluator> composite_evaluator( new CompositeEvaluator(std::move(sub_evaluators))); unique_ptr<PositionEvaluator> evaluator(new ResultEvaluator(std::move(composite_evaluator))); return evaluator; }
void initialize() { for (auto& p : this->swarm) { initializer.InitPosition(p->position); p->best_position = p->position; evaluator(p->best_position); initializer.InitVelocity(p->velocity, p->position); } evaluate(); }
GA1DArrayGenome<T>:: GA1DArrayGenome(unsigned int length, GAGenome::Evaluator f, void * u) : GAArray<T>(length), GAGenome(DEFAULT_1DARRAY_INITIALIZER, DEFAULT_1DARRAY_MUTATOR, DEFAULT_1DARRAY_COMPARATOR) { evaluator(f); userData(u); nx=minX=maxX=length; crossover(DEFAULT_1DARRAY_CROSSOVER); }
AST_Real RangeIterator::eval(AST_Expression exp, VarSymbolTable symbolTable) { EvalExp evaluator(symbolTable); AST_Expression result = evaluator.eval(exp); ERROR_UNLESS(result->expressionType() == EXPREAL || result->expressionType() == EXPINTEGER, "RangeIterator::getVal:\n" "Expression type should be EXPREAL or EXPINTEGER \n"); if (result->expressionType() == EXPREAL) { return result->getAsReal()->val(); } else { return result->getAsInteger()->val(); } }
void Parser::lastEval(bool eval){ if (eval) { while (ops.empty() == false) numbers.push(evaluator(top_pop(ops), top_pop(numbers), top_pop(numbers))); results.push_back(numbers.top()); } }
void currentAnalyzer::showReport() { if( _dataVector.size() > 0 ) { finalAnalyzer evaluator( &_dataVector ); result report; report.setReportHtml( evaluator.getHtmlReport() ); report.showFullScreen(); report.exec(); } }
void StyleBucketParameters::eachFilteredFeature(const Filter& filter, std::function<void (const GeometryTileFeature&, std::size_t index, const std::string& layerName)> function) { auto name = layer.getName(); for (std::size_t i = 0; !cancelled() && i < layer.featureCount(); i++) { auto feature = layer.getFeature(i); FilterEvaluator<GeometryTileFeatureExtractor> evaluator(*feature); if (!Filter::visit(filter, evaluator)) continue; function(*feature, i, name); } }
// Set all the initial values to NULL or zero, then allocate the space we'll // need (using the resize method). We do NOT call the initialize method at // this point - initialization must be done explicitly by the user of the // genome (eg when the population is created or reset). If we called the // initializer routine here then we could end up with multiple initializations // and/or calls to dummy initializers (for example when the genome is // created with a dummy initializer and the initializer is assigned later on). GA1DBinaryStringGenome:: GA1DBinaryStringGenome(unsigned int len, GAGenome::Evaluator f, void * u) : GABinaryString(len), GAGenome(DEFAULT_1DBINSTR_INITIALIZER, DEFAULT_1DBINSTR_MUTATOR, DEFAULT_1DBINSTR_COMPARATOR) { evaluator(f); userData(u); crossover(DEFAULT_1DBINSTR_CROSSOVER); // assign the default sexual crossover nx=minX=maxX=0; resize(len); }
/* ---------------------------------------------------------------------------- Genome class definition ---------------------------------------------------------------------------- */ GA2DBinaryStringGenome:: GA2DBinaryStringGenome(unsigned int width, unsigned int height, GAGenome::Evaluator f, void * u) : GABinaryString(width*height), GAGenome(DEFAULT_2DBINSTR_INITIALIZER, DEFAULT_2DBINSTR_MUTATOR, DEFAULT_2DBINSTR_COMPARATOR) { evaluator(f); userData(u); crossover(DEFAULT_2DBINSTR_CROSSOVER); nx=minX=maxX=0; ny=minY=maxY=0; resize(width, height); }
static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document, const String& as, const String& mimeType, const String& media, CrossOriginAttributeValue crossOrigin, LinkCaller caller, bool& errorOccurred, ViewportDescription* viewportDescription) { if (!document.loader() || !relAttribute.isLinkPreload()) return nullptr; UseCounter::count(document, UseCounter::LinkRelPreload); ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled()); if (!href.isValid() || href.isEmpty()) { document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, WarningMessageLevel, String("<link rel=preload> has an invalid `href` value"))); return nullptr; } if (!media.isEmpty()) { MediaValues* mediaValues = MediaValues::createDynamicIfFrameExists(document.frame()); if (viewportDescription) mediaValues->overrideViewportDimensions(viewportDescription->maxWidth.getFloatValue(), viewportDescription->maxHeight.getFloatValue()); // Preload only if media matches MediaQuerySet* mediaQueries = MediaQuerySet::create(media); MediaQueryEvaluator evaluator(*mediaValues); if (!evaluator.eval(mediaQueries)) return nullptr; } if (caller == LinkCalledFromHeader) UseCounter::count(document, UseCounter::LinkHeaderPreload); Resource::Type resourceType; if (!LinkLoader::getResourceTypeFromAsAttribute(as, resourceType)) { document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, WarningMessageLevel, String("<link rel=preload> must have a valid `as` value"))); errorOccurred = true; return nullptr; } if (!isSupportedType(resourceType, mimeType)) { document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, WarningMessageLevel, String("<link rel=preload> has an unsupported `type` value"))); return nullptr; } ResourceRequest resourceRequest(document.completeURL(href)); ResourceFetcher::determineRequestContext(resourceRequest, resourceType, false); FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link, document.encodingName()); if (crossOrigin != CrossOriginAttributeNotSet) linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), crossOrigin); Settings* settings = document.settings(); if (settings && settings->logPreload()) document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, DebugMessageLevel, String("Preload triggered for " + href.host() + href.path()))); linkRequest.setForPreload(true, monotonicallyIncreasingTime()); linkRequest.setLinkPreload(true); linkRequest.setPriority(document.fetcher()->loadPriority(resourceType, linkRequest)); return document.loader()->startPreload(resourceType, linkRequest); }