Skip to content

Commit

Permalink
fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-yong-zhi committed Dec 10, 2022
1 parent 5ba7d73 commit c2f4141
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Stuffing"
uuid = "4175e07e-e5b7-423e-8796-3ea7f6d48281"
authors = ["guoyongzhi <[email protected]>"]
version = "0.8.4"
version = "0.8.5"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ import Pkg; Pkg.add("Stuffing")
![pyramid2](./res/pyramid2.png)
* Second, a **top-down method** ([`collision`](./src/qtree_functions.jl)) is used to detect collision between two pyramids (trees). On the level 𝑙 and coordinates (𝑎,𝑏), if one tree's node is `FULL` and the other's is NOT `EMPTY`, then these two trees collide at (𝑙,𝑎,𝑏). However, to detect collisions between many objects, pairwise detection would be time-consuming. So, we first locate the objects in hierarchical sub-regions (implemented as a [`HashSpacialQTree` or `LinkedSpacialQTree`](./src/qtree.jl)), and then detect the collision between objects within each sub-region and between the objects in the sub-regions and those in their ancestral regions (see [`totalcollisions_spacial`, `partialcollisions` and `locate!`](./src/qtree_functions.jl)).
![collision](./res/collision.png)
* At last, each object in collision pair is moved according to the **local gradient** (calculated by [`gard2d`](./src/fit.jl)) near the collision point (𝑙,𝑎,𝑏), that is, moving the object away from `EMPTY` region. This will enlarge space between them. After moving the objects, the `AbstractStackedQTree`s should be rebuilt for the next round of collision detection.
* At last, each object in collision pair is moved according to the **local gradient** (calculated by [`grad2d`](./src/fit.jl)) near the collision point (𝑙,𝑎,𝑏), that is, moving the object away from `EMPTY` region. This will enlarge space between them. After moving the objects, the `AbstractStackedQTree`s should be rebuilt for the next round of collision detection.
![gradient](./res/gradient.png)
8 changes: 4 additions & 4 deletions src/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function step!(t1, t2, collisionpoint::Tuple{Integer,Integer,Integer}, optimiser
ks2 = (ks2[1] + ks2[2]) ^ 3
l = collisionpoint[1]
ll = 2^(l - 1)
delta1 = ll .* gard2d(t1, collisionpoint...)
delta2 = ll .* gard2d(t2, collisionpoint...)
delta1 = ll .* grad2d(t1, collisionpoint...)
delta2 = ll .* grad2d(t2, collisionpoint...)
move1 = rand() < ks2 / ks1 # ks1越大移动概率越小,ks1<=ks2时必然移动(质量越大,惯性越大运动越少)
move2 = rand() < ks1 / ks2
if move1
Expand All @@ -49,8 +49,8 @@ end
function step_mask!(mask, t2, collisionpoint::Tuple{Integer,Integer,Integer}, optimiser=(t, Δ) -> Δ ./ 6)
l = collisionpoint[1]
ll = 2^(l - 1)
delta1 = ll .* gard2d(mask, collisionpoint...)
delta2 = ll .* gard2d(t2, collisionpoint...)
delta1 = ll .* grad2d(mask, collisionpoint...)
delta2 = ll .* grad2d(t2, collisionpoint...)
delta2 = (delta2 .- delta1) ./ 2
move!(t2, optimiser(t2, delta2))
end
Expand Down
6 changes: 3 additions & 3 deletions src/fit_helper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ eta!(o::SGD, e) = o.eta = e
# near(a::Integer, b::Integer, r=1) = a-r:a+r, b-r:b+r
# near(m::AbstractMatrix, a::Integer, b::Integer, r=1) = @view m[near(a, b, r)...]
# const KERNEL = collect.(Iterators.product(-1:1,-1:1))
# gard2d(m::AbstractMatrix) = sum(KERNEL .* m)
# gard2d(t::ShiftedQTree, l, a, b) = gard2d(decode2(near(t[l],a,b)))|>Tuple
# grad2d(m::AbstractMatrix) = sum(KERNEL .* m)
# grad2d(t::ShiftedQTree, l, a, b) = grad2d(decode2(near(t[l],a,b)))|>Tuple

function gard2d(t::ShiftedQTree, l, a, b) # FULL is white, Positive directions are right & down
function grad2d(t::ShiftedQTree, l, a, b) # FULL is white, Positive directions are right & down
m = t[l]
diag = -decode2(m[a - 1, b - 1]) + decode2(m[a + 1, b + 1])
cdiag = -decode2(m[a - 1, b + 1]) + decode2(m[a + 1, b - 1])
Expand Down

0 comments on commit c2f4141

Please sign in to comment.