-
Notifications
You must be signed in to change notification settings - Fork 21
Add InfiniteInterpolate as an extension #382
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: master
Are you sure you want to change the base?
Conversation
…linear interpolation + test case
…and handling for variables that don't rely on infinite parameters
…ng interpolated values
…linear interpolation + test case
…and handling for variables that don't rely on infinite parameters
…ng interpolated values
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #382 +/- ##
=======================================
Coverage 99.68% 99.69%
=======================================
Files 35 36 +1
Lines 6759 6786 +27
=======================================
+ Hits 6738 6765 +27
Misses 21 21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…interpolation method error
…linear interpolation + test case
…and handling for variables that don't rely on infinite parameters
…ng interpolated values
…linear interpolation + test case
…ng interpolated values
…interpolation method error
…ue func in hovercraft example + shorten doc string
…terpolate test case
Good work, before proceeding please address the failing test. I will work on a patch to fix the failing docs. |
@wenwen0231, as a workaround for this PR. I think we can clear the tests if we don't import interpolations at the start of |
…nterpolate test file
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.
Overall this is on track, but we need to be careful with versioning and type piracy. Also, we should have a doc section for this addition in the manual docs (this is where the docstrings should be).
@@ -20,12 +26,14 @@ JuMP = "1.18" | |||
MutableArithmetics = "1" | |||
Reexport = "0.2, 1" | |||
julia = "^1.6" | |||
Interpolations = "0.16.1" |
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.
Does it have to be this exact version, will other versions work? We should be permissive as possible.
@@ -23,3 +24,4 @@ JuMP = "1.23" | |||
Literate = "2.18" | |||
Plots = "1" | |||
SpecialFunctions = "2" | |||
Interpolations = "0.16.1" |
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.
Please do 0.16 instead of 0.16.1, we shouldn't specify the patch release unless absolutely necessary, which I suspect is not the case here.
@@ -61,15 +61,21 @@ end) | |||
# Optimize the model: | |||
optimize!(m) | |||
|
|||
# Extract the results: | |||
x_opt = value.(x); | |||
# Extract the results. The InfiniteInterpolate extension can be used to get a smooth interpolated function for x, which is invoked when both the `Interpolations` and `InfiniteOpt` packages are imported: |
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.
I would expand a little more to say that you are choosing to do cubic splines here. Maybe also provide a link to the technical API documentation.
20.9999999956286 | ||
``` | ||
|
||
!!! note |
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 should be a warning, not a note.
@@ -137,7 +137,31 @@ parameter dependencies. | |||
This also holds true for many other methods in `InfiniteOpt`. For example, | |||
adding the dot also vectorizes `dual` and `set_binary`. | |||
|
|||
We can also query the dual of a constraint via | |||
We can also get a continuous representation of our variable as an interpolations object from the `Interpolations.jl` package. This is based on the `InfiniteInterpolate` extension, which is automatically loaded in when both `InfiniteOpt` and `Interpolations` are imported. Currently supported methods are `constant_interpolation`, `linear_interpolation` and `cubic_spline_interpolation`. |
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 should be probably be its own subsection with a header
# Get the parameter supports | ||
Vparams = [] | ||
for pref in prefs | ||
JuMP.check_belongs_to_model(pref, JuMP.owner_model(vref)) |
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 can never not be true. Please remove.
if !(infOpt.UniformGrid in suppsLabel) && !(method isa irregularGridMethod) | ||
throw(ArgumentError("Interpolation method $(method) does not support irregular grids for supports. Please specify a uniform grid or choose a different interpolation method.")) | ||
end |
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.
I suspect this will need updating when the above piracy concerns are addressed.
end | ||
|
||
paramVals = infOpt._get_value(pref, infOpt._index_type(pref); kwargs...) | ||
numSupps = infOpt.num_supports(pref) |
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.
Why do you call num_supports if you already have the values? Just use length
instead.
ext/InfiniteInterpolate.jl
Outdated
# Ensure Vparams is a tuple for interpolation | ||
Vparams = Tuple(Vparams) | ||
|
||
# Get the variable supports | ||
Vsupps = infOpt._get_value(vref, infOpt._index_type(vref); kwargs...) | ||
|
||
# Wrappers for interpolation method | ||
interpolateFunc(interpMethod::Function, params::Tuple, supps::Vector) = interpMethod(params, supps) | ||
|
||
# Wrapper for multi-parameter variables | ||
interpolateFunc(interpMethod::Function, params::Tuple, supps::Matrix) = interpMethod(params, supps) | ||
|
||
# Pass the parameter and variable values to interpolation function | ||
varFunc = interpolateFunc(method, Vparams, Vsupps) | ||
return varFunc | ||
end | ||
end |
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.
Please fix indentation
model = InfiniteModel(Optimizer) | ||
tb = model.backend | ||
|
||
# Define infinite parameters and variables |
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.
We should include testing what happens with orthogonal collocation points.
Summary
Add the module
InfiniteInterpolate
which extends thevalue()
function to return an interpolated function of the variable or parameter being queried, based on the interpolation method defined by the user.Closing issues
Fixes issue #82