# Bounded optimization without prior knowledge of bounds

**URL:** <https://discourse.julialang.org/t/bounded-optimization-without-prior-knowledge-of-bounds/87385>\
**Category:** General Usage\
**Tags:** optimization\
**Created:** [September 16, 2022, 7:35pm UTC](https://discourse.julialang.org/t/bounded-optimization-without-prior-knowledge-of-bounds/87385 "2022-09-16T19:35:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![structural](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@structural](https://discourse.julialang.org/u/structural)\
**Post date:** [September 16, 2022, 7:35pm UTC](https://discourse.julialang.org/t/bounded-optimization-without-prior-knowledge-of-bounds/87385/1 "2022-09-16T19:35:39Z")

</div>

I need to optimize a function f(x) over some region A. The function returns an error if evaluated outside the region. However I do not know the region A beforehand. I can only tell whether x' \in A by evaluating f(x') and checking whether it returns an error.

Given this, would the following procedure give me the argmax over A? Here is a pseudo algorithm.

1. Begin by evaluating f at a guess x\_0.
2. If f(x\_1)\<f(x\_0), update x to x\_1. If f(x\_1) returns an error, define f(x\_1) = 10^5 or some other arbitrarily large number and continue searching by guessing another value for x.

Here is an example of some Julia code to illustrate the issue. In words, I am trying to optimize function `objective_function(y1, y2)` over `y1, y2`. For every guess of `y2` I get `y1` through a contraction mapping. However the contraction mapping may fail to find a fixed point for certain values of `y2`. When this happens I assign an arbitrarily large value to the objective function and continue with the optimization.

```julia
## Define functions
function function_to_be_contraction_mapped(x1, x2)
   # return something
end

function objective_function(y1, y2)
   # return something
end

function contraction_mapping(a)
   y = zeros(Float64, length(a))
   fp_anderson = fixed_point(x1 -> function_to_be_contraction_mapped(x1, a), zeros(Float64, 10); Algorithm = :Anderson)
         
   if fp_anderson.FixedPoint_!==missing
      return objective_function(fp_anderson.FixedPoint_, x2)
   elseif fp_anderson.FixedPoint_===missing
      return 1E6
   end
end

## Optimize
Optim.minimizer(contraction_mapping, zeros(Flat64, 10))

```

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [September 16, 2022, 7:47pm UTC](https://discourse.julialang.org/t/bounded-optimization-without-prior-knowledge-of-bounds/87385/2 "2022-09-16T19:47:59Z")

</div>

A sophisticated strategy roughly similar to the one you mention (but with mechanisms that provide certain convergence guarantees) is implemented in NOMAD.jl.

A model can be used to construct at each iteration that may suggest new promising iterates faster than the standard search strategy.
