Skip to content

Commit

Permalink
Se divide en varios notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
camilomarino committed Dec 27, 2020
1 parent 167b740 commit ab949a2
Show file tree
Hide file tree
Showing 19 changed files with 2,507 additions and 2 deletions.
1 change: 1 addition & 0 deletions ProyectoFinal/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.h5
.virtual_documents/
*.npy
616 changes: 616 additions & 0 deletions ProyectoFinal/Create_vectors.ipynb

Large diffs are not rendered by default.

525 changes: 525 additions & 0 deletions ProyectoFinal/Evaluate_results.ipynb

Large diffs are not rendered by default.

549 changes: 549 additions & 0 deletions ProyectoFinal/Solve_regularization.ipynb

Large diffs are not rendered by default.

204 changes: 204 additions & 0 deletions ProyectoFinal/Solve_restriction.ipynb

Large diffs are not rendered by default.

324 changes: 324 additions & 0 deletions ProyectoFinal/Solve_sanity_check.ipynb

Large diffs are not rendered by default.

238 changes: 238 additions & 0 deletions ProyectoFinal/Solve_simple.ipynb

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions ProyectoFinal/apgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def adam_pgd(D: np.ndarray,
A0: np.ndarray = None,
mask: np.ndarray = None,
n_mask: int = None,
early_stopping = None,
verbose: bool = True) -> np.ndarray:

X = torch.tensor(X, device=device, dtype=torch.float32)
Expand All @@ -33,8 +34,12 @@ def adam_pgd(D: np.ndarray,

optimizer = optim.Adam([A], lr=lr, betas=betas)
losses = list()
best_A = None
best_loss = float('inf')
count_stop = 0
for k in range(max_iter):
optimizer.zero_grad()
if k!=0: A.grad.zero_()
loss = f(A)
losses.append(float(loss))
loss.backward()
Expand All @@ -48,6 +53,15 @@ def adam_pgd(D: np.ndarray,
eps = 1e-10
for i in range(n_mask):
A[mask==i] /= (A[mask==i].sum(dim=0) + eps)


if float(loss)<best_loss:
best_A = to_np(A)
best_loss = float(loss)
count_stop = 0
else:
if early_stopping is not None:
count_stop += 1
if count_stop>early_stopping:
break

return to_np(A), float(loss), losses
return best_A, float(loss), losses
Binary file modified ProyectoFinal/arrays/A_simple.npy
Binary file not shown.
Binary file modified ProyectoFinal/arrays/losses_simple.npy
Binary file not shown.
20 changes: 20 additions & 0 deletions ProyectoFinal/get_arrays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import numpy as np

def get_Q(mask):
Q = np.zeros( (len(np.unique(mask)), len(mask)) )
for i, num_elec in enumerate(np.unique(mask)):
Q[i, mask==num_elec] = 1
return Q



#%%
def get_U(mask, T):
U = np.ones( (len(np.unique(mask)), T) )
return U

def get_G(X, U, beta):
return np.vstack((X, beta*U))

def get_H(D, Q, beta):
return np.vstack((D, beta*Q))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ProyectoFinal/images/loss_con_restriccion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ProyectoFinal/images/plot_agregado_simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ProyectoFinal/images/prediction_prob_simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions ProyectoFinal/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import matplotlib.pyplot as plt
from matplotlib import rcParams

def plot_loss(losses, title=None):
rcParams['font.style'] = 'normal'
rcParams['font.size'] = 12
rcParams['font.weight'] = 'normal'
plt.figure()
plt.plot(losses)
#plt.ylim((1055476.62*0.96, 1265412.12*1.2))
plt.grid(True)
plt.xlabel('Iteración')
plt.ylabel(r'loss$={||X-DA||_F^2}$')
if title is not None: plt.title(title)

0 comments on commit ab949a2

Please sign in to comment.