<commit_before>'''
Created on 06.12.2013

@author: jan-hendrikprinz

This module provides the unittest for the pcca module

'''
import unittest
import numpy as np
from scipy import sparse

from pyemma.util.numeric import assert_allclose
from pcca import pcca


class TestPCCA(unittest.TestCase):


    def setUp(self):
        pass

    def test_pcca_1(self):
        P = np.array([[1, 0],
                      [0, 1]])
        chi = pcca(P, 2)
        sol = np.array([[ 1.,  0.],
                        [ 0.,  1.]])
        assert_allclose(chi, sol)

    def test_pcca_2(self):
        P = np.array([[0.0, 1.0, 0.0],
                      [0.0, 0.999, 0.001],
                      [0.0, 0.001, 0.999]])
        chi = pcca(P, 2)
        sol = np.array([[ 1.,  0.],
                        [ 1.,  0.],
                        [ 0.,  1.]])
        assert_allclose(chi, sol)

    def test_pcca_3(self):
        P = np.array([[0.9, 0.1, 0.0, 0.0],
                      [0.1, 0.9, 0.0, 0.0],
                      [0.0, 0.0, 0.8, 0.2],
                      [0.0, 0.0, 0.2, 0.8]])
        # n=2
        chi = pcca(P, 2)
        sol = np.array([[ 1.,  0.],
                        [ 1.,  0.],
                        [ 0.,  1.],
                        [ 0.,  1.]])
        assert_allclose(chi, sol)
        # n=3
        chi = pcca(P, 3)
        sol = np.array([[ 1.,  0.,  0.],
                        [ 0.,  1.,  0.],
                        [ 0.,  0.,  1.],
                        [ 0.,  0.,  1.]])
        assert_allclose(chi, sol)
        # n=4
        chi = pcca(P, 4)
        sol = np.array([[ 1.,  0.,  0.,  0.],
                        [ 0.,  1.,  0.,  0.],
                        [ 0.,  0.,  1.,  0.],
                        [ 0.,  0.,  0.,  1.]])
        assert_allclose(chi, sol)

    def test_pcca_4(self):
        P = np.array([[0.9, 0.1, 0.0, 0.0],
                      [0.1, 0.8, 0.1, 0.0],
                      [0.0, 0.0, 0.8, 0.2],
                      [0.0, 0.0, 0.2, 0.8]])        
        chi = pcca(P, 2)
        sol = np.array([[ 1.,  0.],
                        [ 1.,  0.],
                        [ 1.,  0.],
                        [ 0.,  1.]])
        assert_allclose(chi, sol)

    def test_pcca_5(self):
        P = np.array([[0.9, 0.1, 0.0, 0.0, 0.0],
                      [0.1, 0.9, 0.0, 0.0, 0.0],
                      [0.0, 0.1, 0.8, 0.1, 0.0],
                      [0.0, 0.0, 0.0, 0.8, 0.2],
                      [0.0, 0.0, 0.0, 0.2, 0.8]])
        # n=2
        chi = pcca(P, 2)
        sol = np.array([[ 1. ,  0. ],
                        [ 1. ,  0. ],
                        [ 0.5,  0.5],
                        [ 0. ,  1. ],
                        [ 0. ,  1. ]])
        assert_allclose(chi, sol)
        # n=4
        chi = pcca(P, 4)
        sol = np.array([[ 1. ,  0. ,  0. ,  0. ],
                        [ 0. ,  1. ,  0. ,  0. ],
                        [ 0. ,  0.5,  0.5,  0. ],
                        [ 0. ,  0. ,  1. ,  0. ],
                        [ 0. ,  0. ,  0. ,  1. ]])
        assert_allclose(chi, sol)

    def test_pcca_large(self):
        P = np.loadtxt('./pyemma/msm/analysis/tests/P_rev_251x251.dat')
        # n=2
        chi = pcca(P, 2)
        assert(np.alltrue(chi >= 0))
        assert(np.alltrue(chi <= 1))
        # n=3
        chi = pcca(P, 3)
        assert(np.alltrue(chi >= 0))
        assert(np.alltrue(chi <= 1))
        # n=4
        chi = pcca(P, 4)
        assert(np.alltrue(chi >= 0))
        assert(np.alltrue(chi <= 1))


if __name__ == "__main__":
    unittest.main()<commit_msg>using module-relative file name in pcca test<commit_after>'''
Created on 06.12.2013

@author: jan-hendrikprinz

This module provides the unittest for the pcca module

'''
import unittest
import numpy as np
from scipy import sparse

from pyemma.util.numeric import assert_allclose
from pcca import pcca


class TestPCCA(unittest.TestCase):


    def setUp(self):
        pass

    def test_pcca_1(self):
        P = np.array([[1, 0],
                      [0, 1]])
        chi = pcca(P, 2)
        sol = np.array([[ 1.,  0.],
                        [ 0.,  1.]])
        assert_allclose(chi, sol)

    def test_pcca_2(self):
        P = np.array([[0.0, 1.0, 0.0],
                      [0.0, 0.999, 0.001],
                      [0.0, 0.001, 0.999]])
        chi = pcca(P, 2)
        sol = np.array([[ 1.,  0.],
                        [ 1.,  0.],
                        [ 0.,  1.]])
        assert_allclose(chi, sol)

    def test_pcca_3(self):
        P = np.array([[0.9, 0.1, 0.0, 0.0],
                      [0.1, 0.9, 0.0, 0.0],
                      [0.0, 0.0, 0.8, 0.2],
                      [0.0, 0.0, 0.2, 0.8]])
        # n=2
        chi = pcca(P, 2)
        sol = np.array([[ 1.,  0.],
                        [ 1.,  0.],
                        [ 0.,  1.],
                        [ 0.,  1.]])
        assert_allclose(chi, sol)
        # n=3
        chi = pcca(P, 3)
        sol = np.array([[ 1.,  0.,  0.],
                        [ 0.,  1.,  0.],
                        [ 0.,  0.,  1.],
                        [ 0.,  0.,  1.]])
        assert_allclose(chi, sol)
        # n=4
        chi = pcca(P, 4)
        sol = np.array([[ 1.,  0.,  0.,  0.],
                        [ 0.,  1.,  0.,  0.],
                        [ 0.,  0.,  1.,  0.],
                        [ 0.,  0.,  0.,  1.]])
        assert_allclose(chi, sol)

    def test_pcca_4(self):
        P = np.array([[0.9, 0.1, 0.0, 0.0],
                      [0.1, 0.8, 0.1, 0.0],
                      [0.0, 0.0, 0.8, 0.2],
                      [0.0, 0.0, 0.2, 0.8]])        
        chi = pcca(P, 2)
        sol = np.array([[ 1.,  0.],
                        [ 1.,  0.],
                        [ 1.,  0.],
                        [ 0.,  1.]])
        assert_allclose(chi, sol)

    def test_pcca_5(self):
        P = np.array([[0.9, 0.1, 0.0, 0.0, 0.0],
                      [0.1, 0.9, 0.0, 0.0, 0.0],
                      [0.0, 0.1, 0.8, 0.1, 0.0],
                      [0.0, 0.0, 0.0, 0.8, 0.2],
                      [0.0, 0.0, 0.0, 0.2, 0.8]])
        # n=2
        chi = pcca(P, 2)
        sol = np.array([[ 1. ,  0. ],
                        [ 1. ,  0. ],
                        [ 0.5,  0.5],
                        [ 0. ,  1. ],
                        [ 0. ,  1. ]])
        assert_allclose(chi, sol)
        # n=4
        chi = pcca(P, 4)
        sol = np.array([[ 1. ,  0. ,  0. ,  0. ],
                        [ 0. ,  1. ,  0. ,  0. ],
                        [ 0. ,  0.5,  0.5,  0. ],
                        [ 0. ,  0. ,  1. ,  0. ],
                        [ 0. ,  0. ,  0. ,  1. ]])
        assert_allclose(chi, sol)

    def test_pcca_large(self):
        import os
        P = np.loadtxt(os.path.split(__file__)[0]+'/../tests/P_rev_251x251.dat')
        # n=2
        chi = pcca(P, 2)
        assert(np.alltrue(chi >= 0))
        assert(np.alltrue(chi <= 1))
        # n=3
        chi = pcca(P, 3)
        assert(np.alltrue(chi >= 0))
        assert(np.alltrue(chi <= 1))
        # n=4
        chi = pcca(P, 4)
        assert(np.alltrue(chi >= 0))
        assert(np.alltrue(chi <= 1))


if __name__ == "__main__":
    unittest.main()
{'fraction_non_alphanumeric': 0.1826629680998613, 'fraction_numerical': 0.0766990291262136, 'mean_word_length': 0.8842435327933107, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2237587', 'n_tokens_mistral': 3022, 'n_tokens_neox': 2701, 'n_words': 607}