POV-Ray : Newsgroups : povray.text.scene-files : [Minimum Volume] Bounding Ellipsoid via SVD Server Time
2 May 2024 16:53:23 EDT (-0400)
  [Minimum Volume] Bounding Ellipsoid via SVD (Message 31 to 34 of 34)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Bald Eagle
Subject: Re: [Minimum Volume] Bounding Ellipsoid via SVD
Date: 17 Nov 2019 21:15:01
Message: <web.5dd1fe9ff7b9a3af4eec112d0@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:

> please post a data file.

done.

>  when you say "400", are you trying to run a 400x400
> matrix?  not sure but you *might* hit the limits -- the code's recursive, no?

400 x 3 matrix.   A "vector" data type that uses 400 povray vectors split up
into x, y, and z values.

So I just figured I'd read in the 400 first, size my array according to that,
and then just pipe the whole file into the compiled SVD processor.

Right now I just wanted to see if that worked, so I'm just gonna import the
data, and then print it back out to show that that part works, then copy that
working code into the SVD .cpp file.

This is mid-hack, so it's uglier than usual    ;)


#include <vector>
#include <iostream>
#include <iomanip>
#include <ctime>
#include <algorithm>


#include <boost/multiprecision/cpp_bin_float.hpp>
#include <boost/math/special_functions/gamma.hpp>

using namespace boost::multiprecision;

typedef number<backends::cpp_bin_float<4096, backends::digit_base_2, void,
boost::int16_t, -16382, 16383>, et_off>  cpp_bin_float_4096;

using namespace std;



std::vector<std::vector<cpp_bin_float_4096> > matrix_i;

template<typename Arg = cpp_bin_float_4096>
void print_matrix(std::vector<std::vector<cpp_bin_float_4096> > matrix)
{
    std::cout << "Printing matrix . . . \n\n";
 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";
}

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::cin >> rows;
 std::srand((unsigned int)std::time(nullptr)); matrix.resize(rows);
 for (std::size_t row = 0; row < matrix.size(); row++)
 {
  matrix[row].resize(3);
  for (std::size_t col = 0; col < 3; col++)
   //std::cin >> ignore(100, '\n') >> matrix[rows][cols];
            std::cin >> matrix[rows][cols];
 }
    std::cout << "Data imported. \n\n";
}




int main(int argc, char* argv[])
{
 std::size_t matrix_size = 0;
 std::vector<std::vector<cpp_bin_float_4096> > u, v;
 std::vector<std::vector<cpp_bin_float_4096> > matrix, s;
 std::cout << "Importing data into matrix . . . \n\n";


  generate_matrix(matrix, matrix_size, matrix_size);

  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);

 std::cin.get();
 //std::cin.get();

 return 0;
}


Post a reply to this message


Attachments:
Download 'vectors.dat.txt' (12 KB)

From: jr
Subject: Re: [Minimum Volume] Bounding Ellipsoid via SVD
Date: 17 Nov 2019 21:45:01
Message: <web.5dd204daf7b9a3affeeb22ff0@news.povray.org>
hi,

"Bald Eagle" <cre### [at] netscapenet> wrote:
> "jr" <cre### [at] gmailcom> wrote:
> > please post a data file.
> done.

cheers.

> >  when you say "400", are you trying to run a 400x400
> > matrix?  not sure but you *might* hit the limits -- the code's recursive, no?
>
> 400 x 3 matrix.   A "vector" data type that uses 400 povray vectors split up
> into x, y, and z values.
>
> So I just figured I'd read in the 400 first, size my array according to that,
> and then just pipe the whole file into the compiled SVD processor.
>
> Right now I just wanted to see if that worked, so I'm just gonna import the
> data, and then print it back out to show that that part works, then copy that
> working code into the SVD .cpp file.
>
> This is mid-hack, so it's uglier than usual    ;)

first glance -- I'd advise to supply both cols + rows as part of the matrix
data, rather than hardwiring the inner loop.

bedtime now, here.  hasta manana.


regards, jr.


Post a reply to this message

From: jr
Subject: Re: [Minimum Volume] Bounding Ellipsoid via SVD
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

From: Bald Eagle
Subject: Re: [Minimum Volume] Bounding Ellipsoid via SVD
Date: 18 Nov 2019 18:30:01
Message: <web.5dd32858f7b9a3af4eec112d0@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:

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

So just replace any spaces with a newline and pipe it to the svd script.

> the "bugbear" is that the code expects to see square matrices.

meh.  For the time being we can just create/resize all matrices with the
optional appending of ", 0)" like so:

inv_matrix[index].resize(matrix[index].size(), 0);

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

I'm not sure what the limit is, but I doubt that you or I would be using more
than 500 points just to do some orienting.  I think right now, just keep it
simple, and get a "flow" working so that we can integrate POV-Ray's .ini and
post-render capabilities so that an object can be "scanned", the vectors written
to disk, SVD can spit out an orientation matrix, and the scene can be re-run: at
which point it checks to see if a data file and/or matrix file has been written,
and then it just skips over to the part where it renders the oriented object.

I'll look it over and see what I can hammer out.   Busy day.
Thanks for the tips.   :)

Having fun with our new friend I see  ;)


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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