Code Duplication    Length = 75-77 lines in 5 locations

NiaPy/benchmarks/infinity.py 1 location

@@ 10-86 (lines=77) @@
7
8
__all__ = ['Infinity']
9
10
class Infinity(Benchmark):
11
	r"""Implementations of Infinity function.
12
13
	Date: 2018
14
15
	Author: Klemen Berkovič
16
17
	License: MIT
18
19
	Function:
20
	**Infinity Function**
21
22
		:math:`f(\textbf{x}) = \sum_{i = 1}^D x_i^6 \left( \sin \left( \frac{1}{x_i} \right) + 2 \right)`
23
24
		**Input domain:**
25
		The function can be defined on any input domain but it is usually
26
		evaluated on the hypercube :math:`x_i ∈ [-1, 1]`, for all :math:`i = 1, 2,..., D`.
27
28
		**Global minimum:**
29
		:math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
30
31
	LaTeX formats:
32
		Inline:
33
				$f(\textbf{x}) = \sum_{i = 1}^D x_i^6 \left( \sin \left( \frac{1}{x_i} \right) + 2 \right)$
34
35
		Equation:
36
				\begin{equation} f(\textbf{x}) = \sum_{i = 1}^D x_i^6 \left( \sin \left( \frac{1}{x_i} \right) + 2 \right) \end{equation}
37
38
		Domain:
39
				$-1 \leq x_i \leq 1$
40
41
	Reference:
42
		http://infinity77.net/global_optimization/test_functions_nd_I.html#go_benchmark.Infinity
43
	"""
44
	Name = ['Infinity']
45
46
	def __init__(self, Lower=-1.0, Upper=1.0):
47
		r"""Initialize of Infinity benchmark.
48
49
		Args:
50
			Lower (Optional[float]): Lower bound of problem.
51
			Upper (Optional[float]): Upper bound of problem.
52
53
		See Also:
54
			:func:`NiaPy.benchmarks.Benchmark.__init__`
55
		"""
56
		Benchmark.__init__(self, Lower, Upper)
57
58
	@staticmethod
59
	def latex_code():
60
		r"""Return the latex code of the problem.
61
62
		Returns:
63
			str: Latex code
64
		"""
65
		return r'''$f(\textbf{x}) = \sum_{i = 1}^D x_i^6 \left( \sin \left( \frac{1}{x_i} \right) + 2 \right)$'''
66
67
	def function(self):
68
		r"""Return benchmark evaluation function.
69
70
		Returns:
71
			Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function
72
		"""
73
		def f(D, X):
74
			r"""Fitness function.
75
76
			Args:
77
				D (int): Dimensionality of the problem
78
				sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check.
79
80
			Returns:
81
				float: Fitness value for the solution.
82
			"""
83
			val = 0.0
84
			for i in range(D): val += X[i] ** 6 * (sin(1 / X[i]) + 2)
85
			return val
86
		return f
87
88
# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3
89

NiaPy/benchmarks/bentcigar.py 1 location

@@ 9-85 (lines=77) @@
6
7
__all__ = ['BentCigar']
8
9
class BentCigar(Benchmark):
10
	r"""Implementations of Bent Cigar functions.
11
12
	Date: 2018
13
14
	Author: Klemen Berkovič
15
16
	License: MIT
17
18
	Function:
19
	**Bent Cigar Function**
20
21
		:math:`f(\textbf{x}) = x_1^2 + 10^6 \sum_{i=2}^D x_i^2`
22
23
		**Input domain:**
24
		The function can be defined on any input domain but it is usually
25
		evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`.
26
27
		**Global minimum:**
28
		:math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
29
30
	LaTeX formats:
31
		Inline:
32
				$f(\textbf{x}) = x_1^2 + 10^6 \sum_{i=2}^D x_i^2$
33
34
		Equation:
35
				\begin{equation} f(\textbf{x}) = x_1^2 + 10^6 \sum_{i=2}^D x_i^2 \end{equation}
36
37
		Domain:
38
				$-100 \leq x_i \leq 100$
39
40
	Reference:
41
		http://www5.zzu.edu.cn/__local/A/69/BC/D3B5DFE94CD2574B38AD7CD1D12_C802DAFE_BC0C0.pdf
42
	"""
43
	Name = ['BentCigar']
44
45
	def __init__(self, Lower=-100.0, Upper=100.0):
46
		r"""Initialize of Bent Cigar benchmark.
47
48
		Args:
49
			Lower (Optional[float]): Lower bound of problem.
50
			Upper (Optional[float]): Upper bound of problem.
51
52
		See Also:
53
			:func:`NiaPy.benchmarks.Benchmark.__init__`
54
		"""
55
		Benchmark.__init__(self, Lower, Upper)
56
57
	@staticmethod
58
	def latex_code():
59
		r"""Return the latex code of the problem.
60
61
		Returns:
62
			str: Latex code
63
		"""
64
		return r'''$f(\textbf{x}) = x_1^2 + 10^6 \sum_{i=2}^D x_i^2$'''
65
66
	def function(slef):
67
		r"""Return benchmark evaluation function.
68
69
		Returns:
70
			Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function
71
		"""
72
		def f(D, sol):
73
			r"""Fitness function.
74
75
			Args:
76
				D (int): Dimensionality of the problem
77
				sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check.
78
79
			Returns:
80
				float: Fitness value for the solution.
81
			"""
82
			val = 0.0
83
			for i in range(1, D): val += sol[i] ** 2
84
			return sol[0] ** 2 + 10 ** 6 * val
85
		return f
86
87
# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3
88

NiaPy/benchmarks/discus.py 1 location

@@ 9-85 (lines=77) @@
6
7
__all__ = ['Discus']
8
9
class Discus(Benchmark):
10
	r"""Implementations of Discus functions.
11
12
	Date: 2018
13
14
	Author: Klemen Berkovič
15
16
	License: MIT
17
18
	Function:
19
	**Discus Function**
20
21
		:math:`f(\textbf{x}) = x_1^2 10^6 + \sum_{i=2}^D x_i^2`
22
23
		**Input domain:**
24
		The function can be defined on any input domain but it is usually
25
		evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`.
26
27
		**Global minimum:**
28
		:math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
29
30
	LaTeX formats:
31
		Inline:
32
				$f(\textbf{x}) = x_1^2 10^6 + \sum_{i=2}^D x_i^2$
33
34
		Equation:
35
				\begin{equation} f(\textbf{x}) = x_1^2 10^6 + \sum_{i=2}^D x_i^2 \end{equation}
36
37
		Domain:
38
				$-100 \leq x_i \leq 100$
39
40
	Reference:
41
	http://www5.zzu.edu.cn/__local/A/69/BC/D3B5DFE94CD2574B38AD7CD1D12_C802DAFE_BC0C0.pdf
42
	"""
43
	Name = ['Discus']
44
45
	def __init__(self, Lower=-100.0, Upper=100.0):
46
		r"""Initialize of Discus benchmark.
47
48
		Args:
49
			Lower (Optional[float]): Lower bound of problem.
50
			Upper (Optional[float]): Upper bound of problem.
51
52
		See Also:
53
			:func:`NiaPy.benchmarks.Benchmark.__init__`
54
		"""
55
		Benchmark.__init__(self, Lower, Upper)
56
57
	@staticmethod
58
	def latex_code():
59
		r"""Return the latex code of the problem.
60
61
		Returns:
62
			str: Latex code
63
		"""
64
		return r'''$f(\textbf{x}) = x_1^2 10^6 + \sum_{i=2}^D x_i^2$'''
65
66
	def function(self):
67
		r"""Return benchmark evaluation function.
68
69
		Returns:
70
			Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function
71
		"""
72
		def f(D, sol):
73
			r"""Fitness function.
74
75
			Args:
76
				D (int): Dimensionality of the problem
77
				sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check.
78
79
			Returns:
80
				float: Fitness value for the solution.
81
			"""
82
			val = 0.0
83
			for i in range(1, D): val += sol[i] ** 2
84
			return sol[0] * 10 ** 6 + val
85
		return f
86
87
# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3
88

NiaPy/benchmarks/elliptic.py 1 location

@@ 9-85 (lines=77) @@
6
7
__all__ = ['Elliptic']
8
9
class Elliptic(Benchmark):
10
	r"""Implementations of High Conditioned Elliptic functions.
11
12
	Date: 2018
13
14
	Author: Klemen Berkovič
15
16
	License: MIT
17
18
	Function:
19
	**High Conditioned Elliptic Function**
20
21
		:math:`f(\textbf{x}) = \sum_{i=1}^D \left( 10^6 \right)^{ \frac{i - 1}{D - 1} } x_i^2`
22
23
		**Input domain:**
24
		The function can be defined on any input domain but it is usually
25
		evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`.
26
27
		**Global minimum:**
28
		:math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
29
30
	LaTeX formats:
31
		Inline:
32
				$f(\textbf{x}) = \sum_{i=1}^D \left( 10^6 \right)^{ \frac{i - 1}{D - 1} } x_i^2$
33
34
		Equation:
35
				\begin{equation} f(\textbf{x}) = \sum_{i=1}^D \left( 10^6 \right)^{ \frac{i - 1}{D - 1} } x_i^2 \end{equation}
36
37
		Domain:
38
				$-100 \leq x_i \leq 100$
39
40
	Reference:
41
	http://www5.zzu.edu.cn/__local/A/69/BC/D3B5DFE94CD2574B38AD7CD1D12_C802DAFE_BC0C0.pdf
42
	"""
43
	Name = ['Elliptic']
44
45
	def __init__(self, Lower=-100.0, Upper=100.0):
46
		r"""Initialize of High Conditioned Elliptic benchmark.
47
48
		Args:
49
			Lower (Optional[float]): Lower bound of problem.
50
			Upper (Optional[float]): Upper bound of problem.
51
52
		See Also:
53
			:func:`NiaPy.benchmarks.Benchmark.__init__`
54
		"""
55
		Benchmark.__init__(self, Lower, Upper)
56
57
	@staticmethod
58
	def latex_code():
59
		r"""Return the latex code of the problem.
60
61
		Returns:
62
			str: Latex code
63
		"""
64
		return r'''$f(\textbf{x}) = \sum_{i=1}^D \left( 10^6 \right)^{ \frac{i - 1}{D - 1} } x_i^2$'''
65
66
	def function(self):
67
		r"""Return benchmark evaluation function.
68
69
		Returns:
70
			Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function
71
		"""
72
		def evaluate(D, sol):
73
			r"""Fitness function.
74
75
			Args:
76
				D (int): Dimensionality of the problem
77
				sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check.
78
79
			Returns:
80
				float: Fitness value for the solution.
81
			"""
82
			val = 0.0
83
			for i in range(D): val += (10 ** 6) ** (i / (D - 1)) * sol[i]
84
			return val
85
		return evaluate
86
87
# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3
88

NiaPy/benchmarks/sphere.py 1 location

@@ 89-163 (lines=75) @@
86
			return val
87
		return evaluate
88
89
class Sphere2(Benchmark):
90
	r"""Implementation of Sphere with different powers function.
91
92
	Date: 2018
93
94
	Authors: Klemen Berkovič
95
96
	License: MIT
97
98
	Function: **Sun of different powers function**
99
100
		:math:`f(\textbf{x}) = \sum_{i = 1}^D \lvert x_i \rvert^{i + 1}`
101
102
		**Input domain:**
103
		The function can be defined on any input domain but it is usually
104
		evaluated on the hypercube :math:`x_i ∈ [-1, 1]`, for all :math:`i = 1, 2,..., D`.
105
106
		**Global minimum:** :math:`f(x^*) = 0`, at :math:`x^* = (0,...,0)`
107
108
	LaTeX formats:
109
		Inline:
110
				$f(\textbf{x}) = \sum_{i = 1}^D \lvert x_i \rvert^{i + 1}$
111
112
		Equation:
113
				\begin{equation} f(\textbf{x}) = \sum_{i = 1}^D \lvert x_i \rvert^{i + 1} \end{equation}
114
115
		Domain:
116
				$-1 \leq x_i \leq 1$
117
118
	Reference URL:
119
		https://www.sfu.ca/~ssurjano/sumpow.html
120
	"""
121
	Name = ['Sphere2']
122
123
	def __init__(self, Lower=-1., Upper=1.):
124
		r"""Initialize of Sphere2 benchmark.
125
126
		Args:
127
			Lower (Optional[float]): Lower bound of problem.
128
			Upper (Optional[float]): Upper bound of problem.
129
130
		See Also:
131
			:func:`NiaPy.benchmarks.Benchmark.__init__`
132
		"""
133
		Benchmark.__init__(self, Lower, Upper)
134
135
	@staticmethod
136
	def latex_code():
137
		r"""Return the latex code of the problem.
138
139
		Returns:
140
			str: Latex code
141
		"""
142
		return r'''$f(\textbf{x}) = \sum_{i = 1}^D \lvert x_i \rvert^{i + 1}$'''
143
144
	def function(self):
145
		r"""Return benchmark evaluation function.
146
147
		Returns:
148
			Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function
149
		"""
150
		def evaluate(D, sol):
151
			r"""Fitness function.
152
153
			Args:
154
				D (int): Dimensionality of the problem
155
				sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check.
156
157
			Returns:
158
				float: Fitness value for the solution.
159
			"""
160
			val = 0.0
161
			for i in range(D): val += abs(sol[i]) ** (i + 2)
162
			return val
163
		return evaluate
164
165
class Sphere3(Benchmark):
166
	r"""Implementation of rotated hyper-ellipsoid function.