Best Python code snippet using slash
test_af.py
Source:test_af.py
...21 def test_init(self):22 function = self._getTargetClass()()23 assert function(-1) == 024 assert function(0) == 125 def test_activation(self):26 function = self._getTargetClass()(1, 5)27 assert function(0) == 028 assert function(1) == 529 def test_activationVector(self):30 from numpy import array31 function = self._getTargetClass()()32 result = function(array([-1, 0, 1])) == array([0, 1, 1])33 assert result.all()34 def test_derivative(self):35 function = self._getTargetClass()()36 assert function.derivative(2) == 137 def test_derivativeVector(self):38 from numpy import array39 function = self._getTargetClass()()40 result = function.derivative(array([1, 2, 3, 4])) == array([1, 1, 1, 1])41 assert result.all()42class Test_Linear(unittest.TestCase):43 def _getTargetClass(self):44 from peach.nn.af import Linear45 return Linear46 def test_alias(self):47 from peach.nn.af import Identity48 assert Identity == self._getTargetClass()49 def test_activation(self):50 from numpy import array51 function = self._getTargetClass()()52 result = function(3) == array([3.])53 assert result.all()54 def test_activationVector(self):55 from numpy import array56 function = self._getTargetClass()()57 result = function(array([-1, 0, 1])) == array([-1, 0, 1])58 assert result.all()59 def test_derivative(self):60 function = self._getTargetClass()()61 assert function.derivative(5) == 162 def test_derivativeVector(self):63 from numpy import array64 function = self._getTargetClass()()65 result = function.derivative(array([1, 2, 3, 4])) == array([1, 1, 1, 1])66 assert result.all()67class Test_Ramp(unittest.TestCase):68 def _getTargetClass(self):69 from peach.nn.af import Ramp70 return Ramp71 def test_activation(self):72 function = self._getTargetClass()((-1, -1), (1, 1))73 assert function(-2) == -174 assert function(0.5) == 0.575 assert function(2) == 176 def test_activationVector(self):77 from numpy import array78 function = self._getTargetClass()((-1, -1), (1, 1))79 result = function(array([-2, 0, 2])) == array([-1, 0, 1])80 assert result.all()81 def test_derivative(self):82 function = self._getTargetClass()()83 assert function.derivative(-1) == 084 assert function.derivative(0.1) == 185 assert function.derivative(1) == 086 def test_derivativeVector(self):87 from numpy import array88 function = self._getTargetClass()()89 result = function.derivative(array([-1, 0.1, 1])) == array([0, 1, 0])90 assert result.all()91class Test_Sigmoid(unittest.TestCase):92 def _getTargetClass(self):93 from peach.nn.af import Sigmoid94 return Sigmoid95 def test_alias(self):96 from peach.nn.af import Logistic97 assert Logistic == self._getTargetClass()98 def test_activation(self):99 function = self._getTargetClass()()100 assert function(0) == 0.5101 self.assertAlmostEquals(function(-1), 0.268941421)102 self.assertAlmostEquals(function(1), 0.731058578)103 def test_activationVector(self):104 from numpy import array105 function = self._getTargetClass()()106 result = function(array([0, 0])) == array([0.5, 0.5])107 assert result.all()108 def test_derivative(self):109 function = self._getTargetClass()()110 assert function.derivative(0) == 0.25111 self.assertAlmostEquals(function.derivative(-1), 0.196611933)112 self.assertAlmostEquals(function.derivative(1), 0.196611933)113 def test_derivativeVector(self):114 from numpy import array115 function = self._getTargetClass()()116 result = function.derivative(array([0, 0])) == array([0.25, 0.25])117 assert result.all()118class Test_Signum(unittest.TestCase):119 def _getTargetClass(self):120 from peach.nn.af import Signum121 return Signum122 def test_activation(self):123 function = self._getTargetClass()()124 assert function(0) == 0125 assert function(-2) == -1126 assert function(2) == 1127 def test_activationVector(self):128 from numpy import array129 function = self._getTargetClass()()130 result = function(array([-2, -1, 0, 1, 2])) == array([-1, -1, 0, 1, 1])131 assert result.all()132 def test_derivative(self):133 function = self._getTargetClass()()134 assert function.derivative(2) == 1135 def test_derivativeVector(self):136 from numpy import array137 function = self._getTargetClass()()138 result = function.derivative(array([1, 2, 3, 4])) == array([1, 1, 1, 1])139 assert result.all()140class Test_ArcTan(unittest.TestCase):141 def _getTargetClass(self):142 from peach.nn.af import ArcTan143 return ArcTan144 def test_activation(self):145 function = self._getTargetClass()()146 assert function(-1) == -0.25147 assert function(0) == 0148 assert function(1) == 0.25149 def test_activationVector(self):150 from numpy import array151 function = self._getTargetClass()()152 result = function(array([-1, 0, 1])) == array([-0.25, 0, 0.25])153 assert result.all()154 def test_derivative(self):155 function = self._getTargetClass()()156 self.assertAlmostEquals(function.derivative(-1), 0.15915494309189)157 self.assertAlmostEquals(function.derivative(0), 0.31830988618379)158 self.assertAlmostEquals(function.derivative(1), 0.15915494309189)159 def test_derivativeVector(self):160 from numpy import array161 function = self._getTargetClass()()162 result = function.derivative(array([-1, 0, 1]))163 self.assertAlmostEquals(result[0], 0.15915494309189)164 self.assertAlmostEquals(result[1], 0.31830988618379)165 self.assertAlmostEquals(result[2], 0.15915494309189)166class Test_TanH(unittest.TestCase):167 def _getTargetClass(self):168 from peach.nn.af import TanH169 return TanH170 def test_activation(self):171 function = self._getTargetClass()()172 assert function(0) == 0173 self.assertAlmostEquals(function(1), 0.7615941559)174 self.assertAlmostEquals(function(-1), -0.7615941559)175 def test_activationVector(self):176 from numpy import array177 function = self._getTargetClass()()178 result = function(array([0, 0])) == array([0, 0])179 assert result.all()180 def test_derivative(self):181 function = self._getTargetClass()()182 assert function.derivative(0) == 1183 self.assertAlmostEquals(function.derivative(1), 0.41997434161)184 self.assertAlmostEquals(function.derivative(-1), 0.41997434161)...
test.py
Source:test.py
1from unittest import TestCase2from hamcrest import assert_that, equal_to3from pytest_reference_formatter.formatter import handling_references4class TestFormatter(TestCase):5 def test_single_reference_can_be_formatted(self):6 """ when user input has one parameter """7 single_reference_input = \8 ['paessler.license.tests.admin_testcases.test_activation.DeactivateSystemIDScenario.'9 'test_deactivating_systemid_creates_sales_comment']10 single_reference_input_with_django_sites_and_py = \11 ['django-sites.paessler.license.tests.admin_testcases.test_activation.py.DeactivateSystemIDScenario.'12 'test_deactivating_systemid_creates_sales_comment']13 single_reference_expected_output = \14 ['django-sites/paessler/license/tests/admin_testcases/test_activation.py::'15 'DeactivateSystemIDScenario::test_deactivating_systemid_creates_sales_comment']16 assert_that(handling_references(single_reference_input),17 equal_to(single_reference_expected_output), 'identifier')18 assert_that(handling_references(single_reference_input_with_django_sites_and_py),19 equal_to(single_reference_expected_output), 'identifier')20 def test_multiple_reference_can_be_formatted(self):21 """ when user input has more than one parameter """22 multiple_reference_input = \23 ['paessler.license.tests.admin_testcases.test_activation.DeactivateSystemIDScenario.'24 'test_deactivating_systemid_creates_sales_comment',25 'django-sites.paessler.license.tests.admin_testcases.test_activation.'26 'ChangeExpirationOfSystemIDGrantScenario.'27 'test_changing_expiration_for_systemid_creates_sales_comment']28 multiple_reference_expected_output = \29 ['django-sites/paessler/license/tests/admin_testcases/test_activation.py::'30 'DeactivateSystemIDScenario::'31 'test_deactivating_systemid_creates_sales_comment',32 'django-sites/paessler/license/tests/admin_testcases/test_activation.py::'33 'ChangeExpirationOfSystemIDGrantScenario::'34 'test_changing_expiration_for_systemid_creates_sales_comment']...
activations.py
Source:activations.py
1import numpy as np2class sigmoid():3 """4 An object that allows for easy access to all activation functions needed for5 sigmoid activation.6 Methods:7 forward : gives the result of a sigmoid avtivation8 derviative : gives the result for backpropagation with sigmoid activation9 """10 def forward(self, inputs):11 return 1 / (1 + np.exp(-inputs))12 13 def derivative(self, inputs):14 return np.exp(-inputs) / np.square(1 + np.exp(-inputs))15if __name__ == "__main__":16 """17 If this file is being run individually test the implementation of neural net classes.18 """19 test_inputs = np.array([[2], [1]])20 test_activation = sigmoid()21 print("Sigmoid Foward Results:", test_activation.forward(test_inputs))22 print("Sigmoid Backwards Results:", test_activation.derivative(test_inputs))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!