### Install PyMDMA Package Source: https://github.com/fraunhoferportugal/pymdma/blob/main/docs/installation.md Installs the base PyMDMA package using pip. This is the fundamental command to get the library up and running. ```shell pip install pymdma ``` -------------------------------- ### Install PyMDMA with Image and Tabular Dependencies Source: https://github.com/fraunhoferportugal/pymdma/blob/main/docs/installation.md Installs PyMDMA with optional dependencies for both image and tabular data modalities. This allows users to work with multiple data types simultaneously. ```shell pip install pymdma[image,tabular] ``` -------------------------------- ### Install Poetry Dependencies with Specific Groups Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Command to install Poetry dependencies, including non-optional ones and those specified in the `--with` argument. This is useful for installing feature-specific dependencies. ```bash poetry install --with ,,... ``` -------------------------------- ### Install Extra Dependencies with Poetry Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Command to install extra dependencies defined in the `pyproject.toml` file. This is used for optional sets of dependencies. ```bash poetry install --extras ``` -------------------------------- ### Minimal PyMDMA Installation (CPU Only) Source: https://github.com/fraunhoferportugal/pymdma/blob/main/docs/installation.md Installs a minimal version of PyMDMA that uses the CPU version of PyTorch, skipping CUDA dependencies. This is useful for environments without GPU support. ```bash pip install pymdma[...] --find-url=https://download.pytorch.org/whl/cpu/torch_stable.html ``` -------------------------------- ### Install PyMDMA from Source Source: https://github.com/fraunhoferportugal/pymdma/blob/main/README.md Installs the PyMDMA package directly from its GitHub repository. This is the primary method for obtaining the latest version. Additional dependencies for specific data modalities (image, tabular, time_series) can be installed by appending the modality in brackets. ```bash pip install "pymdma @ git+https://github.com/fraunhoferportugal/pymdma.git" pip install "pymdma[image] @ git+https://github.com/fraunhoferportugal/pymdma.git" # image dependencies pip install "pymdma[tabular] @ git+https://github.com/fraunhoferportugal/pymdma.git" # tabular dependencies pip install "pymdma[time_series] @ git+https://github.com/fraunhoferportugal/pymdma.git" # time series dependencies ``` -------------------------------- ### Install Pre-commit Git Hooks Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Command to install the pre-commit Git hooks locally. These hooks run checks before each commit to ensure code quality and consistency. ```bash pre-commit install ``` -------------------------------- ### Install PyMDMA with Image Dependencies Source: https://github.com/fraunhoferportugal/pymdma/blob/main/docs/installation.md Installs PyMDMA along with additional dependencies required for working with image data. This command ensures all necessary libraries for image processing are included. ```shell pip install pymdma[image] ``` -------------------------------- ### Install pyMDMA with Modality-Specific Dependencies Source: https://github.com/fraunhoferportugal/pymdma/blob/main/README.md Installs pyMDMA along with specific dependencies for different data modalities. Choose the command corresponding to the modality you intend to use. 'all' installs dependencies for all supported modalities. ```bash pip install pymdma[image] pip install pymdma[tabular] pip install pymdma[time_series] pip install pymdma[all] ``` -------------------------------- ### Install Only Specific Poetry Dependency Groups Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Command to install only the specified dependency groups using Poetry. This is useful for setting up minimal environments or for specific development tasks. ```bash poetry install --only ,,... ``` -------------------------------- ### Install PyMDMA with Tabular Support and PyTorch CPU Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/tabular_examples.ipynb Installs the PyMDMA library with optional tabular data support and specifies a PyTorch wheel URL for CPU-only installations. This command ensures all necessary dependencies for tabular data analysis are met. ```bash %pip install "pymdma[tabular]" --find-links "https://download.pytorch.org/whl/cpu/torch_stable.html" ``` -------------------------------- ### Install Git Pre-commit Hook for Commit Messages Source: https://github.com/fraunhoferportugal/pymdma/blob/main/CONTRIBUTING.md This command installs the pre-commit hook specifically for commit messages, ensuring adherence to conventional commit standards before commits are finalized. It requires the 'pre-commit' tool to be installed. ```bash pre-commit install --hook-type commit-msg ``` -------------------------------- ### Markdown Link Syntax Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Example of how to write local and external links in Markdown files according to the project's conventions. External links are referenced at the end of the file. ```markdown Use a local link to reference the `README.md` file, but an external link for [Fraunhofer AICOS][fhp-aicos]. [fhp-aicos]: https://www.fraunhofer.pt/ ``` -------------------------------- ### Installing a Custom IPython Kernel (Bash) Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/README.md Command to install a custom IPython kernel for the PyMDMA project within its virtual environment. This allows Jupyter to use the project's specific dependencies and configurations. ```bash python -m ipykernel install --user --name="pymdma" ``` -------------------------------- ### Install PyMDMA with CPU Torch Source: https://github.com/fraunhoferportugal/pymdma/blob/main/README.md Installs PyMDMA with CPU-only PyTorch support by forcing pip to use the CPU index. This is useful for environments where CUDA is not available or desired. ```bash pip install "pymdma @ git+https://github.com/fraunhoferportugal/pymdma.git" --find-url https://download.pytorch.org/whl/cpu ``` -------------------------------- ### Set Private Environment Variables Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Example of how to set private environment variables in a .env file. This file should not be version-controlled. Variables defined here are automatically loaded into the application's configuration. ```dotenv MY_VAR=/home/user/my_system_path ``` -------------------------------- ### Download CIFAKE Dataset using KaggleHub Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/image_examples.ipynb This snippet installs the kagglehub library and downloads the CIFAKE dataset from Kaggle. It configures the default cache folder and prints the path to the downloaded dataset. ```python %pip install kagglehub import kagglehub from pathlib import Path kagglehub.config.DEFAULT_CACHE_FOLDER = Path("data/.kagglehub") cifake_path = kagglehub.dataset_download("birdy654/cifake-real-and-ai-generated-synthetic-images") cifake_path = Path(cifake_path) print("Downloaded CIFake dataset to ", str(cifake_path)) ``` -------------------------------- ### Build and Run PyMDMA Docker Image Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Commands to build the Docker image for the PyMDMA REST API server and run it. The build command tags the image as 'pymdma'. The run command starts the container in detached mode, maps host port 8080 to container port 8000, and mounts a local 'data' directory to '/app/data/' within the container. Access the server documentation at http://localhost:8080/docs. ```shell docker build -t pymdma . ``` ```shell docker run -d -p 8080:8000 -v ./data/:/app/data/ pymdma ``` -------------------------------- ### Configure Optional Poetry Dependency Group Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Configuration snippet for `pyproject.toml` to define an optional dependency group in Poetry. This allows for dependencies that are not installed by default. ```toml [tool.poetry.group.] optional = true [tool.poetry.group..dependencies] ... ``` -------------------------------- ### Importing Modules in Jupyter Notebooks (Python) Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/README.md Demonstrates how to import helper modules from the project's directory structure into a Jupyter notebook. This assumes the parent folder of the notebook is added to the Python import path. ```python import imports # or from imports import package_installed ``` -------------------------------- ### Install PyMDMA with Image Support Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/image_examples.ipynb Installs the PyMDMA package with optional image support and specifies a PyTorch CPU-only index URL. This command ensures all necessary dependencies for image processing are included. ```shell %pip install "pymdma[image]" --extra-index-url "https://download.pytorch.org/whl/cpu/torch_stable.html" ``` -------------------------------- ### Install pyMDMA without GPU Support Source: https://github.com/fraunhoferportugal/pymdma/blob/main/README.md Installs pyMDMA with CPU-only PyTorch dependencies, disabling GPU-accelerated features. This is useful for environments without CUDA support or when GPU acceleration is not required. ```bash pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu pip install pymdma ``` -------------------------------- ### Build Image Dataloader for Batch Processing - Python Source: https://github.com/fraunhoferportugal/pymdma/blob/main/docs/guides/image_guides.md Demonstrates how to use `build_img_dataloader` from `pymdma.image.data` to create a dataloader for processing large image datasets in batches. This prevents out-of-memory errors by loading images in smaller chunks. It takes file paths, batch size, and number of workers as input and yields batches of images. ```python from pathlib import Path from pymdma.image.data import build_img_dataloader from pymdma.image.measures.input_val import Brightness # obtain image file paths image_files = list(Path("path-to-large-img-dataset").iterdir()) dataloader = build_img_dataloader( file_paths=image_files, batch_size=10, num_workers=5, ) # compute brightness results and save them brightness = Brightness() brightness_results = [] for imgs, _, _ in dataloader: brightness_results += brightness.compute(imgs).value[1] print("Brightness results:", brightness_results) ``` -------------------------------- ### Compute PSNR Metric with Pymdma Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/image_examples.ipynb Demonstrates the computation of the Peak Signal-to-Noise Ratio (PSNR) metric using the `PSNR` class from `pymdma.image.measures.input_val`. The example shows how to initialize the PSNR object, compute the metric between reference and distorted images, and then plot the instance-level scores. ```python from pymdma.image.measures.input_val import PSNR psnr = PSNR(convert_to_grayscale=True) psnr_result = psnr.compute(reference, distorted) _, instance_level = psnr_result.value for i in range(0, len(instance_level), N_DISTORTIONS): plot_instances_score(distorted[i : i + N_DISTORTIONS], "PSNR", instance_level[i : i + N_DISTORTIONS]) ``` -------------------------------- ### Install PyMDMA with Time Series Support Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/time_series_examples.ipynb Installs the PyMDMA package with the 'time_series' extra, which includes necessary dependencies for time series analysis. It also specifies a custom URL for PyTorch CPU wheels. ```bash %pip install "pymdma[time_series]" --find-links "https://download.pytorch.org/whl/cpu/torch_stable.html" ``` -------------------------------- ### Evaluate Synthetic Image Dataset using PyMDMA CLI Source: https://github.com/fraunhoferportugal/pymdma/blob/main/README.md An example of using the PyMDMA CLI to evaluate a synthetic image dataset against a reference dataset. It specifies the modality, validation domain, data paths, batch size, metric category, and output directory for the evaluation report. ```bash pymdma --modality image \ --validation_domain synth \ --reference_type dataset \ --evaluation_level dataset \ --reference_data data/test/image/synthesis_val/reference \ --target_data data/test/image/synthesis_val/dataset \ --batch_size 3 \ --metric_category feature \ --output_dir reports/image_metrics/ ``` -------------------------------- ### Configuring nbstripout to Keep Cell Output (JSON) Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/README.md Shows how to configure nbstripout to retain specific cell outputs in Jupyter notebooks. This can be done by adding a 'keep_output' tag to the cell or by modifying the cell's metadata. ```json { "keep_output": true } ``` -------------------------------- ### Build Documentation with MkDocs Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Commands to build the project documentation using MkDocs. The first command builds the static files, and the second serves them locally for preview. ```shell make mkdocs-build make mkdocs-serve ``` -------------------------------- ### Prepare Datasets for Evaluation Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/tabular_examples.ipynb This snippet initializes datasets, reference data, and corresponding names and tags for evaluation. It creates copies of the reference dataset and defines lists for datasets, names, and tags, which will be used in subsequent evaluation steps. ```python # Datasets # input validation dataset_list = [dataset_ref, dataset_s1, dataset_s2, dataset_s3, dataset_s4, dataset_s5] # target dataset list ref = np.copy(dataset_ref) # reference dataset names = [name_ref, name_syn1, name_syn2, name_syn3, name_syn4, name_syn5] # dataset names tag_list = [tag_ref, tag_syn1, tag_syn2, tag_syn3, tag_syn4, tag_syn5] # dataset tags ``` -------------------------------- ### Evaluate Image Sharpness using Tenengrad Metric Source: https://github.com/fraunhoferportugal/pymdma/blob/main/README.md Demonstrates how to import and use the Tenengrad metric from PyMDMA to evaluate the sharpness of input images. It shows the process of initializing the metric, computing sharpness on a batch of images, and extracting both dataset-level (which is None in this case) and instance-level sharpness values. ```python from pymdma.image.measures.input_val import Tenengrad import numpy as np images = np.random.rand(10, 224, 224, 3) # 10 random RGB images of size 224x224 tenengrad = Tenengrad() # sharpness metric sharpness = tenengrad.compute(images) # compute on RGB images # get the instance level value (dataset level is None) _dataset_level, instance_level = sharpness.value ``` -------------------------------- ### Run All Pre-commit Git Hooks Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Command to manually run all configured pre-commit Git hooks. This is useful for checking code quality without staging changes. ```bash pre-commit run ``` -------------------------------- ### Development Commands with Make Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Common development commands for the PyMDMA project, including running tests, linting, formatting, and cleaning artifacts. These commands are defined in the Makefile. ```bash # For running tests locally make test ``` ```bash # For formatting and linting make lint make format make format-fix ``` ```bash # Remove all generated artifacts make clean ``` -------------------------------- ### List PyMDMA CLI Commands Source: https://github.com/fraunhoferportugal/pymdma/blob/main/README.md Displays the available commands and options for the PyMDMA command-line interface. This is the first step to understanding how to use PyMDMA for dataset evaluation via the terminal. ```bash pymdma --help # list available commands ``` -------------------------------- ### Python: Compute Brightness and Colorfulness Source: https://context7.com/fraunhoferportugal/pymdma/llms.txt Computes brightness and colorfulness metrics for images using the HSP color model and opponent color theory. Requires image data as a NumPy array. ```python from pymdma.image.measures.input_val import Brightness, Colorfulness import numpy as np # Create test images images = np.random.rand(10, 100, 100, 3) * 255 images = images.astype(np.uint8) ``` -------------------------------- ### Enabling Autoreload in Jupyter Notebooks (IPython) Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/README.md Provides IPython magic commands to enable autoreload for Python modules within a Jupyter notebook or IPython REPL. This automatically loads the latest changes from saved Python modules without requiring a kernel restart. ```ipython %load_ext autoreload %autoreload 2 ``` -------------------------------- ### Python: Compute CLIP-IQA Image Quality Source: https://context7.com/fraunhoferportugal/pymdma/llms.txt Evaluates perceptual quality of images using a CLIP model for general image quality assessment. Requires image data and returns instance-level perceptual quality scores. ```python from pymdma.image.measures.input_val import CLIPIQA import numpy as np # Prepare images images = np.random.rand(8, 512, 512, 3) * 255 images = images.astype(np.uint8) # Initialize CLIP-IQA clip_iqa = CLIPIQA( img_size=(512, 512), data_range=255, device="cpu" ) # Compute quality scores result = clip_iqa.compute(images) _, instance_scores = result.value print(f"CLIP-IQA scores: {instance_scores.value}") # Higher scores indicate better perceptual quality ``` -------------------------------- ### Run Pytest Tests Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Command to execute all tests in the project using the pytest framework. The `-vvv` flag increases verbosity for detailed output. ```shell pytest -vvv ``` -------------------------------- ### Generate Synthetic Datasets with pymdma Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/tabular_examples.ipynb Demonstrates the creation of various synthetic datasets using the `make_dataset` function and NumPy for distortions. These datasets vary in dimensionality, sample size, and feature informativeness, serving as inputs for downstream analysis. ```python tag_in4 = "D" name_in4 = "D - Small Vol. + Non-Inform." dataset_in4 = make_dataset( n_samples=200, n_features=100, n_informative=1, n_repeated=0, n_redundant=99, n_classes=2, n_clusters_per_class=1, weights=None, flip_y=0.01, shift=0.0, scale=3.0, shuffle=True, random_state=42, ).to_numpy() # reference dataset tag_ref = "R" name_ref = "R - Reference Dataset" dataset_ref = make_dataset( n_samples=2000, n_features=10, n_informative=5, n_repeated=2, n_redundant=3, n_classes=2, n_clusters_per_class=1, weights=None, flip_y=0.01, shift=0.0, scale=3.0, shuffle=True, random_state=42, ).to_numpy() # A --> random dataset tag_syn1 = "A" name_syn1 = "A - Random" dataset_s1 = np.random.random(dataset_ref.shape) * 3.0 # B --> cumulative small distortion tag_syn2 = "B" name_syn2 = "B - Small Add Distortion" rnd = np.random.random(dataset_ref.shape) * 0.01 dataset_s2 = np.copy(dataset_ref) + rnd # C --> cumulative large distortion tag_syn3 = "C" name_syn3 = "C - Large Add Distortion" rnd = np.random.random(dataset_ref.shape) * 100 dataset_s3 = np.copy(dataset_ref) + rnd # D --> small multiplicative distortion tag_syn4 = "D" name_syn4 = "D - Small Mult. Distortion" rnd = 0.7 dataset_s4 = np.copy(dataset_ref) * rnd # E --> large multiplicative distortion tag_syn5 = "E" name_syn5 = "E - Large Mult. Distortion" rnd = 100 dataset_s5 = np.copy(dataset_ref) * rnd ``` -------------------------------- ### Implement New Metric Class in Python Source: https://github.com/fraunhoferportugal/pymdma/blob/main/docs/implement_metrics.md This Python code demonstrates how to create a new metric by inheriting from the base Metric class in pymdma. It includes the implementation of __init__ and compute methods, along with setting essential class attributes and providing comprehensive documentation. ```python from pymdma.common.definitions import Metric from pymdma.common.output import MetricResult from pymdma.constants import EvaluationLevel, MetricGroup, OutputsTypes, ReferenceType class NewMetric(Metric): """Metric description **Objective**: An objective Parameters ---------- **kwargs : dict, optional Additional keyword arguments for compatibility. References ---------- Author et al. Paper title (year). . Examples -------- >>> new_metric = NewMetric() >>> data = np.random.rand(100, 100) >>> result: MetricResult = new_metric.compute(data) """ reference_type = ReferenceType.NONE evaluation_level = EvaluationLevel.INSTANCE metric_group = MetricGroup.QUALITY higher_is_better: bool = False min_value: float = 0.0 max_value: float = 1.0 def __init__( self, **kwargs, ): super().__init__(**kwargs) def compute(self, data, **kwargs) -> MetricResult: """Computes colorfulness level of list of images. Parameters ---------- data : type description Returns ------- result: MetricResult small description """ # Delete one of the level results if the metric only has a single evaluation level return MetricResult( dataset_level={ "dtype": OutputsTypes.NUMBER, "subtype": "float", "value": 0.0, }, instance_level={ "dtype": OutputsTypes.ARRAY, "subtype": "float", "value": scores, }, ) ``` -------------------------------- ### Compute Improved Precision and Recall for Synthetic Data Source: https://github.com/fraunhoferportugal/pymdma/blob/main/README.md Demonstrates the computation of Improved Precision and Improved Recall metrics for synthetic datasets using pre-extracted features. It shows how to initialize the metrics, compute the results, and extract both dataset-level and instance-level values for reporting. ```python from pymdma.image.measures.synthesis_val import ImprovedPrecision, ImprovedRecall ip = ImprovedPrecision() # Improved Precision metric ir = ImprovedRecall() # Improved Recall metric # Compute the metrics ip_result = ip.compute(ref_features, synth_features) ir_result = ir.compute(ref_features, synth_features) # Get the dataset and instance level values precision_dataset, precision_instance = ip_result.value recall_dataset, recall_instance = ir_result.value # Print the results print(f"Precision: {precision_dataset:.2f} | Recall: {recall_dataset:.2f}") print(f"Precision: {precision_instance} | Recall: {recall_instance}") ``` -------------------------------- ### Run Pytest with Code Coverage Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Commands to run tests with code coverage enabled and generate an HTML report. This helps in identifying parts of the code that are not covered by tests. ```shell coverage run -m pytest coverage html ``` -------------------------------- ### Make Shell Script Executable for Git Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Command to make a shell script executable and stage it for Git. This is necessary for scripts intended to be run as part of the Git workflow or hooks. ```bash git update-index --chmod=+x scripts/name_of_script.sh ``` -------------------------------- ### Python: Compute Tenengrad Image Sharpness Source: https://context7.com/fraunhoferportugal/pymdma/llms.txt Computes the Tenengrad score for image sharpness using the Tenengrad class. Requires image data as a NumPy array and returns dataset-level and instance-level sharpness scores. ```python from pymdma.image.measures.input_val import Tenengrad import numpy as np # Create random test images (N, H, W, C) - RGB format images = np.random.rand(10, 224, 224, 3) * 255 images = images.astype(np.uint8) # Initialize and compute sharpness metric tenengrad = Tenengrad(kernel_size=3, threshold=0) result = tenengrad.compute(images) # Get instance-level results (per-image scores) dataset_level, instance_level = result.value print(f"Sharpness scores per image: {instance_level.value[:5]}") # Output: Sharpness scores per image: [42.15, 38.92, 45.67, 40.23, 43.89] ``` -------------------------------- ### CLI: Evaluate Input Data Quality Source: https://context7.com/fraunhoferportugal/pymdma/llms.txt Evaluates the quality of input tabular data without a reference dataset. Requires specifying modality, validation domain, target data path, metric category, and output directory. ```bash pymdma --modality tabular \ --validation_domain input \ --reference_type none \ --target_data data/test/tabular/input_val/dataset \ --metric_category quality \ --output_dir reports/tabular_metrics/ ``` -------------------------------- ### Add Package to Poetry Dependency Group Source: https://github.com/fraunhoferportugal/pymdma/blob/main/DEVELOPER.md Command to add a specific package to a named dependency group in Poetry. This helps in organizing project dependencies for different environments or features. ```bash poetry add --group ``` -------------------------------- ### Python: Compute BRISQUE Image Quality Source: https://context7.com/fraunhoferportugal/pymdma/llms.txt Computes the Blind/Referenceless Image Spatial Quality Evaluator (BRISQUE) score for no-reference image quality assessment. Takes image data and returns instance-level quality scores. ```python from pymdma.image.measures.input_val import BRISQUE import numpy as np # Load or create test images images = np.random.rand(5, 256, 256, 3) * 255 images = images.astype(np.uint8) # Initialize BRISQUE metric brisque = BRISQUE( kernel_size=7, kernel_sigma=7/6, data_range=255, device="cpu", same_size=True # Faster computation when all images have same size ) # Compute quality scores result = brisque.compute(images) _, instance_scores = result.value print(f"BRISQUE scores: {instance_scores.value}") # Lower scores indicate better quality ``` -------------------------------- ### Generate Sample Datasets for Validation Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/tabular_examples.ipynb Creates synthetic datasets with varying characteristics (sample size, feature informativeness, dimensionality) using scikit-learn's `make_dataset` function. These datasets are intended for input validation and testing of data processing pipelines. The generated data is converted to NumPy arrays. ```python from sklearn.datasets import make_dataset ## Input validation # A --> High Volume of Samples + Informative Features tag_in1 = "A" name_in1 = "A - High Vol. + Inform." dataset_in1 = make_dataset( n_samples=2000, n_features=10, n_informative=10, n_repeated=0, n_redundant=0, n_classes=2, n_clusters_per_class=1, weights=None, flip_y=0.01, shift=0.0, scale=3.0, shuffle=True, random_state=42, ).to_numpy() # B --> High Volume of Samples + Non-Informative Features tag_in2 = "B" name_in2 = "B - High Vol. + Non-Inform." dataset_in2 = make_dataset( n_samples=2000, n_features=10, n_informative=1, n_repeated=3, n_redundant=6, n_classes=2, n_clusters_per_class=1, weights=None, flip_y=0.01, shift=0.0, scale=3.0, shuffle=True, random_state=42, ).to_numpy() # C --> Small Volume of Samples + High Dimensionality + Informative Features tag_in3 = "C" name_in3 = "C - Small Vol. + Inform." dataset_in3 = make_dataset( n_samples=200, n_features=100, n_informative=95, n_repeated=2, n_redundant=3, n_classes=2, n_clusters_per_class=1, weights=None, flip_y=0.01, shift=0.0, scale=3.0, shuffle=True, random_state=42, ).to_numpy() ``` -------------------------------- ### Extract Features for Synthetic Image Evaluation Source: https://github.com/fraunhoferportugal/pymdma/blob/main/README.md Shows how to use the ExtractorFactory to load a feature extractor (e.g., 'vit_b_32') and extract features from both reference (real) and synthetic image datasets. This is a prerequisite for calculating synthesis validation metrics like Improved Precision and Recall. ```python from pymdma.image.models.features import ExtractorFactory from pathlib import Path test_images_ref = Path("./data/test/image/synthesis_val/reference") # real images test_images_synth = Path("./data/test/image/sythesis_val/dataset") # synthetic images # Get image filenames images_ref = list(test_images_ref.glob("*.jpg")) images_synth = list(test_images_synth.glob("*.jpg")) # Extract features from images extractor = ExtractorFactory.model_from_name(name="vit_b_32") ref_features = extractor.extract_features_from_files(images_ref) synth_features = extractor.extract_features_from_files(images_synth) ``` -------------------------------- ### Import Core Libraries for Data Analysis and Visualization Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/tabular_examples.ipynb Imports essential Python libraries for data manipulation, scientific computing, machine learning, and plotting. These libraries include pandas for dataframes, numpy for numerical operations, matplotlib for plotting, and scikit-learn for machine learning algorithms. ```python from typing import Callable, List, Tuple import matplotlib.pyplot as plt import numpy as np import pandas as pd from matplotlib.offsetbox import AnchoredText from scipy.stats import gaussian_kde from sklearn.datasets import make_classification from sklearn.neighbors import NearestNeighbors ``` -------------------------------- ### Create Synthetic Classification Dataset (Python) Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/tabular_examples.ipynb Generates a synthetic classification dataset using scikit-learn's `make_classification`. It returns a pandas DataFrame with generated features and a target column. Accepts arbitrary arguments and keyword arguments to customize the dataset generation. Dependencies include pandas and scikit-learn. ```python import pandas as pd from sklearn.datasets import make_classification def make_dataset(*args, **kwargs): # generated data X, y = make_classification(*args, **kwargs) # columns cols = [f"att_{idx}" for idx in range(X.shape[-1])] # dataframe conversion X_df = pd.DataFrame(X, columns=cols) X_df["tgt"] = y return X_df ``` -------------------------------- ### Visualize Precise and Imprecise CIFAKE Samples Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/image_examples.ipynb This code visualizes precise and imprecise synthetic samples based on the instance-level precision scores. It randomly selects samples, loads them as images, and displays them in grids using the `plot_instances_grid` function. ```python import random from PIL import Image import matplotlib.pyplot as plt import numpy as np random.seed(12) precision_instance = np.array(precision_instance) imprecise_idx = np.argwhere(precision_instance < 1).flatten() precise_idx = np.argwhere(precision_instance >= 1).flatten() precise_samples = random.sample(list(precise_idx), 200) imprecise_samples = random.sample(list(imprecise_idx), 200) precise_samples = [np.asarray(Image.open(images_synth[i])) for i in precise_samples] imprecise_samples = [np.asarray(Image.open(images_synth[i])) for i in imprecise_samples] precise_fig = plot_instances_grid(precise_samples, n_cols=25) precise_fig.suptitle("CIFAKE Precise samples", fontsize=16) plt.show() imprecise_fig = plot_instances_grid(imprecise_samples, n_cols=25) imprecise_fig.suptitle("CIFAKE Imprecise samples", fontsize=16) plt.show() ``` -------------------------------- ### BibTeX Citation for pyMDMA Project Source: https://github.com/fraunhoferportugal/pymdma/blob/main/README.md Provides a BibTeX entry for citing the pyMDMA project itself, typically used for software or general references. It includes the project title, GitHub URL, authoring entity, and license. ```bibtex @misc{pymdma, title = {{pyMDMA}: Multimodal Data Metrics for Auditing real and synthetic datasets}, url = {https://github.com/fraunhoferportugal/pymdma}, author = {Fraunhofer AICOS}, license = {LGPL-3.0}, year = {2024}, } ``` -------------------------------- ### Visualize Best and Worst CIFAKE Samples by GIQA Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/image_examples.ipynb This code identifies and visualizes the top 200 best and worst synthetic samples based on their instance-level GIQA scores. It loads these images and displays them in grids using the `plot_instances_grid` function. ```python import matplotlib.pyplot as plt import numpy as np from PIL import Image best_idx = np.argsort(giqa_instance)[::-1][:200] best_samples = [np.asarray(Image.open(images_synth[i])) for i in best_idx] best_fig = plot_instances_grid(best_samples, n_cols=25) best_fig.suptitle("CIFAKE Best samples", fontsize=16) plt.show() worst_idx = np.argsort(giqa_instance)[:200] worst_samples = [np.asarray(Image.open(images_synth[i])) for i in worst_idx] worst_fig = plot_instances_grid(worst_samples, n_cols=25) worst_fig.suptitle("CIFAKE Worst samples", fontsize=16) plt.show() ``` -------------------------------- ### Import Necessary Libraries for Time Series Analysis Source: https://github.com/fraunhoferportugal/pymdma/blob/main/notebooks/time_series_examples.ipynb Imports essential Python libraries for data manipulation, file handling, plotting, and working with WFDB (Wave Form DataBase) files. These are foundational for loading and processing physiological signals. ```python import os from pathlib import Path import matplotlib.pyplot as plt import numpy as np import wfdb ``` -------------------------------- ### Compute StatisticalSimScore for Distribution Similarity Source: https://context7.com/fraunhoferportugal/pymdma/llms.txt Compares statistical properties between real and synthetic datasets using Kolmogorov-Smirnov (KS) and Total Variation (TV) tests. It requires a column map defining data types. ```python from pymdma.tabular.measures.synthesis_val import StatisticalSimScore import numpy as np # Real and synthetic data real_data = np.random.rand(100, 4) syn_data = np.random.rand(100, 4) + 0.1 # Slightly shifted col_map = { "col_0": {"type": {"tag": "continuous"}}, "col_1": {"type": {"tag": "continuous"}}, "col_2": {"type": {"tag": "discrete"}}, "col_3": {"type": {"tag": "continuous"}}, } sim_score = StatisticalSimScore(col_map=col_map) result = sim_score.compute(real_data, syn_data) similarity_per_column = result.value[0] stats = result.stats[0] print(f"Similarity scores: {similarity_per_column}") print(f"Mean similarity: {stats['mean']:.2f}") ```