This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | ## Gist originally developed by @craffel and improved by @ljhuang2017 | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| def draw_neural_net(ax, left, right, bottom, top, layer_sizes, coefs_, intercepts_, n_iter_, loss_): | |
| ''' | |
| Draw a neural network cartoon using matplotilb. | |
| :usage: | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import numpy as np | |
| from keras.models import Sequential | |
| from keras.layers import Dense | |
| from keras.optimizers import SGD | |
| from keras.initializers import glorot_normal, normal | |
| # ======================= # | |
| # Data generation process # | |
| # ======================= # | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from deepreplay.callbacks import ReplayData | |
| from deepreplay.datasets.parabola import load_data | |
| X, y = load_data() | |
| replaydata = ReplayData(X, y, filename='hyperparms_in_action.h5', group_name='part1') | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from keras.models import Sequential | |
| from keras.layers import Dense | |
| from keras.optimizers import SGD | |
| from keras.initializers import glorot_normal, normal | |
| model = Sequential() | |
| model.add(Dense(input_dim=2, | |
| units=2, | |
| activation='sigmoid', | |
| kernel_initializer=glorot_normal(seed=42), | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from deepreplay.replay import Replay | |
| replay = Replay(replay_filename='hyperparms_in_action.h5', group_name='part1') | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import matplotlib.pyplot as plt | |
| fig, ax = plt.subplots(1, 1, figsize=(5, 5)) | |
| fs = replay.build_feature_space(ax, layer_name='hidden') | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Plot 60th epoch and save it as PNG | |
| fs.plot(epoch=60).savefig('feature_space_epoch60.png', dpi=120) | |
| # Animate and save it as MP4 | |
| fs.animate().save('feature_space_animation.mp4', dpi=120, fps=5) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | fig = plt.figure(figsize=(12, 6)) | |
| ax_fs = plt.subplot2grid((2, 4), (0, 0), colspan=2, rowspan=2) | |
| ax_ph_neg = plt.subplot2grid((2, 4), (0, 2)) | |
| ax_ph_pos = plt.subplot2grid((2, 4), (1, 2)) | |
| ax_lm = plt.subplot2grid((2, 4), (0, 3)) | |
| ax_lh = plt.subplot2grid((2, 4), (1, 3)) | |
| fs = replay.build_feature_space(ax_fs, layer_name='hidden') | |
| ph = replay.build_probability_histogram(ax_ph_neg, ax_ph_pos) | |
| lh = replay.build_loss_histogram(ax_lh) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from keras.models import Sequential | |
| from keras.layers import Dense | |
| def build_model(n_layers, input_dim, units, activation, initializer): | |
| if isinstance(units, list): | |
| assert len(units) == n_layers | |
| else: | |
| units = [units] * n_layers | |
| model = Sequential() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from deepreplay.callbacks import ReplayData | |
| from deepreplay.replay import Replay | |
| from deepreplay.plot import compose_plots | |
| from keras.initializers import normal | |
| from matplotlib import pyplot as plt | |
| filename = 'part2_weight_initializers.h5' | |
| group_name = 'sigmoid_stdev_0.01' | |
| # Uses normal initializer | 
OlderNewer