Hi folks, I just started my journey on learning Machine Learning and decided that it would be funnier if I used Elixir.
So I’m following along the Neural Network from Scratch book that implements a NN using just python and NumPy, in my case, Elixir and NX. However, I am having issues now because they have a function that generates some data, but I’m not being able to reproduce it in elixir. Can someone help me with that?
Here is the python code:
import numpy as np
# Copyright (c) 2015 Andrej Karpathy
# License: https://github.com/cs231n/cs231n.github.io/blob/master/LICENSE
# Source: https://cs231n.github.io/neural-networks-case-study/
def create_data(samples, classes):
X = np.zeros((samples*classes, 2))
y = np.zeros(samples*classes, dtype='uint8')
for class_number in range(classes):
ix = range(samples*class_number, samples*(class_number+1))
r = np.linspace(0.0, 1, samples)
t = np.linspace(class_number*4, (class_number+1)*4, samples) + np.random.randn(samples)*0.2
X[ix] = np.c_[r*np.sin(t*2.5), r*np.cos(t*2.5)]
y[ix] = class_number
return X, y
The linspace function is not available in the latest release of Nx, although it is present in the main
branch, so I’m using that, but I have no idea how to do the np.c_
part and loop the classes.