





 
 




 
 


"jr" <cre### [at] gmailcom> wrote:
> after posting _that_ I remembered you mentioning your being new to Linux etc in
> another thread. so some more on command lines etc below. (I really feel old 
I was new 20 years ago, I just haven't been involved in administration of the
NMR computers or had the SGI O2 to play with for about a decade. So every
little bit helps, whether it's something I "know" or not.
> and can be just a set of data points, ie no "shape" required? powerful.
Correct. Data is data is data. It doesn't have to be geometric at all.
It could be correlating customer purchases with zip codes or what movie watchers
might also like to watch, or what their most likely preferred theatre snack is,
or just about anything that you can think of.
> > 2D data can be aligned so that the most elongated part is along one axis, and
> > the rest of the data perpendicular to that gets rotated to be in the cardinal
> > plane,
>
> interesting too but cannot visualise use cases. when (what kind of data) would
> you use that?
Just search "application of singular value decomposition to ...." and it goes
on and on and on....
> testing, testing.. :)
Yeah. I upped my test case to 400 points, switched over from the "narrow"
version to the "wide" version, found that all of that introduces some problems,
learned a bit more (logical in retrospect) about the resulting matrices, and now
am awaiting some replies from hopefully helpful experts On The Internet.
I used to write shell scripts, and do a bunch of regular expression stuff, but I
have to get back into that  time, energy, focus, round tuits allowing....
Good progress so far, just have to make it past the usual frustrating roadblocks
to reach the end....
Post a reply to this message


 
 




 
 


Just an interesting aside:
https://blogs.mathworks.com/cleve/2012/12/10/1976matrixsingularvaluedecompositionfilm/
Post a reply to this message


 
 




 
 


hi,
"Bald Eagle" <cre### [at] netscapenet> wrote:
> Just an interesting aside:
>
>
https://blogs.mathworks.com/cleve/2012/12/10/1976matrixsingularvaluedecompositionfilm/
thank you for this link. watching the film helped somewhat. (shades of Tron
:))
regards, jr.
Post a reply to this message


 
 




 
 


"jr" <cre### [at] gmailcom> wrote:
> thank you for this link. watching the film helped somewhat.
You, Sir, are hilarious.
That thing didn't help me a single bit. :D
Try this.
https://towardsdatascience.com/svd8c2f72e264f
There are dozens of other pretty decent summaries / explanations.
Now that I have a functional reorientation, I'm waiting on some feedback from
someone, anyone as to a last bit of the puzzle (unconnected to the present
application).
Also going to try to get some c++ code written, and then hopefully the SVD will
be able to be integrated into a easytouse POVRay workflow.
If THAT works, then I have some other ideas for what to try it on.
Post a reply to this message


 
 




 
 


So, since I don't code in c++, I'm kinda coding by imitation and trial and
error.
I get the current small bit of test code to compile, but when I run it with my
dataset: "400" followed by 1200 numbers "value\n"
#write (Output, NumPoints, "\n")
#write (Output, P[PonS].x, "\n")
#write (Output, P[PonS].y, "\n")
#write (Output, P[PonS].z, "\n")
I get a segmentation fault.
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


 
 




 
 


hi,
"Bald Eagle" <cre### [at] netscapenet> wrote:
> So, since I don't code in c++, I'm kinda coding by imitation and trial and
> error.
>
> I get the current small bit of test code to compile, but when I run it with my
> dataset: "400" followed by 1200 numbers "value\n"
>
> #write (Output, NumPoints, "\n")
> #write (Output, P[PonS].x, "\n")
> #write (Output, P[PonS].y, "\n")
> #write (Output, P[PonS].z, "\n")
>
> I get a segmentation fault.
> ...
please post a data file. 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?
I'll monkey my version + try the data, in coming days.
regards, jr.
Post a reply to this message


 
 




 
 


"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 midhack, 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)


 
 




 
 


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 midhack, 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


 
 




 
 


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' < bevectors  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


 
 




 
 


"jr" <cre### [at] gmailcom> wrote:
> some small progress. I shortened the data to ten rows, prefixed by cols + rows,
> run it with:
> $ tr ' ' '\n' < bevectors  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 POVRay's .ini and
postrender 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 rerun: 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


 
 




 

