MatrixXd Covariances::marginal(const list<Node*>& nodes) const {
  node_lists_t node_lists;
  node_lists.push_back(nodes);
  return marginal(node_lists).front();
}
int LU_sim::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 LU_sim", 
			    total_steps, frequency );

  // In LU simulation, the marginal is a Gaussian cdf, 
  // with mean 0 and variance 1.
  Gaussian_cdf marginal( 0.0, 1.0 );

  //typedef Geostat_grid::random_path_iterator iterator;
  typedef Gval_iterator< TabularMapIndex > iterator;

  std::vector< int > id_unknown;
  std::vector< int > id_data;

  //harddata_grid_->select_property(harddata_property_->name());
  if( harddata_grid_ ) {
    for( int i=0; i< harddata_property_->size(); i++ ) {
      if(!harddata_property_->is_informed(i) ) continue;
      id_data.push_back( i );
    }
  }
  for( int i=0; i< simul_grid_->size(); i++ ) {
    if( simul_grid_ == harddata_grid_ && harddata_property_->is_informed(i) ) continue;
    id_unknown.push_back( i );
  }

  iterator begin_d( harddata_grid_, harddata_property_ ,0,  
			      id_data.size(), TabularMapIndex(&id_data) );
  iterator end_d( harddata_grid_, harddata_property_ ,id_data.size(),  
			      id_data.size(), TabularMapIndex(&id_data) );

  Grid_continuous_property* prop = multireal_property_->new_realization();
  
  iterator begin_u( simul_grid_, prop ,0,  
			      id_unknown.size(), TabularMapIndex(&id_unknown) );
  iterator end_u( simul_grid_, prop ,id_unknown.size(),  
			      id_unknown.size(), TabularMapIndex(&id_unknown) );

  Random_number_generator gen;
  LU_simulator<
        Covariance<Location>,
        Random_number_generator,
        Geostat_grid> 
    lu_sim( covar_,gen, simul_grid_ );
  lu_sim.initialize_matrix(begin_u, end_u, begin_d, end_d);

  // 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" );
    //Grid_continuous_property* prop = multireal_property_->new_realization();
    if(nreal>0) prop = multireal_property_->new_realization();
    prop->set_parameters(parameters_);
    simul_grid_->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 );
    }


    iterator begin_unk( simul_grid_, prop ,0,  
			   id_unknown.size(), TabularMapIndex(&id_unknown) );
    iterator  end_unk( simul_grid_, prop ,id_unknown.size(),  
			   id_unknown.size(), TabularMapIndex(&id_unknown) );

    int status = lu_sim(begin_unk,end_unk,marginal);

    // 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() );
  //  }


    if( status == -1 ) {
      clean( prop );
      return 1;
    }
    // back-transform if needed
    if( use_target_hist_ ) {
      cdf_transform( prop->begin(), prop->end(), 
        marginal, *target_cdf_.raw_ptr() );
    }

  }

  clean();

  return 0;
}
Exemple #3
0
 /* figure out if this snp is epistatic */
 bool epistatic() const { return !marginal(); }