
---
title: "Design Choices in Fully-Supervised setting (No Unlabelled Data)"
author: "Vamsi Ithapu"
date: "February 7, 2017"
output: html_document
runtime: shiny
---

```{r set-options, echo=FALSE}
#
library(shiny)

server <- function(input, output) {
  
  # Reactive expression to compose a data frame containing all of the values
  sliderValues <- reactive({
    
    # Compose data frame
    data.frame(
      Name = c("layers", "d0", "dL", "dropout", "goodness", "S", "C"),
      Value = c(input$layers, input$d0, input$dL, input$goodness, input$S, input$C), stringsAsFactors=FALSE)
    
  })
  
  f <- function(layers, d0, dL, dropout, goodness, S, C) {
    
    pisum = 0;
    outstring <- cat("<b><br> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Input layer length = ",d0, "</b><br>")
    outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
    outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")    
    #
    if (layers==4) {
      g <-  10^goodness; g1 <- sqrt(g);
      d3 <- (1/g1)*dropout/dL; d1 <- d3; d2 <- (1/g)/(dropout*d0*d1);  
      pisum <- (0.1/4)*d2*dropout + (0.1/4)*d3*dropout + (0.1/4)*dL + 13*d3*dL*0.01/(dropout*256);
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 1st Hidden layer length = ",round(d1), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 2st Hidden layer length = ",round(d2), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 3rd Hidden layer length = ",round(d3), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      #  
    } else if (layers==5) {
      g <-  10^goodness; g1 <- sqrt(g);
      d4 <- (1/g1)*dropout/dL; d1 <- d4; 
      d2 <- (1/g)/(dropout*d0*d1); d3 = (1/g)/(dropout*d1*d2); 
      pisum <- (0.1/4)*d2*dropout + (0.1/4)*d3*dropout + (0.1/4)*d4*dropout + (0.1/4)*dL + 13*d4*dL*0.01/(dropout*256);      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 1st Hidden layer length = ",round(d1), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 2st Hidden layer length = ",round(d2), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 3rd Hidden layer length = ",round(d3), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 4th Hidden layer length = ",round(d4), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
    #  
    } else if (layers==6) {
      g <-  10^goodness; g1 <- sqrt(g);
      d5 <- (1/g1)*dropout/dL; d1 <- d5; 
      d2 <- (1/g)/(dropout*d0*d1); d3 = (1/g)/(dropout*d1*d2); d4 = (1/g)/(dropout*d2*d3); 
      pisum <- (0.1/4)*d2*dropout + (0.1/4)*d3*dropout + (0.1/4)*d4*dropout + (0.1/4)*d5*dropout + (0.1/4)*dL + 13*d5*dL*0.01/(dropout*256);
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 1st Hidden layer length = ",round(d1), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 2st Hidden layer length = ",round(d2), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 3rd Hidden layer length = ",round(d3), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 4th Hidden layer length = ",round(d4), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 5th Hidden layer length = ",round(d5), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")            
      #  
    } else if (layers==7) {
      g <-  10^goodness; g1 <- sqrt(g);
      d6 <- (1/g1)*dropout/dL; d1 <- d6; 
      d2 <- (1/g)/(dropout*d0*d1); d3 = (1/g)/(dropout*d1*d2); d4 = (1/g)/(dropout*d2*d3); d5 = (1/g)/(dropout*d3*d4); 
      pisum <- (0.1/4)*d2*dropout + (0.1/4)*d3*dropout + (0.1/4)*d4*dropout + (0.1/4)*d5*dropout + (0.1/4)*d6*dropout + 
        (0.1/4)*dL + 13*d6*dL*0.01/(dropout*256);
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 1st Hidden layer length = ",round(d1), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 2st Hidden layer length = ",round(d2), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 3rd Hidden layer length = ",round(d3), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 4th Hidden layer length = ",round(d4), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 5th Hidden layer length = ",round(d5), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")            
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 6th Hidden layer length = ",round(d6), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")                  
      #        
    }
    #
    outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Last layer = ",dL, "</b><br>")
    emgamma = 0.1; epsilon = 0.05; delta = 0.05; T = 100; 
    B = 2*pisum/(epsilon*emgamma*(delta^(1/T))); 
    N = max(S*C/B, 20*dL/(dropout*dropout*epsilon*emgamma*(delta^(1/T))));
    return(cat(outstring, "<b><br> To compute (0.05,0.05)-solution (10 runs of stochastic gradients) with given epochs <br>
               and training instances; <br> 
               we need a batch-size of at least ",round(B/1000), "k instances and ",round(N/1000),"k gradient iterations </b><br>"))
  }
  
  fnew <- function(layers, d0, dL, goodness, S, C) {
    
    outstring <- cat("<b><br> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Input layer length = ",d0, "</b><br>")
    outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
    outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")    
    #
    if (layers==4) {
      g <-  10^goodness; g1 <- sqrt(g); g2 <- 10*g1; dropout <- 0.5; 
      d3 <- (1/g1)*dropout/dL; d1 <- d3; d2 <- (1/g)/(dropout*d0*d1);  
      pisum <- (0.1/4)*d2*dropout + (0.1/4)*d3*dropout + (0.1/4)*dL + 13*d3*dL*0.01/(dropout*256);
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 1st Hidden layer length = ",round(d1), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 2st Hidden layer length = ",round(d2), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 3rd Hidden layer length = ",round(d3), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      #  
    } else if (layers==5) {
      g <-  10^goodness; g1 <- sqrt(g); g2 <- 10*g1; dropout <- 0.5; 
      d4 <- (1/g1)*dropout/dL; d1 <- d4; 
      d2 <- (1/g)/(dropout*d0*d1); d3 = (1/g)/(dropout*d1*d2); 
      pisum <- (0.1/4)*d2*dropout + (0.1/4)*d3*dropout + (0.1/4)*d4*dropout + (0.1/4)*dL + 13*d4*dL*0.01/(dropout*256);            
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 1st Hidden layer length = ",round(d1), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 2st Hidden layer length = ",round(d2), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 3rd Hidden layer length = ",round(d3), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 4th Hidden layer length = ",round(d4), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      #  
    } else if (layers==6) {
      g <-  10^goodness; g1 <- sqrt(g); g2 <- 10*g1; dropout <- 0.5; 
      d5 <- (1/g1)*dropout/dL; d1 <- d5; 
      d2 <- (1/g)/(dropout*d0*d1); d3 = (1/g)/(dropout*d1*d2); d4 = (1/g)/(dropout*d2*d3); 
      pisum <- (0.1/4)*d2*dropout + (0.1/4)*d3*dropout + (0.1/4)*d4*dropout + (0.1/4)*d5*dropout + (0.1/4)*dL + 13*d5*dL*0.01/(dropout*256);
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 1st Hidden layer length = ",round(d1), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 2st Hidden layer length = ",round(d2), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 3rd Hidden layer length = ",round(d3), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 4th Hidden layer length = ",round(d4), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 5th Hidden layer length = ",round(d5), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")            
      #  
    } else if (layers==7) {
      g <-  10^goodness; g1 <- sqrt(g); g2 <- 10*g1; dropout <-  0.5;
      d6 <- (1/g1)*dropout/dL; d1 <- d6; 
      d2 <- (1/g)/(dropout*d0*d1); d3 = (1/g)/(dropout*d1*d2); d4 = (1/g)/(dropout*d2*d3); d5 = (1/g)/(dropout*d3*d4); 
      pisum <- (0.1/4)*d2*dropout + (0.1/4)*d3*dropout + (0.1/4)*d4*dropout + (0.1/4)*d5*dropout + (0.1/4)*d6*dropout + 
        (0.1/4)*dL + 13*d6*dL*0.01/(dropout*256);
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 1st Hidden layer length = ",round(d1), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 2st Hidden layer length = ",round(d2), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 3rd Hidden layer length = ",round(d3), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 4th Hidden layer length = ",round(d4), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 5th Hidden layer length = ",round(d5), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")            
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 6th Hidden layer length = ",round(d6), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")                  
      #        
    }
    #
    outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Last layer = ",dL, "</b><br>")
    emgamma = 0.1; epsilon = 0.05; delta = 0.05; T = 100; 
    B = 2*pisum/(epsilon*emgamma*(delta^(1/T))); 
    N = max(S*C/B, 20*dL/(dropout*dropout*epsilon*emgamma*(delta^(1/T))));
    return(cat(outstring, "<b><br> To compute (0.05,0.05)-solution (10 runs of stochastic gradients) with given epochs <br>
               and training instances; <br> 
               we need a batch-size of at least ",round(B/1000), "k instances and ",round(N/1000),"k gradient iterations </b><br>"))    
  }
  
  fnew1 <- function(layers, d0, dropout, goodness, S, C) {
    
    outstring <- cat("<b><br> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Input layer length = ",d0, "</b><br>")
    outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
    outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")    
    #
    if (layers==4) {
      g <-  10^goodness; g1 <- sqrt(g); g2 <- 10*g1; dL = (1/g2)*(dropout^2);
      d3 <- (1/g1)*dropout/dL; d1 <- d3; d2 <- (1/g)/(dropout*d0*d1);  
      pisum <- (0.1/4)*d2*dropout + (0.1/4)*d3*dropout + (0.1/4)*dL + 13*d3*dL*0.01/(dropout*256);           
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 1st Hidden layer length = ",round(d1), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 2st Hidden layer length = ",round(d2), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 3rd Hidden layer length = ",round(d3), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Last layer length = ",max(1,round(dL)))
      #  
    } else if (layers==5) {
      g <-  10^goodness; g1 <- sqrt(g); g2 <- 10*g1; dL = (1/g2)*(dropout^2);
      d4 <- (1/g1)*dropout/dL; d1 <- d4; 
      d2 <- (1/g)/(dropout*d0*d1); d3 = (1/g)/(dropout*d1*d2); 
      pisum <- (0.1/4)*d2*dropout + (0.1/4)*d3*dropout + (0.1/4)*d4*dropout + (0.1/4)*dL + 13*d4*dL*0.01/(dropout*256);     
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 1st Hidden layer length = ",round(d1), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 2st Hidden layer length = ",round(d2), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 3rd Hidden layer length = ",round(d3), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 4th Hidden layer length = ",round(d4), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Last layer length = ",max(1,round(dL)))
      #  
    } else if (layers==6) {
      g <-  10^goodness; g1 <- sqrt(g); g2 <- 10*g1; dL = (1/g2)*(dropout^2);
      d5 <- (1/g1)*dropout/dL; d1 <- d5; 
      d2 <- (1/g)/(dropout*d0*d1); d3 = (1/g)/(dropout*d1*d2); d4 = (1/g)/(dropout*d2*d3); 
      pisum <- (0.1/4)*d2*dropout + (0.1/4)*d3*dropout + (0.1/4)*d4*dropout + (0.1/4)*d5*dropout + (0.1/4)*dL + 13*d5*dL*0.01/(dropout*256);
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 1st Hidden layer length = ",round(d1), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 2st Hidden layer length = ",round(d2), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 3rd Hidden layer length = ",round(d3), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 4th Hidden layer length = ",round(d4), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 5th Hidden layer length = ",round(d5), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")            
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Last layer length = ",max(1,round(dL)))
      #  
    } else if (layers==7) {
      g <-  10^goodness; g1 <- sqrt(g); g2 <- 10*g1; dL = (1/g2)*(dropout^2);
      d6 <- (1/g1)*dropout/dL; d1 <- d6; 
      d2 <- (1/g)/(dropout*d0*d1); d3 = (1/g)/(dropout*d1*d2); d4 = (1/g)/(dropout*d2*d3); d5 = (1/g)/(dropout*d3*d4); 
      pisum <- (0.1/4)*d2*dropout + (0.1/4)*d3*dropout + (0.1/4)*d4*dropout + (0.1/4)*d5*dropout + (0.1/4)*d6*dropout + 
        (0.1/4)*dL + 13*d6*dL*0.01/(dropout*256);      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 1st Hidden layer length = ",round(d1), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 2st Hidden layer length = ",round(d2), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 3rd Hidden layer length = ",round(d3), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 4th Hidden layer length = ",round(d4), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")      
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 5th Hidden layer length = ",round(d5), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")            
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 6th Hidden layer length = ",round(d6), "</b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp | </b><br>")                  
      outstring <- cat(outstring, "<b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Last layer length = ",max(1,round(dL)))
      #        
    }
    #
    emgamma = 0.1; epsilon = 0.05; delta = 0.05; T = 100; 
    B = 2*pisum/(epsilon*emgamma*(delta^(1/T))); 
    N = max(S*C/B, 20*dL/(dropout*dropout*epsilon*emgamma*(delta^(1/T))));
    return(cat(outstring, "<b><br> To compute (0.05,0.05)-solution (10 runs of stochastic gradients) with given epochs <br>
               and training instances; <br> 
               we need a batch-size of at least ",round(B/1000), "k instances and ",round(N/1000),"k gradient iterations </b><br>"))        
  }

  output$text <- renderText({
    paste("<b>For the given choices of hyper-parameters, the network architecture is</b>")
  })
  
  # Show the final calculated value 
  output$thedesign <- renderPrint({
    f(input$layers, input$d0, input$dL, input$dropout, input$goodness, input$S, input$C)
    })  
  
  output$textnew <- renderText({
    paste("<b>If the dropout rate is forced to be 0.5, the network architecture is</b>")
  })
  
  # Show the final calculated value 
  output$thenewdesign <- renderPrint({
    fnew(input$layers, input$d0, input$dL, input$goodness, input$S, input$C)
  })
  
  output$textnew1 <- renderText({
    paste("<b>If the last layer length is allowed to change, the network architecture is</b>")
  })
  
  # Show the final calculated value 
  output$thenewdesign1 <- renderPrint({
    fnew1(input$layers, input$d0, input$dropout, input$goodness, input$S, input$C)
  })
  
  output$drawline <- renderText({
    paste("<b><br>---------------------------------------------------------------------------------------------------------------<br>
          ---------------------------------------------------------------------------------------------------------------<br></b>")
  })  
  output$drawline1 <- renderText({
    paste("<b><br>---------------------------------------------------------------------------------------------------------------<br>
          ---------------------------------------------------------------------------------------------------------------<br></b>")
  })  
  output$drawline2 <- renderText({
    paste("<b><br>---------------------------------------------------------------------------------------------------------------<br>
          ---------------------------------------------------------------------------------------------------------------<br></b>")
  })    
}

ui <- fluidPage(
  # Application title
  # titlePanel("Design Choices in Deep Networks (Fully Supervised -- No Unlabelled data)"),
  # Sidebar with a slider input for the number of bins
  sidebarLayout(
    sidebarPanel(
        tags$style(HTML(".js-irs-0 .irs-single, .js-irs-0 .irs-bar-edge, .js-irs-0 .irs-bar {background: blue}")),
        tags$style(HTML(".js-irs-1 .irs-single, .js-irs-1 .irs-bar-edge, .js-irs-1 .irs-bar {background: blue}")),
        tags$style(HTML(".js-irs-2 .irs-single, .js-irs-2 .irs-bar-edge, .js-irs-2 .irs-bar {background: blue}")),
        tags$style(HTML(".js-irs-3 .irs-single, .js-irs-3 .irs-bar-edge, .js-irs-3 .irs-bar {background: blue}")),
        tags$style(HTML(".js-irs-4 .irs-single, .js-irs-4 .irs-bar-edge, .js-irs-4 .irs-bar {background: green}")),
        tags$style(HTML(".js-irs-5 .irs-single, .js-irs-5 .irs-bar-edge, .js-irs-5 .irs-bar {background: green}")),
        tags$style(HTML(".js-irs-6 .irs-single, .js-irs-6 .irs-bar-edge, .js-irs-6 .irs-bar {background: green}")),
       #
       div("Required Hyper-Parameters", style = "color:blue"), br(),
       sliderInput("layers", div("Number of Layers", style = "color:blue"), min = 4, max = 7, value = 5, step = 1), br(),
       #
       sliderInput("d0", div("Input features (first layer length)", style = "color:blue"), min = 100, max = 1000, value = 500, step = 50), br(),
       #
       sliderInput("dL", div("Output features (last layer length)", style = "color:blue"), min = 5, max = 20, value = 10, step = 1), br(),
       #
       sliderInput("S", div("Number of Labelled instances available (i.e., the training data size)", style = "color:blue"), 
                            min = 100, max = 10^6, value = 10^5, step = 50), br(),
       #
       div("___________________________"), br(),   
       div("Optional Hyper-Parameters", style = "color:green"), br(),
       #
       sliderInput("C", div("Number of affordable epochs", style = "color:green"), min = 50, max = 500, value = 100, step = 50), br(),       
       #
       sliderInput("dropout", div("The dropout rate (of input and hidden layers)", style = "color:green"), 
                   min = 0.2, max = 0.8, value = 0.5, step = 0.05), br(),
       #
       sliderInput("goodness", div("The convergence goodness criterion (in log10 scale)", style = "color:green"), 
                   min = -8, max = -5, value = -7, step = 0.1)
    ),
    
    # Show a plot of the generated distribution
    mainPanel(
      htmlOutput("text"), span( uiOutput("thedesign"), style = "color:maroon"), htmlOutput("drawline"), 
      htmlOutput("textnew"), span( uiOutput("thenewdesign"), style = "color:maroon"), htmlOutput("drawline1"),
      htmlOutput("textnew1"), span( uiOutput("thenewdesign1"), style = "color:maroon"), htmlOutput("drawline2")
    )
  )
)

shinyApp(ui = ui, server = server, options = list(height=1550))

```

