# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['bioval', 'bioval.metrics', 'bioval.tests', 'bioval.tutorials', 'bioval.utils']

package_data = \
{'': ['*'], 'bioval.tutorials': ['data/.placeholder', 'images/*']}

install_requires = \
['Pillow',
 'numpy',
 'nvidia-ml-py',
 'piq',
 'pot',
 'scikit-learn',
 'torch',
 'torchvision']

setup_kwargs = {
    'name': 'bioval',
    'version': '0.1.1.6b0',
    'description': 'Bioval is a Python package made to provide a wrapper and an easy access to a collection of evaluation metrics for comparing the similarity of two tensors, adapted to different evaluation processes of generative models applied to biological images.',
    'long_description': "# Bioval\nBioval is a Python package made to provide a wrapper and an easy access to a collection of evaluation metrics for comparing the similarity of two tensors, adapted to different evaluation processes of generative models applied to biological images, and by extension to natural images. The package support unconditional comparison cases, in which we have no labels separating different classes/conditions, and also supports conditional comparisons, with metrics adapted to evaluating the appropriateness of the generated images to all the distributions of real conditions. The package also supports distance of generated conditions from the real negative control condition, used in most biological contexts.\n\nThe package supports both images (with any number of channels) and encoded features of images. The compared tensors need to have the same shape. This package performs encoding of images using the InceptionV3 encoder pretrained on ImageNet dataset, but can also handle features encoded using different encoders.\n\n\n## Table of Content\n- [Bioval](#bioval)\n  * [Installation](#installation)\n    + [Installation from Pypip](#installation-from-pypip)\n    + [Installation from source](#installation-from-source)\n  * [Available Metrics](#available-metrics)\n    + [Overall KID/FID](#overall-kid-fid)\n    + [Intraclass KID/FID](#intraclass-kid-fid)\n    + [IntraClass Conditional Evaluation](#intraclass-conditional-evaluation)\n    + [InterClass Conditional Evaluation](#interclass-conditional-evaluation)\n    + [Distance from Control](#distance-from-control)\n  * [Usage settings](#usage-settings)\n    + [Aggregated](#aggregated)\n    + [Distributed](#distributed)\n  * [Quick Usage](#quick-usage)\n    + [Object Instanciation](#object-instanciation)\n    + [Input tensors](#input-tensors)\n    + [Aggregated Usage of the metrics](#aggregated-usage-of-the-metrics)\n  * [Contributing](#contributing)\n  * [License](#license)\n\n## Installation\n\n### Installation from Pypip\n\nYou can install the current alpha version through the command :\n\n```bash\npip install bioval\n```\n\n### Installation from source\nBioval can be built using the following command (from the root of this package):\n\n```bash\npoetry build\npip install dist/bioval-{version_number}.tar.gz\n```\n\n## Available Metrics\nThe following evaluation metrics are available in Bioval:\n\n### Overall KID/FID\nThis metric measures the KID/FID between two tensors, while being agnostic to the classes and conditions. this metric returns the overall KID/FID score.\n\n### Intraclass KID/FID\n\nThis metric measures the KID/FID score between two tensors (generated tensor and real tensor in the context of image generation) of the same class condition, and computes the mean of the score over all the classes. This metric returns the intraclass KID/FID score.\n\n\n### IntraClass Conditional Evaluation\nThis metric measures the top-k similarity between two tensors, both within and across classes. The metric returns the following scores: intra_top1, intra_top5, and intra_top10. In a detailled output context, it also returns the distance matrix between all generated and true conditions, computed according to the chosen distance method.\n\n### InterClass Conditional Evaluation\nThis metric evaluates the pearson correlation between the distances between generated classes and the distance between real classes. This evaluates if the generated class images keep the same class relationships and distances. This metric returns inter_corr as the interclass correlations between real and generated, and in a detailled output context, it also returns inter_p.\n\n### Distance from Control\nThis metric evaluates the difference between the distances of both generated class images and real class images from real control compounds, to measure if their relationship with the control compound (DMSO for example) is preserved. The metric returns the mean difference between the distance of real and generated conditions from control, as well as the individual difference for each class in the detailled output. The smaller the score, the more adapted the generated images are in the biological context.\n\n## Usage settings \n\n### Aggregated\n\nIn an aggregated setting, the features for each class/condition are aggregated together using a chosen aggregation method, before performing interclass/intraclass comparisons. The aggregated of the features of each class/condition is computed, and the resulting tensor is of shape (N, F), where N is the number of classes/conditions, and F is the number of features.\n\nThe following aggregation methods are available:\n\n- Mean\n\n- Median\n\n- Robust Mean\n\n\n### Distributed\n\nIn a distributed setting, we compute the distributed distance between the features of each class/condition. This approach takes an exponentially longer time to perform, but achieve more precise results.\n\nThe following distributed distance methods are available:\n\n- KID\n\n- FID\n\n\n## Quick Usage \n\n### Object Instanciation\n\nImporting the wrapper class : \n\n```python\nfrom bioval.metrics.conditional_evaluation import ConditionalEvaluation\n```\n\nCreating an object instance of the wrapper class :\n\n```python\ntopk = ConditionalEvaluation()\n```\n\nThe following parameters can be passed to the object constructor:\n\n- In an aggregated setting : \n\n    - aggregate: The aggregation method to use. Can be 'mean', 'median', or 'robust_mean'. Default is 'mean'. It is ignored in a distributed setting.\n\n    - method: The intraclass top-k similarity method to use. Can be 'cosine', 'euclidean', or 'chebyshev'. Default is 'euclidean'. It is ignored in a distributed setting.\n\n- In a distributed setting :\n\n    - distributed_method: The distributed distance method to use. Can be 'fid' or 'kid'. Default is 'kid'. It is ignored in an aggregated setting.\n\n\n### Input tensors\n\nThe package supports both images (with any number of channels) and encoded features of images. The input tensors can be of shape (N, I, H, W, C) or (N, H, W, C) or (N, I, F) or (N, F), where N is the number of classes/conditions, I is the number of instances, H is the height, W is the width, C is the number of channels, and F is the number of features.\n\nThe compared tensors need to have the same shape.\n\nExamples of possible input tensors : \n\n```python\n# 2D tensors (100 conditions, with one image \n# embedding in each condition of size 1024)\narr1 = torch.randn(100, 1024)\narr2 = torch.randn(100, 1024)\n\n# 3D tensors (100 conditions, with 10 image embeddings \n# in each condition of size 1024)\narr1 = torch.randn(100, 10, 1024)\narr2 = torch.randn(100, 10, 1024)\n\n# 4D tensors (100 conditions, with one image\n# in each condition of size 256x256x3)\narr1 = torch.randn(100, 256, 256, 3)\narr2 = torch.randn(100, 256, 256, 3)\n\n# 5D tensors (100 conditions, with 10 images\n# in each condition of size 256x256x3)\narr1 = torch.randn(100, 10, 256, 256, 3)\narr2 = torch.randn(100, 10, 256, 256, 3)\n\n\n# 5D tensors (100 conditions, with 10 images\n# in each condition of size 256x256x5 with 5 channels)\narr1 = torch.randn(100, 10, 256, 256, 5)\narr2 = torch.randn(100, 10, 256, 256, 5)\n\n\n# control array is a torch.Tensor object of shape (I, H, W, C) or \n# (H, W, C) or (I, F) or (F), where C is the number of channels, \n# H is the height, and W is the width of the input image, and \n# I the number of instances, and F is the number of features.\n\n# control array with 10 images and 3 channels\ncontrol = torch.randn(10, 256, 256, 3)\n\n# control array with 10 images and 5 channels\ncontrol = torch.randn(10, 256, 256, 5) # If control has 5 channels, array_1 and array_2 must also have 5 channels\n\n# control array with 1 image and 3 channels\ncontrol = torch.randn(256, 256, 3)\n\n# control array with 10 images and an embedding of size 1024\ncontrol = torch.randn(10, 1024)\n\n# control array with 1 image and an embedding of size 1024\ncontrol = torch.randn(1024)\n\n```\n\nIn the case where nb of channels in input images differs from 3 channels, each channel is encoded separately, and the embeddings of each channel are concatenated into one embedding. For example, if the input images have 5 channels, the output embedding will be of size 5*embedding_size.\n\n\n### Aggregated Usage of the metrics\n\nComputing all the metrics for our input tensors can be done using our created instance of our object, and passing the input tensors to it. The first and second arrays are mandatory inputs with no default values.\n\n```python\n\noutput = topk(arr1, arr2)\n```\n\nThe Object instance can be called with the following parameters:\n\n- arr1: The first input tensor, and a mandatory input. Can be of shape (N, I, H, W, C) or (N, H, W, C) or (N, I, F) or (N, F), where N is the number of classes/conditions, I is the number of instances, H is the height, W is the width, C is the number of channels, and F is the number of features.\n\n- arr2: The second input tensor, and a mandatory input. Can be of shape (N, I, H, W, C) or (N, H, W, C) or (N, I, F) or (N, F), where N is the number of classes/conditions, I is the number of instances, H is the height, W is the width, C is the number of channels, and F is the number of features. Array 1 and Array 2 must have the same shape.\n\n- control: The control tensor. Default is None when the distance from control metric is not of desired. When not None, it is a torch.Tensor object of shape (I, H, W, C) or (H, W, C) or (I, F) or (F), where C is the number of channels, H is the height, and W is the width of the input image, and I the number of instances, and F is the number of features.\n\n- k_range: The range of k values to use for the top-k similarity metrics. Default is [1, 5, 10]. If the range is bigger than the number of conditions, the range is truncated to the number of conditions. \n\n- aggregated : Whether to use the aggregated (if True) or distributed metrics (if False). Default is True.\n\n- detailed : Whether to return the detailed results of the metrics (if True) or not (if False). Default is True.\n\n- batch_size : The batch size to use for the encoding of the input images, to avoid out of memory issues. Default is 256.\n\n- percent : Percentage of images in each condition to be used for unconditional FID computation. Default is 0.1 (10%)\n\n\nOutput is a dictionary with all the computed metrics, and the same no matter the shape of the two arrays.\n    \n```javascript\n{\n        # KID/FID scores\n        'overall_kid': scalar, # if distributed method is kid and aggregated is False\n        'overall_fid': scalar, # if distributed method is fid and aggregated is False\n        'intra_kid': scalar, # if distributed method is kid and aggregated is False\n        'intra_fid': scalar, # if distributed method is fid and aggregated is False\n\n        # Control metric scores\n        'control_score': scalar, \n        'class_control_scores': numpy array, # if detailed output is True, control scores for each condition\n\n        # Interclass scores\n        'inter_corr': scalar, # interclass metric\n        'inter_pval': scalar, # if detailed output is True, p value of correlation\n        'interclass_matrix_1': numpy array, # if detailed output is True, interclass matrix of array 1\n        'interclass_matrix_2': numpy array, # if detailed output is True, interclass matrix of array 2\n\n        # intraclass scores\n        'intra_top1': scalar, \n        'intra_top5': scalar, \n        'intra_top10': scalar,\n        'mean_ranks': scalar, # if detailed output is True, mean ranks of intraclass distances matrix\n        'matrix': numpy array, # if detailed output is True, intraclass distances matrix between all conditions\n}\n```\n\n## Contributing\nContributions are welcome! Please refer to the [Contribute](https://github.com/IhabBendidi/bioval/blob/main/Contribute.md) file for details on how to contribute to Bioval.\n\n## License\nBioval is licensed under the MIT License. Please refer to the [License](https://github.com/IhabBendidi/bioval/blob/main/LICENSE) file for details.\n",
    'author': 'Ihab Bendidi',
    'author_email': 'bendidiihab@gmail.com',
    'maintainer': 'None',
    'maintainer_email': 'None',
    'url': 'None',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.8,<4.0',
}


setup(**setup_kwargs)
