Coverage for src/lsqfitgp/_GP/_gp.py: 100%

7 statements  

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

1# lsqfitgp/_GP/_gp.py 

2# 

3# Copyright (c) 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 _base, _compute, _elements, _processes 1abcdef

21 

22class GP(_compute.GPCompute, _elements.GPElements, _processes.GPProcesses): 1abcdef

23 """ 

24  

25 Object that represents a Gaussian process. 

26 

27 A `GP` is structured like a pair of dictionaries, one for "processes", and 

28 one for "elements". The processes represent independent Gaussian processes, 

29 i.e., infinite-dimensional Normally distributed variables. The elements 

30 represent finite-dimensional Normal variables, typically finite subsets of 

31 the processes. 

32 

33 The methods to define processes start with "def", while those to define 

34 elements starts with "add". The basic methods are `defproc` and `addx`. 

35  

36 A `GP` object is immutable. Methods that modify the Gaussian process return 

37 a new object which differs only in the requested modification, leaving the 

38 original untouched. 

39 

40 Parameters 

41 ---------- 

42 covfun : Kernel, optional 

43 An instance of `Kernel` representing the covariance kernel of the 

44 default process of the GP object. It can be left unspecified. 

45 solver : str, default 'chol' 

46 The algorithm used to decompose the prior covariance matrix. See 

47 `decompose` for the available solvers. 

48 checkpos : bool, default True 

49 Raise a `LinAlgError` if the prior covariance matrix turns out non 

50 positive within numerical error. 

51 checksym : bool, default True 

52 Check that the prior covariance matrix is symmetric. 

53 checkfinite : bool, default True 

54 Check that the prior covariance matrix does not contain infs or nans. 

55 checklin : bool, default True 

56 The method `addlintransf` will check that the given transformation is 

57 linear on a random input tensor. 

58 posepsfac : number, default 1 

59 The threshold used to check if the prior covariance matrix is positive 

60 definite is multiplied by this factor. 

61 halfmatrix : bool, default False 

62 If ``checksym=False``, compute only half of the covariance matrices by 

63 unrolling their lower triangular part as flat arrays. This may actually 

64 be a large performance hit if the input arrays have large item size or 

65 if the implementation of the kernel takes advantage of non-broadcasted 

66 inputs. 

67 **kw 

68 Additional keyword arguments are passed to the solver, see `decompose`. 

69 

70 Methods 

71 ------- 

72 addx 

73 Add points where a process is evaluated. 

74 addlintransf 

75 Define a finite linear transformation. 

76 addtransf 

77 Define a finite linear transformation with explicit coefficients. 

78 addcov 

79 Introduce a set of user-provided prior covariance matrix blocks. 

80 defproc 

81 Define a new independent process with a kernel. 

82 deflintransf 

83 Define a pointwise linear transformation. 

84 deftransf 

85 Define a pointwise linear transformation with explicit coefficients. 

86 deflinop 

87 Define an arbitrary linear transformation through a kernel method. 

88 defderiv 

89 Define a process as the derivative of another one. 

90 defxtransf 

91 Define a process with transformed inputs. 

92 defrescale 

93 Rescale a process. 

94 prior 

95 Compute the prior. 

96 pred 

97 Compute the posterior. 

98 predfromfit 

99 Like `pred` with ``fromdata=False``. 

100 predfromdata 

101 Like `pred` with ``fromdata=True``. 

102 marginal_likelihood 

103 Compute the probability density. 

104 decompose 

105 Decompose a pos. semidef. matrix. 

106 

107 Attributes 

108 ---------- 

109 DefaultProcess : 

110 Key that identifies the default process. 

111  

112 """ 

113 

114 def __init__(self, 1abcdef

115 covfun=None, 

116 *, 

117 solver='chol', 

118 checkpos=True, 

119 checksym=True, 

120 checkfinite=True, 

121 checklin=True, 

122 posepsfac=1, 

123 halfmatrix=False, 

124 **kw, 

125 ): 

126 _base.GPBase.__init__(self, checkfinite=checkfinite, checklin=checklin) 1abcdef

127 _processes.GPProcesses.__init__(self, covfun=covfun) 1abcdef

128 _elements.GPElements.__init__(self, checkpos=checkpos, checksym=checksym, posepsfac=posepsfac, halfmatrix=halfmatrix) 1abcdef

129 _compute.GPCompute.__init__(self, solver=solver, solverkw=kw) 1abcdef