matlabneural-network

training neural network for user recognition in MATLAB


I'm working on gait recognition problem, the aim of this study is to be used for user authentication

I have data of 36 users

I've successfully extracted 143 features for each sample (or example) which are (36 rows and 143 columns) for each user

( in other words, I have 36 examples and 143 features are extracted for each example. Thus a matrix called All_Feat of 36*143 has been created for each individual user).

By the way, column represents the number of the extracted features and row represents the number of samples (examples) for each feature.

Then I have divided the data into two parts, training and testing (the training matrix contains 25 rows and 143 columns, while the testing Matrix contains 11 rows and 143 columns).

Then, for each user, I divided the matrix (All_Feat) into two matrixes ( Training matrix, and Test matrix ).

The training matrix contains ( 25 rows (examples) and 143 columns), while the testing matrix has (11 rows and 143 columns).

I'm new to classification and this stuff

I'd like to use machine learning (Neural Network) for classifying these features.

Therefore, the first step I need to create a reference template for each user ( which called training phase)

this can be done by training the classifier with the user's features (data) and the remaining Users as well (35 users are considered as imposters).

Based on what I have read, training Neural Network requires two classes, the first class contains all the training data of genuine user (e.g. User1) and labelled with 1 , while the second class has the training data of imposters labelled as 0 (which is binary classification, 1 for the authorised user and 0 for imposters).

**now my question is: **

1- i dont know how to create these classes!

2- For example, if I want to train Neural Network for User1, I have these variables, input and target. what should I assign to these variables?

should input= Training matrix of User1 and Training matrixes of User2, User3,.....User35 ?

Target=what should i assign to this matrix?

I really appreciate any help!


Solution

  • Try this: https://es.mathworks.com/help/nnet/gs/classify-patterns-with-a-neural-network.html

    A few notes:

    1. You said that, for each user, you have extracted 136 features. It sounds like you have only one repetition for each user (i.e. the user has tried-used the system once). However, I don't know the source of your data, but I dunno that it hasn't got some type of randomness. You mention gait analysis, and that sounds like that the recorded data of a given one user will be different each time that user uses the system. In other words: the user uses your system, you capture the data, you extract the 136 features (numbers); then, the user uses again the system, but the extracted 136 features will be slightly different. Therefore, you should get several examples for each user to train the classifier. In terms of "matlab matrix" your matrix should have one COLUMN for each example, and 136 rows (each of you features). Since you should have several repetitions for each user (for example 10 times), your big matrix should be something like: 136 rows x 360 columns.

    2. You should "create" one new neural network for each user. Given a user (for example User4), you create a dataset (a new matrix) with samples of that user, and samples of several other users (User1, User3, User5...). You do a binary classification (cases: "user4" against "other users"). After training, it would be advisable to test the classifier with data of other users whose data was not present during the training phase (for example User2 and others). Since you are doing a binary classification your matrices should be somthing like follows:

    Example, you have 10 trials (examples) of each user. You want to create a neural network to detect the user User1. The matrix should be like: (notation cU1_t1 means: column with features of user 1, trial 1) input_matrix = [cU1_t1; cU1_t2; ...; cU1_t10; cU2_t1; ...; cU36_t10]

    The target matrix should be like: target = a matrix whose 10 first columns are [ 1, 0], and the other 350 columns are [0, 1]. That means that the first 10 columns are of type A, and the others of type B. In this case "type A" means "User1", and "type B" means "Not User1".

    Then, you should segment the data (train data, validation data, test data) to train the nerual network and so on. Remember to save some users just for the testing phase, for example, the train matrix should not have any of the columns of five users: user2, user6, user7, user10, user20 (50 columns).

    I think you get the idea.

    Regards.

    ************ UPDATE: ******************************

    This example assumes that the user selects/indicates its name and then the system uses the neural network to authenticate the user (like a password). I will give you an small example with random numbers.

    Let's say you have recorded data from 15 users (but in the future you will have more). You record "gait data" from them when they do something with your recording device. From the recorded signals you extract some features, let's say you extract 5 features (5 numbers). Hence, everytime a user uses the machine you get 5 numbers. Even if user is the same, the 5 numbers will be different each time, because the recorded signals have some randomness. Therefore, to train the neural network you have to have several examples of each user. Let's say that you have 18 repetitions performed by each user.

    To sum up this example:

    Now you have to create one neural network for each user. To that end, you have to construct several matrices.

    Let's say you want to create the neural network (NN) of user 2 (U2). The NN will classify the feature vectors in 2 classes: U2 and NotU2. Therefore, you have to train and test the NN with examples of this. The group NotU2 represents any other user that it is not U2, however, you should NOT train the NN with data of every other user that you have in your experiment. This will be cheating (think that you can't have data from every user in the world). Therefore, to create the train dataset you will exclude all the repetitions of some users to test the NN during the training (validation dataset) and after the trainning (test dataset). For this example we will use users {U1,U3,U4} for validation, and users {U5,U6,U7} for testing.

    Therefore you construct the following matrices:

    IMPORTANT. The columns of each matrix should have a random order to improve the training. That is, do not put all the examples of U2 together and then the others. For this example I have put them in order for clarity. Obviously, if you change the order of the input matrix, you have to use the same order in the target matrix.

    To use MATLAB you will have to to pass two matrices: the inputMatrix and the targetMatrix. The inputMatrix will have the train,validation and test input matrices joined. And the targetMatrix the same with the targets. So, the inputMatrix will be a matrix of 6 rows and 270 columns. The targetMatrix will have 2 rows and 270 columns. For clarity I will say that the first 156 columns are the trainning ones, then the 57 columns of validation, and finally 57 columns of testing.

    The MATLAB commands will be:

    % Create a Pattern Recognition Network
    hiddenLayerSize = 10; %You can play with this number
    net = patternnet(hiddenLayerSize);
    
    %Specify the indices of each matrix
    net.divideFcn = 'divideind';
    net.divideParam.trainInd = [1: 156];
    net.divideParam.valInd = [157:214];
    net.divideParam.testInd = [215:270];
    
    % % Train the Network
    [net,tr] = train(net, inputMatrix, targetMatrix);
    

    In the open window you will be able to see the performance of your neural network. The output object "net" is your neural network trained. You can use it with new data if you want.

    Repeat this process for each other user (U1, U3, ...U15) to obtain his/her neural network.