From 8c5436916c422e580619aafd7879d476047bc6c1 Mon Sep 17 00:00:00 2001 From: John McMaster Date: Fri, 24 Aug 2018 12:51:21 -0700 Subject: [PATCH] timfuz: begin converting to fractions Signed-off-by: John McMaster --- experiments/timfuz/timfuz_checksub.py | 4 +++- experiments/timfuz/timfuz_rref.py | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/experiments/timfuz/timfuz_checksub.py b/experiments/timfuz/timfuz_checksub.py index 774ce020..cf290d78 100644 --- a/experiments/timfuz/timfuz_checksub.py +++ b/experiments/timfuz/timfuz_checksub.py @@ -8,7 +8,7 @@ import math from collections import OrderedDict # check for issues that may be due to round off error -STRICT = 1 +STRICT = 0 def Adi2matrix_random(A_ubd, b_ub, names): # random assignment @@ -92,6 +92,8 @@ def row_sub_syms(row, sub_json, verbose=False): assert pivot not in row # after all constants are applied, the row should end up positive? + # numeric precision issues may limit this + # Ex: AssertionError: ('PIP_BSW_2ELSING0', -2.220446049250313e-16) if STRICT: for k, v in sorted(row.items()): assert v > 0, (k, v) diff --git a/experiments/timfuz/timfuz_rref.py b/experiments/timfuz/timfuz_rref.py index 2fc3c103..1fa514b3 100644 --- a/experiments/timfuz/timfuz_rref.py +++ b/experiments/timfuz/timfuz_rref.py @@ -12,8 +12,22 @@ import math import json import sympy from collections import OrderedDict +from fractions import Fraction -STRICT = 1 +STRICT = 0 + +def fracr(r): + DELTA = 0.0001 + + for i, x in enumerate(r): + if type(x) is float: + xi = int(x) + assert abs(xi - x) < DELTA + r[i] = xi + return [Fraction(x) for x in r] + +def fracm(m): + return [fracr(r) for r in m] class State(object): def __init__(self, Ads, drop_names=[]): @@ -97,10 +111,13 @@ def comb_corr_sets(state, verbose=False): mnp = Anp2matrix(Anp) print('Matrix: %u rows x %u cols' % (len(mnp), len(mnp[0]))) print('Converting np to sympy matrix') - msym = sympy.Matrix(mnp) + mfrac = fracm(mnp) + print('mfrac', type(mfrac[0][0])) + msym = sympy.Matrix(mfrac) print('Making rref') rref, pivots = msym.rref() + if verbose: print('names') print(names)