statsample-optimization 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-08-02
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ ext/statsample/extconf.rb
6
+ ext/statsample/optimization.c
7
+ test/test_statsample_optimization.rb
data/README.txt ADDED
@@ -0,0 +1,31 @@
1
+ = Statsample (optimization package)
2
+
3
+ http://rubyforge.org/projects/ruby-statsample/
4
+
5
+ == DESCRIPTION:
6
+
7
+ Extension for statsample, that speed some methods.
8
+ Optimize the following methods
9
+
10
+ * Vector#frecuencies
11
+ * Vector#set_valid_data
12
+ * Dataset#case_as_hash
13
+ * Dataset#case_as_array
14
+
15
+
16
+
17
+ == SYNOPSIS:
18
+ Only require statsample. The module detects and use the extensions
19
+
20
+
21
+ == REQUIREMENTS:
22
+
23
+ * Statsample
24
+
25
+ == INSTALL:
26
+
27
+ sudo gem install statsample-optimization
28
+
29
+ == LICENSE:
30
+
31
+ GPL-2
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/ruby
2
+ # -*- ruby -*-
3
+
4
+ require 'rubygems'
5
+ require 'hoe'
6
+
7
+ EXT = "ext/statsample/optimization.#{Config::CONFIG['DLEXT']}"
8
+
9
+ task :test => [EXT]
10
+
11
+ file "ext/statsample/Makefile" => ["ext/statsample/extconf.rb"] do |t|
12
+ Dir.chdir "ext/statsample" do
13
+ system %(ruby extconf.rb)
14
+ end
15
+
16
+ end
17
+ file EXT => ["ext/statsample/Makefile", "ext/statsample/optimization.c"] do
18
+ puts "Compiling"
19
+ Dir.chdir "ext/statsample" do
20
+ system %(make)
21
+ end
22
+ end
23
+
24
+
25
+
26
+ Hoe.spec 'statsample-optimization' do |p|
27
+ p.version="1.0.0"
28
+ p.rubyforge_name = 'ruby-statsample'
29
+ p.developer('Claudio Bustos', 'clbustos_at_gmail.com')
30
+ p.spec_extras[:extensions] = ["ext/statsample/extconf.rb"]
31
+ p.extra_deps << "statsample"
32
+ p.clean_globs << EXT
33
+ p.clean_globs << EXT << "ext/statsample/*.o" << "ext/statsample/*.so" << "ext/statsample/Makefile"
34
+ end
35
+
36
+ # vim: syntax=ruby
@@ -0,0 +1,3 @@
1
+ require "mkmf"
2
+ $CFLAGS+=" -Wall "
3
+ create_makefile("optimization")
@@ -0,0 +1,119 @@
1
+ #include <ruby.h>
2
+ /**
3
+ * :stopdoc:
4
+ */
5
+ void Init_optimization();
6
+ VALUE nominal_frequencies(VALUE self);
7
+ VALUE rubyss_frequencies(VALUE self, VALUE data);
8
+ VALUE rubyss_set_valid_data(VALUE self, VALUE vector);
9
+ VALUE dataset_case_as_hash(VALUE self, VALUE index);
10
+ VALUE dataset_case_as_array(VALUE self, VALUE index);
11
+ void Init_optimization()
12
+ {
13
+ VALUE mRubySS = rb_define_module("Statsample");
14
+
15
+ VALUE cNominal = rb_define_class_under(mRubySS,"Nominal",rb_cObject);
16
+ VALUE cDataset = rb_define_class_under(mRubySS,"Dataset",rb_cObject);
17
+
18
+ rb_define_const(mRubySS,"OPTIMIZED",Qtrue);
19
+ rb_define_module_function(mRubySS,"_frequencies",rubyss_frequencies,1);
20
+ rb_define_module_function(mRubySS,"_set_valid_data",rubyss_set_valid_data,1);
21
+ rb_define_method(cNominal,"frequencies",nominal_frequencies,0);
22
+ rb_define_method(cDataset,"case_as_hash",dataset_case_as_hash,1);
23
+ rb_define_method(cDataset,"case_as_array",dataset_case_as_array,1);
24
+
25
+ }
26
+
27
+ VALUE rubyss_set_valid_data(VALUE self, VALUE vector) {
28
+ /** Emulate
29
+
30
+ @data.each do |n|
31
+ if is_valid? n
32
+ @valid_data.push(n)
33
+ @data_with_nils.push(n)
34
+ else
35
+ @data_with_nils.push(nil)
36
+ @missing_data.push(n)
37
+ end
38
+ end
39
+ @has_missing_data=@missing_data.size>0
40
+ */
41
+ VALUE data=rb_iv_get(vector,"@data");
42
+ VALUE valid_data=rb_iv_get(vector,"@valid_data");
43
+ VALUE data_with_nils=rb_iv_get(vector,"@data_with_nils");
44
+ VALUE missing_data=rb_iv_get(vector,"@missing_data");
45
+ VALUE missing_values=rb_iv_get(vector,"@missing_values");
46
+ // VALUE has_missing_data=rb_iv_get(vector,"@has_missing_data");
47
+ long len=RARRAY_LEN(data);
48
+ long i;
49
+ VALUE val;
50
+ for(i=0;i<len;i++) {
51
+ val=rb_ary_entry(data,i);
52
+ if(val==Qnil || rb_ary_includes(missing_values,val)) {
53
+ rb_ary_push(missing_data,val);
54
+ rb_ary_push(data_with_nils,Qnil);
55
+ } else {
56
+ rb_ary_push(valid_data,val);
57
+ rb_ary_push(data_with_nils,val);
58
+ }
59
+ }
60
+ rb_iv_set(vector,"@has_missing_data",(RARRAY_LEN(missing_data)>0) ? Qtrue : Qfalse);
61
+ return Qnil;
62
+ }
63
+ VALUE rubyss_frequencies(VALUE self, VALUE data) {
64
+ VALUE h;
65
+ VALUE val;
66
+ long len;
67
+ long i;
68
+
69
+ Check_Type(data,T_ARRAY);
70
+ h=rb_hash_new();
71
+
72
+ len=RARRAY_LEN(data);
73
+ for(i=0;i<len;i++) {
74
+ val=rb_ary_entry(data,i);
75
+ if(rb_hash_aref(h,val)==Qnil) {
76
+ rb_hash_aset(h,val,INT2FIX(1));
77
+ } else {
78
+ long antiguo=FIX2LONG(rb_hash_aref(h,val));
79
+ rb_hash_aset(h,val,LONG2FIX(antiguo+1));
80
+ }
81
+ }
82
+ return h;
83
+ }
84
+
85
+ VALUE nominal_frequencies(VALUE self) {
86
+ VALUE data=rb_iv_get(self,"@data");
87
+ return rubyss_frequencies(self,data);
88
+ }
89
+ VALUE dataset_case_as_hash(VALUE self, VALUE index) {
90
+ VALUE vector,data,key;
91
+ VALUE fields=rb_iv_get(self,"@fields");
92
+ VALUE vectors=rb_iv_get(self,"@vectors");
93
+ VALUE h=rb_hash_new();
94
+ long len=RARRAY_LEN(fields);
95
+ long i;
96
+ for(i=0;i<len;i++) {
97
+ key=rb_ary_entry(fields,i);
98
+ vector=rb_hash_aref(vectors,key);
99
+ data=rb_iv_get(vector,"@data");
100
+ rb_hash_aset(h,key,rb_ary_entry(data,NUM2LONG(index)));
101
+ }
102
+ return h;
103
+ }
104
+ VALUE dataset_case_as_array(VALUE self, VALUE index) {
105
+ VALUE vector,data,key;
106
+ VALUE fields=rb_iv_get(self,"@fields");
107
+ VALUE vectors=rb_iv_get(self,"@vectors");
108
+ VALUE ar=rb_ary_new();
109
+ long len=RARRAY_LEN(fields);
110
+ long i;
111
+ for(i=0;i<len;i++) {
112
+ key=rb_ary_entry(fields,i);
113
+ vector=rb_hash_aref(vectors,key);
114
+ data=rb_iv_get(vector,"@data");
115
+ rb_ary_push(ar,rb_ary_entry(data,NUM2LONG(index)));
116
+ }
117
+ return ar;
118
+ }
119
+
@@ -0,0 +1,16 @@
1
+ $:.unshift(File.dirname(__FILE__)+"/ext")
2
+ require "test/unit"
3
+ require "statsample"
4
+ require "statsample/optimization"
5
+
6
+ class TestRubyStatsampleOpt < Test::Unit::TestCase
7
+ def test_base
8
+ assert(Statsample::OPTIMIZED,true)
9
+ end
10
+ def test_frequencies
11
+ assert(Statsample.respond_to?(:_frequencies))
12
+ v=[1,1,2].to_vector
13
+ exp={1=>2,2=>1}
14
+ assert_equal(exp,Statsample._frequencies(v.data))
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statsample-optimization
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Claudio Bustos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-03 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: statsample
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.2
34
+ version:
35
+ description: |-
36
+ Extension for statsample, that speed some methods.
37
+ Optimize the following methods
38
+
39
+ * Vector#frecuencies
40
+ * Vector#set_valid_data
41
+ * Dataset#case_as_hash
42
+ * Dataset#case_as_array
43
+ email:
44
+ - clbustos_at_gmail.com
45
+ executables: []
46
+
47
+ extensions:
48
+ - ext/statsample/extconf.rb
49
+ extra_rdoc_files:
50
+ - History.txt
51
+ - Manifest.txt
52
+ - README.txt
53
+ files:
54
+ - History.txt
55
+ - Manifest.txt
56
+ - README.txt
57
+ - Rakefile
58
+ - ext/statsample/extconf.rb
59
+ - ext/statsample/optimization.c
60
+ - test/test_statsample_optimization.rb
61
+ has_rdoc: true
62
+ homepage: http://rubyforge.org/projects/ruby-statsample/
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --main
68
+ - README.txt
69
+ require_paths:
70
+ - ext
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project: ruby-statsample
86
+ rubygems_version: 1.3.5
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Extension for statsample, that speed some methods
90
+ test_files:
91
+ - test/test_statsample_optimization.rb