|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Basis\n", |
| 8 | + "\n", |
| 9 | + "<a href=\"https://colab.research.google.com/github/borglab/gtsam/blob/develop/gtsam/basis/doc/Basis.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>\n", |
| 10 | + "\n", |
| 11 | + "## Overview\n", |
| 12 | + "\n", |
| 13 | + "The `Basis` class is a CRTP base class that defines common utilities for representing functions as linear combinations of basis functions. Derived classes provide `CalculateWeights` and `DerivativeWeights`, while `Basis` supplies functors and helpers for evaluation, vector-valued evaluation, and derivative computation with Jacobians with respect to parameters.\n" |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + "cell_type": "markdown", |
| 18 | + "metadata": { |
| 19 | + "tags": [ |
| 20 | + "remove-cell" |
| 21 | + ] |
| 22 | + }, |
| 23 | + "source": [ |
| 24 | + "GTSAM Copyright 2010-2022, Georgia Tech Research Corporation,\n", |
| 25 | + "Atlanta, Georgia 30332-0415\n", |
| 26 | + "All Rights Reserved\n", |
| 27 | + "\n", |
| 28 | + "Authors: Frank Dellaert, et al. (see THANKS for the full author list)\n", |
| 29 | + "\n", |
| 30 | + "See LICENSE for the license information\n" |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + "cell_type": "code", |
| 35 | + "execution_count": 4, |
| 36 | + "id": "6775be6c", |
| 37 | + "metadata": { |
| 38 | + "tags": [ |
| 39 | + "remove-cell" |
| 40 | + ] |
| 41 | + }, |
| 42 | + "outputs": [], |
| 43 | + "source": [ |
| 44 | + "# Install GTSAM from pip if running in Google Colab\n", |
| 45 | + "try:\n", |
| 46 | + " import google.colab\n", |
| 47 | + " %pip install --quiet gtsam-develop\n", |
| 48 | + "except ImportError:\n", |
| 49 | + " pass # Not in Colab\n" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "markdown", |
| 54 | + "id": "ce1fbbd5", |
| 55 | + "metadata": {}, |
| 56 | + "source": [ |
| 57 | + "## Key Functionality / API\n", |
| 58 | + "\n", |
| 59 | + "- `WeightMatrix(N, X)` and `WeightMatrix(N, X, a, b)` build stacked weight matrices.\n", |
| 60 | + "- `EvaluationFunctor` evaluates a scalar function at `x`.\n", |
| 61 | + "- `VectorEvaluationFunctor` evaluates vector-valued functions from a parameter matrix.\n", |
| 62 | + "- `VectorComponentFunctor` evaluates a single component of a vector-valued function.\n", |
| 63 | + "- `ManifoldEvaluationFunctor` evaluates manifold-valued functions via local coordinates.\n", |
| 64 | + "- `DerivativeFunctor`, `VectorDerivativeFunctor`, and `ComponentDerivativeFunctor` compute derivatives.\n", |
| 65 | + "- `kroneckerProductIdentity` builds efficient block Jacobians for vector-valued cases.\n" |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + "cell_type": "markdown", |
| 70 | + "id": "46f84e69", |
| 71 | + "metadata": {}, |
| 72 | + "source": [ |
| 73 | + "## Derived Classes\n", |
| 74 | + "\n", |
| 75 | + "- `Chebyshev1Basis` (first-kind Chebyshev polynomials)\n", |
| 76 | + "- `Chebyshev2Basis` (second-kind Chebyshev polynomials)\n", |
| 77 | + "- `FourierBasis` (real Fourier series)\n", |
| 78 | + "- `Chebyshev2` (pseudo-spectral Chebyshev points)\n" |
| 79 | + ] |
| 80 | + }, |
| 81 | + { |
| 82 | + "cell_type": "markdown", |
| 83 | + "id": "c8e177a8", |
| 84 | + "metadata": {}, |
| 85 | + "source": [ |
| 86 | + "## Usage Example\n", |
| 87 | + "\n", |
| 88 | + "This example builds a weight matrix for a Chebyshev basis and evaluates\n", |
| 89 | + "Fourier weights at a point.\n" |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "code", |
| 94 | + "execution_count": 5, |
| 95 | + "id": "905a64a4", |
| 96 | + "metadata": {}, |
| 97 | + "outputs": [ |
| 98 | + { |
| 99 | + "name": "stdout", |
| 100 | + "output_type": "stream", |
| 101 | + "text": [ |
| 102 | + "Chebyshev2 WeightMatrix shape: (5, 5)\n", |
| 103 | + "First row: [1. 0. 0. 0. 0.]\n", |
| 104 | + "FourierBasis weights at x=0.3: [1. 0.955 0.296 0.825 0.565]\n" |
| 105 | + ] |
| 106 | + } |
| 107 | + ], |
| 108 | + "source": [ |
| 109 | + "import numpy as np\n", |
| 110 | + "import gtsam\n", |
| 111 | + "\n", |
| 112 | + "np.set_printoptions(precision=3, suppress=True)\n", |
| 113 | + "\n", |
| 114 | + "N = 5\n", |
| 115 | + "X = np.linspace(-1.0, 1.0, 5)\n", |
| 116 | + "W = gtsam.Chebyshev2.WeightMatrix(N, X)\n", |
| 117 | + "print(\"Chebyshev2 WeightMatrix shape:\", np.asarray(W).shape)\n", |
| 118 | + "print(\"First row:\", np.asarray(W)[0])\n", |
| 119 | + "\n", |
| 120 | + "x = 0.3\n", |
| 121 | + "weights = gtsam.FourierBasis.CalculateWeights(N, x)\n", |
| 122 | + "print(\"FourierBasis weights at x=0.3:\", np.asarray(weights).ravel())\n" |
| 123 | + ] |
| 124 | + }, |
| 125 | + { |
| 126 | + "cell_type": "markdown", |
| 127 | + "metadata": {}, |
| 128 | + "source": [ |
| 129 | + "## Source\n", |
| 130 | + "- [Basis.h](https://github.com/borglab/gtsam/blob/develop/gtsam/basis/Basis.h)\n" |
| 131 | + ] |
| 132 | + } |
| 133 | + ], |
| 134 | + "metadata": { |
| 135 | + "kernelspec": { |
| 136 | + "display_name": "py312", |
| 137 | + "language": "python", |
| 138 | + "name": "python3" |
| 139 | + }, |
| 140 | + "language_info": { |
| 141 | + "codemirror_mode": { |
| 142 | + "name": "ipython", |
| 143 | + "version": 3 |
| 144 | + }, |
| 145 | + "file_extension": ".py", |
| 146 | + "mimetype": "text/x-python", |
| 147 | + "name": "python", |
| 148 | + "nbconvert_exporter": "python", |
| 149 | + "pygments_lexer": "ipython3", |
| 150 | + "version": "3.12.6" |
| 151 | + } |
| 152 | + }, |
| 153 | + "nbformat": 4, |
| 154 | + "nbformat_minor": 5 |
| 155 | +} |
0 commit comments