Created
January 8, 2015 01:34
-
-
Save slumos/189ea259a6a451646aaa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initialize to use Indexer object idx. Also precomputes some | |
# things that can be computed with a single traversal of the | |
# document directory. | |
def initialize(idx) | |
@idx = idx | |
@m = 0.0 | |
@c = Hash.new(0.0) | |
@idx.each_document do |doc| | |
@m += 1 | |
@c[cat(doc.name)] += 1 | |
end | |
@categories = @c.keys.sort | |
@kz = (1/@m) / (@m + 2/@m) # Kohavi zero | |
end | |
# From [KBS97] | |
def kohavi(a,b) | |
return @kz if a == @kz and b == @kz | |
if a == 0 then | |
if b == 0 then | |
return @kz | |
else | |
return (1/b) / (b + 2/b) | |
end | |
else | |
return a / b | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment