Skip to content

Commit 2b6ae85

Browse files
Niharika KarnikNiharika Karnik
authored andcommitted
Fixing Some of the issues before merge possible
1 parent 3a24e9c commit 2b6ae85

File tree

11 files changed

+65
-97
lines changed

11 files changed

+65
-97
lines changed

examples/basis_comparison.ipynb

Lines changed: 12 additions & 12 deletions
Large diffs are not rendered by default.

examples/cross_validation.ipynb

Lines changed: 24 additions & 8 deletions
Large diffs are not rendered by default.

examples/functional_constraints_class.ipynb

Lines changed: 12 additions & 19 deletions
Large diffs are not rendered by default.

examples/pysensors_overview.ipynb

Lines changed: 12 additions & 12 deletions
Large diffs are not rendered by default.

pysensors/basis/_custom.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,19 @@ def __init__(self, U, n_basis_modes=10, **kwargs):
3232
kwargs : Not defined but added to remain consistent with prior basis functions.
3333
"""
3434
if isinstance(n_basis_modes, int) and n_basis_modes > 0:
35-
super(Custom, self).__init__() # n_components=n_basis_modes, **kwargs
35+
super(Custom, self).__init__()
3636
self._n_basis_modes = n_basis_modes
3737
self.custom_basis_ = U
3838
else:
3939
raise ValueError("n_basis_modes must be a positive integer.")
4040

41-
def fit(self, X):
41+
def fit(self):
4242
"""
43-
Parameters
44-
----------
45-
X : array-like, shape (n_samples, n_features)
46-
The training data.
47-
4843
Returns
4944
-------
5045
self : instance
5146
"""
52-
# self.basis_matrix_ = self.custom_basis_[
53-
# :,: self.n_basis_modes] @ self.custom_basis_[
54-
# :,: self.n_basis_modes].T @ X[
55-
# : self.n_basis_modes, :].T.copy()
56-
# self.basis_matrix_ = self.custom_basis_ @ self.custom_basis_.T @ X[
57-
# : self.n_basis_modes, :].T.copy()
5847
self.basis_matrix_ = self.custom_basis_[:, : self.n_basis_modes]
59-
# self.basis_matrix_ = (X @ self.custom_basis_[
60-
# :,:self.n_basis_modes] @ self.custom_basis_[
61-
# :,:self.n_basis_modes].T)[:self.n_basis_modes,:].T
62-
63-
# self.basis_matrix_ = ((X @ self.custom_basis_).T)[
64-
# :,:self.n_basis_modes]
65-
# self.basis_matrix_ = ((
66-
# X @ self.custom_basis_ @ self.custom_basis_.T).T)[
67-
# :,:self.n_basis_modes]
6848
return self
6949

7050
def matrix_inverse(self, n_basis_modes=None):

pysensors/basis/_identity.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def matrix_inverse(self, n_basis_modes=None):
9090
B : numpy ndarray, shape (n_features, n_features)
9191
The inverse matrix. In this case B is the identity matrix.
9292
"""
93-
# TODO: validate this
9493
n_basis_modes = self._validate_input(n_basis_modes)
9594

9695
return identity(self.basis_matrix_.shape[0])

pysensors/optimizers/_qr.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ def fit(self, basis_matrix, **optimizer_kws):
4141
-------
4242
4343
"""
44-
45-
# TODO: implement checks on basis_matrix
4644
_, _, self.pivots_ = qr(basis_matrix.conj().T, pivoting=True, **optimizer_kws)
4745

4846
return self

pysensors/reconstruction/_sspor.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sklearn.utils.validation import check_is_fitted
77

88
from ..basis import Identity
9-
from ..optimizers import CCQR, GQR, QR
9+
from ..optimizers import CCQR, QR
1010
from ..utils import validate_input
1111

1212
INT_DTYPES = (int, np.int64, np.int32, np.int16, np.int8)
@@ -504,12 +504,8 @@ def _validate_n_sensors(self):
504504
)
505505
)
506506

507-
# If n_sensors exceeds n_samples, the cost-constrained QR algorithm may
508-
# place sensors in constrained areas.
509507
if (
510508
isinstance(self.optimizer, CCQR)
511-
or isinstance(self.optimizer, QR)
512-
or isinstance(self.optimizer, GQR)
513509
) and self.n_sensors > self.basis_matrix_.shape[1]:
514510
warnings.warn(
515511
"Number of sensors exceeds number of samples, which may cause CCQR to "

pysensors/utils/_base.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
import numpy as np
66

7-
# from sklearn.utils.validation import check_array
8-
97

108
def validate_input(x, sensors=None):
119
"""
@@ -17,12 +15,9 @@ def validate_input(x, sensors=None):
1715
x: numpy ndarray, shape [n_features,] or [n_examples, n_features]
1816
Data to be validated.
1917
"""
20-
# TODO: implement more checks
2118
if not isinstance(x, np.ndarray):
2219
raise ValueError("x must be a numpy array")
2320

24-
# check_array(x)
25-
2621
if sensors is not None:
2722
n_features = len(x) if np.ndim(x) == 1 else x.shape[1]
2823
if len(sensors) != n_features:

pysensors/utils/_constraints.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def get_constrained_sensors_indices(x_min, x_max, y_min, y_max, nx, ny, all_sens
4646
if not isinstance(nx, int) or not isinstance(ny, int):
4747
raise ValueError("nx and ny must be integers")
4848
n_features = len(all_sensors)
49-
# image_size = int(np.sqrt(n_features))
5049
a = np.unravel_index(all_sensors, (nx, ny))
5150
constrained_sensorsx = []
5251
constrained_sensorsy = []
@@ -91,9 +90,6 @@ def get_constrained_sensors_indices_dataframe(x_min, x_max, y_min, y_max, df, **
9190
Name of the column in dataframe to be plotted on the X axis.
9291
Y-axis : string,
9392
Name of the column in dataframe to be plotted on the Y axis.
94-
Field : string,
95-
Name of the column in dataframe to be plotted as a contour map.
96-
## TODO: Field is not used here @Niha please see this.
9793
Returns
9894
-------
9995
idx_constrained : np.darray, shape [No. of constrained locations], array which
@@ -648,10 +644,10 @@ def annotate_sensors(
648644
n_samples, n_features = self.data.shape
649645
n_sensors = len(sensors)
650646
constrained = sensors[
651-
np.where(np.in1d(all_sensors[:n_sensors], sensors) is False)[0]
647+
np.where(np.isin(all_sensors[:n_sensors], sensors) is False)[0]
652648
]
653649
unconstrained = sensors[
654-
np.where(np.in1d(all_sensors[:n_sensors], sensors) is True)[0]
650+
np.where(np.isin(all_sensors[:n_sensors], sensors) is True)[0]
655651
]
656652
if isinstance(self.data, np.ndarray):
657653
xTop = np.mod(sensors, np.sqrt(n_features))
@@ -1169,7 +1165,6 @@ def draw(self, ax, **kwargs):
11691165
)
11701166
ax.add_patch(c)
11711167
ax.autoscale_view()
1172-
# ax.axes.set_aspect('equal')
11731168

11741169
def constraint_function(self, coords):
11751170
"""

0 commit comments

Comments
 (0)