Skip to content

Commit

Permalink
fix compare bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyongzhi committed Dec 31, 2020
1 parent 22e419e commit 36203b8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "WordCloud"
uuid = "6385f0a0-cb03-45b6-9089-4e0acc74b26b"
authors = ["guoyongzhi <[email protected]>"]
version = "0.2.4"
version = "0.2.5"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
16 changes: 9 additions & 7 deletions examples/compare.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using WordCloud

stwords = ["us", "will"];

println("Obama's")
cs = WordCloud.randomscheme()
as = WordCloud.randomangles()
fr = 0.6
fr = 0.6 #not too high
wca = wordcloud(
process(open("res/Barack Obama's First Inaugural Address.txt"), stopwords=WordCloud.stopwords_en stwords),
colors = cs,
angles = as,
filling_rate = fr) |> generate!

println("Trump's")
tb, wb = process(open("res/Donald Trump's Inaugural Address.txt"), stopwords=WordCloud.stopwords_en stwords)
samemask = tb .∈ Ref(wca.words)
println(sum(samemask), " same words")
Expand All @@ -37,15 +37,17 @@ for i in 1:length(tb)
WordCloud.QTree.setcenter!(wcb.qtrees[i], cxy)
end
end

println("ignore defferent words")
ignore(wcb, .!samemask) do
generate!(wcb, 1000, patient=1000, retry=1)
generate!(wcb, 1000, patient=-1, retry=1) #patient=-1 means no teleport; retry=1 means no rescale
end

println("pin same words")
pin(wcb, samemask) do
placement!(wcb)
generate!(wcb, 1000, retry=1)
generate!(wcb, 1000, retry=1) #allow teleport but don‘t allow rescale
end
println("overall tuning")
generate!(wcb, 1000, patient=-1, retry=2) #allow rescale but don‘t allow teleport

ma = paint(wca)
mb = paint(wcb)
Expand Down
5 changes: 4 additions & 1 deletion src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ function randommask(color, sz=800)
end
end
function randomangles()
a = rand((0, (0,90),(0,90,45), -90:90))
a = rand((0, (0,90),(0,90,45),(0,-90),(0,-45,-90),-90:90))
println("angles: ", a)
a
end

import ImageTransformations.imresize
Expand Down Expand Up @@ -123,6 +125,7 @@ function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVec
@show "colors sum failed",colors_o
maskcolor = "black"
end
@show maskcolor
mask = randommask(maskcolor)
transparentcolor = get(params, :transparentcolor, ARGB(1, 1, 1, 0)) |> parsecolor
else
Expand Down
4 changes: 2 additions & 2 deletions src/train.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@ function train_with_teleport!(ts, maskqt, nepoch::Number, args...;
count = 0
nc_min = nc
end
if nc != 0 && length(collpool)>0 && (count >= patient || count > length(collpool)) #超出耐心或少数几个碰撞
if nc != 0 && length(collpool)>0 && patient >0 && (count >= patient || count > length(collpool)) #超出耐心或少数几个碰撞
nc_min = nc
cinds = teleport!(ts, maskqt, collpool=collpool)
println("@epoch $ep, count $count collision $nc teleport $cinds")
println("@epoch $ep, count $count collision $nc($(length(collpool))) teleport $cinds")
count = 0
end
if callbackstep>0 && ep%callbackstep==0
Expand Down

0 comments on commit 36203b8

Please sign in to comment.