# Blackbox optim: customize stopping rule

**URL:** https://discourse.julialang.org/t/blackbox-optim-customize-stopping-rule/124440
**Category:** General Usage
**Tags:** optimization
**Created:** [January 5, 2025, 5:44am UTC](https://discourse.julialang.org/t/blackbox-optim-customize-stopping-rule/124440 "2025-01-05T05:44:24Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jgr](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@jgr](https://discourse.julialang.org/u/jgr)
#### Post date: [January 5, 2025, 5:44am UTC](https://discourse.julialang.org/t/blackbox-optim-customize-stopping-rule/124440/1 "2025-01-05T05:44:24Z")

</div>

Hi, I am using “bboptimize” in Julia for minimization. I tried to change the tolerance rule by setting `FitnessTol=tol,`

```julia
result = bboptimize(funcblackbox;
        MaxSteps = maxiter,
        FitnessTol=tol)

```

The problem I have is the algorithm never converges. I tried to let `tol=Inf` but the algorithm still keeps running until the maxiter.

I also tried to set up my own stopping rule: I only need the “percentage” change between two iterations to be small enough, there is what I did

```julia
last_fitness = Ref(Inf)
    custom_stop_condition = (state) -> begin
        current_fitness = best_fitness(state)
        percent_change = abs(current_fitness - last_fitness[]) / abs(last_fitness[])
        println("Iteration ", BlackBoxOptim.iteration(state),
                ": Best fitness = ", current_fitness,
                ", Percent change = ", percent_change * 100, "%")
        last_fitness[] = current_fitness
        return percent_change < percent_tolerance
    end

    result = bboptimize(func_blackbox;
                        MaxSteps = maxiter,
                        StopFunction = custom_stop_condition)

```

This does not work either. Does anyone know how to change the tolerance or set up our own stopping rule?
