def test_calculating_the_chordal_distance(self):
        expected_chord_dist = 0.473867859572

        # Test calcChordalDistance
        self.assertAlmostEqual(metrics.calc_chordal_distance(self.A, self.B),
                               expected_chord_dist)

        # Test calcChordalDistance2
        self.assertAlmostEqual(metrics.calc_chordal_distance_2(self.A, self.B),
                               expected_chord_dist)

        # Test
        principal_angles = metrics.calc_principal_angles(self.A, self.B)
        self.assertAlmostEqual(
            metrics.calc_chordal_distance_from_principal_angles(
                principal_angles), expected_chord_dist)

        # xxxxxxxxxx Now let's test with complex values xxxxxxxxxxxxxxxxxxx
        A = randn_c(3, 2)
        B = randn_c(3, 2)
        principal_angles2 = metrics.calc_principal_angles(A, B)
        dist1 = metrics.calc_chordal_distance(A, B)
        dist2 = metrics.calc_chordal_distance_2(A, B)
        dist3 = metrics.calc_chordal_distance_from_principal_angles(
            principal_angles2)

        self.assertAlmostEqual(dist1, dist2)
        self.assertAlmostEqual(dist3, dist2)
    def test_calculating_the_chordal_distance(self):
        expected_chord_dist = np.array([0.473867859572])

        # Test calcChordalDistance
        np.testing.assert_array_almost_equal(metrics.calc_chordal_distance(self.A, self.B), expected_chord_dist)

        # Test calcChordalDistance2
        np.testing.assert_array_almost_equal(metrics.calc_chordal_distance_2(self.A, self.B), expected_chord_dist)

        # Test
        principal_angles = metrics.calc_principal_angles(self.A, self.B)
        np.testing.assert_array_almost_equal(
            metrics.calc_chordal_distance_from_principal_angles(principal_angles), expected_chord_dist
        )

        # xxxxxxxxxx Now let's test with complex values xxxxxxxxxxxxxxxxxxx
        A = randn_c(3, 2)
        B = randn_c(3, 2)
        principal_angles2 = metrics.calc_principal_angles(A, B)
        dist1 = metrics.calc_chordal_distance(A, B)
        dist2 = metrics.calc_chordal_distance_2(A, B)
        dist3 = metrics.calc_chordal_distance_from_principal_angles(principal_angles2)

        self.assertAlmostEqual(dist1, dist2)
        self.assertAlmostEqual(dist3, dist2)
Exemple #3
0
    def calc_min_chordal_dist(codebook):
        """
        Calculates the minimum chordal distance in the Codebook.

        Note that the codebook is a 3-dimensional complex numpy array with
        dimension `K x Nt x Ns` (K is the number of precoders in the codebook,
        Nt and Ns are the number of rows and columns, respectively, of each
        precoder.

        Parameters
        ----------
        codebook : np.ndarray
            The codebook for which the minimum chordal distance should be
            calculated. This is a 3-dimensional (K x Nt x Ns) complex numpy
            array.

        Returns
        -------
        (float, np.ndarray)
            The tuple (min_dist, principal_angles).
        """
        K = codebook.shape[0]

        #Se pegar todas as combinacoes possiveis (sem repeticao e sem ligar para
        # ordem) vc tera (ncols**2-ncols)/2 possibilidades. Isso Equivale a pegar
        # uma matriz matrix.ncols() x matrix.ncols() e contar todos os elementos
        # abaixo (ou acima) da diagonal.
        num_possibilidades = (K**2 - K) / 2
        dists = np.empty(num_possibilidades)
        principal_angles = []
        index = 0

        # for comb in calc_all_comb_indexes(K):
        for comb in combinations(range(0, K), 2):
            # comb is a tuple with two elements
            pa = calc_principal_angles(codebook[comb[0]], codebook[comb[1]])
            principal_angles.append(pa)
            dists[index] = calc_chordal_distance_from_principal_angles(pa)
            index += 1

        min_index = dists.argmin()  # Index of the minimum distance (in the
        # flattened array)
        min_dist = dists.flatten()[min_index]  # Same as dists.min()
        ":type: float"
        principal_angles = np.array(principal_angles[min_index])

        return min_dist, principal_angles
Exemple #4
0
    def calc_min_chordal_dist(codebook):
        """Claculates the minimum chordal distance in the Codebook.

        Note that the codebook is a 3-dimensional complex numpy array with
        dimension `K x Nt x Ns` (K is the number of precoders in the codebook,
        Nt and Ns are the number of rows and columns, respectively, of each
        precoder.

        Parameters
        ----------
        codebook : A 3-dimensional (K x Nt x Ns) complex numpy array
            The codebook for which the monimum chordal distance should be
            calculated.

        """
        K = codebook.shape[0]

        #Se pegar todas as combinacoes possiveis (sem repeticao e sem ligar para
        # ordem) vc tera (ncols**2-ncols)/2 possibilidades. Isso Equivale a pegar
        # uma matriz matrix.ncols() x matrix.ncols() e contar todos os elementos
        # abaixo (ou acima) da diagonal.
        num_possibilidades = (K ** 2 - K) / 2
        dists = np.empty(num_possibilidades)
        principal_angles = []
        index = 0

        # for comb in calc_all_comb_indexes(K):
        for comb in combinations(range(0, K), 2):
            #comb is a tuple with two elements
            pa = calc_principal_angles(codebook[comb[0]], codebook[comb[1]])
            principal_angles.append(pa)
            dists[index] = calc_chordal_distance_from_principal_angles(pa)
            index += 1

        min_index = dists.argmin()  # Index of the minimum distance (in the
                                    # flattened array)
        min_dist = dists.flatten()[min_index]  # Same as dists.min()
        principal_angles = np.array(principal_angles[min_index])

        return min_dist, principal_angles