コード例 #1
0
ファイル: AlgLibTools.cpp プロジェクト: hihiy/IntelliVoice
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;
}
コード例 #2
0
ファイル: AlgLibTools.cpp プロジェクト: hihiy/IntelliVoice
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++;
    }
}
コード例 #3
0
ファイル: Evaluation.cpp プロジェクト: hihiy/IntelliVoice
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;

}
コード例 #4
0
ファイル: Evaluation.cpp プロジェクト: hihiy/IntelliVoice
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;
}