fix(optim): refuse non-finite bounds in differential evolution
Assisted-by: DeepSeek V4.1 Flash
This commit is contained in:
+6
-2
@@ -58,8 +58,12 @@ func MinimiseDifferentialEvolution(f func(*core.Array) (float64, error),
|
||||
return nil, 0, base.Errf("%s: complex bounds are not supported", name)
|
||||
}
|
||||
for i := range n {
|
||||
if !(upper.FloatAt(i) > lower.FloatAt(i)) {
|
||||
return nil, 0, base.Errf("%s: bound %d runs from %g to %g", name, i, lower.FloatAt(i), upper.FloatAt(i))
|
||||
lo, up := lower.FloatAt(i), upper.FloatAt(i)
|
||||
// An infinite side has no uniform draw: the population would be
|
||||
// born NaN and the best point would come back NaN with no error,
|
||||
// so a non-finite bound is degenerate exactly as a crossed one is.
|
||||
if math.IsNaN(lo) || math.IsNaN(up) || math.IsInf(lo, 0) || math.IsInf(up, 0) || !(up > lo) {
|
||||
return nil, 0, base.Errf("%s: bound %d runs from %g to %g", name, i, lo, up)
|
||||
}
|
||||
}
|
||||
pop := opts.Population
|
||||
|
||||
Reference in New Issue
Block a user