[SOLVED] Dot Product

veve
veve New Altair Community Member
edited November 2024 in Community Q&A
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!
Tagged:

Welcome!

It looks like you're new here. Sign in or register to get started.

Answers

  • veve
    veve New Altair Community Member
    I just saw that there is another thread "Matrix Multiplication" that is saying that you cannot...

    I'm still truggling to the R code ... :(
  • veve
    veve New Altair Community Member
    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
  • veve
    veve New Altair Community Member
    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)

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.