zoukankan      html  css  js  c++  java
  • libsvm 接口 [供自己的C/C++程序训练预测用]

    #pragma once
    /*
     * lp_svm.h : a svm class use libSVM to train and predict data.
     */
    #include <cstdio>
    #include <iostream>
    #include <cstdlib>
    #include <ctime>
    #include <vector>
    #include <iterator>
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <float.h>
    #include <string.h>
    #include <stdarg.h>
    #include <limits.h>
    #include <locale.h>
    #include <errno.h>
    #include "/home/lvpeng/src/lpinclude/svm/svm.h"
    using namespace std;
    
    #define Malloc(type,n) (type *)malloc((n)*sizeof(type))
    
    /*
     * Class: lpCSVM
     * Func: read & predict & train data
     * Author: Peng Lv
     * Data: 12/04/2012
     */
    class lpCSVM{
    public:
    	struct svm_parameter m_param;
    	struct svm_problem m_prob;
    	struct svm_model *m_model;
    	struct svm_node *m_xSpace;
    
    	int m_crossValid;
    	int m_nrFold;
    	int m_dim;
    
    	char* line;
    	int max_line_len;
    	int max_nr_attr;
    	int m_predict_probability;
    public:
    	lpCSVM(){};
    	~lpCSVM();
    
    	char* readLine(FILE *);
    
    	/////////////////////////////////
    	//   interface functions 
    	/////////////////////////////////
    	void initSVM();
    	void readProblem(const char*);
    	void trainModel(char* input, char * output);
    	int loadModel(char* );
    	void predictFile(FILE* , FILE* );
    	double predictX(vector<double>& );
    };
    
  • 相关阅读:
    CF949C Data Center Maintenance 题解
    P1438 无聊的数列 题解
    CF620E New Year Tree 题解
    结构体优先队列的定义
    CF464E The Classic Problem 题解
    CF427C Checkposts
    CF161D Distance in Tree 题解
    P4375 [USACO18OPEN]Out of Sorts G 题解
    SCI, SCIE, 和ESCI的区别
    Matlab画图中图的方法
  • 原文地址:https://www.cnblogs.com/lvpengms/p/2446608.html
Copyright © 2011-2022 走看看