17.1 Multivariable functions in code
It’s been a long time since we put theory into code. So, let’s take a look at multivariable functions!
Last time, we built a Function base class with two main methods: one for computing the derivative (Function.prime) and one for getting the dictionary of parameters (Function.parameters).
This won’t be much of a surprise: the multivariate function base class is not much different. For clarity, we’ll appropriately rename the prime method to grad.
class MultivariableFunction:
def __init__(self):
pass
def __call__(self, *args, **kwargs):
pass
def grad(self):
pass
def parameters(self):
return dict()
Let’s see a few examples right away. The simplest one is the squared Euclidean norm f(x) = ∥x∥2, a close relative to the mean squared error function. Its gradient is given by
thus everything is ready to implement it. As we’ve used...