Пример #1
0
void histoBook::make( xmlConfig * config, string nodeName ){

	if ( config && config->nodeExists( nodeName ) ){
		
		string hName = config->tagName( nodeName );
		if ( "" == hName )
			hName = nodeName;

		// store the path in the config file
		configPath[ hName ] = nodeName;

		string type = config->getString( nodeName + ":type", "1D" );

		if ( "1D" == type ){
			make1D( hName, config->getString( nodeName + ":title", hName ), 
					config->getInt( nodeName + ":nBinsX", 1 ), config->getDouble( nodeName + ":x1", 0 ),
					config->getDouble( nodeName + ":x2", 1 ) );

		} else if ( "2D" == type ){
			make2D( hName, config->getString( nodeName + ":title", hName ), 
					config->getInt( nodeName + ":nBinsX", 1 ), config->getDouble( nodeName + ":x1", 0 ),
					config->getDouble( nodeName + ":x2", 1 ),
					config->getInt( nodeName + ":nBinsY", 1 ), config->getDouble( nodeName + ":y1", 0 ),
					config->getDouble( nodeName + ":y2", 1 ) );
		}

	
	}

}
Пример #2
0
// Applies previously trained QDA classifier to new data matrix x
//
// Inputs:
// 	i_x - N x p data matrix of N samples in p dimensions
//	i_means - K x p matrix of class centroids
// 	i_icovmats - K x p x p array of inverse covariance matrices
//	i_bias - vector of length containing the bias term for each discriminant function
//	i_N - number of samples in x
//	i_p - dimensionality of x
//	i_K - number of classes
//
// Outputs:
//	o_labels - labels for all samples in i_x
//
// Memory allocation requirements for the outputs:
//	o_labels must be of length N
void QDAtest(
	     double* i_x, double* i_means, double* i_icovmats, double* i_bias,
	     int* i_N, int* i_p, int* i_K, int* o_labels
	     )
{
  // Create local storage
  int t, k, i, j;
  double temp;
  double* x_c = make1D( *i_p );
  double** x = make2D( *i_N, *i_p );
  double** means = make2D( *i_K, *i_p );
  double*** icovmats = make3D( *i_K, *i_p, *i_p );
  double** delta = make2D( *i_N, *i_K );

  // Copy and reshape the inputs to local storage
  cp_vec_mat( *i_N, *i_p, i_x, x );
  cp_vec_mat( *i_K, *i_p, i_means, means );
  cp_vec_3D( *i_K, *i_p, *i_p, i_icovmats, icovmats );

  // Compute the delta function values
  for( t = 0; t < *i_N; t++ )
    for( k = 0; k < *i_K; k++ )
      {
	add_vec_vec( *i_p, 1.0, -1.0, x[t], means[k], x_c );
	delta[t][k] = 0.0;
	for( i = 0; i < *i_p; i++ )
	  for( j = 0; j < *i_p; j++ )
	    delta[t][k] += icovmats[k][i][j] * x_c[i] * x_c[j];
	delta[t][k] *= -0.5;
	delta[t][k] += i_bias[k];
      }

  // Pick the highest discriminant function value for each point
  for( t = 0; t < *i_N; t++ )
    {
      o_labels[t] = 1;
      temp = delta[t][0];
      for( k = 1; k < *i_K; k++ )
	{
	  if( delta[t][k] > temp )
	    {
	      o_labels[t] = k + 1;
	      temp = delta[t][k];
	    }
	}
    }

  // Free up memory
  free( x_c );
  free2D( x, *i_N );
  free2D( means, *i_K );
  free3D( icovmats, *i_K, *i_p );
  free2D( delta, *i_N );
}