repo stringlengths 1 99 | file stringlengths 13 215 | code stringlengths 12 59.2M | file_length int64 12 59.2M | avg_line_length float64 3.82 1.48M | max_line_length int64 12 2.51M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
GRETEL | GRETEL-main/src/explainer/meg/environments/tox21_env.py |
from src.explainer.meg.environments.molecule_env import Molecule
import torch
from torch.nn import functional as F
from src.explainer.meg.utils.similarity import get_similarity
from src.explainer.meg.utils.molecules import mol_from_smiles, mol_to_tox21_pyg
class CF_Tox21(Molecule):
def __init__(
sel... | 2,182 | 35.383333 | 89 | py |
GRETEL | GRETEL-main/src/dataset/dataset_base.py | from typing_extensions import Self
from sqlalchemy import false
from src.dataset.data_instance_base import DataInstance
from abc import ABC, abstractmethod
from typing import Dict, List
import os
import ast
import jsonpickle
import networkx as nx
from sklearn.model_selection import KFold
import torch as th
import dg... | 13,331 | 38.678571 | 111 | py |
GRETEL | GRETEL-main/src/dataset/dataset_node.py | import os
import pickle
from ast import List
import jsonpickle
import networkx as nx
import numpy as np
import torch
from sqlalchemy import true
from src.dataset.data_instance_node import NodeDataInstance
from src.dataset.dataset_base import Dataset
class NodeDataset(Dataset):
def __init__(self, id, config_dic... | 4,057 | 34.911504 | 102 | py |
GRETEL | GRETEL-main/src/oracle/oracle_node_syn_pt.py | import math
import os
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from src.oracle.oracle_node_pt import NodeOracle
from src.dataset.data_instance_node import NodeDataInstance
from src.dataset.dataset_node import NodeDataset
from src.oracle.oracle_base import Oracle
fr... | 6,136 | 36.650307 | 119 | py |
GRETEL | GRETEL-main/src/oracle/oracle_gcn_tf.py | import numpy as np
from sqlalchemy import false
import tensorflow as tf
import selfies as sf
import warnings
from rdkit import Chem
from rdkit.Chem.Draw import rdDepictor
from rdkit.Chem.Draw import IPythonConsole
import os
from src.oracle.oracle_base import Oracle
from src.dataset.data_instance_base import DataInstan... | 6,788 | 32.608911 | 100 | py |
GRETEL | GRETEL-main/src/oracle/oracle_node_pt.py | import math
import os
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from src.dataset.data_instance_node import NodeDataInstance
from src.dataset.dataset_node import NodeDataset
from src.oracle.oracle_base import Oracle
from src.utils import accuracy, normalize_adj
from ... | 2,242 | 27.75641 | 99 | py |
GRETEL | GRETEL-main/src/oracle/oracle_cf2.py | import os
import networkx as nx
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from dgl import from_networkx, mean_nodes
from dgl.nn.pytorch import GraphConv
from dgl.data import DGLDataset
from torch.utils.data.sampler import SubsetRandomSampler
from dgl.dataloading import Graph... | 7,257 | 37.606383 | 87 | py |
GRETEL | GRETEL-main/src/utils/cfgnnexplainer/utils.py | import os
import errno
import torch
import numpy as np
import pandas as pd
from torch_geometric.utils import k_hop_subgraph, dense_to_sparse, to_dense_adj, subgraph
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
els... | 3,087 | 27.330275 | 121 | py |
GRETEL | GRETEL-main/experimental/cfgnnexplainer/import-cf-gnnexplainer-dataset.py | import argparse
import pickle
import torch
from dgl.data.utils import load_graphs
from experimental.cfgnnexplainer.src.gcn import GCNSynthetic
from src.dataset.dataset_syn import NodeDataset, SynDataset
from oracle.oracle_node import NodeOracle
parser = argparse.ArgumentParser()
parser.add_argument('--dataset', defa... | 2,107 | 38.037037 | 110 | py |
GRETEL | GRETEL-main/experimental/cfgnnexplainer/baselines/src_baseline/baseline_ego.py | from __future__ import division
from __future__ import print_function
import sys
sys.path.append('../../')
import argparse
import pickle
import numpy as np
import time
import torch
import torch.nn.functional as F
import torch_geometric.utils as g_utils
from src.gcn import GCNSynthetic
from src.utils.utils import norma... | 4,902 | 36.427481 | 148 | py |
GRETEL | GRETEL-main/experimental/cfgnnexplainer/baselines/src_baseline/testing.py | import os.path as osp
import torch
import torch.nn.functional as F
import matplotlib.pyplot as plt
from torch_geometric.datasets import Planetoid
import torch_geometric.transforms as T
from torch_geometric.nn import GCNConv, GNNExplainer
dataset = 'Cora'
path = osp.join(osp.dirname(osp.realpath(__file__)), '..', 'dat... | 1,488 | 30.680851 | 79 | py |
GRETEL | GRETEL-main/experimental/cfgnnexplainer/baselines/src_baseline/baseline_random.py | from __future__ import division
from __future__ import print_function
import sys
sys.path.append('../../')
import argparse
import pickle
import numpy as np
import time
import torch
import torch.nn.functional as F
from src.gcn import GCNSynthetic
from src.utils.utils import normalize_adj, get_neighbourhood, safe_open, ... | 5,085 | 39.365079 | 148 | py |
GRETEL | GRETEL-main/experimental/cfgnnexplainer/baselines/src_baseline/gnnexplainer.py | # from https://pytorch-geometric.readthedocs.io/en/latest/_modules/torch_geometric/nn/models/gnn_explainer.html#GNNExplainer
from copy import copy
from math import sqrt
from typing import Optional
import torch
from tqdm import tqdm
import matplotlib.pyplot as plt
import networkx as nx
from torch_geometric.nn import ... | 10,113 | 36.459259 | 124 | py |
GRETEL | GRETEL-main/experimental/cfgnnexplainer/baselines/src_baseline/baseline_gnnexplainer.py | from __future__ import division
from __future__ import print_function
import sys
sys.path.append('../../')
import argparse
import pickle
import numpy as np
import time
import torch
import torch.nn.functional as F
import torch.optim as optim
from torch_geometric.utils import accuracy
from torch.nn.utils import clip_grad... | 5,886 | 36.980645 | 148 | py |
GRETEL | GRETEL-main/experimental/cfgnnexplainer/src/evaluate.py | from __future__ import division
from __future__ import print_function
import sys
sys.path.append('../../')
import json
import argparse
import numpy as np
import os
import pandas as pd
import pickle
import torch
from torch_geometric.utils import dense_to_sparse
from gcn import GCNSynthetic
from utils.utils import normal... | 4,488 | 35.201613 | 152 | py |
GRETEL | GRETEL-main/experimental/cfgnnexplainer/src/gcn.py | # Based on https://github.com/tkipf/pygcn/blob/master/pygcn/
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.parameter import Parameter
from torch_geometric.nn import GCNConv
class GraphConvolution(nn.Module):
"""
Simple GCN layer, similar to https://arxiv.org/abs... | 2,287 | 31.225352 | 77 | py |
GRETEL | GRETEL-main/experimental/cfgnnexplainer/src/main_explain.py | from __future__ import division
from __future__ import print_function
import sys
sys.path.append('..')
import argparse
import pickle
import numpy as np
import time
import torch
from gcn import GCNSynthetic
from cf_explanation.cf_explainer import CFExplainer
from utils.utils import normalize_adj, get_neighbourhood, safe... | 5,038 | 36.604478 | 158 | py |
GRETEL | GRETEL-main/experimental/cfgnnexplainer/src/train.py | # Based on https://github.com/tkipf/pygcn/blob/master/pygcn/train.py
from __future__ import division
from __future__ import print_function
import sys
sys.path.append('..')
import argparse
import pickle
import numpy as np
import time
import torch
import torch.optim as optim
import torch.nn.functional as F
from torch.nn... | 3,913 | 33.333333 | 110 | py |
GRETEL | GRETEL-main/experimental/cfgnnexplainer/src/cf_explanation/gcn_perturb.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.parameter import Parameter
from utils.utils import get_degree_matrix, normalize_adj, create_symm_matrix_from_vec, create_vec_from_symm_matrix
from gcn import GraphConvolution, GCNSynthetic
class GraphConvolutionPerturb(nn.Modu... | 5,830 | 34.773006 | 134 | py |
GRETEL | GRETEL-main/experimental/cfgnnexplainer/src/cf_explanation/cf_explainer.py | # Based on https://github.com/RexYing/gnn-model-explainer/blob/master/explainer/explain.py
import math
import time
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import torch.optim as optim
from torch.nn.utils import clip_grad_norm
from utils.utils import get_degree_matrix
from .... | 4,909 | 34.57971 | 128 | py |
GRETEL | GRETEL-main/experimental/cfgnnexplainer/src/utils/utils.py | import os
import errno
import torch
import numpy as np
import pandas as pd
from torch_geometric.utils import k_hop_subgraph, dense_to_sparse, to_dense_adj, subgraph
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
els... | 2,737 | 31.211765 | 121 | py |
DAPS | DAPS-master/train_da.py | import argparse
import datetime
import os.path as osp
import time
import torch
import torch.utils.data
from torch.utils.data.distributed import DistributedSampler
import torch.distributed as dist
from apex import amp
from apex.parallel import convert_syncbn_model
from apex.parallel import DistributedDataParallel as D... | 4,780 | 32.433566 | 105 | py |
DAPS | DAPS-master/engine.py | import math
import sys
import os
from copy import deepcopy
from PIL import Image
import torch
from torch.nn.utils import clip_grad_norm_
from tqdm import tqdm
from apex import amp
from eval_func import eval_detection, eval_search_cuhk, eval_search_prw, _compute_iou
from utils.utils import MetricLogger, SmoothedValue, ... | 10,056 | 39.067729 | 142 | py |
DAPS | DAPS-master/train.py | import argparse
import datetime
import os.path as osp
import time
import torch
import torch.utils.data
from torch.utils.data.distributed import DistributedSampler
import torch.distributed as dist
from spcl.models.dsbn import convert_dsbn
from apex import amp
from apex.parallel import convert_syncbn_model
from datase... | 4,938 | 32.371622 | 102 | py |
DAPS | DAPS-master/train_da_dy_cluster.py | import argparse
import datetime
import os.path as osp
import time
import torch
import torch.utils.data
import torch.nn as nn
import numpy as np
from datasets import build_test_loader, build_train_loader_da, build_dataset,build_train_loader_da_dy_cluster,build_cluster_loader
from utils.transforms import build_transform... | 16,022 | 49.22884 | 240 | py |
DAPS | DAPS-master/models/rpn_da.py | from copy import deepcopy
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn import init
from torchvision.models.detection.rpn import AnchorGenerator, RegionProposalNetwork, RPNHead
from torchvision.ops import boxes as box_ops
class RegionProposalNetworkDA(RegionProposalNetwork):
# d... | 5,071 | 48.72549 | 137 | py |
DAPS | DAPS-master/models/da_loss.py | import torch
from torch import nn
from torch.nn import functional as F
def consistency_loss(img_feas, ins_fea, ins_labels, size_average=True):
"""
Consistency regularization as stated in the paper
`Domain Adaptive Faster R-CNN for Object Detection in the Wild`
L_cst = \sum_{i,j}||\frac{1}{|I|}\sum_{u,v... | 4,088 | 39.485149 | 133 | py |
DAPS | DAPS-master/models/resnet.py | from collections import OrderedDict
import torch.nn.functional as F
import torchvision
import torch
from torch import nn
from spcl.models.dsbn import DSBN2d, DSBN1d
class Backbone(nn.Sequential):
def __init__(self, resnet):
super(Backbone, self).__init__(
OrderedDict(
[
... | 3,619 | 35.565657 | 88 | py |
DAPS | DAPS-master/models/roi_head_da.py | from copy import deepcopy
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn import init
from torchvision.models.detection.roi_heads import RoIHeads
from torchvision.ops import boxes as box_ops
from models.oim import OIMLoss
from apex import amp
class SeqRoIHeadsDa(RoIHeads):
def __... | 21,486 | 39.313321 | 165 | py |
DAPS | DAPS-master/models/da_head.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import torch
import torch.nn.functional as F
from torch import nn
from models.da_loss import DALossComputation
class _GradientScalarLayer(torch.autograd.Function):
@staticmethod
def forward(ctx, input, weight):
ctx.weight = weigh... | 7,467 | 38.513228 | 150 | py |
DAPS | DAPS-master/models/oim.py | import torch
import torch.nn.functional as F
from torch import autograd, nn
# from utils.distributed import tensor_gather
class OIM(autograd.Function):
@staticmethod
def forward(ctx, inputs, targets, lut, cq, header, momentum):
ctx.save_for_backward(inputs, targets, lut, cq, header, momentum)
... | 2,636 | 35.123288 | 97 | py |
DAPS | DAPS-master/models/seqnet_da.py | from copy import deepcopy
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn import init
from torchvision.models.detection.faster_rcnn import FastRCNNPredictor
from torchvision.models.detection.roi_heads import RoIHeads
from torchvision.models.detection.rpn import AnchorGenerator, RegionP... | 25,217 | 40.820896 | 170 | py |
DAPS | DAPS-master/models/seqnet.py | from copy import deepcopy
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn import init
from torchvision.models.detection.faster_rcnn import FastRCNNPredictor
from torchvision.models.detection.roi_heads import RoIHeads
from torchvision.models.detection.rpn import AnchorGenerator, RegionP... | 22,980 | 39.317544 | 122 | py |
DAPS | DAPS-master/datasets/base.py | import torch
from PIL import Image
class BaseDataset:
"""
Base class of person search dataset.
"""
def __init__(self, root, transforms, split, is_source=True, build_tiny=False):
self.root = root
self.transforms = transforms
self.split = split
if build_tiny:
... | 1,948 | 36.480769 | 116 | py |
DAPS | DAPS-master/datasets/build.py | import torch
from utils.transforms import build_transforms
from utils.utils import create_small_table
from torch.utils.data.distributed import DistributedSampler
import torch.distributed as dist
from .cuhk_sysu import CUHKSYSU
from .prw import PRW
def print_statistics(dataset):
"""
Print dataset statistics.
... | 6,427 | 36.372093 | 109 | py |
DAPS | DAPS-master/utils/utils.py | import datetime
import errno
import json
import os
import os.path as osp
import pickle
import random
import time
from collections import defaultdict, deque
import numpy as np
import torch
import torch.distributed as dist
from tabulate import tabulate
# -------------------------------------------------------- #
# ... | 14,884 | 30.010417 | 99 | py |
DAPS | DAPS-master/utils/transforms.py | import random
from torchvision.transforms import functional as F
class Compose:
def __init__(self, transforms):
self.transforms = transforms
def __call__(self, image, target):
for t in self.transforms:
image, target = t(image, target)
return image, target
class RandomHori... | 1,048 | 24.585366 | 53 | py |
DAPS | DAPS-master/spcl/evaluators.py | from __future__ import print_function, absolute_import
import time
import collections
from collections import OrderedDict
import numpy as np
import torch
import random
from eval_func import _compute_iou
from .evaluation_metrics import cmc, mean_ap
from .utils.meters import AverageMeter
from .utils.rerank import re_rank... | 12,686 | 43.989362 | 168 | py |
DAPS | DAPS-master/spcl/trainers.py | from __future__ import print_function, absolute_import
import time
import numpy as np
import collections
import torch
import torch.nn as nn
from torch.nn import functional as F
from .utils.meters import AverageMeter
class SpCLTrainer_UDA(object):
def __init__(self, encoder, memory, source_classes):
supe... | 4,925 | 32.283784 | 123 | py |
DAPS | DAPS-master/spcl/models/resnet.py | from __future__ import absolute_import
from torch import nn
from torch.nn import functional as F
from torch.nn import init
import torchvision
import torch
__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101',
'resnet152']
class ResNet(nn.Module):
__factory = {
18: torchvision... | 4,344 | 29.815603 | 92 | py |
DAPS | DAPS-master/spcl/models/hm.py | import numpy as np
import math
import sys
import torch
import torch.nn.functional as F
from torch.nn import init
from torch import nn, autograd
from collections import OrderedDict
class HM(autograd.Function):
@staticmethod
def forward(ctx, inputs, indexes, features, momentum):
ctx.features = features
... | 3,310 | 35.384615 | 98 | py |
DAPS | DAPS-master/spcl/models/resnet_ibn.py | from __future__ import absolute_import
from torch import nn
from torch.nn import functional as F
from torch.nn import init
import torchvision
import torch
from .resnet_ibn_a import resnet50_ibn_a, resnet101_ibn_a
__all__ = ['ResNetIBN', 'resnet_ibn50a', 'resnet_ibn101a']
class ResNetIBN(nn.Module):
__factory ... | 3,911 | 30.296 | 92 | py |
DAPS | DAPS-master/spcl/models/dsbn.py | import torch
import torch.nn as nn
# Domain-specific BatchNorm
class DSBN2d(nn.Module):
def __init__(self, planes):
super(DSBN2d, self).__init__()
self.num_features = planes
self.BN_S = nn.BatchNorm2d(planes)
self.BN_T = nn.BatchNorm2d(planes)
def forward(self, x, is_source):
... | 2,408 | 32.929577 | 68 | py |
DAPS | DAPS-master/spcl/models/resnet_ibn_a.py | import torch
import torch.nn as nn
import math
import torch.utils.model_zoo as model_zoo
__all__ = ['ResNet', 'resnet50_ibn_a', 'resnet101_ibn_a']
model_urls = {
'ibn_resnet50a': './logs/pretrained/resnet50_ibn_a.pth.tar',
'ibn_resnet101a': './logs/pretrained/resnet101_ibn_a.pth.tar',
}
def conv3x3(in_pla... | 6,588 | 30.227488 | 109 | py |
DAPS | DAPS-master/spcl/utils/faiss_rerank.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
CVPR2017 paper:Zhong Z, Zheng L, Cao D, et al. Re-ranking Person Re-identification with k-reciprocal Encoding[J]. 2017.
url:http://openaccess.thecvf.com/content_cvpr_2017/papers/Zhong_Re-Ranking_Person_Re-Identification_CVPR_2017_paper.pdf
Matlab version: https://githu... | 4,950 | 38.608 | 126 | py |
DAPS | DAPS-master/spcl/utils/faiss_utils.py | import os
import numpy as np
import faiss
import torch
def swig_ptr_from_FloatTensor(x):
assert x.is_contiguous()
assert x.dtype == torch.float32
return faiss.cast_integer_to_float_ptr(
x.storage().data_ptr() + x.storage_offset() * 4)
def swig_ptr_from_LongTensor(x):
assert x.is_contiguous()
... | 3,182 | 28.201835 | 92 | py |
DAPS | DAPS-master/spcl/utils/__init__.py | from __future__ import absolute_import
import torch
def to_numpy(tensor):
if torch.is_tensor(tensor):
return tensor.cpu().numpy()
elif type(tensor).__module__ != 'numpy':
raise ValueError("Cannot convert {} to numpy array"
.format(type(tensor)))
return tensor
de... | 594 | 26.045455 | 60 | py |
DAPS | DAPS-master/spcl/utils/serialization.py | from __future__ import print_function, absolute_import
import json
import os.path as osp
import shutil
import torch
from torch.nn import Parameter
from .osutils import mkdir_if_missing
def read_json(fpath):
with open(fpath, 'r') as f:
obj = json.load(f)
return obj
def write_json(obj, fpath):
m... | 1,758 | 27.370968 | 78 | py |
DAPS | DAPS-master/spcl/evaluation_metrics/classification.py | from __future__ import absolute_import
import torch
from ..utils import to_torch
def accuracy(output, target, topk=(1,)):
with torch.no_grad():
output, target = to_torch(output), to_torch(target)
maxk = max(topk)
batch_size = target.size(0)
_, pred = output.topk(maxk, 1, True, Tr... | 604 | 26.5 | 77 | py |
NUSD | NUSD-main/main_disent_fscore_grad.py | import logging
import logging.handlers
import argparse
import os
import time
from data_loader import organiser as organiser
import shutil
import sys
import torch
import random
import numpy as np
import pandas as pd
import utilities.utilities_main as util
import socket
from distutils.dir_util import copy_tree
import skl... | 82,254 | 41.953003 | 176 | py |
NUSD | NUSD-main/utilities/model_utilities.py | import torch
import torch.nn as nn
def create_tensor_data(x, cuda):
"""
Converts the data from numpy arrays to torch tensors
Inputs
x: The input data
cuda: Bool - Set to true if using the GPU
Output
x: Data converted to a tensor
"""
if 'float' in str(x.dtype):
... | 2,819 | 29 | 88 | py |
NUSD | NUSD-main/utilities/utilities_main.py | import os
import pickle
import numpy as np
import h5py
import pandas as pd
import argparse
import logging
import logging.handlers
import csv
import shutil
import torch
import random
from exp_run import config_process
def save_model(epoch_iter, model, optimizer, main_logger, model_dir, cuda):
"""
Saves the mod... | 21,780 | 33.627981 | 119 | py |
NUSD | NUSD-main/exp_run/ETDNN.py | # source: https://github.com/dong-8080/ETDNN
import torch
import torch.nn as nn
import torch.nn.functional as F
from pdb import set_trace as bp
class Conv1dReluBn(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=1, stride=1, padding=0, dilation=1, bias=False):
super().__init__()
... | 9,522 | 39.012605 | 120 | py |
NUSD | NUSD-main/exp_run/ETDNN_disent.py | # source: https://github.com/dong-8080/ETDNN
import torch
import torch.nn as nn
import torch.nn.functional as F
from pdb import set_trace as bp
class Conv1dReluBn(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=1, stride=1, padding=0, dilation=1, bias=False):
super().__init__()
... | 11,171 | 38.617021 | 120 | py |
NUSD | NUSD-main/exp_run/models_pytorch.py | import math
import torch
import torch.nn as nn
# from exp_run.gradient_reversal import GradientReversal
def init_layer(layer):
"""Initialize a Linear or Convolutional layer.
Ref: He, Kaiming, et al. "Delving deep into rectifiers: Surpassing
human-level performance on imagenet classification." Proceedings ... | 41,086 | 33.182196 | 111 | py |
cholla | cholla-main/docs/sphinx/source/conf.py | # Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If ex... | 2,564 | 29.535714 | 79 | py |
qlib | qlib-main/setup.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import os
import numpy
from setuptools import find_packages, setup, Extension
def read(rel_path: str) -> str:
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, rel_path), encoding="utf-8") as fp:
ret... | 6,226 | 30.933333 | 114 | py |
qlib | qlib-main/examples/run_all_model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import os
import sys
import fire
import time
import glob
import yaml
import shutil
import signal
import inspect
import tempfile
import functools
import statistics
import subprocess
from datetime import datetime
from pathlib import Path
from ope... | 16,427 | 39.764268 | 248 | py |
qlib | qlib-main/examples/benchmarks/TRA/src/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import os
import copy
import math
import json
import collections
import numpy as np
import pandas as pd
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
from tqdm import tqdm
from qlib.utils import... | 19,369 | 31.445561 | 104 | py |
qlib | qlib-main/examples/benchmarks/TRA/src/dataset.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import copy
import torch
import numpy as np
import pandas as pd
from qlib.data.dataset import DatasetH
device = "cuda" if torch.cuda.is_available() else "cpu"
def _to_tensor(x):
if not isinstance(x, torch.Tensor):
return torch.te... | 8,961 | 33.736434 | 104 | py |
qlib | qlib-main/examples/benchmarks/TFT/tft.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from pathlib import Path
from typing import Union
import numpy as np
import pandas as pd
import tensorflow.compat.v1 as tf
import data_formatters.base
import expt_settings.configs
import libs.hyperparam_opt
import libs.tft_model
import libs.utils... | 10,960 | 33.146417 | 116 | py |
qlib | qlib-main/examples/benchmarks/TFT/data_formatters/base.py | # coding=utf-8
# Copyright 2020 The Google Research Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicab... | 7,688 | 33.479821 | 115 | py |
qlib | qlib-main/examples/benchmarks/TFT/libs/tft_model.py | # coding=utf-8
# Copyright 2020 The Google Research Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicab... | 47,187 | 35.923318 | 120 | py |
qlib | qlib-main/qlib/tests/config.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
CSI300_MARKET = "csi300"
CSI100_MARKET = "csi100"
CSI300_BENCH = "SH000300"
DATASET_ALPHA158_CLASS = "Alpha158"
DATASET_ALPHA360_CLASS = "Alpha360"
###################################
# config
###################################
GBDT_MODEL... | 4,834 | 27.779762 | 108 | py |
qlib | qlib-main/qlib/data/dataset/__init__.py | from ...utils.serial import Serializable
from typing import Callable, Union, List, Tuple, Dict, Text, Optional
from ...utils import init_instance_by_config, np_ffill, time_to_slc_point
from ...log import get_module_logger
from .handler import DataHandler, DataHandlerLP
from copy import copy, deepcopy
from inspect impor... | 27,197 | 36.618257 | 200 | py |
qlib | qlib-main/qlib/model/utils.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from torch.utils.data import Dataset
class ConcatDataset(Dataset):
def __init__(self, *datasets):
self.datasets = datasets
def __getitem__(self, i):
return tuple(d[i] for d in self.datasets)
def __len__(self):
... | 579 | 20.481481 | 49 | py |
qlib | qlib-main/qlib/workflow/online/update.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
Updater is a module to update artifacts such as predictions when the stock data is updating.
"""
from abc import ABCMeta, abstractmethod
from typing import Optional
import pandas as pd
from qlib import get_module_logger
from qlib.data import... | 10,586 | 34.408027 | 248 | py |
qlib | qlib-main/qlib/contrib/torch.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
This module is not a necessary part of Qlib.
They are just some tools for convenience
It is should not imported into the core part of qlib
"""
import torch
import numpy as np
import pandas as pd
def data_to_tensor(data, device="c... | 1,074 | 32.59375 | 76 | py |
qlib | qlib-main/qlib/contrib/meta/data_selection/utils.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import numpy as np
import torch
from torch import nn
from qlib.constant import EPS
from qlib.log import get_module_logger
class ICLoss(nn.Module):
def forward(self, pred, y, idx, skip_size=50):
"""forward.
FIXME:
- ... | 3,962 | 33.763158 | 99 | py |
qlib | qlib-main/qlib/contrib/meta/data_selection/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import pandas as pd
import numpy as np
import torch
from torch import nn
from torch import optim
from tqdm.auto import tqdm
import copy
from typing import Union, List
from ....model.meta.dataset import MetaTaskDataset
from ....model.meta.model i... | 6,431 | 33.767568 | 124 | py |
qlib | qlib-main/qlib/contrib/meta/data_selection/dataset.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import pandas as pd
import numpy as np
from copy import deepcopy
from joblib import Parallel, delayed # pylint: disable=E0401
from typing import Dict, List, Union, Text, Tuple
from qlib.data.dataset.utils import init_task_handler
from qlib.data.d... | 17,894 | 44.534351 | 132 | py |
qlib | qlib-main/qlib/contrib/meta/data_selection/net.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import numpy as np
import torch
from torch import nn
from .utils import preds_to_weight_with_clamp, SingleMetaBase
class TimeWeightMeta(SingleMetaBase):
def __init__(self, hist_step_n, clip_weight=None, clip_method="clamp"):
# clip... | 3,024 | 39.333333 | 108 | py |
qlib | qlib-main/qlib/contrib/data/dataset.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import copy
import torch
import warnings
import numpy as np
import pandas as pd
from qlib.data.dataset import DatasetH
device = "cuda" if torch.cuda.is_available() else "cpu"
def _to_tensor(x):
if not isinstance(x, torch.Tensor):
... | 13,594 | 37.403955 | 115 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_localformer_ts.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
import copy
import math
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
import torch.nn as n... | 10,063 | 32.214521 | 113 | py |
qlib | qlib-main/qlib/contrib/model/xgboost.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import numpy as np
import pandas as pd
import xgboost as xgb
from typing import Text, Union
from ...model.base import Model
from ...data.dataset import DatasetH
from ...data.dataset.handler import DataHandlerLP
from ...model.interpret.base import... | 3,083 | 34.860465 | 105 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_sfm.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
from typing import Text, Union
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
im... | 15,886 | 32.097917 | 112 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_tra.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import io
import os
import copy
import math
import json
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
try:
from torch.ut... | 34,221 | 35.640257 | 120 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_gru_ts.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
import torch.nn as nn
import tor... | 9,854 | 29.796875 | 106 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_adarnn.py | # Copyright (c) Microsoft Corporation.
import os
from torch.utils.data import Dataset, DataLoader
import copy
from typing import Text, Union
import numpy as np
import pandas as pd
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.autograd import Function
from ql... | 27,939 | 34.322377 | 116 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_alstm_ts.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
from typing import Text, Union
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
i... | 11,560 | 31.84375 | 106 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_krnn.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
from typing import Text, Union
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
i... | 15,717 | 29.699219 | 118 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_gats.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
from typing import Text, Union
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
im... | 12,705 | 32.002597 | 110 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_alstm.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
from typing import Text, Union
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
i... | 11,332 | 31.849275 | 112 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_lstm_ts.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
import torch.nn as nn
import tor... | 9,646 | 29.625397 | 106 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_nn.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
from collections import defaultdict
import os
import gc
import numpy as np
import pandas as pd
from typing import Callable, Optional, Text, Union
from sklearn.metrics import ... | 17,140 | 37.261161 | 164 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_tcn.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
from typing import Text, Union
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
i... | 9,581 | 29.810289 | 112 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_add.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import copy
import math
from typing import Text, Union
import numpy as np
import pandas as pd
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch... | 21,515 | 34.979933 | 117 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_transformer_ts.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
import copy
import math
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
import torch.nn as n... | 8,903 | 32.6 | 119 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_sandwich.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
from typing import Text, Union
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
i... | 11,661 | 29.528796 | 112 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_gats_ts.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
import torch.nn as nn
import torc... | 13,141 | 32.52551 | 118 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_lstm.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
from typing import Text, Union
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
i... | 9,410 | 29.654723 | 112 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_transformer.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
from typing import Text, Union
import copy
import math
from ...utils import get_or_create_path
from ...log import get_module_logger
im... | 9,578 | 32.493007 | 119 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_igmtf.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
from typing import Text, Union
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
i... | 15,843 | 34.765237 | 115 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_tabnet.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
from typing import Text, Union
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
imp... | 22,855 | 34.490683 | 141 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_localformer.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
from typing import Text, Union
import copy
import math
from ...utils import get_or_create_path
from ...log import get_module_logger
im... | 10,714 | 32.173375 | 119 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_gru.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
from typing import Text, Union
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
i... | 9,645 | 29.622222 | 112 | py |
qlib | qlib-main/qlib/contrib/model/__init__.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
try:
from .catboost_model import CatBoostModel
except ModuleNotFoundError:
CatBoostModel = None
print("ModuleNotFoundError. CatBoostModel are skipped. (optional: maybe installing CatBoostModel can fix it.)")
try:
from .double_ensem... | 1,711 | 37.909091 | 121 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_utils.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import torch.nn as nn
def count_parameters(models_or_parameters, unit="m"):
"""
This function is to obtain the storage size unit of a (or multiple) models.
Parameters
----------
models_or_parameters : PyTorch model(s) or a ... | 1,197 | 30.526316 | 79 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_tcn_ts.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import numpy as np
import pandas as pd
import copy
from ...utils import get_or_create_path
from ...log import get_module_logger
import torch
import torch.nn as nn
import tor... | 9,163 | 29.751678 | 106 | py |
qlib | qlib-main/qlib/contrib/model/pytorch_hist.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import division
from __future__ import print_function
import os
import numpy as np
import pandas as pd
from typing import Text, Union
import urllib.request
import copy
from ...utils import get_or_create_path
from ...log import g... | 18,668 | 36.263473 | 116 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.