Skip to content

Commit 2f2e826

Browse files
scaling against fixed positions
1 parent 489c4a7 commit 2f2e826

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/sfdp.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,23 @@ function Base.iterate(iter::LayoutIterator{SFDP{Dim,Ptype,T}}) where {Dim,Ptype,
5555
M = length(algo.initialpos)
5656
rng = MersenneTwister(algo.seed)
5757
startpos = Vector{Point{Dim,Ptype}}(undef, N)
58+
startposbounds = (min = zero(Point{Dim, Ptype}), max = zero((Point{Dim, Ptype})) .+ one(Ptype))
5859
# take the first
5960
for i in 1:min(N, M)
6061
startpos[i] = algo.initialpos[i]
6162
end
63+
64+
# create bounds for random initial positions
65+
if M > 0
66+
startposbounds = (
67+
min = Point{Dim, Ptype}([minimum((p[d] for p in startpos[1:min(N, M)])) for d in 1:Dim]),
68+
max = Point{Dim, Ptype}([maximum((p[d] for p in startpos[1:min(N, M)])) for d in 1:Dim])
69+
)
70+
end
71+
6272
# fill the rest with random points
6373
for i in (M + 1):N
64-
startpos[i] = 2 .* rand(rng, Point{Dim,Ptype}) .- 1
74+
startpos[i] = (startposbounds.max .- startposbounds.min) .* (2 .* rand(rng, Point{Dim,Ptype}) .- 1) .+ startposbounds.min
6575
end
6676
# iteratorstate: (#iter, energy, step, progress, old pos, stopflag)
6777
return startpos, (1, typemax(T), one(T), 0, startpos, false)

0 commit comments

Comments
 (0)