<jupyter_start><jupyter_text><jupyter_code># Clone the git repository by running the following line
! git clone https://github.com/osmanmusa/LAMP_python3.git
# Copy the LAMP_bg_giid.npz file to your google drive and mount the drive into colab.
# Run the following code ...
from google.colab import drive
drive.mount('/content/drive')
# On the left side of your screen, just under "+ Code" there is a ">" button.
# When you press this button you will be able to see the list of files folders,
# which you can access in colab
# Open the LAMP_python3/LAMP.py file and make sure that untied=True when building 
# the network, and that the learned network is read from the file 
# /content/drive/My Drive/LAMP_bg_giid.npz, when training  and evaluating the network
% run LAMP_python3/LAMP.py
# If everything goes well, you should see the following

# LAMP-soft T=1 nmse=-6.218525 dB
# LAMP-soft linear T=2 nmse=-1.558928 dB
# LAMP-soft non-linear T=2 nmse=-11.149492 dB
# LAMP-soft linear T=3 nmse=-6.030330 dB
# LAMP-soft non-linear T=3 nmse=-15.739241 dB
# LAMP-soft linear T=4 nmse=-11.111426 dB
# LAMP-soft non-linear T=4 nmse=-20.009360 dB
# LAMP-soft linear T=5 nmse=-15.367776 dB
# LAMP-soft non-linear T=5 nmse=-24.644411 dB
# LAMP-soft linear T=6 nmse=-18.936634 dB
# LAMP-soft non-linear T=6 nmse=-29.489040 dB
# LAMP-soft linear T=7 nmse=-22.657232 dB
# LAMP-soft non-linear T=7 nmse=-33.414526 dB
# LAMP-soft linear T=8 nmse=-30.440512 dB
# LAMP-soft non-linear T=8 nmse=-37.886918 dB

# You can evaluate network agian to make sure that restored parameters and matrices give nmse as before
print('Evaluating the learned network ...')
train.evaluate_nmse(sess, training_stages, prob, 'drive/My Drive/LAMP_bg_giid.npz' )
# Here we import the necessary libraries and modules 
#!/usr/bin/python
from __future__ import division
from __future__ import print_function
"""
This file serves as an example of how to 
a) select a problem to be solved 
b) select a network type
c) train the network to minimize recovery MSE

"""
import numpy as np
import os
import matplotlib.pyplot as plt

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # BE QUIET!!!!
os.environ['KMP_DUPLICATE_LIB_OK']='True'
import tensorflow as tf

np.random.seed(1) # numpy is good about making repeatable output
tf.set_random_seed(1) # on the other hand, this is basically useless (see issue 9171)

# import our problems, networks and training modules
from tools import problems,networks,train
# I use this line to get the measurement matrix which is hidden in prob variable
prob = problems.bernoulli_gaussian_trial(kappa=None,M=250,N=500,L=1000,pnz=.1,SNR=40) #a Bernoulli-Gaussian x, noisily observed through a random matrix
A = prob.A
# Insted of reading the matrices B_t from the netowrk, I rather read them from the file
filename = 'drive/My Drive/LAMP_bg_giid.npz'

B_t = []
theta_t = []

try:
    filecontent = np.load(filename).items()
    for k, d in filecontent:
        if k.startswith('B_'):
            B_t.append(d)
            print('reading ' + k + ' as:' + str(d))
        elif k.startswith('theta_'):
            theta_t.append(d)
            print('reading ' + k + ' as:' + str(d))
except IOError:
    print('Couldnt read the file')
    pass
# Do SVD for A and B_t
B_t = np.asarray(B_t)

# Shape of B_t should be 8x500x250
print(B_t.shape)

M,N = A.shape
U_A, S_A, Vh_A = np.linalg.svd(A.transpose())

U_t = np.empty([8,500,500])
S_t = np.empty([8,250])
V_t = np.empty([8,250,250])

for i in range(len(B_t)):
    U, S, Vh = np.linalg.svd(B_t[i])
    U_t[i] = U
    S_t[i] = S
    V_t[i] = Vh
## A few test to check if the SVD of A makes sense

# Check if U_AˆT*U_A is a unitary matrix with dimensions 250x250
# Here comes your code ...
# Check if Vh_AˆT*Vh_A is a unitary matrix with dimensions 500x500
# Here comes your code ...

# Print out Frobenius norm of A
# Here comes your code ...

# Plot singular values of A
# Here comes your code ...
## Frobenius norms of B_t

# Plot Frobenius norms of B_t against t
# Here comes your code ...
## How close is B_t to AˆT?

# Plot Frobenius norms of B_t-AˆT against t
# Here comes your code ...
## How close is B_t to mu_t * AˆT?

# For each t, find mu_t which minimizes Frobenius norm of B_t-mu_t*A
# Here comes your code ...

# ---- Plotting results ----
# Plot Frobenius norms of B_t-mu_t*AˆT against t
# On the same figure, plot B_t-AˆT against t
# Add figure title, legend, axis labels
# Here comes your code ...
## Are succesive B_t getting closer to each other

# Plot Frobenius norms of Frobenius norms of B_{t+1}-B_t against t
# Here comes your code ...
## Plotting the parameters of the soft thresholder

# Plot theta_t (2 parameters) against t
# Add figure title, legend, axis labels
# Here comes your code ...

# Is scaling parameter significantely changing across iterations? 
## Plotting U_t matrices

# Plot U_t matrices as gray scale images
# Here comes your code ... 
## Plotting U_tˆT*U_k. White is 1, black is -1, and gray is 0 

# For each matrix U_t plot U_tˆT*U_k. White is 1, black is -1, and gray is 0
# Here comes your code ... 
      
# Can we conclude the matrices have roughly 'the same' left signal spaces?
## Plotting V_tˆT*V_k. White is 1, black is -1, and gray is 0 

# For each matrix V_t plot V_tˆT*V_k. White is 1, black is -1, and gray is 0
# Here comes your code ... 

# Can we draw any conclusions from here?<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09996297667530545, 'fraction_numerical': 0.0381340244353943, 'mean_word_length': 3.6337907375643224, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '596638', 'license': 'MIT', 'n_tokens_mistral': 2053, 'n_tokens_neox': 1901, 'n_words': 718, 'path': 'Analysis_of_LAMP_network_open_questions.ipynb', 'repo_name': 'osmanmusa/LAMP_python3', 'size': '5402'}