当前位置: 首页>>代码示例>>C++>>正文


C++ ISamples类代码示例

本文整理汇总了C++中ISamples的典型用法代码示例。如果您正苦于以下问题:C++ ISamples类的具体用法?C++ ISamples怎么用?C++ ISamples使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ISamples类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init_conf_mat

void Evaluation::init_conf_mat (ISamples &samples) {

	_n_classes = samples.getClassSize ();

	// store class names
	_class_names = new ssi_char_t *[_n_classes];
	for (ssi_size_t i = 0; i < _n_classes; i++) {
		_class_names[i] = ssi_strcpy (samples.getClassName (i));
	}

	// allocate confussion matrix
	_conf_mat_ptr = new ssi_size_t *[_n_classes];
	_conf_mat_data = new ssi_size_t[_n_classes * _n_classes];
	for (ssi_size_t i = 0; i < _n_classes; ++i) {
		_conf_mat_ptr[i] = _conf_mat_data + i*_n_classes;
	}

	// set all elements in the confussion matrix to zero
	for (ssi_size_t i = 0; i < _n_classes; ++i) {
		for (ssi_size_t j = 0; j < _n_classes; ++j) {
			_conf_mat_ptr[i][j] = 0;
		}
	}

	_n_unclassified = 0;
	_n_classified = 0;	
}
开发者ID:hihiy,项目名称:IntelliVoice,代码行数:27,代码来源:Evaluation.cpp

示例2: samples_s

void AlgLibTools::Samples2matrix (
	ISamples &samples,   
	ssi_size_t stream_id,
	ssi_size_t class_id,
    ae_matrix* m,
    ae_state *state)
{
	
	ae_int_t nfeatures = samples.get (0)->streams[stream_id]->dim;
	ae_int_t nsamples = samples.getSize (class_id);
    ae_int_t i = 0;
    ae_int_t j = 0;

    ae_matrix_clear(m);    
    ae_matrix_set_length(m, nsamples, nfeatures, state);

	ssi_sample_t *sample;
	ISSelectClass samples_s (&samples);
	samples_s.setSelection (class_id);
	samples_s.reset ();
	while (sample = samples_s.next ()) {    
		ssi_real_t *ptr = ssi_pcast (ssi_real_t, sample->streams[stream_id]->ptr);
        for(j=0; j<=nfeatures-1; j++)
        {
			m->ptr.pp_double[i][j] = ssi_cast (double, *ptr++);
        }        
		i++;
    }
}
开发者ID:hihiy,项目名称:IntelliVoice,代码行数:29,代码来源:AlgLibTools.cpp

示例3: train

bool MyFusion::train (ssi_size_t n_models,
	IModel **models,
	ISamples &samples) {

	if (samples.getSize () == 0) {
		ssi_wrn ("empty sample list");
		return false;
	}

	if (isTrained ()) {
		ssi_wrn ("already trained");
		return false;
	}

	ssi_size_t n_streams = samples.getStreamSize ();

	if (n_streams != n_models) {
		ssi_err ("#models (%u) differs from #streams (%u)", n_models, n_streams);
	}

	for (ssi_size_t n_model = 0; n_model < n_models; n_model++) {
		if (!models[n_model]->isTrained ()) {
			models[n_model]->train (samples, n_model);
		}
	}

	_is_trained = true;

	return true;
}
开发者ID:hihiy,项目名称:IntelliVoice,代码行数:30,代码来源:MyFusion.cpp

示例4:

void AlgLibTools::Samples2MatrixWithClass (ISamples &samples,     
		ssi_size_t stream_id, ae_matrix* m) {

	ae_int_t nfeatures = samples.get (0)->streams[stream_id]->dim;
	ae_int_t nsamples = samples.getSize ();

    ae_int_t i = 0;
    ae_int_t j = 0;
    ae_state state;
    ae_matrix_clear(m);
    ae_matrix_set_length(m, nsamples, nfeatures+1, &state);

	ssi_sample_t *sample;
	samples.reset ();	
	while (sample = samples.next ()) {    
		ssi_real_t *ptr = ssi_pcast (ssi_real_t, sample->streams[stream_id]->ptr);
        for (j = 0; j <= nfeatures-1; j++)
        {
			m->ptr.pp_double[i][j] = ssi_cast (double, *ptr++);
        }
		m->ptr.pp_double[i][j] = ssi_cast (double, sample->class_id);
		i++;
    }

	//delete sample;
}
开发者ID:hihiy,项目名称:IntelliVoice,代码行数:26,代码来源:AlgLibTools.cpp

示例5: build

bool Fisher::build (ISamples &samples, ssi_size_t stream_index) {

	if (samples.getSize () == 0) {
		ssi_wrn ("empty sample list");
		return false;
	}

	if (isBuild ()) {
		ssi_wrn ("already trained");
		return false;
	}

	ae_state state;
	ae_int_t info; 


	ae_matrix data;
	ae_matrix_init (&data, 0, 0, DT_REAL, &state, ae_true);	
	// convert the samples to a matrix where the last column holds the class number to which the sample belongs
	AlgLibTools::Samples2MatrixWithClass(samples, 0, &data);

	_basis = new ae_matrix;
	ae_matrix_init (_basis, 0, 0, DT_REAL, &state, ae_true);
	fisherldan(&data,data.rows,data.cols-1 , samples.getClassSize(),&info,_basis,&state);

	ae_matrix_clear (&data);

	_is_build = true;

	return true;

}
开发者ID:hcmlab,项目名称:mobileSSI,代码行数:32,代码来源:Fisher.cpp

示例6: norm

void ISNorm::norm (ISamples &samples) {

	samples.reset ();
	ssi_sample_t *sample = 0;
	while (sample = samples.next ()) {
		norm (*sample);
	}
}
开发者ID:hcmlab,项目名称:mobileSSI,代码行数:8,代码来源:ISNorm.cpp

示例7: write

bool FileSamplesOut::write (ISamples &data) {

	data.reset ();
	ssi_sample_t *sample = 0;
	while (sample = data.next ()) {
		write (*sample);
	}

	return true;
}
开发者ID:hihiy,项目名称:IntelliVoice,代码行数:10,代码来源:FileSamplesOut.cpp

示例8: evalLOUO

void Evaluation::evalLOUO (Trainer *trainer, ISamples &samples){

	_trainer = trainer;
	destroy_conf_mat ();
	init_conf_mat (samples);
	ssi_size_t n_users = samples.getUserSize ();

	_n_total = samples.getSize ();
	_result_vec = new ssi_size_t[2*_n_total];
	_result_vec_ptr = _result_vec;

	ssi_size_t itest  = 0;
	ssi_size_t *itrain = new ssi_size_t[n_users - 1];
	for (ssi_size_t nuser = 0; nuser < n_users - 1; ++nuser) {
		itrain[nuser] = nuser+1;
	}
	
	ISSelectUser strain (&samples);
	ISSelectUser stest (&samples);

	strain.setSelection  (n_users-1, itrain);
	stest.setSelection (1, &itest);

	_trainer->release ();
	if (_fselmethod) {
		_trainer->setSelection (strain, _fselmethod, _pre_fselmethod, _n_pre_feature);
	}
	if (_preproc_mode) {
		_trainer->setPreprocMode (_preproc_mode, _n_streams_refs, _stream_refs);
	}
	_trainer->train (strain);
	eval_h (stest);		

	for (ssi_size_t nuser = 1; nuser < n_users; ++nuser) {
		
		itrain[nuser-1] = nuser-1;
		itest = nuser;

		strain.setSelection  (n_users-1, itrain);
		stest.setSelection (1, &itest);

		_trainer->release ();
		if (_fselmethod) {
			_trainer->setSelection (strain, _fselmethod, _pre_fselmethod, _n_pre_feature);
		}
		if (_preproc_mode) {
			_trainer->setPreprocMode (_preproc_mode, _n_streams_refs, _stream_refs);
		}
		_trainer->train (strain);

		eval_h (stest);		
	}

	delete [] itrain;
}
开发者ID:hihiy,项目名称:IntelliVoice,代码行数:55,代码来源:Evaluation.cpp

示例9: eval

void Evaluation::eval (IFusion &fusion, ssi_size_t n_models, IModel **models, ISamples &samples) {

	// init confussion matrix
	_trainer = 0;
	destroy_conf_mat ();	
	init_conf_mat (samples);
	ssi_size_t n_classes = samples.getClassSize ();
	ssi_real_t *probs = new ssi_real_t[n_classes];

	_n_total = samples.getSize ();
	_result_vec = new ssi_size_t[2*_n_total];
	_result_vec_ptr = _result_vec;

	samples.reset ();
	const ssi_sample_t *sample = 0;	
	while (sample = samples.next ()) {

		ssi_size_t real_index = sample->class_id;
		*_result_vec_ptr++ = real_index;
		if (fusion.forward (n_models, models, sample->num, sample->streams, n_classes, probs)) {

			ssi_size_t max_ind = 0;
			ssi_real_t max_val = probs[0];
			for (ssi_size_t i = 1; i < n_classes; i++) {
				if (probs[i] > max_val) {
					max_val = probs[i];
					max_ind = i;
				}
			}

			*_result_vec_ptr++ = max_ind;
			_conf_mat_ptr[real_index][max_ind]++;
			_n_classified++;

		} else if (!_allow_unclassified) {
			ssi_size_t max_ind = _default_class_id;
			*_result_vec_ptr++ = max_ind;
			_conf_mat_ptr[real_index][max_ind]++;
			_n_classified++;
		} else {
			*_result_vec_ptr++ = SSI_ISAMPLES_GARBAGE_CLASS_ID;
			_n_unclassified++;
		}	
	}

	delete[] probs;
}
开发者ID:hihiy,项目名称:IntelliVoice,代码行数:47,代码来源:Evaluation.cpp

示例10: train

bool SimpleFusion::train (ssi_size_t n_models,
	IModel **models,
	ISamples &samples) {

	if (samples.getSize () == 0) {
		ssi_wrn ("empty sample list");
		return false;
	}

	if (isTrained ()) {
		ssi_wrn ("already trained");
		return false;
	}

	ssi_size_t n_streams = samples.getStreamSize ();

	if (n_streams != 1 && n_streams != n_models) {
		ssi_err ("#models (%u) differs from #streams (%u)", n_models, n_streams);
	}

	if (samples.hasMissingData ()) {
		ISMissingData samples_h (&samples);
		for (ssi_size_t n_model = 0; n_model < n_models; n_model++) {
			if (!models[n_model]->isTrained ()) {
				samples_h.setStream(n_streams == 1 ? 0 : n_model);
				models[n_model]->train (samples_h, n_model);
			}
		}
	} else {
		for (ssi_size_t n_model = 0; n_model < n_models; n_model++) {
			if (!models[n_model]->isTrained ()) {		
				models[n_model]->train(samples, n_streams == 1 ? 0 : n_model);
			}
		}
	}

	_is_trained = true;

	return true;
}
开发者ID:hcmlab,项目名称:mobileSSI,代码行数:40,代码来源:SimpleFusion.cpp

示例11: eval_h

void Evaluation::eval_h (ISamples &samples) {	

	// walk through sample list and test trainer against each sample
	samples.reset ();
	const ssi_sample_t *sample = 0;
	ssi_size_t index, real_index;
	while (sample = samples.next ()) {
		real_index = sample->class_id;
		*_result_vec_ptr++ = real_index;
		if (_trainer->forward (sample->num, sample->streams, index)) {
			*_result_vec_ptr++ = index;
			_conf_mat_ptr[real_index][index]++;
			_n_classified++;
		} else if (!_allow_unclassified) {
			index = _default_class_id;
			*_result_vec_ptr++ = index;
			_conf_mat_ptr[real_index][index]++;
			_n_classified++;
		} else {
			*_result_vec_ptr++ = SSI_ISAMPLES_GARBAGE_CLASS_ID;
			_n_unclassified++;
		}
	}
}
开发者ID:hihiy,项目名称:IntelliVoice,代码行数:24,代码来源:Evaluation.cpp

示例12: evalSplit

void Evaluation::evalSplit (Trainer *trainer, ISamples &samples, ssi_real_t split) {

	if (split <= 0 || split >= 1) {
		ssi_err ("split must be a value between 0 and 1");
	}

	_trainer = trainer;
	destroy_conf_mat ();
	init_conf_mat (samples);
	
	ssi_size_t *indices = new ssi_size_t[samples.getSize ()];
	ssi_size_t *indices_count_lab = new ssi_size_t[samples.getClassSize ()];
	ssi_size_t indices_count_all;

	indices_count_all = 0;
	for (ssi_size_t j = 0; j < samples.getClassSize (); j++) {
		indices_count_lab[j] = 0;
	}

	ssi_size_t label;
	ssi_size_t label_size;
	for (ssi_size_t j = 0; j < samples.getSize (); j++) {
		label = samples.get (j)->class_id;
		label_size = samples.getSize (label);
		if (++indices_count_lab[label] <= ssi_cast (ssi_size_t, label_size * split + 0.5f)) {
			indices[indices_count_all++] = j;			
		}
	}

	SampleList strain;
	SampleList stest;

	// split off samples
	ModelTools::SelectSampleList (samples, strain, stest, indices_count_all, indices);
	_n_total = stest.getSize ();
	_result_vec = new ssi_size_t[2*_n_total];
	_result_vec_ptr = _result_vec;

	// train with remaining samples
	_trainer->release ();	
	if (_preproc_mode) {
		_trainer->setPreprocMode (_preproc_mode, _n_streams_refs, _stream_refs);
	} else if (_fselmethod) {
		_trainer->setSelection (strain, _fselmethod, _pre_fselmethod, _n_pre_feature);
	}
	_trainer->train (strain);		

	// test with remaining samples
	eval_h (stest);

	delete[] indices;
	delete[] indices_count_lab;

}
开发者ID:hihiy,项目名称:IntelliVoice,代码行数:54,代码来源:Evaluation.cpp

示例13: evalKFold

void Evaluation::evalKFold (Trainer *trainer, ISamples &samples, ssi_size_t k) {

	// init confussion matrix
	_trainer = trainer;
	destroy_conf_mat ();
	init_conf_mat (samples);

	_n_total = samples.getSize ();
	_result_vec = new ssi_size_t[2*_n_total];
	_result_vec_ptr = _result_vec;
	
	ssi_size_t *indices = new ssi_size_t[samples.getSize ()];
	ssi_size_t *indices_count_lab = new ssi_size_t[samples.getClassSize ()];
	ssi_size_t indices_count_all;

	for (ssi_size_t i = 0; i < k; ++i) {

		indices_count_all = 0;
		for (ssi_size_t j = 0; j < samples.getClassSize (); j++) {
			indices_count_lab[j] = 0;
		}

		ssi_size_t label;
		for (ssi_size_t j = 0; j < samples.getSize (); j++) {
			label = samples.get (j)->class_id;
			if (++indices_count_lab[label] % k == i) {
				indices[indices_count_all++] = j;			
			}
		}

		SampleList strain;
		SampleList stest;	
		// split off i'th fold
		ModelTools::SelectSampleList (samples, stest, strain, indices_count_all, indices);

		// train with i'th fold
		_trainer->release ();
		if (_fselmethod) {
			_trainer->setSelection (strain, _fselmethod, _pre_fselmethod, _n_pre_feature);
		}
		if (_preproc_mode) {
			_trainer->setPreprocMode (_preproc_mode, _n_streams_refs, _stream_refs);
		}
		_trainer->train (strain);

		// test with remaining samples
		eval_h (stest);
	}

	delete[] indices;
	delete[] indices_count_lab;
}
开发者ID:hihiy,项目名称:IntelliVoice,代码行数:52,代码来源:Evaluation.cpp

示例14: train

bool Rank::train (ISamples &samples,
	ssi_size_t stream_index) {

	if (!_model) {
		ssi_wrn ("a model has not been set yet");
		return false;
	}

	release ();

	_n_scores = samples.getStream (stream_index).dim;	
	_scores = new score[_n_scores];

	Evaluation eval;
	Trainer trainer (_model, stream_index);
	
	SSI_DBG (SSI_LOG_LEVEL_DEBUG, "evaluate dimensions:");
	for (ssi_size_t ndim = 0; ndim < _n_scores; ndim++) {
		ISSelectDim samples_s (&samples);
		samples_s.setSelection (stream_index, 1, &ndim);
		if (_options.loo) {
			eval.evalLOO (&trainer, samples_s);
		} else if (_options.louo) {
			eval.evalLOUO (&trainer, samples_s);
		} else {
			eval.evalKFold (&trainer, samples_s, _options.kfold);
		}
		_scores[ndim].index = ndim;
		_scores[ndim].value = eval.get_classwise_prob ();
		SSI_DBG (SSI_LOG_LEVEL_DEBUG, "  #%02u -> %.2f", _scores[ndim].index, _scores[ndim].value);
	} 

	trainer.release ();

	return true;
}
开发者ID:hihiy,项目名称:IntelliVoice,代码行数:36,代码来源:Rank.cpp

示例15: train

bool SimpleKNN::train (ISamples &samples,
	ssi_size_t stream_index) {

	if (samples.getSize () == 0) {
		ssi_wrn ("empty sample list");
		return false;
	}

	if (samples.getSize () < _options.k) {
		ssi_wrn ("sample list has less than '%u' entries", _options.k);
		return false;
	}

	if (isTrained ()) {
		ssi_wrn ("already trained");
		return false;
	}

	_n_classes = samples.getClassSize ();
	_n_samples = samples.getSize ();	
	_n_features = samples.getStream (stream_index).dim;
	_data = new ssi_real_t[_n_features*_n_samples];
	_classes = new ssi_size_t[_n_samples];

	ssi_sample_t *sample;	
	samples.reset ();
	ssi_real_t *data_ptr = _data;
	ssi_size_t *class_ptr = _classes;
	ssi_stream_t *stream_ptr = 0;
	ssi_size_t bytes_to_copy = _n_features * sizeof (ssi_real_t);
	while (sample = samples.next ()) {				
		memcpy (data_ptr, sample->streams[stream_index]->ptr, bytes_to_copy);
		*class_ptr++ = sample->class_id;
		data_ptr += _n_features;
	}	 

	return true;
}
开发者ID:hihiy,项目名称:IntelliVoice,代码行数:38,代码来源:SimpleKNN.cpp


注:本文中的ISamples类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。