mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-27 14:25:16 +02:00
add the function of saving all the parameters into a HDF5 file
This commit is contained in:
parent
9b2e49c949
commit
5736caa8fd
1 changed files with 25 additions and 0 deletions
|
|
@ -1009,3 +1009,28 @@ class Parameterizable(OptimizationHandlable):
|
||||||
updates get passed through. See :py:function:``GPy.core.param.Observable.add_observer``
|
updates get passed through. See :py:function:``GPy.core.param.Observable.add_observer``
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def save_params_H5(self, filename):
|
||||||
|
"""
|
||||||
|
Save all the model parameters into a HDF5 file.
|
||||||
|
"""
|
||||||
|
from . import Param
|
||||||
|
from ...util.misc import param_to_array
|
||||||
|
def gather_params(self, plist):
|
||||||
|
if isinstance(self,Param):
|
||||||
|
plist.append(self)
|
||||||
|
plist = []
|
||||||
|
self.traverse(gather_params, plist)
|
||||||
|
names = self.parameter_names(adjust_for_printing=True)
|
||||||
|
try:
|
||||||
|
import h5py
|
||||||
|
f = h5py.File(filename,'w')
|
||||||
|
for p,n in zip(plist,names):
|
||||||
|
n = n.replace('.','_')
|
||||||
|
p = param_to_array(p)
|
||||||
|
d = f.create_dataset(n,p.shape,dtype=p.dtype)
|
||||||
|
d[:] = p
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
raise 'Fails to write the parameters into a HDF5 file!'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue