OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MLModelMap Class Reference

#include <MLModel.h>

Public Member Functions

void addModel (const std::string &model_name, std::shared_ptr< AbstractMLModel > model)
 
bool modelExists (const std::string &model_name) const
 
std::shared_ptr< AbstractMLModelgetModel (const std::string &model_name) const
 
void deleteModel (const std::string &model_name)
 
std::vector< std::string > getModelNames () const
 
std::vector< MLModelMetadatagetModelMetadata () const
 
MLModelMetadata getModelMetadata (const std::string &model_name) const
 

Private Attributes

std::map< std::string,
std::shared_ptr
< AbstractMLModel > > 
model_map_
 
std::shared_mutex model_map_mutex_
 

Detailed Description

Definition at line 35 of file MLModel.h.

Member Function Documentation

void MLModelMap::addModel ( const std::string &  model_name,
std::shared_ptr< AbstractMLModel model 
)
inline

Definition at line 37 of file MLModel.h.

References model_map_, model_map_mutex_, and to_upper().

Referenced by linear_reg_fit_impl(), and pca_fit_impl().

37  {
38  const auto upper_model_name = to_upper(model_name);
39  std::lock_guard<std::shared_mutex> model_map_write_lock(model_map_mutex_);
40  model_map_[upper_model_name] = model;
41  }
std::string to_upper(const std::string &str)
std::shared_mutex model_map_mutex_
Definition: MLModel.h:121
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:120

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MLModelMap::deleteModel ( const std::string &  model_name)
inline

Definition at line 61 of file MLModel.h.

References model_map_, model_map_mutex_, and to_upper().

Referenced by Parser::DropModelStmt::execute().

61  {
62  const auto upper_model_name = to_upper(model_name);
63  std::lock_guard<std::shared_mutex> model_map_write_lock(model_map_mutex_);
64  auto const model_it = model_map_.find(upper_model_name);
65  if (model_it == model_map_.end()) {
66  std::ostringstream error_oss;
67  error_oss << "Cannot erase model " << upper_model_name
68  << ". No model by that name was found.";
69  throw std::runtime_error(error_oss.str());
70  }
71  model_map_.erase(model_it);
72  }
std::string to_upper(const std::string &str)
std::shared_mutex model_map_mutex_
Definition: MLModel.h:121
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:120

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<AbstractMLModel> MLModelMap::getModel ( const std::string &  model_name) const
inline

Definition at line 50 of file MLModel.h.

References model_map_, model_map_mutex_, and to_upper().

Referenced by CodeGenerator::codegen(), ShowModelFeatureDetailsCommand::execute(), get_decision_trees__cpu_1(), linear_reg_coefs__cpu_1(), ml_reg_predict__cpu_template(), r2_score__cpu_template(), and random_forest_reg_var_importance__cpu_1().

50  {
51  const auto upper_model_name = to_upper(model_name);
52  std::shared_lock<std::shared_mutex> model_map_read_lock(model_map_mutex_);
53  auto model_map_itr = model_map_.find(upper_model_name);
54  if (model_map_itr != model_map_.end()) {
55  return model_map_itr->second;
56  }
57  const std::string error_str = "Model '" + upper_model_name + "' does not exist.";
58  throw std::runtime_error(error_str);
59  }
std::string to_upper(const std::string &str)
std::shared_mutex model_map_mutex_
Definition: MLModel.h:121
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:120

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<MLModelMetadata> MLModelMap::getModelMetadata ( ) const
inline

Definition at line 83 of file MLModel.h.

References model_map_, and model_map_mutex_.

Referenced by ShowModelDetailsCommand::execute(), EvaluateModelCommand::execute(), and foreign_storage::InternalMLModelMetadataDataWrapper::initializeObjectsForTable().

83  {
84  std::shared_lock<std::shared_mutex> model_map_read_lock(model_map_mutex_);
85  std::vector<MLModelMetadata> model_metadata;
86  for (auto const& model : model_map_) {
87  model_metadata.emplace_back(MLModelMetadata(
88  model.first,
89  model.second->getModelType(),
90  model.second->getModelTypeString(),
91  model.second->getNumLogicalFeatures(),
92  model.second->getNumFeatures(),
93  model.second->getNumCatFeatures(),
94  model.second->getNumLogicalFeatures() - model.second->getNumCatFeatures(),
95  model.second->getModelMetadataStr()));
96  }
97  return model_metadata;
98  }
std::shared_mutex model_map_mutex_
Definition: MLModel.h:121
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:120

+ Here is the caller graph for this function:

MLModelMetadata MLModelMap::getModelMetadata ( const std::string &  model_name) const
inline

Definition at line 100 of file MLModel.h.

References model_map_, model_map_mutex_, and to_upper().

100  {
101  const auto upper_model_name = to_upper(model_name);
102  std::shared_lock<std::shared_mutex> model_map_read_lock(model_map_mutex_);
103  auto model_map_itr = model_map_.find(upper_model_name);
104  if (model_map_itr != model_map_.end()) {
105  return MLModelMetadata(model_map_itr->first,
106  model_map_itr->second->getModelType(),
107  model_map_itr->second->getModelTypeString(),
108  model_map_itr->second->getNumLogicalFeatures(),
109  model_map_itr->second->getNumFeatures(),
110  model_map_itr->second->getNumCatFeatures(),
111  model_map_itr->second->getNumLogicalFeatures() -
112  model_map_itr->second->getNumCatFeatures(),
113  model_map_itr->second->getModelMetadataStr());
114  }
115  const std::string error_str = "Model '" + upper_model_name + "' does not exist.";
116  throw std::runtime_error(error_str);
117  }
std::string to_upper(const std::string &str)
std::shared_mutex model_map_mutex_
Definition: MLModel.h:121
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:120

+ Here is the call graph for this function:

std::vector<std::string> MLModelMap::getModelNames ( ) const
inline

Definition at line 74 of file MLModel.h.

References model_map_, and model_map_mutex_.

Referenced by ShowModelsCommand::execute(), and ShowModelDetailsCommand::getFilteredModelNames().

74  {
75  std::shared_lock<std::shared_mutex> model_map_read_lock(model_map_mutex_);
76  std::vector<std::string> model_names;
77  model_names.reserve(model_map_.size());
78  for (auto const& model : model_map_) {
79  model_names.emplace_back(model.first);
80  }
81  return model_names;
82  }
std::shared_mutex model_map_mutex_
Definition: MLModel.h:121
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:120

+ Here is the caller graph for this function:

bool MLModelMap::modelExists ( const std::string &  model_name) const
inline

Definition at line 43 of file MLModel.h.

References model_map_, model_map_mutex_, and to_upper().

Referenced by Parser::CreateModelStmt::check_model_exists().

43  {
44  const auto upper_model_name = to_upper(model_name);
45  std::shared_lock<std::shared_mutex> model_map_read_lock(model_map_mutex_);
46  auto model_map_itr = model_map_.find(upper_model_name);
47  return model_map_itr != model_map_.end();
48  }
std::string to_upper(const std::string &str)
std::shared_mutex model_map_mutex_
Definition: MLModel.h:121
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:120

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::map<std::string, std::shared_ptr<AbstractMLModel> > MLModelMap::model_map_
private

Definition at line 120 of file MLModel.h.

Referenced by addModel(), deleteModel(), getModel(), getModelMetadata(), getModelNames(), and modelExists().

std::shared_mutex MLModelMap::model_map_mutex_
mutableprivate

Definition at line 121 of file MLModel.h.

Referenced by addModel(), deleteModel(), getModel(), getModelMetadata(), getModelNames(), and modelExists().


The documentation for this class was generated from the following file: