C
Chris Bond
Given a file that looks like so:
7 ==> training Set length
11 ==> file length
1 0 0 0 0 1 0 0
0 1 1 1 0 0 1 0
1 0 1 0 1 0 1 1
1 0 1 1 1 1 1 1
0 0 1 0 1 1 1 1
1 1 0 1 0 1 1 0
0 0 0 1 0 1 0 1
1 1 0 0 1 0 0 1
1 1 0 0 0 0 0 0
0 1 0 1 0 1 1 0
1 1 1 1 1 0 0 0 ==>end of file
#training set #Answer
For now, I need to do this : get the dotProduct of the vector training
set and weight vector, and if that number is > 0 , output 1 ,else output
0. later in the problem I compare that to the answer, but I'm not there
yet. Here is what I have(with tests) to try to get 1 training set to add
up all numbers(without the dotProduct of weights) using IO.readlines,
splitting each line using split, for loops to get an array of integers
to be added together to get output for Perceptron_Bond object named
einstein. coding is as follows
class Perceptron_Bond
attr_reader :weights, utput
attr_writer :weights, utput
def initialize(input, weights)
@weights = weights
@input =input
end
def output
y = @input.inject(0) {|sum, element | sum+element}
@output=y
end
end
str = ARGV[0]
inputs = Array.new
inputs1 = Array.new
inputsNum = Array.new
setArr = Array.new
answers = Array.new
arr = IO.readlines(str)
arr.shift
arr.shift
arr.each { |y| inputs1.push(y.split)}
inputs1.each do|x|
answers.push(x.last)
x.pop
end
for i in 0...inputs1.length
setArr= Array.new
for j in 0...inputs1.length
inputsNum[j] = Array.new
inputsNum[j].push(Integer(inputs1[j]))
if j==(inputs1.length-1) then
inputs = inputsNum
end
end
puts inputs.to_s
end
puts inputs.to_s
puts inputs[2][1].class ==> Array #i want fixnum
initWeights = Array.new(inputs.length) { |index| index =0 }
einstein = Perceptron_Bond.new(inputs[0] , initWeights)
puts einstein.output #should produce fixnum 2
i get an error as well in output telling me I cannot coerce an Array to
a fixnum
Im guessing its stemming from the nested for loops I have, but I am just
stumped
I need help in a bad way, please.
Attachments:
http://www.ruby-forum.com/attachment/524/somefile.rb
7 ==> training Set length
11 ==> file length
1 0 0 0 0 1 0 0
0 1 1 1 0 0 1 0
1 0 1 0 1 0 1 1
1 0 1 1 1 1 1 1
0 0 1 0 1 1 1 1
1 1 0 1 0 1 1 0
0 0 0 1 0 1 0 1
1 1 0 0 1 0 0 1
1 1 0 0 0 0 0 0
0 1 0 1 0 1 1 0
1 1 1 1 1 0 0 0 ==>end of file
#training set #Answer
For now, I need to do this : get the dotProduct of the vector training
set and weight vector, and if that number is > 0 , output 1 ,else output
0. later in the problem I compare that to the answer, but I'm not there
yet. Here is what I have(with tests) to try to get 1 training set to add
up all numbers(without the dotProduct of weights) using IO.readlines,
splitting each line using split, for loops to get an array of integers
to be added together to get output for Perceptron_Bond object named
einstein. coding is as follows
class Perceptron_Bond
attr_reader :weights, utput
attr_writer :weights, utput
def initialize(input, weights)
@weights = weights
@input =input
end
def output
y = @input.inject(0) {|sum, element | sum+element}
@output=y
end
end
str = ARGV[0]
inputs = Array.new
inputs1 = Array.new
inputsNum = Array.new
setArr = Array.new
answers = Array.new
arr = IO.readlines(str)
arr.shift
arr.shift
arr.each { |y| inputs1.push(y.split)}
inputs1.each do|x|
answers.push(x.last)
x.pop
end
for i in 0...inputs1.length
setArr= Array.new
for j in 0...inputs1.length
inputsNum[j] = Array.new
inputsNum[j].push(Integer(inputs1[j]))
if j==(inputs1.length-1) then
inputs = inputsNum
end
end
puts inputs.to_s
end
puts inputs.to_s
puts inputs[2][1].class ==> Array #i want fixnum
initWeights = Array.new(inputs.length) { |index| index =0 }
einstein = Perceptron_Bond.new(inputs[0] , initWeights)
puts einstein.output #should produce fixnum 2
i get an error as well in output telling me I cannot coerce an Array to
a fixnum
Im guessing its stemming from the nested for loops I have, but I am just
stumped
I need help in a bad way, please.
Attachments:
http://www.ruby-forum.com/attachment/524/somefile.rb