예제 #1
0
	void	CTrainNodeCvKNN::train(bool doClean)
	{
#ifdef DEBUG_PRINT_INFO
		printf("\n");
#endif

		// Filling the <samples> and <classes>
		Mat samples, classes;
		for (byte s = 0; s < m_nStates; s++) {						// states
			int nSamples = m_pSamplesAcc->getNumSamples(s);
#ifdef DEBUG_PRINT_INFO		
			printf("State[%d] - %d of %d samples\n", s, nSamples, m_pSamplesAcc->getNumInputSamples(s));
#endif
			samples.push_back(m_pSamplesAcc->getSamplesContainer(s));
			classes.push_back(Mat(nSamples, 1, CV_32FC1, Scalar(s)));
			if (doClean) m_pSamplesAcc->release(s);				// free memory
		} // s
		samples.convertTo(samples, CV_32FC1);

		// Filling <var_type>
		Mat var_type(getNumFeatures() + 1, 1, CV_8UC1, Scalar(ml::VAR_NUMERICAL));		// all inputs are numerical
		var_type.at<byte>(getNumFeatures(), 0) = ml::VAR_CATEGORICAL;

		// Training
		try {
			m_pKNN->train(ml::TrainData::create(samples, ml::ROW_SAMPLE, classes, noArray(), noArray(), noArray(), var_type));
		}
		catch (std::exception &e) {
			printf("EXCEPTION: %s\n", e.what());
			getchar();
			exit(-1);
		}
	}
  virtual void visit_vector_type (const OASIS_PDL_Vector_Type & v)
  {
    this->out_ << "std::vector < ";

    Stub_Var_Type_Generator var_type (this->out_);
    v.type ()->accept (var_type);

    this->out_ << " > &";
  }
예제 #3
0
파일: bcompile2.c 프로젝트: kstephens/ll
ll_define_primitive_end


/*
** Compile into code to generate a value for an exports vector.
*/
ll_define_primitive(pair, _ir_compile2_export, _2(self, ir), _0())
{
  ll_v x = ll_SELF;
  ll_v var = ll_car(x);
  ll_v type = var_type(x);
  ll_v index = var_index(x);

  ll_assert_ref(IR);

  /* slot ref */
  if ( ll_EQ(type, ll_s(slot)) ) {
    /* Create a const containing the global var name */
    index = ll_call(ll_o(_ir_const_index), _2(IR, var));
  } else
  if ( ll_EQ(type, ll_s(glo)) ) {
    ll_abort("<pair>:%ir-compile2-export");
  }

  /* undef export is a local from a car-pos sub lambda */
  if ( ll_EQ(type, ll_undef) ) {
    ll_call_tail(ll_o(_ir_compile2), _3(ll_undef, IR, ll_f));
  } else {
    ll_v emit_type = type;

    /* env_loc is an environment slot containing a locative */
    if ( ll_EQ(type, ll_s(env_loc)) ) {
      emit_type = ll_s(env);
    }

    if ( ll_unbox_boolean(index) ) {
      ll_call(ll_o(_ir_emit_with_int), _3(IR, emit_type, index));
    } else {
      ll_call(ll_o(_ir_emit), _2(IR, emit_type));
    }

    /*
    ** arg and local values are stored directly into the exports vector.
    ** so put the value, not a locative to the arg or local in the exports vector.
    */
    if ( ll_EQ(type, ll_s(arg)) 
	 || ll_EQ(type, ll_s(local)) 
	 || ll_EQ(type, ll_s(env_loc))
      ) {
      ll_call_tail(ll_o(_ir_emit), _2(IR, ll_s(contents)));
    }
  }
}
예제 #4
0
파일: bcompile2.c 프로젝트: kstephens/ll
/*
** Compiles a symbol into an instruction that generates a get,
** locative, or set operation.
** to the variable.
*/
ll_define_primitive(symbol, _ir_compile2_gen, _4(self, ir, tail_posQ, mode), _0())
{
  ll_v x = ll_call(ll_o(_ir_var_scope), _2(IR, SELF));
  ll_v mode = ll_ARG_3;
  ll_v var = SELF;
  ll_v type = var_type(x);
  ll_v index = var_index(x);
  ll_v co = var_closed_overQ(x);
  ll_v isn = ll_nil;

  _ll_gdb_stop_at();

  if ( ll_DEBUG(compile_emit) ) {
    ll_format(ll_undef, "  ~O: compile2-gen: ~S ~S\n", 3, IR, mode, x);
  }

  ll_assert_ref(IR);

  /* If it's closed over and environment has been exported.
   *
   * The environment has not been exported until 
   * the rest args creation
   * and other preambles have been emited.
   */
  if ( ll_unbox_boolean(co) 
       && ! in_preamble 
       /* && ll_unbox_boolean(ll_THIS_ISA(_ir, IR)->_env_exportedQ) */
       ) {
    /* Get the locative to the exports[slots] value */
    ll_call(ll_o(_ir_emit_with_int), _3(IR, ll_s(export), co));

    /*
    ** If the closed-over variable is an argument or a local
    ** the value is stored directly in the exported environment
    ** vector.
    **
    ** Otherwise the environment slot contains a locative
    ** to the actual value, probably an object slot.
    */
    if ( ! (ll_EQ(type, ll_s(arg)) || ll_EQ(type, ll_s(local))) ) {
      ll_call(ll_o(_ir_emit), _2(IR, ll_s(contents)));
    }
  }
예제 #5
0
//Decision Tree
void decisiontree ( Mat & trainingData , Mat & trainingClasses , Mat & testData ,
		Mat & testClasses ) {
	CvDTree dtree ;
	Mat var_type (3 , 1 , CV_8U ) ;
	// define attributes as numerical
	var_type.at < unsigned int >(0 ,0) = CV_VAR_NUMERICAL;
	var_type.at < unsigned int >(0 ,1) = CV_VAR_NUMERICAL ;
	// define output node as numerical
	var_type.at < unsigned int >(0 ,2) = CV_VAR_NUMERICAL;
	dtree.train ( trainingData , CV_ROW_SAMPLE , trainingClasses , Mat () , Mat () ,
			var_type , Mat () , CvDTreeParams () ) ;
	Mat predicted ( testClasses.rows , 1 , CV_32F ) ;
	for ( int i = 0; i < testData.rows ; i ++) {
		const Mat sample = testData.row ( i ) ;
		CvDTreeNode * prediction = dtree.predict ( sample ) ;
		predicted.at < float > (i , 0) = prediction->value ;
	}
	cout << " Accuracy_ { TREE } = " << evaluate ( predicted , testClasses ) << endl ;
	plot_binary ( testData , predicted , " Predictions tree " ) ;
}
예제 #6
0
CField::VarType CField::var_type ( const std::string& vname ) const
{
  return var_type(var_number(vname));
}