bors 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/Gemfile +30 -0
- data/Gemfile.lock +57 -0
- data/LICENSE.txt +20 -0
- data/README.md +26 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/bors.gemspec +87 -0
- data/lib/bors/example/feature.rb +36 -0
- data/lib/bors/example.rb +74 -0
- data/lib/bors/exceptions.rb +13 -0
- data/lib/bors/maths.rb +9 -0
- data/lib/bors/model.rb +82 -0
- data/lib/bors/prediction/result.rb +19 -0
- data/lib/bors/prediction.rb +17 -0
- data/lib/bors.rb +67 -0
- data/spec/bors/example/feature.rb +29 -0
- data/spec/bors/example.rb +68 -0
- data/spec/bors.rb +64 -0
- data/spec/runner.rb +3 -0
- data/spec/spec_helper.rb +8 -0
- metadata +231 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'oj'
|
4
|
+
#gem 'rake'
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem "shoulda", ">= 0"
|
8
|
+
gem "rdoc", "~> 3.12"
|
9
|
+
gem "jeweler", "~> 1.8.4"
|
10
|
+
gem "bundler"
|
11
|
+
end
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem 'rspec'
|
15
|
+
end
|
16
|
+
|
17
|
+
source "http://rubygems.org"
|
18
|
+
# Add dependencies required to use your gem here.
|
19
|
+
# Example:
|
20
|
+
# gem "activesupport", ">= 2.3.5"
|
21
|
+
|
22
|
+
# Add dependencies to develop your gem here.
|
23
|
+
# Include everything needed to run rake, tests, features, etc.
|
24
|
+
group :development do
|
25
|
+
gem "shoulda", ">= 0"
|
26
|
+
gem "rdoc", "~> 3.12"
|
27
|
+
gem "bundler"
|
28
|
+
gem "jeweler", "~> 1.8.4"
|
29
|
+
gem "simplecov"
|
30
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
remote: http://rubygems.org/
|
4
|
+
specs:
|
5
|
+
activesupport (3.2.9)
|
6
|
+
i18n (~> 0.6)
|
7
|
+
multi_json (~> 1.0)
|
8
|
+
bourne (1.1.2)
|
9
|
+
mocha (= 0.10.5)
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
git (1.2.5)
|
12
|
+
i18n (0.6.1)
|
13
|
+
jeweler (1.8.4)
|
14
|
+
bundler (~> 1.0)
|
15
|
+
git (>= 1.2.5)
|
16
|
+
rake
|
17
|
+
rdoc
|
18
|
+
json (1.7.5)
|
19
|
+
metaclass (0.0.1)
|
20
|
+
mocha (0.10.5)
|
21
|
+
metaclass (~> 0.0.1)
|
22
|
+
multi_json (1.5.0)
|
23
|
+
oj (2.0.0)
|
24
|
+
rake (10.0.3)
|
25
|
+
rdoc (3.12)
|
26
|
+
json (~> 1.4)
|
27
|
+
rspec (2.12.0)
|
28
|
+
rspec-core (~> 2.12.0)
|
29
|
+
rspec-expectations (~> 2.12.0)
|
30
|
+
rspec-mocks (~> 2.12.0)
|
31
|
+
rspec-core (2.12.2)
|
32
|
+
rspec-expectations (2.12.1)
|
33
|
+
diff-lcs (~> 1.1.3)
|
34
|
+
rspec-mocks (2.12.1)
|
35
|
+
shoulda (3.3.2)
|
36
|
+
shoulda-context (~> 1.0.1)
|
37
|
+
shoulda-matchers (~> 1.4.1)
|
38
|
+
shoulda-context (1.0.2)
|
39
|
+
shoulda-matchers (1.4.2)
|
40
|
+
activesupport (>= 3.0.0)
|
41
|
+
bourne (~> 1.1.2)
|
42
|
+
simplecov (0.7.1)
|
43
|
+
multi_json (~> 1.0)
|
44
|
+
simplecov-html (~> 0.7.1)
|
45
|
+
simplecov-html (0.7.1)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
bundler
|
52
|
+
jeweler (~> 1.8.4)
|
53
|
+
oj
|
54
|
+
rdoc (~> 3.12)
|
55
|
+
rspec
|
56
|
+
shoulda
|
57
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Sam Richardson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Bors
|
2
|
+
|
3
|
+
> "One rabbit stew coming right up!"
|
4
|
+
|
5
|
+
Bors is a wrapper for the Vowpal Wabbit library by John Langford. It consists of a wrapper around the command line making it easy to interface to it via Ruby.
|
6
|
+
|
7
|
+
NO QUITE FINSHED YET. USE AT YOUR OWN RISK!
|
8
|
+
|
9
|
+
You can read more about Vowpal Wabbit here: http://hunch.net/~vw/
|
10
|
+
|
11
|
+
## Using the library
|
12
|
+
|
13
|
+
## Contributing to bors
|
14
|
+
|
15
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
16
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
17
|
+
* Fork the project.
|
18
|
+
* Start a feature/bugfix branch.
|
19
|
+
* Commit and push until you are happy with your contribution.
|
20
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
21
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
22
|
+
|
23
|
+
## Copyright
|
24
|
+
|
25
|
+
Copyright (c) 2012 Sam Richardson. See LICENSE.txt for
|
26
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "bors"
|
18
|
+
gem.homepage = "http://github.com/rodeoclash/bors"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Wrapper for the Vowpal Wabbit library}
|
21
|
+
gem.description = %Q{Wrapper for the Vowpal Wabbit library}
|
22
|
+
gem.email = "sam@richardson.co.nz"
|
23
|
+
gem.authors = ["Sam Richardson"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :test
|
36
|
+
|
37
|
+
require 'rdoc/task'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "bors #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/bors.gemspec
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "bors"
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Sam Richardson"]
|
12
|
+
s.date = "2013-01-13"
|
13
|
+
s.description = "Wrapper for the Vowpal Wabbit library"
|
14
|
+
s.email = "sam@richardson.co.nz"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"bors.gemspec",
|
28
|
+
"lib/bors.rb",
|
29
|
+
"lib/bors/example.rb",
|
30
|
+
"lib/bors/example/feature.rb",
|
31
|
+
"lib/bors/exceptions.rb",
|
32
|
+
"lib/bors/maths.rb",
|
33
|
+
"lib/bors/model.rb",
|
34
|
+
"lib/bors/prediction.rb",
|
35
|
+
"lib/bors/prediction/result.rb",
|
36
|
+
"spec/bors.rb",
|
37
|
+
"spec/bors/example.rb",
|
38
|
+
"spec/bors/example/feature.rb",
|
39
|
+
"spec/runner.rb",
|
40
|
+
"spec/spec_helper.rb"
|
41
|
+
]
|
42
|
+
s.homepage = "http://github.com/rodeoclash/bors"
|
43
|
+
s.licenses = ["MIT"]
|
44
|
+
s.require_paths = ["lib"]
|
45
|
+
s.rubygems_version = "1.8.23"
|
46
|
+
s.summary = "Wrapper for the Vowpal Wabbit library"
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_runtime_dependency(%q<oj>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
56
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
59
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
61
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<oj>, [">= 0"])
|
64
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
67
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
68
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
70
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
72
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
73
|
+
end
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<oj>, [">= 0"])
|
76
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
77
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
78
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
79
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
80
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
81
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
82
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
83
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
84
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative "../exceptions"
|
2
|
+
require_relative "../maths"
|
3
|
+
|
4
|
+
class Bors
|
5
|
+
class Example
|
6
|
+
class Feature
|
7
|
+
include Maths
|
8
|
+
|
9
|
+
def initialize(value)
|
10
|
+
@value = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
returning = ""
|
15
|
+
|
16
|
+
if @value.kind_of?(String)
|
17
|
+
returning += @value
|
18
|
+
else
|
19
|
+
@value.each do |key, value|
|
20
|
+
raise Exceptions::NotRealNumber.new unless is_real_number?(value)
|
21
|
+
if key.to_s.match(/\s/)
|
22
|
+
key.split(/\s/).each do |word|
|
23
|
+
returning += "#{word}:#{value} "
|
24
|
+
end
|
25
|
+
else
|
26
|
+
returning += "#{key}:#{value} "
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
returning.strip
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/bors/example.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require_relative "exceptions"
|
2
|
+
require_relative "maths"
|
3
|
+
require_relative "example/feature"
|
4
|
+
|
5
|
+
class Bors
|
6
|
+
class Example
|
7
|
+
include Maths
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"#{label} #{importance} #{initial_prediction} #{tag}#{namespaces}".squeeze(' ')
|
15
|
+
end
|
16
|
+
|
17
|
+
def label
|
18
|
+
return_options_key_if_valid_real_number :label
|
19
|
+
end
|
20
|
+
|
21
|
+
def importance
|
22
|
+
return_options_key_if_valid_real_number :importance
|
23
|
+
end
|
24
|
+
|
25
|
+
def initial_prediction
|
26
|
+
return_options_key_if_valid_real_number :initial_prediction
|
27
|
+
end
|
28
|
+
|
29
|
+
def tag
|
30
|
+
if @options[:tag]
|
31
|
+
raise Exceptions::ArgumentError.new('Tag must not contain spaces') unless @options[:tag].to_s.match(/\s/).nil?
|
32
|
+
raise Exceptions::ArgumentError.new('Tag must be A-z-0-9') unless @options[:tag].to_s.match(/\W/).nil?
|
33
|
+
@options[:tag]
|
34
|
+
else
|
35
|
+
""
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def namespaces
|
40
|
+
raise Exceptions::ArgumentError.new('You must provide at least one namespace') unless @options[:namespaces] && @options[:namespaces].length > 0
|
41
|
+
|
42
|
+
@options[:namespaces].map do |name, options|
|
43
|
+
raise Exceptions::ArgumentError.new('Incorrect format for options, must be a Hash') unless options.kind_of? Hash
|
44
|
+
|
45
|
+
returning = ""
|
46
|
+
returning += "|#{name}"
|
47
|
+
returning += ":#{options[:value]}" if options[:value]
|
48
|
+
|
49
|
+
if options[:features].kind_of? Array
|
50
|
+
options[:features].each do |feature|
|
51
|
+
returning += " #{Feature.new(feature).to_s}"
|
52
|
+
end
|
53
|
+
else
|
54
|
+
returning += " #{Feature.new(options[:features]).to_s}"
|
55
|
+
end
|
56
|
+
|
57
|
+
returning += " "
|
58
|
+
|
59
|
+
end.join.strip
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def return_options_key_if_valid_real_number(key)
|
65
|
+
if @options[key]
|
66
|
+
raise Exceptions::NotRealNumber.new unless is_real_number?(@options[key])
|
67
|
+
@options[key]
|
68
|
+
else
|
69
|
+
""
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
data/lib/bors/maths.rb
ADDED
data/lib/bors/model.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
class Bors
|
2
|
+
class Model
|
3
|
+
|
4
|
+
def initialize(err, out, status)
|
5
|
+
@err = err
|
6
|
+
@out = out
|
7
|
+
@status = status
|
8
|
+
puts @out
|
9
|
+
end
|
10
|
+
|
11
|
+
def settings
|
12
|
+
return @settings unless @settings.nil?
|
13
|
+
@settings = Hash.new
|
14
|
+
@out.each_line do |line|
|
15
|
+
return @settings if line.match('loss')
|
16
|
+
line.match(/\s=\s/) do |m|
|
17
|
+
label, value = split_line(line)
|
18
|
+
@settings[format_label(label)] = format_value(value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def sample
|
24
|
+
return @sample unless @sample.nil?
|
25
|
+
@sample = Array.new
|
26
|
+
found = false
|
27
|
+
@out.each_line do |line|
|
28
|
+
if line.match(/^\n/)
|
29
|
+
return @sample
|
30
|
+
end
|
31
|
+
if line.match('loss')
|
32
|
+
found = true
|
33
|
+
next
|
34
|
+
end
|
35
|
+
if found == true
|
36
|
+
average_loss, since_last, example_counter, example_weight, current_label, current_predict, current_features = line.scan(/\d+\.?\d*/)
|
37
|
+
@sample.push({
|
38
|
+
:average_loss => average_loss,
|
39
|
+
:since_last => since_last,
|
40
|
+
:example_counter => example_counter,
|
41
|
+
:example_weight => example_weight,
|
42
|
+
:current_label => current_label,
|
43
|
+
:current_predict => current_predict,
|
44
|
+
:current_features => current_features
|
45
|
+
})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def results
|
51
|
+
return @settings unless @settings.nil?
|
52
|
+
@settings = Hash.new
|
53
|
+
@out.each_line do |line|
|
54
|
+
if line.match('finished run')
|
55
|
+
found = true
|
56
|
+
next
|
57
|
+
end
|
58
|
+
if found == true
|
59
|
+
line.match(/\s=\s/) do |m|
|
60
|
+
label, value = split_line(line)
|
61
|
+
@settings[format_label(label)] = format_value(value)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def split_line(line)
|
70
|
+
line.split(/\s=\s/)
|
71
|
+
end
|
72
|
+
|
73
|
+
def format_label(label)
|
74
|
+
label.gsub(' ', '_').downcase.to_sym
|
75
|
+
end
|
76
|
+
|
77
|
+
def format_value(value)
|
78
|
+
value.delete("\n")
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
data/lib/bors.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require_relative 'bors/example'
|
2
|
+
require_relative 'bors/model'
|
3
|
+
require_relative 'bors/prediction'
|
4
|
+
require 'open3'
|
5
|
+
require 'tempfile'
|
6
|
+
|
7
|
+
class Bors
|
8
|
+
|
9
|
+
attr_reader :examples
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
@examples = Tempfile.new('bors')
|
13
|
+
@example_count = 0
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_example(details)
|
18
|
+
begin
|
19
|
+
@examples.write("#{Example.new(details).to_s}\n")
|
20
|
+
@example_count += 1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# returns an example from the file
|
25
|
+
def get_example(at)
|
26
|
+
get_line_from_file(@examples, at)
|
27
|
+
end
|
28
|
+
|
29
|
+
# load examples from path, should automatically detect a cache file and use that instead
|
30
|
+
def load_examples(path)
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
# outputs examples to the specified file
|
35
|
+
def save_examples(path)
|
36
|
+
raise Exceptions::MissingExamples.new unless @examples.length > 0
|
37
|
+
# should copy tempfile to path then automatically reload it
|
38
|
+
end
|
39
|
+
|
40
|
+
# creates a training model from the loaded examples
|
41
|
+
def model(path)
|
42
|
+
raise Exceptions::MissingExamples.new unless @examples.length > 0
|
43
|
+
err, out, status = Open3.capture3("vw #{@examples.path} -c --passes 30 -b 25 --invariant -l 10 --loss_function logistic --exact_adaptive_norm -f #{path}.model")
|
44
|
+
Model.new(err, out, status)
|
45
|
+
end
|
46
|
+
|
47
|
+
# predict using a model and the loaded exampels
|
48
|
+
def predict(model_path)
|
49
|
+
raise Exceptions::MissingExamples.new unless @examples.length > 0
|
50
|
+
out, err, status = Open3.capture3("vw -i #{model_path} -t #{@examples.path} -p /dev/stdout --quiet")
|
51
|
+
Prediction.new(out)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def get_line_from_file(path, line)
|
57
|
+
result = nil
|
58
|
+
File.open(path, "r") do |f|
|
59
|
+
while line > 0
|
60
|
+
line -= 1
|
61
|
+
result = f.gets
|
62
|
+
end
|
63
|
+
end
|
64
|
+
return result
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative "../../spec_helper"
|
2
|
+
|
3
|
+
module Indus
|
4
|
+
|
5
|
+
describe Bors::Example::Feature do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to create a Feature object" do
|
11
|
+
expect { Bors::Example::Feature.new("") }.to_not raise_error
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return the feature if given as a string" do
|
15
|
+
Bors::Example::Feature.new("Sam").to_s.should be == "Sam"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should correctly split features defined as a hash" do
|
19
|
+
Bors::Example::Feature.new({"Sam" => 1.1}).to_s.should be == "Sam:1.1"
|
20
|
+
Bors::Example::Feature.new({:test => 1}).to_s.should be == "test:1"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should raise an error when defining a feature with a non real number weight" do
|
24
|
+
expect { Bors::Example::Feature.new({:test => -1}).to_s }.to raise_error Bors::Exceptions::NotRealNumber
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
|
3
|
+
module Indus
|
4
|
+
|
5
|
+
describe Bors::Example do
|
6
|
+
|
7
|
+
it "should be able to create a new item without errors when given options" do
|
8
|
+
expect { Bors::Example.new({}) }.to_not raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should allow you to define a label for the object" do
|
12
|
+
Bors::Example.new({ :label => 1 }).label.should == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should raise an error when trying to define an invalid label" do
|
16
|
+
expect { Bors::Example.new({ :label => "invalid" }).label }.to raise_error Bors::Exceptions::NotRealNumber
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should allow you to define an importance for the object" do
|
20
|
+
Bors::Example.new({ :importance => 1.0 }).importance.should == 1.0
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should raise an error when trying to define an invalid importance" do
|
24
|
+
expect { Bors::Example.new({ :importance => -1 }).importance }.to raise_error Bors::Exceptions::NotRealNumber
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should allow you to define an initial prediction for the object" do
|
28
|
+
Bors::Example.new({ :initial_prediction => 1 }).initial_prediction.should == 1
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should raise an error when trying to define an invalid initial_prediction" do
|
32
|
+
expect { Bors::Example.new({ :importance => "invalid" }).importance }.to raise_error Bors::Exceptions::NotRealNumber
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should allow you to define a tag for the object" do
|
36
|
+
Bors::Example.new({ :tag => "Sam" }).tag.should == "Sam"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should raise an error when trying to a tag which contains spaces" do
|
40
|
+
expect { Bors::Example.new({ :tag => "No spaces" }).tag }.to raise_error Bors::Exceptions::ArgumentError
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should raise an error when trying to a tag which contains invalid characters" do
|
44
|
+
expect { Bors::Example.new({ :tag => "nospecial?*" }).tag }.to raise_error Bors::Exceptions::ArgumentError
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should allow you to define a namespace" do
|
48
|
+
Bors::Example.new({ :namespaces => {
|
49
|
+
"Diet" => {
|
50
|
+
:value => 2,
|
51
|
+
:features => [
|
52
|
+
"Other small animals"
|
53
|
+
]
|
54
|
+
},
|
55
|
+
"Description" => {
|
56
|
+
:value => 16,
|
57
|
+
:features => [
|
58
|
+
{"Legs" => 4},
|
59
|
+
{"Horns" => 2}
|
60
|
+
]
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}).namespaces.should == "|Diet:2 Other small animals |Description:16 Legs:4 Horns:2"
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/spec/bors.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
module Indus
|
4
|
+
|
5
|
+
describe Bors do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to create a Bors object" do
|
11
|
+
expect { Bors.new }.to_not raise_error
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be able to add an example to the Bors object with full options" do
|
15
|
+
bors = Bors.new
|
16
|
+
bors.add_example({
|
17
|
+
:label => 0,
|
18
|
+
:initial_prediction => 0.5,
|
19
|
+
:importance => 1,
|
20
|
+
:tag => "second_house",
|
21
|
+
|
22
|
+
# required to have at least 1
|
23
|
+
:namespaces => {
|
24
|
+
|
25
|
+
"Animal" => {
|
26
|
+
:value => 1,
|
27
|
+
:features => [
|
28
|
+
"Any plain old text in here",
|
29
|
+
"or",
|
30
|
+
"single",
|
31
|
+
"string",
|
32
|
+
{"NumberOfLegs with spaces in it" => 1.0},
|
33
|
+
{"Size" => 2.0, "Weird Setup" => 1.5}
|
34
|
+
]
|
35
|
+
},
|
36
|
+
|
37
|
+
"Diet" => {
|
38
|
+
:value => 2,
|
39
|
+
:features => [
|
40
|
+
"Other small animals"
|
41
|
+
]
|
42
|
+
}
|
43
|
+
|
44
|
+
}
|
45
|
+
})
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should be possible to omit items that are not required" do
|
49
|
+
bors = Bors.new
|
50
|
+
bors.add_example({
|
51
|
+
|
52
|
+
# real number we're trying to predict
|
53
|
+
:label => 1,
|
54
|
+
|
55
|
+
# required to have at least 1
|
56
|
+
:namespaces => {
|
57
|
+
"text" => { :features => "Some basic string" }
|
58
|
+
}
|
59
|
+
})
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/spec/runner.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,231 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sam Richardson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: oj
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: shoulda
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rdoc
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.12'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.4
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.4
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: shoulda
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rdoc
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.12'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '3.12'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: bundler
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: jeweler
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ~>
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 1.8.4
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ~>
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: 1.8.4
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: simplecov
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
description: Wrapper for the Vowpal Wabbit library
|
175
|
+
email: sam@richardson.co.nz
|
176
|
+
executables: []
|
177
|
+
extensions: []
|
178
|
+
extra_rdoc_files:
|
179
|
+
- LICENSE.txt
|
180
|
+
- README.md
|
181
|
+
files:
|
182
|
+
- .document
|
183
|
+
- Gemfile
|
184
|
+
- Gemfile.lock
|
185
|
+
- LICENSE.txt
|
186
|
+
- README.md
|
187
|
+
- Rakefile
|
188
|
+
- VERSION
|
189
|
+
- bors.gemspec
|
190
|
+
- lib/bors.rb
|
191
|
+
- lib/bors/example.rb
|
192
|
+
- lib/bors/example/feature.rb
|
193
|
+
- lib/bors/exceptions.rb
|
194
|
+
- lib/bors/maths.rb
|
195
|
+
- lib/bors/model.rb
|
196
|
+
- lib/bors/prediction.rb
|
197
|
+
- lib/bors/prediction/result.rb
|
198
|
+
- spec/bors.rb
|
199
|
+
- spec/bors/example.rb
|
200
|
+
- spec/bors/example/feature.rb
|
201
|
+
- spec/runner.rb
|
202
|
+
- spec/spec_helper.rb
|
203
|
+
homepage: http://github.com/rodeoclash/bors
|
204
|
+
licenses:
|
205
|
+
- MIT
|
206
|
+
post_install_message:
|
207
|
+
rdoc_options: []
|
208
|
+
require_paths:
|
209
|
+
- lib
|
210
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
211
|
+
none: false
|
212
|
+
requirements:
|
213
|
+
- - ! '>='
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
segments:
|
217
|
+
- 0
|
218
|
+
hash: 2511003888972238038
|
219
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
220
|
+
none: false
|
221
|
+
requirements:
|
222
|
+
- - ! '>='
|
223
|
+
- !ruby/object:Gem::Version
|
224
|
+
version: '0'
|
225
|
+
requirements: []
|
226
|
+
rubyforge_project:
|
227
|
+
rubygems_version: 1.8.23
|
228
|
+
signing_key:
|
229
|
+
specification_version: 3
|
230
|
+
summary: Wrapper for the Vowpal Wabbit library
|
231
|
+
test_files: []
|