Initial Steps towards Defining a NeuralNetwork Class

In [16]:
class Silly():
    
    def __init__(self, my_name):
        
        self.my_name = my_name
        
    def __str__(self):
        return f'This is a Silly object for {self.my_name}' 
    
    def __repr__(self):
        return f'Silly(\'{self.my_name}\')'
In [17]:
print(Silly('Chuck'))
This is a Silly object for Chuck
In [18]:
Silly('Chuck')
Out[18]:
Silly('Chuck')
In [19]:
me = Silly('Chuck')
me
Out[19]:
Silly('Chuck')
In [20]:
import numpy as np
np
Out[20]:
<module 'numpy' from '/home/anderson/anaconda3/lib/python3.8/site-packages/numpy/__init__.py'>
In [24]:
me.my_name = 'Lori'
In [26]:
me.my_name
Out[26]:
'Lori'
In [27]:
me.my_town = "fort collins"
In [29]:
me.my_town
Out[29]:
'fort collins'
In [30]:
nnet = NeuralNetwork(1, [5, 4, 3], 2)

nnet.train(X, T, n_epochs, learning_rate, method='sgd')

Y = nnet.use(X)

nnet.save('mybestresult.nnet')  # save the whole network
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-30-7a92c2e315f3> in <module>
----> 1 nnet = NeuralNetwork(1, [5, 4, 3], 2)
      2 
      3 nnet.train(X, T, n_epochs, learning_rate, method='sgd')
      4 
      5 Y = nnet.use(X)

NameError: name 'NeuralNetwork' is not defined
In [41]:
class NeuralNetwork():
    
    def __init__(self, n_inputs, n_hiddens_list, n_outputs):
        
        self.n_inputs = n_inputs
        self.n_hiddens_list = n_hiddens_list
        self.n_outputs = n_outputs
        
    def __repr__(self):
        return f'NeuralNetwork(n_inputs={self.n_inputs}, n_hiddens_list={self.n_hiddens_list}, n_outputs={self.n_outputs})'
    
    def train(self, X, T, n_epochs, learning_rate, method):
        pass
    
    def use(self, X):
        return None
In [42]:
nnet = NeuralNetwork(1, [10], 3)
In [43]:
X = np.arange(10).reshape(-1, 1)
T = X
nnet.train(X, T, 100, 0.1, 'sgd')
Y = nnet.use(X)
In [ ]: