Migration to Tensorflow 2.0 Problems

39 views
Skip to first unread message

Kevin Corella Nieto

unread,
May 14, 2020, 8:19:48 PM5/14/20
to TensorFlow Community Testing

Hi all,

 

Currently i get a problem with the migration to Tensorflow 2.0 my code is the following:

 

def __init__(self, n_inputs, n_codings, learning_rate=0.01):

        self.learning_rate = learning_rate

        n_outputs = n_inputs

        self.destroy()

        reset_graph()

   

        # the inputs are n_inputs x n_inputs covariance matrices

        self.X = tf.compat.v1.placeholder(tf.float32, shape=[None, n_inputs, n_inputs])

        with tf.name_scope("lin_ae"):

            self.codings_layer = None

            self.outputs = None

           

            self.codings_layer =  fully_connected(self.X,n_codings, activation=None)

           

            self.outputs = fully_connected(self.codings_layer, n_outputs, activation_fn=None)

 

The error message is the following when executed this lines

 

ix_offset = 1000

stock_tickers = asset_returns.columns.values[:-1]

assert 'SPX' not in stock_tickers, "By accident included SPX index"

 

step_size = 60

num_samples = 5

lookback_window = 252 * 2   # in (days)

num_assets = len(stock_tickers)

cov_matricies = np.zeros((num_samples, num_assets, num_assets)) # hold training data

 

# collect training and test data

ik = 0

for ix in range(ix_offset, min(ix_offset + num_samples * step_size, len(normed_r)), step_size):

    ret_frame = normed_r.iloc[ix_offset - lookback_window:ix_offset, :-1]

    print("time index and covariance matrix shape", ix, ret_frame.shape)

    cov_matricies[ik, :, :] = ret_frame.cov()

    ik += 1

 

# the last covariance matrix determines the absorption ratio

lin_ae = LinearAutoEncoder(n_inputs=num_assets, n_codings=200)

np.array([cov_matricies[-1, :, :]]).shape

lin_codings, test_absorp_ratio = lin_ae.train(cov_matricies[ : int((2/3)*num_samples), :, :],

                                                np.array([cov_matricies[-1, :, :]]),

                                                n_epochs=10,

                                                batch_size=5)

lin_codings, in_sample_absorp_ratio = lin_ae.absorption_ratio(np.array([cov_matricies[0, :, :]]))

 

 

time index and covariance matrix shape 1000 (504, 418)

time index and covariance matrix shape 1060 (504, 418)

time index and covariance matrix shape 1120 (504, 418)

time index and covariance matrix shape 1180 (504, 418)

time index and covariance matrix shape 1240 (504, 418)

---------------------------------------------------------------------------

NameError                                 Traceback (most recent call last)

<ipython-input-77-1685a4c86e35> in <module>

     20

     21 # the last covariance matrix determines the absorption ratio

---> 22 lin_ae = LinearAutoEncoder(n_inputs=num_assets, n_codings=200)

     23 np.array([cov_matricies[-1, :, :]]).shape

     24 lin_codings, test_absorp_ratio = lin_ae.train(cov_matricies[ : int((2/3)*num_samples), :, :],

 

<ipython-input-76-d62f9a1f8593> in __init__(self, n_inputs, n_codings, learning_rate)

     21             self.outputs = None

     22

---> 23             self.codings_layer =  fully_connected(self.X,n_codings, activation=tf.nn.relu)

     24

     25             self.outputs = fully_connected(self.codings_layer, n_outputs, activation_fn=None)

 

NameError: name 'fully_connected' is not defined

 

I don’t know what is the correct process for resolve this issue….

Reply all
Reply to author
Forward
0 new messages