🎉 🎉 RAPIDMINER 9.10 IS OUT!!! 🎉🎉

Download the latest version helping analytics teams accelerate time-to-value for streaming and IIOT use cases.

CLICK HERE TO DOWNLOAD

User defined Similarity?

fjcuberosfjcuberos Member Posts: 18  Maven
edited November 2018 in Help
I´ve seen  the revamped distance-similarity schema in RM 4.3.
Is there any way  to use a user defined similarity? 
The only I imagine  is to extend DistanceMeasures

  public static final String PARAMETER_USER_CLASS= "user_class";
  ... 
    public static final String[] MEASURE_TYPES = new String[] {
        "MixedMeasures",
        "NominalMeasures",
        "NumericalMeasures",
        "BregmanDivergences",
        "UserDefinedDistance"
    };
....
    type = new ParameterTypeString(PARAMETER_USER_CLASS,"Class reference","put.your.class.here");
        type.registerDependencyCondition(new EqualTypeCondition(operator, PARAMETER_MEASURE_TYPES, true, 4));
        list.add(type);
...
And some logic to instantiate the class.

But I label this way unelegant  (require change core code) and I can´t see a way a plugin can expand the list of selectable distances-similarities. Any idea? A suggestion for RM5.0?

Thanks for your attention and great work.

F.J. Cuberos
Tagged:

Answers

  • landland RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 2,531   Unicorn
    Hi,
    there will be a method for registering new measures on the DistanceMeasures static class. Plugins will be able to do this during startup using a new init method, which is called if its present.

    Greetings,
      Sebastian
  • fjcuberosfjcuberos Member Posts: 18  Maven
    Thanks a lot. A great approach.
    I´ll wait for the inclusion of this method in the CVS version.

    Thanks again.

    F.J. Cuberos

  • landland RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 2,531   Unicorn
    Hi,
    this feature is finally included in the new RapidMiner Version 4.4
    You Plugin now might provide a class as follows:
    package com.rapidminer;

    import com.rapidminer.tools.math.similarity.DistanceMeasures;

    public class PluginInit {
    public static void initPlugin() {
    DistanceMeasures.registerMeasure(DistanceMeasures.DIVERGENCES_TYPE, "Test", TestMeasure.class);
    }
    }
    The method initPlugin is called during startup so that your plugin might do something for initilizing itself or register a distance measure as done here.

    Greetings,
      Sebastian
  • fjcuberosfjcuberos Member Posts: 18  Maven
    Thanks a lot.
    Yesterday I was debugging the new 4.4 version and found the class-method solution.

    Thank you very much for your reply.

    F.J. Cuberos
  • fjcuberosfjcuberos Member Posts: 18  Maven
    One more question.

    I´ve implemented a "distance": is a kernel function defined for discretized sets and the definition is based in the ranges for every nominal value obtained in the discretization processs.
    Previosly, defined as an operator I could access to the IOContainer and read the discretization model in the apply() method.
    Now, defined as a SimilarityMeasure, ¿How can I get any object from the input of the current operator? The current operator uses the distanceMeasure and makes its instantiation.
    ¿Any idea? ???

    Thanks again for all you support to the RM users community. ;)

    Francisco J. Cuberos
  • IngoRMIngoRM Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,751  RM Founder
    Hi,

    oh, that's more difficult now, sorry for that. Actually, it's only possible by introducing a small "hack" into your distance measure:

    During the creation process of the distance measure, the methods

    measure = (DistanceMeasure) measureClass.newInstance();
    measure.init(exampleSet, parameterHandler);
    will be invoked. The first one constructs the measure by reflection and the second one invokes the init method with the example set only. But you can still make use of the second argument, the parameterHandler, since it is actually the invoking operator. So if you implement you init method like in the following, you should have access to the other IOObjects:

    public void init(ExampleSet exampleSet, ParameterHandler parameterHandler) {
        // case parameter handler to Operator
        Operator operator = (Operator)parameterHandler;

        // retrieve the model
        Model model = operator.getInput().get(Model.class);

        // do whatever you want...
    }
    Currently, it should be ensured that only operator invoke this method. I will ask Sebastian and we could change the method to "Operator" instead of "ParameterHandler".

    Cheers,
    Ingo
  • fjcuberosfjcuberos Member Posts: 18  Maven
    Thanks for your quickly and clear answer, as usual.

    I found then calling code but get confused with the ParameterHandler.
    I´ll try your code but it´s clear this is the solution to my problem.

    Thanks again Ingo.

    F.J. Cuberos

    P.D. Some time agoI ask if I could post some documents about RM in spanish in the wiki. The wiki has been redesigned already, but there is no "internalization zone". Are you interested in this work?


  • IngoRMIngoRM Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,751  RM Founder
    Hi again,

    thanks for your kind words  :D

    About the Wiki: actually, coming up with an improved Wiki is pretty on the top of our agenda but will probably needs time until May / June - whether the Wiki will be internationalized or not (same applies for this forum) is actually not yet decided.

    Cheers,
    Ingo
  • fjcuberosfjcuberos Member Posts: 18  Maven
    A minor "inconvenience": all the getInput() methods in the operator Class are defined as protected.
    I'll try it using reflexion.

    Thanks again.

    F.J. Cuberos
  • IngoRMIngoRM Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,751  RM Founder
    Hmm, via reflection this is probably working but it isn't of course as nice as it could be...

    I will talk to Sebastian and see if we could change the way of distance measure creation in a way those things would become simpler.

    Thanks for pointing this out. Cheers,
    Ingo
Sign In or Register to comment.