Peng Lv

毋意,毋必,毋固,毋我。 言必行,行必果。

导航

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>& );
};

 

posted on 2012-04-14 00:32  Lvpengms  阅读(2158)  评论(0编辑  收藏  举报