<commit_before># -*- coding: utf-8 -*-
"""

Created on Thu Jan 17 20:14:26 2013

Author: <NAME>
"""

import numpy as np
from numpy.testing import assert_equal, assert_almost_equal, assert_array_less

from scipy import stats

import dist_mixtures.mixture_von_mises as mixvn

def test_split_params():
    npar = 2
    for k_dist in range(1, 5):
        nparams = npar * k_dist + k_dist - 1
        params = np.arange(nparams)
        sh, loc, pr = mixvn._split_params(params)

        m, r = divmod(sh, 2)
        assert_equal(r, np.zeros(k_dist))
        assert_equal(m.max(), k_dist - 1)

        m, r = divmod(loc, 2)
        assert_equal(r, np.ones(k_dist))
        assert_equal(m.max(), k_dist - 1)

        assert_equal(len(pr), k_dist - 1)

def test_mix1():
    np.random.seed(987789)<commit_msg>TST: add test for normalize_params<commit_after># -*- coding: utf-8 -*-
"""

Created on Thu Jan 17 20:14:26 2013

Author: <NAME>
"""

import numpy as np
from numpy.testing import assert_equal, assert_almost_equal, assert_array_less

from scipy import stats

import dist_mixtures.mixture_von_mises as mixvn

def test_split_params():
    npar = 2
    for k_dist in range(1, 5):
        nparams = npar * k_dist + k_dist - 1
        params = np.arange(nparams)
        sh, loc, pr = mixvn._split_params(params)

        m, r = divmod(sh, 2)
        assert_equal(r, np.zeros(k_dist))
        assert_equal(m.max(), k_dist - 1)

        m, r = divmod(loc, 2)
        assert_equal(r, np.ones(k_dist))
        assert_equal(m.max(), k_dist - 1)

        assert_equal(len(pr), k_dist - 1)

def test_normalize():
    np.random.seed(123)
    npar = 2
    k = 3
    x = np.linspace(-k*np.pi, k*np.pi, 21)
    vnm = mixvn.VonMisesMixture(x)
    for k_dist in range(1, 5):
        nparams = npar * k_dist + k_dist - 1
        for _ in range(10):
            params = np.random.uniform(-5, 5, size=nparams)
            params[npar * k_dist:] /= 10
            pdf1 = vnm.pdf_mix(params)
            params2 = mixvn.normalize_params(params)
            #most params are changed
            #print np.max(np.abs(params - params2)) > 0.001,
            pdf2 = vnm.pdf_mix(params2)
            assert_almost_equal(pdf2, pdf1, decimal=14)


def test_mix1():
    np.random.seed(987789)
{'fraction_non_alphanumeric': 0.12196199734865223, 'fraction_numerical': 0.03844454264250994, 'mean_word_length': 2.4884437596302003, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4916373', 'n_tokens_mistral': 910, 'n_tokens_neox': 828, 'n_words': 201}