-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenfc.py
More file actions
61 lines (61 loc) · 1.66 KB
/
enfc.py
File metadata and controls
61 lines (61 loc) · 1.66 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
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
#
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
#
#
class Enfc:
#
def __init__(self):
self.pf = []
self.sgma = 0e-2
self.gama = 0e-4
self.kapa = 0e-4
self.beta = 1.-self.gama
#
def con_pas(self,g_1,g_k,q_k,c_x):
gama=self.gama
f_k = g_k[0]; f_1 = g_1[0]
# if feasible descent
if f_k < f_1 and not np.amax(g_k[1:]) > 0.: return True
# if conservative
else:
if np.any(np.where(q_k + 1e-6 < g_k,1,0)):
return False
return True
#
def gcm_pas(self,g_k,q_k):
# if conservative
if np.any(np.where(q_k + 1e-6 < g_k, 1, 0)):
return False
return True
#
def par_pas(self,f_1,f_k,v_k,p_k):
sgma=self.sgma
gama=self.gama
kapa=self.kapa
beta=self.beta
pf=self.pf
# check if acceptable to filter
if not f_k+gama*v_k>min([p[0] for p in pf]) or not v_k>beta*min([p[1] for p in pf]):
df = f_1 - f_k # actual descent
dq = f_1 - p_k # predicted descent
if df < sgma*dq and dq > kapa*v_k**2.:
return False
else:
# if h-type step
if dq <= kapa*v_k**2.:
tmp=[]
for p in pf:
if f_k > p[0] or v_k > p[1]: tmp.append((p[0],p[1]))
tmp.append((f_k,v_k))
self.pf=tmp
return True
else: return False
#
def par_add(self,f_k,v_k,k):
pf=self.pf
pf.append((f_k,v_k,k))
self.pf=pf
#