Skip to content

Commit

Permalink
remove callbackstep
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-yong-zhi committed Dec 6, 2021
1 parent b6384db commit 5b240c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Stuffing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ QTrees.overlap(qtrees::AbstractVector{<:ShiftedQTree}; karg...) = QTrees.overlap
function getpositions(mask::ShiftedQTree, qtrees::AbstractVector, inds=:; type=getshift)
msy, msx = getshift(mask)
pos = type.(qtrees[inds])
pos = eltype(pos) <: Number ? Ref(pos) : pos
eltype(pos) <: Number && (pos = Ref(pos))
Broadcast.broadcast(p -> (p[2] - msx + 1, p[1] - msy + 1), pos) # 左上角重合时返回(1,1)
end
function getpositions(qtrees::AbstractVector{<:ShiftedQTree}, inds=:; type=getshift)
Expand All @@ -79,7 +79,7 @@ function getpositions(qtrees::AbstractVector{<:ShiftedQTree}, inds=:; type=getsh
end
function setpositions!(mask::ShiftedQTree, qtrees::AbstractVector, inds, x_y; type=setshift!)
msy, msx = getshift(mask)
x_y = eltype(x_y) <: Number ? Ref(x_y) : x_y
eltype(x_y) <: Number && (x_y = Ref(x_y))
Broadcast.broadcast(qtrees[inds], x_y) do qt, p
type(qt, (p[2] - 1 + msy, p[1] - 1 + msx))
end
Expand Down
10 changes: 4 additions & 6 deletions src/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ end

function train!(ts, nepoch::Number=-1, args...;
trainer=trainepoch_EM2!, patient::Number=trainer(:patient), optimiser=Momentum=1 / 4, ρ=0.5),
callbackstep=1, callbackfun=x -> x, reposition=i -> true, resource=trainer(inputs=ts), kargs...)
callback=x -> x, reposition=i -> true, resource=trainer(inputs=ts), kargs...)
reposition_flag = true
if reposition isa Function
from = reposition
Expand All @@ -469,7 +469,7 @@ function train!(ts, nepoch::Number=-1, args...;
@assert reposition >= 0
from = i -> i >= reposition
else
reposition = reposition isa AbstractSet ? reposition : Set(reposition)
reposition isa AbstractSet || (reposition = Set(reposition))
from = i -> i in reposition
end
ep = 0
Expand All @@ -486,7 +486,7 @@ function train!(ts, nepoch::Number=-1, args...;
else
colist = resource[:levelpools][end] |> last
end
nepoch = nepoch >= 0 ? nepoch : trainer(:nepoch)
nepoch >= 0 || (nepoch = trainer(:nepoch))
@info "nepoch: $nepoch, " * (reposition_flag ? "patient: $patient" : "reposition off")
while ep < nepoch
nc = trainer(ts, args...; resource..., optimiser=optimiser, kargs...)
Expand Down Expand Up @@ -517,9 +517,7 @@ function train!(ts, nepoch::Number=-1, args...;
end
last_repositioned = repositioned_set
end
if ep % callbackstep == 0
callbackfun(ep)
end
callback(ep)
if nc == 0
outinds = reposition!(ts)
outlen = length(outinds)
Expand Down
10 changes: 4 additions & 6 deletions src/qtree_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,7 @@ function place!(ground::ShiftedQTree, sortedtrees::AbstractVector, index::Number
end
place!(ground, sortedtrees[index]; kargs...)
end
function place!(ground::ShiftedQTree, sortedtrees::AbstractVector, indexes;
callbackstep=1, callbackfun=x -> x, kargs...)
function place!(ground::ShiftedQTree, sortedtrees::AbstractVector, indexes; callback=x -> x, kargs...)
for i in 1:length(sortedtrees)
if i in indexes continue end
overlap!(ground, sortedtrees[i])
Expand All @@ -389,20 +388,19 @@ function place!(ground::ShiftedQTree, sortedtrees::AbstractVector, indexes;
ind = place!(ground, sortedtrees[i]; kargs...)
if ind === nothing return ind end
overlap!(ground, sortedtrees[i])
if i % callbackstep == 0 callbackfun(i) end
callback(i)
end
ind
end

"将sortedtrees依次叠加到ground上,同时修改sortedtrees的shift"
function place!(ground::ShiftedQTree, sortedtrees::AbstractVector;
callbackstep=1, callbackfun=x -> x, kargs...)
function place!(ground::ShiftedQTree, sortedtrees::AbstractVector; callback=x -> x, kargs...)
ind = nothing
for (i, t) in enumerate(sortedtrees)
ind = place!(ground, t; kargs...)
if ind === nothing return ind end
overlap!(ground, t)
if i % callbackstep == 0 callbackfun(i) end
callback(i)
end
ind
end

2 comments on commit 5b240c4

@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/50065

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.0 -m "<description of version>" 5b240c444999a6832fd8550a87006f182c02ec20
git push origin v0.6.0

Please sign in to comment.