Skip to content

Commit a3fb775

Browse files
Merge pull request #185 from LCSB-BioCore/develop
Develop
2 parents e1823ef + c01c119 commit a3fb775

File tree

5 files changed

+57
-59
lines changed

5 files changed

+57
-59
lines changed

.github/workflows/docker.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: Publish Docker image
2+
23
on:
34
release:
4-
types: [published]
5+
types: [published, created]
6+
57
jobs:
68
push_to_registry:
79
name: Push Docker image to GitHub Packages
@@ -14,9 +16,12 @@ jobs:
1416
with:
1517
registry: docker.pkg.github.com
1618
username: cylon-x
17-
password: ${{ secrets.DOCKER_TOKEN }}
18-
- uses: docker/build-push-action@v2
19+
password: ${{ secrets.docker_token }}
20+
- name: Push to GitHub Registry
21+
uses: mr-smithers-excellent/docker-build-push@v5
1922
with:
20-
push: true
21-
tags: lcsb-biocore/gigasom:latest
22-
23+
image: gigasom.jl
24+
tags: latest
25+
registry: ghcr.io
26+
username: cylon-x
27+
password: ${{ secrets.docker_token }}

.github/workflows/docs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
branches:
77
- develop
88
tags: '*'
9-
pull_request:
109
release:
1110
types: [published, created]
1211

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "GigaSOM"
22
uuid = "a03a9c34-069e-5582-a11c-5c984cab887c"
3-
version = "0.6.4"
3+
version = "0.6.5"
44

55
[deps]
66
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
@@ -23,10 +23,10 @@ XLSX = "fdbf4ff8-1666-58a4-91e7-1b58723a45e0"
2323

2424
[compat]
2525
CSV = "^0.5.12, 0.6, 0.7, 0.8"
26-
DataFrames = "0.20, 0.21, 0.22"
26+
DataFrames = "0.20, 0.21, 0.22, 1.0"
2727
Distances = "^0.8.2, 0.9, 0.10"
2828
DistributedArrays = "^0.6.4"
29-
Distributions = "^0.21.1, 0.22, 0.23, 0.24"
29+
Distributions = "^0.21.1, 0.22, 0.23, 0.24, 0.25"
3030
FCSFiles = "^0.1.1"
3131
FileIO = "^1.0.7"
3232
JSON = "0.21"

src/analysis/core.jl

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,19 @@ end
8282

8383

8484
"""
85-
trainGigaSOM(som::Som, dInfo::LoadedDataInfo;
86-
kernelFun::Function = gaussianKernel,
87-
metric = Euclidean(),
88-
somDistFun = distMatrix(Chebyshev()),
89-
knnTreeFun = BruteTree,
90-
rStart = 0.0, rFinal=0.1, radiusFun=expRadius(-5.0),
91-
epochs = 20)
85+
trainGigaSOM(
86+
som::Som,
87+
dInfo::LoadedDataInfo;
88+
kernelFun::Function = gaussianKernel,
89+
metric = Euclidean(),
90+
somDistFun = distMatrix(Chebyshev()),
91+
knnTreeFun = BruteTree,
92+
rStart = 0.0,
93+
rFinal = 0.1,
94+
radiusFun = expRadius(-5.0),
95+
epochs = 20,
96+
eachEpoch = (e, r, som) -> nothing,
97+
)
9298
9399
# Arguments:
94100
- `som`: object of type Som with an initialised som
@@ -102,6 +108,9 @@ end
102108
- `rFinal`: target radius at the last epoch, defaults to 0.1
103109
- `radiusFun`: Function that generates radius decay, e.g. `linearRadius` or `expRadius(10.0)`
104110
- `epochs`: number of SOM training iterations (default 10)
111+
- `eachEpoch`: a function to call back after each epoch, accepting arguments
112+
`(epochNumber, radius, som)`. For simplicity, this gets additionally called
113+
once before the first epoch, with `epochNumber` set to zero.
105114
"""
106115
function trainGigaSOM(
107116
som::Som,
@@ -114,6 +123,7 @@ function trainGigaSOM(
114123
rFinal = 0.1,
115124
radiusFun = expRadius(-5.0),
116125
epochs = 20,
126+
eachEpoch = (e, r, som) -> nothing,
117127
)
118128

119129
# set the default radius
@@ -125,75 +135,51 @@ function trainGigaSOM(
125135
# get the SOM neighborhood distances
126136
dm = somDistFun(som.grid)
127137

128-
codes = som.codes
138+
result_som = copy(som)
139+
result_som.codes = copy(som.codes) # prevent rewriting by reference
140+
141+
eachEpoch(0, rStart, result_som)
129142

130-
for j = 1:epochs
131-
@debug "Epoch $j..."
143+
for epoch = 1:epochs
144+
@debug "Epoch $epoch..."
132145

133146
numerator, denominator = distributedEpoch(
134147
dInfo,
135-
codes,
136-
knnTreeFun(Array{Float64,2}(transpose(codes)), metric),
148+
result_som.codes,
149+
knnTreeFun(Array{Float64,2}(transpose(result_som.codes)), metric),
137150
)
138151

139-
r = radiusFun(rStart, rFinal, j, epochs)
152+
r = radiusFun(rStart, rFinal, epoch, epochs)
140153
@debug "radius: $r"
141154
if r <= 0
142155
@error "Sanity check failed: radius must be positive"
143156
error("Radius check")
144157
end
145158

146159
wEpoch = kernelFun(dm, r)
147-
codes = (wEpoch * numerator) ./ (wEpoch * denominator)
148-
end
160+
result_som.codes = (wEpoch * numerator) ./ (wEpoch * denominator)
149161

150-
som.codes = copy(codes)
162+
eachEpoch(epoch, r, result_som)
163+
end
151164

152-
return som
165+
return result_som
153166
end
154167

155168
"""
156169
trainGigaSOM(som::Som, train;
157-
kernelFun::Function = gaussianKernel,
158-
metric = Euclidean(),
159-
somDistFun = distMatrix(Chebyshev()),
160-
knnTreeFun = BruteTree,
161-
rStart = 0.0, rFinal=0.1, radiusFun=expRadius(-5.0),
162-
epochs = 20)
170+
kwargs...)
163171
164172
Overload of `trainGigaSOM` for simple DataFrames and matrices. This slices the
165-
data using `DistributedArrays`, sends them the workers, and runs normal
166-
`trainGigaSOM`. Data is `undistribute`d after the computation.
173+
data, distributes them to the workers, and runs normal `trainGigaSOM`. Data is
174+
`undistribute`d after the computation.
167175
"""
168-
function trainGigaSOM(
169-
som::Som,
170-
train;
171-
kernelFun::Function = gaussianKernel,
172-
metric = Euclidean(),
173-
somDistFun = distMatrix(Chebyshev()),
174-
knnTreeFun = BruteTree,
175-
rStart = 0.0,
176-
rFinal = 0.1,
177-
radiusFun = expRadius(-5.0),
178-
epochs = 20,
179-
)
176+
function trainGigaSOM(som::Som, train; kwargs...)
180177

181178
train = Matrix{Float64}(train)
182179

183180
#this slices the data into parts and and sends them to workers
184181
dInfo = distribute_array(:GigaSOMtrainDataVar, train, workers())
185-
som_res = trainGigaSOM(
186-
som,
187-
dInfo,
188-
kernelFun = kernelFun,
189-
metric = metric,
190-
somDistFun = somDistFun,
191-
knnTreeFun = knnTreeFun,
192-
rStart = rStart,
193-
rFinal = rFinal,
194-
radiusFun = radiusFun,
195-
epochs = epochs,
196-
)
182+
som_res = trainGigaSOM(som, dInfo; kwargs...)
197183
undistribute(dInfo)
198184
return som_res
199185
end

src/base/structs.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ mutable struct Som
2828
) = new(codes, xdim, ydim, numCodes, grid)
2929
end
3030

31+
Base.copy(som::Som) = Som(
32+
codes = som.codes,
33+
xdim = som.xdim,
34+
ydim = som.ydim,
35+
numCodes = som.numCodes,
36+
grid = som.grid,
37+
)
38+
3139
"""
3240
LoadedDataInfo
3341

0 commit comments

Comments
 (0)