Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. require 'torch' -- torch
  2. require 'optim'
  3. require 'nn' -- provides a normalization operator
  4.  
  5. function string:split(sep)
  6. local sep, fields = sep, {}
  7. local pattern = string.format("([^%s]+)", sep)
  8. self:gsub(pattern, function(substr) fields[#fields + 1] = substr end)
  9. return fields
  10. end
  11.  
  12. local f_file = io.open(arg[1], 'r')
  13. local p_file = io.open(arg[2], 'w')
  14. local data = torch.Tensor(1, 351)
  15. local name = ''
  16. for line in f_file:lines('*l') do
  17. local l = line:split(',')
  18. first = true
  19. for key, val in ipairs(l) do
  20. if first == false then
  21. data[1][key] = val
  22. else data[1][key] = 0
  23. first = false
  24. name = val
  25. end
  26. end
  27. end
  28.  
  29. local X = data[{{},{2,-1}}]
  30. print(X)
  31. model = torch.load('estimation_model.dat')
  32. local myPrediction = model:forward(X)
  33. p_file:write('NAME,F1,F2,F3,F4n')
  34. p_file:write(name..','..tostring(1000*myPrediction[1]
  35. [1])..','..tostring(1000*myPrediction[1]
  36. [2])..','..tostring(1000*myPrediction[1]
  37. [3])..','..tostring(1000*myPrediction[1][4])..'n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement