cabalist 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cabalist.rb +2 -0
- data/lib/cabalist/manager.rb +30 -0
- data/lib/cabalist/object_hooks.rb +59 -0
- metadata +66 -0
data/lib/cabalist.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Cabalist
|
4
|
+
|
5
|
+
class Manager
|
6
|
+
|
7
|
+
include Singleton
|
8
|
+
attr_accessor :classifiers
|
9
|
+
|
10
|
+
def initialize() self.classifiers = [] end
|
11
|
+
|
12
|
+
|
13
|
+
def self.register_classifier(klass, proc)
|
14
|
+
instance.classifiers << { :klass => klass, :proc => proc }
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.setup!
|
18
|
+
instance.classifiers.each do |classifier|
|
19
|
+
classifier[:klass].const_set( 'CABALIST_CLASSIFIER',
|
20
|
+
classifier[:proc].call )
|
21
|
+
classifier[:klass].class_eval do
|
22
|
+
def classify() CABALIST_CLASSIFIER.eval(self.get_signals) end
|
23
|
+
def classify!() set_category(classify) end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'ai4r'
|
2
|
+
|
3
|
+
Object::instance_eval do
|
4
|
+
|
5
|
+
def acts_as_cabalist(options = {})
|
6
|
+
|
7
|
+
# == Set defaults ======================================================= #
|
8
|
+
collection = options[:collection] || :all
|
9
|
+
algorithm = options[:algorithm] || :id3
|
10
|
+
# == END ================================================================ #
|
11
|
+
|
12
|
+
# == Determine a classifier ============================================= #
|
13
|
+
classifier = case algorithm
|
14
|
+
when :hyperpipes then Ai4r::Classifiers::Hyperpipes
|
15
|
+
when :ib1 then Ai4r::Classifiers::IB1
|
16
|
+
when :id3 then Ai4r::Classifiers::ID3
|
17
|
+
when :one_r then Ai4r::Classifiers::OneR
|
18
|
+
when :prism then Ai4r::Classifiers::Prism
|
19
|
+
when :zero_r then Ai4r::Classifiers::ZeroR
|
20
|
+
else raise 'Unknown algorithm provided'
|
21
|
+
end
|
22
|
+
# == END ================================================================ #
|
23
|
+
|
24
|
+
# == Set classification methods ========================================= #
|
25
|
+
get_signals_proc = Proc::new do
|
26
|
+
options[:fields].map do |field|
|
27
|
+
field.is_a?(Proc) ? field.call(self) : self.send(field)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
get_category_proc = Proc::new do
|
32
|
+
self.send(options[:category])
|
33
|
+
end
|
34
|
+
|
35
|
+
set_category_proc = Proc::new do |val|
|
36
|
+
self.send("#{options[:category]}=".to_sym, val)
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
send(:define_method, 'get_signals'.to_sym, &get_signals_proc)
|
41
|
+
send(:define_method, 'get_category'.to_sym, &get_category_proc)
|
42
|
+
send(:define_method, 'set_category'.to_sym, &set_category_proc)
|
43
|
+
|
44
|
+
proc = Proc::new do
|
45
|
+
data_items = send(collection).map do |el|
|
46
|
+
el.get_signals.push(el.get_category)
|
47
|
+
end
|
48
|
+
data_set = Ai4r::Data::DataSet::new({ :data_items => data_items })
|
49
|
+
classifier::new.build(data_set)
|
50
|
+
end
|
51
|
+
# == END ================================================================ #
|
52
|
+
|
53
|
+
# == Register classifier ================================================ #
|
54
|
+
Cabalist::Manager.register_classifier(self, proc)
|
55
|
+
# == END ================================================================ #
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cabalist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marcin Wyszynski
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-09-04 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ai4r
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "1.10"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description:
|
27
|
+
email: marcin.pixie@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files: []
|
33
|
+
|
34
|
+
files:
|
35
|
+
- lib/cabalist/manager.rb
|
36
|
+
- lib/cabalist/object_hooks.rb
|
37
|
+
- lib/cabalist.rb
|
38
|
+
homepage: https://github.com/marcinwyszynski/cabalist
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project: cabalist
|
61
|
+
rubygems_version: 1.8.5
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Cabalist adds some precognition to your models using machine learning algorithms. It is more or less a simple, easy to use wrapper around Ai4r - Ruby implementation of AI algorithms.
|
65
|
+
test_files: []
|
66
|
+
|