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:
- How do I code it in a custom layer ?
- How do I code the equation using tensorflow?
Thank you for all the help!