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

Follow up question for #32 #34

Open
yejiwi opened this issue Apr 9, 2023 · 1 comment
Open

Follow up question for #32 #34

yejiwi opened this issue Apr 9, 2023 · 1 comment

Comments

@yejiwi
Copy link

yejiwi commented Apr 9, 2023

Hi,
As suggested in the reply for #32, I modified the function safe_test

y_pred.append(model.predict(dde.nn.tensorflow_compat_v1.nn.NN.apply_feature_transform(self,X_add)))

but it gives an error saying

TypeError: apply_feature_transform() missing 1 required positional argument: 'transform'

First of all, I am not sure if this is how I am supposed to change the code based on the answer for #32.

If I put apply_feature_transform(self,X_add)),

and it gives

NameError: name 'self' is not defined

I see in nn.py, self is defined. What should I do in this case?

Please refer the full code below. Thanks.

def safe_test(model, data, X_test, y_test, fname=None):
       
    def is_nonempty(X):
        return len(X[0]) > 0 if isinstance(X, (list, tuple)) else len(X) > 0
    
    y_pred = []
    X = X_test
    while is_nonempty(X):
        X_add, X = trim_to_65535(X)
        
        #Original Code
        #y_pred.append(model.predict(data.transform_inputs(X_add))) 
        
        #Modified Code
        y_pred.append(model.predict(dde.nn.tensorflow_compat_v1.nn.NN.apply_feature_transform(self,X_add)))
        
                
    y_pred = np.vstack(y_pred)
    error = np.mean((y_test - y_pred) ** 2)
    print("Test MSE: {}".format(error))
    error = mean_squared_error_outlier(y_test, y_pred)
    print("Test MSE w/o outliers: {}\n".format(error))

    if fname is not None:
        np.savetxt(fname, np.hstack((X_test[1], y_test, y_pred)))

@xuliang5115
Copy link

# build a net then train it.
def periodic(inputs):  # just a function
  inputs *= 2 * np.pi
  out = tf.concat([tf.cos(inputs), tf.sin(inputs), tf.cos(2 * inputs), tf.sin(2 * inputs)], 1)
  return out
def main(_,_):
net = MIONetIn4CartesianProd(
      [m, w*2, w*2, m*2], [m, w*2, w*2, m*2],
      [m*_r, w*2, w*2, m*2], [m*_r, w*2, w*2, m*2],
      [2, w, w, m],
      activation,
      "Glorot normal")
  net.apply_feature_transform(periodic)  # without self

if model trained, just predict with model.preict(input_data),
because input feature layer is in the graph of the net.
图片3

# so, code may be like this:
y_pred = model.predict(X_add)  

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