<jupyter_start><jupyter_text><jupyter_code>%matplotlib inline
import numpy as np
from matplotlib import pyplot as plt
plt.style.use('ggplot')
n=200
def normal(n):
    return np.random.randn(n)
x1=np.concatenate((normal(n)-2,normal(n)+2),axis=None)
x2=np.concatenate((normal(n)-2,normal(n)+2),axis=None)
yt=np.ones(2*n)
yt[:n]=-1
plt.plot(x1[yt==-1],x2[yt==-1],'or')
plt.plot(x1[yt==1],x2[yt==1],'ob')
import numpy as np
from matplotlib import pyplot as plt
step = 0.2
mx2, mx1 = np.mgrid[slice(-6,6, step),
                    slice(-6,6, step)]

theta1 = 0.0
theta2 = 0.0
theta3 = 0.0
alpha =0.1

def func_yp(x1,x2):
    global theta1,theta2,theta3
    z=theta1*x1 + theta2*x2 +theta3
    return np.tanh(z)

plt.plot(x1[yt==-1],x2[yt==-1],'or')
plt.plot(x1[yt==1],x2[yt==1],'ob')
for i in range(100):
    yp=func_yp(x1,x2)
    theta1 = theta1 - alpha*np.average( (yp-yt)*(1-yp*yp)*x1 )
    theta2 = theta2 - alpha*np.average( (yp-yt)*(1-yp*yp)*x2 )
    theta3 = theta3 - alpha*np.average( (yp-yt)*(1-yp*yp ))
    if i%10==0:
        print(theta1,theta2,theta3)
        #plt.plot(x,theta1*x+theta2,'r')
cmap = plt.get_cmap('PuOr')
plt.pcolormesh(mx1, mx2, func_yp(mx1,mx2), cmap=cmap)<jupyter_output>0.1976665887384656 0.20787391578374406 0.0
0.3530885495946269 0.35842156459919483 6.880647910762733e-05
0.4146402780819341 0.4125217203076539 -0.0006200139493686056
0.45660761734581434 0.44723857215596735 -0.001123326078840783
0.489317857185922 0.47303783561055857 -0.001410130146165805
0.5165074780393089 0.493641330904874 -0.0015044855895632637
0.5399849311451368 0.510822683656161 -0.001433873237298427
0.5607738096010985 0.5255714933112404 -0.0012221915221131002
0.5795141928765997 0.5384983709861253 -0.0008892462759973083
0.5966351492731626 0.5500075422706383 -0.00045135054350762513
{'fraction_non_alphanumeric': 0.1626607043040805, 'fraction_numerical': 0.33761878144214647, 'mean_word_length': 5.193771626297578, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '578787', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1178, 'n_tokens_neox': 853, 'n_words': 117, 'path': 'cs409/Activity3 sol Single Layer Perceptron-Copy1.ipynb', 'repo_name': 'wasit7/2019', 'size': '1789'}