diff --git a/__pycache__/backend.cpython-37.pyc b/__pycache__/backend.cpython-37.pyc index 41042d9..9898e44 100644 Binary files a/__pycache__/backend.cpython-37.pyc and b/__pycache__/backend.cpython-37.pyc differ diff --git a/__pycache__/models.cpython-37.pyc b/__pycache__/models.cpython-37.pyc new file mode 100644 index 0000000..1f9ab0a Binary files /dev/null and b/__pycache__/models.cpython-37.pyc differ diff --git a/models.py b/models.py index f4fde16..1378860 100644 --- a/models.py +++ b/models.py @@ -30,6 +30,7 @@ class PerceptronModel(object): Returns: a node containing a single number (the score) """ "*** YOUR CODE HERE ***" + return nn.DotProduct(x, self.w) def get_prediction(self, x): """ @@ -38,12 +39,22 @@ class PerceptronModel(object): Returns: 1 or -1 """ "*** YOUR CODE HERE ***" + result = nn.as_scalar(nn.DotProduct(x, self.w)) + if (result >= 0): + return 1 + return -1 def train(self, dataset): """ Train the perceptron until convergence. """ "*** YOUR CODE HERE ***" + batch_size = 1 + for x, y in dataset.iterate_once(batch_size): + print(x) + print(y) + result_y = self.run(x) + self.w.update(y, .2) class RegressionModel(object): @@ -82,7 +93,7 @@ class RegressionModel(object): A node with shape (batch_size x 1) containing predicted y-values """ "*** YOUR CODE HERE ***" - self.graph = nn.Graph( + self.graph = nn.DataNode( [self.w1, self.w2, self.w3, self.b1, self.b2, self.b3]) if y is not None: @@ -91,8 +102,8 @@ class RegressionModel(object): # that the node belongs to. The loss node must be the last node # added to the graph. "*** YOUR CODE HERE ***" - input_x = nn.Input(self.graph, x) - input_y = nn.Input(self.graph, y) + input_x = nn.Constant(x) + input_y = nn.Constant(y) xw1 = nn.MatrixMultiply(self.graph, input_x, self.w1) xw1_plus_b1 = nn.MatrixVectorAdd(self.graph, xw1, self.b1) l1 = nn.ReLU(self.graph, xw1_plus_b1)