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
// helper for cython
double State::transition_view_i(int which_view, const MatrixD& data) {
    vector<int> global_column_indices = create_sequence(data.size2());
    View& v = get_view(which_view);
    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> > data_subset_map = construct_data_map(data_subset);
    return v.transition(data_subset_map);
}
Esempio n. 3
0
double State::transition_views(const MatrixD& data) {
    vector<int> global_column_indices = create_sequence(data.size2());
    //
    double score_delta = 0;
    // ordering doesn't matter, don't need to shuffle
    for (int view_idx = 0; view_idx < get_num_views(); view_idx++) {
        View& v = get_view(view_idx);
        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> > data_subset_map = construct_data_map(data_subset);
        score_delta += v.transition(data_subset_map);
    }
    return score_delta;
}
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
double State::transition_features(const MatrixD &data, vector<int> which_features) {
    double score_delta = 0;
    int num_features = which_features.size();
    if(num_features==0) {
        which_features = create_sequence(data.size2());
        // FIXME: use seed to shuffle
        std::random_shuffle(which_features.begin(), which_features.end());
    }
    vector<int>::iterator it;
    for(it=which_features.begin(); it!=which_features.end(); it++) {
        int feature_idx = *it;
        vector<double> feature_data = extract_col(data, feature_idx);
        // kernel selection
        if(ct_kernel == 0) {
            score_delta += transition_feature_gibbs(feature_idx, feature_data);
        } else if(ct_kernel == 1) {
            score_delta += transition_feature_mh(feature_idx, feature_data);
        } else {
            printf("Invalid CT_KERNEL");
            assert(0==1);
        }
    }
    return score_delta;
}