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, autograd, optim | |
from torch.utils.tensorboard import SummaryWriter | |
import tqdm#.notebook as tqdm | |
import torchvision.datasets | |
import torchvision.transforms | |
class WGanGpLoss(nn.Module): | |
def __init__(self, critic, gp_lambda=10, align=False): | |
super().__init__() |
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
paste -d '#' a.* b.* | shuf | awk -F '#' '{print $1 >"a-shuf.txt"; print $2 >"b-shuf.txt"}' |
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
package players; | |
import game.AbstractPlayer; | |
import game.BoardSquare; | |
import game.Move; | |
import java.util.List; | |
public class GreedyPlayer extends AbstractPlayer { | |
public GreedyPlayer(int depth) { |
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
package com.bandbaz.ref; | |
public class Either<L, R> { | |
public static <U, V> Either<U, V> left(U value) { | |
return new Either<>(value, null); | |
} | |
public static <U, V> Either<U, V> right(V value) { | |
return new Either<>(null, value); | |
} |
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 java.util.concurrent.*; | |
// poor-mans-promise | |
public class Promise<T> { | |
private static ExecutorService executor = Executors.newCachedThreadPool(); | |
private volatile boolean isFull; | |
public static <T> Promise<T> error(RuntimeException e) { | |
ArrayBlockingQueue<PromiseResult<T>> queue = new ArrayBlockingQueue<>(1); | |
queue.add(Promise.<T>promiseError(e)); |
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
package dictionary; | |
import com.google.common.base.Optional; | |
import java.util.HashSet; | |
import java.util.Set; | |
public class TranslatorValidator implements WordTranslator { | |
private final WordTranslator wordTranslator; | |
private final Set<String> validWords; |
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 numpy | |
def nextPower(a, x): | |
y = a.dot(x) | |
return y / numpy.linalg.norm(y, ord=numpy.inf) | |
def findEigVal(a, v): | |
return numpy.linalg.norm(a.dot(v), ord=numpy.inf) | |
def findLargestEigVal(a, initialGuess): |
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 numpy as np | |
import math | |
r = np.random.randint(0, 30, (3, 3)).astype('d') | |
def spectral_radius(m): | |
return max(abs(y) for y in np.linalg.eigvals(m)) | |
def matrix_norm2(m): | |
return math.sqrt(spectral_radius(m.dot(m.T))) |