A function may have a discontinuity, meaning that the smooth change in inputs to the function may result in non-smooth changes in the output.
We might refer to functions with this property as non-smooth functions or discontinuous functions.
There are many different types of discontinuity, although one common example is a jump or acute change in direction in the output values of the function, which is easy to see in a plot of the function.
Discontinuous Function
The range is bounded to -2.0 and 2.0 and the optimal input value is 1.0.
non-smooth optimization function
from numpy import arange
from matplotlib import pyplot
objective function
def objective(x):
if x > 1.0:
return x**2.0
elif x == 1.0:
return 0.0
return 2.0 - x
define range for input
r_min, r_max = -2.0, 2.0
sample input range uniformly at 0.1 increments
inputs = arange(r_min, r_max, 0.1)
compute targets
results = [objective(x) for x in inputs]
create a line plot of input vs result
pyplot.plot(inputs, results)
define optimal input value
x_optima = 1.0
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
25
26
non-smooth optimization function
from numpy import arange
from matplotlib import pyplot
objective function
def objective(x):
if x > 1.0:
return x**2.0
elif x == 1.0:
return 0.0
return 2.0 - x
define range for input
r_min, r_max = -2.0, 2.0
sample input range uniformly at 0.1 increments
inputs = arange(r_min, r_max, 0.1)
compute targets
results = [objective(x) for x in inputs]
create a line plot of input vs result
pyplot.plot(inputs, results)
define optimal input value
x_optima = 1.0
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 Discontinuous Optimization Function