Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from serialhex/master
merging final batch of ruby examples
- Loading branch information
Showing
24 changed files
with
275 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'narray' | ||
require 'pp' | ||
x = Modshogun::RealFeatures.new | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'narray' | ||
x = Modshogun::Labels.new | ||
y = [1, 3, 5, 7] | ||
|
35 changes: 35 additions & 0 deletions
35
examples/undocumented/ruby_modular/classifier_custom_kernel_modular.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# this was trancekoded by the awesome trancekoder | ||
# ...and fixifikated by the awesum fixifikator | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'pp' | ||
|
||
parameter_list = [[1,7],[2,8]] | ||
|
||
def classifier_custom_kernel_modular(c=1,dim=7) | ||
|
||
Modshogun::Math.init_random(c) | ||
|
||
lab = (2*NArray.float(dim).random! - 1).sign | ||
data= NMatrix.float(dim, dim).random! | ||
symdata=data*data.transpose + NMatrix.float(dim,dim).unit | ||
|
||
kernel=Modshogun::CustomKernel.new | ||
kernel.set_full_kernel_matrix_from_full(data) | ||
# *** labels=Labels(lab) | ||
labels=Modshogun::Labels.new(lab) | ||
# labels.set_features(lab) | ||
# *** svm=LibSVM(c, kernel, labels) | ||
svm=Modshogun::LibSVM.new(c, kernel, labels) | ||
# svm.set_features(c, kernel, labels) | ||
svm.train() | ||
predictions =svm.apply() | ||
out=svm.apply().get_labels() | ||
return svm,out | ||
|
||
end | ||
|
||
if __FILE__ == $0 | ||
puts 'custom_kernel' | ||
pp classifier_custom_kernel_modular(*parameter_list[0]) | ||
end |
54 changes: 27 additions & 27 deletions
54
examples/undocumented/ruby_modular/classifier_libsvm_minimal_modular.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'narray' | ||
require 'load' | ||
|
||
@num = 1000 | ||
@dist = 1 | ||
@width = 2.1 | ||
C = 1 | ||
|
||
#puts "generating training data" | ||
#traindata_real = gen_rand_ary(@num, @dist) | ||
#testdata_real = gen_rand_ary(@num, @dist) | ||
# | ||
#puts "generating labels" | ||
#trainlab = gen_labels_vec(@num) | ||
#testlab = gen_labels_vec(@num) | ||
# | ||
#puts "doing feature stuff" | ||
#feats_train = Modshogun::RealFeatures.new | ||
#feats_train.set_feature_matrix traindata_real | ||
#feats_test = Modshogun::RealFeatures.new | ||
#feats_test.set_feature_matrix testdata_real | ||
#kernel = Modshogun::GaussianKernel.new feats_train, feats_train, @width | ||
# | ||
#puts "labeling stuff" | ||
#labels = Modshogun::Labels.new | ||
#labels.set_labels trainlab | ||
#svm = Modshogun::LibSVM.new C, kernel, labels | ||
#svm.train | ||
# | ||
#puts "the grand finale" | ||
#kernel.init feats_train, feats_test | ||
#out = svm.apply.get_labels | ||
#testerr = mean out.sign.eql_items? testlab | ||
#puts testerr | ||
puts "generating training data" | ||
traindata_real = gen_rand_ary @num | ||
testdata_real = gen_rand_ary @num | ||
|
||
puts "generating labels" | ||
trainlab = gen_ones_vec @num | ||
testlab = gen_ones_vec @num | ||
|
||
puts "doing feature stuff" | ||
feats_train = Modshogun::RealFeatures.new | ||
feats_train.set_feature_matrix traindata_real | ||
feats_test = Modshogun::RealFeatures.new | ||
feats_test.set_feature_matrix testdata_real | ||
kernel = Modshogun::GaussianKernel.new feats_train, feats_train, @width | ||
|
||
puts "labeling stuff" | ||
labels = Modshogun::Labels.new | ||
labels.set_labels trainlab | ||
svm = Modshogun::LibSVM.new C, kernel, labels | ||
svm.train | ||
|
||
puts "the grand finale" | ||
kernel.init feats_train, feats_test | ||
out = svm.apply.get_labels | ||
testerr = mean out.sign.eql_items? testlab | ||
puts testerr |
1 change: 1 addition & 0 deletions
1
examples/undocumented/ruby_modular/clustering_hierarchical_modular.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'pp' | ||
require 'load' | ||
|
||
|
1 change: 1 addition & 0 deletions
1
examples/undocumented/ruby_modular/distance_braycurtis_modular.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'pp' | ||
require 'load' | ||
|
||
|
1 change: 1 addition & 0 deletions
1
examples/undocumented/ruby_modular/distance_canberra_modular.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'pp' | ||
require 'load' | ||
|
||
|
1 change: 1 addition & 0 deletions
1
examples/undocumented/ruby_modular/distribution_histogram_modular.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'pp' | ||
require 'load' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
examples/undocumented/ruby_modular/features_read_svmlight_format_modular.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'pp' | ||
parameter_list=[['../data/train_sparsereal.light']] | ||
|
||
|
1 change: 1 addition & 0 deletions
1
examples/undocumented/ruby_modular/features_string_char_modular.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'pp' | ||
|
||
strings=['hey','guys','i','am','a','string'] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'pp' | ||
require 'load' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'pp' | ||
require 'load' | ||
|
||
|
1 change: 1 addition & 0 deletions
1
examples/undocumented/ruby_modular/kernel_combined_custom_poly_modular.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
require 'narray' | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'load' | ||
require 'pp' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
gk=Modshogun::GaussianKernel.new() | ||
puts gk.get_width() |
1 change: 1 addition & 0 deletions
1
examples/undocumented/ruby_modular/modelselection_parameter_tree_modular.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'pp' | ||
|
||
# | ||
|
1 change: 1 addition & 0 deletions
1
examples/undocumented/ruby_modular/preprocessor_hessianlocallylinearembedding_modular.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'pp' | ||
require 'load' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
examples/undocumented/ruby_modular/regression_libsvr_modular.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'modshogun' | ||
require 'shogun_helpers' | ||
require 'pp' | ||
require 'load' | ||
|
||
|
Oops, something went wrong.