|
54 | 54 | "## Reconstruction\n", |
55 | 55 | "For our reconstruction examples we will consider the Olivetti faces dataset from AT&T, consisting of 10 64-by-64 pictures of 40 different people. Each pixel will be treated as a sensor. An additional example performing sensor selection with `PySensors` to approximate global sea surface temperatures is given [here](https://github.com/dynamicslab/pysensors/blob/master/examples/sea_surface_temperature.ipynb)\n", |
56 | 56 | "\n", |
57 | | - "For reconstruction `PySensors` provides the `SensorSelector` class, which is largely based on the following paper ([link](https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=8361090)):\n", |
| 57 | + "For reconstruction `PySensors` provides the `SSPOR` class (Sparse Sensor Placement Optimization for Reconstruction), which is largely based on the following paper ([link](https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=8361090)):\n", |
58 | 58 | "\n", |
59 | | - " Manohar, Krithika, et al. \"Data-driven sparse sensor placement for reconstruction: Demonstrating the benefits of exploiting known patterns.\" IEEE Control Systems Magazine 38.3 (2018): 63-86." |
| 59 | + " Manohar, Krithika, et al. \"Data-driven sparse sensor placement for reconstruction: Demonstrating the benefits of exploiting known patterns.\" IEEE Control Systems Magazine 38.3 (2018): 63-86.\n", |
| 60 | + " \n", |
| 61 | + "`SSPOR` objects can be imported directly from `pysensors` or from `pysensors.reconstruction`." |
60 | 62 | ] |
61 | 63 | }, |
62 | 64 | { |
|
163 | 165 | "metadata": {}, |
164 | 166 | "source": [ |
165 | 167 | "### Simplest case\n", |
166 | | - "A `SensorSelector` object is instantiated and fit to the data to obtain a ranking of sensors (technically sensor indices) in descending order of importance. We print the top 10 here." |
| 168 | + "A `SSPOR` object is instantiated and fit to the data to obtain a ranking of sensors (technically sensor indices) in descending order of importance. We print the top 10 here." |
167 | 169 | ] |
168 | 170 | }, |
169 | 171 | { |
|
185 | 187 | } |
186 | 188 | ], |
187 | 189 | "source": [ |
188 | | - "model = ps.SensorSelector()\n", |
| 190 | + "model = ps.SSPOR()\n", |
189 | 191 | "model.fit(X_train)\n", |
190 | 192 | "\n", |
191 | 193 | "# Ranked list of sensors\n", |
|
238 | 240 | "metadata": {}, |
239 | 241 | "source": [ |
240 | 242 | "### Changing the number of sensors\n", |
241 | | - "Since we didn't specify the number of sensors, `SensorSelector.get_selected_sensors()` returned them all.\n", |
242 | | - "Instead we can pass in the desired number of sensors when instantiating a `SensorSelector` or after it has been fitted. Both options yield the same result." |
| 243 | + "Since we didn't specify the number of sensors, `SSPOR.get_selected_sensors()` returned them all.\n", |
| 244 | + "Instead we can pass in the desired number of sensors when instantiating a `SSPOR` object or after it has been fitted. Both options yield the same result." |
243 | 245 | ] |
244 | 246 | }, |
245 | 247 | { |
|
266 | 268 | "model.set_number_of_sensors(n_sensors)\n", |
267 | 269 | "\n", |
268 | 270 | "# Set number of sensors before fitting\n", |
269 | | - "model_alt = ps.SensorSelector(n_sensors=n_sensors)\n", |
| 271 | + "model_alt = ps.SSPOR(n_sensors=n_sensors)\n", |
270 | 272 | "model_alt.fit(X_train)\n", |
271 | 273 | "\n", |
272 | 274 | "print('Number of sensors originally returned:', len(ranked_sensors))\n", |
|
280 | 282 | "metadata": {}, |
281 | 283 | "source": [ |
282 | 284 | "### Forming reconstructions\n", |
283 | | - "Once a `SensorSelector` model has been fit to the data, it can be used to form reconstructions based on measurements from the selected sensor locations." |
| 285 | + "Once a `SSPOR` model has been fit to the data, it can be used to form reconstructions based on measurements from the selected sensor locations." |
284 | 286 | ] |
285 | 287 | }, |
286 | 288 | { |
|
317 | 319 | "source": [ |
318 | 320 | "# Fit the model\n", |
319 | 321 | "n_sensors = 60\n", |
320 | | - "model = ps.SensorSelector(n_sensors=n_sensors).fit(X_train)\n", |
| 322 | + "model = ps.SSPOR(n_sensors=n_sensors).fit(X_train)\n", |
321 | 323 | "\n", |
322 | 324 | "# Get the chosen sensor locations\n", |
323 | 325 | "sensors = model.get_selected_sensors()\n", |
|
368 | 370 | } |
369 | 371 | ], |
370 | 372 | "source": [ |
371 | | - "model = ps.SensorSelector().fit(X_train)\n", |
| 373 | + "model = ps.SSPOR().fit(X_train)\n", |
372 | 374 | "\n", |
373 | 375 | "sensor_range = np.arange(1, 1000, 10)\n", |
374 | 376 | "errors = model.reconstruction_error(X_test, sensor_range=sensor_range)\n", |
|
435 | 437 | ], |
436 | 438 | "source": [ |
437 | 439 | "basis = ps.basis.SVD(n_basis_modes=n_basis_modes)\n", |
438 | | - "model = ps.SensorSelector(basis=basis)\n", |
| 440 | + "model = ps.SSPOR(basis=basis)\n", |
439 | 441 | "model.fit(X_train)\n", |
440 | 442 | "\n", |
441 | 443 | "# Ranked list of sensors\n", |
|
472 | 474 | ], |
473 | 475 | "source": [ |
474 | 476 | "basis = ps.basis.RandomProjection(n_basis_modes=n_basis_modes)\n", |
475 | | - "model = ps.SensorSelector(basis=basis)\n", |
| 477 | + "model = ps.SSPOR(basis=basis)\n", |
476 | 478 | "model.fit(X_train)\n", |
477 | 479 | "\n", |
478 | 480 | "# Ranked list of sensors\n", |
|
486 | 488 | "metadata": {}, |
487 | 489 | "source": [ |
488 | 490 | "#### Updating the number of basis modes\n", |
489 | | - "The number of basis modes can be updated after a `SensorSelector` model has been fit via the `update_n_basis_modes` function.\n", |
| 491 | + "The number of basis modes can be updated after a `SSPOR` model has been fit via the `update_n_basis_modes` function.\n", |
490 | 492 | "\n", |
491 | 493 | "Note that when using `update_n_basis_modes` to *increase* the number of basis modes from the number specified when the model was fit requires one to pass in the training data. The number of basis modes can be decreased without the need for the training data." |
492 | 494 | ] |
|
504 | 506 | "source": [ |
505 | 507 | "# Decreasing the number of basis modes\n", |
506 | 508 | "basis = ps.basis.SVD(n_basis_modes=20)\n", |
507 | | - "model = ps.SensorSelector(basis=basis).fit(X_train)\n", |
| 509 | + "model = ps.SSPOR(basis=basis).fit(X_train)\n", |
508 | 510 | "model.update_n_basis_modes(10)\n", |
509 | 511 | "\n", |
510 | 512 | "# Increasing the number of basis modes\n", |
511 | 513 | "basis = ps.basis.SVD(n_basis_modes=20)\n", |
512 | | - "model = ps.SensorSelector(basis=basis).fit(X_train)\n", |
| 514 | + "model = ps.SSPOR(basis=basis).fit(X_train)\n", |
513 | 515 | "model.update_n_basis_modes(30, x=X_train)" |
514 | 516 | ] |
515 | 517 | }, |
|
587 | 589 | "\n", |
588 | 590 | "# Fit the cost-constrained model\n", |
589 | 591 | "optimizer = ps.optimizers.CCQR(sensor_costs=costs)\n", |
590 | | - "model = ps.SensorSelector(optimizer=optimizer, n_sensors=n_sensors)\n", |
| 592 | + "model = ps.SSPOR(optimizer=optimizer, n_sensors=n_sensors)\n", |
591 | 593 | "model.fit(X_train)\n", |
592 | 594 | "\n", |
593 | 595 | "# Visualize the top sensors\n", |
|
607 | 609 | "\n", |
608 | 610 | "`PySensors` implements the Sparse Sensor Placement Optimization for Classification (SSPOC) algorithm in the `SSPOC` class. See the original SSPOC paper for more information ([link](https://epubs.siam.org/doi/pdf/10.1137/15M1036713)):\n", |
609 | 611 | "\n", |
610 | | - " Brunton, Bingni W., et al. \"Sparse sensor placement optimization for classification.\" SIAM Journal on Applied Mathematics 76.5 (2016): 2099-2122." |
| 612 | + " Brunton, Bingni W., et al. \"Sparse sensor placement optimization for classification.\" SIAM Journal on Applied Mathematics 76.5 (2016): 2099-2122.\n", |
| 613 | + "\n", |
| 614 | + "`SSPOC` can be imported directly from `pysensors` or from `pysensors.classification`." |
611 | 615 | ] |
612 | 616 | }, |
613 | 617 | { |
|
621 | 625 | }, |
622 | 626 | "outputs": [], |
623 | 627 | "source": [ |
624 | | - "from pysensors.classification import SSPOC" |
| 628 | + "from pysensors import SSPOC" |
625 | 629 | ] |
626 | 630 | }, |
627 | 631 | { |
|
843 | 847 | "metadata": {}, |
844 | 848 | "source": [ |
845 | 849 | "### Changing the basis\n", |
846 | | - "Like the `SensorSelector` object, `SSPOC` instances accept a `basis` argument." |
| 850 | + "Like the `SSPOR` object, `SSPOC` instances accept a `basis` argument." |
847 | 851 | ] |
848 | 852 | }, |
849 | 853 | { |
|
0 commit comments