<p>For what it's worth, this problem is encountered with other mlpack algorithms: sometimes the user wants to do, e.g., nearest neighbor search and save the model, but they can use different types of trees, and the trees are template parameters.</p>

<p>What I've done in those situations is to create a "wrapper" class that serializes an identifier saying what type is being used, then serializing the appropriate type.  Take a look here:</p>

<p><a href="https://github.com/mlpack/mlpack/blob/master/src/mlpack/methods/neighbor_search/ns_model_impl.hpp#L52">https://github.com/mlpack/mlpack/blob/master/src/mlpack/methods/neighbor_search/ns_model_impl.hpp#L52</a></p>

<p>For the situation of an arbitrary neural network architecture, the problem is a lot harder: you need some way to serialize the type information, and then some way to assemble an arbitrary type and return it when deserializing.  I think it will be a tricky (but fun) problem to solve... :)</p>

<p>The approach I've taken, in general, towards serializing arbitrary types is this: "if using an mlpack command-line program, the type should be handled for the user; if using the mlpack C++ code, then the user is responsible for serializing and deserializing the correct type".  So if the user uses the <code>mlpack_allknn</code> program, then the <code>NSModel</code> class is transparently used to serialize the correct type.  If the user is writing C++, then they can use the <code>NSModel</code> class if they want, but whatever they choose to do, they will have to remember to deserialize their model into the correct type.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/mlpack/mlpack/issues/531#issuecomment-190758563">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFARALvy1Wa-UhSiNA48o9s3IBt_Zks5ppFWdgaJpZM4HmbCC.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/mlpack/mlpack/issues/531#issuecomment-190758563"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>