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 time | |
from concurrent.futures import ProcessPoolExecutor, as_completed | |
import random | |
import jsonlines as jl | |
class MyExecutor: | |
def write(self, text: str): | |
time.sleep(random.randint(0, 2)) |
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
from typing import Tuple | |
import torch | |
import torch.nn as nn | |
class GradientReversalFunction(torch.autograd.Function): | |
@staticmethod | |
def forward(ctx, input_forward: torch.Tensor, scale: torch.Tensor) -> torch.Tensor: |
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 collection | |
log.debug(len(train_loader)) | |
labels = [] | |
for i, data in enumerate(train_loader): | |
_, label = data | |
labels.append(label.item()) | |
labels_counter = collections.Counter(labels) | |
log.debug(labels_counter) | |
labels = [] | |
log.debug(len(val_loader)) |
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 torch | |
from torch import nn as nn | |
from torch import autograd as ag | |
data = ag.Variable(torch.Tensor(torch.randn([100, 100]))) | |
labels = ag.Variable(torch.Tensor(torch.randn([100, 100]))) | |
multi_label_soft_margin = nn.MultiLabelSoftMarginLoss() | |
print(multi_label_soft_margin(data, labels)) |
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
# MultiLabelSoftMarginLoss only | |
ml_criterion = nn.MultiLabelSoftMarginLoss() | |
## torch.randn | |
data, labels = Variable(torch.randn([1, 5])), Variable(torch.randn([1, 5])) | |
print(data.data, labels.data) | |
print(ml_criterion(data, labels)) | |
## fixed FloatTensor | |
data, labels = Variable(torch.FloatTensor([1, 50, 100, 50, 1])), Variable(torch.FloatTensor([0, 0, 1, 0, 0])) | |
print(data.data, labels.data) | |
print(ml_criterion(data, labels)) |
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
#!/usr/bin/env python3 | |
# coding: utf-8 | |
# プログラミングのための確率統計 p.280 例題8.2 の numpy での実装 | |
import numpy as np | |
# データ群 | |
x1 = np.array([0, 5]) | |
x2 = np.array([0, -5]) | |
x3 = np.array([4, 3]) |
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 sys | |
import numpy as np | |
import numpy.random as rnd | |
import matplotlib.pyplot as plt | |
A = 0.7 | |
SEED = 10000 | |
TRIAL = 100 |
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
#!/usr/bin/env python3 | |
# coding: utf-8 | |
import sys | |
import numpy as np | |
def make_data(n): | |
""" | |
優先順位が行ごとにシャッフルされたn次正方行列を生成する |
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
#!/usr/bin/env python3 | |
# coding: utf-8 | |
import numpy as np | |
NUM = 100000 # 試行回数 | |
DOORS = np.array([1, 2, 3]) # ドア | |
NewerOlder