mirror of
https://github.com/ejeanboris/MDAF.git
synced 2025-06-17 18:48:29 +00:00
Reorganised the code into a PyPI package format
This commit is contained in:
121
PackageCode/LICENSE
Normal file
121
PackageCode/LICENSE
Normal file
@ -0,0 +1,121 @@
|
||||
Creative Commons Legal Code
|
||||
|
||||
CC0 1.0 Universal
|
||||
|
||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||
HEREUNDER.
|
||||
|
||||
Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for
|
||||
the purpose of contributing to a commons of creative, cultural and
|
||||
scientific works ("Commons") that the public can reliably and without fear
|
||||
of later claims of infringement build upon, modify, incorporate in other
|
||||
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||
and for any purposes, including without limitation commercial purposes.
|
||||
These owners may contribute to the Commons to promote the ideal of a free
|
||||
culture and the further production of creative, cultural and scientific
|
||||
works, or to gain reputation or greater distribution for their Work in
|
||||
part through the use and efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any
|
||||
expectation of additional consideration or compensation, the person
|
||||
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not
|
||||
limited to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display,
|
||||
communicate, and translate a Work;
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
iii. publicity and privacy rights pertaining to a person's image or
|
||||
likeness depicted in a Work;
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||
in a Work;
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation
|
||||
thereof, including any amended or successor version of such
|
||||
directive); and
|
||||
vii. other similar, equivalent or corresponding rights throughout the
|
||||
world based on applicable law or treaty, and any national
|
||||
implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||
of action, whether now known or unknown (including existing as well as
|
||||
future claims and causes of action), in the Work (i) in all territories
|
||||
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||
treaty (including future time extensions), (iii) in any current or future
|
||||
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||
including without limitation commercial, advertising or promotional
|
||||
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||
member of the public at large and to the detriment of Affirmer's heirs and
|
||||
successors, fully intending that such Waiver shall not be subject to
|
||||
revocation, rescission, cancellation, termination, or any other legal or
|
||||
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||
as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||
be judged legally invalid or ineffective under applicable law, then the
|
||||
Waiver shall be preserved to the maximum extent permitted taking into
|
||||
account Affirmer's express Statement of Purpose. In addition, to the
|
||||
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||
maximum duration provided by applicable law or treaty (including future
|
||||
time extensions), (iii) in any current or future medium and for any number
|
||||
of copies, and (iv) for any purpose whatsoever, including without
|
||||
limitation commercial, advertising or promotional purposes (the
|
||||
"License"). The License shall be deemed effective as of the date CC0 was
|
||||
applied by Affirmer to the Work. Should any part of the License for any
|
||||
reason be judged legally invalid or ineffective under applicable law, such
|
||||
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||
of the License, and in such case Affirmer hereby affirms that he or she
|
||||
will not (i) exercise any of his or her remaining Copyright and Related
|
||||
Rights in the Work or (ii) assert any associated claims and causes of
|
||||
action with respect to the Work, in either case contrary to Affirmer's
|
||||
express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
b. Affirmer offers the Work as-is and makes no representations or
|
||||
warranties of any kind concerning the Work, express, implied,
|
||||
statutory or otherwise, including without limitation warranties of
|
||||
title, merchantability, fitness for a particular purpose, non
|
||||
infringement, or the absence of latent or other defects, accuracy, or
|
||||
the present or absence of errors, whether or not discoverable, all to
|
||||
the greatest extent permissible under applicable law.
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without
|
||||
limitation any person's Copyright and Related Rights in the Work.
|
||||
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||
consents, permissions or other rights required for any use of the
|
||||
Work.
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to
|
||||
this CC0 or use of the Work.
|
272
PackageCode/MDAF/MDAF.py
Normal file
272
PackageCode/MDAF/MDAF.py
Normal file
@ -0,0 +1,272 @@
|
||||
# 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
|
||||
import re
|
||||
from numpy import random as r
|
||||
from numpy import *
|
||||
import statistics
|
||||
from functools import partial
|
||||
import shutil
|
||||
|
||||
# Surrogate modelling
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
def __init__(self, func):
|
||||
self.func = func
|
||||
self.count = 0
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
self.count += 1
|
||||
return self.func(*args, **kwargs)
|
||||
|
||||
def simulate(algName, algPath, funcname, funcpath, args, initpoint):
|
||||
# loading the heuristic object into the namespace and memory
|
||||
spec = importlib.util.spec_from_file_location(algName, algPath)
|
||||
heuristic = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(heuristic)
|
||||
|
||||
# loading the test function object into the namespace and memory
|
||||
testspec = importlib.util.spec_from_file_location(funcname, funcpath)
|
||||
func = importlib.util.module_from_spec(testspec)
|
||||
testspec.loader.exec_module(func)
|
||||
|
||||
# defining a countable test function
|
||||
@counter
|
||||
def testfunc(args):
|
||||
return func.main(args)
|
||||
|
||||
# using a try statement to handle potential exceptions raised by child processes like the algorithm or test functions or the pooling algorithm
|
||||
try:
|
||||
#This timer calculates directly the CPU time of the process (Nanoseconds)
|
||||
tic = time.process_time_ns()
|
||||
# running the test by calling the heuritic script with the test function as argument
|
||||
quality = heuristic.main(testfunc, initpoint, args)
|
||||
toc = time.process_time_ns()
|
||||
# ^^ The timer ends right above this; the CPU time is then calculated below by simple difference ^^
|
||||
|
||||
# CPU time in seconds
|
||||
cpuTime = (toc - tic)*(10**-9)
|
||||
numCalls = testfunc.count
|
||||
converged = 1
|
||||
except:
|
||||
quality = NaN
|
||||
cpuTime = NaN
|
||||
numCalls = testfunc.count
|
||||
converged = 0
|
||||
return cpuTime, quality, numCalls, converged
|
||||
|
||||
def measure(heuristicpath, funcpath, args, connection):
|
||||
'''
|
||||
This function runs a set of optimization flows for each test function. it returns the mean and standard deviation of the performance results
|
||||
'''
|
||||
|
||||
#defining the heuristic's name
|
||||
heuristic_name = path.splitext(path.basename(heuristicpath))[0]
|
||||
|
||||
#defining the test function's name
|
||||
funcname = path.splitext(path.basename(funcpath))[0]
|
||||
|
||||
# Seeding the random module for generating the initial point of the optimizer: Utilising random starting point for experimental validity
|
||||
r.seed(int(time.time()))
|
||||
|
||||
# guetting the representation of the function
|
||||
funcChars = representfunc(funcpath)
|
||||
|
||||
n = funcChars['dimmensions']
|
||||
upper = funcChars['upper']
|
||||
lower = funcChars['lower']
|
||||
|
||||
if upper is not list: upper = [upper for i in range(n)]
|
||||
if lower is not list: lower = [lower for i in range(n)]
|
||||
|
||||
|
||||
scale = list()
|
||||
for i in range(n):
|
||||
scale.append(upper[i] - lower[i])
|
||||
|
||||
|
||||
# Defining random initial points to start testing the algorithms
|
||||
initpoints = [[r.random() * scale[i] + lower[i] for i in range(n)] for run in range(30)] #update the inner as [r.random() * scale for i in range(testfuncDimmensions)]
|
||||
# building the iterable arguments
|
||||
partfunc = partial(simulate, heuristic_name, heuristicpath, funcname, funcpath, args)
|
||||
|
||||
n_proc = multiprocessing.cpu_count() # Guetting the number of cpus
|
||||
with multiprocessing.Pool(processes = n_proc) as pool:
|
||||
# running the simulations
|
||||
newRun = pool.map(partfunc,initpoints)
|
||||
|
||||
cpuTime = array([resl[0] for resl in newRun])
|
||||
quality = array([resl[1] for resl in newRun])
|
||||
numCalls = array([resl[2] for resl in newRun])
|
||||
converged = array([resl[3] for resl in newRun])
|
||||
|
||||
cpuTime = cpuTime[~(isnan(cpuTime))]
|
||||
quality = quality[~(isnan(quality))]
|
||||
numCalls = numCalls[~(isnan(numCalls))]
|
||||
converged = converged[~(isnan(converged))]
|
||||
|
||||
results = dict()
|
||||
results['cpuTime'] = array([statistics.fmean(cpuTime), statistics.stdev(cpuTime)])
|
||||
results['quality'] = array([statistics.fmean(quality), statistics.stdev(quality)])
|
||||
results['numCalls'] = array([statistics.fmean(numCalls), statistics.stdev(numCalls)])
|
||||
results['convRate'] = array([statistics.fmean(converged), statistics.stdev(converged)])
|
||||
|
||||
connection.send((results,newRun))
|
||||
|
||||
def writerepresentation(funcpath, charas):
|
||||
# Save a backup copy of the function file
|
||||
shutil.copyfile(funcpath, funcpath + '.old')
|
||||
|
||||
# create a string format of the representation variables
|
||||
representation = ''
|
||||
for line in list(charas):
|
||||
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:
|
||||
content = file.read()
|
||||
docstrs = re.findall("def main\(.*?\):.*?'''(.*?)'''.*?return\s+.*?", content, re.DOTALL)[0]
|
||||
docstrs += representation
|
||||
repl = "\\1"+docstrs+"\t\\2"
|
||||
|
||||
# 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
|
||||
with open(funcpath,"w") as file:
|
||||
file.write(newContent)
|
||||
|
||||
def representfunc(funcpath, forced = False):
|
||||
#defining the function name
|
||||
funcname = path.splitext(path.basename(funcpath))[0]
|
||||
# loading the function to be represented
|
||||
spec = importlib.util.spec_from_file_location(funcname, funcpath)
|
||||
funcmodule = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(funcmodule)
|
||||
|
||||
# Finding the function characteristics inside the docstring
|
||||
if funcmodule.main.__doc__:
|
||||
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]] = 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'])
|
||||
blocks = int(1+10/n)
|
||||
if blocks< 3: blocks=3
|
||||
|
||||
# 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)
|
||||
|
||||
# Verify if a list of limits has been specified for all dimensions or if all dimensions will use the same boundaries
|
||||
if (type(results['lower']) is list):
|
||||
lowerval = r_unlist(rvector(results['lower']))
|
||||
upperval = r_unlist(rvector(results['upper']))
|
||||
else:
|
||||
lowerval = results['lower']
|
||||
upperval = results['upper']
|
||||
|
||||
X = flacco.createInitialSample(n_obs = 500, dim = n, control = rlist(**{'init_sample.type' : 'lhs', 'init_sample.lower' : lowerval, 'init_sample.upper' : upperval}))
|
||||
y = rapply(X, 1, rtestfunc)
|
||||
testfuncobj = flacco.createFeatureObject(**{'X': X, 'y': y, 'fun': rtestfunc, 'lower': lowerval, 'upper': upperval, 'blocks': blocks, 'force': forced})
|
||||
|
||||
# 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' (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
|
||||
|
||||
|
||||
|
||||
def doe(heuristicpath, testfunctionpaths, args):
|
||||
|
||||
#defining the function's name
|
||||
funcnames = [path.splitext(path.basename(funcpath))[0] for funcpath in testfunctionpaths]
|
||||
|
||||
#defining the heuristic's name
|
||||
heuristic_name = path.splitext(path.basename(heuristicpath))[0]
|
||||
|
||||
# logic variables to deal with the processes
|
||||
proc = []
|
||||
connections = {}
|
||||
|
||||
# loading the test functions into the namespace and memory
|
||||
for idx, funcpath in enumerate(testfunctionpaths):
|
||||
funcname = funcnames[idx]
|
||||
# Creating the connection objects for communication between the heuristic and this module
|
||||
connections[funcname] = multiprocessing.Pipe(duplex=False)
|
||||
proc.append(multiprocessing.Process(target=measure, name=funcname, args=(heuristicpath, funcpath, args, connections[funcname][1])))
|
||||
|
||||
# defining the response variables
|
||||
responses = {}
|
||||
failedfunctions = {}
|
||||
processtiming = {}
|
||||
|
||||
# Starting the subprocesses for each testfunction
|
||||
for idx,process in enumerate(proc):
|
||||
process.start()
|
||||
|
||||
# Waiting for all the runs to be done
|
||||
for process in proc: process.join()
|
||||
|
||||
for process in proc:
|
||||
run = process.name
|
||||
if process.exitcode == 0: responses[run] = connections[run][0].recv()
|
||||
else:
|
||||
responses[run] = "this run was not successful"
|
||||
failedfunctions[run] = process.exitcode
|
||||
connections[run][0].close()
|
||||
connections[run][1].close()
|
||||
|
||||
|
||||
# display output
|
||||
print("\n\n||||| Responses: [mean,stdDev] |||||")
|
||||
for process in proc: print(process.name + "____\n" + str(responses[process.name][0]) + "\n_________________")
|
||||
|
||||
#return the performance values
|
||||
return responses
|
||||
|
||||
|
||||
# %%
|
84
PackageCode/MDAF/SampleAlgorithms/SimmulatedAnnealing.py
Normal file
84
PackageCode/MDAF/SampleAlgorithms/SimmulatedAnnealing.py
Normal file
@ -0,0 +1,84 @@
|
||||
import math as m
|
||||
import numpy as np
|
||||
from numpy import random as r
|
||||
import time
|
||||
import matplotlib.pyplot as plt
|
||||
from mpl_toolkits import mplot3d
|
||||
import copy as cp
|
||||
|
||||
|
||||
#def func(Sc):
|
||||
# x1 = Sc[0]
|
||||
# x2 = Sc[1]
|
||||
# return m.sqrt(x1**2+x2**2)
|
||||
|
||||
def tweak(St,p,sigma,high,low):
|
||||
for i in range(len(St)):
|
||||
if p > r.random():
|
||||
while True:
|
||||
n = r.normal(loc=0, scale=sigma)
|
||||
if (high > St[i]+n) and (low < St[i]+n):
|
||||
St[i]+=n
|
||||
break
|
||||
return St
|
||||
|
||||
def Quality(Sc,objective,func):
|
||||
func_output = func(Sc)
|
||||
if type(func_output) == list:
|
||||
error = [func_output[i]-objective[i] for i in range(len(func_output))]
|
||||
else:
|
||||
error = func_output - objective
|
||||
print("Error is: "+str(error))
|
||||
return 1/abs(error)
|
||||
|
||||
def main(func, S, args):
|
||||
r.seed(int(time.time()))
|
||||
route = list()
|
||||
#Parsing arguments
|
||||
y = args["objs"]
|
||||
t = args["t"]
|
||||
p = args["p"]
|
||||
high = 20
|
||||
low = -20
|
||||
|
||||
Best = list()
|
||||
Best[:] = cp.deepcopy(S)
|
||||
sigma = 0.1
|
||||
route.append(Best[:])
|
||||
while True:
|
||||
print('\n\n\n')
|
||||
R = tweak(cp.deepcopy(S),p,sigma,high, low)
|
||||
print(R)
|
||||
print(S)
|
||||
Qr = Quality(R,y,func)
|
||||
Qs = Quality(S,y,func)
|
||||
try:
|
||||
P = m.e**((Qr-Qs)/t)
|
||||
except:
|
||||
pass
|
||||
print('QUALITY_R///{}'.format(Qr))
|
||||
print('QUALITY_S///{}'.format(Qs))
|
||||
print('fraction is:{}'.format(P))
|
||||
if (Qr > Qs) or (r.random() < P):
|
||||
print('NEW_S')
|
||||
S[:] = R[:]
|
||||
if t > 0.01:
|
||||
t-= t/10
|
||||
print('t = {}'.format(t))
|
||||
|
||||
if (Quality(S,y,func) > Quality(Best,y,func)):
|
||||
print('new Best****:{}'.format(Best))
|
||||
Best[:] = S[:]
|
||||
route.append(Best[:])
|
||||
print(route)
|
||||
|
||||
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)))
|
||||
print("final Temperature is: {}".format(t))
|
||||
return Quality(Best,y,func)
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
@ -0,0 +1,6 @@
|
||||
{
|
||||
"cells": [],
|
||||
"metadata": {},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
33
PackageCode/MDAF/TestFunctions/Brown.py
Normal file
33
PackageCode/MDAF/TestFunctions/Brown.py
Normal file
@ -0,0 +1,33 @@
|
||||
def main(args):
|
||||
'''
|
||||
|
||||
#_# dimmensions: 6
|
||||
#_# upper: 4
|
||||
#_# lower: -1
|
||||
#_# minimum: 0
|
||||
|
||||
|
||||
#_# cm_angle: array([[4.38674589e+00], [1.19556006e+00], [4.47966360e+00], [1.19983352e+00], [5.60286032e+00], [1.07792176e+01], [2.25826784e-03], [2.51639450e-02], [0.00000000e+00], [2.62000000e-01]])
|
||||
#_# cm_conv: array([[0.33635988], [0.16095749], [0.76392901], [0.23607099], [0. ], [0.57 ]])
|
||||
#_# cm_grad: array([[0.74319842], [0.11137735], [0. ], [0.095 ]])
|
||||
#_# ela_conv: array([[ 9.80000000e-01], [ 0.00000000e+00], [-2.06944119e+18], [ 2.06944119e+18], [ 1.00000000e+03], [ 1.12000000e-01]])
|
||||
#_# ela_curv: array([[4.79755856e+00], [1.34573105e+03], [5.12834662e+19], [3.70342074e+07], [3.86444487e+12], [8.88644003e+21], [5.30415946e+20], [0.00000000e+00], [3.81373465e+00], [4.90886432e+02], [5.97651830e+14], [1.97651206e+05], [9.10648718e+08], [7.52108388e+16], [5.45247010e+15], [1.94000000e-01], [4.54265125e+00], [3.29125394e+03], [9.25189949e+46], [2.18081469e+07], [9.89777937e+09], [2.74236176e+49], [1.35682556e+48], [5.00000000e-02], [1.07656000e+05], [1.04290000e+01]])
|
||||
#_# ela_distr: array([[1.33769544e+01], [1.94701124e+02], [1.80000000e+01], [0.00000000e+00], [2.90000000e-02]])
|
||||
#_# ela_local: array([[2.70000000e+02], [9.00000000e-01], [2.35864648e-04], [4.89568303e-02], [8.33333333e-02], [3.40768278e-03], [3.33333333e-03], [1.17000000e+02], [2.08000000e+02], [2.95273333e+02], [2.73000000e+02], [3.77000000e+02], [7.28000000e+02], [1.02839577e+02], [8.88520000e+04], [7.16600000e+00]])
|
||||
#_# ela_meta: array([[ 2.12758964e-02], [-6.21915065e+18], [ 1.35144338e+16], [ 2.24256868e+18], [ 1.65938782e+02], [ 6.15453221e-02], [ 5.94927163e-02], [ 6.24028558e+00], [ 2.43822411e-01], [ 0.00000000e+00], [ 1.50000000e-02]])
|
||||
#_# basic: array([[ 6.00000000e+00], [ 5.00000000e+02], [-1.00000000e+00], [-1.00000000e+00], [ 4.00000000e+00], [ 4.00000000e+00], [ 2.88961528e+00], [ 4.10691709e+20], [ 3.00000000e+00], [ 3.00000000e+00], [ 7.29000000e+02], [ 3.96000000e+02], [ 1.00000000e+00], [ 0.00000000e+00], [ 0.00000000e+00]])
|
||||
#_# disp: array([[ 0.54940333], [ 0.63595834], [ 0.77089952], [ 0.89491857], [ 0.53989005], [ 0.63417083], [ 0.7646051 ], [ 0.88560301], [-2.18734742], [-1.76718039], [-1.1121306 ], [-0.5101005 ], [-2.24631371], [-1.78602329], [-1.14922704], [-0.55850027], [ 0. ], [ 0.01 ]])
|
||||
#_# limo: array([[ nan], [ nan], [ nan], [ nan], [ nan], [ nan], [ nan], [ nan], [ nan], [ nan], [ nan], [ nan], [0. ], [0.033]])
|
||||
#_# nbc: array([[ 0.47974042], [ 0.96061989], [ 0.34786143], [ 0.0693798 ], [-0.0889751 ], [ 0. ], [ 0.04 ]])
|
||||
#_# pca: array([[1. ], [1. ], [0.14285714], [1. ], [0.18943524], [0.18942493], [1. ], [0.17000728], [0. ], [0.003 ]])
|
||||
#_# gcm: array([[1.00000000e+00], [1.37174211e-03], [5.41838134e-01], [0.00000000e+00], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [ nan], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [ nan], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [ nan], [5.43209877e-01], [5.43209877e-01], [1.37174211e-03], [0.00000000e+00], [7.93900000e+00], [1.00000000e+00], [1.37174211e-03], [5.41838134e-01], [0.00000000e+00], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [ nan], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [ nan], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [5.43209877e-01], [ nan], [5.43209877e-01], [5.43209877e-01], [1.37174211e-03], [0.00000000e+00], [7.53700000e+00], [2.00000000e+00], [2.74348422e-03], [9.97256516e-01], [1.00000000e+00], [5.00000000e-01], [5.00000000e-01], [5.00000000e-01], [5.00000000e-01], [0.00000000e+00], [0.00000000e+00], [0.00000000e+00], [0.00000000e+00], [0.00000000e+00], [0.00000000e+00], [0.00000000e+00], [4.88340192e-01], [5.00000000e-01], [5.00000000e-01], [5.11659808e-01], [1.64894585e-02], [1.00000000e+00], [1.00000000e+00], [2.74348422e-03], [0.00000000e+00], [1.21150000e+01]])
|
||||
#_# ic: array([[ 0.57808329], [ nan], [68.69928016], [10.73573574], [ 0.53413655], [ 0. ], [ 0.281 ]])
|
||||
|
||||
#_# Represented: 1
|
||||
|
||||
'''
|
||||
result = 0
|
||||
for i,x in enumerate(args[0:-1]):
|
||||
result += (x**2)**(args[i+1]**2+1) + (args[i+1]**2)**(x**2 + 1)
|
||||
|
||||
return result
|
29
PackageCode/MDAF/TestFunctions/Bukin2.py
Normal file
29
PackageCode/MDAF/TestFunctions/Bukin2.py
Normal file
@ -0,0 +1,29 @@
|
||||
def main(args):
|
||||
'''
|
||||
|
||||
#_# 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
|
28
PackageCode/MDAF/TestFunctions/Bukin4.py
Normal file
28
PackageCode/MDAF/TestFunctions/Bukin4.py
Normal file
@ -0,0 +1,28 @@
|
||||
def main(args):
|
||||
'''
|
||||
#_# dimmensions: 2
|
||||
#_# upper: [-5, 3]
|
||||
#_# lower: [-15, -3]
|
||||
#_# minimum: [-10,0]
|
||||
|
||||
|
||||
#_# cm_angle: array([[3.46336319e-01], [1.11596448e-01], [3.32688632e-01], [1.10567852e-01], [1.26709762e+02], [3.96040507e+01], [1.47616482e-01], [9.06041269e-02], [0.00000000e+00], [7.90000000e-02]])
|
||||
#_# cm_conv: array([[0.23809524], [0.19642857], [0.67857143], [0.32142857], [0. ], [0.033 ]])
|
||||
#_# cm_grad: array([[0.81854428], [0.1192788 ], [0. ], [0.052 ]])
|
||||
#_# ela_conv: array([[ 1.00000000e+00], [ 0.00000000e+00], [-1.06441804e+02], [ 1.06441804e+02], [ 1.00000000e+03], [ 1.04000000e-01]])
|
||||
#_# ela_curv: array([[3.20384285e+00], [1.59352986e+02], [3.11716056e+02], [3.16753438e+02], [4.75852875e+02], [5.98482830e+02], [1.80339798e+02], [0.00000000e+00], [3.20382725e+02], [1.59352986e+04], [3.11716055e+04], [3.16753436e+04], [4.75852869e+04], [5.98482828e+04], [1.80339798e+04], [0.00000000e+00], [5.31778742e+06], [4.94191117e+07], [1.07037935e+36], [3.96591773e+08], [6.61335123e+12], [1.60389805e+38], [1.16318553e+37], [0.00000000e+00], [8.40000000e+03], [9.98000000e-01]])
|
||||
#_# ela_distr: array([[ 0.63700187], [-0.86671884], [ 2. ], [ 0. ], [ 0.024 ]])
|
||||
#_# ela_local: array([[9.00000000e+01], [9.00000000e-01], [1.00000000e+00], [1.64410646e-01], [1.00000000e-01], [1.01123596e-02], [1.00000000e-02], [4.50000000e+01], [8.00000000e+01], [8.93000000e+01], [9.00000000e+01], [1.00000000e+02], [1.35000000e+02], [1.65758130e+01], [9.02000000e+03], [7.07000000e-01]])
|
||||
#_# ela_meta: array([[-6.03426790e-03], [ 3.06569525e+02], [ 2.05064239e-02], [ 6.61146864e-01], [ 3.22409635e+01], [-7.94339775e-03], [ 1.00000000e+00], [ 5.33390671e+04], [ 1.00000000e+00], [ 0.00000000e+00], [ 1.40000000e-02]])
|
||||
#_# basic: array([[ 2.00000000e+00], [ 5.00000000e+02], [-1.50000000e+01], [-3.00000000e+00], [-5.00000000e+00], [ 3.00000000e+00], [ 8.36446791e-03], [ 8.95463288e+02], [ 1.00000000e+01], [ 1.00000000e+01], [ 1.00000000e+02], [ 1.00000000e+02], [ 1.00000000e+00], [ 0.00000000e+00], [ 1.00000000e-03]])
|
||||
#_# disp: array([[ 0.90387646], [ 0.87562005], [ 0.80237804], [ 0.81384686], [ 0.90019544], [ 0.85330973], [ 0.74450389], [ 0.74867028], [-0.40830656], [-0.52833206], [-0.83944411], [-0.79072771], [-0.40329912], [-0.59275905], [-1.03243135], [-1.01559546], [ 0. ], [ 0.011 ]])
|
||||
#_# limo: array([[4.17880614e-01], [4.99806181e-03], [2.99599766e+02], [1.70588576e+02], [6.54778826e-02], [5.20933692e-03], [9.01491863e+02], [3.18988622e+03], [9.03063909e+01], [3.88297785e+01], [1.74942209e+02], [5.15283205e-01], [0.00000000e+00], [1.12000000e-01]])
|
||||
#_# nbc: array([[ 0.19285636], [ 0.84080448], [ 0.11842373], [ 0.17016598], [-0.30584099], [ 0. ], [ 0.034 ]])
|
||||
#_# pca: array([[1. ], [1. ], [0.33333333], [1. ], [0.73538694], [0.50398941], [0.99984257], [0.33688393], [0. ], [0.003 ]])
|
||||
#_# gcm: array([[5. ], [0.05 ], [0.95 ], [0.93 ], [0.16376097], [0.2 ], [0.18658697], [0.26119064], [0.03940216], [0.01 ], [0.014 ], [0.01 ], [0.02 ], [0.00547723], [0.07 ], [0.08 ], [0.2 ], [0.21 ], [0.32 ], [0.10024969], [1. ], [0.21551545], [0.01 ], [0. ], [0.091 ], [4. ], [0.04 ], [0.96 ], [0.9 ], [0.10082007], [0.25 ], [0.19083529], [0.51750934], [0.18364899], [0.01 ], [0.025 ], [0.015 ], [0.06 ], [0.02380476], [0.1 ], [0.05 ], [0.25 ], [0.18 ], [0.59 ], [0.23537205], [1. ], [0.17734396], [0.01 ], [0. ], [0.094 ], [4. ], [0.04 ], [0.96 ], [0.88 ], [0.15058257], [0.25 ], [0.22415964], [0.40109815], [0.10875386], [0.01 ], [0.03 ], [0.025 ], [0.06 ], [0.0244949 ], [0.12 ], [0.14 ], [0.25 ], [0.22 ], [0.42 ], [0.13241349], [1. ], [0.40109815], [0.01 ], [0. ], [0.095 ]])
|
||||
#_# ic: array([[ 0.56692136], [ 2.74774775], [116.69898186], [ 2.36736737], [ 0.27710843], [ 0. ], [ 0.228 ]])
|
||||
|
||||
#_# Represented: 1
|
||||
|
||||
'''
|
||||
return 100*args[1]**2+0.01*abs(args[0]+10)
|
12
PackageCode/MDAF/TestFunctions/Bukin6.py
Normal file
12
PackageCode/MDAF/TestFunctions/Bukin6.py
Normal file
@ -0,0 +1,12 @@
|
||||
from math import sqrt, fabs
|
||||
|
||||
|
||||
def main(args):
|
||||
'''
|
||||
#_# dimmensions: 2
|
||||
#_# upper: [-5, 3]
|
||||
#_# lower: [-15, -3]
|
||||
#_# minimum: [-10,1]
|
||||
|
||||
'''
|
||||
return 100*sqrt(fabs(args[1]-0.01*args[0]**2))+0.01*fabs(args[0]+10)
|
11
PackageCode/MDAF/TestFunctions/Keane.py
Normal file
11
PackageCode/MDAF/TestFunctions/Keane.py
Normal file
@ -0,0 +1,11 @@
|
||||
#Import math library
|
||||
import math
|
||||
|
||||
|
||||
def main(args):
|
||||
'''
|
||||
#_# dimmensions: 2
|
||||
'''
|
||||
for x in args:
|
||||
if(x<0 | x>10): return 0
|
||||
return (math.sin(args[0]-args[1])**2*math.sin(args[0]+args[1])**2)/(math.sqrt(args[0]**2+args[1]**2))
|
11
PackageCode/MDAF/TestFunctions/Leon.py
Normal file
11
PackageCode/MDAF/TestFunctions/Leon.py
Normal file
@ -0,0 +1,11 @@
|
||||
#Import math library
|
||||
|
||||
|
||||
def main(args):
|
||||
'''
|
||||
#_# dimmensions: 2
|
||||
'''
|
||||
for x in args:
|
||||
if x < -1.2 or x > 1.2:
|
||||
return 0
|
||||
return (100*(args[1]-args[0])**2)+(1-args[0])**2
|
17
PackageCode/MDAF/TestFunctions/Matyas.py
Normal file
17
PackageCode/MDAF/TestFunctions/Matyas.py
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
def main(args):
|
||||
'''
|
||||
>>> main([0,1])
|
||||
0.26
|
||||
|
||||
|
||||
#_# dimmensions: 2
|
||||
'''
|
||||
for x in args:
|
||||
if x < -10 or x > 10:
|
||||
return 0
|
||||
return (0.26*(args[0]**2+args[1]**2))-(0.48*args[0]*args[1])
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
doctest.testmod()
|
16
PackageCode/MDAF/TestFunctions/McCormick.py
Normal file
16
PackageCode/MDAF/TestFunctions/McCormick.py
Normal file
@ -0,0 +1,16 @@
|
||||
import math
|
||||
def main(args):
|
||||
'''
|
||||
>>>main([-0.547, -1.547])
|
||||
0
|
||||
|
||||
#_# dimmensions: 2
|
||||
|
||||
'''
|
||||
for args[0] in args:
|
||||
if args[0] < -1.5 or args[0] > 4:
|
||||
return 0
|
||||
if args[1] < -3 or args[1] > 3:
|
||||
return 0
|
||||
return math.sin(args[0]+args[1])+(args[0]-args[1])**2-(3*args[0]/2)+(5*args[1]/2)+1
|
||||
|
16
PackageCode/MDAF/TestFunctions/Miele_Cantrell.py
Normal file
16
PackageCode/MDAF/TestFunctions/Miele_Cantrell.py
Normal file
@ -0,0 +1,16 @@
|
||||
import math
|
||||
|
||||
|
||||
def main(args):
|
||||
'''
|
||||
>>>main([0, 1, 1, 1])
|
||||
0
|
||||
|
||||
#_# dimmensions: 4
|
||||
'''
|
||||
for x in args:
|
||||
if x < -1 or x > 1:
|
||||
return 0
|
||||
return (math.exp(-args[0])-args[1])**4+(100*(args[1]-args[2])**6)+(math.tan(args[2]-args[3]))**4+args[0]**8
|
||||
|
||||
|
6
PackageCode/MDAF/TestFunctions/Untitled.ipynb
Normal file
6
PackageCode/MDAF/TestFunctions/Untitled.ipynb
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"cells": [],
|
||||
"metadata": {},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
BIN
PackageCode/MDAF/TestFunctions/__pycache__/Brown.cpython-39.pyc
Normal file
BIN
PackageCode/MDAF/TestFunctions/__pycache__/Brown.cpython-39.pyc
Normal file
Binary file not shown.
BIN
PackageCode/MDAF/TestFunctions/__pycache__/Bukin2.cpython-39.pyc
Normal file
BIN
PackageCode/MDAF/TestFunctions/__pycache__/Bukin2.cpython-39.pyc
Normal file
Binary file not shown.
BIN
PackageCode/MDAF/TestFunctions/__pycache__/Bukin4.cpython-39.pyc
Normal file
BIN
PackageCode/MDAF/TestFunctions/__pycache__/Bukin4.cpython-39.pyc
Normal file
Binary file not shown.
BIN
PackageCode/MDAF/TestFunctions/__pycache__/Bukin6.cpython-39.pyc
Normal file
BIN
PackageCode/MDAF/TestFunctions/__pycache__/Bukin6.cpython-39.pyc
Normal file
Binary file not shown.
0
PackageCode/MDAF/__init__.py
Normal file
0
PackageCode/MDAF/__init__.py
Normal file
BIN
PackageCode/MDAF/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
PackageCode/MDAF/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
2
PackageCode/README.md
Normal file
2
PackageCode/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# MDAF
|
||||
THe desc will go here
|
3
PackageCode/pyproject.toml
Normal file
3
PackageCode/pyproject.toml
Normal file
@ -0,0 +1,3 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=42", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
26
PackageCode/setup.cfg
Normal file
26
PackageCode/setup.cfg
Normal file
@ -0,0 +1,26 @@
|
||||
[metadata]
|
||||
name = MDAF
|
||||
version = 0.1
|
||||
description =A Framework for the Analysis and Benchmarking of Metaheuristics
|
||||
url = https://git.rehounou.ca/remi/MDAF
|
||||
author = Remi Ehounou
|
||||
author_email = remi.ehounou@outlook.com
|
||||
license = MIT
|
||||
long_description = file: README.md
|
||||
long_description_content_type = text/markdown
|
||||
classifiers =
|
||||
Programming Language :: Python :: 3
|
||||
License :: OSI Approved :: MIT License
|
||||
Operating System :: OS Independent
|
||||
|
||||
|
||||
[options]
|
||||
package_dir =
|
||||
= .
|
||||
include_package_data = True
|
||||
packages = find:
|
||||
python_requires = >=3.6
|
||||
install_requires =
|
||||
numpy
|
||||
importlib
|
||||
rpy2 == 3.4.4
|
Reference in New Issue
Block a user