Skip to content

Commit 60f3874

Browse files
committed
Import fixes, some tests now pass.
1 parent 339fc5d commit 60f3874

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/qinfer/tests/test_optimiser.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,30 @@
3535
import numpy as np
3636
import random as rnd
3737

38+
from qinfer.tests.base_test import DerandomizedTestCase
39+
3840
import qinfer.rb as rb
3941
import qinfer.distributions as dist
4042

41-
from qinfer.tests.base_test import DerandomizedTestCase
43+
from qinfer.hyper_heuristic_optimisers import ParticleSwarmOptimizer
44+
from qinfer.expdesign import ExpSparseHeuristic
4245

4346
## CLASSES ####################################################################
4447

4548
class TestPSO(DerandomizedTestCase):
4649

4750
def test_pso_quad(self):
48-
f_quad = lambda x: numpy.sum(10 * (x - 0.5) ** 2)
51+
f_quad = lambda x: np.sum(10 * (x - 0.5) ** 2)
4952
hh_opt = ParticleSwarmOptimizer(['x', 'y', 'z', 'a'], fitness_function=f_quad)
5053
hh_opt()
5154

5255
def test_pso_sin_sq(self):
53-
f_sin_sq = lambda x: numpy.sum(np.sin(x - 0.2) ** 2)
56+
f_sin_sq = lambda x: np.sum(np.sin(x - 0.2) ** 2)
5457
hh_opt = ParticleSwarmOptimizer(['x', 'y', 'z', 'a'], fitness_function=f_sin_sq)
5558
hh_opt()
5659

5760
def test_pso_rosenbrock(self):
58-
f_rosenbrock = lambda x: numpy.sum([
61+
f_rosenbrock = lambda x: np.sum([
5962
((x[i + 1] - x[i] ** 2) ** 2 + (1 - x[i])** 2) / len(x)
6063
for i in range(len(x) - 1)
6164
])
@@ -81,14 +84,12 @@ def test_pso_perf_test_multiple_short(self):
8184
)
8285

8386
#Heuristic used in the experiment
84-
heuristic_class = qi.expdesign.ExpSparseHeuristic
87+
heuristic_class = ExpSparseHeuristic
8588

8689
#Heuristic Parameters
8790
params = ['base', 'scale']
8891

8992
#Fitness function to evaluate the performance of the experiment
90-
EXPERIMENT_FITNESS = lambda performance: performance['loss'][:,-1].mean(axis=0)
91-
9293
hh_opt = ParticleSwarmOptimizer(params,
9394
n_trials = n_trials,
9495
n_particles = n_particles,

0 commit comments

Comments
 (0)