I just started to use Eigen Matrix algebra library and aim to create a similarity matrix of a dataset, suggestions?

I try to create a similarity matrix with eigen library on a dataset. I just read the csv file into eigen matrix but know as a matlab customer I am looking for something like bsxfun or something to define the distances between instances by Euclidean distance calculation.How can I get away with a solution or what sources, functions might help me ?


Assuming your samples are stored row-wise in a matrix D, then you can do:

VectorXd N = D.rowwise().squaredNorm();
MatrixXd S = N.replicate(1,n) + N.transpose().replicate(n,1);
S.noalias() -= 2. * D * D.transpose();
S = S.array().sqrt();

This exploits the fact that |x-y|²=x²+y²-2x'y. The noalias() statement is just an optimization to Eigen there is no risk of aliasing in this product, thus no temporary is needed. The .array() statement switches to the array world where all functions are applied coefficient-wise.

Need Your Help

PHP creating an array from form input fields

php html forms input name-attribute

I'm trying to create an array to store numbers and add them together.

3D Map for website

javascript html google-maps

I am trying to create a 3D map on a web page. Google Maps and Open Street Maps provide an API for using 2D maps. Are there any APIs available for 3D maps?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.