Esempio n. 1
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))
Esempio n. 2
0
    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
Esempio n. 3
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))
Esempio n. 4
0
    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())
Esempio n. 5
0
    def test_projectionDOFvalues(self):
        array = oapackage.exampleArray(5, 0)
        arrayclass = oapackage.arraylink2arraydata(array)
        dof_values = oapackage.projectionDOFvalues(array)
        sg = oapackage.symmetry_group(dof_values, False)
        with mock.patch('sys.stdout', new_callable=io.StringIO) as mock_stdout:
            sg.show(1)
        self.assertIn('symmetry group: 5 elements, 5 subgroups: 1 1 1 1 1',
                      mock_stdout.getvalue())

        for column in range(array.n_columns):
            dof_element = list(dof_values[column].raw_values())
            self.assertEqual(dof_element[0],
                             -arrayclass.factor_levels()[column])
Esempio n. 6
0
    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
Esempio n. 7
0
    def test_LMCcheck(self):
        array = oapackage.exampleArray(1)

        lmc_type = oapackage.LMCcheck(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)

        array2 = array.selectColumns([2, 1, 0, 3, 4])
        lmc_type = oapackage.LMCcheck(array2)
        self.assertEqual(lmc_type, oapackage.LMC_LESS)

        arrayclass = oapackage.arraylink2arraydata(array)
        reduction = oapackage.LMCreduction_t(arrayclass)
        oaextend = oapackage.OAextend(arrayclass)
        lmc_type = oapackage.LMCcheck(array2.array, arrayclass, oaextend,
                                      reduction)
        self.assertEqual(lmc_type, oapackage.LMC_LESS)
Esempio n. 8
0
    def test_array_transformation_t(self):
        at = oapackage.array_transformation_t()
        with patch('sys.stdout', new_callable=io.StringIO) as mock_stdout:
            at.show()
            std_output = mock_stdout.getvalue()
            self.assertEqual(std_output,
                             'array transformation: no class defined\n')

        al = oapackage.exampleArray(0, 0)
        arrayclass = oapackage.arraylink2arraydata(al)
        at = oapackage.array_transformation_t(arrayclass)
        at.setcolperm([1, 0])
        with patch('sys.stdout', new_callable=io.StringIO) as mock_stdout:
            _ = at.show()
            std_output = mock_stdout.getvalue()
            self.assertEqual(
                std_output,
                'array transformation: N 8\ncolumn permutation: {1,0}\nlevel perms:\n{0,1}\n{0,1}\nrow permutation: {0,1,2,3,4,5,6,7}\n'
            )
        self.assertEqual(at.colperm(), (1, 0))
Esempio n. 9
0
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()
Esempio n. 10
0
 def test_oa2graph(self):
     al = oapackage.exampleArray(2, 0)
     adata = oapackage.arraylink2arraydata(al)
     g = oapackage.graphtools.oa2graph(al, adata)
     self.assertTrue(g[0].shape == (34, 34))
Esempio n. 11
0
 def test_factor_levels(self):
     array = oapackage.exampleArray(5, 0)
     arrayclass = oapackage.arraylink2arraydata(array)
     factor_levels = arrayclass.factor_levels()
     self.assertEqual(factor_levels, (4, 3, 2, 2, 2))
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)
        oapackage.tprint('optimize array %d: %f -> D %f Ds %f D1 %f' % (ii, Dinit, D, Ds, D1))