예제 #1
0
파일: Doptim.py 프로젝트: Cxb1993/oapackage
def array2Dtable(sols, verbose=1, titlestr=None):
    """ Generate HTML table with information about for a list of designs """
    na = len(sols)
    page = markup.page()
    page.table(style=' border-collapse: collapse;')
    page.tr(style='font-weight: bold; border-bottom: solid 1px black;')
    page.th('Array', style='padding-right:30px; ')
    page.th(('D-efficiency', 'Ds-efficiency', 'D1-efficiency'),
            style='padding-right:14px;')
    page.th(('GWLP'), style='padding-right:14px;')
    page.tr.close()
    for ii, al in enumerate(sols):
        aidx = ii
        (D, Ds, D1) = al.Defficiencies()
        gwlp = al.GWLP()
        page.tr(style='font-weight: normal;')
        page.td('%d' % aidx, style='padding-right:10px;')
        for v in [D, Ds, D1]:
            page.td('%.4f' % v, style='padding-right:1px;')
        gstr = oahelper.gwlp2str(gwlp)
        page.td(e.small(gstr), style='padding-right:1px;')
        page.tr.close()
    page.table.close()
    # page.p.close()
    return page
예제 #2
0
def array2Dtable(array_list, verbose=1, titlestr=None):
    """ Generate HTML table with information about for a list of designs

    Args:
        array_list (list): list of arrays
        verbose (int): verbosity level
    """
    page = markup.page()
    page.table(style=' border-collapse: collapse;')
    page.tr(style='font-weight: bold; border-bottom: solid 1px black;')
    page.th('Array', style='padding-right:30px; ')
    page.th(('D-efficiency', 'Ds-efficiency', 'D1-efficiency'),
            style='padding-right:14px;')
    page.th(('GWLP'), style='padding-right:14px;')
    page.tr.close()
    for ii, al in enumerate(array_list):
        aidx = ii
        (D, Ds, D1) = al.Defficiencies()
        gwlp = al.GWLP()
        page.tr(style='font-weight: normal;')
        page.td('%d' % aidx, style='padding-right:10px;')
        for statistic in [D, Ds, D1]:
            page.td('%.4f' % statistic, style='padding-right:1px;')
        gstr = oahelper.gwlp2str(gwlp)
        page.td(e.small(gstr), style='padding-right:1px;')
        page.tr.close()
    page.table.close()
    return page
예제 #3
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
예제 #4
0
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