lightmodels 0.1.2-java → 0.2.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,69 +0,0 @@
1
- require 'emf_jruby'
2
-
3
- module LightModels
4
-
5
- class CountingMap
6
-
7
- def initialize
8
- @map = {}
9
- @sum_values = 0
10
- end
11
-
12
- def inc(key)
13
- @map[key] = 0 unless @map[key]
14
- @map[key] = @map[key]+1
15
- @sum_values += 1
16
- end
17
-
18
- def value(key)
19
- @map[key] = 0 unless @map[key]
20
- @map[key]
21
- end
22
-
23
- # number of times the value appeared divived by total frequency
24
- def p(key)
25
- @map[key].to_f/total_frequency.to_f
26
- end
27
-
28
- def each(&block)
29
- @map.each(&block)
30
- end
31
-
32
- def total_frequency
33
- @sum_values
34
- end
35
-
36
- def n_values
37
- @map.count
38
- end
39
-
40
- end
41
-
42
- def self.entropy(counting_map)
43
- s = 0.0
44
- counting_map.each do |k,v|
45
- p = counting_map.p(k)
46
- s += p*Math.log(p)
47
- end
48
- -s
49
- end
50
-
51
- def idf(n,n_docs)
52
- Math.log(n_docs.to_f/n.to_f)
53
- end
54
-
55
- def combine_self(arr,&op)
56
- for i in 0..(arr.count-2)
57
- for j in (i+1)..(arr.count-1)
58
- op.call(arr[i],arr[j])
59
- end
60
- end
61
- end
62
-
63
- def combine(arr1,arr2,&op)
64
- arr1.each do |el1|
65
- arr2.each {|el2| op.call(el1,el2)}
66
- end
67
- end
68
-
69
- end