@@ -127,7 +127,12 @@ function fitpredictneigh(model, gtb, dom, path, point, prob, minneighbors, maxne
127
127
end
128
128
129
129
# pre-allocate memory for neighbors
130
- neighbors = Vector {Int} (undef, maxneighbors)
130
+ neighbors = collect (1 : maxneighbors)
131
+
132
+ # initialize fitted model with first samples
133
+ ninds = view (neighbors, 1 : maxneighbors)
134
+ ndata = view (gtb, ninds)
135
+ fmodel = fit (model, ndata)
131
136
132
137
# traverse domain with given path
133
138
inds = traverse (dom, path)
@@ -143,18 +148,18 @@ function fitpredictneigh(model, gtb, dom, path, point, prob, minneighbors, maxne
143
148
center = centroid (dom, ind)
144
149
145
150
# find neighbors with data
146
- nneigh = search! (neighbors, center, searcher)
151
+ n = search! (neighbors, center, searcher)
147
152
148
153
# predict if enough neighbors
149
- if nneigh ≥ minneighbors
154
+ if n ≥ minneighbors
150
155
# final set of neighbors
151
- ninds = view (neighbors, 1 : nneigh )
156
+ ninds = view (neighbors, 1 : n )
152
157
153
158
# view neighborhood with data
154
- samples = view (gtb, ninds)
159
+ ndata = view (gtb, ninds)
155
160
156
- # fit model to samples
157
- fmodel = fit (model, samples )
161
+ # fit model to neighborhood
162
+ fit! (fmodel, ndata )
158
163
159
164
# save prediction
160
165
geom = point ? center : dom[ind]
0 commit comments