Non-Convex Unimodal Functions

A function is non-convex if a line cannot be drawn between two points in the domain and the line remains in the domain.

This means it is possible to find two points in the domain where a line between them crosses a line plot of the function.

Typically, if a plot of a one-dimensional function has more than one hill or valley, then we know immediately that the function is non-convex. Nevertheless, a non-convex function may or may not be unimodal.

Most real functions that we’re interested in optimizing are non-convex.

The range for the function below is bounded to -10.0 and 10.0 and the optimal input value is 0.67956.

non-convex unimodal optimization function

from numpy import arange
from numpy import sin
from numpy import exp
from matplotlib import pyplot

objective function

def objective(x):
return -(x + sin(x)) * exp(-x**2.0)

define range for input

r_min, r_max = -10.0, 10.0

sample input range uniformly at 0.1 increments

inputs = arange(r_min, r_max, 0.1)

compute targets

results = objective(inputs)

create a line plot of input vs result

pyplot.plot(inputs, results)

define optimal input value

x_optima = 0.67956

draw a vertical line at the optimal input

pyplot.axvline(x=x_optima, ls=’–’, color=‘red’)

show the plot

pyplot.show()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

non-convex unimodal optimization function

from numpy import arange
from numpy import sin
from numpy import exp
from matplotlib import pyplot

objective function

def objective(x):
return -(x + sin(x)) * exp(-x**2.0)

define range for input

r_min, r_max = -10.0, 10.0

sample input range uniformly at 0.1 increments

inputs = arange(r_min, r_max, 0.1)

compute targets

results = objective(inputs)

create a line plot of input vs result

pyplot.plot(inputs, results)

define optimal input value

x_optima = 0.67956

draw a vertical line at the optimal input

pyplot.axvline(x=x_optima, ls=’–’, color=‘red’)

show the plot

pyplot.show()
Running the example creates a line plot of the function and marks the optima with a red line.

Line Plot of Non-Convex Unimodal Optimization Function