Improving the code
First things first, let's focus on the types. Just by looking at the code, it's not quite clear what we mean every time we use List<Float64>
. Sometimes, it means the "inputs vector," and sometimes the "weights vector." It would be much more readable if we had a custom type definition that would speak for itself. Let's create two additional types:
typedef WeightsVector = List<Float64>; typedef InputsVector = List<Float64>;
As you can see, they are both the same, but they serve for better readability. Let's apply this change in the code. The weights vector is used in the Perceptron
entity, the train
function, and both entrypoint functions. Look at the following examples to see how they change.
In the Perceptron
entity, we must change the field weights
definition to look like this:
field weights: WeightsVector;
Here, we have replaced the List<Int>
type with the WeightsVector
one.
Another...