diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/MDAF-GitLAB.iml b/.idea/MDAF-GitLAB.iml new file mode 100644 index 0000000..8388dbc --- /dev/null +++ b/.idea/MDAF-GitLAB.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/aws.xml b/.idea/aws.xml new file mode 100644 index 0000000..b63b642 --- /dev/null +++ b/.idea/aws.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f6104af --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7e217d9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.spyproject/config/backups/codestyle.ini.bak b/.spyproject/config/backups/codestyle.ini.bak new file mode 100644 index 0000000..0f54b4c --- /dev/null +++ b/.spyproject/config/backups/codestyle.ini.bak @@ -0,0 +1,8 @@ +[codestyle] +indentation = True +edge_line = True +edge_line_columns = 79 + +[main] +version = 0.2.0 + diff --git a/.spyproject/config/backups/encoding.ini.bak b/.spyproject/config/backups/encoding.ini.bak new file mode 100644 index 0000000..a17aced --- /dev/null +++ b/.spyproject/config/backups/encoding.ini.bak @@ -0,0 +1,6 @@ +[encoding] +text_encoding = utf-8 + +[main] +version = 0.2.0 + diff --git a/.spyproject/config/backups/vcs.ini.bak b/.spyproject/config/backups/vcs.ini.bak new file mode 100644 index 0000000..fd66eae --- /dev/null +++ b/.spyproject/config/backups/vcs.ini.bak @@ -0,0 +1,7 @@ +[vcs] +use_version_control = False +version_control_system = + +[main] +version = 0.2.0 + diff --git a/.spyproject/config/backups/workspace.ini.bak b/.spyproject/config/backups/workspace.ini.bak new file mode 100644 index 0000000..8760223 --- /dev/null +++ b/.spyproject/config/backups/workspace.ini.bak @@ -0,0 +1,12 @@ +[workspace] +restore_data_on_startup = True +save_data_on_exit = True +save_history = True +save_non_project_files = False +project_type = empty-project-type +recent_files = ['SourceCode/AlgorithmAnalyser.py'] + +[main] +version = 0.2.0 +recent_files = [] + diff --git a/.spyproject/config/codestyle.ini b/.spyproject/config/codestyle.ini new file mode 100644 index 0000000..0f54b4c --- /dev/null +++ b/.spyproject/config/codestyle.ini @@ -0,0 +1,8 @@ +[codestyle] +indentation = True +edge_line = True +edge_line_columns = 79 + +[main] +version = 0.2.0 + diff --git a/.spyproject/config/defaults/defaults-codestyle-0.2.0.ini b/.spyproject/config/defaults/defaults-codestyle-0.2.0.ini new file mode 100644 index 0000000..0b95e5c --- /dev/null +++ b/.spyproject/config/defaults/defaults-codestyle-0.2.0.ini @@ -0,0 +1,5 @@ +[codestyle] +indentation = True +edge_line = True +edge_line_columns = 79 + diff --git a/.spyproject/config/defaults/defaults-encoding-0.2.0.ini b/.spyproject/config/defaults/defaults-encoding-0.2.0.ini new file mode 100644 index 0000000..0ce193c --- /dev/null +++ b/.spyproject/config/defaults/defaults-encoding-0.2.0.ini @@ -0,0 +1,3 @@ +[encoding] +text_encoding = utf-8 + diff --git a/.spyproject/config/defaults/defaults-vcs-0.2.0.ini b/.spyproject/config/defaults/defaults-vcs-0.2.0.ini new file mode 100644 index 0000000..ee25483 --- /dev/null +++ b/.spyproject/config/defaults/defaults-vcs-0.2.0.ini @@ -0,0 +1,4 @@ +[vcs] +use_version_control = False +version_control_system = + diff --git a/.spyproject/config/defaults/defaults-workspace-0.2.0.ini b/.spyproject/config/defaults/defaults-workspace-0.2.0.ini new file mode 100644 index 0000000..2a73ab7 --- /dev/null +++ b/.spyproject/config/defaults/defaults-workspace-0.2.0.ini @@ -0,0 +1,6 @@ +[workspace] +restore_data_on_startup = True +save_data_on_exit = True +save_history = True +save_non_project_files = False + diff --git a/.spyproject/config/encoding.ini b/.spyproject/config/encoding.ini new file mode 100644 index 0000000..a17aced --- /dev/null +++ b/.spyproject/config/encoding.ini @@ -0,0 +1,6 @@ +[encoding] +text_encoding = utf-8 + +[main] +version = 0.2.0 + diff --git a/.spyproject/config/vcs.ini b/.spyproject/config/vcs.ini new file mode 100644 index 0000000..fd66eae --- /dev/null +++ b/.spyproject/config/vcs.ini @@ -0,0 +1,7 @@ +[vcs] +use_version_control = False +version_control_system = + +[main] +version = 0.2.0 + diff --git a/.spyproject/config/workspace.ini b/.spyproject/config/workspace.ini new file mode 100644 index 0000000..8760223 --- /dev/null +++ b/.spyproject/config/workspace.ini @@ -0,0 +1,12 @@ +[workspace] +restore_data_on_startup = True +save_data_on_exit = True +save_history = True +save_non_project_files = False +project_type = empty-project-type +recent_files = ['SourceCode/AlgorithmAnalyser.py'] + +[main] +version = 0.2.0 +recent_files = [] + diff --git a/.vscode/settings.json b/.vscode/settings.json index 7dc6613..e9d5e48 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { - "python.pythonPath": "/usr/bin/python3.8", + "python.pythonPath": "/usr/sbin/python", "python.testing.pytestArgs": [ "Sample codes" ], diff --git a/SourceCode/AlgorithmAnalyser.py b/SourceCode/AlgorithmAnalyser.py index 0210984..f6b1844 100644 --- a/SourceCode/AlgorithmAnalyser.py +++ b/SourceCode/AlgorithmAnalyser.py @@ -1,5 +1,6 @@ # directly running the DOE because existing surrogates can be explored with another workflow from os import path +from os import sys import importlib.util import multiprocessing import time @@ -15,6 +16,11 @@ import itertools import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D +# Test function representation +from rpy2 import robjects as robjs +from rpy2.robjects.packages import importr +from rpy2 import rinterface + # Test function characteristics import statistics as st from scipy import signal, misc, ndimage @@ -140,93 +146,30 @@ def representfunc(funcpath): # 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 specified\n===\n******Calculating the Characteristics******") + print("Warning, the Representation of the Test Function has not been specified\n===\n******Calculating the Characteristics******") n = int(results['dimmensions']) - # pickle these steps - coords = arange(-10,10,0.5) - samplemx = array([*itertools.product(coords, repeat=n)]) - funcmap = array([* map(funcmodule.main, samplemx)]) - - # Arrays for plotting the test function - X = array([tp[0] for tp in samplemx]) - Y = array([tp[1] for tp in samplemx]) - Z = array(funcmap) - - # reshaping the array into a 3D topology - topology = reshape(Z,(coords.size,coords.size)) - ck = topology - - # Plotting the test function - fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') - ax.plot_trisurf(X, Y, Z) - # plt.show() - + execpath = sys.executable + # creating the r functions + rlist = robjs.r['list'] + rapply = robjs.r['apply'] + rtestfunc = rinterface.rternalize(funcmodule.main) - # Number of Modes filter the data for local optima: look for circle like shapes, or squares or rectangles of very low derivative (tip of modes) + ### + lower =-10 + upper = 10 + X = flacco.createInitialSample(n_obs = 500, dim = 2, 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) + + rawfeats = flacco.calculateFeatureSet(testfuncobj, set='ela_meta') + + pyfeat = asarray(rawfeats) - # Valleys and Bassins - # Alternative filter used for calculating derivatives - #derfilt = array([1.0, -2, 1.0], dtype=float32) - #alpha = signal.sepfir2d(ck, derfilt, [1]) + signal.sepfir2d(ck, [1], derfilt) - - # Currently used filter for Valley detection - hor = array([[0,1,1],[-1,0,1], [-1,-1,0]]) - vert = array([[-1,-1,0], [-1,0,1], [0,1,1]]) - - for i in range(1): betaH = signal.convolve(ck,hor,mode='valid') - for i in range(1): betaV = signal.convolve(ck,vert, mode='valid') - - beta = sqrt(betaH ** 2 + betaV ** 2) - - - #beta = beta[5:-5][5:-5] - - norm = linalg.norm(beta) - beta/= norm # normalized matrix - - - # custom filter for detection should light up the locaton of pattern - kernel = array([[1,1,1], [1,100,1], [1,1,1]]) - beta = beta < average(beta) - beta = beta * 1 - for i in range(100): - beta = ndimage.convolve(beta,kernel) - beta = beta >= 101 - beta = beta * 1 - - if any(beta): results['Valleys'] = True - - - # Separability: calculate the derivatives in one dimension and see if independant from other dimension - - - # Dimensionality: number of objectives, inputs: call function once and see what it gives | for number of inputs call until it works; try catch - - - # Pareto fronts: - - - # Noisyness: use the previously generated DOE and calculate a noisyness factor; average of derivative - - # Displaying the plots for development purposes - #img1 = plt.figure() - #ax2 = img1.add_subplot(111) - #ax2.imshow(alpha) - - img2 = plt.figure() - ax3 = img2.add_subplot(111) - ax3.imshow(beta) - - plt.show() - - # Writing the calculated representation into the test function file - # results['Represented'] = True writerepresentation(funcpath, results) @@ -285,14 +228,23 @@ if __name__ == '__main__': funcnames = ["Bukin2", "Bukin4", "Brown"] # 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} scale = 1 - data = doe (heuristicpath, heuristic_name, testfunctionpaths, funcnames, objs, args, scale) - print(data['Bukin2'][1][2]) - #representfunc("TestFunctions/Bukin6.py") + # data = doe (heuristicpath, heuristic_name, testfunctionpaths, funcnames, objs, args, scale) + # print([point[2] for point in data['Bukin2'][1]]) + representfunc("TestFunctions/Bukin2.py") # %% diff --git a/SourceCode/SampleAlgorithms/SimmulatedAnnealing.py b/SourceCode/SampleAlgorithms/SimmulatedAnnealing.py index 991ab89..90cf488 100644 --- a/SourceCode/SampleAlgorithms/SimmulatedAnnealing.py +++ b/SourceCode/SampleAlgorithms/SimmulatedAnnealing.py @@ -72,7 +72,7 @@ def main(func, obj, S, args): route.append(Best[:]) print(route) - if t < 0 or Quality(Best,y,func) > 200: + if t < 0 or Quality(Best,y,func) > 50: break #print('the Best Quality obtained was:{}'.format(Quality(Best,y))) print("Final Quality is: {}".format(Quality(Best,y,func))) diff --git a/SourceCode/SampleAlgorithms/__pycache__/SimmulatedAnnealing.cpython-39.pyc b/SourceCode/SampleAlgorithms/__pycache__/SimmulatedAnnealing.cpython-39.pyc new file mode 100644 index 0000000..4300cc8 Binary files /dev/null and b/SourceCode/SampleAlgorithms/__pycache__/SimmulatedAnnealing.cpython-39.pyc differ diff --git a/SourceCode/TestFunctions/Bukin6.py b/SourceCode/TestFunctions/Bukin6.py index e01548a..0c4d127 100644 --- a/SourceCode/TestFunctions/Bukin6.py +++ b/SourceCode/TestFunctions/Bukin6.py @@ -5,88 +5,5 @@ def main(args): ''' #_# dimmensions: 2 - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - - #_# dimmensions: 2.0 - #_# Valleys: True - - #_# dimmensions: 2.0 - #_# Valleys: True - - #_# dimmensions: 2.0 - #_# Valleys: True - - #_# dimmensions: 2.0 - #_# Valleys: True - - #_# dimmensions: 2.0 - #_# Valleys: True - - #_# dimmensions: 2.0 - #_# Valleys: True - - #_# dimmensions: 2.0 - #_# Valleys: True - - #_# dimmensions: 2.0 - #_# Valleys: True - - #_# dimmensions: 2.0 - #_# Valleys: True - - #_# dimmensions: 2.0 - #_# Valleys: True ''' return 100*sqrt(fabs(args[1]-0.01*args[0]**2))+0.01*fabs(args[0]+10) diff --git a/SourceCode/TestFunctions/__pycache__/Brown.cpython-39.pyc b/SourceCode/TestFunctions/__pycache__/Brown.cpython-39.pyc new file mode 100644 index 0000000..d0530ff Binary files /dev/null and b/SourceCode/TestFunctions/__pycache__/Brown.cpython-39.pyc differ diff --git a/SourceCode/TestFunctions/__pycache__/Bukin2.cpython-39.pyc b/SourceCode/TestFunctions/__pycache__/Bukin2.cpython-39.pyc new file mode 100644 index 0000000..c38e353 Binary files /dev/null and b/SourceCode/TestFunctions/__pycache__/Bukin2.cpython-39.pyc differ diff --git a/SourceCode/TestFunctions/__pycache__/Bukin4.cpython-39.pyc b/SourceCode/TestFunctions/__pycache__/Bukin4.cpython-39.pyc new file mode 100644 index 0000000..0bd0846 Binary files /dev/null and b/SourceCode/TestFunctions/__pycache__/Bukin4.cpython-39.pyc differ diff --git a/SourceCode/TestFunctions/__pycache__/Bukin6.cpython-39.pyc b/SourceCode/TestFunctions/__pycache__/Bukin6.cpython-39.pyc new file mode 100644 index 0000000..427df38 Binary files /dev/null and b/SourceCode/TestFunctions/__pycache__/Bukin6.cpython-39.pyc differ diff --git a/SourceCode/Testingground.py b/SourceCode/Testingground.py new file mode 100644 index 0000000..0d3fad4 --- /dev/null +++ b/SourceCode/Testingground.py @@ -0,0 +1,31 @@ +from mpl_toolkits.mplot3d import Axes3D +import matplotlib.pyplot as plt +from matplotlib import cm +from matplotlib.ticker import LinearLocator, FormatStrFormatter +import numpy as np + + +fig = plt.figure() +ax = fig.gca(projection='3d') + +# Make data. +X = np.arange(-5, 5, 0.25) +Y = np.arange(-5, 5, 0.25) +X, Y = np.meshgrid(X, Y) +R = np.sqrt(X**2 + Y**2) +Z = np.sin(R) +print(Z[1]) + +# Plot the surface. +surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm, + linewidth=0, antialiased=False) + +# Customize the z axis. +ax.set_zlim(-1.01, 1.01) +ax.zaxis.set_major_locator(LinearLocator(10)) +ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f')) + +# Add a color bar which maps values to colors. +fig.colorbar(surf, shrink=0.5, aspect=5) + +plt.show() diff --git a/SourceCode/__pycache__/AlgorithmAnalyser.cpython-39.pyc b/SourceCode/__pycache__/AlgorithmAnalyser.cpython-39.pyc new file mode 100644 index 0000000..9baf9b0 Binary files /dev/null and b/SourceCode/__pycache__/AlgorithmAnalyser.cpython-39.pyc differ diff --git a/SourceCode/calcFeatures.R b/SourceCode/calcFeatures.R new file mode 100644 index 0000000..dcacf58 --- /dev/null +++ b/SourceCode/calcFeatures.R @@ -0,0 +1,31 @@ +library(reticulate) +library(flacco) +library(parallelMap) +library(parallel) + +# Other packages to install +# plyr +# RANN +# numDeriv +# e1071 +# mda - needs to install gcc-fortran on Operating system + + +genTestFeatures <- function(path,pypath, upper=10, lower=-10, n) { + + use_python(pypath) + source_python(path) + + X = createInitialSample(n.obs = 500, dim = n, control = list(init_sample.type = 'lhs', init_sample.lower = lower, init_sample.upper = upper)) + + y = apply(X, 1, main) + + testfunc <- createFeatureObject(X = X, y = y, fun = main, lower = lower, upper = upper, blocks = 10) + + n.cores = detectCores() + parallelStart(mode = "local", logging = FALSE, show.info = FALSE) + system.time((levelset.par = calculateFeatures(testfunc , control = list('cm_angle.show_warnings'=TRUE, 'cm_grad.show_warnings'=TRUE, 'ic.show_warnings'=TRUE)))) + parallelStop() + + +}