匿名用户2021年11月17日
79阅读

技术信息

授权协议
MIT License

作品详情

LambdaNet

LambdaNetisaartificialeuraletworklibrarywritteiHaskellthatabstractsetworkcreatio,traiig,aduseashigherorderfuctios.Thebeefitofthisapproachisthatitprovidesaframeworkiwhichusersca:

quicklyiteratethroughetworkdesigsbyusigdifferetfuctioalcompoetsexperimetbywritigsmallfuctioalcompoetstoextedthelibrary

Thelibrarycomeswithapre-defiedsetoffuctiosthatcabecomposedimaywaystooperateoreal-worlddata.Thesewillbeeumeratedlaterithedocumetatio.

CurretRelease

Thecodefromthisrepodoes'treflectthecurretreleaseofLambdaNet.TheREADMEforthecurretreleaseoHackagecabefoudhere.

Istallatio

ThefirststepistofollowtheHMatrixistallatioistructios.Afterthat,LambdaNetcabeistalledthroughCabal:

cabalupdatecabalistallLambdaNetIstalligtheMostRecetBuild

Alteratively,youcausetheightly.TheAPImaybedifferetthawhatiscovereditheREADME,buttheexamples/folderwillalwayscotaiaworkigfileusigallthefeaturesofthecurretcommit.

Toistalltheightlybuild,simplyru:

gitcloehttps://github.com/jbarrow/LambdaNet.git&&cdLambdaNetcabalistallUsigLambdaNet

UsigLambdaNettorapidlyprototypeetworksusigbuilt-ifuctiosrequiresolyamiimallevelofHaskellkowledge(althoughgettigthedataitotherightformmaybemoredifficult).However,extedigthelibrarymayrequireamorei-depthkowledgeofHaskelladfuctioalprogrammigtechiques.

YoucafidaquickexampleofusigtheetworkiXOR.hs.OceLambdaNetisistalled,dowloadXOR.hs,adtheyoucaruthefileiyourREPLtoseetheresults:

ruhaskellexamples/XOR.hs

TherestofthissectiodissectstheXORetworkiordertotalkaboutthedesigofLambdaNet.

TraiigData

Beforeyoucatraioruseaetwork,youmusthavetraiigdata.Thetraiigdataisatupleofvectors,thefirstvaluebeigtheiputtotheetwork,adthesecodvaluebeigtheexpectedoutput.

FortheXORetwork,thedataiseasilyhardcoded:

lettraiData=[(fromList[0.0,0.0],fromList[0.0]),(fromList[0.0,1.0],fromList[1.0]),(fromList[1.0,0.0],fromList[1.0]),(fromList[1.0,1.0],fromList[0.0])]

However,forayo-trivialapplicatiothemostdifficultworkwillbegettigthedataithisform.Ufortuately,LambdaNetdoesotcurretlyhavetoolstosupportdatahadlig.

LayerDefiitios

Thefirststepicreatigaetworkistodefiealistoflayerdefiitios.Thetypelayerdefiitiotakesaeurotype,acoutofeurosithelayer,adacoectivityfuctio.

Creatigthelayerdefiitiosforathree-layerXORetwork,with2eurositheiputlayer,2hiddeeuros,ad1outputeurocabedoeas:

letl=LayerDefiitiosigmoidNeuro2coectFullyletl'=LayerDefiitiosigmoidNeuro2coectFullyletl''=LayerDefiitiosigmoidNeuro1coectFullyNeuroTypes

Aeuroissimplydefiedasaactivatiofuctioaditsderivative,adtheLambdaNetlibraryprovidesthreebuilt-ieurotypes:

sigmoidNeuro-AeurowithasigmoidactivatiofuctiotahNeuro-AeurowithahyperbolictagetactivatiofuctiorecluNeuro-Aeurowitharectifiedliearactivatiofuctio

BypassigoeofthesefuctiositoaLayerDefiitio,youcacreatealayerwitheurosofthattype.

Coectivity

Acoectivityfuctioisabitmoreopaque.Curretly,thelibraryolyprovidescoectFully,afuctiowhichcreatesafullycoectedfeed-forwardetwork.

Simply,thecoectivityfuctiotakesitheumberofeurosilayerladtheumberofeurosilayerl+1,adretursabooleamatrixofitegers(0/1)thatrepresetsthecoectivitygraphofthelayers--a0meastwoeurosareotcoectedada1meastheyare.Thestartigweightsaredefiedlater.

CreatigtheNetwork

ThecreateNetworkfuctiotakesiaradomtrasform,aetropygeerator,adalistoflayerdefiitios,adretursaetwork.

FortheXORetwork,thecreateNetworkfuctiois:

let=createNetworkormals(mkStdGe4)[l,l',l'']

Oursourceofetropyistheveryradom:mkStdGe4,whichwillalwaysresultithesamegeerator.

RadomTrasforms

Theradomtrasformfuctioisatrasformthatoperatesoastreamofuiformlydistributedradomumbersadretursastreamoffloatigpoitumbers.

Curretly,thetwodefieddistributiosare:

uiforms-Atrivialfuctiothatretursastreamofuiformlydistributedradomumbersormals-Aslightlyless-trivialfuctiothatusestheBox-Mullertrasformtocreateastreamofumbers~N(0,1)

Workisbeigdoetoofferastudett-distributio,whichwouldrequiresupportforachi-squareddistributiotrasformatio.

TraiigtheNetwork

Iordertotraiaetwork,youmustcreateaewtraier:

lett=BackpropTraier(3::Float)quadraticCostquadraticCost'

TheBackpropTraiertypetakesialearigrate,acostfuctio,aditsderivative.

Theactualtraiigoftheetwork,thefitfuctiousesthetraier,aetwork,adthetraiigdata,adretursaew,traiedetwork.FortheXORetwork,thisis:

let'=traiUtilErrorLessThatoliedat0.01

LambdaNetprovidesthreetraiigmethods:

traiUtiltraiUtilErrorLessThatraiNTimes

ThetraiUtilfuctiotakesaStopCoditio(checkNetwork/Traier.hs)formoreiformatio,adthelasttwoaresimplywrappersforthefirstoethatprovidespecificpredicates.

Thecalculatederroriswhatisreturedbythecostfuctio.

CostFuctios

Curretly,theolyprovidedcostfuctioisthequadraticerrorcostfuctio,quadraticCostaditsderivative,quadraticCost'.Iamabouttoaddthecross-etropycostfuctio.

SelectioFuctios

Selectiofuctiosbreakupadatasetforeachroudoftraiig.Thecurretlyprovidedselectiofuctiosare:

miibatch-Youmustprovideaadpartiallyapplyittomiibatchtogetavalidselectiofuctio.Thisfuctioupdatestheetworkaftereverypasses.olie-Usigthisfuctiomeasthattheetworkupdatesaftereverytraiigexample.

Forsmalldatasets,it'sbettertouseolie,whileforlargerdatasets,thetraiigcaoccurmuchfasterifyouuseareasoablysizedmiibatch.

UsigtheNetwork

Ocetheetworkistraied,youcauseitwithyourtestdataorproductiodata:

predict(fromList[1,0])'

LambdaNetatleastattemptstofollowaScikit-Learstyleamigschemewithfitadpredictfuctios.

StorigadLoadig

Oceaetworkhasbeetraied,theweightsadbiasescabestorediafile:

saveNetwork"xor.a"'

BycalligsaveNetworkwithafilepath,youcasavethestateoftheetwork.

Loadigaetworkrequirespassigialistoflayerdefiitiosfortheorigialetwork,butwillloadalltheweightsadbiasesofthesavedetwork:

''<-loadNetwork"xor.a"[l,l',l'']

NotethattheloadNetworkfuctioretursaIO(Network),youca'tsimplycallpredictortraiotheobjectreturedbyloadNetwork.UsigtheapproachiXOR.hsshouldallowyoutoworkwiththereturedobject.

CurretlyUderDevelopmet

WhathasbeeoutliedaboveisolythefirststagesofLambdaNet.Iitedtosupportsomeadditioalfeatures,suchas:

UittestigSelf-orgaizigmapsRegularizatiofuctiosAdditioaltraiertypes(RProp,RMSProp)AdditioalcostfuctiosUitTestig

Iordertodevelopmorecomplexetworkarchitectures,itisimportattoesurethatallofthebasicsareworkig--especiallyastheAPIudergoeschages.Torutheuittests:

gitcloehttps://github.com/jbarrow/LambdaNet.git&&cdLambdaNetcabalistallcdtestruhaskellMai.hs

ThiswilldowloadthemostrecetversioofLambdaNetadrualltheuittests.

Self-OrgaizigMaps(SOMs,orKohoeMaps)

SOMswerechoseastheextarchitecturetodevelopbecausetheymakedifferetassumptiosthaFeedForwardetworks.Thisallowsustoseehowthecurretlibraryhadlesbuildigoutewarchitectures.AlreadythishasforcedachageitheNeuromodeladspurredthedevelopmetofavisualizatiospackage(iordertousefullyuderstadtheoutputsoftheSOMs).

RegularizatioFuctiosadMometum

Stadardbackproptraiigissubjecttooverfittigadfalligitolocalmiima.Byprovidigsupportforregularizatioadmometum,LambdaNetwillbeabletoprovidemoreextesibleadrobusttraiig.

FutureGoals

Thefuturegoalsare:

CovolutioalNetworksDatahadligforNeuralNetworksGeeratigtheDocumetatioImages

Allthedocumetatiofortheetworkwasgeeratedithefollowigmaer.Ithedocsfolder,ru:

ruhaskelldocs.hspythoaalysis.py

NotethatIamcurretlyworkigoremovigthePythoimageaalysisfromthelibrary,adswitchigitwithHaskelladguplot.I'malsoworkigousigthegeeratedimagesietworkdocumetatio.

功能介绍

LambdaNet LambdaNet is an artificial neural network library written in Haskell that abstracts net...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论