Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
BUILDINGTHEARTIFICIALNEURALNETWORKENVIRONMENT
ArtificialNeuralNetworksinplanecontrol
Bachelor’sthesis
Valkeakoski,AutomationEngineering
Fall2016
DaniilNaumetc
ABSTRACTAutomationEngineeringValkeakoskiAuthor DaniilNaumetc Year2016Subject ArtificialNeuralNetworksinplanecontrolABSTRACT
These days Artificial Neural Networks have penetrated into all digital technologies that surround us. Mostly every online service like Facebook, Google, Instagram are using Artificial Intelligence to build better service for their users.
Google Self-Driving Car Project that started several years ago already have results as driverless cars already moving on the streets of California.
Artificial Intelligence makes a breakthrough in Medicine as well. Such programs already successfully find disease reasons and make clinical decisions.
Boldly saying, we can expect AI replacing human beings in most spheres of our lives.
This Thesis idea is to make approach for developing AI for piloting, since the topic is not highly developed yet.
Keywords Artificial neural networks, autopilot, artificial intelligence, machinelearningPages 32pagesincludingappendices9pages
CONTENTS
1 INTRODUCTION...........................................................................................................1
2 BACKGROUND.............................................................................................................2
2.1 Neuron................................................................................................................22.2 NeuralNetwork...................................................................................................22.3 Artificialneuron..................................................................................................32.4 ArtificialNetwork................................................................................................42.5 Simpleperceptron...............................................................................................42.6 Backpropagation.................................................................................................62.7 Inputandoutput,Normalization........................................................................72.8 ActivationFunctions............................................................................................8
2.8.1 Identity....................................................................................................92.8.2 Sigmoid..................................................................................................102.8.3 Tanh.......................................................................................................122.8.4 ReLU......................................................................................................13
2.9 Types.................................................................................................................142.9.1 FeedforwardNetwork..........................................................................142.9.2 RecurrentNetwork................................................................................152.9.3 LSTM......................................................................................................162.9.4 Kohonen’sself-organizingmaps............................................................17
2.10Learningprocedureoffeed-forwardnetwork..................................................182.11Commonlyusedframeworks............................................................................22
3 MATERIALSANDMETHODS......................................................................................22
3.1 Planestablingtask,basicconcept.....................................................................233.2 Planestablingtaskindetails.............................................................................243.3 Planesimulation................................................................................................253.4 DataprocessingfortheANN.............................................................................283.5 JetsonTX1.........................................................................................................293.6 ArtificialNeuralNetwork..................................................................................293.7 Learningprocess...............................................................................................30
4 CONCLUSION.............................................................................................................30
5 FUTUREWORK..........................................................................................................30
REFERENCES...................................................................................................................32
AppendicesAppendix1 ContentsofXMLinput/outputfileAppendix2 PythonprogramforreceivingFlightGeardataAppendix3 ContentsofPythonlibraryforpreparingdataforCaffeAppendix4 PrototxtfilecontainingdescriptionofnetworkforCaffeAppendix5 PrototxtfilecontainingdescriptionofsolverforCaffe
1
1 INTRODUCTION
Everyprogramisbuiltuponamodel.Themodelcanbefullornot,someofvariablesmaybesoinsignificantthatwon’treallyaffecttheresult.Butsomevariablesthatwerenottakenintocountcanmodifytheresultinaveryunexpectedway,sothatahardwarethatworkswithanincompletesoftwarecancausedamagetoanenvironmentitoperateswith.Alongwiththeopenmodelbasedclassofproblems,thereisaclassofproblems,thathasalackofinformationlikehowdoesaproblemcanbesolved.Themodelofaprocesscanbesolargethatitisimpossibletocoveritall,orevenonlyasmallpart.Todealwiththatkindofproblemswheresomevariablesarenotknownwecanreplacethemwiththeartificialones(nodes)andtrytofindtheirroleusingtherecordedexperienceofinputsandoutputs.Thepre-learnedmodelfoundwhilesolvingtheproblemcanbenotasfullastherealworldmodel,butusingneuralnetworkswecanstartsolvingtheproblemnottryingtounderstandhowitworks.So,wecantrytobalancebetweentimespentondevelopmentandtheoutcome,thatcanbeaccurateenough.Ontheother,handthemodellearnedbylargeamountofdatacanbemuchmoreaccuratethananyotheralgorithmthatwasbuiltbyahumanbeing.Also,itisnecessarytomentionthatANNcanbecomeanextremelyeffectiveblack-boxintopicswherehumandoesn’tknowhowtomakemachinedosomeoperations.Forinstance,processingnaturallanguageisakindofaproblem,whereitisnotobvioushowtoprogramthevoicerecognitioninaclassicway.Aneuralnetworkistheonlyway,letsvoicerecognitionworksinGoogleorApple.Summarisingthefirstimpression,ANNisaprogramthatcanlearnpossibleresultsbythedatagivenontheinputs.Todosoitbuildsabstractmodelsofrelationshipsbetweenvariables.
Modernsystemsthatoperateplanesaredevelopedenoughtobesomehowresponsibleforpeoplewhousesairlineservices.Autopilotsystemswereevolvingfordecadesandonetechnologyisnotenoughtoupendthewholeindustry.IalsobelievethatsuchsystemsthatIwanttoproposearebeingdevelopedrightnow.Sincealltheprogramsandmodelswerebuiltbyhumans,theyarequiteheavyandhaveastrongtheoreticalbackground.Itcanbecomeaninterestingtopictobuildaplane,thatcanlearntoflyandheadthecoursebyitself.Therearetwoproblemsthatcanbecoveredbythisproject:hardpredictabilityofnaturalprocessesandimpossibilitytowork
2
inanunknownenvironment.Secondproblemisseenquiteinterestingformebecauseforcomputersunknownenvironmentcanbeaplacewithunusualconditions,forexampleairpressure,orbrokenleftwingwiththedifferentliftcharacteristicsfromtherightonecanbeagoodexampleofunknownenvironment.
2 BACKGROUND
2.1 Neuron
BrainofeverybeingisrepresentedbyalargeNeuralNetwork,theamountofneuronsandtheirstructureasanetworkdeterminesalevelofintellectofthatcreature.Buttheneuronitselfremainsthesameamongmostofcreatures.Thebasicideabehindtheneuronistoreceivesignalsofotherneurons,combineatransformedsignalbasedoninputsandtransferittootherneurons.Signalsaretransferredaselectricalsignalsfromoneneurontoanotheranditisalwayschangedbythelastone.Basicnaturalneuronconsistsofthreemainparts:dendrite,nucleusandaxon.Dendriteisaterminal,thatreceiveselectricalsignalsandtransferittonucleus.Nucleusisapartthatrememberspreviousexperiencesinaway,thatitcangiveapositiveoutputiftheinputsatisfiesitornegativeonthecontrary.Thentheoutputgoestoaxon,whichisconnectedtoseveralotherneuronsofthenetwork.Itisimportanttounderstandaboutneurons,thateachofthemcanberepresentedassomemathematical(logical)function.Forexample,wecandefineaneuronthatwewanttogivehighpositivesignal(1)ascatandneutral(0)as“other”.Dendrites(inputs)canbeprogrammedtoreceive0or1fromotherneuronsresponsibleforcatwool,fourpawsandtail.Ifallthreeinputshave1,thatmakesnucleusgive1aswell.[1]
Themostattractivefeatureofneuronisthatitcanlearn.Thefunctionrepresentedaneuroncanchangestandardvariablesintimewhileitislearning.Theresultswiththesameinputsmayvarybeforeandafterlearningactivities.Basically,ifeverytimeneurongivesusanopinion,thatathingthathasfourpawsandatailisacat,wesaythatitisnotacat,itcanleadtoextinctionoftheparticularneuron.
2.2 NeuralNetwork
Oneneuroncansolvequitesimpleproblemsanddoesn’trepresentvalue
3
byitself.Butacollectionofneuronsconnectedinacertainwaycansolvequitecomplexproblems.BasicNNcontainsoneorseverallayersofneurons.Layerrepresentsasetofneuronsthatarenotconnectedbetweeneachotherinmostcases;andstaybetweenotherlayers.Someneuronlayersaredefinedasinputandoutputlayerswhichdependsonitsposition.
Thesimplestkindofneuralnetworkisasingle-layerperceptronnetwork,whichconsistsofasinglelayerofoutputnodes.Theinputsarefeddirectlytotheoutputsviaaseriesofweights.
Betweeninputandoutputneuronscanbeasetofotherlayers,whichcalledhiddenlayers.Theyareresponsibleforbuildingcomplexhigh-levelabstractions.
Theexamplewiththecatinsection2.1isquiteempiricalone.Inreallifewefacedtomuchcomplexsystems.Ifwewanttodefineacat,werequirelotsofotherpropertiesofananimal:colouring,height,weight,faceandsoon.Amountofpropertiescanbecountedinhundredsandthousands,butneuroncan’tbeconnectedtoeachofthem,andevenifcouldthatwouldkeepNNverysimple.Insuchcaseneuronsinhiddenlayerscanhandleprocessingofabstractions.Neuronsinthemiddlehiddenlayersrecognisepatternsfrompreviouslayersandtheresultsbeingsentforward.
Incomplexneuralnetworksneuronsinhiddenlayerscanrepresentabstractionsthatcan’tbeunderstoodbyhumans,butinsuchproblemslikeimagerecognition,onelayercanrecognisepatternslikecircles,thatcouldbeusedtorecognisewheelsofacar.
2.3 Artificialneuron
Artificialneuronrepresentsrealneuronmathematically.Realneuronhasverycomplicatedconcept.Itworksbybiologicalmechanics.Manyfeaturesplayroleinit:hormones,speedofconduction,chemicalcompositionoftheneuron,presenceofelementsinorganism.Artificialneuronworksbyverybasicrules.Nucleusreplacedwithsimplemathematicalfunctioncalled“activationfunction”,dendritesaremultiplicationfunction,theymultiplyincomingsignalbyaweightthatisalwayschangedafterlearning.Axonhasnotransformationfunctions.
Therearelotsofactivationfunctionsusedinprogrammedneuron,butthemostbasicandeffectiveoneissigmoidfunction.Sigmoidcaninputsignalofanyrangebutoutputssignalonlybetween-1and1.Thatmakesmucheasiertoworkwithinanetwork.Moreover,onlyafterthesigmoidwasusedwasfoundanothercharacteristicthatincreaseseffectivenessofthefunction.Neuralnetworklearningprocessisveryexpensiveforthe
4
computer,becauseoftheamountofmathematicalcomputations.Sigmoidfunctionsimplifiestheprocessbecausethecalculationofderivativeofsigmoidfunctionisveryeasy.Thatwouldbecoveredfurtherer.[2]
2.4 ArtificialNetwork
Duetocomplexityofrealneuralnetworkwecan’tmakeafullmodelofit.Creatingthemodelthatrepeatsalltheprocessesinfluencingtheneuronswouldbearoughproblemtosolve.Eventhough,rightnow,themodelsbuilttorecognisevoiceorpicturesarerelativelysimplecomparingtobrainofasmallestbeingandtheyrequirelotsofcomputationalpowerfromanoperatingunit.
Thewaythatletsususeneuralnetworksisquitesimple.Firstofall,programmersofneuralnetworksdonotthinkintermsofneuronsascomputationunits.Whatplaysaroleinprogrammingofartificialneuralnetworksaretheweights.Thatweightsthatrepresentdendriteinnaturalneuronisthemostimportantthingbecauseonlythemarealwayschangingwhileneuralnetworkslearn.Afterlearningallthethingsusedtocreateanetworkremainsthesameexceptweights.Insomecases,learningratecanbechanged,butitisnotnecessarytoknowthelearningratetousethelearnednetwork.
Secondly,inmostcasesthenetworkisjustaprogram.Thememoryofanetwork,astoldbefore,isstoredasweights.InmostofmodernNeuralNetworksneuronsoftwoparticularlayersareconnectedbetweeneachother(notinsideofonelayer).ThistypeofconnectioniscalledEach-to-Each.Theinterestingfeatureofthisconnectiontypeisthatallweightscanbeeasilystoredasmassive.Forexample,ifwehave2layersconnectedEach-to-Each:10neuronsand5neurons,becauseeachof5neuronsinthesecondlayerwouldhave10connectionsfromthefirstlayer.Wecaneasilystorethemasanarrayoftwodimensions,5and10respectively,andtreatthemasmatrixes.
2.5 Simpleperceptron
Singlelayerperceptronisanexampleofabasicfeedforwardnetwork,whichwasthefirstartificialneuralnetworkbuilt.Ithasjusttwolayers:oneinputandoneoutput.Neuronsinthefirstlayerreceivesignalsandtransferthemtotheoutputneurons.Asacceptedfirstlayerdoesn’tapplyanyfiltertodataandtransferitdirectlyfromdendritetoaxon.Afterthatsignalsgotmultipliedbyweightsandcontinuetoactivationfunctionandfurtheroutcomeasoutputsignals.
5
AsanexampleofhowitworkswecanmodelasinglelayerperceptronwithANDactivationfunction.Wewillhavetwoinputneuronsandoneoutput.[3]
Theoutputneuronwouldhavetwoweightsw1andw2thatcomefromNeuron1andNeuron2respectively.TheoutputwouldbeT.TheoutputofinputneuronsismeanttobeaninputitselfandequaltoI1andI2.Theperceptronseparatesinputintotwocategories:theonethatcausefireonoutputandtheonethatdoesnot.Itdoesthisbylookingat
w1I1+w2I2<t,
IfLHSissmallerthantitdoesn’tfire,otherwiseitfires.Thatis,itisdrawingtheline:
w1I1+w2I2=t,
andlookingatwheretheinputpointlies.Pointsononesideofthelinefallinto1category,pointsontheothersidefallintotheothercategory.Andbecausetheweightsandthresholdscanbeanything,thisisjustanylineacrossthe2dimensionalinputspace.
Sowhattheperceptronisdoingissimplydrawingalineacrossthe2-dinputspace.Inputstoonesideofthelineareclassifiedintoonecategory,inputsontheothersideareclassifiedintoanother.e.g.theORperceptron,w1=1,w2=1,t=0.5,drawstheline:
I1+I2=0.5
acrosstheinputspace,thusseparatingthepoints(0,1),(1,0),(1,1)fromthepoint(0,0):
6
Figurе 1: Input space
Asyoumightimagine,noteverysetofpointscanbedividedbyalinelikethis.Thosethatcanbe,arecalledlinearlyseparable.
In2inputdimensions,wedrawa1dimensionalline.Inndimensions,wearedrawingthe(n-1)dimensionalhyperplane:
w1I1+…+wnIn=t
2.6 Backpropagation
BackpropagationisthemostbasicideabehindtheNeuralNetworks.Itletsneuralnetworkslearn.Ifweconsiderthatfeedforwardnetworkiscalledbyfeedinginputsignalsthrough the entire network towards its output. The backpropagationmechanismistheoppositetofeedingforward–feedingbackward.Toarrange learningprocessweneed topropagate the teachingsampleinput-output pair to the experience-less network and get thepredictedoutputofthenetwork.Thenwhatwewouldistoshowthenetworkwhichhowdiffersitspredictiontooriginalone.Forthattaskwewouldcalculatethedifferencebetweenoriginaloutputandimperfectoutputdonebythenetwork.Ifwewilljustsendtheoriginaloutputbackthroughthenetworkwillbejustseamless.Forsuchacasewasinventedawaytobackpropagatetheerroritself.
7
Tobackpropagatetheerrorfirstwewillapplyittotheinputweightsoftheoutput neurons. We will compute ∆"# for each input weight and thesignals outputted by previous layer. Afterwe calculated the outputs ofeachneuronofpreviouslayerweneedtobackpropagatetheerrorthroughtheactivationfunction.Wecan’tjustsendtheerrorthroughit,sowhatwedoiswegetthederivativeofthefunctionandthroughthederivativewesendtheerror.Afterthatallthestepstakenwerepeatforeachneuronandeachlayerdowntotheinputofthenetwork.[4]This trick is the basic for all the most used neural networks, likefeedforward,convolutional,recurrentandLongShort-TermMemorycells.
2.7 Inputandoutput,Normalization
Themost important and time consuming step inworkingwithArtificialNeural Networks is preparing data. Since we are working withmathematical functions it is not possible just to input some values inrandomformat. Inmachine learningand inneuralnetworks learning, inparticular,datashouldbeinrightformat.Theprocessofformattingthedata is called “Normalization”. Artificial Neural Networks input datadependsonactivationfunction.Usuallydatashouldbebroughttointerval[0,1]or[-1,1]iftheinputneuron’sactivationfunctionisSigmoidorTanh,orsimilar.Ifnormalizationisnotapplied,inputdatawouldexertadditionalinfluence.Neuralnetworkoutputsdatainsameformatasinputs,usually,between0and1.Forexample,ifwehaveaproblemofimagerecognition,popularMNIST,wheretheon inputwegetapictureandweshouldoutputadigit, thatcorresponds to an image. Raw images for that problem are pictures of28x28pixels,eachpixelhasarangeof256colors.Toinputthispicture,wemakeanarray,thatiscalled“Tensor”andcontainasetofnumbers.Inourcasethetensorwillhave784variables.Eachofthemshouldbebetween0and1,where0iswhiteand1isblack.Ifwehaveapixelthatismiddlegrayvaluedas128,tostoreitinrequiredrangewedividethevalueby256.Soweget0.5 formiddlegray.Weapply this technique toall the rest783variables. To say further we will have an input neuron for each inputvariableinthetensor.Tosolvetheproblem,weneedtorecognizewhichdigitisdrawnonimage.Forexample,wecanhaveonly10possibilities,animagecanhaveadigitbetween0and9,inclusive.So,wemake10outputneurons,foreachdigit.Afterthemodelistrainednetworkshouldoutputsomevaluesbetween0and 1, and the one neuron that has the highest value, is winning. Forinstance, if output is [0.1,0.2,0.15,0.94,0.25,0.12,0.21,0.3,0.1,0.2], 4th
8
value has the highest number, that means, that 4th value wins, whichcorrespondstonumber3.Thistechniqueiscalled“One-hot”.[5]Machinelearningproblemsconsumebigamountsofdata.Tobesurethatwelearnedmodelwouldworkoutitisusuallyneededtocollectnotlessthan ten thousand of working samples for simple problems. But morecomplex ones require even more. For example, accomplished task byDeepDrive,whichaimwaslearningamodeltodrivesimulatedcar,tookadatasetof600thousandphotos,whichconsumed80Gigabytesofmemorysize.Tocollectthisamountofdataresearchersneededtorecorddrivencarfor42hours.[6]ItisobviousthatitisnotpossibletoloadsuchlargedatasetsintoRAMtoprocessit.Forsuchcasesresearchersdividedataintobatches.Eachbatchcontain some amount of working samples, for example, 1000 imageswhichareloadedtoRAM.Afterbatchisfinished,nextbatchisloaded.Working sample contain inputs and outputs that are fed intomodel toteachit.Itcanbeimageortext,orjustasequenceofsignals.Thedesiredoutputshavetobeloadedinparallel,sothateachsampleshouldbefedandprocessedwiththecorrespondingoutput.
2.8 ActivationFunctions
Incomputersystemsactivationfunctionsusedinsidenodes.Theydefinetheoutputofnodeaccordingtoinput.Forexample,standardcomputerchipcangive1or0dependingoinput.ThisisverysimpletolinearactivationfunctioninNeuralNetworks.However,linearactivationfunctionsdon’tlettosolvenontrivialproblemsinwithsmallamountofneuronsinanetwork.Nonlinearfunctionsarethebasethatletsneuralnetworkssolvecomplextasks.
Inneuralnetworksthatdesignedtobebiologicallysimilar.Activationfunctionrepresentspotentialofneurontofireoncertainconditions.Basicneuroncangiveits’outputas1or0,butmoresophisticatedactivationfunctionsallowmorecomplexoutputs,likebetween0and1,whereoutputof0.3canmeanthattheneuronsurefor30%,thatisprobablynotenough,but0.9canmeanthattheneuronis90%sure.So,togetunderstandingonhowdiffersfunctionswewillreviewmostusedones.
9
2.8.1 Identity
Firstofall,goesthesimplestfunctionwhichislinear,thatisalsocalledIdentity.Themaindrawbackofthiskindofactivationfunctionisthatifweapplytwoormorehiddenlayers,theentirenetworkwouldbeequivalenttoasinglelayermodel.Alsothistypeofactivatorisunbounded,thatcreatesalackofnormalisation,whichisveryharmfulforcomputationprocessandformodelitself.
Tounderstandbetter,wewilltakealookathowoneIdentityneuronwillseparatethepointindataspace.
Wewillhaveasetofpointsmarkedas1andsetof0markedpoints.Afterlearningwasappliedweseethelineseparatessets.
Figurе 2: Logistic Regression – Stochastic Gradient Descent
Thelineseparatespointsverywell,unlesswehaveatrickiertask,likethis:
10
Figurе 3: Logistic Regression
Heresetscan’tbedividedbyoneline,soweneedtoapplysomecomplexsolution.Non-linearfunctionwouldfittheproblem.Multi-layerperceptronwithonehiddenlayerof200neuronspoweredwithsigmoidfunctionswillsolveit.
Figurе 4: Multi-layer Perceptron, w. 1 hidden layer, 70 units
2.8.2 Sigmoid
11
Figurе 5: Sigmoid graphic
Sigmoidisasmoothmonotonicnon-linearfunction,thathas“S”shapeandalwaysincrease.ItgainedpopularityinNeuralNetworksasanactivationfunctionduetoabilityincreaselowsignalsandnotgetoversaturatedfromhighsignals.Thefunctioncaninputsignalsfrom-∞to+∞andoutputssignalfrom0to1,thatmakesitperfectnormalisingfunction.Derivativeofsigmoidcanbeeasilyexpressedthroughthefunctionitself,thatsignificantlysimplifiesthebackpropagationprocess.[7]
Ontheotherhand,saturationofsigmoidfunctionisadrawback,becauseitkillsgradients.Gradientsthatcloseto0or1arealmostzero.Recallthatduringbackpropagation,this(local)gradientwillbemultipliedtothegradientofthisgate’soutputforthewholeobjective.Therefore,ifthelocalgradientisverysmall,itwilleffectively“kill”thegradientandalmostnosignalwillflowthroughtheneurontoitsweightsandrecursivelytoitsdata.Additionally,onemustpayextracautionwheninitializingtheweightsofsigmoidneuronstopreventsaturation.Forexample,iftheinitialweightsaretoolargethenmostneuronswouldbecomesaturatedandthenetworkwillbarelylearn.Orevenitispossiblethatsigmoidgiveirrelevantresults:
f’(a)=f(a)(1-f(a)),whenagoesinfinitelargef(a)canbecome1,so:
1*(1-1)=0
Also,sigmoidoutputsarenotzero-centred.ThisisundesirablesinceneuronsinlaterlayersofprocessinginaNeuralNetworkwouldbereceivingdatathatisnotzero-centered.Thishasimplicationsonthedynamicsduringgradientdescent,becauseifthedatacomingintoaneuronisalwayspositive,thenthegradientontheweightswillduringbackpropagationbecomeeitherallbepositive,orallnegative.Thiscouldintroduceundesirablezig-zaggingdynamicsinthegradientupdatesfor
12
theweights.However,noticethatoncethesegradientsareaddedupacrossabatchofdatathefinalupdatefortheweightscanhavevariablesigns,somewhatmitigatingthisissue.Therefore,thisisaninconveniencebutithaslesssevereconsequencescomparedtothesaturatedactivationproblemabove.
2.8.3 Tanh
Figurе 6: Tanh graphic
Thetanhnon-linearityisshownontheimageaboveontheright.Itsquashesareal-valuednumbertotherange[-1,1].Likethesigmoidneuron,itsactivationssaturate,butunlikethesigmoidneuronitsoutputiszero-centred.[7]Therefore,inpracticethetanhnon-linearityisalwayspreferredtothesigmoidnonlinearity.Alsonotethatthetanhneuronissimplyascaledsigmoidneuron,inparticularthefollowingholds:
tanh(x)=2σ(2x)-1
13
2.8.4 ReLU
Figurе 7: ReLU graphic
TheRectifiedLinearUnithasbecomeverypopularinthelastfewyears.Itcomputesthefunctionf(x)=max(0,x).Inotherwords,theactivationissimplythresholdedatzero.Itwasfoundtogreatlyacceleratetheconvergenceofstochasticgradientdescentcomparedtothesigmoid/tanhfunctions.Itisarguedthatthisisduetoitslinear,non-saturatingform.Comparedtotanh/sigmoidneuronsthatinvolveexpensiveoperations(exponentials,etc.),theReLUcanbeimplementedbysimplythresholdingamatrixofactivationsatzero.[7]
Ontheotherhand,ReLUcandie.Forexample,alargegradientflowingthroughaReLUneuroncouldcausetheweightstoupdateinsuchawaythattheneuronwillneveractivateonanydatapointagain.Ifthishappens,thenthegradientflowingthroughtheunitwillforeverbezerofromthatpointon.Thatis,theReLUunitscanirreversiblydieduringtrainingsincetheycangetknockedoffthedatamanifold.Forexample,youmayfindthatasmuchas40%ofyournetworkcanbe“dead”(i.e.neuronsthatneveractivateacrosstheentiretrainingdataset)ifthelearningrateissettoohigh.Withapropersettingofthelearningratethisislessfrequentlyanissue.
LeakyReLUcansolvethisproblembychangingthethresholdfrom0to0.01.
14
2.9 Types
2.9.1 FeedforwardNetwork
Sincethefirstsinglelayerperceptronwascreated,scientistsweretryingtosolvedifferenttypesofproblemswithit.Unfortunately,notalltheproblemscanbesolvedwithfeedforwardnetworks.TherewerecreatedseveraltypesofNeuralNetworkswithdifferentstructuresthatsolveproblemsofdifferentkinds.Tosaymoreabouttypesoftasksthatcanbesolvedwithneuralnetworksmostlyitsproblemswithpredictions.Ifweneedtopredictsomekindofeventinfutureifwehavesomeinformationaboutthepast,wewilluseNeuralNetworks.Butitisnottheonlycaseweusethem.UsingNeuralNetworks,wecanclassifygiveninformation,forecast,compressdata,makeassociativememory,etc.
TherearethreemaintypesofNetworks:FeedforwardNetworks,RecurrentNetworksandself-organisingmaps.AlsothereisanetworkcalledRadialBasisFunctionNetwork,butitdidn’tgetpopularity.
ANNsallowsignalstotravelonewayonly:frominputtooutput.Therearenofeedback(loops);i.e.,theoutputofanylayerdoesnotaffectthatsamelayer.Feed-forwardANNstendtobestraightforwardnetworksthatassociateinputswithoutputs.Theyareextensivelyusedinpatternrecognition.Thistypeoforganisationisalsoreferredtoasbottom-uportop-down.
Figurе 8: Multi-layer perceptron
Thelayers’structurecanvarytobeextremelylargeandcomplicated.Forexample,toaproblemofimagerecognitionwasinventedastructurecalledconvolutionalneuralnetwork,whereeachimagegetsdividedintoblocksofpixelsformanytimes.Ifpicturehasresolution4x4pixelsitcan
15
besplitin9blocksof2x2pixelsforfurtherprocessing.
Figurе 9: Convolutional Neural Nework
2.9.2 RecurrentNetwork
Recurrentnetworkscanhavesignalstravelinginbothdirectionsbyintroducingloopsinthenetwork.Feedbacknetworksarepowerfulandcangetextremelycomplicated.Computationsderivedfromearlierinputarefedbackintothenetwork,whichgivesthemakindofmemory.Feedbacknetworksaredynamic;their'state'ischangingcontinuouslyuntiltheyreachanequilibriumpoint.Theyremainattheequilibriumpointuntiltheinputchangesandanewequilibriumneedstobefound.
Figurе 10.1: Recurrent Network
Feedforwardneuralnetworksareideallysuitableformodellingrelationshipsbetweenasetofpredictororinputvariablesandoneor
16
moreresponseoroutputvariables.Inotherwords,theyareappropriateforanyfunctionalmappingproblemwherewewanttoknowhowanumberofinputvariablesaffecttheoutputvariable.Themultilayerfeedforwardneuralnetworks,alsocalledmulti-layerperceptron(MLP),arethemostwidelystudiedandusedneuralnetworkmodelinpractice.
Figurе 10.2 : Recurrent network
Asanexampleoffeedbacknetwork,IcanrecallHopfield’snetwork.ThemainuseofHopfield’snetworkisasassociativememory.Anassociativememoryisadevicewhichacceptsaninputpatternandgeneratesanoutputasthestoredpatternwhichismostcloselyassociatedwiththeinput.Thefunctionoftheassociatememoryistorecallthecorrespondingstoredpattern,andthenproduceaclearversionofthepatternattheoutput.Hopfieldnetworksaretypicallyusedforthoseproblemswithbinarypatternvectorsandtheinputpatternmaybeanoisyversionofoneofthestoredpatterns.IntheHopfieldnetwork,thestoredpatternsareencodedastheweightsofthenetwork.
2.9.3 LSTM
LSTMnetworksareoneofthemostinterestingtypesofnetworksandtheyarequitenewcomparingtoothertypes.Theywereinventedasareplacementofnormalrecurrentnetworksduetosomereasonableadvantages.Normalrecurrentnetworkswereakindofbreakthrough.However,theyalsohaddrawbacks.Oneofthemostsignificantdisadvantageswastheproblemofvanishing(orexploding)gradients.Themainideaisthattherecurrentnetworksworklessefficientlywithbiggeramountsofstepsrememberedbynetwork.AsasolutionforthisproblemwasinventedLongShort-TermMemoryunit.Inthismodelnormalneuronsarereplacedwithspecialunitsthathavequitecomplicatedstructurecomparingwithnormalneuralnetworks.LSTMunitshelptokeepanerrorthatcanbebackpropagatedthroughlayersandtime.Unlikenormalrecurrentnetworks,thatwould
17
behardtocalculateat100step,LSTMcanrememberover1000steps.LSTMscontaininformationoutsidethenormalflowoftherecurrentnetworkinagatedcell.Todatacouldbeappliedalltypesofoperations,like,writingorreading.Insidethecellthereisamechanism,thatwhenreceivestheinformationcandecidewhattodowithit.Itdecideswhetheritisnecessarytostoretheinformationoritcanbedeleted.Tomakesuchdecisionscellgateslearnonpractice,whichoperationsinwhichconditionsbroughtmoreprecisepredictionsinthepast.Thislearningprocessalsocoveredwiththesamemechanismofbackpropagation,mainlythisispossibleduetouniversalityofthebackpropagationalgorithm.[8]
Figurе 11: LSTM cell
2.9.4 Kohonen’sself-organizingmaps
Kohonen’sself-organizingmaps(SOM)representanotherneuralnetworktypethatismarkedlydifferentfromthefeedforwardmultilayernetworks.UnliketraininginthefeedforwardMLP,theSOMtrainingorlearningisoftencalledunsupervisedbecausetherearenoknowntargetoutputsassociatedwitheachinputpatterninSOMandduringthetrainingprocess,theSOMprocessestheinputpatternsandlearnstoclusterorsegmentthedatathroughadjustmentofweights(thatmakesitanimportantneuralnetworkmodelfordimensionreductionanddataclustering).Atwo-dimensionalmapistypicallycreatedinsuchawaythattheordersoftheinterrelationshipsamonginputsarepreserved.Thenumberandcompositionofclusterscanbevisuallydeterminedbasedontheoutputdistributiongeneratedbythetrainingprocess.Withonlyinputvariablesinthetrainingsample,SOMaimstolearnordiscovertheunderlyingstructureofthedata.
18
Figurе 12: Kohonen’s SOM
TheseNeuralnetworkarethebasicones.Onthetopofthempeopleconstructmoresophisticatednetworksformoretighttypeofproblems.Todealwiththetopicwedon’tneedtoknowsomesortofspecificnetwork,weneedtosucceedworkingwithoneofthosearementioned.Atsomepointwemayunderstandthatwemayneedsomesortofspecificstructure,butitwouldbeamatterofanexperiment,becausemostofthenetworksaresomehowunique.Moreover,everydaywepeopleinventnewstructuresworkingontheirgoals.
2.10 Learningprocedureoffeed-forwardnetwork
TounderstandhowneuralnetworkslearnwewilltakeanexampleofAndrewTrask.Thegoaloftheexperimentwouldbeteachingcomputerstatisticaltorecogniseinputsandpredictoutcome.Todosowewillfeedtothenetworkseveralcombinationsof3inputdigitswhereeachcanbe1or0,andoneoutputdigit1or0.ReviewingthesimplestprocessoflearningofNeuralNetworkswearegoingtowriteacodeinPythonprogramminglanguage,whichisquitesimpletounderstandandaneffectivetoolforprototyping.Themodelwewanttobuildistwolayer-perceptron.TomultiplyandprocessmatrixeswewilluseNumPylibraryforPython.Wewillusesigmoidasactivationfunction.Back-propagationwillcoverthelearningprocess.[9]
19
Firstofall,weneedtodefineSigmoidfunction.Sigmoidisdefinedasformula
S(t)=1/(1+e^-t)
Forbackpropagationalgorithmweneedtodefinethederivativeofsigmoidfunction.Asitwassaidalreadysimplesigmoidderivativeisoneofmainreasonsofsigmoidpopularity.Thederivativecanbewrittenas
S’(t)=t*(1-t)
Itisobviousthatderivativeofsigmoidismucheasiertocalculatethantheoriginalfunction.
NowweanttowritethesigmoidasaPythonfunctionthatcanbeusedinprogram.Wewilldoitinawaythatonefunctionwillbeusedtocalculatesigmoidandderivativeofit.Tocalculatesigmoidwillbeusedsuchform:nonlin(x),wherexisavariableneededtopassthroughsigmoid.Ifweneedtoknowtheoutcomeofderivativewerequest
nonlin(x,deriv=True)defnonlin(x,deriv=False): if(deriv==True): returnx*(1-x) return1/(1+np.exp(-x))
Nextwearegoingtodefineinputsandoutputs.Asitwasmentionedbeforetheinputdatashouldbenormalised.But,ourtaskdoesnotrequiredigitsmorethanoneandlessthanzero.
Forourtaskweneed3inputnodes,1outputnodeand4hiddenneurons.Wearegoingtofeedtoosmallbatchofinformation,butweaimtofeeditacoupleofthousandstimes.Theinputbatchwilllooklikeamassiveof3columnsand4rows.3columnsmeanthatinfirstrowwehave3digitsthatare3inputs.Wewillhave4teachingexamples,sothatwehave4rows.Outputwilllooklikeanarrayof1columnand4rows:oneoutputforeachoffourexamples.Xwouldbetheinputsandyoutputs.
X=np.array([[0,0,1], [0,1,1], [1,0,1], [1,1,1]])y=np.array([[0], [1], [1], [0]])
20
Between3layerswewillhave2setsofweightconnections.Firstitisnecessarytoinitialisethemwithrandomvaluestobreakthesymmetryandpreventequalweightsafterlearning.Theweightsmatrixeswewillcallsynapses.Tocreatetwosynapses,wewillrunthefollowingcode:
syn0=2*np.random.random((3,4))-1syn1=2*np.random.random((4,1))-1
Afterthatpreparationsareready,nowwestartaloopof60thousandrepetitions,allthecodeafterthatwillbeinsideofaloopandwillrunalongtheprogramworks
forjinxrange(60000):
Firstofallweneedtofeedforwardournetworkwithgivensequences.Layer0willinputthefeedbatchmatrix3by4.Thesecondlayermarkedasl1willbearesultofmatrixmultiplicationoflayer0withweightsofthefirstsynapseandapplicationofsigmoidfunctiontothat.Theprocessofcalculationofthelastlayerissimilarbutworkswiththesecondlayerandthesecondsynapse.
l0=X
l1=nonlin(np.dot(l0,syn0))l2=nonlin(np.dot(l1,syn1))
Sincetheoutputlayervaluesnowchangedandhave1;4dimensions,wewanttocheckhowmuchourresultsaredifferentfromwhatwereallywant.InPythonlanguageitisveryeasytoworkwithmatrixes,sowejustsubtractonefromanotherone.
l2_error=y-l2
21
Figurе 13: Derivatives for sigmoid function
Bytheendoftheloopcycleweneedtoeditweightsbysomevalue,sothenexttimetheywillmakemoreaccuratepredictions.Butfirstofallweneedtofindavaluetochangetheexistingweights.ForthatwewilluseamethodcalledTheErrorWeightedDerivative.Wewillapplythismethodtothefirstandthesecondlayers.Theideaofthistechniqueisverysimple.Ifwegetaderivativeofavalue,wegetanangleofaslope.Afterthat,multiplying“slope”bytheangle,wecanreducetheerrorofhighlyconfidentialpredictions.
Forexample,ifthetheslopeisparalleltoabscissa,thenetworkeitherhaveveryhighvalueorverylow.Thismeansthatthenetworkisquitesurethatinpositiveornegativeway.Ontheotherhand,iftheangleisquitesteep,thevalueisneartox=0,y=0.5,forinstance,thismeansthatthenetworkisnotconfidentatall.So,weneedtoforceittomakeachoicetomoreconfidentdecisions.
l2_delta=l2_error*nonlin(l2,deriv=True)
Afterthatwecalculatetheerrorforthefirstlayer.Todosoweuse"confidenceweightederror"froml2toestablishanerrorforl1.Itsimplysendstheerroracrosstheweightsfroml2tol1.Thisgiveswhatyoucouldcalla"contributionweightederror"becausewelearnhowmucheachnodevalueinl1"contributed"totheerrorinl2.
l1_error=l2_delta.dot(syn1.T)
22
Nextwearegettingdeltaforlayer1aswedidforthelayer2.
l1_delta=l1_error*nonlin(l1,deriv=True)
Intheendweaddthevalueswecalculatedtosynapses0and1justmultiplyinglayerandcorrespondingdelta.
syn1+=l1.T.dot(l2_delta)syn0+=l0.T.dot(l1_delta)
Thisisagoodexampleofsimplefeedforwardperceptronwithbackpropagationlearningalgorithm.
2.11 Commonlyusedframeworks
Neural networks are quite complicated tools to use. They requireunderstandinglotsofmathematicsandlogics.Also,itisnecessarytoknowprogramming tomaintain in computing. Basic high level languages likePythonorPascalcanbeappropriateonlyinstudyingstage,iftheuserofneuralnetworksneedtobuildhisownnetworkandprogramit,itisveryimportanttoknowfastlow-levellanguage,likeC,C++orGOatleast.Also,some knowledge aboutUnix-like systems and possibilities to parallelizecomputingtaskswoulddefinitelyhelptheresearchertosolvehistasksindeadline.Thelistofrequirementstouserisquitebig,andthatcankeepoutlotsofresearchersfromtasksofmachinelearninganddeeplearninginparticular.Also,writingnewcodetoexperimentwithneuralnetworkswouldtakelotsoftime.Researchersstartedtobuildframeworksandopen-sourcethemtopopulate this fieldof studies andalso, to get supportof researchersfromallovertheworld.Basicallymostoftheframeworksarebuildinhigh-levellanguagesasfront-endtogivemoreflexibilityandsupportaccesstoGPUparallelism,whichisthemostefficientwaycalculatingmatrixesthesedaysandgivefrom10to40timesincreaseinlearningrateofneuralnetwork.[10]Thefront-endlanguage is used for prototyping and it is usually Python, due to itspopularity, flexibilityandsimplicity.C++ is theback-end language inthemostpopularframeworks.Thecompilationprocesstakesveryshorttimeandtheprogrambuildwithitrunsveryfast.
3 MATERIALSANDMETHODS
23
Thetaskofautopilotingwithneuralnetworksisquitepopularthesedays,mostlyitisusedonlyintermsofdriver-lesscars.Buildingpilot-lessplaneismuchmore complicated and responsible task. Car autopilot dependsmoreonpicture recognition tasks,whileplane task requiresmoredatafrom sensors and not deal with image processing at all, except tasksrelatedtolandingandtakingoff,wherepilotactivelyobservecurrentstateof environment. Between landing and taking off pilot is guidedonly bysignalsofsensorslikeGPS,heading,altitudeindicators.Since plane automation development is quite time and resourceconsuming task, the best idea for developing auto pilot is to use planesimulator.
3.1 Planestablingtask,basicconcept
Stable flight is one of the basic routine of a flight. We can divide thesimplifiedflightalgorithminto5parts:takingoff,alignmenttothecourse,keepingthecourse,preparingtolanding,landingitself.Tokeepthecourseit is needed to stay stable during the flight. This can be achieved bycontrollingsimplesetofvariables.Tosetourtaskmoreobvioustosolve,lets define its goal as a stable flight, opposite to crashing.Wewill nothardlyfocusonthewaytheplanegoes,butatthesametimewedonotneedtheplanetoflybyrounds.Tokeeptheplaneflyingwerequestsuchvariablesas:3-axisacceleration,altitude, pitch, roll, turn rate, airspeed. This set of variables can beassumedasanenvironmentalfeedbackonouractions.Also,itwouldbeagood practice to monitor the current states of flight control systems:throttling,aileron,elevatorandrudder.Thefirstsetofvariableswecancalloutputsandthesecondinthiscasewillbeinputs.Mainly,weareconsideringtheenvironmentasadynamicsystemthatrespondsuswithitsstatechangeaccordingtoouractions.Ifwechangesomeoutputlikewewillturnrightwithelevator,thesystemwill respond us with decreasing height and increasing turn rate. Thisconcept can be called Proactive: we do something and environmentresponduswithsomethingelse.Thisconceptcouldbehelpfulifwehaveafewoptionsandwecanpredictthefuturewiththem,andchoosethebestoptionforus.But,ontheotherhand ifwehavetoomanyoptionscalculatingeachoneinbulkwillconsumetimeandresourcesgreaterthanallowed.Inthiscasewehavetochangeinputandoutputinplaces.NowitwillbeaReactiveapproach.Wewillinputcurrentenvironmentstatesandproduceoutputasasetofchangesweneedtoapplytoaileron,elevatororrudder.
24
So,now,theinputwouldbeenvironmentalstatesandtheoutputwillbethechangeneededtoapplytocontrolsystems.
3.2 Planestablingtaskindetails
As it isstatedalreadywearegoingtotakeseveralvariablesfromFlightGear to develop our piloting system. Stepping forwardwewill take allsomehow relevant variables from Flight Gear. It is not necessary, butneural networks tend to pull out all information from inputs andindependentlydecidewhichinformationisrelevantandwhichisnot.Iftheinputinformationnotaffectstheoutputs,itwillnotscrewupourresults,furthermore itwillbepossible todefinewhichdata is irrelevanton thelaterstepsanditcanberetrainedwithoutuselessinputs.Sothefulllistofvariablesweneedis:1. 3-axisacceleration2. Altitude3. Pitch4. Roll5. Aircraftspeedrelativelytotheground6. Turnrate7. Verticalspeedindicator8. Airspeed9. Throttle10. Aileron11. Elevator12. RudderTokeepstableflyitisneededtokeepallthevariablesfrom1to8staythesamechangingvariablesfrom9to12.
25
Figurе 14: Pitch, roll and yaw Axis
ThemainvariablesherearePitchandRolltheycontrolthatplaneisparalleltotheground.IftheplaneisstableinPitch,Roll,HeightandTurnrate,thatmeansthat itmovesstraight.Airspeeddeterminesthespeedofaircraftrelativelytotheairaround.Windpresencealsoaffectthisindicator.Sincewindaffectsmovingaircraftveryhigh,pitchandrollmaybedifferentwiththesamethrottle,aileron,elevatorandrudder,forsuchareasonweneedtohavetoknowasmuchaspossibleaboutwindaffectontheaircraft.Forsuchreasonweneedadditionalvariableslike3-axisacceleration,groundand vertical speed. These additional information gives enoughrepresentationofwhatisgoingonaroundtheplane.
3.3 Planesimulation
FlightGearsimulatorwaschosenfordevelopment.Itisopen-sourcedandhasquitelargedevelopercommunity.Forthetaskofstablingtheplaneweneedseveralpropertiesofthecurrentstateofaplane,thatcomedirectlyfromplanesensorindicators.Allthevariablesdescribedin3.2canbeextractedfromtheprogram.Flight Gear have convenient mechanism of extracting and importingvariables,thatletsdevelopersmaketheircontrolsystemsoutsideoftheprogramonthefly.Allthevariablesthatcanbeextractedandchangedare
26
storedinamodulecalledProperty-tree.Theaccesstothepropertytreecanbeobtainedthrough“native”and“generic”protocols.Firstonegivesaccesstothepropertytreefrommemory,thatcanbecapturedfromsidedC++program.ThesecondoneopensaccessthroughUDPprotocoloroverSerialport.
Figurе 15: Property-tree in Flight Gear
UsingUDPwecanrunaserveronthehostmachineandthecontrollingmachine can capture the information if it is in local network, or evenoutside of it. Serial port can be used to connect low-level devices likeArduino,RaspberryPiorotherdevicesthathaveGPIOextensionslotontheboard.Tousetheseoptions,itisnecessarytocreateaXMLfilewithaverysimplestructure.<?xmlversion="1.0"?><PropertyList><generic><output><line_separator>newline</line_separator><var_separator>,</var_separator>
27
<chunk><name>pilot-gdamped</name><type>float</type><node>/accelerations/pilot-gdamped</node><format>%f</format></chunk> …<chunk><name>airspeed-kt</name><type>float</type><node>/velocities/airspeed-kt</node><format>%f</format></chunk></output><input><chunk><name>throttle</name><type>float</type><node/controls/engines/engine[0]/throttle</node><format>%f</format></chunk></input></generic></PropertyList>It iseasytounderstandameaningofeach line inthecode.Thecode isdividedintotwoparts:inputandoutput.Inputsectiondefinestheinputprotocolandtheoutputdefinestheoutputrules.Themostinterestingpartisthe“chunk”statement.Amountofchunksiscorrelatedwithamountofpropertieswearegoingtoworkwith.Insideachunknamecanberandomanddoesn’tplayroleintheresult.Typemeansthetypeofrepresentationofavalue.Itcanbefloat,integerorbool,dependsonhowwewilluseit.InsidethenodeisstoredthepathtoapropertyinsideofthePropertytree.Ifthevalueisneededtobemultipliedorconvertedtheruleisdefinedinthissection.Torungenericprotocol,itisneededtoruntheFlightGearprogramwithflags
--generic=socket,out,10,127.0.0.1,49001,udp,outputprotocol--generic=socket,in,10,,49000,udp,inputprotocol
28
Firstflagisforexportingdatafromtheprogram.Firstparameterisalways“socket”. Secondparameterdefineswhether the flag is for inputor foroutput.Onthe3rdplacedigitdefinesamountofpackageswithdatawouldbesentorreceivedinasecond.NextgoesIPaddressandportnumberofthemachinethatisgoingtoreceivethepackages.Inputprotocoldoesn’tneedtohaveIPaddress.OnthelastplacestandsthenameoftheXMLfilecontainingtheprotocol instructionswithout“.xml”ending.TheXMLfileshouldbeplacedintothe/data/ProtocolfolderundertherootoftheFlightGear.TheoutputofthefileinAppendix1islookinglikethat:0.910101,1.000,0.000,0.150,0.050,1148.926025,3.260596,-0.272000,28.521667,0.043057,4.652739,114.134407,56.8938940.908808,1.000,0.000,0.150,0.050,1152.446167,3.008736,0.216146,28.492014,0.051938,4.457239,114.064537,56.915268ThePythonprogramthatreceivedpackagesisunderAppendix2.
3.4 DataprocessingfortheANN
Toprocessthedata,weneedtodefinethealgorithmofthenetwork.Forthetaskofstablingtheplaneintheairwearegoingtoexportsomedatafromthesimulationprogram,learntheArtificialNeuralNetworkandafterthatdeploythelearnedmodelunderextensivecomputertocontroltheplanebythelearnedalgorithm.To learn themodel,we need to define the roles of each variables andnormalize them.Someof thevalues, like turnrateandaccelerationarealreadyfinevaluestoputinaneuralnetwork,excepttheyareneededtoputunder-1;1or0;1frame,sowewilldefinetheframestheyarealreadyexistanddividebythebiggestvalueexistingforthatvariable,ofcoursewithout“-“.ValueslikePitch,Roll,Aircraftspeedswearegoingtocomparewithvaluesontheprevioustimestamp,calculatethedeltaforthevaluesand,finally,normalizeit,likewedidbefore.Assoonasourelevator,aileronandruddershouldbethereactiononthepreviouslyhappenedchangesinotherproperties,wearegoingtocalculatethedelta for themcomparingcurrentand thenext timestamp.So,asaresultwehavesuchdatasetmap.
29
Figurе 16: Timestamp dataset development
Thetimestampdatasetsampleisrepresentedasaccelerationandturnrateastheyareatcurrenttimestamp.Aileronandelevatorcanberepresentedas the difference between previous timestamp or also as they are atcurrent.Altitude,pitch, roll,groundspeed,vertical speedandair speedcanberepresentedasdifferencebetweentwotimestamps,currentandprevious. To simplify learning process, we can get rid of throttle andrudder,sothedifferencebetweennexttimestepandcurrentforaileronand elevator can represent label samples that can be reactions for thesituationincurrenttimestamp.The Python program-library that content functions for converting rawdatasetintonewdatasetwithdatadescribedaboveforCaffeframeworkcanbefoundinAppendix3.
3.5 JetsonTX1
NvidiaJetsonTX1willfittherequirementforcontrollingcomputer.Ithas256 GPU cores that are perfect for processing matrix and computingArtificialNeuralNetworks inparticular. It runsspecialLinuxdistributive,modifiedUbuntu. ItsupportsCUDAandCudnnlibrariesfromthebox. IthasGPIO,thatcanbeusedforserialportconnectiontohostcomputer.ToconnecthosttoJetsonneededtohaveUSB-TTLcable.ArduinoNanocanbeusedasaUSB-TTLconnector.ItisneededtoconnectRSTwithGNDpinson theArduino,GNDpinofArduino shouldbe connected to groundofJetson,TXpinoftheArduinoshouldbeconnectedtoRXofJetsonandRXoftheArduinotoTXofJetson.Afterthatserialportwillbeopenon115200baudrate.
3.6 ArtificialNeuralNetwork
By the moment of writing the thesis the most advanced, communitysupportedandwelldocumentedANNlibraryisTensorFlow.Unfortunately,itisnotworkingwellonJetsonduetocomplexityofinstallationforthatplatform.Alternatively,Caffecanbeused.
30
Thenetworkcontains3files:datasetforlearning,prototxtfiledescribingthe ANN model, prototxt file describing working process of learning,testinganddeploying.Because the flight control is not a single event process the best choicewouldbetouseLSTMnetwork,sinceitcanrememberlongsequencesofevents.Unfortunately,byNovemberCaffeframeworkcommunitydoesn’thavedocumentationforusingLSTMcells.Alternatively,simpledeepfeed-forwardnetworkcanbeused.Appendix4and5containstheprototxtfilesforbuildingdeepfeedforwardnetwork.
3.7 Learningprocess
After capturing the data started theprocess of learning can takeup toseveraldays.Gathering4samplesasecondwillgive14.400samplesanhour. Tomake sure that the neural networkwill remember better it isnecessarytotakeatleast100.000samples,whichwillrequiremoretime.Moreover, the learningprocesswill requestmaximumattention fromateacheralongtheway.IncaseLSTMcellswereused,thenetworkwillcopyallthemannertheteacherpilotingtheplane.
4 CONCLUSION
Thetopicofartificialneuralnetworksisaroundaircraftsforawhile,buthow alreadywasmentioned it takes huge amount ofwork and lots ofresponsibilities to build up a project from scratch to real-lifeimplementationonworkingprototypes.Itisabsolutelynecessarytocontinuetheprojectinfuturesinceartificialneuralnetworks are coming intoour livesquitedeeply,with increasingcomputing powers and development of Artificial Intelligence. Suchsystemsbutinmorecompleximplementationswilldefinitelyconquerthemarket,notonlytheAircraftsbutalsoothercontrollingsystems.Theproofis Google implementations in car control systems, that already drivewithoutdriveronstreetsofCalifornia.
5 FUTUREWORK
31
ThecurrentimplementationwithLSTMcellsseemstobeverypromising.Butevennow it requiressomesortof teacherpresentedatall learningtime. Thepossible and cleverwaywouldbeautomationof theprocesswithReinforcementlearningtechnology,whereprogramreceivingsomefeedbackfromcontrolledsystem,sothatitcanlearnnotonlywhatactionsaregood,butatthesametimeitcanlearnwhatisharmfulforthesystem.Ontheotherwaysuchwayoflearningcannotbeimplementedinmoreexpensiveplanes.Itwillrequireatleastsomepeoplepresentonaplanetocontrolthelearningprocessfromdestroyingfacilities.The other goodwaywould be to start implementing only the learningsystems with different specifications, for example, if every plane thatperformsfliesthesedayswillbeequippedwithsuchasystem,infuturewewillhavelotsofdatathatcanbeusedtoteachsuchsystems.Afterthatimplementation LSTM with reinforcement modules to pilot-less planesmayforcesuchsystemstoevolve.
32
REFERENCES
1. Stanford - Artificial Neuron. (n.d.). Retrieved November 27, 2016, fromhttps://cs.stanford.edu/people/eroberts/courses/soco/projects/neural-networks/Neuron/index.html
2. Karpathy, A., PhD. (n.d.). Hacker's guide to Neural Networks. RetrievedNovember27,2016,fromhttp://karpathy.github.io/neuralnets/
3. Single-layerNeuralNetworks(Perceptrons).(n.d.).RetrievedNovember27,2016, fromhttp://computing.dcu.ie/~humphrys/Notes/Neural/single.neural.html
4. How the backpropagation algorithm works, chapter 2. (n.d.). RetrievedNovember 27, 2016, fromhttp://neuralnetworksanddeeplearning.com/chap2.html
5. MNIST For ML Beginners. (n.d.). Retrieved November 27, 2016, fromhttps://www.tensorflow.org/versions/r0.7/tutorials/mnist/beginners/index.html
6. DeepDrive - self-driving carAI. (n.d.). RetrievedNovember 27, 2016, fromhttp://deepdrive.io/
7. Convolutional Neural Networks for Visual Recognition. (n.d.). RetrievedNovember27,2016,fromhttp://cs231n.github.io/neural-networks-1/
8. Convolutional Neural Networks for Visual Recognition. (n.d.). RetrievedNovember27,2016,fromhttp://cs231n.github.io/neural-networks-1/
9. ANeuralNetworkin11linesofPython(Part1).(n.d.).RetrievedNovember27, 2016, from http://iamtrask.github.io/2015/07/12/basic-python-network/
10. CUDASpotlight:GPU-AcceleratedDeepNeuralNetworks.(2015).RetrievedNovember 27, 2016, from https://devblogs.nvidia.com/parallelforall/cuda-spotlight-gpu-accelerated-deep-neural-networks/
33
Appendix1
ContentsofXMLinput/outputfile<?xmlversion="1.0"?><PropertyList><generic><output><line_separator>newline</line_separator><var_separator>,</var_separator><chunk><name>pilot-gdamped</name><type>float</type><node>/accelerations/pilot-gdamped</node><format>%f</format></chunk><chunk><name>throttle</name><type>float</type><node>/controls/engines/engine[0]/throttle</node><format>%f</format></chunk><chunk><name>aileron</name><type>float</type><node>/controls/flight/aileron</node><format>%f</format></chunk><chunk><name>elevator</name><type>float</type><node>/controls/flight/elevator</node><format>%f</format></chunk>
34
<chunk><name>rudder</name><type>float</type><node>/controls/flight/rudder</node><format>%f</format></chunk><chunk><name>indicated-altitude-ft</name><type>float</type><node>/instrumentation/altimeter/indicated-altitude-ft</node><format>%f</format></chunk><chunk><name>indicated-pitch-deg</name><type>float</type><node>/instrumentation/attitude-indicator/indicated-pitch-deg</node><format>%f</format></chunk><chunk><name>indicated-roll-deg</name><type>float</type><node>/instrumentation/attitude-indicator/indicated-roll-deg</node><format>%f</format></chunk><chunk><name>ns-velosity-msec</name><type>float</type><node>/instrumentation/gps/ns-velocity-msec</node><format>%f</format></chunk><chunk><name>indicated-turn-rate</name><type>float</type><node>/instrumentation/turn-indicator/indicated-turn-rate</node><format>%f</format></chunk><chunk><name>vertical-speed-indicator</name><type>float</type><node>/instrumentation/vertical-speed-indicator/indicated-speed-mps</node><format>%f</format>
35
</chunk><chunk><name>airspeed-kt</name><type>float</type><node>/velocities/airspeed-kt</node><format>%f</format></chunk><chunk><name>heading</name><type>float</type><node>/instrumentation/heading-indicator/indicated-heading-deg</node><format>%f</format></chunk></output><input><chunk><name>Inthrottle</name><type>float</type><node>/controls/engines/engine[0]/throttle</node><format>%f</format></chunk><chunk><name>Inaileron</name><type>float</type><node>/controls/flight/aileron</node><format>%f</format></chunk><chunk><name>Inelevator</name><type>float</type><node>/controls/flight/elevator</node><format>%f</format></chunk><chunk><name>Inrudder</name><type>float</type><node>/controls/flight/rudder</node><format>%f</format></chunk></input>
36
</generic></PropertyList>
Appendix2PythonprogramforreceivingFlightGeardataimportsocketUDP_IP="127.0.0.1"UDP_PORT=49001sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)#UDPsock.bind((UDP_IP,UDP_PORT))counter=0dataset=85data=[]dataToFlush=''whileTrue: dataInput,addr=sock.recvfrom(1024) dataRawList=str(dataInput).split(',') dataRawList[1]=dataRawList[1][:5] dataRawList[2]=dataRawList[2][:5] dataRawList[3]=dataRawList[3][:5] dataRawList[4]=dataRawList[4][:5] print('|ail: ',dataRawList[2],'|el: ',dataRawList[3],'|rud:',dataRawList[4],'|hgt:',dataRawList[5],'|head:',dataRawList[12],'\n') dataToFlush+=','.join(dataRawList)+'\n' counter+=1 ifcounter==240: dataset+=1 counter=0 withopen('dataset'+str(dataset)+".txt",'w')asfile: file.write(dataToFlush) dataToFlush=''
Appendix3ContentsofPythonlibraryforpreparingdataforCaffe
37
importnumpyasnpimportdeepdishasdd#lolnp=np.array(lol,dtype='float64')defdeleteCols(array,liOColl): liOColl.reverse() foriinliOColl: array=np.delete(array,np.s_[i:i+1],1) returnarraydefdelta(di,nu):prev=float(di[0][nu])max1=min1=float(di[1][nu])-float(di[0][nu])foriindi:cdel=float(i[nu])-previfcdel>max1:max1=cdelifcdel<min1:min1=cdelprev=float(i[nu])return([min1,max1])defminmax(di,nu):min1=float(di[0][nu])max1=float(di[0][nu])foriindi:iffloat(i[nu])<min1:min1=float(i[nu])iffloat(i[nu])>max1:max1=float(i[nu])return([min1,max1])defgetparams(indi): #out=np.zeros(len(indi)-2,len(indi[0])) out1data=np.zeros([1,10],dtype=float) out1label=np.zeros([1,2],dtype=float) foriinrange(len(indi)-1): ifi==0: continue #tm1=indi[i-1]
38
#t=indi[i] #tp1=indi[i+1] curr=indi[i] d1=indi[i]-indi[i-1] d2=indi[i+1]-indi[i] single=np.array([[curr[0],curr[1],curr[2],d1[3],d1[4],d1[5],d1[6],curr[7],d1[8],d1[9]]]) singlelabel=np.array([[d2[1],d2[2]]]) out1data=np.append(out1data,single,axis=0) out1label=np.append(out1label,singlelabel,axis=0) return([np.delete(out1data,np.s_[0:1],0),np.delete(out1label,np.s_[0:1],0)])defdivideAlongAxis(array,column,num): foriinarray: i[column]=i[column]/num returnarraydefminMaxColumn(array,column): return([np.min(array[:,column]),np.max(array[:,column])])defmultiDivideAlongAxis(array,column,num): newarray=array forninrange(len(column)): newarray=divideAlongAxis(newarray,column[n],num[n]) returnnewarraydefmakeh5(data,labels): iflen(data)==len(labels): X=np.zeros((len(data),1,1,len(data[0]))) y=np.zeros((len(labels),len(labels[0]))) foriinrange(len(data)): forlinrange(len(data[0])): X[i][0][0][l]=data[i][l] forlinrange(len(labels[0])): y[i][l]=labels[i][l] print('Donecreating') dd.io.save('test.h5',{'data':X,'label':y},compression=None) print('Donewriting') return([X,y])defmakeh5_2d(data,labels): X=data y=labels dd.io.save('2ddata.h5',{'data':X,'label':y},compression=None) return0
39
Appendix4PrototxtfilecontainingdescriptionofnetworkforCaffename:"DeepNet"layer{name:"input"type:"HDF5Data"top:"data"top:"label"include{phase:TRAIN}hdf5_data_param{source:"way/to/dataset.h5"batch_size:64}}layer{name:"ip1"type:"InnerProduct"bottom:"data"top:"ip"inner_product_param{num_output:10}}layer{name:"Sigmoid1"type:"Sigmoid"bottom:"ip1"top:"Sigmoid1"}layer{name:"ip2"type:"InnerProduct"bottom:"Sigmoid1"top:"ip2"inner_product_param{num_output:20}
40
}layer{name:"Sigmoid2"type:"Sigmoid"bottom:"ip2"top:"Sigmoid1"}layer{name:"ip3"type:"InnerProduct"bottom:"Sigmoid2"top:"ip3"inner_product_param{num_output:10}}layer{name:"Sigmoid3"type:"Sigmoid"bottom:"ip3"top:"Sigmoid1"}layer{name:"loss"type:"SigmoidCrossEntropyLoss"#"SoftmaxWithLoss"bottom:"Sigmoid3"bottom:"label"top:"loss"}
Appendix5PrototxtfilecontainingdescriptionofsolverforCaffe#reducelearningrateafter120epochs(60000iters)byfactor0f10#thenanotherfactorof10after10moreepochs(5000iters)#Thetrain/testnetprotocolbufferdefinitionnet:"way/to/model.prototxt"#test_iterspecifieshowmanyforwardpassesthetestshouldcarryout.test_iter:10#Carryouttestingevery1000trainingiterations.test_interval:1000#Thebaselearningrate,momentumandtheweightdecayofthenetwork.
41
base_lr:0.001momentum:0.9#weight_decay:0.004#Thelearningratepolicylr_policy:"step"gamma:1stepsize:5000#Displayevery100iterationsdisplay:100#Themaximumnumberofiterationsmax_iter:60000#snapshotintermediateresultssnapshot:10000snapshot_prefix:"examples/example_sigmoid"#solvermode:CPUorGPUsolver_mode:GPU