Spaces:
Sleeping
Sleeping
File size: 1,345 Bytes
165ee00 |
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 77 78 79 80 81 82 83 84 85 86 87 88 89 |
import torch
import numpy as np
#
#
# KeaneBump: N-D objective (can take data of different dimention; we use 18),
# 2 constraints
#
# Reference:
# Keane A (1994) Experiences with optimizers in
# structural design. In: Proceedings of the con-
# ference on adaptive computing in engineering
# design and control, pp 14–27
#
#
def KeaneBump(X):
fx = torch.zeros(X.shape[0], 1)
gx1 = torch.zeros(X.shape[0], 1)
gx2 = torch.zeros(X.shape[0], 1)
for i in range(X.shape[0]):
x = X[i,:]
cos4 = 0
cos2 = 1
sq_denom = 0
pi_sum = 1
sigma_sum = 0
for j in range(X.shape[1]):
cos4 += torch.cos(x[j]) ** 4
cos2 *= torch.cos(x[j]) ** 2
sq_denom += (j+1) * (x[j])**2
pi_sum *= x[j]
sigma_sum += x[j]
# Objective
test_function = torch.abs( (cos4 - 2*cos2) / torch.sqrt(sq_denom) )
fx[i] = test_function
# Constraints
gx1[i] = 0.75 - pi_sum
gx2[i] = sigma_sum - 7.5* (X.shape[1])
gx = torch.cat((gx1, gx2), 1)
return gx, fx
def KeaneBump_Scaling(X):
X_scaled = X*10
return X_scaled
|