"Replicating Rapid Miner Trained ANN Model in C"

chiragjnchiragjn Member Posts: 1 Contributor I
edited June 2019 in Help
We are working on a pattern recognition problem for last few months using Artificial Neural Network (ANN) modelling.

Recently we experimented with Rapid Miner to train our ANN models. The accuracy of the models is as desirable.

As the next step, we want to replicate the following trained ANN model in C.

Input Vector (3 nodes)  --- > Normalization ----> Hidden Layer (3 nodes)  -----> Sigmoid function ----> Output Layer (2 nodes) --> Sigmoid function


Query 1: We have used default normalization method. As per online documentation, since sigmoid function is used, the input vector values are scaled down between +1 and -1. Is the example below show my understanding of normalization:

Input1 (say 3 components) :    [1, -3, 4]; 
Input2 (say 3 components) :    [2, 6, -1];

Max value for each component: [2 6 4];

Normalized Input 1: [1/2 , -3/6, 4/4]; == [.5, -.5, 1];
Normalized Input 2: [2/2 , 6/6, -1/4]; == [1, 1, -.25];

Kindly confirm.

Query 2: If some other normalization is used (say using standard deviation and mean), how to view the values of those parameters?

Query 3: If there a direct export tool available with in Rapid Miner, so that we can replicate the model in C/Java?

We will be highly thankful if someone can respond with answers to our queries.

Answers

  • MariusHelfMariusHelf RapidMiner Certified Expert, Member Posts: 1,869 Unicorn
    Hi,

    in your last question you ask, how to export a RapidMiner model to C or Java. RapidMiner is written entirely in Java, and it is open source, so you can access the complete RapidMiner API from your Java code (if it is released under the terms of the AGPL). One way to go would be to train your models in RapidMiner and store them in a repository. Then you can connect to the repository from your java code (using RapidMiner's API) and apply it.

    Another possibilty which we probably would chose is to install an instance of RapidAnalytics, which allows you to export a classification process as a webservice. That way you could send unknown examples to the webservice, which will classify the data and send the labelled data back to the caller.

    Question 1 and 2: to have more control over the normalization used you could disable the normalization option in the Neural Net and instead use the Normalization operator in front of it.

    Best regards,
    Marius
  • ljlj Member Posts: 10 Contributor II

    Replicating trained ANN model in any application; just to see it working

    Hello,

    what the matter? I’ve trained an ANN for a regression task. It consists of 19 Input nodes, 11 HiddenLayer- nodes and one in the output. (learning rate 0,35, training cycles 1000, Cross-Validation with 10 folds, root_mean_squared_error: 0.063 +/- 0.032 )

     I wanted to recalculate the model acording to the values of weights and bias provided by RapidMiner. I did the following steps:

    • For every node in the hidden layer I multiplied the input-values (X1-X19) with their coresponding weight, summed them up and added bias
    • The result was put into the sigmoid function.
    • The result of the sigmoid function was multiplied with the weight for the corresponding node.
    • This values, as far as they were grater than the threshold, were added, and should be near the real value/ predicted value. They aren’t. I get 1,9172 and the value to be predicted is somewhere between 0,35800 and 0,36054.

    Under this link: an excel-file whith all values and calculation ca be found:

    https://www.dropbox.com/sh/je5pvetfguq9yrg/AAB0eN1vH_Zo4DnW0lzSkL0Va?dl=0

    Any idea, where at which point i’ve taken the wrong way?

    Thanks in advance.

    Lukas

  • Thomas_OttThomas_Ott RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,761 Unicorn

    Would you be able to provide the process XML?

  • MartinLiebigMartinLiebig Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, University Professor Posts: 3,503 RM Data Scientist

    Hey,

     

    i think the easiest way is too look into our source code. The important class is: https://github.com/rapidminer/rapidminer-studio/blob/master/src/main/java/com/rapidminer/operator/learner/functions/neuralnet/ImprovedNeuralNetModel.java

     

    Input and output nodes are basically just normalizing. The sigmoid function for inner nodes is defined at:

    	public double calculateValue(InnerNode node, Example example) {
    Node[] inputs = node.getInputNodes();
    double[] weights = node.getWeights();
    double weightedSum = weights[0]; // bias
    for (int i = 0; i < inputs.length; i++) {
    weightedSum += inputs[i].calculateValue(true, example) * weights[i + 1];
    }

    double result = 0.0d;
    if (weightedSum < -45.0d) {
    result = 0;
    } else if (weightedSum > 45.0d) {
    result = 1;
    } else {
    result = 1 / (1 + Math.exp(-1 * weightedSum));
    }
    return result;
    }

    Best,

    Martin

     

    - Sr. Director Data Solutions, Altair RapidMiner -
    Dortmund, Germany
  • ljlj Member Posts: 10 Contributor II

    Sorry Thomas fo beeing so late respondig to Your post. Somehow I didn't get a mail....

    So, I dont´' t get it. I did again the regression (ANN) on Rapidminer, where everything looks brilliant, but when rebuilding the process with excell i do not get the value i am searching for. This link provides the xml-file of the RM-process and the excel-sheet: https://www.dropbox.com/sh/je5pvetfguq9yrg/AAB0eN1vH_Zo4DnW0lzSkL0Va?dl=0

    Hmm, my activision function is (1+exp(-x))^-1 where x ist the summed up product of the input values with their corresponding optimized weights. Do You use an other function?

    Thank you very much in advance.

    Lukas

     

     

  • ljlj Member Posts: 10 Contributor II

    And here again sorry for looking up so late Your post.

    It is usefill for me because now I know, that my sigmoid-function is not the problem.

    1 / (1 + Math.exp(-1 * weightedSum))

    If I ever find a solution, I let You know.

    Thanks& have a nice week-end.

    Lukas

Sign In or Register to comment.