MCPcopy
hub / github.com/ddbourgin/numpy-ml / set_params

Method set_params

numpy_ml/utils/kernels.py:34–69  ·  view source on GitHub ↗

Set the model parameters and hyperparameters using the settings in `summary_dict`. Parameters ---------- summary_dict : dict A dictionary with keys 'parameters' and 'hyperparameters', structured as would be returned by the :meth:`summ

(self, summary_dict)

Source from the content-addressed store, hash-verified

32 }
33
34 def set_params(self, summary_dict):
35 """
36 Set the model parameters and hyperparameters using the settings in
37 `summary_dict`.
38
39 Parameters
40 ----------
41 summary_dict : dict
42 A dictionary with keys 'parameters' and 'hyperparameters',
43 structured as would be returned by the :meth:`summary` method. If
44 a particular (hyper)parameter is not included in this dict, the
45 current value will be used.
46
47 Returns
48 -------
49 new_kernel : :doc:`Kernel <numpy_ml.utils.kernels>` instance
50 A kernel with parameters and hyperparameters adjusted to those
51 specified in `summary_dict`.
52 """
53 kr, sd = self, summary_dict
54
55 # collapse `parameters` and `hyperparameters` nested dicts into a single
56 # merged dictionary
57 flatten_keys = ["parameters", "hyperparameters"]
58 for k in flatten_keys:
59 if k in sd:
60 entry = sd[k]
61 sd.update(entry)
62 del sd[k]
63
64 for k, v in sd.items():
65 if k in self.parameters:
66 kr.parameters[k] = v
67 if k in self.hyperparameters:
68 kr.hyperparameters[k] = v
69 return kr
70
71
72class LinearKernel(KernelBase):

Callers 1

init_from_dictMethod · 0.45

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected