本文整理汇总了C++中vcl_vector::end方法的典型用法代码示例。如果您正苦于以下问题:C++ vcl_vector::end方法的具体用法?C++ vcl_vector::end怎么用?C++ vcl_vector::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vcl_vector
的用法示例。
在下文中一共展示了vcl_vector::end方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: transition_matrix
bool rgrsn_ldp::transition_matrix(const vcl_vector<int> & fns,
const vcl_vector<double> & values,
vnl_matrix<double> & transition,
const double resolution)
{
assert(fns.size() == values.size());
double min_v = *vcl_min_element(values.begin(), values.end());
double max_v = *vcl_max_element(values.begin(), values.end());
unsigned num_bin = (max_v - min_v)/resolution;
transition = vnl_matrix<double>(num_bin, num_bin, 0.0);
vnl_vector<double> column(num_bin, 0.0);
for (int i = 0; i<fns.size()-1; i++) {
if (fns[i] + 1 == fns[i+1]) {
double cur_v = values[i];
double next_v = values[i+1];
unsigned cur_bin = value_to_bin_number(min_v, resolution, cur_v, num_bin);
unsigned next_bin = value_to_bin_number(min_v, resolution, next_v, num_bin);
transition[next_bin][cur_bin] += 1.0;
column[cur_bin] += 1.0;
}
}
// normalize each column
for (int r = 0; r < transition.rows(); r++) {
for (int c = 0; c < transition.cols(); c++) {
transition[r][c] /= column[c];
}
}
return true;
}
示例2: compact_transition_matrix
bool rgrsn_ldp::compact_transition_matrix(const vcl_vector<int> & fns,
const vcl_vector<double> & values,
vnl_matrix<double> & transition,
const double resolution)
{
assert(fns.size() == values.size());
double min_v = *vcl_min_element(values.begin(), values.end());
double max_v = *vcl_max_element(values.begin(), values.end());
unsigned num_bin = (max_v - min_v)/resolution;
unsigned max_bin_transition = 0; // biggest transition between frames quantized in bin
for (int i = 0; i<fns.size(); i++) {
if (fns[i] + 1 == fns[i+1]) {
double cur_v = values[i];
double next_v = values[i+1];
int cur_bin = value_to_bin_number(min_v, resolution, cur_v, num_bin);
int next_bin = value_to_bin_number(min_v, resolution, next_v, num_bin);
int dif = abs(next_bin - cur_bin);
if (dif > max_bin_transition) {
max_bin_transition = dif;
}
}
}
transition = vnl_matrix<double>(max_bin_transition * 2 + 1, num_bin, 0.0);
vnl_vector<double> column(num_bin, 0.0);
for (int i = 0; i<fns.size()-1; i++) {
if (fns[i] + 1 == fns[i+1]) {
double cur_v = values[i];
double next_v = values[i+1];
int cur_bin = value_to_bin_number(min_v, resolution, cur_v, num_bin);
int next_bin = value_to_bin_number(min_v, resolution, next_v, num_bin);
int row = max_bin_transition + (next_bin - cur_bin);
transition[row][cur_bin] += 1.0;
column[cur_bin] += 1.0;
}
}
// normalize each column
for (int r = 0; r < transition.rows(); r++) {
for (int c = 0; c < transition.cols(); c++) {
// transition[r][c] /= column[c];
}
}
return true;
}
示例3: local_dynamic_programming_log
bool rgrsn_ldp::local_dynamic_programming_log(const vnl_matrix<double> & probMap, int nNeighborBin,
vcl_vector<int> & optimalBins)
{
// find minimum path
const int N = probMap.rows();
const int nBin = probMap.cols();
const double epsilon = 0.01;
vnl_matrix<double> negLogProbMap(N, nBin);
for (int r = 0; r<N; r++) {
for (int c = 0; c <nBin; c++) {
negLogProbMap(r, c) = -log(probMap(r, c) + epsilon);
}
}
// dynamic programming
vnl_matrix<double> accumulatedMap = vnl_matrix<double>(N, nBin);
accumulatedMap.fill(0.0);
vnl_matrix<int> lookbackTable = vnl_matrix<int>(N, nBin);
lookbackTable.fill(0);
// copy first row
for (int c = 0; c<negLogProbMap.cols(); c++) {
accumulatedMap[0][c] = negLogProbMap[0][c];
}
for (int r = 1; r <N; r++) {
for (int c = 0; c<negLogProbMap.cols(); c++) {
// lookup all possible place in the window
double min_val = INT_MAX;
int index = -1;
for (int w = -nNeighborBin; w <= nNeighborBin; w++) {
if (c + w <0 || c + w >= negLogProbMap.cols()) {
continue;
}
double val = negLogProbMap[r][c] + accumulatedMap[r-1][c+w];
if (val < min_val) {
min_val = val;
index = c + w;
}
}
assert(index != -1);
accumulatedMap[r][c] = min_val;
lookbackTable[r][c] = index;
}
}
// lookback the table
double min_val = INT_MAX;
int initIndex = -1;
for (int c = 0; c<accumulatedMap.cols(); c++) {
if (accumulatedMap[N-1][c] < min_val) {
min_val = accumulatedMap[N-1][c];
initIndex = c;
}
}
// back track
optimalBins.push_back(initIndex);
for (int r = N-1; r > 0; r--) {
int bin = lookbackTable[r][optimalBins.back()];
optimalBins.push_back(bin);
}
assert(optimalBins.size() == N);
vcl_reverse(optimalBins.begin(), optimalBins.end());
return true;
}
示例4: viterbi
bool rgrsn_ldp::viterbi(const vnl_matrix<double> & prob_map, const vnl_vector<double> & transition,
vcl_vector<int> & optimal_bins)
{
const int N = prob_map.rows();
const int nBin = prob_map.cols();
const int nNeighborBin = transition.size()/2;
const double epsilon = 0.01;
// dynamic programming
vnl_matrix<double> log_accumulatedProbMap = vnl_matrix<double>(N, nBin);
log_accumulatedProbMap.fill(0.0);
vnl_matrix<int> lookbackTable = vnl_matrix<int>(N, nBin);
lookbackTable.fill(0);
// copy first row
for (int c = 0; c<prob_map.cols(); c++) {
log_accumulatedProbMap[0][c] = log(prob_map[0][c] + epsilon);
lookbackTable[0][c] = c;
}
vnl_vector<double> log_transition = vnl_vector<double>(transition.size(), 0);
for (int i = 0; i<transition.size(); i++) {
log_transition[i] = log(transition[i] + epsilon);
}
for (int r = 1; r <N; r++) {
for (int c = 0; c<prob_map.cols(); c++) {
// lookup all possible place in the window
double max_val = vcl_numeric_limits<int>::min();
int max_index = -1;
for (int w = -nNeighborBin; w <= nNeighborBin; w++) {
if (c + w < 0 || c + w >= prob_map.cols()) {
continue;
}
assert(w + nNeighborBin >= 0 && w + nNeighborBin < transition.size());
double val = log_accumulatedProbMap[r-1][c+w] + log_transition[w + nNeighborBin];
if (val > max_val) {
max_val = val;
max_index = c + w; // most probable path from the [r-1] row, in column c + w
}
}
assert(max_index != -1);
log_accumulatedProbMap[r][c] = max_val + log(prob_map[r][c] + epsilon);
lookbackTable[r][c] = max_index;
}
}
// lookback the table
double max_prob = vcl_numeric_limits<int>::min();
int max_prob_index = -1;
for (int c = 0; c<log_accumulatedProbMap.cols(); c++) {
if (log_accumulatedProbMap[N-1][c] > max_prob) {
max_prob = log_accumulatedProbMap[N-1][c];
max_prob_index = c;
}
}
// back track
optimal_bins.push_back(max_prob_index);
for (int r = N-1; r > 0; r--) {
int bin = lookbackTable[r][optimal_bins.back()];
optimal_bins.push_back(bin);
}
assert(optimal_bins.size() == N);
vcl_reverse(optimal_bins.begin(), optimal_bins.end());
return true;
}