This commit is contained in:
Remi Ehounou
2021-06-09 15:53:58 -04:00
parent a6d862cd4e
commit 50191dd984
20 changed files with 139 additions and 17 deletions

4
.vscode/launch.json vendored
View File

@ -4,11 +4,13 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "MDAF"
"module": "MDAF",
"args": ["plotfuncs('@Bukin2', features)"]
},
{
"name": "Python: Current File",

View File

@ -3,8 +3,6 @@
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.unittestArgs": [
"-v",
@ -13,5 +11,7 @@
"-p",
"test_*.py"
],
"python.testing.cwd": "tests"
"python.testing.cwd": "",
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": false
}

View File

@ -269,5 +269,19 @@ def doe(heuristicpath, testfunctionpaths, args):
#return the performance values
return responses
def plotfuncs(funcpaths, features):
print ('help')
for i,funpath in enumerate(funcpaths):
if funpath.find('@') == 0:
funcpaths[i] = path.dirname(__file__) + '/TestFunctions/' + funpath[1:]
funcnames = [path.splitext(path.basename(funcpath))[0] for funcpath in funcpaths]
representations = {}
for idx,funpath in enumerate(funcpaths):
representations[funcnames[idx]] = representfunc(funpath)
# %%

View File

@ -0,0 +1,15 @@
import math as m
def main(args):
'''
#_# dimmensions: 2
#_# upper: 32
#_# lower: -32
#_# minimum: [0, 0]
>>> main([0, 0])
-200.0
'''
return -200 * m.e**(-0.02 * m.sqrt(args[0]**2 + args[1]**2))

View File

@ -5,6 +5,9 @@ import math
def main(args):
'''
#_# dimmensions: 2
#_# upper: 10
#_# lower: 0
#_# minimum: [0, 1.39325]
'''
for x in args:
if(x<0 | x>10): return 0

View File

@ -4,6 +4,9 @@
def main(args):
'''
#_# dimmensions: 2
#_# upper: 1.2
#_# lower: -1.2
#_# minimum: [1, 1]
'''
for x in args:
if x < -1.2 or x > 1.2:

View File

@ -6,6 +6,9 @@ def main(args):
#_# dimmensions: 2
#_# upper: 10
#_# lower: -10
#_# minimum: [0, 0]
'''
for x in args:
if x < -10 or x > 10:

View File

@ -1,10 +1,13 @@
import math
def main(args):
'''
>>>main([-0.547, -1.547])
>>> main([-0.547, -1.547])
0
#_# dimmensions: 2
#_# upper: [4, 3]
#_# lower: [-1.5, -3]
#_# minimum: [-0.547, -1.547]
'''
for args[0] in args:

View File

@ -3,10 +3,14 @@ import math
def main(args):
'''
>>>main([0, 1, 1, 1])
0
>>> main([0, 1, 1, 1])
0.0
#_# dimmensions: 4
#_# upper: 1
#_# lower: -1
#_# minimum: [0, 1, 1, 1]
'''
for x in args:
if x < -1 or x > 1:

View File

@ -1,6 +0,0 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 4
}

View File

@ -0,0 +1,5 @@
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
for importer, modname, ispkg in pkgutil.walk_packages(path=__path__, prefix=__name__+'.'):
__import__(modname)

Binary file not shown.

21
tests/deprecated_funcs.py Normal file
View File

@ -0,0 +1,21 @@
import unittest
import os
import importlib.util as utl
from MDAF.TestFunctions import *
import doctest
# Testing the test function representation workflow
def load_tests(loader, tests, ignore):
fullpath = 'MDAF/TestFunctions'
for func in os.scandir(fullpath):
name = str(func.name)
if(name.find('.py') and name.find('.old') == -1 and func.is_file() and name.find('__init__.py')==-1):
spec = utl.spec_from_file_location(name[-3], fullpath+'/'+name)
funcmodule = utl.module_from_spec(spec)
spec.loader.exec_module(funcmodule)
tests.addTests(doctest.DocTestSuite(funcmodule))
return tests

53
tests/deprecated_unit.py Normal file
View File

@ -0,0 +1,53 @@
import unittest
import doctest
import os
def load_tests(loader, tests, ignore):
fullpath = 'MDAF/TestFunctions'
testlist = []
for func in os.scandir(fullpath):
name = str(func.name)
if(name.find('.py') and name.find('.old') == -1 and func.is_file()):
spec = importlib.util.spec_from_file_location(name, fullpath)
funcmodule = importlib.util.module_from_spec(spec)
spec.loader.exec_module(funcmodule)
tests.addTests(doctest.DocTestSuite(funcmodule))
return tests
if __name__ == '__main__':
runner = unittest.TextTestRunner()
runner.run(load_tests())
import unittest
import os
from MDAF.TestFunctions import *
import doctest
#target = __import__("MDAF.py")
# Testing the test function representation workflow
def load_tests(loader, tests, ignore):
fullpath = 'MDAF/TestFunctions'
testlist = []
for func in os.scandir(fullpath):
name = str(func.name)
if(name.find('.py') and name.find('.old') == -1 and func.is_file()):
curtest = doctest.DocTestSuite(os.path.relpath('../'+func.path[:-3]+'.main.__module__'))
testlist.append(curtest)
tests.addTests(testlist)
tests.addTests(doctest.DocTestSuite(Ackley2.main.__module__))
for t in tests: return t
# run the suite
suite = load_tests(loader, tests, ignore)
runner = unittest.TextTestRunner()
runner.run(suite)

View File

@ -4,6 +4,7 @@ import os
from MDAF.MDAF import representfunc
from MDAF.MDAF import installFalcoo
from MDAF.MDAF import doe
from MDAF.TestFunctions import *
#target = __import__("MDAF.py")
@ -32,11 +33,12 @@ class Test_representfunc(unittest.TestCase):
Test that the function can calculate the representation and write to the function docstring
"""
funcpath = '@Bukin2.py'
funcverify = 'MDAF/TestFunctions/Bukin2.py'
#funcpath_backup = 'tests/Bukin2.py.old'
results = representfunc(funcpath, forced = True)
with open(funcpath,"r") as file:
with open(funcverify,"r") as file:
content = file.read()
reprCheck = bool(content.find('#_# Represented: 1'))