Example #1
0
void lars_select_beta( lars_type * lars , int beta_index) {
  int nvars = matrix_get_rows( lars->beta );
  if (lars->beta0 == NULL)
    lars->beta0 = matrix_alloc( nvars , 1 );
  {
    matrix_type * beta_vector = matrix_alloc( nvars , 1 );
    matrix_copy_column( beta_vector , lars->beta , 0 , beta_index );
    lars->Y0 = regression_unscale( beta_vector , lars->X_norm , lars->X_mean , lars->Y_mean , lars->beta0 );
    matrix_free( beta_vector );
  }
}
Example #2
0
void rml_enkf_common_store_state( matrix_type * state , const matrix_type * A , const bool_vector_type * ens_mask ) { 
  matrix_resize( state , matrix_get_rows( A ) , bool_vector_size( ens_mask ) , false);
  {
    const int ens_size = bool_vector_size( ens_mask );
    int active_index = 0;
    for (int iens = 0; iens < ens_size; iens++) {
      if (bool_vector_iget( ens_mask , iens ))
        matrix_copy_column( state , A , iens , active_index );
      else
        matrix_set_const_column( state , iens  , 0);
    }
  }
}
Example #3
0
void rml_enkf_common_recover_state( const matrix_type * state , matrix_type * A , const bool_vector_type * ens_mask ) { 
  const int ens_size = bool_vector_size( ens_mask );
  const int active_size = bool_vector_count_equal( ens_mask , true );
  const int rows = matrix_get_rows( state );
  
  matrix_resize( A , rows , active_size , false );
  {
    int active_index = 0;
    for (int iens = 0; iens < ens_size; iens++) {
      if (bool_vector_iget( ens_mask , iens ))
        matrix_copy_column( A , state , active_index , iens );
    }
  }
}
Example #4
0
void matrix_column_compressed_memcpy(matrix_type * target, const matrix_type * src, const bool_vector_type * mask) {
  if (bool_vector_count_equal( mask , true ) != matrix_get_columns( target ))
    util_abort("%s: size mismatch. \n",__func__);

  if (bool_vector_size( mask ) != matrix_get_columns( src))
    util_abort("%s: size mismatch. \n",__func__);

  {
    int target_col = 0;
    int src_col;
    for (src_col = 0; src_col < bool_vector_size( mask ); src_col++) {
      if (bool_vector_iget( mask , src_col)) {
        matrix_copy_column( target , src , target_col , src_col);
        target_col++;
      }
    }
  }
}
Example #5
0
void bootstrap_enkf_updateA(void * module_data ,
                            matrix_type * A ,
                            matrix_type * S ,
                            matrix_type * R ,
                            matrix_type * dObs ,
                            matrix_type * E ,
                            matrix_type * D ) {

    bootstrap_enkf_data_type * bootstrap_data = bootstrap_enkf_data_safe_cast( module_data );
    {
        const int num_cpu_threads = 4;
        int ens_size              = matrix_get_columns( A );
        matrix_type * X           = matrix_alloc( ens_size , ens_size );
        matrix_type * A0          = matrix_alloc_copy( A );
        matrix_type * S_resampled = matrix_alloc_copy( S );
        matrix_type * A_resampled = matrix_alloc( matrix_get_rows(A0) , matrix_get_columns( A0 ));
        int ** iens_resample      = alloc_iens_resample( bootstrap_data->rng , ens_size );
        {
            int ensemble_members_loop;
            for ( ensemble_members_loop = 0; ensemble_members_loop < ens_size; ensemble_members_loop++) {
                int unique_bootstrap_components;
                int ensemble_counter;
                /* Resample A and meas_data. Here we are careful to resample the working copy.*/
                {
                    {
                        int_vector_type * bootstrap_components = int_vector_alloc( ens_size , 0);
                        for (ensemble_counter  = 0; ensemble_counter < ens_size; ensemble_counter++) {
                            int random_column = iens_resample[ ensemble_members_loop][ensemble_counter];
                            int_vector_iset( bootstrap_components , ensemble_counter , random_column );
                            matrix_copy_column( A_resampled , A0 , ensemble_counter , random_column );
                            matrix_copy_column( S_resampled , S  , ensemble_counter , random_column );
                        }
                        int_vector_select_unique( bootstrap_components );
                        unique_bootstrap_components = int_vector_size( bootstrap_components );
                        int_vector_free( bootstrap_components );
                    }

                    if (bootstrap_data->doCV) {
                        const bool_vector_type * ens_mask = NULL;
                        cv_enkf_init_update( bootstrap_data->cv_enkf_data , ens_mask , S_resampled , R , dObs , E , D);
                        cv_enkf_initX( bootstrap_data->cv_enkf_data , X , A_resampled , S_resampled , R , dObs , E , D);
                    } else
                        std_enkf_initX(bootstrap_data->std_enkf_data , X , NULL , S_resampled,R, dObs, E,D );


                    matrix_inplace_matmul_mt1( A_resampled , X , num_cpu_threads );
                    matrix_inplace_add( A_resampled , A0 );
                    matrix_copy_column( A , A_resampled, ensemble_members_loop, ensemble_members_loop);

                }
            }
        }


        free_iens_resample( iens_resample , ens_size);
        matrix_free( X );
        matrix_free( S_resampled );
        matrix_free( A_resampled );
        matrix_free( A0 );
    }
}