How to use the captum.attr._utils.approximation_methods.riemann_builders function in captum

To help you get started, we’ve selected a few captum examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytorch / captum / tests / attr / test_approximation_methods.py View on Github external
def _assert_steps_and_alphas(
        self,
        n,
        expected_step_sizes,
        expected_step_sizes_trapezoid,
        expected_left,
        expected_right,
        expected_middle,
        expected_trapezoid,
    ):
        step_sizes_left, alphas_left = riemann_builders(Riemann.left)
        step_sizes_right, alphas_right = riemann_builders(Riemann.right)
        step_sizes_middle, alphas_middle = riemann_builders(Riemann.middle)
        step_sizes_trapezoid, alphas_trapezoid = riemann_builders(Riemann.trapezoid)
        assertArraysAlmostEqual(expected_step_sizes, step_sizes_left(n))
        assertArraysAlmostEqual(expected_step_sizes, step_sizes_right(n))
        assertArraysAlmostEqual(expected_step_sizes, step_sizes_middle(n))
        assertArraysAlmostEqual(expected_step_sizes_trapezoid, step_sizes_trapezoid(n))
        assertArraysAlmostEqual(expected_left, alphas_left(n))
        assertArraysAlmostEqual(expected_right, alphas_right(n))
        assertArraysAlmostEqual(expected_middle, alphas_middle(n))
        assertArraysAlmostEqual(expected_trapezoid, alphas_trapezoid(n))
github pytorch / captum / tests / attr / test_approximation_methods.py View on Github external
def _assert_steps_and_alphas(
        self,
        n,
        expected_step_sizes,
        expected_step_sizes_trapezoid,
        expected_left,
        expected_right,
        expected_middle,
        expected_trapezoid,
    ):
        step_sizes_left, alphas_left = riemann_builders(Riemann.left)
        step_sizes_right, alphas_right = riemann_builders(Riemann.right)
        step_sizes_middle, alphas_middle = riemann_builders(Riemann.middle)
        step_sizes_trapezoid, alphas_trapezoid = riemann_builders(Riemann.trapezoid)
        assertArraysAlmostEqual(expected_step_sizes, step_sizes_left(n))
        assertArraysAlmostEqual(expected_step_sizes, step_sizes_right(n))
        assertArraysAlmostEqual(expected_step_sizes, step_sizes_middle(n))
        assertArraysAlmostEqual(expected_step_sizes_trapezoid, step_sizes_trapezoid(n))
        assertArraysAlmostEqual(expected_left, alphas_left(n))
        assertArraysAlmostEqual(expected_right, alphas_right(n))
        assertArraysAlmostEqual(expected_middle, alphas_middle(n))
        assertArraysAlmostEqual(expected_trapezoid, alphas_trapezoid(n))
github pytorch / captum / tests / attr / test_approximation_methods.py View on Github external
def _assert_steps_and_alphas(
        self,
        n,
        expected_step_sizes,
        expected_step_sizes_trapezoid,
        expected_left,
        expected_right,
        expected_middle,
        expected_trapezoid,
    ):
        step_sizes_left, alphas_left = riemann_builders(Riemann.left)
        step_sizes_right, alphas_right = riemann_builders(Riemann.right)
        step_sizes_middle, alphas_middle = riemann_builders(Riemann.middle)
        step_sizes_trapezoid, alphas_trapezoid = riemann_builders(Riemann.trapezoid)
        assertArraysAlmostEqual(expected_step_sizes, step_sizes_left(n))
        assertArraysAlmostEqual(expected_step_sizes, step_sizes_right(n))
        assertArraysAlmostEqual(expected_step_sizes, step_sizes_middle(n))
        assertArraysAlmostEqual(expected_step_sizes_trapezoid, step_sizes_trapezoid(n))
        assertArraysAlmostEqual(expected_left, alphas_left(n))
        assertArraysAlmostEqual(expected_right, alphas_right(n))
        assertArraysAlmostEqual(expected_middle, alphas_middle(n))
        assertArraysAlmostEqual(expected_trapezoid, alphas_trapezoid(n))
github pytorch / captum / tests / attr / test_approximation_methods.py View on Github external
def test_riemann_0(self):
        with self.assertRaises(AssertionError):
            step_sizes, alphas = riemann_builders()
            step_sizes(0)
            alphas(0)
github pytorch / captum / tests / attr / test_approximation_methods.py View on Github external
def _assert_steps_and_alphas(
        self,
        n,
        expected_step_sizes,
        expected_step_sizes_trapezoid,
        expected_left,
        expected_right,
        expected_middle,
        expected_trapezoid,
    ):
        step_sizes_left, alphas_left = riemann_builders(Riemann.left)
        step_sizes_right, alphas_right = riemann_builders(Riemann.right)
        step_sizes_middle, alphas_middle = riemann_builders(Riemann.middle)
        step_sizes_trapezoid, alphas_trapezoid = riemann_builders(Riemann.trapezoid)
        assertArraysAlmostEqual(expected_step_sizes, step_sizes_left(n))
        assertArraysAlmostEqual(expected_step_sizes, step_sizes_right(n))
        assertArraysAlmostEqual(expected_step_sizes, step_sizes_middle(n))
        assertArraysAlmostEqual(expected_step_sizes_trapezoid, step_sizes_trapezoid(n))
        assertArraysAlmostEqual(expected_left, alphas_left(n))
        assertArraysAlmostEqual(expected_right, alphas_right(n))
        assertArraysAlmostEqual(expected_middle, alphas_middle(n))
        assertArraysAlmostEqual(expected_trapezoid, alphas_trapezoid(n))