Skip to content

Commit

Permalink
Rename dataT to transposed
Browse files Browse the repository at this point in the history
  • Loading branch information
appleparan committed Feb 19, 2020
1 parent 4630dd1 commit e4cd596
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/imputors/knn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,30 @@ function impute!(data::AbstractMatrix{<:Union{T, Missing}},
impute!(data, Fill(; value=mean, context=ctx))

# transpose to D x N for KDTree
dataT = float.(collect(transpose(data)))
kdtree = KDTree(dataT, imp.dist)
transposed = float.(collect(transpose(data)))
kdtree = KDTree(transposed, imp.dist)

# index of columns
idxs, dists = NearestNeighbors.knn(kdtree, dataT, imp.num_nn, true)
invWdist(i) = dists[i] == 0 ? dataT[idxs[i]] : dists[i]
idxs, dists = NearestNeighbors.knn(kdtree, transposed, imp.num_nn, true)
invWdist(i) = dists[i] == 0 ? transposed[idxs[i]] : dists[i]
# TODO : going to parallel?
for (i, x) in enumerate(mdata)
if ndims(dataT) != 1
if ndims(transposed) != 1
# ndims(dataT) == 1 means there is there is only single row.
if mmask[i] == 1
# idxs[i] = k-length column indicies
# weighted sum

# what about mulitple missings??
coli = div(i, size(dataT, 1)) + 1
coli = div(i, size(transposed, 1)) + 1
# println("$i $coli $(size(mdata))")
w = sum(dists[coli]) ./ dists[coli]
# Inverse distance weighting
if isnan(sum(w)) || isinf(sum(w))
# if some distance is zero, keep original value
data[i] = data[i]
else
data[i] = sum(w .* dataT[idxs[coli]])
data[i] = sum(w .* transposed[idxs[coli]])
end
end
end
Expand Down

0 comments on commit e4cd596

Please sign in to comment.