Skip to content

Commit a468919

Browse files
committed
Changed classification selection to non-allocating map! (addresses #26)
1 parent 9bcf1f6 commit a468919

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/AdaBoost.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,10 @@ function learn(
122122
# classification_errors = zeros(length(feature_indices))
123123
classification_errors = Matrix{Float64}(undef, length(feature_indices), 1)
124124
# normalize the weights $w_{t,i}\gets \frac{w_{t,i}}{\sum_{j=1}^n w_{t,j}}$
125-
weights = float(weights) / sum(weights)
125+
weights = float.(weights) ./ sum(weights)
126126

127127
# For each feature j, train a classifier $h_j$ which is restricted to using a single feature. The error is evaluated with respect to $w_j,\varepsilon_j = \sum_i w_i\left|h_j\left(x_i\right)-y_i\right|$
128-
for j in 1:length(feature_indices)
129-
f_idx = feature_indices[j]
130-
# classifier error is the sum of image weights where the classifier is right
131-
ε = sum(img_idx -> labels[img_idx] ≠ votes[f_idx, img_idx] ? weights[img_idx] : zero(Float64), 1:num_imgs)
132-
classification_errors[j] = ε
133-
end
128+
map!(j -> sum(img_idx -> labels[img_idx] ≠ votes[feature_indices[j], img_idx] ? weights[img_idx] : zero(Float64), 1:num_imgs), view(classification_errors, :), 1:length(feature_indices))
134129

135130
# choose the classifier $h_t$ with the lowest error $\varepsilon_t$
136131
min_error_idx = argmin(classification_errors) # returns the index of the minimum in the array # consider `findmin`

0 commit comments

Comments
 (0)