Passed
Pull Request — master (#101)
by Simon
02:06
created

test_function.SphereFunction.__init__()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
import numpy as np
2
3
from hyperactive import BaseExperiment
4
5
6
class SphereFunction(BaseExperiment):
7
    def __init__(self, const, n_dim=2):
8
        super().__init__()
9
10
        self.const = const
11
        self.n_dim = n_dim
12
13
    def _score(self, **params):
14
        return np.sum(np.array(params) ** 2) + self.const
15
16
17
class AckleyFunction(BaseExperiment):
18
    def __init__(self, A):
19
        super().__init__()
20
        self.A = A
21
22 View Code Duplication
    def _score(self, **params):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
23
        x = params["x0"]
24
        y = params["x1"]
25
26
        loss1 = -self.A * np.exp(-0.2 * np.sqrt(0.5 * (x * x + y * y)))
27
        loss2 = -np.exp(0.5 * (np.cos(2 * np.pi * x) + np.cos(2 * np.pi * y)))
28
        loss3 = np.exp(1)
29
        loss4 = self.A
30
31
        return -(loss1 + loss2 + loss3 + loss4)
32