forked from SMTorg/smt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter column indices of sparse matrix to ensure non-negativity
In Issue SMTorg#573, I observed that `scipy`s compressed sparse column matrix was throwing an exception about specification of negative indices. I traced this issue to the column specification in the C++ implementation of RMTB. I could not figure out what precisely was going wrong. However, by simply replacing all negative column indices with zeros, I found that the unit tests pass. This is in no way a permanent solution, but given the lack of shared understanding of this code, it is preferable to it being fully nonfunctional. While we're at it, replace all internal `int`s by `long` in order to support larger model sizes, similar to the diff made in RMTC.
- Loading branch information
1 parent
e7829ce
commit ef3c381
Showing
2 changed files
with
114 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from math import pi as π | ||
import numpy as np | ||
from smt.surrogate_models import RMTB | ||
|
||
|
||
dimension = 2 | ||
|
||
|
||
def generate_sine_surface_data(samples=20): | ||
training_points = np.full(shape=(samples, dimension), fill_value=np.nan) | ||
training_values = np.full(shape=samples, fill_value=np.nan) | ||
|
||
rng = np.random.default_rng(12345) | ||
for i in range(samples): | ||
x = rng.uniform(-1, 1, dimension) | ||
training_points[i, :] = x | ||
v = 1 | ||
for j in range(dimension): | ||
v *= np.sin(π * x[j]) | ||
training_values[i] = v | ||
return training_points, training_values | ||
|
||
|
||
def test_rmtb_surrogate_model(): | ||
training_points, training_values = generate_sine_surface_data() | ||
limits = np.full(shape=(dimension, 2), fill_value=np.nan) | ||
for i in range(dimension): | ||
limits[i, 0] = -1 | ||
limits[i, 1] = 1 | ||
|
||
model = RMTB( | ||
xlimits=limits, | ||
) | ||
model.set_training_values(training_points, training_values) | ||
model.train() | ||
computed_values = model.predict_values(training_points) | ||
for i in range(len(computed_values)): | ||
expected = training_values[i] | ||
# TODO: Fix the shape of the results: | ||
computed = computed_values[i][0] | ||
assert np.isclose(expected, computed, atol=0.2) |