Skip to content

Commit 6c796d7

Browse files
committed
Fix assumed history sequentiality
1 parent 90286f7 commit 6c796d7

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/strategies/basic.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,18 @@ function MLJTuning.models(
162162
tuning::ParticleSwarm,
163163
model,
164164
history,
165-
state,
165+
state::ParticleSwarmState{T},
166166
n_remaining,
167167
verbosity
168-
)
168+
) where {T}
169169
n_particles = tuning.n_particles
170170
if !isnothing(history)
171171
sig = MLJTuning.signature(first(history).measure)
172-
pbest!(state, tuning, map(h -> sig * h.measurement[1],
173-
history[end-n_particles+1:end]))
172+
measurements = Vector{T}(undef, n_particles)
173+
map(history[end-n_particles+1:end]) do h
174+
measurements[h.metadata] = sig * h.measurement[1]
175+
end
176+
pbest!(state, tuning, measurements)
174177
gbest!(state, tuning)
175178
move!(state, tuning)
176179
end
@@ -181,7 +184,7 @@ function MLJTuning.models(
181184
for (field, param) in zip(fields, getindex.(state.parameters, i))
182185
recursive_setproperty!(clone, field, param)
183186
end
184-
clone
187+
(clone, i)
185188
end
186189
return new_models, state
187190
end

0 commit comments

Comments
 (0)