-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathCMetricModelFactory.h
More file actions
191 lines (155 loc) · 7.19 KB
/
Copy pathCMetricModelFactory.h
File metadata and controls
191 lines (155 loc) · 7.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the following additional limitation. Functionality enabled by the
* files subject to the Elastic License 2.0 may only be used in production when
* invoked by an Elasticsearch process with a license key installed that permits
* use of machine learning features. You may not use this file except in
* compliance with the Elastic License 2.0 and the foregoing additional
* limitation.
*/
#ifndef INCLUDED_ml_model_CMetricModelFactory_h
#define INCLUDED_ml_model_CMetricModelFactory_h
#include <model/CModelFactory.h>
#include <model/CSearchKey.h>
#include <model/ImportExport.h>
namespace ml {
namespace core {
class CStateRestoreTraverser;
}
namespace model {
//! \brief A factory class implementation for CMetricModel.
//!
//! DESCRIPTION:\n
//! This concrete factory implements the methods to make new models
//! and data gatherers, and create default priors suitable for the
//! CMetricModel class.
class MODEL_EXPORT CMetricModelFactory final : public CModelFactory {
public:
//! Lift all overloads into scope.
using CModelFactory::defaultMultivariatePrior;
using CModelFactory::defaultPrior;
public:
//! \note The default arguments supplied to the constructor are
//! intended for unit testing and are not necessarily good defaults.
//! The CModelConfig class is responsible for providing sensible
//! default values for the factory for use within our products.
CMetricModelFactory(const SModelParams& params,
const TInterimBucketCorrectorWPtr& interimBucketCorrector,
model_t::ESummaryMode summaryMode = model_t::E_None,
const std::string& summaryCountFieldName = "");
//! Create a copy of the factory owned by the calling code.
CMetricModelFactory* clone() const override;
//! \name Factory Methods
//@{
//! Make a new metric model.
//!
//! \param[in] initData The parameters needed to initialize the model.
//! \warning It is owned by the calling code.
CAnomalyDetectorModel* makeModel(const SModelInitializationData& initData) const override;
//! Make a new metric model from part of a state document.
//!
//! \param[in] initData Additional parameters needed to initialize
//! the model.
//! \param[in,out] traverser A state document traverser.
//! \warning It is owned by the calling code.
CAnomalyDetectorModel* makeModel(const SModelInitializationData& initData,
core::CStateRestoreTraverser& traverser) const override;
//! Make a new metric data gatherer.
//!
//! \param[in] initData The parameters needed to initialize the
//! data gatherer.
//! \warning It is owned by the calling code.
TDataGathererPtr makeDataGatherer(const SGathererInitializationData& initData) const override;
//! Make a new metric data gatherer from part of a state document.
//!
//! \param[in] partitionFieldValue The partition field value.
//! \param[in,out] traverser A state document traverser.
//! \warning It is owned by the calling code.
TDataGathererPtr makeDataGatherer(const std::string& partitionFieldValue,
core::CStateRestoreTraverser& traverser) const override;
//@}
//! \name Defaults
//@{
//! Get the default prior for \p feature.
//!
//! \param[in] feature The feature for which to get the prior.
//! \param[in] params The model parameters.
TPriorPtr defaultPrior(model_t::EFeature feature, const SModelParams& params) const override;
//! Get the default multivariate prior for \p feature.
//!
//! \param[in] feature The feature for which to get the prior.
//! \param[in] params The model parameters.
TMultivariatePriorUPtr defaultMultivariatePrior(model_t::EFeature feature,
const SModelParams& params) const override;
//! Get the default prior for pairs of correlated time series
//! of \p feature.
//!
//! \param[in] feature The feature for which to get the prior.
//! \param[in] params The model parameters.
TMultivariatePriorUPtr defaultCorrelatePrior(model_t::EFeature feature,
const SModelParams& params) const override;
//@}
//! Get the search key corresponding to this factory.
const CSearchKey& searchKey() const override;
//! Returns false.
bool isSimpleCount() const override;
//! Check the pre-summarisation mode for this factory.
model_t::ESummaryMode summaryMode() const override;
//! Get the default data type for models from this factory.
maths_t::EDataType dataType() const override;
//! \name Customization by a specific search
//@{
//! Set the identifier of the search for which this generates models.
void detectorIndex(int detectorIndex) override;
//! Set the name of the field whose values will be counted.
void fieldNames(const std::string& partitionFieldName,
const std::string& overFieldName,
const std::string& byFieldName,
const std::string& valueFieldName,
const TStrVec& influenceFieldNames) override;
//! Set whether the models should process missing person fields.
void useNull(bool useNull) override;
//! Set the features which will be modeled.
void features(const TFeatureVec& features) override;
//! Set the modeled bucket length.
void bucketLength(core_t::TTime bucketLength);
//@}
//! Get the minimum seasonal variance scale
double minimumSeasonalVarianceScale() const override;
private:
//! Get the field values which partition the data for modeling.
TStrCRefVec partitioningFields() const override;
private:
//! The identifier of the search for which this generates models.
int m_DetectorIndex = 0;
//! Indicates whether the data being gathered are already summarized
//! by an external aggregation process.
model_t::ESummaryMode m_SummaryMode;
//! If m_SummaryMode is E_Manual then this is the name of the field
//! holding the summary count.
std::string m_SummaryCountFieldName;
//! The name of the field which splits the data.
std::string m_PartitionFieldName;
//! The name of field whose values define the metric series' names
//! which will be analyzed.
std::string m_PersonFieldName;
//! The name of field whose values define the metric series' values
//! which will be analyzed.
std::string m_ValueFieldName;
//! The field names for which we are computing influence. These are
//! the fields which can be used to join results across different
//! searches.
TStrVec m_InfluenceFieldNames;
//! If true the models will process missing person fields.
bool m_UseNull = false;
//! The count features which will be modeled.
TFeatureVec m_Features;
//! The bucket length to analyze.
core_t::TTime m_BucketLength;
//! A cached search key.
mutable TOptionalSearchKey m_SearchKeyCache;
};
}
}
#endif // INCLUDED_ml_model_CMetricModelFactory_h