From 3b2b6c43a9310a50c108d0858b51da5906543052 Mon Sep 17 00:00:00 2001 From: Kai Staats Date: Mon, 19 Sep 2016 01:13:59 -0600 Subject: [PATCH] minor adjust to lambdify test code --- RELEASE_NOTES.txt | 19 ++++++++++--------- karoo_gp_base_class.py | 20 +++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 1cfb5b0..dfd7d5f 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,3 +1,8 @@ +2016 09/19 + +Minor adjustment to the lambdify test code in 'fx_eval_subs()' method. Testing now ... + + 2016 09/16 With the 09/14 update I failed to upload the new coefficients.csv file to the files/ directory. While not yet engaged, @@ -17,8 +22,7 @@ I welcome any assistance with these, if anyone has experience and time. 2016 09/14 - version 0.9.2.0 In karoo_gp_base_class.py - - Merged 2 instances of 'algo_sym.subs(data)' into a single, new method 'fx_eval_subs' - - Removed redundant lines in the method 'fx_karoo_data_load' + - Removed redundant lines in the method 'fx_karoo_data_load()' - Added support for the Sympy 'lambdify' function in 'fx_karoo_data_load' (see explanation below) - Added a draft means of catching divide-by-zero errors in the new 'lambdify' function - Discovered the prior 'fx_eval_subs' incorrected applied a value of 1 to the variable 'result' as a means to @@ -26,12 +30,9 @@ In karoo_gp_base_class.py Classification and Regression runs. My apology for not catching this sooner. "While attending the CHEAPR 2016 workshop hosted by the Center for Cosmology and Astro-Particle Physics, The Ohio State -University, Erik Hemberg of MIT suggested that I could improve the performance by combining what were to Sympy.subs -calls into one. This was successfully completed and the new method 'fx_eval_subs' was created. - -Michael Zevin of Northwestern University proposed that Karoo GP *should* be able to process trees far faster than what -we were seeing. I looked into the Sympy functions I was at that time using. Indeed, '.subs' is noted as easy to use, -but terribly slow as it relies upon an internal, Python mathematical library. I therefore replaced '.subs' with +University, Michael Zevin of Northwestern University proposed that Karoo GP *should* be able to process trees far faster +than what we were seeing. I looked into the Sympy functions I was at that time using. Indeed, '.subs' is noted as easy +to use, but terribly slow as it relies upon an internal, Python mathematical library. I therefore replaced '.subs' with '.lambdify' which calls upon the C-based Numpy maths library. It is slated to be 500x faster than '.subs', but I am seeing only a 2x performance increase. Clearly, there are yet other barriers to remove. @@ -49,7 +50,7 @@ I'll keep you informed ..." --kai 2016 08/08 - version 0.9.1.9 In karoo_gp_base_class.py - - Created a new method 'fx_eval_subs' which conducts the SymPy subs function for both train and test data. + - Created a new method 'fx_eval_subs()' which conducts the SymPy subs function for both train and test data. - Consolidated duplicate SymPy sub calls in both Train and Test methods, at Erik H. suggestion --thank you! - Consolidated duplicate lines into single lines in both Train and Test methods. - Fixed bug in which Ramped 50/50 trees would not print in Play mode; removed Ramped 50/50 option from Play mode as diff --git a/karoo_gp_base_class.py b/karoo_gp_base_class.py index c0682e7..b46dc0b 100644 --- a/karoo_gp_base_class.py +++ b/karoo_gp_base_class.py @@ -2,7 +2,7 @@ # Define the methods and global variables used by Karoo GP # by Kai Staats, MSc UCT / AIMS; see LICENSE.md # Much thanks to Emmanuel Dufourq and Arun Kumar for their support, guidance, and free psychotherapy sessions -# version 0.9.2.0 +# version 0.9.2.0b ''' A NOTE TO THE NEWBIE, EXPERT, AND BRAVE @@ -1198,16 +1198,18 @@ class Base_GP(object): ''' ### OLD .subs method ### - #result = self.algo_sym.subs(data) # process the expression against the data - #if str(result) == 'zoo': result = 1 # TEST & DEBUG: print 'divide by zero', result; self.fx_karoo_pause(0) - #else: result = round(float(result), self.precision) # force 'result' to the set number of floating points + subs = self.algo_sym.subs(data) # process the expression against the data + if str(subs) == 'zoo': pass # TEST & DEBUG: print 'divide by zero', subs; self.fx_karoo_pause(0) + else: result = round(float(subs), self.precision) # force 'result' to the set number of floating points + result = round(float(subs), self.precision) # force 'result' to the set number of floating points ### NEW .lambdify method ### - f = sp.lambdify(self.algo_ops, self.algo_sym, "numpy") # define the function - with np.errstate(divide = 'ignore'): # do not raise 'divide by zero' errors - result = f(*sp.flatten(data.values())) # execute the function against the given data row; which currently remains a dictionary - # if str(subs) == 'inf' or str(subs) == '-inf': print subs; self.fx_karoo_pause(0) # TEST & DEBUG catch divide by zero - result = round(float(result), self.precision) # force 'result' to the set number of floating points + # f = sp.lambdify(self.algo_ops, self.algo_sym, "numpy") # define the function + # with np.errstate(divide = 'ignore', invalid = 'ignore'): # do not raise 'divide by zero' errors + # lamb = f(*sp.flatten(data.values())) # execute the function against the given data row; which currently remains a dictionary + # MAY NOT BE NEEDED - if str(lamb) == 'inf' or str(lamb) == '-inf': pass # TEST & DEBUG: print 'divide by zero', subs; self.fx_karoo_pause(0) + # MAY NOT BE NEEDED - else: result = round(float(lamb), self.precision) # force 'result' to the set number of floating points + # result = round(float(lamb), self.precision) # force 'result' to the set number of floating points return result