Skip to content

Commit

Permalink
Fixes failing tests due to scipy version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtsap committed May 9, 2024
1 parent 05644a5 commit 85aee9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/UQpy/sampling/stratified_sampling/strata/VoronoiStrata.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,18 @@ def sample_strata(self, nsamples_per_stratum, random_state):

# Compute volume of each delaunay
volume = list()
for i in range(len(delaunay_obj.vertices)):
vert = delaunay_obj.vertices[i]
for i in range(len(delaunay_obj.simplices)):
vert = delaunay_obj.simplices[i]
ch = ConvexHull(seed_and_vertices[vert])
volume.append(ch.volume)

temp_prob = np.array(volume) / sum(volume)
a = list(range(len(delaunay_obj.vertices)))
a = list(range(len(delaunay_obj.simplices)))
for k in range(int(nsamples_per_stratum[j])):
simplex = random_state.choice(a, p=temp_prob)

new_samples = SimplexSampling(
nodes=seed_and_vertices[delaunay_obj.vertices[simplex]],
nodes=seed_and_vertices[delaunay_obj.simplices[simplex]],
nsamples=1,
random_state=self.random_state,
).samples
Expand All @@ -205,15 +205,15 @@ def compute_centroids(self):

for j in range(self.mesh.nsimplex):
try:
ConvexHull(self.points[self.mesh.vertices[j]])
ConvexHull(self.points[self.mesh.simplices[j]])
self.mesh.centroids[j, :], self.mesh.volumes[j] = \
DelaunayStrata.compute_delaunay_centroid_volume(self.points[self.mesh.vertices[j]])
DelaunayStrata.compute_delaunay_centroid_volume(self.points[self.mesh.simplices[j]])
except qhull.QhullError:
self.mesh.centroids[j, :], self.mesh.volumes[j] = (np.mean(self.points[self.mesh.vertices[j]]), 0,)

def initialize(self, samples_number, training_points):
self.add_boundary_points_and_construct_delaunay(samples_number, training_points)
self.mesh.old_vertices = self.mesh.vertices.copy()
self.mesh.old_vertices = self.mesh.simplices.copy()

def add_boundary_points_and_construct_delaunay(
self, samples_number, training_points
Expand Down Expand Up @@ -377,7 +377,7 @@ def _update_strata(self, new_point, samples_u01):
p_ = new_point.shape[0]
# Update the matrices to have recognize the new point
self.points_to_samplesU01 = np.hstack([self.points_to_samplesU01, np.arange(i_, i_ + p_)])
self.mesh.old_vertices = self.mesh.vertices
self.mesh.old_vertices = self.mesh.simplices

# Update the Delaunay triangulation mesh to include the new point.
self.mesh.add_points(new_point)
Expand Down
6 changes: 2 additions & 4 deletions tests/unit_tests/sampling/test_refined_stratified.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from beartype.roar import BeartypeCallHintPepParamException
from beartype.roar import BeartypeCallHintPepParamException, BeartypeCallHintParamViolation

from UQpy import GaussianProcessRegression, LinearRegression
from UQpy.utilities.kernels.euclidean_kernels.RBF import RBF
Expand Down Expand Up @@ -180,11 +180,9 @@ def test_rss_kriging_object():
x = TrueStratifiedSampling(distributions=marginals, strata_object=strata, nsamples_per_stratum=1, random_state=1)
model = PythonModel(model_script='python_model_function.py', model_object_name="y_func")
rmodel = RunModel(model=model)
with pytest.raises(NotImplementedError):
with pytest.raises(BeartypeCallHintParamViolation):
refinement = GradientEnhancedRefinement(strata=x.strata_object, runmodel_object=rmodel,
surrogate="abc")
RefinedStratifiedSampling(stratified_sampling=x, nsamples=6, samples_per_iteration=2,
refinement_algorithm=refinement)


def test_nsamples():
Expand Down

0 comments on commit 85aee9e

Please sign in to comment.