Skip to content

Commit

Permalink
fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
tawheeler committed Aug 16, 2017
1 parent aabab48 commit d84cc06
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/linear_discretizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,21 @@ function encode{N,D<:Integer}(ld::LinearDiscretizer{N,D}, x::N)
elseif x > ld.binedges[end]
return ld.force_outliers_to_closest ? ld.i2d[ld.nbins] : throw(BoundsError())
else
i = searchsortedfirst(ld.binedges, x) # index of first val in binedges ≥ x
if ld.binedges[i] != x
i -= 1

# run bisection search
binedges = ld.binedges
a, b = 1, length(binedges)
va, vb = binedges[a], binedges[b]
while b-a > 1
c = div(a+b, 2)
vc = binedges[c]
if x < vc
b, vb = c, vc
else
a, va = c, vc
end
end
return ld.i2d[min(i, ld.nbins)]
return ld.i2d[a]
end
end
encode{N,D}(ld::LinearDiscretizer{N,D}, x) = encode(ld, convert(N, x))::D
Expand Down

0 comments on commit d84cc06

Please sign in to comment.