Aman Pratik
Aman Pratik

Reputation: 13

Embarrassingly Parallel Helper not returning same result for different 'n_jobs' parameter

def test_n_jobs_parallel():
# Test to check the functioning of n_jobs parameter.
    for kernel in kernels:
        gpr1 = GaussianProcessRegressor(kernel=kernel, n_jobs=1,
                                        n_restarts_optimizer=5).fit(X, y)
        gpr2 = GaussianProcessRegressor(kernel=kernel, n_jobs=2,
                                        n_restarts_optimizer=5).fit(X, y)
        gpr3 = GaussianProcessRegressor(kernel=kernel, n_jobs=-1,
                                        n_restarts_optimizer=5).fit(X, y)
        y1, y1_cov = gpr1.predict(X, return_cov=True)
        y2, y2_cov = gpr2.predict(X, return_cov=True)
        y3, y3_cov = gpr3.predict(X, return_cov=True)

    # Successfully passed tests
        assert_almost_equal(y1, y2)
        assert_almost_equal(y1, y3)
        assert_almost_equal(y1_cov, y2_cov)
        assert_almost_equal(y1_cov, y3_cov)
    # Failing tests
        assert_almost_equal(gpr1.alpha_, gpr2.alpha_)
        assert_almost_equal(gpr1.alpha_, gpr3.alpha_)
        assert_almost_equal(gpr1.log_marginal_likelihood_value_,
                            gpr2.log_marginal_likelihood_value_)
        assert_almost_equal(gpr1.log_marginal_likelihood_value_,
                            gpr3.log_marginal_likelihood_value_)

I also tried decreasing the precision value (required decimal places). This problem is arising for few kernels only.

Upvotes: 1

Views: 94

Answers (1)

Joshua Howard
Joshua Howard

Reputation: 916

Two things that I can think of that might be causing your problem:

  1. The algorithm uses a random seed
  2. The kernel hyperparameters change during fitting

I would try setting the random seed to be a constant and then retrying. If that doesn't work, would you mind sharing which kernels fail your tests?

(This is more of a comment, but my privileges aren't that high..)

Upvotes: 1

Related Questions