Skip to content

Commit

Permalink
Fixes minor static code analysis issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtsap committed May 9, 2024
1 parent fa8f5de commit d12f199
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/UQpy/sensitivity/MorrisSensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _compute_elementary_effects(self, trajectories_physical_space):
self.runmodel_object.run(samples=samples, append_samples=False)
qoi = np.array(self.runmodel_object.qoi_list)
el_effect = np.zeros((self.dimension,))
perms = [np.argwhere(bi != 0.0)[0, 0] for bi in (samples[1:] - samples[:-1])]
perms = [np.argwhere(not np.isclose(bi, 0.0))[0, 0] for bi in (samples[1:] - samples[:-1])]
for count_d, d in enumerate(perms):
el_effect[d] = (qoi[count_d + 1] - qoi[count_d]) / self.delta
elementary_effects.append(el_effect)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ def predict(self, points, return_std: bool = False, hyperparameters: list = None
else:
mu1 = np.einsum("ij,jk->ik", fx, self.beta)

self.kernel.kernel_parameter = kernelparameters[:-1]
sigma = kernelparameters[-1]
if kernelparameters is not None:
self.kernel.kernel_parameter = kernelparameters[:-1]
sigma = kernelparameters[-1]

k = sigma**2*self.kernel.calculate_kernel_matrix(x=x_, s=s_)
y = mu1 + k @ alpha_
Expand Down
2 changes: 1 addition & 1 deletion src/UQpy/utilities/Utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def correlation_distortion(dist_object, rho):
:rtype: float
"""

if rho == 1.0:
if np.isclose(rho, 1.0):
rho = 0.999
n = 512
zmax = 8
Expand Down
6 changes: 3 additions & 3 deletions src/UQpy/utilities/kernels/euclidean_kernels/Matern.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def __init__(self, kernel_parameter: Union[int, float] = 1, nu=1.5):
def calculate_kernel_matrix(self, x, s):
l = self.kernel_parameter
stack = cdist(x / l, s / l, metric='euclidean')
if self.nu == 0.5:
if np.isclose(self.nu, 0.5):
self.kernel_matrix = np.exp(-np.abs(stack))
elif self.nu == 1.5:
elif np.isclose(self.nu,1.5):
self.kernel_matrix = (1 + np.sqrt(3) * stack) * np.exp(-np.sqrt(3) * stack)
elif self.nu == 2.5:
elif np.isclose(self.nu, 2.5):
self.kernel_matrix = (1 + np.sqrt(5) * stack + 5 * (stack ** 2) / 3) * np.exp(-np.sqrt(5) * stack)
elif self.nu == np.inf:
self.kernel_matrix = np.exp(-(stack ** 2) / 2)
Expand Down

0 comments on commit d12f199

Please sign in to comment.