pyomo icon indicating copy to clipboard operation
pyomo copied to clipboard

Solve square problem to initialize regression problem using objective_at_theta() in parmest

Open kanishka-ghosh opened this issue 3 years ago • 7 comments

Fixes # .

Implements changes proposed in issue #2377

Summary/Motivation:

Add code and tests to solve a square problem instance in order to initialize the regression problem in parmest

Changes proposed in this PR:

  • Solve square problem instances of the model for each scenario using parameter values provided by user or values used to initialize fitted parameters; create extensive form of the model before calling theta_est() for parameter estimation.
    • Call objective_at_theta(initialize_parmest_model=True) which calls _Q_at_theta()
    • In _Q_at_theta(), iterate over scenarios, create and solve instance of Pyomo model, and store solved model instance in scenario dictionary
    • Call function _create_EF_from_scen_dict() to create the extensive form model with the scenario dictionary from above and set flag model_initialized=True
    • Call theta_est() to solve parameter estimation problem using extensive form of model from above (skip building the extensive form using theta_est()).
  • Create instance of Rooney-Biegler problem with Constraints to test square solve initialization
  • Add tests for square solve functionality

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

kanishka-ghosh avatar Jun 20 '22 19:06 kanishka-ghosh

Codecov Report

Base: 86.54% // Head: 86.55% // Increases project coverage by +0.01% :tada:

Coverage data is based on head (5170ece) compared to base (7ba914f). Patch coverage: 90.96% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2438      +/-   ##
==========================================
+ Coverage   86.54%   86.55%   +0.01%     
==========================================
  Files         717      718       +1     
  Lines       80234    80348     +114     
==========================================
+ Hits        69436    69544     +108     
- Misses      10798    10804       +6     
Flag Coverage Δ
linux 83.46% <90.32%> (+0.02%) :arrow_up:
osx 73.67% <8.38%> (-0.11%) :arrow_down:
other 83.65% <90.32%> (+0.02%) :arrow_up:
win 80.64% <90.32%> (+0.02%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pyomo/contrib/parmest/parmest.py 83.80% <89.60%> (+2.17%) :arrow_up:
...s/rooney_biegler/rooney_biegler_with_constraint.py 95.83% <95.83%> (ø)
pyomo/contrib/parmest/utils/create_ef.py 84.16% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar Jun 22 '22 20:06 codecov[bot]

@kanishka-ghosh Note that the failing test is due to code coverage of your patch is slightly below the average coverage of the Pyomo codebase.

jsiirola avatar Jun 28 '22 21:06 jsiirola

@kanishka-ghosh I merged PR #2352 from Kate which caused some conflicts with this PR. Could you try to resolve the conflicts and let me know if you have any issues?

blnicho avatar Jun 30 '22 22:06 blnicho

@blnicho I resolved the merge conflicts

kanishka-ghosh avatar Jul 01 '22 18:07 kanishka-ghosh

@kaklise could you review this PR?

blnicho avatar Jul 05 '22 19:07 blnicho

@kaklise could you review this PR again when you have a chance?

blnicho avatar Jul 25 '22 14:07 blnicho

@adowling2 volunteered to review

kanishka-ghosh avatar Aug 02 '22 17:08 kanishka-ghosh

@kanishka-ghosh I think we should wait on this one for the release. I was taking a closer look at the test failures before your commits today and I'm not convinced that your fix is what we want. In fact, I think the tests you added for the functionality introduced in this PR are missing some important edge cases. For example, when I try adding the initialize_parmest_model=True flag to the test_parmest_basics test (https://github.com/kanishka-ghosh/pyomo/blob/square_solve_obj_at_theta/pyomo/contrib/parmest/tests/test_parmest.py#L411) it fails with a ZeroDivisionError. test_parmest_basics tests different configurations/structures for the same model so it's concerning to me that it doesn't work. If this is an invalid test case for your initialize_parmest_model flag let me know.

blnicho avatar Aug 16 '22 23:08 blnicho

@kaklise could you take another look at this PR?

blnicho avatar Aug 30 '22 17:08 blnicho