Open hstrey opened 2 months ago
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
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.
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?
So I've got the setp
stuff working now here: https://github.com/Neuroblox/GraphDynamics.jl/pull/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.
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?