From 00e46546f49e2d861fd37282be3d7ee2c5ea9784 Mon Sep 17 00:00:00 2001 From: Remi Ehounou Date: Sat, 22 May 2021 01:05:18 -0400 Subject: [PATCH] Test function represent flow operational --- SourceCode/AlgorithmAnalyser.py | 45 ++++++++-------- SourceCode/TestFunctions/Bukin2.py | 49 +++++++++--------- .../__pycache__/Bukin2.cpython-39.pyc | Bin 663 -> 5253 bytes 3 files changed, 46 insertions(+), 48 deletions(-) diff --git a/SourceCode/AlgorithmAnalyser.py b/SourceCode/AlgorithmAnalyser.py index 76b69bf..d0b4f78 100644 --- a/SourceCode/AlgorithmAnalyser.py +++ b/SourceCode/AlgorithmAnalyser.py @@ -26,6 +26,11 @@ import statistics as st from scipy import signal, misc, ndimage +def installFalcoo(mirror = 'https://utstat.toronto.edu/cran/'): + utils = importr('utils') + utils.install_packages('flacco', repos=mirror) + utils.install_packages('list', repos=mirror) + class counter: #wraps a function, to keep a running count of how many #times it's been called @@ -111,8 +116,8 @@ def writerepresentation(funcpath, charas): # create a string format of the representation variables representation = '' for line in list(charas): - representation += '\n\t#_# ' + line + ': ' + str(charas[line]).replace('\n', ',') - representation+='\n' + representation += '\n\t#_# ' + line + ': ' + repr(charas[line]).replace('\n','') + representation+='\n\n\t#_# Represented: 1\n\n' # Creating the new docstring to be inserted into the file with open(funcpath, "r") as file: @@ -121,7 +126,7 @@ def writerepresentation(funcpath, charas): docstrs += representation repl = "\\1"+docstrs+"\t\\2" - # Create the new content of the file to replace the old. Overwriting the whole thing + # Create the new content of the file to replace the old. Replacing the whole thing pattrn = re.compile("(def main\(.*?\):.*?''').*?('''.*?return\s+.*?\n|$)", flags=re.DOTALL) newContent = pattrn.sub(repl, content, count=1) # Overwrite the test function file @@ -138,46 +143,45 @@ def representfunc(funcpath): # Finding the function characteristics inside the docstring if funcmodule.main.__doc__: - regex = re.compile("#_#\s?(\w+):\s?([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)") + regex = re.compile("#_#\s?(\w+):(.+)?\n") # this regular expression matches the characteristics already specified in the docstring section of the function -- old exp: "#_#\s?(\w+):\s?([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)" characs = re.findall(regex, funcmodule.main.__doc__) results = {} for charac in characs: - results[charac[0]] = float(charac[1]) + results[charac[0]] = eval(charac[1]) # Automatically generate the representation if the docstrings did not return anything if not ('Represented' in results): print("Warning, the Representation of the Test Function has not been specified\n===\n******Calculating the Characteristics******") n = int(results['dimmensions']) - - execpath = sys.executable + + # Importing FLACCO using rpy2 + flacco = importr('flacco') # creating the r functions rlist = robjs.r['list'] rapply = robjs.r['apply'] + rvector = robjs.r['c'] + r_unlist = robjs.r['unlist'] rtestfunc = rinterface.rternalize(funcmodule.main) ### - lower =-10 - upper = 10 - X = flacco.createInitialSample(n_obs = 500, dim = n, control = rlist(init_sample_type = 'lhs', init_sample_lower = lower, init_sample_upper = upper)) + lower = r_unlist(rvector(results['lower'])) + upper = r_unlist(rvector(results['upper'])) + X = flacco.createInitialSample(n_obs = 500, dim = n, control = rlist(**{'init_sample.type' : 'lhs', 'init_sample.lower' : lower, 'init_sample.upper' : upper})) y = rapply(X, 1, rtestfunc) testfuncobj = flacco.createFeatureObject(X = X, y = y, fun = rtestfunc, lower = lower, upper = upper, blocks = 10) - # these are the retained features. Note that some features are being excluded for being problematic and to avoid overcomplicating the neural network + # these are the retained features. Note that some features are being excluded for being problematic and to avoid overcomplicating the neural network.... the feature sets are redundant and the most relevant ones have been retained # the excluded feature sets are: 'bt', 'ela_level' - # feature sets that require special attention: 'cm_angle', 'cm_grad', 'limo', 'gcm' (soo big with some nans), + # feature sets that require special attention: 'cm_angle', 'cm_grad', 'limo', 'gcm' (large set with some nans), featureset = ['cm_angle','cm_conv','cm_grad','ela_conv','ela_curv','ela_distr','ela_local','ela_meta','basic','disp','limo','nbc','pca','gcm','ic'] pyfeats = dict() for feature in featureset: rawfeats = flacco.calculateFeatureSet(testfuncobj, set=feature) pyfeats[feature] = asarray(rawfeats) - - - writerepresentation(funcpath, pyfeats) - return results @@ -234,14 +238,7 @@ if __name__ == '__main__': # testfunctionpaths = ["/home/remi/Documents/MDAF-GitLAB/SourceCode/TestFunctions/Bukin4.py"] # funcnames = ["Bukin4"] - # Installing the packages needed for FLACCO - utils = importr('utils') - #utils.install_packages('flacco', repos='https://utstat.toronto.edu/cran/') - #utils.install_packages('list', repos='https://utstat.toronto.edu/cran/') - ####utils.install_packages('reticulate', repos='https://utstat.toronto.edu/cran/') - - reticulate = importr('reticulate') - flacco = importr('flacco') + objs = 0 args = {"high": 200, "low": -200, "t": 1000, "p": 0.95} diff --git a/SourceCode/TestFunctions/Bukin2.py b/SourceCode/TestFunctions/Bukin2.py index 2966192..13ac998 100644 --- a/SourceCode/TestFunctions/Bukin2.py +++ b/SourceCode/TestFunctions/Bukin2.py @@ -1,28 +1,29 @@ def main(args): - ''' - - :param args: list of floats - :return: float - - - #_# dimmensions: 2 + ''' - #_# cm_angle: [[1.33897501e+01], [ nan], [1.40464922e+01], [ nan], [3.10339907e+00], [ nan], [1.00000000e+00], [ nan], [0.00000000e+00], [1.40000000e-02]] - #_# cm_conv: [[0.0297619 ], [0.00595238], [0.22619048], [0.33333333], [0. ], [0.062 ]] - #_# cm_grad: [[0.64254617], [ nan], [0. ], [0.01 ]] - #_# ela_conv: [[0.00000000e+00], [0.00000000e+00], [2.77028225e-02], [2.77028225e-02], [1.00000000e+03], [1.31000000e-01]] - #_# ela_curv: [[1.00000000e+02], [1.00000355e+02], [1.00005040e+02], [1.00002931e+02], [1.00009346e+02], [1.00015828e+02], [5.10494927e-03], [0.00000000e+00], [5.62028278e+01], [7.31406032e+01], [5.13544460e+02], [1.30604608e+02], [3.75618981e+02], [1.05254867e+04], [1.23941806e+03], [0.00000000e+00], [3.02592268e+00], [9.02638335e+02], [1.56148314e+29], [3.81682127e+03], [3.25219248e+04], [2.89737144e+31], [2.05852895e+30], [5.00000000e-03], [8.40000000e+03], [1.13300000e+00]] - #_# ela_distr: [[-0.03671804], [-1.24272349], [ 5. ], [ 0. ], [ 0.023 ]] - #_# ela_local: [[3.00000000e+00], [3.00000000e-02], [1.00267380e+00], [6.66666667e-01], [1.10000000e-01], [4.45000000e-01], [4.45000000e-01], [2.00000000e+01], [2.00000000e+01], [2.26000000e+01], [2.00000000e+01], [2.50000000e+01], [3.00000000e+01], [3.51619629e+00], [2.26300000e+03], [2.35000000e-01]] - #_# ela_meta: [[9.99993630e-01], [1.01176187e+02], [8.08905581e-01], [9.99825941e+01], [1.23602305e+02], [9.99993660e-01], [1.00000000e+00], [3.95467951e+13], [1.00000000e+00], [0.00000000e+00], [1.00000000e-02]] - #_# basic: [[ 2. ], [500. ], [-10. ], [-10. ], [ 10. ], [ 10. ], [100.74931228], [199.87416126], [ 10. ], [ 10. ], [100. ], [ 1. ], [ 1. ], [ 0. ], [ 0. ]] - #_# disp: [[ 0.75879825], [ 0.61920947], [ 0.61336996], [ 0.68491606], [ 0.76149282], [ 0.5882951 ], [ 0.56069976], [ 0.60774698], [-0.12954581], [-0.20451683], [-0.20765314], [-0.16922681], [-0.12717398], [-0.21952442], [-0.23423848], [-0.20915252], [ 0. ], [ 0.011 ]] - #_# limo: [[9.99858662e+01], [1.00000000e+00], [9.99858662e+01], [ nan], [ nan], [ nan], [1.23602305e+02], [ nan], [ nan], [ nan], [ nan], [ nan], [0.00000000e+00], [3.00000000e-03]] - #_# nbc: [[ 0.30653068], [ 0.64759411], [ 0.26842005], [ 0.37025091], [-0.10065679], [ 0. ], [ 0.031 ]] - #_# pca: [[1. ], [1. ], [0.33333333], [0.66666667], [0.51467093], [0.50754981], [0.9998948 ], [0.66673408], [0. ], [0.002 ]] - #_# gcm: [[1.00000000e+00], [1.00000000e-02], [0.00000000e+00], [0.00000000e+00], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [ nan], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [ nan], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [ nan], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [0.00000000e+00], [6.00000000e-03], [1.00000000e+00], [1.00000000e-02], [0.00000000e+00], [0.00000000e+00], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [ nan], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [ nan], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [ nan], [1.00000000e-02], [1.00000000e-02], [1.00000000e-02], [0.00000000e+00], [5.00000000e-03], [5.00000000e+00], [5.00000000e-02], [9.50000000e-01], [1.00000000e+00], [1.53846154e-01], [2.00000000e-01], [2.30769231e-01], [2.30769231e-01], [4.21325044e-02], [0.00000000e+00], [0.00000000e+00], [0.00000000e+00], [0.00000000e+00], [0.00000000e+00], [0.00000000e+00], [0.00000000e+00], [2.00000000e-01], [1.00000000e-02], [6.40000000e-01], [2.88183969e-01], [1.00000000e+00], [1.00000000e+00], [5.00000000e-02], [0.00000000e+00], [1.02000000e-01]] - #_# ic: [[ 0.71881882], [ 2.00700701], [64.09244019], [ 1.82682683], [ 0.29116466], [ 0. ], [ 0.203 ]] + #_# dimmensions: 2 + #_# upper: [-5, 3] + #_# lower: [-15, -3] + #_# minimum: [-10,0] + + + #_# cm_angle: array([[3.49881571e-01], [1.07838645e-01], [3.22906733e-01], [1.09086923e-01], [1.36740093e+02], [3.72333248e+01], [6.24743683e-02], [1.45683932e-02], [0.00000000e+00], [7.70000000e-02]]) + #_# cm_conv: array([[0.08928571], [0.04166667], [0.51785714], [0.48214286], [0. ], [0.038 ]]) + #_# cm_grad: array([[0.80986036], [0.11715403], [0. ], [0.05 ]]) + #_# ela_conv: array([[0.00000000e+00], [0.00000000e+00], [2.74360332e+00], [2.74360332e+00], [1.00000000e+03], [1.39000000e-01]]) + #_# ela_curv: array([[1.00520667e+02], [1.01157352e+02], [1.02102548e+02], [1.01875092e+02], [1.03042277e+02], [1.04371521e+02], [1.09894163e+00], [0.00000000e+00], [3.34559633e+00], [4.02357156e+00], [5.48926800e+00], [5.13982675e+00], [6.55405463e+00], [9.78678891e+00], [1.70558030e+00], [0.00000000e+00], [3.29353234e+00], [1.48351404e+04], [2.19236653e+31], [4.03941866e+04], [3.14916313e+07], [4.17710288e+33], [2.95558281e+32], [0.00000000e+00], [8.40000000e+03], [1.06400000e+00]]) + #_# ela_distr: array([[ 0.01739786], [-1.01700978], [ 1. ], [ 0. ], [ 0.02 ]]) + #_# ela_local: array([[1.000e+00], [1.000e-02], [1.000e+00], [ nan], [1.000e+00], [0.000e+00], [1.000e+00], [1.000e+01], [1.000e+01], [1.000e+01], [1.000e+01], [1.000e+01], [1.000e+01], [0.000e+00], [1.001e+03], [9.300e-02]]) + #_# ela_meta: array([[9.98338849e-01], [1.91750766e+02], [1.99998995e+01], [1.00059864e+02], [5.00301834e+00], [9.98335620e-01], [1.00000000e+00], [3.55077954e+14], [1.00000000e+00], [0.00000000e+00], [9.00000000e-03]]) + #_# basic: array([[ 2. ], [ 500. ], [ -15. ], [ -3. ], [ -5. ], [ 3. ], [-388.17734244], [ 369.94308917], [ 10. ], [ 10. ], [ 100. ], [ 100. ], [ 1. ], [ 0. ], [ 0. ]]) + #_# disp: array([[ 0.26139886], [ 0.36358526], [ 0.5516879 ], [ 0.80572442], [ 0.25023966], [ 0.32900436], [ 0.49402763], [ 0.72135232], [-3.13648576], [-2.70254902], [-1.90376706], [-0.82499549], [-3.02850003], [-2.7103465 ], [-2.04376951], [-1.125539 ], [ 0. ], [ 0.01 ]]) + #_# limo: array([[ 1.02002699e+02], [ 9.98507972e-01], [ 1.02155253e+02], [ 1.13240181e+00], [-3.88783841e-02], [-9.92102532e-01], [ 5.48006296e+00], [ 1.74733189e+00], [ 3.39374032e+01], [ 5.00221530e+00], [ 2.94406289e+00], [ 3.22874553e-02], [ 0.00000000e+00], [ 9.50000000e-02]]) + #_# nbc: array([[ 0.5341454 ], [ 0.87561488], [ 0.47062778], [ 0.15902654], [-0.19513986], [ 0. ], [ 0.027 ]]) + #_# pca: array([[1. ], [1. ], [0.33333333], [0.66666667], [0.73549361], [0.51109865], [0.99976032], [0.66217335], [0. ], [0.002 ]]) + #_# gcm: array([[1. ], [0.01 ], [0.99 ], [0. ], [1. ], [1. ], [1. ], [1. ], [ nan], [1. ], [1. ], [1. ], [1. ], [ nan], [1. ], [1. ], [1. ], [1. ], [1. ], [ nan], [1. ], [1. ], [0.01 ], [0. ], [0.085], [1. ], [0.01 ], [0.99 ], [0. ], [1. ], [1. ], [1. ], [1. ], [ nan], [1. ], [1. ], [1. ], [1. ], [ nan], [1. ], [1. ], [1. ], [1. ], [1. ], [ nan], [1. ], [1. ], [0.01 ], [0. ], [0.084], [1. ], [0.01 ], [0.99 ], [0. ], [1. ], [1. ], [1. ], [1. ], [ nan], [1. ], [1. ], [1. ], [1. ], [ nan], [1. ], [1. ], [1. ], [1. ], [1. ], [ nan], [1. ], [1. ], [0.01 ], [0. ], [0.088]]) + #_# ic: array([[ 0.67118887], [ 2.02702703], [70.28244264], [ 1.90690691], [ 0.23293173], [ 0. ], [ 0.204 ]]) + + #_# Represented: 1 + ''' return 100*(args[1]-0.01*args[0]**2+1)+0.01*(args[0]+10)**2 - - return 0 diff --git a/SourceCode/TestFunctions/__pycache__/Bukin2.cpython-39.pyc b/SourceCode/TestFunctions/__pycache__/Bukin2.cpython-39.pyc index c38e353e7f793390c32e0070c2b291a7bd09e60c..8661be07d23bbdb4047a4aa1babada35b78f23c8 100644 GIT binary patch literal 5253 zcmeHLJC7Vi5T5f3+rp789Y_QtIpKu2x4WyK76SZ`od5wQ;$)fi?&!Q?AE$kQ41~@| z_y?qr@PnKoqKnCh_jrLw-UuC0nkFtaF!#zNok^a7j?>&5%2A9#^kC^vvHad^r3;4Zw zJ-d;;18g6^XXvH<(3BAtuBU0PlD8!0ZsZQ9PX@E2NpU+LEEa?3?;jqLFfjyW zy()TAJ-(G!<4_6d0|jSn6DOf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