mmgp_blocks =========== .. py:module:: mmgp_blocks .. autoapi-nested-parse:: Custom blocks for applying MMGP. Includes: - MMGPPreparer. - MMGPTransformer. Classes ------- .. autoapisummary:: mmgp_blocks.MMGPPreparer mmgp_blocks.MMGPTransformer Functions --------- .. autoapisummary:: mmgp_blocks.compute_FE_projection_operator mmgp_blocks.compute_node_to_node_graph mmgp_blocks.initialize_graph_points_from_mesh_points mmgp_blocks.renumber_mesh_for_parametrization mmgp_blocks.floater_mesh_parametrization Module Contents --------------- .. py:class:: MMGPPreparer(common_mesh_id: Optional[int] = None, morphing: Optional[Callable] = None) Bases: :py:obj:`sklearn.base.TransformerMixin`, :py:obj:`sklearn.base.BaseEstimator` Preparer for MMGP. Transforms :param common_mesh_id: ... :param morphing: ... .. py:attribute:: common_mesh_id :value: None .. py:attribute:: morphing :value: None .. py:method:: fit(dataset: plaid.containers.dataset.Dataset, _y=None) Fits the underlying scikit-learn transformer on selected input features. :param dataset: A `Dataset` object containing the features to transform. :param _y: Ignored. :returns: The fitted transformer. :rtype: self .. py:method:: transform(dataset: plaid.containers.dataset.Dataset) Applies the fitted transformer to the selected input features. :param dataset: A `Dataset` object to transform. :returns: Transformed features wrapped as a new `Dataset`. :rtype: Dataset .. py:method:: inverse_transform(dataset: plaid.containers.dataset.Dataset) Applies inverse transformation to the output features. :param dataset: A `Dataset` object with transformed output features. :returns: Dataset with inverse-transformed features. :rtype: Dataset .. py:class:: MMGPTransformer(in_features_identifiers: Optional[list[dict]] = None) Bases: :py:obj:`sklearn.base.TransformerMixin`, :py:obj:`sklearn.base.BaseEstimator` Adapter for using a scikit-learn transformer on PLAID Datasets. Transforms tabular data extracted from homogeneous feature identifiers, and returns results as a `Dataset`. Supports forward and inverse transforms. :param sklearn_block: A scikit-learn Transformer implementing fit/transform APIs. :param in_features_identifiers: List of feature identifiers to extract input data from. :param out_features_identifiers: List of feature identifiers used for outputs. If None, defaults to `in_features_identifiers`. .. py:attribute:: in_features_identifiers :value: None .. py:method:: fit(dataset: plaid.containers.dataset.Dataset, _y=None) Fit. :param dataset: The dataset used to fit the MMGPTransformer. :type dataset: Dataset .. py:method:: transform(dataset: plaid.containers.dataset.Dataset) Transform. :param dataset: The dataset to transform. :type dataset: Dataset .. py:method:: inverse_transform(dataset: plaid.containers.dataset.Dataset) Inverse transform. :param dataset: The dataset to inverse transform. :type dataset: Dataset .. py:function:: compute_FE_projection_operator(origin_mesh: Muscat.Containers.Mesh.Mesh, target_mesh: Muscat.Containers.Mesh.Mesh, verbose: bool = False) -> Tuple[numpy.ndarray, numpy.ndarray] Compute Finite Element Projection Operators. :param origin_mesh: The original mesh data. :type origin_mesh: Mesh :param target_mesh: The target mesh data. :type target_mesh: Mesh :param verbose: Whether to display verbose output. Defaults to False. :type verbose: bool, optional :returns: A tuple containing two projection operators (projOperator, invProjOperator). :rtype: tuple(np.ndarray, np.ndarray) .. py:function:: compute_node_to_node_graph(in_mesh: Muscat.Containers.Mesh.Mesh, dimensionality: Optional[int] = None, dist_func: Optional[Callable] = None) -> networkx.Graph Creates a networkx graph from the node connectivity on a Mesh through edges. :param in_mesh: input mesh :type in_mesh: Mesh :param dimensionality: dimension of the elements considered to initalize the graph :type dimensionality: int :param dist_func: function applied to the lengh of the edges of the mesh, and attached of the corresponding edge of the graph of the mesh :type dist_func: func :param Returns: :param -------: :param networkx.Graph: Element to element graph .. py:function:: initialize_graph_points_from_mesh_points(in_mesh: Muscat.Containers.Mesh.Mesh) -> networkx.Graph Initializes a networkx graph with nodes consistant with the number of nodes of a Mesh. This enables further edge addition compatible with the connectivity of the elements of the Mesh. :param in_mesh: input mesh :type in_mesh: Mesh :param Returns: :param -------: :param networkx.Graph: initialized graph .. py:function:: renumber_mesh_for_parametrization(in_mesh: Muscat.Containers.Mesh.Mesh, in_place: bool = True, boundary_orientation: str = 'direct', fixed_boundary_points: Optional[list] = None, starting_point_rank_on_boundary: Optional[int] = None) -> Tuple[Muscat.Containers.Mesh.Mesh, numpy.ndarray, int] Only for linear triangle meshes. Renumber the node IDs, such that the points on the boundary are placed at the end of the numbering. Serves as a preliminary step for mesh parametrization. :param in_mesh: input triangular to be renumbered :type in_mesh: Mesh :param in_place: if "True", in_mesh is modified if "False", in_mesh is let unmodified, and a new mesh is produced :type in_place: bool :param boundary_orientation: if "direct, the boundary of the parametrisation is constructed in the direct trigonometric order if "indirect", the boundary of the parametrisation is constructed in the indirect trigonometric orderc order :type boundary_orientation: str :param fixed_boundary_points: list containing lists of two np.ndarrays. Each 2-member list is used to identify one point on the boundary: the first array contains the specified components, and the second the :type fixed_boundary_points: list :param starting_point_rank_on_boundary: node id (in the complete mesh) of the point on the boundary where the mapping starts :type starting_point_rank_on_boundary: int :param Returns: :param -------: :param Mesh: renumbered mesh :param ndarray(1) of ints: renumbering of the nodes of the returned renumbered mesh, with respect to in_mesh :param int: number of node of the boundary of in_mesh .. py:function:: floater_mesh_parametrization(in_mesh: Muscat.Containers.Mesh.Mesh, n_boundary: int, out_shape: str = 'circle', boundary_orientation: str = 'direct', curv_abs_boundary: bool = True, fixed_interior_points: Optional[dict[str, list]] = None, fixed_boundary_points: Optional[list] = None) -> Tuple[Muscat.Containers.Mesh.Mesh, dict[str, float]] STILL LARGELY EXPERIMENTAL. Only for linear triangular meshes Computes the Mesh Parametrization algorithm [1] proposed by Floater, in the case of target parametrization fitted to the unit 2D circle (R=1) or square (L=1). Adapted for ML need: the out_shape's boundary is sampled following the curvilinear abscissa along the boundary on in_mesh (only for out_shape = "circle" for the moment) :param in_mesh: Renumbered triangular mesh to parametrize :type in_mesh: Mesh :param n_boundary: number nodes on the line boundary :type n_boundary: int :param out_shape: if "circle", the boundary of in_mesh is mapped into the unit circle if "square", the boundary of in_mesh is mapped into the unit square :type out_shape: str :param boundary_orientation: if "direct, the boundary of the parametrisation is constructed in the direct trigonometric order if "indirect", the boundary of the parametrisation is constructed in the indirect trigonometric order :type boundary_orientation: str :param curv_abs_boundary: only if fixed_interior_points = None if True, the point density on the boundary of out_shape is the same as the point density on the boundary of in_mesh if False, the point density on the boundary is uniform :type curv_abs_boundary: bool :param fixed_interior_points: with one key, and corresponding value, a list: [ndarray(n), ndarray(n,2)], with n the number of interior points to be fixed; the first ndarray is the index of the considered interior point, the second ndarray is the corresponding prescribed positions if key is "mean", the interior points are displaced by the mean of the prescribed positions if key is "value", the interior points are displaced by the value of the prescribed positions :type fixed_interior_points: dict :param fixed_boundary_points: list of lists: [ndarray(2), ndarray(2)], helping definining a point in in_mesh; the first ndarray is the component of a point on the boundary, and the second array is the value of corresponding component. Tested for triangular meshes in the 3D space. :type fixed_boundary_points: list :param Returns: :param -------: :param Mesh: parametrization of mesh :param dict: containing 3 keys: "minEdge", "maxEdge" and "weights", with values floats containing the minimal and maximal edged length of the parametrized mesh, and the weights (lambda) in the Floater algorithm :param Attention: :param -----: mesh must be a renumbered Mesh of triangles (either in a 2D or 3D ambiant space), with a line boundary (no closed surface in 3D). out_shape = "circle" is more robust in the sense that is in_mesh has a 2D square-like, for triangles may ended up flat with out_shape = "square" :param References: :param ----------: [1] M. S. Floater. Parametrization and smooth approximation of surface triangulations, 1997. URL: https://www.sciencedirect.com/science/article/abs/pii/S0167839696000313