From 97ea34d4cd5e39d0c68bf92a7d0200dd49153363 Mon Sep 17 00:00:00 2001 From: John McMaster Date: Fri, 24 Aug 2018 13:22:34 -0700 Subject: [PATCH] timfuz: checksub uses fractions Signed-off-by: John McMaster --- experiments/timfuz/timfuz_checksub.py | 32 +++++---------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/experiments/timfuz/timfuz_checksub.py b/experiments/timfuz/timfuz_checksub.py index a1bbc5d7..3bd4df63 100644 --- a/experiments/timfuz/timfuz_checksub.py +++ b/experiments/timfuz/timfuz_checksub.py @@ -6,6 +6,7 @@ import glob import json import math from collections import OrderedDict +from fractions import Fraction # check for issues that may be due to round off error STRICT = 1 @@ -77,8 +78,8 @@ def row_sub_syms(row, sub_json, verbose=False): if verbose: print('pivot %i %s' % (n, pivot)) for subk, subv in sorted(sub_json['subs'][group].items()): - oldn = row.get(subk, 0) - rown = oldn - n * (1.0* subv[0] / subv[1]) + oldn = row.get(subk, Fraction(0)) + rown = oldn - n * subv if verbose: print(" %s: %d => %d" % (subk, oldn, rown)) if rown == 0: @@ -190,32 +191,11 @@ def run(fns_in, sub_json=None, verbose=False, corner=None): print('slogdet :) : %s, %s' % (sign, logdet)) def load_sub(fn): - delta = 0.001 j = json.load(open(fn, 'r')) - # convert groups to use integer constants - # beware of roundoff error - # if we round poorly here, it won't give incorrect results later, but may make it fail to find a good solution - - if 'pivots' in j: - print('pivots: using existing') - else: - print('pivots: guessing') - - pivots = OrderedDict() - j['pivots'] = pivots - - for name, vals in sorted(j['subs'].items()): - pivot = None - for k, v in vals.items(): - vals[k] = float(v) - - # there may be more than one acceptable pivot - # take the first - if v == 1 and pivot is None: - pivot = k - assert pivot is not None - pivots[name] = pivot + for name, vals in sorted(j['subs'].items()): + for k, v in vals.items(): + vals[k] = Fraction(v[0], v[1]) return j