Pyomo. DoE: Sensitivity initialization#3639
Conversation
…pected. Now, I need to add cases when some of the design variables are not changed.
…mo into sensitivity-initialization
… use compute_FIM_metrics() method. Added both the nested for loop and change_one_design_at_a_time argument to compute_FIM_factorial() in doe.py. Everything is working fine.
…gn_values` does not need to be in the same order as the `experiment_inputs` as long as the key matches, we are good. Also, if we don't want to change a design variable, just not passing it as a key in the `design_values` dictionary will do the trick. Tested with the `reactor_example.py`
|
@adowling2 @djlaky, this draft PR is ready for initial review. |
|
Does this PR depend on changes in #3575? |
adowling2
left a comment
There was a problem hiding this comment.
@smondal13 I left some initial comments.
pyomo/contrib/doe/utils_updated.py
Outdated
| @@ -0,0 +1,267 @@ | |||
| # ___________________________________________________________________________ | |||
There was a problem hiding this comment.
@smondal13 Why are your creating a new utils file instead of updating the current one? There might be a point of confusion regarding branches in git.
There was a problem hiding this comment.
This issue is resolved now. merged the utils file from my previous PR # 3525.
|
|
||
| return self.fim_factorial_results | ||
|
|
||
| def compute_FIM_factorial( |
There was a problem hiding this comment.
Was this function already in Pyomo.DoE somewhere else?
There was a problem hiding this comment.
No, I created this method. I do not see the same name anywhere else.
There was a problem hiding this comment.
@adowling2, we have compute_FIM_full_factorial(). I have not changed that method, rather I have added a new method. Maybe we can show a deprecation warning for compute_FIM_full_factorial()
There was a problem hiding this comment.
Yes, a depreciation warning sounds reasonable.
pyomo/contrib/doe/doe.py
Outdated
| # design_map_keys so that design_point can be constructed correctly in the loop. | ||
| des_ranges = [design_values[k.name] for k in design_map_keys] | ||
| if change_one_design_at_a_time: | ||
| factorial_points = generate_snake_zigzag_pattern(*des_ranges) |
There was a problem hiding this comment.
Let's brainstorm different sensitivity analysis sequences we might use. We can then define an enum.
Also added test for patter generator
…mo into sensitivity-initialization
…ensitivity-initialization
…f. The code is run by using a simple model.
|
@adowling2 , @djlaky, @blnicho This PR is ready for design review. |
|
|
||
| return self.fim_factorial_results | ||
|
|
||
| def compute_FIM_factorial( |
There was a problem hiding this comment.
Yes, a depreciation warning sounds reasonable.
pyomo/contrib/doe/doe.py
Outdated
| factorial_points = snake_traversal_grid_sampling(*design_values) | ||
| elif scheme_enum == SensitivityInitialization.nested_for_loop: | ||
| factorial_points = product(*design_values) | ||
|
|
There was a problem hiding this comment.
Does it make sense to split the function here? That way, we can do extensive testing on the results of factorial_points without running the rest of the function.
| ---------- | ||
| model : DoE model, optional | ||
| The model to perform the full factorial exploration on. Default: None | ||
| design_vals : dict, |
There was a problem hiding this comment.
After reading this doc string, I do not fully appreciate all of options. I do not think we are looking at all of the edge cases with the tests.
|
@smondal13 As a next step, I suggest you create a Google Doc as a mock-up for the documentation you plan to write for this new feature. In the mock-up, you can provide example usage to show the programmatic interface. I would set the Google Doc to allow for anonymous commenting and post the link here. Alternatively, you could do this in a markdown |
|
To see the Google Doc that shows the documentation and example of this feature, click here |
…)` in utils.py. 2. Raised error instead of warning if the DesignSpaceTraversal is wrong in doe.py
…mo into sensitivity-initialization
adowling2
left a comment
There was a problem hiding this comment.
Please see my requested changes.
pyomo/contrib/doe/doe.py
Outdated
| traversal_scheme="snake_traversal", | ||
| file_name: str = None, | ||
| ): | ||
| """Will run a simulation-based factorial exploration of the experimental input |
There was a problem hiding this comment.
Change "will run" to "performs"
| ---------- | ||
| model : DoE model, optional | ||
| The model to perform the full factorial exploration on. Default: None | ||
| design_vals : dict, |
|
|
||
| return self.factorial_results | ||
|
|
||
| # TODO: Overhaul plotting functions to not use strings |
There was a problem hiding this comment.
Do we still want to overhaul the plotting functions to not use strings? Or do we just want this function to be consistent with our user interface above? In other words, if we use string-based names above, I think it it okay to use string-based names here.
| def draw_factorial_figure( | ||
| self, | ||
| results=None, | ||
| sensitivity_design_variables=None, |
There was a problem hiding this comment.
Let's update this user interface to match the function above. It appears that design variables as specified differently in these two functions. Likewise, this function should do design variable name error checking similar to the function above.
|
|
||
|
|
||
| def compute_correlation_matrix( | ||
| covariance_matrix, var_name: list = None, significant_digits=3 |
There was a problem hiding this comment.
Please make the default for significant digits None.
| var_name : list, optional | ||
| List of variable names corresponding to the rows/columns of the covariance matrix. | ||
| significant_digits : int, optional | ||
| Number of significant digits to round the correlation matrix to. Default: 3. |
There was a problem hiding this comment.
Number of significant digits for rounding entries of the correlation matrix. Default: None (no rounding)
| ---------- | ||
| covariance_matrix : numpy.ndarray | ||
| 2D array representing the covariance matrix. | ||
| var_name : list, optional |
There was a problem hiding this comment.
What happens if this optional argument is not provided? The doc string does not tell me what happens with this information or the consequences of not providing it.
|
|
||
| Parameters | ||
| ---------- | ||
| covariance_matrix : numpy.ndarray |
There was a problem hiding this comment.
Can this be a square DataFrame? If yes, what type of error checking should we do on the column and row names?
| # Set the index to the variable names if provided, | ||
| corr_df = ( | ||
| pd.DataFrame(correlation_matrix, index=var_name, columns=var_name) | ||
| if var_name |
There was a problem hiding this comment.
What is this logic doing here?
Fixes # .
Summary/Motivation:
Changes proposed in this PR:
compute_FIM_factorial()in Pyomo.DoE for sensitivity initializationsnake_traversal_grid_sampling()andcompute_correlation_matrix()in utils.pyLegal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: