Skip to content

Instantly share code, notes, and snippets.

@gallettilance
Created November 9, 2021 20:36
Show Gist options
  • Select an option

  • Save gallettilance/a85f852b1c9f9143e8d1af63253f40e0 to your computer and use it in GitHub Desktop.

Select an option

Save gallettilance/a85f852b1c9f9143e8d1af63253f40e0 to your computer and use it in GitHub Desktop.
import numpy as np
from tensorflow import keras, norm
RANK = 10
def custom_loss(y_true, y_pred):
return norm(y_true - y_pred, ord='euclidean')
boat = np.loadtxt('boat.dat')
model = keras.models.Sequential()
model.add(keras.layers.Dense(RANK, use_bias=False, input_dim=len(boat)))
model.add(keras.layers.Dense(len(boat), use_bias=False))
model.compile(loss=custom_loss)
history = model.fit(boat, boat, batch_size=50, epochs=500)
rank_k_boat_approx = model.predict(boat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment