Exp 6ml

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Experiment 6

import numpy as np
import math
import time
np.set_printoptions(threshold=np.inf)
X = np.array([[1,-2,0,-1],[0,1.5,-0.5,-1],[-1,1,0.5,-1]])
D=np.array([-1,-1,1])
c=0.1;
W=np.array([[1,-1,0,0.5]])
e_max=0.1
#e_max=0.0001
#print(W)
while(1):
e=0
for i in range(3):
#y=X[0]
y=[X[i]]
#print(y)
net =sum(sum(W*y))
#print("\n Net is :",net)
O=(2/(1+math.exp(-net)))-1
#print("\n O is :",O)
e=e+(1/2)*(D[i]-O)**2
f_net=(1/2)*(1-O**2)
W_new=W+(np.asarray(c*(D[i]-O))*(y)*f_net)
#print("\n f'(net) :",f_net)
W=W_new
print("\n New weight is :",W)
time.sleep(1)

if e<=e_max:
break
// Output
New weight is : [[ 0.97408569 -0.94817138 0. 0.52591431]]

New weight is : [[ 0.97408569 -0.95634441 0.00272434 0.531363 ]]

New weight is : [[ 0.94737155 -0.92963027 0.01608141 0.50464886]]

New weight is : [[ 0.9173058 -0.86949877 0.01608141 0.53471461]]

New weight is : [[ 0.9173058 -0.87911636 0.01928728 0.54112633]]

New weight is : [[ 0.88780387 -0.84961443 0.03403824 0.5116244 ]]

New weight is : [[ 0.85259281 -0.77919231 0.03403824 0.54683547]]

New weight is : [[ 0.85259281 -0.79070218 0.03787486 0.55450871]]

New weight is : [[ 0.81977526 -0.75788463 0.05428364 0.52169116]]

New weight is : [[ 0.77832315 -0.67498041 0.05428364 0.56314327]]

New weight is : [[ 0.77832315 -0.68900908 0.05895986 0.57249572]]

New weight is : [[ 0.74157763 -0.65226356 0.07733262 0.5357502 ]]

New weight is : [[ 0.69303157 -0.55517144 0.07733262 0.58429626]]

New weight is : [[ 0.69303157 -0.57257325 0.08313322 0.59589746]]

New weight is : [[ 0.65172558 -0.53126726 0.10378622 0.55459147]]

New weight is : [[ 0.59638513 -0.42058635 0.10378622 0.60993193]]

New weight is : [[ 0.59638513 -0.44242747 0.11106659 0.62449268]]

New weight is : [[ 0.55005028 -0.39609262 0.13423402 0.57815783]]

New weight is : [[ 0.49088952 -0.27777111 0.13423402 0.63731858]]

New weight is : [[ 0.49088952 -0.30511292 0.14334796 0.65554646]]

New weight is : [[ 0.43955839 -0.25378179 0.16901352 0.60421533]]

New weight is : [[ 0.38275498 -0.14017498 0.16901352 0.66101874]]

New weight is : [[ 0.38275498 -0.17360041 0.18015533 0.68330236]]


New weight is : [[ 0.32725739 -0.11810281 0.20790413 0.62780476]]

New weight is : [[ 0.27891543 -0.02141889 0.20790413 0.67614672]]

New weight is : [[ 0.27891543 -0.06069033 0.22099461 0.70232769]]

New weight is : [[ 0.22073649 -0.00251139 0.25008408 0.64414875]]

New weight is : [[0.18273376 0.07349406 0.25008408 0.68215147]]

New weight is : [[0.18273376 0.02921863 0.26484256 0.71166843]]

New weight is : [[0.12350536 0.08844703 0.29445676 0.65244002]]

New weight is : [[0.09425067 0.14695641 0.29445676 0.68169471]]

New weight is : [[0.09425067 0.09870197 0.31054157 0.71386433]]

New weight is : [[0.03537751 0.15757514 0.33997815 0.65499116]]

New weight is : [[0.01254352 0.20324311 0.33997815 0.67782515]]

New weight is : [[0.01254352 0.15198892 0.35706288 0.7119946 ]]

New weight is : [[-0.04492204 0.20945449 0.38579566 0.65452904]]

New weight is : [[-0.06321287 0.24603614 0.38579566 0.67281987]]

New weight is : [[-0.06321287 0.19264799 0.40359171 0.70841197]]

New weight is : [[-0.11857428 0.24800941 0.43127242 0.65305056]]

New weight is : [[-0.13363511 0.27813106 0.43127242 0.66811138]]

New weight is : [[-0.13363511 0.22335155 0.44953225 0.70463105]]

New weight is : [[-0.18650339 0.27621983 0.47596639 0.65176277]]

New weight is : [[-0.19922452 0.3016621 0.47596639 0.6644839 ]]

New weight is : [[-0.19922452 0.24611649 0.4944816 0.70151431]]

New weight is : [[-0.24944683 0.29633879 0.51959275 0.651292 ]]

New weight is : [[-0.26043456 0.31831425 0.51959275 0.66227973]]

New weight is : [[-0.26043456 0.26252056 0.53819065 0.69947553]]

New weight is : [[-0.30801981 0.31010581 0.56198328 0.65189027]]

New weight is : [[-0.31769358 0.32945335 0.56198328 0.66156404]]

New weight is : [[-0.31769358 0.27383389 0.5805231 0.69864369]]

New weight is : [[-0.36274883 0.31888914 0.60305072 0.65358844]]

New weight is : [[-0.37140434 0.33620016 0.60305072 0.66224394]]

New weight is : [[-0.37140434 0.28109334 0.62141966 0.69898182]]


New weight is : [[-0.41408754 0.32377654 0.64276126 0.65629863]]

New weight is : [[-0.42193726 0.33947598 0.64276126 0.66414835]]

New weight is : [[-0.42193726 0.28514773 0.66087068 0.70036718]]

New weight is : [[-0.46242583 0.3256363 0.68111496 0.65987861]]

New weight is : [[-0.46962528 0.3400352 0.68111496 0.66707807]]

New weight is : [[-0.46962528 0.28668951 0.69889686 0.70264186]]

New weight is : [[-0.50809727 0.3251615 0.71813286 0.66416987]]

New weight is : [[-0.51476229 0.33849153 0.71813286 0.67083489]]

New weight is : [[-0.51476229 0.2862801 0.73553666 0.7056425 ]]

New weight is : [[-0.55138619 0.32290401 0.75384861 0.6690186 ]]

New weight is : [[-0.55760448 0.33534059 0.75384861 0.67523689]]

New weight is : [[-0.55760448 0.28437153 0.7708383 0.70921626]]

New weight is : [[-0.59253459 0.31930164 0.78830336 0.67428615]]

New weight is : [[-0.59837364 0.33097975 0.78830336 0.6801252 ]]

New weight is : [[-0.59837364 0.28132518 0.80485488 0.71322824]]

New weight is : [[-0.63174872 0.31470026 0.82154241 0.67985317]]

New weight is : [[-0.63726123 0.32572529 0.82154241 0.68536569]]

New weight is : [[-0.63726123 0.27742811 0.83764147 0.7175638 ]]

New weight is : [[-0.66920485 0.30937173 0.85361328 0.68562019]]

New weight is : [[-0.6744326 0.31982723 0.85361328 0.69084794]]

New weight is : [[-0.6744326 0.27290693 0.86925338 0.72212813]]

New weight is : [[-0.70505442 0.30352875 0.88456429 0.69150632]]

New weight is : [[-0.71003096 0.31348184 0.88456429 0.69648286]]

New weight is : [[-0.71003096 0.26793949 0.89974507 0.72684442]]

New weight is : [[-0.73942827 0.2973368 0.91444372 0.69744712]]

New weight is : [[-0.74418095 0.30684216 0.91444372 0.7021998 ]]

New weight is : [[-0.74418095 0.26266461 0.92916957 0.7316515 ]]

New weight is : [[-0.77244024 0.2909239 0.94329922 0.70339221]]

New weight is : [[-0.77699162 0.30002666 0.94329922 0.70794359]]


New weight is : [[-0.77699162 0.25719002 0.9575781 0.73650136]]

New weight is : [[-0.80419008 0.28438848 0.97117733 0.7093029 ]]

New weight is : [[-0.808559 0.29312633 0.97117733 0.71367182]]

New weight is : [[-0.808559 0.2515988 0.98501984 0.74135684]]

New weight is : [[-0.83476583 0.27780563 0.99812325 0.71515002]]

New weight is : [[-0.83896823 0.28621043 0.99812325 0.71935242]]

New weight is : [[-0.83896823 0.24595466 1.01154184 0.7461896 ]]

New weight is : [[-0.86424573 0.27123216 1.02418059 0.7209121 ]]

New weight is : [[-0.86829522 0.27933114 1.02418059 0.7249616 ]]

New weight is : [[-0.86829522 0.24030602 1.03718896 0.75097835]]

New weight is : [[-0.89269978 0.26471058 1.04939124 0.72657378]]

New weight is : [[-0.89660812 0.27252726 1.04939124 0.73048212]]

New weight is : [[-0.89660812 0.23468937 1.06200387 0.75570738]]

New weight is : [[-0.92019102 0.25827227 1.07379532 0.73212448]]

New weight is : [[-0.92396845 0.26582713 1.07379532 0.73590192]]

New weight is : [[-0.92396845 0.22913188 1.08602707 0.76036541]]

New weight is : [[-0.9467765 0.25193993 1.09743109 0.73755737]]

New weight is : [[-0.95043203 0.25925099 1.09743109 0.7412129 ]]

New weight is : [[-0.95043203 0.22365347 1.10929693 0.76494458]]

New weight is : [[-0.97250814 0.24572959 1.12033499 0.74286846]]

New weight is : [[-0.97604975 0.25281281 1.12033499 0.74641008]]

New weight is : [[-0.97604975 0.21826842 1.13184979 0.76943967]]

New weight is : [[-0.99743343 0.23965209 1.14254163 0.748056 ]]

New weight is : [[-1.00086825 0.24652173 1.14254163 0.75149082]]

New weight is : [[-1.00086825 0.21298665 1.15371999 0.77384754]]

New weight is : [[-1.02159593 0.23371433 1.16408383 0.75311986]]

New weight is : [[-1.02493036 0.24038319 1.16408383 0.75645429]]

New weight is : [[-1.02493036 0.20781474 1.17493998 0.77816659]]

New weight is : [[-1.04503579 0.22792017 1.18499269 0.75806115]]

New weight is : [[-1.04827561 0.2343998 1.18499269 0.76130097]]


New weight is : [[-1.04827561 0.20275668 1.1955404 0.78239639]]

New weight is : [[-1.06779012 0.22227118 1.20529766 0.76288188]]

New weight is : [[-1.07094057 0.22857209 1.20529766 0.76603233]]

New weight is : [[-1.07094057 0.19781449 1.21555019 0.7865374 ]]

New weight is : [[-1.08989329 0.2167672 1.22502655 0.76758469]]

New weight is : [[-1.09295917 0.22289897 1.22502655 0.77065057]]

New weight is : [[-1.09295917 0.19298871 1.23499664 0.79059075]]

New weight is : [[-1.11137725 0.21140679 1.24420568 0.77217267]]

New weight is : [[-1.11436296 0.2173782 1.24420568 0.77515837]]

New weight is : [[-1.11436296 0.18827874 1.2539055 0.79455801]]

New weight is : [[-1.13227177 0.20618755 1.2628599 0.7766492 ]]

New weight is : [[-1.13518133 0.21200667 1.2628599 0.77955876]]

New weight is : [[-1.13518133 0.18368317 1.27230107 0.79844109]]

New weight is : [[-1.15260458 0.20110643 1.2810127 0.78101784]]

New weight is : [[-1.15544172 0.2067807 1.2810127 0.78385498]]

New weight is : [[-1.15544172 0.17919995 1.29020629 0.80224215]]

New weight is : [[-1.17240165 0.19615988 1.29868625 0.78528222]]

New weight is : [[-1.17516982 0.2016962 1.29868625 0.78805038]]

New weight is : [[-1.17516982 0.1748266 1.30764278 0.80596345]]

New weight is : [[-1.19168726 0.19134405 1.31590151 0.789446 ]]

New weight is : [[-1.19438965 0.19674882 1.31590151 0.79214839]]

New weight is : [[-1.19438965 0.17056035 1.324631 0.80960737]]

New weight is : [[-1.21048419 0.18665489 1.33267827 0.79351283]]

New weight is : [[-1.21312377 0.19193406 1.33267827 0.79615241]]

New weight is : [[-1.21312377 0.16639821 1.34119022 0.81317631]]

New weight is : [[-1.22881382 0.18208825 1.34903524 0.79748626]]

New weight is : [[-1.23139337 0.18724736 1.34903524 0.80006581]]

New weight is : [[-1.23139337 0.16233708 1.35733867 0.81667267]]

New weight is : [[-1.24669625 0.17763996 1.36499011 0.80136979]]


New weight is : [[-1.24921836 0.18268419 1.36499011 0.80389191]]

New weight is : [[-1.24921836 0.1583738 1.37309357 0.82009883]]

New weight is : [[-1.2641504 0.17330583 1.38055959 0.8051668 ]]

New weight is : [[-1.2666175 0.17824003 1.38055959 0.8076339 ]]

New weight is : [[-1.2666175 0.15450518 1.3884712 0.82345713]]

New weight is : [[-1.28119409 0.16908177 1.3957595 0.80888054]]

New weight is : [[-1.28360845 0.1739105 1.3957595 0.8112949 ]]

New weight is : [[-1.28360845 0.15072808 1.40348697 0.82674985]]

New weight is : [[-1.29784413 0.16496376 1.41060481 0.81251417]]

New weight is : [[-1.30020789 0.16969128 1.41060481 0.81487793]]

New weight is : [[-1.30020789 0.14703938 1.41815544 0.82997919]]

New weight is : [[-1.31411639 0.16094788 1.42510969 0.81607069]]

New weight is : [[-1.31643156 0.16557821 1.42510969 0.81838585]]

New weight is : [[-1.31643156 0.14343604 1.43249042 0.8331473 ]]

New weight is : [[-1.33002586 0.15703034 1.43928757 0.81955299]]

New weight is : [[-1.33229432 0.16156726 1.43928757 0.82182145]]

New weight is : [[-1.33229432 0.13991508 1.44650497 0.83625624]]

New weight is : [[-1.34558672 0.15320748 1.45315117 0.82296385]]

New weight is : [[-1.34781026 0.15765456 1.45315117 0.82518739]]

New weight is : [[-1.34781026 0.13647363 1.46021148 0.83930801]]

New weight is : [[-1.36081239 0.14947575 1.46671254 0.82630588]]

New weight is : [[-1.36299269 0.15383636 1.46671254 0.82848619]]

New weight is : [[-1.36299269 0.1331089 1.47362169 0.8423045 ]]

New weight is : [[-1.37571557 0.14583177 1.47998313 0.82958162]]

New weight is : [[-1.37785423 0.1501091 1.47998313 0.83172029]]

New weight is : [[-1.37785423 0.1298182 1.48674677 0.84524756]]

New weight is : [[-1.39030832 0.14227228 1.49297381 0.83279347]]

New weight is : [[-1.39240685 0.14646934 1.49297381 0.834892 ]]

New weight is : [[-1.39240685 0.12659894 1.49959728 0.84813894]]

New weight is : [[-1.40460207 0.13879416 1.50569489 0.83594372]]


New weight is : [[-1.40666189 0.1429138 1.50569489 0.83800354]]

New weight is : [[-1.40666189 0.12344863 1.51218328 0.85098032]]

New weight is : [[-1.41860767 0.1353944 1.51815617 0.83903454]]

New weight is : [[-1.42063013 0.13943934 1.51815617 0.84105701]]

New weight is : [[-1.42063013 0.12036488 1.52451432 0.85377332]]

New weight is : [[-1.43233542 0.13207017 1.53036697 0.84206803]]

New weight is : [[-1.43432183 0.13604297 1.53036697 0.84405444]]

New weight is : [[-1.43432183 0.11734539 1.5365995 0.85651949]]

New weight is : [[-1.44579514 0.1288187 1.54233615 0.84504617]]

New weight is : [[-1.4477467 0.13272181 1.54233615 0.84699773]]

New weight is : [[-1.4477467 0.11438795 1.54844744 0.8592203 ]]

New weight is : [[-1.45899615 0.1256374 1.55407217 0.84797085]]

New weight is : [[-1.46091402 0.12947314 1.55407217 0.84988872]]

New weight is : [[-1.46091402 0.11149047 1.56006639 0.86187717]]

New weight is : [[-1.47194732 0.12252376 1.56558304 0.85084388]]

New weight is : [[-1.47383261 0.12629434 1.56558304 0.85272917]]

New weight is : [[-1.47383261 0.1086509 1.57146419 0.86449146]]

New weight is : [[-1.4846571 0.1194754 1.57687643 0.85366697]]

New weight is : [[-1.48651086 0.12318292 1.57687643 0.85552073]]

New weight is : [[-1.48651086 0.10586733 1.5826483 0.86706446]]

New weight is : [[-1.49713356 0.11649002 1.58795965 0.85644176]]

New weight is : [[-1.49895679 0.1201365 1.58795965 0.858265 ]]

New weight is : [[-1.49895679 0.10313788 1.59362585 0.86959741]]

New weight is : [[-1.50938437 0.11356546 1.59883964 0.85916983]]

New weight is : [[-1.51117804 0.1171528 1.59883964 0.8609635 ]]

New weight is : [[-1.51117804 0.10046079 1.60440365 0.87209151]]

New weight is : [[-1.52141688 0.11069963 1.60952306 0.86185267]]

New weight is : [[-1.5231819 0.11422966 1.60952306 0.86361768]]

New weight is : [[-1.5231819 0.09783434 1.61498817 0.87454789]]


New weight is : [[-1.53323808 0.10789053 1.62001626 0.8644917 ]]

New weight is : [[-1.53497532 0.111365 1.62001626 0.86622894]]

New weight is : [[-1.53497532 0.09525692 1.62538562 0.87696766]]

New weight is : [[-1.54485467 0.10513627 1.6303253 0.8670883 ]]

New weight is : [[-1.54656496 0.10855684 1.6303253 0.86879859]]

New weight is : [[-1.54656496 0.09272694 1.63560193 0.87935185]]

New weight is : [[-1.55627304 0.10243503 1.64045597 0.86964377]]

New weight is : [[-1.55795717 0.10580329 1.64045597 0.87132791]]

New weight is : [[-1.55795717 0.09024293 1.64564276 0.88170148]]

New weight is : [[-1.5674993 0.09978506 1.65041382 0.87215935]]

New weight is : [[-1.56915804 0.10310255 1.65041382 0.8738181 ]]

New weight is : [[-1.56915804 0.08780345 1.65551352 0.88401751]]

New weight is : [[-1.5785393 0.0971847 1.66020415 0.87463625]]

New weight is : [[-1.58017339 0.10045289 1.66020415 0.87627034]]

New weight is : [[-1.58017339 0.08540711 1.66521941 0.88630086]]

New weight is : [[-1.58939866 0.09463237 1.66983204 0.8770756 ]]

New weight is : [[-1.59100879 0.09785264 1.66983204 0.87868573]]

New weight is : [[-1.59100879 0.0830526 1.67476539 0.88855242]]

New weight is : [[-1.60008272 0.09212654 1.67930236 0.87947849]]

New weight is : [[-1.60166958 0.09530024 1.67930236 0.88106534]]

New weight is : [[-1.60166958 0.08073866 1.68415622 0.89077306]]

New weight is : [[-1.61059665 0.08966574 1.68861975 0.88184598]]

New weight is : [[-1.61216086 0.09279416 1.68861975 0.8834102 ]]

New weight is : [[-1.61216086 0.07846408 1.69339645 0.89296359]]

New weight is : [[-1.62094537 0.08724858 1.6977887 0.88417908]]

New weight is : [[-1.62248756 0.09033296 1.6977887 0.88572127]]

New weight is : [[-1.62248756 0.07622768 1.70249046 0.8951248 ]]

New weight is : [[-1.63113361 0.08487373 1.70681349 0.88647875]]

New weight is : [[-1.63265437 0.08791525 1.70681349 0.88799951]]

New weight is : [[-1.63265437 0.07402835 1.71144246 0.89725744]]


New weight is : [[-1.64116591 0.08253989 1.71569822 0.88874591]]

New weight is : [[-1.64266581 0.0855397 1.71569822 0.89024581]]

New weight is : [[-1.64266581 0.07186502 1.72025645 0.89936226]]

New weight is : [[-1.65104663 0.08024584 1.72444686 0.89098145]]

New weight is : [[-1.65252623 0.08320503 1.72444686 0.89246104]]

New weight is : [[-1.65252623 0.06973666 1.72893631 0.90143996]]

New weight is : [[-1.66077996 0.0779904 1.73306318 0.89318622]]

New weight is : [[-1.66223978 0.08091003 1.73306318 0.89464604]]

New weight is : [[-1.66223978 0.06764228 1.73748576 0.90349121]]

New weight is : [[-1.67036993 0.07577243 1.74155084 0.89536106]]

New weight is : [[-1.67181047 0.07865351 1.74155084 0.8968016 ]]

New weight is : [[-1.67181047 0.06558092 1.74590837 0.90551666]]

New weight is : [[-1.6798204 0.07359085 1.74991333 0.89750673]]

New weight is : [[-1.68124215 0.07643436 1.74991333 0.89892849]]

New weight is : [[-1.68124215 0.06355167 1.75420756 0.90751695]]

New weight is : [[-1.68913509 0.07144461 1.75815403 0.89962401]]

New weight is : [[-1.69053854 0.0742515 1.75815403 0.90102745]]

New weight is : [[-1.69053854 0.06155365 1.76238665 0.90949269]]

New weight is : [[-1.6983176 0.06933271 1.76627618 0.90171362]]

New weight is : [[-1.69970318 0.07210388 1.76627618 0.9030992 ]]

New weight is : [[-1.69970318 0.05958601 1.77044881 0.91144445]]

New weight is : [[-1.70737137 0.06725419 1.7742829 0.90377627]]

New weight is : [[-1.70873952 0.06999051 1.7742829 0.90514442]]

New weight is : [[-1.70873952 0.05764793 1.77839709 0.91337281]]

New weight is : [[-1.71629971 0.06520812 1.78217718 0.90581262]]

New weight is : [[-1.71765086 0.06791043 1.78217718 0.90716378]]

New weight is : [[-1.71765086 0.05573864 1.78623444 0.9152783 ]]

New weight is : [[-1.72510583 0.0631936 1.789961993 0.90782334]]

You might also like