Wei Hua | 6b4eebc | 2012-03-09 10:24:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | #ifndef LEARNING_JNI_STOCHASTIC_LINEAR_RANKER_H |
| 18 | #define LEAENING_JNI_STOCHASTIC_LINEAR_RANKER_H |
| 19 | |
| 20 | #include <jni.h> |
| 21 | |
| 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
saberian | b019e89 | 2012-04-19 11:33:44 -0700 | [diff] [blame^] | 26 | /* Counts the number of learning iterations. */ |
| 27 | const char * ITR_NUM = "IterationNumber"; |
| 28 | |
| 29 | /* The maximum norm of the weight vector. If norm of weights are larger than NormConstraint |
| 30 | they will be reprojected using RegularizationType to satisfy this constraint. */ |
| 31 | const char * NORM_CONSTRAINT = "NormConstraint"; |
| 32 | |
| 33 | /* Ddetermines type of the regularization used in learning. |
| 34 | This regularization can be based on different norms. |
| 35 | Options: "L0", "L1", "L2", "L1L2", "L1LInf". |
| 36 | Default : LINEAR */ |
| 37 | const char * REG_TYPE = "RegularizationType"; |
| 38 | |
| 39 | /* Lambda is a factor that is multiplied with the step size in learning. This can be used |
| 40 | to change the step size. |
| 41 | Default : 1.0 */ |
| 42 | const char * LAMBDA = "Lambda"; |
| 43 | |
| 44 | /* This parameter determines the update type in learning process. |
| 45 | Options: "FULL_CS" , "CLIP_CS", "REG_CS", "SL", "ADAPTIVE_REG" |
| 46 | Default : "SL" */ |
| 47 | const char * UPDATE_TYPE = "UpdateType"; |
| 48 | |
| 49 | /* Options: "CONST", "INV_LINEAR", "INV_QUADRATIC", "INV_SQRT" |
| 50 | Default: "INV_LINEAR". */ |
| 51 | const char * ADAPT_MODE = "AdaptationMode"; |
| 52 | |
| 53 | /* Three differnt kernels are supported: Linear "LINEAR", Polynomial "POLY", and RBF "RBF" |
| 54 | Default : "LINEAR" */ |
| 55 | const char * KERNEL_TYPE = "KernelType"; |
| 56 | |
| 57 | /* Kernel param is kernel-specific. In case of polynomial kernel, it is the degree of the |
| 58 | polynomial. In case of RBF kernel, it implies the sigma parameter. In case of linear |
| 59 | kernel, it is not used. */ |
| 60 | const char * KERNEL_PARAM = "KernelParameter"; |
| 61 | |
| 62 | /* Kernel gain is typically a multiplicative factor to the dot product while calculating |
| 63 | the kernel function. In most use cases, gain should be set to 1.0. */ |
| 64 | const char * KERNEL_GAIN = "KernelGain"; |
| 65 | |
| 66 | /* Kernel bias is typically an additive factors to the dot product while calculating |
| 67 | the kernel function. In most use cases, bias should be set to 0.0. */ |
| 68 | const char * KERNEL_BIAS = "KernelBias"; |
| 69 | |
| 70 | /* This parameter determines the type of loss function to minimize. |
| 71 | Options : "PAIRWISE", "RECIPROCAL_RANK" |
| 72 | Default : "PAIRWISE" */ |
| 73 | const char * LOSS_TYPE = "LossType"; |
| 74 | |
| 75 | /* The minimum percent of training pairs that are used in training. |
| 76 | Default : "0.1" */ |
| 77 | const char * ACC_PROB = "AcceptaceProbability"; |
| 78 | |
| 79 | /* The code averages out gradient updates for MinimumBatchSize samples |
| 80 | before performing an iteration of the algorithm. */ |
| 81 | const char * MIN_BATCH_SIZE = "MinimumBatchSize"; |
| 82 | |
| 83 | /* Specifies the number of non-zero entries allowed in a gradient. |
| 84 | Default is -1 which means we take the gradient as given by data without |
| 85 | adding any new constraints. positive number is treated as an L0 constraint */ |
| 86 | const char * GRAD_L0_NORM = "GradientL0Nrom"; |
| 87 | |
| 88 | const char * REG_TYPE_L0 = "L0"; |
| 89 | const char * REG_TYPE_L1 = "L1"; |
| 90 | const char * REG_TYPE_L2 = "L2"; |
| 91 | const char * REG_TYPE_L1L2 = "L1L2"; |
| 92 | const char * REG_TYPE_L1LInf = "L1LInf"; |
| 93 | const char * UPDATE_TYPE_FULL_CS = "FULL_CS"; |
| 94 | const char * UPDATE_TYPE_CLIP_CS = "CLIP_CS"; |
| 95 | const char * UPDATE_TYPE_REG_CS = "REG_CS"; |
| 96 | const char * UPDATE_TYPE_SL = "SL"; |
| 97 | const char * UPDATE_TYPE_ADAPTIVE_REG = "ADAPTIVE_REG"; |
| 98 | const char * ADAPT_MODE_CONST = "CONST"; |
| 99 | const char * ADAPT_MODE_INV_LINEAR = "INV_LINEAR"; |
| 100 | const char * ADAPT_MODE_INV_QUADRATIC = "INV_QUADRATIC"; |
| 101 | const char * ADAPT_MODE_INV_SQRT = "INV_SQRT"; |
| 102 | const char * KERNEL_TYPE_LINEAR = "LINEAR"; |
| 103 | const char * KERNEL_TYPE_POLY = "POLY"; |
| 104 | const char * KERNEL_TYPE_RBF = "RBF"; |
| 105 | const char * LOSS_TYPE_PAIRWISE = "PAIRWISE"; |
| 106 | const char * LOSS_TYPE_RECIPROCAL_RANK = "RECIPROCAL_RANK"; |
| 107 | |
Wei Hua | 6b4eebc | 2012-03-09 10:24:16 -0800 | [diff] [blame] | 108 | JNIEXPORT jint JNICALL |
| 109 | Java_android_bordeaux_learning_StochasticLinearRanker_initNativeClassifier( |
| 110 | JNIEnv* env, |
| 111 | jobject thiz); |
| 112 | |
| 113 | |
| 114 | JNIEXPORT jboolean JNICALL |
| 115 | Java_android_bordeaux_learning_StochasticLinearRanker_deleteNativeClassifier( |
| 116 | JNIEnv* env, |
| 117 | jobject thiz, |
| 118 | jint paPtr); |
| 119 | |
| 120 | JNIEXPORT jboolean JNICALL |
| 121 | Java_android_bordeaux_learning_StochasticLinearRanker_nativeUpdateClassifier( |
| 122 | JNIEnv* env, |
| 123 | jobject thiz, |
| 124 | jobjectArray key_array_positive, |
| 125 | jfloatArray value_array_positive, |
| 126 | jobjectArray key_array_negative, |
| 127 | jfloatArray value_array_negative, |
| 128 | jint paPtr); |
| 129 | |
| 130 | JNIEXPORT jfloat JNICALL |
| 131 | Java_android_bordeaux_learning_StochasticLinearRanker_nativeScoreSample( |
| 132 | JNIEnv* env, |
| 133 | jobject thiz, |
| 134 | jobjectArray key_array, |
| 135 | jfloatArray value_array, |
| 136 | jint paPtr); |
| 137 | |
| 138 | JNIEXPORT void JNICALL |
saberian | b019e89 | 2012-04-19 11:33:44 -0700 | [diff] [blame^] | 139 | Java_android_bordeaux_learning_StochasticLinearRanker_nativeGetWeightClassifier( |
Wei Hua | 6b4eebc | 2012-03-09 10:24:16 -0800 | [diff] [blame] | 140 | JNIEnv* env, |
| 141 | jobject thiz, |
saberian | b019e89 | 2012-04-19 11:33:44 -0700 | [diff] [blame^] | 142 | jobjectArray key_array_weight, |
| 143 | jfloatArray value_array_weight, |
| 144 | jfloat normalizer, |
| 145 | jint paPtr); |
| 146 | |
| 147 | JNIEXPORT void JNICALL |
| 148 | Java_android_bordeaux_learning_StochasticLinearRanker_nativeGetParameterClassifier( |
| 149 | JNIEnv* env, |
| 150 | jobject thiz, |
| 151 | jobjectArray key_array_param, |
| 152 | jobjectArray value_array_param, |
Wei Hua | 6b4eebc | 2012-03-09 10:24:16 -0800 | [diff] [blame] | 153 | jint paPtr); |
| 154 | |
| 155 | JNIEXPORT jint JNICALL |
| 156 | Java_android_bordeaux_learning_StochasticLinearRanker_nativeGetLengthClassifier( |
| 157 | JNIEnv* env, |
| 158 | jobject thiz, |
| 159 | jint paPtr); |
| 160 | |
| 161 | JNIEXPORT jboolean JNICALL |
saberian | b019e89 | 2012-04-19 11:33:44 -0700 | [diff] [blame^] | 162 | Java_android_bordeaux_learning_StochasticLinearRanker_nativeSetWeightClassifier( |
Wei Hua | 6b4eebc | 2012-03-09 10:24:16 -0800 | [diff] [blame] | 163 | JNIEnv* env, |
| 164 | jobject thiz, |
| 165 | jobjectArray key_array_model, |
| 166 | jfloatArray value_array_model, |
saberian | b019e89 | 2012-04-19 11:33:44 -0700 | [diff] [blame^] | 167 | jfloat normalizer_model, |
| 168 | jint paPtr); |
| 169 | |
| 170 | JNIEXPORT jboolean JNICALL |
| 171 | Java_android_bordeaux_learning_StochasticLinearRanker_nativeSetParameterClassifier( |
| 172 | JNIEnv* env, |
| 173 | jobject thiz, |
| 174 | jstring key, |
| 175 | jstring value, |
Wei Hua | 6b4eebc | 2012-03-09 10:24:16 -0800 | [diff] [blame] | 176 | jint paPtr); |
| 177 | |
| 178 | #ifdef __cplusplus |
| 179 | } |
| 180 | #endif |
| 181 | |
| 182 | #endif /* ANDROID_LERNING_JNI_STOCHASTIC_LINEAR_RANKER_H */ |