Esempio n. 1
0
double State::transition_row_partition_assignments(const MatrixD& data,
        vector<int> which_rows) {
    vector<int> global_column_indices = create_sequence(data.size2());
    double score_delta = 0;
    //
    int num_rows = which_rows.size();
    if (num_rows == 0) {
        num_rows = data.size1();
        which_rows = create_sequence(num_rows);
        //FIXME: use own shuffle so seed control is in effect
        std::random_shuffle(which_rows.begin(), which_rows.end());
    }
    set<View*>::iterator svp_it;
    for (svp_it = views.begin(); svp_it != views.end(); svp_it++) {
        // for each view
        View& v = **svp_it;
        vector<int> view_cols = get_indices_to_reorder(global_column_indices,
                                v.global_to_local);
        const MatrixD data_subset = extract_columns(data, view_cols);
        map<int, vector<double> > row_data_map = construct_data_map(data_subset);
        vector<int>::iterator vi_it;
        for (vi_it = which_rows.begin(); vi_it != which_rows.end(); vi_it++) {
            // for each SPECIFIED row
            int row_idx = *vi_it;
            vector<double> vd = row_data_map[row_idx];
            score_delta += v.transition_z(vd, row_idx);
        }
    }
    data_score += score_delta;
    return score_delta;
}
Esempio n. 2
0
map<int, vector<double> > construct_data_map(const MatrixD data) {
  unsigned int num_rows = data.size1();
  map<int, vector<double> > data_map;
  for(unsigned int row_idx=0; row_idx<num_rows; row_idx++) {
    data_map[row_idx] = extract_row(data, row_idx);
  }
  return data_map;
}
Esempio n. 3
0
MatrixD extract_columns(const MatrixD fromM, vector<int> from_cols) {
  int num_rows = fromM.size1();
  int num_cols = from_cols.size();
  MatrixD toM(num_rows, num_cols);
  for(int to_col=0; to_col<num_cols; to_col++) {
    int from_col = from_cols[to_col];
    copy_column(fromM, from_col, toM, to_col);
  }
  return toM;
}
Esempio n. 4
0
void State::construct_base_hyper_grids(const MatrixD& data, int N_GRID,
        vector<double> ROW_CRP_ALPHA_GRID,
        vector<double> COLUMN_CRP_ALPHA_GRID) {
    int num_rows = data.size1();
    int num_cols = data.size2();
    if (ROW_CRP_ALPHA_GRID.size() == 0) {
        ROW_CRP_ALPHA_GRID = create_crp_alpha_grid(num_rows, N_GRID);
    }
    if (COLUMN_CRP_ALPHA_GRID.size() == 0) {
        COLUMN_CRP_ALPHA_GRID = create_crp_alpha_grid(num_cols, N_GRID);
    }
    row_crp_alpha_grid = ROW_CRP_ALPHA_GRID;
    column_crp_alpha_grid = COLUMN_CRP_ALPHA_GRID;
    construct_cyclic_base_hyper_grids(N_GRID, num_rows, vm_b_grid);
    construct_continuous_base_hyper_grids(N_GRID, num_rows, r_grid, nu_grid);
    construct_multinomial_base_hyper_grids(N_GRID, num_rows,
                                           multinomial_alpha_grid);
}
Esempio n. 5
0
void copy_column(const MatrixD fromM, int from_col, MatrixD &toM, int to_col) {
  assert(fromM.size1()==toM.size1());
  int num_rows = fromM.size1();
  project(toM, boost::numeric::ublas::range(0, num_rows), boost::numeric::ublas::range(to_col, to_col+1)) = \
    project(fromM, boost::numeric::ublas::range(0, num_rows), boost::numeric::ublas::range(from_col, from_col+1));
}