You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to access ate_inference from the DeepIV object, I consistently encounter the error 'DeepIV' object has no attribute '_inference'. However, I am able to obtain the ate value without any issues.I have defined my inference method using the string inference='bootstrap'. Additionally, I am using TensorFlow version 2.10.0, Keras version 2.10.0, and Python version 3.10.0.
Could you kindly assist me in understanding what might be causing this issue? Any guidance would be greatly appreciated.
import numpy as np
import keras
from keras import backend as K
import keras.layers as L
from keras.models import Model
from econml.iv.nnet import DeepIV
from econml.inference import BootstrapInference
np.random.seed(42)
n = 5000
e = np.random.normal(size=(n,))
x = np.random.uniform(low=0.0, high=10.0, size=(n,))
z = np.random.uniform(low=0.0, high=10.0, size=(n,))
t = np.sqrt((x + 2) * z) + e
y = t * t / 10 - x * t / 10 + e
y = y.reshape(-1, 1)
t = t.reshape(-1, 1)
x = x.reshape(-1, 1)
z = z.reshape(-1, 1)
treatment_model = keras.Sequential([
keras.layers.Dense(64, activation='relu', input_shape=(2,)),
keras.layers.Dense(32, activation='relu'),
keras.layers.Dense(1)
])
response_model = keras.Sequential([
keras.layers.Dense(64, activation='relu', input_shape=(2,)),
keras.layers.Dense(32, activation='relu'),
keras.layers.Dense(1)
])
keras_fit_options = {
"epochs": 30,
"validation_split": 0.1,
"callbacks": [keras.callbacks.EarlyStopping(patience=2, restore_best_weights=True)]
}
deepIvEst = DeepIV(
n_components=10,
m=lambda z, x: treatment_model(keras.layers.concatenate([z, x])),
h=lambda t, x: response_model(keras.layers.concatenate([t, x])),
n_samples=1,
use_upper_bound_loss=False,
n_gradient_samples=1,
optimizer='adam',
first_stage_options=keras_fit_options,
second_stage_options=keras_fit_options
)
inference = BootstrapInference(n_bootstrap_samples=100, n_jobs=-1, bootstrap_type='pivot')
try:
deepIvEst.fit(Y=y, T=t, X=x, Z=z, inference=inference)
print("Model fitting completed successfully.")
if hasattr(deepIvEst, '_inference'):
print("Inference object was correctly set.")
else:
print("Inference object was not set.")
except Exception as e:
print("Model fitting failed:", e)
T0 = np.zeros_like(t)
T1 = np.ones_like(t)
try:
ate = deepIvEst.ate(X=x, T0=T0, T1=T1)
ate_interval = deepIvEst.ate_interval(X=x, T0=T0, T1=T1, alpha=0.05)
ate_inference = deepIvEst.ate_inference(X=x, T0=T0, T1=T1)
print(ate_inference.summary())
except Exception as e:
print("ATE inference failed:", e)
The text was updated successfully, but these errors were encountered:
When attempting to access ate_inference from the DeepIV object, I consistently encounter the error 'DeepIV' object has no attribute '_inference'. However, I am able to obtain the ate value without any issues.I have defined my inference method using the string inference='bootstrap'. Additionally, I am using TensorFlow version 2.10.0, Keras version 2.10.0, and Python version 3.10.0.
Could you kindly assist me in understanding what might be causing this issue? Any guidance would be greatly appreciated.
The text was updated successfully, but these errors were encountered: