A multi-modal function means a function with more than one “mode” or optima (e.g. valley).
Multimodal functions are non-convex.
There may be one global optima and one or more local or deceptive optima. Alternately, there may be multiple global optima, i.e. multiple different inputs that result in the same minimal output of the function.
Let’s look at a few examples of multi-modal functions.
Multimodal Function 1
The range is bounded to -2.7 and 7.5 and the optimal input value is 5.145735.
multimodal function
from numpy import sin
from numpy import arange
from matplotlib import pyplot
objective function
def objective(x):
return sin(x) + sin((10.0 / 3.0) * x)
define range for input
r_min, r_max = -2.7, 7.5
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 = 5.145735
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
multimodal function
from numpy import sin
from numpy import arange
from matplotlib import pyplot
objective function
def objective(x):
return sin(x) + sin((10.0 / 3.0) * x)
define range for input
r_min, r_max = -2.7, 7.5
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 = 5.145735
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 Multimodal Optimization Function 1
Line Plot of Multimodal Optimization Function 1
Multimodal Function 2
The range is bounded to 0.0 and 1.2 and the optimal input value is 0.96609.
multimodal function
from numpy import sin
from numpy import arange
from matplotlib import pyplot
objective function
def objective(x):
return -(1.4 - 3.0 * x) * sin(18.0 * x)
define range for input
r_min, r_max = 0.0, 1.2
sample input range uniformly at 0.01 increments
inputs = arange(r_min, r_max, 0.01)
compute targets
results = objective(inputs)
create a line plot of input vs result
pyplot.plot(inputs, results)
define optimal input value
x_optima = 0.96609
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
multimodal function
from numpy import sin
from numpy import arange
from matplotlib import pyplot
objective function
def objective(x):
return -(1.4 - 3.0 * x) * sin(18.0 * x)
define range for input
r_min, r_max = 0.0, 1.2
sample input range uniformly at 0.01 increments
inputs = arange(r_min, r_max, 0.01)
compute targets
results = objective(inputs)
create a line plot of input vs result
pyplot.plot(inputs, results)
define optimal input value
x_optima = 0.96609
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 Multimodal Optimization Function 2
Line Plot of Multimodal Optimization Function 2
Multimodal Function 3
The range is bounded to 0.0 and 10.0 and the optimal input value is 7.9787.
multimodal function
from numpy import sin
from numpy import arange
from matplotlib import pyplot
objective function
def objective(x):
return -x * sin(x)
define range for input
r_min, r_max = 0.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 = 7.9787
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
multimodal function
from numpy import sin
from numpy import arange
from matplotlib import pyplot
objective function
def objective(x):
return -x * sin(x)
define range for input
r_min, r_max = 0.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 = 7.9787
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 Multimodal Optimization Function 3