mmgp_blocks

Custom blocks for applying MMGP.

Includes: - MMGPPreparer. - MMGPTransformer.

Classes

MMGPPreparer

Preparer for MMGP.

MMGPTransformer

Adapter for using a scikit-learn transformer on PLAID Datasets.

Functions

compute_FE_projection_operator(→ Tuple[numpy.ndarray, ...)

Compute Finite Element Projection Operators.

compute_node_to_node_graph(→ networkx.Graph)

Creates a networkx graph from the node connectivity on a Mesh through edges.

initialize_graph_points_from_mesh_points(→ networkx.Graph)

Initializes a networkx graph with nodes consistant with the number of nodes of a Mesh.

renumber_mesh_for_parametrization(...)

Only for linear triangle meshes.

floater_mesh_parametrization(...)

STILL LARGELY EXPERIMENTAL.

Module Contents

class mmgp_blocks.MMGPPreparer(common_mesh_id: int | None = None, morphing: Callable | None = None)[source]

Bases: sklearn.base.TransformerMixin, sklearn.base.BaseEstimator

Preparer for MMGP.

Transforms

Parameters:
  • common_mesh_id

  • morphing

common_mesh_id = None[source]
morphing = None[source]
fit(dataset: plaid.containers.dataset.Dataset, _y=None)[source]

Fits the underlying scikit-learn transformer on selected input features.

Parameters:
  • dataset – A Dataset object containing the features to transform.

  • _y – Ignored.

Returns:

The fitted transformer.

Return type:

self

transform(dataset: plaid.containers.dataset.Dataset)[source]

Applies the fitted transformer to the selected input features.

Parameters:

dataset – A Dataset object to transform.

Returns:

Transformed features wrapped as a new Dataset.

Return type:

Dataset

inverse_transform(dataset: plaid.containers.dataset.Dataset)[source]

Applies inverse transformation to the output features.

Parameters:

dataset – A Dataset object with transformed output features.

Returns:

Dataset with inverse-transformed features.

Return type:

Dataset

class mmgp_blocks.MMGPTransformer(in_features_identifiers: list[dict] | None = None)[source]

Bases: sklearn.base.TransformerMixin, 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.

Parameters:
  • sklearn_block – A scikit-learn Transformer implementing fit/transform APIs.

  • in_features_identifiers – List of feature identifiers to extract input data from.

  • out_features_identifiers – List of feature identifiers used for outputs. If None, defaults to in_features_identifiers.

in_features_identifiers = None[source]
fit(dataset: plaid.containers.dataset.Dataset, _y=None)[source]

Fit.

Parameters:

dataset (Dataset) – The dataset used to fit the MMGPTransformer.

transform(dataset: plaid.containers.dataset.Dataset)[source]

Transform.

Parameters:

dataset (Dataset) – The dataset to transform.

inverse_transform(dataset: plaid.containers.dataset.Dataset)[source]

Inverse transform.

Parameters:

dataset (Dataset) – The dataset to inverse transform.

mmgp_blocks.compute_FE_projection_operator(origin_mesh: Muscat.Containers.Mesh.Mesh, target_mesh: Muscat.Containers.Mesh.Mesh, verbose: bool = False) Tuple[numpy.ndarray, numpy.ndarray][source]

Compute Finite Element Projection Operators.

Parameters:
  • origin_mesh (Mesh) – The original mesh data.

  • target_mesh (Mesh) – The target mesh data.

  • verbose (bool, optional) – Whether to display verbose output. Defaults to False.

Returns:

A tuple containing two projection operators (projOperator, invProjOperator).

Return type:

tuple(np.ndarray, np.ndarray)

mmgp_blocks.compute_node_to_node_graph(in_mesh: Muscat.Containers.Mesh.Mesh, dimensionality: int | None = None, dist_func: Callable | None = None) networkx.Graph[source]

Creates a networkx graph from the node connectivity on a Mesh through edges.

Parameters:
  • in_mesh (Mesh) – input mesh

  • dimensionality (int) – dimension of the elements considered to initalize the graph

  • dist_func (func) – function applied to the lengh of the edges of the mesh, and attached of the corresponding edge of the graph of the mesh

  • Returns

  • -------

  • networkx.Graph – Element to element graph

mmgp_blocks.initialize_graph_points_from_mesh_points(in_mesh: Muscat.Containers.Mesh.Mesh) networkx.Graph[source]

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.

Parameters:
  • in_mesh (Mesh) – input mesh

  • Returns

  • -------

  • networkx.Graph – initialized graph

mmgp_blocks.renumber_mesh_for_parametrization(in_mesh: Muscat.Containers.Mesh.Mesh, in_place: bool = True, boundary_orientation: str = 'direct', fixed_boundary_points: list | None = None, starting_point_rank_on_boundary: int | None = None) Tuple[Muscat.Containers.Mesh.Mesh, numpy.ndarray, int][source]

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.

Parameters:
  • in_mesh (Mesh) – input triangular to be renumbered

  • in_place (bool) – if “True”, in_mesh is modified if “False”, in_mesh is let unmodified, and a new mesh is produced

  • boundary_orientation (str) – 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

  • fixed_boundary_points (list) – 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

  • starting_point_rank_on_boundary (int) – node id (in the complete mesh) of the point on the boundary where the mapping starts

  • Returns

  • -------

  • Mesh – renumbered mesh

  • ints (ndarray(1) of) – renumbering of the nodes of the returned renumbered mesh, with respect to in_mesh

  • int – number of node of the boundary of in_mesh

mmgp_blocks.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: dict[str, list] | None = None, fixed_boundary_points: list | None = None) Tuple[Muscat.Containers.Mesh.Mesh, dict[str, float]][source]

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)

Parameters:
  • in_mesh (Mesh) – Renumbered triangular mesh to parametrize

  • n_boundary (int) – number nodes on the line boundary

  • out_shape (str) – 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

  • boundary_orientation (str) – 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

  • curv_abs_boundary (bool) – 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

  • fixed_interior_points (dict) – 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

  • fixed_boundary_points (list) – 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.

  • Returns

  • -------

  • Mesh – parametrization of mesh

  • 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

  • Attention

  • ----- – 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”

  • References

  • ---------- – [1] M. S. Floater. Parametrization and smooth approximation of surface triangulations, 1997. URL: https://www.sciencedirect.com/science/article/abs/pii/S0167839696000313