Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 pandas as pd | |
def format_best(to_bold, numeric_df=None, order="max", format_str="\\bfseries{{{}}}"): | |
"""Format the row with the best value within each column of a pandas DataFrame in a particular way. | |
Args: | |
to_bold: pandas.DataFrame to operate on in-place. | |
numeric_df: Optional pandas.DataFrame from which the best rows should be infered. | |
order: Define what is the row that should be formatted. Supported: `max`, `min`, `second_highest`, `second_lowest`. If it is a list then it is interpreted in a per column way, otherwise applies to all columns. |
This file contains 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
def brier_decomposition(labels, probs): | |
"""Compute the decompositon of the Brier score into its three components | |
uncertainty (UNC), reliability (REL) and resolution (RES). | |
Brier score is given by `BS = REL - RES + UNC`. The decomposition requires partioning | |
into discrete events. Partioning into probability classes `M_k` is done for `p_k > p_i` | |
for all `i!=k`. This induces a error when compared to the Brier score. | |
For more information on the partioning see | |
Murphy, A. H. (1973). A New Vector Partition of the Probability Score, Journal of Applied Meteorology and Climatology, 12(4) |
This file contains 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 | |
import seaborn as sns | |
sns.set() | |
sns.set_style("ticks") | |
sns.set_context("paper", font_scale=1.0) | |
params = { | |
'text.usetex' : True, | |
'font.size' : 11, |
This file contains 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
class GradNormLogger: | |
def __init__(self): | |
self.grad_norms = defaultdict(list) | |
def update(self, model: torch.nn.Module, norm_type: float = 2.): | |
total_norm = 0 | |
for name, p in model.named_parameters(): | |
if p.requires_grad: | |
try: |
This file contains 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
dpi = 80 | |
# What size does the figure need to be in inches to fit the image? | |
figsize = width / float(dpi), height / float(dpi) | |
# Create a figure of the right size with one axes that takes up the full figure | |
fig = plt.figure(figsize=figsize) | |
ax = fig.add_axes([0, 0, 1, 1]) | |
ax.set_aspect('equal', adjustable='box') |