<jupyter_start><jupyter_text>questions:- der should be same with backpropagation when function value are the same, or what condition?- when using autodiff math, there no new autodiff object generated and calculated partial derivation?<jupyter_code>def test_backpropagation_arc():
    '''function for testing backpropagation'''
    x1 = ad.autodiff(name="x1", val=0.5, der=1)
    x2 = ad.autodiff(name="x2", val=0.5, der=1)
    w0 = ad.autodiff(name="w0", val=0.5, der=1)
    w1 = ad.autodiff(name="w1", val=0.5, der=1)
    w2 = ad.autodiff(name="w2", val=-0.5, der=1)

    f = admath.arctan(w0) * (w1/admath.arcsin(x1) - w2/admath.arccos(x2))
    assert abs(f.backprop()['w0'] - 1.4323944878270578) < 1E-10
    assert abs(f.backprop()['w1'] - 0.8855017059025995) < 1E-10
    assert abs(f.backprop()['x1'] - (-0.8455918416642267)) < 1E-10
    assert abs(f.backprop()['w2'] - (-0.44275085295129973)) < 1E-10
    assert abs(f.backprop()['x2'] - (-0.21139796041605668)) < 1E-10
    
test_backpropagation_arc()
def test_backpropagation_arc():
    '''function for testing backpropagation'''
    x1 = ad.autodiff(name="x1", val=[0.5, 0.5], der=1)
    w0 = ad.autodiff(name="w0", val=0.5, der=1)
    w1 = ad.autodiff(name="w1", val=[0.5, -0.5], der=1)
    
    f = admath.arctan(w0)-(w1/admath.arcsin(x1))- w2/admath.arccos(x2)
    #print('\n backpropagation evaluation result:', f.backprop())
    #print('auto differentiate function evaluation result:', f6.der)
    #print(abs(f.backprop()['w1'] - [-1.90985932, -1.90985932]))
    assert np.max(abs(f.backprop()['w0'] - 1)) < 1E-6
    assert np.max(abs(f.backprop()['w1'] - [-1.90985932, -1.90985932])) < 1E-6
    assert np.max(abs(f.backprop()['x1'] - [ 1.82378131, -1.82378131])) < 1E-6
    assert np.max(abs(f.backprop()['w2'] - [-0.95492966])) < 1E-6
    assert np.max(abs(f.backprop()['x2'] - [-0.45594533])) < 1E-6
    
test_backpropagation_arc()
import numpy as np
A= np.matrix([[1, 0],[0, 1]])
b= np.matrix([[0, 1]])
print(A*b.T)
def print(A**2)
def updatefun(param, func, data):
    #initiate autodiff
    w0 = ad.autodiff(name="w0",val = param[0],der = 1)
    w1 = ad.autodiff(name="w1", val = param[1], der = 1)
    w2 = ad.autodiff(name="w2",val = param[2], der = 1)
    
    funobj = func(data, w0, w1, w2)
    backprop = funobj['backprop']
    ypred = funobj['val']
    
    return backprop, ypred

def func(data, w0, w1, w2):
    '''
    data: 2d array with row as samples, column as features 
    '''
    funobj = {}
    vals = []
    backprops = []
    
    for i in range(len(data)):
        fobj = data[i, 0]*w0 +data[i, 1]*w1+data[i, 2]*w2
        backprops.append(list(fobj.backprop().values()))
        vals.append(fobj.val[0])
   
    funobj['backprop'] = np.mean(backprops, axis = 0) #np.average(backprops, axis = 1)
    funobj['val'] = vals
    return funobj

param = [1, 1, 1]
N = 10


def grad(param, data,y,  N = 10, tolerance = 0, step = 0.1):
    iteration = 0
    backprop= np.array([1, 1, 1])
    error = 1
    while iteration<N and error>tolerance: #number of  1000
        #calculate gradient descent
        #print(param)
        print(backprop)
        param = param - step*backprop*param
        backprop, ypred = updatefun(param, func, data)
        #print(backprop, ypred)
        error = np.sum(abs(ypred - y))/len(y)
        print(error)
        iteration+=1
        
    return param

if __name__ == '__main__':
    #test on gradient functions
    print(grad(np.array([1, 1, 1]), np.array([[1, 1, 1], [2, 1, 2]]), np.array([1, 1]), 10, 1e-3))
np.mean([[1, 1, 1], [2, 1, 2]], axis = 0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18977493748263408, 'fraction_numerical': 0.09113642678521812, 'mean_word_length': 3.2303172737955346, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '308507', 'license': 'MIT', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1479, 'n_words': 308, 'path': '.ipynb_checkpoints/playground-checkpoint.ipynb', 'repo_name': 'rajayuco/cs207-FinalProject', 'size': '3599'}