<commit_before>from syft import TensorBase
import numpy as np
from syft.nonlin import sigmoid, PolyApproximator
import unittest


# Here's our "unit tests".
class NonlinTests(unittest.TestCase):
    def test_sigmoid(self):

        a = TensorBase(np.array([1, 2, 3]))
        approx = sigmoid(a)
        self.assertEqual(approx[0], 0.70788285770000015)
        self.assertEqual(approx[1], 0.87170293820000011)
        self.assertEqual(approx[2], 0.96626517229999997)


class TestPolyApproximators(unittest.TestCase):
    def test_poly_approx_sigmoid(self):

        sigmoid = PolyApproximator(lambda x: 1 / (1 + np.exp(-x))).output

        a = TensorBase(np.array([.1, .2, .3, .4]))
        b = TensorBase(np.ones(4))

        siga = sigmoid(a)
        sigb = sigmoid(b)

        self.assertEqual(siga[0], 0.52158376423960751)
        self.assertEqual(siga[1], 0.54311827756855013)

        self.assertEqual(sigb[0], 0.7078828574)
        self.assertEqual(sigb[1], 0.7078828574)
        self.assertEqual(sigb[2], 0.7078828574)
        self.assertEqual(sigb[3], 0.7078828574)<commit_msg>test poly approximator on tanh<commit_after>from syft import TensorBase
import numpy as np
from syft.nonlin import sigmoid, PolyApproximator
import unittest


# Here's our "unit tests".
class NonlinTests(unittest.TestCase):
    def test_sigmoid(self):

        a = TensorBase(np.array([1, 2, 3]))
        approx = sigmoid(a)
        self.assertEqual(approx[0], 0.70788285770000015)
        self.assertEqual(approx[1], 0.87170293820000011)
        self.assertEqual(approx[2], 0.96626517229999997)


class TestPolyApproximators(unittest.TestCase):
    def test_poly_approx_sigmoid(self):

        sigmoid = PolyApproximator(lambda x: 1 / (1 + np.exp(-x))).output

        a = TensorBase(np.array([.1, .2, .3, .4]))
        b = TensorBase(np.ones(4))

        siga = sigmoid(a)
        sigb = sigmoid(b)

        self.assertEqual(siga[0], 0.52158376423960751)
        self.assertEqual(siga[1], 0.54311827756855013)

        self.assertEqual(sigb[0], 0.7078828574)
        self.assertEqual(sigb[1], 0.7078828574)
        self.assertEqual(sigb[2], 0.7078828574)
        self.assertEqual(sigb[3], 0.7078828574)

    def test_poly_approx_tanh(self):

        tanh = PolyApproximator(np.tanh).output

        a = TensorBase(np.array([.1, .2, .3, .4]))
        b = TensorBase(np.ones(4))

        tana = tanh(a)
        tanb = tanh(b)

        self.assertTrue(np.abs(tana[0] - 0.05772423) < 0.0001)
        self.assertTrue(np.abs(tana[1] - 0.11527286) < 0.0001)

        self.assertTrue(np.abs(tanb[1] - 0.54896505) < 0.0001)
{'fraction_non_alphanumeric': 0.1348444102958125, 'fraction_numerical': 0.1367652708413369, 'mean_word_length': 3.012326656394453, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, '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': '2185185', 'n_tokens_mistral': 1172, 'n_tokens_neox': 940, 'n_words': 163}