FileDocCategorySizeDatePackage
BordeauxClassifier.javaAPI DocAndroid 5.1 API3597Thu Mar 12 22:22:48 GMT 2015android.bordeaux.services

BordeauxClassifier

public class BordeauxClassifier extends Object
Classifier for the Learning framework. For training: call trainOneSample For classifying: call classify Data is represented as sparse key, value pair. And key is an integer, value is a float. Class label(target) for the training data is an integer. Note: since the actual classifier is running in a remote the service. Sometimes the connection may be lost or not established.

Fields Summary
static final String
TAG
private android.content.Context
mContext
private String
mName
private android.bordeaux.services.ILearning_MulticlassPA
mClassifier
Constructors Summary
public BordeauxClassifier(android.content.Context context)

        mContext = context;
        mName = "defaultClassifier";
        mClassifier = BordeauxManagerService.getClassifier(context, mName);
    
public BordeauxClassifier(android.content.Context context, String name)

        mContext = context;
        mName = name;
        mClassifier = BordeauxManagerService.getClassifier(context, mName);
    
Methods Summary
public intclassify(java.util.HashMap sample)

        // if classifier is not available return -1 as an indication of fail.
        if (!retrieveClassifier())
            return -1;
        try {
            return mClassifier.Classify(getArrayList(sample));
        } catch (RemoteException e) {
            Log.e(TAG,"Exception: classify the sample.");
            // return an invalid number.
            // TODO: throw exception.
            return -1;
        }
    
private java.util.ArrayListgetArrayList(java.util.HashMap sample)

          
        ArrayList<IntFloat> intfloat_sample = new ArrayList<IntFloat>();
        for (Map.Entry<Integer, Float> x : sample.entrySet()) {
           IntFloat v = new IntFloat();
           v.index = x.getKey();
           v.value = x.getValue();
           intfloat_sample.add(v);
        }
        return intfloat_sample;
    
private booleanretrieveClassifier()

        if (mClassifier == null)
            mClassifier = BordeauxManagerService.getClassifier(mContext, mName);
        // if classifier is not available, return false
        if (mClassifier == null) {
            Log.i(TAG,"Classifier not available.");
            return false;
        }
        return true;
    
public booleanupdate(java.util.HashMap sample, int target)

        if (!retrieveClassifier())
            return false;
        try {
            mClassifier.TrainOneSample(getArrayList(sample), target);
        } catch (RemoteException e) {
            Log.e(TAG,"Exception: training one sample.");
            return false;
        }
        return true;