Module: LightModels
- Defined in:
- lib/lightmodels/jsonser_nav.rb,
lib/lightmodels/model.rb,
lib/lightmodels/query.rb,
lib/lightmodels/stats.rb,
lib/lightmodels/serialization.rb,
lib/lightmodels/model_building.rb
Overview
This module permits to manipulate Objects serialized as Hash
Defined Under Namespace
Modules: ModelBuilding, Query, Serialization
Classes: CountingMap, Model
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.entropy(counting_map) ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/lightmodels/stats.rb', line 42
def self.entropy(counting_map)
s = 0.0
counting_map.each do |k,v|
p = counting_map.p(k)
s += p*Math.log(p)
end
-s
end
|
Instance Method Details
#combine(arr1, arr2, &op) ⇒ Object
63
64
65
66
67
|
# File 'lib/lightmodels/stats.rb', line 63
def combine(arr1,arr2,&op)
arr1.each do |el1|
arr2.each {|el2| op.call(el1,el2)}
end
end
|
#combine_self(arr, &op) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/lightmodels/stats.rb', line 55
def combine_self(arr,&op)
for i in 0..(arr.count-2)
for j in (i+1)..(arr.count-1)
op.call(arr[i],arr[j])
end
end
end
|
#idf(n, n_docs) ⇒ Object
51
52
53
|
# File 'lib/lightmodels/stats.rb', line 51
def idf(n,n_docs)
Math.log(n_docs.to_f/n.to_f)
end
|