├── .gitignore ├── AndroidLibSVM ├── androidlibsvm │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── umich │ │ │ └── cse │ │ │ └── yctung │ │ │ └── androidlibsvm │ │ │ └── ExampleInstrumentedTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── umich │ │ │ │ └── cse │ │ │ │ └── yctung │ │ │ │ └── androidlibsvm │ │ │ │ └── LibSVM.java │ │ ├── jni │ │ │ ├── Android.mk │ │ │ ├── Application.mk │ │ │ ├── common.cpp │ │ │ ├── common.h │ │ │ ├── jnilibsvm.cpp │ │ │ └── libsvm │ │ │ │ ├── COPYRIGHT │ │ │ │ ├── README │ │ │ │ ├── svm-predict.cpp │ │ │ │ ├── svm-predict.cpp.back │ │ │ │ ├── svm-predict.h │ │ │ │ ├── svm-scale.c.back │ │ │ │ ├── svm-scale.cpp │ │ │ │ ├── svm-scale.h │ │ │ │ ├── svm-train.cpp │ │ │ │ ├── svm-train.cpp.back │ │ │ │ ├── svm-train.h │ │ │ │ ├── svm.cpp │ │ │ │ ├── svm.cpp.back │ │ │ │ └── svm.h │ │ └── res │ │ │ └── values │ │ │ └── strings.xml │ │ └── test │ │ └── java │ │ └── umich │ │ └── cse │ │ └── yctung │ │ └── androidlibsvm │ │ └── ExampleUnitTest.java ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── edu │ │ │ └── umich │ │ │ └── eecs │ │ │ └── androidlibsvm │ │ │ └── ApplicationTest.java │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ ├── heart_scale │ │ ├── heart_scale_predict │ │ └── heart_scale_train │ │ ├── java │ │ └── edu │ │ │ └── umich │ │ │ └── eecs │ │ │ └── androidlibsvm │ │ │ └── MainActivity.java │ │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew └── settings.gradle ├── COPYRIGHT.txt ├── Deprecated ├── README.md └── androidlibsvm-release.aar ├── Example ├── .gitignore ├── androidlibsvm-release │ ├── androidlibsvm-release.aar │ └── build.gradle ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ ├── data │ │ │ ├── heart_scale │ │ │ ├── heart_scale_predict │ │ │ └── heart_scale_train │ │ └── html │ │ │ ├── Predict_Options.html │ │ │ ├── Scale_Options.html │ │ │ ├── Train_Options.html │ │ │ └── copyright.html │ │ ├── java │ │ └── com │ │ │ └── test │ │ │ └── libsvmandroidexample │ │ │ ├── ContainerActivity.java │ │ │ ├── PredictFragment.java │ │ │ ├── ScaleFragment.java │ │ │ ├── TrainFragment.java │ │ │ └── Utility.java │ │ └── res │ │ ├── layout │ │ ├── activity_container.xml │ │ ├── dialog_layout.xml │ │ ├── dialog_result.xml │ │ ├── fragment_predict.xml │ │ ├── fragment_scale.xml │ │ └── fragment_train.xml │ │ ├── menu │ │ └── main_menu.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots │ ├── demo_all.png │ ├── demo_predict.png │ ├── demo_scale.png │ └── demo_train.png └── settings.gradle ├── README.md └── Release └── androidlibsvm-release.aar /.gitignore: -------------------------------------------------------------------------------- 1 | **/local.properties 2 | **/*.iml 3 | **/.gradle/ 4 | **/.idea/ 5 | **/.DS_Store 6 | AndroidLibSVM/build 7 | Example/build 8 | **/main/obj 9 | **/main/libs 10 | **/.externalNativeBuild 11 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/build.gradle: -------------------------------------------------------------------------------- 1 | import org.apache.tools.ant.taskdefs.condition.Os 2 | 3 | apply plugin: 'com.android.library' 4 | 5 | android { 6 | compileSdkVersion 24 7 | buildToolsVersion "25.0.2" 8 | 9 | defaultConfig { 10 | minSdkVersion 16 11 | targetSdkVersion 24 12 | versionCode 1 13 | versionName "1.0" 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | ndk { 17 | moduleName "jnilibsvm" // <-- This is the name of my C++ module! 18 | ldLibs "log" 19 | stl "stlport_shared" 20 | cFlags "-DDEV_NDK=1" 21 | } 22 | } 23 | 24 | buildTypes { 25 | release { 26 | minifyEnabled false 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 28 | } 29 | } 30 | } 31 | 32 | dependencies { 33 | compile fileTree(include: ['*.jar'], dir: 'libs') 34 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 35 | exclude group: 'com.android.support', module: 'support-annotations' 36 | }) 37 | compile 'com.android.support:appcompat-v7:24.0.0' 38 | testCompile 'junit:junit:4.12' 39 | } 40 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/eddyxd/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/androidTest/java/umich/cse/yctung/androidlibsvm/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package umich.cse.yctung.androidlibsvm; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("umich.cse.yctung.androidlibsvm.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/java/umich/cse/yctung/androidlibsvm/LibSVM.java: -------------------------------------------------------------------------------- 1 | package umich.cse.yctung.androidlibsvm; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * Created by yctung on 9/26/17. 7 | * This is a java wrapper of LibSVM 8 | */ 9 | 10 | public class LibSVM { 11 | String LOG_TAG = "LibSVM"; 12 | 13 | static { 14 | System.loadLibrary("jnilibsvm"); 15 | } 16 | 17 | // connect the native functions 18 | private native void testLog(String log); 19 | private native void jniSvmTrain(String cmd); 20 | private native void jniSvmPredict(String cmd); 21 | private native void jniSvmScale(String cmd, String fileOutPath); 22 | 23 | // public interfaces 24 | public void train(String cmd) { 25 | jniSvmTrain(cmd); 26 | } 27 | public void predict(String cmd) { 28 | jniSvmPredict(cmd); 29 | } 30 | public void scale(String cmd, String fileOutPath) { 31 | jniSvmScale(cmd, fileOutPath); 32 | } 33 | 34 | // singleton for the easy access 35 | private static LibSVM svm; 36 | public static LibSVM getInstance() { 37 | if (svm == null) { 38 | svm = new LibSVM(); 39 | } 40 | return svm; 41 | } 42 | 43 | public LibSVM() { 44 | Log.d(LOG_TAG, "LibSVM init"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:=$(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := jnilibsvm 6 | LOCAL_CFLAGS := -DDEV_NDK=1 7 | LOCAL_SRC_FILES := \ 8 | common.cpp jnilibsvm.cpp \ 9 | libsvm/svm-train.cpp \ 10 | libsvm/svm-predict.cpp \ 11 | libsvm/svm-scale.cpp \ 12 | libsvm/svm.cpp 13 | 14 | LOCAL_LDLIBS += -llog -ldl 15 | 16 | include $(BUILD_SHARED_LIBRARY) 17 | 18 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/Application.mk: -------------------------------------------------------------------------------- 1 | #APP_STL := stlport_static 2 | APP_STL := gnustl_static 3 | APP_CPPFLAGS := -frtti -fexceptions 4 | APP_ABI := armeabi 5 | APP_PLATFORM := android-14 6 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/common.cpp: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | //========================================================================== 3 | // 2015/02/07: move all common functions to here (include signal processing) 4 | //========================================================================== 5 | 6 | void debug(const char *s,...) 7 | { 8 | va_list va; va_start(va,s); 9 | char buffer[debug_message_max]; 10 | vsprintf(buffer,s,va); 11 | va_end(va); 12 | DEBUG_MACRO(buffer); 13 | } 14 | 15 | 16 | 17 | void cmdToArgv(std::string cmd, std::vector &v){ 18 | std::istringstream ss(cmd); 19 | std::string arg; 20 | std::list ls; 21 | while (ss >> arg) 22 | { 23 | //debug("arg = %s", arg.c_str()); 24 | ls.push_back(arg); 25 | 26 | int c_size = sizeof(char)*ls.back().length(); 27 | //debug("c_size = %d",c_size); 28 | char *c = (char*)malloc(c_size+1); // copy the null char in the end also 29 | memcpy(c, const_cast(ls.back().c_str()), c_size+1); 30 | 31 | 32 | //v.push_back(const_cast(ls.back().c_str())); 33 | v.push_back(c); 34 | } 35 | //v.push_back(0); // need terminating null pointer 36 | } 37 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/common.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | //using namespace std; 16 | 17 | #ifndef COMMON_H 18 | #define COMMON_H 19 | 20 | #define DEBUG_TAG "LibSVM-NDK" 21 | #define DEBUG_MACRO(x) __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK: %s", x); 22 | 23 | #define JNI_FUNC_NAME(name) Java_umich_cse_yctung_androidlibsvm_LibSVM_ ## name 24 | 25 | const int debug_message_max=1024; 26 | 27 | void debug(const char *s,...); 28 | 29 | void cmdToArgv(std::string, std::vector &); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/jnilibsvm.cpp: -------------------------------------------------------------------------------- 1 | //========================================================================== 2 | // 2015/08/31: yctung: add this new test for libSVM in jni interface 3 | //========================================================================== 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "./libsvm/svm-train.h" 13 | #include "./libsvm/svm-predict.h" 14 | #include "./libsvm/svm-scale.h" 15 | #include "common.h" 16 | 17 | // helper function to be called in Java for making svm-scale 18 | extern "C" void JNI_FUNC_NAME(jniSvmScale)(JNIEnv *env, jobject obj, jstring cmdIn, jstring fileOutPathIn){ 19 | const char *cmd = env->GetStringUTFChars(cmdIn, 0); 20 | const char *fileOutPath = env->GetStringUTFChars(fileOutPathIn, 0); 21 | debug("jniSvmScale cmd = %s, fileOutPath = %s", cmd, fileOutPath); 22 | 23 | std::vector v; 24 | 25 | // add dummy head to meet argv/command format 26 | std::string cmdString = std::string("dummy ")+std::string(cmd); 27 | 28 | cmdToArgv(cmdString, v); 29 | 30 | // hack to redirect the std output of svm-scale to a file 31 | // credit: https://stackoverflow.com/questions/10150468/how-to-redirect-cin-and-cout-to-files 32 | freopen(fileOutPath,"w", stdout); 33 | 34 | // make svm train by libsvm 35 | svmscale::main(v.size(),&v[0]); 36 | 37 | // close the redirect file(stdout) 38 | // TODO: should we get the stdout back? seems not necessary in this case 39 | fclose (stdout); 40 | 41 | 42 | // free vector memory 43 | for(int i=0;iReleaseStringUTFChars(cmdIn, cmd); 49 | env->ReleaseStringUTFChars(fileOutPathIn, fileOutPath); 50 | } 51 | 52 | 53 | // helper function to be called in Java for making svm-train 54 | extern "C" void JNI_FUNC_NAME(jniSvmTrain)(JNIEnv *env, jobject obj, jstring cmdIn){ 55 | const char *cmd = env->GetStringUTFChars(cmdIn, 0); 56 | debug("jniSvmTrain cmd = %s", cmd); 57 | 58 | std::vector v; 59 | 60 | // add dummy head to meet argv/command format 61 | std::string cmdString = std::string("dummy ")+std::string(cmd); 62 | 63 | cmdToArgv(cmdString, v); 64 | 65 | // make svm train by libsvm 66 | svmtrain::main(v.size(),&v[0]); 67 | 68 | 69 | // free vector memory 70 | for(int i=0;iReleaseStringUTFChars(cmdIn, cmd); 76 | } 77 | 78 | // helper function to be called in Java for making svm-predict 79 | extern "C" void JNI_FUNC_NAME(jniSvmPredict)(JNIEnv *env, jobject obj, jstring cmdIn){ 80 | const char *cmd = env->GetStringUTFChars(cmdIn, 0); 81 | debug("jniSvmPredict cmd = %s", cmd); 82 | 83 | std::vector v; 84 | 85 | // add dummy head to meet argv/command format 86 | std::string cmdString = std::string("dummy ")+std::string(cmd); 87 | 88 | cmdToArgv(cmdString, v); 89 | 90 | // make svm train by libsvm 91 | svmpredict::main(v.size(),&v[0]); 92 | 93 | 94 | // free vector memory 95 | for(int i=0;iReleaseStringUTFChars(cmdIn, cmd); 101 | } 102 | 103 | 104 | 105 | /* 106 | * just some test functions -> can be removed 107 | */ 108 | extern "C" JNIEXPORT int JNICALL JNI_FUNC_NAME(testInt)(JNIEnv * env, jobject obj){ 109 | return 5566; 110 | } 111 | 112 | extern "C" void JNI_FUNC_NAME(testLog)(JNIEnv *env, jobject obj, jstring logThis){ 113 | const char * szLogThis = env->GetStringUTFChars(logThis, 0); 114 | debug("%s",szLogThis); 115 | 116 | env->ReleaseStringUTFChars(logThis, szLogThis); 117 | } 118 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/libsvm/COPYRIGHT: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2000-2014 Chih-Chung Chang and Chih-Jen Lin 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither name of copyright holders nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/libsvm/svm-predict.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "../common.h" 7 | #include "svm-predict.h" 8 | #include "svm.h" 9 | 10 | namespace svmpredict { 11 | int print_null(const char *s,...) {return 0;} 12 | 13 | //static int (*info)(const char *fmt,...) = &printf; 14 | //static void (*info)(const char *fmt,...) = &debug; 15 | 16 | struct svm_node *x; 17 | int max_nr_attr = 64; 18 | 19 | struct svm_model* model; 20 | int predict_probability=0; 21 | 22 | static char *line = NULL; 23 | static int max_line_len; 24 | 25 | static char* readline(FILE *input) 26 | { 27 | int len; 28 | 29 | if(fgets(line,max_line_len,input) == NULL) 30 | return NULL; 31 | 32 | while(strrchr(line,'\n') == NULL) 33 | { 34 | max_line_len *= 2; 35 | line = (char *) realloc(line,max_line_len); 36 | len = (int) strlen(line); 37 | if(fgets(line+len,max_line_len-len,input) == NULL) 38 | break; 39 | } 40 | return line; 41 | } 42 | 43 | void exit_input_error(int line_num) 44 | { 45 | debug("Wrong input format at line %d\n", line_num); 46 | exit(1); 47 | } 48 | 49 | void predict(FILE *input, FILE *output) 50 | { 51 | int correct = 0; 52 | int total = 0; 53 | double error = 0; 54 | double sump = 0, sumt = 0, sumpp = 0, sumtt = 0, sumpt = 0; 55 | 56 | int svm_type=svm_get_svm_type(model); 57 | int nr_class=svm_get_nr_class(model); 58 | double *prob_estimates=NULL; 59 | int j; 60 | 61 | if(predict_probability) 62 | { 63 | if (svm_type==NU_SVR || svm_type==EPSILON_SVR) 64 | debug("Prob. model for test data: target value = predicted value + z,\nz: Laplace distribution e^(-|z|/sigma)/(2sigma),sigma=%g\n",svm_get_svr_probability(model)); 65 | else 66 | { 67 | int *labels=(int *) malloc(nr_class*sizeof(int)); 68 | svm_get_labels(model,labels); 69 | prob_estimates = (double *) malloc(nr_class*sizeof(double)); 70 | fprintf(output,"labels"); 71 | for(j=0;j start from 0 86 | 87 | label = strtok(line," \t\n"); 88 | if(label == NULL) // empty line 89 | exit_input_error(total+1); 90 | 91 | target_label = strtod(label,&endptr); 92 | if(endptr == label || *endptr != '\0') 93 | exit_input_error(total+1); 94 | 95 | while(1) 96 | { 97 | if(i>=max_nr_attr-1) // need one more for index = -1 98 | { 99 | max_nr_attr *= 2; 100 | x = (struct svm_node *) realloc(x,max_nr_attr*sizeof(struct svm_node)); 101 | } 102 | 103 | idx = strtok(NULL,":"); 104 | val = strtok(NULL," \t"); 105 | 106 | if(val == NULL) 107 | break; 108 | errno = 0; 109 | x[i].index = (int) strtol(idx,&endptr,10); 110 | if(endptr == idx || errno != 0 || *endptr != '\0' || x[i].index <= inst_max_index) 111 | exit_input_error(total+1); 112 | else 113 | inst_max_index = x[i].index; 114 | 115 | errno = 0; 116 | x[i].value = strtod(val,&endptr); 117 | if(endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr))) 118 | exit_input_error(total+1); 119 | 120 | ++i; 121 | } 122 | x[i].index = -1; 123 | 124 | if (predict_probability && (svm_type==C_SVC || svm_type==NU_SVC)) 125 | { 126 | predict_label = svm_predict_probability(model,x,prob_estimates); 127 | fprintf(output,"%g",predict_label); 128 | for(j=0;j=argc-2) 199 | exit_with_help(); 200 | 201 | input = fopen(argv[i],"r"); 202 | if(input == NULL) 203 | { 204 | debug("can't open input file %s\n",argv[i]); 205 | exit(1); 206 | } 207 | 208 | output = fopen(argv[i+2],"w"); 209 | if(output == NULL) 210 | { 211 | debug("can't open output file %s\n",argv[i+2]); 212 | exit(1); 213 | } 214 | 215 | if((model=svm_load_model(argv[i+1]))==0) 216 | { 217 | debug("can't open model file %s\n",argv[i+1]); 218 | exit(1); 219 | } 220 | 221 | x = (struct svm_node *) malloc(max_nr_attr*sizeof(struct svm_node)); 222 | if(predict_probability) 223 | { 224 | if(svm_check_probability_model(model)==0) 225 | { 226 | debug("Model does not support probabiliy estimates\n"); 227 | exit(1); 228 | } 229 | } 230 | else 231 | { 232 | if(svm_check_probability_model(model)!=0) 233 | debug("Model supports probability estimates, but disabled in prediction.\n"); 234 | } 235 | 236 | predict(input,output); 237 | svm_free_and_destroy_model(&model); 238 | free(x); 239 | free(line); 240 | fclose(input); 241 | fclose(output); 242 | return 0; 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/libsvm/svm-predict.cpp.back: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "svm-predict.h" 7 | #include "svm.h" 8 | 9 | namespace svmpredict { 10 | int print_null(const char *s,...) {return 0;} 11 | 12 | static int (*info)(const char *fmt,...) = &printf; 13 | 14 | struct svm_node *x; 15 | int max_nr_attr = 64; 16 | 17 | struct svm_model* model; 18 | int predict_probability=0; 19 | 20 | static char *line = NULL; 21 | static int max_line_len; 22 | 23 | static char* readline(FILE *input) 24 | { 25 | int len; 26 | 27 | if(fgets(line,max_line_len,input) == NULL) 28 | return NULL; 29 | 30 | while(strrchr(line,'\n') == NULL) 31 | { 32 | max_line_len *= 2; 33 | line = (char *) realloc(line,max_line_len); 34 | len = (int) strlen(line); 35 | if(fgets(line+len,max_line_len-len,input) == NULL) 36 | break; 37 | } 38 | return line; 39 | } 40 | 41 | void exit_input_error(int line_num) 42 | { 43 | fprintf(stderr,"Wrong input format at line %d\n", line_num); 44 | exit(1); 45 | } 46 | 47 | void predict(FILE *input, FILE *output) 48 | { 49 | int correct = 0; 50 | int total = 0; 51 | double error = 0; 52 | double sump = 0, sumt = 0, sumpp = 0, sumtt = 0, sumpt = 0; 53 | 54 | int svm_type=svm_get_svm_type(model); 55 | int nr_class=svm_get_nr_class(model); 56 | double *prob_estimates=NULL; 57 | int j; 58 | 59 | if(predict_probability) 60 | { 61 | if (svm_type==NU_SVR || svm_type==EPSILON_SVR) 62 | info("Prob. model for test data: target value = predicted value + z,\nz: Laplace distribution e^(-|z|/sigma)/(2sigma),sigma=%g\n",svm_get_svr_probability(model)); 63 | else 64 | { 65 | int *labels=(int *) malloc(nr_class*sizeof(int)); 66 | svm_get_labels(model,labels); 67 | prob_estimates = (double *) malloc(nr_class*sizeof(double)); 68 | fprintf(output,"labels"); 69 | for(j=0;j start from 0 84 | 85 | label = strtok(line," \t\n"); 86 | if(label == NULL) // empty line 87 | exit_input_error(total+1); 88 | 89 | target_label = strtod(label,&endptr); 90 | if(endptr == label || *endptr != '\0') 91 | exit_input_error(total+1); 92 | 93 | while(1) 94 | { 95 | if(i>=max_nr_attr-1) // need one more for index = -1 96 | { 97 | max_nr_attr *= 2; 98 | x = (struct svm_node *) realloc(x,max_nr_attr*sizeof(struct svm_node)); 99 | } 100 | 101 | idx = strtok(NULL,":"); 102 | val = strtok(NULL," \t"); 103 | 104 | if(val == NULL) 105 | break; 106 | errno = 0; 107 | x[i].index = (int) strtol(idx,&endptr,10); 108 | if(endptr == idx || errno != 0 || *endptr != '\0' || x[i].index <= inst_max_index) 109 | exit_input_error(total+1); 110 | else 111 | inst_max_index = x[i].index; 112 | 113 | errno = 0; 114 | x[i].value = strtod(val,&endptr); 115 | if(endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr))) 116 | exit_input_error(total+1); 117 | 118 | ++i; 119 | } 120 | x[i].index = -1; 121 | 122 | if (predict_probability && (svm_type==C_SVC || svm_type==NU_SVC)) 123 | { 124 | predict_label = svm_predict_probability(model,x,prob_estimates); 125 | fprintf(output,"%g",predict_label); 126 | for(j=0;j=argc-2) 197 | exit_with_help(); 198 | 199 | input = fopen(argv[i],"r"); 200 | if(input == NULL) 201 | { 202 | fprintf(stderr,"can't open input file %s\n",argv[i]); 203 | exit(1); 204 | } 205 | 206 | output = fopen(argv[i+2],"w"); 207 | if(output == NULL) 208 | { 209 | fprintf(stderr,"can't open output file %s\n",argv[i+2]); 210 | exit(1); 211 | } 212 | 213 | if((model=svm_load_model(argv[i+1]))==0) 214 | { 215 | fprintf(stderr,"can't open model file %s\n",argv[i+1]); 216 | exit(1); 217 | } 218 | 219 | x = (struct svm_node *) malloc(max_nr_attr*sizeof(struct svm_node)); 220 | if(predict_probability) 221 | { 222 | if(svm_check_probability_model(model)==0) 223 | { 224 | fprintf(stderr,"Model does not support probabiliy estimates\n"); 225 | exit(1); 226 | } 227 | } 228 | else 229 | { 230 | if(svm_check_probability_model(model)!=0) 231 | info("Model supports probability estimates, but disabled in prediction.\n"); 232 | } 233 | 234 | predict(input,output); 235 | svm_free_and_destroy_model(&model); 236 | free(x); 237 | free(line); 238 | fclose(input); 239 | fclose(output); 240 | return 0; 241 | } 242 | } 243 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/libsvm/svm-predict.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBSVM_PREDICT 2 | #define LIBSVM_PREDICT 3 | namespace svmpredict { 4 | int main(int argc, char **argv); 5 | } 6 | #endif 7 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/libsvm/svm-scale.c.back: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void exit_with_help() 8 | { 9 | printf( 10 | "Usage: svm-scale [options] data_filename\n" 11 | "options:\n" 12 | "-l lower : x scaling lower limit (default -1)\n" 13 | "-u upper : x scaling upper limit (default +1)\n" 14 | "-y y_lower y_upper : y scaling limits (default: no y scaling)\n" 15 | "-s save_filename : save scaling parameters to save_filename\n" 16 | "-r restore_filename : restore scaling parameters from restore_filename\n" 17 | ); 18 | exit(1); 19 | } 20 | 21 | char *line = NULL; 22 | int max_line_len = 1024; 23 | double lower=-1.0,upper=1.0,y_lower,y_upper; 24 | int y_scaling = 0; 25 | double *feature_max; 26 | double *feature_min; 27 | double y_max = -DBL_MAX; 28 | double y_min = DBL_MAX; 29 | int max_index; 30 | int min_index; 31 | long int num_nonzeros = 0; 32 | long int new_num_nonzeros = 0; 33 | 34 | #define max(x,y) (((x)>(y))?(x):(y)) 35 | #define min(x,y) (((x)<(y))?(x):(y)) 36 | 37 | void output_target(double value); 38 | void output(int index, double value); 39 | char* readline(FILE *input); 40 | int clean_up(FILE *fp_restore, FILE *fp, const char *msg); 41 | 42 | int main(int argc,char **argv) 43 | { 44 | int i,index; 45 | FILE *fp, *fp_restore = NULL; 46 | char *save_filename = NULL; 47 | char *restore_filename = NULL; 48 | 49 | for(i=1;i lower) || (y_scaling && !(y_upper > y_lower))) 72 | { 73 | fprintf(stderr,"inconsistent lower/upper specification\n"); 74 | exit(1); 75 | } 76 | 77 | if(restore_filename && save_filename) 78 | { 79 | fprintf(stderr,"cannot use -r and -s simultaneously\n"); 80 | exit(1); 81 | } 82 | 83 | if(argc != i+1) 84 | exit_with_help(); 85 | 86 | fp=fopen(argv[i],"r"); 87 | 88 | if(fp==NULL) 89 | { 90 | fprintf(stderr,"can't open file %s\n", argv[i]); 91 | exit(1); 92 | } 93 | 94 | line = (char *) malloc(max_line_len*sizeof(char)); 95 | 96 | #define SKIP_TARGET\ 97 | while(isspace(*p)) ++p;\ 98 | while(!isspace(*p)) ++p; 99 | 100 | #define SKIP_ELEMENT\ 101 | while(*p!=':') ++p;\ 102 | ++p;\ 103 | while(isspace(*p)) ++p;\ 104 | while(*p && !isspace(*p)) ++p; 105 | 106 | /* assumption: min index of attributes is 1 */ 107 | /* pass 1: find out max index of attributes */ 108 | max_index = 0; 109 | min_index = 1; 110 | 111 | if(restore_filename) 112 | { 113 | int idx, c; 114 | 115 | fp_restore = fopen(restore_filename,"r"); 116 | if(fp_restore==NULL) 117 | { 118 | fprintf(stderr,"can't open file %s\n", restore_filename); 119 | exit(1); 120 | } 121 | 122 | c = fgetc(fp_restore); 123 | if(c == 'y') 124 | { 125 | readline(fp_restore); 126 | readline(fp_restore); 127 | readline(fp_restore); 128 | } 129 | readline(fp_restore); 130 | readline(fp_restore); 131 | 132 | while(fscanf(fp_restore,"%d %*f %*f\n",&idx) == 1) 133 | max_index = max(idx,max_index); 134 | rewind(fp_restore); 135 | } 136 | 137 | while(readline(fp)!=NULL) 138 | { 139 | char *p=line; 140 | 141 | SKIP_TARGET 142 | 143 | while(sscanf(p,"%d:%*f",&index)==1) 144 | { 145 | max_index = max(max_index, index); 146 | min_index = min(min_index, index); 147 | SKIP_ELEMENT 148 | num_nonzeros++; 149 | } 150 | } 151 | 152 | if(min_index < 1) 153 | fprintf(stderr, 154 | "WARNING: minimal feature index is %d, but indices should start from 1\n", min_index); 155 | 156 | rewind(fp); 157 | 158 | feature_max = (double *)malloc((max_index+1)* sizeof(double)); 159 | feature_min = (double *)malloc((max_index+1)* sizeof(double)); 160 | 161 | if(feature_max == NULL || feature_min == NULL) 162 | { 163 | fprintf(stderr,"can't allocate enough memory\n"); 164 | exit(1); 165 | } 166 | 167 | for(i=0;i<=max_index;i++) 168 | { 169 | feature_max[i]=-DBL_MAX; 170 | feature_min[i]=DBL_MAX; 171 | } 172 | 173 | /* pass 2: find out min/max value */ 174 | while(readline(fp)!=NULL) 175 | { 176 | char *p=line; 177 | int next_index=1; 178 | double target; 179 | double value; 180 | 181 | if (sscanf(p,"%lf",&target) != 1) 182 | return clean_up(fp_restore, fp, "ERROR: failed to read labels\n"); 183 | y_max = max(y_max,target); 184 | y_min = min(y_min,target); 185 | 186 | SKIP_TARGET 187 | 188 | while(sscanf(p,"%d:%lf",&index,&value)==2) 189 | { 190 | for(i=next_index;i num_nonzeros) 319 | fprintf(stderr, 320 | "WARNING: original #nonzeros %ld\n" 321 | " new #nonzeros %ld\n" 322 | "Use -l 0 if many original feature values are zeros\n", 323 | num_nonzeros, new_num_nonzeros); 324 | 325 | free(line); 326 | free(feature_max); 327 | free(feature_min); 328 | fclose(fp); 329 | return 0; 330 | } 331 | 332 | char* readline(FILE *input) 333 | { 334 | int len; 335 | 336 | if(fgets(line,max_line_len,input) == NULL) 337 | return NULL; 338 | 339 | while(strrchr(line,'\n') == NULL) 340 | { 341 | max_line_len *= 2; 342 | line = (char *) realloc(line, max_line_len); 343 | len = (int) strlen(line); 344 | if(fgets(line+len,max_line_len-len,input) == NULL) 345 | break; 346 | } 347 | return line; 348 | } 349 | 350 | void output_target(double value) 351 | { 352 | if(y_scaling) 353 | { 354 | if(value == y_min) 355 | value = y_lower; 356 | else if(value == y_max) 357 | value = y_upper; 358 | else value = y_lower + (y_upper-y_lower) * 359 | (value - y_min)/(y_max-y_min); 360 | } 361 | printf("%g ",value); 362 | } 363 | 364 | void output(int index, double value) 365 | { 366 | /* skip single-valued attribute */ 367 | if(feature_max[index] == feature_min[index]) 368 | return; 369 | 370 | if(value == feature_min[index]) 371 | value = lower; 372 | else if(value == feature_max[index]) 373 | value = upper; 374 | else 375 | value = lower + (upper-lower) * 376 | (value-feature_min[index])/ 377 | (feature_max[index]-feature_min[index]); 378 | 379 | if(value != 0) 380 | { 381 | printf("%d:%g ",index, value); 382 | new_num_nonzeros++; 383 | } 384 | } 385 | 386 | int clean_up(FILE *fp_restore, FILE *fp, const char* msg) 387 | { 388 | fprintf(stderr, "%s", msg); 389 | free(line); 390 | free(feature_max); 391 | free(feature_min); 392 | fclose(fp); 393 | if (fp_restore) 394 | fclose(fp_restore); 395 | return -1; 396 | } 397 | 398 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/libsvm/svm-scale.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace svmscale { 8 | void exit_with_help() 9 | { 10 | printf( 11 | "Usage: svm-scale [options] data_filename\n" 12 | "options:\n" 13 | "-l lower : x scaling lower limit (default -1)\n" 14 | "-u upper : x scaling upper limit (default +1)\n" 15 | "-y y_lower y_upper : y scaling limits (default: no y scaling)\n" 16 | "-s save_filename : save scaling parameters to save_filename\n" 17 | "-r restore_filename : restore scaling parameters from restore_filename\n" 18 | ); 19 | exit(1); 20 | } 21 | 22 | char *line = NULL; 23 | int max_line_len = 1024; 24 | double lower=-1.0,upper=1.0,y_lower,y_upper; 25 | int y_scaling = 0; 26 | double *feature_max; 27 | double *feature_min; 28 | double y_max = -DBL_MAX; 29 | double y_min = DBL_MAX; 30 | int max_index; 31 | int min_index; 32 | long int num_nonzeros = 0; 33 | long int new_num_nonzeros = 0; 34 | 35 | #define max(x,y) (((x)>(y))?(x):(y)) 36 | #define min(x,y) (((x)<(y))?(x):(y)) 37 | 38 | void output_target(double value); 39 | void output(int index, double value); 40 | char* readline(FILE *input); 41 | int clean_up(FILE *fp_restore, FILE *fp, const char *msg); 42 | 43 | int main(int argc,char **argv) 44 | { 45 | int i,index; 46 | FILE *fp, *fp_restore = NULL; 47 | char *save_filename = NULL; 48 | char *restore_filename = NULL; 49 | 50 | for(i=1;i lower) || (y_scaling && !(y_upper > y_lower))) 73 | { 74 | fprintf(stderr,"inconsistent lower/upper specification\n"); 75 | exit(1); 76 | } 77 | 78 | if(restore_filename && save_filename) 79 | { 80 | fprintf(stderr,"cannot use -r and -s simultaneously\n"); 81 | exit(1); 82 | } 83 | 84 | if(argc != i+1) 85 | exit_with_help(); 86 | 87 | fp=fopen(argv[i],"r"); 88 | 89 | if(fp==NULL) 90 | { 91 | fprintf(stderr,"can't open file %s\n", argv[i]); 92 | exit(1); 93 | } 94 | 95 | line = (char *) malloc(max_line_len*sizeof(char)); 96 | 97 | #define SKIP_TARGET\ 98 | while(isspace(*p)) ++p;\ 99 | while(!isspace(*p)) ++p; 100 | 101 | #define SKIP_ELEMENT\ 102 | while(*p!=':') ++p;\ 103 | ++p;\ 104 | while(isspace(*p)) ++p;\ 105 | while(*p && !isspace(*p)) ++p; 106 | 107 | /* assumption: min index of attributes is 1 */ 108 | /* pass 1: find out max index of attributes */ 109 | max_index = 0; 110 | min_index = 1; 111 | 112 | if(restore_filename) 113 | { 114 | int idx, c; 115 | 116 | fp_restore = fopen(restore_filename,"r"); 117 | if(fp_restore==NULL) 118 | { 119 | fprintf(stderr,"can't open file %s\n", restore_filename); 120 | exit(1); 121 | } 122 | 123 | c = fgetc(fp_restore); 124 | if(c == 'y') 125 | { 126 | readline(fp_restore); 127 | readline(fp_restore); 128 | readline(fp_restore); 129 | } 130 | readline(fp_restore); 131 | readline(fp_restore); 132 | 133 | while(fscanf(fp_restore,"%d %*f %*f\n",&idx) == 1) 134 | max_index = max(idx,max_index); 135 | rewind(fp_restore); 136 | } 137 | 138 | while(readline(fp)!=NULL) 139 | { 140 | char *p=line; 141 | 142 | SKIP_TARGET 143 | 144 | while(sscanf(p,"%d:%*f",&index)==1) 145 | { 146 | max_index = max(max_index, index); 147 | min_index = min(min_index, index); 148 | SKIP_ELEMENT 149 | num_nonzeros++; 150 | } 151 | } 152 | 153 | if(min_index < 1) 154 | fprintf(stderr, 155 | "WARNING: minimal feature index is %d, but indices should start from 1\n", min_index); 156 | 157 | rewind(fp); 158 | 159 | feature_max = (double *)malloc((max_index+1)* sizeof(double)); 160 | feature_min = (double *)malloc((max_index+1)* sizeof(double)); 161 | 162 | if(feature_max == NULL || feature_min == NULL) 163 | { 164 | fprintf(stderr,"can't allocate enough memory\n"); 165 | exit(1); 166 | } 167 | 168 | for(i=0;i<=max_index;i++) 169 | { 170 | feature_max[i]=-DBL_MAX; 171 | feature_min[i]=DBL_MAX; 172 | } 173 | 174 | /* pass 2: find out min/max value */ 175 | while(readline(fp)!=NULL) 176 | { 177 | char *p=line; 178 | int next_index=1; 179 | double target; 180 | double value; 181 | 182 | if (sscanf(p,"%lf",&target) != 1) 183 | return clean_up(fp_restore, fp, "ERROR: failed to read labels\n"); 184 | y_max = max(y_max,target); 185 | y_min = min(y_min,target); 186 | 187 | SKIP_TARGET 188 | 189 | while(sscanf(p,"%d:%lf",&index,&value)==2) 190 | { 191 | for(i=next_index;i num_nonzeros) 320 | fprintf(stderr, 321 | "WARNING: original #nonzeros %ld\n" 322 | " new #nonzeros %ld\n" 323 | "Use -l 0 if many original feature values are zeros\n", 324 | num_nonzeros, new_num_nonzeros); 325 | 326 | free(line); 327 | free(feature_max); 328 | free(feature_min); 329 | fclose(fp); 330 | return 0; 331 | } 332 | 333 | char* readline(FILE *input) 334 | { 335 | int len; 336 | 337 | if(fgets(line,max_line_len,input) == NULL) 338 | return NULL; 339 | 340 | while(strrchr(line,'\n') == NULL) 341 | { 342 | max_line_len *= 2; 343 | line = (char *) realloc(line, max_line_len); 344 | len = (int) strlen(line); 345 | if(fgets(line+len,max_line_len-len,input) == NULL) 346 | break; 347 | } 348 | return line; 349 | } 350 | 351 | void output_target(double value) 352 | { 353 | if(y_scaling) 354 | { 355 | if(value == y_min) 356 | value = y_lower; 357 | else if(value == y_max) 358 | value = y_upper; 359 | else value = y_lower + (y_upper-y_lower) * 360 | (value - y_min)/(y_max-y_min); 361 | } 362 | printf("%g ",value); 363 | } 364 | 365 | void output(int index, double value) 366 | { 367 | /* skip single-valued attribute */ 368 | if(feature_max[index] == feature_min[index]) 369 | return; 370 | 371 | if(value == feature_min[index]) 372 | value = lower; 373 | else if(value == feature_max[index]) 374 | value = upper; 375 | else 376 | value = lower + (upper-lower) * 377 | (value-feature_min[index])/ 378 | (feature_max[index]-feature_min[index]); 379 | 380 | if(value != 0) 381 | { 382 | printf("%d:%g ",index, value); 383 | new_num_nonzeros++; 384 | } 385 | } 386 | 387 | int clean_up(FILE *fp_restore, FILE *fp, const char* msg) 388 | { 389 | fprintf(stderr, "%s", msg); 390 | free(line); 391 | free(feature_max); 392 | free(feature_min); 393 | fclose(fp); 394 | if (fp_restore) 395 | fclose(fp_restore); 396 | return -1; 397 | } 398 | } 399 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/libsvm/svm-scale.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBSVM_SCALE 2 | #define LIBSVM_SCALE 3 | namespace svmscale { 4 | int main(int argc, char **argv); 5 | } 6 | #endif 7 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/libsvm/svm-train.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "../common.h" 7 | #include "svm-train.h" 8 | #include "svm.h" 9 | #define Malloc(type,n) (type *)malloc((n)*sizeof(type)) 10 | 11 | namespace svmtrain { 12 | void print_null(const char *s) {} 13 | 14 | void exit_with_help() 15 | { 16 | debug( 17 | "Usage: svm-train [options] training_set_file [model_file]\n" 18 | "options:\n" 19 | "-s svm_type : set type of SVM (default 0)\n" 20 | " 0 -- C-SVC (multi-class classification)\n" 21 | " 1 -- nu-SVC (multi-class classification)\n" 22 | " 2 -- one-class SVM\n" 23 | " 3 -- epsilon-SVR (regression)\n" 24 | " 4 -- nu-SVR (regression)\n" 25 | "-t kernel_type : set type of kernel function (default 2)\n" 26 | " 0 -- linear: u'*v\n" 27 | " 1 -- polynomial: (gamma*u'*v + coef0)^degree\n" 28 | " 2 -- radial basis function: exp(-gamma*|u-v|^2)\n" 29 | " 3 -- sigmoid: tanh(gamma*u'*v + coef0)\n" 30 | " 4 -- precomputed kernel (kernel values in training_set_file)\n" 31 | "-d degree : set degree in kernel function (default 3)\n" 32 | "-g gamma : set gamma in kernel function (default 1/num_features)\n" 33 | "-r coef0 : set coef0 in kernel function (default 0)\n" 34 | "-c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)\n" 35 | "-n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)\n" 36 | "-p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)\n" 37 | "-m cachesize : set cache memory size in MB (default 100)\n" 38 | "-e epsilon : set tolerance of termination criterion (default 0.001)\n" 39 | "-h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)\n" 40 | "-b probability_estimates : whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)\n" 41 | "-wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)\n" 42 | "-v n: n-fold cross validation mode\n" 43 | "-q : quiet mode (no outputs)\n" 44 | ); 45 | exit(1); 46 | } 47 | 48 | void exit_input_error(int line_num) 49 | { 50 | debug("Wrong input format at line %d\n", line_num); 51 | exit(1); 52 | } 53 | 54 | void parse_command_line(int argc, char **argv, char *input_file_name, char *model_file_name); 55 | void read_problem(const char *filename); 56 | void do_cross_validation(); 57 | 58 | struct svm_parameter param; // set by parse_command_line 59 | struct svm_problem prob; // set by read_problem 60 | struct svm_model *model; 61 | struct svm_node *x_space; 62 | int cross_validation; 63 | int nr_fold; 64 | 65 | static char *line = NULL; 66 | static int max_line_len; 67 | 68 | static char* readline(FILE *input) 69 | { 70 | int len; 71 | 72 | if(fgets(line,max_line_len,input) == NULL) 73 | return NULL; 74 | 75 | while(strrchr(line,'\n') == NULL) 76 | { 77 | max_line_len *= 2; 78 | line = (char *) realloc(line,max_line_len); 79 | len = (int) strlen(line); 80 | if(fgets(line+len,max_line_len-len,input) == NULL) 81 | break; 82 | } 83 | return line; 84 | } 85 | 86 | int main(int argc, char **argv) 87 | { 88 | char input_file_name[1024]; 89 | char model_file_name[1024]; 90 | const char *error_msg; 91 | 92 | 93 | parse_command_line(argc, argv, input_file_name, model_file_name); 94 | read_problem(input_file_name); 95 | error_msg = svm_check_parameter(&prob,¶m); 96 | 97 | 98 | if(error_msg) 99 | { 100 | debug("ERROR: %s\n",error_msg); 101 | exit(1); 102 | } 103 | 104 | if(cross_validation) 105 | { 106 | do_cross_validation(); 107 | } 108 | else 109 | { 110 | 111 | 112 | model = svm_train(&prob,¶m); 113 | 114 | 115 | if(svm_save_model(model_file_name,model)) 116 | { 117 | debug( "can't save model to file %s\n", model_file_name); 118 | exit(1); 119 | } 120 | svm_free_and_destroy_model(&model); 121 | 122 | } 123 | svm_destroy_param(¶m); 124 | free(prob.y); 125 | free(prob.x); 126 | free(x_space); 127 | free(line); 128 | 129 | return 0; 130 | } 131 | 132 | void do_cross_validation() 133 | { 134 | int i; 135 | int total_correct = 0; 136 | double total_error = 0; 137 | double sumv = 0, sumy = 0, sumvv = 0, sumyy = 0, sumvy = 0; 138 | double *target = Malloc(double,prob.l); 139 | 140 | svm_cross_validation(&prob,¶m,nr_fold,target); 141 | if(param.svm_type == EPSILON_SVR || 142 | param.svm_type == NU_SVR) 143 | { 144 | for(i=0;i=argc) 199 | exit_with_help(); 200 | switch(argv[i-1][1]) 201 | { 202 | case 's': 203 | param.svm_type = atoi(argv[i]); 204 | break; 205 | case 't': 206 | param.kernel_type = atoi(argv[i]); 207 | break; 208 | case 'd': 209 | param.degree = atoi(argv[i]); 210 | break; 211 | case 'g': 212 | param.gamma = atof(argv[i]); 213 | break; 214 | case 'r': 215 | param.coef0 = atof(argv[i]); 216 | break; 217 | case 'n': 218 | param.nu = atof(argv[i]); 219 | break; 220 | case 'm': 221 | param.cache_size = atof(argv[i]); 222 | break; 223 | case 'c': 224 | param.C = atof(argv[i]); 225 | break; 226 | case 'e': 227 | param.eps = atof(argv[i]); 228 | break; 229 | case 'p': 230 | param.p = atof(argv[i]); 231 | break; 232 | case 'h': 233 | param.shrinking = atoi(argv[i]); 234 | break; 235 | case 'b': 236 | param.probability = atoi(argv[i]); 237 | break; 238 | case 'q': 239 | print_func = &print_null; 240 | i--; 241 | break; 242 | case 'v': 243 | cross_validation = 1; 244 | nr_fold = atoi(argv[i]); 245 | if(nr_fold < 2) 246 | { 247 | debug("n-fold cross validation: n must >= 2\n"); 248 | exit_with_help(); 249 | } 250 | break; 251 | case 'w': 252 | ++param.nr_weight; 253 | param.weight_label = (int *)realloc(param.weight_label,sizeof(int)*param.nr_weight); 254 | param.weight = (double *)realloc(param.weight,sizeof(double)*param.nr_weight); 255 | param.weight_label[param.nr_weight-1] = atoi(&argv[i-1][2]); 256 | param.weight[param.nr_weight-1] = atof(argv[i]); 257 | break; 258 | default: 259 | debug("Unknown option: -%c\n", argv[i-1][1]); 260 | exit_with_help(); 261 | } 262 | } 263 | 264 | svm_set_print_string_function(print_func); 265 | 266 | // determine filenames 267 | 268 | if(i>=argc) 269 | exit_with_help(); 270 | 271 | strcpy(input_file_name, argv[i]); 272 | 273 | if(i start from 0 333 | readline(fp); 334 | prob.x[i] = &x_space[j]; 335 | label = strtok(line," \t\n"); 336 | if(label == NULL) // empty line 337 | exit_input_error(i+1); 338 | 339 | prob.y[i] = strtod(label,&endptr); 340 | if(endptr == label || *endptr != '\0') 341 | exit_input_error(i+1); 342 | 343 | while(1) 344 | { 345 | idx = strtok(NULL,":"); 346 | val = strtok(NULL," \t"); 347 | 348 | if(val == NULL) 349 | break; 350 | 351 | errno = 0; 352 | x_space[j].index = (int) strtol(idx,&endptr,10); 353 | if(endptr == idx || errno != 0 || *endptr != '\0' || x_space[j].index <= inst_max_index) 354 | exit_input_error(i+1); 355 | else 356 | inst_max_index = x_space[j].index; 357 | 358 | errno = 0; 359 | x_space[j].value = strtod(val,&endptr); 360 | if(endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr))) 361 | exit_input_error(i+1); 362 | 363 | ++j; 364 | } 365 | 366 | if(inst_max_index > max_index) 367 | max_index = inst_max_index; 368 | x_space[j++].index = -1; 369 | } 370 | 371 | if(param.gamma == 0 && max_index > 0) 372 | param.gamma = 1.0/max_index; 373 | 374 | if(param.kernel_type == PRECOMPUTED) 375 | for(i=0;i max_index) 383 | { 384 | debug("Wrong input format: sample_serial_number out of range\n"); 385 | exit(1); 386 | } 387 | } 388 | 389 | fclose(fp); 390 | } 391 | } 392 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/libsvm/svm-train.cpp.back: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "svm-train.h" 7 | #include "svm.h" 8 | #define Malloc(type,n) (type *)malloc((n)*sizeof(type)) 9 | 10 | namespace svmtrain { 11 | void print_null(const char *s) {} 12 | 13 | void exit_with_help() 14 | { 15 | printf( 16 | "Usage: svm-train [options] training_set_file [model_file]\n" 17 | "options:\n" 18 | "-s svm_type : set type of SVM (default 0)\n" 19 | " 0 -- C-SVC (multi-class classification)\n" 20 | " 1 -- nu-SVC (multi-class classification)\n" 21 | " 2 -- one-class SVM\n" 22 | " 3 -- epsilon-SVR (regression)\n" 23 | " 4 -- nu-SVR (regression)\n" 24 | "-t kernel_type : set type of kernel function (default 2)\n" 25 | " 0 -- linear: u'*v\n" 26 | " 1 -- polynomial: (gamma*u'*v + coef0)^degree\n" 27 | " 2 -- radial basis function: exp(-gamma*|u-v|^2)\n" 28 | " 3 -- sigmoid: tanh(gamma*u'*v + coef0)\n" 29 | " 4 -- precomputed kernel (kernel values in training_set_file)\n" 30 | "-d degree : set degree in kernel function (default 3)\n" 31 | "-g gamma : set gamma in kernel function (default 1/num_features)\n" 32 | "-r coef0 : set coef0 in kernel function (default 0)\n" 33 | "-c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)\n" 34 | "-n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)\n" 35 | "-p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)\n" 36 | "-m cachesize : set cache memory size in MB (default 100)\n" 37 | "-e epsilon : set tolerance of termination criterion (default 0.001)\n" 38 | "-h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)\n" 39 | "-b probability_estimates : whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)\n" 40 | "-wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)\n" 41 | "-v n: n-fold cross validation mode\n" 42 | "-q : quiet mode (no outputs)\n" 43 | ); 44 | exit(1); 45 | } 46 | 47 | void exit_input_error(int line_num) 48 | { 49 | fprintf(stderr,"Wrong input format at line %d\n", line_num); 50 | exit(1); 51 | } 52 | 53 | void parse_command_line(int argc, char **argv, char *input_file_name, char *model_file_name); 54 | void read_problem(const char *filename); 55 | void do_cross_validation(); 56 | 57 | struct svm_parameter param; // set by parse_command_line 58 | struct svm_problem prob; // set by read_problem 59 | struct svm_model *model; 60 | struct svm_node *x_space; 61 | int cross_validation; 62 | int nr_fold; 63 | 64 | static char *line = NULL; 65 | static int max_line_len; 66 | 67 | static char* readline(FILE *input) 68 | { 69 | int len; 70 | 71 | if(fgets(line,max_line_len,input) == NULL) 72 | return NULL; 73 | 74 | while(strrchr(line,'\n') == NULL) 75 | { 76 | max_line_len *= 2; 77 | line = (char *) realloc(line,max_line_len); 78 | len = (int) strlen(line); 79 | if(fgets(line+len,max_line_len-len,input) == NULL) 80 | break; 81 | } 82 | return line; 83 | } 84 | 85 | int main(int argc, char **argv) 86 | { 87 | char input_file_name[1024]; 88 | char model_file_name[1024]; 89 | const char *error_msg; 90 | 91 | parse_command_line(argc, argv, input_file_name, model_file_name); 92 | read_problem(input_file_name); 93 | error_msg = svm_check_parameter(&prob,¶m); 94 | 95 | if(error_msg) 96 | { 97 | fprintf(stderr,"ERROR: %s\n",error_msg); 98 | exit(1); 99 | } 100 | 101 | if(cross_validation) 102 | { 103 | do_cross_validation(); 104 | } 105 | else 106 | { 107 | model = svm_train(&prob,¶m); 108 | if(svm_save_model(model_file_name,model)) 109 | { 110 | fprintf(stderr, "can't save model to file %s\n", model_file_name); 111 | exit(1); 112 | } 113 | svm_free_and_destroy_model(&model); 114 | } 115 | svm_destroy_param(¶m); 116 | free(prob.y); 117 | free(prob.x); 118 | free(x_space); 119 | free(line); 120 | 121 | return 0; 122 | } 123 | 124 | void do_cross_validation() 125 | { 126 | int i; 127 | int total_correct = 0; 128 | double total_error = 0; 129 | double sumv = 0, sumy = 0, sumvv = 0, sumyy = 0, sumvy = 0; 130 | double *target = Malloc(double,prob.l); 131 | 132 | svm_cross_validation(&prob,¶m,nr_fold,target); 133 | if(param.svm_type == EPSILON_SVR || 134 | param.svm_type == NU_SVR) 135 | { 136 | for(i=0;i=argc) 191 | exit_with_help(); 192 | switch(argv[i-1][1]) 193 | { 194 | case 's': 195 | param.svm_type = atoi(argv[i]); 196 | break; 197 | case 't': 198 | param.kernel_type = atoi(argv[i]); 199 | break; 200 | case 'd': 201 | param.degree = atoi(argv[i]); 202 | break; 203 | case 'g': 204 | param.gamma = atof(argv[i]); 205 | break; 206 | case 'r': 207 | param.coef0 = atof(argv[i]); 208 | break; 209 | case 'n': 210 | param.nu = atof(argv[i]); 211 | break; 212 | case 'm': 213 | param.cache_size = atof(argv[i]); 214 | break; 215 | case 'c': 216 | param.C = atof(argv[i]); 217 | break; 218 | case 'e': 219 | param.eps = atof(argv[i]); 220 | break; 221 | case 'p': 222 | param.p = atof(argv[i]); 223 | break; 224 | case 'h': 225 | param.shrinking = atoi(argv[i]); 226 | break; 227 | case 'b': 228 | param.probability = atoi(argv[i]); 229 | break; 230 | case 'q': 231 | print_func = &print_null; 232 | i--; 233 | break; 234 | case 'v': 235 | cross_validation = 1; 236 | nr_fold = atoi(argv[i]); 237 | if(nr_fold < 2) 238 | { 239 | fprintf(stderr,"n-fold cross validation: n must >= 2\n"); 240 | exit_with_help(); 241 | } 242 | break; 243 | case 'w': 244 | ++param.nr_weight; 245 | param.weight_label = (int *)realloc(param.weight_label,sizeof(int)*param.nr_weight); 246 | param.weight = (double *)realloc(param.weight,sizeof(double)*param.nr_weight); 247 | param.weight_label[param.nr_weight-1] = atoi(&argv[i-1][2]); 248 | param.weight[param.nr_weight-1] = atof(argv[i]); 249 | break; 250 | default: 251 | fprintf(stderr,"Unknown option: -%c\n", argv[i-1][1]); 252 | exit_with_help(); 253 | } 254 | } 255 | 256 | svm_set_print_string_function(print_func); 257 | 258 | // determine filenames 259 | 260 | if(i>=argc) 261 | exit_with_help(); 262 | 263 | strcpy(input_file_name, argv[i]); 264 | 265 | if(i start from 0 325 | readline(fp); 326 | prob.x[i] = &x_space[j]; 327 | label = strtok(line," \t\n"); 328 | if(label == NULL) // empty line 329 | exit_input_error(i+1); 330 | 331 | prob.y[i] = strtod(label,&endptr); 332 | if(endptr == label || *endptr != '\0') 333 | exit_input_error(i+1); 334 | 335 | while(1) 336 | { 337 | idx = strtok(NULL,":"); 338 | val = strtok(NULL," \t"); 339 | 340 | if(val == NULL) 341 | break; 342 | 343 | errno = 0; 344 | x_space[j].index = (int) strtol(idx,&endptr,10); 345 | if(endptr == idx || errno != 0 || *endptr != '\0' || x_space[j].index <= inst_max_index) 346 | exit_input_error(i+1); 347 | else 348 | inst_max_index = x_space[j].index; 349 | 350 | errno = 0; 351 | x_space[j].value = strtod(val,&endptr); 352 | if(endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr))) 353 | exit_input_error(i+1); 354 | 355 | ++j; 356 | } 357 | 358 | if(inst_max_index > max_index) 359 | max_index = inst_max_index; 360 | x_space[j++].index = -1; 361 | } 362 | 363 | if(param.gamma == 0 && max_index > 0) 364 | param.gamma = 1.0/max_index; 365 | 366 | if(param.kernel_type == PRECOMPUTED) 367 | for(i=0;i max_index) 375 | { 376 | fprintf(stderr,"Wrong input format: sample_serial_number out of range\n"); 377 | exit(1); 378 | } 379 | } 380 | 381 | fclose(fp); 382 | } 383 | } 384 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/libsvm/svm-train.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBSVM_TRAIN 2 | #define LIBSVM_TRAIN 3 | namespace svmtrain { 4 | int main(int argc, char **argv); 5 | } 6 | #endif 7 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/jni/libsvm/svm.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBSVM_H 2 | #define _LIBSVM_H 3 | 4 | #define LIBSVM_VERSION 320 5 | 6 | #include "../common.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | extern int libsvm_version; 13 | 14 | struct svm_node 15 | { 16 | int index; 17 | double value; 18 | }; 19 | 20 | struct svm_problem 21 | { 22 | int l; 23 | double *y; 24 | struct svm_node **x; 25 | }; 26 | 27 | enum { C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR }; /* svm_type */ 28 | enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; /* kernel_type */ 29 | 30 | struct svm_parameter 31 | { 32 | int svm_type; 33 | int kernel_type; 34 | int degree; /* for poly */ 35 | double gamma; /* for poly/rbf/sigmoid */ 36 | double coef0; /* for poly/sigmoid */ 37 | 38 | /* these are for training only */ 39 | double cache_size; /* in MB */ 40 | double eps; /* stopping criteria */ 41 | double C; /* for C_SVC, EPSILON_SVR and NU_SVR */ 42 | int nr_weight; /* for C_SVC */ 43 | int *weight_label; /* for C_SVC */ 44 | double* weight; /* for C_SVC */ 45 | double nu; /* for NU_SVC, ONE_CLASS, and NU_SVR */ 46 | double p; /* for EPSILON_SVR */ 47 | int shrinking; /* use the shrinking heuristics */ 48 | int probability; /* do probability estimates */ 49 | }; 50 | 51 | // 52 | // svm_model 53 | // 54 | struct svm_model 55 | { 56 | struct svm_parameter param; /* parameter */ 57 | int nr_class; /* number of classes, = 2 in regression/one class svm */ 58 | int l; /* total #SV */ 59 | struct svm_node **SV; /* SVs (SV[l]) */ 60 | double **sv_coef; /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */ 61 | double *rho; /* constants in decision functions (rho[k*(k-1)/2]) */ 62 | double *probA; /* pariwise probability information */ 63 | double *probB; 64 | int *sv_indices; /* sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the training set */ 65 | 66 | /* for classification only */ 67 | 68 | int *label; /* label of each class (label[k]) */ 69 | int *nSV; /* number of SVs for each class (nSV[k]) */ 70 | /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */ 71 | /* XXX */ 72 | int free_sv; /* 1 if svm_model is created by svm_load_model*/ 73 | /* 0 if svm_model is created by svm_train */ 74 | }; 75 | 76 | struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param); 77 | void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target); 78 | 79 | int svm_save_model(const char *model_file_name, const struct svm_model *model); 80 | struct svm_model *svm_load_model(const char *model_file_name); 81 | 82 | int svm_get_svm_type(const struct svm_model *model); 83 | int svm_get_nr_class(const struct svm_model *model); 84 | void svm_get_labels(const struct svm_model *model, int *label); 85 | void svm_get_sv_indices(const struct svm_model *model, int *sv_indices); 86 | int svm_get_nr_sv(const struct svm_model *model); 87 | double svm_get_svr_probability(const struct svm_model *model); 88 | 89 | double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double* dec_values); 90 | double svm_predict(const struct svm_model *model, const struct svm_node *x); 91 | double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double* prob_estimates); 92 | 93 | void svm_free_model_content(struct svm_model *model_ptr); 94 | void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr); 95 | void svm_destroy_param(struct svm_parameter *param); 96 | 97 | const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param); 98 | int svm_check_probability_model(const struct svm_model *model); 99 | 100 | void svm_set_print_string_function(void (*print_func)(const char *)); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* _LIBSVM_H */ 107 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidLibSVM 3 | 4 | -------------------------------------------------------------------------------- /AndroidLibSVM/androidlibsvm/src/test/java/umich/cse/yctung/androidlibsvm/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package umich.cse.yctung.androidlibsvm; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /AndroidLibSVM/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /AndroidLibSVM/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | applicationId "edu.umich.eecs.androidlibsvm" 9 | minSdkVersion 22 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile project(path: ':androidlibsvm') 25 | } 26 | -------------------------------------------------------------------------------- /AndroidLibSVM/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/eddyxd/adt/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /AndroidLibSVM/app/src/androidTest/java/edu/umich/eecs/androidlibsvm/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package edu.umich.eecs.androidlibsvm; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /AndroidLibSVM/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 13 | 14 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /AndroidLibSVM/app/src/main/assets/heart_scale_predict: -------------------------------------------------------------------------------- 1 | -1 1:0.0416667 2:-1 3:0.333333 4:-0.698113 5:-0.598174 6:-1 7:-1 8:0.328244 9:-1 10:-0.483871 12:-1 13:-1 2 | -1 1:0.666667 2:-1 3:-1 4:-0.132075 5:-0.484018 6:-1 7:-1 8:0.221374 9:-1 10:-0.419355 11:-1 12:0.333333 13:-1 3 | +1 1:1 2:1 3:1 4:-0.415094 5:-0.187215 6:-1 7:1 8:0.389313 9:1 10:-1 11:-1 12:1 13:-1 4 | -1 1:0.625 2:1 3:0.333333 4:-0.54717 5:-0.310502 6:-1 7:-1 8:0.221374 9:-1 10:-0.677419 11:-1 12:-0.333333 13:1 5 | +1 1:0.208333 2:1 3:1 4:-0.415094 5:-0.205479 6:-1 7:1 8:0.526718 9:-1 10:-1 11:-1 12:0.333333 13:1 6 | +1 1:0.291667 2:1 3:1 4:-0.415094 5:-0.39726 6:-1 7:1 8:0.0687023 9:1 10:-0.0967742 12:-0.333333 13:1 7 | +1 1:-0.0833333 2:1 3:1 4:-0.132075 5:-0.210046 6:-1 7:-1 8:0.557252 9:1 10:-0.483871 11:-1 12:-1 13:1 8 | +1 1:0.0833333 2:1 3:1 4:0.245283 5:-0.255708 6:-1 7:1 8:0.129771 9:1 10:-0.741935 12:-0.333333 13:1 9 | -1 1:-0.0416667 2:1 3:-1 4:0.0943396 5:-0.214612 6:1 7:-1 8:0.633588 9:-1 10:-0.612903 12:-1 13:1 10 | -1 1:0.291667 2:-1 3:0.333333 4:-0.849057 5:-0.123288 6:-1 7:-1 8:0.358779 9:-1 10:-1 11:-1 12:-0.333333 13:-1 11 | -1 1:0.208333 2:1 3:0.333333 4:-0.792453 5:-0.479452 6:-1 7:1 8:0.267176 9:1 10:-0.806452 12:-1 13:1 12 | +1 1:0.458333 2:1 3:0.333333 4:-0.415094 5:-0.164384 6:-1 7:-1 8:-0.0839695 9:1 10:-0.419355 12:-1 13:1 13 | -1 1:-0.666667 2:1 3:0.333333 4:-0.320755 5:-0.43379 6:-1 7:-1 8:0.770992 9:-1 10:0.129032 11:1 12:-1 13:-1 14 | +1 1:0.25 2:1 3:-1 4:0.433962 5:-0.260274 6:-1 7:1 8:0.343511 9:-1 10:-0.935484 12:-1 13:1 15 | -1 1:-0.0833333 2:1 3:0.333333 4:-0.415094 5:-0.456621 6:1 7:1 8:0.450382 9:-1 10:-0.225806 12:-1 13:-1 16 | -1 1:-0.416667 2:-1 3:0.333333 4:-0.471698 5:-0.60274 6:-1 7:-1 8:0.435115 9:-1 10:-0.935484 12:-1 13:-1 17 | +1 1:0.208333 2:1 3:1 4:-0.358491 5:-0.589041 6:-1 7:1 8:-0.0839695 9:1 10:-0.290323 12:1 13:1 18 | -1 1:-1 2:1 3:-0.333333 4:-0.320755 5:-0.643836 6:-1 7:1 8:1 9:-1 10:-1 11:-1 12:-1 13:-1 19 | -1 1:-0.5 2:-1 3:-0.333333 4:-0.320755 5:-0.643836 6:-1 7:1 8:0.541985 9:-1 10:-0.548387 11:-1 12:-1 13:-1 20 | -1 1:0.416667 2:-1 3:0.333333 4:-0.226415 5:-0.424658 6:-1 7:1 8:0.541985 9:-1 10:-1 11:-1 12:-1 13:-1 21 | -1 1:-0.0833333 2:1 3:0.333333 4:-1 5:-0.538813 6:-1 7:-1 8:0.267176 9:1 10:-1 11:-1 12:-0.333333 13:1 22 | -1 1:0.0416667 2:1 3:0.333333 4:-0.509434 5:-0.39726 6:-1 7:1 8:0.160305 9:-1 10:-0.870968 12:-1 13:1 23 | -1 1:-0.375 2:1 3:-0.333333 4:-0.509434 5:-0.570776 6:-1 7:-1 8:0.51145 9:-1 10:-1 11:-1 12:-1 13:-1 24 | +1 1:0.0416667 2:1 3:1 4:-0.698113 5:-0.484018 6:-1 7:-1 8:-0.160305 9:1 10:-0.0967742 12:-0.333333 13:1 25 | +1 1:0.5 2:1 3:1 4:-0.226415 5:-0.415525 6:-1 7:1 8:-0.145038 9:-1 10:-0.0967742 12:-0.333333 13:1 26 | -1 1:0.166667 2:1 3:0.333333 4:0.0566038 5:-0.808219 6:-1 7:-1 8:0.572519 9:-1 10:-0.483871 11:-1 12:-1 13:-1 27 | +1 1:0.416667 2:1 3:1 4:-0.320755 5:-0.0684932 6:1 7:1 8:-0.0687023 9:1 10:-0.419355 11:-1 12:1 13:1 28 | -1 1:-0.75 2:-1 3:1 4:-0.169811 5:-0.739726 6:-1 7:-1 8:0.694656 9:-1 10:-0.548387 11:-1 12:-1 13:-1 29 | -1 1:-0.5 2:1 3:-0.333333 4:-0.226415 5:-0.648402 6:-1 7:-1 8:-0.0687023 9:-1 10:-1 12:-1 13:0.5 30 | +1 1:0.375 2:-1 3:0.333333 4:-0.320755 5:-0.374429 6:-1 7:-1 8:-0.603053 9:-1 10:-0.612903 12:-0.333333 13:1 31 | +1 1:-0.416667 2:-1 3:1 4:-0.283019 5:-0.0182648 6:1 7:1 8:-0.00763359 9:1 10:-0.0322581 12:-1 13:1 32 | -1 1:0.208333 2:-1 3:-1 4:0.0566038 5:-0.283105 6:1 7:1 8:0.389313 9:-1 10:-0.677419 11:-1 12:-1 13:-1 33 | -1 1:-0.0416667 2:1 3:-1 4:-0.54717 5:-0.726027 6:-1 7:1 8:0.816794 9:-1 10:-1 12:-1 13:0.5 34 | +1 1:0.333333 2:-1 3:1 4:-0.0377358 5:-0.173516 6:-1 7:1 8:0.145038 9:1 10:-0.677419 12:-1 13:1 35 | +1 1:-0.583333 2:1 3:1 4:-0.54717 5:-0.575342 6:-1 7:-1 8:0.0534351 9:-1 10:-0.612903 12:-1 13:1 36 | -1 1:-0.333333 2:1 3:1 4:-0.603774 5:-0.388128 6:-1 7:1 8:0.740458 9:-1 10:-1 11:-1 12:-1 13:-1 37 | +1 1:-0.0416667 2:1 3:1 4:-0.358491 5:-0.410959 6:-1 7:-1 8:0.374046 9:1 10:-1 11:-1 12:-0.333333 13:1 38 | -1 1:0.375 2:1 3:0.333333 4:-0.320755 5:-0.520548 6:-1 7:-1 8:0.145038 9:-1 10:-0.419355 12:1 13:1 39 | +1 1:0.375 2:-1 3:1 4:0.245283 5:-0.826484 6:-1 7:1 8:0.129771 9:-1 10:1 11:1 12:1 13:1 40 | -1 2:-1 3:1 4:-0.169811 5:-0.506849 6:-1 7:1 8:0.358779 9:-1 10:-1 11:-1 12:-1 13:-1 41 | +1 1:-0.416667 2:1 3:1 4:-0.509434 5:-0.767123 6:-1 7:1 8:-0.251908 9:1 10:-0.193548 12:-1 13:1 42 | -1 1:-0.25 2:1 3:0.333333 4:-0.169811 5:-0.401826 6:-1 7:1 8:0.29771 9:-1 10:-1 11:-1 12:-1 13:-1 43 | -1 1:-0.0416667 2:1 3:-0.333333 4:-0.509434 5:-0.0913242 6:-1 7:-1 8:0.541985 9:-1 10:-0.935484 11:-1 12:-1 13:-1 44 | +1 1:0.625 2:1 3:0.333333 4:0.622642 5:-0.324201 6:1 7:1 8:0.206107 9:1 10:-0.483871 12:-1 13:1 45 | -1 1:-0.583333 2:1 3:0.333333 4:-0.132075 5:-0.109589 6:-1 7:1 8:0.694656 9:-1 10:-1 11:-1 12:-1 13:-1 46 | -1 2:-1 3:1 4:-0.320755 5:-0.369863 6:-1 7:1 8:0.0992366 9:-1 10:-0.870968 12:-1 13:-1 47 | +1 1:0.375 2:-1 3:1 4:-0.132075 5:-0.351598 6:-1 7:1 8:0.358779 9:-1 10:0.16129 11:1 12:0.333333 13:-1 48 | -1 1:-0.0833333 2:-1 3:0.333333 4:-0.132075 5:-0.16895 6:-1 7:1 8:0.0839695 9:-1 10:-0.516129 11:-1 12:-0.333333 13:-1 49 | +1 1:0.291667 2:1 3:1 4:-0.320755 5:-0.420091 6:-1 7:-1 8:0.114504 9:1 10:-0.548387 11:-1 12:-0.333333 13:1 50 | +1 1:0.5 2:1 3:1 4:-0.698113 5:-0.442922 6:-1 7:1 8:0.328244 9:-1 10:-0.806452 11:-1 12:0.333333 13:0.5 51 | -1 1:0.5 2:-1 3:0.333333 4:0.150943 5:-0.347032 6:-1 7:-1 8:0.175573 9:-1 10:-0.741935 11:-1 12:-1 13:-1 52 | +1 1:0.291667 2:1 3:0.333333 4:-0.132075 5:-0.730594 6:-1 7:1 8:0.282443 9:-1 10:-0.0322581 12:-1 13:-1 53 | +1 1:0.291667 2:1 3:1 4:-0.0377358 5:-0.287671 6:-1 7:1 8:0.0839695 9:1 10:-0.0967742 12:0.333333 13:1 54 | +1 1:0.0416667 2:1 3:1 4:-0.509434 5:-0.716895 6:-1 7:-1 8:-0.358779 9:-1 10:-0.548387 12:-0.333333 13:1 55 | -1 1:-0.375 2:1 3:-0.333333 4:-0.320755 5:-0.575342 6:-1 7:1 8:0.78626 9:-1 10:-1 11:-1 12:-1 13:-1 56 | +1 1:-0.375 2:1 3:1 4:-0.660377 5:-0.251142 6:-1 7:1 8:0.251908 9:-1 10:-1 11:-1 12:-0.333333 13:-1 57 | -1 1:-0.0833333 2:1 3:0.333333 4:-0.698113 5:-0.776256 6:-1 7:-1 8:-0.206107 9:-1 10:-0.806452 11:-1 12:-1 13:-1 58 | -1 1:0.25 2:1 3:0.333333 4:0.0566038 5:-0.607306 6:1 7:-1 8:0.312977 9:-1 10:-0.483871 11:-1 12:-1 13:-1 59 | -1 1:0.75 2:-1 3:-0.333333 4:0.245283 5:-0.196347 6:-1 7:-1 8:0.389313 9:-1 10:-0.870968 11:-1 12:0.333333 13:-1 60 | -1 1:0.333333 2:1 3:0.333333 4:0.0566038 5:-0.465753 6:1 7:-1 8:0.00763359 9:1 10:-0.677419 12:-1 13:-1 61 | +1 1:0.0833333 2:1 3:1 4:-0.283019 5:0.0365297 6:-1 7:-1 8:-0.0687023 9:1 10:-0.612903 12:-0.333333 13:1 62 | +1 1:0.458333 2:1 3:0.333333 4:-0.132075 5:-0.0456621 6:-1 7:-1 8:0.328244 9:-1 10:-1 11:-1 12:-1 13:-1 63 | -1 1:-0.416667 2:1 3:1 4:0.0566038 5:-0.447489 6:-1 7:-1 8:0.526718 9:-1 10:-0.516129 11:-1 12:-1 13:-1 64 | -1 1:0.208333 2:-1 3:0.333333 4:-0.509434 5:-0.0228311 6:-1 7:-1 8:0.541985 9:-1 10:-1 11:-1 12:-1 13:-1 65 | +1 1:0.291667 2:1 3:1 4:-0.320755 5:-0.634703 6:-1 7:1 8:-0.0687023 9:1 10:-0.225806 12:0.333333 13:1 66 | +1 1:0.208333 2:1 3:-0.333333 4:-0.509434 5:-0.278539 6:-1 7:1 8:0.358779 9:-1 10:-0.419355 12:-1 13:-1 67 | -1 1:-0.166667 2:1 3:-0.333333 4:-0.320755 5:-0.360731 6:-1 7:-1 8:0.526718 9:-1 10:-0.806452 11:-1 12:-1 13:-1 68 | +1 1:-0.208333 2:1 3:-0.333333 4:-0.698113 5:-0.52968 6:-1 7:-1 8:0.480916 9:-1 10:-0.677419 11:1 12:-1 13:1 69 | -1 1:-0.0416667 2:1 3:0.333333 4:0.471698 5:-0.666667 6:1 7:-1 8:0.389313 9:-1 10:-0.83871 11:-1 12:-1 13:1 70 | -1 1:-0.375 2:1 3:-0.333333 4:-0.509434 5:-0.374429 6:-1 7:-1 8:0.557252 9:-1 10:-1 11:-1 12:-1 13:1 71 | -1 1:0.125 2:-1 3:-0.333333 4:-0.132075 5:-0.232877 6:-1 7:1 8:0.251908 9:-1 10:-0.580645 12:-1 13:-1 72 | -1 1:0.166667 2:1 3:1 4:-0.132075 5:-0.69863 6:-1 7:-1 8:0.175573 9:-1 10:-0.870968 12:-1 13:0.5 73 | +1 1:0.583333 2:1 3:1 4:0.245283 5:-0.269406 6:-1 7:1 8:-0.435115 9:1 10:-0.516129 12:1 13:-1 74 | -------------------------------------------------------------------------------- /AndroidLibSVM/app/src/main/java/edu/umich/eecs/androidlibsvm/MainActivity.java: -------------------------------------------------------------------------------- 1 | package edu.umich.eecs.androidlibsvm; 2 | 3 | import android.app.Activity; 4 | import android.content.res.AssetManager; 5 | import android.os.Bundle; 6 | import android.os.Environment; 7 | import android.util.Log; 8 | 9 | import java.io.File; 10 | import java.io.FileOutputStream; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.io.OutputStream; 14 | 15 | import umich.cse.yctung.androidlibsvm.LibSVM; 16 | 17 | public class MainActivity extends Activity { 18 | LibSVM svm; 19 | static final String LOG_TAG = "LibSVMApp"; 20 | String appFolderPath; 21 | String systemPath; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_main); 27 | systemPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/"; 28 | appFolderPath = systemPath+"libsvm/"; 29 | 30 | // 1. create necessary folder to save model files 31 | CreateAppFolderIfNeed(); 32 | copyAssetsDataIfNeed(); 33 | 34 | // 2. assign model/output paths 35 | String dataTrainPath = appFolderPath+"heart_scale "; 36 | String dataScaledPath = appFolderPath+"scaled"; 37 | String dataPredictPath = appFolderPath+"heart_scale "; 38 | String modelPath = appFolderPath+"model "; 39 | String outputPath = appFolderPath+"predict "; 40 | 41 | svm = new LibSVM(); 42 | 43 | // 3. (optional) make SVM scale 44 | // NOTE: the jni interface is different from the original svm-scale because the it requires 45 | // to redirect the output by Linux Redirecting, e.g., svm-scale input > out 46 | // in this case, the jni interface changed to: jniSvmScale(input, output) 47 | svm.scale(dataTrainPath, dataScaledPath); 48 | 49 | // 4. make SVM train 50 | String svmTrainOptions = "-t 2 "; // note the ending space 51 | svm.train(svmTrainOptions + dataTrainPath + modelPath); 52 | 53 | // 5. make SVM predict 54 | svm.predict(dataPredictPath + modelPath + outputPath); 55 | } 56 | 57 | 58 | // Some utility functions 59 | private void CreateAppFolderIfNeed(){ 60 | // 1. create app folder if necessary 61 | File folder = new File(appFolderPath); 62 | 63 | if (!folder.exists()) { 64 | folder.mkdir(); 65 | Log.d(LOG_TAG,"Appfolder is not existed, create one"); 66 | } else { 67 | Log.w(LOG_TAG,"WARN: Appfolder has not been deleted"); 68 | } 69 | 70 | 71 | } 72 | 73 | private void copyAssetsDataIfNeed(){ 74 | String assetsToCopy[] = {"heart_scale_predict","heart_scale_train","heart_scale"}; 75 | //String targetPath[] = {C.systemPath+C.INPUT_FOLDER+C.INPUT_PREFIX+AudioConfigManager.inputConfigTrain+".wav", C.systemPath+C.INPUT_FOLDER+C.INPUT_PREFIX+AudioConfigManager.inputConfigPredict+".wav",C.systemPath+C.INPUT_FOLDER+"SomeoneLikeYouShort.mp3"}; 76 | 77 | for(int i=0; i 7 | 8 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /AndroidLibSVM/app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /AndroidLibSVM/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yctung/AndroidLibSVM/282e44fa88153b4334b759af8c5632428175a26e/AndroidLibSVM/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidLibSVM/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yctung/AndroidLibSVM/282e44fa88153b4334b759af8c5632428175a26e/AndroidLibSVM/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidLibSVM/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yctung/AndroidLibSVM/282e44fa88153b4334b759af8c5632428175a26e/AndroidLibSVM/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidLibSVM/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yctung/AndroidLibSVM/282e44fa88153b4334b759af8c5632428175a26e/AndroidLibSVM/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidLibSVM/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /AndroidLibSVM/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /AndroidLibSVM/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidLibSvm 3 | 4 | Hello world! 5 | Settings 6 | 7 | -------------------------------------------------------------------------------- /AndroidLibSVM/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /AndroidLibSVM/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.3.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /AndroidLibSVM/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | #org.gradle.jvmargs=-Xdebug 15 | org.gradle.jvmargs=-Xmx1536m 16 | 17 | # When configured, Gradle will run in incubating parallel mode. 18 | # This option should only be used with decoupled projects. More details, visit 19 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 20 | # org.gradle.parallel=true 21 | android.useDeprecatedNdk=true 22 | -------------------------------------------------------------------------------- /AndroidLibSVM/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yctung/AndroidLibSVM/282e44fa88153b4334b759af8c5632428175a26e/AndroidLibSVM/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /AndroidLibSVM/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Sep 25 23:53:56 EDT 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /AndroidLibSVM/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /AndroidLibSVM/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':androidlibsvm' 2 | -------------------------------------------------------------------------------- /COPYRIGHT.txt: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2000-2017 Chih-Chung Chang and Chih-Jen Lin 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither name of copyright holders nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /Deprecated/README.md: -------------------------------------------------------------------------------- 1 | # AndroidLibSvm 2 | 3 | use the latest libsvm 3.2 in Android via Java-Native-Interface (JNI) 4 | 5 | ## Features 6 | - minimal changes on the original c library (https://www.csie.ntu.edu.tw/~cjlin/libsvm/) 7 | - use the latest libsvm 3.2 8 | - compatible to Android Studio 9 | 10 | ## Usage 11 | Once you import the whole project to your Android Studio and run it on your device. The svm model and prediction output file will be located at /sdcard/libsvm of your device. 12 | You can also check the livsvm output at your logcat output. 13 | 14 | In java, you can call the original "./svm-train options" function as: 15 | ```sh 16 | jniSvmTrain(String options); 17 | ``` 18 | 19 | In a similar way, the the origianl "./svm-predict options" function is equivalent to: 20 | ```sh 21 | jniSvmPredict(String options); 22 | ``` 23 | 24 | An example usage in Java could be: 25 | ```sh 26 | jniSvmTrain("-t 2 your_train_data_path your_model_file_path"); 27 | jniSvmPredict("your_predict_data_path your_model_file_path your_output_file_path"); 28 | ``` 29 | 30 | The svm-scale is also supported. Please note that I changed the input interface becasue the original svm-scale relies on linux redirecting (e.g., svm-scale input > out) 31 | An example could be: 32 | ```sh 33 | jniSvmScale("-l -1 -u 1 your_input_data_path", "your_output_file_path"); 34 | ``` 35 | 36 | By reading and analyze the output file, most applications can easily enjoy the powerful libsvm functionaility with this project. 37 | 38 | ## Troubleshooting 39 | Your Android Studio might complain something about "(null)/ndk-build". This is because the compiler doesn't get the path of your local ndk path 40 | - Solution: add ndk path to your local.properties file like this: "ndk.dir=/Users/MyName/Android/ndk" 41 | 42 | ## Include this project to existing Android project 43 | To use this project in your existing Android project, you need to do the following actions: 44 | - copy the whole AndroidLibSvm/app/src/main/jni/ to your project (with the same relative path) 45 | - edit AndroidLibSvm/app/src/main/jni/jnilibsvm.cpp to replace any occurance of "edu_umich_eecs_androidlibsvm_MainActivity" to your package and activity name. For example, if your package name is com.happy.project and your activity name is HappyActivity, you should change the prefix to com_happy_project_HappyActivity (see this link to know the name convention in JNI: `http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/declare.html`). 46 | - copy the AndroidLibSvm/app/build.gradle to your project and ensure ndk-build is installed (see this link for further reference about compiling ndk functions in Android: `http://www.shaneenishry.com/blog/2014/08/17/ndk-with-android-studio/`). 47 | 48 | -------------------------------------------------------------------------------- /Deprecated/androidlibsvm-release.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yctung/AndroidLibSVM/282e44fa88153b4334b759af8c5632428175a26e/Deprecated/androidlibsvm-release.aar -------------------------------------------------------------------------------- /Example/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /Example/androidlibsvm-release/androidlibsvm-release.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yctung/AndroidLibSVM/282e44fa88153b4334b759af8c5632428175a26e/Example/androidlibsvm-release/androidlibsvm-release.aar -------------------------------------------------------------------------------- /Example/androidlibsvm-release/build.gradle: -------------------------------------------------------------------------------- 1 | configurations.maybeCreate("default") 2 | artifacts.add("default", file('androidlibsvm-release.aar')) -------------------------------------------------------------------------------- /Example/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Example/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.test.libsvmandroidexample" 8 | minSdkVersion 22 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | 14 | compileOptions { 15 | sourceCompatibility JavaVersion.VERSION_1_7 16 | targetCompatibility JavaVersion.VERSION_1_7 17 | } 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | compile fileTree(include: ['*.jar'], dir: 'libs') 29 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 30 | exclude group: 'com.android.support', module: 'support-annotations' 31 | }) 32 | compile 'com.android.support:support-v4:25.3.1' 33 | compile 'com.android.support:appcompat-v7:25.3.1' 34 | compile 'com.android.support:design:25.3.1' 35 | compile 'com.android.support:cardview-v7:25.3.1' 36 | compile 'com.adityak:browsemyfiles:1.4' 37 | compile 'net.alhazmy13.Gota:libary:1.4.1' 38 | testCompile 'junit:junit:4.12' 39 | compile project(':androidlibsvm-release') 40 | } 41 | -------------------------------------------------------------------------------- /Example/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/isaacfreeman/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /Example/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Example/app/src/main/assets/data/heart_scale_predict: -------------------------------------------------------------------------------- 1 | -1 1:0.0416667 2:-1 3:0.333333 4:-0.698113 5:-0.598174 6:-1 7:-1 8:0.328244 9:-1 10:-0.483871 12:-1 13:-1 2 | -1 1:0.666667 2:-1 3:-1 4:-0.132075 5:-0.484018 6:-1 7:-1 8:0.221374 9:-1 10:-0.419355 11:-1 12:0.333333 13:-1 3 | +1 1:1 2:1 3:1 4:-0.415094 5:-0.187215 6:-1 7:1 8:0.389313 9:1 10:-1 11:-1 12:1 13:-1 4 | -1 1:0.625 2:1 3:0.333333 4:-0.54717 5:-0.310502 6:-1 7:-1 8:0.221374 9:-1 10:-0.677419 11:-1 12:-0.333333 13:1 5 | +1 1:0.208333 2:1 3:1 4:-0.415094 5:-0.205479 6:-1 7:1 8:0.526718 9:-1 10:-1 11:-1 12:0.333333 13:1 6 | +1 1:0.291667 2:1 3:1 4:-0.415094 5:-0.39726 6:-1 7:1 8:0.0687023 9:1 10:-0.0967742 12:-0.333333 13:1 7 | +1 1:-0.0833333 2:1 3:1 4:-0.132075 5:-0.210046 6:-1 7:-1 8:0.557252 9:1 10:-0.483871 11:-1 12:-1 13:1 8 | +1 1:0.0833333 2:1 3:1 4:0.245283 5:-0.255708 6:-1 7:1 8:0.129771 9:1 10:-0.741935 12:-0.333333 13:1 9 | -1 1:-0.0416667 2:1 3:-1 4:0.0943396 5:-0.214612 6:1 7:-1 8:0.633588 9:-1 10:-0.612903 12:-1 13:1 10 | -1 1:0.291667 2:-1 3:0.333333 4:-0.849057 5:-0.123288 6:-1 7:-1 8:0.358779 9:-1 10:-1 11:-1 12:-0.333333 13:-1 11 | -1 1:0.208333 2:1 3:0.333333 4:-0.792453 5:-0.479452 6:-1 7:1 8:0.267176 9:1 10:-0.806452 12:-1 13:1 12 | +1 1:0.458333 2:1 3:0.333333 4:-0.415094 5:-0.164384 6:-1 7:-1 8:-0.0839695 9:1 10:-0.419355 12:-1 13:1 13 | -1 1:-0.666667 2:1 3:0.333333 4:-0.320755 5:-0.43379 6:-1 7:-1 8:0.770992 9:-1 10:0.129032 11:1 12:-1 13:-1 14 | +1 1:0.25 2:1 3:-1 4:0.433962 5:-0.260274 6:-1 7:1 8:0.343511 9:-1 10:-0.935484 12:-1 13:1 15 | -1 1:-0.0833333 2:1 3:0.333333 4:-0.415094 5:-0.456621 6:1 7:1 8:0.450382 9:-1 10:-0.225806 12:-1 13:-1 16 | -1 1:-0.416667 2:-1 3:0.333333 4:-0.471698 5:-0.60274 6:-1 7:-1 8:0.435115 9:-1 10:-0.935484 12:-1 13:-1 17 | +1 1:0.208333 2:1 3:1 4:-0.358491 5:-0.589041 6:-1 7:1 8:-0.0839695 9:1 10:-0.290323 12:1 13:1 18 | -1 1:-1 2:1 3:-0.333333 4:-0.320755 5:-0.643836 6:-1 7:1 8:1 9:-1 10:-1 11:-1 12:-1 13:-1 19 | -1 1:-0.5 2:-1 3:-0.333333 4:-0.320755 5:-0.643836 6:-1 7:1 8:0.541985 9:-1 10:-0.548387 11:-1 12:-1 13:-1 20 | -1 1:0.416667 2:-1 3:0.333333 4:-0.226415 5:-0.424658 6:-1 7:1 8:0.541985 9:-1 10:-1 11:-1 12:-1 13:-1 21 | -1 1:-0.0833333 2:1 3:0.333333 4:-1 5:-0.538813 6:-1 7:-1 8:0.267176 9:1 10:-1 11:-1 12:-0.333333 13:1 22 | -1 1:0.0416667 2:1 3:0.333333 4:-0.509434 5:-0.39726 6:-1 7:1 8:0.160305 9:-1 10:-0.870968 12:-1 13:1 23 | -1 1:-0.375 2:1 3:-0.333333 4:-0.509434 5:-0.570776 6:-1 7:-1 8:0.51145 9:-1 10:-1 11:-1 12:-1 13:-1 24 | +1 1:0.0416667 2:1 3:1 4:-0.698113 5:-0.484018 6:-1 7:-1 8:-0.160305 9:1 10:-0.0967742 12:-0.333333 13:1 25 | +1 1:0.5 2:1 3:1 4:-0.226415 5:-0.415525 6:-1 7:1 8:-0.145038 9:-1 10:-0.0967742 12:-0.333333 13:1 26 | -1 1:0.166667 2:1 3:0.333333 4:0.0566038 5:-0.808219 6:-1 7:-1 8:0.572519 9:-1 10:-0.483871 11:-1 12:-1 13:-1 27 | +1 1:0.416667 2:1 3:1 4:-0.320755 5:-0.0684932 6:1 7:1 8:-0.0687023 9:1 10:-0.419355 11:-1 12:1 13:1 28 | -1 1:-0.75 2:-1 3:1 4:-0.169811 5:-0.739726 6:-1 7:-1 8:0.694656 9:-1 10:-0.548387 11:-1 12:-1 13:-1 29 | -1 1:-0.5 2:1 3:-0.333333 4:-0.226415 5:-0.648402 6:-1 7:-1 8:-0.0687023 9:-1 10:-1 12:-1 13:0.5 30 | +1 1:0.375 2:-1 3:0.333333 4:-0.320755 5:-0.374429 6:-1 7:-1 8:-0.603053 9:-1 10:-0.612903 12:-0.333333 13:1 31 | +1 1:-0.416667 2:-1 3:1 4:-0.283019 5:-0.0182648 6:1 7:1 8:-0.00763359 9:1 10:-0.0322581 12:-1 13:1 32 | -1 1:0.208333 2:-1 3:-1 4:0.0566038 5:-0.283105 6:1 7:1 8:0.389313 9:-1 10:-0.677419 11:-1 12:-1 13:-1 33 | -1 1:-0.0416667 2:1 3:-1 4:-0.54717 5:-0.726027 6:-1 7:1 8:0.816794 9:-1 10:-1 12:-1 13:0.5 34 | +1 1:0.333333 2:-1 3:1 4:-0.0377358 5:-0.173516 6:-1 7:1 8:0.145038 9:1 10:-0.677419 12:-1 13:1 35 | +1 1:-0.583333 2:1 3:1 4:-0.54717 5:-0.575342 6:-1 7:-1 8:0.0534351 9:-1 10:-0.612903 12:-1 13:1 36 | -1 1:-0.333333 2:1 3:1 4:-0.603774 5:-0.388128 6:-1 7:1 8:0.740458 9:-1 10:-1 11:-1 12:-1 13:-1 37 | +1 1:-0.0416667 2:1 3:1 4:-0.358491 5:-0.410959 6:-1 7:-1 8:0.374046 9:1 10:-1 11:-1 12:-0.333333 13:1 38 | -1 1:0.375 2:1 3:0.333333 4:-0.320755 5:-0.520548 6:-1 7:-1 8:0.145038 9:-1 10:-0.419355 12:1 13:1 39 | +1 1:0.375 2:-1 3:1 4:0.245283 5:-0.826484 6:-1 7:1 8:0.129771 9:-1 10:1 11:1 12:1 13:1 40 | -1 2:-1 3:1 4:-0.169811 5:-0.506849 6:-1 7:1 8:0.358779 9:-1 10:-1 11:-1 12:-1 13:-1 41 | +1 1:-0.416667 2:1 3:1 4:-0.509434 5:-0.767123 6:-1 7:1 8:-0.251908 9:1 10:-0.193548 12:-1 13:1 42 | -1 1:-0.25 2:1 3:0.333333 4:-0.169811 5:-0.401826 6:-1 7:1 8:0.29771 9:-1 10:-1 11:-1 12:-1 13:-1 43 | -1 1:-0.0416667 2:1 3:-0.333333 4:-0.509434 5:-0.0913242 6:-1 7:-1 8:0.541985 9:-1 10:-0.935484 11:-1 12:-1 13:-1 44 | +1 1:0.625 2:1 3:0.333333 4:0.622642 5:-0.324201 6:1 7:1 8:0.206107 9:1 10:-0.483871 12:-1 13:1 45 | -1 1:-0.583333 2:1 3:0.333333 4:-0.132075 5:-0.109589 6:-1 7:1 8:0.694656 9:-1 10:-1 11:-1 12:-1 13:-1 46 | -1 2:-1 3:1 4:-0.320755 5:-0.369863 6:-1 7:1 8:0.0992366 9:-1 10:-0.870968 12:-1 13:-1 47 | +1 1:0.375 2:-1 3:1 4:-0.132075 5:-0.351598 6:-1 7:1 8:0.358779 9:-1 10:0.16129 11:1 12:0.333333 13:-1 48 | -1 1:-0.0833333 2:-1 3:0.333333 4:-0.132075 5:-0.16895 6:-1 7:1 8:0.0839695 9:-1 10:-0.516129 11:-1 12:-0.333333 13:-1 49 | +1 1:0.291667 2:1 3:1 4:-0.320755 5:-0.420091 6:-1 7:-1 8:0.114504 9:1 10:-0.548387 11:-1 12:-0.333333 13:1 50 | +1 1:0.5 2:1 3:1 4:-0.698113 5:-0.442922 6:-1 7:1 8:0.328244 9:-1 10:-0.806452 11:-1 12:0.333333 13:0.5 51 | -1 1:0.5 2:-1 3:0.333333 4:0.150943 5:-0.347032 6:-1 7:-1 8:0.175573 9:-1 10:-0.741935 11:-1 12:-1 13:-1 52 | +1 1:0.291667 2:1 3:0.333333 4:-0.132075 5:-0.730594 6:-1 7:1 8:0.282443 9:-1 10:-0.0322581 12:-1 13:-1 53 | +1 1:0.291667 2:1 3:1 4:-0.0377358 5:-0.287671 6:-1 7:1 8:0.0839695 9:1 10:-0.0967742 12:0.333333 13:1 54 | +1 1:0.0416667 2:1 3:1 4:-0.509434 5:-0.716895 6:-1 7:-1 8:-0.358779 9:-1 10:-0.548387 12:-0.333333 13:1 55 | -1 1:-0.375 2:1 3:-0.333333 4:-0.320755 5:-0.575342 6:-1 7:1 8:0.78626 9:-1 10:-1 11:-1 12:-1 13:-1 56 | +1 1:-0.375 2:1 3:1 4:-0.660377 5:-0.251142 6:-1 7:1 8:0.251908 9:-1 10:-1 11:-1 12:-0.333333 13:-1 57 | -1 1:-0.0833333 2:1 3:0.333333 4:-0.698113 5:-0.776256 6:-1 7:-1 8:-0.206107 9:-1 10:-0.806452 11:-1 12:-1 13:-1 58 | -1 1:0.25 2:1 3:0.333333 4:0.0566038 5:-0.607306 6:1 7:-1 8:0.312977 9:-1 10:-0.483871 11:-1 12:-1 13:-1 59 | -1 1:0.75 2:-1 3:-0.333333 4:0.245283 5:-0.196347 6:-1 7:-1 8:0.389313 9:-1 10:-0.870968 11:-1 12:0.333333 13:-1 60 | -1 1:0.333333 2:1 3:0.333333 4:0.0566038 5:-0.465753 6:1 7:-1 8:0.00763359 9:1 10:-0.677419 12:-1 13:-1 61 | +1 1:0.0833333 2:1 3:1 4:-0.283019 5:0.0365297 6:-1 7:-1 8:-0.0687023 9:1 10:-0.612903 12:-0.333333 13:1 62 | +1 1:0.458333 2:1 3:0.333333 4:-0.132075 5:-0.0456621 6:-1 7:-1 8:0.328244 9:-1 10:-1 11:-1 12:-1 13:-1 63 | -1 1:-0.416667 2:1 3:1 4:0.0566038 5:-0.447489 6:-1 7:-1 8:0.526718 9:-1 10:-0.516129 11:-1 12:-1 13:-1 64 | -1 1:0.208333 2:-1 3:0.333333 4:-0.509434 5:-0.0228311 6:-1 7:-1 8:0.541985 9:-1 10:-1 11:-1 12:-1 13:-1 65 | +1 1:0.291667 2:1 3:1 4:-0.320755 5:-0.634703 6:-1 7:1 8:-0.0687023 9:1 10:-0.225806 12:0.333333 13:1 66 | +1 1:0.208333 2:1 3:-0.333333 4:-0.509434 5:-0.278539 6:-1 7:1 8:0.358779 9:-1 10:-0.419355 12:-1 13:-1 67 | -1 1:-0.166667 2:1 3:-0.333333 4:-0.320755 5:-0.360731 6:-1 7:-1 8:0.526718 9:-1 10:-0.806452 11:-1 12:-1 13:-1 68 | +1 1:-0.208333 2:1 3:-0.333333 4:-0.698113 5:-0.52968 6:-1 7:-1 8:0.480916 9:-1 10:-0.677419 11:1 12:-1 13:1 69 | -1 1:-0.0416667 2:1 3:0.333333 4:0.471698 5:-0.666667 6:1 7:-1 8:0.389313 9:-1 10:-0.83871 11:-1 12:-1 13:1 70 | -1 1:-0.375 2:1 3:-0.333333 4:-0.509434 5:-0.374429 6:-1 7:-1 8:0.557252 9:-1 10:-1 11:-1 12:-1 13:1 71 | -1 1:0.125 2:-1 3:-0.333333 4:-0.132075 5:-0.232877 6:-1 7:1 8:0.251908 9:-1 10:-0.580645 12:-1 13:-1 72 | -1 1:0.166667 2:1 3:1 4:-0.132075 5:-0.69863 6:-1 7:-1 8:0.175573 9:-1 10:-0.870968 12:-1 13:0.5 73 | +1 1:0.583333 2:1 3:1 4:0.245283 5:-0.269406 6:-1 7:1 8:-0.435115 9:1 10:-0.516129 12:1 13:-1 74 | -------------------------------------------------------------------------------- /Example/app/src/main/assets/html/Predict_Options.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Predict Options 5 | 6 | 7 | 18 | 19 | 20 |
21 | -b probability_estimates : whether to predict probability estimates, 0 or 1  (default 0) for one-class SVM only 0 is supported
22 |         
23 | 24 | 25 | -------------------------------------------------------------------------------- /Example/app/src/main/assets/html/Scale_Options.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Scale Options 5 | 6 | 7 | 18 | 19 | 20 |
21 | -l lower : x scaling lower limit (default -1)
22 | 
23 | -u upper : x scaling upper limit (default +1)
24 | 
25 | -y y_lower y_upper : y scaling limits (default: no y scaling)
26 | 
27 | -s save_filename : save scaling parameters to save_filename
28 | 
29 | -r restore_filename : restore scaling parameters from restore_filename
30 |         
31 | 32 | 33 | -------------------------------------------------------------------------------- /Example/app/src/main/assets/html/Train_Options.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Train Options 5 | 6 | 7 | 21 | 22 | 23 |
24 | -s svm_type: set type of SVM (default 0)
25 | 	0 -- C-SVC
26 | 	1 -- nu-SVC
27 | 	2 -- one-class SVM
28 | 	3 -- epsilon-SVR
29 | 	4 -- nu-SVR
30 | 
31 | -t kernel_type: set type of kernel function (default 2)
32 | 	0 -- linear: u'*v
33 | 	1 -- polynomial: (gamma*u'*v + coef0)^degree
34 | 	2 -- radial basis function: exp(-gamma*|u-v|^2)
35 | 	3 -- sigmoid: tanh(gamma*u'*v + coef0)
36 | 
37 | -d degree: set degree in kernel function (default 3)
38 | 
39 | -g gamma: set gamma in kernel function (default 1/num_features)
40 | 
41 | -r coef0: set coef0 in kernel function (default 0)
42 | 
43 | -c cost: set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)
44 | 
45 | -n nu: set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)
46 | 
47 | -p epsilon: set the epsilon in loss function of epsilon-SVR (default 0.1)
48 | 
49 | -m cachesize: set cache memory size in MB (default 100)
50 | 
51 | -e epsilon: set tolerance of termination criterion (default 0.001)
52 | 
53 | -h shrinking: whether to use the shrinking heuristics, 0 or 1 (default 1)
54 | 
55 | -b probability_estimates: whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)
56 | 
57 | -wi weight: set the parameter C of class i to weight*C, for C-SVC (default 1)
58 | 
59 | The k in the -g option means the number of attributes in the input data.
60 |         
61 | 62 | 63 | -------------------------------------------------------------------------------- /Example/app/src/main/assets/html/copyright.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Copyright 5 | 6 | 7 | 16 | 17 | 18 |

LibSVM v3.20

19 |
20 | Copyright (c) 2000-2017 Chih-Chung Chang and Chih-Jen Lin
21 | All rights reserved.
22 | 
23 | Redistribution and use in source and binary forms, with or without
24 | modification, are permitted provided that the following conditions
25 | are met:
26 | 
27 | 1. Redistributions of source code must retain the above copyright
28 | notice, this list of conditions and the following disclaimer.
29 | 
30 | 2. Redistributions in binary form must reproduce the above copyright
31 | notice, this list of conditions and the following disclaimer in the
32 | documentation and/or other materials provided with the distribution.
33 | 
34 | 3. Neither name of copyright holders nor the names of its contributors
35 | may be used to endorse or promote products derived from this software
36 | without specific prior written permission.
37 | 
38 | 
39 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
40 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
41 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
42 | A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
43 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
45 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
46 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
47 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
48 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
49 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 |         
51 |

FileBrowser v1.4

52 |
53 | MIT License
54 | 
55 | Copyright (c) 2017 adityak368
56 | 
57 | Permission is hereby granted, free of charge, to any person obtaining a copy
58 | of this software and associated documentation files (the "Software"), to deal
59 | in the Software without restriction, including without limitation the rights
60 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
61 | copies of the Software, and to permit persons to whom the Software is
62 | furnished to do so, subject to the following conditions:
63 | 
64 | The above copyright notice and this permission notice shall be included in all
65 | copies or substantial portions of the Software.
66 | 
67 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
70 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
71 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
72 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
73 | SOFTWARE.
74 |         
75 |

Gota v1.4.1

76 |
77 | Copyright (c) 2015 Abdullah Alhazmy
78 | 
79 | Licensed under the Apache License, Version 2.0 (the "License");
80 | you may not use this file except in compliance with the License.
81 | You may obtain a copy of the License at
82 | 
83 |     http://www.apache.org/licenses/LICENSE-2.0
84 | 
85 | Unless required by applicable law or agreed to in writing, software
86 | distributed under the License is distributed on an "AS IS" BASIS,
87 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
88 | See the License for the specific language governing permissions and
89 | limitations under the License.
90 |     
91 | 92 | 93 | -------------------------------------------------------------------------------- /Example/app/src/main/java/com/test/libsvmandroidexample/ContainerActivity.java: -------------------------------------------------------------------------------- 1 | package com.test.libsvmandroidexample; 2 | 3 | import android.Manifest; 4 | import android.app.AlertDialog; 5 | import android.content.DialogInterface; 6 | import android.content.pm.PackageManager; 7 | import android.content.res.AssetManager; 8 | import android.os.Bundle; 9 | import android.os.Environment; 10 | import android.support.annotation.NonNull; 11 | import android.support.design.widget.TabLayout; 12 | import android.support.v4.app.Fragment; 13 | import android.support.v4.app.FragmentManager; 14 | import android.support.v4.app.FragmentPagerAdapter; 15 | import android.support.v4.content.ContextCompat; 16 | import android.support.v4.view.ViewPager; 17 | import android.support.v7.app.AppCompatActivity; 18 | import android.support.v7.widget.Toolbar; 19 | import android.util.Log; 20 | import android.view.LayoutInflater; 21 | import android.view.Menu; 22 | import android.view.MenuItem; 23 | import android.view.View; 24 | import android.webkit.WebView; 25 | import android.widget.Toast; 26 | import net.alhazmy13.gota.Gota; 27 | import net.alhazmy13.gota.GotaResponse; 28 | import java.io.File; 29 | import java.io.FileOutputStream; 30 | import java.io.IOException; 31 | import java.io.InputStream; 32 | import java.io.OutputStream; 33 | import java.util.ArrayList; 34 | import java.util.List; 35 | 36 | 37 | public class ContainerActivity extends AppCompatActivity implements Gota.OnRequestPermissionsBack { 38 | 39 | public static final String TAG = "LibSVMExample"; 40 | public static final String processId = Integer.toString(android.os.Process.myPid()); 41 | 42 | private Toolbar toolbar; 43 | private TabLayout tabLayout; 44 | private ViewPager viewPager; 45 | public static String appFolderPath; 46 | public static String systemPath; 47 | 48 | @Override 49 | protected void onCreate(Bundle savedInstanceState) { 50 | super.onCreate(savedInstanceState); 51 | setContentView(R.layout.activity_container); 52 | toolbar = (Toolbar) findViewById(R.id.toolbar); 53 | setSupportActionBar(toolbar); 54 | viewPager = (ViewPager) findViewById(R.id.viewpager); 55 | setupViewPager(viewPager); 56 | tabLayout = (TabLayout) findViewById(R.id.tabs); 57 | tabLayout.setupWithViewPager(viewPager); 58 | final boolean readStorage = canReadExternalStorage(); 59 | final boolean writeStorage = canWriteExternalStorage(); 60 | // request app permissions 61 | if (!readStorage || !writeStorage){ 62 | new Gota.Builder(this) 63 | .withPermissions(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_LOGS) 64 | .requestId(1) 65 | .setListener(this) 66 | .check(); 67 | } 68 | systemPath = Environment.getExternalStorageDirectory() + "/"; 69 | appFolderPath = systemPath+"LibSVMAssets/"; 70 | 71 | // create assets folder if it doesn't exist 72 | createAssetsFolder(); 73 | 74 | // copy all data files from assets to external storage 75 | try { 76 | String[] list = getAssets().list("data"); 77 | for (String file: list) { 78 | copyToExternalStorage(file, "data"); 79 | } 80 | } catch (IOException e) { 81 | e.printStackTrace(); 82 | } 83 | } 84 | 85 | private void setupViewPager(ViewPager viewPager) { 86 | ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); 87 | adapter.addFragment(new ScaleFragment(), "Scale"); 88 | adapter.addFragment(new TrainFragment(), "Train"); 89 | adapter.addFragment(new PredictFragment(), "Predict"); 90 | viewPager.setAdapter(adapter); 91 | } 92 | 93 | @Override 94 | public void onRequestBack(int requestId, @NonNull GotaResponse gotaResponse) { 95 | if (gotaResponse.isDenied(Manifest.permission.READ_EXTERNAL_STORAGE)){ 96 | Toast.makeText(this, "READ_EXTERNAL_STORAGE permission is required for the app to function properly.", Toast.LENGTH_LONG).show(); 97 | } 98 | if (gotaResponse.isDenied(Manifest.permission.WRITE_EXTERNAL_STORAGE)){ 99 | Toast.makeText(this, "WRITE_EXTERNAL_STORAGE permission is required for the app to function properly.", Toast.LENGTH_LONG).show(); 100 | } 101 | if (gotaResponse.isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE) || gotaResponse.isGranted(Manifest.permission.READ_EXTERNAL_STORAGE)){ 102 | Toast.makeText(this, "Restart the app to able to use the newly granted permissions.", Toast.LENGTH_LONG).show(); 103 | } 104 | } 105 | 106 | @Override 107 | public boolean onCreateOptionsMenu(Menu menu) { 108 | getMenuInflater().inflate(R.menu.main_menu, menu); 109 | return super.onCreateOptionsMenu(menu); 110 | } 111 | 112 | @Override 113 | public boolean onOptionsItemSelected(MenuItem item) { 114 | switch (item.getItemId()){ 115 | case R.id.menu_copyright_btn: 116 | // show copyright dialog 117 | showDialog("copyright"); 118 | return true; 119 | case R.id.menu_train_options: 120 | // show train options dialog 121 | showDialog("Train_Options"); 122 | return true; 123 | case R.id.menu_scale_options: 124 | // show scale options dialog 125 | showDialog("Scale_Options"); 126 | return true; 127 | case R.id.menu_predict_options: 128 | // show train options dialog 129 | showDialog("Predict_Options"); 130 | return true; 131 | default: 132 | return super.onOptionsItemSelected(item); 133 | } 134 | } 135 | 136 | public void showDialog(String htmlFile){ 137 | LayoutInflater li = LayoutInflater.from(this); 138 | View promptsView = li.inflate(R.layout.dialog_layout, null); 139 | AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this) 140 | .setTitle((htmlFile.contains("_") ? htmlFile.replace("_", " ") : htmlFile)) 141 | .setView(promptsView) 142 | .setNeutralButton("Ok", new DialogInterface.OnClickListener() { 143 | @Override 144 | public void onClick(DialogInterface dialog, int which) { 145 | dialog.dismiss(); 146 | } 147 | }); 148 | final WebView webview = (WebView) promptsView.findViewById(R.id.webview); 149 | webview.loadUrl("file:///android_asset/html/"+htmlFile+".html"); 150 | final AlertDialog alertDialog = alertDialogBuilder.create(); 151 | alertDialog.show(); 152 | } 153 | 154 | private class ViewPagerAdapter extends FragmentPagerAdapter { 155 | private final List mFragmentList = new ArrayList<>(); 156 | private final List mFragmentTitleList = new ArrayList<>(); 157 | 158 | public ViewPagerAdapter(FragmentManager manager) { 159 | super(manager); 160 | } 161 | 162 | @Override 163 | public Fragment getItem(int position) { 164 | return mFragmentList.get(position); 165 | } 166 | 167 | @Override 168 | public int getCount() { 169 | return mFragmentList.size(); 170 | } 171 | 172 | public void addFragment(Fragment fragment, String title) { 173 | mFragmentList.add(fragment); 174 | mFragmentTitleList.add(title); 175 | } 176 | 177 | @Override 178 | public CharSequence getPageTitle(int position) { 179 | return mFragmentTitleList.get(position); 180 | } 181 | } 182 | 183 | public boolean canReadExternalStorage(){ 184 | int permissionStatus = ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE); 185 | if (permissionStatus == PackageManager.PERMISSION_GRANTED){ 186 | return true; 187 | } else { 188 | return false; 189 | } 190 | } 191 | 192 | public boolean canWriteExternalStorage(){ 193 | int permissionStatus = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE); 194 | if (permissionStatus == PackageManager.PERMISSION_GRANTED){ 195 | return true; 196 | } else { 197 | return false; 198 | } 199 | } 200 | 201 | private void createAssetsFolder(){ 202 | // create app assets folder if not created 203 | File folder = new File(appFolderPath); 204 | 205 | if (!folder.exists()) { 206 | Log.d(TAG,"LibSVMAssets folder does not exist, creating one"); 207 | folder.mkdirs(); 208 | } else { 209 | Log.w(TAG,"INFO: LibSVMAssets folder already exists."); 210 | } 211 | } 212 | 213 | private void copyToExternalStorage(String assetName, String assetsDirectory){ 214 | String from = assetName; 215 | String to = appFolderPath+from; 216 | 217 | // check if the file exists 218 | File file = new File(to); 219 | if(file.exists()){ 220 | Log.d(TAG, "copyToExternalStorage: file already exist, no need to copy: "+from); 221 | } else { 222 | // do copy 223 | boolean copyResult = copyAsset(getAssets(), from, assetsDirectory, to); 224 | Log.d(TAG, "copyToExternalStorage: isCopied -> "+copyResult); 225 | } 226 | } 227 | 228 | private boolean copyAsset(AssetManager assetManager, String fromAssetPath, String assetsDirectory, String toPath) { 229 | InputStream inputStream = null; 230 | OutputStream outputStream = null; 231 | try { 232 | inputStream = assetManager.open(assetsDirectory+"/"+fromAssetPath); 233 | new File(toPath).createNewFile(); 234 | outputStream = new FileOutputStream(toPath); 235 | copyFile(inputStream, outputStream); 236 | inputStream.close(); 237 | outputStream.flush(); 238 | outputStream.close(); 239 | return true; 240 | } catch(Exception e) { 241 | e.printStackTrace(); 242 | Log.e(TAG, "copyAsset: unable to copy file: "+fromAssetPath); 243 | return false; 244 | } 245 | } 246 | 247 | private void copyFile(InputStream inputStream, OutputStream outputStream) throws IOException { 248 | byte[] buffer = new byte[1024]; 249 | int read; 250 | while((read = inputStream.read(buffer)) != -1){ 251 | outputStream.write(buffer, 0, read); 252 | } 253 | } 254 | 255 | } -------------------------------------------------------------------------------- /Example/app/src/main/java/com/test/libsvmandroidexample/PredictFragment.java: -------------------------------------------------------------------------------- 1 | package com.test.libsvmandroidexample; 2 | 3 | import android.app.Activity; 4 | import android.app.ProgressDialog; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.os.AsyncTask; 8 | import android.os.Bundle; 9 | import android.support.v4.app.Fragment; 10 | import android.text.TextUtils; 11 | import android.util.Log; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.Button; 16 | import android.widget.CheckBox; 17 | import android.widget.CompoundButton; 18 | import android.widget.EditText; 19 | import android.widget.Toast; 20 | 21 | import com.aditya.filebrowser.Constants; 22 | import com.aditya.filebrowser.FileChooser; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | import umich.cse.yctung.androidlibsvm.LibSVM; 28 | 29 | 30 | public class PredictFragment extends Fragment { 31 | 32 | ProgressDialog progressDialog; 33 | public static int PICK_TESTFILE = 3000; 34 | public static int PICK_MODELFILE = 3001; 35 | Button predictButton; 36 | Button testFilePicker; 37 | Button modelFilePicker; 38 | EditText outputFileNameInput; 39 | EditText probabilityInput; 40 | CheckBox probabilityCheckbox; 41 | 42 | 43 | public PredictFragment() { 44 | // Required empty public constructor 45 | } 46 | 47 | @Override 48 | public void onCreate(Bundle savedInstanceState) { 49 | super.onCreate(savedInstanceState); 50 | } 51 | 52 | @Override 53 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 54 | Bundle savedInstanceState) { 55 | // Inflate the layout for this fragment 56 | View view = inflater.inflate(R.layout.fragment_predict, container, false); 57 | progressDialog = new ProgressDialog(getContext()); 58 | testFilePicker = (Button) view.findViewById(R.id.testfilepicker); 59 | modelFilePicker = (Button) view.findViewById(R.id.modelfilepicker); 60 | predictButton = (Button) view.findViewById(R.id.predict_btn); 61 | outputFileNameInput = (EditText) view.findViewById(R.id.output_filename); 62 | probabilityInput = (EditText) view.findViewById(R.id.probabilityinput); 63 | probabilityCheckbox = (CheckBox) view.findViewById(R.id.probabilitycheckbox); 64 | probabilityCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 65 | @Override 66 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 67 | if (isChecked){ 68 | probabilityInput.setEnabled(true); 69 | } else { 70 | probabilityInput.setEnabled(false); 71 | } 72 | } 73 | }); 74 | testFilePicker.setOnClickListener(new View.OnClickListener() { 75 | @Override 76 | public void onClick(View v) { 77 | Intent i2 = new Intent(getContext(), FileChooser.class); 78 | i2.putExtra(Constants.SELECTION_MODE, Constants.SELECTION_MODES.SINGLE_SELECTION.ordinal()); 79 | startActivityForResult(i2, PICK_TESTFILE); 80 | } 81 | }); 82 | modelFilePicker.setOnClickListener(new View.OnClickListener() { 83 | @Override 84 | public void onClick(View v) { 85 | Intent i2 = new Intent(getContext(), FileChooser.class); 86 | i2.putExtra(Constants.SELECTION_MODE, Constants.SELECTION_MODES.SINGLE_SELECTION.ordinal()); 87 | startActivityForResult(i2, PICK_MODELFILE); 88 | } 89 | }); 90 | predictButton.setOnClickListener(new View.OnClickListener() { 91 | @Override 92 | public void onClick(View v) { 93 | List commands = new ArrayList<>(); 94 | if (probabilityCheckbox.isChecked()){ 95 | if (!Utility.isEmptyOrWhitespace(probabilityInput.getText().toString())){ 96 | commands.add("-b"); 97 | commands.add(probabilityInput.getText().toString()); 98 | } 99 | } 100 | commands.add(testFilePicker.getText().toString()); 101 | commands.add(modelFilePicker.getText().toString()); 102 | if (Utility.isEmptyOrWhitespace(outputFileNameInput.getText().toString())) { 103 | Toast.makeText(getContext(), "Output file name is required!", Toast.LENGTH_SHORT).show(); 104 | return; 105 | } 106 | commands.add(ContainerActivity.appFolderPath+outputFileNameInput.getText().toString()); 107 | new AsyncPredictTask().execute(commands.toArray(new String[0])); 108 | } 109 | }); 110 | return view; 111 | } 112 | 113 | @Override 114 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 115 | super.onActivityResult(requestCode, resultCode, data); 116 | if (requestCode == PICK_TESTFILE && data != null) { 117 | if (resultCode == Activity.RESULT_OK) { 118 | Uri file = data.getData(); 119 | testFilePicker.setText(file.getPath()); 120 | } 121 | } 122 | if (requestCode == PICK_MODELFILE && data != null) { 123 | if (resultCode == Activity.RESULT_OK) { 124 | Uri file = data.getData(); 125 | modelFilePicker.setText(file.getPath()); 126 | } 127 | } 128 | } 129 | 130 | private class AsyncPredictTask extends AsyncTask 131 | { 132 | @Override 133 | protected void onPreExecute() { 134 | super.onPreExecute(); 135 | progressDialog.setTitle("SVM Predict"); 136 | progressDialog.setMessage("Executing svm-predict, please wait..."); 137 | progressDialog.show(); 138 | Log.d(ContainerActivity.TAG, "==================\nStart of SVM PREDICT\n=================="); 139 | } 140 | 141 | @Override 142 | protected Void doInBackground(String... params) { 143 | LibSVM.getInstance().predict(TextUtils.join(" ", params)); 144 | return null; 145 | } 146 | @Override 147 | protected void onPostExecute(Void result) { 148 | progressDialog.dismiss(); 149 | Toast.makeText(getContext(), "SVM Predict has executed successfully!", Toast.LENGTH_LONG).show(); 150 | Log.d(ContainerActivity.TAG, "==================\nEnd of SVM PREDICT\n=================="); 151 | Utility.readLogcat(getContext(), "SVM-Predict Results"); 152 | } 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /Example/app/src/main/java/com/test/libsvmandroidexample/ScaleFragment.java: -------------------------------------------------------------------------------- 1 | package com.test.libsvmandroidexample; 2 | 3 | import android.app.Activity; 4 | import android.app.ProgressDialog; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.os.AsyncTask; 8 | import android.os.Bundle; 9 | import android.support.v4.app.Fragment; 10 | import android.text.TextUtils; 11 | import android.util.Log; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.Button; 16 | import android.widget.CheckBox; 17 | import android.widget.CompoundButton; 18 | import android.widget.EditText; 19 | import android.widget.Toast; 20 | 21 | import com.aditya.filebrowser.Constants; 22 | import com.aditya.filebrowser.FileChooser; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | import umich.cse.yctung.androidlibsvm.LibSVM; 28 | 29 | 30 | public class ScaleFragment extends Fragment { 31 | 32 | ProgressDialog progressDialog; 33 | public static int PICK_DATAFILE = 1000; 34 | public static int PICK_RESTOREFILE = 1001; 35 | Button dataFilePicker; 36 | Button restoreFilePicker; 37 | Button scaleButton; 38 | CheckBox saveFileNameCheckBox; 39 | CheckBox restoreFileNameCheckbox; 40 | CheckBox xLowerCheckBox; 41 | CheckBox xUpperCheckBox; 42 | CheckBox yLimitsCheckBox; 43 | EditText saveFileNameInput; 44 | EditText xLowerLimitInput; 45 | EditText xUpperLimitInput; 46 | EditText yLimitsInput; 47 | EditText outputFileNameInput; 48 | 49 | 50 | public ScaleFragment() { 51 | // Required empty public constructor 52 | } 53 | 54 | @Override 55 | public void onCreate(Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | } 58 | 59 | @Override 60 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 61 | Bundle savedInstanceState) { 62 | // Inflate the layout for this fragment 63 | final View view = inflater.inflate(R.layout.fragment_scale, container, false); 64 | progressDialog = new ProgressDialog(getContext()); 65 | 66 | // Buttons 67 | dataFilePicker = (Button) view.findViewById(R.id.datafilepicker); 68 | restoreFilePicker = (Button) view.findViewById(R.id.restorefilepicker); 69 | scaleButton = (Button) view.findViewById(R.id.scale_btn); 70 | 71 | // EditTexts 72 | saveFileNameInput = (EditText) view.findViewById(R.id.save_filename); 73 | outputFileNameInput = (EditText) view.findViewById(R.id.output_filename); 74 | xLowerLimitInput = (EditText) view.findViewById(R.id.lowerlimit); 75 | xUpperLimitInput = (EditText) view.findViewById(R.id.upperlimit); 76 | yLimitsInput = (EditText) view.findViewById(R.id.ylimit); 77 | 78 | // CheckBoxes 79 | saveFileNameCheckBox = (CheckBox) view.findViewById(R.id.savecheckBox); 80 | restoreFileNameCheckbox = (CheckBox) view.findViewById(R.id.restorecheckBox); 81 | xLowerCheckBox = (CheckBox) view.findViewById(R.id.lowerlimitcheckbox); 82 | xUpperCheckBox = (CheckBox) view.findViewById(R.id.upperlimitcheckbox); 83 | yLimitsCheckBox = (CheckBox) view.findViewById(R.id.ylimitcheckbox); 84 | 85 | // Listeners 86 | dataFilePicker.setOnClickListener(new View.OnClickListener() { 87 | @Override 88 | public void onClick(View v) { 89 | Intent i2 = new Intent(getContext(), FileChooser.class); 90 | i2.putExtra(Constants.SELECTION_MODE, Constants.SELECTION_MODES.SINGLE_SELECTION.ordinal()); 91 | startActivityForResult(i2, PICK_DATAFILE); 92 | } 93 | }); 94 | restoreFilePicker.setOnClickListener(new View.OnClickListener() { 95 | @Override 96 | public void onClick(View v) { 97 | Intent i2 = new Intent(getContext(), FileChooser.class); 98 | i2.putExtra(Constants.SELECTION_MODE, Constants.SELECTION_MODES.SINGLE_SELECTION.ordinal()); 99 | startActivityForResult(i2, PICK_RESTOREFILE); 100 | } 101 | }); 102 | saveFileNameCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 103 | @Override 104 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 105 | if (isChecked){ 106 | saveFileNameInput.setEnabled(true); 107 | restoreFileNameCheckbox.setChecked(false); 108 | } else { 109 | saveFileNameInput.setEnabled(false); 110 | } 111 | } 112 | }); 113 | restoreFileNameCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 114 | @Override 115 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 116 | if (isChecked){ 117 | restoreFilePicker.setEnabled(true); 118 | saveFileNameCheckBox.setChecked(false); 119 | } else { 120 | restoreFilePicker.setEnabled(false); 121 | } 122 | } 123 | }); 124 | xLowerCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 125 | @Override 126 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 127 | if (isChecked){ 128 | xLowerLimitInput.setEnabled(true); 129 | yLimitsCheckBox.setChecked(false); 130 | } else { 131 | xLowerLimitInput.setEnabled(false); 132 | } 133 | } 134 | }); 135 | xUpperCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 136 | @Override 137 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 138 | if (isChecked){ 139 | xUpperLimitInput.setEnabled(true); 140 | yLimitsCheckBox.setChecked(false); 141 | } else { 142 | xUpperLimitInput.setEnabled(false); 143 | } 144 | } 145 | }); 146 | yLimitsCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 147 | @Override 148 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 149 | if (isChecked){ 150 | yLimitsInput.setEnabled(true); 151 | xLowerCheckBox.setChecked(false); 152 | xUpperCheckBox.setChecked(false); 153 | } else { 154 | yLimitsInput.setEnabled(false); 155 | } 156 | } 157 | }); 158 | scaleButton.setOnClickListener(new View.OnClickListener() { 159 | @Override 160 | public void onClick(View v) { 161 | List options = new ArrayList<>(); 162 | String dataFilePath = dataFilePicker.getText().toString(); 163 | String outputFileName = outputFileNameInput.getText().toString(); 164 | if (xLowerCheckBox.isChecked() || xUpperCheckBox.isChecked()){ 165 | if (xLowerCheckBox.isChecked()){ 166 | if (!Utility.isEmptyOrWhitespace(xLowerLimitInput.getText().toString())){ 167 | options.add("-l"); 168 | options.add(xLowerLimitInput.getText().toString()); 169 | } 170 | } 171 | if (xUpperCheckBox.isChecked()){ 172 | if (!Utility.isEmptyOrWhitespace(xUpperLimitInput.getText().toString())){ 173 | options.add("-u"); 174 | options.add(xUpperLimitInput.getText().toString()); 175 | } 176 | } 177 | } else if (yLimitsCheckBox.isChecked()){ 178 | if (!Utility.isEmptyOrWhitespace(yLimitsInput.getText().toString())){ 179 | options.add("-y"); 180 | options.add(yLimitsInput.getText().toString()); 181 | } 182 | } 183 | if (saveFileNameCheckBox.isChecked()) { 184 | String saveFileName = saveFileNameInput.getText().toString(); 185 | if (!Utility.isEmptyOrWhitespace(saveFileName)){ 186 | options.add("-s"); 187 | options.add(ContainerActivity.appFolderPath+saveFileName); 188 | } 189 | } else if (restoreFileNameCheckbox.isChecked()){ 190 | options.add("-r"); 191 | options.add(restoreFilePicker.getText().toString()); 192 | } 193 | options.add(dataFilePath); 194 | String optionsString = TextUtils.join(" ", options); 195 | String outputFilePath = null; 196 | if (Utility.isEmptyOrWhitespace(outputFileName)) { 197 | Toast.makeText(getContext(), "Output file name is required!", Toast.LENGTH_SHORT).show(); 198 | return; 199 | } 200 | outputFilePath = ContainerActivity.appFolderPath+outputFileName; 201 | new AsyncScaleTask().execute(new String[]{optionsString, outputFilePath}); 202 | } 203 | }); 204 | return view; 205 | } 206 | 207 | @Override 208 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 209 | super.onActivityResult(requestCode, resultCode, data); 210 | if (requestCode == PICK_DATAFILE && data != null) { 211 | if (resultCode == Activity.RESULT_OK) { 212 | Uri file = data.getData(); 213 | dataFilePicker.setText(file.getPath()); 214 | } 215 | } 216 | if (requestCode == PICK_RESTOREFILE && data != null) { 217 | if (resultCode == Activity.RESULT_OK) { 218 | Uri file = data.getData(); 219 | restoreFilePicker.setText(file.getPath()); 220 | } 221 | } 222 | } 223 | 224 | 225 | private class AsyncScaleTask extends AsyncTask 226 | { 227 | @Override 228 | protected void onPreExecute() { 229 | super.onPreExecute(); 230 | progressDialog.setTitle("SVM Scale"); 231 | progressDialog.setMessage("Executing svm-scale, please wait..."); 232 | progressDialog.show(); 233 | Log.d(ContainerActivity.TAG, "==================\nStart of SVM SCALE\n=================="); 234 | } 235 | 236 | @Override 237 | protected Void doInBackground(String... params) { 238 | LibSVM.getInstance().scale(params[0], params[1]); 239 | return null; 240 | } 241 | @Override 242 | protected void onPostExecute(Void result) { 243 | progressDialog.dismiss(); 244 | Toast.makeText(getContext(), "SVM Scale has executed successfully!", Toast.LENGTH_LONG).show(); 245 | Log.d(ContainerActivity.TAG, "==================\nEnd of SVM SCALE\n=================="); 246 | Utility.readLogcat(getContext(), "SVM-Scale Results"); 247 | } 248 | } 249 | } -------------------------------------------------------------------------------- /Example/app/src/main/java/com/test/libsvmandroidexample/TrainFragment.java: -------------------------------------------------------------------------------- 1 | package com.test.libsvmandroidexample; 2 | 3 | import android.app.Activity; 4 | import android.app.ProgressDialog; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.os.AsyncTask; 8 | import android.os.Bundle; 9 | import android.support.v4.app.Fragment; 10 | import android.text.TextUtils; 11 | import android.util.Log; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.Button; 16 | import android.widget.EditText; 17 | import android.widget.Toast; 18 | 19 | import com.aditya.filebrowser.Constants; 20 | import com.aditya.filebrowser.FileChooser; 21 | 22 | import umich.cse.yctung.androidlibsvm.LibSVM; 23 | 24 | 25 | public class TrainFragment extends Fragment { 26 | 27 | ProgressDialog progressDialog; 28 | public static int PICK_DATAFILE = 2000; 29 | Button trainButton; 30 | Button dataFilePicker; 31 | EditText outputFileInput; 32 | EditText commandInput; 33 | 34 | 35 | public TrainFragment() { 36 | // Required empty public constructor 37 | } 38 | 39 | @Override 40 | public void onCreate(Bundle savedInstanceState) { 41 | super.onCreate(savedInstanceState); 42 | } 43 | 44 | @Override 45 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 46 | Bundle savedInstanceState) { 47 | View view = inflater.inflate(R.layout.fragment_train, container, false); 48 | progressDialog = new ProgressDialog(getContext()); 49 | trainButton = (Button) view.findViewById(R.id.train_btn); 50 | dataFilePicker = (Button) view.findViewById(R.id.datafilepicker); 51 | outputFileInput = (EditText) view.findViewById(R.id.output_filename); 52 | commandInput = (EditText) view.findViewById(R.id.train_options); 53 | trainButton.setOnClickListener(new View.OnClickListener() { 54 | @Override 55 | public void onClick(View v) { 56 | if (Utility.isEmptyOrWhitespace(outputFileInput.getText().toString()) || Utility.isEmptyOrWhitespace(commandInput.getText().toString())) { 57 | Toast.makeText(getContext(), "All fields are required!", Toast.LENGTH_SHORT).show(); 58 | return; 59 | } 60 | String outputModelPath = ContainerActivity.appFolderPath+outputFileInput.getText().toString(); 61 | String commandString = commandInput.getText().toString(); 62 | String dataFilePath = dataFilePicker.getText().toString(); 63 | new AsyncTrainTask().execute(new String[]{commandString, dataFilePath, outputModelPath}); 64 | } 65 | }); 66 | dataFilePicker.setOnClickListener(new View.OnClickListener() { 67 | @Override 68 | public void onClick(View v) { 69 | Intent i2 = new Intent(getContext(), FileChooser.class); 70 | i2.putExtra(Constants.SELECTION_MODE, Constants.SELECTION_MODES.SINGLE_SELECTION.ordinal()); 71 | startActivityForResult(i2, PICK_DATAFILE); 72 | } 73 | }); 74 | return view; 75 | } 76 | 77 | @Override 78 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 79 | super.onActivityResult(requestCode, resultCode, data); 80 | if (requestCode == PICK_DATAFILE && data != null) { 81 | if (resultCode == Activity.RESULT_OK) { 82 | Uri file = data.getData(); 83 | dataFilePicker.setText(file.getPath()); 84 | } 85 | } 86 | } 87 | 88 | private class AsyncTrainTask extends AsyncTask 89 | { 90 | @Override 91 | protected void onPreExecute() { 92 | super.onPreExecute(); 93 | progressDialog.setTitle("SVM Train"); 94 | progressDialog.setMessage("Executing svm-train, please wait..."); 95 | progressDialog.show(); 96 | Log.d(ContainerActivity.TAG, "==================\nStart of SVM TRAIN\n=================="); 97 | } 98 | 99 | @Override 100 | protected Void doInBackground(String... params) { 101 | LibSVM.getInstance().train(TextUtils.join(" ", params)); 102 | return null; 103 | } 104 | @Override 105 | protected void onPostExecute(Void result) { 106 | progressDialog.dismiss(); 107 | Toast.makeText(getContext(), "SVM Train has executed successfully!", Toast.LENGTH_LONG).show(); 108 | Log.d(ContainerActivity.TAG, "==================\nEnd of SVM TRAIN\n=================="); 109 | Utility.readLogcat(getContext(), "SVM-Train Results"); 110 | } 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /Example/app/src/main/java/com/test/libsvmandroidexample/Utility.java: -------------------------------------------------------------------------------- 1 | package com.test.libsvmandroidexample; 2 | 3 | import android.app.AlertDialog; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.util.Log; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.widget.TextView; 10 | 11 | import java.io.BufferedReader; 12 | import java.io.IOException; 13 | import java.io.InputStreamReader; 14 | 15 | public class Utility { 16 | 17 | public static boolean isEmptyOrWhitespace(String str){ 18 | if (str.isEmpty() || str.trim().isEmpty()) 19 | return true; 20 | else 21 | return false; 22 | } 23 | 24 | public static void readLogcat(Context context, String title){ 25 | try { 26 | Process process = Runtime.getRuntime().exec("logcat -d"); 27 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); 28 | StringBuilder log = new StringBuilder(); 29 | String line = ""; 30 | while ((line = bufferedReader.readLine()) != null) { 31 | if (line.contains(ContainerActivity.processId) && line.contains("LibSvm")) { 32 | if (line.contains("=======")){ 33 | log.append("==================\n"); 34 | } else if (line.contains("Start of SVM")){ 35 | log.append(line.substring(line.indexOf("Start"))+"\n"); 36 | } else if (line.contains("End of SVM")) { 37 | log.append(line.substring(line.indexOf("End"))+"\n"); 38 | } else { 39 | int indexOfProcessId = line.lastIndexOf(ContainerActivity.processId); 40 | String newLine = line.substring(indexOfProcessId); 41 | log.append(newLine+"\n\n"); 42 | } 43 | } 44 | } 45 | showResult(context, log.toString(), title); 46 | 47 | } catch (IOException e) { 48 | e.printStackTrace(); 49 | Log.e(ContainerActivity.TAG, "readLogcat: failed to read from logcat logger."); 50 | } 51 | } 52 | 53 | public static void showResult(Context context, String resultText, String title){ 54 | LayoutInflater li = LayoutInflater.from(context); 55 | View promptsView = li.inflate(R.layout.dialog_result, null); 56 | AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context) 57 | .setTitle(title) 58 | .setView(promptsView) 59 | .setNeutralButton("Ok", new DialogInterface.OnClickListener() { 60 | @Override 61 | public void onClick(DialogInterface dialog, int which) { 62 | dialog.dismiss(); 63 | } 64 | }); 65 | final TextView resultTextView = (TextView) promptsView.findViewById(R.id.resulttextview); 66 | resultTextView.setText(resultText); 67 | final AlertDialog alertDialog = alertDialogBuilder.create(); 68 | alertDialog.show(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Example/app/src/main/res/layout/activity_container.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 19 | 20 | 26 | 27 | 28 | 33 | -------------------------------------------------------------------------------- /Example/app/src/main/res/layout/dialog_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Example/app/src/main/res/layout/dialog_result.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 10 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Example/app/src/main/res/layout/fragment_predict.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | 13 | 19 | 20 |