Skip to content

Commit

Permalink
irregular to basis doctest example with plot
Browse files Browse the repository at this point in the history
  • Loading branch information
pcuestas committed Apr 20, 2024
1 parent 7104d2a commit 5f58016
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
# Sphinx extensions
extensions = [
"jupyter_sphinx",
"matplotlib.sphinxext.plot_directive",
"myst_parser",
"sphinx.ext.autodoc",
"sphinx.ext.autodoc.typehints",
Expand Down
35 changes: 35 additions & 0 deletions skfda/representation/irregular.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,41 @@ def to_basis(
Returns:
FDataBasis: Basis representation of the funtional data
object.
.. plot::
:format: python
:include-source: True
>>> from skfda.datasets import fetch_weather, irregular_sample
>>> from skfda.representation.basis import FourierBasis
>>> import matplotlib.pyplot as plt
>>> fd_temperatures = fetch_weather().data.coordinates[0]
>>> temp_irregular = irregular_sample(
... fdata=fd_temperatures,
... n_points_per_curve=8,
... random_state=4934755,
... )
>>> basis = FourierBasis(
... n_basis=5, domain_range=fd_temperatures.domain_range,
... )
>>> temp_basis_repr = temp_irregular.to_basis( #doctest: +SKIP
... basis, conversion_type="mixed_effects",
... )
>>> fig = plt.figure(figsize=(10, 10))
>>> for k in range(4): #doctest: +SKIP
... axes = plt.subplot(2, 2, k + 1)
... fd_temperatures.plot(axes=axes, alpha=0.05, color="black")
... fd_temperatures[k].plot(
... axes=axes, color=f"C{k}",
... label="Original data", linestyle="--",
... )
... temp_basis_repr[k].plot(
... axes=axes, color=f"C{k}",
... label="Basis representation",
... )
... temp_irregular[k].scatter(axes=axes, color=f"C{k}")
... plt.legend()
>>> plt.show() #doctest: +SKIP
"""
if self.dim_domain != basis.dim_domain:
raise ValueError(
Expand Down

0 comments on commit 5f58016

Please sign in to comment.