Added serialization support for the running_stats_decayed object.

This commit is contained in:
Davis King 2017-08-20 20:39:44 -04:00
parent dc45871a31
commit d009916e76
2 changed files with 62 additions and 0 deletions

View File

@ -723,6 +723,18 @@ namespace dlib
return std::sqrt(variance()); return std::sqrt(variance());
} }
template <typename U>
friend void serialize (
const running_stats_decayed<U>& item,
std::ostream& out
);
template <typename U>
friend void deserialize (
running_stats_decayed<U>& item,
std::istream& in
);
private: private:
T sum_x; T sum_x;
@ -731,6 +743,38 @@ namespace dlib
T forget; T forget;
}; };
template <typename T>
void serialize (
const running_stats_decayed<T>& item,
std::ostream& out
)
{
int version = 1;
serialize(version, out);
serialize(item.sum_x, out);
serialize(item.sum_xx, out);
serialize(item.n, out);
serialize(item.forget, out);
}
template <typename T>
void deserialize (
running_stats_decayed<T>& item,
std::istream& in
)
{
int version = 0;
deserialize(version, in);
if (version != 1)
throw dlib::serialization_error("Unexpected version number found while deserializing dlib::running_stats_decayed object.");
deserialize(item.sum_x, in);
deserialize(item.sum_xx, in);
deserialize(item.n, in);
deserialize(item.forget, in);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <

View File

@ -652,6 +652,24 @@ namespace dlib
}; };
template <typename T>
void serialize (
const running_stats_decayed<T>& item,
std::ostream& out
);
/*!
provides serialization support
!*/
template <typename T>
void deserialize (
running_stats_decayed<T>& item,
std::istream& in
);
/*!
provides serialization support
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <