int Kriging_x_validation::execute( GsTL_project* ) {
  // those flags will be used to signal if some of the nodes could not be
  // informed
  bool issue_singular_system_warning = false;
  bool issue_no_conditioning_data_warning = false;
 
  // Set up a progress notifier	
  int total_steps = harddata_grid_->size();
  int frequency = std::max( total_steps / 20, 1 );
  SmartPtr<Progress_notifier> progress_notifier = 
    utils::create_notifier( "Running Kriging", 
			    total_steps, frequency );

  // create the property
  

  Grid_continuous_property* kvalue_prop = geostat_utils::add_property_to_grid(harddata_grid_, property_name_ );
  property_name_ = kvalue_prop->name();
  kvalue_prop->set_parameters(parameters_);

  Grid_continuous_property* var_prop = 
    geostat_utils::add_property_to_grid( harddata_grid_, property_name_ + "_krig_var" );
  appli_assert( var_prop );
  var_prop->set_parameters(parameters_);

  Grid_continuous_property* error_prop = 
    geostat_utils::add_property_to_grid( harddata_grid_, property_name_ + "_error" );
  appli_assert( error_prop );
  error_prop->set_parameters(parameters_);

  Grid_continuous_property* error2_prop = 
    geostat_utils::add_property_to_grid( harddata_grid_, property_name_ + "_error2" );
  appli_assert( error2_prop );
  error2_prop->set_parameters(parameters_);

  Grid_continuous_property* error2_kvar_prop = 
    geostat_utils::add_property_to_grid( harddata_grid_, property_name_ + "_error2_kvar_ratio" );
  appli_assert( error2_kvar_prop );
  error2_kvar_prop->set_parameters(parameters_);

  harddata_grid_->select_property( kvalue_prop->name() );



  typedef Geostat_grid::iterator iterator;
  iterator begin = harddata_grid_->begin();
  iterator end = harddata_grid_->end();
  
  for( ; begin != end; ++begin ) {
    if( !progress_notifier->notify() ) {
      clean( property_name_ );
      return 1;
    }

  
    neighborhood_->find_neighbors( *begin );
    
    if( neighborhood_->size() < min_neigh_ )  continue;
    if(!neighborhood_->is_valid()) continue;
/*
 //   if( neighborhood_->is_empty() ) {
    if( neighborhood_->size() < min_neigh_ ) {
      //if we don't have any conditioning data, skip the node
      issue_no_conditioning_data_warning = true;
      continue;
    }
*/
    double variance;
    int status = kriging_weights_2( kriging_weights_, variance,
                                  *begin, *(neighborhood_.raw_ptr()),
                      				    covar_,*rhs_covar_, *Kconstraints_ );

    if(status == 0) {
    	// the kriging system could be solved
    	double estimate = (*combiner_)( kriging_weights_.begin(), 
		                            			kriging_weights_.end(),
					                            *(neighborhood_.raw_ptr()) );
      begin->set_property_value( estimate );

      int nodeid = begin->node_id();
      Grid_continuous_property::property_type value = neighborhood_->selected_property()->get_value(nodeid);
      float error = estimate - value;
      float error2 = error*error;
      float error_kvar = error2/variance;

      var_prop->set_value( variance, nodeid );
      error_prop->set_value( error, nodeid );
      error2_prop->set_value( error2, nodeid );
      error2_kvar_prop->set_value( error_kvar, nodeid );


    }
    else {
    	// the kriging system could not be solved, issue a warning and skip the
    	// node
      issue_singular_system_warning = true;
        
    }
  }
/* This pop-up windows breaks script

  if( issue_singular_system_warning )
    GsTLcerr << "Kriging could not be performed at some locations because\n"
             << "the kriging system was singular\n" 
             << gstlIO::end; 
  if( issue_no_conditioning_data_warning )
    GsTLcerr << "Kriging could not be performed at some locations because\n"
             << "the neighborhood of those locations was empty.\n"
             << "Try increasing the size of the search ellipsoid.\n"
             << gstlIO::end; 
*/

  return 0;
}
Esempio n. 2
0
int KrigingMean::execute( GsTL_project* ) {
  // those flags will be used to signal if some of the nodes could not be
  // informed
  bool issue_singular_system_warning = false;
  bool issue_no_conditioning_data_warning = false;
 
  // Set up a progress notifier	
  int total_steps = simul_grid_->size();
  int frequency = std::max( total_steps / 20, 1 );
  SmartPtr<Progress_notifier> progress_notifier = 
    utils::create_notifier( "Running Kriging", 
			    total_steps, frequency );

  // create the property
  appli_message("creating new property: " << property_name_ << "..." );
  GsTLGridProperty* prop = 
    geostat_utils::add_property_to_grid( simul_grid_, property_name_ );
  simul_grid_->select_property( prop->name() );

  typedef Geostat_grid::iterator iterator;
  iterator begin = simul_grid_->begin();
  iterator end = simul_grid_->end();
  
  for( ; begin != end; ++begin ) {
    if( !progress_notifier->notify() ) {
      clean( property_name_ );
      return 1;
    }

    if( begin->is_informed() ) continue;
    
      
    neighborhood_->find_neighbors( *begin );
    if( neighborhood_->size() < min_neigh_ )  continue;
    if(!neighborhood_->is_valid()) continue;
    

    double variance;



    int status;
    

    status = kriging_weights_2( kriging_weights_, variance,
                                  begin->location(), *(neighborhood_.raw_ptr()),
                      				    covar_,*rhs_covar_, *Kconstraints_ );


    if(status == 0) {
    	// the kriging system could be solved
    	double estimate = (*combiner_)( kriging_weights_.begin(), 
		                            			kriging_weights_.end(),
					                            *(neighborhood_.raw_ptr()) );
      begin->set_property_value( estimate );

    }
    else {
    	// the kriging system could not be solved, issue a warning and skip the
    	// node
      issue_singular_system_warning = true;
        
    }
  }
/* This pop-up windows breaks script

  if( issue_singular_system_warning )
    GsTLcerr << "Kriging could not be performed at some locations because\n"
             << "the kriging system was singular\n" 
             << gstlIO::end; 
  if( issue_no_conditioning_data_warning )
    GsTLcerr << "Kriging could not be performed at some locations because\n"
             << "the neighborhood of those locations was empty.\n"
             << "Try increasing the size of the search ellipsoid.\n"
             << gstlIO::end; 
*/

  return 0;
}