MulticlassPA.java revision 6b4eebc73439cbc3ddfb547444a341d1f9be7996
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 18package android.bordeaux.learning; 19 20/** 21 * Wrapper for multiclass passive aggressive classifier. 22 * version 1 supports indexed sparse feature only. 23 */ 24public class MulticlassPA { 25 26 public MulticlassPA(int numClasses, int numDimensions, float aggressiveness) { 27 nativeClassifier = initNativeClassifier(numClasses, numDimensions, 28 aggressiveness); 29 } 30 31 /** 32 * Train on one example 33 */ 34 public boolean sparseTrainOneExample(int[] index_array, 35 float[] float_array, 36 int target) { 37 return nativeSparseTrainOneExample( 38 index_array, float_array, target, nativeClassifier); 39 } 40 41 /** 42 * Train on one example 43 */ 44 public int sparseGetClass(int[] index_array, float[] float_array) { 45 return nativeSparseGetClass(index_array, float_array, nativeClassifier); 46 } 47 48 static { 49 System.loadLibrary("bordeaux"); 50 } 51 52 private int nativeClassifier; 53 54 /* 55 * Initialize native classifier 56 */ 57 private native int initNativeClassifier(int num_classes, int num_dims, float aggressiveness); 58 59 private native void deleteNativeClassifier(int classPtr); 60 61 private native boolean nativeSparseTrainOneExample(int[] index_array, 62 float[] float_array, 63 int target, int classPtr); 64 65 private native int nativeSparseGetClass(int[] index_array, 66 float[] float_array, 67 int classPtr); 68} 69