mirror of
https://github.com/ejeanboris/MDAF.git
synced 2025-04-29 20:12:37 +00:00
Right before pooling the randomized inner-sampling
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -8,7 +8,10 @@
|
|||||||
*.log
|
*.log
|
||||||
*.log.*
|
*.log.*
|
||||||
*.sig
|
*.sig
|
||||||
|
*.py.old
|
||||||
|
*.cpython-38.pyc
|
||||||
|
|
||||||
pkg/
|
pkg/
|
||||||
src/
|
src/
|
||||||
snippets/
|
snippets/
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import time
|
|||||||
import re
|
import re
|
||||||
from numpy import random as r
|
from numpy import random as r
|
||||||
from numpy import *
|
from numpy import *
|
||||||
|
import statistics
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
@ -19,6 +20,16 @@ import statistics as st
|
|||||||
from scipy import signal, misc, ndimage
|
from scipy import signal, misc, ndimage
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -39,20 +50,49 @@ def measure(heuristicpath, heuristic_name, funcpath, funcname, objs, args, scale
|
|||||||
func = importlib.util.module_from_spec(testspec)
|
func = importlib.util.module_from_spec(testspec)
|
||||||
testspec.loader.exec_module(func)
|
testspec.loader.exec_module(func)
|
||||||
|
|
||||||
|
responses = array([0,0])
|
||||||
|
convergence = empty(0)
|
||||||
|
best = empty(0)
|
||||||
|
|
||||||
|
with pool(processes = 10) as pool:
|
||||||
|
|
||||||
|
for run in range(30):
|
||||||
|
# defining a countable test function
|
||||||
|
@counter
|
||||||
|
def testfunc(args):
|
||||||
|
return func.main(args)
|
||||||
# Defining a random initial point to start testing the algorithms
|
# Defining a random initial point to start testing the algorithms
|
||||||
initpoint = [r.random() * scale, r.random() * scale]
|
initpoint = [r.random() * scale, r.random() * scale]
|
||||||
|
|
||||||
|
try:
|
||||||
#This timer calculates directly the CPU time of the process (Nanoseconds)
|
#This timer calculates directly the CPU time of the process (Nanoseconds)
|
||||||
tic = time.process_time_ns()
|
tic = time.process_time_ns()
|
||||||
# running the test by calling the heuritic script with the test function as argument
|
# running the test by calling the heuritic script with the test function as argument
|
||||||
best = heuristic.main(func, objs, initpoint, args)
|
best = append(best, heuristic.main(testfunc, objs, initpoint, args))
|
||||||
toc = time.process_time_ns()
|
toc = time.process_time_ns()
|
||||||
# ^^ The timer ends right above this; the CPU time is then calculated below by simple difference ^^
|
# ^^ 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:
|
||||||
|
best = NaN
|
||||||
|
cpuTime = NaN
|
||||||
|
numCalls = testfunc.count
|
||||||
|
converged = 0
|
||||||
|
|
||||||
# Building the response
|
# Building the response
|
||||||
response = "The optimum point obtained is: " + str(best) + "\nThe CPU time of the process was: " + str((toc - tic)*(10**-9)) + " Seconds"
|
responses = vstack([responses, array([cpuTime,numCalls])])
|
||||||
|
convergence = append(convergence,[converged])
|
||||||
|
|
||||||
connection.send(response)
|
responses = delete(responses,[0],axis=0)
|
||||||
|
results = dict()
|
||||||
|
results['stdevs'] = array([statistics.stdev(responses[:,[0]].flatten()), statistics.stdev(responses[:,[1]].flatten())])
|
||||||
|
results['means'] = array([statistics.mean(responses[:,[0]].flatten()), statistics.mean(responses[:,[1]].flatten())])
|
||||||
|
results['convrate'] = statistics.mean(convergence)
|
||||||
|
|
||||||
|
connection.send(results)
|
||||||
|
|
||||||
def writerepresentation(funcpath, charas):
|
def writerepresentation(funcpath, charas):
|
||||||
# Save a backup copy of the function file
|
# Save a backup copy of the function file
|
||||||
@ -229,7 +269,7 @@ def doe(heuristicpath, heuristic_name, testfunctionpaths, funcnames, objs, args,
|
|||||||
connections[run][1].close()
|
connections[run][1].close()
|
||||||
|
|
||||||
# display output
|
# display output
|
||||||
print("\n\n||||| Responses |||||")
|
print("\n\n||||| Responses: [cpuTime,numCalls] |||||")
|
||||||
for process in proc: print(process.name + "____\n" + str(responses[process.name]) + "\n_________________")
|
for process in proc: print(process.name + "____\n" + str(responses[process.name]) + "\n_________________")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -244,9 +284,9 @@ if __name__ == '__main__':
|
|||||||
args = {"high": 200, "low": -200, "t": 1000, "p": 0.95}
|
args = {"high": 200, "low": -200, "t": 1000, "p": 0.95}
|
||||||
scale = 1
|
scale = 1
|
||||||
|
|
||||||
#doe (heuristicpath, heuristic_name, testfunctionpaths, funcnames, objs, args, scale)
|
doe (heuristicpath, heuristic_name, testfunctionpaths, funcnames, objs, args, scale)
|
||||||
|
|
||||||
representfunc("TestFunctions/Bukin6.py")
|
#representfunc("TestFunctions/Bukin6.py")
|
||||||
|
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
|
@ -23,7 +23,7 @@ def tweak(St,p,sigma,high,low):
|
|||||||
return St
|
return St
|
||||||
|
|
||||||
def Quality(Sc,objective,func):
|
def Quality(Sc,objective,func):
|
||||||
func_output = func.main(Sc)
|
func_output = func(Sc)
|
||||||
if type(func_output) == list:
|
if type(func_output) == list:
|
||||||
error = [func_output[i]-objective[i] for i in range(len(func_output))]
|
error = [func_output[i]-objective[i] for i in range(len(func_output))]
|
||||||
else:
|
else:
|
||||||
|
Binary file not shown.
@ -83,6 +83,9 @@ def main(args):
|
|||||||
#_# dimmensions: 2.0
|
#_# dimmensions: 2.0
|
||||||
#_# Valleys: True
|
#_# Valleys: True
|
||||||
|
|
||||||
|
#_# dimmensions: 2.0
|
||||||
|
#_# Valleys: True
|
||||||
|
|
||||||
#_# dimmensions: 2.0
|
#_# dimmensions: 2.0
|
||||||
#_# Valleys: True
|
#_# Valleys: True
|
||||||
'''
|
'''
|
||||||
|
@ -80,6 +80,9 @@ def main(args):
|
|||||||
#_# dimmensions: 2.0
|
#_# dimmensions: 2.0
|
||||||
#_# Valleys: True
|
#_# Valleys: True
|
||||||
|
|
||||||
|
#_# dimmensions: 2.0
|
||||||
|
#_# Valleys: True
|
||||||
|
|
||||||
#_# dimmensions: 2.0
|
#_# dimmensions: 2.0
|
||||||
#_# Valleys: True
|
#_# Valleys: True
|
||||||
'''
|
'''
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user