File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ function train_with_gradient!(
34
34
verbose = get (params, :verbose , true )
35
35
compute_cost_every = get (params, :compute_cost_every , 1 )
36
36
time_limit = get (params, :time_limit , Inf )
37
+ g_tol = get (params, :g_tol , 0 )
37
38
38
39
# init parameters
39
40
start_time = time ()
@@ -87,6 +88,17 @@ function train_with_gradient!(
87
88
88
89
# check time limit reach
89
90
if time () - start_time > time_limit
91
+ if verbose
92
+ println (" Time limit reached." )
93
+ end
94
+ break
95
+ end
96
+
97
+ # check gradient tolerance
98
+ if maximum (abs .(dC)) < g_tol
99
+ if verbose
100
+ println (" Gradient tolerance reached." )
101
+ end
90
102
break
91
103
end
92
104
Original file line number Diff line number Diff line change @@ -17,14 +17,15 @@ function train_with_gradient_mpi!(
17
17
compute_cost_every = get (params, :compute_cost_every , 1 )
18
18
mpi_finalize = get (params, :mpi_finalize , true )
19
19
time_limit = get (params, :time_limit , Inf )
20
+ g_tol = get (params, :g_tol , 0 )
20
21
21
22
JQM. mpi_init ()
22
23
23
24
# init parameters
24
25
start_time = time ()
25
26
is_done = false
26
27
best_C = Inf
27
- best_θ = []
28
+ best_θ = extract_params (model . forecast)
28
29
curr_C = 0.0
29
30
trace = Array {Float64} (undef, epochs)
30
31
dCdz = Vector {Float32} (undef, size (model. policy_vars, 1 ))
@@ -121,6 +122,17 @@ function train_with_gradient_mpi!(
121
122
122
123
# check time limit reach
123
124
if time () - start_time > time_limit
125
+ if verbose
126
+ println (" Time limit reached." )
127
+ end
128
+ break
129
+ end
130
+
131
+ # check gradient tolerance
132
+ if maximum (abs .(dCdy)) < g_tol
133
+ if verbose
134
+ println (" Gradient tolerance reached." )
135
+ end
124
136
break
125
137
end
126
138
You can’t perform that action at this time.
0 commit comments