Skip to content

Commit 3a24e9c

Browse files
Niharika KarnikNiharika Karnik
authored andcommitted
Fixing Linting error
1 parent 2b8a326 commit 3a24e9c

File tree

15 files changed

+1162
-755
lines changed

15 files changed

+1162
-755
lines changed

README.rst

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ Use the ``predict`` method to reconstruct a new function sampled at the chosen s
5858
Reconstruction with constraints
5959
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6060
In most engineering applications, certain areas within the region of interest might allow a limited number of sensors or none at all.
61-
We develop a data-driven technique that incorporates constraints into an optimization framework for sensor placement, with the primary objective
62-
of minimizing reconstruction errors under noisy sensor measurements.
61+
We develop a data-driven technique that incorporates constraints into an optimization framework for sensor placement, with the primary objective
62+
of minimizing reconstruction errors under noisy sensor measurements.
6363

64-
This work has been implemented in the general QR optimizer for sensor selection.
64+
This work has been implemented in the general QR optimizer for sensor selection.
6565
This is an extension that requires a more intrusive access to the QR optimizer to facilitate a more adaptive optimization. It is a generalized version of cost constraints
66-
in the sense that users can allow `n_const_sensors` in the constrained area. If n = 0 this converges to the CCQR results. If there is
66+
in the sense that users can allow `n_const_sensors` in the constrained area. If n = 0 this converges to the CCQR results. If there is
6767
no constrained region it should converge to the results from QR optimizer.
6868

69-
To implement constrained sensing we initialize the optimizer GQR and provide it additional kwargs such as the constrained region, number of allowable
70-
sensors in the constrained region and the type of constraint.
69+
To implement constrained sensing we initialize the optimizer GQR and provide it additional kwargs such as the constrained region, number of allowable
70+
sensors in the constrained region and the type of constraint.
7171

72-
Three strategies to deal with constraints are currently developed:
72+
Three strategies to deal with constraints are currently developed:
7373

7474
* ``max_n`` - Number of sensors in the constrained region should be less than or equal to the allowable constrained sensors.
7575

@@ -87,9 +87,9 @@ Three strategies to deal with constraints are currently developed:
8787
'constraint_option':"exact_n"}
8888
8989
We have further provided functions to compute the sensors in the constrained regions. For example if the user provides the center and radius of a circular
90-
constrained region, the constraints in utils compute the constrained sensor indices. Direct constraint plotting capabilities have also been developed.
90+
constrained region, the constraints in utils compute the constrained sensor indices. Direct constraint plotting capabilities have also been developed.
9191

92-
The constrained shapes currently implemented are:
92+
The constrained shapes currently implemented are:
9393

9494
* ``Circle``
9595

@@ -105,7 +105,7 @@ The constrained shapes currently implemented are:
105105

106106
* ``UserDefinedConstraints``
107107

108-
- This type of constraint has the ability to take in either a function from the user or a
108+
- This type of constraint has the ability to take in either a function from the user or a
109109
.py file which contains a functional definition of the constrained region.
110110

111111
Classification
@@ -300,6 +300,12 @@ References
300300
(2018): 2642-2656.
301301
`[DOI] <https://doi.org/10.1109/JSEN.2018.2887044>`__
302302

303+
- Karnik, Niharika, Mohammad G. Abdo, Carlos E. Estrada-Perez, Jun Soo Yoo,
304+
Joshua J. Cogliati, Richard S. Skifton, Pattrick Calderoni, Steven L. Brunton, and Krithika Manohar.
305+
"Constrained Optimization of Sensor Plcaement for Nuclear Digital Twins" IEEE Sensors Journal 24, no. 9
306+
(2024): 15501 - 15516.
307+
`[DOI] <https://doi.org/10.1109/JSEN.2024.3368875>`__
308+
303309
.. |Build| image:: https://github.com/dynamicslab/pysensors/workflows/Tests/badge.svg
304310
:target: https://github.com/dynamicslab/pysensors/actions?query=workflow%3ATests
305311

examples/README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ where sensor locations are learned for a monomial basis for the task of reconstr
3939

4040
`Spatial constraints example <https://python-sensors.readthedocs.io/en/latest/examples/spatially_constrained_qr.html>`_
4141
----------------------------------------------------------------------------------------------------
42-
Sensor locations are learned for a constrained sensing problem for the task of reconstruction. For further details of constrained sensing refer
42+
Sensor locations are learned for a constrained sensing problem for the task of reconstruction. For further details of constrained sensing refer
4343
`Karnik et al. (2024) <https://ieeexplore.ieee.org/abstract/document/10453459>`_
4444

4545
`Functional constraints example <https://python-sensors.readthedocs.io/en/latest/examples/functional_constraints.html>`_
4646
----------------------------------------------------------------------------------------------------
47-
Sensor locations are learned for various shapes of constrained regions. For further details refer to
47+
Sensor locations are learned for various shapes of constrained regions. For further details refer to
4848
`Karnik et al. (2024) <https://www.mdpi.com/1996-1073/17/13/3355>`_
4949

5050
`Spatially Constrained sensing for a nuclear application <https://python-sensors.readthedocs.io/en/latest/examples/nuclear_application.html>`_
5151
----------------------------------------------------------------------------------------------------
52-
See how `PySensors` can be used to pick near optimal locations for sensors that accurateely reconstruct temperature in a nuclear fuel rod prototype
52+
See how `PySensors` can be used to pick near optimal locations for sensors that accurateely reconstruct temperature in a nuclear fuel rod prototype
5353
. For further details refer to `Karnik et al. (2024) <https://ieeexplore.ieee.org/abstract/document/10453459>`_
5454

5555

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
1-
21
import numpy as np
32

4-
def twistParabolicConstraint(x,y,**kwargs):
3+
4+
def twistParabolicConstraint(x, y, **kwargs):
55
"""
6-
Function for evaluating constrained sensor locations on the grid by returning a negative value (if index is constrained) and a positive value (if index is unconstrained).
6+
Function for evaluating constrained sensor locations on the grid by returning a
7+
negative value (if index is constrained) and a positive value
8+
(if index is unconstrained).
79
810
Parameters
911
----------
1012
x: float, x coordinate of all grid-points considered for sensor placement
1113
y : float, y coordinate of all grid-points considered for sensor placement
12-
13-
**kwargs : h : float, x-coordinate of the vertex of the parabola we want to be constrained;
14-
k : float, y-coordinate of the vertex of the parabola we want to be constrained;
14+
15+
**kwargs : h : float, x-coordinate of the vertex of the parabola we want to be
16+
constrained;
17+
k : float, y-coordinate of the vertex of the parabola we want to be
18+
constrained;
1519
a : float, The x-coordinate of the focus of the parabola.
1620
1721
Returns
1822
-------
19-
g : np.darray, shape [No. of grid points],
20-
A boolean array for every single grid point based on whether the grid point lies in the constrained region or not
23+
g : np.darray, shape [No. of grid points],
24+
A boolean array for every single grid point based on whether the grid point lies
25+
in the constrained region or not.
2126
"""
2227
# make sure the length of x is the same as y
2328
assert len(x) == len(y)
24-
if ('h' not in kwargs.keys()) or (kwargs['h'] == None) :
25-
kwargs['h'] = 0.025
26-
if ('k' not in kwargs.keys()) or (kwargs['k'] == None) :
27-
kwargs['k'] = 0
28-
if ('a' not in kwargs.keys()) or (kwargs['a'] == None) :
29-
kwargs['a'] = 100
29+
if ("h" not in kwargs.keys()) or (kwargs["h"] is None):
30+
kwargs["h"] = 0.025
31+
if ("k" not in kwargs.keys()) or (kwargs["k"] is None):
32+
kwargs["k"] = 0
33+
if ("a" not in kwargs.keys()) or (kwargs["a"] is None):
34+
kwargs["a"] = 100
3035
# initialize the constraint evaluation function g
31-
g1 = np.zeros(len(x),dtype=float) - 1
32-
g2 = np.zeros(len(x),dtype=float) - 1
33-
g = np.zeros(len(x),dtype=float)
34-
# loop over all given location and check if they violate the constraints
35-
# make sure the retuned value is negative if it is in the constrained area and positive otherwise
36+
g1 = np.zeros(len(x), dtype=float) - 1
37+
g2 = np.zeros(len(x), dtype=float) - 1
38+
g = np.zeros(len(x), dtype=float)
3639
for i in range(len(x)):
3740
# circle of center (h,k)=(0,0) and radius 2.5 cm
38-
g1[i] = (kwargs['a']*(x[i]-kwargs['h'])**2) - (y[i]-kwargs['k'])
41+
g1[i] = (kwargs["a"] * (x[i] - kwargs["h"]) ** 2) - (y[i] - kwargs["k"])
3942
#
4043
# Second constraint:
4144
g2[i] = y[i] - 0.2
42-
if bool(g1[i]>=0) == bool(g2[i]>=0):
43-
g[i] = (bool(g1[i]>=0) and bool(g2[i]>=0))-1
44-
return g
45+
if bool(g1[i] >= 0) == bool(g2[i] >= 0):
46+
g[i] = (bool(g1[i] >= 0) and bool(g2[i] >= 0)) - 1
47+
return g
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import numpy as np
22

3-
def userExplicitConstraint1(x,y,**kwargs):
4-
'''
5-
'''
6-
assert len(x) == len(y)
7-
g = np.zeros(len(x),dtype=float)
8-
for i in range(len(x)):
9-
g[i] = ((x[i]-30)**2 + (y[i]-40)**2) - 5**2
10-
return g
3+
4+
def userExplicitConstraint1(x, y, **kwargs):
5+
""" """
6+
assert len(x) == len(y)
7+
g = np.zeros(len(x), dtype=float)
8+
for i in range(len(x)):
9+
g[i] = ((x[i] - 30) ** 2 + (y[i] - 40) ** 2) - 5**2
10+
return g
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
2-
def userExplicitConstraint2(x,y,**kwargs):
3-
g = (x-20)**2 + (y-10)**2 - 49
4-
return g
1+
def userExplicitConstraint2(x, y, **kwargs):
2+
g = (x - 20) ** 2 + (y - 10) ** 2 - 49
3+
return g

pysensors/optimizers/_gqr.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ def fit(self, basis_matrix, **optimizer_kws):
9393
for j in range(k):
9494
r = R[j:, j:]
9595

96-
# Norm of each column
97-
if j == 0:
98-
dlens_old = np.sqrt(np.sum(np.abs(r) ** 2, axis=0))
99-
else:
100-
dlens_old = dlens
10196
dlens = np.sqrt(np.sum(np.abs(r) ** 2, axis=0))
10297
dlens_updated = self._norm_calc_Instance(
10398
self.idx_constrained,

pysensors/reconstruction/_sspor.py

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

88
from ..basis import Identity
9-
from ..optimizers import CCQR
10-
from ..optimizers import QR
11-
from ..optimizers import GQR
9+
from ..optimizers import CCQR, GQR, QR
1210
from ..utils import validate_input
1311

1412
INT_DTYPES = (int, np.int64, np.int32, np.int16, np.int8)
@@ -509,9 +507,10 @@ def _validate_n_sensors(self):
509507
# If n_sensors exceeds n_samples, the cost-constrained QR algorithm may
510508
# place sensors in constrained areas.
511509
if (
512-
(isinstance(self.optimizer, CCQR) or isinstance(self.optimizer, QR) or isinstance(self.optimizer, GQR))
513-
and self.n_sensors > self.basis_matrix_.shape[1]
514-
):
510+
isinstance(self.optimizer, CCQR)
511+
or isinstance(self.optimizer, QR)
512+
or isinstance(self.optimizer, GQR)
513+
) and self.n_sensors > self.basis_matrix_.shape[1]:
515514
warnings.warn(
516515
"Number of sensors exceeds number of samples, which may cause CCQR to "
517516
"select sensors in constrained regions."

pysensors/utils/__init__.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
from ._base import validate_input
2-
from ._optimizers import constrained_binary_solve
3-
from ._optimizers import constrained_multiclass_solve
4-
from ._constraints import get_constrained_sensors_indices
5-
from ._constraints import get_constrained_sensors_indices_dataframe
6-
from ._constraints import BaseConstraint
7-
from ._constraints import Circle
8-
from ._constraints import Cylinder
9-
from ._constraints import Line
10-
from ._constraints import Ellipse
11-
from ._constraints import Parabola
12-
from ._constraints import Polygon
13-
from ._constraints import UserDefinedConstraints
2+
from ._constraints import (
3+
BaseConstraint,
4+
Circle,
5+
Cylinder,
6+
Ellipse,
7+
Line,
8+
Parabola,
9+
Polygon,
10+
UserDefinedConstraints,
11+
get_constrained_sensors_indices,
12+
get_constrained_sensors_indices_dataframe,
13+
get_coordinates_from_indices,
14+
get_indices_from_coordinates,
15+
load_functional_constraints,
16+
)
17+
from ._norm_calc import exact_n, max_n, predetermined
18+
from ._optimizers import constrained_binary_solve, constrained_multiclass_solve
19+
from ._validation import determinant, relative_reconstruction_error
20+
1421
# from ._constraints import check_constraints
1522
# from ._constraints import constraints_eval
1623

17-
from ._constraints import load_functional_constraints
18-
from ._constraints import get_coordinates_from_indices
19-
from ._constraints import get_indices_from_coordinates
20-
from ._norm_calc import exact_n
21-
from ._norm_calc import max_n
22-
from ._norm_calc import predetermined
23-
from ._validation import determinant
24-
from ._validation import relative_reconstruction_error
2524

2625
__all__ = [
2726
"constrained_binary_solve",
@@ -31,13 +30,11 @@
3130
"get_constrained_sensors_indices_linear",
3231
"BaseConstraint",
3332
"Circle",
34-
"Cylinder"
35-
"Line",
33+
"Cylinder" "Line",
3634
"Parabola",
3735
"Polygon",
3836
"Ellipse",
39-
"UserDefinedConstraints"
40-
"box_constraints",
37+
"UserDefinedConstraints" "box_constraints",
4138
# "constraints_eval",
4239
"functional_constraints",
4340
"get_coordinates_from_indices",

0 commit comments

Comments
 (0)