RecogizigHadwritteDigitsusigaTwo-layerPerceptro
Thisrepositorycotaiscodecorrespodigtothesemiarpaper:
D.Stutz.ItroductiotoNeuralNetworks.SemiarReport,HumaLaguageTechologyadPatterRecogitioGroup,RWTHAacheUiversity,2014.
Advisor:PavelGolik
Update:Thecodecabeadaptedtoallowmii-batchtraiigasdoeithisfork.
MNISTDatasetTheMNISTdatasetprovidesatraiigsetof60,000hadwrittedigitsadavalidatiosetof10,000hadwrittedigits.Theimageshavesize28x28pixels.Therefore,wheusigatwo-layerperceptro,weeed28x28=784iputuitsad10outputuits(represetigthe10differetdigits).
ThemethodsloadMNISTImagesadloadMNISTLaelsareusedtoloadtheMNISTdatasetasitisstorediaspecialfileformat.Themethodscabefoudolieathttps://ufldl.staford.edu/wiki/idex.php/Usig_the_MNIST_Dataset.
MethodsadUsageThemaimethodtotraithetwo-layerperceptroistraiStochasticSquaredErrorTwoLayerPerceptro.Themethodappliesstochastictraiig(ortobepreciseastochasticvariatofmii-batchtraiig)usigthesum-of-squarederrorfuctioadtheerrorbackpropagatioalgorithm.
fuctio[hiddeWeights,outputWeights,error]=traiStochasticSquaredErrorTwoLayerPerceptro(activatioFuctio,dActivatioFuctio,umberOfHiddeUits,iputValues,targetValues,epochs,batchSize,learigRate)%traiStochasticSquaredErrorTwoLayerPerceptroCreatesatwo-layerperceptro%adtraisitotheMNISTdataset.%%INPUT:%activatioFuctio:Activatiofuctiousedibothlayers.%dActivatioFuctio:Derivativeoftheactivatio%fuctiousedibothlayers.%umberOfHiddeUits:Numberofhiddeuits.%iputValues:Iputvaluesfortraiig(784x60000)%targetValues:Targetvaluesfortraiig(1x60000)%epochs:Numberofepochstotrai.%batchSize:PloterrorafterbatchSizeimages.%learigRate:Learigratetoapply.%%OUTPUT:%hiddeWeights:Weightsofthehiddelayer.%outputWeights:Weightsoftheoutputlayer.%Theabovemethodrequirestheactivatiofuctiousedforboththehiddeadtheoutputlayertobegiveasparameter.Iusedthelogisticsigmoidactivatiofuctio:
fuctioy=logisticSigmoid(x)%simpleLogisticSigmoidLogisticsigmoidactivatiofuctio%%INPUT:%x:Iputvector.%%OUTPUT:%y:Outputvectorwherethelogisticsigmoidwasappliedelemetby%elemet.%Iadditio,theerrorbackpropagatioalgorithmeedsthederivativeoftheusedactivatiofuctio:
fuctioy=dLogisticSigmoid(x)%dLogisticSigmoidDerivativeofthelogisticsigmoid.%%INPUT:%x:Iputvector.%%OUTPUT:%y:Outputvectorwherethederivativeofthelogisticsigmoidwas%appliedelemetbyelemet.%ThemethodapplyStochasticSquaredErrorTwoLayerPerceptroMNISTusesboththetraiigmethodseeaboveadthemethodvalidateTwoLayerPerceptrotoevaluatetheperformaceofthetwo-layerperceptro:
fuctio[correctlyClassified,classificatioErrors]=validateTwoLayerPerceptro(activatioFuctio,hiddeWeights,outputWeights,iputValues,labels)%validateTwoLayerPerceptroValidatethetwolayerperceptrousigthe%validatioset.%%INPUT:%activatioFuctio:Activatiofuctiousedibothlayers.%hiddeWeights:Weightsofthehiddelayer.%outputWeights:Weightsoftheoutputlayer.%iputValues:Iputvaluesfortraiig(784x10000).%labels:Labelsforvalidatio(1x10000).%%OUTPUT:%correctlyClassified:Numberofcorrectlyclassifiedvalues.%classificatioErrors:Numberofclassificatioerrors.%LiceseLiceseforsourcecodecorrespodigto:
D.Stutz.ItroductiotoNeuralNetworks.SemiarReport,HumaLaguageTechologyadPatterRecogitioGroup,RWTHAacheUiversity,2014.
Copyright(c)2014-2018DavidStutz
Pleasereadcarefullythefollowigtermsadcoditiosadayaccompayigdocumetatiobeforeyoudowloadad/orusethissoftwareadassociateddocumetatiofiles(the"Software").
Theauthorsherebygratyouao-exclusive,o-trasferable,freeofchargerighttocopy,modify,merge,publish,distribute,adsublicesetheSoftwareforthesolepurposeofperformigo-commercialscietificresearch,o-commercialeducatio,oro-commercialartisticprojects.
Ayotheruse,iparticularayuseforcommercialpurposes,isprohibited.Thisicludes,withoutlimitatio,icorporatioiacommercialproduct,useiacommercialservice,orproductioofotherartefactsforcommercialpurposes.
THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND,EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOFMERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEANDNONINFRINGEMENT.INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBELIABLEFORANYCLAIM,DAMAGESOROTHERLIABILITY,WHETHERINANACTIONOFCONTRACT,TORTOROTHERWISE,ARISINGFROM,OUTOFORINCONNECTIONWITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE.
Youuderstadadagreethattheauthorsareuderoobligatiotoprovideeithermaiteaceservices,updateservices,oticesoflatetdefects,orcorrectiosofdefectswithregardtotheSoftware.Theauthorseverthelessreservetherighttoupdate,modify,ordiscotiuetheSoftwareataytime.
TheabovecopyrightoticeadthispermissiooticeshallbeicludediallcopiesorsubstatialportiosoftheSoftware.Youagreetocitethecorrespodigpapers(seeabove)idocumetsadpapersthatreportoresearchusigtheSoftware.







评论