matlab-mnist-two-layer-perceptron

我要开发同款
匿名用户2021年11月17日
47阅读
开发技术Python
所属分类人工智能、机器学习/深度学习
授权协议Readme

作品详情

RecognizingHandwrittenDigitsusingaTwo-layerPerceptron

Thisrepositorycontainscodecorrespondingtotheseminarpaper:

D.Stutz.IntroductiontoNeuralNetworks.SeminarReport,HumanLanguageTechnologyandPatternRecognitionGroup,RWTHAachenUniversity,2014.

Advisor:PavelGolik

Update:Thecodecanbeadaptedtoallowmini-batchtrainingasdoneinthisfork.

MNISTDataset

TheMNISTdatasetprovidesatrainingsetof60,000handwrittendigitsandavalidationsetof10,000handwrittendigits.Theimageshavesize28x28pixels.Therefore,whenusingatwo-layerperceptron,weneed28x28=784inputunitsand10outputunits(representingthe10differentdigits).

ThemethodsloadMNISTImagesandloadMNISTLaelsareusedtoloadtheMNISTdatasetasitisstoredinaspecialfileformat.Themethodscanbefoundonlineathttps://ufldl.stanford.edu/wiki/index.php/Using_the_MNIST_Dataset.

MethodsandUsage

Themainmethodtotrainthetwo-layerperceptronistrainStochasticSquaredErrorTwoLayerPerceptron.Themethodappliesstochastictraining(ortobepreciseastochasticvariantofmini-batchtraining)usingthesum-of-squarederrorfunctionandtheerrorbackpropagationalgorithm.

function[hiddenWeights,outputWeights,error]=trainStochasticSquaredErrorTwoLayerPerceptron(activationFunction,dActivationFunction,numberOfHiddenUnits,inputValues,targetValues,epochs,batchSize,learningRate)%trainStochasticSquaredErrorTwoLayerPerceptronCreatesatwo-layerperceptron%andtrainsitontheMNISTdataset.%%INPUT:%activationFunction:Activationfunctionusedinbothlayers.%dActivationFunction:Derivativeoftheactivation%functionusedinbothlayers.%numberOfHiddenUnits:Numberofhiddenunits.%inputValues:Inputvaluesfortraining(784x60000)%targetValues:Targetvaluesfortraining(1x60000)%epochs:Numberofepochstotrain.%batchSize:PloterrorafterbatchSizeimages.%learningRate:Learningratetoapply.%%OUTPUT:%hiddenWeights:Weightsofthehiddenlayer.%outputWeights:Weightsoftheoutputlayer.%

Theabovemethodrequirestheactivationfunctionusedforboththehiddenandtheoutputlayertobegivenasparameter.Iusedthelogisticsigmoidactivationfunction:

functiony=logisticSigmoid(x)%simpleLogisticSigmoidLogisticsigmoidactivationfunction%%INPUT:%x:Inputvector.%%OUTPUT:%y:Outputvectorwherethelogisticsigmoidwasappliedelementby%element.%

Inaddition,theerrorbackpropagationalgorithmneedsthederivativeoftheusedactivationfunction:

functiony=dLogisticSigmoid(x)%dLogisticSigmoidDerivativeofthelogisticsigmoid.%%INPUT:%x:Inputvector.%%OUTPUT:%y:Outputvectorwherethederivativeofthelogisticsigmoidwas%appliedelementbyelement.%

ThemethodapplyStochasticSquaredErrorTwoLayerPerceptronMNISTusesboththetrainingmethodseenaboveandthemethodvalidateTwoLayerPerceptrontoevaluatetheperformanceofthetwo-layerperceptron:

function[correctlyClassified,classificationErrors]=validateTwoLayerPerceptron(activationFunction,hiddenWeights,outputWeights,inputValues,labels)%validateTwoLayerPerceptronValidatethetwolayerperceptronusingthe%validationset.%%INPUT:%activationFunction:Activationfunctionusedinbothlayers.%hiddenWeights:Weightsofthehiddenlayer.%outputWeights:Weightsoftheoutputlayer.%inputValues:Inputvaluesfortraining(784x10000).%labels:Labelsforvalidation(1x10000).%%OUTPUT:%correctlyClassified:Numberofcorrectlyclassifiedvalues.%classificationErrors:Numberofclassificationerrors.%License

Licenseforsourcecodecorrespondingto:

D.Stutz.IntroductiontoNeuralNetworks.SeminarReport,HumanLanguageTechnologyandPatternRecognitionGroup,RWTHAachenUniversity,2014.

Copyright(c)2014-2018DavidStutz

Pleasereadcarefullythefollowingtermsandconditionsandanyaccompanyingdocumentationbeforeyoudownloadand/orusethissoftwareandassociateddocumentationfiles(the"Software").

Theauthorsherebygrantyouanon-exclusive,non-transferable,freeofchargerighttocopy,modify,merge,publish,distribute,andsublicensetheSoftwareforthesolepurposeofperformingnon-commercialscientificresearch,non-commercialeducation,ornon-commercialartisticprojects.

Anyotheruse,inparticularanyuseforcommercialpurposes,isprohibited.Thisincludes,withoutlimitation,incorporationinacommercialproduct,useinacommercialservice,orproductionofotherartefactsforcommercialpurposes.

THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND,EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOFMERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEANDNONINFRINGEMENT.INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBELIABLEFORANYCLAIM,DAMAGESOROTHERLIABILITY,WHETHERINANACTIONOFCONTRACT,TORTOROTHERWISE,ARISINGFROM,OUTOFORINCONNECTIONWITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE.

Youunderstandandagreethattheauthorsareundernoobligationtoprovideeithermaintenanceservices,updateservices,noticesoflatentdefects,orcorrectionsofdefectswithregardtotheSoftware.Theauthorsneverthelessreservetherighttoupdate,modify,ordiscontinuetheSoftwareatanytime.

TheabovecopyrightnoticeandthispermissionnoticeshallbeincludedinallcopiesorsubstantialportionsoftheSoftware.Youagreetocitethecorrespondingpapers(seeabove)indocumentsandpapersthatreportonresearchusingtheSoftware.

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

评论