⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adaboost.h

📁 AdaBoost is an efficient tool in machine learning. It can combine a series of weak learners into a s
💻 H
字号:
/****************************************************************************
 NJU Magic.  Copyright (c) 2007.  All Rights Reserved.            
  
--------------------------------------------------------------------
Permission to use, copy, or modify this software and its documentation
for educational and research purposes only and without fee is hereby
granted, provided that this copyright notice appear on all copies and
supporting documentation.  For any other uses of this software, in
original or modified form, including but not limited to distribution
in whole or in part, specific prior permission must be obtained from
NJU Magic and the authors.  These programs shall not be used, rewritten,
or adapted as the basis of a commercial software or hardware product
without first obtaining appropriate licenses from NJU Magic. NJU Magic 
makes no representations about the suitability of this software for any
purpose.  It is provided "as is" without express or implied warranty.

---------------------------------------------------------------------

 File: adaboost.h                                                                         
 Authors: Yao Wei  
 Date Created    : 2007-8-11
                                          
****************************************************************************/

#ifndef ADA_BOOST_H
#define ADA_BOOST_H

#include "WeakLearner.h"
#include "mex.h"

class Boosting  
{
private:
	int n_samples;         //number of train sample
	int n_input;            //dimension of each sample
	int max_iter;       //max number of boost step
	WeakLearner *leaner;   //all weaker leaner
	
	//information of train set contains: #class, #each class and each class item
	//that is to say, if we have label={1,1,2,6,4,1,4,4,6,1,6,2,1,1,1,4,4}; we will get 
    //# class: count=4
	//concrete label:      eachlabel={1,2,6,4}
	//each count of label: eachcount={7,2,3,5} 
	struct taginfo
	{
		taginfo()
		{
			count = 0;
			eachlabel = 0;
			eachcount = 0;
		}
		int count;                   //class count;
		int *eachcount;              //each class's count
		double *eachlabel;           //store all label
	}info;

	Mat *submat;    //sub-sample correspond to each class


public:
	//matlab interface of boosting train
	void mexTrain(int nlhs, mxArray *plhs[],
		int nrhs, const mxArray *prhs[]);

	//matlab interface of boosting predict
	void mexPredict(int nlhs, mxArray *plhs[],
		int nrhs, const mxArray *prhs[]);

	Boosting();    //Construction

	virtual ~Boosting();

private:
	// free memory
	void Free();

	//predict a sample using majority voting
	double Vote(double *feature,int n_input);
	
	//set iteration of Boosting
	void SetIteration(int _max_iter){max_iter = _max_iter;}

	//train Multi-Class Boosting
	void DoTrain(); 
	
	//train Boosting 1 vs 1
	WeakLearner TrainOneVsOne
		(const Mat &mat1,const Mat &mat2,double label1,double label2);
	
	//get information of train data
	void GetClassInfo(const Vec &responses);
	
	//preprocess train data
	void Preprocess(const Mat &train,const Vec &responses);
	
	//unroll data according to each class label
	void UnrollData(const Mat &train,const Vec &responses);
	
};

#endif //ADA_BOOST_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -