#-----------------------------------------------------------------------------------------------------#
# Figure 3 and Appendix D
#-----------------------------------------------------------------------------------------------------#

* Organization:
	- colab_codes: contains the sh-files, py-files, ipynb-notebook, and m-files to train the DNNs
	- colab_data: contains the data to train the DNNs.
	- colab_results: contains the data obtained from the DNNs.
	
	- data: contains the data generated 
	- figs: contains the figures
	- results: contains the results from extraction of the data  
	- src: main m-files for generating the data and the figures
	- utils: various m-files used to compute the approximations. 
	
#-----------------------------------------------------------------------------------------------------#
* Steps to Run the code

Step 1: "Generate or load the data from MATLAB"
	1.1. Run "generate_data.m" from folder "src/gen data/".
	1.2. It generates the PDE data and saves it on "colab_data/". 
	1.3. It also plots the data, you can press 
		>> close all
	     to close all the figures. 
	1.4. Compress the file as "colab_data.zip". 
		
Step 2: "Create the Google Colab Notebook"
	2.1. You will need a Google account 
	2.2. Compress the folder "colab_codes/" as zip file "colab_codes.zip".
	2.3. On Colab, press the option "File" (on the top-left), press the option "Upload notebook" 
	     and upload: 
		- "CS4ML_Appendix_D.ipynb" from the folder "colab_codes/". 
		
	2.4. Connect to a GPU:
		- Press the option "Edit" on the top-left, next to the option "File". 
		- Then press the option "Notebook settings".
		- Choose GPU, with the biggest RAM, and save.
		
	2.5. On the left of the notebook, press the icon that looks like a folder, below the icon {x}.
	2.6. Wait until Colab allocates a GPU, you should see the folder "sample_data/".
	2.7. Press the right button of the mouse below the folder "sample_data/", and choose the option 
	     "Upload" and upload the files:
		- colab_data.zip
		- colab_codes.zip
	
Step 2: "Run main code"
	Press run. This will execute seven instructions:
		2.1. Unzip the folders "colab_data.zip" and "colab_codes.zip" by executing:
			>> !unzip /content/colab_codes.zip
			>> !unzip /content/colab_data.zip
			
		2.2. Install and import Packages:
			>> !python -m pip install hdf5storage --user
			>> import time, os
			
		2.3. It will create the folders:
			- colab_codes/
			- colab_data/
			- colab_results/
			
		2.4. Train, test, and evaluate on plot data all the DNNs in Figure 3 by executing:	
			>> !bash batch_train_fig_3.sh
			>> !bash batch_test_fig_3.sh 
			
		2.5. Train, test, and evaluate on plot data all the DNNs in figures in Appendix D 
		     by executing:	
			>> !bash batch_train_fig_AppD.sh
			>> !bash batch_test_fig_AppD.sh  
			
		2.6. Save the folder "colab_results/" as "colab_results.zip" by executing:
			>> !zip -r /content/colab_results.zip /content/colab_results
			
		2.7. Download the file "colab_results.zip"
			>> from google.colab import files
			>> files.download('/content/colab_results.zip')

Step 3: "Move data to the local machine"
	3.1. Move the file "colab_results.zip" to the main folder.
	3.2. Unzip "colab_results.zip" in the main folder.
	3.3. Inside colab_results.zip you will find the folder 'content/colab_results/". Merge 
	     this folder "colab_results/" with "colab_results/" in the main folder.
	
Step 4: "Extract data from several files"
	4.1. Open MATLAB and run "extract_data.m" in "colab_codes/" folder. 
	4.2. It will create the main data from "colab_results/" and save it in the folder "results/".
	
Step 5: "Generate data to plot"
	Open MATLAB and run:
		5.1. "fig_3_run.m" in the "src/" folder.
		5.2. "fig_App_D_run.m" in the "src/" folder.
		
Step 6: "Plot"
	6.1. Open MATLAB and run:
		- "fig_3_plot.m"  in folder "src/Figure 3". 
		- "fig_App_D_plot.m" in folder "src/Figure App D".
		
	6.2. It will generate the plots for Figure 3 and Appendix D.
	6.3. The figures will be saved in the folders:
		- "figs/Figure 3"
		- "figs/Figure App D"
		- "figs/Figure App D 4"
		- "figs/Figure App 5 6 7/"
		
#-----------------------------------------------------------------------------------------------------#
* Note: To run a small set such as 2 trials.  Do the following 

1. Modify colab_codes/:
	1.1. Open "batch_train_fig_3.sh " using Vim or similar and modify line 157 to
		>> for t in {0..1..1}
		
	1.2. Open "batch_test_fig_3.sh " using Vim or similar and modify line 17 to
		>> declare -r nb_trials="2"
		
	1.3. Open "batch_train_fig_AppD.sh " using Vim or similar and modify line 157 to
		>> for t in {0..1..1}
		
	1.4. Open "batch_test_fig_AppD.sh " using Vim or similar and modify line 17 to
		>> declare -r nb_trials="2"		
		
2. Modify MATLAB functions:
	2.1. file extrac_data.m in folder colab_codes/, modify line 32 to
		>>  num_trials = 2;
		
	2.2. file fig_3_data.m in folder src/Figure 3/, modify line 24 to
		>> nb_trials = 2;
		
	2.3. file fig_App_D_data.m in folder src/Figure App D/, modify line 22 to
		>> nb_trials = 2;
		
	2.4. file fig_App_D_4_data.m in folder src/Figure App D/, modify line 21 to
		>> nb_trials = 2;
		
	2.5. file fig_App_D_4_plot.m in folder src/Figure App D/, modify line 22 to
		>> nb_trials = 2;
		
	2.5. file fig_App_D_5_6_7_data.m in folder src/Figure App D/, modify line 22 to
		>> nb_trials = 2;
		
3. Then you can execute the previous instructions Step 1 to Step 6.
		
	
		





























	
