cleaned up FeedForward class to pass test

isaac
yelircaasi 5 years ago
parent 49dec048c8
commit 69f913c801

@ -24,6 +24,7 @@ class FeedForward(torch.nn.Module):
self.fc2 = torch.nn.Linear(self.hidden_size, self.output_size) self.fc2 = torch.nn.Linear(self.hidden_size, self.output_size)
self.sigmoid = torch.nn.Sigmoid() self.sigmoid = torch.nn.Sigmoid()
self.softmax = torch.nn.Softmax(dim=1) self.softmax = torch.nn.Softmax(dim=1)
self.read_data()
def forward(self, x): def forward(self, x):
""" Computes output from a given input x. """ """ Computes output from a given input x. """
@ -35,7 +36,8 @@ class FeedForward(torch.nn.Module):
def read_data(self): def read_data(self):
"""" Reads in training and test data and converts it to proper format. """ """" Reads in training and test data and converts it to proper format. """
self.X_train_, self.y_train_, self.X_test_ = read_csv_nn() self.X_train_, self.y_train_, self.X_test = read_csv_nn()
self.X_test = torch.FloatTensor(self.X_test)
yclass = np.array([(x[1] == 1) + 2 * (x[2] == 1) for x in self.y_train_]) yclass = np.array([(x[1] == 1) + 2 * (x[2] == 1) for x in self.y_train_])
is0 = yclass == 0 is0 = yclass == 0
is1 = yclass == 1 is1 = yclass == 1
@ -118,7 +120,7 @@ class FeedForward(torch.nn.Module):
p0 = torch.randperm(self.l0) p0 = torch.randperm(self.l0)
p1 = torch.randperm(self.l1) p1 = torch.randperm(self.l1)
p2 = torch.randperm(self.l2) p2 = torch.randperm(self.l2)
n = self.l0 + self.l1 + self.l2 n = self.samples0 + self.samples1 + self.samples2
p = torch.randperm(n) p = torch.randperm(n)
# sample and shuffle data # sample and shuffle data

@ -1,3 +1,6 @@
import sys
import os
sys.path.append(os.getcwd())
from classifier.nn_ff import FeedForward from classifier.nn_ff import FeedForward

Loading…
Cancel
Save