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 |
|---|---|---|---|---|---|---|
T2NER | T2NER-master/t2ner/data/utils.py | # -*- coding: utf-8 -*-
import os
import logging
import torch
import torch.nn as nn
from abc import ABC, abstractmethod
from transformers import AutoTokenizer
logger = logging.getLogger(__name__)
IGNORE_INDEX = torch.nn.CrossEntropyLoss().ignore_index
class TokenizerFeatures(ABC):
def __init__(self, **kw... | 3,840 | 29.484127 | 88 | py |
T2NER | T2NER-master/t2ner/losses/focal.py | # -*- coding: utf-8 -*-
# Modified from: https://raw.githubusercontent.com/kaidic/LDAM-DRW/master/losses.py
import torch
import torch.nn as nn
import torch.nn.functional as F
from ..data import IGNORE_INDEX
class MaskedSeqFocalLoss(nn.Module):
def __init__(self, num_labels, weight=None, gamma=2.):
... | 1,564 | 28.528302 | 87 | py |
T2NER | T2NER-master/t2ner/losses/cross_entropy.py | # -*- coding: utf-8 -*-
import torch
import torch.nn as nn
import torch.nn.functional as F
from ..data import IGNORE_INDEX
class MaskedSeqCrossEntropyLoss(nn.Module):
def __init__(self, num_labels, weight=None):
super().__init__()
self.num_labels = num_labels
self.weight = weight
... | 1,125 | 26.463415 | 60 | py |
T2NER | T2NER-master/t2ner/losses/causal_language_modeling.py | # -*- coding: utf-8 -*-
import torch
import torch.nn as nn
class CausalLanguageModelingLoss(nn.Module):
def __init__(self, num_labels):
super().__init__()
self.num_labels = num_labels
self.cross_entropy = nn.CrossEntropyLoss()
def forward(self, logits, labels):
# lab... | 656 | 28.863636 | 84 | py |
T2NER | T2NER-master/t2ner/losses/ldam.py | # -*- coding: utf-8 -*-
# Modified from: https://raw.githubusercontent.com/kaidic/LDAM-DRW/master/losses.py
import torch
import torch.nn as nn
import numpy as np
import torch.nn.functional as F
from ..data import IGNORE_INDEX
class MaskedSeqLDAMLoss(nn.Module):
def __init__(self, num_labels, cls_num_list,... | 2,205 | 34.015873 | 89 | py |
T2NER | T2NER-master/t2ner/trainers/semisupervised.py | # -*- coding: utf-8 -*-
import torch
from ..train import BaseTrainer
from ..data import SemiSupervisedData
class SSLTrainer(BaseTrainer):
def __init__(self, training_args, model_args, exp_args):
super().__init__(training_args, model_args, exp_args)
self.load_data()
def load_data(se... | 2,279 | 36.377049 | 94 | py |
T2NER | T2NER-master/t2ner/trainers/semisupervised_learning/entmin.py | # -*- coding: utf-8 -*-
import torch
import torch.nn as nn
from dataclasses import dataclass, field
from ...base import ArgumentsBase
from ...modules import MaskedSoftmax
from ..semisupervised import SSLTrainer
class EntMinTrainer(SSLTrainer):
def __init__(self, training_args, model_args, exp_args):
... | 3,869 | 33.553571 | 100 | py |
T2NER | T2NER-master/t2ner/trainers/unsup_adaptation/emd.py | # -*- coding: utf-8 -*-
import torch
import torch.autograd as autograd
from dataclasses import dataclass, field
from ...base import ArgumentsBase
from ...modules import WassersteinCritic, SeqWassersteinCritic
from ..adaptation import AdaptationTrainer
class EMDTrainer(AdaptationTrainer):
def __init__(self... | 10,566 | 35.437931 | 109 | py |
T2NER | T2NER-master/t2ner/trainers/unsup_adaptation/grl.py | # -*- coding: utf-8 -*-
import torch.nn as nn
from dataclasses import dataclass, field
from ...base import ArgumentsBase
from ...modules import BinaryAdvClassifier
from ..adaptation import AdaptationTrainer
class GRLTrainer(AdaptationTrainer):
def __init__(self, training_args, model_args, exp_args):
... | 5,072 | 33.277027 | 100 | py |
T2NER | T2NER-master/t2ner/trainers/unsup_adaptation/mcd.py | # -*- coding: utf-8 -*-
import torch
import torch.nn as nn
from dataclasses import dataclass, field
from ...base import ArgumentsBase
from ...modules import TokenClassifier, MaskedSoftmax
from ..adaptation import AdaptationTrainer
class MCDTrainer(AdaptationTrainer):
def __init__(self, training_args, mode... | 7,509 | 35.105769 | 100 | py |
T2NER | T2NER-master/t2ner/trainers/unsup_adaptation/mme.py | # -*- coding: utf-8 -*-
import torch
import torch.nn as nn
from dataclasses import dataclass, field
from ...base import ArgumentsBase
from ...modules import GRL, MaskedSoftmax
from ..adaptation import AdaptationTrainer
class MMETrainer(AdaptationTrainer):
def __init__(self, training_args, model_args, exp_... | 5,377 | 33.037975 | 100 | py |
T2NER | T2NER-master/t2ner/trainers/unsup_adaptation/keung.py | # -*- coding: utf-8 -*-
import torch.nn as nn
from dataclasses import dataclass, field
from ...base import ArgumentsBase
from ...modules import BinaryAdvClassifier
from ..adaptation import AdaptationTrainer
class KeungTrainer(AdaptationTrainer):
def __init__(self, training_args, model_args, exp_args):
... | 7,047 | 36.489362 | 100 | py |
pymarl_transformers | pymarl_transformers-main/src/main.py | import numpy as np
import os
import collections
from os.path import dirname, abspath, join
from copy import deepcopy
from sacred import Experiment, SETTINGS
from sacred.observers import FileStorageObserver
from sacred.utils import apply_backspaces_and_linefeeds
import sys
import torch as th
from utils.logging import ge... | 4,147 | 30.664122 | 172 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/mixers/n_transf_mixer.py | from turtle import forward
import torch as th
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from utils.th_utils import orthogonal_init_
from torch.nn import LayerNorm
from ..layer.transformer import Transformer
class TransformerMixer(nn.Module):
def __init__(self, args, abs=True):
... | 3,423 | 32.242718 | 92 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/mixers/qmix.py | import torch as th
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
class QMixer(nn.Module):
def __init__(self, args):
super(QMixer, self).__init__()
self.args = args
self.n_agents = args.n_agents
self.state_dim = int(np.prod(args.state_shape))
sel... | 3,422 | 39.270588 | 101 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/mixers/vdn.py | import torch as th
import torch.nn as nn
class VDNMixer(nn.Module):
def __init__(self):
super(VDNMixer, self).__init__()
def forward(self, agent_qs, batch, obs):
return th.sum(agent_qs, dim=2, keepdim=True) | 233 | 22.4 | 52 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/mixers/qmix_central_no_hyper.py | import torch as th
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
class QMixerCentralFF(nn.Module):
def __init__(self, args):
super(QMixerCentralFF, self).__init__()
self.args = args
self.n_agents = args.n_agents
self.state_dim = int(np.prod(args.state_s... | 1,558 | 31.479167 | 88 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/mixers/dmaq_general.py | # From https://github.com/wjh720/QPLEX/, added here for convenience.
import torch as th
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from .dmaq_si_weight import DMAQ_SI_Weight
class DMAQer(nn.Module):
def __init__(self, args):
super(DMAQer, self).__init__()
self.args =... | 3,024 | 35.011905 | 85 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/mixers/nmix.py | import torch as th
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from utils.th_utils import orthogonal_init_
from torch.nn import LayerNorm
class Mixer(nn.Module):
def __init__(self, args, abs=True):
super(Mixer, self).__init__()
self.args = args
self.n_agents = ... | 2,709 | 36.123288 | 103 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/mixers/qtran.py | import torch as th
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
class QTranBase(nn.Module):
def __init__(self, args):
super(QTranBase, self).__init__()
self.args = args
self.n_agents = args.n_agents
self.n_actions = args.n_actions
self.state_di... | 5,051 | 46.660377 | 161 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/mixers/qatten.py | import torch as th
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
class QattenMixer(nn.Module):
def __init__(self, args):
super(QattenMixer, self).__init__()
self.args = args
self.n_agents = args.n_agents
self.state_dim = int(np.prod(args.state_shape))
... | 4,203 | 41.04 | 132 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/mixers/dmaq_si_weight.py | # From https://github.com/wjh720/QPLEX/, added here for convenience.
import torch as th
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
class DMAQ_SI_Weight(nn.Module):
def __init__(self, args):
super(DMAQ_SI_Weight, self).__init__()
self.args = args
self.n_agents... | 4,774 | 57.231707 | 117 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/agents/conv_agent.py | import torch.nn as nn
import torch.nn.functional as F
class ConvAgent(nn.Module):
def __init__(self, input_shape, args):
super(ConvAgent, self).__init__()
self.args = args
self.hidden_dim = self.args.rnn_hidden_dim
self.conv1 = nn.Conv1d(input_shape, self.hidden_dim, 2)
se... | 1,056 | 33.096774 | 73 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/agents/noisy_agents.py | import torch.nn as nn
import torch.nn.functional as F
from utils.noisy_liner import NoisyLinear
from torch.nn import LayerNorm
class NoisyRNNAgent(nn.Module):
def __init__(self, input_shape, args):
super(NoisyRNNAgent, self).__init__()
self.args = args
self.fc1 = nn.Linear(input_shape, arg... | 1,231 | 34.2 | 86 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/agents/rnn_agent.py | import torch.nn as nn
import torch.nn.functional as F
class RNNAgent(nn.Module):
def __init__(self, input_shape, args):
super(RNNAgent, self).__init__()
self.args = args
self.fc1 = nn.Linear(input_shape, args.rnn_hidden_dim)
self.rnn = nn.GRUCell(args.rnn_hidden_dim, args.rnn_hidd... | 928 | 34.730769 | 77 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/agents/ff_agent.py | import torch as th
import torch.nn as nn
import torch.nn.functional as F
class FFAgent(nn.Module):
def __init__(self, input_shape, args):
super(FFAgent, self).__init__()
self.args = args
# Easiest to reuse rnn_hidden_dim variable
self.fc1 = nn.Linear(input_shape, args.rnn_hidden_di... | 840 | 32.64 | 71 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/agents/rnn_ppo_agent.py | import torch.nn as nn
import torch.nn.functional as F
class RNNPPOAgent(nn.Module):
def __init__(self, input_shape, args):
super(RNNPPOAgent, self).__init__()
self.args = args
self.fc1 = nn.Linear(input_shape, args.rnn_hidden_dim)
self.rnn = nn.GRUCell(args.rnn_hidden_dim, args.rnn... | 856 | 34.708333 | 71 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/agents/updet_smac.py | import torch.nn as nn
import torch.nn.functional as F
import torch as th
from ..layer.transformer import Transformer
class UpdetSmac(nn.Module):
def __init__(self, input_shape, args):
super(UpdetSmac, self).__init__()
self.args = args
self.n_agents = args.n_agents
self.n_entiti... | 2,197 | 25.481928 | 94 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/agents/n_rnn_agent.py | import torch.nn as nn
import torch.nn.functional as F
import torch as th
import numpy as np
import torch.nn.init as init
from utils.th_utils import orthogonal_init_
from torch.nn import LayerNorm
class NRNNAgent(nn.Module):
def __init__(self, input_shape, args):
super(NRNNAgent, self).__init__()
se... | 1,417 | 32.761905 | 71 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/agents/central_rnn_agent.py | import torch as th
import torch.nn as nn
import torch.nn.functional as F
class CentralRNNAgent(nn.Module):
def __init__(self, input_shape, args):
super(CentralRNNAgent, self).__init__()
self.args = args
self.fc1 = nn.Linear(input_shape, args.rnn_hidden_dim)
self.rnn = nn.GRUCell(ar... | 909 | 35.4 | 93 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/agents/n_transf_agent_smac.py | import torch.nn as nn
import torch.nn.functional as F
import torch as th
from ..layer.transformer import Transformer
class TransformerAgentSmac(nn.Module):
def __init__(self, input_shape, args):
super(TransformerAgentSmac, self).__init__()
self.args = args
self.n_agents = args.n_agents... | 2,083 | 26.064935 | 122 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/agents/mlp_agent.py | import torch.nn as nn
import torch.nn.functional as F
class MLPAgent(nn.Module):
def __init__(self, input_shape, args):
super(MLPAgent, self).__init__()
self.args = args
self.fc1 = nn.Linear(input_shape, args.rnn_hidden_dim)
self.fc2 = nn.Linear(args.rnn_hidden_dim, args.rnn_hidde... | 784 | 29.192308 | 83 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/agents/atten_rnn_agent.py | import torch.nn as nn
import torch.nn.functional as F
import torch as th
import numpy as np
import torch.nn.init as init
from modules.layer.self_atten import SelfAttention
class ATTRNNAgent(nn.Module):
def __init__(self, input_shape, args):
super(ATTRNNAgent, self).__init__()
self.args = args
... | 1,539 | 34 | 89 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/agents/n_transf_agent.py | import torch.nn as nn
import torch.nn.functional as F
import torch as th
from ..layer.transformer import Transformer
class TransformerAgent(nn.Module):
def __init__(self, input_shape, args):
super(TransformerAgent, self).__init__()
self.args = args
self.n_agents = args.n_agents
... | 1,901 | 25.054795 | 89 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/layer/self_atten.py | import torch
import torch.nn as nn
import torch.nn.functional as F
class SelfAttention(nn.Module):
def __init__(self, input_size, heads, embed_size):
super().__init__()
self.input_size = input_size
self.heads = heads
self.emb_size = embed_size
self.tokeys = nn.Linear(self.i... | 1,598 | 36.186047 | 93 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/layer/transformer.py | import torch.nn as nn
import torch.nn.functional as F
import torch
def mask_(matrices, maskval=0.0, mask_diagonal=True):
b, h, w = matrices.size()
indices = torch.triu_indices(h, w, offset=0 if mask_diagonal else 1)
matrices[:, indices[0], indices[1]] = maskval
class MultiHeadAttention(nn.Module):
de... | 3,921 | 25.863014 | 90 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/critics/centralV.py | import torch as th
import torch.nn as nn
import torch.nn.functional as F
class CentralVCritic(nn.Module):
def __init__(self, scheme, args):
super(CentralVCritic, self).__init__()
self.args = args
self.n_actions = args.n_actions
self.n_agents = args.n_agents
input_shape = ... | 2,524 | 36.686567 | 127 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/critics/ac.py | import torch as th
import torch.nn as nn
import torch.nn.functional as F
class ACCritic(nn.Module):
def __init__(self, scheme, args):
super(ACCritic, self).__init__()
self.args = args
self.n_actions = args.n_actions
self.n_agents = args.n_agents
input_shape = self._get_in... | 1,442 | 29.0625 | 117 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/critics/offpg.py | import torch as th
import torch.nn as nn
import torch.nn.functional as F
class OffPGCritic(nn.Module):
def __init__(self, scheme, args):
super(OffPGCritic, self).__init__()
self.args = args
self.n_actions = args.n_actions
self.n_agents = args.n_agents
input_shape = self._... | 2,388 | 35.19697 | 117 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/critics/fmac_critic.py | from numpy.core.numeric import True_
import torch as th
import torch.nn as nn
import torch.nn.functional as F
from modules.layer.self_atten import SelfAttention
class FMACCritic(nn.Module):
def __init__(self, scheme, args):
super(FMACCritic, self).__init__()
self.args = args
self.n_actions... | 2,105 | 36.607143 | 91 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/critics/coma.py | import torch as th
import torch.nn as nn
import torch.nn.functional as F
class COMACritic(nn.Module):
def __init__(self, scheme, args):
super(COMACritic, self).__init__()
self.args = args
self.n_actions = args.n_actions
self.n_agents = args.n_agents
input_shape = self._ge... | 2,701 | 37.6 | 127 | py |
pymarl_transformers | pymarl_transformers-main/src/modules/critics/lica.py | import torch as th
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
class LICACritic(nn.Module):
def __init__(self, scheme, args):
super(LICACritic, self).__init__()
self.args = args
self.n_actions = args.n_actions
self.n_agents = args.n_agents
sel... | 2,079 | 35.491228 | 92 | py |
pymarl_transformers | pymarl_transformers-main/src/envs/gfootball/FootballEnv.py | import numpy as np
import gfootball.env as football_env
from gfootball.env import observation_preprocessing
from ..multiagentenv import MultiAgentEnv
import gym
import torch as th
class GoogleFootballEnv(MultiAgentEnv):
def __init__(
self,
dense_reward=False,
write_full_episode_dumps=Fals... | 4,792 | 31.167785 | 136 | py |
pymarl_transformers | pymarl_transformers-main/src/envs/stag_hunt/stag_hunt.py | # From https://github.com/wendelinboehmer/dcg/blob/master/src/envs/stag_hunt.py
from envs.multiagentenv import MultiAgentEnv
import torch as th
import numpy as np
import random
import pygame
from utils.dict2namedtuple import convert
'''
A simple n*m grid-world game for N agents trying to capture M prey and M' hares.
... | 42,965 | 54.297297 | 134 | py |
pymarl_transformers | pymarl_transformers-main/src/envs/matrix_game/one_step_matrix_game.py | from envs.multiagentenv import MultiAgentEnv
from utils.dict2namedtuple import convert
import numpy as np
import torch as th
import torch.nn.functional as F
# this non-monotonic matrix can be solved by qmix
# payoff_values = [[12, -0.1, -0.1],
# [-0.1, 0, 0],
# [-0.1, 0, 0]]
pa... | 7,622 | 33.96789 | 121 | py |
pymarl_transformers | pymarl_transformers-main/src/components/episode_buffer.py | import torch as th
import numpy as np
from types import SimpleNamespace as SN
from .segment_tree import SumSegmentTree, MinSegmentTree
import random
class EpisodeBatch:
def __init__(self,
scheme,
groups,
batch_size,
max_seq_length,
... | 14,895 | 42.428571 | 134 | py |
pymarl_transformers | pymarl_transformers-main/src/components/standarize_stream.py | """
Taken from: https://github.com/semitable/fast-marl
"""
import torch
from typing import Tuple
class RunningMeanStd(object):
def __init__(self, epsilon: float = 1e-4, shape: Tuple[int, ...] = (), device="cpu"):
"""
https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algor... | 1,445 | 30.434783 | 92 | py |
pymarl_transformers | pymarl_transformers-main/src/components/action_selectors.py | from matplotlib.pyplot import xcorr
import torch as th
from torch.distributions import Categorical
from torch.distributions.one_hot_categorical import OneHotCategorical
from .epsilon_schedules import DecayThenFlatSchedule
class GumbelSoftmax(OneHotCategorical):
def __init__(self, logits, probs=None, temperature=1... | 6,659 | 33.86911 | 112 | py |
pymarl_transformers | pymarl_transformers-main/src/components/transforms.py | import torch as th
class Transform:
def transform(self, tensor):
raise NotImplementedError
def infer_output_info(self, vshape_in, dtype_in):
raise NotImplementedError
class OneHot(Transform):
def __init__(self, out_dim):
self.out_dim = out_dim
def transform(self, tensor):
... | 568 | 24.863636 | 71 | py |
pymarl_transformers | pymarl_transformers-main/src/run/dop_run.py | import datetime
import os
import pprint
import time
import math as mth
import threading
import torch as th
from types import SimpleNamespace as SN
from utils.logging import Logger
from utils.timehelper import time_left, time_str
from os.path import dirname, abspath
from learners import REGISTRY as le_REGISTRY
from run... | 9,524 | 34.408922 | 116 | py |
pymarl_transformers | pymarl_transformers-main/src/run/on_off_run.py | import datetime
import os
import pprint
import time
import math as mth
import threading
import torch as th
from types import SimpleNamespace as SN
from utils.logging import Logger
from utils.timehelper import time_left, time_str
from os.path import dirname, abspath
from learners import REGISTRY as le_REGISTRY
from run... | 8,901 | 34.185771 | 116 | py |
pymarl_transformers | pymarl_transformers-main/src/run/per_run.py | import datetime
import os
import pprint
import time
import threading
import torch as th
from types import SimpleNamespace as SN
from utils.logging import Logger
from utils.timehelper import time_left, time_str
from os.path import dirname, abspath
from learners import REGISTRY as le_REGISTRY
from runners import REGISTR... | 8,691 | 34.917355 | 116 | py |
pymarl_transformers | pymarl_transformers-main/src/run/run.py | import datetime
import os
import pprint
import time
import threading
import torch as th
from types import SimpleNamespace as SN
from utils.logging import Logger
from utils.timehelper import time_left, time_str
from os.path import dirname, abspath
import pandas as pd
from learners import REGISTRY as le_REGISTRY
from ru... | 10,190 | 33.545763 | 142 | py |
pymarl_transformers | pymarl_transformers-main/src/runners/parallel_runner.py | from envs import REGISTRY as env_REGISTRY
from functools import partial
from components.episode_buffer import EpisodeBatch
from multiprocessing import Pipe, Process
from runners.episode_runner import EpisodeRunner
import numpy as np
import torch as th
import copy
# Based (very) heavily on SubprocVecEnv from OpenAI Ba... | 11,295 | 38.086505 | 133 | py |
pymarl_transformers | pymarl_transformers-main/src/controllers/basic_central_controller.py | from modules.agents import REGISTRY as agent_REGISTRY
from components.action_selectors import REGISTRY as action_REGISTRY
import torch as th
# This multi-agent controller shares parameters between agents
class CentralBasicMAC:
def __init__(self, scheme, args):
self.n_agents = args.n_agents
self.ar... | 3,015 | 39.213333 | 122 | py |
pymarl_transformers | pymarl_transformers-main/src/controllers/basic_controller.py | from modules.agents import REGISTRY as agent_REGISTRY
from components.action_selectors import REGISTRY as action_REGISTRY
import torch as th
from utils.th_utils import get_parameters_num
# This multi-agent controller shares parameters between agents
class BasicMAC:
def __init__(self, scheme, groups, args):
... | 4,149 | 40.919192 | 125 | py |
pymarl_transformers | pymarl_transformers-main/src/controllers/n_controller.py | from modules.agents import REGISTRY as agent_REGISTRY
from components.action_selectors import REGISTRY as action_REGISTRY
from .basic_controller import BasicMAC
import torch as th
from utils.rl_utils import RunningMeanStd
import numpy as np
# This multi-agent controller shares parameters between agents
class NMAC(Basi... | 1,311 | 41.322581 | 117 | py |
pymarl_transformers | pymarl_transformers-main/src/controllers/conv_controller.py | from modules.agents import REGISTRY as agent_REGISTRY
from components.action_selectors import REGISTRY as action_REGISTRY
from .basic_controller import BasicMAC
import torch as th
from utils.rl_utils import RunningMeanStd
import numpy as np
# This multi-agent controller shares parameters between agents
class ConvMAC(B... | 2,285 | 47.638298 | 111 | py |
pymarl_transformers | pymarl_transformers-main/src/controllers/ppo_controller.py | from modules.agents import REGISTRY as agent_REGISTRY
from components.action_selectors import REGISTRY as action_REGISTRY
import torch as th
# This multi-agent controller shares parameters between agents
class PPOMAC:
def __init__(self, scheme, groups, args):
self.n_agents = args.n_agents
self.arg... | 3,672 | 41.709302 | 128 | py |
pymarl_transformers | pymarl_transformers-main/src/controllers/lica_controller.py | from modules.agents import REGISTRY as agent_REGISTRY
from components.action_selectors import REGISTRY as action_REGISTRY
import torch as th
from .basic_controller import BasicMAC
# This multi-agent controller shares parameters between agents
class LICAMAC(BasicMAC):
def select_actions(self, ep_batch, t_ep, t_env... | 1,754 | 49.142857 | 115 | py |
pymarl_transformers | pymarl_transformers-main/src/controllers/dop_controller.py | from modules.agents import REGISTRY as agent_REGISTRY
from components.action_selectors import REGISTRY as action_REGISTRY
import torch as th
# This multi-agent controller shares parameters between agents
class DOPMAC:
def __init__(self, scheme, groups, args):
self.n_agents = args.n_agents
self.arg... | 4,517 | 42.864078 | 125 | py |
pymarl_transformers | pymarl_transformers-main/src/utils/noisy_liner.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
class NoisyLinear(nn.Module):
r"""Applies a linear transformation to the incoming data: :math:`y = xA^T + b`
This module supports :ref:`TensorFloat32<tf32_on_ampere>`.
Args:
in_features: size of each input sample
... | 3,285 | 41.128205 | 108 | py |
pymarl_transformers | pymarl_transformers-main/src/utils/logging.py | from collections import defaultdict
import logging
import numpy as np
import torch as th
class Logger:
def __init__(self, console_logger):
self.console_logger = console_logger
self.use_tb = False
self.use_sacred = False
self.use_hdf = False
self.stats = defaultdict(lambda:... | 2,393 | 31.794521 | 130 | py |
pymarl_transformers | pymarl_transformers-main/src/utils/th_utils.py | import torch
from torch import nn
def clip_by_tensor(t,t_min,t_max):
"""
clip_by_tensor
:param t: tensor
:param t_min: min
:param t_max: max
:return: cliped tensor
"""
t=t.float()
t_min=t_min.float()
t_max=t_max.float()
result = (t >= t_min).float() * t + (t < t_min).float... | 852 | 24.848485 | 82 | py |
pymarl_transformers | pymarl_transformers-main/src/utils/value_norm.py | import numpy as np
import torch
import torch.nn as nn
class ValueNorm(nn.Module):
""" Normalize a vector of observations - across the first norm_axes dimensions"""
def __init__(self, input_shape, norm_axes=1, beta=0.99999, per_element_update=False, epsilon=1e-5, device=torch.device("cpu")):
super(Va... | 3,067 | 39.368421 | 131 | py |
pymarl_transformers | pymarl_transformers-main/src/utils/rl_utils.py | import torch as th
import torch.nn as nn
import numpy as np
def build_td_lambda_targets(rewards, terminated, mask, target_qs, n_agents, gamma, td_lambda):
# Assumes <target_qs > in B*T*A and <reward >, <terminated >, <mask > in (at least) B*T-1*1
# Initialise last lambda -return for not terminated epis... | 3,646 | 39.977528 | 110 | py |
pymarl_transformers | pymarl_transformers-main/src/learners/fmac_learner.py | import copy
from components.episode_buffer import EpisodeBatch
from modules.critics.fmac_critic import FMACCritic
from modules.critics.lica import LICACritic
import torch as th
from torch.optim import RMSprop, Adam
from modules.mixers.vdn import VDNMixer
from modules.mixers.qmix import QMixer
from components.action_sel... | 7,548 | 45.030488 | 133 | py |
pymarl_transformers | pymarl_transformers-main/src/learners/coma_learner.py | import copy
from components.episode_buffer import EpisodeBatch
from modules.critics.coma import COMACritic
from utils.rl_utils import build_td_lambda_targets
from torch.distributions import Categorical
import torch as th
from torch.optim import Adam
class COMALearner:
def __init__(self, mac, scheme, logger, args)... | 7,644 | 41.949438 | 136 | py |
pymarl_transformers | pymarl_transformers-main/src/learners/qtran_learner.py | import copy
from components.episode_buffer import EpisodeBatch
from modules.mixers.qtran import QTranBase
from envs.matrix_game import print_matrix_status_qtran
import torch as th
from torch.optim import RMSprop, Adam
class QLearner:
def __init__(self, mac, scheme, logger, args):
self.args = args
... | 9,396 | 49.521505 | 206 | py |
pymarl_transformers | pymarl_transformers-main/src/learners/max_q_learner.py | import copy
from components.episode_buffer import EpisodeBatch
from modules.mixers.vdn import VDNMixer
from modules.mixers.qmix import QMixer
from modules.mixers.qmix_central_no_hyper import QMixerCentralFF
from utils.rl_utils import build_td_lambda_targets
import torch as th
from torch.optim import RMSprop, Adam
from ... | 12,007 | 45.542636 | 195 | py |
pymarl_transformers | pymarl_transformers-main/src/learners/offpg_learner.py | import copy
from torch.distributions import Categorical
from torch.optim.rmsprop import RMSprop
from components.episode_buffer import EpisodeBatch
from modules.critics.offpg import OffPGCritic
import torch as th
from utils.rl_utils import build_td_lambda_targets, build_target_q
from torch.optim import Adam
from modules... | 13,136 | 47.120879 | 160 | py |
pymarl_transformers | pymarl_transformers-main/src/learners/dmaq_qatten_learner.py | # From https://github.com/wjh720/QPLEX/, added here for convenience.
import copy
from components.episode_buffer import EpisodeBatch
from modules.mixers.dmaq_general import DMAQer
import torch.nn.functional as F
import torch as th
from torch.optim import Adam
import numpy as np
from utils.rl_utils import build_td_lambda... | 9,163 | 44.59204 | 118 | py |
pymarl_transformers | pymarl_transformers-main/src/learners/nq_transf_learner.py | import copy
from components.episode_buffer import EpisodeBatch
from modules.mixers.n_transf_mixer import TransformerMixer
from envs.matrix_game import print_matrix_status_transf
from utils.rl_utils import build_td_lambda_targets, build_q_lambda_targets
import torch as th
from torch.optim import RMSprop, Adam
import num... | 10,582 | 45.621145 | 132 | py |
pymarl_transformers | pymarl_transformers-main/src/learners/nq_learner.py | import copy
from components.episode_buffer import EpisodeBatch
from modules.mixers.nmix import Mixer
from modules.mixers.vdn import VDNMixer
from modules.mixers.qatten import QattenMixer
from envs.matrix_game import print_matrix_status
from utils.rl_utils import build_td_lambda_targets, build_q_lambda_targets
import to... | 8,415 | 43.765957 | 132 | py |
pymarl_transformers | pymarl_transformers-main/src/learners/lica_learner.py | import copy
from components.episode_buffer import EpisodeBatch
from modules.critics.lica import LICACritic
from components.action_selectors import multinomial_entropy
from utils.rl_utils import build_td_lambda_targets
import torch as th
from torch.optim import RMSprop, Adam
from utils.th_utils import get_parameters_num... | 7,521 | 42.479769 | 140 | py |
pymarl_transformers | pymarl_transformers-main/src/learners/ppo_learner.py | import copy
from components.episode_buffer import EpisodeBatch
import torch as th
from torch.optim import Adam
from modules.critics import REGISTRY as critic_resigtry
from components.standarize_stream import RunningMeanStd
class PPOLearner:
def __init__(self, mac, scheme, logger, args):
self.args = args
... | 9,559 | 43.465116 | 124 | py |
pymarl_transformers | pymarl_transformers-main/src/learners/policy_gradient_v2.py | import copy
from components.episode_buffer import EpisodeBatch
from modules.mixers.vdn import VDNMixer
from modules.mixers.qmix import QMixer
from utils.rl_utils import build_td_lambda_targets
from components.action_selectors import categorical_entropy
import torch as th
from torch.optim import Adam, RMSprop
"""
IAC a... | 6,571 | 43.107383 | 141 | py |
pymarl_transformers | pymarl_transformers-main/src/learners/q_learner.py | import copy
from components.episode_buffer import EpisodeBatch
from modules.mixers.vdn import VDNMixer
from modules.mixers.qmix import QMixer
from utils.rl_utils import build_td_lambda_targets
from envs.matrix_game import print_matrix_status
import torch as th
from torch.optim import RMSprop, Adam
import numpy as np
c... | 6,611 | 41.11465 | 132 | py |
networkx | networkx-main/doc/conf.py | from datetime import date
from sphinx_gallery.sorting import ExplicitOrder, FileNameSortKey
from warnings import filterwarnings
filterwarnings(
"ignore", message="Matplotlib is currently using agg", category=UserWarning
)
# General configuration
# ---------------------
# Add any Sphinx extension module names her... | 7,710 | 30.092742 | 190 | py |
PseudoLabeling | PseudoLabeling-master/cifar10/train.py | import torch
import torch.nn as nn
import torch.backends.cudnn as cudnn
import torch.utils.data as data
from torch import optim
from torchvision import datasets, transforms
import numpy as np
import random
import sys
import argparse
import os
import time
from dataset.cifar10 import get_dataset
sys.path.append('../ut... | 18,454 | 45.959288 | 202 | py |
PseudoLabeling | PseudoLabeling-master/cifar10/dataset/cifar10.py | import torchvision as tv
import numpy as np
from PIL import Image
import time
def get_dataset(args, transform_train, transform_val):
# prepare datasets
cifar10_train_val = tv.datasets.CIFAR10(args.train_root, train=True, download=args.download)
# get train/val dataset
train_indexes, val_indexes = tra... | 5,553 | 37.569444 | 147 | py |
PseudoLabeling | PseudoLabeling-master/utils_pseudoLab/wideArchitectures.py | # Network from here:
# Interpolation Consistency Training (ICT) for Deep Semi-supervised Learning
# https://github.com/vikasverma1077/ICT/blob/master/networks/wide_resnet.py
import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
from torch.autograd import Variable
import sys, ... | 3,445 | 33.808081 | 114 | py |
PseudoLabeling | PseudoLabeling-master/utils_pseudoLab/TwoSampler.py | # Code obtained from:
# https://github.com/CuriousAI/mean-teacher/blob/bd4313d5691f3ce4c30635e50fa207f49edf16fe/pytorch/mean_teacher/data.py
import itertools
import logging
import os.path
from PIL import Image
import numpy as np
from torch.utils.data.sampler import Sampler
class TwoStreamBatchSampler(Sampler):
... | 1,927 | 31.677966 | 118 | py |
PseudoLabeling | PseudoLabeling-master/utils_pseudoLab/PreResNet.py | '''ResNet in PyTorch.
BasicBlock and Bottleneck module is from the original ResNet paper:
[1] Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun
Deep Residual Learning for Image Recognition. arXiv:1512.03385
PreActBlock and PreActBottleneck module is from the later paper:
[2] Kaiming He, Xiangyu Zhang, Shaoqing Ren,... | 3,709 | 36.474747 | 114 | py |
PseudoLabeling | PseudoLabeling-master/utils_pseudoLab/utils_ssl.py | from __future__ import print_function
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms
import scipy.stats as stats
import math
import numpy as np
from matplotlib import pyplot as plt
from utils.AverageMeter import... | 9,340 | 37.599174 | 125 | py |
PseudoLabeling | PseudoLabeling-master/utils_pseudoLab/ssl_networks.py | import sys
import math
import itertools
import torch
from torch import nn
from torch.nn import functional as F
from torch.autograd import Variable, Function
from torch.nn.utils import weight_norm
# For cifar_cnn
class CNN(nn.Module):
"""
CNN from Mean Teacher paper
"""
def __init__(self, num_classe... | 10,431 | 31.6 | 86 | py |
PseudoLabeling | PseudoLabeling-master/utils_pseudoLab/utils/AverageMeter.py |
class AverageMeter(object):
"""
Computes and stores the average and current value
Imported from https://github.com/pytorch/examples/blob/master/imagenet/main.py#L247-L262
"""
def __init__(self):
self.reset()
def reset(self):
self.val = 0
self.avg = 0
self.sum =... | 495 | 21.545455 | 92 | py |
PseudoLabeling | PseudoLabeling-master/utils_pseudoLab/utils/criterion.py | import torch
import torch.nn.functional as F
def accuracy_v1(preds, labels, top=[1,5]):
"""Compute the precision@k for the specified values of k"""
correct = [0] * len(top)
_, labels_pred = torch.sort(preds, dim=1, descending=True)
for idx, label_pred in labels_pred:
result = (label_pred == lab... | 1,152 | 30.162162 | 93 | py |
PseudoLabeling | PseudoLabeling-master/cifar100/train.py | import torch
import torch.nn as nn
import torch.backends.cudnn as cudnn
import torch.utils.data as data
from torch import optim
from torchvision import datasets, transforms
import numpy as np
import random
import sys
import argparse
import os
import time
from dataset.cifar100 import get_dataset
sys.path.append('../u... | 18,323 | 46.968586 | 202 | py |
PseudoLabeling | PseudoLabeling-master/cifar100/dataset/cifar100.py | import torchvision as tv
import numpy as np
from PIL import Image
import time
def get_dataset(args, transform_train, transform_val):
# prepare datasets
cifar100_train_val = tv.datasets.CIFAR100(args.train_root, train=True, download=args.download)
# get train/val dataset
train_indexes, val_indexes = t... | 5,734 | 38.551724 | 148 | py |
PseudoLabeling | PseudoLabeling-master/miniImagenet/train.py | import torch
import torch.nn as nn
import torch.backends.cudnn as cudnn
import torch.utils.data as data
from torch import optim
from torchvision import datasets, transforms
import numpy as np
import random
import sys
import argparse
import os
import time
from dataset.miniImagenet import get_dataset
sys.path.append('... | 17,798 | 47.235772 | 202 | py |
PseudoLabeling | PseudoLabeling-master/miniImagenet/dataset/miniImagenet.py | import torchvision as tv
import numpy as np
from PIL import Image
from IPython import embed
import time
from torch.utils.data import Dataset
from os.path import join
import csv
from tqdm import tqdm
def get_dataset(args, transform_train, transform_val):
# prepare datasets
train_data, train_labels, val_data, v... | 7,554 | 36.587065 | 155 | py |
unbalanced-ot-functionals | unbalanced-ot-functionals-master/setup.py | #! /usr/bin/env python
from setuptools import setup
setup(
name="unbalancedot",
distname="",
version='0.0.1',
description="Functionals derived from the theory of entropically "
"regularized unbalanced optimal transport ",
author='Thibault Sejourne',
author_email='thibault.sejour... | 594 | 26.045455 | 70 | py |
unbalanced-ot-functionals | unbalanced-ot-functionals-master/examples/plot_unb_gradient_flows_2D_waffle_v2.py | import os
import time
import numpy as np
from random import choices
import imageio
from matplotlib import pyplot as plt
from functools import partial
import torch
from unbalancedot.functional import regularized_ot, hausdorff_divergence, \
sinkhorn_divergence
from unbalancedot.sinkhorn import BatchVanillaSinkhorn
... | 5,233 | 33.434211 | 79 | py |
unbalanced-ot-functionals | unbalanced-ot-functionals-master/examples/plot_unb_gradient_flows_2D_frame_v3.py | import os
import numpy as np
from random import choices
import imageio
from matplotlib import pyplot as plt, use
from functools import partial
from sympy import EX
import torch
from unbalancedot.functional import energyDistance, gaussianKernel
from unbalancedot.utils import euclidean_cost
# Build path to save plots
... | 4,699 | 30.333333 | 79 | py |
unbalanced-ot-functionals | unbalanced-ot-functionals-master/examples/plan_marginal_impact_reach_v2.py | import os
import torch
import numpy as np
import matplotlib.pyplot as plt
from unbalancedot.utils import euclidean_cost
from unbalancedot.sinkhorn import BatchVanillaSinkhorn
from unbalancedot.entropy import KullbackLeibler, TotalVariation
path = os.getcwd() + "/output"
if not os.path.isdir(path):
os.mkdir(path)... | 2,809 | 27.673469 | 78 | py |
unbalanced-ot-functionals | unbalanced-ot-functionals-master/examples/display_aprox_operator.py | import numpy as np
import torch
import matplotlib.pyplot as plt
from unbalancedot.entropy import Balanced, KullbackLeibler, TotalVariation, \
Range, PowerEntropy
x = torch.linspace(-5, 5, 200)
x_, y_ = np.zeros(200), np.zeros(200)
L_entropy = [Balanced(1e0), KullbackLeibler(1e0, 1e0),
TotalVariation(1... | 851 | 34.5 | 77 | py |
unbalanced-ot-functionals | unbalanced-ot-functionals-master/examples/plan_marginal.py | import os
import torch
import numpy as np
import matplotlib.pyplot as plt
from unbalancedot.utils import euclidean_cost
from unbalancedot.sinkhorn import BatchVanillaSinkhorn
from unbalancedot.entropy import (
KullbackLeibler,
Balanced,
TotalVariation,
Range,
PowerEntropy,
)
path = os.getcwd() + ... | 2,712 | 24.59434 | 69 | py |
unbalanced-ot-functionals | unbalanced-ot-functionals-master/examples/plot_unb_gradient_flows_2D_frame.py | import os
import numpy as np
from random import choices
import imageio
from matplotlib import pyplot as plt, use
from functools import partial
from sympy import EX
import torch
from unbalancedot.functional import regularized_ot, hausdorff_divergence, \
sinkhorn_divergence
from unbalancedot.sinkhorn import BatchVa... | 8,080 | 38.038647 | 79 | py |
unbalanced-ot-functionals | unbalanced-ot-functionals-master/examples/display_aprox_operator_v2.py | import numpy as np
import torch
import matplotlib.pyplot as plt
from unbalancedot.entropy import Balanced, KullbackLeibler, TotalVariation, \
Range, PowerEntropy
x = torch.linspace(-3, 3, 200)
x_, y_ = np.zeros(200), np.zeros(200)
setting = 2
if setting == 1:
L_entropy = [Balanced(1e0), KullbackLeibler(1e0, ... | 1,296 | 33.131579 | 81 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.