stomp.cpp
Go to the documentation of this file.
1 
27 #include <ros/console.h>
28 #include <limits.h>
29 #include <Eigen/LU>
30 #include <Eigen/Cholesky>
31 #include <math.h>
32 #include <stomp_core/utils.h>
33 #include <numeric>
34 #include "stomp_core/stomp.h"
35 
36 static const double DEFAULT_NOISY_COST_IMPORTANCE_WEIGHT = 1.0;
37 static const double MIN_COST_DIFFERENCE = 1e-8;
38 static const double MIN_CONTROL_COST_WEIGHT = 1e-8;
47 static void computeLinearInterpolation(const std::vector<double>& first,const std::vector<double>& last,
48  int num_timesteps,
49  Eigen::MatrixXd& trajectory_joints)
50 {
51  trajectory_joints.setZero(first.size(),num_timesteps);
52  for(int unsigned i = 0; i < first.size(); i++)
53  {
54  double dtheta = (last[i] - first[i])/(num_timesteps - 1);
55  for(unsigned int j = 0; j < num_timesteps; j++)
56  {
57  trajectory_joints(i,j) = first[i] + j * dtheta;
58  }
59  }
60 }
61 
70 static void computeCubicInterpolation(const std::vector<double>& first,const std::vector<double>& last,
71  int num_points,double dt,
72  Eigen::MatrixXd& trajectory_joints)
73 {
74  std::vector<double> coeffs(4,0);
75  double total_time = (num_points - 1) * dt;
76  for(int unsigned i = 0; i < first.size(); i++)
77  {
78  coeffs[0] = first[i];
79  coeffs[2] = (3/(pow(total_time,2))) * (last[i] - first[i]);
80  coeffs[3] = (-2/(pow(total_time,3))) * (last[i] - first[i]);
81 
82  double t;
83  for(unsigned j = 0; j < num_points; j++)
84  {
85  t = j*dt;
86  trajectory_joints(i,j) = coeffs[0] + coeffs[2]*pow(t,2) + coeffs[3]*pow(t,3);
87  }
88  }
89 }
90 
100 bool computeMinCostTrajectory(const std::vector<double>& first,
101  const std::vector<double>& last,
102  const Eigen::MatrixXd& control_cost_matrix_R_padded,
103  const Eigen::MatrixXd& inv_control_cost_matrix_R,
104  Eigen::MatrixXd& trajectory_joints)
105 {
106  using namespace stomp_core;
107 
108  if(control_cost_matrix_R_padded.rows() != control_cost_matrix_R_padded.cols())
109  {
110  ROS_ERROR("Control Cost Matrix is not square");
111  return false;
112  }
113 
114 
115  int timesteps = control_cost_matrix_R_padded.rows() - 2*(FINITE_DIFF_RULE_LENGTH - 1);
116  int start_index_padded = FINITE_DIFF_RULE_LENGTH - 1;
117  int end_index_padded = start_index_padded + timesteps-1;
118  std::vector<Eigen::VectorXd> linear_control_cost(first.size(),Eigen::VectorXd::Zero(timesteps));
119  trajectory_joints.setZero(first.size(),timesteps);
120 
121 
122  for(unsigned int d = 0; d < first.size(); d++)
123  {
124  linear_control_cost[d].transpose() = first[d] * Eigen::VectorXd::Ones(FINITE_DIFF_RULE_LENGTH - 1).transpose() *
125  control_cost_matrix_R_padded.block(0,start_index_padded,FINITE_DIFF_RULE_LENGTH - 1,timesteps);
126 
127  linear_control_cost[d].transpose() += last[d] * Eigen::VectorXd::Ones(FINITE_DIFF_RULE_LENGTH - 1).transpose() *
128  control_cost_matrix_R_padded.block(end_index_padded + 1,start_index_padded,FINITE_DIFF_RULE_LENGTH - 1,
129  timesteps);
130 
131  linear_control_cost[d] *=2;
132 
133  trajectory_joints.row(d) = -0.5*inv_control_cost_matrix_R*linear_control_cost[d];
134  trajectory_joints(d,0) = first[d];
135  trajectory_joints(d,timesteps - 1) = last[d];
136  }
137 
138  return true;
139 }
140 
149 void computeParametersControlCosts(const Eigen::MatrixXd& parameters,
150  double dt,
151  double control_cost_weight,
152  const Eigen::MatrixXd& control_cost_matrix_R,
153  Eigen::MatrixXd& control_costs)
154 {
155  std::size_t num_timesteps = parameters.cols();
156  double cost = 0;
157  for(auto d = 0u; d < parameters.rows(); d++)
158  {
159  cost = double(parameters.row(d)*(control_cost_matrix_R*parameters.row(d).transpose()));
160  control_costs.row(d).setConstant( 0.5*(1/dt)*cost );
161  }
162 
163  double max_coeff = control_costs.maxCoeff();
164  control_costs /= (max_coeff > 1e-8) ? max_coeff : 1;
165  control_costs *= control_cost_weight;
166 }
167 
168 
169 namespace stomp_core {
170 
171 
173  config_(config),
174  task_(task)
175 {
176 
177  resetVariables();
178 
179 }
180 
182 {
183  return resetVariables();
184 }
185 
187 {
188  config_ = config;
189  resetVariables();
190 }
191 
192 bool Stomp::solve(const std::vector<double>& first,const std::vector<double>& last,
193  Eigen::MatrixXd& parameters_optimized)
194 {
195  // initialize trajectory
196  if(!computeInitialTrajectory(first,last))
197  {
198  ROS_ERROR("Unable to generate initial trajectory");
199  }
200 
201  return solve(parameters_optimized_,parameters_optimized);
202 }
203 
204 bool Stomp::solve(const Eigen::VectorXd& first,const Eigen::VectorXd& last,
205  Eigen::MatrixXd& parameters_optimized)
206 {
207  // converting to std vectors
208  std::vector<double> start(first.size());
209  std::vector<double> end(last.size());
210 
211  Eigen::VectorXd::Map(&start[0],first.size()) = first;
212  Eigen::VectorXd::Map(&end[0],last.size()) = last;
213 
214  return solve(start,end,parameters_optimized);
215 }
216 
217 bool Stomp::solve(const Eigen::MatrixXd& initial_parameters,
218  Eigen::MatrixXd& parameters_optimized)
219 {
220  if(parameters_optimized_.isZero())
221  {
222  parameters_optimized_ = initial_parameters;
223  }
224 
225  // check initial trajectory size
226  if(initial_parameters.rows() != config_.num_dimensions || initial_parameters.cols() != config_.num_timesteps)
227  {
228  ROS_ERROR("Initial trajectory dimensions is incorrect");
229  return false;
230  }
231  else
232  {
233  if(initial_parameters.cols() != config_.num_timesteps)
234  {
235  ROS_ERROR("Initial trajectory number of time steps is incorrect");
236  return false;
237  }
238  }
239 
240  current_iteration_ = 1;
241  unsigned int valid_iterations = 0;
242  current_lowest_cost_ = std::numeric_limits<double>::max();
243 
244  // computing initialial trajectory cost
245  if(!computeOptimizedCost())
246  {
247  ROS_ERROR("Failed to calculate initial trajectory cost");
248  return false;
249  }
250 
253  {
254 
255  ROS_DEBUG("STOMP completed iteration %i with cost %f",current_iteration_,current_lowest_cost_);
256 
257 
259  {
260  ROS_DEBUG("Found valid solution, will iterate %i more time(s) ",
261  config_.num_iterations_after_valid - valid_iterations);
262 
263  valid_iterations++;
264  }
265  else
266  {
267  valid_iterations = 0;
268  }
269 
270  if(valid_iterations > config_.num_iterations_after_valid)
271  {
272  break;
273  }
274 
276  }
277 
279  {
280  ROS_INFO("STOMP found a valid solution with cost %f after %i iterations",
282  }
283  else
284  {
285  if (proceed_)
286  ROS_ERROR("STOMP failed to find a valid solution after %i iterations",current_iteration_);
287  else
288  ROS_ERROR_STREAM("Stomp was terminated");
289  }
290 
291  parameters_optimized = parameters_optimized_;
292 
293  // notifying task
295 
296  return parameters_valid_;
297 }
298 
300 {
301  proceed_= true;
303  parameters_valid_ = false;
305  current_iteration_ = 0;
306 
307  // verifying configuration
309  {
310  ROS_DEBUG_STREAM("'max_rollouts' must be greater than 'num_rollouts_per_iteration'.");
311  config_.max_rollouts = config_.num_rollouts + 1; // one more to accommodate optimized trajectory
312  }
313 
314  // noisy rollouts allocation
315  int d = config_.num_dimensions;
319 
320  // initializing rollout
321  Rollout rollout;
322  rollout.noise.resize(d, config_.num_timesteps);
323  rollout.noise.setZero();
324 
325  rollout.parameters_noise.resize(d, config_.num_timesteps);
326  rollout.parameters_noise.setZero();
327 
328  rollout.probabilities.resize(d, config_.num_timesteps);
329  rollout.probabilities.setZero();
330 
331  rollout.full_probabilities.clear();
332  rollout.full_probabilities.resize(d);
333 
334  rollout.full_costs.clear();
335  rollout.full_costs.resize(d);
336 
337  rollout.control_costs.resize(d, config_.num_timesteps);
338  rollout.control_costs.setZero();
339 
340  rollout.total_costs.resize(d, config_.num_timesteps);
341  rollout.total_costs.setZero();
342 
343  rollout.state_costs.resize(config_.num_timesteps);
344  rollout.state_costs.setZero();
345 
347 
348  for(unsigned int r = 0; r < config_.max_rollouts ; r++)
349  {
350  noisy_rollouts_[r] = rollout;
351  reused_rollouts_[r] = rollout;
352  }
353 
354  // parameter updates
356  parameters_updates_.setZero();
357 
359  parameters_control_costs_.setZero();
360 
362  parameters_state_costs_.setZero();
363 
365  parameters_optimized_.setZero();
366 
367  // generate finite difference matrix
368  start_index_padded_ = FINITE_DIFF_RULE_LENGTH-1;
369  num_timesteps_padded_ = config_.num_timesteps + 2*(FINITE_DIFF_RULE_LENGTH-1);
370  generateFiniteDifferenceMatrix(num_timesteps_padded_,DerivativeOrders::STOMP_ACCELERATION,
372 
373  /* control cost matrix (R = A_transpose * A):
374  * Note: Original code multiplies the A product by the time interval. However this is not
375  * what was described in the literature
376  */
380  inv_control_cost_matrix_R_ = control_cost_matrix_R_.fullPivLu().inverse();
381 
382  /*
383  * Applying scale factor to ensure that max(R^-1)==1
384  */
385  double maxVal = std::abs(inv_control_cost_matrix_R_.maxCoeff());
387  control_cost_matrix_R_ *= maxVal;
388  inv_control_cost_matrix_R_ /= maxVal; // used in computing the minimum control cost initial trajectory
389 
390  return true;
391 }
392 
393 bool Stomp::computeInitialTrajectory(const std::vector<double>& first,const std::vector<double>& last)
394 {
395  bool valid = true;
396 
398  {
399  case TrajectoryInitializations::CUBIC_POLYNOMIAL_INTERPOLATION:
400 
402  break;
403  case TrajectoryInitializations::LINEAR_INTERPOLATION:
404 
406  break;
407  case TrajectoryInitializations::MININUM_CONTROL_COST:
408 
410  break;
411  }
412 
413  return valid;
414 }
415 
417 {
418  ROS_WARN("Interrupting STOMP");
419  proceed_ = false;
420  return !proceed_;
421 }
422 
424 {
425  if(!proceed_)
426  {
427  return false;
428  }
429 
430  bool proceed = generateNoisyRollouts() &&
434  updateParameters() &&
436 
437  // notifying end of iteration
439 
440  return proceed;
441 }
442 
444 {
445  // calculating number of rollouts to reuse from previous iteration
446  std::vector< std::pair<double,int> > rollout_cost_sorter; // Used to sort noisy trajectories in ascending order wrt their total cost
448  int rollouts_stored = num_active_rollouts_-1; // don't take the optimized rollout into account
449  rollouts_stored = rollouts_stored < 0 ? 0 : rollouts_stored;
450  int rollouts_generate = config_.num_rollouts;
451  int rollouts_total = rollouts_generate + rollouts_stored +1;
452  int rollouts_reuse = rollouts_total < config_.max_rollouts ? rollouts_stored : config_.max_rollouts - (rollouts_generate + 1) ; // +1 for optimized params
453 
454  // selecting least costly rollouts from previous iteration
455  if(rollouts_reuse > 0)
456  {
457  // find min and max cost for exponential cost scaling
458  double min_cost = std::numeric_limits<double>::max();
459  double max_cost = std::numeric_limits<double>::min();
460  for (int r=1; r<rollouts_stored; ++r)
461  {
462  double c = noisy_rollouts_[r].total_cost;
463  if (c < min_cost)
464  min_cost = c;
465  if (c > max_cost)
466  max_cost = c;
467  }
468 
469  double cost_denom = max_cost - min_cost;
470  if (cost_denom < 1e-8)
471  cost_denom = 1e-8;
472 
473  // compute weighted cost on all rollouts
474  double cost_prob;
475  double weighted_prob;
476  for (auto r = 0u; r<rollouts_stored; ++r)
477  {
478 
479  // Apply noise generated on the previous iteration onto the current trajectory
480  noisy_rollouts_[r].noise = noisy_rollouts_[r].parameters_noise
482 
483  cost_prob = exp(-h*(noisy_rollouts_[r].total_cost - min_cost)/cost_denom);
484  weighted_prob = cost_prob * noisy_rollouts_[r].importance_weight;
485  rollout_cost_sorter.push_back(std::make_pair(-weighted_prob,r));
486  }
487 
488 
489  std::sort(rollout_cost_sorter.begin(), rollout_cost_sorter.end());
490 
491  // use the best ones: (copy them into reused_rollouts)
492  for (auto r = 0u; r<rollouts_stored; ++r)
493  {
494  int reuse_index = rollout_cost_sorter[r].second;
495  reused_rollouts_[r] = noisy_rollouts_[reuse_index];
496  }
497 
498  // copy them back from reused_rollouts_ into rollouts_
499  for (auto r = 0u; r<rollouts_reuse; ++r)
500  {
501  noisy_rollouts_[rollouts_generate + r ] = reused_rollouts_[r];
502  }
503  }
504 
505  // adding optimized trajectory as the last rollout
506  noisy_rollouts_[rollouts_generate + rollouts_reuse].parameters_noise = parameters_optimized_;
507  noisy_rollouts_[rollouts_generate + rollouts_reuse].noise.setZero();
508  noisy_rollouts_[rollouts_generate + rollouts_reuse].state_costs = parameters_state_costs_;
509  noisy_rollouts_[rollouts_generate + rollouts_reuse].control_costs = parameters_control_costs_;
510 
511 
512  // generate new noisy rollouts
513  for(auto r = 0u; r < rollouts_generate; r++)
514  {
515  if(!proceed_)
516  {
517  return false;
518  }
519 
520  if(!task_->generateNoisyParameters(parameters_optimized_,
523  noisy_rollouts_[r].parameters_noise,
524  noisy_rollouts_[r].noise))
525  {
526  ROS_ERROR("Failed to generate noisy parameters at iteration %i",current_iteration_);
527  return false;
528  }
529 
530  }
531 
532  // update total active rollouts
533  num_active_rollouts_ = rollouts_reuse + rollouts_generate + 1;
534 
535  return true;
536 }
537 
539 {
540  // apply post noise generation filters
541  bool filtered = false;
542  for(auto r = 0u ; r < config_.num_rollouts; r++)
543  {
544  if(!proceed_)
545  {
546  return false;
547  }
548 
549  if(!task_->filterNoisyParameters(0,config_.num_timesteps,current_iteration_,r,noisy_rollouts_[r].parameters_noise,filtered))
550  {
551  ROS_ERROR_STREAM("Failed to filter noisy parameters");
552  return false;
553  }
554 
555  if(filtered)
556  {
557  noisy_rollouts_[r].noise = noisy_rollouts_[r].parameters_noise - parameters_optimized_;
558  }
559  }
560 
561  return true;
562 }
563 
565 {
566  // computing state and control costs
568 
569  if(valid)
570  {
571  // compute total costs
572  double total_state_cost ;
573  double total_control_cost;
574 
575  for(auto r = 0u ; r < num_active_rollouts_;r++)
576  {
577  Rollout& rollout = noisy_rollouts_[r];
578  total_state_cost = rollout.state_costs.sum();
579 
580  // Compute control + state cost for each joint
581  total_control_cost = 0;
582  double ccost = 0;
583  for(auto d = 0u; d < config_.num_dimensions; d++)
584  {
585  ccost = rollout.control_costs.row(d).sum();
586  total_control_cost += ccost;
587  rollout.full_costs[d] = ccost + total_state_cost;
588  }
589  rollout.total_cost = total_state_cost + total_control_cost;
590 
591  // Compute total cost for each time step
592  for(auto d = 0u; d < config_.num_dimensions; d++)
593  {
594  rollout.total_costs.row(d) = rollout.state_costs.transpose() + rollout.control_costs.row(d);
595  }
596  }
597  }
598 
599  return valid;
600 }
601 
603 {
604 
605  bool all_valid = true;
606  bool proceed = true;
607  for(auto r = 0u ; r < config_.num_rollouts; r++)
608  {
609  if(!proceed_)
610  {
611  proceed = false;
612  break;
613  }
614 
615  Rollout& rollout = noisy_rollouts_[r];
616  if(!task_->computeNoisyCosts(rollout.parameters_noise,0,
619  rollout.state_costs,all_valid))
620  {
621  ROS_ERROR("Trajectory cost computation failed for rollout %i.",r);
622  proceed = false;
623  break;
624  }
625  }
626 
627  return proceed;
628 }
630 {
631  Eigen::ArrayXXd Ax; // accelerations
632  for(auto r = 0u ; r < num_active_rollouts_; r++)
633  {
634  Rollout& rollout = noisy_rollouts_[r];
635 
637  {
638  for(auto d = 0u; d < config_.num_dimensions; d++)
639  {
640  rollout.control_costs.row(d).setConstant(0);
641  }
642  }
643  else
644  {
649  }
650  }
651  return true;
652 }
653 
655 {
656 
657  double cost;
658  double min_cost;
659  double max_cost;
660  double denom;
661  double numerator;
662  double probl_sum = 0.0; // total probability sum of all rollouts for each joint
663  const double h = config_.exponentiated_cost_sensitivity;
664  double exponent = 0;
665 
666  for (auto d = 0u; d<config_.num_dimensions; ++d)
667  {
668 
669  for (auto t = 0u; t<config_.num_timesteps; t++)
670  {
671 
672  // find min and max cost over all rollouts at timestep 't':
673  min_cost = noisy_rollouts_[0].total_costs(d,t);
674  max_cost = min_cost;
675  for (auto r=0u; r<num_active_rollouts_; ++r)
676  {
677  cost = noisy_rollouts_[r].total_costs(d,t);
678  if (cost < min_cost)
679  min_cost = cost;
680  if (cost > max_cost)
681  max_cost = cost;
682  }
683 
684  denom = max_cost - min_cost;
685 
686  // prevent division by zero:
687  if (denom < MIN_COST_DIFFERENCE)
688  {
689  denom = MIN_COST_DIFFERENCE;
690  }
691 
692  probl_sum = 0.0;
693  for (auto r = 0u; r<num_active_rollouts_; ++r)
694  {
695  // this is the exponential term in the probability calculation described in the literature
696  exponent = -h*(noisy_rollouts_[r].total_costs(d,t) - min_cost)/denom;
697  noisy_rollouts_[r].probabilities(d,t) = noisy_rollouts_[r].importance_weight *
698  exp(exponent);
699 
700  probl_sum += noisy_rollouts_[r].probabilities(d,t);
701  }
702 
703  // scaling each probability value by the sum of all probabilities corresponding to all rollouts at time "t"
704  for (auto r = 0u; r<num_active_rollouts_; ++r)
705  {
706  noisy_rollouts_[r].probabilities(d,t) /= probl_sum;
707  }
708  }
709 
710 
711  // computing full probabilities
712  min_cost = noisy_rollouts_[0].full_costs[d];
713  max_cost = min_cost;
714  double c = 0.0;
715  for (int r=1; r<num_active_rollouts_; ++r)
716  {
717  c = noisy_rollouts_[r].full_costs[d];
718  if (c < min_cost)
719  min_cost = c;
720  if (c > max_cost)
721  max_cost = c;
722  }
723 
724  denom = max_cost - min_cost;
725  denom = denom < MIN_COST_DIFFERENCE ? MIN_COST_DIFFERENCE : denom;
726 
727  probl_sum = 0.0;
728  for (int r=0; r<num_active_rollouts_; ++r)
729  {
730  noisy_rollouts_[r].full_probabilities[d] = noisy_rollouts_[r].importance_weight *
731  exp(-h*(noisy_rollouts_[r].full_costs[d] - min_cost)/denom);
732  probl_sum += noisy_rollouts_[r].full_probabilities[d];
733  }
734  for (int r=0; r<num_active_rollouts_; ++r)
735  {
736  noisy_rollouts_[r].full_probabilities[d] /= probl_sum;
737  }
738  }
739 
740  return true;
741 }
742 
744 {
745  // computing updates from probabilities using convex combination
746  parameters_updates_.setZero();
747  for(auto d = 0u; d < config_.num_dimensions ; d++)
748  {
749 
750  for(auto r = 0u; r < num_active_rollouts_; r++)
751  {
752  auto& rollout = noisy_rollouts_[r];
753  parameters_updates_.row(d) += (rollout.noise.row(d).array() * rollout.probabilities.row(d).array()).matrix();
754  }
755 
756  }
757 
758  // filtering updates
760  {
761  ROS_ERROR("Updates filtering step failed");
762  return false;
763  }
764 
765  // updating parameters
767 
768  return true;
769 }
770 
772 {
773 
774  // control costs
777  {
783 
784  // adding all costs
785  parameters_total_cost_ = parameters_control_costs_.rowwise().sum().sum();
786 
787  }
788 
789  // state costs
790  if(task_->computeCosts(parameters_optimized_,
792  {
793 
794 
796  }
797  else
798  {
799  return false;
800  }
801 
802  // stop optimizing when valid solution is found
804  {
807  }
808  else
809  {
811  {
812  // reverting updates as no improvement was made
815 
816  }
817  }
818 
819  return true;
820 }
821 
822 } /* namespace stomp */
std::shared_ptr< Task > TaskPtr
Definition: task.h:37
Eigen::MatrixXd finite_diff_matrix_A_padded_
The finite difference matrix including padding.
Definition: stomp.h:202
static void computeCubicInterpolation(const std::vector< double > &first, const std::vector< double > &last, int num_points, double dt, Eigen::MatrixXd &trajectory_joints)
Compute a cubic interpolated trajectory given a start and end state.
Definition: stomp.cpp:70
d
int num_rollouts
Number of noisy trajectories.
Definition: utils.h:95
Eigen::MatrixXd control_cost_matrix_R_padded_
The control cost matrix including padding.
Definition: stomp.h:203
The data structure used to store information about a single rollout.
Definition: utils.h:37
bool resetVariables()
Reset all internal variables.
Definition: stomp.cpp:299
int num_active_rollouts_
Number of active rollouts.
Definition: stomp.h:197
Stomp(const StompConfiguration &config, TaskPtr task)
Stomp Constructor.
Definition: stomp.cpp:172
std::atomic< bool > proceed_
Used to determine if the optimization has been cancelled.
Definition: stomp.h:178
bool runSingleIteration()
Run a single iteration of the stomp algorithm.
Definition: stomp.cpp:423
int num_timesteps_padded_
The number of timesteps to pad the optimization with: timesteps + 2*(FINITE_DIFF_RULE_LENGTH - 1) ...
Definition: stomp.h:200
bool cancel()
Cancel optimization in progress. (Thread-Safe) This method is thead-safe.
Definition: stomp.cpp:416
int start_index_padded_
The index corresponding to the start of the non-paded section in the padded arrays.
Definition: stomp.h:201
This contains the stomp core algorithm.
bool generateNoisyRollouts()
Generate a set of noisy rollouts.
Definition: stomp.cpp:443
Eigen::VectorXd state_costs
A vector [num_time_steps] of the cost at each timestep.
Definition: utils.h:42
int num_iterations
Maximum number of iteration allowed.
Definition: utils.h:84
StompConfiguration config_
Configuration parameters.
Definition: stomp.h:180
double control_cost_weight
Percentage of the trajectory accelerations cost to be applied in the total cost calculation > ...
Definition: utils.h:99
bool computeMinCostTrajectory(const std::vector< double > &first, const std::vector< double > &last, const Eigen::MatrixXd &control_cost_matrix_R_padded, const Eigen::MatrixXd &inv_control_cost_matrix_R, Eigen::MatrixXd &trajectory_joints)
Compute a minimum cost trajectory given a start and end state.
Definition: stomp.cpp:100
int num_dimensions
Parameter dimensionality.
Definition: utils.h:87
double exponentiated_cost_sensitivity
Default exponetiated cost sensitivity coefficient.
Definition: utils.h:92
unsigned int current_iteration_
Current iteration for the optimization.
Definition: stomp.h:181
std::vector< Rollout > noisy_rollouts_
Holds the noisy rollouts.
Definition: stomp.h:195
void setConfig(const StompConfiguration &config)
Sets the configuration and resets all internal variables.
Definition: stomp.cpp:186
#define ROS_WARN(...)
bool computeOptimizedCost()
Computes the optimized trajectory cost [Control Cost + State Cost] If the current cost is not less th...
Definition: stomp.cpp:771
TaskPtr task_
The task to be optimized.
Definition: stomp.h:179
bool computeRolloutsStateCosts()
Computes the cost at every timestep for each noisy rollout.
Definition: stomp.cpp:602
Eigen::VectorXd parameters_state_costs_
A vector [timesteps] of the parameters state costs.
Definition: stomp.h:191
bool computeRolloutsControlCosts()
Compute the control cost for each noisy rollout. This is the sum of the acceleration squared...
Definition: stomp.cpp:629
double parameters_total_cost_
Total cost of the optimized parameters.
Definition: stomp.h:186
Eigen::MatrixXd control_cost_matrix_R_
A matrix [timesteps][timesteps], Referred to as &#39;R = A x A_transpose&#39; in the literature.
Definition: stomp.h:204
double current_lowest_cost_
Hold the lowest cost of the optimized parameters.
Definition: stomp.h:187
#define ROS_INFO(...)
bool filterNoisyRollouts()
Applies the optimization task&#39;s filter methods to the noisy trajectories.
Definition: stomp.cpp:538
Eigen::MatrixXd inv_control_cost_matrix_R_
A matrix [timesteps][timesteps], R^-1 &#39; matrix.
Definition: stomp.h:205
Eigen::MatrixXd probabilities
A matrix [num_dimensions][num_time_steps] of the probability for each parameter at every timestep...
Definition: utils.h:45
std::vector< double > full_costs
A vector [num_dimensions] of the full coss, state_cost + control_cost for each joint over the entire ...
Definition: utils.h:48
static const double MIN_COST_DIFFERENCE
Definition: stomp.cpp:37
bool computeProbabilities()
Computes the probability from the state cost at every timestep for each noisy rollout.
Definition: stomp.cpp:654
bool computeInitialTrajectory(const std::vector< double > &first, const std::vector< double > &last)
Computes an inital guess at a solution given a start and end state.
Definition: stomp.cpp:393
void computeParametersControlCosts(const Eigen::MatrixXd &parameters, double dt, double control_cost_weight, const Eigen::MatrixXd &control_cost_matrix_R, Eigen::MatrixXd &control_costs)
Compute the parameters control costs.
Definition: stomp.cpp:149
The data structure used to store STOMP configuration parameters.
Definition: utils.h:81
#define ROS_DEBUG_STREAM(args)
Eigen::MatrixXd parameters_noise
A matrix [num_dimensions][num_time_steps] of the sum of parameters + noise.
Definition: utils.h:40
bool solve(const std::vector< double > &first, const std::vector< double > &last, Eigen::MatrixXd &parameters_optimized)
Find the optimal solution provided a start and end goal.
Definition: stomp.cpp:192
Eigen::MatrixXd parameters_optimized_
A matrix [dimensions][timesteps] of the optimized parameters.
Definition: stomp.h:188
bool parameters_valid_prev_
whether or not the optimized parameters from the previous iteration are valid
Definition: stomp.h:185
bool clear()
Resets all internal variables.
Definition: stomp.cpp:181
int initialization_method
TrajectoryInitializations::TrajectoryInitialization.
Definition: utils.h:89
double importance_weight
importance sampling weight
Definition: utils.h:51
bool updateParameters()
Computes update from probabilities using convex combination.
Definition: stomp.cpp:743
double total_cost
combined state + control cost over the entire trajectory for all joints
Definition: utils.h:52
Eigen::MatrixXd noise
A matrix [num_dimensions][num_time_steps] of random noise applied to the parameters.
Definition: utils.h:39
bool computeNoisyRolloutsCosts()
Computes the total cost for each of the noisy rollouts.
Definition: stomp.cpp:564
static const double MIN_CONTROL_COST_WEIGHT
Definition: stomp.cpp:38
bool parameters_valid_
whether or not the optimized parameters are valid
Definition: stomp.h:184
int max_rollouts
The combined number of new and old rollouts during each iteration shouldn&#39;t exceed this value...
Definition: utils.h:96
#define ROS_ERROR_STREAM(args)
Eigen::MatrixXd parameters_control_costs_
A matrix [dimensions][timesteps] of the parameters control costs.
Definition: stomp.h:192
static void computeLinearInterpolation(const std::vector< double > &first, const std::vector< double > &last, int num_timesteps, Eigen::MatrixXd &trajectory_joints)
Compute a linear interpolated trajectory given a start and end state.
Definition: stomp.cpp:47
std::vector< double > full_probabilities
A vector [num_dimensions] of the probabilities for the full trajectory.
Definition: utils.h:47
double delta_t
Time change between consecutive points.
Definition: utils.h:88
Eigen::MatrixXd total_costs
A matrix [num_dimensions][num_time_steps] of the total cost, where total_cost[d] = state_costs_ + con...
Definition: utils.h:44
#define ROS_ERROR(...)
Eigen::MatrixXd parameters_updates_
A matrix [dimensions][timesteps] of the parameter updates.
Definition: stomp.h:190
std::vector< Rollout > reused_rollouts_
Used for reordering arrays based on cost.
Definition: stomp.h:196
int num_iterations_after_valid
Stomp will stop optimizing this many iterations after finding a valid solution.
Definition: utils.h:85
Eigen::MatrixXd control_costs
A matrix [num_dimensions][num_time_steps] of the control cost for each parameter at every timestep...
Definition: utils.h:43
int num_timesteps
Number of timesteps.
Definition: utils.h:86
static const double DEFAULT_NOISY_COST_IMPORTANCE_WEIGHT
Definition: stomp.cpp:36
#define ROS_DEBUG(...)


stomp_core
Author(s): Jorge Nicho
autogenerated on Fri May 8 2020 03:35:43