void TwoStageDynamicBayesianNetwork:: ScopeBackup( const Scope & stateScope, const Scope & agentScope, Scope & X, Scope & A) const { //first we compute the 'closure' of the NS state factors Y and //observations O. I.e., within stage connections can grow the set //of Y and O that need to be considered: Scope Y = stateScope; Scope O = agentScope; ComputeWithinNextStageClosure(Y,O); X.clear(); A.clear(); //Next we do the backup of the Ys and Os for( Scope::iterator y_it = Y.begin(); y_it != Y.end(); y_it++) { Index yI = *y_it; X.Insert( _m_XSoI_Y.at(yI) ); A.Insert( _m_ASoI_Y.at(yI) ); } for( Scope::iterator o_it = O.begin(); o_it != O.end(); o_it++) { X.Insert( _m_XSoI_O.at(*o_it) ); A.Insert( _m_ASoI_O.at(*o_it) ); } X.Sort(); A.Sort(); return; }
void TwoStageDynamicBayesianNetwork:: ComputeWithinNextStageClosure(Scope& Y, Scope& O) const { bool converged = true; do{ converged = true; //check all Y for non-included Y dependencies Scope::const_iterator s_it = Y.begin(); Scope::const_iterator s_last = Y.end(); while(s_it != s_last) { Index yI = *s_it; const Scope& y_YSoI = _m_YSoI_Y.at(yI); for(Scope::const_iterator oy_it = y_YSoI.begin(); oy_it != y_YSoI.end(); oy_it++) //yI has other Y (oyI = *oy_it) that point to it... //let's see if they are in Y already. if(! Y.Contains( *oy_it ) ) { converged = false; Y.Insert(*oy_it); } s_it++; } //check all O for non-included O and Y dependencies Scope::const_iterator o_it = O.begin(); Scope::const_iterator o_last = O.end(); while(o_it != o_last) { Index oI = *o_it; const Scope& o_YSoI = _m_YSoI_O.at(oI); for(Scope::const_iterator oy_it = o_YSoI.begin(); oy_it != o_YSoI.end(); oy_it++) //oI has other Y (oyI = *oy_it) that point to it... //let's see if they are in Y already. if(! Y.Contains( *oy_it ) ) { converged = false; Y.Insert(*oy_it); } const Scope& o_OSoI = _m_OSoI_O.at(oI); for(Scope::const_iterator oo_it = o_OSoI.begin(); oo_it != o_OSoI.end(); oo_it++) //oI has other O (ooI = *oo_it) that point to it... //let's see if they are in O already. if(! O.Contains( *oo_it ) ) { converged = false; O.Insert(*oo_it); } o_it++; } }while (! converged ); }
/** * Remove annotation classes that are marked explicitly with a removable * annotation (specified as "kill_annos" in config). Facebook uses these to * remove DI binding annotations. */ void kill_annotation_classes( Scope& scope, const std::unordered_set<DexType*>& kill_annos ) { // Determine which annotation classes are removable. class_set_t bannotations; for (auto clazz : scope) { if (!(clazz->get_access() & DexAccessFlags::ACC_ANNOTATION)) continue; auto aset = clazz->get_anno_set(); if (aset == nullptr) continue; auto& annos = aset->get_annotations(); for (auto anno : annos) { if (kill_annos.count(anno->type())) { bannotations.insert(clazz); TRACE(CLASSKILL, 5, "removable annotation class %s\n", SHOW(clazz->get_type())); } } } // Annotation classes referenced explicitly can't be removed. walk_code( scope, [](DexMethod*) { return true; }, [&](DexMethod* meth, DexCode* code) { auto opcodes = code->get_instructions(); for (const auto& opcode : opcodes) { if (opcode->has_types()) { auto typeop = static_cast<DexOpcodeType*>(opcode); auto dtexclude = typeop->get_type(); DexClass* exclude = type_class(dtexclude); if (exclude != nullptr && bannotations.count(exclude)) { bannotations.erase(exclude); } } } }); // Do the removal. int annotations_removed_count = 0; if (bannotations.size()) { // We have some annotations we can kill. First let's clear all annotation // references to the classes. annotations_removed_count = clear_annotation_references(scope, bannotations); scope.erase( std::remove_if( scope.begin(), scope.end(), [&](DexClass* cls) { return bannotations.count(cls); }), scope.end()); } TRACE(CLASSKILL, 1, "Annotation classes removed %lu\n", bannotations.size()); TRACE(CLASSKILL, 1, "Method param annotations removed %d\n", annotations_removed_count); }
void Sonogram::analyze(QPainter& p, const Scope& s, bool new_frame) { if (!new_frame) { p.drawPixmap(0, 0, canvas_); return; } int x = width() - 1; QColor c; QPainter canvas_painter(&canvas_); canvas_painter.drawPixmap(0, 0, canvas_, 1, 0, x, -1); Scope::const_iterator it = s.begin(), end = s.end(); for (int y = height() - 1; y;) { if (it >= end || *it < .005) c = palette().color(QPalette::Background); else if (*it < .05) c.setHsv(95, 255, 255 - static_cast<int>(*it * 4000.0)); else if (*it < 1.0) c.setHsv(95 - static_cast<int>(*it * 90.0), 255, 255); else c = Qt::red; canvas_painter.setPen(c); canvas_painter.drawPoint(x, y--); if (it < end) ++it; } canvas_painter.end(); p.drawPixmap(0, 0, canvas_); }
XPathValue lookup(const Scope& scope, const string_type& name) const { typename Scope::const_iterator i = scope.find(name); if(i == scope.end()) return XPathValue(0); return i->second->value(); } // lookup
void Sonogram::analyze(QPainter& p, const Scope& s, bool new_frame) { if (!new_frame) { p.drawPixmap(0, 0, canvas_); return; } int x = width() - 1; QColor c; QPainter canvas_painter(&canvas_); canvas_painter.drawPixmap(0, 0, canvas_, 1, 0, x, -1); Scope::const_iterator it = s.begin(), end = s.end(); if (scope_size_ != s.size()) { scope_size_ = s.size(); updateBandSize(scope_size_); } if (psychedelic_enabled_) { c = getPsychedelicColor(s, 20, 100); for (int y = height() - 1; y;) { if (it >= end || *it < .005) { c = palette().color(QPalette::Background); } else if (*it < .05) { c.setHsv(c.hue(), c.saturation(), 255 - static_cast<int>(*it * 4000.0)); } else if (*it < 1.0) { c.setHsv((c.hue() + static_cast<int>(*it * 90.0)) % 255, 255, 255); } else { c = getPsychedelicColor(s, 10, 50); } canvas_painter.setPen(c); canvas_painter.drawPoint(x, y--); if (it < end) ++it; } } else { for (int y = height() - 1; y;) { if (it >= end || *it < .005) c = palette().color(QPalette::Background); else if (*it < .05) c.setHsv(95, 255, 255 - static_cast<int>(*it * 4000.0)); else if (*it < 1.0) c.setHsv(95 - static_cast<int>(*it * 90.0), 255, 255); else c = Qt::red; canvas_painter.setPen(c); canvas_painter.drawPoint(x, y--); if (it < end) ++it; } } canvas_painter.end(); p.drawPixmap(0, 0, canvas_); }
// Return the declaration associated with the name n, // or nullptr if no such name exists. Expr* lookup(Name* n) { Scope* s = current_scope(); while (s) { auto iter = s->find(n); if (iter != s->end()) return iter->second; s = s->parent; } return nullptr; }
bool FactoredDecPOMDPDiscrete:: ConsistentVectorsOnSpecifiedScopes( const std::vector<Index>& v1, const Scope& scope1, const std::vector<Index>& v2, const Scope& scope2) { Scope::const_iterator s2_it = scope2.begin(); Scope::const_iterator s2_last = scope2.end(); Index v2_I = 0; while(s2_it != s2_last) { //check that v1 specifies the same value for variable *s2_it Index varI = *s2_it; Index pos_in_v1 = scope1.GetPositionForIndex(varI); if(v1[pos_in_v1] != v2[v2_I] ) return false; s2_it++; v2_I++; } return true; }