Skip to content

Instantly share code, notes, and snippets.

@soumith
Created July 3, 2014 15:22
Show Gist options
  • Save soumith/948be97efc9a7a300592 to your computer and use it in GitHub Desktop.
Save soumith/948be97efc9a7a300592 to your computer and use it in GitHub Desktop.
dataset=torch.Tensor{
{742313794,6385273,1362403386,80,169085576,0,1698277100,451,0},
{742313860,6385273,1362403386,80,169085576,0,1698300945,452,0},
{742338872,6385273,167840643,137,169085576,0,1718221933,480,0},
{742338872,6385273,167926801,53,169085576,0,1718222057,471,0},
{742338872,6385273,167846975,8014,169085576,0,1718222380,487,0},
{742338872,641958438357784123396879472047392017641614042483,167846975,8014,169085576,0,1718222453,517,0},
{742338934,6385273,167926801,53,169085576,0,1718273961,472,0},
{742338934,641958438357784123396879472047392017641614042483,167846975,8014,169085576,0,1718275304,519,0},
{742338934,6385273,167840643,137,169085576,0,1718275541,483,0},
{742339456,6385273,1515469714,80,169085576,0,1718710395,451,0},
{742339482,6385273,167846952,389,169085576,0,1718735080,475,0},
{742339482,6385273,167840642,53,169085576,0,1718735132,472,0},
{742339482,6385273,167926801,53,169085576,0,1718735138,471,0},
{742339482,6385273,167840642,389,169085576,0,1718735139,476,0},
{742339482,6385273,167840642,53,169085576,0,1718735141,472,0},
{742339482,6385273,167926801,53,169085576,0,1718735143,471,0},
{742339482,6385273,167840642,389,169085576,0,1718735144,476,0},
{742339482,6385273,167926801,53,169085576,0,1718735186,471,0},
{742339482,6385273,167840642,53,169085576,0,1718735187,472,0},
{742339482,6385273,167840642,389,169085576,0,1718735228,476,0},
{742339482,6385273,167840641,389,169085576,0,1718735229,476,0},
{742339482,6385273,167840643,137,169085576,0,1718735246,480,0},
{742339482,6385273,167840642,53,169085576,0,1718735277,474,0},
{742339482,6385273,167840646,80,169085576,0,1718736072,484,0},
{742339484,6385273,1515469714,80,169085576,0,1718737011,476,0},
}
function distance (vect,taille)
local som= 0
for i=1,taille do
som = som + vect[i]^2
end
return math.sqrt(som)
end
function datadist (dataset)
local distma = {};
--print(dataset:size()[1])
for i = 1,dataset:size()[1] do
distma[i]=distance(dataset[i],dataset:size()[2]);
end
return distma
end
d = {}
for i=1,dataset:size()[1] do
local label = distance(dataset[i],dataset:size(2))
d[i]={dataset[i],torch.Tensor({label})};
end
d.size = function() return dataset:size(1); end
require 'nn'
--exit()
mlp = nn.Sequential();
inputs = 9;output = 1 ;HUs = 2;
mlp:add(nn.Linear(inputs,HUs));
--exit()
mlp:add(nn.Tanh());
mlp:add(nn.Linear(HUs,output))
criterion = nn.MSECriterion()
trainer = nn.StochasticGradient(mlp, criterion)
trainer.learningRate = 0.001
trainer:train(d)
--d = datadist(dataset)
-- print(d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment