当前位置: 首页>>代码示例>>C++>>正文


C++ unordered_map::at方法代码示例

本文整理汇总了C++中boost::unordered_map::at方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::at方法的具体用法?C++ unordered_map::at怎么用?C++ unordered_map::at使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost::unordered_map的用法示例。


在下文中一共展示了unordered_map::at方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: cache_p_hat

// sets p_hat to the across-skill state right before the trial = first_exposure
// used to reduce redundant computation during gibbs sampling
void MixtureWCRP::cache_p_hat(const size_t student, const size_t end_trial, boost::unordered_map<size_t, double> & p_hat) const {

    // define some references for convenience:
    const vector<bool> & recall_sequence = recall_sequences.at(student);
    const vector<size_t> & item_sequence = item_sequences.at(student);

    // initialize p_hat
    for (boost::unordered_map<size_t, struct bkt_parameters>::const_iterator table_itr = parameters.begin(); table_itr != parameters.end(); table_itr++) p_hat[table_itr->first] = table_itr->second.psi;

    for (size_t trial = 0; trial < end_trial; trial++) {

        // define some constants for notational clarity
        const bool did_recall = recall_sequence.at(trial);
        const size_t table_id = seating_arrangement.at(item_sequence.at(trial));
        const struct bkt_parameters & skill_params = parameters.at(table_id);
        const double skill_pi1 = skill_params.pi1;
        const double skill_pi0 = skill_pi1 *  skill_params.prop0;
        const double skill_mu = skill_params.mu;
        const double cur_p_hat = p_hat.at(table_id);
        const double one_minus_cur_p_hat = 1.0 - cur_p_hat;

        // update
        if (did_recall) p_hat[table_id] = (skill_pi1 * cur_p_hat + skill_mu * skill_pi0 * one_minus_cur_p_hat) / (skill_pi1 * cur_p_hat + skill_pi0 * one_minus_cur_p_hat);
        else p_hat[table_id] = ((1.0 - skill_pi1) * cur_p_hat + skill_mu * (1.0 - skill_pi0) * one_minus_cur_p_hat) / ((1.0 - skill_pi1) * cur_p_hat + (1.0 - skill_pi0) * one_minus_cur_p_hat);
    }
}
开发者ID:robert-lindsey,项目名称:WCRP,代码行数:28,代码来源:MixtureWCRP.cpp

示例2: disabledReasonFromString

// ******************************************************************************************
// Converts a string reason for disabling a link pair into a struct data type
// ******************************************************************************************
DisabledReason disabledReasonFromString( const std::string& reason )
{
  DisabledReason r;
  try
  {
    r = reasonsFromString.at( reason );
  }
  catch( std::out_of_range )
  {
    r = USER;
  }

  return r;
}
开发者ID:ksenglee,项目名称:ros,代码行数:17,代码来源:compute_default_collisions.cpp

示例3: if

static std::pair<double, double>
score(const boost::unordered_map<int, double> &real,
      const boost::unordered_map<int, double> &fake,
      double threshold = 0.0)
{
  double res = 0.0;
  int cnt = 0;
  double e = std::numeric_limits<double>::epsilon();
  for (auto i = fake.begin(); i != fake.end(); ++i)
    if (i->second >= threshold &&
        real.find(i->first) != real.end()) {
      ++cnt;

      double p = real.at(i->first);
      double q = fake.at(i->first);

      if (p <= e)
        res += (1-p) * log((1-p)/(1-q));
      else if (1-p <= e || 1-q <= e)
        res += p * log(p/q);
      else res += p * log(p/q) + (1-p) * log((1-p)/(1-q));
    }
  return {res, cnt ? res / cnt : 0.0};
}
开发者ID:FormatMemory,项目名称:QuerySimulation,代码行数:24,代码来源:main.cpp

示例4: disabledReasonToString

// ******************************************************************************************
// Converts a reason for disabling a link pair into a string
// ******************************************************************************************
const std::string disabledReasonToString( DisabledReason reason )
{
  return reasonsToString.at( reason );
}
开发者ID:ksenglee,项目名称:ros,代码行数:7,代码来源:compute_default_collisions.cpp

示例5: timer_callback

  void timer_callback(const ros::TimerEvent &)
  {
    mil_msgs::MoveToResult actionresult;

    // Handle disabled, killed, or no odom before attempting to produce trajectory
    std::string err = "";
    if (disabled)
      err = "c3 disabled";
    else if (kill_listener.isRaised())
      err = "killed";
    else if (!c3trajectory)
      err = "no odom";

    if (!err.empty())
    {
      if (c3trajectory)
        c3trajectory.reset();  // On revive/enable, wait for odom before station keeping

      // Cancel all goals while killed/disabled/no odom
      if (actionserver.isNewGoalAvailable())
        actionserver.acceptNewGoal();
      if (actionserver.isActive())
      {
        actionresult.error = err;
        actionresult.success = false;
        actionserver.setAborted(actionresult);
      }
      return;
    }

    ros::Time now = ros::Time::now();

    auto old_waypoint = current_waypoint;

    if (actionserver.isNewGoalAvailable())
    {
      boost::shared_ptr<const mil_msgs::MoveToGoal> goal = actionserver.acceptNewGoal();
      current_waypoint =
          subjugator::C3Trajectory::Waypoint(Point_from_PoseTwist(goal->posetwist.pose, goal->posetwist.twist),
                                             goal->speed, !goal->uncoordinated, !goal->blind);
      current_waypoint_t = now;
      this->linear_tolerance = goal->linear_tolerance;
      this->angular_tolerance = goal->angular_tolerance;

      waypoint_validity_.pub_size_ogrid(Pose_from_Waypoint(current_waypoint), (int)OGRID_COLOR::GREEN);

      // Check if waypoint is valid
      std::pair<bool, WAYPOINT_ERROR_TYPE> checkWPResult = waypoint_validity_.is_waypoint_valid(
          Pose_from_Waypoint(current_waypoint), current_waypoint.do_waypoint_validation);
      actionresult.error = WAYPOINT_ERROR_TO_STRING.at(checkWPResult.second);
      actionresult.success = checkWPResult.first;
      if (checkWPResult.first == false && waypoint_check_)  // got a point that we should not move to
      {
        waypoint_validity_.pub_size_ogrid(Pose_from_Waypoint(current_waypoint), (int)OGRID_COLOR::RED);
        if (checkWPResult.second ==
            WAYPOINT_ERROR_TYPE::UNKNOWN)  // if unknown, check if there's a huge displacement with the new waypoint
        {
          auto a_point = Pose_from_Waypoint(current_waypoint);
          auto b_point = Pose_from_Waypoint(old_waypoint);
          // If moved more than .5m, then don't allow
          if (abs(a_point.position.x - b_point.position.x) > .5 || abs(a_point.position.y - b_point.position.y) > .5)
          {
            ROS_ERROR("can't move there! - need to rotate");
            current_waypoint = old_waypoint;
          }
        }
        // if point is occupied, reject move
        if (checkWPResult.second == WAYPOINT_ERROR_TYPE::OCCUPIED)
        {
          ROS_ERROR("can't move there! - waypoint is occupied");
          current_waypoint = old_waypoint;
        }
        // if point is above water, reject move
        if (checkWPResult.second == WAYPOINT_ERROR_TYPE::ABOVE_WATER)
        {
          ROS_ERROR("can't move there! - waypoint is above water");
          current_waypoint = old_waypoint;
        }
        if (checkWPResult.second == WAYPOINT_ERROR_TYPE::NO_OGRID)
        {
          ROS_ERROR("WaypointValidity - Did not recieve any ogrid");
        }
      }
    }
    if (actionserver.isPreemptRequested())
    {
      current_waypoint = c3trajectory->getCurrentPoint();
      current_waypoint.do_waypoint_validation = false;
      current_waypoint.r.qdot = subjugator::Vector6d::Zero();  // zero velocities
      current_waypoint_t = now;

      // don't try to make output c3 continuous when cancelled - instead stop as quickly as possible
      c3trajectory.reset(new subjugator::C3Trajectory(current_waypoint.r, limits));
      c3trajectory_t = now;
    }

    // Remember the previous trajectory
    auto old_trajectory = c3trajectory->getCurrentPoint();

    while (c3trajectory_t + traj_dt < now)
//.........这里部分代码省略.........
开发者ID:uf-mil,项目名称:SubjuGator,代码行数:101,代码来源:node.cpp


注:本文中的boost::unordered_map::at方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。