|
5 | 5 | "metadata": {}, |
6 | 6 | "source": [ |
7 | 7 | "\n", |
8 | | - "# FitBasis Example (Fourier + Chebyshev)\n", |
| 8 | + "# FitBasis (Fourier + Chebyshev)\n", |
9 | 9 | "\n", |
10 | 10 | "<a href=\"https://colab.research.google.com/github/borglab/gtsam/blob/develop/python/gtsam/examples/FitBasisExample.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>\n", |
11 | 11 | "\n", |
|
42 | 42 | }, |
43 | 43 | { |
44 | 44 | "cell_type": "code", |
45 | | - "execution_count": 12, |
| 45 | + "execution_count": 1, |
46 | 46 | "id": "50e0e944", |
47 | 47 | "metadata": { |
48 | 48 | "tags": [ |
|
61 | 61 | }, |
62 | 62 | { |
63 | 63 | "cell_type": "code", |
64 | | - "execution_count": 13, |
| 64 | + "execution_count": 2, |
65 | 65 | "id": "b8cf1aff", |
66 | 66 | "metadata": {}, |
67 | 67 | "outputs": [], |
|
76 | 76 | }, |
77 | 77 | { |
78 | 78 | "cell_type": "code", |
79 | | - "execution_count": 14, |
| 79 | + "execution_count": 3, |
80 | 80 | "id": "a040dcaf", |
81 | 81 | "metadata": {}, |
82 | 82 | "outputs": [], |
|
97 | 97 | }, |
98 | 98 | { |
99 | 99 | "cell_type": "code", |
100 | | - "execution_count": 15, |
| 100 | + "execution_count": 4, |
101 | 101 | "id": "dab48fee", |
102 | 102 | "metadata": {}, |
103 | 103 | "outputs": [], |
|
139 | 139 | }, |
140 | 140 | { |
141 | 141 | "cell_type": "code", |
142 | | - "execution_count": 16, |
| 142 | + "execution_count": 5, |
143 | 143 | "id": "c05c36fa", |
144 | 144 | "metadata": {}, |
145 | 145 | "outputs": [ |
|
985 | 985 | "sequence : dict = {float(xi): float(yi) for xi, yi in zip(x_fourier, y)}\n", |
986 | 986 | "model = gtsam.noiseModel.Isotropic.Sigma(1, 0.05)\n", |
987 | 987 | "fit = gtsam.FitBasisFourierBasis(sequence, model, N)\n", |
988 | | - "params = np.asarray(fit.parameters()).ravel()\n", |
| 988 | + "params = fit.parameters()\n", |
989 | 989 | "\n", |
990 | 990 | "# Extend the time domain to show periodic behavior\n", |
991 | 991 | "t_dense = np.linspace(-0.5, 1.5, 600)\n", |
992 | 992 | "x_dense = 2.0 * np.pi * t_dense\n", |
993 | | - "W = np.asarray(gtsam.FourierBasis.WeightMatrix(len(params), x_dense))\n", |
| 993 | + "W = gtsam.FourierBasis.WeightMatrix(len(params), x_dense)\n", |
994 | 994 | "y_fit = W @ params\n", |
995 | 995 | "\n", |
996 | 996 | "plot_fit(t, y, t_dense, y_fit, \"FourierBasis Fit (periodic beyond [0, 1])\")\n" |
|
1014 | 1014 | }, |
1015 | 1015 | { |
1016 | 1016 | "cell_type": "code", |
1017 | | - "execution_count": 17, |
| 1017 | + "execution_count": 6, |
1018 | 1018 | "id": "ddacb31c", |
1019 | 1019 | "metadata": {}, |
1020 | 1020 | "outputs": [ |
|
1860 | 1860 | "sequence = {float(xi): float(yi) for xi, yi in zip(x_cheb, y)}\n", |
1861 | 1861 | "model = gtsam.noiseModel.Isotropic.Sigma(1, 0.05)\n", |
1862 | 1862 | "fit = gtsam.FitBasisChebyshev1Basis(sequence, model, N)\n", |
1863 | | - "params = np.asarray(fit.parameters()).ravel()\n", |
| 1863 | + "params = fit.parameters()\n", |
1864 | 1864 | "\n", |
1865 | 1865 | "t_dense = np.linspace(-0.1, 1.1, 600)\n", |
1866 | 1866 | "x_dense = 2.0 * t_dense - 1.0\n", |
1867 | | - "W = np.asarray(gtsam.Chebyshev1Basis.WeightMatrix(len(params), x_dense))\n", |
| 1867 | + "W = gtsam.Chebyshev1Basis.WeightMatrix(len(params), x_dense)\n", |
1868 | 1868 | "y_fit = W @ params\n", |
1869 | 1869 | "\n", |
1870 | 1870 | "plot_fit(t, y, t_dense, y_fit, \"Chebyshev1Basis Fit (extrapolation outside [0, 1])\")\n" |
|
1889 | 1889 | }, |
1890 | 1890 | { |
1891 | 1891 | "cell_type": "code", |
1892 | | - "execution_count": 18, |
| 1892 | + "execution_count": 7, |
1893 | 1893 | "id": "fc3d1235", |
1894 | 1894 | "metadata": {}, |
1895 | 1895 | "outputs": [ |
|
2734 | 2734 | "sequence = {float(xi): float(yi) for xi, yi in zip(x_cheb, y)}\n", |
2735 | 2735 | "model = gtsam.noiseModel.Isotropic.Sigma(1, 0.05)\n", |
2736 | 2736 | "fit = gtsam.FitBasisChebyshev2Basis(sequence, model, N)\n", |
2737 | | - "params = np.asarray(fit.parameters()).ravel()\n", |
| 2737 | + "params = fit.parameters()\n", |
2738 | 2738 | "\n", |
2739 | 2739 | "t_dense = np.linspace(-0.1, 1.1, 600)\n", |
2740 | 2740 | "x_dense = 2.0 * t_dense - 1.0\n", |
2741 | | - "W = np.asarray(gtsam.Chebyshev2Basis.WeightMatrix(len(params), x_dense))\n", |
| 2741 | + "W = gtsam.Chebyshev2Basis.WeightMatrix(len(params), x_dense)\n", |
2742 | 2742 | "y_fit = W @ params\n", |
2743 | 2743 | "\n", |
2744 | 2744 | "plot_fit(t, y, t_dense, y_fit, \"Chebyshev2Basis Fit (extrapolation outside [0, 1])\")\n" |
|
2764 | 2764 | }, |
2765 | 2765 | { |
2766 | 2766 | "cell_type": "code", |
2767 | | - "execution_count": 19, |
| 2767 | + "execution_count": 8, |
2768 | 2768 | "id": "37db92b8", |
2769 | 2769 | "metadata": {}, |
2770 | 2770 | "outputs": [ |
|
3625 | 3625 | "sequence = {float(xi): float(yi) for xi, yi in zip(x_cheb, y)}\n", |
3626 | 3626 | "model = gtsam.noiseModel.Isotropic.Sigma(1, 0.05)\n", |
3627 | 3627 | "fit = gtsam.FitBasisChebyshev2(sequence, model, N)\n", |
3628 | | - "params = np.asarray(fit.parameters()).ravel()\n", |
| 3628 | + "params = fit.parameters()\n", |
3629 | 3629 | "\n", |
3630 | 3630 | "t_dense = np.linspace(-0.1, 1.1, 600)\n", |
3631 | 3631 | "x_dense = 2.0 * t_dense - 1.0\n", |
3632 | | - "W = np.asarray(gtsam.Chebyshev2.WeightMatrix(len(params), x_dense))\n", |
| 3632 | + "W = gtsam.Chebyshev2.WeightMatrix(len(params), x_dense)\n", |
3633 | 3633 | "y_fit = W @ params\n", |
3634 | 3634 | "\n", |
3635 | | - "cheb_points = np.asarray(gtsam.Chebyshev2.Points(N)).ravel()\n", |
| 3635 | + "cheb_points = gtsam.Chebyshev2.Points(N)\n", |
3636 | 3636 | "t_cheb = 0.5 * (cheb_points + 1.0)\n", |
3637 | 3637 | "y_cheb = params\n", |
3638 | 3638 | "markers = go.Scatter(x=t_cheb, y=y_cheb, mode=\"markers\", name=\"Chebyshev2 points\", marker=dict(color=\"red\"))\n", |
|
3649 | 3649 | "\n", |
3650 | 3650 | "Chebyshev points are fixed nodes that cluster near the interval ends; this improves interpolation stability and reduces endpoint oscillations compared to equally spaced nodes (mitigating the Runge phenomenon)." |
3651 | 3651 | ] |
3652 | | - }, |
3653 | | - { |
3654 | | - "cell_type": "markdown", |
3655 | | - "id": "7d4c0b1d", |
3656 | | - "metadata": {}, |
3657 | | - "source": [] |
3658 | 3652 | } |
3659 | 3653 | ], |
3660 | 3654 | "metadata": { |
|
0 commit comments