Example #1
0
int Cosisim::full_ik( RandomPath begin, RandomPath end,
                      Progress_notifier* progress_notifier ) {
  typedef FullIK_cdf_estimator< geostat_utils::CoKrigingConstraints,
                                geostat_utils::CoKrigingCombiner, 
                                MarkovBayesCovariance > FullIkEstimator;
  FullIkEstimator cdf_estimator( marginal_->p_begin(),marginal_->p_end(),
                                 covariances_.begin(), covariances_.end(),
                                 combiners_.begin(), combiners_.end(),
                                 *kconstraints_ );

  // set up the sampler
  Random_number_generator gen;
  Monte_carlo_sampler_t< Random_number_generator > sampler( gen );

  
  // this vector will contain the indicies of the indicators to be estimated
  // at a given grid node
  std::vector< unsigned int > unestimated_indicators;
  
  for( ; begin != end ; ++begin ) {
    if( !progress_notifier->notify() ) return 1;

    get_current_local_cdf( *begin, unestimated_indicators );
    if( unestimated_indicators.empty() ) {
      sampler( *begin, *ccdf_ ); 
      continue;
    }
   
    geostat_utils::NeighborhoodVector neighborhoods =
      full_ik_find_neighbors( *begin, unestimated_indicators );

    DEBUG_PRINT_LOCATION( "center", begin->location() );
    DEBUG_PRINT_NEIGHBORHOOD( "hard1", &neighborhoods[0] );
    DEBUG_PRINT_NEIGHBORHOOD( "soft1", &neighborhoods[1] );
    DEBUG_PRINT_NEIGHBORHOOD( "hard2", &neighborhoods[2] );
    DEBUG_PRINT_NEIGHBORHOOD( "soft2", &neighborhoods[3] );

    GsTLPoint watch( 52, 95, 13 );
    if( begin->location() == watch ) {
      std::cout << "found" << std::endl;
    }

    clear_ccdf();
    int status = cdf_estimator( *begin,
                                neighborhoods.begin(), neighborhoods.end(),
                                *ccdf_ );

    sampler( *begin, *ccdf_ );
    code_into_indicators( *begin );
  }

  return 0;
}
Example #2
0
int dssim::execute( GsTL_project* ) {
  
  // Initialize the global random number generator
  Global_random_number_generator::instance()->seed( seed_ );
  
  
  // Set up a progress notifier	
  int total_steps = simul_grid_->size() * (nb_of_realizations_);
  int frequency = std::max( total_steps / 20, 1 );
  SmartPtr<Progress_notifier> progress_notifier = 
    utils::create_notifier( "Running dssim", 
			    total_steps, frequency );

  // Initialize the marginal cdf for the direct sequential simulation
 // LogNormal_cdf marginal( 0.1, 1.0 );
 // LogNormal_cdf ccdf;

  // work on the fine grid
  if( dynamic_cast<Strati_grid*>( simul_grid_ ) ) {
    Strati_grid* sgrid = dynamic_cast<Strati_grid*>( simul_grid_ );
    sgrid->set_level( 1 );
  }

  // set up the cdf-estimator
  typedef First2_moments_cdf_Kestimator< Covariance<Location>,
                                   Neighborhood,
                                   geostat_utils::KrigingConstraints
                                  >    Kriging_cdf_estimator;
  Kriging_cdf_estimator cdf_estimator( covar_,
				       *Kconstraints_,
				       *combiner_ );

  // set up the sampler
  Random_number_generator gen;
  Monte_carlo_sampler_t< Random_number_generator > sampler( gen );
  
  // compute the random path
  simul_grid_->init_random_path();

  // loop on all realizations
  for( int nreal = 0; nreal < nb_of_realizations_ ; nreal ++ ) {

    // update the progress notifier
    progress_notifier->message() << "working on realization " 
                                 << nreal+1 << gstlIO::end;
    if( !progress_notifier->notify() ) return 1;


    // Create a new property to hold the realization and tell the simulation 
    // grid to use it as the current property 
    appli_message( "Creating new realization" );
    GsTLGridProperty* prop = multireal_property_->new_realization();
    simul_grid_->select_property( prop->name() );
    neighborhood_->select_property( prop->name() );

    // initialize the new realization with the hard data, if that was requested 
    if( property_copier_ ) {
      property_copier_->copy( harddata_grid_, harddata_property_,
                              simul_grid_, prop );
      //initializer_->assign( prop, harddata_grid_, harddata_property_->name() );
    }


    appli_message( "Doing simulation" );
    // do the simulation
    int status = 
      sequential_simulation( simul_grid_->random_path_begin(),
			     simul_grid_->random_path_end(),
			     *(neighborhood_.raw_ptr()),
			     *ccdf_,
			     cdf_estimator,
			     *marginal_,
			     sampler, progress_notifier.raw_ptr()
			     );
    if( status == -1 ) {
      clean( prop );
      return 1;
    }
  }

  clean();

  return 0;
}