Skip to content

Commit

Permalink
CMake: External mixmod
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Nov 22, 2023
1 parent 6e5d357 commit b2fd0c8
Showing 202 changed files with 63 additions and 57,771 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -33,6 +33,8 @@ if (NOT DEFINED OPENTURNS_PYTHON_MODULE_PATH)
set (OPENTURNS_PYTHON_MODULE_PATH ${OPENTURNS_PYTHON3_MODULE_PATH})
endif ()

find_package (Mixmod 3.24 REQUIRED)

if (NOT BUILD_SHARED_LIBS)
list ( APPEND OTMIXMOD_DEFINITIONS "-DOTMIXMOD_STATIC" )
endif ()
9 changes: 6 additions & 3 deletions lib/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

add_subdirectory ( mixmod )

ot_add_current_dir_to_include_dirs ()

ot_add_source_file ( MixtureClassifierFactory.cxx )
@@ -21,6 +18,12 @@ endif ()
set_target_properties ( otmixmod PROPERTIES VERSION ${LIB_VERSION} )
set_target_properties ( otmixmod PROPERTIES SOVERSION ${LIB_SOVERSION} )
target_link_libraries (otmixmod ${OPENTURNS_LIBRARY})

if (USE_EXTERNAL_MIXMOD)
target_include_directories(otmixmod PRIVATE ${MIXMOD_INCLUDE_DIRS})
target_link_libraries (otmixmod ${MIXMOD_LIBRARIES})
endif ()

set_target_properties (otmixmod PROPERTIES UNITY_BUILD OFF)

# Add targets to the build-tree export set
54 changes: 31 additions & 23 deletions lib/src/MixtureFactory.cxx
Original file line number Diff line number Diff line change
@@ -27,11 +27,18 @@
#include <openturns/Path.hxx>
#include <openturns/Os.hxx>

#include "XEMGaussianData.h"
#include "XEMClusteringInput.h"
#include "XEMClusteringOutput.h"
#include "XEMClusteringMain.h"
#include "XEMGaussianEDDAParameter.h"
#include "GaussianData.h"
#include "ClusteringInput.h"
#include "ClusteringOutput.h"
#include "ClusteringMain.h"
#include "GaussianEDDAParameter.h"
#include "ParameterDescription.h"
#include "ClusteringModelOutput.h"
#include "mixmod/Matrix/Matrix.h"
#include "LabelDescription.h"
#include "Label.h"
#include "mixmod/Kernel/Model/Model.h"
#include "mixmod/Utilities/Random.h"

namespace OTMIXMOD
{
@@ -44,6 +51,7 @@ MixtureFactory::MixtureFactory () :
atomsNumber_ (0)
{
setCovarianceModel("Gaussian_pk_Lk_C");
setSeed(0);
}

/* Parameters constructor */
@@ -100,33 +108,33 @@ OT::Mixture MixtureFactory::buildAsMixture(const OT::Sample & sample,
for (OT::UnsignedInteger j = 0; j < dimension; ++j)
matrix[i][j] = sample[i][j];

XEMGaussianData * gaussianData = new XEMGaussianData(sampleSize, dimension, matrix);
XEM::GaussianData * gaussianData = new XEM::GaussianData(sampleSize, dimension, matrix);
for (OT::UnsignedInteger i = 0; i < sampleSize; ++i) delete [] matrix[i];
delete [] matrix;

// Create a Mixmod description
XEMDataDescription dataDescription(gaussianData);
XEM::DataDescription dataDescription(gaussianData);
vector<int64_t> nbCluster;
nbCluster.push_back(atomsNumber_);

// Prepare Mixmod for clustering
XEMClusteringInput * clusteringInput(new XEMClusteringInput(nbCluster, dataDescription));
XEMModelType modelType(StringToXEMModelName(covarianceModel_));
XEM::ClusteringInput * clusteringInput(new XEM::ClusteringInput(nbCluster, dataDescription));
XEM::ModelType modelType(XEM::StringToModelName(covarianceModel_));
clusteringInput->setModelType(&modelType, 0);
clusteringInput->finalize();

// Do the computation
XEMClusteringMain clusteringMain(clusteringInput);
XEM::ClusteringMain clusteringMain(clusteringInput);
clusteringMain.run();

// Extract the results
XEMClusteringOutput * clusteringOutput(clusteringMain.getClusteringOutput());
XEM::ClusteringOutput * clusteringOutput(clusteringMain.getOutput());

XEMClusteringModelOutput * clusteringModelOutput(clusteringOutput->getClusteringModelOutput(0));
XEMParameterDescription * paramDescription(clusteringModelOutput->getParameterDescription());
XEM::ClusteringModelOutput * clusteringModelOutput(clusteringOutput->getClusteringModelOutput(0));
XEM::ParameterDescription * paramDescription(clusteringModelOutput->getParameterDescription());
if (paramDescription == NULL) throw OT::InternalException(HERE) << "Error: Mixmod is unable to estimate a mixture with the given data and the current number of atoms. You may have repeated points in your data, a situation not well handled by Mixmod.";
XEMParameter * paramTmp(paramDescription->getParameter());
XEMGaussianEDDAParameter * param = dynamic_cast< XEMGaussianEDDAParameter * >(paramTmp);
XEM::Parameter * paramTmp(paramDescription->getParameter());
XEM::GaussianEDDAParameter *param = dynamic_cast< XEM::GaussianEDDAParameter * >(paramTmp);

OT::Mixture::DistributionCollection coll(0);
for (OT::UnsignedInteger i = 0; i < atomsNumber_; ++i)
@@ -149,17 +157,18 @@ OT::Mixture MixtureFactory::buildAsMixture(const OT::Sample & sample,
atom.setWeight(w);
coll.add(atom);
}
XEMLabelDescription * labelDescription(clusteringModelOutput->getLabelDescription());
XEM::LabelDescription * labelDescription(clusteringModelOutput->getLabelDescription());
labels = OT::Indices(sampleSize);
// Labels run from 1 to nbAtoms, we want indices in {0,\dots,nbAtoms-1}
// getTabLabel() returns a copy of original vector, it must be destroyed explicitly
int64_t * tabLabels = labelDescription->getLabel()->getTabLabel();
for (OT::UnsignedInteger i = 0; i < sampleSize; ++i) labels[i] = tabLabels[i] - 1;
delete [] tabLabels;

BICLogLikelihood = OT::Point(3);
BICLogLikelihood[0] = param->getModel()->getLogLikelihood(false);
BICLogLikelihood[1] = param->getModel()->getCompletedLogLikelihood();
BICLogLikelihood[2] = param->getModel()->getEntropy();
// BICLogLikelihood[0] = param->getModel()->getLogLikelihood(false);
// BICLogLikelihood[1] = param->getModel()->getCompletedLogLikelihood();
// BICLogLikelihood[2] = param->getModel()->getEntropy();
return OT::Mixture(coll);
}

@@ -182,7 +191,7 @@ OT::UnsignedInteger MixtureFactory::getAtomsNumber () const
/* MixmodCovariance model accessors */
void MixtureFactory::setCovarianceModel (const OT::String covarianceModel)
{
(void) StringToXEMModelName(covarianceModel);
(void) XEM::StringToModelName(covarianceModel);
covarianceModel_ = covarianceModel;
}

@@ -209,10 +218,9 @@ MixtureFactory::SampleCollection MixtureFactory::BuildClusters(const OT::Sample
}

/* Mixmod PRNG state accessor */
void MixtureFactory::setState(const OT::UnsignedInteger yState,
const OT::UnsignedInteger zState)
void MixtureFactory::setSeed(const OT::UnsignedInteger seed)
{
setSeed(yState, zState);
XEM::initRandomize(seed);
}

} // namespace OTMIXMOD
2 changes: 0 additions & 2 deletions lib/src/mixmod/CMakeLists.txt

This file was deleted.

79 changes: 0 additions & 79 deletions lib/src/mixmod/MIXMOD/CMakeLists.txt

This file was deleted.

Loading
Oops, something went wrong.

0 comments on commit b2fd0c8

Please sign in to comment.