POV-Ray : Newsgroups : povray.text.scene-files : [Minimum Volume] Bounding Ellipsoid via SVD : Re: [Minimum Volume] Bounding Ellipsoid via SVD Server Time
16 Apr 2024 03:37:24 EDT (-0400)
  Re: [Minimum Volume] Bounding Ellipsoid via SVD  
From: jr
Date: 18 Nov 2019 08:45:00
Message: <web.5dd29f35f7b9a3affeeb22ff0@news.povray.org>
hi,

"Bald Eagle" <cre### [at] netscapenet> wrote:
> "jr" <cre### [at] gmailcom> wrote:
> > please post a data file.
> done.
> ...
> 400 x 3 matrix.   A "vector" data type that uses 400 povray vectors split up
> into x, y, and z values.
hi,

some small progress.  I shortened the data to ten rows, prefixed by cols + rows,
run it with:
  $ tr ' ' '\n' < be-vectors | svd


3 10
0.0883597 -0.326943 -0.337204
-0.405332 0.103699 0.242547
0.421881 0.0228523 -0.10112
0.432184 0.124463 -0.081805
-0.397722 -0.42712 0.00183197
0.176067 -0.254352 -0.364851
-0.0141579 0.454459 -0.317524
0.354473 0.731663 -0.0403544
0.188762 -0.165013 0.215763
0.267797 0.895557 -0.10793


the "bugbear" is that the code expects to see square matrices.  the following
modifications get me to the point where 'svd()' is called in main; I think the
transpose_matrix is next in need of .. attention.


int main(int argc, char* argv[]) {
  std::size_t mncols = 0,
              mnrows = 0;
  std::vector<std::vector<cpp_bin_float_4096> > u, v;
  std::vector<std::vector<cpp_bin_float_4096> > matrix, s;
  std::cout << "Singular Value Decomposition (SVD):\n";

  std::cin >> mncols;  std::cout << "number columns: " << mncols << ".\n";
  std::cin >> mnrows;  std::cout << "number rows: " << mnrows << ".\n";

  if (mnrows <= 500)
  {
    generate_matrix(matrix, mnrows, mncols);
    std::cout << "\nA = \n"; print_matrix(matrix);
    svd(matrix, s, u, v);
    std::cout << "\nS = \n"; print_matrix(s);
    std::cout << "\nU = \n"; print_matrix(u);
    std::cout << "\nV = \n"; print_matrix(v);
  }
  else std::cout << "Wrong matrix size... (matrix decomposition recommended)";

  return 0;
}


template<typename Arg = cpp_bin_float_4096>
void print_matrix(std::vector<std::vector<cpp_bin_float_4096> >  matrix)
{
  for (std::size_t row = 0; row < matrix.size(); row++)
  {
    for (std::size_t col = 0; col < matrix[row].size(); col++)
      std::cout << std::setprecision(1) << std::fixed << matrix[row][col]
              << " "; std::cout << "\n";
  }

//  std::cout << "\n";
}

compare this to the previous, wrt loop (counter) limit.  I suspect all functions
dealing with matrices will need similar change(s).


template<typename Arg = cpp_bin_float_4096>
void generate_matrix(std::vector<std::vector<cpp_bin_float_4096> >& \
  matrix, std::size_t rows, std::size_t cols)
{
  std::srand((unsigned int)std::time(nullptr)); matrix.resize(rows);
  for (std::size_t row = 0; row < matrix.size(); row++)
  {
    matrix[row].resize(cols);
    for (std::size_t col = 0; col < matrix[row].size(); col++)
      std::cin >> matrix[row][col];
  }
}


regards, jr.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.