micrograd/test/test_neuron.py

32 lines
568 B
Python
Raw Normal View History

2024-02-22 08:41:04 -08:00
import pytest
from micrograd.engine import Value
# @pytest.mark.skip(reason="complicated assertion")
def test_big_neuron():
# inputs
x1 = Value(2.0, label='x1')
x2 = Value(0.0, label='x2')
# weights
w1 = Value(-3.0, label='w1')
w2 = Value(1.0, label='w2')
# bias
b = Value(6.8813735870195432, label='b')
h1 = x1 * w1
h1.label = 'h1'
h2 = x2 * w2
h2.label = 'h2'
h = h1 + h2
h.label = 'h'
n = h + b
n.label = 'n'
y = n.tanh()
y.label = 'y'
assert pytest.approx(y.data, 0.01) == 0.7071