Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mislabeled plot being generated using plot_pairwise_marginal() #103

Open
apoorv4wadhwani opened this issue Jun 24, 2020 · 2 comments
Open

Comments

@apoorv4wadhwani
Copy link

apoorv4wadhwani commented Jun 24, 2020

Hi, while trying to understand the package, I tried to use fanova on a pre-determined objective function given below:

def objective(args):
    a, b = args
    return a ** 2

I used the following code to generate random samples from the search-space as given below:

# imports
from smac.configspace import ConfigurationSpace
from ConfigSpace.hyperparameters import UniformFloatHyperparameter
from fanova import fANOVA
import hyperopt.pyll.stochastic
from hyperopt import hp
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import fanova.visualizer

# generating random state
rng = np.random.RandomState(42)

# search space
variable_param_ranges = {
            'a': (-10, 10),
            'b': (-10, 10),
            }

# creating space
space = tuple(hp.uniform(k, *v) \
        for k, v in variable_param_ranges.items())

# creating a df
X = pd.DataFrame(columns=list(variable_param_ranges.keys()) +["loss"])

# generating random samples
ntrials = 50
for _ in range(ntrials):
    sample = hyperopt.pyll.stochastic.sample(space, rng=rng)
    loss = objective(sample)
    # populating df
    X.loc[len(X)] = sample + (loss,)

# preheating for fanova
cs = ConfigurationSpace()
for k, v in variable_param_ranges.items():
    cs.add_hyperparameter(UniformFloatHyperparameter(k, v[0], v[1]))

# running fanova
f = fANOVA(X = X[X.columns[:-1]], Y = X["loss"].values, 
    config_space = cs, seed=42)

# creating plots
plot_dir = '.'
vis = fanova.visualizer.Visualizer(f, cs, plot_dir)
vis.plot_pairwise_marginal(['a', 'b'])
plt.show()

The plot generated from the analysis done by fANVOA looks something like as below.

We should ideally be getting something as below:

Generated from:

from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

a = np.arange(-10, 10, 0.25)
b = np.arange(-10, 10, 0.25)
a, b = np.meshgrid(a, b)
R = objective((a, b))
R

surf = ax.plot_surface(a, b, R, cmap='jet',
                       linewidth=0, antialiased=False)
plt.colorbar(surf)
plt.xlabel("a")
plt.ylabel("b")

NOTICE: labels for a and b seem to have got interchanged.

@apoorv4wadhwani apoorv4wadhwani changed the title mislabeled plot bieng generated using plot_pairwise_marginal() mislabeled plot being generated using plot_pairwise_marginal() Jun 24, 2020
@shukon
Copy link
Collaborator

shukon commented Jun 24, 2020

Thanks a lot for bringing this up and providing an excellent MWE.
This is similar to #96, it is indeed a bug and will now be fixed with #104.

@shukon
Copy link
Collaborator

shukon commented Jun 24, 2020

Fixed in new release 2.0.19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants