diff options
Diffstat (limited to 'bordeaux/learning/predictor_histogram/java/android/bordeaux/learning/PredictorHist.java')
-rw-r--r-- | bordeaux/learning/predictor_histogram/java/android/bordeaux/learning/PredictorHist.java | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/bordeaux/learning/predictor_histogram/java/android/bordeaux/learning/PredictorHist.java b/bordeaux/learning/predictor_histogram/java/android/bordeaux/learning/PredictorHist.java deleted file mode 100644 index c332be560..000000000 --- a/bordeaux/learning/predictor_histogram/java/android/bordeaux/learning/PredictorHist.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package android.bordeaux.learning; - -import java.util.HashMap; -import java.util.Map; -import android.util.Log; - -/** - * A simple impelentation of histograms with sparse enteries using HashMap. - * User can push examples or extract probabilites from this histogram. - */ -public class PredictorHist { - private HashMap<String, Integer> mCountHist; - private int mSampleCount; - String TAG = "PredicrtHist"; - - public PredictorHist() { - mCountHist = new HashMap<String, Integer>(); - mSampleCount = 0; - } - - // reset histogram - public void resetPredictorHist() { - mCountHist.clear(); - mSampleCount = 0; - } - - // getters - public final HashMap<String, Integer> getHist() { - return mCountHist; - } - - public int getHistCounts() { - return mSampleCount; - } - - //setter - public void set(HashMap<String, Integer> hist) { - resetPredictorHist(); - for (Map.Entry<String, Integer> x : hist.entrySet()) { - mCountHist.put(x.getKey(), x.getValue()); - mSampleCount = mSampleCount + x.getValue(); - } - } - - /** - * pushes a new example to the histogram - */ - public void pushSample( String fs) { - int histValue = 1; - if (mCountHist.containsKey(fs)) { - histValue = histValue + mCountHist.get(fs); - } - mCountHist.put(fs,histValue); - mSampleCount++; - } - - /** - * return probabilty of an exmple using the histogram - */ - public float getProbability(String fs) { - float res = 0; - if (mCountHist.containsKey(fs)) { - res = ((float) mCountHist.get(fs)) / ((float)mSampleCount); - } - return res; - } -} |