mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-11 15:15:15 +02:00
rename the save_params_H5 function to be a general function save which can potentially support other file format
This commit is contained in:
parent
5736caa8fd
commit
0018b5e583
1 changed files with 14 additions and 13 deletions
|
|
@ -1010,9 +1010,9 @@ class Parameterizable(OptimizationHandlable):
|
|||
"""
|
||||
pass
|
||||
|
||||
def save_params_H5(self, filename):
|
||||
def save(self, filename, ftype='HDF5'):
|
||||
"""
|
||||
Save all the model parameters into a HDF5 file.
|
||||
Save all the model parameters into a file (HDF5 by default).
|
||||
"""
|
||||
from . import Param
|
||||
from ...util.misc import param_to_array
|
||||
|
|
@ -1022,15 +1022,16 @@ class Parameterizable(OptimizationHandlable):
|
|||
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!'
|
||||
if ftype=='HDF5':
|
||||
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