void Optimizer::CostExpression(std::shared_ptr<GroupExpression> gexpr) { LOG_TRACE("Costing expression of group %d with op %s", gexpr->GetGroupID(), gexpr->Op().name().c_str()); // Get required properties of children std::vector<PropertySet> required_child_properties = gexpr->Op().RequiredInputProperties(); std::vector<GroupID> child_group_ids = gexpr->GetChildGroupIDs(); if (required_child_properties.empty()) { required_child_properties.resize(child_group_ids.size(), PropertySet()); } std::vector<std::shared_ptr<GroupExpression>> best_child_expressions; std::vector<std::shared_ptr<Stats>> best_child_stats; std::vector<double> best_child_costs; for (size_t i = 0; i < child_group_ids.size(); ++i) { GroupID child_group_id = child_group_ids[i]; const PropertySet &input_properties = required_child_properties[i]; // Optimize child OptimizeGroup(child_group_id, input_properties); // Find best child expression std::shared_ptr<GroupExpression> best_expression = memo.GetGroupByID(child_group_id)->GetBestExpression(input_properties); // TODO(abpoms): we should allow for failure in the case where no expression // can provide the required properties assert(best_expression != nullptr); best_child_expressions.push_back(best_expression); best_child_stats.push_back(best_expression->GetStats()); best_child_costs.push_back(best_expression->GetCost()); } // Perform costing gexpr->DeriveStatsAndCost(best_child_stats, best_child_costs); }
std::shared_ptr<OpExpression> Optimizer::ChooseBestPlan( GroupID id, PropertySet requirements) { LOG_TRACE("Choosing best plan for group %d", id); Group *group = memo.GetGroupByID(id); std::shared_ptr<GroupExpression> gexpr = group->GetBestExpression(requirements); std::vector<GroupID> child_groups = gexpr->GetChildGroupIDs(); std::vector<PropertySet> required_input_props = gexpr->Op().RequiredInputProperties(); if (required_input_props.empty()) { required_input_props.resize(child_groups.size(), PropertySet()); } std::shared_ptr<OpExpression> op = std::make_shared<OpExpression>(gexpr->Op()); for (size_t i = 0; i < child_groups.size(); ++i) { std::shared_ptr<OpExpression> child_op = ChooseBestPlan(child_groups[i], required_input_props[i]); op->PushChild(child_op); } return op; }
Parameter::Parameter(Host *h, OfxParamHandle hdl) throw(Exception) : mHandle(hdl) { if (!h) { throw BadHandleError("ofx::Parameter::Parameter: invalid host"); } mSuite = h->parameterSuite(); OfxPropertySetHandle hProps; mSuite->paramGetPropertySet(mHandle, &hProps); mProps = PropertySet(h, hProps); }
BOOL COrnament::PositionChanged(CPropertyState* pState) const { COrnamentState* pCurrent = CurrentState(); COrnamentState* pCompare = StateType(pState); if (!PropertySet(pState)) { return FALSE; } return (pState == NULL) || (pCurrent->m_cpPosition != pCompare->m_cpPosition); }
ImageEffectDescriptor::ImageEffectDescriptor(ImageEffectHost *h, OfxImageEffectHandle hdl) throw(Exception) : mHandle(hdl), mHost(h) { if (!h) { throw BadHandleError("ofx::ImageEffectDescriptor::ImageEffectDescriptor: invalid host"); } OfxPropertySetHandle hProps; mHost->imageEffectSuite()->getPropertySet(mHandle, &hProps); mProps = PropertySet(mHost, hProps); OfxParamSetHandle hParams; mHost->imageEffectSuite()->getParamSet(mHandle, &hParams); mParams = ParameterSetDescriptor(mHost, hParams); }
BOOL COrnament::SizeChanged(CPropertyState* pState) const { COrnamentState* pCurrent = CurrentState(); COrnamentState* pCompare = StateType(pState); if (!PropertySet(pState)) { return FALSE; } return (pState == NULL) || (pCurrent->m_dwStyle != pCompare->m_dwStyle) || (pCurrent->m_czExtent != pCompare->m_czExtent); }
void ImageEffect::handle(OfxImageEffectHandle handle) throw(Exception) { if (mHandle != 0) { gEffects.erase(gEffects.find(mHandle)); gParamSetEffects.erase(gParamSetEffects.find(mParams.handle())); } if (!mHost) { throw BadHandleError("ofx::ImageEffet::setHandle: invalid host"); } mHandle = handle; if (mHandle != 0) { OfxPropertySetHandle hProps; mHost->imageEffectSuite()->getPropertySet(mHandle, &hProps); mProps = PropertySet(mHost, hProps); OfxParamSetHandle hParams; mHost->imageEffectSuite()->getParamSet(mHandle, &hParams); mParams = ParameterSet(mHost, hParams); gParamSetEffects[hParams] = this; gEffects[mHandle] = this; } }
PropertySet Optimizer::GetQueryTreeRequiredProperties( std::shared_ptr<Select> tree) { (void)tree; return PropertySet(); }
GameRunningState2::GameRunningState2(GameApp* app) : GameState(app) , m_tmap(0) , m_gameObject(0) , m_pongComponents(0) , m_score1(0) , m_score2(0) { esLogMessage("Initializing secret level!"); m_tmap = new TmxMap(); m_pongComponents = new PongGameComponents(m_tmap); bool load = m_tmap->loadMapFile("assets/level_pong.tmx", m_pongComponents); if (load) { m_tmap->getCamera()->setPosition(vec2(m_tmap->getWidth()/2.22f, m_tmap->getHeight()/2.2f)); } // Player 1 score m_scoreFont1 = static_cast<GameObject*>(m_pongComponents->createNewEntity(m_pongComponents, "Score", nullptr, PropertySet())); m_scoreFont1->getComponent<TextComponent>()->getText()->setText(std::to_string(m_score1)); m_scoreFont1->getComponent<TextComponent>()->getText()->setColor(255, 255, 255, 1); m_scoreFont1->setSize(vec2(64.0f, 64.0f) * 20.0f); m_scoreFont1->setPosition(7.0f, 6.0f); // Player 2 score m_scoreFont2 = static_cast<GameObject*>(m_pongComponents->createNewEntity(m_pongComponents, "Score", nullptr, PropertySet())); m_scoreFont2->getComponent<TextComponent>()->getText()->setText(std::to_string(m_score2)); m_scoreFont2->getComponent<TextComponent>()->getText()->setColor(255, 255, 255, 1); m_scoreFont2->setSize(vec2(64.0f, 64.0f) * 20.0f); m_scoreFont2->setPosition(15.0f, 6.0f); // You only need 5 points to win // Player 1 win text m_p1Win = static_cast<GameObject*>(m_pongComponents->createNewEntity(m_pongComponents, "Score", nullptr, PropertySet())); // Player 2 win text m_p2Win = static_cast<GameObject*>(m_pongComponents->createNewEntity(m_pongComponents, "Score", nullptr, PropertySet())); }
Real MR::calcCavityCorrelations() { Real md = 0.0; for( size_t i = 0; i < nrVars(); i++ ) { vector<Factor> pairq; if( props.inits == Properties::InitType::EXACT ) { JTree jtcav(*this, PropertySet()("updates", string("HUGIN"))("verbose", (size_t)0) ); jtcav.makeCavity( i ); pairq = calcPairBeliefs( jtcav, delta(i), false, true ); } else if( props.inits == Properties::InitType::CLAMPING ) { BP bpcav(*this, PropertySet()("updates", string("SEQMAX"))("tol", (Real)1.0e-9)("maxiter", (size_t)10000)("verbose", (size_t)0)("logdomain", false)); bpcav.makeCavity( i ); pairq = calcPairBeliefs( bpcav, delta(i), false, true ); md = std::max( md, bpcav.maxDiff() ); } else if( props.inits == Properties::InitType::RESPPROP ) { BP bpcav(*this, PropertySet()("updates", string("SEQMAX"))("tol", (Real)1.0e-9)("maxiter", (size_t)10000)("verbose", (size_t)0)("logdomain", false)); bpcav.makeCavity( i ); bpcav.makeCavity( i ); bpcav.init(); bpcav.run(); BBP bbp( &bpcav, PropertySet()("verbose",(size_t)0)("tol",(Real)1.0e-9)("maxiter",(size_t)10000)("damping",(Real)0.0)("updates",string("SEQ_MAX")) ); bforeach( const Neighbor &j, G.nb(i) ) { // Create weights for magnetization of some spin Prob p( 2, 0.0 ); p.set( 0, -1.0 ); p.set( 1, 1.0 ); // BBP cost function would be the magnetization of spin j vector<Prob> b1_adj; b1_adj.reserve( nrVars() ); for( size_t l = 0; l < nrVars(); l++ ) if( l == j ) b1_adj.push_back( p ); else b1_adj.push_back( Prob( 2, 0.0 ) ); bbp.init_V( b1_adj ); // run BBP to estimate adjoints bbp.run(); bforeach( const Neighbor &k, G.nb(i) ) { if( k != j ) cors[i][j.iter][k.iter] = (bbp.adj_psi_V(k)[1] - bbp.adj_psi_V(k)[0]); else cors[i][j.iter][k.iter] = 0.0; } } } if( props.inits != Properties::InitType::RESPPROP ) { for( size_t jk = 0; jk < pairq.size(); jk++ ) { VarSet::const_iterator kit = pairq[jk].vars().begin(); size_t j = findVar( *(kit) ); size_t k = findVar( *(++kit) ); pairq[jk].normalize(); Real cor = (pairq[jk][3] - pairq[jk][2] - pairq[jk][1] + pairq[jk][0]) - (pairq[jk][3] + pairq[jk][2] - pairq[jk][1] - pairq[jk][0]) * (pairq[jk][3] - pairq[jk][2] + pairq[jk][1] - pairq[jk][0]); size_t _j = G.findNb(i,j); size_t _k = G.findNb(i,k); cors[i][_j][_k] = cor; cors[i][_k][_j] = cor; } } }