Skip to content

Commit 73d73ea

Browse files
authored
Merge pull request #32 from JuliaAI/dev
For a 0.1.5 release
2 parents a3a8d5e + ab7af96 commit 73d73ea

File tree

12 files changed

+91
-89
lines changed

12 files changed

+91
-89
lines changed

.github/workflows/CI.yml

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,44 @@
11
name: CI
22
on:
3-
pull_request:
4-
branches:
5-
- master
6-
- dev
73
push:
84
branches:
9-
- master
105
- dev
11-
tags: '*'
6+
tags: ['*']
7+
pull_request:
8+
workflow_dispatch:
9+
concurrency:
10+
# Skip intermediate builds: always.
11+
# Cancel intermediate builds: only if it is a pull request build.
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
1214
jobs:
1315
test:
14-
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
16+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
1517
runs-on: ${{ matrix.os }}
18+
timeout-minutes: 60
19+
permissions: # needed to allow julia-actions/cache to proactively delete old caches that it has created
20+
actions: write
21+
contents: read
1622
strategy:
1723
fail-fast: false
1824
matrix:
1925
version:
20-
- '1.6'
2126
- '1'
27+
- 'lts'
2228
os:
2329
- ubuntu-latest
2430
arch:
2531
- x64
2632
steps:
27-
- uses: actions/checkout@v2
28-
- uses: julia-actions/setup-julia@v1
33+
- uses: actions/checkout@v4
34+
- uses: julia-actions/setup-julia@v2
2935
with:
3036
version: ${{ matrix.version }}
3137
arch: ${{ matrix.arch }}
32-
- uses: actions/cache@v1
33-
env:
34-
cache-name: cache-artifacts
35-
with:
36-
path: ~/.julia/artifacts
37-
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
38-
restore-keys: |
39-
${{ runner.os }}-test-${{ env.cache-name }}-
40-
${{ runner.os }}-test-
41-
${{ runner.os }}-
38+
- uses: julia-actions/cache@v2
4239
- uses: julia-actions/julia-buildpkg@v1
4340
- uses: julia-actions/julia-runtest@v1
44-
env:
45-
JULIA_NUM_THREADS: '2'
4641
- uses: julia-actions/julia-processcoverage@v1
47-
- uses: codecov/codecov-action@v1
42+
- uses: codecov/codecov-action@v5
4843
with:
49-
file: lcov.info
44+
files: lcov.info

Project.toml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MLJParticleSwarmOptimization"
22
uuid = "17a086e9-ed03-4f30-ab88-8b63f0f6126c"
33
authors = ["Long Nguyen <[email protected]> and contributors"]
4-
version = "0.1.3"
4+
version = "0.1.5"
55

66
[deps]
77
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
@@ -12,6 +12,19 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1212

1313
[compat]
1414
Distributions = "0.25"
15-
MLJBase = "0.18, 0.19, 0.20, 0.21"
16-
MLJTuning = "0.6, 0.7"
17-
julia = "1.6"
15+
LinearAlgebra = "1"
16+
MLJBase = "1"
17+
MLJTuning = "0.8"
18+
Random = "1"
19+
julia = "1"
20+
21+
[extras]
22+
ComputationalResources = "ed09eef8-17a6-5b46-8889-db040fac31e3"
23+
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
24+
EvoTrees = "f6006082-12f8-11e9-0c9c-0d5d367ab1e5"
25+
MLJ = "add582a8-e3ab-11e8-2d5e-e98b27df1bc7"
26+
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
27+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
28+
29+
[targets]
30+
test = ["ComputationalResources", "Distributed", "EvoTrees", "MLJ", "StableRNGs", "Test"]

src/MLJParticleSwarmOptimization.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ using MLJTuning
88

99
export ParticleSwarm, AdaptiveParticleSwarm
1010

11-
include("swarm.jl")
11+
include("interface.jl")
1212
include("parameters.jl")
1313
include("update.jl")
14-
include("strategies/abstract.jl")
1514
include("strategies/basic.jl")
1615
include("strategies/adaptive.jl")
1716

src/interface.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
abstract type AbstractParticleSwarm <: MLJTuning.TuningStrategy end
2+
3+
struct ParticleSwarmState{T, R, P, I}
4+
ranges::R
5+
parameters::P
6+
indices::I
7+
X::Matrix{T}
8+
V::Matrix{T}
9+
pbest_X::Matrix{T}
10+
gbest_X::Matrix{T}
11+
pbest::Vector{T}
12+
gbest::Vector{T}
13+
end
14+
15+
mutable struct ParticleSwarm <: AbstractParticleSwarm
16+
n_particles::Integer
17+
w::Float64
18+
c1::Float64
19+
c2::Float64
20+
prob_shift::Float64
21+
rng::AbstractRNG
22+
# TODO: topology
23+
end
24+
25+
mutable struct AdaptiveParticleSwarm <: AbstractParticleSwarm
26+
n_particles::Integer
27+
c1::Float64
28+
c2::Float64
29+
prob_shift::Float64
30+
rng::AbstractRNG
31+
end
32+
33+
get_n_particles(tuning::AbstractParticleSwarm) = tuning.n_particles
34+
get_prob_shift(tuning::AbstractParticleSwarm) = tuning.prob_shift
35+
get_rng(tuning::AbstractParticleSwarm) = tuning.rng
36+
37+
function initialize(r, tuning::AbstractParticleSwarm)
38+
return initialize(get_rng(tuning), r, get_n_particles(tuning))
39+
end
40+
41+
function retrieve!(state::ParticleSwarmState, tuning::AbstractParticleSwarm)
42+
return retrieve!(get_rng(tuning), state)
43+
end
44+
45+
function pbest!(state::ParticleSwarmState, measurements, tuning::AbstractParticleSwarm)
46+
return pbest!(state, measurements, get_prob_shift(tuning))
47+
end

src/strategies/abstract.jl

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/strategies/adaptive.jl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ copy of `model`. If the corresponding range has a specified `scale` function,
4040
then the transformation is applied before the hyperparameter is returned. If
4141
`scale` is a symbol (eg, `:log`), it is ignored.
4242
"""
43-
mutable struct AdaptiveParticleSwarm{R<:AbstractRNG} <: AbstractParticleSwarm
44-
n_particles::Int
45-
c1::Float64
46-
c2::Float64
47-
prob_shift::Float64
48-
rng::R
49-
end
50-
51-
# Constructor
5243

5344
function AdaptiveParticleSwarm(;
5445
n_particles=3,
@@ -57,7 +48,7 @@ function AdaptiveParticleSwarm(;
5748
prob_shift=0.25,
5849
rng::R=Random.GLOBAL_RNG
5950
) where {R}
60-
swarm = AdaptiveParticleSwarm{R}(n_particles, c1, c2, prob_shift, rng)
51+
swarm = AdaptiveParticleSwarm(n_particles, c1, c2, prob_shift, rng)
6152
message = MLJTuning.clean!(swarm)
6253
isempty(message) || @warn message
6354
return swarm

src/strategies/basic.jl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,6 @@ where pₛ is the probability of the sampled hyperparameter value. For more
103103
information, refer to "A New Discrete Particle Swarm Optimization Algorithm" by
104104
Strasser, Goodman, Sheppard, and Butcher.
105105
"""
106-
mutable struct ParticleSwarm{R<:AbstractRNG} <: AbstractParticleSwarm
107-
n_particles::Int
108-
w::Float64
109-
c1::Float64
110-
c2::Float64
111-
prob_shift::Float64
112-
rng::R
113-
# TODO: topology
114-
end
115106

116107
function ParticleSwarm(;
117108
n_particles=3,
@@ -121,7 +112,7 @@ function ParticleSwarm(;
121112
prob_shift=0.25,
122113
rng::R=Random.GLOBAL_RNG
123114
) where {R}
124-
swarm = ParticleSwarm{R}(n_particles, w, c1, c2, prob_shift, rng)
115+
swarm = ParticleSwarm(n_particles, w, c1, c2, prob_shift, rng)
125116
message = MLJTuning.clean!(swarm)
126117
isempty(message) || @warn message
127118
return swarm

src/swarm.jl

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/Project.toml

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ addprocs(2)
88
using ComputationalResources
99
using Distributions
1010
using EvoTrees
11-
using MLJBase
11+
using MLJ
1212
using MLJTuning
1313
using StableRNGs
1414
end

0 commit comments

Comments
 (0)