33 lines
829 B
Python
33 lines
829 B
Python
|
from layer import *
|
||
|
import numpy as np
|
||
|
import pickle
|
||
|
|
||
|
DIMENTION = 3
|
||
|
VAR_RANGE = 1
|
||
|
N = 10
|
||
|
ALPHA = 0.1
|
||
|
SIGMA = VAR_RANGE * ALPHA
|
||
|
|
||
|
gen: np.random.Generator = np.random.default_rng()
|
||
|
or_weight = (gen.uniform(high = VAR_RANGE,low = -VAR_RANGE,size=(1,DIMENTION)))
|
||
|
or_bias = (gen.uniform(high = VAR_RANGE, low = -VAR_RANGE,size=()))
|
||
|
print(or_bias)
|
||
|
|
||
|
input_x = gen.uniform(low = -VAR_RANGE,high=VAR_RANGE,size=(DIMENTION,N))
|
||
|
y = or_weight @ input_x + or_bias
|
||
|
error = gen.normal(0,SIGMA,size = (1,N))
|
||
|
y += error
|
||
|
print(y)
|
||
|
|
||
|
|
||
|
input_var = Variable(np.array([[1],[2],[3]]))
|
||
|
weight = Variable(np.array([[2,-1,1]]))
|
||
|
bias = Variable(np.array([[1]]))
|
||
|
v = ((weight @ input_var) + bias)
|
||
|
|
||
|
print(make_mermaid_graph(v))
|
||
|
|
||
|
print(f"result : {v.numpy()}")
|
||
|
v.backprop(np.ones(()))
|
||
|
print(f"grad input : {input_var.grad}, w : {weight.grad}, b : {bias.grad}")
|