-
Notifications
You must be signed in to change notification settings - Fork 15
Add support for setting constants by name #15
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
Conversation
Pull Request Test Coverage Report for Build 4250650704
💛 - Coveralls |
src/Equation.jl
Outdated
@@ -384,7 +385,7 @@ function Base.hash(tree::Node{T})::UInt where {T} | |||
if tree.degree == 0 | |||
if tree.constant | |||
# tree.val used. | |||
return hash((0, tree.val::T)) | |||
return hash((0, tree.val)) |
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 was this deleted? This type assertion helps quite a bit for performance
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, sorry! I experimented with using the name in the hash.
Hey @AlCap23, thanks for the PR. Just to help me understand the use-case, why is the naming necessary? The nodes are already well-ordered and can be get/set based on that order (which returns a vector of nodes). |
Sometimes, in the constant optimization, I'd like to have equality within a subset of the constants ( not on default, though ). Where the frequency should match. So instead of collecting individual constants, I use the same one based on the generated name. Given that this is an easy example, think about it on a system level: Where the identifiability might be enhanced by using this matching. Additionally, this allows for constraining specific variables with bounds ( using TransformVariables ) within the optimization. So in total: It might add more structure to the overall process without loss of generality. Quick Copy-Paste from my last answer in the issue: op = OperatorEnum(binary_operators = [-, *], unary_operators = [sin])
param = Node(; val = 3.0)
feat = Node(; feature = 1)
ex = sin(feat*param) - param
get_constants(ex) # Returns [3.0, 3.0], so each Node is still treated as an individual
set_constants(ex, [2.0]) # Error which makes sense And I tried to constraint it by using the hash map, but this did not work out either. Another approach would be to just store the parameters and set them, which could also be done ( I think ). |
Allright, feel free to close or keep 😅 . Figured it out. Simple solutions are not always my strong suite here. I am to used to immutable op = OperatorEnum(binary_operators = [-, *], unary_operators = [sin])
param = Node(; val = 3.0)
feat = Node(; feature = 1)
ex = sin(feat*param) - param
param.val = 2.0
ex # Works |
Cool, no problem at all! Indeed I think using |
Related to #14 .
This allows users to reuse constants within a node. This can be useful if substructures shares parameters or parameters are shared between equations ( e.g. PK/PD systems with transition compartments ). Should be useable with ComponentArrays (hence the dispatch on
C
rather than aNamedTuple
).