# Bayesian Optimization with Julia

**URL:** <https://discourse.julialang.org/t/bayesian-optimization-with-julia/75143>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 24, 2022, 7:51pm UTC](https://discourse.julialang.org/t/bayesian-optimization-with-julia/75143 "2022-01-24T19:51:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![xspeng](https://avatars.discourse-cdn.com/v4/letter/x/90ced4/32.png) [@xspeng](https://discourse.julialang.org/u/xspeng)\
**Post date:** [January 24, 2022, 7:51pm UTC](https://discourse.julialang.org/t/bayesian-optimization-with-julia/75143/1 "2022-01-24T19:51:54Z")

</div>

Hi, anyone knows how to use bayesian optimization to get the minimum value of a blackbox function, I read the manual of BayesianOptimization.jl  
[https://github.com/jbrea/BayesianOptimization.jl](https://github.com/jbrea/BayesianOptimization.jl)  
but it’s not easy to understand, and I don’t want to optimize the hyperparameters, I just have a function that can output a value once a group of parameters are input, and I want to use bayesian optimization to get the minimum value and the corresponding parameters. Can anyone give me an easy example, e.g. for` f=x^2+(y-2)^2`, we know the minimum parameter is` x=0,y=2`, I can use bayesopt function in matlab and get this parameter, but for Julia, I don’t know how to do it  
Here is a example of Matlab

```julia
xrange = optimizableVariable('v1',[-2,2],'Type','real');
yrange = optimizableVariable('v2',[-5,5],'Type','real');

var=[xrange yrange];

bayesObject = bayesopt(@(tbl)mdlfun(tbl),var,...
    'MaxObjectiveEvaluations',50); % iteration numbers

function rel = mdlfun(tbl)

x=tbl.v1;
y=tbl.v2;
rel=f(x,y);

end

function output=f(x,y)
output=x^2+(y-2)^2;
end

```

Can anyone help me to re-write it with Julia

---

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [January 24, 2022, 8:33pm UTC](https://discourse.julialang.org/t/bayesian-optimization-with-julia/75143/2 "2022-01-24T20:33:23Z")

</div>

We do not yet have good defaults in BayesianOptimization.jl, but it is planned to implement some as a [GSOC project](https://julialang.org/jsoc/gsoc/bayesopt/).

For now, you can copy-paste the example from the readme and replace `f(x) = sum((x .- 1).^2) + randn()` with the function you want to optimize, e.g. `f(x) = x[1]^2 + (x[2] - 2)^2`.

> [@xspeng](#):
>
> I don’t want to optimize the hyperparameters

You do not need to optimize the hyperparameters, but you should define them. Prior knowledge helps the optimization.

Note that [Nonconvex.jl](https://julianonconvex.github.io/Nonconvex.jl/stable/algorithms/surrogate/) also offers Bayesian optimization (so far I have not used it though).

---

<div class="post-metadata">

**Author:** ![xspeng](https://avatars.discourse-cdn.com/v4/letter/x/90ced4/32.png) [@xspeng](https://discourse.julialang.org/u/xspeng)\
**Post date:** [January 24, 2022, 8:48pm UTC](https://discourse.julialang.org/t/bayesian-optimization-with-julia/75143/3 "2022-01-24T20:48:24Z")

</div>

I have some additional questions about your example, if I have more than 2 parameters, do I need to change position `1` and `2` in the graph accordingly? Why it needs to evaluate the function for each input 5 times? Finally, for all the other parts, just keep the value, right?

 ![Capture](https://global.discourse-cdn.com/julialang/original/3X/d/9/d98d1153e6290bdd78f57434f7d1cf727982fcff.png)

---

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [January 24, 2022, 9:02pm UTC](https://discourse.julialang.org/t/bayesian-optimization-with-julia/75143/4 "2022-01-24T21:02:18Z")

</div>

1. & 2.: yes. But the kernel should also be adapted. E.g. `kernel = SEArd(zeros(7), 5.)` or `kernel = SEIso(0., 5.)` and `kernbounds` should also be adapted (see `GaussianProcesses.get_param_names(model.kernel)`). Only for noisy functions it may make sense to have `repetitions > 1` (the default is 1).

---

<div class="post-metadata">

**Author:** ![afishy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/afishy/32/18870_2.png) [@afishy](https://discourse.julialang.org/u/afishy)\
**Post date:** [January 25, 2022, 3:50am UTC](https://discourse.julialang.org/t/bayesian-optimization-with-julia/75143/5 "2022-01-25T03:50:34Z")

</div>

It looks like [Hyperopt.jl](https://github.com/baggepinnen/Hyperopt.jl) has a Bayesian optimization method for searching through model hyper-parameters, if that’s the kind of thing you’re looking for.

---

<div class="post-metadata">

**Author:** ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Post date:** [July 14, 2022, 7:31am UTC](https://discourse.julialang.org/t/bayesian-optimization-with-julia/75143/6 "2022-07-14T07:31:38Z")

</div>

But note that it currently only supports optimizing continous numeric (floating point) values.

---

<div class="post-metadata">

**Author:** ![Resul.Akay](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Resul.Akay](https://discourse.julialang.org/u/Resul.Akay)\
**Post date:** [December 22, 2025, 9:08pm UTC](https://discourse.julialang.org/t/bayesian-optimization-with-julia/75143/7 "2025-12-22T21:08:34Z")

</div>

> [@jbrea](#):
>
> BayesianOptimization.jl

Is package still maintained?

Do we have a stable Bayesian Optimization package in Julia for Machine Learning hyper parameter tuning tasks ideally does search distributed?

Example: [[1206.2944] Practical Bayesian Optimization of Machine Learning Algorithms](https://arxiv.org/abs/1206.2944)
