/* ************************************************************************* */ VectorValues GaussianConditional::solveOtherRHS( const VectorValues& parents, const VectorValues& rhs) const { // Concatenate all vector values that correspond to parent variables Vector xS = parents.vector(FastVector<Key>(beginParents(), endParents())); // Instead of updating getb(), update the right-hand-side from the given rhs const Vector rhsR = rhs.vector(FastVector<Key>(beginFrontals(), endFrontals())); xS = rhsR - get_S() * xS; // Solve Matrix Vector soln = get_R().triangularView<Eigen::Upper>().solve(xS); // Scale by sigmas if(model_) soln.array() *= model_->sigmas().array(); // Insert solution into a VectorValues VectorValues result; DenseIndex vectorPosition = 0; for(const_iterator frontal = beginFrontals(); frontal != endFrontals(); ++frontal) { result.insert(*frontal, soln.segment(vectorPosition, getDim(frontal))); vectorPosition += getDim(frontal); } return result; }
/* ************************************************************************* */ VectorValues GaussianConditional::solve(const VectorValues& x) const { // Concatenate all vector values that correspond to parent variables const Vector xS = x.vector(FastVector<Key>(beginParents(), endParents())); // Update right-hand-side const Vector rhs = get_d() - get_S() * xS; // Solve matrix const Vector solution = get_R().triangularView<Eigen::Upper>().solve(rhs); // Check for indeterminant solution if (solution.hasNaN()) { throw IndeterminantLinearSystemException(keys().front()); } // Insert solution into a VectorValues VectorValues result; DenseIndex vectorPosition = 0; for (const_iterator frontal = beginFrontals(); frontal != endFrontals(); ++frontal) { result.insert(*frontal, solution.segment(vectorPosition, getDim(frontal))); vectorPosition += getDim(frontal); } return result; }
FloatsList GaussianProcessInterpolation::get_data_variance() const { FloatsList ret; IMP_Eigen::MatrixXd S(get_S()); for (unsigned i = 0; i < M_; i++) { Floats val; for (unsigned j = 0; j < M_; j++) val.push_back(S(i, j)); ret.push_back(val); } return ret; }
IMP_Eigen::MatrixXd GaussianProcessInterpolation::get_Omega_derivative( unsigned particle) const { const_cast<GaussianProcessInterpolation *>(this)->update_flags_covariance(); // Omega = W + sigma*S/n_obs if (particle == 0) { // sigma return IMP_Eigen::MatrixXd(get_S()) / n_obs_; } else { return covariance_function_->get_derivative_matrix(particle - 1, x_); } }
double Bchart:: parse() { alreadyPopedNum = 0; SentRepIter sri(sentence_); bool haveS = false; int locTimeout = ruleiCountTimeout_; int count = 0; for (;; count ++) { //check(); if( ruleiCounts_ > locTimeout ) { break; } if(get_S() && !haveS) { // once we have found a parse, the total edes is set to edges * 3.5; haveS = true; if(printDebug(10)) cerr << "Found S " << popedEdgeCount_ << endl; popedEdgeCountAtS_ = popedEdgeCount_; totEdgeCountAtS_ = ruleiCounts_; int newTime = (int)(ruleiCounts_ * timeFactor); if(newTime < ruleiCountTimeout_) locTimeout = newTime; } // We keep track of number of ruleis to decide when time out on parsing.; /* get best thing off of keylist */ Edge* edge = heap->pop(); if (!edge) { break; } int stus = edge->status(); int cD = curDemerits_[edge->start()][edge->loc()]; if(edge->demerits() < cD - 5 && !haveS) { edge->demerits() = cD; edge->setmerit(); heap->insert(edge); continue; } if(alreadyPopedNum >= 400000) { cerr << "alreadyPoped got too large" << endl; break; } if(printDebug() > 10) { cerr << popedEdgeCount_ << "\tPop"; if(stus == 0) cerr << "< "; else if(stus == 2) cerr << ". "; else cerr << "> "; cerr << *edge << "\t" << edge->prob() << "\t" << edge->merit(); cerr << endl; } popedEdgeCount_++; alreadyPoped[alreadyPopedNum++] = edge; if(!haveS) addToDemerits(edge); /* and add it to chart */ //heap->check(); switch (stus) { case 0 : add_edge(edge, 0); break; //0 => continuing left; case 1 : add_edge(edge, 1); break; //1 => continung right; case 2 : addFinishedEdge(edge); } } /* at this point we are done looking for edges etc. */ Item *snode = get_S(); /* No "S" node means the sentence was unparsable. */ if (!snode) return badParse; double ans = snode->prob(); if (ans <= 0.0L) error("zero probability parse?"); /* ans = -log2(ans); if (ans == quiet_nan(0L)) error("log returned quiet_nan()"); */ static double nat_log_2 = log( 2.0 ); ans = -log( ans )/ nat_log_2; crossEntropy_ = ans; return ans; }
void GaussianProcessInterpolation::compute_Omega() { // sigma_val_ is up-to-date because update_flags_covariance was just called Omega_ = get_W() + sigma_val_ * IMP_Eigen::MatrixXd(get_S()) / n_obs_; }
ada::data_t fill_data(std::string const& bada_path, std::string const& aircraft_kind ) { ada::data_t ac_settings; create_proxy_fn_t create_proxy_fn = reinterpret_cast<create_proxy_fn_t> (lib_loader().get_symbol(BADA_DLL,"create_proxy")); if (create_proxy_fn) { auto proxy = create_proxy_fn(bada_path); //auto proxy = bada::create_proxy(bada_path); auto syn_data = proxy->get_synonim_data(aircraft_kind) ; if(!syn_data) syn_data = proxy->get_synonim_data("A319") ; auto air_data = proxy->get_aircraft_data(syn_data->getSynonim()) ; auto air_global_data = proxy->get_global_data() ; ac_settings.base_model = syn_data->getSynonim(); ac_settings.manufacturer = syn_data->getManufacturer(); ac_settings.model_name = syn_data->getModelName(); ac_settings.S = air_data->get_S(); ac_settings.span = air_data->get_span(); ac_settings.length = air_data->get_length(); ac_settings.engine = air_data->getEngineType(); ac_settings.turbulence = air_data->getWakeCategory(); ac_settings.cd_0_cruise = air_data->get_Cd0_cr(); ac_settings.cd_2_cruise = air_data->get_Cd2_cr(); ac_settings.cd_0_approach = air_data->get_Cd0_ap(); ac_settings.cd_2_approach = air_data->get_Cd2_ap(); ac_settings.cd_0_landing = air_data->get_Cd0_ld(); ac_settings.cd_0_landing_gear = air_data->get_Cd0_ldg(); ac_settings.cd_2_landing = air_data->get_Cd2_ld(); ac_settings.cf_1 = air_data->get_Cf_1(); ac_settings.cf_2 = air_data->get_Cf_2() * cg::kt2mps(); ac_settings.cf_3 = air_data->get_Cf_3() / 60.; ac_settings.cf_4 = air_data->get_Cf_4() * cg::feet2meter(); ac_settings.cf_cruise = air_data->get_Cfr(); switch(ac_settings.engine) { case bada::jet: ac_settings.cf_1 /= (60. * 1000.); break; case bada::turboprop: ac_settings.cf_1 /= (60. * 1000. * cg::kt2mps()); break; case bada::piston: ac_settings.cf_1 /= 60.; break; } ac_settings.nominal_ba_to_ld = 15.; // TODO: make difference to military objects ac_settings.nominal_ba = 35.; ac_settings.max_ba_to_ld = 25.; ac_settings.max_ba_hold = 35.; ac_settings.max_ba = 45.; ac_settings.max_operating_height = air_data->get_hmo() * cg::feet2meter(); ac_settings.max_height = air_data->get_hmax() * cg::feet2meter(); ac_settings.temperature_gradient = air_data->get_Gt() * cg::feet2meter(); ac_settings.mass_gradient = air_data->get_Gw() * cg::feet2meter(); ac_settings.max_mass = air_data->get_m_max() * 1000; ac_settings.min_mass = air_data->get_m_min() * 1000; ac_settings.max_payload_mass = air_data->get_m_pyld() * 1000; ac_settings.ref_mass = air_data->get_m_ref() * 1000; if (ac_settings.engine == bada::jet ||ac_settings.engine == bada::piston) ac_settings.ct_1 = air_data->get_Ctc_1(); else // turboprop ac_settings.ct_1 = air_data->get_Ctc_1() * cg::kt2mps(); ac_settings.ct_2 = air_data->get_Ctc_2() * cg::feet2meter(); if (ac_settings.engine == bada::jet) ac_settings.ct_3 = air_data->get_Ctc_3() / cg::sqr(cg::feet2meter()); else if (ac_settings.engine == bada::turboprop) ac_settings.ct_3 = air_data->get_Ctc_3(); else // piston ac_settings.ct_3 = air_data->get_Ctc_3() * cg::kt2mps(); ac_settings.ct_4 = air_data->get_Ctc_4(); ac_settings.ct_5 = air_data->get_Ctc_5(); ac_settings.ct_descent_low = air_data->get_Ct_des_low(); ac_settings.descent_height_level = air_data->get_Hp_des() * cg::feet2meter(); ac_settings.ct_descent_high = air_data->get_Ct_des_high(); ac_settings.ct_descent_approach = air_data->get_Ct_des_app(); ac_settings.ct_descent_landing = air_data->get_Ct_des_ld(); ac_settings.V_1[fms::climb_stage] = air_data->getDataCLS().getStandardCAS().first * cg::kt2mps(); ac_settings.V_1[fms::cruise_stage] = air_data->getDataCRS().getStandardCAS().first * cg::kt2mps(); ac_settings.V_1[fms::descent_stage] = air_data->getDataDS().getStandardCAS().first * cg::kt2mps(); ac_settings.V_2[fms::climb_stage] = air_data->getDataCLS().getStandardCAS().second * cg::kt2mps(); ac_settings.V_2[fms::cruise_stage] = air_data->getDataCRS().getStandardCAS().second * cg::kt2mps(); ac_settings.V_2[fms::descent_stage] = air_data->getDataDS().getStandardCAS().second * cg::kt2mps(); ac_settings.M[fms::climb_stage] = air_data->getDataCLS().getMach(); ac_settings.M[fms::cruise_stage] = air_data->getDataCRS().getMach(); ac_settings.M[fms::descent_stage] = air_data->getDataDS().getMach(); // jet ac_settings.v_d_cl[0] = 5 * cg::kt2mps(); ac_settings.v_d_cl[1] = 10 * cg::kt2mps(); ac_settings.v_d_cl[2] = 30 * cg::kt2mps(); ac_settings.v_d_cl[3] = 60 * cg::kt2mps(); ac_settings.v_d_cl[4] = 80 * cg::kt2mps(); // turboprop/piston ac_settings.v_d_cl[5] = 20 * cg::kt2mps(); ac_settings.v_d_cl[6] = 30 * cg::kt2mps(); ac_settings.v_d_cl[7] = 35 * cg::kt2mps(); // jet/turboprop ac_settings.v_d_des[0] = 5 * cg::kt2mps(); ac_settings.v_d_des[1] = 10 * cg::kt2mps(); ac_settings.v_d_des[2] = 20 * cg::kt2mps(); ac_settings.v_d_des[3] = 50 * cg::kt2mps(); // piston ac_settings.v_d_des[4] = 5 * cg::kt2mps(); ac_settings.v_d_des[5] = 10 * cg::kt2mps(); ac_settings.v_d_des[6] = 20 * cg::kt2mps(); ac_settings.v_stall_to = air_data->get_Vstall_to() * cg::kt2mps(); ac_settings.v_stall_ic = air_data->get_Vstall_ic() * cg::kt2mps(); ac_settings.v_stall_cr = air_data->get_Vstall_cr() * cg::kt2mps(); ac_settings.v_stall_ap = air_data->get_Vstall_ap() * cg::kt2mps(); ac_settings.v_stall_ld = air_data->get_Vstall_ld() * cg::kt2mps(); ac_settings.v_rw_backtrack = 35 * cg::kt2mps(); ac_settings.v_taxi = 15 * cg::kt2mps(); ac_settings.v_apron = 10 * cg::kt2mps(); ac_settings.v_gate = 5 * cg::kt2mps(); ac_settings.c_v_min = air_global_data->getCVmin(0).second; ac_settings.c_v_min_to = 1.2; ac_settings.h_descent = air_data->get_Hp_des() * cg::feet2meter(); ac_settings.h_max_to = 400 * cg::feet2meter(); ac_settings.h_max_ic = 2000 * cg::feet2meter(); ac_settings.h_max_ap = 8000 * cg::feet2meter(); ac_settings.h_max_ld = 3000 * cg::feet2meter(); ac_settings.takeoff_length = 0.75 * air_data->get_TOL(); ac_settings.landing_length = air_data->get_LDL(); ac_settings.max_cas = air_data->get_Vmo() * cg::kt2mps(); ac_settings.max_mach = air_data->get_Mmo(); } return ac_settings; }
void ChartBase:: set_Alphas() { Item *snode = get_S(); double tempAlpha[400]; //400 has no particular meaning, just large enough. if( !snode || snode->prob() == 0.0 ) { warn( "estimating the counts on a zero-probability sentence" ); return; } double sAlpha = 1.0/snode->prob(); snode->poutside() = sAlpha; /* for each position in the 2D chart, starting at top*/ /* look at every bucket of length j */ for (int j = wrd_count_-1 ; j >= 0 ; j--) { for (int i = 0 ; i <= wrd_count_ - j ; i++) { Items il = regs[j][i]; list<Item*>::iterator ili = il.begin(); Item* itm; for(; ili != il.end(); ili++ ) { itm = *ili; if(itm != snode) itm->poutside() = 0; //init outside probs to 0; } bool valuesChanging = true; /* do alpha calulcations until values settle down */ ili = il.begin(); while(valuesChanging) { valuesChanging = false; int tempPos = 0; //position in tempAlpha; ili = il.begin(); for(; ili != il.end(); ili++ ) { itm = *ili; if(itm == snode) continue; double itmalpha = 0; NeedmeIter nmi(itm); Edge* e; while( nmi.next(e) ) { const Item* lhsItem = e->finishedParent(); if(lhsItem) itmalpha += lhsItem->poutside() * e->prob(); } assert(tempPos < 400); double val = itmalpha/itm->prob(); tempAlpha[tempPos++] = val; } /* at this point the new alpha values are stored in tempAlpha */ int temppos = 0; ili = il.begin(); for(; ili != il.end(); ili++ ) { itm = *ili; if(itm == snode) continue; /* the start symbol for the entire sentence has poutside =1*/ if(i == 0 && j ==wrd_count_-1 && itm->term()->name() == "S1") itm->poutside() = sAlpha; else { double oOutside = itm->poutside(); double nOutside = tempAlpha[temppos]; if(nOutside == 0) { if(oOutside != 0) error("Alpha went down"); } else if(oOutside/nOutside < .95) { itm->poutside() = nOutside; valuesChanging = true; //cerr << "alpha*beta " << *itm << " = " //<< (itm->poutside() * itm->prob()) << endl; } } temppos++; } if(temppos != tempPos) { cerr << "temppos = " << temppos << " and tempPos = " << tempPos << " "; error("Funnly situation in setAlphas"); } } } } }