size_t integrate_adaptive( Stepper stepper , System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer , dense_output_stepper_tag ) { typename odeint::unwrap_reference< Observer >::type &obs = observer; typename odeint::unwrap_reference< Stepper >::type &st = stepper; size_t count = 0; st.initialize( start_state , start_time , dt ); while( less_with_sign( st.current_time() , end_time , st.current_time_step() ) ) { while( less_eq_with_sign( static_cast<Time>(st.current_time() + st.current_time_step()) , end_time , st.current_time_step() ) ) { //make sure we don't go beyond the end_time obs( st.current_state() , st.current_time() ); st.do_step( system ); ++count; } // calculate time step to arrive exactly at end time st.initialize( st.current_state() , st.current_time() , end_time - st.current_time() ); } obs( st.current_state() , st.current_time() ); // overwrite start_state with the final point boost::numeric::odeint::copy( st.current_state() , start_state ); return count; }
size_t integrate_const( Stepper stepper , System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer , stepper_tag ) { typename odeint::unwrap_reference< Observer >::type &obs = observer; typename odeint::unwrap_reference< Stepper >::type &st = stepper; Time time = start_time; int step = 0; // cast time+dt explicitely in case of expression templates (e.g. multiprecision) while( less_eq_with_sign( static_cast<Time>(time+dt) , end_time , dt ) ) { obs( start_state , time ); st.do_step( system , start_state , time , dt ); // direct computation of the time avoids error propagation happening when using time += dt // we need clumsy type analysis to get boost units working here ++step; time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * dt; } obs( start_state , time ); return step; }
void cons(){ int i,j,k; pos t,tn,t0,t1,t2,t3; for(i=0;i<MN;i++)for(j=0;j<MN;j++){ t.y=i;t.x=j; //printf("%c ",frt[i][j]); switch(frt[i][j]){ case 'F': case 'C':{ if(frt[i][j]=='F'){frm.y=i;frm.x=j;} if(frt[i][j]=='C'){cow.y=i;cow.x=j;} } case '.':{ for(k=0;k<4;k++){ t0=nbr(t,k); t1=nbr(t,(k+1)%4); t2=nbr(t,(k+2)%4); t3=nbr(t,(k+3)%4); if(!obs(t2)) edg[nod[i][j][k]][nod[t2.y][t2.x][k]]=1; if(obs(t2)&&!obs(t3)) edg[nod[i][j][k]][nod[t3.y][t3.x][(k+1)%4]]=2; if(obs(t2)&&obs(t3)&&!obs(t0)) edg[nod[i][j][k]][nod[t0.y][t0.x][(k+2)%4]]=3; if(obs(t2)&&obs(t3)&&obs(t0)&&!obs(t1)) edg[nod[i][j][k]][nod[t1.y][t1.x][(k+3)%4]]=4; } break; } case '*':break; }; } }
size_t integrate_adaptive( Stepper stepper , System system , State &start_state , Time &start_time , Time end_time , Time &dt , Observer observer , controlled_stepper_tag ) { typename odeint::unwrap_reference< Observer >::type &obs = observer; typename odeint::unwrap_reference< Stepper >::type &st = stepper; const size_t max_attempts = 1000; const char *error_string = "Integrate adaptive : Maximal number of iterations reached. A step size could not be found."; size_t count = 0; while( less_with_sign( start_time , end_time , dt ) ) { obs( start_state , start_time ); if( less_with_sign( end_time , start_time + dt , dt ) ) { dt = end_time - start_time; } size_t trials = 0; controlled_step_result res = success; do { res = st.try_step( system , start_state , start_time , dt ); ++trials; } while( ( res == fail ) && ( trials < max_attempts ) ); if( trials == max_attempts ) throw std::overflow_error( error_string ); ++count; } obs( start_state , start_time ); return count; }
size_t integrate_const( Stepper stepper , System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer , controlled_stepper_tag ) { typename odeint::unwrap_reference< Observer >::type &obs = observer; Time time = start_time; const Time time_step = dt; int real_steps = 0; int step = 0; while( less_eq_with_sign( static_cast<Time>(time+time_step) , end_time , dt ) ) { obs( start_state , time ); real_steps += detail::integrate_adaptive( stepper , system , start_state , time , time+time_step , dt , null_observer() , controlled_stepper_tag() ); // direct computation of the time avoids error propagation happening when using time += dt // we need clumsy type analysis to get boost units working here step++; time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * time_step; } obs( start_state , time ); return real_steps; }
void CHemlockLooperModel::AddDailyResult(const StringVector& header, const StringVector& data) { enum TInputAllStage{ E_NAME, E_ID, E_YEAR, E_MONTH, E_DAY, E_JDAY, E_CUMUL_L1, E_CUMUL_L2, E_CUMUL_L3, E_CUMUL_L4, E_CUMUL_PUPA, E_CUMUL_ADULT, NB_INPUT, NB_COLUMN = NB_INPUT + 7 }; enum TInputPupasion{ P_NAME, P_ID, P_YEAR, P_MONTH, P_DAY, P_NB_DAYS, P_N, NB_INPUT_PUPAISON }; CTRef TRef(ToInt(data[E_YEAR]), ToSizeT(data[E_MONTH]) - 1, ToSizeT(data[E_DAY]) - 1); if (header.size() == NB_COLUMN) { std::vector<double> obs(NB_INPUT - E_CUMUL_L1); for (size_t i = 0; i < obs.size(); i++) obs[i] = ToDouble(data[E_CUMUL_L1 + i]); m_SAResult.push_back(CSAResult(TRef, obs)); } else if (header.size() == NB_INPUT_PUPAISON) { std::vector<double> obs(2); obs[PUP_NB_DAYS] = ToDouble(data[P_NB_DAYS]); obs[PUP_N] = ToDouble(data[P_N]); m_SAResult.push_back(CSAResult(TRef, obs)); } }
size_t integrate_adaptive( Stepper stepper , System system , State &start_state , Time &start_time , Time end_time , Time &dt , Observer observer , controlled_stepper_tag ) { typename odeint::unwrap_reference< Observer >::type &obs = observer; typename odeint::unwrap_reference< Stepper >::type &st = stepper; failed_step_checker fail_checker; // to throw a runtime_error if step size adjustment fails size_t count = 0; while( less_with_sign( start_time , end_time , dt ) ) { obs( start_state , start_time ); if( less_with_sign( end_time , static_cast<Time>(start_time + dt) , dt ) ) { dt = end_time - start_time; } controlled_step_result res; do { res = st.try_step( system , start_state , start_time , dt ); fail_checker(); // check number of failed steps } while( res == fail ); fail_checker.reset(); // if we reach here, the step was successful -> reset fail checker ++count; } obs( start_state , start_time ); return count; }
Type objective_function<Type>::operator() () { DATA_MATRIX(obs); DATA_MATRIX(coord); DATA_VECTOR(covObs); DATA_INTEGER(p); DATA_VECTOR(h); PARAMETER(logObsSd); PARAMETER(logObsTSd); PARAMETER(logStatSd); PARAMETER_MATRIX(x); Type nll = 0.0; covafill<Type> cf(coord,covObs,h,p); // Contribution from states for(int i = 1; i < x.cols(); ++i) { nll -= dnorm(x(0,i), x(0,i-1), exp(logStatSd),true); nll -= dnorm(x(1,i), x(1,i-1), exp(logStatSd),true); } // contribution from observations for(int i = 0; i < obs.cols(); ++i) { nll -= dnorm(obs(0,i), x(0,i), exp(logObsSd),true); nll -= dnorm(obs(1,i), x(1,i), exp(logObsSd),true); vector<Type> tmp = x.col(i); Type val = evalFill((CppAD::vector<Type>)tmp, cf)[0]; nll -= dnorm(obs(2,i), val, exp(logObsTSd),true); } return nll; }
size_t integrate_const( Stepper stepper , System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer , dense_output_stepper_tag ) { typename odeint::unwrap_reference< Observer >::type &obs = observer; typename odeint::unwrap_reference< Stepper >::type &st = stepper; Time time = start_time; st.initialize( start_state , time , dt ); obs( start_state , time ); time += dt; int obs_step( 1 ); int real_step( 0 ); while( less_with_sign( static_cast<Time>(time+dt) , end_time , dt ) ) { while( less_eq_with_sign( time , st.current_time() , dt ) ) { st.calc_state( time , start_state ); obs( start_state , time ); ++obs_step; // direct computation of the time avoids error propagation happening when using time += dt // we need clumsy type analysis to get boost units working here time = start_time + static_cast< typename unit_value_type<Time>::type >(obs_step) * dt; } // we have not reached the end, do another real step if( less_with_sign( static_cast<Time>(st.current_time()+st.current_time_step()) , end_time , st.current_time_step() ) ) { while( less_eq_with_sign( st.current_time() , time , dt ) ) { st.do_step( system ); ++real_step; } } else if( less_with_sign( st.current_time() , end_time , st.current_time_step() ) ) { // do the last step ending exactly on the end point st.initialize( st.current_state() , st.current_time() , end_time - st.current_time() ); st.do_step( system ); ++real_step; } } // last observation, if we are still in observation interval if( less_eq_with_sign( time , end_time , dt ) ) { st.calc_state( time , start_state ); obs( start_state , time ); } return real_step; }
Time integrate_n_steps( Stepper stepper , System system , State &start_state , Time start_time , Time dt , size_t num_of_steps , Observer observer , dense_output_stepper_tag ) { typename odeint::unwrap_reference< Observer >::type &obs = observer; typename odeint::unwrap_reference< Stepper >::type &st = stepper; Time time = start_time; const Time end_time = start_time + static_cast< typename unit_value_type<Time>::type >(num_of_steps) * dt; st.initialize( start_state , time , dt ); size_t step = 0; while( step < num_of_steps ) { while( less_with_sign( time , st.current_time() , st.current_time_step() ) ) { st.calc_state( time , start_state ); obs( start_state , time ); ++step; // direct computation of the time avoids error propagation happening when using time += dt // we need clumsy type analysis to get boost units working here time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * dt; } // we have not reached the end, do another real step if( less_with_sign( static_cast<Time>(st.current_time()+st.current_time_step()) , end_time , st.current_time_step() ) ) { st.do_step( system ); } else if( less_with_sign( st.current_time() , end_time , st.current_time_step() ) ) { // do the last step ending exactly on the end point st.initialize( st.current_state() , st.current_time() , static_cast<Time>(end_time - st.current_time()) ); st.do_step( system ); } } while( st.current_time() < end_time ) { if( less_with_sign( end_time , static_cast<Time>(st.current_time()+st.current_time_step()) , st.current_time_step() ) ) st.initialize( st.current_state() , st.current_time() , static_cast<Time>(end_time - st.current_time()) ); st.do_step( system ); } // observation at end point, only if we ended exactly on the end-point (or above due to finite precision) obs( st.current_state() , end_time ); return time; }
size_t integrate_times( Stepper stepper , System system , State &start_state , TimeIterator start_time , TimeIterator end_time , Time dt , Observer observer , dense_output_stepper_tag ) { typename odeint::unwrap_reference< Observer >::type &obs = observer; typename odeint::unwrap_reference< Stepper >::type &st = stepper; typedef typename unit_value_type<Time>::type time_type; if( start_time == end_time ) return 0; TimeIterator last_time_iterator = end_time; --last_time_iterator; Time last_time_point = static_cast<time_type>(*last_time_iterator); st.initialize( start_state , *start_time , dt ); obs( start_state , *start_time++ ); size_t count = 0; while( start_time != end_time ) { while( ( start_time != end_time ) && less_eq_with_sign( static_cast<time_type>(*start_time) , st.current_time() , st.current_time_step() ) ) { st.calc_state( *start_time , start_state ); obs( start_state , *start_time ); start_time++; } // we have not reached the end, do another real step if( less_eq_with_sign( st.current_time() + st.current_time_step() , last_time_point , st.current_time_step() ) ) { st.do_step( system ); ++count; } else if( start_time != end_time ) { // do the last step ending exactly on the end point st.initialize( st.current_state() , st.current_time() , last_time_point - st.current_time() ); st.do_step( system ); ++count; } } return count; }
void singlePlanner::setObstacles(const std::vector<Vector> &obstacles) { //obsSet.resize(obstacles.size()); region *obstacle; for(int j=0; j<obstacles.size(); j++) { obstacle = new region; obstacle->setNumDimensions(nDim); Vector obs(2*nDim,0.0); for (int i=0; i<nDim; i++) { obstacle->center[i] = obstacles[j][i]; obstacle->size[i] = obstacles[j][i+3]; obs[i]=obstacles[j][i]; obs[i+3]=obstacles[j][i+3]; } system.obstacles.push_front(obstacle); obsSet.push_back(obs); } // cout<<"data in obsSet "<<endl; // for (int j=0; j<obsSet.size(); j++) // { // printf("Obstacle [%i] = [%g,%g,%g,%g,%g,%g]\n", // j, obsSet[j][0], obsSet[j][1], obsSet[j][2], // obsSet[j][3], obsSet[j][4], obsSet[j][5]); // } // cout<<endl; // rrts.setSystem(system); }
void Casan::check_observed_resources (Msg &out) { Resource *res ; reslist *rl ; for (rl = reslist_ ; rl != NULL ; rl = rl->next) { res = rl->res ; if (res->check_trigger ()) { DBG1 (F (B_BLUE "Observed resource '")) ; DBG1 (rl->res->name ()) ; DBG1 (F ("' triggered" C_RESET)) ; DBGLN0 () ; out.reset () ; out.set_type (COAP_TYPE_ACK) ; out.set_token (res->get_token ()) ; out.set_id (curid_++) ; out.set_code (COAP_CODE_OK) ; option obs (option::MO_Observe, res->next_serial ()) ; out.push_option (obs) ; request_resource (NULL, &out, res) ; out.send (*master_) ; } } }
void testObservations() { printf("== TEST OBSERVATIONS ==\n"); printf("- Testing construction\n"); RLObservation obs(3); RLObservation obs2(3); for (int i=0; i<3; i++) { obs[i] = observation[i]; obs2[i] = observation2[i]; } printf("-> PASSED\n"); printf("- Testing [] operator\n"); for (int i=0; i<3; i++) { printf("%f %f\n", obs.observations[i], observation[i]); assert( obs[i] == observation[i] ); } printf("-> PASSED\n"); printf("- Testing copyFrom\n"); obs.copyFrom(obs2); for (int i=0; i<3; i++) assert( obs[i] == observation2[i] ); printf("-> PASSED\n"); }
bool operator()(KMInput & input) { bool improvement(false); input.computeDistances(); // IntVector tLabel(input.getK(), 0); // _v.allocate(input.nbObs(), input.getK()); // for (size_t obs(0); obs < input.nbObs(); ++obs) { // for (size_t j(0); j < input.getK(); ++j) { // _v.get(obs, j) = input.getDelta(obs, j); // } // } do { ++input.ite(); improvement = false; for (size_t obs(0); obs < input.nbObs(); ++obs) { std::pair<size_t, Double> const delta(input.getBest(obs)); if (delta.second < 0) { input.cost() += delta.second; input.shift(obs, delta.first); improvement = true; } } if (improvement && isTraceOn) input.out("KMEANS"); } while (improvement); return improvement; }
TEST(Account, shouldTriggerMemberObserverEvents) { // given Account acc; MockModelObserver obs(acc); { InSequence dummy; EXPECT_CALL(obs, willChange("name")); EXPECT_CALL(obs, didChange("name")); EXPECT_CALL(obs, willChange("descr")); EXPECT_CALL(obs, didChange("descr")); EXPECT_CALL(obs, willChange("type")); EXPECT_CALL(obs, didChange("type")); } // when acc.setName("A name"); acc.setDescr("A descr"); acc.setType(Account::AccountType::Asset); // then // mock expectations implicitly verified }
int main() { // Run IRIS with the required_containment_points including a point which is outside the feasible set, which should result in an empty polyhedron iris::IRISProblem problem(2); problem.setSeedPoint(Eigen::Vector2d(0.1, 0.1)); Eigen::MatrixXd obs(2,2); // Inflate a region inside a 1x1 box obs << 0, 1, 0, 0; problem.addObstacle(obs); obs << 1, 1, 0, 1; problem.addObstacle(obs); obs << 1, 0, 1, 1; problem.addObstacle(obs); obs << 0, 0, 1, 0; problem.addObstacle(obs); iris::IRISOptions options; options.require_containment = true; options.required_containment_points = {Eigen::Vector2d(1.5, 1.5)}; auto region = inflate_region(problem, options); if (region->polyhedron->getNumberOfConstraints() > 0) { throw std::runtime_error("polyhedron should be empty"); } return 0; }
bool GridDetector::initCameraGeometryFromObservations(boost::shared_ptr<std::vector<cv::Mat> > images_ptr) { std::vector<cv::Mat>& images = *images_ptr; SM_DEFINE_EXCEPTION(Exception, std::runtime_error); SM_ASSERT_TRUE(Exception, images.size() != 0, "Need min. one image"); std::vector<GridCalibrationTargetObservation> observations; for(unsigned int i=0; i<images.size(); i++) { GridCalibrationTargetObservation obs(_target); //detect calibration target bool success = findTargetNoTransformation(images[i], obs); //delete image copy (save memory) obs.clearImage(); //append if(success) observations.push_back(obs); } //initialize the intrinsics if(observations.size() > 0) return _geometry->initializeIntrinsics(observations); return false; }
int main(int argc, char** argv) { iris::IRISProblem problem(2); problem.setSeedPoint(Eigen::Vector2d(0.1, 0.1)); Eigen::MatrixXd obs(2,2); // Inflate a region inside a 1x1 box obs << 0, 1, 0, 0; problem.addObstacle(obs); obs << 1, 1, 0, 1; problem.addObstacle(obs); obs << 1, 0, 1, 1; problem.addObstacle(obs); obs << 0, 0, 1, 0; problem.addObstacle(obs); iris::IRISOptions options; iris::IRISRegion region = inflate_region(problem, options); std::cout << "C: " << region.ellipsoid.getC() << std::endl; std::cout << "d: " << region.ellipsoid.getD() << std::endl; return 0; }
int haplotypeCluster::closestN(int N, int clusteridx, vector<pair<int, float> > &output) { output.resize(N); int count = 0; float d, maxdist = -1.0; int maxind = -1; for (int i = 0; i < nhap; i++) { if (cluster_mask[i]) { d = euc(i, clusteridx, mu, dlook); pair<int, float> obs(i, d); if (count < N) { output[count] = obs; if (obs.second > maxdist) { maxdist = obs.second; maxind = count; } } else if (obs.second > maxdist) { output[maxind] = obs; maxind = 0; for (int j = 1; j < N; j++) if (output[j].second > output[maxind].second) maxind = j; maxdist = output[maxind].second; } count++; } } return 0; }
size_t integrate_times( Stepper stepper , System system , State &start_state , TimeIterator start_time , TimeIterator end_time , Time dt , Observer observer , stepper_tag ) { typename odeint::unwrap_reference< Observer >::type &obs = observer; typename odeint::unwrap_reference< Stepper >::type &st = stepper; typedef typename unit_value_type<Time>::type time_type; size_t steps = 0; Time current_dt = dt; while( true ) { Time current_time = *start_time++; obs( start_state , current_time ); if( start_time == end_time ) break; while( less_with_sign( current_time , static_cast<time_type>(*start_time) , current_dt ) ) { current_dt = min_abs( dt , *start_time - current_time ); st.do_step( system , start_state , current_time , current_dt ); current_time += current_dt; steps++; } } return steps; }
void CWhitePineWeevilModel::AddDailyResult(const StringVector& header, const StringVector& data) { enum TInputAllStage{ E_ID, E_YEAR, E_MONTH, E_DAY, E_DD, E_EGG, E_EGG_CUMUL, E_L1, E_CUMUL_L1, E_L2, E_CUMUL_L2, E_L3, E_CUMUL_L3, E_L4, E_CUMUL_L4, E_PUPA, E_CUMUL_PUPA, E_ADULT, E_CUMUL_ADULT, NB_INPUTS_STAGE }; enum TInputDD{ P_YEAR, P_MONTH, P_DAY, P_DD, NB_INPUTS_DD }; if (header.size() == NB_INPUTS_STAGE) { CTRef TRef(ToInt(data[E_YEAR]), ToSizeT(data[E_MONTH]) - 1, ToSizeT(data[E_DAY]) - 1); std::vector<double> obs(NB_STAGES,-999); for (size_t i = 0; i < 7 && E_EGG_CUMUL + 2 * i<data.size(); i++) obs[i] = !data[E_EGG_CUMUL + 2 * i].empty()?ToDouble(data[E_EGG_CUMUL + 2 * i]):-999; m_SAResult.push_back(CSAResult(TRef, obs)); } /*else if (header.size() == NB_INPUTS_DD) { //CTRef TRef(ToInt(data[P_YEAR]), ToSizeT(data[P_MONTH]) - 1, ToSizeT(data[P_DAY]) - 1); std::vector<double> obs(2); obs[PUP_NB_DAYS] = ToDouble(data[P_NB_DAYS]); obs[PUP_N] = ToDouble(data[P_N]); m_SAResult.push_back(CSAResult(TRef, obs)); }*/ }
double crudeMC(crudeMCArgs& args) { std::size_t n = args.n; if(n <= 0) { throw std::runtime_error("Input n must be positive"); } const context& contextObj = args.contextObj; boost::detail::depth_first_visit_restricted_impl_helper<context::internalGraph>::stackType stack; std::vector<int> components; std::vector<int> interestComponents; const std::vector<int> interestVertices = contextObj.getInterestVertices(); std::vector<boost::default_color_type> colorMap; int countDisconnected = 0; for(std::size_t i = 0; i < n; i++) { NetworkReliabilityObs obs(contextObj, args.randomSource); if(!isSingleComponent(contextObj.getGraph(), obs.getState(), components, stack, colorMap, contextObj.getInterestVertices())) { countDisconnected++; } } return (float)countDisconnected / (float)n; }
void covafillJAGS::evaluate (double *value, vector<double const *> const &args, vector<vector<unsigned int> > const &dims) const { // Create X unsigned int nrowX = dims[0][0]; unsigned int ncolX = dims[0].size() == 2 ? dims[0][1] : 1; cMatrix X(nrowX,ncolX); unsigned int indx; indx = 0; // JAGS uses column-major for (unsigned int j = 0; j < ncolX; ++j) { for (unsigned int i = 0; i < nrowX; ++i) { X(i,j) = args[0][indx++]; } } // Create coordinates unsigned int nrowC = dims[1][0]; unsigned int ncolC = dims[1].size() == 2 ? dims[1][1] : 1; cMatrix coord(nrowC,ncolC); indx = 0; // JAGS uses column-major for (unsigned int j = 0; j < ncolC; ++j) { for (unsigned int i = 0; i < nrowC; ++i) { coord(i,j) = args[1][indx++]; } } // Create obs unsigned int lengthO = dims[2][0]; cVector obs(lengthO); for(unsigned int i = 0; i < lengthO; ++i){ obs[i] = args[2][i]; } // Create h unsigned int lengthH = dims[3][0]; cVector h(ncolC); for(unsigned int i = 0; i < ncolC; ++i){ if(lengthH == 1){ h[i] = args[3][0]; }else{ h[i] = args[3][i]; } } // Create p double p = args[4][0]; // Create covarfill covafill<double> cf(coord,obs,h,p); // Calculate for(unsigned int i = 0; i < nrowX; ++i) value[i] = cf((cVector)X.row(i))(0); }
TEST(DetectAll, detection) { // DetectAll should detect all candidates DetectAll obs("Wait", "You forgot your lunchbox"); Candidate c; obs.process(&c); EXPECT_FALSE(c.isActive()); EXPECT_TRUE(c.hasProperty("Wait")); }
TEST(SmallObserverSphere, limitStep) { SmallObserverSphere obs(Vector3d(0, 0, 0), 1); Candidate c; c.setNextStep(10); c.current.setPosition(Vector3d(0, 0, 2)); obs.process(&c); EXPECT_DOUBLE_EQ(c.getNextStep(), 1); }
int ObservationInfo::processArgs (const char *arg) { int obs_id; obs_id = atoi (arg); rts2db::Observation obs (obs_id); obsset->push_back (obs); return 0; }
int main(int argc, char** argv) { pMyObservable d(new DataRepository); myObserver obs(d,"count_to_10_data"); d->run(); return 0; }
List viterbi(const arma::mat& transition, NumericVector emissionArray, const arma::vec& init, IntegerVector obsArray) { IntegerVector eDims = emissionArray.attr("dim"); //m,p,r IntegerVector oDims = obsArray.attr("dim"); //k,n,r arma::cube emission(emissionArray.begin(), eDims[0], eDims[1], eDims[2], false, true); arma::icube obs(obsArray.begin(), oDims[0], oDims[1], oDims[2], false, true); arma::umat q(obs.n_slices, obs.n_cols); arma::vec logp(obs.n_slices); arma::mat delta(emission.n_rows, obs.n_cols); arma::umat phi(emission.n_rows, obs.n_cols); for (unsigned int k = 0; k < obs.n_slices; k++) { delta.col(0) = init; for (unsigned int r = 0; r < emission.n_slices; r++) { delta.col(0) += emission.slice(r).col(obs(r, 0, k)); } phi.col(0).zeros(); for (unsigned int t = 1; t < obs.n_cols; t++) { for (unsigned int j = 0; j < emission.n_rows; j++) { (delta.col(t - 1) + transition.col(j)).max(phi(j, t)); delta(j, t) = delta(phi(j, t), t - 1) + transition(phi(j, t), j); for (unsigned int r = 0; r < emission.n_slices; r++) { delta(j, t) += emission(j, obs(r, t, k), r); } } } delta.col(obs.n_cols - 1).max(q(k, obs.n_cols - 1)); for (int t = (obs.n_cols - 2); t >= 0; t--) { q(k, t) = phi(q(k, t + 1), t + 1); } logp(k) = delta.col(obs.n_cols - 1).max(); } return List::create(Named("q") = wrap(q), Named("logp") = wrap(logp)); }
nsAppShellService::nsAppShellService() : mXPCOMShuttingDown(PR_FALSE), mModalWindowCount(0), mApplicationProvidedHiddenWindow(PR_FALSE) { nsCOMPtr<nsIObserverService> obs (do_GetService("@mozilla.org/observer-service;1")); if (obs) obs->AddObserver(this, "xpcom-shutdown", PR_FALSE); }