To train the network, use trainNetwork.m.

‫بسم هللا الرحمن الرحیم‬
To train the network, use trainNetwork.m.
This script will setup the network and train it with specified number epochs and specified set of images.
It contains various parameters: number of epochs, trace learning rule, and trace rate.
Once it finishes training, it will create a matrix containing the most invariant cells in the fourth layer for
the specific set of inputs. This matrix can be used to classify novel inputs.
‫ آدرس پوشه حاوی تصاویر آموزشی باید در متغیر‬
‫شود‬
‫ در این مسیر به ازای هر کالس یک پوشه و در هر پوشه تصاویر آموزشی‬
.‫مربوط به آن کالس وجود دارد‬
‫ مقدار دهی‬trainRootDir
‫ وزن های آپدیت شده و‬+ ‫در انتهای این کد اطالعات شامل توپولوژی شبکه‬
.‫ که شامل نورونهای مربوط به هر کالس ذخیره میشود‬invarMatrix ‫همچنین‬
.‫ داریم‬invarMatrix ‫برای هر کالس یک ماتریس به نام‬
‫ است؛ هر‬1 ‫ و‬0 ‫ شامل تعدادی‬32*32 ‫ یک کالس یک ماتریس‬invarMatrix
‫ داشته باشد یعنی برای اشیاء مربوط به‬1 ‫ که عدد‬32*32 ‫نورون از فضای‬
.‫آن کالس باید فعال شود‬
Core:
trainNetwork.m - main script to train the network
setupNetwork.m - function to create the model (can change the radius and number of connections
made per neuron)
updateLayer.m - function used to update the layers weight using the trace learning rule
layerOutput.m - function used to calculate the firing rate of the neuron without updating the weights
contrastEnhancement.m - simple sigmoid function
lateralInhibition.m - perform local competition on a given matrix and return matrix once done
inputFilter.m - compute difference of gaussian filter
inputResponses.m - apply battery of filters on a given image
Utility Functions:
vectorizeImage.m - the given image matrix is turned into a vector to speed up the process
normaliz.m - normalize inputted data
percentile.m - calculate the value at the indicated percentile
readAllImages.m - read images in the directory specified
simulate.m - pass the input image through the model upto the indicated layer (1 - 4)
Testing/Evaluating
testNetwork.m:
passed in the trained network and the invariance matrix formed after training the network and this
function will compare the fourth layer neurons of the specified images to the invariance matrix and
output the number of neurons that matches (resultSum)
:‫نحوه ی فراخوانی‬
testNetwork(layers, invarMatrix)
‫ پس از اجرای‬save ‫ اگر از نتیجه ی ذخیره شده در پوشه ی‬
‫ اطالعات الیه ها پس از آموزش در‬,‫ استفاده کنید‬trainNetwork.m
.‫ ذخیره میشود‬trained ‫متغیر‬
.‫ نیز شامل ماتریس نورونهای فعال هر کالس میباشد‬invarMatrix 
plotResults.m
.‫ اجرا شود‬testNetwork.m ‫قبل این تابع حتما باید‬
‫ هر کالس به ازای‬invarMatrix ‫این تابع تعداد نورونهای فعال شده از‬
.‫تصاویر مربوط به کالس های مختلف را رسم میکند‬
result_table.m
.‫ اجرا شود‬testNetwork.m ‫قبل این تابع حتما باید‬
‫در صد فعالیت هر کالس برای هر ‪invarMatrix‬‬
‫‪percentage.m‬‬
‫قبل این تابع حتما باید ‪ testNetwork.m‬اجرا شود‪.‬‬
‫در واقع فراخوانی هر بار این تابع یک سطر از ‪ result_table.m‬را بر میگرداند‬
‫‪test_classification.m‬‬
‫این کد؛ الیه ی آخر را با طبقه بند ‪ SVM‬طبقه بندی کرده و درصد اعالم میکند‪.‬‬
‫برای استفاده از این تابع باید کالس ‪ SVM‬را مطابق شکل زیر به پروژه اضافه‬
‫نماءید‪:‬‬
‫برای استفاده متغیر ‪ testRootDir‬را با آدرس پوشه ی اصلی که شامل پوشه‬
‫هایی از کالسهای مختلف شامل تصاویر تست هست میباشد‪.‬‬
‫;'‪testRootDir='./data/2class_5daraje/test_full‬‬