# Path: hub_toolbox/hubness_analysis.py
# CITATION = \
# """
# R. Feldbauer, M. Leodolter, C. Plant and A. Flexer,
# "Fast Approximate Hubness Reduction for Large High-Dimensional Data",
# 2018 IEEE International Conference on Big Knowledge (ICBK), Singapore, 2018,
# pp. 358-367. doi: 10.1109/ICBK.2018.00055
# (tech report available at http://www.ofai.at/cgi-bin/tr-online?number+2018-02)
# 
# or
# 
# R. Feldbauer, A. Flexer, "A comprehensive empirical comparison of hubness reduction in high-dimensional spaces"
# Knowledge and Information Systems, 2018, https://doi.org/10.1007/s10115-018-1205-y
# """
# SEC_DIST = {'mp': mutual_proximity_empiric,
#             'mp_gaussi': mutual_proximity_gaussi,
#             'mp_gammai': mutual_proximity_gammai,
#             'ls': local_scaling,
#             'nicdm': nicdm,
#             'snn': shared_nearest_neighbors,
#             'cent': centering,
#             'wcent': weighted_centering,
#             'lcent': localized_centering,
#             'dsg': dis_sim_global,
#             'dsl': dis_sim_local,
#             'orig': _primary_distance  # a dummy function
#             }
# def _primary_distance(D: np.ndarray, metric):
#     def __init__(self, D: np.ndarray = None, classes: np.ndarray = None,
#                  vectors: np.ndarray = None, metric: str = 'distance'):
#     def _header(self):
#     def _calc_intrinsic_dim(self):
#     def analyze_hubness(self, experiments="orig,mp,mp_gaussi,nicdm,cent,dsg",
#                         hubness_k=(5, 10), knn_k=(1, 5, 20),
#                         print_results=True, verbose: int = 0):
#     def print_analysis_report(self, experiment=None, report_nr:int=0):
#     def __init__(self, D: np.ndarray, secondary_distance_type: str,
#                  metric: str = 'distance', classes: np.ndarray = None,
#                  vectors: np.ndarray = None):
#     def _calc_secondary_distance(self):
#     def _calc_hubness(self, k: int = 5):
#     def _calc_knn_accuracy(self, k: int = 5):
#     def _calc_gk_index(self):
# class HubnessAnalysis:
# class HubnessExperiment:
# 
# Path: hub_toolbox/distances.py
# def euclidean_distance(X):
#     """Calculate the euclidean distances between all pairs of vectors in `X`.
#     
#     Consider using sklearn.metric.pairwise.euclidean_distances for faster,
#     but less accurate distances (not necessarily symmetric, too)."""
#     return squareform(pdist(X, 'euclidean'))


import unittest
import numpy as np
from hub_toolbox import hubness_analysis
from hub_toolbox.distances import euclidean_distance
"""
This file is part of the HUB TOOLBOX available at
https://github.com/OFAI/hub-toolbox-python3/
The HUB TOOLBOX is licensed under the terms of the GNU GPLv3.

(c) 2016-2018, Roman Feldbauer
Austrian Research Institute for Artificial Intelligence (OFAI)
Contact: <roman.feldbauer@ofai.at>
"""

class TestHubnessAnalysis(unittest.TestCase):
    """Test the hubness_analysis class (check for results,
       but not for *correct* results.)
    """

    def setUp(self):
        points = 100
        dim = 10
        self.vector = 99. * (np.random.rand(points, dim) - 0.5)
        self.label = np.random.randint(0, 5, points)
        self.dist = euclidean_distance(self.vector)
        self.SEC_DIST = set(['mp', 'mp_gaussi', 'mp_gammai', 
                            'ls', 'nicdm', 'snn', 'cent', 'wcent', 'lcent', 
                            'dsg', 'dsl', 'orig'])

    def tearDown(self):
        del self.dist, self.label, self.vector, self.SEC_DIST

    def test_all_sec_dist_are_covered_in_unittests(self):
        n_self_sec_dist = len(self.SEC_DIST)

# Path: hub_toolbox/hubness_analysis.py
# CITATION = \
# """
# R. Feldbauer, M. Leodolter, C. Plant and A. Flexer,
# "Fast Approximate Hubness Reduction for Large High-Dimensional Data",
# 2018 IEEE International Conference on Big Knowledge (ICBK), Singapore, 2018,
# pp. 358-367. doi: 10.1109/ICBK.2018.00055
# (tech report available at http://www.ofai.at/cgi-bin/tr-online?number+2018-02)
# 
# or
# 
# R. Feldbauer, A. Flexer, "A comprehensive empirical comparison of hubness reduction in high-dimensional spaces"
# Knowledge and Information Systems, 2018, https://doi.org/10.1007/s10115-018-1205-y
# """
# SEC_DIST = {'mp': mutual_proximity_empiric,
#             'mp_gaussi': mutual_proximity_gaussi,
#             'mp_gammai': mutual_proximity_gammai,
#             'ls': local_scaling,
#             'nicdm': nicdm,
#             'snn': shared_nearest_neighbors,
#             'cent': centering,
#             'wcent': weighted_centering,
#             'lcent': localized_centering,
#             'dsg': dis_sim_global,
#             'dsl': dis_sim_local,
#             'orig': _primary_distance  # a dummy function
#             }
# def _primary_distance(D: np.ndarray, metric):
#     def __init__(self, D: np.ndarray = None, classes: np.ndarray = None,
#                  vectors: np.ndarray = None, metric: str = 'distance'):
#     def _header(self):
#     def _calc_intrinsic_dim(self):
#     def analyze_hubness(self, experiments="orig,mp,mp_gaussi,nicdm,cent,dsg",
#                         hubness_k=(5, 10), knn_k=(1, 5, 20),
#                         print_results=True, verbose: int = 0):
#     def print_analysis_report(self, experiment=None, report_nr:int=0):
#     def __init__(self, D: np.ndarray, secondary_distance_type: str,
#                  metric: str = 'distance', classes: np.ndarray = None,
#                  vectors: np.ndarray = None):
#     def _calc_secondary_distance(self):
#     def _calc_hubness(self, k: int = 5):
#     def _calc_knn_accuracy(self, k: int = 5):
#     def _calc_gk_index(self):
# class HubnessAnalysis:
# class HubnessExperiment:
# 
# Path: hub_toolbox/distances.py
# def euclidean_distance(X):
#     """Calculate the euclidean distances between all pairs of vectors in `X`.
#     
#     Consider using sklearn.metric.pairwise.euclidean_distances for faster,
#     but less accurate distances (not necessarily symmetric, too)."""
#     return squareform(pdist(X, 'euclidean'))


# Path: tests/hubnessanalysis_test.py
import unittest
import numpy as np
from hub_toolbox import hubness_analysis
from hub_toolbox.distances import euclidean_distance

"""
This file is part of the HUB TOOLBOX available at
https://github.com/OFAI/hub-toolbox-python3/
The HUB TOOLBOX is licensed under the terms of the GNU GPLv3.

(c) 2016-2018, Roman Feldbauer
Austrian Research Institute for Artificial Intelligence (OFAI)
Contact: <roman.feldbauer@ofai.at>
"""

class TestHubnessAnalysis(unittest.TestCase):
    """Test the hubness_analysis class (check for results,
       but not for *correct* results.)
    """

    def setUp(self):
        points = 100
        dim = 10
        self.vector = 99. * (np.random.rand(points, dim) - 0.5)
        self.label = np.random.randint(0, 5, points)
        self.dist = euclidean_distance(self.vector)
        self.SEC_DIST = set(['mp', 'mp_gaussi', 'mp_gammai', 
                            'ls', 'nicdm', 'snn', 'cent', 'wcent', 'lcent', 
                            'dsg', 'dsl', 'orig'])

    def tearDown(self):
        del self.dist, self.label, self.vector, self.SEC_DIST

    def test_all_sec_dist_are_covered_in_unittests(self):
        n_self_sec_dist = len(self.SEC_DIST)

        hub_ana_sec_dist = set(hubness_analysis.SEC_DIST.keys())