StochasticLinearRankerpublic class StochasticLinearRanker extends Object Stochastic Linear Ranker, learns how to rank a sample. The learned rank score
can be used to compare samples.
This java class wraps the native StochasticLinearRanker class.
To update the ranker, call updateClassifier with two samples, with the first
one having higher rank than the second one.
To get the rank score of the sample call scoreSample.
TODO: adding more interfaces for changing the learning parameters |
Fields Summary |
---|
String | TAG | public static int | VAR_NUM | private long | mNativeClassifier |
Constructors Summary |
---|
public StochasticLinearRanker()Initializing a ranker
mNativeClassifier = initNativeClassifier();
|
Methods Summary |
---|
private native void | deleteNativeClassifier(long classifierPtr)
| protected void | finalize()
deleteNativeClassifier(mNativeClassifier);
| public android.bordeaux.learning.StochasticLinearRanker$Model | getUModel()Get the current model and parameters of ranker
Model slrModel = new Model();
int len = nativeGetLengthClassifier(mNativeClassifier);
String[] wKeys = new String[len];
float[] wValues = new float[len];
float wNormalizer = 1;
nativeGetWeightClassifier(wKeys, wValues, wNormalizer, mNativeClassifier);
slrModel.weightNormalizer = wNormalizer;
for (int i=0; i< wKeys.length ; i++)
slrModel.weights.put(wKeys[i], wValues[i]);
String[] paramKeys = new String[VAR_NUM];
String[] paramValues = new String[VAR_NUM];
nativeGetParameterClassifier(paramKeys, paramValues, mNativeClassifier);
for (int i=0; i< paramKeys.length ; i++)
slrModel.parameters.put(paramKeys[i], paramValues[i]);
return slrModel;
| private native long | initNativeClassifier()
| public boolean | loadModel(android.bordeaux.learning.StochasticLinearRanker$Model model)load the given model and parameters to the ranker
String[] wKeys = new String[model.weights.size()];
float[] wValues = new float[model.weights.size()];
int i = 0 ;
for (Map.Entry<String, Float> e : model.weights.entrySet()){
wKeys[i] = e.getKey();
wValues[i] = e.getValue();
i++;
}
boolean res = setModelWeights(wKeys, wValues, model.weightNormalizer);
if (!res)
return false;
for (Map.Entry<String, String> e : model.parameters.entrySet()){
res = setModelParameter(e.getKey(), e.getValue());
if (!res)
return false;
}
return res;
| private native int | nativeGetLengthClassifier(long classifierPtr)
| private native void | nativeGetParameterClassifier(java.lang.String[] keys, java.lang.String[] values, long classifierPtr)
| private native void | nativeGetWeightClassifier(java.lang.String[] keys, float[] values, float normalizer, long classifierPtr)
| private native float | nativeScoreSample(java.lang.String[] keys, float[] values, long classifierPtr)
| private native boolean | nativeSetParameterClassifier(java.lang.String key, java.lang.String value, long classifierPtr)
| private native boolean | nativeSetWeightClassifier(java.lang.String[] keys, float[] values, float normalizer, long classifierPtr)
| private native boolean | nativeUpdateClassifier(java.lang.String[] keys_positive, float[] values_positive, java.lang.String[] keys_negative, float[] values_negative, long classifierPtr)
| public void | print(android.bordeaux.learning.StochasticLinearRanker$Model model)Print a model for debugging
String Sw = "";
String Sp = "";
for (Map.Entry<String, Float> e : model.weights.entrySet())
Sw = Sw + "<" + e.getKey() + "," + e.getValue() + "> ";
for (Map.Entry<String, String> e : model.parameters.entrySet())
Sp = Sp + "<" + e.getKey() + "," + e.getValue() + "> ";
Log.i(TAG, "Weights are " + Sw);
Log.i(TAG, "Normalizer is " + model.weightNormalizer);
Log.i(TAG, "Parameters are " + Sp);
| public void | resetRanker()Reset the ranker
deleteNativeClassifier(mNativeClassifier);
mNativeClassifier = initNativeClassifier();
| public float | scoreSample(java.lang.String[] keys, float[] values)Get the rank score of the sample, a sample is a list of key, value pairs.
return nativeScoreSample(keys, values, mNativeClassifier);
| public boolean | setModelParameter(java.lang.String key, java.lang.String value)
boolean res = nativeSetParameterClassifier(key, value, mNativeClassifier);
return res;
| public boolean | setModelWeights(java.lang.String[] keys, float[] values, float normalizer)
return nativeSetWeightClassifier(keys, values, normalizer, mNativeClassifier);
| public boolean | updateClassifier(java.lang.String[] keys_positive, float[] values_positive, java.lang.String[] keys_negative, float[] values_negative)Train the ranker with a pair of samples. A sample, a pair of arrays of
keys and values. The first sample should have higher rank than the second
one.
return nativeUpdateClassifier(keys_positive, values_positive,
keys_negative, values_negative,
mNativeClassifier);
|
|