[mlpack-git] master: Add Serialize() to kernels; not yet tested. Also I didn't do the p-spectrum string kernel yet. (264ef97)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Fri Jul 10 18:59:28 EDT 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/4a97187bbba7ce8a6191b714949dd818ef0f37d2...e5905e62c15d1bcff21e6359b11efcd7ab6d7ca0
>---------------------------------------------------------------
commit 264ef974e976557ca6e09206747324c05ffa5cc7
Author: ryan <ryan at ratml.org>
Date: Fri Apr 17 14:24:12 2015 -0400
Add Serialize() to kernels; not yet tested.
Also I didn't do the p-spectrum string kernel yet.
>---------------------------------------------------------------
264ef974e976557ca6e09206747324c05ffa5cc7
src/mlpack/core/kernels/cosine_distance.hpp | 4 ++++
src/mlpack/core/kernels/epanechnikov_kernel.hpp | 6 ++++++
src/mlpack/core/kernels/epanechnikov_kernel_impl.hpp | 9 +++++++++
src/mlpack/core/kernels/example_kernel.hpp | 7 +++++++
src/mlpack/core/kernels/gaussian_kernel.hpp | 8 ++++++++
src/mlpack/core/kernels/hyperbolic_tangent_kernel.hpp | 8 ++++++++
src/mlpack/core/kernels/laplacian_kernel.hpp | 7 +++++++
src/mlpack/core/kernels/linear_kernel.hpp | 4 ++++
src/mlpack/core/kernels/polynomial_kernel.hpp | 8 ++++++++
src/mlpack/core/kernels/spherical_kernel.hpp | 8 ++++++++
src/mlpack/core/kernels/triangular_kernel.hpp | 7 +++++++
11 files changed, 76 insertions(+)
diff --git a/src/mlpack/core/kernels/cosine_distance.hpp b/src/mlpack/core/kernels/cosine_distance.hpp
index 77c8142..4014edc 100644
--- a/src/mlpack/core/kernels/cosine_distance.hpp
+++ b/src/mlpack/core/kernels/cosine_distance.hpp
@@ -44,6 +44,10 @@ class CosineDistance
convert << "CosineDistance [" << this << "]" << std::endl;
return convert.str();
}
+
+ //! Serialize the class (there's nothing to save).
+ template<typename Archive>
+ void Serialize(Archive& /* ar */, const unsigned int /* version */) const { }
};
//! Kernel traits for the cosine distance.
diff --git a/src/mlpack/core/kernels/epanechnikov_kernel.hpp b/src/mlpack/core/kernels/epanechnikov_kernel.hpp
index 4db40c6..83b03ed 100644
--- a/src/mlpack/core/kernels/epanechnikov_kernel.hpp
+++ b/src/mlpack/core/kernels/epanechnikov_kernel.hpp
@@ -70,6 +70,12 @@ class EpanechnikovKernel
*/
double Normalizer(const size_t dimension);
+ /**
+ * Serialize the kernel.
+ */
+ template<typename Archive>
+ void Serialize(Archive& ar, const unsigned int version);
+
//! Returns string representation of object.
std::string ToString() const;
diff --git a/src/mlpack/core/kernels/epanechnikov_kernel_impl.hpp b/src/mlpack/core/kernels/epanechnikov_kernel_impl.hpp
index bd40bb2..e38ccd8 100644
--- a/src/mlpack/core/kernels/epanechnikov_kernel_impl.hpp
+++ b/src/mlpack/core/kernels/epanechnikov_kernel_impl.hpp
@@ -70,6 +70,15 @@ double EpanechnikovKernel::ConvolutionIntegral(const VecTypeA& a,
}
}
+//! Serialize the kernel.
+template<typename Archive>
+void EpanechnikovKernel::Serialize(Archive& ar,
+ const unsigned int /* version */)
+{
+ ar & data::CreateNVP(bandwidth, "bandwidth");
+ ar & data::CreateNVP(inverseBandwidthSquared, "inverseBandwidthSquared");
+}
+
}; // namespace kernel
}; // namespace mlpack
diff --git a/src/mlpack/core/kernels/example_kernel.hpp b/src/mlpack/core/kernels/example_kernel.hpp
index 46380ea..c32b50b 100644
--- a/src/mlpack/core/kernels/example_kernel.hpp
+++ b/src/mlpack/core/kernels/example_kernel.hpp
@@ -105,6 +105,13 @@ class ExampleKernel
{ return 0; }
/**
+ * Serializes the kernel. In this case, the kernel has no members, so we do
+ * not need to do anything at all.
+ */
+ template<typename Archive>
+ void Serialize(Archive& /* ar */, const unsigned int /* version */) const { }
+
+ /**
* Returns a string for the kernel object; in this case, with only the memory
* address for the kernel. If your kernel has any members, your ToString()
* method should include those as neccessary as well.
diff --git a/src/mlpack/core/kernels/gaussian_kernel.hpp b/src/mlpack/core/kernels/gaussian_kernel.hpp
index 9e52638..b2220e7 100644
--- a/src/mlpack/core/kernels/gaussian_kernel.hpp
+++ b/src/mlpack/core/kernels/gaussian_kernel.hpp
@@ -115,6 +115,14 @@ class GaussianKernel
//! Get the precalculated constant.
double Gamma() const { return gamma; }
+ //! Serialize the kernel.
+ template<typename Archive>
+ void Serialize(Archive& ar, const unsigned int /* version */)
+ {
+ ar & data::CreateNVP(bandwidth, "bandwidth");
+ ar & data::CreateNVP(gamma, "gamma");
+ }
+
//! Convert object to string.
std::string ToString() const
{
diff --git a/src/mlpack/core/kernels/hyperbolic_tangent_kernel.hpp b/src/mlpack/core/kernels/hyperbolic_tangent_kernel.hpp
index 7ebd41c..98535f6 100644
--- a/src/mlpack/core/kernels/hyperbolic_tangent_kernel.hpp
+++ b/src/mlpack/core/kernels/hyperbolic_tangent_kernel.hpp
@@ -67,6 +67,14 @@ class HyperbolicTangentKernel
//! Modify offset for the kernel.
double& Offset() { return offset; }
+ //! Serialize the kernel.
+ template<typename Archive>
+ void Serialize(Archive& ar, const unsigned int /* version */)
+ {
+ ar & data::CreateNVP(scale, "scale");
+ ar & data::CreateNVP(offset, "offset");
+ }
+
//! Convert object to string.
std::string ToString() const
{
diff --git a/src/mlpack/core/kernels/laplacian_kernel.hpp b/src/mlpack/core/kernels/laplacian_kernel.hpp
index bb865ef..453ec0a 100644
--- a/src/mlpack/core/kernels/laplacian_kernel.hpp
+++ b/src/mlpack/core/kernels/laplacian_kernel.hpp
@@ -78,6 +78,13 @@ class LaplacianKernel
//! Modify the bandwidth.
double& Bandwidth() { return bandwidth; }
+ //! Serialize the kernel.
+ template<typename Archive>
+ void Serialize(Archive& ar, const unsigned int /* version */)
+ {
+ ar & data::CreateNVP(bandwidth, "bandwidth");
+ }
+
//! Return a string representation of the kernel.
std::string ToString() const
{
diff --git a/src/mlpack/core/kernels/linear_kernel.hpp b/src/mlpack/core/kernels/linear_kernel.hpp
index 26c098e..a829daf 100644
--- a/src/mlpack/core/kernels/linear_kernel.hpp
+++ b/src/mlpack/core/kernels/linear_kernel.hpp
@@ -50,6 +50,10 @@ class LinearKernel
return arma::dot(a, b);
}
+ //! Serialize the kernel (it has no members... do nothing).
+ template<typename Archive>
+ void Serialize(Archive& /* ar */, const unsigned int /* version */) const { }
+
//! Return a string representation of the kernel.
std::string ToString() const
{
diff --git a/src/mlpack/core/kernels/polynomial_kernel.hpp b/src/mlpack/core/kernels/polynomial_kernel.hpp
index b64f133..89805ca 100644
--- a/src/mlpack/core/kernels/polynomial_kernel.hpp
+++ b/src/mlpack/core/kernels/polynomial_kernel.hpp
@@ -62,6 +62,14 @@ class PolynomialKernel
//! Modify the offset of the dot product of the arguments.
double& Offset() { return offset; }
+ //! Serialize the kernel.
+ template<typename Archive>
+ void Serialize(Archive& ar, const unsigned int /* version */)
+ {
+ ar & data::CreateNVP(degree, "degree");
+ ar & data::CreateNVP(offset, "offset");
+ }
+
//! Return a string representation of the kernel.
std::string ToString() const
{
diff --git a/src/mlpack/core/kernels/spherical_kernel.hpp b/src/mlpack/core/kernels/spherical_kernel.hpp
index d8e04f8..c8b4763 100644
--- a/src/mlpack/core/kernels/spherical_kernel.hpp
+++ b/src/mlpack/core/kernels/spherical_kernel.hpp
@@ -96,6 +96,14 @@ class SphericalKernel
return (t <= bandwidth) ? 1.0 : 0.0;
}
+ //! Serialize the object.
+ template<typename Archive>
+ void Serialize(Archive& ar, const unsigned int /* version */)
+ {
+ ar & data::CreateNVP(bandwidth, "bandwidth");
+ ar & data::CreateNVP(bandwidthSquared, "bandwidthSquared");
+ }
+
//! Return a string representation of the kernel.
std::string ToString() const
{
diff --git a/src/mlpack/core/kernels/triangular_kernel.hpp b/src/mlpack/core/kernels/triangular_kernel.hpp
index 7b8020a..659a948 100644
--- a/src/mlpack/core/kernels/triangular_kernel.hpp
+++ b/src/mlpack/core/kernels/triangular_kernel.hpp
@@ -63,6 +63,13 @@ class TriangularKernel
//! Modify the bandwidth of the kernel.
double& Bandwidth() { return bandwidth; }
+ //! Serialize the kernel.
+ template<typename Archive>
+ void Serialize(Archive& ar, const unsigned int /* version */)
+ {
+ ar & data::CreateNVP(bandwidth, "bandwidth");
+ }
+
//! Return a string representation of the kernel.
std::string ToString() const
{
More information about the mlpack-git
mailing list