コード例 #1
0
ファイル: ptest.py プロジェクト: fgs-pwright/oapackage
def main(argv=None):
    """ Main testing function """
    print('OA performance testing')
    ss = oalib.version()
    print('OAlib: version %s' % ss)
    ss = oalib.compile_information()
    print(ss)
    print('System:')
    print('  Python: ' + ' '.join(sys.version.split('\n')))
    print('  Machine: ' + ' '.join(['%s' % x for x in platform.uname()]))

    if argv is None:
        argv = sys.argv
    try:
        try:
            opts, args = getopt.getopt(argv[1:], "h", ["help"])
        except getopt.error as msg:
            raise Usage(msg)
        # more code, unchanged
    except Usage as err:
        print >> sys.stderr, err.msg
        print >> sys.stderr, "for help use --help"
        return 2

    print('\nRunning tests:\n')
    (dt, tt, cases, dt2) = pytest()

    pytest2(oadir)
    pytest3(verbose=0)
    pytest4(verbose=1)
    ta1 = pytest5(verbose=1)
    pytest6(verbose=0)
    pytest7(verbose=0)

    pytest2level(verbose=1)

    print('-----')

    #tt=[];dt=0

    dtx = ta1

    print('\nResults:\n')
    for ii, t in enumerate(tt):
        print('%s: time %.2f [s]' % (cases[ii], t))
    print('Total time: %.3f [s], %.3f [s], %.3f [s]' % (dt, dt2, dtx))
    print('   should be of order 4.4 [s], 4.6 [s], 5.9 [s] (woelmuis)')
    print('   should be of order 3.2 [s], 3.3 [s], 4.7 [s] (marmot) [v 2.0.0]')
    print(
        '   should be of order 2.96 [s], 3.0 [s], 4.6 [s] (marmot) [v 2.0.24]')
コード例 #2
0
ファイル: Doptim.py プロジェクト: Cxb1993/oapackage
def generateDpage(outputdir,
                  arrayclass,
                  dds,
                  allarrays,
                  fig=20,
                  optimfunc=[1, 0, 0],
                  nofig=False,
                  urlprefix='',
                  makeheader=True,
                  verbose=1,
                  lbls=None):
    """ Helper function to generate web page with D-optimal design results """
    if verbose:
        print('generateDpage: dds %s' % str(dds.shape))

    pp = oahelper.createPareto(dds)

    narrays = dds.shape[0]
    npareto = pp.number()

    if verbose:
        print('generateDpage: narrays %d' % narrays)

    xstr = oahelper.series2htmlstr(arrayclass, case=1)
    xstrplain = oahelper.series2htmlstr(arrayclass, html=0, case=1)

    if verbose:
        print('generateDpage: selectParetoArrays ')
    paretoarrays = oahelper.selectParetoArrays(allarrays, pp)
    at = array2Dtable(paretoarrays, verbose=1)

    if verbose:
        print('generateDpage: write file with Pareto arrays')

    pfile0 = 'paretoarrays.oa'
    pfile = os.path.join(outputdir, pfile0)
    oalib.writearrayfile(pfile, paretoarrays)

    istrlnk = markup.oneliner.a('paretoarrays.oa', href=urlprefix + pfile0)

    if lbls is None:
        lbls = ['Optimization of $D$']
    hh = generateDscatter(dds, lbls=lbls, fig=fig, nofig=nofig)
    oahelper.niceplot(hh.get('ax', None), despine=True, legend=hh['pltlegend'])

    scatterfile = os.path.join(outputdir, 'scatterplot.png')
    if verbose:
        print('generateDpage: writen scatterplot to %s' % scatterfile)
    plt.savefig(scatterfile, bbox_inches='tight', pad_inches=0.25, dpi=160)

    #%% Create page

    page = markup.page()

    if makeheader:
        page.init(
            title="Class %s" % xstrplain,
            css=('../oastyle.css'),
            lang='en',
            htmlattrs=dict({
                'xmlns': 'http://www.w3.org/1999/xhtml',
                'xml:lang': 'en'
            }),
            header="<!-- Start of page -->",
            bodyattrs=dict({'style': 'padding-left: 3px;'}),
            # doctype=markup.doctype.strict,
            doctype=
            '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
            metainfo=({
                'text/html': 'charset=utf-8',
                'keywords': 'orthogonal arrays designs',
                'robots': 'index, follow',
                'description': 'Even-Odd arrays'
            }),
            footer="<!-- End of page -->")

    page.h1('Results for array class %s ' % xstr)

    # mathjax is not updated properly...
    ss = 'The Pareto optimaly was calculated according to the statistics \(D\), \(D1\) and \(Ds\).'
    ss = 'The Pareto optimaly was calculated according to the statistics D, D<sub>1</sub> and D<sub>s</sub>.'
    if npareto == 1:
        page.p('Generated %d arrays, %d is Pareto optimal. %s' %
               (narrays, npareto, ss))
    else:
        page.p('Generated %d arrays, %d are Pareto optimal. %s' %
               (narrays, npareto, ss))

    if narrays > 0:

        scores = calcScore(dds, optimfunc)
        tmp, dd, sols = selectDn(scores, dds, allarrays, nout=1)
        A = sols[0]
        bestdesignfile = os.path.join(outputdir, 'best-design.oa')
        oalib.writearrayfile(bestdesignfile, A)

        page.h2('Best design')
        page.p('The best design: %s.' % e.a(
            'best-design.oa', href=os.path.join(urlprefix, 'best-design.oa')))

        page.p()

        dd = dd[0]
        page.span('D-efficiency: %.4f, ' % A.Defficiency())  # page.br()
        page.span('D<sub>s</sub>-efficiency: %.4f, ' % dd[1])  # page.br()
        page.span('D<sub>1</sub>-efficiency: %.4f' % dd[2])
        page.br()
        page.span('A-efficiency: %.3f' % A.Aefficiency())
        page.br()
        gwlp = A.GWLP()
        # gwlp=','.join(['%.3f' % xq for xq in gwlp])
        gwlp = oahelper.gwlp2str(gwlp, jstr=', ')
        page.span('Generalized wordlength pattern: %s' % gwlp)
        page.br()
        # page.p('D-efficiency: %.3f' % A.Defficiency() )
        pec = oalib.PECsequence(A)
        pec = ','.join(['%.3f' % xq for xq in pec])
        page.span('PEC-sequence: %s' % pec)
        page.br()

    page.h2('Table of Pareto optimal arrays ')

    page.span(str(at))
    page.p('All Pareto optimal arrays: %s' % istrlnk)

    page.img(
        src=urlprefix + 'scatterplot.png',
        style=
        "margin: 10px; width:95%; min-width: 300px;  max-width:1100px; height: auto; "
    )

    citationstr = markup.oneliner.a(
        'Complete Enumeration of Pure-Level and Mixed-Level Orthogonal Arrays',
        href='http://dx.doi.org/10.1002/jcd.20236')

    page.br(clear='both')
    page.p(
        'Citation notice: if you make use of the results on this page, please cite the following paper:'
    )
    page.p(
        '%s, Journal of Combinatorial Designs, Volume 18, Issue 2, pages 123-140, 2010.'
        % citationstr)

    page.p('Generated with oapackage %s, date %s.' %
           (oalib.version(), oahelper.timeString()))

    outfile = os.path.join(outputdir, 'Dresults.html')
    fid = open(outfile, 'wt')
    fid.write(str(page))
    fid.close()
    print('written to file %s' % outfile)

    return outfile
コード例 #3
0
ファイル: test_oapackage.py プロジェクト: lepy/oapackage
def miscunittest(verbose=1):
    """ Perform some unit testing, return True if succesfull """
    if verbose:
        print('oapackage: unittest: oalib version %s' % oalib.version())
    al = oalib.array_link()
    ii = 0
    al = oalib.exampleArray(ii, 0)

    arrayclass = oalib.arraydata_t(2, 16, 2, 6)  # fine
    alist = [arrayclass.create_root()]
    r = oalib.extend_arraylist(alist, arrayclass)
    if len(r) != 3:
        raise Exception('extension generation for %s failed' % (arrayclass, ))

    if not isinstance(al.getarray(), np.ndarray):
        print(
            'oapackage: unittest: error: array interface not working properly')
    else:
        if not al[2, 0] == al.getarray()[2, 0]:
            print(
                'oapackage: unittest: error: array interface not working properly'
            )

    arrayclass = oalib.arraylink2arraydata(al)

    if verbose >= 2:
        print('unittest: calculate efficiencies')
    Deff = al.Defficiency()
    aa = oalib.Aefficiencies(al)
    assert (aa[0] == 1.0)
    assert (aa[1] == 1.0)
    assert (aa[2] == 1.0)

    if verbose >= 2:
        print('## oapackage test: example array %d: Deff %.3f' % (ii, Deff))

    # DOP reduction
    if verbose >= 2:
        print('unittest: test delete-one-factor GWLP reduction')
    al = oalib.exampleArray(5, verbose)
    al2 = al.randomperm()

    alr = al.reduceDOP()
    al2r = al2.reduceDOP()
    if not alr == al2r:
        print('error: DOP reduced arrays unequal!: %d' % (alr == al2r))
        print('alr')
        alr.showarraycompact()
        print('al2r')
        al2r.showarraycompact()
        return False

    transformation = oalib.reductionDOP(al)
    check = transformation.apply(al) == al.reduceDOP()
    if not check:
        print('error: DOP reduction transformation is invalid')

    # test graphtools
    if verbose >= 2:
        print('unittest: test graphtools')
    from oapackage.graphtools import oa2graph
    arrayclass = oalib.arraylink2arraydata(al)
    _ = oa2graph(al, arrayclass)

    test_numpy_interface()
    test_nauty()

    return True
コード例 #4
0
def unittest(verbose=1):
    """ Perform some unit testing, return True if succesfull """
    if verbose:
        print('oapackage: unittest: oalib version %s' % oalib.version())
    al = oalib.array_link()
    ii = 0
    al = oalib.exampleArray(ii, 0)

    #test_numpy_interface()

    if not isinstance(al.getarray(), np.ndarray):
        print(
            'oapackage: unittest: error: array interface not working properly')
    else:
        if not al[2, 0] == al.getarray()[2, 0]:
            print(
                'oapackage: unittest: error: array interface not working properly'
            )

    arrayclass = oalib.arraylink2arraydata(al)
    #    print(arrayclass)

    if verbose >= 2:
        print('unittest: calculate efficiencies')
    Deff = al.Defficiency()
    aa = oalib.Aefficiencies(al)
    if verbose >= 2:
        print('## oapackage test: example array %d: Deff %.3f' % (ii, Deff))

    # DOP reduction
    if verbose >= 2:
        print('unittest: test delete-one-factor GWLP reduction')
    al = oalib.exampleArray(5, 1)
    al2 = al.randomperm()

    alr = al.reduceDOP()
    al2r = al2.reduceDOP()
    if not alr == al2r:
        print('error: DOP reduced arrays unequal!: %d' % (alr == al2r))
        print('alr')
        alr.showarraycompact()
        print('al2r')
        al2r.showarraycompact()
        return False

    at = oalib.reductionDOP(al)
    check = at.apply(al) == al.reduceDOP()
    if not check:
        print('error: DOP reduction transformation is invalid')

    # test graphtools
    if verbose >= 2:
        print('unittest: test graphtools')
    # import . graphtools
    from .graphtools import oa2graph
    arrayclass = oalib.arraylink2arraydata(al)
    _ = oa2graph(al, arrayclass)

    test_numpy_interface()
    test_nauty()

    return True
コード例 #5
0
__uri__ = "http://www.pietereendebak.nl/oapackage/index.html"
__doc__ = __description__ + " <" + __uri__ + ">"

import oalib
oalib.setloglevel(oalib.SYSTEM)
oalib.log_print(-oalib.SYSTEM, '')
from oalib import *
# import .oahelper
from .oahelper import *
# import .Doptim
from .Doptim import *
from . import scanf

import numpy as np

__version__ = oalib.version()

#%%


def autodoctest():
    """ Test the module using autodoc
    Example:
      >>> import oapackage
      >>> arrayclass=oapackage.arraydata_t(2, 40, 0, 7)
      >>> print(arrayclass)
      arrayclass: N 40, k 7, strength 0, s {2,2,2,2,2,2,2}, order 0

    """
    return
コード例 #6
0
ファイル: Doptim.py プロジェクト: eendebakpt/oapackage
def generateDpage(outputdir, arrayclass, dds, allarrays, fig=20, optimfunc=[1, 0, 0],
                  nofig=False, urlprefix='', makeheader=True, verbose=1, lbls=None):
    """ Helper function to generate web page with D-optimal design results """
    if verbose:
        print('generateDpage: dds %s' % str(dds.shape))

    pp = oahelper.createPareto(dds)

    narrays = dds.shape[0]
    npareto = pp.number()

    if verbose:
        print('generateDpage: narrays %d' % narrays)

    xstr = oahelper.series2htmlstr(arrayclass, case=1)
    xstrplain = oahelper.series2htmlstr(arrayclass, html=0, case=1)

    if verbose:
        print('generateDpage: selectParetoArrays ')
    paretoarrays = oahelper.selectParetoArrays(allarrays, pp)
    at = array2Dtable(paretoarrays, verbose=1)

    if verbose:
        print('generateDpage: write file with Pareto arrays')

    pfile0 = 'paretoarrays.oa'
    pfile = os.path.join(outputdir, pfile0)
    oalib.writearrayfile(pfile, paretoarrays)

    istrlnk = markup.oneliner.a('paretoarrays.oa', href=urlprefix + pfile0)

    if lbls is None:
        lbls = ['Optimization of $D$']
    if fig is not None:
        hh = generateDscatter(dds, lbls=lbls, fig=fig, nofig=nofig)
        oahelper.niceplot(hh.get('ax', None), despine=True, legend=hh['pltlegend'])

        scatterfile = os.path.join(outputdir, 'scatterplot.png')
        if verbose:
            print('generateDpage: writen scatterplot to %s' % scatterfile)
        plt.savefig(scatterfile, bbox_inches='tight', pad_inches=0.25, dpi=160)

    page = markup.page()

    if makeheader:
        page.init(title="Class %s" % xstrplain,
                  css=('../oastyle.css'),
                  lang='en', htmlattrs=dict({'xmlns': 'http://www.w3.org/1999/xhtml', 'xml:lang': 'en'}),
                  header="<!-- Start of page -->",
                  bodyattrs=dict({'style': 'padding-left: 3px;'}),
                       doctype='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
                       metainfo=({'text/html': 'charset=utf-8', 'keywords': 'orthogonal arrays designs',
                                  'robots': 'index, follow', 'description': 'Even-Odd arrays'}),
                       footer="<!-- End of page -->")

    page.h1('Results for array class %s ' % xstr)

    ss = r'The Pareto optimaly was calculated according to the statistics D, D<sub>1</sub> and D<sub>s</sub>.'
    if npareto == 1:
        page.p('Generated %d arrays, %d is Pareto optimal. %s' %
               (narrays, npareto, ss))
    else:
        page.p('Generated %d arrays, %d are Pareto optimal. %s' %
               (narrays, npareto, ss))

    if narrays > 0:

        scores = calcScore(dds, optimfunc)
        _, dd, sols = selectDn(scores, dds, allarrays, nout=1)
        A = sols[0]
        bestdesignfile = os.path.join(outputdir, 'best-design.oa')
        oalib.writearrayfile(bestdesignfile, A)

        page.h2('Best design')
        page.p('The best design: %s.' %
               e.a('best-design.oa', href=os.path.join(urlprefix, 'best-design.oa')))

        page.p()

        dd = dd[0]
        page.span('D-efficiency: %.4f, ' % A.Defficiency())  # page.br()
        page.span('D<sub>s</sub>-efficiency: %.4f, ' % dd[1])  # page.br()
        page.span('D<sub>1</sub>-efficiency: %.4f' % dd[2])
        page.br()
        page.span('A-efficiency: %.3f' % A.Aefficiency())
        page.br()
        gwlp = A.GWLP()
        # gwlp=','.join(['%.3f' % xq for xq in gwlp])
        gwlp = oahelper.gwlp2str(gwlp, jstr=', ')
        page.span('Generalized wordlength pattern: %s' % gwlp)
        page.br()
        # page.p('D-efficiency: %.3f' % A.Defficiency() )
        pec = oalib.PECsequence(A)
        pec = ','.join(['%.3f' % xq for xq in pec])
        page.span('PEC-sequence: %s' % pec)
        page.br()

    page.h2('Table of Pareto optimal arrays ')

    page.span(str(at))
    page.p('All Pareto optimal arrays: %s' % istrlnk)

    page.img(src=urlprefix + 'scatterplot.png',
             style="margin: 10px; width:95%; min-width: 300px;  max-width:1100px; height: auto; ")

    citationstr = markup.oneliner.a(
        'Complete Enumeration of Pure-Level and Mixed-Level Orthogonal Arrays', href='https://doi.org/10.1002/jcd.20236')

    page.br(clear='both')
    page.p(
        'Citation notice: if you make use of the results on this page, please cite the following paper:')
    page.p('%s, Journal of Combinatorial Designs, Volume 18, Issue 2, pages 123-140, 2010.' %
           citationstr)

    page.p('Generated with oapackage %s, date %s.' %
           (oalib.version(), oahelper.timeString()))

    outfile = os.path.join(outputdir, 'Dresults.html')
    fid = open(outfile, 'wt')
    fid.write(str(page))
    fid.close()
    print('written to file %s' % outfile)

    return outfile