Beispiel #1
0
misfit_ranking_type *  misfit_ranking_alloc(const misfit_ensemble_type * misfit_ensemble , const stringlist_type * sort_keys , const int_vector_type * steps, const char * ranking_key) {
  const int ens_size = misfit_ensemble_get_ens_size( misfit_ensemble );
  int iens;
  misfit_ranking_type * ranking = misfit_ranking_alloc_empty(ens_size);
  
  for (iens = 0; iens < ens_size; iens++) {
    const misfit_member_type * misfit_member = misfit_ensemble_iget_member( misfit_ensemble , iens );  /* Lookup in the master ensemble. */
    
    {
      double iens_valid = true;
      double total = 0;
      hash_type * obs_hash = hash_alloc();
      for (int ikey = 0; ikey < stringlist_get_size( sort_keys ); ikey++) {
        const char * obs_key        = stringlist_iget( sort_keys , ikey );
        if (misfit_member_has_ts( misfit_member , obs_key )) {
          misfit_ts_type * ts = misfit_member_get_ts( misfit_member , obs_key );
          double value        = misfit_ts_eval( ts , steps );  /* Sum up the misfit for this key - and these timesteps. */
          hash_insert_double( obs_hash , obs_key , value);
          total += value;
        } else
          iens_valid = true;
      }
      if (iens_valid) 
        misfit_ranking_iset( ranking , iens , obs_hash , total );
      else
        misfit_ranking_iset_invalid( ranking , iens );
    }
  }
  ranking->sort_permutation = double_vector_alloc_sort_perm( ranking->total );

  return ranking;
}
Beispiel #2
0
void misfit_ensemble_initialize( misfit_ensemble_type * misfit_ensemble ,
                                 const ensemble_config_type * ensemble_config ,
                                 const enkf_obs_type * enkf_obs ,
                                 enkf_fs_type * fs ,
                                 int ens_size ,
                                 int history_length,
                                 bool force_init) {

    if (force_init || !misfit_ensemble->initialized) {
        misfit_ensemble_clear( misfit_ensemble );

        msg_type * msg                 = msg_alloc("Evaluating misfit for observation: " , false);
        double ** chi2_work            = __2d_malloc( history_length + 1 , ens_size );
        bool_vector_type * iens_valid  = bool_vector_alloc( ens_size , true );

        hash_iter_type * obs_iter = enkf_obs_alloc_iter( enkf_obs );
        const char * obs_key      = hash_iter_get_next_key( obs_iter );

        misfit_ensemble->history_length = history_length;
        misfit_ensemble_set_ens_size( misfit_ensemble , ens_size );

        msg_show( msg );
        while (obs_key != NULL) {
            obs_vector_type * obs_vector = enkf_obs_get_vector( enkf_obs , obs_key );
            msg_update( msg , obs_key );

            bool_vector_reset( iens_valid );
            bool_vector_iset( iens_valid , ens_size - 1 , true );
            obs_vector_ensemble_chi2( obs_vector ,
                                      fs ,
                                      iens_valid ,
                                      0 ,
                                      misfit_ensemble->history_length,
                                      0 ,
                                      ens_size ,
                                      chi2_work);

            /**
                Internalizing the results from the chi2_work table into the misfit structure.
            */
            for (int iens = 0; iens < ens_size; iens++) {
                misfit_member_type * node = misfit_ensemble_iget_member( misfit_ensemble , iens );
                if (bool_vector_iget( iens_valid , iens))
                    misfit_member_update( node , obs_key , misfit_ensemble->history_length , iens , (const double **) chi2_work);
            }
            obs_key = hash_iter_get_next_key( obs_iter );
        }

        bool_vector_free( iens_valid );
        msg_free(msg , true );
        hash_iter_free( obs_iter );

        __2d_free( chi2_work , misfit_ensemble->history_length + 1);
        misfit_ensemble->initialized = true;
    }
}