azami 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/azami.rb +24 -21
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ab05804a9638e3b584242d1ceade1e1595a7cb9
4
- data.tar.gz: 3f67fcfb9d870e8b4c6b6a765f7c1c6843bb6842
3
+ metadata.gz: aff3ce034f65417a0d6a486e0e56e5bbe2ab20e6
4
+ data.tar.gz: 6c85bd9ffb21f9cc3f1309c1d8df6bd2e2e12849
5
5
  SHA512:
6
- metadata.gz: b7fca74c5f0ead536db8bfd462037e204f20ad4d8c3f6d418b07d266e33b26e77925e97938a232a527f9193548e3e391196d75b4e629f47b8d9139341088adfe
7
- data.tar.gz: 45d81c1dfa3fdc229dd001f730199981a04946f5a8d76f0396aa7b7fc333d6ce60b824d0063c36a1cb5815ea6e2e0a2aaf80d4ad96496d096941451136c74bc9
6
+ metadata.gz: 1c4b6634739be5c8ee532c26c92692d9811bc39c119794e51de011d0e79a5a95bf2cd405d9441c4e8456ffc21d3b4265b899715dacfff3fe839973f7f21d1f60
7
+ data.tar.gz: ce07429d25995a3f763039b66fe64177c4421ff6dbc5de22a1af6e56bd938c84c720eb0ce8e311fe651956f309eea0fcdb6a522b0a2e4fc5cbb0a934aa67541a
@@ -1,32 +1,35 @@
1
+ #Azami
1
2
  module Azami
2
-
3
3
  def self.em(data)
4
+ inputs = data[:inputs]
5
+ normal_params = data[:normal_params]
6
+ iteration_count = data[:iteration_count]
4
7
 
5
- inputs, normal_params, iteration_count =
6
- data[:inputs], data[:normal_params], data[:iteration_count]
7
-
8
- iteration_count.times{
8
+ iteration_count.times do
9
9
  likelihood_weights =
10
- inputs.map { |input|
11
- likelihoods = normal_params.map { |normal_param|
12
- mean,stdev = normal_param[:mean],normal_param[:stdev]
13
- (0.398942*(2.71828**(-(0.5*(input - mean)**2)/stdev**2)))/stdev
14
- }
10
+ inputs.map do |input|
11
+ likelihoods = normal_params.map do |normal_param|
12
+ mean = normal_param[:mean]
13
+ stdev = normal_param[:stdev]
14
+ (0.398942 * (2.71828**(-(0.5 * (input - mean)**2) / stdev**2))) / stdev
15
+ end
15
16
  total_likelihood = likelihoods.sum
16
- likelihoods.map { |lk|
17
- lk/total_likelihood
18
- }
19
- }.transpose
17
+ likelihoods.map do |lk|
18
+ lk / total_likelihood
19
+ end
20
+ end.transpose
20
21
 
21
- normal_params.each_with_index { |normal_param, normal_index|
22
+ normal_params.each_with_index do |normal_param, normal_index|
22
23
  weights = likelihood_weights[normal_index]
23
24
  weights_sum = weights.sum
24
- normal_param[:mean] = mean = (weights.map.with_index { |weight,input_i|
25
- (weight*inputs[input_i])}.sum)/(weights_sum)
26
- normal_param[:stdev] = Math.sqrt(((weights.map.with_index { |weight,input_i|
27
- (((inputs[input_i]-mean)**2)*weight) }).sum)/(weights_sum))
28
- }
29
- }
25
+ normal_param[:mean] = mean = weights.map.with_index do |weight, input_i|
26
+ (weight * inputs[input_i])
27
+ end .sum / weights_sum
28
+ normal_param[:stdev] = Math.sqrt((weights.map.with_index do |weight, input_i|
29
+ (((inputs[input_i] - mean)**2) * weight)
30
+ end).sum / weights_sum)
31
+ end
32
+ end
30
33
  normal_params
31
34
  end
32
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azami
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - forvelin