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

Problem with generative_model (generative.py) #80

Open
pedrocklein opened this issue Dec 6, 2019 · 0 comments
Open

Problem with generative_model (generative.py) #80

pedrocklein opened this issue Dec 6, 2019 · 0 comments

Comments

@pedrocklein
Copy link

Greetings,

I am running into an IndexError problem when using the evaluate_generative_model function.
To give you a better picture of what am I doing, I am using hyperopt to optimize the hyperparameters eta and gamma from the function evaluate_generative_model, and the parameter space for each is [-10, 10] in steps of 0.1, so for each trial, it selects two values from this space and send them to the function. Here is my code:

# Define the hyperparameters space
gamma = np.r_[-10:10:0.1]
eta = np.r_[-10:10:0.1]
hp_space = {
        'gamma': hp.choice('gamma', gamma),
        'eta': hp.choice('eta', eta)
}

# Setting up the number of evaluations and Trials object
n_evals = 2000
trials = Trials()

# Running the optimization
res_gnm = fmin(
            lambda hps: bct.evaluate_generative_model(seed_network,
                                                  target_network,
                                                  mean_dist,
                                                  [hps['eta']],
                                                  gamma=[hps['gamma']],
                                                  model_type='matching')[0],
            space=hp_space, algo=tpe.suggest, trials=trials, max_evals=n_evals,
            rstate=np.random.RandomState(42)
        )

Apparently, this problem disappears if I add this to the generative.py code (line 327)

...
for ii in range(mseed, m):
            C = np.append(0, np.cumsum(Ff[u,v]))
            r_n = np.sum(np.random.random()*C[-1] >= C) #storing the original index
            r = r_n - 1 #subtracting 1 from it
            uu = u[r]
            vv = v[r]
            A[uu,vv] = A[vv,uu] = 1
...

which is basically subtracting one from the index (I was assuming that it could be a 0-indexing problem, since the original code came from a matlab toolbox).

Even with this fix, though, the same error occurs when I use the evaluate_generative_model function passing eta and gamma as vectors.
gnm_eval = bct.evaluate_generative_model(seed_network, sc_dataset[0]['weights_bu'], mean_dist, eta, gamma=gamma)

Is there anything that I am doing wrong when using this function?

Thank you for your help.

P.S: I am attaching the dist, seed and target matrices as numpy files.
dist.txt
seed.txt
target.txt

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

No branches or pull requests

2 participants