コード例 #1
0
ファイル: test_gradients.py プロジェクト: zenourn/pymc
def check_model_gradients(model):

    model = set(model)
    # find the markov blanket
    children = set([])
    for s in model:
        for s2 in s.extended_children:
            if isinstance(s2, Stochastic) and s2.observed:
                children.add(s2)

    # self.markov_blanket is a list, because we want self.stochastics to have the chance to
    # raise ZeroProbability exceptions before self.children.
    markov_blanket = list(model) + list(children)

    gradients = utils.logp_gradient_of_set(model)
    for variable in model:

        analytic_gradient = gradients[variable]

        numeric_gradient = get_numeric_gradient(markov_blanket, variable)

        assert_array_almost_equal(
            numeric_gradient, analytic_gradient, 3,
            "analytic gradient for model " + str(model) +
            " with respect to variable " + str(variable) + " is not correct.")
コード例 #2
0
def check_model_gradients(model):

    model = set(model)
    # find the markov blanket
    children = set([])
    for s in model:
        for s2 in s.extended_children:
            if isinstance(s2, Stochastic) and s2.observed:
                children.add(s2)

    # self.markov_blanket is a list, because we want self.stochastics to have the chance to
    # raise ZeroProbability exceptions before self.children.
    markov_blanket = list(model) + list(children)

    gradients = utils.logp_gradient_of_set(model)
    for variable in model:

        analytic_gradient = gradients[variable]

        numeric_gradient = get_numeric_gradient(markov_blanket, variable)

        assert_array_almost_equal(numeric_gradient, analytic_gradient, 3,
                                  "analytic gradient for model " + str(model) +
                                  " with respect to variable " + str(variable) +
                                  " is not correct.")
コード例 #3
0
ファイル: test_gradients.py プロジェクト: zenourn/pymc
def check_gradients(stochastic):

    stochastics = find_variable_set(stochastic)
    gradients = utils.logp_gradient_of_set(stochastics, stochastics)

    for s, analytic_gradient in six.iteritems(gradients):

        numeric_gradient = get_numeric_gradient(stochastics, s)

        assert_array_almost_equal(
            numeric_gradient, analytic_gradient, 3,
            "analytic gradient for " + str(stochastic) +
            " with respect to parameter " + str(s) + " is not correct.")
コード例 #4
0
def check_gradients(stochastic):

    stochastics = find_variable_set(stochastic)
    gradients = utils.logp_gradient_of_set(stochastics, stochastics)

    for s, analytic_gradient in six.iteritems(gradients):

            numeric_gradient = get_numeric_gradient(stochastics, s)

            assert_array_almost_equal(numeric_gradient, analytic_gradient, 3,
                                      "analytic gradient for " + str(stochastic) +
                                      " with respect to parameter " + str(s) +
                                      " is not correct.")