python_code stringlengths 0 4.04M | repo_name stringlengths 7 58 | file_path stringlengths 5 147 |
|---|---|---|
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
from IPython import embed
number_datapoints = 50000
number_timesteps = 20
x_array_dataset = np.zeros((n... | CausalSkillLearning-main | DataGenerator/ContinuousTrajs.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
from IPython import embed
number_datapoints = 50000
number_timesteps = 20
x_array_dataset = np.zeros((n... | CausalSkillLearning-main | DataGenerator/ContinuousNonZero.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
from IPython import embed
import matplotlib.pyplot as plt
#number_datapoints = 20
number_datapoints = 50... | CausalSkillLearning-main | DataGenerator/DeterministicGoalDirectedTraj.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
from IPython import embed
import matplotlib.pyplot as plt
number_datapoints = 1
# number_datapoints = 50... | CausalSkillLearning-main | DataGenerator/GoalDirectedTrajs.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np, copy
from IPython import embed
import matplotlib.pyplot as plt
number_datapoints = 20
# number_datapoin... | CausalSkillLearning-main | DataGenerator/PolicyVisualizer.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
from IPython import embed
number_datapoints = 50000
number_timesteps = 25
x_array_dataset = np.zeros((n... | CausalSkillLearning-main | DataGenerator/DirectedContinuousNonZero.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np, copy
from IPython import embed
import matplotlib.pyplot as plt
number_datapoints = 20
# number_datapoin... | CausalSkillLearning-main | DataGenerator/NewGoalDirectedTraj.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
from IPython import embed
import matplotlib.pyplot as plt
# number_datapoints = 20
number_datapoints = 5... | CausalSkillLearning-main | DataGenerator/SeparableTrajs.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from setuptools import setup, find_packages
from setuptools.extension import Extension
from Cython.Build import cythonize
import numpy
extensi... | CPC_audio-main | setup.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import torch
from cpc.model import CPCModel as cpcmodel
from cpc.cpc_default_config import get_default_cpc_config
from cpc.feat... | CPC_audio-main | hubconf.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torchaudio
import os
import json
import argparse
from .cpc_default_config import get_default_cpc_config
from .dataset impor... | CPC_audio-main | cpc/feature_loader.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import math
class ScaledDotProductAttention(nn.Module):
def __init__(self,
sizeSeq, ... | CPC_audio-main | cpc/transformers.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
| CPC_audio-main | cpc/__init__.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch.nn as nn
import torch.nn.functional as F
import torchaudio
import torch
###########################################
# Networks
#... | CPC_audio-main | cpc/model.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import random
import time
import tqdm
import torch
import soundfile as sf
from pathlib import Path
from copy import deepcopy
from tor... | CPC_audio-main | cpc/dataset.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import json
import os
import numpy as np
import torch
import time
from copy import deepcopy
import random
import psutil
import ... | CPC_audio-main | cpc/train.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
import os
import cpc.feature_loader as fl
from .dataset import AudioBatchData, findAllSeqs, filterSeqs
from nose.t... | CPC_audio-main | cpc/unit_tests.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
def get_default_cpc_config():
parser = set_default_cpc_config(argparse.ArgumentParser())
return parser.parse_args([])... | CPC_audio-main | cpc/cpc_default_config.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import json
import numpy as np
import random
import torch
import sys
import psutil
from copy import deepcopy
from bisect import bisect_left
d... | CPC_audio-main | cpc/utils/misc.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
| CPC_audio-main | cpc/utils/__init__.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
import os
from nose.tools import eq_, ok_
from .misc import SchedulerCombiner, ramp_scheduling_function
class T... | CPC_audio-main | cpc/utils/unit_tests.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import math
import torch.nn as nn
from numpy import prod
class Norma... | CPC_audio-main | cpc/criterion/custom_layers.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from .criterion import CPCUnsupersivedCriterion, SpeakerCriterion, \
PhoneCriterion, NoneCriterion, CTCPhoneCriterion
| CPC_audio-main | cpc/criterion/__init__.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import progressbar
import torch
from multiprocessing import Lock, Manager, Process
from copy import deepcopy
def beam_search(score_preds, nKe... | CPC_audio-main | cpc/criterion/seq_alignment.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from .seq_alignment import collapseLabelChain
from .custom_layers import EqualizedLinear, EqualizedConv1d
... | CPC_audio-main | cpc/criterion/criterion.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import sys
import torch
import json
from pathlib import Path
import ABX.abx_group_computation as abx_g
import ABX.abx_iterators... | CPC_audio-main | cpc/eval/ABX.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import os
import torchaudio
from copy import deepcopy
import torch
import time
import random
import math
import json
import sub... | CPC_audio-main | cpc/eval/common_voices_eval.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import json
import torch
import progressbar
import argparse
import numpy as np
from cpc.dataset import findAllSeqs
from cpc.feature_... | CPC_audio-main | cpc/eval/build_zeroSpeech_features.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import sys
import torch
import json
import time
import numpy as np
from pathlib import Path
from copy import deepcopy
import os... | CPC_audio-main | cpc/eval/linear_separability.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
| CPC_audio-main | cpc/eval/__init__.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import progressbar
import math
import random
def normalize_with_singularity(x):
r"""
Normalize the given vector across t... | CPC_audio-main | cpc/eval/ABX/abx_iterators.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
| CPC_audio-main | cpc/eval/ABX/__init__.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
from nose.tools import eq_, ok_
from . import abx_group_computation
from . import abx_iterators
from pathlib impor... | CPC_audio-main | cpc/eval/ABX/unit_tests.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import math
from . import dtw
import progressbar
def get_distance_function_from_name(name_str):
if name_str == 'euclidian':
... | CPC_audio-main | cpc/eval/ABX/abx_group_computation.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import torchaudio
import progressbar
import os
import sys
from pathlib import Path
def adjust_sample_rate(path_db, file_list,... | CPC_audio-main | cpc/eval/utils/adjust_sample_rate.py |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
import os
import glob
import argparse
import numpy as np
import resampy
from scikits.audiolab impo... | 2.5D-Visual-Sound-main | reEncodeAudio.py |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import os
import time
import torch
from options.train_options import TrainOptions
from data.data_loa... | 2.5D-Visual-Sound-main | train.py |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import os
import librosa
import argparse
import numpy as np
from numpy import linalg as LA
from sci... | 2.5D-Visual-Sound-main | evaluate.py |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import os
import argparse
import librosa
import numpy as np
from PIL import Image
import subprocess
... | 2.5D-Visual-Sound-main | demo.py |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
from .base_options import BaseOptions
class TestOptions(BaseOptions):
def initialize(self):
Base... | 2.5D-Visual-Sound-main | options/test_options.py |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
from .base_options import BaseOptions
class TrainOptions(BaseOptions):
def initialize(self):
Bas... | 2.5D-Visual-Sound-main | options/train_options.py |
2.5D-Visual-Sound-main | options/__init__.py | |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import os
from util import util
import torch
class BaseOptions():
def __init__(sel... | 2.5D-Visual-Sound-main | options/base_options.py |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import os
def mkdirs(paths):
if isinstance(paths, list) and not isinstance(paths, str):
... | 2.5D-Visual-Sound-main | util/util.py |
2.5D-Visual-Sound-main | util/__init__.py | |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torchvision
from .networks import VisualNet, AudioNet, weights_init
class Model... | 2.5D-Visual-Sound-main | models/models.py |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import os
import numpy as np
import torch
from torch import optim
import torch.nn.functional as F
fr... | 2.5D-Visual-Sound-main | models/audioVisual_model.py |
2.5D-Visual-Sound-main | models/__init__.py | |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
import functools
def unet_conv(i... | 2.5D-Visual-Sound-main | models/networks.py |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
class BaseLoss(nn.Module):
... | 2.5D-Visual-Sound-main | models/criterion.py |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch.utils.data as data
from PIL import Image
import torchvision.transforms as transforms
c... | 2.5D-Visual-Sound-main | data/base_dataset.py |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
def CreateDataLoader(opt):
from data.custom_dataset_data_loader import CustomDatasetDataLoader
... | 2.5D-Visual-Sound-main | data/data_loader.py |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
class BaseDataLoader():
def __init__(self):
pass
def initialize(self, opt):
... | 2.5D-Visual-Sound-main | data/base_data_loader.py |
2.5D-Visual-Sound-main | data/__init__.py | |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch.utils.data
from data.base_data_loader import BaseDataLoader
def CreateDataset(opt):
... | 2.5D-Visual-Sound-main | data/custom_dataset_data_loader.py |
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
import os.path
import time
import librosa
import h5py
import random
import math
import numpy as np... | 2.5D-Visual-Sound-main | data/audioVisual_dataset.py |
import torch
import pytorch_lightning as pl
def pl_train(cfg, pl_model_class):
if cfg.seed is not None:
torch.manual_seed(cfg.seed)
if torch.cuda.is_available():
torch.cuda.manual_seed(cfg.seed)
model = pl_model_class(cfg.model, cfg.dataset, cfg.train)
if 'pl' in cfg and 'profi... | hippo-code-master | pl_runner.py |
import torch
from omegaconf.dictconfig import DictConfig
from munch import Munch
def remove_postfix(text, postfix):
if text.endswith(postfix):
return text[:-len(postfix)]
return text
# pytorch-lightning returns pytorch 0-dim tensor instead of python scalar
def to_scalar(x):
return x.item() if i... | hippo-code-master | utils.py |
from pathlib import Path
project_root = Path(__file__).parent.absolute()
import os
# Add to $PYTHONPATH so that ray workers can see
os.environ['PYTHONPATH'] = str(project_root) + ":" + os.environ.get('PYTHONPATH', '')
import numpy as np
import torch
import pytorch_lightning as pl
import hydra
from omegaconf import Om... | hippo-code-master | train.py |
from setuptools import setup
from torch.utils.cpp_extension import CppExtension, BuildExtension
ext_modules = []
extension = CppExtension('hippo', ['hippo.cpp', 'hippolegs.cpp', 'hippolegt.cpp'], extra_compile_args=['-march=native'])
ext_modules.append(extension)
setup(
name='hippo',
ext_modules=ext_modules,
... | hippo-code-master | csrc/setup.py |
import torch
import torch.nn as nn
import torch.nn.functional as F
# from torch.utils.data.dataset import IterableDataset
import numpy as np
def np_copying_data(L, M, A, batch_shape=()):
seq = np.random.randint(low=1, high=A-1, size=batch_shape+(M,))
zeros_x = np.zeros(batch_shape+(L,))
markers = (A-1) * ... | hippo-code-master | datasets/copying.py |
import torch
from torch import nn
from torch.nn import functional as F
class Task:
@staticmethod
def metrics(outs, y, len_batch=None):
return {}
@staticmethod
def metrics_epoch(outs, y, len_batch=None):
return {}
class BinaryClassification(Task):
@staticmethod
def loss(logit... | hippo-code-master | datasets/tasks.py |
""" Load data for UEA datasets, in particular CharacterTrajectories
Adapted from https://github.com/patrick-kidger/NeuralCDE/blob/master/experiments/datasets/uea.py
"""
import os
import pathlib
import urllib.request
import zipfile
import sklearn.model_selection
import sktime.utils.data_io
import numpy as np
import tor... | hippo-code-master | datasets/uea.py |
import os
dir_path = os.path.dirname(os.path.abspath(__file__))
import random
import torch
from torch import nn
from torch.nn import functional as F
from torchvision import datasets, transforms
from . import copying, adding
from . import utils
from .tasks import BinaryClassification, MulticlassClassification, MSEReg... | hippo-code-master | datasets/__init__.py |
import math
import numpy as np
import torch
def bitreversal_po2(n):
m = int(math.log(n)/math.log(2))
perm = np.arange(n).reshape(n,1)
for i in range(m):
n1 = perm.shape[0]//2
perm = np.hstack((perm[:n1],perm[n1:]))
return perm.squeeze(0)
def bitreversal_permutation(n):
m = int(ma... | hippo-code-master | datasets/utils.py |
import torch
import torch.nn as nn
import torch.nn.functional as F
# from torch.utils.data.dataset import IterableDataset
import numpy as np
def torch_adding_data(L, batch_shape=()):
assert L >= 2
mid = L//2
idx0 = torch.randint(low=0, high=mid, size=batch_shape)
idx1 = torch.randint(low=0, high=L-mid... | hippo-code-master | datasets/adding.py |
import math
import unittest
import numpy as np
from scipy import linalg as la
import torch
import torch.nn.functional as F
import hippo
# from .op import transition
def transition(measure, N, **measure_args):
""" A, B transition matrices for different measures """
if measure == 'lagt':
# A_l = (1 - ... | hippo-code-master | tests/test_legs_extension.py |
import math
import unittest
import numpy as np
from scipy import linalg as la
import torch
import torch.nn.functional as F
import hippo
# from .op import transition
def transition(measure, N, **measure_args):
""" A, B transition matrices for different measures """
if measure == 'lagt':
# A_l = (1 - ... | hippo-code-master | tests/test_legt_extension.py |
import numpy as np
from keras import backend as K
from keras import activations, initializers
from keras.initializers import Constant, Initializer
from keras.layers import Layer
from scipy import signal
from scipy import linalg as la
import math
import tensorflow as tf
def transition(measure, N, **measure_args):
... | hippo-code-master | tensorflow/hippo.py |
import torch
import torch.nn as nn
from torch.nn import functional as F
import numpy as np
from model.memory import LTICell, LSICell
from model.op import transition
class OPLTICell(LTICell):
# name = 'lagt'
measure = None
def __init__(self, input_size, hidden_size, memory_size=1, memory_order=-1, measur... | hippo-code-master | model/opcell.py |
import torch
import torch.nn as nn
import torch.nn.functional as F
import math
import numpy as np
from scipy import signal
from scipy import linalg as la
from functools import partial
from model.rnncell import RNNCell
from model.orthogonalcell import OrthogonalLinear
from model.components import Gate, Linear_, Modrelu... | hippo-code-master | model/memory.py |
import torch
import torch.nn as nn
from model.exprnn.orthogonal import Orthogonal
from model.exprnn.trivializations import expm, cayley_map
from model.exprnn.initialization import henaff_init_, cayley_init_
from model.components import Modrelu
param_name_to_param = {'cayley': cayley_map, 'expm': expm}
init_name_to_i... | hippo-code-master | model/orthogonalcell.py |
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from scipy import signal
import math
# from model.toeplitz import triangular_toeplitz_multiply, triangular_toeplitz_multiply_padded
# from toeplitz import triangular_toeplitz_multiply, triangular_toeplitz_multiply_padded
### Utili... | hippo-code-master | model/unroll.py |
import torch
import torch.nn as nn
from functools import partial
from model.rnn import RNN, RNNWrapper, LSTMWrapper
from model import rnncell, opcell # TODO: this is just to force cell_registry to update. There is probably a better programming pattern for this
from model.rnncell import CellBase
from model.orthogonalce... | hippo-code-master | model/model.py |
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from scipy import signal
from scipy import linalg as la
from scipy import special as ss
def transition(measure, N, **measure_args):
""" A, B transition matrices for different measures.
measure: the type of measure
leg... | hippo-code-master | model/op.py |
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.data as data
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
from scipy import linalg as la
from scipy import special as ss
import nengo
from model import unroll
from model.op import transition
"""
The H... | hippo-code-master | model/hippo.py |
""" Baseline RNN cells such as the vanilla RNN and GRU. """
import torch
import torch.nn as nn
import torch.nn.functional as F
from model.components import Gate, Linear_, Modrelu, get_activation, get_initializer
from model.orthogonalcell import OrthogonalLinear
class CellBase(nn.Module):
""" Abstract class for ... | hippo-code-master | model/rnncell.py |
from functools import partial
import torch
import torch.nn as nn
from model.exprnn.orthogonal import modrelu
def get_activation(activation, size):
if activation == 'id':
return nn.Identity()
elif activation == 'tanh':
return torch.tanh
elif activation == 'relu':
return torch.relu
... | hippo-code-master | model/components.py |
import torch
import torch.nn as nn
import torch.nn.functional as F
def apply_tuple(tup, fn):
"""Apply a function to a Tensor or a tuple of Tensor
"""
if isinstance(tup, tuple):
return tuple((fn(x) if isinstance(x, torch.Tensor) else x) for x in tup)
else:
return fn(tup)
def concat_tup... | hippo-code-master | model/rnn.py |
# Downloaded from https://github.com/Lezcano/expRNN
"""
Adaptation of expm and expm_frechet in numpy for torch
"""
#
# Authors: Travis Oliphant, March 2002
# Anthony Scopatz, August 2012 (Sparse Updates)
# Jake Vanderplas, August 2012 (Sparse Updates)
#
from __future__ import division, print_functi... | hippo-code-master | model/exprnn/expm32.py |
# Downloaded from https://github.com/Lezcano/expRNN
import torch
import numpy as np
import scipy.linalg as la
def henaff_init_(A):
size = A.size(0) // 2
diag = A.new(size).uniform_(-np.pi, np.pi)
return create_diag_(A, diag)
def cayley_init_(A):
size = A.size(0) // 2
diag = A.new(size).uniform_... | hippo-code-master | model/exprnn/initialization.py |
# Adapted from https://github.com/Lezcano/expRNN
import torch
import torch.nn as nn
from .parametrization import Parametrization
class Orthogonal(Parametrization):
""" Class that implements optimization restricted to the Stiefel manifold """
def __init__(self, input_size, output_size, initializer_skew, mode... | hippo-code-master | model/exprnn/orthogonal.py |
# Downloaded from https://github.com/Lezcano/expRNN
import torch
# from model.exprnn.expm32 import expm32, differential
from .expm32 import expm32, differential
def cayley_map(X):
n = X.size(0)
Id = torch.eye(n, dtype=X.dtype, device=X.device)
return torch.solve(Id - X, Id + X)[0]
class expm_class(torch... | hippo-code-master | model/exprnn/trivializations.py |
# Downloaded from https://github.com/Lezcano/expRNN
import torch
import torch.nn as nn
def get_parameters(model):
parametrized_params = []
def get_parametrized_params(mod):
nonlocal parametrized_params
if isinstance(mod, Parametrization):
parametrized_params.append(mod.A)
de... | hippo-code-master | model/exprnn/parametrization.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import gym
import torch
from collections import deque, defaultdict
from gym import spaces
import numpy as np
from gym_mini... | adversarially-motivated-intrinsic-goals-main | env_utils.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
"""Naive profiling using timeit."""
import collections
import timeit
class Timings:
"""Not thread-safe."""
def ... | adversarially-motivated-intrinsic-goals-main | torchbeast/core/prof.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import copy
import datetime
import csv
import json
import logging
import os
import time
from typing import Dict
import git... | adversarially-motivated-intrinsic-goals-main | torchbeast/core/file_writer.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This file taken from
# https://github.com/deepmind/scalable_agent/blob/
# cd66d00914d56c8ba2f0615d9cdeefcb169a8d70/vtrace.py
# and modified.
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "Li... | adversarially-motivated-intrinsic-goals-main | torchbeast/core/vtrace.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
"""The environment class."""
import torch
def _format_frame(frame):
frame = torch.from_numpy(frame)
return frame... | adversarially-motivated-intrinsic-goals-main | torchbeast/core/environment.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
| adversarially-motivated-intrinsic-goals-main | monobeast/__init__.py |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
# Must be run with OMP_NUM_THREADS=1
import random
import argparse
import logging
import os
import threading
import time
i... | adversarially-motivated-intrinsic-goals-main | monobeast/minigrid/monobeast_amigo.py |
import numpy as np
import pandas as pd
import statsmodels.api as sm
import gc
import operator
import networkx as nx
from tqdm import tqdm
G = nx.watts_strogatz_graph(2000000, 10, 0.5)
assignments = np.concatenate([[k]*10 for k in list(np.random.randint(0, 2, 2000000//10))])
sample = np.random.choice(2000000, 100000)
... | CausalMotifs-master | generate_WS.py |
from causalPartition import causalPartition
import pandas as pd
import numpy as np
import warnings
warnings.filterwarnings("ignore")
# load and process data
data = pd.read_csv('data_ws.csv')
probabilities = np.load('probabilities_ws.npy')
new_probabilities = {}
new_probabilities['bbb_2_normalized'] = 1.0 * probabi... | CausalMotifs-master | example.py |
import numpy as np
import pandas as pd
import statsmodels.api as sm
import gc
import operator
import networkx as nx
class causalPartition:
df = None # the whole dataset
probabilities = None # the Monte Carlo probabilities, a dict, each element represents a dimension of the intervention vector
# each eleme... | CausalMotifs-master | causalPartition.py |
import os
import sys
import torch
import logging
import argparse
import numpy as np
import pandas as pd
from scipy.stats import mode
from maude import MaudeReport
from maude.labelers.gender import lfs
from maude.labelers import LabelingServer
logger = logging.getLogger(__name__)
os.environ['CUDA_VISIBLE_DEVICES']='... | icij-maude-master | preprocess.py |
from .core import MaudeReport | icij-maude-master | maude/__init__.py |
import numpy as np
class MaudeReport(object):
def __init__(self, row, unique_id):
if type(row.foi_text) is float:
row.foi_text = 'NONE'
for key in row.keys():
setattr(self, key, getattr(row, key))
self.unique_id = unique_id
@property
def key(self):
... | icij-maude-master | maude/core.py |
import re
ABSTAIN = 0
MALE = 1
FEMALE = 2
UNKNOWN = 3
# ================================================================================
#
# Mandy's LFs
#
# ================================================================================
patient_rgx = '(patient| pt | pts |patients|consumer|customer|client)'
de... | icij-maude-master | maude/labelers/gender.py |
from .core import LabelingServer | icij-maude-master | maude/labelers/__init__.py |
import itertools
import numpy as np
from scipy import sparse
from functools import partial
from toolz import partition_all
from joblib import Parallel, delayed
class Distributed(object):
def __init__(self,
num_workers=1,
backend='multiprocessing',
verbose=False)... | icij-maude-master | maude/labelers/core.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.