-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPenaltyFunction.py
More file actions
30 lines (22 loc) · 1.12 KB
/
PenaltyFunction.py
File metadata and controls
30 lines (22 loc) · 1.12 KB
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
import torch
import numpy as np
def PenaltyFunction(gx, fx, rho): # This should be the test function
#############################################################################
#############################################################################
## Adding penalty function
n = fx.shape[0]
N_GX = gx.shape[1]
arr_to_be_mult_rho = torch.zeros((n,N_GX))
for i in range(N_GX):
zero_gx = torch.cat((torch.zeros((n,1)), gx[:,i].reshape((n,1))), 1)
max_rslt = torch.max(zero_gx, 1)
max_rslt = max_rslt.values
arr_to_be_mult_rho[:,i] = max_rslt**2
arr_to_be_mult_rho = torch.sum(arr_to_be_mult_rho, dim=1)
arr_to_be_mult_rho = arr_to_be_mult_rho
#############################################################################
#############################################################################
#############################################################################
fx_new = fx - rho * arr_to_be_mult_rho.reshape((n,1))
#############################################################################
return fx_new