Skip to content

Commit

Permalink
new schedule strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-yong-zhi committed Dec 13, 2021
1 parent cdefa5b commit 5ae7981
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ end

function train!(ts, nepoch::Number=-1, args...;
trainer=trainepoch_EM2!, patient::Number=trainer(:patient),
optimiser=Momentum=0.3, ρ=0.5), scheduler=opt->eta!(opt, eta(opt)*0.8),
optimiser=Momentum=1/4, ρ=0.5), scheduler=lr->lr*√0.5,
callback=x -> x, reposition=i -> true, resource=trainer(inputs=ts), kargs...)
reposition_flag = true
if reposition isa Function
Expand All @@ -477,6 +477,7 @@ function train!(ts, nepoch::Number=-1, args...;
indi_r = MonotoneIndicator{Int}() #for reposition
indi_g = MonotoneIndicator{Int}() #for global patient
indi_s = MonotoneIndicator{Int}() #for lr scheduler
eta_list = []
reposition_count = 0.
last_repositioned = nothing
colist = nothing
Expand Down Expand Up @@ -524,9 +525,17 @@ function train!(ts, nepoch::Number=-1, args...;
@info "The repositioning strategy failed after $ep epochs"
break
end
if indi_s.age > max(1, patient, nepoch / 200 * max(1, (length(ts) / indi_g.min)))
scheduler(optimiser)
@info "@epoch $ep(+$(indi_s.age)) η -> $(round(eta(optimiser), digits=3)) (current $nc collisions, best $(indi_s.min) collisions)"
if indi_s.age > max(1, patient, nepoch / 50)
if isempty(eta_list) || indi_s.min < eta_list[end][2] || (indi_s.min == eta_list[end][2] && rand()>0.5)
_eta = eta(optimiser)
push!(eta_list, (_eta, indi_s.min))
eta!(optimiser, scheduler(_eta))
@info "@epoch $ep(+$(indi_s.age)) η -> $(round(eta(optimiser), digits=3)) (current $nc collisions, best $(indi_s.min) collisions)"
else
last_eta, last_nc = pop!(eta_list)
eta!(optimiser, last_eta)
@info "@epoch $ep(+$(indi_s.age)) η <- $(round(eta(optimiser), digits=3)) (collisions $(indi_s.min)$(last_nc))"
end
reset!(indi_s)
end
if indi_g.age > max(2, 2patient, nepoch / 50 * max(1, (length(ts) / indi_g.min)))
Expand Down

2 comments on commit 5ae7981

@guo-yong-zhi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/50429

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.1 -m "<description of version>" 5ae7981b9a1b8772650e6dcbf6d34c725d2d1470
git push origin v0.6.1

Please # to comment.