コード例 #1
0
ファイル: ec_stats.py プロジェクト: jvoight/lmfdb
    def init_ecdb_stats(self):
        if self._stats:
            return
        logger.debug("Computing elliptic curve stats...")
        ecdb = db.ec_curves
        counts = self._counts
        stats = {}

        # rank distribution
        
        rank_counts = []
        ranks = range(counts['max_rank']+1)
        for r in ranks:
            ncu = ecdb.count({'rank':r})
            ncl = ecdb.count({'rank':r, 'number':1})
            prop = format_percentage(ncl,counts['nclasses'])
            rank_counts.append({'r': r, 'ncurves': ncu, 'nclasses': ncl, 'prop': prop})
        stats['rank_counts'] = rank_counts

        # torsion distribution
        
        tor_counts = []
        tor_counts2 = []
        ncurves = counts['ncurves']
        for t in  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16]:
            ncu = ecdb.count({'torsion':t})
            if t in [4,8,12]: # two possible structures
                ncyc = ecdb.count({'torsion_structure':[t]})
                gp = "\(C_{%s}\)"%t
                prop = format_percentage(ncyc,ncurves)
                tor_counts.append({'t': t, 'gp': gp, 'ncurves': ncyc, 'prop': prop})
                nncyc = ncu-ncyc
                gp = "\(C_{2}\\times C_{%s}\)"%(t//2)
                prop = format_percentage(nncyc,ncurves)
                tor_counts2.append({'t': t, 'gp': gp, 'ncurves': nncyc, 'prop': prop})
            elif t==16: # all C_2 x C_8
                gp = "\(C_{2}\\times C_{8}\)"
                prop = format_percentage(ncu,ncurves)
                tor_counts2.append({'t': t, 'gp': gp, 'ncurves': ncu, 'prop': prop})
            else: # all cyclic
                gp = "\(C_{%s}\)"%t
                prop = format_percentage(ncu,ncurves)
                tor_counts.append({'t': t, 'gp': gp, 'ncurves': ncu, 'prop': prop})
        stats['tor_counts'] = tor_counts+tor_counts2

        # Sha distribution
        
        max_sha = ecdb.max('sha')
        stats['max_sha'] = max_sha
        max_sqrt_sha = max_sha.sqrt() # exact!
        sha_counts = [{'s':s,'ncurves':ecdb.count({'sha':s**2})} for s in range(1,1+max_sqrt_sha)]
        # remove values with a count of 0
        sha_counts = [sc for sc in sha_counts if sc['ncurves']]
        stats['sha_counts'] = sha_counts
        self._stats = stats
        logger.debug("... finished computing elliptic curve stats.")
コード例 #2
0
 def init_g2c_stats(self):
     if self._stats:
         return
     curves = g2c_db_curves()
     counts = self._counts
     total = counts["ncurves"]
     stats = {}
     dists = []
     # TODO use aggregate $group to speed this up and/or just store these counts in the database
     for attr in stats_attribute_list:
         counts = attribute_value_counts(curves, attr['name'])
         counts = [c for c in counts if c[0] != None]
         if len(counts) == 0:
             continue
         vcounts = []
         rows = []
         avg = 0
         total = sum([c[1] for c in counts])
         for value, n in counts:
             prop = format_percentage(n, total)
             if 'avg' in attr and attr['avg'] and (type(value) == int
                                                   or type(value) == float):
                 avg += n * value
             value_string = attr['format'](
                 value) if 'format' in attr else value
             vcounts.append({
                 'value':
                 value_string,
                 'curves':
                 n,
                 'query':
                 url_for(".index_Q") + '?' + attr['name'] + '=' +
                 str(value),
                 'proportion':
                 prop
             })
             if len(vcounts) == 10:
                 rows.append(vcounts)
                 vcounts = []
         if len(vcounts):
             rows.append(vcounts)
         if 'avg' in attr and attr['avg']:
             vcounts.append({
                 'value':
                 '\(\\mathrm{avg}\\ %.2f\)' % (float(avg) / total),
                 'curves':
                 total,
                 'query':
                 url_for(".index_Q") + '?' + attr['name'],
                 'proportion':
                 format_percentage(1, 1)
             })
         dists.append({'attribute': attr, 'rows': rows})
     stats["distributions"] = dists
     self._stats = stats
コード例 #3
0
ファイル: main.py プロジェクト: haraldschilly/lmfdb
 def init_g2c_stats(self):
     if self._stats:
         return
     curves = g2c_db_curves()
     counts = self._counts
     total = counts["ncurves"]
     stats = {}
     dists = []
     # TODO use aggregate $group to speed this up and/or just store these counts in the database
     for attr in stats_attribute_list:
         counts = attribute_value_counts(curves, attr['name'])
         counts = [c for c in counts if c[0] != None]
         if len(counts) == 0:
             continue
         vcounts = []
         rows = []
         avg = 0
         total = sum([c[1] for c in counts])
         for value,n in counts:
             prop = format_percentage(n,total)
             if 'avg' in attr and attr['avg'] and (type(value) == int or type(value) == float):
                 avg += n*value
             value_string = attr['format'](value) if 'format' in attr else value
             vcounts.append({'value': value_string, 'curves': n, 'query':url_for(".index_Q")+'?'+attr['name']+'='+str(value),'proportion': prop})
             if len(vcounts) == 10:
                 rows.append(vcounts)
                 vcounts = []
         if len(vcounts):
             rows.append(vcounts)
         if 'avg' in attr and attr['avg']:
             vcounts.append({'value':'\(\\mathrm{avg}\\ %.2f\)'%(float(avg)/total), 'curves':total, 'query':url_for(".index_Q") +'?'+attr['name'],'proportion':format_percentage(1,1)})
         dists.append({'attribute':attr,'rows':rows})
     stats["distributions"] = dists
     self._stats = stats
コード例 #4
0
def galstatdict(li, tots, t):
    return [{
        'cnt':
        comma(li[nn]),
        'prop':
        format_percentage(li[nn], tots[nn]),
        'query':
        url_for(".number_field_render_webpage") +
        '?degree=%d&galois_group=%s' % (nn + 1, "%dt%d" % (nn + 1, t[nn]))
    } for nn in range(len(li))]
コード例 #5
0
def statistics():
    t = 'Global Number Field Statistics'
    bread = [('Global Number Fields', url_for(".number_field_render_webpage")),
             ('Number Field Statistics', '')]
    init_nf_count()
    n = db.nf_fields.stats.get_oldstat('degree')['counts']
    nsig = db.nf_fields.stats.get_oldstat('nsig')['counts']
    # Galois groups
    nt_all = db.nf_fields.stats.get_oldstat('nt')['counts']
    nt = [nt_all[j] for j in range(7)]
    # Galois group families
    cn = galstatdict([u[0] for u in nt_all], n, [1 for u in nt_all])
    sn = galstatdict([u[max(len(u) - 1, 0)] for u in nt_all], n,
                     [len(u) for u in nt_all])
    an = galstatdict([u[max(len(u) - 2, 0)] for u in nt_all], n,
                     [len(u) - 1 for u in nt_all])
    # t-numbers for D_n
    dn_tlist = [
        1, 1, 2, 3, 2, 3, 2, 6, 3, 3, 2, 12, 2, 3, 2, 56, 2, 13, 2, 10, 5, 3, 2
    ]
    dn = galstatdict(
        db.nf_fields.stats.get_oldstat('dn')['counts'], n, dn_tlist)

    h = db.nf_fields.stats.get_oldstat('h_range')['counts']
    has_h = db.nf_fields.stats.get_oldstat('has_h')['val']
    hdeg = db.nf_fields.stats.get_oldstat('hdeg')['counts']
    has_hdeg = db.nf_fields.stats.get_oldstat('has_hdeg')['counts']
    hdeg = [[{
        'cnt':
        comma(hdeg[nn][j]),
        'prop':
        format_percentage(hdeg[nn][j], has_hdeg[nn]),
        'query':
        url_for(".number_field_render_webpage") +
        '?degree=%d&class_number=%s' %
        (nn + 1, str(1 + 10**(j - 1)) + '-' + str(10**j))
    } for j in range(len(h))] for nn in range(len(hdeg))]

    has_hdeg = [{
        'cnt':
        comma(has_hdeg[nn]),
        'prop':
        format_percentage(has_hdeg[nn], n[nn]),
        'query':
        url_for(".number_field_render_webpage") +
        '?degree=%d&class_number=1-10000000000000' % (nn + 1)
    } for nn in range(len(has_hdeg))]
    maxt = 1 + max([len(entry) for entry in nt])

    nt = [[{
        'cnt':
        comma(nt[nn][tt]),
        'prop':
        format_percentage(nt[nn][tt], n[nn]),
        'query':
        url_for(".number_field_render_webpage") +
        '?degree=%d&galois_group=%s' % (nn + 1, "%dt%d" % (nn + 1, tt + 1))
    } for tt in range(len(nt[nn]))] for nn in range(len(nt))]
    # Totals for signature table
    sigtotals = [
        comma(sum([nsig[nn][r2] for nn in range(max(r2 * 2 - 1, 0), 23)]))
        for r2 in range(12)
    ]
    nsig = [[{
        'cnt':
        comma(nsig[nn][r2]),
        'prop':
        format_percentage(nsig[nn][r2], n[nn]),
        'query':
        url_for(".number_field_render_webpage") +
        '?degree=%d&signature=[%d,%d]' % (nn + 1, nn + 1 - 2 * r2, r2)
    } for r2 in range(len(nsig[nn]))] for nn in range(len(nsig))]
    h = [{
        'cnt':
        comma(h[j]),
        'prop':
        format_percentage(h[j], has_h),
        'label':
        '$10^{' + str(j - 1) + '}<h\leq 10^{' + str(j) + '}$',
        'query':
        url_for(".number_field_render_webpage") + '?class_number=%s' %
        (str(1 + 10**(j - 1)) + '-' + str(10**j))
    } for j in range(len(h))]
    h[0]['label'] = '$h=1$'
    h[1]['label'] = '$1<h\leq 10$'
    h[2]['label'] = '$10<h\leq 10^2$'
    h[0]['query'] = url_for(".number_field_render_webpage") + '?class_number=1'

    # Class number 1 by signature
    sigclass1 = db.nf_fields.stats.get_oldstat('sigclass1')['counts']
    sighasclass = db.nf_fields.stats.get_oldstat('sighasclass')['counts']
    sigclass1 = [[{
        'cnt':
        comma(sigclass1[nn][r2]),
        'prop':
        format_percentage(sigclass1[nn][r2], sighasclass[nn][r2])
        if sighasclass[nn][r2] > 0 else 0,
        'show':
        sighasclass[nn][r2] > 0,
        'query':
        url_for(".number_field_render_webpage") +
        '?degree=%d&signature=[%d,%d]&class_number=1' %
        (nn + 1, nn + 1 - 2 * r2, r2)
    } for r2 in range(len(nsig[nn]))] for nn in range(len(nsig))]

    n = [{
        'cnt':
        comma(n[nn]),
        'prop':
        format_percentage(n[nn], nfields),
        'query':
        url_for(".number_field_render_webpage") + '?degree=%d' % (nn + 1)
    } for nn in range(len(n))]

    info = {
        'degree': n,
        'nt': nt,
        'nsig': nsig,
        'sigtotals': sigtotals,
        'h': h,
        'has_h': comma(has_h),
        'has_h_pct': format_percentage(has_h, nfields),
        'hdeg': hdeg,
        'has_hdeg': has_hdeg,
        'sigclass1': sigclass1,
        'total': comma(nfields),
        'maxt': maxt,
        'cn': cn,
        'dn': dn,
        'an': an,
        'sn': sn,
        'maxdeg': max_deg
    }
    return render_template("nf-statistics.html",
                           info=info,
                           credit=NF_credit,
                           title=t,
                           bread=bread)
コード例 #6
0
ファイル: number_field.py プロジェクト: cscmnu/lmfdb
def statistics():
    fields = db.nf_fields
    nfstatdb = fields.stats
    title = 'Number field statistics'
    bread = bread_prefix() + [('Statistics', '')]
    init_nf_count()
    ntrans = [
        0, 1, 1, 2, 5, 5, 16, 7, 50, 34, 45, 8, 301, 9, 63, 104, 1954, 10, 983,
        8, 1117, 164, 59, 7, 25000, 211, 96, 2392, 1854, 8, 5712
    ]
    degree_stats = nfstatdb.column_counts('degree')
    n = [degree_stats[elt + 1] for elt in range(23)]

    degree_r2_stats = nfstatdb.column_counts(['degree', 'r2'])
    # if a count is missing it is because it is zero
    nsig = [[
        degree_r2_stats.get((deg + 1, s), 0) for s in range((deg + 3) // 2)
    ] for deg in range(23)]
    # Galois groups
    nt_stats = nfstatdb.column_counts(['degree', 'galois_label'])
    nt_stats = {(key[0], int(key[1].split('T')[1])): value
                for (key, value) in nt_stats.items()}
    # if a count is missing it is because it is zero
    nt_all = [[
        nt_stats.get((deg + 1, t + 1), 0) for t in range(ntrans[deg + 1])
    ] for deg in range(23)]
    nt = [nt_all[j] for j in range(7)]
    # Galois group families
    cn = galstatdict([u[0] for u in nt_all], n, [1 for u in nt_all])
    sn = galstatdict([u[max(len(u) - 1, 0)] for u in nt_all], n,
                     [len(u) for u in nt_all])
    an = galstatdict([u[max(len(u) - 2, 0)] for u in nt_all], n,
                     [len(u) - 1 for u in nt_all])
    # t-numbers for D_n
    dn_tlist = [
        1, 1, 2, 3, 2, 3, 2, 6, 3, 3, 2, 12, 2, 3, 2, 56, 2, 13, 2, 10, 5, 3, 2
    ]
    dn = galstatdict(
        [nt_stats[(j + 1, dn_tlist[j])] for j in range(len(dn_tlist))], n,
        dn_tlist)

    hdeg_stats = {
        j: nfstatdb.column_counts(
            'degree', {'class_number': {
                '$lt': 1 + 10**j,
                '$gt': 10**(j - 1)
            }})
        for j in range(1, 12)
    }
    hdeg_stats[0] = nfstatdb.column_counts('degree', {'class_number': 1})
    h = [
        sum(hdeg_stats[j].get(k + 1, 0) for k in range(max_deg))
        for j in range(12)
    ]
    # if a count is missing it is because it is zero
    hdeg = [[hdeg_stats[j].get(deg + 1, 0) for j in range(12)]
            for deg in range(23)]
    has_hdeg_stats = nfstatdb.column_counts(
        'degree', {'class_number': {
            '$exists': True
        }})
    has_hdeg = [has_hdeg_stats[deg + 1] for deg in range(23)]
    has_h = sum(has_hdeg[j] for j in range(len(has_hdeg)))
    hdeg = [[{
        'cnt':
        comma(hdeg[nn][j]),
        'prop':
        format_percentage(hdeg[nn][j], has_hdeg[nn]),
        'query':
        url_for(".number_field_render_webpage") +
        '?degree=%d&class_number=%s' %
        (nn + 1, str(1 + 10**(j - 1)) + '-' + str(10**j))
    } for j in range(len(h))] for nn in range(len(hdeg))]

    has_hdeg = [{
        'cnt':
        comma(has_hdeg[nn]),
        'prop':
        format_percentage(has_hdeg[nn], n[nn]),
        'query':
        url_for(".number_field_render_webpage") +
        '?degree=%d&class_number=1-10000000000000' % (nn + 1)
    } for nn in range(len(has_hdeg))]
    maxt = 1 + max([len(entry) for entry in nt])

    nt = [[{
        'cnt':
        comma(nt[nn][tt]),
        'prop':
        format_percentage(nt[nn][tt], n[nn]),
        'query':
        url_for(".number_field_render_webpage") +
        '?degree=%d&galois_group=%s' % (nn + 1, "%dt%d" % (nn + 1, tt + 1))
    } for tt in range(len(nt[nn]))] for nn in range(len(nt))]
    # Totals for signature table
    sigtotals = [
        comma(sum([nsig[nn][r2] for nn in range(max(r2 * 2 - 1, 0), 23)]))
        for r2 in range(12)
    ]
    nsig = [[{
        'cnt':
        comma(nsig[nn][r2]),
        'prop':
        format_percentage(nsig[nn][r2], n[nn]),
        'query':
        url_for(".number_field_render_webpage") +
        '?degree=%d&signature=[%d,%d]' % (nn + 1, nn + 1 - 2 * r2, r2)
    } for r2 in range(len(nsig[nn]))] for nn in range(len(nsig))]
    h = [{
        'cnt':
        comma(h[j]),
        'prop':
        format_percentage(h[j], has_h),
        'label':
        '$10^{' + str(j - 1) + r'}<h\leq 10^{' + str(j) + '}$',
        'query':
        url_for(".number_field_render_webpage") + '?class_number=%s' %
        (str(1 + 10**(j - 1)) + '-' + str(10**j))
    } for j in range(len(h))]
    h[0]['label'] = '$h=1$'
    h[1]['label'] = r'$1<h\leq 10$'
    h[2]['label'] = r'$10<h\leq 10^2$'
    h[0]['query'] = url_for(".number_field_render_webpage") + '?class_number=1'

    # Class number 1 by signature
    sigclass1 = nfstatdb.column_counts(['degree', 'r2'], {'class_number': 1})
    sighasclass = nfstatdb.column_counts(['degree', 'r2'],
                                         {'class_number': {
                                             '$exists': True
                                         }})
    sigclass1 = [[{
        'cnt':
        comma(sigclass1.get((nn + 1, r2), 0)),
        'prop':
        format_percentage(sigclass1.get(
            (nn + 1, r2), 0), sighasclass.get(
                (nn + 1, r2), 0)) if sighasclass.get(
                    (nn + 1, r2), 0) > 0 else 0,
        'show':
        sighasclass.get((nn + 1, r2), 0) > 0,
        'query':
        url_for(".number_field_render_webpage") +
        '?degree=%d&signature=[%d,%d]&class_number=1' %
        (nn + 1, nn + 1 - 2 * r2, r2)
    } for r2 in range(len(nsig[nn]))] for nn in range(len(nsig))]

    n = [{
        'cnt':
        comma(n[nn]),
        'prop':
        format_percentage(n[nn], nfields),
        'query':
        url_for(".number_field_render_webpage") + '?degree=%d' % (nn + 1)
    } for nn in range(len(n))]

    info = {
        'degree': n,
        'nt': nt,
        'nsig': nsig,
        'sigtotals': sigtotals,
        'h': h,
        'has_h': comma(has_h),
        'has_h_pct': format_percentage(has_h, nfields),
        'hdeg': hdeg,
        'has_hdeg': has_hdeg,
        'sigclass1': sigclass1,
        'total': comma(nfields),
        'maxt': maxt,
        'cn': cn,
        'dn': dn,
        'an': an,
        'sn': sn,
        'maxdeg': max_deg
    }
    return render_template("nf-statistics.html",
                           info=info,
                           credit=NF_credit,
                           title=title,
                           bread=bread)
コード例 #7
0
ファイル: ec_stats.py プロジェクト: kedlaya/lmfdb
    def init_ecdb_stats(self):
        if self._stats:
            return
        logger.debug("Computing elliptic curve stats...")
        ecdbstats = db.ec_curves.stats
        counts = self._counts
        stats = {}
        rank_counts = []
        rdict = dict(ecdbstats.get_oldstat('rank')['counts'])
        crdict = dict(ecdbstats.get_oldstat('class/rank')['counts'])
        for r in range(counts['max_rank'] + 1):
            try:
                ncu = rdict[str(r)]
                ncl = crdict[str(r)]
            except KeyError:
                ncu = rdict[r]
                ncl = crdict[r]
            prop = format_percentage(ncl, counts['nclasses'])
            rank_counts.append({
                'r': r,
                'ncurves': ncu,
                'nclasses': ncl,
                'prop': prop
            })
        stats['rank_counts'] = rank_counts
        tor_counts = []
        tor_counts2 = []
        ncurves = counts['ncurves']
        tdict = dict(ecdbstats.get_oldstat('torsion')['counts'])
        tsdict = dict(ecdbstats.get_oldstat('torsion_structure')['counts'])
        for t in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16]:
            try:
                ncu = tdict[t]
            except KeyError:
                ncu = tdict[str(t)]
            if t in [4, 8, 12]:  # two possible structures
                ncyc = tsdict[str(t)]
                gp = "\(C_{%s}\)" % t
                prop = format_percentage(ncyc, ncurves)
                tor_counts.append({
                    't': t,
                    'gp': gp,
                    'ncurves': ncyc,
                    'prop': prop
                })
                nncyc = ncu - ncyc
                gp = "\(C_{2}\\times C_{%s}\)" % (t // 2)
                prop = format_percentage(nncyc, ncurves)
                tor_counts2.append({
                    't': t,
                    'gp': gp,
                    'ncurves': nncyc,
                    'prop': prop
                })
            elif t == 16:  # all C_2 x C_8
                gp = "\(C_{2}\\times C_{8}\)"
                prop = format_percentage(ncu, ncurves)
                tor_counts2.append({
                    't': t,
                    'gp': gp,
                    'ncurves': ncu,
                    'prop': prop
                })
            else:  # all cyclic
                gp = "\(C_{%s}\)" % t
                prop = format_percentage(ncu, ncurves)
                tor_counts.append({
                    't': t,
                    'gp': gp,
                    'ncurves': ncu,
                    'prop': prop
                })
        stats['tor_counts'] = tor_counts + tor_counts2

        shadict = dict(ecdbstats.get_oldstat('sha')['counts'])
        stats['max_sha'] = max([int(s) for s in shadict])
        sha_counts = []
        from sage.misc.functional import isqrt
        sha_is_int = True
        try:
            nc = shadict[1]
        except KeyError:
            sha_is_int = False
        for s in range(1, 1 + isqrt(stats['max_sha'])):
            s2 = s * s
            if sha_is_int:
                nc = shadict.get(s2, 0)
            else:
                nc = shadict.get(str(s2), 0)
            if nc:
                sha_counts.append({'s': s, 'ncurves': nc})
        stats['sha_counts'] = sha_counts
        self._stats = stats
        logger.debug("... finished computing elliptic curve stats.")
コード例 #8
0
ファイル: number_field.py プロジェクト: koffie/lmfdb
def statistics():
    t = 'Global Number Field Statistics'
    bread = [('Global Number Fields', url_for(".number_field_render_webpage")), ('Number Field Statistics', '')]
    init_nf_count()
    n = db.nf_fields.stats.get_oldstat('degree')['counts']
    nsig = db.nf_fields.stats.get_oldstat('nsig')['counts']
    # Galois groups
    nt_all = db.nf_fields.stats.get_oldstat('nt')['counts']
    nt = [nt_all[j] for j in range(7)]
    # Galois group families
    cn = galstatdict([u[0] for u in nt_all], n, [1 for u in nt_all])
    sn = galstatdict([u[max(len(u)-1,0)] for u in nt_all], n, [len(u) for u in nt_all])
    an = galstatdict([u[max(len(u)-2,0)] for u in nt_all], n, [len(u)-1 for u in nt_all])
    # t-numbers for D_n
    dn_tlist = [1,1,2,3,2,3,2,6,3,3,2,12,2,3,2,56,2,13,2,10,5,3,2]
    dn = galstatdict(db.nf_fields.stats.get_oldstat('dn')['counts'], n, dn_tlist)

    h = db.nf_fields.stats.get_oldstat('h_range')['counts']
    has_h = db.nf_fields.stats.get_oldstat('has_h')['val']
    hdeg = db.nf_fields.stats.get_oldstat('hdeg')['counts']
    has_hdeg = db.nf_fields.stats.get_oldstat('has_hdeg')['counts']
    hdeg = [ [ {'cnt': comma(hdeg[nn][j]), 
              'prop': format_percentage(hdeg[nn][j], has_hdeg[nn]),
              'query': url_for(".number_field_render_webpage")+'?degree=%d&class_number=%s'%(nn+1,str(1+10**(j-1))+'-'+str(10**j))} for j in range(len(h))] for nn in range(len(hdeg))]

    has_hdeg = [{'cnt': comma(has_hdeg[nn]),
                 'prop': format_percentage(has_hdeg[nn], n[nn]),
                 'query': url_for(".number_field_render_webpage")+'?degree=%d&class_number=1-10000000000000'%(nn+1)} for nn in range(len(has_hdeg))]
    maxt = 1+max([len(entry) for entry in nt])

    nt = [ [ {'cnt': comma(nt[nn][tt]), 
              'prop': format_percentage(nt[nn][tt], n[nn]),
              'query': url_for(".number_field_render_webpage")+'?degree=%d&galois_group=%s'%(nn+1,"%dt%d"%(nn+1,tt+1))} for tt in range(len(nt[nn]))] for nn in range(len(nt))]
    # Totals for signature table
    sigtotals = [ comma(sum([nsig[nn][r2] for nn in range(max(r2*2-1,0),23)])) for r2 in range(12)]
    nsig = [ [ {'cnt': comma(nsig[nn][r2]), 
              'prop': format_percentage(nsig[nn][r2], n[nn]),
              'query': url_for(".number_field_render_webpage")+'?degree=%d&signature=[%d,%d]'%(nn+1,nn+1-2*r2,r2)} for r2 in range(len(nsig[nn]))] for nn in range(len(nsig))]
    h = [ {'cnt': comma(h[j]),
           'prop': format_percentage(h[j], has_h),
           'label': '$10^{'+str(j-1)+'}<h\leq 10^{'+str(j)+'}$',
           'query': url_for(".number_field_render_webpage")+'?class_number=%s'%(str(1+10**(j-1))+'-'+str(10**j))} for j in range(len(h))]
    h[0]['label'] = '$h=1$'
    h[1]['label'] = '$1<h\leq 10$'
    h[2]['label'] = '$10<h\leq 10^2$'
    h[0]['query'] = url_for(".number_field_render_webpage")+'?class_number=1'

    # Class number 1 by signature
    sigclass1 = db.nf_fields.stats.get_oldstat('sigclass1')['counts']
    sighasclass = db.nf_fields.stats.get_oldstat('sighasclass')['counts']
    sigclass1 = [ [ {'cnt': comma(sigclass1[nn][r2]), 
              'prop': format_percentage(sigclass1[nn][r2], sighasclass[nn][r2]) if sighasclass[nn][r2]>0 else 0,
              'show': sighasclass[nn][r2]>0,
              'query': url_for(".number_field_render_webpage")+'?degree=%d&signature=[%d,%d]&class_number=1'%(nn+1,nn+1-2*r2,r2)} for r2 in range(len(nsig[nn]))] for nn in range(len(nsig))]

    n = [ {'cnt': comma(n[nn]),
           'prop': format_percentage(n[nn], nfields),
           'query': url_for(".number_field_render_webpage")+'?degree=%d'%(nn+1)} for nn in range(len(n))]

    info = {'degree': n,
            'nt': nt,
            'nsig': nsig,
            'sigtotals': sigtotals,
            'h': h,
            'has_h': comma(has_h),
            'has_h_pct': format_percentage(has_h, nfields),
            'hdeg': hdeg,
            'has_hdeg': has_hdeg,
            'sigclass1': sigclass1,
            'total': comma(nfields),
            'maxt': maxt,
            'cn': cn, 'dn': dn, 'an': an, 'sn': sn,
            'maxdeg': max_deg}
    return render_template("nf-statistics.html", info=info, credit=NF_credit, title=t, bread=bread)
コード例 #9
0
ファイル: number_field.py プロジェクト: koffie/lmfdb
def galstatdict(li, tots, t):
    return [ {'cnt': comma(li[nn]), 
              'prop': format_percentage(li[nn], tots[nn]),
              'query': url_for(".number_field_render_webpage")+'?degree=%d&galois_group=%s'%(nn+1,"%dt%d"%(nn+1,t[nn]))} for nn in range(len(li))]
コード例 #10
0
 def test_format_percentage(self):
     r"""
     Checking utility: format_percentage
     """
     self.assertEqual(format_percentage(12, 31), '     38.71')
     self.assertEqual(format_percentage(12, 37), '     32.43')
コード例 #11
0
ファイル: test_utils.py プロジェクト: koffie/lmfdb
 def test_format_percentage(self):
     r"""
     Checking utility: format_percentage
     """
     self.assertEqual(format_percentage(12,31), '     38.71')
     self.assertEqual(format_percentage(12,37), '     32.43')
コード例 #12
0
ファイル: ec_stats.py プロジェクト: jenpaulhus/lmfdb
    def init_ecdb_stats(self):
        if self._stats:
            return
        logger.debug("Computing elliptic curve stats...")
        ecdbstats = db.ec_curves.stats
        counts = self._counts
        stats = {}
        rank_counts = []
        rdict = dict(ecdbstats.get_oldstat('rank')['counts'])
        crdict = dict(ecdbstats.get_oldstat('class/rank')['counts'])
        for r in range(counts['max_rank']+1):
            try:
                ncu = rdict[str(r)]
                ncl = crdict[str(r)]
            except KeyError:
                ncu = rdict[r]
                ncl = crdict[r]
            prop = format_percentage(ncl,counts['nclasses'])
            rank_counts.append({'r': r, 'ncurves': ncu, 'nclasses': ncl, 'prop': prop})
        stats['rank_counts'] = rank_counts
        tor_counts = []
        tor_counts2 = []
        ncurves = counts['ncurves']
        tdict = dict(ecdbstats.get_oldstat('torsion')['counts'])
        tsdict = dict(ecdbstats.get_oldstat('torsion_structure')['counts'])
        for t in  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16]:
            try:
                ncu = tdict[t]
            except KeyError:
                ncu = tdict[str(t)]
            if t in [4,8,12]: # two possible structures
                ncyc = tsdict[str(t)]
                gp = "\(C_{%s}\)"%t
                prop = format_percentage(ncyc,ncurves)
                tor_counts.append({'t': t, 'gp': gp, 'ncurves': ncyc, 'prop': prop})
                nncyc = ncu-ncyc
                gp = "\(C_{2}\\times C_{%s}\)"%(t//2)
                prop = format_percentage(nncyc,ncurves)
                tor_counts2.append({'t': t, 'gp': gp, 'ncurves': nncyc, 'prop': prop})
            elif t==16: # all C_2 x C_8
                gp = "\(C_{2}\\times C_{8}\)"
                prop = format_percentage(ncu,ncurves)
                tor_counts2.append({'t': t, 'gp': gp, 'ncurves': ncu, 'prop': prop})
            else: # all cyclic
                gp = "\(C_{%s}\)"%t
                prop = format_percentage(ncu,ncurves)
                tor_counts.append({'t': t, 'gp': gp, 'ncurves': ncu, 'prop': prop})
        stats['tor_counts'] = tor_counts+tor_counts2

        shadict = dict(ecdbstats.get_oldstat('sha')['counts'])
        stats['max_sha'] = max([int(s) for s in shadict])
        sha_counts = []
        from sage.misc.functional import isqrt
        sha_is_int = True
        try:
            nc = shadict[1]
        except KeyError:
            sha_is_int = False
        for s in range(1,1+isqrt(stats['max_sha'])):
            s2 = s*s
            if sha_is_int:
                nc = shadict.get(s2,0)
            else:
                nc = shadict.get(str(s2),0)
            if nc:
                sha_counts.append({'s': s, 'ncurves': nc})
        stats['sha_counts'] = sha_counts
        self._stats = stats
        logger.debug("... finished computing elliptic curve stats.")
コード例 #13
0
    def init_ecdb_stats(self):
        if self._stats:
            return
        logger.debug("Computing elliptic curve stats...")
        ecdb = db.ec_curves
        counts = self._counts
        stats = {}

        # rank distribution

        rank_counts = []
        ranks = range(counts['max_rank'] + 1)
        for r in ranks:
            ncu = ecdb.count({'rank': r})
            ncl = ecdb.count({'rank': r, 'number': 1})
            prop = format_percentage(ncl, counts['nclasses'])
            rank_counts.append({
                'r': r,
                'ncurves': ncu,
                'nclasses': ncl,
                'prop': prop
            })
        stats['rank_counts'] = rank_counts

        # torsion distribution

        tor_counts = []
        tor_counts2 = []
        ncurves = counts['ncurves']
        for t in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16]:
            ncu = ecdb.count({'torsion': t})
            if t in [4, 8, 12]:  # two possible structures
                ncyc = ecdb.count({'torsion_structure': [t]})
                gp = "\(C_{%s}\)" % t
                prop = format_percentage(ncyc, ncurves)
                tor_counts.append({
                    't': t,
                    'gp': gp,
                    'ncurves': ncyc,
                    'prop': prop
                })
                nncyc = ncu - ncyc
                gp = "\(C_{2}\\times C_{%s}\)" % (t // 2)
                prop = format_percentage(nncyc, ncurves)
                tor_counts2.append({
                    't': t,
                    'gp': gp,
                    'ncurves': nncyc,
                    'prop': prop
                })
            elif t == 16:  # all C_2 x C_8
                gp = "\(C_{2}\\times C_{8}\)"
                prop = format_percentage(ncu, ncurves)
                tor_counts2.append({
                    't': t,
                    'gp': gp,
                    'ncurves': ncu,
                    'prop': prop
                })
            else:  # all cyclic
                gp = "\(C_{%s}\)" % t
                prop = format_percentage(ncu, ncurves)
                tor_counts.append({
                    't': t,
                    'gp': gp,
                    'ncurves': ncu,
                    'prop': prop
                })
        stats['tor_counts'] = tor_counts + tor_counts2

        # Sha distribution

        max_sha = ecdb.max('sha')
        stats['max_sha'] = max_sha
        max_sqrt_sha = Integer(
            max_sha).sqrt()  # exact since all sha values are squares!
        sha_counts = [{
            's': s,
            'ncurves': ecdb.count({'sha': s**2})
        } for s in range(1, 1 + max_sqrt_sha)]
        # remove values with a count of 0
        sha_counts = [sc for sc in sha_counts if sc['ncurves']]
        stats['sha_counts'] = sha_counts
        self._stats = stats
        logger.debug("... finished computing elliptic curve stats.")
コード例 #14
0
ファイル: number_field.py プロジェクト: LMFDB/lmfdb
def statistics():
    # FIXME use StatsDisplay
    fields = db.nf_fields
    title = 'Global Number Field Statistics'
    bread = [('Global Number Fields', url_for(".number_field_render_webpage")),
             ('Number Field Statistics', '')]
    init_nf_count()
    ntrans = [0, 1, 1, 2, 5, 5, 16, 7, 50, 34, 45, 8, 301, 9, 63, 104, 1954,
              10, 983, 8, 1117, 164, 59, 7, 25000, 211, 96, 2392, 1854, 8, 5712]
    degree_stats = fields.stats.column_counts('degree')
    n = [degree_stats[elt + 1] for elt in range(23)]

    degree_r2_stats = fields.stats.column_counts(['degree', 'r2'])
    # if a count is missing it is because it is zero
    nsig = [[degree_r2_stats.get((deg+1, s), 0) for s in range((deg+3)/2)]
            for deg in range(23)]
    # Galois groups
    nt_stats = fields.stats.column_counts(['degree', 'galt'])
    # if a count is missing it is because it is zero
    nt_all = [[nt_stats.get((deg+1, t+1), 0) for t in range(ntrans[deg+1])]
              for deg in range(23)]
    nt = [nt_all[j] for j in range(7)]
    # Galois group families
    cn = galstatdict([u[0] for u in nt_all], n, [1 for u in nt_all])
    sn = galstatdict([u[max(len(u)-1,0)] for u in nt_all], n, [len(u) for u in nt_all])
    an = galstatdict([u[max(len(u)-2,0)] for u in nt_all], n, [len(u)-1 for u in nt_all])
    # t-numbers for D_n
    dn_tlist = [1, 1, 2, 3, 2, 3, 2, 6, 3, 3, 2, 12, 2, 3, 2, 56, 2, 13, 2, 10,
                5, 3, 2]
    dn = galstatdict([nt_stats[(j+1,dn_tlist[j])] for j in range(len(dn_tlist))], n, dn_tlist)

    h = [fields.count({'class_number': {'$lt': 1+10**j, '$gt': 10**(j-1)}}) for j in range(12)]
    has_h = fields.count({'class_number': {'$exists': True}})
    hdeg_stats = {j: fields.stats.column_counts('degree', {'class_number': {'$lt': 1+10**j, '$gt': 10**(j-1)}}) for j in range(1, 12)}
    hdeg_stats[0] = fields.stats.column_counts('degree', {'class_number': 1})
    # if a count is missing it is because it is zero
    hdeg = [[hdeg_stats[j].get(deg+1, 0) for j in range(12)] for deg in range(23)]
    has_hdeg_stats = fields.stats.column_counts('degree', {'class_number': {'$exists': True}})
    has_hdeg = [has_hdeg_stats[deg+1] for deg in range(23)]
    hdeg = [[{'cnt': comma(hdeg[nn][j]),
              'prop': format_percentage(hdeg[nn][j], has_hdeg[nn]),
              'query': url_for(".number_field_render_webpage")+'?degree=%d&class_number=%s' % (nn + 1, str(1 + 10**(j - 1)) + '-' + str(10**j))}
             for j in range(len(h))]
            for nn in range(len(hdeg))]

    has_hdeg = [{'cnt': comma(has_hdeg[nn]),
                 'prop': format_percentage(has_hdeg[nn], n[nn]),
                 'query': url_for(".number_field_render_webpage")+'?degree=%d&class_number=1-10000000000000' % (nn + 1)} for nn in range(len(has_hdeg))]
    maxt = 1+max([len(entry) for entry in nt])

    nt = [[{'cnt': comma(nt[nn][tt]),
            'prop': format_percentage(nt[nn][tt], n[nn]),
            'query': url_for(".number_field_render_webpage")+'?degree=%d&galois_group=%s' % (nn + 1, "%dt%d" % (nn + 1, tt + 1))}
           for tt in range(len(nt[nn]))]
          for nn in range(len(nt))]
    # Totals for signature table
    sigtotals = [comma(
                 sum([nsig[nn][r2]
                 for nn in range(max(r2*2 - 1, 0), 23)]))
                 for r2 in range(12)]
    nsig = [[{'cnt': comma(nsig[nn][r2]),
             'prop': format_percentage(nsig[nn][r2], n[nn]),
             'query': url_for(".number_field_render_webpage")+'?degree=%d&signature=[%d,%d]'%(nn+1,nn+1-2*r2,r2)} for r2 in range(len(nsig[nn]))] for nn in range(len(nsig))]
    h = [{'cnt': comma(h[j]),
          'prop': format_percentage(h[j], has_h),
          'label': '$10^{' + str(j - 1) + '}<h\leq 10^{' + str(j) + '}$',
          'query': url_for(".number_field_render_webpage")+'?class_number=%s' % (str(1 + 10**(j - 1)) + '-' + str(10**j))} for j in range(len(h))]
    h[0]['label'] = '$h=1$'
    h[1]['label'] = '$1<h\leq 10$'
    h[2]['label'] = '$10<h\leq 10^2$'
    h[0]['query'] = url_for(".number_field_render_webpage")+'?class_number=1'

    # Class number 1 by signature
    sigclass1 = fields.stats.get_oldstat('sigclass1')['counts']
    sighasclass = fields.stats.get_oldstat('sighasclass')['counts']
    sigclass1 = [[{'cnt': comma(sigclass1[nn][r2]),
                   'prop': format_percentage(sigclass1[nn][r2], sighasclass[nn][r2]) if sighasclass[nn][r2] > 0 else 0,
                   'show': sighasclass[nn][r2] > 0,
                   'query': url_for(".number_field_render_webpage")+'?degree=%d&signature=[%d,%d]&class_number=1' % (nn + 1, nn + 1 - 2*r2, r2)}
                  for r2 in range(len(nsig[nn]))] for nn in range(len(nsig))]

    n = [{'cnt': comma(n[nn]),
          'prop': format_percentage(n[nn], nfields),
          'query': url_for(".number_field_render_webpage")+'?degree=%d' % (nn + 1)}
         for nn in range(len(n))]

    info = {'degree': n,
            'nt': nt,
            'nsig': nsig,
            'sigtotals': sigtotals,
            'h': h,
            'has_h': comma(has_h),
            'has_h_pct': format_percentage(has_h, nfields),
            'hdeg': hdeg,
            'has_hdeg': has_hdeg,
            'sigclass1': sigclass1,
            'total': comma(nfields),
            'maxt': maxt,
            'cn': cn, 'dn': dn, 'an': an, 'sn': sn,
            'maxdeg': max_deg}
    return render_template("nf-statistics.html",
                           info=info,
                           credit=NF_credit,
                           title=title,
                           bread=bread)