[mlpack-git] [mlpack] Provide serialization for ann module (#495)

Ryan Curtin notifications at github.com
Sun Dec 13 20:58:49 EST 2015


There are a couple options here.  I ran into this problem when adding serialization support to trees.  First, you can either replace the references with pointers and then add a default constructor that initializes all the pointers to NULL, or, I think you can add `boost::serialization::access` as a friend class, and add a private constructor to build from the archive.

The basic problem, as I encountered it (and maybe this is a little bit different) is that a lot of the mlpack code was built with the assumption that the data matrices and other relevant information (like metrics or whatever) were owned by a higher level of the code.  This makes sense when the highest-level code is "load matrix, run method, save results", but as soon as loading and saving models needs to be supported, the problem gets a lot harder, and it needs to be possible for the method to own everything.

Here's an example of what I had to do to the NeighborSearch class to get serialization working, since it internally held a reference to the data matrices:
https://github.com/mlpack/mlpack/commit/60c81702c432014544351948c091d03deeef6985

I think rvalue references like you mentioned provide a reasonable solution here.  In most places I've done something like provide a const reference constructor that copies the given data, and a move constructor that allows the object to take ownership of what's passed (and therefore avoid the copy).  In this case it seems like making `FFN::outputLayer` into `OutputLayerType` instead of `OutputLayerType&` (just like `FFN::layerTypes` is of type `LayerTypes`), like you've suggested, might be the easiest solution.  @zoq's opinion will probably be more pertinent and useful here, but I thought I'd share my experiences from my (almost finished!) refactoring of all the mlpack methods. :)

---
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/issues/495#issuecomment-164321866
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20151213/f9ee00a2/attachment.html>


More information about the mlpack-git mailing list