PlainModel#
- class PlainModel#
A plaintext representation of an ML model.
- static create(*args, **kwargs)#
Overloaded function.
create(hyper_params: pyhelayers.PlainModelHyperParams) -> pyhelayers.PlainModel
Creates and returns a plain model given hyperparameters.
- param hyper_params:
The hyperparameters object.
create(hyper_params: pyhelayers.PlainModelHyperParams, files: List[str]) -> pyhelayers.PlainModel
Creates and returns a plain model given hyperparameters and names of files with contents to load.
- param hyper_params:
The hyperparameters object.
- param files:
List of file names with content to load, depending on the underlying model.
create(hyper_params: pyhelayers.PlainModelHyperParams, buffers: List[bytes], files: List[str]) -> pyhelayers.PlainModel
Creates and returns a plain model given hyperparameters, buffers with contents to load, and file names corresponding to each stream.
- param hyper_params:
The hyperparameters object.
- param buffers:
List of buffers with content to load, depending on the underlying model. All buffers must be rewindable.
- param files:
List of file names corresponding to each buffer.
- fit(self: pyhelayers.PlainModel, inputs: List[numpy.ndarray[numpy.float64]]) None #
Fit (train) the model.
- Parameters:
inputs – The training inputs.
- get_empty_he_model(self: pyhelayers.PlainModel, he_context: pyhelayers.HeContext) pyhelayers.HeModel #
Returns an empty (not initialized) HE model from the underlying type corresponding to this plain model.
- Parameters:
he_context – The HE context.
- get_hyper_params(self: pyhelayers.PlainModel) pyhelayers.PlainModelHyperParams #
Returns the model’s hyperparameters.
- get_input_shapes_for_fit(self: pyhelayers.PlainModel) List[List[int]] #
Returns the expected shapes of the inputs for fit. If batch dimension is applicable, the value of the batch dimension is set to zero.
- get_input_shapes_for_predict(self: pyhelayers.PlainModel) List[List[int]] #
Returns the expected shapes of the inputs for predict. If batch dimension is applicable, the value of the batch dimension is set to zero.
- get_inputs_names_for_fit(self: pyhelayers.PlainModel) List[str] #
Returns the names of inputs the model expects for fit, to be used to deduce the order in which multiple inputs are expected.
- get_inputs_names_for_predict(self: pyhelayers.PlainModel) List[str] #
Returns the names of inputs the model expects for predict, to be used to deduce the order in which multiple inputs are expected.
- get_outputs_names_of_predict(self: pyhelayers.PlainModel) List[str] #
Returns the names of outputs the model returns after predict, to be used to deduce the order in which multiple outputs are returned.
- init(self: pyhelayers.PlainModel, hyper_params: pyhelayers.PlainModelHyperParams, buffers: List[bytes], files: List[str]) None #
Initializes a plain model given hyperparameters, buffers with contents to load, and file names corresponding to each stream.
- Parameters:
hyper_params – The hyperparameters object.
buffers – List of buffers with content to load, depending on the underlying model. All buffers must be rewindable.
files – List of file names corresponding to each buffer.
- init_from_files(self: pyhelayers.PlainModel, hyper_params: pyhelayers.PlainModelHyperParams, files: List[str]) None #
Initializes a plain model given hyperparameters and names of files with contents to load.
- Parameters:
hyper_params – The hyperparameters object.
files – List of file names with content to load, depending on the underlying model.
- is_fit_mode(self: pyhelayers.PlainModel) bool #
Returns indication for whether the initialized model is on fit-only or on predict-only mode.
- is_verbose(self: pyhelayers.PlainModel) bool #
Returns indication for whether the initialized model verbosity is turned on or off.
- predict(self: pyhelayers.PlainModel, inputs: List[numpy.ndarray[numpy.float64]]) List[numpy.ndarray[numpy.float64]] #
Run prediction (inference) over the model. Returns predictions.
- Parameters:
inputs – The inputs.
- validate_init(self: pyhelayers.PlainModel) None #
Validates this model has been initialized.
-
class PlainModel : public helayers::Printable#
A plaintext representation of an ML model.
Subclassed by helayers::ArimaPlain, helayers::DTreePlain, helayers::KMeansPlain, helayers::LogisticRegressionPlain, helayers::NeuralNetPlain, helayers::XGBoostPlain
Public Functions
-
PlainModel()#
Construct a new plain model object.
-
virtual ~PlainModel()#
Destroy the plain model object.
-
PlainModel(const PlainModel &src) = delete#
Deleted copy constructor.
-
PlainModel &operator=(const PlainModel &src) = delete#
Deleted operator=.
Initializes a plain model given hyperparameters, streams with contents to load, and file names corresponding to each stream.
- Parameters:
hyperParams – The hyperparameters object.
streams – List of streams with content to load, depending on the underlying model. All streams must be rewindable.
files – List of file names corresponding to each stream.
-
void initFromFiles(const PlainModelHyperParams &hyperParams, const std::vector<std::string> &files)#
Initializes a plain model given hyperparameters and names of files with contents to load.
- Parameters:
hyperParams – The hyperparameters object.
files – List of file names with content to load, depending on the underlying model.
-
virtual std::vector<std::string> getInputsNamesForPredict() const#
Returns the names of inputs the model expects for predict, to be used to deduce the order in which multiple inputs are expected.
-
virtual std::vector<std::string> getInputsNamesForFit() const#
Returns the names of inputs the model expects for fit, to be used to deduce the order in which multiple inputs are expected.
-
virtual std::vector<std::string> getOutputsNamesOfPredict() const#
Returns the names of outputs the model returns after predict, to be used to deduce the order in which multiple outputs are returned.
-
virtual std::vector<std::vector<DimInt>> getInputShapesForPredict() const = 0#
Returns the expected shapes of the inputs for predict.
If batch dimension is applicable, the value of the batch dimension is set to zero.
-
virtual std::vector<std::vector<DimInt>> getInputShapesForFit() const#
Returns the expected shapes of the inputs for fit.
If batch dimension is applicable, the value of the batch dimension is set to zero.
-
std::vector<DoubleTensorCPtr> predict(const std::vector<DoubleTensorCPtr> &inputs) const#
Run prediction (inference) over the model.
Returns predictions.
- Parameters:
inputs – The inputs.
-
void fit(const std::vector<DoubleTensorCPtr> &inputs)#
Fit (train) the model.
- Parameters:
inputs – The training inputs.
-
bool isFitMode() const#
Returns indication for whether the initialized model is on fit-only or on predict-only mode.
-
bool isVerbose() const#
Returns indication for whether the initialized model verbosity is turned on or off.
-
const PlainModelHyperParams &getHyperParams() const#
Returns the model’s hyperparameters.
-
bool isInitialized() const#
Returns indication for whether the model is initialized.
-
void validateInit() const#
Validates this model has been initialized.
-
virtual std::shared_ptr<HeModel> getEmptyHeModel(const HeContext &he) const = 0#
Returns an empty (not initialized) HE model from the underlying type corresponding to this plain model.
- Parameters:
he – The HE context.
-
virtual std::string getClassName() const = 0#
Retunrs the name of this class.
-
virtual void debugPrint(const std::string &title = "", Verbosity verbosity = VERBOSITY_REGULAR, std::ostream &out = std::cout) const override#
Prints the content of this object.
- Parameters:
title – Text to add to the print
verbosity – Verbosity level
out – Output stream
Public Static Functions
-
static std::shared_ptr<PlainModel> create(const PlainModelHyperParams &hyperParams)#
Creates and returns a plain model given hyperparameters.
- Parameters:
hyperParams – The hyperparameters object.
Creates and returns a plain model given hyperparameters, streams with contents to load, and file names corresponding to each stream.
- Parameters:
hyperParams – The hyperparameters object.
streams – List of streams with content to load, depending on the underlying model. All streams must be rewindable.
files – List of file names corresponding to each stream.
-
static std::shared_ptr<PlainModel> create(const PlainModelHyperParams &hyperParams, const std::vector<std::string> &files)#
Creates and returns a plain model given hyperparameters and names of files with contents to load.
- Parameters:
hyperParams – The hyperparameters object.
files – List of file names with content to load, depending on the underlying model.
-
PlainModel()#