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 23extern "C" { 24#endif 25 26/* Counts the number of learning iterations. */ 27const 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. */ 31const 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 */ 37const 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 */ 42const 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" */ 47const char * UPDATE_TYPE = "UpdateType"; 48 49/* Options: "CONST", "INV_LINEAR", "INV_QUADRATIC", "INV_SQRT" 50 Default: "INV_LINEAR". */ 51const char * ADAPT_MODE = "AdaptationMode"; 52 53/* Three differnt kernels are supported: Linear "LINEAR", Polynomial "POLY", and RBF "RBF" 54 Default : "LINEAR" */ 55const 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. */ 60const 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. */ 64const 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. */ 68const char * KERNEL_BIAS = "KernelBias"; 69 70/* This parameter determines the type of loss function to minimize. 71 Options : "PAIRWISE", "RECIPROCAL_RANK" 72 Default : "PAIRWISE" */ 73const char * LOSS_TYPE = "LossType"; 74 75/* The minimum percent of training pairs that are used in training. 76 Default : "0.1" */ 77const char * ACC_PROB = "AcceptaceProbability"; 78 79/* The code averages out gradient updates for MinimumBatchSize samples 80 before performing an iteration of the algorithm. */ 81const 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 */ 86const char * GRAD_L0_NORM = "GradientL0Nrom"; 87 88const char * REG_TYPE_L0 = "L0"; 89const char * REG_TYPE_L1 = "L1"; 90const char * REG_TYPE_L2 = "L2"; 91const char * REG_TYPE_L1L2 = "L1L2"; 92const char * REG_TYPE_L1LInf = "L1LInf"; 93const char * UPDATE_TYPE_FULL_CS = "FULL_CS"; 94const char * UPDATE_TYPE_CLIP_CS = "CLIP_CS"; 95const char * UPDATE_TYPE_REG_CS = "REG_CS"; 96const char * UPDATE_TYPE_SL = "SL"; 97const char * UPDATE_TYPE_ADAPTIVE_REG = "ADAPTIVE_REG"; 98const char * ADAPT_MODE_CONST = "CONST"; 99const char * ADAPT_MODE_INV_LINEAR = "INV_LINEAR"; 100const char * ADAPT_MODE_INV_QUADRATIC = "INV_QUADRATIC"; 101const char * ADAPT_MODE_INV_SQRT = "INV_SQRT"; 102const char * KERNEL_TYPE_LINEAR = "LINEAR"; 103const char * KERNEL_TYPE_POLY = "POLY"; 104const char * KERNEL_TYPE_RBF = "RBF"; 105const char * LOSS_TYPE_PAIRWISE = "PAIRWISE"; 106const char * LOSS_TYPE_RECIPROCAL_RANK = "RECIPROCAL_RANK"; 107 108JNIEXPORT jint JNICALL 109Java_android_bordeaux_learning_StochasticLinearRanker_initNativeClassifier( 110 JNIEnv* env, 111 jobject thiz); 112 113 114JNIEXPORT jboolean JNICALL 115Java_android_bordeaux_learning_StochasticLinearRanker_deleteNativeClassifier( 116 JNIEnv* env, 117 jobject thiz, 118 jint paPtr); 119 120JNIEXPORT jboolean JNICALL 121Java_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 130JNIEXPORT jfloat JNICALL 131Java_android_bordeaux_learning_StochasticLinearRanker_nativeScoreSample( 132 JNIEnv* env, 133 jobject thiz, 134 jobjectArray key_array, 135 jfloatArray value_array, 136 jint paPtr); 137 138JNIEXPORT void JNICALL 139Java_android_bordeaux_learning_StochasticLinearRanker_nativeGetWeightClassifier( 140 JNIEnv* env, 141 jobject thiz, 142 jobjectArray key_array_weight, 143 jfloatArray value_array_weight, 144 jfloat normalizer, 145 jint paPtr); 146 147JNIEXPORT void JNICALL 148Java_android_bordeaux_learning_StochasticLinearRanker_nativeGetParameterClassifier( 149 JNIEnv* env, 150 jobject thiz, 151 jobjectArray key_array_param, 152 jobjectArray value_array_param, 153 jint paPtr); 154 155JNIEXPORT jint JNICALL 156Java_android_bordeaux_learning_StochasticLinearRanker_nativeGetLengthClassifier( 157 JNIEnv* env, 158 jobject thiz, 159 jint paPtr); 160 161JNIEXPORT jboolean JNICALL 162Java_android_bordeaux_learning_StochasticLinearRanker_nativeSetWeightClassifier( 163 JNIEnv* env, 164 jobject thiz, 165 jobjectArray key_array_model, 166 jfloatArray value_array_model, 167 jfloat normalizer_model, 168 jint paPtr); 169 170JNIEXPORT jboolean JNICALL 171Java_android_bordeaux_learning_StochasticLinearRanker_nativeSetParameterClassifier( 172 JNIEnv* env, 173 jobject thiz, 174 jstring key, 175 jstring value, 176 jint paPtr); 177 178#ifdef __cplusplus 179} 180#endif 181 182#endif /* ANDROID_LERNING_JNI_STOCHASTIC_LINEAR_RANKER_H */ 183