Hinton diagram
The hinton diagram is a 2D plot for visualizing weight matrices in deep learning applications. Matplotlib
does not have a direct method to plot this diagram. So we will have to write a code to plot this. The weight matrix for this is taken from one of machine learning (ML) algorithms that classifies images.
Getting ready
Import required libraries:
import numpy as np import matplotlib.pyplot as plt import pandas as pd
How to do it...
- Following code block will define the function and makes a call to the function to plot Hinton diagram:
matrix = np.asarray((pd.read_excel('weight_matrix.xlsx'))) fig, ax = plt.subplots() max_weight = 2 ** np.ceil(np.log(np.abs(matrix).max()) / np.log(2)) ax.patch.set_facecolor('gray') ax.set_aspect('equal', 'box') ax.xaxis.set_major_locator(plt.NullLocator()) ax.yaxis.set_major_locator(plt.NullLocator()) for (x, y), w in np.ndenumerate(matrix): color = 'white' if w > 0 else 'black' size = np.sqrt(np.abs(w) / max_weight) rect = plt.Rectangle...