23
23
# and returns a Matrix containing the resulting vectors, stacked vertically
24
24
function stack_function_results (row_fun:: Function , X:: Matrix )
25
25
N = size (X, 1 )
26
- N_cols = length (row_fun (_squeeze ( X[1 ,:], 1 ) )) # gets the number of columns
26
+ N_cols = length (row_fun (X[1 , :] )) # gets the number of columns
27
27
out = Array {Float64} (N, N_cols)
28
28
for i in 1 : N
29
- out[i, :] = row_fun (_squeeze ( X[i,:], 1 ) )
29
+ out[i, :] = row_fun (X[i, :] )
30
30
end
31
31
return out
32
32
end
@@ -94,7 +94,7 @@ function _split_neg_z1_loss(labels::Vector, features::Matrix, weights::Vector)
94
94
domain_i = sort (unique (features[:,i]))
95
95
for thresh in domain_i[2 : end ]
96
96
cur_split = features[:,i] .< thresh
97
- value = _neg_z1_loss (labels[cur_split], weights[cur_split]) + _neg_z1_loss (labels[neg ( cur_split)], weights[neg (cur_split)])
97
+ value = _neg_z1_loss (labels[cur_split], weights[cur_split]) + _neg_z1_loss (labels[( ! ) . ( cur_split)], weights[( ! ) . (cur_split)])
98
98
if value > best_val
99
99
best_val = value
100
100
best = (i, thresh)
@@ -114,7 +114,7 @@ function build_stump(labels::Vector, features::Matrix, weights=[0];
114
114
split = features[:,id] .< thresh
115
115
return Node (id, thresh,
116
116
Leaf (majority_vote (labels[split]), labels[split]),
117
- Leaf (majority_vote (labels[neg ( split)]), labels[neg (split)]))
117
+ Leaf (majority_vote (labels[( ! ) . ( split)]), labels[( ! ) . (split)]))
118
118
end
119
119
120
120
function build_tree (labels:: Vector , features:: Matrix , nsubfeatures= 0 , maxdepth= - 1 ; rng= Base. GLOBAL_RNG)
@@ -131,7 +131,7 @@ function build_tree(labels::Vector, features::Matrix, nsubfeatures=0, maxdepth=-
131
131
id, thresh = S
132
132
split = features[:,id] .< thresh
133
133
labels_left = labels[split]
134
- labels_right = labels[neg (split)]
134
+ labels_right = labels[( ! ) . (split)]
135
135
pure_left = all (labels_left .== labels_left[1 ])
136
136
pure_right = all (labels_right .== labels_right[1 ])
137
137
if pure_right && pure_left
@@ -141,7 +141,7 @@ function build_tree(labels::Vector, features::Matrix, nsubfeatures=0, maxdepth=-
141
141
elseif pure_left
142
142
return Node (id, thresh,
143
143
Leaf (labels_left[1 ], labels_left),
144
- build_tree (labels_right,features[neg (split),:], nsubfeatures,
144
+ build_tree (labels_right,features[( ! ) . (split),:], nsubfeatures,
145
145
max (maxdepth- 1 , - 1 ); rng= rng))
146
146
elseif pure_right
147
147
return Node (id, thresh,
@@ -152,7 +152,7 @@ function build_tree(labels::Vector, features::Matrix, nsubfeatures=0, maxdepth=-
152
152
return Node (id, thresh,
153
153
build_tree (labels_left,features[split,:], nsubfeatures,
154
154
max (maxdepth- 1 , - 1 ); rng= rng),
155
- build_tree (labels_right,features[neg (split),:], nsubfeatures,
155
+ build_tree (labels_right,features[( ! ) . (split),:], nsubfeatures,
156
156
max (maxdepth- 1 , - 1 ); rng= rng))
157
157
end
158
158
end
@@ -202,10 +202,10 @@ function apply_tree(tree::LeafOrNode, features::Matrix)
202
202
N = size (features,1 )
203
203
predictions = Array {Any} (N)
204
204
for i in 1 : N
205
- predictions[i] = apply_tree (tree, _squeeze ( features[i,:], 1 ) )
205
+ predictions[i] = apply_tree (tree, features[i, :] )
206
206
end
207
207
if typeof (predictions[1 ]) <: Float64
208
- return float (predictions)
208
+ return Float64 . (predictions)
209
209
else
210
210
return predictions
211
211
end
@@ -252,7 +252,7 @@ function apply_forest(forest::Ensemble, features::Vector)
252
252
ntrees = length (forest)
253
253
votes = Array {Any} (ntrees)
254
254
for i in 1 : ntrees
255
- votes[i] = apply_tree (forest. trees[i],features)
255
+ votes[i] = apply_tree (forest. trees[i], features)
256
256
end
257
257
if typeof (votes[1 ]) <: Float64
258
258
return mean (votes)
@@ -265,10 +265,10 @@ function apply_forest(forest::Ensemble, features::Matrix)
265
265
N = size (features,1 )
266
266
predictions = Array {Any} (N)
267
267
for i in 1 : N
268
- predictions[i] = apply_forest (forest, _squeeze ( features[i,:], 1 ) )
268
+ predictions[i] = apply_forest (forest, features[i, :] )
269
269
end
270
270
if typeof (predictions[1 ]) <: Float64
271
- return float (predictions)
271
+ return Float64 . (predictions)
272
272
else
273
273
return predictions
274
274
end
@@ -302,7 +302,7 @@ function build_adaboost_stumps(labels::Vector, features::Matrix, niterations::In
302
302
err = _weighted_error (labels, predictions, weights)
303
303
new_coeff = 0.5 * log ((1.0 + err) / (1.0 - err))
304
304
matches = labels .== predictions
305
- weights[neg (matches)] *= exp (new_coeff)
305
+ weights[( ! ) . (matches)] *= exp (new_coeff)
306
306
weights[matches] *= exp (- new_coeff)
307
307
weights /= sum (weights)
308
308
push! (coeffs, new_coeff)
@@ -336,7 +336,7 @@ function apply_adaboost_stumps(stumps::Ensemble, coeffs::Vector{Float64}, featur
336
336
N = size (features,1 )
337
337
predictions = Array {Any} (N)
338
338
for i in 1 : N
339
- predictions[i] = apply_adaboost_stumps (stumps, coeffs, _squeeze ( features[i,:], 1 ) )
339
+ predictions[i] = apply_adaboost_stumps (stumps, coeffs, features[i,:])
340
340
end
341
341
return predictions
342
342
end
0 commit comments