Skip to content
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

We need a Neuroblox interface to change parameters for remake #407

Open
hstrey opened this issue Sep 12, 2024 · 4 comments
Open

We need a Neuroblox interface to change parameters for remake #407

hstrey opened this issue Sep 12, 2024 · 4 comments
Assignees

Comments

@hstrey
Copy link
Member

hstrey commented Sep 12, 2024

I have been looking into different ways to change parameters in an already existing problem.
The MTK way is that you do the following:
prob_new = remake(prob, p = [p1 => 2.0])

The problem for us is that p1 is a symbolic parameter that has to be known in the namespace. But our parameters are not in the global namespace, and therefore we have to find them.

We can find them by doing:
parameters(sys)
and then searching for the name by:
sym_p = parameters(sys)
myp = sym_p[findall(x->contains(string(x),"p1"),sym_p)][1]
prob_new = remake(prob, p=[myp => 2.0])

is this a good way of approaching the problem? Shall we implement this method in blox_utilities?

@gabrevaya
Copy link
Contributor

gabrevaya commented Sep 12, 2024

I had implemented something along the same lines as what you propose, but using the getp function, so that you can pass the new values as a vector instead of a map. According to the documentation, using pure remake with maps can be less performant and is not always inferable.

get_inds(x::Vector{SymbolicUtils.BasicSymbolic{Real}}, name) = findall(x -> contains(string(x), name), x)
σ_ind = get_inds(parameters(sys), "σ")
setσ! = setp(prob, parameters(sys)[σ_ind])

σ_new = 1.0
prob_new = remake(prob)
setσ!(prob_new, fill(σ_new, length(setσ!.original_index)))

This was for setting all the values of a class of parameter to the same value, but you could pass a vector with different values too.

σ_new = rand(10)
setσ!(prob_new, σ_new)

For reference, these are the relevant parts of my implementation, but was basically as shown above:

https://github.com/Neuroblox/DBS-experiments/blob/13096ab0693860ca6a40a8181eb34e89f044a115/src/utils.jl#L45
https://github.com/Neuroblox/DBS-experiments/blob/13096ab0693860ca6a40a8181eb34e89f044a115/scripts/MSN_main.jl#L29
https://github.com/Neuroblox/DBS-experiments/blob/13096ab0693860ca6a40a8181eb34e89f044a115/src/utils.jl#L201

@hstrey
Copy link
Member Author

hstrey commented Sep 12, 2024

German, thanks. I had looked at your code before I created the Issue. I want to get opinions from the whole Neuroblox development group on what strategy to implement for Neuroblox.

@MasonProtter
Copy link
Contributor

Yeah, this is kinda a hard problem I think. I've played around with a couple ideas for this in GraphSystems but haven't developed any of them very far. I'll try to spend some time on this soon though because its an important usability problem.

Maybe the way to do it would be to have an API for replacing a specific neuron or something?

@MasonProtter
Copy link
Contributor

So I've got the setp stuff working now here: Neuroblox/GraphDynamics.jl#3, one thing I've learned is that you actually can do this getp /setp buisiness with just plain symbols instead of the symbolic objects themselves.

This is actually quite convenient for GraphDynamics because we aren't necessarily storing those symbolic objects anyways, we're just storing symbols currently.

So you can do e.g.

prob_new = remake(prob, p = [:neuron1₊p1 => 2.0])

without having to have that thing defined in your namespace at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants