repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
local-astar | local-astar-master/src/search/local_search.py | from joblib import dump, load, delayed, Parallel
import logging
import os
import numpy as np
from search.exact_search import exact_search
from utils.dag import get_k_steps_neighbors, get_vstructures, get_neighbors, add_to_pdag, \
get_cpdag_from_pdag, get_dag_from_pdag, get_local_info
from util... | 6,678 | 45.381944 | 105 | py |
local-astar | local-astar-master/src/search/priority_queue.py | """
Code modified from:
https://github.com/jmschrei/pomegranate/blob/master/pomegranate/utils.pyx
"""
import heapq
class PriorityQueue:
def __init__(self):
self.n = 0
self.pq = []
self.entries = {}
def __len__(self):
return self.n
def push(self, item, weight):
ent... | 1,024 | 23.404762 | 76 | py |
local-astar | local-astar-master/src/utils/dir.py | """
Code obtained from:
https://github.com/ignavier/golem/blob/main/src/utils/dir.py
"""
from datetime import datetime
import logging
import os
import pathlib
from pytz import timezone
_logger = logging.getLogger(__name__)
def create_dir(output_dir):
"""Create directory.
Args:
output_dir (str): A ... | 838 | 21.675676 | 78 | py |
local-astar | local-astar-master/src/utils/dag.py | import causaldag as cd
import networkx as nx
import numpy as np
def is_dag(B):
"""Check whether B corresponds to a DAG.
Args:
B (numpy.ndarray): [d, d] binary or weighted matrix.
"""
return nx.is_directed_acyclic_graph(nx.DiGraph(B))
def get_skeleton(B):
B_bin = (B != 0).astype(int)
... | 7,787 | 33.30837 | 107 | py |
local-astar | local-astar-master/src/utils/logging.py | """
Code modified from:
https://github.com/ignavier/golem/blob/main/src/utils/logger.py
"""
from datetime import datetime
import logging
import platform
import subprocess
import sys
import psutil
from pytz import timezone, utc
def setup_logger(log_path, level='INFO'):
"""Set up logger.
Args:
log_pat... | 2,396 | 30.539474 | 111 | py |
local-astar | local-astar-master/src/utils/utils.py | """
Code modified from:
https://github.com/ignavier/golem/blob/main/src/utils/utils.py
"""
import random
import matplotlib.pyplot as plt
import numpy as np
from utils.dag import compute_und_accuracy, compute_cpdag_accuracy
def set_seed(seed):
"""Set random seed for reproducibility.
Args:
seed (int)... | 4,555 | 38.964912 | 103 | py |
local-astar | local-astar-master/src/utils/config.py | """
Code modified from:
https://github.com/ignavierng/golem/blob/main/src/utils/config.py
"""
import argparse
import sys
import yaml
def load_yaml_config(path):
"""Load the config file in yaml format.
Args:
path (str): Path to load the config file.
Returns:
dict: config.
"""
wit... | 4,793 | 28.592593 | 107 | py |
local-astar | local-astar-master/src/utils/glasso.py | import numpy as np
from sklearn.covariance import graphical_lasso
def glasso(X, l1_lambda=0.01, max_iter=1000):
cov_emp = np.cov(X.T, bias=False)
_, inv_cov_est = graphical_lasso(cov_emp, alpha=l1_lambda, max_iter=max_iter)
return inv_cov_est
| 257 | 27.666667 | 81 | py |
corrfitter | corrfitter-master/setup.py | # from distutils.command.build_py import build_py
from distutils.core import setup
CORRFITTER_VERSION = open('src/corrfitter/_version.py', 'r').readlines()[0].split("'")[1]
# pypi
with open('README.rst', 'r') as file:
long_description = file.read()
setup(name='corrfitter',
version=CORRFITTER_VERSION,
des... | 1,573 | 38.35 | 89 | py |
corrfitter | corrfitter-master/dataset.py | #!/usr/bin/env python
# encoding: utf-8
"""
dataset.py --- simplified replacement for old module; for legacy purposes only
(use gvar.dataset for new stuff).
"""
# Created by G. Peter Lepage, Cornell University, on 2012-05-22.
# Copyright (c) 2010-2012 G. Peter Lepage.
#
# This program is free software: ... | 6,532 | 29.962085 | 79 | py |
corrfitter | corrfitter-master/avg.py | #! /usr/bin/env python
""" Average dataset files.
Usage:
avg.py file1 file2 ... (for text files)
avg.py file.h5 group1 group2 ... (for hdf5 file)
Returns a table showing averages and standard deviations for all
quantities in the dataset files. (See gvar.dataset.Dataset for
information on file formats.)
"""
... | 859 | 24.294118 | 75 | py |
corrfitter | corrfitter-master/dataset-setup.py | from distutils.core import setup
setup(name='dataset', version='1.0',
description="Reworked dataset module for legacy code. gvar.dataset is better",
py_modules=['dataset']) | 186 | 36.4 | 84 | py |
corrfitter | corrfitter-master/examples/etab-svdcut.py | from __future__ import print_function # makes this work for python2 and 3
import gvar as gv
import corrfitter as cf
def main():
dset = cf.read_dataset('etab.h5', grep='1s0')
s = gv.dataset.svd_diagnosis(dset, models=make_models())
print('svdcut =', s.svdcut)
s.plot_ratio(show=True)
from etab import... | 372 | 22.3125 | 75 | py |
corrfitter | corrfitter-master/examples/etas-Ds-chained.py | from __future__ import print_function # makes this work for python2 and 3
import gvar as gv
import corrfitter as cf
DISPLAYPLOTS = False # display plots at end of fitting
try:
import matplotlib
except ImportError:
DISPLAYPLOTS = False
def main():
data = make_data('etas-Ds.h5')
models = ma... | 3,740 | 33.962617 | 76 | py |
corrfitter | corrfitter-master/examples/Ds-Ds.py | from __future__ import print_function # makes this work for python2 and python3
import collections
import h5py
import gvar as gv
import corrfitter as cf
SHOWPLOTS = False # display plots at end?
SVDCUT = 0.002
try:
import matplotlib
except ImportError:
SHOWPLOTS = False
def main():
data = make_da... | 4,189 | 30.037037 | 79 | py |
corrfitter | corrfitter-master/examples/Ds-Ds-svdcut.py | from __future__ import print_function # makes this work for python2 and 3
import gvar as gv
import corrfitter as cf
def main():
dset = cf.read_dataset('Ds-Ds.h5')
s = gv.dataset.svd_diagnosis(dset, models=make_models())
print('svdcut =', s.svdcut)
s.plot_ratio(show=True)
import importlib
import sys... | 906 | 24.914286 | 75 | py |
corrfitter | corrfitter-master/examples/etab-stab.py | from __future__ import print_function # makes this work for python2 and 3
# use etab.py but with different make_prior
import etab
main = etab.main
etab.DISPLAYPLOTS = False # display plots at end of fits?
def make_prior(N, basis):
return basis.make_prior(nterm=N, keyfmt='etab.{s1}', states=[0, 1, 2])
eta... | 424 | 25.5625 | 75 | py |
corrfitter | corrfitter-master/examples/etas-Ds.py | from __future__ import print_function # makes this work for python2 and 3
import collections
import gvar as gv
import numpy as np
import corrfitter as cf
SHOWPLOTS = True
SVDCUT = 8e-5
def main():
data = make_data('etas-Ds.h5')
fitter = cf.CorrFitter(models=make_models())
p0 = None
for N in [1, 2, ... | 5,395 | 27.855615 | 77 | py |
corrfitter | corrfitter-master/examples/etab-alt-svdcut.py | from __future__ import print_function # makes this work for python2 and 3
import gvar as gv
import corrfitter as cf
def main():
data, basis = make_data('etab.h5')
s = gv.dataset.svd_diagnosis((data, 113), models=make_models())
print('svdcut =', s.svdcut)
s.plot_ratio(show=True)
import importlib
imp... | 566 | 23.652174 | 75 | py |
corrfitter | corrfitter-master/examples/etas.py | from __future__ import print_function # makes this work for python2 and 3
import collections
import gvar as gv
import numpy as np
import corrfitter as cf
def main():
data = make_data(filename='etas.data')
fitter = cf.CorrFitter(models=make_models())
p0 = None
for N in [2, 3, 4]:
print(30 * '... | 2,070 | 29.910448 | 81 | py |
corrfitter | corrfitter-master/examples/etab-alt.py | from __future__ import print_function # makes this work for python2 and 3
import collections
import gvar as gv
import numpy as np
import corrfitter as cf
DISPLAYPLOTS = False # display plots at end of fits?
SOURCES = ['l', 'g', 'd', 'e']
EIG_SOURCES = ['0', '1', '2', '3'] ... | 3,137 | 33.483516 | 76 | py |
corrfitter | corrfitter-master/examples/etas-Ds-svdcut.py | from __future__ import print_function # makes this work for python2 and 3
import gvar as gv
import corrfitter as cf
def main():
dset = cf.read_dataset('etas-Ds.h5')
s = gv.dataset.svd_diagnosis(dset, models=make_models())
print('svdcut =', s.svdcut)
s.plot_ratio(show=True)
# chained fit
mode... | 1,157 | 26.571429 | 75 | py |
corrfitter | corrfitter-master/examples/etas-Ds-marginalize.py | from __future__ import print_function # makes this work for python2 and 3
import gvar as gv
import corrfitter as cf
DISPLAYPLOTS = False # display plots at end of fitting?
try:
import matplotlib
except ImportError:
DISPLAYPLOTS = False
def main():
data = make_data('etas-Ds.h5')
fitter = cf.... | 2,348 | 31.625 | 75 | py |
corrfitter | corrfitter-master/examples/etab.py | from __future__ import print_function # makes this work for python2 and 3
import collections
import gvar as gv
import numpy as np
import corrfitter as cf
SHOWPLOTS = False # display plots at end of fits?
SOURCES = ['l', 'g', 'd', 'e']
KEYFMT = '1s0.{s1}{s2}'
TDATA = range(1, 24)
SVDCUT = 0.007
try:
im... | 3,631 | 29.779661 | 75 | py |
corrfitter | corrfitter-master/src/corrfitter/_version.py | __version__ = '8.2' | 19 | 19 | 19 | py |
corrfitter | corrfitter-master/src/corrfitter/_corrfitter.py | """ corrfitter source code """
# Created by G. Peter Lepage, Cornell University, on 2010-11-26.
# Copyright (c) 2010-2021 G. Peter Lepage.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, eith... | 97,835 | 43.370068 | 113 | py |
corrfitter | corrfitter-master/src/corrfitter/__init__.py | """
This module contains tools that facilitate least-squares fits, as functions
of time ``t``, of simulation (or other statistical) data for 2-point and
3-point correlators of the form::
Gab(t) = <b(t) a(0)>
Gavb(t,T) = <b(T) V(t) a(0)>
where ``T > t > 0``. Each correlator is modeled using |Corr2| for 2-... | 2,490 | 44.290909 | 75 | py |
corrfitter | corrfitter-master/tests/test_corrfitter.py | # Copyright (c) 2017-18 G. Peter Lepage.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version (see <http://www.gnu.org/licenses/>).
#
# This ... | 61,263 | 35.70701 | 98 | py |
corrfitter | corrfitter-master/tests/__init__.py | # empty file -- turns directory into a package so
# 'python -m unittest discover' works. | 104 | 51.5 | 53 | py |
corrfitter | corrfitter-master/doc/source/conf.py | # -*- coding: utf-8 -*-
#
# corrfitter documentation build configuration file, created by
# sphinx-quickstart on Thu Jan 14 23:21:34 2010.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# ... | 6,976 | 32.382775 | 81 | py |
deepgoplus-stability | deepgoplus-stability-master/modified_files/main.py | #!/usr/bin/env python
import os
from threadpoolctl import threadpool_limits, threadpool_info
import click as ck
import numpy as np
import pandas as pd
from tensorflow.keras.models import load_model
from subprocess import Popen, PIPE
import time
from utils import Ontology, NAMESPACES
from aminoacids import to_onehot
im... | 9,185 | 37.596639 | 109 | py |
deepgoplus-stability | deepgoplus-stability-master/modified_files/evaluate_deepgoplus.py | #!/usr/bin/env python
import numpy as np
import pandas as pd
import click as ck
from sklearn.metrics import classification_report
from sklearn.metrics.pairwise import cosine_similarity
import sys
from collections import deque
import time
import logging
from sklearn.metrics import roc_curve, auc, matthews_corrcoef
from... | 10,750 | 33.680645 | 121 | py |
deepgoplus-stability | deepgoplus-stability-master/modified_files/compute_sig_protein.py | import sigdigits
import sys
import numpy as np
if __name__ == '__main__':
xf = sys.argv[-1]
x = np.load(xf, allow_pickle=True)
#ref = np.array([2, -2])
ref = np.load(sys.argv[2], allow_pickle=True)
#print(np.array(ref))
sig_file = open(sys.argv[1], 'w')
for j, r in zip (x.values(), ref... | 2,173 | 44.291667 | 89 | py |
torchTT | torchTT-main/setup.py | from setuptools import setup, Extension
import platform
logo_ascii = """
_ _ _____ _____
| |_ ___ _ __ ___| |_|_ _|_ _|
| __/ _ \| '__/ __| '_ \| | | |
| || (_) | | | (__| | | | | | |
\__\___/|_| \___|_| |_|_| |_|
"""
try:
from torc... | 1,847 | 27.875 | 156 | py |
torchTT | torchTT-main/conf.py | # Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master... | 4,105 | 36.669725 | 107 | py |
torchTT | torchTT-main/examples/random_tt.py | #%% Imports
import torch as tn
import torchtt as tntt
#%% Variance 1.0
x = tntt.randn([30]*5,[1,8,16,16,8,1])
x_full = x.full()
print('Var = ',tn.std(x_full).numpy()**2,' (has to be comparable to 1.0)')
#%% Variance 4.0
x = tntt.randn([30]*5,[1,8,16,16,8,1],var = 4.0)
x_full = x.full()
print('Var = ',tn.std(x_full).... | 708 | 28.541667 | 75 | py |
torchTT | torchTT-main/examples/automatic_differentiation.py | """
# Automatic differentiation
Being based on `pytorch`, `torchtt` can handle automatic differentiation with respect to the TT cores.
"""
#%% Imports
import torch as tn
import torchtt as tntt
#%% First, a function to differentiate is created and some tensors:
N = [2,3,4,5]
A = tntt.randn([(n,n) for n in N],[1]+[2]... | 1,353 | 33.717949 | 203 | py |
torchTT | torchTT-main/examples/system_solvers.py | """
Linear solvers in the TT format
This tutorial addresses solving multilinear systems $\mathsf{Ax}=\mathsf{b}$ in the TT format.
"""
#%% Imports
import torch as tn
import torchtt as tntt
import datetime
#%% Small example
# A random tensor operator $\mathsf{A}$ is created in the TT format. We create a random rig... | 2,835 | 34.898734 | 188 | py |
torchTT | torchTT-main/examples/tensor_completion.py | #%% Imports
import torchtt as tntt
import torch as tn
import numpy as np
import datetime
#%% Preparation
# create a random tensor
N = 20
target = tntt.random([N]*4,[1,4,5,3,1])
Xs = tntt.meshgrid([tn.linspace(0,1,N, dtype = tn.float64)]*4)
target = Xs[0]+1+Xs[1]+Xs[2]+Xs[3]+Xs[0]*Xs[1]+Xs[1]*Xs[2]+tntt.TT(tn.sin(Xs[0... | 2,005 | 28.5 | 138 | py |
torchTT | torchTT-main/examples/basic_nn.py | #!/usr/bin/env python
# coding: utf-8
#%% Tensor Train layers for neural networks
# In this section, the TT layers are introduced.
# Imports:
import torch as tn
import torch.nn as nn
import datetime
import torchtt as tntt
#%% We consider a linear layer $\mathcal{LTT}(\mathsf{x}) = \mathsf{Wx}+\mathsf{b}$ acting on a... | 4,041 | 42.462366 | 534 | py |
torchTT | torchTT-main/examples/mnist_nn.py | #!/usr/bin/env python
# coding: utf-8
#%% Digit recognition using TT neural networks
# The TT layer is applied to the MNIST dataset.
# Imports:
import torch as tn
import torch.nn as nn
import torchtt as tntt
from torch import optim
from torchvision import datasets
from torchvision.transforms import ToTensor
from torch... | 2,759 | 31.470588 | 167 | py |
torchTT | torchTT-main/examples/cuda.py | """
# GPU acceleration
The package `torchtt` can use the built-in GPU acceleration from `pytorch`.
"""
#%% Imports and check if any CUDA device is available.
import datetime
import torch as tn
try:
import torchtt as tntt
except:
print('Installing torchTT...')
# %pip install git+https://github.com/ion-g-i... | 3,398 | 30.472222 | 145 | py |
torchTT | torchTT-main/examples/basic_tutorial.py | """
Basic tutorial
This notebook is a tutorial on how to use the basic functionalities of the `torchtt` package.
"""
#%% Imports
import torch as tn
import torchtt as tntt
#%% Decomposition of a full tensor in TT format
# We now create a 4d `torch.tensor` which we will use later
tens_full = tn.reshape(tn.arange(... | 6,346 | 48.976378 | 491 | py |
torchTT | torchTT-main/examples/cross_interpolation.py | """
# Cross approximation in the TT format
Using the `torchtt.TT` constructor, a TT decomposition of a given tensor can be obtained.
However, in the cases where the entries of the tensor are computed using a given function, building full tensors becomes unfeasible.
It is possible to construct a TT decomposition usin... | 4,130 | 66.721311 | 389 | py |
torchTT | torchTT-main/examples/manifold.py |
import torch as tn
import torchtt as tntt
N = [10,11,12,13,14]
Rt = [1,3,4,5,6,1]
Rx = [1,6,6,6,6,1]
target = tntt.randn(N,Rt).round(0)
func = lambda x: 0.5*(x-target).norm(True)
x0 = tntt.randn(N,Rx)
x =x0.clone()
for i in range(20):
# compute riemannian gradient using AD
gr = tntt.manifold.riemannian... | 746 | 19.189189 | 80 | py |
torchTT | torchTT-main/examples/efficient_linalg.py | """
# AMEN and DMRG for fast TT operations
The torchtt package includes DMRG and AMEN schemes for fast matrix vector product and elementwise inversion in the TT format.
"""
#%% Imports
import torch as tn
import torchtt as tntt
import datetime
#%% Efficient matrix vector product
# When performing the multiplication ... | 3,337 | 42.921053 | 217 | py |
torchTT | torchTT-main/examples/basic_linalg.py | """
# Basic linear algebra in torchTT
This notebook is an introduction into the basic linar algebra operations that can be perfromed using the `torchtt` package.
The basic operations such as +,-,*,@,norm,dot product can be performed between `torchtt.TT` instances without computing the full format by computing the TT ... | 6,009 | 44.530303 | 299 | py |
torchTT | torchTT-main/tests/test_decomposition.py | import unittest
import torchtt as tntt
import torch as tn
import numpy as np
err_rel = lambda t, ref : tn.linalg.norm(t-ref).numpy() / tn.linalg.norm(ref).numpy() if ref.shape == t.shape else np.inf
class TestDecomposition(unittest.TestCase):
basic_dtype = tn.complex128
def test_init(self):
"""
... | 9,242 | 37.836134 | 241 | py |
torchTT | torchTT-main/tests/test_solvers.py | """
Test the multilinear solvers.
"""
import unittest
import torchtt
import torch as tn
import numpy as np
err_rel = lambda t, ref : tn.linalg.norm(t-ref).numpy() / tn.linalg.norm(ref).numpy() if ref.shape == t.shape else np.inf
class TestSolvers(unittest.TestCase):
basic_dtype = tn.complex128... | 4,164 | 41.938144 | 122 | py |
torchTT | torchTT-main/tests/test_algebra_2.py | """
Test the advanced multilinear algebra operations between torchtt.TT objects.
Some operations (matvec for large ranks and elemntwise division) can be only computed using optimization (AMEN and DMRG).
"""
import unittest
import torchtt as tntt
import torch as tn
import numpy as np
err_rel = lambda t, ref : tn.linal... | 3,746 | 31.868421 | 122 | py |
torchTT | torchTT-main/tests/test_ad.py | """
Test all the AD related functions.
@author: ion
"""
import torch as tn
import torchtt
import unittest
err_rel = lambda t, ref : tn.linalg.norm(t-ref).numpy() / tn.linalg.norm(ref).numpy() if ref.shape == t.shape else np.inf
class TestAD(unittest.TestCase):
def test_manifold(self):
"""
Com... | 3,188 | 34.831461 | 151 | py |
torchTT | torchTT-main/tests/test_linalg.py | """
Test the basic multilinear algebra operations between torchtt.TT objects.
"""
import unittest
import torchtt as tntt
import torch as tn
import numpy as np
err_rel = lambda t, ref : (tn.linalg.norm(t-ref).numpy() / tn.linalg.norm(ref).numpy() if tn.linalg.norm(ref).numpy()>0 else tn.linalg.norm(t-ref).numpy() ) if... | 23,011 | 38.00339 | 244 | py |
torchTT | torchTT-main/tests/test_cross.py | """
Test the cross approximation method.
"""
import unittest
import torchtt as tntt
import torch as tn
import numpy as np
err_rel = lambda t, ref : tn.linalg.norm(t-ref).numpy() / tn.linalg.norm(ref).numpy() if ref.shape == t.shape else np.inf
class TestCrossApproximation(unittest.TestCase):
def test_dmrg_... | 1,972 | 36.226415 | 122 | py |
torchTT | torchTT-main/torchtt/_dmrg.py | """
DMRG implementation for fast matvec product.
Inspired by TT-Toolbox from MATLAB.
@author: ion
"""
import torchtt
import torch as tn
from torchtt._decomposition import rank_chop, QR, SVD
import datetime
import opt_einsum as oe
try:
import torchttcpp
_flag_use_cpp = True
except:
import warnings
war... | 16,355 | 42.384615 | 171 | py |
torchTT | torchTT-main/torchtt/_aux_ops.py | """
Additional operations.
@author: ion
"""
import torch as tn
def apply_mask(cores, R, indices):
"""
compute the entries
Args:
cores ([type]): [description]
R ([type]): [description]
indices ([type]): [description]
"""
d = len(cores)
dt = cores[0].dtype
M = len(... | 2,198 | 25.817073 | 135 | py |
torchTT | torchTT-main/torchtt/errors.py | """
Contains the errors used in the `torchtt` package.
"""
class ShapeMismatch(Exception):
"""The shape of the tensors does not match.
This means that the inputs have shapes that do not match.
"""
pass
class RankMismatch(Exception):
"""The TT-ranks do not match.
This means that t... | 720 | 23.033333 | 96 | py |
torchTT | torchTT-main/torchtt/nn.py | """
Implements a basic TT layer for constructing deep TT networks.
"""
import torch as tn
import torch.nn as nn
import torchtt
from ._aux_ops import dense_matvec
from .errors import *
class LinearLayerTT(nn.Module):
"""
Basic class for TT layers. See `Tensorizing Neural Networks <https://arxiv.org/abs/1509.0... | 3,607 | 41.447059 | 222 | py |
torchTT | torchTT-main/torchtt/_extras.py | """
This file implements additional functions that are visible in the module.
"""
import torch as tn
import torch.nn.functional as tnf
from torchtt._decomposition import mat_to_tt, to_tt, lr_orthogonal, round_tt, rl_orthogonal, QR, SVD, rank_chop
from torchtt._division import amen_divide
import numpy as np
import ma... | 37,410 | 37.291709 | 202 | py |
torchTT | torchTT-main/torchtt/manifold.py | """
Manifold gradient module.
"""
import torch as tn
from torchtt._decomposition import mat_to_tt, to_tt, lr_orthogonal, round_tt, rl_orthogonal
from . import TT
from torchtt.errors import *
def _delta2cores(tt_cores, R, Sds, is_ttm = False, ortho = None):
"""
Convert the detla notation to TT.
Implements... | 5,672 | 31.603448 | 138 | py |
torchTT | torchTT-main/torchtt/__init__.py |
r"""
Provides Tensor-Train (TT) decomposition using `pytorch` as backend.
Contains routines for computing the TT decomposition and all the basisc linear algebra in the TT format. Additionally, GPU support can be used thanks to the `pytorch` backend.
It also has linear solvers in TT and cross approximation as well ... | 1,287 | 46.703704 | 264 | py |
torchTT | torchTT-main/torchtt/_decomposition.py | """
Basic decomposition and orthogonalization.
@author: ion
"""
import torch as tn
import numpy as np
def QR(mat):
"""
Compute the QR decomposition. Backend can be changed.
Parameters
----------
mat : tn array
DESCRIPTION.
Returns
-------
Q : the Q matrix
R : t... | 10,713 | 25.324324 | 188 | py |
torchTT | torchTT-main/torchtt/_division.py | """
Elementwise division using AMEN
@author: ion
"""
import torch as tn
import numpy as np
import datetime
from torchtt._decomposition import QR, SVD, rl_orthogonal, lr_orthogonal
from torchtt._iterative_solvers import BiCGSTAB_reset, gmres_restart
import opt_einsum as oe
def local_product(Phi_right, Phi_left, coreA,... | 20,269 | 41.494759 | 203 | py |
torchTT | torchTT-main/torchtt/_tt_base.py | """
This file implements the core TT class.
"""
import torch as tn
import torch.nn.functional as tnf
from torchtt._decomposition import mat_to_tt, to_tt, lr_orthogonal, round_tt, rl_orthogonal, QR, SVD, rank_chop
from torchtt._division import amen_divide
import numpy as np
import math
from torchtt._dmrg import dmrg_... | 64,632 | 42.818983 | 237 | py |
torchTT | torchTT-main/torchtt/_torchtt.py | """
Basic class for TT decomposition.
It contains the base TT class as well as additional functions.
The TT class implements tensors in the TT format as well as tensors operators in TT format. Once in the TT format, linear algebra operations (`+`, `-`, `*`, `@`, `/`) can be performed without resorting to the full forma... | 97,941 | 40.448159 | 297 | py |
torchTT | torchTT-main/torchtt/solvers.py | """
System solvers in the TT format.
"""
import torch as tn
import numpy as np
import torchtt
import datetime
from torchtt._decomposition import QR, SVD, lr_orthogonal, rl_orthogonal
from torchtt._iterative_solvers import BiCGSTAB_reset, gmres_restart
import opt_einsum as oe
from .errors import *
try:
import tor... | 30,074 | 44.022455 | 269 | py |
torchTT | torchTT-main/torchtt/grad.py | """
Adds AD functionality to torchtt.
"""
import torch as tn
from torchtt import TT
def watch(tens, core_indices = None):
"""
Watch the TT-cores of a given tensor.
Necessary for autograd.
Args:
tens (torchtt.TT): the TT-object to be watched.
core_indices (list[int], optional): Th... | 2,852 | 30.01087 | 154 | py |
torchTT | torchTT-main/torchtt/_iterative_solvers.py | """
Contains iteratiove solvers like GMRES and BiCGSTAB
@author: ion
"""
import torch as tn
import datetime
import numpy as np
def BiCGSTAB(Op, rhs, x0, eps=1e-6, nmax = 40):
pass
def BiCGSTAB_reset(Op,rhs,x0,eps=1e-6,nmax=40):
"""
BiCGSTAB solver.
"""
# initial residual
r = rhs - Op.matvec... | 5,472 | 26.094059 | 138 | py |
torchTT | torchTT-main/torchtt/interpolate.py | """
Implements the cross approximation methods (DMRG).
"""
import torch as tn
import numpy as np
import torchtt
import datetime
from torchtt._decomposition import QR, SVD, rank_chop, lr_orthogonal, rl_orthogonal
from torchtt._iterative_solvers import BiCGSTAB_reset, gmres_restart
import opt_einsum as oe
def _LU(M):... | 29,837 | 43.139053 | 399 | py |
torchTT | torchTT-main/torchtt/cpp.py | """
Module for the C++ backend.
"""
import warnings
try:
import torchttcpp
_cpp_available = True
except:
warnings.warn("\x1B[33m\nC++ implementation not available. Using pure Python.\n\033[0m")
_cpp_available = False
def cpp_avaible():
"""
Return True if C++ backend is available.
Re... | 430 | 16.958333 | 92 | py |
plotnine | plotnine-main/tools/visualize_tests.py | #!/usr/bin/env python
#
# This builds a html page of all images from the image comparison tests
# and opens that page in the browser.
#
# $ python tools/visualize_tests.py
#
import argparse
from collections import defaultdict
from pathlib import Path
html_template = """<html><head><style media="screen" type="text/c... | 4,715 | 24.770492 | 78 | py |
plotnine | plotnine-main/tests/test_layers.py | from pathlib import Path
import numpy as np
import pandas as pd
import pytest
from plotnine import aes, geom_path, geom_point, ggplot
from plotnine.exceptions import PlotnineError, PlotnineWarning
from plotnine.layer import Layers, layer
df = pd.DataFrame({"x": range(10), "y": range(10)})
colors = ["red", "green", "... | 3,759 | 26.445255 | 74 | py |
plotnine | plotnine-main/tests/test_geom_quantile.py | import numpy as np
import pandas as pd
from plotnine import aes, geom_point, geom_quantile, ggplot
n = 200 # Should not be too big, affects the test duration
random_state = np.random.RandomState(1234567890)
# points that diverge like a point flash-light
df = pd.DataFrame(
{"x": np.arange(n), "y": np.arange(n) * ... | 718 | 27.76 | 77 | py |
plotnine | plotnine-main/tests/test_geom_path_line_step.py | import numpy as np
import pandas as pd
import pytest
from plotnine import (
aes,
arrow,
facet_grid,
geom_line,
geom_path,
geom_point,
geom_step,
ggplot,
)
from plotnine.exceptions import PlotnineWarning
# steps with diagonals at the ends
df = pd.DataFrame(
{
"x": [1, 2, 3, ... | 3,187 | 21.450704 | 79 | py |
plotnine | plotnine-main/tests/test_stat_summary.py | import numpy as np
import pandas as pd
import pytest
from plotnine import aes, geom_point, ggplot, stat_summary
random_state = np.random.RandomState(1234567890)
df = pd.DataFrame(
{
"x": list("aaaaabbbbcccccc"),
"y": [1, 2, 3, 4, 5, 1.5, 1.5, 6, 6, 5, 5, 5, 5, 5, 5],
}
)
def test_mean_cl_bo... | 1,808 | 21.333333 | 77 | py |
plotnine | plotnine-main/tests/test_geom_rug.py | import numpy as np
import pandas as pd
from plotnine import aes, coord_flip, geom_rug, ggplot
n = 4
seq = np.arange(1, n + 1)
df = pd.DataFrame(
{
"x": seq,
"y": seq,
"z": seq,
}
)
def test_aesthetics():
p = (
ggplot(df)
+ geom_rug(aes("x", "y"), size=2)
+... | 805 | 21.388889 | 79 | py |
plotnine | plotnine-main/tests/test_geom_errorbar_errorbarh.py | import pandas as pd
from plotnine import aes, geom_errorbar, geom_errorbarh, ggplot
n = 4
df = pd.DataFrame(
{
"x": [1] * n,
"ymin": range(1, 2 * n + 1, 2),
"ymax": range(2, 2 * n + 2, 2),
"z": range(n),
}
)
def test_errorbar_aesthetics():
p = (
ggplot(df, aes(ymi... | 1,104 | 26.625 | 69 | py |
plotnine | plotnine-main/tests/test_position.py | import string
import numpy as np
import pandas as pd
import pytest
from plotnine import (
aes,
after_stat,
geom_bar,
geom_boxplot,
geom_col,
geom_jitter,
geom_point,
geom_rect,
geom_text,
ggplot,
position_dodge,
position_dodge2,
position_jitter,
position_jitterd... | 5,622 | 23.880531 | 79 | py |
plotnine | plotnine-main/tests/test_ggsave.py | import warnings
from pathlib import Path
import matplotlib.pyplot as plt
import pandas as pd
import pytest
from plotnine import (
aes,
facet_wrap,
geom_point,
geom_text,
ggplot,
ggsave,
theme_xkcd,
)
from plotnine.data import mtcars
from plotnine.exceptions import PlotnineError, PlotnineWa... | 4,239 | 27.648649 | 76 | py |
plotnine | plotnine-main/tests/test_geom_hline.py | import pandas as pd
import pytest
from plotnine import aes, geom_hline, geom_point, ggplot
from plotnine.exceptions import PlotnineError, PlotnineWarning
df = pd.DataFrame(
{"yintercept": [1, 2], "x": [-1, 1], "y": [0.5, 3], "z": range(2)}
)
def test_aesthetics():
p = (
ggplot(df)
+ geom_poi... | 1,134 | 25.395349 | 73 | py |
plotnine | plotnine-main/tests/test_geom_text_label.py | import os
import numpy as np
import pandas as pd
import pytest
from plotnine import (
aes,
geom_label,
geom_point,
geom_text,
ggplot,
scale_size_continuous,
scale_y_continuous,
)
from plotnine.data import mtcars
from plotnine.exceptions import PlotnineWarning
is_CI = os.environ.get("CI") ... | 3,948 | 24.642857 | 79 | py |
plotnine | plotnine-main/tests/test_geom_linerange_pointrange.py | import numpy as np
import pandas as pd
from plotnine import aes, geom_linerange, geom_pointrange, ggplot
n = 4
df = pd.DataFrame(
{
"x": range(n),
"y": np.arange(n) + 0.5,
"ymin": range(n),
"ymax": range(1, n + 1),
"z": range(n),
}
)
def test_linerange_aesthetics():
... | 1,437 | 28.346939 | 79 | py |
plotnine | plotnine-main/tests/test_stat_summary_bin.py | import numpy as np
import pandas as pd
from plotnine import aes, ggplot, stat_summary_bin
df = pd.DataFrame(
{
"xd": list("aaaaabbbbcccccc"),
"xc": range(0, 15),
"y": [1, 2, 3, 4, 5, 1.5, 1.5, 6, 6, 5, 5, 5, 5, 5, 5],
}
)
def test_discrete_x():
p = ggplot(df, aes("xd", "y")) + st... | 636 | 20.965517 | 75 | py |
plotnine | plotnine-main/tests/test_geom_smooth.py | import numpy as np
import pandas as pd
import pytest
import statsmodels.api as sm
from plotnine import (
aes,
coord_trans,
geom_point,
geom_smooth,
ggplot,
stat_smooth,
)
from plotnine.exceptions import PlotnineWarning
random_state = np.random.RandomState(1234567890)
n = 100
# linear relation... | 6,945 | 22.869416 | 79 | py |
plotnine | plotnine-main/tests/test_stat_ellipse.py | import numpy as np
import numpy.testing as npt
import pandas as pd
from plotnine import aes, geom_point, ggplot, stat_ellipse
from plotnine.stats.stat_ellipse import cov_trob
df = pd.DataFrame(
{
"x": [1, 2, 3, 4, 5],
"y": [1, 4, 3, 6, 7],
"z": [3, 4, 3, 2, 6],
}
)
def test_ellipse()... | 1,681 | 24.104478 | 58 | py |
plotnine | plotnine-main/tests/conftest.py | import inspect
import locale
import shutil
import types
import warnings
from copy import deepcopy
from pathlib import Path
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.testing.compare import compare_images
from plotnine import ggplot, theme
TOLERANCE = 2 # Default tolerance for the tests... | 6,397 | 26.938865 | 77 | py |
plotnine | plotnine-main/tests/test_geom_count.py | import pandas as pd
from plotnine import aes, geom_count, ggplot
df = pd.DataFrame(
{
"x": list("aaaaaaaaaabbbbbbbbbbcccccccccc"),
"y": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
... | 952 | 14.883333 | 52 | py |
plotnine | plotnine-main/tests/test_geom_rect_tile.py | import numpy as np
import pandas as pd
from plotnine import (
aes,
coord_trans,
geom_point,
geom_rect,
geom_tile,
ggplot,
labs,
)
n = 4
df = pd.DataFrame(
{
"xmin": range(1, n * 2, 2),
"xmax": range(2, n * 2 + 1, 2),
"ymin": [1] * n,
"ymax": [2] * n,
... | 3,800 | 21.625 | 77 | py |
plotnine | plotnine-main/tests/test_facet_labelling.py | from plotnine import (
aes,
as_labeller,
facet_grid,
facet_wrap,
geom_point,
ggplot,
labeller,
)
from plotnine.data import mtcars
def number_to_word(n):
lst = [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven"... | 2,339 | 19.526316 | 66 | py |
plotnine | plotnine-main/tests/test_geom_density.py | import numpy as np
import pandas as pd
import pytest
from plotnine import aes, geom_density, ggplot, lims
from plotnine.exceptions import PlotnineWarning
n = 6 # Some even number greater than 2
# ladder: 0 1 times, 1 2 times, 2 3 times, ...
df = pd.DataFrame(
{
"x": np.repeat(range(n + 1), range(n + 1))... | 1,557 | 26.333333 | 79 | py |
plotnine | plotnine-main/tests/test_animation.py | import matplotlib.pyplot as plt
import pytest
from plotnine import labs, lims, qplot, theme_minimal
from plotnine.animation import PlotnineAnimation
from plotnine.exceptions import PlotnineError
plt.switch_backend("Agg") # TravisCI needs this
x = [1, 2, 3, 4, 5]
y = [1, 2, 3, 4, 5]
colors = [[1, 2, 3, 4, 5], [2, 3,... | 2,723 | 26.24 | 77 | py |
plotnine | plotnine-main/tests/test_geom_boxplot.py | import numpy as np
import pandas as pd
from plotnine import (
aes,
coord_flip,
geom_boxplot,
ggplot,
position_nudge,
)
n = 4
m = 10
df = pd.DataFrame(
{
"x": np.repeat([chr(65 + i) for i in range(n)], m),
"y": (
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+ [-2, 2, ... | 2,833 | 25.485981 | 73 | py |
plotnine | plotnine-main/tests/test_geom_density_2d.py | import pandas as pd
from plotnine import (
aes,
after_stat,
geom_density_2d,
geom_point,
ggplot,
lims,
scale_size_radius,
stat_density_2d,
)
n = 20
adj = n // 4
df = pd.DataFrame({"x": range(n), "y": range(n)})
p0 = ggplot(df, aes("x", "y")) + lims(x=(-adj, n + adj), y=(-adj, n + adj... | 877 | 18.086957 | 75 | py |
plotnine | plotnine-main/tests/test_geom_raster.py | import numpy as np
import pandas as pd
import pytest
from plotnine import aes, geom_raster, ggplot
from plotnine.exceptions import PlotnineWarning
def _random_grid(n, m=None, seed=123):
if m is None:
m = n
prg = np.random.RandomState(seed)
g = prg.uniform(size=n * m)
x, y = np.meshgrid(range(... | 1,345 | 24.396226 | 63 | py |
plotnine | plotnine-main/tests/test_stat.py | import numpy as np
import pytest
from plotnine import aes, geom_bar, ggplot
from plotnine.data import mtcars
from plotnine.exceptions import PlotnineError, PlotnineWarning
from plotnine.geoms.geom import geom
from plotnine.stats.stat import stat
def test_stat_basics():
class stat_abc(stat):
DEFAULT_PARAM... | 2,504 | 27.465909 | 79 | py |
plotnine | plotnine-main/tests/test_doctools.py | from plotnine import position_stack
from plotnine.doctools import document
from plotnine.geoms.geom import geom
from plotnine.scales.scale import scale
from plotnine.stats.stat import stat
@document
class scale_expand(scale):
"""
Expand
Parameters
----------
base_param_1 : int or float
Ba... | 2,539 | 20.344538 | 76 | py |
plotnine | plotnine-main/tests/test_binning.py | import numpy as np
from plotnine.scales import scale_x_continuous, scale_x_discrete
from plotnine.stats.binning import (
_adjust_breaks,
breaks_from_bins,
breaks_from_binwidth,
fuzzybreaks,
)
def test_breaks_from_bins():
n = 10
x = list(range(n))
limits = min(x), max(x)
breaks = break... | 3,582 | 26.143939 | 72 | py |
plotnine | plotnine-main/tests/test_geom_segment.py | import pandas as pd
from plotnine import aes, arrow, geom_segment, ggplot
n = 4
# stepped horizontal line segments
df = pd.DataFrame(
{
"x": range(1, n + 1),
"xend": range(2, n + 2),
"y": range(n, 0, -1),
"yend": range(n, 0, -1),
"z": range(1, n + 1),
}
)
def test_ae... | 1,236 | 24.244898 | 72 | py |
plotnine | plotnine-main/tests/test_scale_linetype.py | import pandas as pd
from plotnine import aes, geom_line, ggplot, scale_linetype_manual
def test_scale_linetype_manual_tuples():
# linetype_manual accepts tuples as mapping results
# this must be tested specifically.
df = pd.DataFrame(
{
"x": [0, 1, 0, 1, 0, 1],
"y": [0, 1,... | 1,218 | 26.704545 | 76 | py |
plotnine | plotnine-main/tests/test_geom_dotplot.py | import pandas as pd
from plotnine import aes, geom_dotplot, ggplot
df = pd.DataFrame({"x": [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]})
def test_dotdensity():
p = ggplot(df, aes("x")) + geom_dotplot(bins=15)
assert p == "dotdensity"
def test_histodot():
p = ggplot(df, aes("x")) + geom_dotplot(bins=15, method="hi... | 1,950 | 22.506024 | 76 | py |
plotnine | plotnine-main/tests/test_geom_polygon.py | import pandas as pd
from plotnine import aes, geom_polygon, ggplot
df = pd.DataFrame(
{
"x": ([1, 2, 3, 2] + [5, 6, 7] + [9, 9, 10, 11, 11, 10]),
"y": ([2, 3, 2, 1] + [1, 3, 1] + [1.5, 2.5, 3, 2.5, 1.5, 1]),
"z": ([1] * 4 + [2] * 3 + [3] * 6),
}
)
def test_aesthetics():
p = (
... | 1,188 | 26.651163 | 72 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.