<commit_before>import pytest
import numpy as np
import math

import sys, os
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(myPath, '..'))

from DBNlogic.util import sigmoid, activation, squared_error

def test_sigmoidDefinition():
    """The `sigmoid` function applied to `x` returns 1 / (1 + e^-x)."""
    for i in range(-1000,1001):
        x = 0.1 * i
        assert sigmoid(np.array(x)) == 1 / (1 + math.exp(-x))

def test_sigmoidShape():
    """The `sigmoid` function returns a Numpy array with
    the same shape as the input array."""
    v = np.random.randn(5, 12, 38)
    assert sigmoid(v).shape == v.shape

def test_sigmoidZero():
    """The `sigmoid` function applied to 0 returns 0.5."""
    x = 0
    assert sigmoid(np.array(x)) == 0.5

def test_sigmoidAsymptotes():
    """The `sigmoid` function always stays between 0 and 1."""
    for i in range(-100,101):
        s = sigmoid(np.array(0.23 * i))
        assert s > 0
        assert s < 1

def test_activationShape():
    """The `activation` function returns a Numpy array with
    the same shape as the input array."""
    v = np.random.randn(5, 12)
    assert activation(v).shape == v.shape

def test_MSQZero():
    """The `squared_error` function applied to `x` and `x` returns 0."""
    x = np.random.rand(13, 4, 1)
    assert squared_error(x, x) == 0<commit_msg>Add testing for heatmap<commit_after>import pytest
import numpy as np
import math

import sys, os
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(myPath, '..'))

from DBNlogic.util import sigmoid, activation, squared_error, heatmap

def test_sigmoidDefinition():
    """The `sigmoid` function applied to `x` returns 1 / (1 + e^-x)."""
    for i in range(-1000,1001):
        x = 0.1 * i
        assert sigmoid(np.array(x)) == 1 / (1 + math.exp(-x))

def test_sigmoidShape():
    """The `sigmoid` function returns a Numpy array with
    the same shape as the input array."""
    v = np.random.randn(5, 12, 38)
    assert sigmoid(v).shape == v.shape

def test_sigmoidZero():
    """The `sigmoid` function applied to 0 returns 0.5."""
    x = 0
    assert sigmoid(np.array(x)) == 0.5

def test_sigmoidAsymptotes():
    """The `sigmoid` function always stays between 0 and 1."""
    for i in range(-100,101):
        s = sigmoid(np.array(0.23 * i))
        assert s > 0
        assert s < 1

def test_activationShape():
    """The `activation` function returns a Numpy array with
    the same shape as the input array."""
    v = np.random.randn(5, 12)
    assert activation(v).shape == v.shape

def test_MSQZero():
    """The `squared_error` function applied to `x` and `x` returns 0."""
    x = np.random.rand(13, 4, 1)
    assert squared_error(x, x) == 0

def test_heatmap():
    """A heatmap of an array has the same length as the array."""
    array = np.random.rand(16).tolist()
    hmap = heatmap(array)
    assert len(array) == len(hmap)
{'fraction_non_alphanumeric': 0.14455378350865286, 'fraction_numerical': 0.0332541567695962, 'mean_word_length': 3.1288515406162465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1671644', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1016, 'n_words': 326}