【发布时间】:2016-05-10 05:55:11
【问题描述】:
我正在使用 torch7 生成 XOR 门数据集。但是当我打印数据集时,我发现数据是错误的,但我找不到错误。代码似乎没有任何问题。但是我是新手,所以可能会发生错误。
所以,这是我的代码
input = torch.Tensor (4,2)
input:random(0,1)
output = torch.Tensor(1)
dataset={};
function dataset:size() return 4 end
for i=1,dataset:size() do
if input[i][1]==input[i][2] then
output[1] = 0
else
output[1] = 1
end
print("original")
print(input[i][1].." "..input[i][2].." "..output[1]) -- the values that are going to dataset
dataset[i] = {input[i], output}
print("dataset")
print(dataset[i][1][1].." "..dataset[i][1][2].." "..dataset[i][2][1]) -- for double checking i read from dataset again
end
print("Why dataset is different now?")
for i=1,4 do
print(dataset[i][1][1].." "..dataset[i][1][2].." "..dataset[i][2][1]) -- So, why this is different?
end
如您所见,我打印了插入dataset 列表中的值,并再次从dataset 中读取以进行双重检查。
最后我在完全插入后从dataset 检查。数据集以某种方式有所不同。我跑了几次。每次都不一样。就像卡在 1 或 0 上一样。
这是我的输出
original
1 0 1
dataset
1 0 1
original
0 0 0
dataset
0 0 0
original
1 1 0
dataset
1 1 0
original
0 0 0
dataset
0 0 0
Why dataset is different now?
1 0 0
0 0 0
1 1 0
0 0 0
如你所见,格式是这样的
input input output
当我从 input[i] 读取并输出时,我打印了原件。
我在插入后从数据集读取时打印了数据集。
您还可以看到,当我打印时,第一组值是不同的。应该是 1 0 1。但它是 1 0 0。
我在我的代码中找不到错误。任何人都可以帮忙吗?如果问题不清楚,请告诉我。
【问题讨论】:
标签: lua machine-learning neural-network torch luajit