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
#include <limits> | |
namespace Detail | |
{ | |
double constexpr sqrtNewtonRaphson(double x, double curr, double prev) | |
{ | |
return curr == prev | |
? curr | |
: sqrtNewtonRaphson(x, 0.5 * (curr + x / curr), curr); | |
} |
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 | |
import torch.nn.functional as F | |
import copy | |
import math | |
def ipw_crossentropy(weights, scores, label): | |
propensities = torch.reciprocal(weights) | |
return ( | |
-label * (scores + torch.log(propensities)) |
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 | |
class BatchIter: | |
""" | |
tensors: feature tensors (each with shape: num_instances x *) | |
""" | |
def __init__(self, *tensors, batch_size, shuffle=True): | |
self.tensors = tensors |