私は持っている :
//in AdaBoost.h
#pragma once
#define ITERATIONS_NUMBER 1000 //numar iteratii AdaBoost
class AdaBoost
{
public:
AdaBoost(void);
~AdaBoost(void);
bool train(int* trainData, int* responses,int,int);
float predict(int* sample);
bool save(char filename[]);
bool load(char filename[]);
private:
WeakClassifier * weakClassifiers[ITERATIONS_NUMBER];
float weights[];
};
class WeakClassifier
{
public:
WeakClassifier(void);
WeakClassifier(int*,int*,float*,int,int);
~WeakClassifier(void);
virtual int compute(int* sample);
double getScore(){return score;}
protected:
double score;
};
class DecisionStump :
public WeakClassifier
{
public:
DecisionStump(void);
DecisionStump(int*,int*,float*,int,int);
~DecisionStump(void);
int compute(int *sample)
{
if (s * sample[dimIndex] < s * stump) return -1;
else return 1;
};
private:
int s;
int stump;
int dimIndex;
int length;
int dimensions;
};
//in AdaBoost.cpp
#include "AdaBoost.h"
#include <limits>
AdaBoost::AdaBoost(void)
{
}
AdaBoost::~AdaBoost(void)
{
}
bool AdaBoost::train(int* trainData, int* responses,int length,int dimensions)
{
//initializarea ponderilor
float tmp = 1.0/dimensions;
for(int i = 0;i < dimensions; i++)
{
weights[i] = tmp;
}
for(int t=0;t < ITERATIONS_NUMBER; t++)
{
//normalizare ponderi
double sumWeights = 0.0;
for(int i = 0;i < dimensions; i++)
{
sumWeights += weights[i];
}
for(int i = 0;i < dimensions; i++)
{
weights[i] = weights[i] / sumWeights;
}
//get weak classifier
weakClassifiers[t] = new DecisionStump(trainData,responses,weights,length,dimensions);
//obtine eroarea clasificatorului slab
double score = weakClassifiers[t]->getScore();
}
return false;
}
WeakClassifier::WeakClassifier(int* trainingData,int* results,float* weights, int length,int dimensions)
{
}
DecisionStump::DecisionStump(void)
{
s = 0;
stump = 0;
dimIndex = 0;
length = 0;
dimensions = 0;
}
DecisionStump::DecisionStump(int* trainingData,int* results,float* weights, int length,int dimensions)
{
this->length = length;
this->dimensions = dimensions;
int dimIndexTmp;
int stumpTmp;
int sTemp;
score = DBL_MAX;
double scoreTemp;
for(int i = 0;i < dimensions;i++)
for(int j = 0;j < length;j++)
{
dimIndexTmp = i;
stumpTmp = trainingData[j* dimensions + dimIndexTmp];
sTemp = -1;
scoreTemp = 0.0;
for(int k = 0;k < length;k++)
{
int result;
if (sTemp * trainingData[k* dimensions + dimIndexTmp] < sTemp * stumpTmp) result = -1;
else result = 1;
//verifica daca clasificarea e corecta
if (result != results[k]) scoreTemp += weights[k];
}
if (scoreTemp < score)
{
dimIndex = dimIndexTmp;
stump = stumpTmp;
s = sTemp;
score = scoreTemp;
}
sTemp = 1;
scoreTemp = 0.0;
for(int k = 0;k < length;k++)
{
int result;
if (sTemp * trainingData[k* dimensions + dimIndexTmp] < sTemp * stumpTmp) result = -1;
else result = 1;
//verifica daca clasificarea e corecta
if (result != results[k]) scoreTemp += weights[k];
}
if (scoreTemp < score)
{
dimIndex = dimIndexTmp;
stump = stumpTmp;
s = sTemp;
score = scoreTemp;
}
}
length = 0;
dimensions = 0;
}
私は C++ を使用するのが初めてで、エラーが発生し続けます。'weakClassifiers' : undeclared identifier " at [1] and [2] but intellisense from VS 2012 doesn't have a problem
助けてください!