-
Notifications
You must be signed in to change notification settings - Fork 327
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
Trapping constraints #437
Trapping constraints #437
Conversation
This is much faster than fitting the features, and can be used by trapping to replace some constraint index calculations. Also: Add docstring/type annotations Rename a variable so it doesn't shadow newly-imported name
There are several major differences from the version in example 8: * Coupled with PolynomialLibrary logic using PolynomialLibrary.powers_. Previously, this coupling was implicit and actually tied to the specific order in Example 8, not the order users would expect. * Instead of handling pre-flattened 2D array, constraints are built with target and feature axes separately, letting the caller handle formatting the constraints as "target" or "feature". This gives us flexibility to later clean up the constraint logic outside this function without needing to return here and removes the need for striding calculations like: n_tgts * (n_tgts + k - 1) + i + n_tgts * int(j * (2 * n_tgts - j - 3) / 2.0) Since constraints are built directly from the terms and exponents in the library, its much easier to read and debug the code. * Renamed "r" as "n_tgts", etc. Single-letter index variables are removed. When they occur in homogenous iterators, they are concatenated with what they're iterating (e.g. tgt_i, tgt_j) * Broke out the different kinds of constraints into helper functions to make it easier to test. This allows follow on work to auto-attach constraints to a problem.
(other than degree, which has to be 2)
@Jacob-Stevens-Haas or @MPeng5 Have you checked the updated trapping constraints are consistent with @MPeng5 's branch? Mai, it might be worth merging your branch into this pull request and then rewriting your examples to be consistent with the new syntax here. |
Oh damn, sorry, I thought I responded a while ago. TL; DR they should be consistent, but mine aren't int target/feature format - user has to flatten them to whichever format they want (there is code in the docstring for each type). I'll check when I get back from break. |
Note to self:
|
I wanted to share this work as a draft that adds
_make_constraints()
from example 8 totrapping_sr3.py
. All the differences are noted in the commit messages, but the big ones are:PolynomialLibrary.powers_
.IMO this makes the logic a lot clearer, since the term in
n_tgts * (n_tgts + k - 1) + i + n_tgts * int(j * (2 * n_tgts - j - 3) / 2.0)
.Also a draft because I enabled too many
PolynomialLibrary
options.include_interaction=False
would be incompatible with the trapping constraints IIUC. OTOH, connecting topowers_
gives usinclude_bias=True
andinteraction_only=True
constraints for free.