Coverage for src/lsqfitgp/_Kernel/_kernel.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.6.3, created at 2024-10-15 19:54 +0000

1# lsqfitgp/_Kernel/_kernel.py 

2# 

3# Copyright (c) 2020, 2022, 2023, Giacomo Petrillo 

4# 

5# This file is part of lsqfitgp. 

6# 

7# lsqfitgp is free software: you can redistribute it and/or modify 

8# it under the terms of the GNU General Public License as published by 

9# the Free Software Foundation, either version 3 of the License, or 

10# (at your option) any later version. 

11# 

12# lsqfitgp is distributed in the hope that it will be useful, 

13# but WITHOUT ANY WARRANTY; without even the implied warranty of 

14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

15# GNU General Public License for more details. 

16# 

17# You should have received a copy of the GNU General Public License 

18# along with lsqfitgp. If not, see <http://www.gnu.org/licenses/>. 

19 

20from . import _util 1efabcd

21from . import _crosskernel 1efabcd

22 

23class Kernel(_crosskernel.CrossKernel): 1efabcd

24 r""" 

25 

26 Subclass of `CrossKernel` to represent the kernel of a single function: 

27 

28 .. math:: 

29 \mathrm{kernel}(x, y) = \mathrm{Cov}[f(x), f(y)]. 

30 

31 """ 

32 

33 def _swap(self): 1efabcd

34 return self 1efabcd

35 

36Kernel.inherit_transf('xtransf') 1efabcd

37Kernel.inherit_transf('diff') 1efabcd

38# other transformations are registered by IsotropicKernel 

39 

40@Kernel.register_transf 1efabcd

41def forcekron(tcls, self): 1efabcd

42 r""" 

43  

44 Force the kernel to be a separate product over dimensions: 

45 

46 .. math:: 

47 \mathrm{newkernel}(x, y) = \prod_i \mathrm{kernel}(x_i, y_i) 

48  

49 Returns 

50 ------- 

51 newkernel : Kernel 

52 The transformed kernel. 

53 

54 """ 

55 

56 core = self.core 1abcd

57 newcore = lambda x, y, **kw: _util.prod_recurse_dtype(core, x, y, **kw) 1abcd

58 return self._clone(tcls, core=newcore) 1abcd

59 

60_crosskernel.Kernel = Kernel 1efabcd