I am training a denoising autoencoder with tensorflow 1.14.0 in python 3.6.8. each training step includes a fit of the model and should also optimize an other variable theta (of a binomial distribution used in loss) based on the previous prediction, which has an impact on the next prediction.
here is my question: how do I minimize this theta after each training step for each column individually? so alternate training based on the current prediction as input for minimization problem per column?
what I already tried:
used tf.map_fn with a minimization function which induced a new session and optimizer for each column to minimize -> works fine but is way too slow due to multiple session creation (see tf_minimize from Minimize a function of one variable in Tensorflow)
created hashtable of optimizer for each column to minimize theta -> individual optimizer initialization for 10 000 columns is not feasible (compare: How to alternate train op's in tensorflow?)
### no functioning python code, just to give you an idea
### input in tensorflow model: ae_input, theta
### training steps
for epoch in range(200):
model.fit( x = ae_input+theta,
y = ae_input,
epochs = epoch+1)
current_pred = model.predict(ae_input+theta)
theta = update_theta(ae_input, current_pred) # PROBLEMATIC STEP
### current way because map_fn is not working and
### would also be too slow due to multiple session creation
def update_theta(y_true, y_pred):
theta_list=[]
for col in range(y_true.get_shape()[1]):
t = theta_optimize(y_true[:,x], y_pred[:,x])
theta_list.append(t)
return theta_list
### minimize theta for single column
def theta_optimize(y_t, y_p):
var_theta = tf.Variable(5.)
func_to_minimize = loss_per_col(y_t, y_p, var_theta)
optimial_theta = tf_minimize(func_to_optimize, output=var_theta)
### tf_minimize from link mentioned above
return optimal_theta