Search code examples
c++mlpack

Installation of mlpack on Ubuntu 22.04


I have performed a mlpack installation using the OS version of package manager (Ubuntu 22.04):

sudo apt install libmlpack-dev mlpack-bin libarmadillo-dev

Now I am trying to compile a simple program. However no file mlpack.hpp was installed in my system. There exists a folder usr/include/mlpack but it does not contain the required header. In quickstart nor in installation guide there is no information that this file should be installed/downloaded separately. How to make it compile? Where do I take this file from?

The code from the mlpack website I am trying to compile:


#include <iostream>
#include <mlpack.hpp>

using namespace mlpack;

int main()
{
  // Load the data from data.csv (hard-coded).  Use CLI for simple command-line
  // parameter handling.
  arma::mat data("0.339406815,0.843176636,0.472701471; \
                  0.212587646,0.351174901,0.81056695;  \
                  0.160147626,0.255047893,0.04072469;  \
                  0.564535197,0.943435462,0.597070812");
  data = data.t();

  // Use templates to specify that we want a NeighborSearch object which uses
  // the Manhattan distance.
  NeighborSearch<NearestNeighborSort, ManhattanDistance> nn(data);

  // Create the object we will store the nearest neighbors in.
  arma::Mat<size_t> neighbors;
  arma::mat distances; // We need to store the distance too.

  // Compute the neighbors.
  nn.Search(1, neighbors, distances);

  // Write each neighbor and distance using Log.
  for (size_t i = 0; i < neighbors.n_elem; ++i)
  {
    std::cout << "Nearest neighbor of point " << i << " is point "
        << neighbors[i] << " and the distance is " << distances[i] << "." << std::endl;
  }

  return 0;
}

Solution

  • Note that mlpack.hpp is directly in /usr/include so that one does not need any further -I... switches. I can compile your question just fine on Ubuntu 23.04 with the mlpack 4.0.1 release I use there:

    $ g++ -o question question.cpp
    $ ./question 
    Nearest neighbor of point 0 is point 3 and the distance is 0.449757.
    Nearest neighbor of point 1 is point 2 and the distance is 0.918409.
    Nearest neighbor of point 2 is point 1 and the distance is 0.918409.
    Nearest neighbor of point 3 is point 0 and the distance is 0.449757.
    $ 
    

    As for the narrower 'where is mlpack.hpp question, you can also ask Debian / Ubuntu:

    $ dpkg -S mlpack.hpp
    libmlpack-dev:amd64: /usr/include/mlpack.hpp
    $ 
    

    PS Per the comment, the screenshot of my PPA with the updated packages:

    enter image description here