Skip to content

Instantly share code, notes, and snippets.

@slumos
Created January 8, 2015 01:34
Show Gist options
  • Save slumos/189ea259a6a451646aaa to your computer and use it in GitHub Desktop.
Save slumos/189ea259a6a451646aaa to your computer and use it in GitHub Desktop.
# 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