fix the randomness in iterating a dict, and supply fixed random seed for multiclass extension
# =============================================================================
import numpy as np
+from qiskit.aqua import aqua_globals
from qiskit.aqua import run_algorithm
from qiskit.aqua.input import SVMInput
from test.common import QiskitAquaTestCase
@@ -24,6 +25,7 @@ from test.common import QiskitAquaTestCase
class TestSVMClassical(QiskitAquaTestCase):
def setUp(self):
super().setUp()
+ aqua_globals.random_seed = 10598
pass
def test_classical_binary(self):
@@ -89,7 +91,7 @@ class TestSVMClassical(QiskitAquaTestCase):
[0.06195634, -0.23262325],
[0.06183066, -0.53376975]])}
- temp = [test_input[k] for k in test_input]
+ temp = [test_input[k] for k in sorted(test_input)]
total_array = np.concatenate(temp)
params = {
@@ -102,6 +104,7 @@ class TestSVMClassical(QiskitAquaTestCase):
algo_input = SVMInput(training_input, test_input, total_array)
result = run_algorithm(params, algo_input)
+ print(result)
self.assertEqual(result['testing_accuracy'], 1.0)
self.assertEqual(result['predicted_classes'],
['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A',
@@ -200,7 +203,7 @@ class TestSVMClassical(QiskitAquaTestCase):
[-0.73856328, 0.80699537],
[-0.66489165, 0.1181712]])}
- temp = [test_input[k] for k in test_input]
+ temp = [test_input[k] for k in sorted(test_input)]
total_array = np.concatenate(temp)
params = {
@@ -312,7 +315,7 @@ class TestSVMClassical(QiskitAquaTestCase):
[-0.73856328, 0.80699537],
[-0.66489165, 0.1181712]])}
- temp = [test_input[k] for k in test_input]
+ temp = [test_input[k] for k in sorted(test_input)]
total_array = np.concatenate(temp)
params = {
@@ -426,7 +429,7 @@ class TestSVMClassical(QiskitAquaTestCase):
[-0.73856328, 0.80699537],
[-0.66489165, 0.1181712]])}
- temp = [test_input[k] for k in test_input]
+ temp = [test_input[k] for k in sorted(test_input)]
total_array = np.concatenate(temp)
params = {
