void update(Matrix<IndexType, ItorType>* m, ValueType* y, LabelType* is_observed, bool is_skip(ValueType, LabelType)) { // The last parameter is log(sigma) IndexType nfeature = m->getNFeature(); for(IndexType instance_id = 0;instance_id < m->getNInstance();instance_id++) { if (is_skip(y[instance_id], is_observed[instance_id])) continue; double pred = 0, g0 = 0, sigma = exp(ftprl->get_w(z[nfeature], n[nfeature])); #pragma omp parallel for reduction(+:pred) for(ItorType iter = m->getFeatureItorBegin(instance_id);iter < m->getFeatureItorEnd(instance_id); iter++) { IndexType feature_id = m->getFeatureId(iter); double value = m->getValue(iter); double w = ftprl->get_w(z[feature_id], n[feature_id]); pred += value * w; } double zscore = (pred - y[instance_id]) / sigma; double dzscore_dloss = (is_observed[instance_id] ? zscore : - exp(logdnorm(zscore) - logpnorm(zscore))); #pragma omp parallel for for(ItorType iter = m->getFeatureItorBegin(instance_id);iter < m->getFeatureItorEnd(instance_id); iter++) { IndexType feature_id = m->getFeatureId(iter); double value = m->getValue(iter); double g = dzscore_dloss * value / sigma; ftprl->update_zn(g, z + feature_id, n + feature_id); } { // update sigma IndexType &feature_id(nfeature); double g = - dzscore_dloss * zscore; ftprl->update_zn(g, z + feature_id, n + feature_id); } } }
bool binspector_parser_t::is_named_statement() { return is_invariant() || is_constant() || is_skip() || is_slot() || is_signal() || is_field(); // field should be last because atoms only // require an expression which most everything // falls into; the more explicit stuff should // come first. }
void remove_skip(goto_programt &goto_program) { typedef std::map<goto_programt::targett, goto_programt::targett> new_targetst; new_targetst new_targets; // remove skip statements for(goto_programt::instructionst::iterator it=goto_program.instructions.begin(); it!=goto_program.instructions.end();) { goto_programt::targett old_target=it; // for collecting labels std::list<irep_idt> labels; while(is_skip(it)) { // don't remove the last skip statement, // it could be a target if(it==--goto_program.instructions.end()) break; // save labels labels.splice(labels.end(), it->labels); it++; } goto_programt::targett new_target=it; // save labels it->labels.splice(it->labels.begin(), labels); if(new_target!=old_target) { while(new_target!=old_target) { // remember the old targets new_targets[old_target]=new_target; old_target=goto_program.instructions.erase(old_target); } } else it++; } // adjust gotos Forall_goto_program_instructions(i_it, goto_program) if(i_it->is_goto()) { for(goto_programt::instructiont::targetst::iterator t_it=i_it->targets.begin(); t_it!=i_it->targets.end(); t_it++) { new_targetst::const_iterator result=new_targets.find(*t_it); if(result!=new_targets.end()) *t_it=result->second; } } // remove the last skip statement unless it's a target goto_program.compute_incoming_edges(); if(!goto_program.instructions.empty() && is_skip(--goto_program.instructions.end()) && !goto_program.instructions.back().is_target()) goto_program.instructions.pop_back(); }