Discretizers.jl icon indicating copy to clipboard operation
Discretizers.jl copied to clipboard

RegularLinearDiscretizer or something better than bisection search

Open zsunberg opened this issue 5 years ago • 2 comments

Turns out removing the Dicts didn't help my performance too much... I guess I didn't look hard enough at the profiling.

The encoding still seems to be a bit slow because of the binary search. All of my grids are regular, so I could implement at RegularLinearDiscretizer that encodes in O(1) time.

Another option would be to replace https://github.com/sisl/Discretizers.jl/blob/b43839f39c3f9ca09c025434788eb8f10c48d55c/src/linear_discretizer.jl#L70 with something like

c = floor(Int, (b-a)*(x-va)/(vb-va))

which would be faster if the bins are evenly spaced, but could have bad performance if bins are irregular (maybe... I think).

Seems like RegularLinearDiscretizer would be best, but wanted to check if anyone else had anything to say/if anyone knows of another package that already does this.

zsunberg avatar Jan 31 '20 23:01 zsunberg

Or...

struct LinearDiscretizer{N, D, E<:AbstractVector} ...
    binedges::E
    ...
end

And then we could write a special method of encode that does O(1) lookup for LinearDiscretizers that have an AbstractRange as binedges.

zsunberg avatar Jan 31 '20 23:01 zsunberg

Yeah, I think we could specialize for uniform bins. I like O(1) lookups.

mykelk avatar Feb 01 '20 02:02 mykelk