Spaces:
Sleeping
Sleeping
File size: 2,671 Bytes
1dd761f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | from L1Problems import *
import numpy as np
def writeCoordinates(x):
#=== Write coordinates (unit hypercube)
np.savetxt("variables.inp", x.T, fmt='%.16E', delimiter=' ')
def L1interface(x,InfoCase,FidelityLevel,noise):
flag = 0 # 0: function value only, >0: function and gradient value (only implemented for Rosenbrock and ALOS functions)
#Write x to variables.inp
writeCoordinates(x)
if (InfoCase[0:8] == '1DSASENA' or InfoCase[0:8] == '1dsasena'):
[x, f, df] = Sasena(FidelityLevel, flag)
if (InfoCase[0:11] == '1DFORRESTER' or InfoCase[0:11] == '1dforrester'):
[x, f, df] = Forrester(FidelityLevel, flag)
if (InfoCase[0:6] == '1DALOS' or InfoCase[0:6] == '1dalos'):
[x, f, df] = Alos1(FidelityLevel, flag)
if (InfoCase[0:6] == '2DALOS' or InfoCase[0:6] == '2dalos'):
[x, f, df] = Alos2(FidelityLevel, flag)
if (InfoCase[0:6] == '3DALOS' or InfoCase[0:6] == '3dalos'):
[x, f, df] = Alos3(FidelityLevel, flag)
if (InfoCase[0:12] == '2DROSENBROCK' or InfoCase[0:12] == '2drosenbrock'):
[x, f, df] = Rosenbrock2(FidelityLevel, flag)
if (InfoCase[0:12] == '5DROSENBROCK' or InfoCase[0:12] == '5drosenbrock'):
[x, f, df] = Rosenbrock5(FidelityLevel, flag)
if (InfoCase[0:13] == '10DROSENBROCK' or InfoCase[0:13] == '10drosenbrock'):
[x, f, df] = Rosenbrock10(FidelityLevel, flag)
if (InfoCase[0:11] == '2DRASTRIGIN' or InfoCase[0:11] == '2drastrigin'):
[x, f, df] = Rastrigin2(FidelityLevel, flag)
if (InfoCase[0:11] == '5DRASTRIGIN' or InfoCase[0:11] == '5drastrigin'):
[x, f, df] = Rastrigin5(FidelityLevel, flag)
if (InfoCase[0:12] == '10DRASTRIGIN' or InfoCase[0:12] == '10drastrigin'):
[x, f, df] = Rastrigin10(FidelityLevel, flag)
if (InfoCase[0:6] == '2DMASS' or InfoCase[0:6] == '2dmass'):
[x, f, df] = Mass(FidelityLevel, flag)
if (InfoCase[0:8] == '2DSPRING' or InfoCase[0:8] == '2dspring'):
[x, f, df] = Spring(FidelityLevel, flag)
if (InfoCase[0:12] == '4DSPRINGMASS' or InfoCase[0:12] == '4dspringmass'):
[x, f, df] = SpringMass(FidelityLevel, flag)
# === Write output ===
print()
if (flag == 0):
print(x, f)
else:
print(x, f, df)
print()
f = f + np.random.normal(0,noise)
return f
def EvaluateL1(x,InfoCase,FidelityLevel,noise):
samples = np.shape(x)[0]
y = np.empty([samples, 1])
y[:] = np.nan
for i in np.arange(samples):
y[i] = L1interface(x[i], InfoCase, FidelityLevel,noise)
return np.array(y) |