def test_modelmatrix(self): al = oapackage.exampleArray(1, 0) sizes = oapackage.array2modelmatrix_sizes(al) k = al.n_columns self.assertEqual(sizes, (1, 1 + k, int(1 + k + k * (k - 1) / 2), int(1 + k + k * (k + 1) / 2))) model_matrix = oapackage.array2modelmatrix(al, "main", verbose=0) np.testing.assert_array_equal(2 * np.array(al) - 1, model_matrix[:, 1:]) conf_design = oapackage.exampleArray(41, 0) sizes = oapackage.array2modelmatrix_sizes(conf_design) k = conf_design.n_columns self.assertEqual(sizes, (1, 1 + k, int(1 + k + k * (k - 1) / 2), int(1 + k + k * (k + 1) / 2))) model_matrix = oapackage.array2modelmatrix(conf_design, "i", 0) self.assertTrue(model_matrix.shape[1] == sizes[2]) model_matrix = oapackage.array2modelmatrix(conf_design, "q", 0) last_column = np.array(conf_design)[:, -1] np.testing.assert_array_equal(model_matrix[:, -1], last_column * last_column) self.assertTrue(model_matrix.shape[1] == sizes[3])
def test_is_ortogonal_array(self): al = oapackage.exampleArray(1, 0) self.assertTrue(al.is_orthogonal_array()) al[1, 2] = -1 self.assertFalse(al.is_orthogonal_array()) al = oapackage.exampleArray(41, 0) self.assertFalse(al.is_orthogonal_array())
def test_conference_model_statistics(self): arrays = [ oapackage.exampleArray(idx, 0).selectFirstColumns(4) for idx in [46, 47, 48] ] dsds = [oapackage.conference2DSD(array) for array in arrays] with mock.patch('sys.stdout', new_callable=io.StringIO) as mock_stdout: statistics = [ oapackage.conference.modelStatistics(al, verbose=2) for al in dsds ] stdout = mock_stdout.getvalue() self.assertIn('modelStatistics: condition number: ', stdout) expected = [(0, 0, 0), (0, 0, 0), (1, 17.081221494279234, 1.7610790263409104)] _statistics_equal(statistics, expected) arrays = [ oapackage.exampleArray(idx, 0).selectLastColumns(4) for idx in [46, 47, 48] ] dsds = [oapackage.conference2DSD(array) for array in arrays] statistics = [ oapackage.conference.modelStatistics(al, verbose=0) for al in dsds ] expected = [(1, 17.312358463836613, 1.8538666749267378), (1, 17.312358463836613, 1.8538666749267378), (1, 17.08122149427922, 1.7610790263409093)] _statistics_equal(statistics, expected)
def test_array2eigenModelMatrixMixed(self): array = oapackage.exampleArray(0, 0) r = oapackage.array2eigenModelMatrixMixed(array.selectFirstColumns(1), verbose=0) main_effects = r[0] np.testing.assert_array_equal( main_effects, np.array([[-1., -1., -1., -1., 1., 1., 1., 1.]]).T) array = oapackage.exampleArray(10, 0).selectFirstColumns(2) r = oapackage.array2eigenModelMatrixMixed(array, verbose=0) main_effects = r[0] interaction_model = r[1] np.testing.assert_array_almost_equal( main_effects, np.array([[-1.22474487, -0.70710678, -1.22474487, -0.70710678], [-1.22474487, -0.70710678, 1.22474487, -0.70710678], [-1.22474487, -0.70710678, 0., 1.41421356], [1.22474487, -0.70710678, 1.22474487, -0.70710678], [1.22474487, -0.70710678, 1.22474487, -0.70710678], [1.22474487, -0.70710678, 0., 1.41421356], [0., 1.41421356, -1.22474487, -0.70710678], [0., 1.41421356, -1.22474487, -0.70710678], [0., 1.41421356, 0., 1.41421356]])) np.testing.assert_array_almost_equal( interaction_model, np.array([[1.5, 0.8660254, 0.8660254, 0.5], [-1.5, 0.8660254, -0.8660254, 0.5], [-0., -1.73205081, -0., -1.], [1.5, -0.8660254, -0.8660254, 0.5], [1.5, -0.8660254, -0.8660254, 0.5], [0., 1.73205081, -0., -1.], [-0., -0., -1.73205081, -1.], [-0., -0., -1.73205081, -1.], [0., 0., 0., 2.]]))
def test_double_conference_foldover_permutation(self): al = oapackage.exampleArray(37, 0) expected = [ 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 11, 16, 19, 17, 18, 15, 14, 13, 12 ] permutation = oapackage.double_conference_foldover_permutation(al) self.assertEqual(list(permutation), expected) N = int(al.n_rows / 2) folded = np.array(oapackage.array_link(np.array(al)[permutation, :])) np.testing.assert_array_equal(folded[0:N, :], -folded[N:, :]) expected[5], expected[3] = expected[3], expected[5] expected[-1], expected[4] = expected[4], expected[-1] expected[-3], expected[7] = expected[7], expected[-3] al = oapackage.array_link(np.array(al)[expected, :]) permutation = oapackage.double_conference_foldover_permutation(al) folded = np.array(oapackage.array_link(np.array(al)[permutation, :])) N = int(al.n_rows / 2) np.testing.assert_array_equal(folded[0:N, :], -folded[N:, :]) al = oapackage.exampleArray(45, 0) permutation = oapackage.double_conference_foldover_permutation(al) self.assertEqual(permutation[0], -1) al = oapackage.exampleArray(5, 0) with self.assertRaises(RuntimeError): permutation = oapackage.double_conference_foldover_permutation(al) al = oapackage.array_link(3, 4, 0) with self.assertRaises(RuntimeError): permutation = oapackage.double_conference_foldover_permutation(al)
def test_generateDpage(self): outputdir = tempfile.mkdtemp() allarrays = [ oapackage.exampleArray(2, 0), oapackage.exampleArray(2, 0) ] dds = np.array([A.Defficiencies() for A in allarrays]) arrayclass = oapackage.arraylink2arraydata(allarrays[0]) with mock.patch('sys.stdout', new_callable=io.StringIO) as mock_stdout: page = oapackage.Doptim.generateDpage(outputdir, arrayclass, dds, allarrays, fig=None, optimfunc=[1, 0, 0], nofig=True) if self.guitest and 0: print('test_generateDpage: run gui test') page = oapackage.Doptim.generateDpage(outputdir, arrayclass, dds, allarrays, fig=100, optimfunc=[1, 0, 0], nofig=True) self.assertIsInstance(page, oapackage.markup.page) try: import matplotlib matplotlib.pyplot.close(100) except ImportError: pass
def test_exampleArray(self): # test a selection of the example arrays al = oapackage.exampleArray(5, 0) self.assertTrue(al.md5() == '3885c883d3bee0c7546511255bb5c3ae') al = oapackage.exampleArray(20, 0) self.assertTrue(np.array(al).shape == (24, 3)) al = oapackage.exampleArray(40, 0) self.assertTrue(np.array(al).shape == (14, 5))
def test_isConferenceFoldover(self): al = oapackage.exampleArray(37, 0) self.assertTrue(oapackage.isConferenceFoldover(al)) al[2, 0] = -1 self.assertFalse(oapackage.isConferenceFoldover(al)) al = oapackage.exampleArray(7, 0) self.assertFalse(oapackage.isConferenceFoldover(al)) al = oapackage.exampleArray(45, 0) self.assertFalse(oapackage.isConferenceFoldover(al))
def test_compareJ54(self): al1 = oapackage.exampleArray(24, 0) al2 = oapackage.exampleArray(25, 0) al3 = oapackage.exampleArray(26, 0) self.assertEqual(oapackage.compareJ54(al1, al2), -1) self.assertEqual(oapackage.compareJ54(al2, al1), 1) self.assertEqual(oapackage.compareJ54(al1, al3), 1) self.assertEqual(oapackage.compareJ54(al2, al3), 1)
def test_Jcharacteristics(self): al = oapackage.exampleArray(30, 0) jx = al.Jcharacteristics(4) self.assertEqual(jx, (0, )) jx = al.Jcharacteristics(2) self.assertEqual(jx, (0, 0, 0, 0, 0, 0)) al = oapackage.exampleArray(48, 0).selectFirstColumns(6) jx = al.Jcharacteristics(4) self.assertEqual(jx, (4, 4, 4, 0, 8, -8, 8, 4, -4, -4, 8, 4, -4, 8, -4))
def test_misc_file_operations(self): _, array_filename = tempfile.mkstemp(suffix='.oa') lst = [oapackage.exampleArray(4, 0)] oapackage.writearrayfile(array_filename, lst) assert (oapackage.oahelper.oaIsBinary(array_filename) is False) oapackage.writearrayfile(array_filename, oapackage.exampleArray(4, 0), oapackage.ABINARY) assert (oapackage.oahelper.oaIsBinary(array_filename)) oapackage.oahelper.oainfo(array_filename) _ = oapackage.oahelper.compressOAfile(array_filename)
def test_designStandardError(self): al = oapackage.exampleArray(14, 0) v = oapackage.oahelper.designStandardError(al) self.assertAlmostEqual(v[0], 0.3747931073686535) al = oapackage.exampleArray(9, 0) v = oapackage.oahelper.designStandardError(al) np.testing.assert_array_almost_equal( v[1], np.array([ 0.1679305, 0.17229075, 0.17286095, 0.17287786, 0.17303912, 0.17353519, 0.17548291 ]))
def test_compareLMC(self): al1 = oapackage.exampleArray(24, 0) al2 = oapackage.exampleArray(25, 0) al3 = oapackage.exampleArray(26, 0) self.assertEqual(oapackage.compareLMC(al1, al2), -1) self.assertEqual(oapackage.compareLMC(al2, al1), 1) self.assertEqual(oapackage.compareLMC(al1, al3), 1) al1 = oapackage.exampleArray(2, 0).selectFirstColumns(5) al2 = oapackage.exampleArray(2, 0).selectLastColumns(5) self.assertEqual(oapackage.compareLMC(al1, al2), -1)
def test_LMCcheckOriginal(self): array = oapackage.exampleArray(1) lmc_type = oapackage.LMCcheckOriginal(array) self.assertEqual(lmc_type, oapackage.LMC_MORE) array2 = array.selectColumns([0, 1, 2, 4, 3]) lmc_type = oapackage.LMCcheck(array2) self.assertEqual(lmc_type, oapackage.LMC_LESS) array = oapackage.exampleArray(5, 0) with self.assertRaises(RuntimeError): lmc_type = oapackage.LMCcheckOriginal(array)
def test_LMC(self): al = oapackage.array_link(2, 2, 0) al[1, 1] = -1 self.assertRaises(RuntimeError, oapackage.reduceLMCform, al) al = oapackage.exampleArray(8, 0) alr = oapackage.reduceLMCform(al) self.assertTrue(alr == al) array0 = oapackage.exampleArray(1, 0).selectFirstColumns(3) array = array0.randomperm() reduced_array = oapackage.reduceLMCform(array) self.assertEqual(array0, reduced_array)
def test_array_class_functions(self): al = oapackage.exampleArray(1, 0) self.assertTrue(al.is2level()) self.assertFalse(al.is_mixed_level()) al = oapackage.exampleArray(11, 0) self.assertTrue(al.is2level()) self.assertFalse(al.is_mixed_level()) al = oapackage.array_link(2, 2, 0) al[1, 1] = -1 self.assertFalse(al.is2level()) self.assertFalse(al.is_mixed_level())
def test_array_link_dimensions(self): for example_idx in [0, 2, 6, 10]: al = oapackage.exampleArray(example_idx, 0) self.assertEqual(al.size, al.n_rows * al.n_columns) self.assertEqual(al.shape, (al.n_rows, al.n_columns)) with self.assertRaises(AttributeError): al.shape = 1
def test_arraylink2arraydata(self): al = oapackage.exampleArray(0, 0) adata = oapackage.arraylink2arraydata(al) self.assertEqual( str(adata), r'arrayclass: N 8, k 2, strength 2, s {2,2}, order 0') al = oapackage.array_link(4, 4, 0) al.setconstant(0) adata = oapackage.arraylink2arraydata(al) al.setconstant(-1) with self.assertRaises(RuntimeError): _ = oapackage.arraylink2arraydata(al) for ii in [0, 4, 8, 10]: al = oapackage.exampleArray(ii, 0) arrayclass = oapackage.arraylink2arraydata(al, strength=-1) self.assertEqual(arrayclass.strength, al.strength())
def test_modelmatrix_verbosity(self): conf_design = oapackage.exampleArray(41, 0) with mock.patch('sys.stdout', new_callable=io.StringIO) as mock_stdout: oapackage.array2modelmatrix(conf_design, "i", 1) stdout = mock_stdout.getvalue() self.assertIn( 'array2modelmatrix: type conference, model_type_idx 2', stdout)
def test_rankStructure(self): array = oapackage.exampleArray(45, 0) array2 = oapackage.exampleArray(46, 0) rank_structure = oapackage.rankStructure(array) rank_structure.verbose = 2 if python3: with patch('sys.stdout', new_callable=io.StringIO) as mock_stdout: rank_structure.info() rank_structure.verbose = 0 rank_direct = rank_structure.rankxf(array) rank = rank_structure.rankxf(array) rank2 = rank_structure.rankxf(array2) self.assertEqual(rank_direct, 20) self.assertEqual(rank, 20) self.assertEqual(rank2, 20)
def test_nArrayFile(self): _, array_filename = tempfile.mkstemp(suffix='.oa', dir=tempfile.tempdir) oapackage.writearrayfile(array_filename, [oapackage.exampleArray(4, 0)]) self.assertEqual(oapackage.oahelper.nArrayFile(array_filename), 1) self.assertEqual(oapackage.oahelper.nArrayFile('notavalidfile.oa'), -1)
def test_findfiles(self): _, array_filename = tempfile.mkstemp(suffix='.oa', dir=tempfile.tempdir) lst = [oapackage.exampleArray(4, 0)] oapackage.writearrayfile(array_filename, lst) lst = oapackage.oahelper.findfiles(tempfile.tempdir, '.*oa') self.assertIn(os.path.split(array_filename)[-1], lst)
def test_extendSingleArray(): A = oapackage.exampleArray(4, 1) adata = oapackage.arraylink2arraydata(A, extracols=2) B = A.selectFirstColumns(5) ee = extendSingleArray(B, adata, t=2, verbose=1) assert (ee[0].n_columns == B.n_columns + 1) assert (ee[1] == A.selectFirstColumns(6))
def test_write_arrayfile_with_comment(self): designs = [oapackage.exampleArray(3)] filename = tempfile.mktemp(suffix='.oa') write_text_arrayfile(filename, designs, comment='Test comment') arrays = oapackage.readarrayfile(filename, 0) self.assertEqual(len(designs), len(arrays)) self.assertEqual(designs[0], arrays[0])
def test_extendSingleArray(): A = oapackage.exampleArray(4, 1) adata = oapackage.arraylink2arraydata(A, extracols=2) B = A.selectFirstColumns(5) ee = extendSingleArray(B, adata, t=2, verbose=1) assert(ee[0].n_columns == B.n_columns + 1) assert(ee[1] == A.selectFirstColumns(6))
def test_optimDeffPython(self): al = oapackage.exampleArray(2, 0) with mock.patch('sys.stdout', new_callable=io.StringIO) as mock_stdout: _, al = oapackage.Doptim.optimDeffPython(al, arrayclass=None, niter=1000, nabort=1500, verbose=1, alpha=[1, 0, 0], method=0) stdout = mock_stdout.getvalue() self.assertTrue( stdout.startswith('optimDeff: initial Deff 0.0000')) for method in [ oapackage.oalib.DOPTIM_SWAP, oapackage.oalib.DOPTIM_FLIP, oapackage.oalib.DOPTIM_UPDATE ]: r, al = oapackage.Doptim.optimDeffPython(al, arrayclass=None, niter=100, nabort=200, verbose=0, alpha=[1, 0, 0], method=method)
def test_nauty(verbose=0): if verbose: print('test_nauty: test reduction to normal form') al = oapackage.exampleArray(0, verbose) alr = al.randomperm() tr = oapackage.reduceOAnauty(alr) alx = tr.apply(alr) assert (alx == al)
def test_selectFirstColumns(self): al = oapackage.exampleArray(41, 0) al = al.selectFirstColumns(3) self.assertEqual(al.n_columns, 3) al = oapackage.array_link() with self.assertRaises(RuntimeError): al = al.selectFirstColumns(1)
def test_write_latex_format(self): lst = [oapackage.exampleArray(2, 0)] filename = tempfile.mktemp(suffix='.tex') oapackage.writearrayfile(filename, oapackage.arraylist_t(lst), oapackage.ALATEX) with open(filename, 'rt') as fid: latex = fid.read() self.assertIsInstance(latex, str)
def test_array2eigenModelMatrixMixed(self): array = oapackage.exampleArray(5, 0) model = oapackage.array2eigenModelMatrixMixed(array) expected_main_effects = np.frombuffer( b'\xcc;\x7ff\x9e\xa0\xf6\xbf=,\x0cp\xbd \xea\xbf\x1c3\x90E\xa7y\xe2\xbf.!\t\x14\x8e\x98\xf3\xbf\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\xcc;\x7ff\x9e\xa0\xf6\xbf=,\x0cp\xbd \xea\xbf\x1c3\x90E\xa7y\xe2\xbf.!\t\x14\x8e\x98\xf3\xbf\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\xcc;\x7ff\x9e\xa0\xf6\xbf=,\x0cp\xbd \xea\xbf\x1c3\x90E\xa7y\xe2\xbf.!\t\x14\x8e\x98\xf3?\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\xcc;\x7ff\x9e\xa0\xf6\xbf=,\x0cp\xbd \xea\xbf\x1c3\x90E\xa7y\xe2\xbf.!\t\x14\x8e\x98\xf3?\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\xcc;\x7ff\x9e\xa0\xf6\xbf=,\x0cp\xbd \xea\xbf\x1c3\x90E\xa7y\xe2\xbf\x00\x00\x00\x00\x00\x00\x00\x00\xcc;\x7ff\x9e\xa0\xf6?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\xcc;\x7ff\x9e\xa0\xf6\xbf=,\x0cp\xbd \xea\xbf\x1c3\x90E\xa7y\xe2\xbf\x00\x00\x00\x00\x00\x00\x00\x00\xcc;\x7ff\x9e\xa0\xf6?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\xcc;\x7ff\x9e\xa0\xf6?=,\x0cp\xbd \xea\xbf\x1c3\x90E\xa7y\xe2\xbf.!\t\x14\x8e\x98\xf3\xbf\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\xcc;\x7ff\x9e\xa0\xf6?=,\x0cp\xbd \xea\xbf\x1c3\x90E\xa7y\xe2\xbf.!\t\x14\x8e\x98\xf3\xbf\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\xcc;\x7ff\x9e\xa0\xf6?=,\x0cp\xbd \xea\xbf\x1c3\x90E\xa7y\xe2\xbf.!\t\x14\x8e\x98\xf3?\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0?\xcc;\x7ff\x9e\xa0\xf6?=,\x0cp\xbd \xea\xbf\x1c3\x90E\xa7y\xe2\xbf.!\t\x14\x8e\x98\xf3?\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0\xbf\xcc;\x7ff\x9e\xa0\xf6?=,\x0cp\xbd \xea\xbf\x1c3\x90E\xa7y\xe2\xbf\x00\x00\x00\x00\x00\x00\x00\x00\xcc;\x7ff\x9e\xa0\xf6?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\xcc;\x7ff\x9e\xa0\xf6?=,\x0cp\xbd \xea\xbf\x1c3\x90E\xa7y\xe2\xbf\x00\x00\x00\x00\x00\x00\x00\x00\xcc;\x7ff\x9e\xa0\xf6?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\x00\x00=,\x0cp\xbd \xfa?\x1c3\x90E\xa7y\xe2\xbf.!\t\x14\x8e\x98\xf3\xbf\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00\x00=,\x0cp\xbd \xfa?\x1c3\x90E\xa7y\xe2\xbf.!\t\x14\x8e\x98\xf3\xbf\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00\x00=,\x0cp\xbd \xfa?\x1c3\x90E\xa7y\xe2\xbf.!\t\x14\x8e\x98\xf3?\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\x00\x00=,\x0cp\xbd \xfa?\x1c3\x90E\xa7y\xe2\xbf.!\t\x14\x8e\x98\xf3?\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00\x00=,\x0cp\xbd \xfa?\x1c3\x90E\xa7y\xe2\xbf\x00\x00\x00\x00\x00\x00\x00\x00\xcc;\x7ff\x9e\xa0\xf6?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\x00\x00=,\x0cp\xbd \xfa?\x1c3\x90E\xa7y\xe2\xbf\x00\x00\x00\x00\x00\x00\x00\x00\xcc;\x7ff\x9e\xa0\xf6?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaaLX\xe8z\xb6\xfb?.!\t\x14\x8e\x98\xf3\xbf\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaaLX\xe8z\xb6\xfb?.!\t\x14\x8e\x98\xf3\xbf\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaaLX\xe8z\xb6\xfb?.!\t\x14\x8e\x98\xf3?\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaaLX\xe8z\xb6\xfb?.!\t\x14\x8e\x98\xf3?\xcc;\x7ff\x9e\xa0\xe6\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaaLX\xe8z\xb6\xfb?\x00\x00\x00\x00\x00\x00\x00\x00\xcc;\x7ff\x9e\xa0\xf6?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaaLX\xe8z\xb6\xfb?\x00\x00\x00\x00\x00\x00\x00\x00\xcc;\x7ff\x9e\xa0\xf6?\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0\xbf\x00\x00\x00\x00\x00\x00\xf0?' ).reshape(24, 8) main_effects, interaction_effects = model[0], model[1] np.testing.assert_array_equal(main_effects, expected_main_effects) self.assertEqual(interaction_effects.shape, (24, 24))
def test_generateDpage(self): outputdir = tempfile.mkdtemp() allarrays = [oapackage.exampleArray(2, 0), oapackage.exampleArray(2, 0)] dds = np.array([A.Defficiencies() for A in allarrays]) arrayclass = oapackage.arraylink2arraydata(allarrays[0]) with mock.patch('sys.stdout', new_callable=io.StringIO) as mock_stdout: page = oapackage.Doptim.generateDpage(outputdir, arrayclass, dds, allarrays, fig=None, optimfunc=[1, 0, 0], nofig=True) if self.guitest and 0: print('test_generateDpage: run gui test') page = oapackage.Doptim.generateDpage(outputdir, arrayclass, dds, allarrays, fig=100, optimfunc=[1, 0, 0], nofig=True) try: import matplotlib matplotlib.pyplot.close(100) except Exception: pass
def test_selectArrays(self): _, array_filename = tempfile.mkstemp(suffix='.oa', dir=tempfile.tempdir) _, array_filename_out = tempfile.mkstemp(suffix='.oa', dir=tempfile.tempdir) oapackage.writearrayfile( array_filename, [oapackage.exampleArray(4, 0), oapackage.exampleArray(4, 0)]) oapackage.oahelper.selectArraysInFile(array_filename, array_filename_out, [1], afmode=oalib.ABINARY, verbose=1, cache=0) oapackage.oahelper.selectArraysInFile(array_filename, array_filename_out, [-1], afmode=oalib.ABINARY, verbose=1, cache=0)
def test_optimDeffPython(self): al = oapackage.exampleArray(2, 0) with mock.patch('sys.stdout', new_callable=io.StringIO) as mock_stdout: _, al = oapackage.Doptim.optimDeffPython( al, arrayclass=None, niter=1000, nabort=1500, verbose=1, alpha=[1, 0, 0], method=0) stdout = mock_stdout.getvalue() self.assertTrue(stdout.startswith('optimDeff: initial Deff 0.0000')) for method in [oapackage.oalib.DOPTIM_SWAP, oapackage.oalib.DOPTIM_FLIP, oapackage.oalib.DOPTIM_UPDATE]: r, al = oapackage.Doptim.optimDeffPython( al, arrayclass=None, niter=100, nabort=200, verbose=0, alpha=[1, 0, 0], method=method)
def test_array2Dtable(self): sols = [oapackage.exampleArray(9, 0)] _ = oapackage.Doptim.array2Dtable(sols, verbose=1, titlestr=None)
def test_selectJ(): al = oapackage.exampleArray(12, 1) sols0 = [al] r = selectJ(sols0) assert(len(r) == 0)
# -*- coding: utf-8 -*- """ Example script for Python interface to Orthogonal Array code. mathescape, numbersep=5pt, label=Python session, gobble=0, frame=lines, framesep=1.5mm, bgcolor=bg > pygmentize -P "bgcolor=.95,.95,.95" -P "style=colorful" -f html example_python_testing.py > pygmentize -S colorful -f html > style.css; cp style.css ~/misc/homepage/oapage/ @author: Pieter Eendebak """ #import oalib import oapackage print('oalib version: %s' % oapackage.version() ) al=oapackage.exampleArray(0) al.showarray() print('D-efficiency %f, rank %d' % (al.Defficiency(), al.rank()) ) print('Generalized wordlength pattern: %s' % str(al.GWLP())) al=oapackage.exampleArray(1) print('Generalized wordlength pattern: %s' % str(al.GWLP()))
def test_select_isomorphism(): ll = [oapackage.exampleArray(0), oapackage.exampleArray(0)] indices, mm = selectIsomorphismClasses(ll, verbose=3) assert(indices[0] == indices[1]) assert(len(mm) == 2) assert(np.all(mm[0] == mm[1]))
import oapackage def addData(data, extra_data, index=0, arrays=None, extra_arrays=None): """ Vertically stack data together """ nn = extra_data.shape[1] ww = np.vstack((extra_data, index * np.ones(nn,))) data = np.hstack((data, ww)) if arrays is None: return data else: allarrays = oapackage.joinArrayLists([arrays, extra_arrays]) return data, allarrays #%% Load a strength 3 orthogonal array that is D-optimal strength3_pareto = oapackage.exampleArray(44) arrayclass = oapackage.arraylink2arraydata(strength3_pareto) #%% Optimize with alpha variations def optimize_arrays(sols, alpha=None, verbose=1, niter=400): """ Optimize set of designs """ vv2 = [] ll = oapackage.arraylist_t() for ii, A in enumerate(sols): Dinit = A.Defficiency() Df, Ax = oapackage.optimDeffPython( A, niter=niter, verbose=0, alpha=alpha) D, Ds, D1 = Ax.Defficiencies() ll.push_back(Ax)