User defined Similarity?
fjcuberos
New Altair Community Member
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
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
Is there any way to use a user defined similarity?
The only I imagine is to extend DistanceMeasures
And some logic to instantiate the class.
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);
...
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
0
Answers
-
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,
Sebastian0 -
Thanks a lot. A great approach.
I´ll wait for the inclusion of this method in the CVS version.
Thanks again.
F.J. Cuberos
0 -
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;
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.
import com.rapidminer.tools.math.similarity.DistanceMeasures;
public class PluginInit {
public static void initPlugin() {
DistanceMeasures.registerMeasure(DistanceMeasures.DIVERGENCES_TYPE, "Test", TestMeasure.class);
}
}
Greetings,
Sebastian0 -
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. Cuberos0 -
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
0 -
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
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:
measure = (DistanceMeasure) measureClass.newInstance();
measure.init(exampleSet, parameterHandler);
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".
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...
}
Cheers,
Ingo0 -
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?
0 -
Hi again,
thanks for your kind words
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,
Ingo0 -
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
0 -
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,
Ingo0