# Parameter estimation in biological network

**URL:** https://discourse.julialang.org/t/parameter-estimation-in-biological-network/119630
**Category:** Optimization (Mathematical)
**Tags:** optimization, ordinarydiffeq
**Created:** [September 19, 2024, 11:42pm UTC](https://discourse.julialang.org/t/parameter-estimation-in-biological-network/119630 "2024-09-19T23:42:48Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@Nick1](https://discourse.julialang.org/u/Nick1)
#### Post date: [September 19, 2024, 11:42pm UTC](https://discourse.julialang.org/t/parameter-estimation-in-biological-network/119630/1 "2024-09-19T23:42:48Z")

</div>

I am working on a large signaling pathway and trying to get a rough estimation of the baseline parameters. I have been trying to do the fitting with the Particle Swarm Optimization from Metaheuristics.jl but it does not converge properly.

Here is the part related to the optimization:

```julia
# time points from each data set (first column: time points, second column: values)

t1 = data[1][:,1];
t2 = data[2][:,1];
t3 = data[3][:,1];
t4 = data[4][:,1];
t5 = data[5][:,1];
t6 = data[6][:,1];
t7 = data[7][:,1];
t8 = data[8][:,1];
t9 = data[9][:,1];
t10 = data[10][:,1];
t11 = data[11][:,1];

t = [t1;t2;t3;t4;t5;t6;t7;t8;t9;t10;t11];

# Remove repeated time points
t=unique(sort(t));

# indices for the respective model outputs
indices =[2, 65, 67, 69, 39, 44, 14, 31, 29, 25, 74];

# objective function
function obj_fun(p)
    err = 0.0;

    alg = AutoTsit5(Rosenbrock23(autodiff=false));

    prob = ODEProblem(model!, collect(init), tspan, p, callback=cbs);

    sol = solve(prob, alg=alg, saveat = t);

    for i in 1:11

        for (j,t) in enumerate(data[i][:,1])

# Experimental data are normalized to the maximum concentration on each dataset

            err = err + ((sol(t)[indices[i]] - maximum(sol[indices[i],:])*data[i][j,2]))^2;

        end
    end
    return err
end

bounds = BoxConstrainedSpace(lb = lb, ub = ub);

options = Options(f_calls_limit = 500*length(param), f_tol = 1e-3);

algorithm = PSO(N = 100, options = options);

result = optimize(obj_fun, bounds, algorithm);

p_est = minimizer(result);

```

The minimum optimization result is around 223, and many parameters remain the same. Does anyone have any experience in tackling this issue, e.g. different objective functions, algorithms etc?

Thanks!

---

<div class="post-metadata">

### Author: ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)
#### Post date: [September 20, 2024, 12:58am UTC](https://discourse.julialang.org/t/parameter-estimation-in-biological-network/119630/2 "2024-09-20T00:58:44Z")

</div>

Just a quick reply. Don’t create the `ODEProblem` inside the objective function; rather, create the problem outside and use either `solve(...; p = new_params)` or `remake`.  
For example like here: [Parameter Estimation of Ordinary Differential Equations · SciMLSensitivity.jl](https://docs.sciml.ai/SciMLSensitivity/stable/tutorials/parameter_estimation_ode/)

See also [Global Optimization via NLopt · DiffEqParamEstim.jl](https://docs.sciml.ai/DiffEqParamEstim/stable/tutorials/global_optimization/) or [GitHub - sebapersson/PEtab.jl: Create parameter estimation problems for ODE models](https://github.com/sebapersson/PEtab.jl) for more automatic frameworks.

My personal note: If you have only a few parameters and don’t know the system well, maybe spend a few hours making a data frame with `p -> obj_fun(p)` with randomly sampled values for `p` and plot the data to learn about your system. That way, you can see what the `obj_fun` looks like and judge if you need something complicated.  
(For me, often the solvers from [BlackBoxOptim.jl](https://docs.sciml.ai/Optimization/stable/optimization_packages/blackboxoptim/#BlackBoxOptim.jl) seem to work well. But it depends on the problem class you are in. And reasonable upper/lower bounds might be half of the trick.)

---

<div class="post-metadata">

### Author: ![Nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@Nick1](https://discourse.julialang.org/u/Nick1)
#### Post date: [September 20, 2024, 1:28am UTC](https://discourse.julialang.org/t/parameter-estimation-in-biological-network/119630/3 "2024-09-20T01:28:41Z")

</div>

Thanks for your reply!

My model is large (77 ODEs, 162 parameters), while I have 11 datasets, one for a different output. Also, the datasets contain different time points and normalized values to the maximum measured concentration on each dataset.

Do you think PEtab can handle large models with the above features? It looks helpful.

---

<div class="post-metadata">

### Author: ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)
#### Post date: [September 20, 2024, 1:57am UTC](https://discourse.julialang.org/t/parameter-estimation-in-biological-network/119630/4 "2024-09-20T01:57:47Z")

</div>

I am not experienced enough with that many parameters. Just today the JuliaCon talk was uploaded (I haven’t watched it yet, but maybe it was informative):

[![](https://global.discourse-cdn.com/julialang/original/3X/c/d/cd56e2001b9b0ee77bb557b15b8de8937ff77a16.jpeg "PEtab.jl - Efficient parameter estimation for dynamic models | Persson | JuliaCon 2024") ](https://www.youtube.com/watch?v=ud-TNMauaWI)

---

<div class="post-metadata">

### Author: ![Nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@Nick1](https://discourse.julialang.org/u/Nick1)
#### Post date: [September 20, 2024, 6:27am UTC](https://discourse.julialang.org/t/parameter-estimation-in-biological-network/119630/5 "2024-09-20T06:27:14Z")

</div>

Thank you a lot! I just tried to install PEtab.jl but I get the following error:

```julia
223 dependencies successfully precompiled in 829 seconds. 368 already precompiled.
  104 dependencies precompiled but different versions are currently loaded. Restart julia to access the new versions
  2 dependencies had output during precompilation:
┌ BlackBoxOptim
│ [pid 4384] waiting for IO to finish:
│ Handle type uv_handle_t->data
│ fs_event 0000018fbf51aa50->0000018fc304c490
│ timer 0000018fc3ddc0c0->0000018fc304c4c0
│ This means that a package has started a background task or event source that has not finished running. For precompilation to complete successfully, the event source needs to be closed explicitly. See the developer documentation on fixing precompilation hangs for more help.
└
┌ LinearSolve
│ Downloading artifact: IntelOpenMP
│
│ [pid 27832] waiting for IO to finish:
│ Handle type uv_handle_t->data
│ timer 0000024dd59368d0->0000024dd1e8d900
│ This means that a package has started a background task or event source that has not finished running. For precompilation to complete successfully, the event source needs to be closed explicitly. See the developer documentation on fixing precompilation hangs for more help.
│
│ [pid 27832] waiting for IO to finish:
│ Handle type uv_handle_t->data
│ timer 0000024dd59368d0->0000024dd1e8d900
│ This means that a package has started a background task or event source that has not finished running. For precompilation to complete successfully, the event source needs to be closed explicitly. See the developer documentation on fixing precompilation hangs for more help.
└
  4 dependencies errored.
  For a report of the errors see `julia> err`. To retry use `pkg> precompile`

```

It might be some compatibility issue with BlackBoxOptim.jl?

---

<div class="post-metadata">

### Author: ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)
#### Post date: [September 20, 2024, 6:34am UTC](https://discourse.julialang.org/t/parameter-estimation-in-biological-network/119630/6 "2024-09-20T06:34:37Z")

</div>

For this kind of error, try first to restart Julia and precompile again… Maybe it goes away.

[Or remove BlackBoxOptim, I guess it is not required for PEtab.]

---

<div class="post-metadata">

### Author: ![Nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@Nick1](https://discourse.julialang.org/u/Nick1)
#### Post date: [September 20, 2024, 6:42am UTC](https://discourse.julialang.org/t/parameter-estimation-in-biological-network/119630/7 "2024-09-20T06:42:49Z")

</div>

I tried restarting Julia, removing BlackBoxOptim and reinstalling PEtab.jl but still got the following:

```julia
Precompiling project...
  ✗ PEtab → PEtabOptimizationExtension
  ✗ PEtab → PEtabOptimExtension
  ✗ PEtab → PEtabPlotsExtension
  42 dependencies successfully precompiled in 92 seconds. 549 already precompiled. 1 skipped during auto due to previous errors.

```

---

<div class="post-metadata">

### Author: ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)
#### Post date: [September 20, 2024, 6:55am UTC](https://discourse.julialang.org/t/parameter-estimation-in-biological-network/119630/8 "2024-09-20T06:55:37Z")

</div>

But does the code work? (I am maybe forgetful, but I had in mind sometimes it just happens to work even though some precompiling fails; or at least you get a better error msg.)
