-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAIFinder.rb
More file actions
49 lines (39 loc) · 860 Bytes
/
AIFinder.rb
File metadata and controls
49 lines (39 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
hy = 0.9852
total = 3
def get_I(total, hy)
size_and_h = {}
block = 0
puts "How many categories?\n"
num = gets.to_i
(1..num).each_with_index do |i|
puts "Sample size for category #{i}"
size = gets.to_i
size_and_h[size] = get_H(size.to_f)
block += (size / total) * size_and_h[size]
end
result = hy - block
puts "Result:\nI(Y;X) = #{result}"
end
def get_H(total)
puts "Number of positives:\n"
pos = gets.to_f
neg = total - pos
pos_prop = pos/total
neg_prop = neg/total
if pos == 0 || pos == total
value = 0
else
value = -(pos_prop * Math.log2(pos_prop) + neg_prop * Math.log2(neg_prop))
end
puts "H(Y|X=x) = #{value}"
value
end
puts "Enter 0 for H(Y|X=x), 1 for I(Y;X):\n"
num = gets.to_f
#puts "Total sample size:\n"
#total = gets.to_f
if num == 0
value = get_H(total.to_f)
else
value = get_I(total.to_f, hy)
end