hyperas icon indicating copy to clipboard operation
hyperas copied to clipboard

can hyperas support read global variable ?

Open stevexxs opened this issue 6 years ago • 1 comments

I know that data function is a must, but how can I return global variable inside data function ?

like, X_train, y_train = .. X_test, y_test = ... def data(): return X_train, X_test, y_train, y_test

but when run optim.minimize(), the below NameError happened. NameError: name 'X_train' is not defined

Is there anyone tell me how to fix this ?

stevexxs avatar May 21 '19 10:05 stevexxs

As suggested here you could create a python file with all your global variables and then import them, e.g.:

### [FILE NAME = globalvars.py] ###
global x_train, y_train, x_test, y_test
x_train = ...

then in the file where you define your data() function:

import globalvars as gv
def data():
    x_train = gv.x_train
    y_train = gv.y_train
    x_test = gv.x_test
    y_test = gv.y_test

    return x_train, y_train, x_test, y_test

of course it's not the cleanest or neat in any way, but it will solve your problem.

Peon26 avatar Jun 11 '19 15:06 Peon26