standard_deviation 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,27 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
#include <math.h>
|
3
3
|
|
4
|
-
static double sum(double array[], long size) {
|
5
|
-
int i;
|
6
|
-
double total = 0;
|
7
|
-
|
8
|
-
for (i = 0; i < size; i++) {
|
9
|
-
total += array[i];
|
10
|
-
}
|
11
|
-
|
12
|
-
return total;
|
13
|
-
}
|
14
|
-
|
15
4
|
static double distance_from_mean(VALUE *array, long size) {
|
16
5
|
int i;
|
17
|
-
double mean, distance;
|
6
|
+
double mean, distance, total;
|
18
7
|
double values[size];
|
19
8
|
|
20
|
-
for (i = 0; i < size; i++) {
|
21
|
-
|
9
|
+
for (i = 0, total = 0; i < size; i++) {
|
10
|
+
double value;
|
11
|
+
|
12
|
+
switch (TYPE(array[i])) {
|
13
|
+
case T_FIXNUM:
|
14
|
+
value = FIX2LONG(array[i]);
|
15
|
+
default:
|
16
|
+
value = NUM2DBL(array[i]);
|
17
|
+
break;
|
18
|
+
}
|
19
|
+
|
20
|
+
values[i] = value;
|
21
|
+
total += value;
|
22
22
|
}
|
23
23
|
|
24
|
-
mean =
|
24
|
+
mean = total / size;
|
25
25
|
|
26
26
|
for (i = 0, distance = 0; i < size; i++) {
|
27
27
|
distance += pow(values[i] - mean, 2);
|
@@ -79,11 +79,15 @@ static VALUE stdevp(VALUE self) {
|
|
79
79
|
}
|
80
80
|
|
81
81
|
void Init_standard_deviation() {
|
82
|
-
|
83
|
-
|
84
|
-
rb_define_method(
|
82
|
+
VALUE mStandardDeviation = rb_define_module("StandardDeviation");
|
83
|
+
|
84
|
+
rb_define_method(mStandardDeviation, "stdev", stdev, 0);
|
85
|
+
rb_define_alias(mStandardDeviation, "standard_deviation", "stdev");
|
86
|
+
rb_define_method(mStandardDeviation, "stdevp", stdevp, 0);
|
87
|
+
|
88
|
+
rb_define_method(mStandardDeviation, "sample_variance", sample_variance, 0);
|
89
|
+
rb_define_alias(mStandardDeviation, "variance", "sample_variance");
|
90
|
+
rb_define_method(mStandardDeviation, "population_variance", population_variance, 0);
|
85
91
|
|
86
|
-
|
87
|
-
rb_define_alias(rb_cArray, "variance", "sample_variance");
|
88
|
-
rb_define_method(rb_cArray, "population_variance", population_variance, 0);
|
92
|
+
rb_include_module(rb_cArray, mStandardDeviation);
|
89
93
|
}
|
data/lib/standard_deviation.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standard_deviation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake-compiler
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156775860 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156775860
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &2156775260 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2156775260
|
36
36
|
description: ! "An implementation of the standard deviation calculation in C,\n with
|
37
37
|
much better performance (50x-100x) than using pure ruby."
|
38
38
|
email:
|
@@ -73,7 +73,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
73
|
version: '0'
|
74
74
|
segments:
|
75
75
|
- 0
|
76
|
-
hash:
|
76
|
+
hash: 3904352237865759400
|
77
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
78
|
none: false
|
79
79
|
requirements:
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
version: '0'
|
83
83
|
segments:
|
84
84
|
- 0
|
85
|
-
hash:
|
85
|
+
hash: 3904352237865759400
|
86
86
|
requirements: []
|
87
87
|
rubyforge_project:
|
88
88
|
rubygems_version: 1.8.10
|