-
Notifications
You must be signed in to change notification settings - Fork 18
Proper multilinear interpolation for both value and gradient #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dynamic_planner
Are you sure you want to change the base?
Conversation
| typename PD, typename RS, typename RD, typename B> | ||
| VectorXd MatlabValueFunction<TS, TC, TD, PS, PC, PD, RS, RD, B>:: | ||
| RecursiveGradientInterpolator(const VectorXd& x, size_t idx) const { | ||
| return RecursiveMultilinearInterpolator(x idx, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah crap this is a typo, will fix!
| VectorXd DirectionToCenter(const VectorXd& x) const; | ||
|
|
||
| // Accessor for precomputed value at the given state. | ||
| VectorXd ValueAccessor(const VectorXd& x) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be outputting a double?
| const size_t idx = StateToIndex(x); | ||
|
|
||
| VectorXd value(x.size()); | ||
| for (size_t ii = 0; ii < value.size(); ii++) value(ii) = data_[ii][idx]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work. Remember, data_ is a std::vector<double>, i.e. it's flattened. Also value output should be a double.
| // Recursive helper function for value or gradient multilinear interpolation. | ||
| // Takes in a state and index along which to interpolate, and a boolean | ||
| // determining whether this is for the gradient or, otherwise, for the value. | ||
| VectorXd RecursiveMultilinearInterpolator(const VectorXd& x, size_t idx, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooooooh cool idea. Instead of passing in a bool flag, could template the function itself on the accessor function, like:
template <typename Accessor, typename OutputType>
OutputType RecursiveMultilinearInterpolator(const VectorXd& x, size_t idx) const;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case, since the output type can be either double or VectorXd you need to template that.
dfridovi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main issue is that Value should output a double, not a VectorXd. Also suggesting a cleaner template approach to the recursive helper.
2ded36b to
e002e7d
Compare
1c1a269 to
9d1adbb
Compare
Added some wrappers for RecursiveGradientInterpolator (and now also RecursiveValueInterpolator) to also work.
Be sure to take a look, I tried not to break anything but let's make sure!