From 36203b80ad6cf05b4908025d74941486ea1df936 Mon Sep 17 00:00:00 2001 From: guoyongzhi Date: Thu, 31 Dec 2020 20:28:08 +0800 Subject: [PATCH] fix compare bugs --- Project.toml | 2 +- examples/compare.jl | 16 +++++++++------- src/interface.jl | 5 ++++- src/train.jl | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Project.toml b/Project.toml index ac5c9d8..36f5ce8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "WordCloud" uuid = "6385f0a0-cb03-45b6-9089-4e0acc74b26b" authors = ["guoyongzhi "] -version = "0.2.4" +version = "0.2.5" [deps] ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" diff --git a/examples/compare.jl b/examples/compare.jl index 13a7ad4..eef6afb 100644 --- a/examples/compare.jl +++ b/examples/compare.jl @@ -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") @@ -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) diff --git a/src/interface.jl b/src/interface.jl index a7e0724..a85f0a4 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -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 @@ -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 diff --git a/src/train.jl b/src/train.jl index 4b376eb..78b6ec9 100644 --- a/src/train.jl +++ b/src/train.jl @@ -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