PyDLLib 1.0.1__tar.gz → 1.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_Conv2D.py +6 -4
  2. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Optimisers/_RMSPROP.py +1 -1
  3. pydllib-1.0.3/DLL/MachineLearning/SupervisedLearning/GaussianProcesses/_GaussianProcessClassifier.py +261 -0
  4. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/GaussianProcesses/_GaussianProcessRegressor.py +34 -34
  5. pydllib-1.0.3/DLL/MachineLearning/SupervisedLearning/GaussianProcesses/__init__.py +2 -0
  6. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Kernels.py +16 -15
  7. {pydllib-1.0.1 → pydllib-1.0.3}/PKG-INFO +1 -1
  8. {pydllib-1.0.1 → pydllib-1.0.3}/PyDLLib.egg-info/PKG-INFO +1 -1
  9. {pydllib-1.0.1 → pydllib-1.0.3}/PyDLLib.egg-info/SOURCES.txt +1 -0
  10. {pydllib-1.0.1 → pydllib-1.0.3}/pyproject.toml +1 -1
  11. pydllib-1.0.1/DLL/MachineLearning/SupervisedLearning/GaussianProcesses/__init__.py +0 -1
  12. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/Data/Metrics.py +0 -0
  13. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/Data/Preprocessing.py +0 -0
  14. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/Data/_DataReader.py +0 -0
  15. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/Data/__init__.py +0 -0
  16. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Callbacks/_BackUp.py +0 -0
  17. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Callbacks/_BaseCallback.py +0 -0
  18. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Callbacks/_EarlyStopping.py +0 -0
  19. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Callbacks/_ReduceLROnPlateau.py +0 -0
  20. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Callbacks/__init__.py +0 -0
  21. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Initialisers/_Initialiser.py +0 -0
  22. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Initialisers/_Kaiming_He.py +0 -0
  23. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Initialisers/_Xavier_Glorot.py +0 -0
  24. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Initialisers/__init__.py +0 -0
  25. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/Activations/_Activation.py +0 -0
  26. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/Activations/_ReLU.py +0 -0
  27. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/Activations/_Sigmoid.py +0 -0
  28. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/Activations/_SoftMax.py +0 -0
  29. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/Activations/_Tanh.py +0 -0
  30. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/Activations/__init__.py +0 -0
  31. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/Regularisation/_BaseRegularisation.py +0 -0
  32. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/Regularisation/_BatchNormalisation.py +0 -0
  33. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/Regularisation/_Dropout.py +0 -0
  34. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/Regularisation/_GroupNormalisation.py +0 -0
  35. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/Regularisation/_InstanceNormalisation.py +0 -0
  36. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/Regularisation/_LayerNormalisation.py +0 -0
  37. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/Regularisation/__init__.py +0 -0
  38. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_Add.py +0 -0
  39. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_Attention.py +0 -0
  40. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_BaseLayer.py +0 -0
  41. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_Bidirectional.py +0 -0
  42. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_Dense.py +0 -0
  43. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_DenseKAN.py +0 -0
  44. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_Flatten.py +0 -0
  45. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_Identity.py +0 -0
  46. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_Input.py +0 -0
  47. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_LSTM.py +0 -0
  48. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_LayerList.py +0 -0
  49. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_MaxPooling2D.py +0 -0
  50. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_RNN.py +0 -0
  51. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/_Reshape.py +0 -0
  52. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Layers/__init__.py +0 -0
  53. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Losses/_BCE.py +0 -0
  54. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Losses/_BaseLoss.py +0 -0
  55. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Losses/_CCE.py +0 -0
  56. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Losses/_Exponential.py +0 -0
  57. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Losses/_Huber.py +0 -0
  58. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Losses/_MAE.py +0 -0
  59. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Losses/_MSE.py +0 -0
  60. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Losses/__init__.py +0 -0
  61. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Model.py +0 -0
  62. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Optimisers/_ADADELTA.py +0 -0
  63. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Optimisers/_ADAGRAD.py +0 -0
  64. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Optimisers/_ADAM.py +0 -0
  65. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Optimisers/_BaseOptimiser.py +0 -0
  66. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Optimisers/_LBFGS.py +0 -0
  67. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Optimisers/_SGD.py +0 -0
  68. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/Optimisers/__init__.py +0 -0
  69. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/DeepLearning/__init__.py +0 -0
  70. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/Exceptions/_Exceptions.py +0 -0
  71. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/Exceptions/__init__.py +0 -0
  72. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Calibration/_CalibratedClassifier.py +0 -0
  73. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Calibration/_IsotonicRegression.py +0 -0
  74. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Calibration/__init__.py +0 -0
  75. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/LinearModels/TimeSeries.py +0 -0
  76. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/LinearModels/_Elasticnet.py +0 -0
  77. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/LinearModels/_LassoRegression.py +0 -0
  78. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/LinearModels/_LinearRegression.py +0 -0
  79. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/LinearModels/_LogisticRegression.py +0 -0
  80. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/LinearModels/_RANSAC.py +0 -0
  81. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/LinearModels/_RidgeRegression.py +0 -0
  82. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/LinearModels/__init__.py +0 -0
  83. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/NaiveBayes/_BernoulliNaiveBayes.py +0 -0
  84. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/NaiveBayes/_GaussianNaiveBayes.py +0 -0
  85. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/NaiveBayes/_MultinomialNaiveBayes.py +0 -0
  86. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/NaiveBayes/__init__.py +0 -0
  87. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Neighbors/_KNearestNeighborsClassifier.py +0 -0
  88. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Neighbors/_KNearestNeighborsRegressor.py +0 -0
  89. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Neighbors/__init__.py +0 -0
  90. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/SupportVectorMachines/_SVC.py +0 -0
  91. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/SupportVectorMachines/_SVR.py +0 -0
  92. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/SupportVectorMachines/__init__.py +0 -0
  93. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_AdaBoostClassifier.py +0 -0
  94. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_AdaBoostRegressor.py +0 -0
  95. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_DecisionTree.py +0 -0
  96. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_GradientBoostingClassifier.py +0 -0
  97. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_GradientBoostingRegressor.py +0 -0
  98. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_LGBMClassifier.py +0 -0
  99. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_LGBMRegressor.py +0 -0
  100. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_LGBMTree.py +0 -0
  101. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_RandomForest.py +0 -0
  102. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_RegressionForest.py +0 -0
  103. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_RegressionTree.py +0 -0
  104. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_XGBoostClassifier.py +0 -0
  105. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_XGBoostRegressor.py +0 -0
  106. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/_XGBoostTree.py +0 -0
  107. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/Trees/__init__.py +0 -0
  108. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/SupervisedLearning/__init__.py +0 -0
  109. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/Clustering/_DBScan.py +0 -0
  110. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/Clustering/_GaussianMixtureModels.py +0 -0
  111. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/Clustering/_KMeans.py +0 -0
  112. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/Clustering/_SpectralClustering.py +0 -0
  113. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/Clustering/__init__.py +0 -0
  114. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/DimensionalityReduction/_LDA.py +0 -0
  115. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/DimensionalityReduction/_PCA.py +0 -0
  116. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/DimensionalityReduction/_QDA.py +0 -0
  117. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/DimensionalityReduction/_RobustPCA.py +0 -0
  118. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/DimensionalityReduction/_TSNE.py +0 -0
  119. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/DimensionalityReduction/_UMAP.py +0 -0
  120. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/DimensionalityReduction/__init__.py +0 -0
  121. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/OutlierDetection/_IsolationForest.py +0 -0
  122. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/OutlierDetection/__init__.py +0 -0
  123. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/UnsupervisedLearning/__init__.py +0 -0
  124. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/MachineLearning/__init__.py +0 -0
  125. {pydllib-1.0.1 → pydllib-1.0.3}/DLL/__init__.py +0 -0
  126. {pydllib-1.0.1 → pydllib-1.0.3}/LICENSE +0 -0
  127. {pydllib-1.0.1 → pydllib-1.0.3}/PyDLLib.egg-info/dependency_links.txt +0 -0
  128. {pydllib-1.0.1 → pydllib-1.0.3}/PyDLLib.egg-info/requires.txt +0 -0
  129. {pydllib-1.0.1 → pydllib-1.0.3}/PyDLLib.egg-info/top_level.txt +0 -0
  130. {pydllib-1.0.1 → pydllib-1.0.3}/README.md +0 -0
  131. {pydllib-1.0.1 → pydllib-1.0.3}/requirements.txt +0 -0
  132. {pydllib-1.0.1 → pydllib-1.0.3}/setup.cfg +0 -0
@@ -46,12 +46,13 @@ class Conv2D(BaseLayer):
46
46
  self.input_depth = input_depth
47
47
  self.output_shape = (self.output_depth, input_height - self.kernel_size + 1, input_width - self.kernel_size + 1)
48
48
  self.kernels_shape = (self.output_depth, input_depth, self.kernel_size, self.kernel_size)
49
- self.nparams = np.prod(self.kernels_shape) + np.prod(self.output_shape)
49
+ self.nparams = np.prod(self.kernels_shape) + self.output_depth
50
50
 
51
51
  super().initialise_layer(input_shape, data_type, device)
52
52
 
53
53
  self.kernels = self.initialiser.initialise(self.kernels_shape, data_type=self.data_type, device=self.device)
54
- self.biases = torch.zeros(self.output_shape)
54
+ # self.biases = torch.zeros(self.output_shape)
55
+ self.biases = torch.zeros((self.output_depth,), dtype=self.data_type, device=self.device)
55
56
 
56
57
  if self.activation:
57
58
  self.activation.initialise_layer(self.output_shape, self.data_type, self.device)
@@ -87,11 +88,12 @@ class Conv2D(BaseLayer):
87
88
 
88
89
  batch_size = input.shape[0]
89
90
  self.input = input
90
- self.output = self.biases.clone().repeat(batch_size, 1, 1, 1)
91
+ self.output = torch.zeros((batch_size, *self.output_shape), dtype=self.data_type, device=self.device)
91
92
  for i in range(self.output_depth):
92
93
  for j in range(self.input_depth):
93
94
  conv_output = F.conv2d(input[:, j:j+1, :, :], self.kernels[i:i+1, j:j+1, :, :], padding="valid")
94
95
  self.output[:, i, :, :] += conv_output[:, 0, :, :]
96
+ self.output += self.biases.view(1, -1, 1, 1)
95
97
 
96
98
  if self.normalisation: self.output = self.normalisation.forward(self.output, training=training)
97
99
  if self.activation: self.output = self.activation.forward(self.output)
@@ -122,7 +124,7 @@ class Conv2D(BaseLayer):
122
124
  kernel_gradient[i, j] = F.conv2d(self.input[:, j:j+1, :, :], dCdy[:, i:i+1, :, :], padding="valid")[0, 0, :, :]
123
125
  dCdx[:, j] += F.conv2d(dCdy[:, i:i+1, :, :], torch.flip(self.kernels[i:i+1, j:j+1, :, :], dims=(2, 3)), padding=[self.kernel_size - 1, self.kernel_size - 1])[0, 0, :, :]
124
126
 
125
- self.biases.grad += dCdy.mean(dim=0)
127
+ self.biases.grad += dCdy.mean(dim=(0, 2, 3))
126
128
  self.kernels.grad += kernel_gradient / batch_size
127
129
  return dCdx
128
130
 
@@ -5,7 +5,7 @@ from ._BaseOptimiser import BaseOptimiser
5
5
 
6
6
  class RMSPROP(BaseOptimiser):
7
7
  """
8
- The adaptive moment estimation optimiser. Is very robust and does not require a lot of tuning it's hyperparameters. A first order method and therefore does not use information on second gradients, i.e. the hessian matrix. Hence, does not require a lot of memory.
8
+ The Root Mean Square Propagation optimiser. An improvement over the ADAGRAD optimiser solving the diminishing learning rate problem. A first order method and therefore does not use information on second gradients, i.e. the hessian matrix. Hence, does not require a lot of memory.
9
9
 
10
10
  Args:
11
11
  learning_rate (float, optional): The learning rate of the optimiser. Must be positive. Defaults to 0.001.
@@ -0,0 +1,261 @@
1
+ import torch
2
+ from math import floor
3
+
4
+ from ..Kernels import _Base
5
+ from ....DeepLearning.Optimisers import ADAM
6
+ from ....DeepLearning.Optimisers._BaseOptimiser import BaseOptimiser
7
+ from ....Exceptions import NotFittedError
8
+
9
+
10
+ LAMBDAS = torch.tensor([0.41, 0.4, 0.37, 0.44, 0.39]).unsqueeze(-1)
11
+ COEFS = torch.tensor([-1854.8214151, 3516.89893646, 221.29346712, 128.12323805, -2010.49422654]).unsqueeze(-1)
12
+
13
+
14
+ class GaussianProcessClassifier:
15
+ """
16
+ Implements the Gaussian process classification model for binary classes. This model can be extended to multiclass classification by OvO or OvR. This implementation is adapted from the sklearn implementation and is based chapters 3 and 5 of on `this book <https://gaussianprocess.org/gpml/chapters/RW.pdf>`_.
17
+
18
+ Args:
19
+ covariance_function (:ref:`kernel_section_label`, optional): The kernel function expressing how similar are different samples.
20
+ noise (int | float, optional): The artificially added noise to the model. Is added as variance to each sample. Must be non-negative. Defaults to 0.
21
+ n_iter_laplace_mode (int, optional): The max amount of Newton iterations used to find the mode of the Laplace approximation. Must be a positive integer. Defaults to 100.
22
+ epsilon (float, optional): Implemented similarly to noise. Makes sure the covariance matrix is positive definite and hence invertible. Must be positive. Defaults to 1e-5. If one gets a RunTimeError for a matrix not being invertible, one should increase this parameter.
23
+ device (torch.device, optional): The device of all matrices. Defaults to torch.device("cpu").
24
+
25
+ Attributes:
26
+ n_features (int): The number of features. Available after fitting.
27
+ """
28
+ def __init__(self, covariance_function, noise=0, n_iter_laplace_mode=100, epsilon=1e-5, device=torch.device("cpu")):
29
+ if not isinstance(covariance_function, _Base):
30
+ raise TypeError("covariance_function must be from DLL.MachineLearning.Supervisedlearning.Kernels.")
31
+ if not isinstance(noise, int | float) or noise < 0:
32
+ raise ValueError("noise must be non-negative.")
33
+ if not isinstance(n_iter_laplace_mode, int) or n_iter_laplace_mode <= 0:
34
+ raise ValueError("n_iter_laplace_mode must be a positive integer.")
35
+ if not isinstance(epsilon, int | float) or epsilon <= 0:
36
+ raise ValueError("epsilon must be positive.")
37
+ if not isinstance(device, torch.device):
38
+ raise TypeError("device must be an instance of torch.device.")
39
+
40
+ self.covariance_function = covariance_function
41
+ self.noise = noise
42
+ self.n_iter_laplace_mode = n_iter_laplace_mode
43
+ self.epsilon = epsilon
44
+ self.device = device
45
+
46
+ def _get_covariance_matrix(self, X1, X2):
47
+ return self.covariance_function(X1, X2).to(X1.dtype).to(self.device)
48
+
49
+ def fit(self, X, y):
50
+ """
51
+ Fits the GaussianProcessClassifier model to the input data.
52
+
53
+ Args:
54
+ X (torch.Tensor of shape (n_samples, n_features)): The input data, where each row is a sample and each column is a feature.
55
+ y (torch.Tensor of shape (n_samples,)): The target values corresponding to each sample. Should be normalized to zero mean and one variance. Every element must be in [0, 1].
56
+ Returns:
57
+ None
58
+ Raises:
59
+ TypeError: If the input matrix or the target matrix is not a PyTorch tensor.
60
+ ValueError: If the input matrix or the target matrix is not the correct shape.
61
+ """
62
+ if not isinstance(X, torch.Tensor) or not isinstance(y, torch.Tensor):
63
+ raise TypeError("The input matrix and the target matrix must be a PyTorch tensor.")
64
+ if X.ndim != 2:
65
+ raise ValueError("The input matrix must be a 2 dimensional tensor.")
66
+ if y.ndim != 1 or len(y) != len(X):
67
+ raise ValueError("The targets must be 1 dimensional with the same number of samples as the input data")
68
+ if len(y) < 2:
69
+ raise ValueError("There must be atleast 2 samples.")
70
+ vals = torch.unique(y).numpy()
71
+ if set(vals) != {0, 1}:
72
+ raise ValueError("y must only contain the values in [0, 1].")
73
+
74
+ self.n_features = X.shape[1]
75
+ self.X = X
76
+ self.Y = y
77
+ self.prior_covariance_matrix = self._get_covariance_matrix(X, X) + (self.noise + self.epsilon) * torch.eye(len(X), device=self.device)
78
+ _, (self._pi, self._W_sr, self._L, _, _) = self._posterior_mode() # save necessary things for the predictions
79
+
80
+ def predict(self, X):
81
+ """
82
+ Applies the fitted GaussianProcessClassifier model to the input data, predicting the correct values.
83
+
84
+ Args:
85
+ X (torch.Tensor of shape (n_samples, n_features)): The input data to be regressed.
86
+ Returns:
87
+ mean, covariance (tuple[torch.Tensor of shape (n_samples,), torch.Tensor of shape (n_samples, n_samples)): A tuple containing the posterior mean and posterior covariance. As the prediction, one should use the mean.
88
+ Raises:
89
+ NotFittedError: If the GaussianProcessClassifier model has not been fitted before predicting.
90
+ TypeError: If the input matrix is not a PyTorch tensor.
91
+ ValueError: If the input matrix is not the correct shape.
92
+ """
93
+ if not hasattr(self, "prior_covariance_matrix"):
94
+ raise NotFittedError("GaussianProcessClassifier.fit() must be called before predicting.")
95
+ if not isinstance(X, torch.Tensor):
96
+ raise TypeError("The input matrix must be a PyTorch tensor.")
97
+ if X.ndim != 2 or X.shape[1] != self.n_features:
98
+ raise ValueError("The input matrix must be a 2 dimensional tensor with the same number of features as the fitted tensor.")
99
+
100
+ K = self._get_covariance_matrix(self.X, X)
101
+ f_star = K.T @ (self.Y - self._pi)
102
+ return torch.where(f_star > 0, 1, 0)
103
+
104
+ def predict_proba(self, X):
105
+ """
106
+ Applies the fitted GaussianProcessClassifier model to the input data, predicting the probabilities of each class.
107
+
108
+ Args:
109
+ X (torch.Tensor of shape (n_samples, n_features)): The input data to be regressed.
110
+ Returns:
111
+ probabilities (tuple[torch.Tensor of shape (n_samples,)): The probabilities that the class belongs to class 1.
112
+ Raises:
113
+ NotFittedError: If the GaussianProcessClassifier model has not been fitted before predicting.
114
+ TypeError: If the input matrix is not a PyTorch tensor.
115
+ ValueError: If the input matrix is not the correct shape.
116
+ """
117
+ if not hasattr(self, "prior_covariance_matrix"):
118
+ raise NotFittedError("GaussianProcessClassifier.fit() must be called before predicting.")
119
+ if not isinstance(X, torch.Tensor):
120
+ raise TypeError("The input matrix must be a PyTorch tensor.")
121
+ if X.ndim != 2 or X.shape[1] != self.n_features:
122
+ raise ValueError("The input matrix must be a 2 dimensional tensor with the same number of features as the fitted tensor.")
123
+
124
+ K = self._get_covariance_matrix(self.X, X)
125
+ f_star = K.T @ (self.Y - self._pi)
126
+ v = torch.linalg.solve(self._L, self._W_sr.unsqueeze(-1) * K)
127
+ var_f_star = torch.diag(self._get_covariance_matrix(X, X)) - torch.diag(v.T @ v)
128
+
129
+ alpha = 1 / (2 * var_f_star)
130
+ gamma = LAMBDAS * f_star
131
+ integrals = torch.sqrt(torch.pi / alpha) * torch.erf(gamma * torch.sqrt(alpha / (alpha + LAMBDAS ** 2))) / (2 * torch.sqrt(var_f_star * 2 * torch.pi))
132
+ pi_star = (COEFS * integrals).sum(axis=0) + 0.5 * COEFS.sum()
133
+ return pi_star
134
+
135
+ def log_marginal_likelihood(self):
136
+ """
137
+ Computes the log marginal likelihood of the current model. This value is used to optimize hyperparameters.
138
+
139
+ Returns:
140
+ log marginal likelihood (float): The log marginal likelihood of the current model.
141
+ """
142
+ if not hasattr(self, "prior_covariance_matrix"):
143
+ raise NotFittedError("GaussianProcessClassifier.fit() must be called before calculating the log marginal likelihood.")
144
+
145
+ return self._posterior_mode()[0]
146
+
147
+ def _posterior_mode(self):
148
+ # adapted from sklearn source code: https://github.com/scikit-learn/scikit-learn/blob/98ed9dc73a86f5f11781a0e21f24c8f47979ec67/sklearn/gaussian_process/_gpc.py#L269
149
+ f = self._f_cached if hasattr(self, "_f_cached") else torch.zeros_like(self.Y)
150
+ log_marginal_likelihood = -torch.inf
151
+ K = self.prior_covariance_matrix
152
+ for _ in range(self.n_iter_laplace_mode):
153
+ pi = 1 / (1 + torch.exp(-f))
154
+ W = pi * (1 - pi)
155
+ W_sr = torch.sqrt(W)
156
+ W_sr_K = W_sr.unsqueeze(-1) * K
157
+ B = torch.eye(len(W)) + W_sr_K * W_sr
158
+ L = torch.linalg.cholesky(B)
159
+ b = W * f + (self.Y - pi)
160
+ a = b - W_sr * torch.cholesky_solve((W_sr_K @ b).unsqueeze(-1), L).squeeze(-1)
161
+ f = K @ a
162
+ lml = -0.5 * a @ f - torch.log1p(torch.exp(-(self.Y * 2 - 1) * f)).sum() - torch.log(torch.diag(L)).sum()
163
+ if lml - log_marginal_likelihood < 1e-10:
164
+ break
165
+ log_marginal_likelihood = lml
166
+ self._f_cached = f
167
+ return log_marginal_likelihood, (pi, W_sr, L, b, a)
168
+
169
+ def _derivative(self, parameter_derivative):
170
+ K = self.prior_covariance_matrix
171
+ _, (pi, W_sr, L, b, a) = self._posterior_mode()
172
+ R = W_sr.unsqueeze(-1) * torch.cholesky_solve(torch.diag(W_sr), L)
173
+ C = torch.linalg.solve(L, W_sr.unsqueeze(-1) * K)
174
+ s_2 = -0.5 * (torch.diag(K) - torch.diag(C.T @ C)) * (pi * (1 - pi) * (1 - 2 * pi))
175
+ if parameter_derivative.ndim == 2:
176
+ C = parameter_derivative
177
+ s_1 = 0.5 * (a @ C) @ a - 0.5 * R.T.ravel() @ C.ravel()
178
+ b = C @ (self.Y - pi)
179
+ s_3 = b - K @ (R @ b)
180
+ derivative = (s_1 + s_2 @ s_3).unsqueeze(-1)
181
+ else:
182
+ d = parameter_derivative.shape[0]
183
+ a = a.view(1, -1)
184
+ s_1 = 0.5 * (a @ parameter_derivative @ a.transpose(1, 0)).squeeze()
185
+ s_1 -= 0.5 * (R.ravel() * parameter_derivative.view(d, -1)).sum(dim=1)
186
+
187
+ Y_minus_pi = (self.Y - pi).unsqueeze(0)
188
+ b = torch.matmul(parameter_derivative, Y_minus_pi.unsqueeze(-1)).squeeze(-1)
189
+ Rb = (R.T @ b.T).T
190
+ s_3 = b - (K @ Rb.T).T
191
+
192
+ s_2 = s_2.unsqueeze(0)
193
+ s_2_s_3 = (s_2 * s_3).sum(dim=1)
194
+
195
+ derivative = s_1 + s_2_s_3
196
+ return -derivative
197
+
198
+ def train_kernel(self, epochs=10, optimiser=None, callback_frequency=1, verbose=False):
199
+ """
200
+ Trains the current covariance function parameters by maximizing the log marginal likelihood.
201
+
202
+ Args:
203
+ epochs (int, optional): The number of optimisation rounds. Must be a positive integer. Defaults to 10.
204
+ optimiser (:ref:`optimisers_section_label` | None, optional): The optimiser used for training the model. If None, the Adam optimiser is used.
205
+ callback_frequency (int, optional): The number of iterations between printing info from training. Must be a positive integer. Defaults to 1, which means that every iteration, info is printed assuming verbose=True.
206
+ verbose (bool, optional): If True, prints the log marginal likelihood of the model during training. Defaults to False.
207
+
208
+ Returns:
209
+ history (dict[str, torch.Tensor], the tensor is floor(epochs / callback_frequency) long.): A dictionary tracking the evolution of the log marginal likelihood at intervals defined by callback_frequency. The tensor can be accessed with history["log marginal likelihood"].
210
+
211
+ Raises:
212
+ NotFittedError: If the GaussianProcessClassifier model has not been fitted before training the kernel.
213
+ TypeError: If the parameters are of wrong type.
214
+ ValueError: If epochs is not a positive integer.
215
+ """
216
+ if not hasattr(self, "prior_covariance_matrix"):
217
+ raise NotFittedError("GaussianProcessClassifier.fit() must be called before calculating the log marginal likelihood.")
218
+ if not isinstance(epochs, int) or epochs <= 0:
219
+ raise ValueError("epochs must be a positive integer.")
220
+ if not isinstance(optimiser, BaseOptimiser) and optimiser is not None:
221
+ raise TypeError("optimiser must be from DLL.DeepLearning.Optimisers")
222
+ if not isinstance(verbose, bool):
223
+ raise TypeError("verbose must be a boolean.")
224
+
225
+ optimiser = ADAM() if optimiser is None else optimiser
226
+ optimiser.initialise_parameters(list(self.covariance_function.parameters().values()))
227
+
228
+ history = {"log marginal likelihood": torch.zeros(floor(epochs / callback_frequency))}
229
+
230
+ for epoch in range(epochs):
231
+ optimiser.zero_grad()
232
+
233
+ # calculate the derivatives
234
+ self.covariance_function.update(self._derivative, self.X)
235
+
236
+ # update the parameters
237
+ optimiser.update_parameters()
238
+
239
+ self.prior_covariance_matrix = self._get_covariance_matrix(self.X, self.X) + (self.noise + self.epsilon) * torch.eye(len(self.X), device=self.device)
240
+ if epoch % callback_frequency == 0:
241
+ lml = self.log_marginal_likelihood().item()
242
+ history["log marginal likelihood"][int(epoch / callback_frequency)] = lml
243
+ if verbose:
244
+ params = {}
245
+ for key, param in self.covariance_function.parameters().items():
246
+ if len(param) == 1:
247
+ params[key] = round(param.item(), 3)
248
+ continue
249
+ for i, param_ in enumerate(param):
250
+ params[key + "_" + str(i + 1)] = round(param_.item(), 3)
251
+ print(f"Epoch: {epoch + 1} - Log marginal likelihood: {lml} - Parameters: {params}")
252
+
253
+ _, (self._pi, self._W_sr, self._L, _, _) = self._posterior_mode() # save necessary things for the predictions
254
+ return history
255
+
256
+ # def is_positive_definite(matrix):
257
+ # print("-----------------")
258
+ # if not torch.allclose(matrix, matrix.T):
259
+ # print(f"Matrix not symmetric: {torch.linalg.norm(matrix.T - matrix)}")
260
+ # eigenvalues = torch.linalg.eigvalsh(matrix)
261
+ # print(f"Minimum eigenvalue: {torch.min(eigenvalues).item()}")
@@ -1,11 +1,11 @@
1
1
  import torch
2
2
  from math import floor
3
+ from warnings import warn
3
4
 
4
5
  from ..Kernels import _Base
5
6
  from ....DeepLearning.Optimisers import ADAM
6
7
  from ....DeepLearning.Optimisers._BaseOptimiser import BaseOptimiser
7
8
  from ....Exceptions import NotFittedError
8
- from ....Data.Metrics import _round_dictionary
9
9
 
10
10
 
11
11
  class GaussianProcessRegressor:
@@ -16,7 +16,7 @@ class GaussianProcessRegressor:
16
16
  covariance_function (:ref:`kernel_section_label`, optional): The kernel function expressing how similar are different samples.
17
17
  noise (int | float, optional): The artificially added noise to the model. Is added as variance to each sample. Must be non-negative. Defaults to 0.
18
18
  epsilon (float, optional): Implemented similarly to noise. Makes sure the covariance matrix is positive definite and hence invertible. Must be positive. Defaults to 1e-5. If one gets a RunTimeError for a matrix not being invertible, one should increase this parameter.
19
- device (torch.device, optional): The device of all matricies. Defaults to torch.device("cpu").
19
+ device (torch.device, optional): The device of all matrices. Defaults to torch.device("cpu").
20
20
 
21
21
  Attributes:
22
22
  n_features (int): The number of features. Available after fitting.
@@ -25,7 +25,7 @@ class GaussianProcessRegressor:
25
25
  if not isinstance(covariance_function, _Base):
26
26
  raise TypeError("covariance_function must be from DLL.MachineLearning.Supervisedlearning.Kernels.")
27
27
  if not isinstance(noise, int | float) or noise < 0:
28
- raise ValueError("noise must b non-negative.")
28
+ raise ValueError("noise must be non-negative.")
29
29
  if not isinstance(epsilon, int | float) or epsilon <= 0:
30
30
  raise ValueError("epsilon must be positive.")
31
31
  if not isinstance(device, torch.device):
@@ -60,18 +60,19 @@ class GaussianProcessRegressor:
60
60
  raise ValueError("The targets must be 1 dimensional with the same number of samples as the input data")
61
61
  if len(y) < 2:
62
62
  raise ValueError("There must be atleast 2 samples.")
63
- # variance = torch.var(y)
64
- # mean = torch.mean(y)
65
- # if not torch.allclose(variance, torch.ones_like(variance)):
66
- # raise ValueError("y must have one variance. Use DLL.Data.Preprocessing.StandardScaler to scale the data.")
67
- # if not torch.allclose(mean, torch.zeros_like(mean)):
68
- # raise ValueError("y must have zero mean. Use DLL.Data.Preprocessing.StandardScaler to scale the data.")
63
+ variance = torch.var(y)
64
+ mean = torch.mean(y)
65
+ if not torch.allclose(variance, torch.ones_like(variance)):
66
+ warn("y should have one variance for optimal results. Use DLL.Data.Preprocessing.StandardScaler to scale the data.")
67
+ if not torch.allclose(mean, torch.zeros_like(mean)):
68
+ warn("y should have zero mean for optimal results. Use DLL.Data.Preprocessing.StandardScaler to scale the data.")
69
69
 
70
70
  self.n_features = X.shape[1]
71
71
  self.X = X
72
72
  self.Y = y.unsqueeze(dim=1)
73
73
  self.prior_covariance_matrix = self._get_covariance_matrix(X, X) + (self.noise + self.epsilon) * torch.eye(len(X), device=self.device)
74
- self.inverse_prior_covariance_matrix = torch.linalg.inv(self.prior_covariance_matrix)
74
+ self._L = torch.linalg.cholesky(self.prior_covariance_matrix)
75
+ self._alpha = torch.cholesky_solve(self.Y, self._L)
75
76
 
76
77
  def predict(self, X):
77
78
  """
@@ -86,7 +87,7 @@ class GaussianProcessRegressor:
86
87
  TypeError: If the input matrix is not a PyTorch tensor.
87
88
  ValueError: If the input matrix is not the correct shape.
88
89
  """
89
- if not hasattr(self, "inverse_prior_covariance_matrix"):
90
+ if not hasattr(self, "prior_covariance_matrix"):
90
91
  raise NotFittedError("GaussianProcessRegressor.fit() must be called before predicting.")
91
92
  if not isinstance(X, torch.Tensor):
92
93
  raise TypeError("The input matrix must be a PyTorch tensor.")
@@ -95,8 +96,9 @@ class GaussianProcessRegressor:
95
96
 
96
97
  k_1 = self._get_covariance_matrix(self.X, X)
97
98
  k_2 = self._get_covariance_matrix(X, X) + (self.noise + self.epsilon) * torch.eye(len(X), device=self.device)
98
- mean = k_1.T @ self.inverse_prior_covariance_matrix @ self.Y
99
- posterior_covariance = k_2 - k_1.T @ self.inverse_prior_covariance_matrix @ k_1
99
+ mean = (k_1.T @ self._alpha).squeeze(-1)
100
+ V = torch.linalg.solve_triangular(self._L, k_1, upper=False)
101
+ posterior_covariance = k_2 - V.T @ V
100
102
  return mean, posterior_covariance
101
103
 
102
104
  def log_marginal_likelihood(self):
@@ -106,13 +108,21 @@ class GaussianProcessRegressor:
106
108
  Returns:
107
109
  log marginal likelihood (float): The log marginal likelihood of the current model.
108
110
  """
109
- if not hasattr(self, "inverse_prior_covariance_matrix"):
111
+ if not hasattr(self, "prior_covariance_matrix"):
110
112
  raise NotFittedError("GaussianProcessRegressor.fit() must be called before calculating the log marginal likelihood.")
111
113
 
112
- L = torch.linalg.cholesky(self.prior_covariance_matrix)
113
- alpha = torch.cholesky_solve(self.Y, L)
114
- lml = -0.5 * self.Y.T @ alpha - torch.sum(torch.log(torch.diagonal(L))) - 0.5 * len(self.Y) * torch.log(torch.tensor(2 * torch.pi, device=self.device))
115
- return lml.item()
114
+ lml = -0.5 * self.Y.T @ self._alpha - torch.sum(torch.log(torch.diagonal(self._L))) - 0.5 * len(self.Y) * torch.log(torch.tensor(2 * torch.pi, dtype=self.Y.dtype, device=self.device))
115
+ return lml
116
+
117
+ def _derivative(self, parameter_derivative):
118
+ inner = self._alpha @ self._alpha.T - torch.cholesky_inverse(self._L)
119
+ # derivative = 0.5 * torch.trace(inner @ parameter_derivative).unsqueeze(-1)
120
+ if parameter_derivative.dim() == 2:
121
+ derivative = 0.5 * torch.trace(inner @ parameter_derivative).unsqueeze(-1)
122
+ elif parameter_derivative.dim() == 3:
123
+ derivative = 0.5 * torch.einsum("ij,kji->k", inner, parameter_derivative)
124
+ # minus sign, since goal is to maximise the log_marginal_likelihood
125
+ return -derivative
116
126
 
117
127
  def train_kernel(self, epochs=10, optimiser=None, callback_frequency=1, verbose=False):
118
128
  """
@@ -132,7 +142,7 @@ class GaussianProcessRegressor:
132
142
  TypeError: If the parameters are of wrong type.
133
143
  ValueError: If epochs is not a positive integer.
134
144
  """
135
- if not hasattr(self, "inverse_prior_covariance_matrix"):
145
+ if not hasattr(self, "prior_covariance_matrix"):
136
146
  raise NotFittedError("GaussianProcessRegressor.fit() must be called before calculating the log marginal likelihood.")
137
147
  if not isinstance(epochs, int) or epochs <= 0:
138
148
  raise ValueError("epochs must be a positive integer.")
@@ -147,29 +157,19 @@ class GaussianProcessRegressor:
147
157
  history = {"log marginal likelihood": torch.zeros(floor(epochs / callback_frequency))}
148
158
 
149
159
  for epoch in range(epochs):
150
- # form the derivative function
151
- def derivative(parameter_derivative):
152
- derivative = 0.5 * self.Y.T @ self.inverse_prior_covariance_matrix @ parameter_derivative @ self.inverse_prior_covariance_matrix @ self.Y
153
-
154
- if parameter_derivative.ndim == 2:
155
- derivative = derivative.squeeze(1)
156
- derivative -= 0.5 * torch.trace(self.inverse_prior_covariance_matrix @ parameter_derivative)
157
- else:
158
- derivative = derivative.squeeze((1, 2))
159
- derivative -= 0.5 * (self.inverse_prior_covariance_matrix @ parameter_derivative).diagonal(dim1=1, dim2=2).sum(dim=-1)
160
- # minus sign, since goal is to maximise the log_marginal_likelihood
161
- return -derivative
160
+ optimiser.zero_grad()
162
161
 
163
162
  # calculate the derivatives
164
- self.covariance_function.update(derivative, self.X)
163
+ self.covariance_function.update(self._derivative, self.X)
165
164
 
166
165
  # update the parameters
167
166
  optimiser.update_parameters()
168
167
 
169
168
  self.prior_covariance_matrix = self._get_covariance_matrix(self.X, self.X) + (self.noise + self.epsilon) * torch.eye(len(self.X), device=self.device)
170
- self.inverse_prior_covariance_matrix = torch.linalg.inv(self.prior_covariance_matrix)
169
+ self._L = torch.linalg.cholesky(self.prior_covariance_matrix)
170
+ self._alpha = torch.cholesky_solve(self.Y, self._L)
171
171
  if epoch % callback_frequency == 0:
172
- lml = self.log_marginal_likelihood()
172
+ lml = self.log_marginal_likelihood().item()
173
173
  history["log marginal likelihood"][int(epoch / callback_frequency)] = lml
174
174
  if verbose:
175
175
  params = {}
@@ -0,0 +1,2 @@
1
+ from ._GaussianProcessRegressor import GaussianProcessRegressor
2
+ from ._GaussianProcessClassifier import GaussianProcessClassifier
@@ -185,8 +185,8 @@ class RBF(_Base):
185
185
  derivative_covariance_sigma = self.derivative_sigma(X, X)
186
186
  derivative_covariance_corr_len = self.derivative_corr_len(X, X)
187
187
 
188
- self.sigma.grad = derivative_function(derivative_covariance_sigma).to(dtype=self.sigma.dtype)
189
- self.correlation_length.grad = derivative_function(derivative_covariance_corr_len).to(dtype=self.correlation_length.dtype)
188
+ self.sigma.grad += derivative_function(derivative_covariance_sigma).to(dtype=self.sigma.dtype)
189
+ self.correlation_length.grad += derivative_function(derivative_covariance_corr_len).to(dtype=self.correlation_length.dtype)
190
190
 
191
191
  def parameters(self):
192
192
  """
@@ -273,7 +273,7 @@ class Linear(_Base):
273
273
  self.sigma = self.sigma.to(X1.device)
274
274
  self.sigma_bias = self.sigma_bias.to(X1.device)
275
275
 
276
- return self.sigma_bias ** 2 + self.sigma ** 2 * X1 @ X2.T
276
+ return self.sigma_bias + self.sigma ** 2 * X1 @ X2.T
277
277
 
278
278
  def derivative_sigma(self, X1, X2):
279
279
  """
@@ -294,7 +294,8 @@ class Linear(_Base):
294
294
  :meta private:
295
295
  """
296
296
  if not self.train_sigma_bias: return torch.zeros((len(X1), len(X2)), dtype=X1.dtype, device=X1.device)
297
- val = (2 * self.sigma_bias).to(X1.dtype)
297
+ # val = (2 * self.sigma_bias).to(X1.dtype)
298
+ val = torch.ones((len(X1), len(X2)), dtype=X1.dtype, device=X1.device)
298
299
  # descrete = -self(X1, X2)
299
300
  # eps = 1e-6
300
301
  # self.sigma_bias += eps
@@ -310,8 +311,8 @@ class Linear(_Base):
310
311
  derivative_covariance_sigma = self.derivative_sigma(X, X)
311
312
  derivative_covariance_sigma_bias = self.derivative_sigma_bias(X, X)
312
313
 
313
- self.sigma.grad = derivative_function(derivative_covariance_sigma).to(dtype=self.sigma.dtype)
314
- self.sigma_bias.grad = derivative_function(derivative_covariance_sigma_bias).to(dtype=self.sigma_bias.dtype)
314
+ self.sigma.grad += derivative_function(derivative_covariance_sigma).to(dtype=self.sigma.dtype)
315
+ self.sigma_bias.grad += derivative_function(derivative_covariance_sigma_bias).to(dtype=self.sigma_bias.dtype)
315
316
 
316
317
  def parameters(self):
317
318
  """
@@ -404,7 +405,7 @@ class WhiteGaussian(_Base):
404
405
  """
405
406
  derivative_covariance_sigma = self.derivative_sigma(X, X)
406
407
 
407
- self.sigma.grad = derivative_function(derivative_covariance_sigma).to(dtype=self.sigma.dtype)
408
+ self.sigma.grad += derivative_function(derivative_covariance_sigma).to(dtype=self.sigma.dtype)
408
409
 
409
410
  def parameters(self):
410
411
  """
@@ -549,9 +550,9 @@ class Periodic(_Base):
549
550
  derivative_covariance_corr_len = self.derivative_corr_len(X, X)
550
551
  derivative_covariance_period = self.derivative_period(X, X)
551
552
 
552
- self.sigma.grad = derivative_function(derivative_covariance_sigma).to(dtype=self.sigma.dtype)
553
- self.correlation_length.grad = derivative_function(derivative_covariance_corr_len).to(dtype=self.correlation_length.dtype)
554
- self.period.grad = derivative_function(derivative_covariance_period).to(dtype=self.period.dtype)
553
+ self.sigma.grad += derivative_function(derivative_covariance_sigma).to(dtype=self.sigma.dtype)
554
+ self.correlation_length.grad += derivative_function(derivative_covariance_corr_len).to(dtype=self.correlation_length.dtype)
555
+ self.period.grad += derivative_function(derivative_covariance_period).to(dtype=self.period.dtype)
555
556
 
556
557
  def parameters(self):
557
558
  """
@@ -696,9 +697,9 @@ class RationalQuadratic(_Base):
696
697
  derivative_covariance_corr_len = self.derivative_corr_len(X, X)
697
698
  derivative_covariance_alpha = self.derivative_alpha(X, X)
698
699
 
699
- self.sigma.grad = derivative_function(derivative_covariance_sigma).to(dtype=self.sigma.dtype)
700
- self.correlation_length.grad = derivative_function(derivative_covariance_corr_len).to(dtype=self.correlation_length.dtype)
701
- self.alpha.grad = derivative_function(derivative_covariance_alpha).to(dtype=self.alpha.dtype)
700
+ self.sigma.grad += derivative_function(derivative_covariance_sigma).to(dtype=self.sigma.dtype)
701
+ self.correlation_length.grad += derivative_function(derivative_covariance_corr_len).to(dtype=self.correlation_length.dtype)
702
+ self.alpha.grad += derivative_function(derivative_covariance_alpha).to(dtype=self.alpha.dtype)
702
703
 
703
704
  def parameters(self):
704
705
  """
@@ -837,8 +838,8 @@ class Matern(_Base):
837
838
  derivative_covariance_sigma = self.derivative_sigma(X, X)
838
839
  derivative_covariance_corr_len = self.derivative_corr_len(X, X)
839
840
 
840
- self.sigma.grad = derivative_function(derivative_covariance_sigma).to(dtype=self.sigma.dtype)
841
- self.correlation_length.grad = derivative_function(derivative_covariance_corr_len).to(dtype=self.correlation_length.dtype)
841
+ self.sigma.grad += derivative_function(derivative_covariance_sigma).to(dtype=self.sigma.dtype)
842
+ self.correlation_length.grad += derivative_function(derivative_covariance_corr_len).to(dtype=self.correlation_length.dtype)
842
843
 
843
844
  def parameters(self):
844
845
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyDLLib
3
- Version: 1.0.1
3
+ Version: 1.0.3
4
4
  Summary: A deep and machine learning library. Made for learning purposes and ease of understanding.
5
5
  Author-email: Aatu Selkee <aatu.selkee@gmail.com>
6
6
  Project-URL: Homepage, https://naapeli.github.io/deep-learning-library/index.html
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyDLLib
3
- Version: 1.0.1
3
+ Version: 1.0.3
4
4
  Summary: A deep and machine learning library. Made for learning purposes and ease of understanding.
5
5
  Author-email: Aatu Selkee <aatu.selkee@gmail.com>
6
6
  Project-URL: Homepage, https://naapeli.github.io/deep-learning-library/index.html
@@ -71,6 +71,7 @@ DLL/MachineLearning/SupervisedLearning/__init__.py
71
71
  DLL/MachineLearning/SupervisedLearning/Calibration/_CalibratedClassifier.py
72
72
  DLL/MachineLearning/SupervisedLearning/Calibration/_IsotonicRegression.py
73
73
  DLL/MachineLearning/SupervisedLearning/Calibration/__init__.py
74
+ DLL/MachineLearning/SupervisedLearning/GaussianProcesses/_GaussianProcessClassifier.py
74
75
  DLL/MachineLearning/SupervisedLearning/GaussianProcesses/_GaussianProcessRegressor.py
75
76
  DLL/MachineLearning/SupervisedLearning/GaussianProcesses/__init__.py
76
77
  DLL/MachineLearning/SupervisedLearning/LinearModels/TimeSeries.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "PyDLLib"
7
- version = "1.0.1"
7
+ version = "1.0.3"
8
8
  authors = [
9
9
  {name = "Aatu Selkee", email = "aatu.selkee@gmail.com"},
10
10
  ]
@@ -1 +0,0 @@
1
- from ._GaussianProcessRegressor import GaussianProcessRegressor
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes