Skip to content

rohanwinsor/basicgrad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BasicGrad

Inspired by micrograd

Simple Regression Model

Training

from basicgrad import Value, Neuron

# Create Training Data
c2f = lambda x : float(1.8*x + 32) 
X = [[Value(float(i))] for i in range(-5,5)]
y = [Value(c2f(i)) for i in range(-5,5)]

# Init Model
model = Neuron(1, nonlin=False)
model.parameters()
lr = 0.01

# Training loop
while True:
    losss = []
    for x, yout in zip(X,y):
        pred = model(x)
        loss = (yout - pred)**2
        losss.append(loss)
    loss = sum(losss)
    if loss.data < 0.0001:
        break
    for pr in model.parameters():
        pr.grad = 0.0
    loss.backward()
    for pr in model.parameters():
        pr.data += (-lr * pr.grad)

Inference

X = [Value(10)]
y = model(X)
print(y.summary()) # c2f(10) -> 50

inference

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published