<commit_before>from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import numpy as np

from numpy.testing import assert_equal
from numpy.testing.utils import assert_allclose

from ..spatial import RipleysKEstimate

def test_ripley_isotropic_implementation():
    # Test against Ripley's K function implemented in R package `spatstat`
    a = np.array([[1, 4], [2, 5], [3, 6]])
    area = 100
    Kest = RipleysKEstimate(data=a, area=area)
    r = np.linspace(0, 2.5, 5)

    answer = np.array([0, 0, 0, 66.667, 66.667])
    assert_allclose(answer, Kest(r), atol=1e-3)

def test_ripley_isotropic_uniform_property():
    # Ripley's K function converges to the area when the number of points
    # and the argument are large enough, i.e., K(x) --> area as x --> inf
    x = np.random.uniform(low=0, high=10, size=100)
    y = np.random.uniform(low=5, high=10, size=100)
    z = np.array([x, y]).T

    area = 50
    Kest = RipleysKEstimate(data=z, area=area)
    r = np.linspace(0, 20, 5)
    assert_allclose(area, Kest(r)[4])<commit_msg>add test for translation mode<commit_after>from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import numpy as np

from numpy.testing.utils import assert_allclose

from ..spatial import RipleysKEstimate

def test_ripley_K_implementation():
    """
        +-+---------+---------+----------+---------+-+
      6 +                                          * +
        |                                            |
        |                                            |
    5.5 +                                            +
        |                                            |
        |                                            |
      5 +                     *                      +
        |                                            |
    4.5 +                                            +
        |                                            |
        |                                            |
      4 + *                                          +
        +-+---------+---------+----------+---------+-+
          1        1.5        2         2.5        3
    """
    # Test against Ripley's K function implemented in R package `spatstat`
    a = np.array([[1, 4], [2, 5], [3, 6]])
    area = 100
    r = np.linspace(0, 2.5, 5)
    Kest = RipleysKEstimate(data=a, area=area, max_height=10, max_width=10)

    ANS_NONE = np.array([0, 0, 0, 66.667, 66.667])
    assert_allclose(ANS_NONE, Kest(radii=r, mode='none'), atol=1e-3)

    ANS_TRANS = np.array([0, 0, 0, 82.304, 82.304])
    assert_allclose(ANS_TRANS, Kest(radii=r, mode='translation'), atol=1e-3)

def test_ripley_uniform_property():
    # Ripley's K function converges to the area when the number of points
    # and the argument radii are large enough, i.e., K(x) --> area as x --> inf
    x = np.random.uniform(low=0, high=10, size=100)
    y = np.random.uniform(low=5, high=10, size=100)
    z = np.array([x, y]).T

    area = 50
    Kest = RipleysKEstimate(data=z, area=area)
    r = np.linspace(0, 20, 5)
    assert_allclose(area, Kest(radii=r)[4])
{'fraction_non_alphanumeric': 0.13750786658275646, 'fraction_numerical': 0.039962240402769036, 'mean_word_length': 1.4605263157894737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 27, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4314036', 'n_tokens_mistral': 1053, 'n_tokens_neox': 960, 'n_words': 239}