I'd like to propose a different kind of golfing challenge to this community:
(Artificial) Neural Networks are very popular machine learning models that can be designed and trained to approximate any given (usually unknown) function. They're often used to solve highly complex problems that we don't know how to solve algorithmically like speech recognition, certain kinds of image classifications, various tasks in autonomous driving systems, ... For a primer on neural networks, consider this excellent Wikipedia article.
As this is the first in what I hope to be a series of machine learning golf challenges, I'd like to keep things as simple as possible:
In the language and framework of your choice, design and train a neural network that, given \$(x_1, x_2)\$ calculates their product \$x_1 \cdot x_2\$ for all integers \$x_1, x_2\$ between (and including) \$-10\$ and \$10\$.
Performance Goal
To qualify, your model may not deviate by more than \$0.5\$ from the correct result on any of those entries.
Rules
Your model
- must be a 'traditional' neural network (a node's value is calculated as a weighted linear combination of some of the nodes in a previous layer followed by an activation function),
- may only use the following standard activation functions:
- \$\textrm{linear}(x) = x\$,
- \$\textrm{softmax}(\vec{x})_i = \frac{e^{x_i}}{\sum_j e^{x_j}}\$,
- \$\textrm{selu}_{\alpha, \beta}(x) = \begin{cases} \beta \cdot x & \text{, if } x > 0 \\ \alpha \cdot \beta (e^x -1 ) & \text{, otherwise} \end{cases}\$,
- \$\textrm{softplus}(x) = \ln(e^x+1)\$,
- \$\textrm{leaky-relu}_\alpha(x) = \begin{cases} x & \text{, if } x < 0 \\ \alpha \cdot x & \text{, otherwise} \end{cases}\$,
- \$\tanh(x)\$,
- \$\textrm{sigmoid}(x) = \frac{e^x}{e^x+1}\$,
- \$\textrm{hard-sigmoid}(x) = \begin{cases} 0 & \text{, if } x < -2.5 \\ 1 & \text{, if } x > 2.5 \\ 0.2 \cdot x + 0.5 & \text{, otherwise} \end{cases}\$,
- \$e^x\$
- must take \$(x_1, x_2)\$ either as a tupel/vector/list/... of integers or floats as its only input,
- return the answer as an integer, float (or a suitable container, e.g. a vector or list, that contains this answer).
Your answer must include (or link to) all code necessary to check your results -- including the trained weights of your model.
Scoring
The neural network with the smallest number of weights (including bias weights) wins.
Enjoy!
f(x) = x
to forward its input? \$\endgroup\$