FileDocCategorySizeDatePackage
Predictor.javaAPI DocAndroid 5.1 API6117Thu Mar 12 22:22:48 GMT 2015android.bordeaux.services

Predictor

public class Predictor extends IPredictor.Stub implements IBordeauxLearner
This is interface to implement Prediction based on histogram that uses predictor_histogram from learnerning section

Fields Summary
private final String
TAG
private ModelChangeCallback
modelChangeCallback
private android.bordeaux.services.FeatureAssembly
mFeatureAssembly
public static final String
SET_FEATURE
public static final String
SET_PAIRED_FEATURES
public static final String
FEATURE_SEPARATOR
public static final String
USE_HISTORY
public static final String
PREVIOUS_SAMPLE
private boolean
mUseHistory
private long
mHistorySpan
private String
mPrevSample
private long
mPrevSampleTime
private static final String[]
APP_BLACKLIST
private android.bordeaux.learning.HistogramPredictor
mPredictor
Constructors Summary
Methods Summary
public android.os.IBindergetBinder()

        return this;
    
public byte[]getModel()

      return mPredictor.getModel();
    
private java.util.MapgetSampleFeatures()

        Map<String, String> sampleFeatures = mFeatureAssembly.getFeatureMap();
        long currTime = System.currentTimeMillis();

        if (mUseHistory && mPrevSample != null &&
            ((currTime - mPrevSampleTime) < mHistorySpan)) {
            sampleFeatures.put(PREVIOUS_SAMPLE, mPrevSample);
        }

        return sampleFeatures;
    
public java.util.ListgetTopCandidates(int topK)
return probabilty of an exmple using the histogram

        Map<String, String> features = getSampleFeatures();
        List<Map.Entry<String, Double> > topApps = mPredictor.findTopClasses(features, topK);

        int listSize =  topApps.size();
        ArrayList<StringFloat> result = new ArrayList<StringFloat>(listSize);
        for (int i = 0; i < listSize; ++i) {
            Map.Entry<String, Double> entry = topApps.get(i);
            result.add(new StringFloat(entry.getKey(), entry.getValue().floatValue()));
        }
        return result;
    
public voidpushNewSample(java.lang.String sampleName)
Input is a sampleName e.g.action name. This input is then augmented with requested build-in features such as time and location to create sampleFeatures. The sampleFeatures is then pushed to the histogram

        Map<String, String> sampleFeatures = getSampleFeatures();
        Log.i(TAG, "pushNewSample " + sampleName + ": " + sampleFeatures);

        // TODO: move to the end of the function?
        mPrevSample = sampleName;
        mPrevSampleTime = System.currentTimeMillis();

        mPredictor.addSample(sampleName, sampleFeatures);
        if (modelChangeCallback != null) {
            modelChangeCallback.modelChanged(this);
        }
    
public voidresetPredictor()
Reset the Predictor



            
      
        mPredictor.resetPredictor();

        if (modelChangeCallback != null) {
            modelChangeCallback.modelChanged(this);
        }
    
public booleansetModel(byte[] modelData)

      return mPredictor.setModel(modelData);
    
public voidsetModelChangeCallback(ModelChangeCallback callback)

        modelChangeCallback = callback;
    
public booleansetPredictorParameter(java.lang.String key, java.lang.String value)
Set parameters for 1) using History in probability estimations e.g. consider the last event and 2) featureAssembly e.g. time and location.

        Log.i(TAG, "setParameter : " + key + ", " + value);
        boolean result = true;
        if (key.equals(SET_FEATURE)) {
            result = mFeatureAssembly.registerFeature(value);
            if (!result) {
               Log.e(TAG,"Setting on feauture: " + value + " which is not available");
            }
        } else if (key.equals(SET_PAIRED_FEATURES)) {
            String[] features = value.split(FEATURE_SEPARATOR);
            result = mFeatureAssembly.registerFeaturePair(features);
            if (!result) {
                Log.e(TAG,"Setting feauture pair: " + value + " is not valid");
            }
        } else if (key.equals(USE_HISTORY)) {
            mUseHistory = true;
            mHistorySpan = Long.valueOf(value);
        } else {
            Log.e(TAG,"Setting parameter " + key + " with " + value + " is not valid");
        }
        return result;