[SOLVED] Dot Product

veveveve Member Posts: 63 Contributor II
edited November 2018 in Help
Hello,

How should we do the a "matrix" dot product of the exampleSets? I only found the cartesian product..
I tryied to use the R scripts but I didn't manage to transform the input into a matrix..

Could you please give an example on the iris/golf sample on how to transform it into a matrix and then use the matrix multiplication? Or if there is any other solution...

Thank you!

Answers

  • veveveve Member Posts: 63 Contributor II
    I just saw that there is another thread "Matrix Multiplication" that is saying that you cannot...

    I'm still truggling to the R code ... :(
  • veveveve Member Posts: 63 Contributor II
    My final solution is using groovy:

    import com.rapidminer.tools.Ontology;

    //imports----------------------------------------------------------------------
    ExampleSet ASet = operator.getInput(ExampleSet.class, 0)  //(n x f)
    ExampleSet BSet = operator.getInput(ExampleSet.class, 1)  // (f x m)
    ExampleSet resultSet = operator.getInput(ExampleSet.class, 2)  // (n x m)

    //init----------------------------------------------------------------------------
    Integer m = operator.getProcess().macroHandler.getMacro("m").toInteger();
    Integer n = operator.getProcess().macroHandler.getMacro("n").toInteger();
    Integer f =  operator.getProcess().macroHandler.getMacro("f").toInteger();
    Integer i = 0
    Integer j = 0
    Integer k = 0

    //save attributes name into array-------------------------------------------
    String[] ASetAttributes = new String;
    j = 0
    for (Attribute attribute : ASet.getAttributes()) {
    ASetAttributes = attribute.getName();
    j = j+1
    }

    String[] userSetAttributes = new String;
    j = 0
    for (Attribute attribute : BSet.getAttributes()) {
    BSetAttributes = attribute.getName();
    j = j+1
    }


    //table and exampleset------------------------------------------------------
    Integer a = 0i
    Integer b = 0i
    Integer c = 0i
    for (i = 0; i < (n-1); i++){
    for (j = 0; j < (m-1); j++) {
      for(k = 0; k < (f-1); k++){
      //resultant += a * b;
      AAtt = ASetAttributes.toString();
      BAtt = BSetAttributes.toString();
      resultAtt = BSetAttributes.toString();
      if(AAtt!="idA" && BAtt!="idB"){
    a = (Integer)(ASet.getExample(i)[AAtt]);
    b = (Integer)(BSet.getExample(k)[BAtt]); 
    c = (Integer) (resultSet.getExample(i)[resultAtt])
    resultSet.getExample(i)[resultAtt] = (Integer)(c+a*b);
      }
      }
    }
    }
    return resultSet
  • veveveve Member Posts: 63 Contributor II
    Finally, I didn't used my solution, since is too slow :D
    I used python for that (wrote a csv file and python read-it and did the multiplication and wrote the output into another file)
Sign In or Register to comment.