mirror of https://github.com/CGAL/cgal
Add function to copy random forest classifier
This commit is contained in:
parent
c0897c29bf
commit
7ac0eccbb9
|
|
@ -90,6 +90,26 @@ public:
|
|||
: m_labels (labels), m_features (features), m_rfc (NULL)
|
||||
{ }
|
||||
|
||||
/*!
|
||||
\brief Copies the `other` classifier's configuration using another
|
||||
set of `features`.
|
||||
|
||||
This constructor can be used to apply a trained random forest to
|
||||
another data set.
|
||||
|
||||
\warning The feature set should be composed of the same features
|
||||
than the ones used by `other`, and in the same order.
|
||||
|
||||
*/
|
||||
ETHZ_random_forest_classifier (const ETHZ_random_forest_classifier& other,
|
||||
const Feature_set& features)
|
||||
: m_labels (other.m_labels), m_features (features), m_rfc (NULL)
|
||||
{
|
||||
std::stringstream stream;
|
||||
other.save_configuration(stream);
|
||||
this->load_configuration(stream);
|
||||
}
|
||||
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
~ETHZ_random_forest_classifier ()
|
||||
{
|
||||
|
|
@ -267,7 +287,7 @@ public:
|
|||
The output file is written in an GZIP container that is readable
|
||||
by the `load_configuration()` method.
|
||||
*/
|
||||
void save_configuration (std::ostream& output)
|
||||
void save_configuration (std::ostream& output) const
|
||||
{
|
||||
boost::iostreams::filtering_ostream outs;
|
||||
outs.push(boost::iostreams::gzip_compressor());
|
||||
|
|
|
|||
|
|
@ -87,13 +87,18 @@ int main (int, char**)
|
|||
std::ifstream inf ("output_config.gz", std::ios::binary);
|
||||
classifier2.load_configuration(inf);
|
||||
|
||||
Classifier classifier3 (classifier, features);
|
||||
|
||||
std::vector<std::size_t> label_indices;
|
||||
std::vector<std::size_t> label_indices_2;
|
||||
std::vector<std::size_t> label_indices_3;
|
||||
|
||||
Classification::classify<CGAL::Sequential_tag> (points, labels, classifier, label_indices);
|
||||
Classification::classify<CGAL::Sequential_tag> (points, labels, classifier2, label_indices_2);
|
||||
Classification::classify<CGAL::Sequential_tag> (points, labels, classifier3, label_indices_3);
|
||||
|
||||
assert (label_indices == label_indices_2);
|
||||
|
||||
assert (label_indices == label_indices_3);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue