arow 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/arow.gemspec +19 -0
- data/lib/arow.rb +50 -0
- data/lib/arow/version.rb +3 -0
- metadata +53 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
arow: A pure ruby implementation of the AROW
|
2
|
+
============================================
|
3
|
+
|
4
|
+
|
5
|
+
Installation
|
6
|
+
------------
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'arow'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install arow
|
19
|
+
|
20
|
+
|
21
|
+
Usage
|
22
|
+
-----
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
|
27
|
+
References
|
28
|
+
----------
|
29
|
+
|
30
|
+
- Java implementation http://d.hatena.ne.jp/tsubosaka/20091225/1261747441
|
31
|
+
- C++ implementation http://code.google.com/p/arowpp/
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/arow.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'arow/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "arow"
|
8
|
+
gem.version = AROW::VERSION
|
9
|
+
gem.authors = ["KOMIYA Atsushi"]
|
10
|
+
gem.email = ["komiya.atsushi@gmail.com"]
|
11
|
+
gem.description = %q{A pure ruby implementation of the AROW}
|
12
|
+
gem.summary = %q{A pure ruby implementation of the AROW}
|
13
|
+
gem.homepage = "http://k11i.biz/"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
data/lib/arow.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "arow/version"
|
2
|
+
|
3
|
+
module AROW
|
4
|
+
class Model
|
5
|
+
def initialize(num_features, r = 0.1)
|
6
|
+
@num_features = num_features
|
7
|
+
@r = r
|
8
|
+
|
9
|
+
@means = Array.new(num_features, 0.0)
|
10
|
+
@covariances = Array.new(num_features, 1.0)
|
11
|
+
end
|
12
|
+
|
13
|
+
def margin(features)
|
14
|
+
result = 0.0
|
15
|
+
|
16
|
+
features.each do |index, value|
|
17
|
+
result += @means[index] * value
|
18
|
+
end
|
19
|
+
|
20
|
+
return result
|
21
|
+
end
|
22
|
+
|
23
|
+
def predict(features)
|
24
|
+
return margin(features) > 0
|
25
|
+
end
|
26
|
+
|
27
|
+
def update(features, label)
|
28
|
+
margin = margin(features)
|
29
|
+
label_value = label ? 1 : -1;
|
30
|
+
|
31
|
+
return false if label_value * margin >= 1
|
32
|
+
|
33
|
+
confidence = 0.0
|
34
|
+
features.each do |index, value|
|
35
|
+
confidence += @covariances[index] * value * value
|
36
|
+
end
|
37
|
+
|
38
|
+
beta = 1.0 / (confidence + @r)
|
39
|
+
alpha = label_value * (1.0 - label_value * margin) * beta
|
40
|
+
|
41
|
+
features.each do |index, value|
|
42
|
+
v = @covariances[index] * value
|
43
|
+
@means[index] += alpha * v
|
44
|
+
@covariances[index] -= beta * v * v
|
45
|
+
end
|
46
|
+
|
47
|
+
return true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/arow/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- KOMIYA Atsushi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-13 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A pure ruby implementation of the AROW
|
15
|
+
email:
|
16
|
+
- komiya.atsushi@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- arow.gemspec
|
27
|
+
- lib/arow.rb
|
28
|
+
- lib/arow/version.rb
|
29
|
+
homepage: http://k11i.biz/
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.24
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: A pure ruby implementation of the AROW
|
53
|
+
test_files: []
|