Skip to content

Commit 49ded97

Browse files
author
Giovanni Amorim
committed
time limit arg on gradient mode
1 parent 211264f commit 49ded97

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/optimizers/gradient.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ function train_with_gradient!(
3131
batch_size = get(params, :batch_size, -1)
3232
verbose = get(params, :verbose, true)
3333
compute_cost_every = get(params, :compute_cost_every, 1)
34+
time_limit = get(params, :time_limit, Inf)
3435

3536
# init parameters
37+
start_time = time()
3638
T = size(X)[1]
3739
best_C = Inf
3840
best_θ = extract_params(model.forecast)
@@ -69,6 +71,11 @@ function train_with_gradient!(
6971
best_C = C
7072
best_θ = extract_params(model.forecast)
7173
end
74+
75+
# check time limit reach
76+
if time() - start_time > time_limit
77+
break
78+
end
7279
end
7380

7481
# take gradient step

0 commit comments

Comments
 (0)