Skip to content

Commit 3d4bd55

Browse files
verbosity for mmphi, unique
1 parent b482432 commit 3d4bd55

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "spotpython"
10-
version = "0.29.19"
10+
version = "0.29.20"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotpython/light/regression/nn_funnel_regressor.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,22 @@ def __init__(
110110
if self.hparams.l1 < 8:
111111
raise ValueError("l1 must be at least 8")
112112

113-
114113
layers = []
115114
in_features = self._L_in
116115
hidden_size = self.hparams.l1
117116
output_dim = self._L_out
118117

119118
for i in range(self.hparams.num_layers):
120119
out_features = max(hidden_size // 2, 8) # Enforce minimum of 8 units
121-
120+
122121
layers.append(nn.Linear(in_features, hidden_size))
123-
122+
124123
if self.hparams.batch_norm:
125124
layers.append(nn.BatchNorm1d(hidden_size)) # Add BatchNorm if enabled
126-
125+
127126
layers.append(self.hparams.act_fn)
128127
layers.append(nn.Dropout(self.hparams.dropout_prob))
129-
128+
130129
in_features = hidden_size
131130
hidden_size = out_features
132131

@@ -264,7 +263,7 @@ def configure_optimizers(self) -> torch.optim.Optimizer:
264263
"""
265264
# optimizer = torch.optim.Adam(self.parameters(), lr=self.learning_rate)
266265
optimizer = optimizer_handler(optimizer_name=self.hparams.optimizer, params=self.parameters(), lr_mult=self.hparams.lr_mult)
267-
266+
268267
# If the lr_sched hyperparameter is set to True, we will use a learning rate scheduler.
269268
if self.hparams.lr_sched:
270269
num_milestones = 3 # Number of milestones to divide the epochs

src/spotpython/utils/sampling.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def mm(X1: np.ndarray, X2: np.ndarray, p: Optional[float] = 1.0) -> int:
311311
return c[idx]
312312

313313

314-
def mmphi(X: np.ndarray, q: Optional[float] = 2.0, p: Optional[float] = 1.0) -> float:
314+
def mmphi(X: np.ndarray, q: Optional[float] = 2.0, p: Optional[float] = 1.0, verbosity=0) -> float:
315315
"""
316316
Calculates the Morris-Mitchell sampling plan quality criterion.
317317
@@ -324,6 +324,9 @@ def mmphi(X: np.ndarray, q: Optional[float] = 2.0, p: Optional[float] = 1.0) ->
324324
p (float, optional):
325325
The distance norm to use. For example, p=1 is Manhattan (L1),
326326
p=2 is Euclidean (L2). Defaults to 1.0.
327+
verbosity (int, optional):
328+
If set to 1, prints additional information about the computation.
329+
Defaults to 0 (no additional output).
327330
328331
Returns:
329332
float:
@@ -358,8 +361,15 @@ def mmphi(X: np.ndarray, q: Optional[float] = 2.0, p: Optional[float] = 1.0) ->
358361
>>> print(quality)
359362
# This value indicates how well points are spread out, with smaller being better.
360363
"""
364+
# check that X has unique rows
365+
if X.shape[0] != len(np.unique(X, axis=0)):
366+
# issue a warning if there are duplicate rows
367+
print("Warning: X contains duplicate rows. This may affect the space-fillingness metric.")
368+
# make X unique
369+
X = np.unique(X, axis=0)
361370
# Compute the distance multiplicities: J, and unique distances: d
362371
J, d = jd(X, p)
372+
print(f"J: {J}, d: {d}") if verbosity > 0 else None
363373

364374
# Summation of J[i] * d[i]^(-q), then raised to 1/q
365375
# This follows the Morris-Mitchell definition.

0 commit comments

Comments
 (0)