Just like any class in Python, you can also define custom method on PyTorch modules
(self)
| 35 | return self.a + self.b * x + self.c * x ** 2 + self.d * x ** 3 |
| 36 | |
| 37 | def string(self): |
| 38 | """ |
| 39 | Just like any class in Python, you can also define custom method on PyTorch modules |
| 40 | """ |
| 41 | return f'y = {self.a.item()} + {self.b.item()} x + {self.c.item()} x^2 + {self.d.item()} x^3' |
| 42 | |
| 43 | |
| 44 | # Create Tensors to hold input and outputs. |