GPy/GPy/__init__.py

76 lines
2.4 KiB
Python
Raw Normal View History

# Copyright (c) 2012, GPy authors (see AUTHORS.txt).
# Licensed under the BSD 3-clause license (see LICENSE.txt)
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
from . import core
from . import models
from . import mappings
from . import inference
from . import util
from . import examples
from . import likelihoods
from . import testing
from . import kern
from . import plotting
2015-11-05 09:27:59 +00:00
# backwards compatibility
import sys
backwards_compatibility = ['lists_and_dicts', 'observable_array', 'ties_and_remappings', 'index_operations']
for bc in backwards_compatibility:
sys.modules['GPy.core.parameterization.{!s}'.format(bc)] = getattr(core.parameterization, bc)
# Direct imports for convenience:
2015-10-15 15:13:16 +01:00
from .core import Model
2015-11-05 09:27:59 +00:00
from .core.parameterization import priors
from paramz import Param, Parameterized, ObsAr, transformations as constraints
from .__version__ import __version__
2015-09-09 08:58:01 +01:00
from numpy.testing import Tester
#@nottest
try:
#Get rid of nose dependency by only ignoring if you have nose installed
from nose.tools import nottest
@nottest
2015-09-10 14:45:52 +01:00
def tests(verbose=10):
Tester(testing).test(verbose=verbose)
except:
2015-09-10 14:45:52 +01:00
def tests(verbose=10):
Tester(testing).test(verbose=verbose)
def load(file_or_path):
"""
Load a previously pickled model, using `m.pickle('path/to/file.pickle)'
:param file_name: path/to/file.pickle
"""
# This is the pickling pain when changing _src -> src
2015-11-05 09:27:59 +00:00
import inspect
2015-11-05 10:02:31 +00:00
sys.modules['GPy.kern._src'] = kern.src # @UndefinedVariable
for name, module in inspect.getmembers(kern.src): # @UndefinedVariable
2015-11-05 09:27:59 +00:00
if not name.startswith('_'):
sys.modules['GPy.kern._src.{}'.format(name)] = module
2015-10-11 01:42:49 +01:00
try:
2015-11-05 09:27:59 +00:00
import cPickle as pickle
if isinstance(file_or_path, basestring):
with open(file_or_path, 'rb') as f:
m = pickle.load(f)
else:
m = pickle.load(file_or_path)
2015-11-05 09:52:27 +00:00
except: # python3
2015-11-05 10:02:31 +00:00
import pickle # @Reimport
2015-11-05 09:27:59 +00:00
if isinstance(file_or_path, str):
with open(file_or_path, 'rb') as f:
#u = pickle._Unpickler(f) # @UndefinedVariable
#u.encoding = 'latin1'
#m = u.load()
m = pickle.load(f, encoding='latin1')#
2015-11-05 09:27:59 +00:00
else:
#u = pickle._Unpickler(file_or_path) # @UndefinedVariable
#u.encoding = 'latin1'
#m = u.load(protocol=2)
m = pickle.load(f, encoding='latin1')#
return m