Пример #1
0
void CMySharkML::RFClassification(cv::Mat &trainingFeat, std::vector<int> &trainingLabel, cv::Mat &TestFeat, std::vector<int> &OutputLabel, cv::Mat &OutputConf)
{
	ClassificationDataset data, dataTest;
	Features2SharkData(data, trainingFeat, trainingLabel); //Training set
	std::vector<int> testLabel(TestFeat.rows, 0);
	Features2SharkData(dataTest, TestFeat, testLabel); //Test Set

	m_numLabels = numberOfClasses(data);
	if(m_numLabels < 2) {
		cout<<"ERROR in training Labels"<<endl;
		return;
	}

	cout << "Training set - number of data points: " << data.numberOfElements()
		<< " number of classes: " << m_numLabels
		<< " input dimension: " << inputDimension(data) << endl;

	cout << "Test set - number of data points: " << dataTest.numberOfElements()
		<< " number of classes: " << numberOfClasses(dataTest)
		<< " input dimension: " << inputDimension(dataTest) << endl;

	
	clock_t start_time_RF=clock();

	//Generate a random forest
	//###begin<train>
	RFTrainer trainer;
	trainer.setNTrees(m_numTrees);

	RFClassifier model;
	trainer.train(model, data);
	//###end<train>

	Data<RealVector> prediction = model(dataTest.inputs());
	//cout << "Random Forest on test set accuracy:     " << 1. - loss.eval(dataTest.labels(), prediction) << endl;
	//###end<eval>

	clock_t end_time_RF=clock();
	cout<< "Random Forest running time is: "<<static_cast<double>(end_time_RF-start_time_RF)/CLOCKS_PER_SEC<<"ms"<<endl;

	// output
	GetPredictionLabelandConfidence(OutputLabel, OutputConf, prediction);
}
Пример #2
0
void Sum::refresh()
{
    yReg = 0;
    for (int i=0; i<inputDimension(); i++)
	yReg += signs[i] * getInputValue(i);
}
Пример #3
0
/* < SPIEGAZIONE SU src_out > */
bool MultiInput::addInput(Block* src, int src_output_index, int input_index, int instructionCounter)
{
    if (in.size() == 0) // se ciò si verifica vuol dire che nel costruttore del blocco non è stata chiamata la funzione initInputDimension()
    {
	oss << "At instruction # " << instructionCounter << ": can't add input to block '" << name << "': use function initInputDimension() to set input dimension of type '" << microType << "'";
	throw SyxError(oss.str());
    }
    if (input_index >= in.size())
    {
	oss << "At instruction # " << instructionCounter << ": input dimension of block' " << name << "' is " << inputDimension() << ": you can't use index " << input_index;
	throw SyxError(oss.str());
    }
    if (name != "" && used[ input_index ]) // il warning non è significativo quando stiamo clonando le connessioni di un superblocco
	cout << ">>warning: multiple assignment of " << name << ".input[" << input_index << "] at instruction #" << instructionCounter << "\n";
    else
	used[ input_index ] = true;
    in[ input_index ] = src;
    src_out[ input_index ] = src_output_index;
    return true;
}