0

Equation to be coded Model showing what the equation does

I would like to be code the equation attached in a custom layer. This layer will accept inputs of dimensions (None,3) & (None,37,3) and generate an output of the dimension (3,37)

The equation is for centroid generation as shown in the model.

k is 3 t is 37 in the code

The code for for calculating the same using numpy was coded as below:

Membership_Output = Membership_DNN.predict(latent_representation_input)
Reconstructed_Data = np.zeros((k,autoencoder_output_1.shape[0],autoencoder_output_1.shape[1]))
Reconstructed_Data[0,:,:] = autoencoder_output_1
Reconstructed_Data[1,:,:] = autoencoder_output_2
Reconstructed_Data[2,:,:] = autoencoder_output_3
centroid_scenario=np.zeros((k,cols))
for time in range(0, cols):
    for scenario in range(0, rows):
        centroid_scenario[scenario,time] = sum(np.multiply((np.power(Membership_Output[:,scenario],2)),Reconstructed_Data[scenario,:,time]))/sum((np.power(Membership_Output[:,scenario],2)))

How can I use a keras custom layer to code the above code ( same as the equation provided) ? I assume I may need to use tensorflow calculations to do the same in a custom layer. But. I'm not quite sure on the following things:

  1. How do I code it in a custom layer ?
  2. How do I code the equation using tensorflow?

Thank you for all the help!

2
  • can you give some context on what is k and t? Commented Apr 3, 2023 at 12:21
  • @AlbertoSinigaglia : Sure, Thank you for the response! k = 3 (number of autoencoders/ number of reduced scenarios) and t =37 (number of time periods) for the code. The equation provided is part of the model shown in the figure. The equation is used for centroid generation by using the data from 3 decoders (Autoencoder's output shown as X in the equation) and a membership DNN (shown as U in the equation). Commented Apr 4, 2023 at 12:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.