Ask Your Question

Ihab Taher's profile - activity

2017-02-04 09:42:21 -0600 commented question MLP XOR classification problem with predict method

Thank you. I think it is finally working I have provided these examples and here are the responses I got ( putting in mind labeling classes 1,-1)

0.1,0.1 -> -0.95
0.2,0.2 -> -.066
0.8,0.8 -> -0.66
0.9,0.9 -> -.095
0.2,0.9 -> 0.998
0.5,0.5 -> 0.998

But I have 2 questions 1. How is Layers Mat organized as I chose 3 layers and I found Layers Mat has 5 elements i.e. 5 layers ? 2. What is weightScale parameter taken by setTrainMethod is this the learning rate ?

2017-02-03 14:38:37 -0600 commented question How to integrate OpenCV Manager in Android App without ask user to install additional app in the device please

I faced a problem which may be the same problem of you. I couldn't run my app on my phone despite installing OpenCV manager but I found a link that solves this problem by adding native libraries of OpenCV to your app and it also uses some code to check that it is working properly. Here is the link : https://www.learn2crack.com/2016/03/setup-opencv-sdk-android-studio.html (https://www.learn2crack.com/2016/03/s...)

2017-02-02 09:34:07 -0600 commented question MLP XOR classification problem with predict method

Thank you. I will edit this post to contain a more clear description of this network.

2017-02-02 08:30:33 -0600 asked a question MLP XOR classification problem with predict method

Note : I misused the noun of my object as I named it Digits_Classifier putting in mind I want to classify digits but I started with this simple example to try to understand OpenCV but I faced this problem here :

Does anyone have any idea of why this code produces incorrect classification labels

public class Classifier {

// This is an MLP classifier
// We will use an MLP with structure 2-2-1 to do the task of classifying XOR problem

// MLP Attributes
ANN_MLP Digits_Classifier;
Mat Layers; // A mat contains number of neurons in each layer starting from the input till the output
Mat Training_Samples; // Training data
Mat Training_Responses; // Training data labels
Mat Test_Samples; // Test data 
Mat Test_Responses; // Test data labels that will be produced by MLP
int Row_Index , Col_Index; 
float Label;

// class constructor just declares / defines attributes
public Classifier()
{
    Digits_Classifier = ANN_MLP.create();

    Layers = new Mat(3,1,CvType.CV_32FC1);
    Training_Samples = new Mat(4,2,CvType.CV_32FC1);
    Training_Responses = new Mat(4,1,CvType.CV_32FC1);
    Test_Samples = new Mat(1,2,CvType.CV_32FC1);
    Test_Responses = new Mat(1,1,CvType.CV_32FC1);
}

public void Start()
{
    // Fill in Layers Mat
    int Layers_Arr[] = new int[]{2,2,1};
    for(int i=0 ; i<3 ; i++)
        Layers.put(i,0,Layers_Arr[i]);

    Row_Index = 0;
    Col_Index = 0;

    // Fill in Training_Samples Mat
    float[] Training_Samples_Arr = new float[]{0,0,0,1,1,0,1,1};
    for(int i=0 ; i<8 ; i++) {
        Training_Samples.put(Row_Index,Col_Index,Training_Samples_Arr[i]);
        Col_Index++;
        if(Col_Index >= 2)
        {
            Row_Index++;
            Col_Index = 0;
        }
    }

    // Fill in Training_Responses Mat
    float[] Training_Responses_Arr = new float[]{0,1,1,0};
    for(int i=0 ; i<4 ; i++)
        Training_Responses.put(i,0,Training_Responses_Arr[i]);

    // Fill in Test_Samples Mat
    double[] Test_Samples_Arr = new double[] {1.0,0.0};
    for(int i=0 ; i<2 ; i++)
        Test_Samples.put(0,i,Test_Samples_Arr[i]);

    Digits_Classifier.setLayerSizes(Layers);

    // The other 2 parameters other than type are Alpha and Beta
    Digits_Classifier.setActivationFunction(ANN_MLP.SIGMOID_SYM, 1.0, 1.0);

    // Term_Criteria object is created with 3 parameters : type , Iterations_Num , Error_Limit
    TermCriteria Digits_Classifier_Term_Criteria = new TermCriteria(TermCriteria.EPS,500,0.001);
    Digits_Classifier.setTermCriteria(Digits_Classifier_Term_Criteria);

    // the other 2 parameters other than type are momentum and weight scales
    Digits_Classifier.setTrainMethod(ANN_MLP.BACKPROP,0.1,0.1);

    Digits_Classifier.train(Training_Samples,Ml.ROW_SAMPLE,Training_Responses);

    // I think this method is the source of problem I face. 
    Label = Digits_Classifier.predict(Test_Samples,Test_Responses,StatModel.RAW_OUTPUT);
}

}

  • So to summarize this is a 2-2-1 Neural net I use to perform XOR problem. I trained the network by using train method just once I then tried to predict what will the output be for test_sample such as (1 , 0) but the predict method returns 0 although it must be one and another thing is that I provided this example as a training sample what is the problem ?

  • Another thing I want to ask about is that I defined Layers to be 3x1 Mat i.e. to have 3 layers one of them is the hidden one but when I use function getweights(int Layer_Index) it accepts until Layer_Index = 4 i.e. I have 5 layers so what ?

Note : I have ... (more)

2017-02-01 16:48:46 -0600 commented question Clear explaination of train and predict methods in ML library ?

This is something good. But I can't find any explaination for train and predict methods.

2017-02-01 09:48:25 -0600 received badge  Editor (source)
2017-02-01 09:36:24 -0600 commented question Clear explaination of train and predict methods in ML library ?

Thank you. But unfortunately this isn't what I am looking for. I need a neat and clear explaination of these functions : Train , Predict and how to update weights.

2017-01-31 19:26:03 -0600 asked a question Clear explaination of train and predict methods in ML library ?

Can anyone refer me to a more clear ML Library documentation ? As I am confused now and can't get a real description of methods such as : Train and Predict. One more thing that I saw many times those train flags such as : Update weights and No input scale but I can't use them as the only definition I can see for train is this :

public  boolean train(Mat samples, int layout, Mat responses)
    {

        boolean retVal = train_0(nativeObj, samples.nativeObj, layout, responses.nativeObj);

        return retVal;
    }

So I want to know :

  1. Do I need to use train method in a for loop to update weights or I just use it once and it will perform what I need ?
  2. Does predict method returns the class label ?
  3. What is this definition of predict where it takes 3 parameters (Mat Test_Data , Mat Responses(output) , int Flags) and what is this Flags parameter ?
  4. How can I update weights during training or function train performs it ?