{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to compute a pointwise map from a functional map?" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import geomstats.backend as gs\n", "\n", "from geomfum.convert import P2pFromFmConverter\n", "from geomfum.dataset import NotebooksDataset\n", "from geomfum.shape import TriangleMesh" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Load meshes](00_load_mesh_from_file.ipynb)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(7207, 5000)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dataset = NotebooksDataset()\n", "\n", "mesh_a = TriangleMesh.from_file(dataset.get_filename(\"cat-00\"))\n", "mesh_b = TriangleMesh.from_file(dataset.get_filename(\"lion-00\"))\n", "\n", "mesh_a.n_vertices, mesh_b.n_vertices" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Set Laplace eigenbasis](./02_mesh_laplacian_spectrum.ipynb) for each mesh." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "mesh_a.laplacian.find_spectrum(spectrum_size=6, set_as_basis=True)\n", "mesh_b.laplacian.find_spectrum(spectrum_size=6, set_as_basis=True)\n", "\n", "mesh_b.basis.use_k = 5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Assume we have a [valid functional map](./07_functional_map.ipynb) $C$ between `mesh_a` and `mesh_b` (which for demonstration purposes, we instantiate randomly)." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(5, 6)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fmap_matrix = gs.random.uniform(\n", " size=(mesh_b.basis.spectrum_size, mesh_a.basis.spectrum_size)\n", ")\n", "\n", "fmap_matrix.shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compute pointwise map." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(5000,)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p2p_converter = P2pFromFmConverter()\n", "\n", "p2p = p2p_converter(fmap_matrix, mesh_a.basis, mesh_b.basis)\n", "\n", "p2p.shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The adjoint method can be used by setting `adjoint`." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(5000,)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p2p_converter.adjoint = True\n", "\n", "p2p = p2p_converter(fmap_matrix, mesh_a.basis, mesh_b.basis)\n", "\n", "p2p.shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The bijective method can be use by setting `bijective`." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(7207,)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p2p_converter.bijective = True\n", "\n", "p2p = p2p_converter(fmap_matrix, mesh_a.basis, mesh_b.basis)\n", "\n", "p2p.shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Further reading\n", "\n", "* [How to compute a functional map from a pointwise map?](./09_functional_from_pointwise.ipynb)\n", "\n", "* [How to compute a functional map?](./07_functional_map.ipynb)" ] } ], "metadata": { "kernelspec": { "display_name": "py12", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }