Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a 'modshogun.rb' file to do some (ok, eventually a lot) of the …
…ruby start-up stuff, like requiring 'narray' and such. also completed more examples. more examples to come!!
- Loading branch information
Showing
5 changed files
with
97 additions
and
38 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
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
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,70 @@ | ||
require 'narray' | ||
require 'modshogun.so' | ||
|
||
def LoadMatrix(filename, type = :numbers) | ||
case type | ||
when :numbers | ||
x = LoadMatrix.load_numbers(filename) | ||
pp x | ||
when :dna | ||
LoadMatrix.load_dna(filename) | ||
when :cubes | ||
LoadMatrix.load_cubes(filename) | ||
when :labels | ||
LoadMatrix.load_labels(filename) | ||
end | ||
end | ||
|
||
module LoadMatrix | ||
def load_numbers(filename) | ||
matrix = [] | ||
File.open(filename) do |file| | ||
file.each_line do |line| | ||
ary = [] | ||
line.split(" ").each{ |n| ary << n.to_f } | ||
matrix << ary | ||
end | ||
end | ||
#pp matrix | ||
matrix = NArray.to_na(matrix) | ||
#pp matrix | ||
matrix = matrix.transpose(1,0) | ||
#pp matrix | ||
end | ||
|
||
def load_dna(filename) | ||
matrix=[] | ||
File.open(filename) do |file| | ||
file.each_line do |line| | ||
line.split("\n").each{|n| matrix << n } | ||
end | ||
end | ||
matrix | ||
end | ||
|
||
|
||
def load_cubes(filename) | ||
matrix=[] | ||
File.open(filename) do |file| | ||
file.each_line do |line| | ||
line.split("\n").each{|n| matrix << n } | ||
end | ||
end | ||
matrix | ||
end | ||
|
||
|
||
def load_labels(filename) | ||
vector = [] | ||
File.open(filename) do |file| | ||
file.each_line do |line| | ||
vector << line.to_f | ||
end | ||
end | ||
vector = NArray.to_na(vector) | ||
# loading vectors is not yet implemented, | ||
# use a 1D array instead (for now) | ||
#vector = vector.reshape(1, vector.total) | ||
end | ||
extend self | ||
end |