本文整理汇总了C++中vnl_matrix::rows方法的典型用法代码示例。如果您正苦于以下问题:C++ vnl_matrix::rows方法的具体用法?C++ vnl_matrix::rows怎么用?C++ vnl_matrix::rows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vnl_matrix
的用法示例。
在下文中一共展示了vnl_matrix::rows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
vnl_matrix <double> Normalize_Feature_Matrix(vnl_matrix<double> feats)
{
mbl_stats_nd stats;
for(int i = 0; i<feats.rows() ; ++i)
{
vnl_vector<double> temp_row = feats.get_row(i);
stats.obs(temp_row);
}
vnl_vector<double> std_vec = stats.sd();
vnl_vector<double> mean_vec = stats.mean();
for(int i = 0; i<feats.columns()-3 ; ++i)
{
vnl_vector<double> temp_col = feats.get_column(i);
if(std_vec(i) > 0)
{
for(int j =0; j<temp_col.size() ; ++j)
temp_col[j] = (temp_col[j] - mean_vec(i))/std_vec(i) ;
}
feats.set_column(i,temp_col);
}
return feats;
}
示例2: local_dynamic_programming
bool rgrsn_ldp::local_dynamic_programming(const vnl_matrix<double> & probMap, int nNeighborBin,
vcl_vector<int> & optimalBins)
{
const int N = probMap.rows();
const int nBin = probMap.cols();
// dynamic programming
vnl_matrix<double> accumulatedProbMap = vnl_matrix<double>(N, nBin);
accumulatedProbMap.fill(0.0);
vnl_matrix<int> lookbackTable = vnl_matrix<int>(N, nBin);
lookbackTable.fill(0);
// copy first row
for (int c = 0; c<probMap.cols(); c++) {
accumulatedProbMap[0][c] = probMap[0][c];
lookbackTable[0][c] = c;
}
for (int r = 1; r <N; r++) {
for (int c = 0; c<probMap.cols(); c++) {
// lookup all possible place in the window
double max_val = -1;
int max_index = -1;
for (int w = -nNeighborBin; w <= nNeighborBin; w++) {
if (c + w <0 || c + w >= probMap.cols()) {
continue;
}
double val = probMap[r][c] + accumulatedProbMap[r-1][c+w];
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);
accumulatedProbMap[r][c] = max_val;
lookbackTable[r][c] = max_index;
}
}
// lookback the table
double max_prob = -1.0;
int max_prob_index = -1;
for (int c = 0; c<accumulatedProbMap.cols(); c++) {
if (accumulatedProbMap[N-1][c] > max_prob) {
max_prob = accumulatedProbMap[N-1][c];
max_prob_index = c;
}
}
// back track
optimalBins.push_back(max_prob_index);
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;
}
示例3: denormalize
void denormalize(vnl_matrix<double>& x, const vnl_vector<double>& centroid, const double scale) {
int n = x.rows();
if (n==0) return;
int d = x.cols();
for (int i = 0; i < n; ++i) {
x.set_row(i, x.get_row(i) * scale + centroid);
}
}
示例4: Vectorize
//std::vector<double> Vectorize(const vnl_matrix<double> &M)
vnl_vector<double> Vectorize(const vnl_matrix<double> &M)
{
//std::vector<double> V;
vnl_vector<double> V(M.rows() * M.columns());
for (unsigned j = 0; j < M.rows(); j++)
{
for (unsigned i = 0; i < M.columns(); i++)
{
//V.push_back(M(i,j));
V[M.columns() * j + i] = M(i,j);
}
}
return V;
}
示例5: compute_P
void compute_P(const vnl_matrix<double>& x,const vnl_matrix<double>& y, vnl_matrix<double>& P, double &E, double sigma, int outliers) {
double k;
k = -2*sigma*sigma;
//P.set_size(m,n); P.fill(0);
//vnl_vector<double> v_ij;
vnl_vector<double> column_sum;
int m = x.rows();
int s = y.rows();
int d = x.cols();
column_sum.set_size(s);
column_sum.fill(0);
double outlier_term = outliers*pow((2*sigma*sigma*3.1415926),0.5*d);
for (int i = 0; i < m; ++i) {
for (int j = 0; j < s; ++j) {
double r = 0;
for (int t = 0; t < d; ++t) {
r += (x(i,t) - y(j,t))*(x(i,t) - y(j,t));
}
P(i,j) = exp(r/k);
column_sum[j]+=P(i,j);
}
}
if (outliers!=0) {
for (int i = 0; i < s; ++i)
column_sum[i] += outlier_term;
}
if (column_sum.min_value()>(1e-12)) {
E = 0;
for (int i = 0; i < s; ++i) {
for (int j = 0; j < m; ++j){
P(j,i) = P(j,i)/column_sum[i];
}
E -= log(column_sum[i]);
}
//vcl_cerr< < s;
//vcl_cerr<<P.get_column(10);
}
else {
P.empty();
}
}
示例6: normalize_same
void normalize_same(vnl_matrix<double>& x,
vnl_vector<double>& centroid, double& scale) {
int n = x.rows();
if (n==0) return;
int d = x.cols();
for (int i = 0; i < n; ++i) {
x.set_row(i, (x.get_row(i) - centroid) / scale);
}
}
示例7: search
void vnl_flann::search(const vnl_matrix<double> & query_data,
vcl_vector<vcl_vector<int> > & indices,
vcl_vector<vcl_vector<double> > & dists, int knn) const
{
const int dim = (int)query_data.cols();
assert(dim == dim_);
Matrix<double> query_data_wrap((double *)query_data.data_block(), (int)query_data.rows(), dim);
index_.knnSearch(query_data_wrap, indices, dists, knn, flann::SearchParams(128));
}
示例8: dynamic_programming
bool rgrsn_ldp::dynamic_programming(const vnl_matrix<double> & data, double v_min, double v_max,
unsigned int nBin, int nJumpBin, unsigned int windowSize,
vnl_vector<double> & optimalSignal)
{
assert(v_min < v_max);
// raw data to probability map
const int N = data.rows();
vnl_matrix<double> probMap = vnl_matrix<double>(N, nBin);
double interval = (v_max - v_min)/nBin;
for (int r = 0; r<N; r++) {
for (int c = 0; c<data.cols(); c++) {
int num = value_to_bin_number(v_min, interval, data[r][c], nBin);
probMap[r][num] += 1.0;
}
}
probMap /= data.cols(); // normalize
// save prob
{
// vnl_matlab_filewrite awriter("prob.mat");
// awriter.write(probMap, "prob");
// printf("save to prob.mat.\n");
}
vcl_vector<double> optimalValues(N, 0);
vcl_vector<int> numValues(N, 0); // multiple values from local dynamic programming
for (int i = 0; i<=N - windowSize; i++) {
// get a local probMap;
vnl_matrix<double> localProbMap = probMap.extract(windowSize, probMap.cols(), i, 0);
vcl_vector<int> localOptimalBins;
rgrsn_ldp::local_dynamic_programming(localProbMap, nJumpBin, localOptimalBins);
assert(localOptimalBins.size() == windowSize);
for (int j = 0; j < localOptimalBins.size(); j++) {
numValues[j + i] += 1;
optimalValues[j + i] += bin_number_to_value(v_min, interval, localOptimalBins[j]);
}
// test
if (0 && i == 0)
{
printf("test first window output\n");
for (int j = 0; j<optimalValues.size() && j<windowSize; j++) {
printf("%f ", optimalValues[j]);
}
printf("\n");
}
}
//
for (int i = 0; i<optimalValues.size(); i++) {
optimalValues[i] /= numValues[i];
}
optimalSignal = vnl_vector<double>(&optimalValues[0], (int)optimalValues.size());
return true;
}
示例9: Initialize
void LocalGeometryRef::Initialize(vnl_matrix<double> data)
{
this->num_row = data.rows();
this->num_col = data.columns();
this->data_matrix.set_size(this->num_row, this->num_col);
for(int row = 0; row < this->num_row; row++)
{
for(int col = 0; col < this->num_col; col++)
{
this->data_matrix(row, col) = data(row, col);
}
}
}
示例10: ComputeGaussianKernel
/*
Matlab code in cpd_G.m:
k=-2*beta^2;
[n, d]=size(x); [m, d]=size(y);
G=repmat(x,[1 1 m])-permute(repmat(y,[1 1 n]),[3 2 1]);
G=squeeze(sum(G.^2,2));
G=G/k;
G=exp(G);
*/
void ComputeGaussianKernel(const vnl_matrix<double>& model,
const vnl_matrix<double>& ctrl_pts,
vnl_matrix<double>& G, vnl_matrix<double>& K,
double lambda) {
int m,n,d;
m = model.rows();
n = ctrl_pts.rows();
d = ctrl_pts.cols();
//asssert(model.cols()==d);
//assert(lambda>0);
G.set_size(m,n);
GaussianAffinityMatrix(model.data_block(), ctrl_pts.data_block(),
m, n, d, lambda, G.data_block());
if (model == ctrl_pts) {
K = G;
} else {
K.set_size(n,n);
GaussianAffinityMatrix(ctrl_pts.data_block(), ctrl_pts.data_block(),
n, n, d, lambda, K.data_block());
}
}
示例11: ComputeTPSKernelU
void ComputeTPSKernelU(const vnl_matrix<double>& model,
const vnl_matrix<double>& ctrl_pts,
vnl_matrix<double>& U) {
int m = model.rows();
int n = ctrl_pts.rows();
int d = ctrl_pts.cols();
//asssert(model.cols()==d==(2|3));
//K.set_size(n, n);
//K.fill(0);
U.set_size(m, n);
U.fill(0);
double eps = 1e-006;
vnl_vector<double> v_ij;
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j)
{
v_ij = model.get_row(i) - ctrl_pts.get_row(j);
double r = v_ij.two_norm();
U(i, j) = -r;
}
}
}
示例12: mat
//Reshape the matrix : columns first ; Similar to MATLAB
vnl_matrix<double> MCLR_SM::Reshape_Matrix(vnl_matrix<double>mat,int r,int c )
{
if(mat.rows()*mat.cols() != r*c)
{
cout<< "Number of elements in the matrix/vector should be equal to the total number of elements in the reshaped matrix";
getchar();
exit(1);
}
vnl_matrix<double>reshaped_matrix;
reshaped_matrix.set_size(r,c);
int count = 0;
for(int j=0;j<c;++j)
{
for(int i=0;i<r;++i)
{
reshaped_matrix(i,j) = mat(count%mat.rows(),floor(static_cast<double>(count/mat.rows())));
count++;
}
}
return reshaped_matrix;
}
示例13: WriteMatrixImage
void WriteMatrixImage(const vnl_matrix<double> &M, const std::string &Filename)
{
vil_image_view<vxl_byte> Image(M.rows(), M.columns(), 1, 1); //(ni, nj, n_planes, n_interleaved_planes)
for (unsigned j = 0; j < Image.nj(); j++)
{
for (unsigned i = 0; i < Image.ni(); i++)
{
Image(i,j) = static_cast<vxl_byte>(255 * M(i,j));
}
}
vil_save(Image, Filename.c_str());
}
示例14: CloseEnough
bool CloseEnough(const vnl_matrix<double> &M1, const vnl_matrix<double> &M2, const double eps)
{
unsigned int NumRows = M1.rows();
unsigned int NumCols = M1.columns();
if((M2.rows() != NumRows) || (M2.columns() != NumCols))
{
std::cout << "Dimensions do not match!" << std::endl;
return false;
}
for(unsigned int r = 0; r < NumRows; r++)
{
for(unsigned int c = 0; c < NumCols; c++)
{
if(fabs(M1(r,c) - M2(r,c)) > eps)
{
std::cout << "Failed comparison: " << "M1: " << M1(r,c) << " M2: " << M2(r,c) << " diff: " << fabs(M1(r,c) - M2(r,c)) << std::endl;
return false;
}
}
}
return true;
}
示例15: local_viterbi
bool rgrsn_ldp::local_viterbi(const vnl_matrix<double> & data,
double resolution,
const vnl_vector<double> & transition,
unsigned int window_size,
vnl_vector<double> & optimal_signal)
{
assert(resolution > 0.0);
assert(transition.size()%2 == 1);
const double min_v = data.min_value();
const double max_v = data.max_value();
const int nBin = (max_v - min_v)/resolution;
// raw data to probability map
// quantilization
const int N = data.rows();
vnl_matrix<double> probMap = vnl_matrix<double>(N, nBin);
for (int r = 0; r<N; r++) {
for (int c = 0; c<data.cols(); c++) {
int num = value_to_bin_number(min_v, resolution, data[r][c], nBin);
probMap[r][num] += 1.0;
}
}
probMap /= data.cols(); // normalization
vcl_vector<double> optimalValues(N, 0);
vcl_vector<int> numValues(N, 0); // multiple values from local dynamic programming
for (int i = 0; i <= N - window_size; i++) {
// get a local probMap;
vnl_matrix<double> localProbMap = probMap.extract(window_size, probMap.cols(), i, 0);
vcl_vector<int> localOptimalBins;
rgrsn_ldp::viterbi(localProbMap, transition, localOptimalBins);
assert(localOptimalBins.size() == window_size);
for (int j = 0; j < localOptimalBins.size(); j++) {
double value = bin_number_to_value(min_v, resolution, localOptimalBins[j]);
numValues[j + i] += 1;
optimalValues[j + i] += value;
}
}
// average all optimal path as final result
for (int i = 0; i<optimalValues.size(); i++) {
optimalValues[i] /= numValues[i];
}
optimal_signal = vnl_vector<double>(&optimalValues[0], (int)optimalValues.size());
return true;
}