python_code
stringlengths
0
4.04M
repo_name
stringlengths
7
58
file_path
stringlengths
5
147
#!/usr/bin/env python3 # 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 sys from aepsych.config import Config from .min_asks import MinAsks from .min_total_outcome_...
aepsych-main
aepsych/generators/completion_criterion/__init__.py
#!/usr/bin/env python3 # 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 typing import Any, Dict from aepsych.config import Config, ConfigurableMixin from ax.modelbrid...
aepsych-main
aepsych/generators/completion_criterion/min_total_outcome_occurrences.py
#!/usr/bin/env python3 # 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 typing import Any, Dict from aepsych.config import Config, ConfigurableMixin from ax.core.base_...
aepsych-main
aepsych/generators/completion_criterion/min_total_tells.py
#!/usr/bin/env python3 # 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 sys from ..config import Config from .factory import ( default_mean_covar_factory, mo...
aepsych-main
aepsych/factory/__init__.py
#!/usr/bin/env python3 # 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 configparser import NoOptionError from typing import Optional, Tuple import gpytorch import tor...
aepsych-main
aepsych/factory/factory.py
#!/usr/bin/env python3 # coding: utf-8 # ### Semi-parametric psychophysical model tutorial # # This tutorial will demonstrate how to fit the semiparametric psychophysical models described in [Keeley et al., 2023](https://arxiv.org/abs/2302.01187). # # The semi-parametric model uses a conventional parametric form fo...
aepsych-main
website/static/files/Semi_P_tutorial.py
#!/usr/bin/env python3 # coding: utf-8 # # Data Collection and Analysis Using AEPsych # # This tutorial serves as a complete example on how to collect and analyze data from perceptual experiments using AEPsych. For more information on AEPsych, refer to the documentation in the [GitHub repository](https://github.com/f...
aepsych-main
website/static/files/data_collection_analysis_tutorial.py
#!/usr/bin/env python3 # 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 unittest from copy import deepcopy import numpy as np import torch from aepsych.config import...
aepsych-main
tests/test_utils.py
#!/usr/bin/env python3 # 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 unittest from unittest.mock import MagicMock import numpy as np import torch from aepsych.acq...
aepsych-main
tests/test_strategy.py
#!/usr/bin/env python3 # 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 unittest import torch from aepsych.benchmark.test_functions import make_songetal_testfun from...
aepsych-main
tests/test_bench_testfuns.py
#!/usr/bin/env python3 # 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 json import os import shutil import unittest import uuid from configparser import DuplicateOpt...
aepsych-main
tests/test_db.py
#!/usr/bin/env python3 # 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 unittest from itertools import product import numpy as np import torch from aepsych.acquisiti...
aepsych-main
tests/test_lookahead.py
#!/usr/bin/env python3 # 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.
aepsych-main
tests/__init__.py
#!/usr/bin/env python3 # 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 unittest import gpytorch import numpy as np from aepsych.config import Config from aepsych.fa...
aepsych-main
tests/test_mean_covar_factories.py
#!/usr/bin/env python3 # 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 scipy.stats import norm def f_1d(x, mu=0): """ latent is just a gau...
aepsych-main
tests/common.py
#!/usr/bin/env python3 # 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 random import time import unittest import numpy as np import torch from aepsych.ben...
aepsych-main
tests/test_benchmark.py
#!/usr/bin/env python3 # 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 json import os import unittest import uuid import torch from aepsych.acquisition import EAVC,...
aepsych-main
tests/test_config.py
#!/usr/bin/env python3 # 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 unittest import torch from aepsych.likelihoods import OrdinalLikelihood from gpytorch.test.ba...
aepsych-main
tests/test_likelihoods.py
#!/usr/bin/env python3 # 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 unittest import uuid import torch from aepsych.server import AEPsychServer from ae...
aepsych-main
tests/test_multioutcome.py
#!/usr/bin/env python3 # 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 math import os import unittest import uuid import numpy as np import torch from aepsych.conf...
aepsych-main
tests/test_ax_integration.py
#!/usr/bin/env python3 # 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. """ These tests check that the server can handle different experiments (multi/single stimuli, multi/s...
aepsych-main
tests/test_integration.py
#!/usr/bin/env python3 # 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.
aepsych-main
tests/acquisition/__init__.py
#!/usr/bin/env python3 # 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 unittest import numpy as np import torch from aepsych.acquisition.lse import MCLevelSetEstima...
aepsych-main
tests/acquisition/test_lse.py
#!/usr/bin/env python3 # 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 unittest import numpy as np import torch from aepsych.acquisition.mutual_information import (...
aepsych-main
tests/acquisition/test_mi.py
#!/usr/bin/env python3 # 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 unittest from itertools import product import numpy as np import torch from aepsych.acquisiti...
aepsych-main
tests/acquisition/test_objective.py
#!/usr/bin/env python3 # 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 from aepsych.acquisition.monotonic_rejection import MonotonicMCLSE from aepsych.acquisit...
aepsych-main
tests/acquisition/test_monotonic.py
#!/usr/bin/env python3 # 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 from aepsych.acquisition.rejection_sampler import RejectionSampler from aepsych.models.d...
aepsych-main
tests/acquisition/test_rejection_sampler.py
#!/usr/bin/env python3 # 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.
aepsych-main
tests/server/__init__.py
#!/usr/bin/env python3 # 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 json import logging import select import unittest import uuid from unittest.mock import MagicM...
aepsych-main
tests/server/test_server.py
#!/usr/bin/env python3 # 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 unittest from aepsych.config import Config from ..test_server import BaseServerTestCase, dum...
aepsych-main
tests/server/message_handlers/test_handle_get_config.py
#!/usr/bin/env python3 # 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.
aepsych-main
tests/server/message_handlers/__init__.py
#!/usr/bin/env python3 # 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 unittest from unittest.mock import MagicMock from ..test_server import BaseServerTestCase c...
aepsych-main
tests/server/message_handlers/test_handle_exit.py
#!/usr/bin/env python3 # 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 unittest from ..test_server import BaseServerTestCase, dummy_config class QueryHandlerTestC...
aepsych-main
tests/server/message_handlers/test_query_handlers.py
#!/usr/bin/env python3 # 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 unittest from ..test_server import BaseServerTestCase, dummy_config class StratCanModelTest...
aepsych-main
tests/server/message_handlers/test_can_model.py
#!/usr/bin/env python3 # 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 unittest from ..test_server import BaseServerTestCase, dummy_config class ResumeTestCase(Ba...
aepsych-main
tests/server/message_handlers/test_handle_finish_strategy.py
#!/usr/bin/env python3 # 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 unittest from unittest.mock import MagicMock from ..test_server import BaseServerTestCase, du...
aepsych-main
tests/server/message_handlers/test_tell_handlers.py
#!/usr/bin/env python3 # 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 unittest import numpy as np import torch from sklearn.datasets import make_classification fr...
aepsych-main
tests/models/test_utils.py
#!/usr/bin/env python3 # 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 unittest import torch # run on single threads to keep us from deadlocking weirdly ...
aepsych-main
tests/models/test_monotonic_projection_gp.py
#!/usr/bin/env python3 # 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 unittest import numpy as np import torch from aepsych.generators import SobolGenera...
aepsych-main
tests/models/test_multitask_regression.py
#!/usr/bin/env python3 # 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 unittest import uuid import numpy as np import numpy.testing as npt import torch fr...
aepsych-main
tests/models/test_gp_regression.py
#!/usr/bin/env python3 # 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.
aepsych-main
tests/models/__init__.py
#!/usr/bin/env python3 # 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 unittest import numpy as np import numpy.testing as npt import torch from aepsych.acquisitio...
aepsych-main
tests/models/test_semi_p.py
#!/usr/bin/env python3 # 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 from aepsych.kernels.rbf_partial_grad import RBFKernelPartialObsGrad from aepsych.means....
aepsych-main
tests/models/test_derivative_gp.py
#!/usr/bin/env python3 # 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 unittest import numpy as np import numpy.testing as npt import torch from aepsych.likelihoods...
aepsych-main
tests/models/test_variational_gp.py
#!/usr/bin/env python3 # 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 logging import unittest import uuid import numpy as np import numpy.testing as npt import tor...
aepsych-main
tests/models/test_pairwise_probit.py
#!/usr/bin/env python3 # 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 torch # run on single threads to keep us from deadlocking weirdly in CI if "CI" in...
aepsych-main
tests/models/test_monotonic_rejection_gp.py
#!/usr/bin/env python3 # 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 unittest import numpy as np import torch from botorch.fit import fit_gpytorch_mll from gpytor...
aepsych-main
tests/models/test_model_query.py
#!/usr/bin/env python3 # 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 unittest import torch # run on single threads to keep us from deadlocking weirdly ...
aepsych-main
tests/models/test_gp_classification.py
#!/usr/bin/env python3 # 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 time import unittest import numpy as np import torch from aepsych.acquisition import MCLevelS...
aepsych-main
tests/generators/test_optimize_acqf_generator.py
#!/usr/bin/env python3 # 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 unittest import numpy as np import numpy.testing as npt from aepsych.config import Config fro...
aepsych-main
tests/generators/test_random_generator.py
#!/usr/bin/env python3 # 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 unittest from aepsych.config import Config from aepsych.generators.completion_criterion impor...
aepsych-main
tests/generators/test_completion_criteria.py
#!/usr/bin/env python3 # 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 unittest from unittest.mock import MagicMock import numpy as np import torch from aepsych.acq...
aepsych-main
tests/generators/test_epsilon_greedy_generator.py
#!/usr/bin/env python3 # 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.
aepsych-main
tests/generators/__init__.py
#!/usr/bin/env python3 # 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 unittest import numpy as np import numpy.testing as npt import torch from aepsych.config impo...
aepsych-main
tests/generators/test_sobol_generator.py
#!/usr/bin/env python3 # 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 unittest import numpy as np import numpy.testing as npt from aepsych.config import Config fro...
aepsych-main
tests/generators/test_manual_generator.py
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. All Rights Reserved # Configuration file for the Sphinx documentation builder. # # This file does only contain a selection of the most common options. For a # full list see the documentation: # http://www.sphinx-doc.org/en/master/config # Th...
aepsych-main
sphinx/source/conf.py
#!/usr/bin/env python3 # 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 datetime import datetime import numpy as np constants = { "savefolder": "./databases/", ...
aepsych-main
examples/contrast_discrimination_psychopy/experiment_config.py
#!/usr/bin/env python3 # 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 experiment_config import numpy as np import torch from aepsych_client import AEPsychClient fro...
aepsych-main
examples/contrast_discrimination_psychopy/experiment.py
#!/usr/bin/env python3 # 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 import pyglet from psychopy import core, event from psychopy.visual import Window ...
aepsych-main
examples/contrast_discrimination_psychopy/helpers.py
#!/usr/bin/env python3 # 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. # we have pretty verbose messaging by default, suppress that here import logging import warnings war...
aepsych-main
pubs/owenetal/code/benchmark_threshold.py
#!/usr/bin/env python3 # 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 copy import copy import matplotlib.pyplot as plt import numpy as np import torch from aepsych....
aepsych-main
pubs/owenetal/code/stratplots.py
#!/usr/bin/env python3 # 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 gpytorch import matplotlib.pyplot as plt import numpy as np import seaborn as sns import torch...
aepsych-main
pubs/owenetal/code/prior_plots.py
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the scripts directory. from __future__ import annotations import argparse import json import os import nbformat from bs4 import BeautifulSoup from nbconver...
aepsych-main
scripts/parse_tutorials.py
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the scripts directory. from __future__ import annotations import argparse import os from bs4 import BeautifulSoup #The base_url must match the base url in...
aepsych-main
scripts/parse_sphinx.py
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved. from __future__ import annotations import argparse import json import os import shutil import nbformat from bs4 import BeautifulSoup from nbconvert import HTMLExporter TEMPLATE = """const CWD = process.cwd(); const Rea...
aepsych-main
scripts/parse_demos.py
from setuptools import find_packages, setup from os.path import basename, splitext from glob import glob setup(name='smallfry', version='0.1', description='Code for smallfry.', packages=find_packages("src"), package_dir={"": "src"}, py_modules=[splitext(basename(path))[0] for path in glob...
smallfry-master
setup.py
from quant_embedding import compress_long_mat from quant_embedding import decompress_long_mat from quant_embedding import QuantEmbedding from quant_embedding import quantize_embed import compress from unittest import TestCase import torch import numpy as np import logging import sys logging.basicConfig(stream=sys.stdou...
smallfry-master
src/smallfry/quant_embedding_test.py
import torch import torch.nn as nn import torch.nn.functional as F import numpy as np import math from smallfry import compress import logging import sys, os LONG_BITS = 64 def fix_randomness(seed): np.random.seed(seed) use_cuda = torch.cuda.is_available() torch.manual_seed(seed) if use_cuda: ...
smallfry-master
src/smallfry/quant_embedding.py
import os import sys import socket import json import datetime import logging import pathlib import time import random import subprocess import argparse import numpy as np import getpass def load_embeddings(path): """ Loads a GloVe or FastText format embedding at specified path. Returns a vector of string...
smallfry-master
src/smallfry/utils.py
import os import logging import math import time import pathlib import traceback import numpy as np from smallfry import utils def compress_uniform(X, bit_rate, adaptive_range=False, stochastic_round=False, skip_quantize=False): ''' This function compresses an embedding matrix using uniform quantizatio...
smallfry-master
src/smallfry/compress.py
from utils import * import pickle as pkl import datetime, os class ModelParams: def __init__(self, dataset_name, transform, test, log_path, input_size, layer_size, out_size, num_layers, loss, r, steps, batch_size, lr, mom, init_type, class_type, learn_corner, n_diag_learned, ini...
structured-nets-master
tensorflow/model_params.py
import tensorflow as tf from utils import * import numpy as np from scipy.linalg import solve_sylvester import time from krylov import * def eigendecomp(A): d, P = tf.self_adjoint_eig(A) return P, tf.diag(d), tf.matrix_inverse(P) def general_recon(G, H, A, B): P,D_A, Pinv = eigendecomp(A) Q, D_B, Qin...
structured-nets-master
tensorflow/reconstruction.py
import numpy as np import os import tensorflow as tf from utils import * from reconstruction import * from model import * def vandermonde_like(dataset, params, test_freq=100, verbose=False): # A is learned, B is fixed B_vand = gen_Z_f(params.layer_size, 0).T f_V = 0 # Create the model x = tf.placeholder(tf.float...
structured-nets-master
tensorflow/fixed_operators.py
import tensorflow as tf import io,os import matplotlib matplotlib.use('agg') import matplotlib.pyplot as plt import sys sys.path.insert(0, '../tensorflow/') from utils import * from PIL import Image import numpy as np import time # One image with params.num_pred_plot: image, caption - actual and predicted # Here assum...
structured-nets-master
tensorflow/visualize.py
from scipy.sparse import diags import numpy as np import tensorflow as tf import functools from reconstruction import * from utils import * from krylov import * def check_rank(sess, x, y_, batch_xs, batch_ys, params, model): if not params.check_disp: return if params.class_type in ['unconstrained', '...
structured-nets-master
tensorflow/model.py
from tensorflow.examples.tutorials.mnist import input_data import numpy as np import os,sys,h5py import scipy.io as sio from scipy.linalg import solve_sylvester import pickle as pkl from sklearn.preprocessing import OneHotEncoder # sys.path.insert(0, '../../../../') from utils import * class Dataset: # here n is t...
structured-nets-master
tensorflow/dataset.py
from scipy.linalg import toeplitz, circulant, solve_sylvester from scipy.sparse import diags import numpy as np import tensorflow as tf import time, subprocess import functools def kth_diag_indices(A, k): rows, cols = np.diag_indices_from(A) if k < 0: return rows[-k:], cols[:k] elif k > 0: return rows[:-k], col...
structured-nets-master
tensorflow/utils.py
import numpy as np from scipy.sparse import diags import tensorflow as tf import functools def identity_mult_fn(v, n): return v # Multiplication by (Z_{f,v} + diag(d))^T def circ_diag_transpose_mult_fn(v_f, d, x, n): #sess = tf.InteractiveSession() #tf.initialize_all_variables().run() #print sess.ru...
structured-nets-master
tensorflow/krylov.py
import numpy as np import tensorflow as tf from utils import * from reconstruction import * from krylov import * import functools import time, os # Only an approximate reconstruction. def tridiagonal_corner(dataset, params, test_freq=100, verbose=False): # Create the model x = tf.placeholder(tf.float64, [None, param...
structured-nets-master
tensorflow/learned_operators.py
""" Compare methods in parallel, spawning separate thread for each. """ import sys, os, datetime import pickle as pkl sys.path.insert(0, '../../') # from optimize import optimize from utils import * from model_params import ModelParams from dataset import Dataset import argparse import thread def create_command(args,...
structured-nets-master
tensorflow/compare_parallel.py
import numpy as np import os #os.environ["CUDA_VISIBLE_DEVICES"]="-1" import tensorflow as tf import pickle as pkl from utils import * from reconstruction import * from visualize import visualize from model import * import time import logging def restore_from_checkpoint(dataset, params, sess, saver, x, y_, loss, accur...
structured-nets-master
tensorflow/optimize_tf.py
""" Compare methods and hyperparameter settings sequentially. """ import sys, os, datetime import pickle as pkl # sys.path.insert(0, '../') import argparse import threading import logging import numpy as np from optimize_tf import optimize_tf from utils import * from model_params import ModelParams from dataset impor...
structured-nets-master
tensorflow/compare.py
import sys sys.path.insert(0, '../') from reconstruction import * from model_params import ModelParams from utils import * from krylov import * from scipy.linalg import toeplitz import numpy as np def test_circ_sparsity(n): # Generate Toeplitz matrix A = gen_Z_f(n, 1).T B = gen_Z_f(n, -1) M = toeplitz(np.random.r...
structured-nets-master
tensorflow/tests/test_reconstruction.py
""" Computes projections onto various classes. """ import numpy as np from scipy.linalg import toeplitz def kth_diag_indices(A, k): rows, cols = np.diag_indices_from(A) if k < 0: return rows[-k:], cols[:k] elif k > 0: return rows[:-k], cols[k:] else: return rows, cols # Project...
structured-nets-master
scripts/misc/projections.py
import pickle import numpy as np import matplotlib.pyplot as plt arrays = pickle.load(open('mnist_noise_toep_dr2_0.pkl', 'rb'), encoding='bytes') G_toeplitz, H_toeplitz, W_toeplitz = [arrays[key] for key in [b'G', b'H', b'W']] arrays = pickle.load(open('mnist_noise_circ_0.pkl', 'rb'), encoding='bytes') A_subdiag, B_su...
structured-nets-master
scripts/analysis/analysis.py
import matplotlib.pyplot as plt import numpy as np # from matplotlib import rc # # activate latex text rendering # rc('text', usetex=True) def update_minmax(mini, maxi, a): return min(mini, min(a)), max(maxi, max(a)) def normalize(params, n): return [float(p)/n**2 for p in params] # return [n**2/float(p)...
structured-nets-master
scripts/visualizations/acc_vs_params.py
import matplotlib.pyplot as plt import pickle as pkl import numpy as np n_iters = 20000 step = 100 n = 50 mom = 0.99 prefix = '../../results/mom' xs = np.arange(0, n_iters, step) trid_corner = pkl.load(open(prefix + str(mom) + '_' + 'toeplitz_tridiagonal_corner_losses_' + str(n) + '.p', 'rb')) circ = pkl.load(open(pr...
structured-nets-master
scripts/visualizations/make_plot.py
import numpy as np import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import pickle as pkl # MNIST variants # idx = 1 # # data_loc = '/dfs/scratch1/thomasat/datasets/mnist_noise/mnist_noise_variations_all_' + str(idx) + '.amat' # data_loc = '/dfs/scratch1/thomasat/datasets/mnist_bg_rot/mnist_all_...
structured-nets-master
scripts/visualizations/show_example.py
import os os.environ["MKL_NUM_THREADS"] = "1" os.environ["NUMEXPR_NUM_THREADS"] = "1" os.environ["OMP_NUM_THREADS"] = "1" import numpy as np import matplotlib.pyplot as plt plt.switch_backend('agg') from timeit import default_timer as timer import timeit import pickle as pkl import matplotlib.patches as mpatches impor...
structured-nets-master
scripts/visualizations/plot_speed.py
import matplotlib.pyplot as plt # For MNIST noise fixed_xs = [10202, 11770, 13338, 14906] lowrank = [0.2403, 0.377, 0.4577, 0.546] lowrank_std = [0.0184407, 0.004, 0.00334066, 0.006] toep = [0.62525, 0.681, 0.6758, 0.712] toep_std = [0.00125, 0.017, 0.0227389, 0.012] hank = [0.66175, 0.696667, 0.70475, 0.704] hank_std...
structured-nets-master
scripts/visualizations/make_params_plot_iclr.py
import numpy as np import matplotlib.pyplot as plt # name = 'mnist_sd_r4' names = ['bgrot_sd_r1', 'bgrot_sd_r4', 'bgrot_sd_r16'] # names = ['patch2_sd_r8', 'patch_sd_r8_best'] ranks = [1, 1, 4, 4, 16, 16] for name in names: # for name in [names[2]]: n = 1024 # r = 4 G = np.loadtxt(name+'_G') H = np.lo...
structured-nets-master
scripts/visualizations/fat.py
# Modified from https://github.com/ndrplz/small_norb/blob/master/smallnorb/dataset.py import struct import numpy as np #import matplotlib.pyplot as plt import scipy.misc from tqdm import tqdm from os import makedirs from os.path import join from os.path import exists from itertools import groupby #names = ['train1', ...
structured-nets-master
scripts/data/norb.py
import numpy as np import pickle as pkl from sklearn.preprocessing import OneHotEncoder from data_utils import normalize_data, apply_normalization # Download from http://www.iro.umontreal.ca/~lisa/twiki/bin/view.cgi/Public/DeepVsShallowComparisonICML2007 def process_data(data): X = data[:, :-1] Y = np.expand_...
structured-nets-master
scripts/data/preprocess_convex.py
import numpy as np import pickle as pkl import os from sklearn.preprocessing import OneHotEncoder import matplotlib.pyplot as plt from data_utils import normalize_data, apply_normalization # Download from https://www.cs.toronto.edu/~kriz/cifar.html # Assumes 3 input channels # Converts to grayscale def convert_graysc...
structured-nets-master
scripts/data/preprocess_cifar10.py
import h5py import scipy.io as sio import numpy as np import pickle as pkl def process(feat_loc,lab_loc,train,top_N_classes=None,N=None): lab = sio.loadmat(lab_loc)['lab'] if train: with h5py.File(feat_loc) as f: feat = np.array(f['fea']) else: feat = sio.loadmat(feat_loc)['fea'] if top_N_classes is None: ...
structured-nets-master
scripts/data/timit.py
# Download from https://cs.nyu.edu/~ylclab/data/norb-v1.0-small/ import sys import pickle as pkl sys.path.insert(0, '../../') import numpy as np from sklearn.preprocessing import OneHotEncoder from smallnorb import SmallNORBDataset from scipy.misc import imresize MAX_VAL = 255.0 DS_SIZE = (24, 24) N_CATEGORIES = 5 OU...
structured-nets-master
scripts/data/preprocess_smallnorb.py
# Download from http://www.iro.umontreal.ca/~lisa/twiki/bin/view.cgi/Public/DeepVsShallowComparisonICML2007 import numpy as np import pickle as pkl from sklearn.preprocessing import OneHotEncoder from data_utils import normalize_data, apply_normalization def process_data(data): X = data[:, :-1] Y = np.expand_...
structured-nets-master
scripts/data/preprocess_rect.py
import numpy as np def normalize_data(data): mean = np.mean(data,axis=0) std = np.std(data,axis=0) return apply_normalization(data,mean,std), mean, std def apply_normalization(data, mean, std): normalized = (data-mean)/std print('Apply normalization: mean, std: ', np.mean(normalized,axis=0), np.s...
structured-nets-master
scripts/data/data_utils.py
# From https://github.com/ndrplz/small_norb/blob/master/smallnorb/dataset.py import struct import numpy as np import matplotlib.pyplot as plt import scipy.misc from tqdm import tqdm from os import makedirs from os.path import join from os.path import exists from itertools import groupby class SmallNORBExample: ...
structured-nets-master
scripts/data/smallnorb.py
import numpy as np import pickle as pkl from sklearn.preprocessing import OneHotEncoder from data_utils import normalize_data, apply_normalization # Download from http://www.iro.umontreal.ca/~lisa/twiki/bin/view.cgi/Public/DeepVsShallowComparisonICML2007 n_variations = 6 for idx in np.arange(1, n_variations+1): d...
structured-nets-master
scripts/data/preprocess_mnist_noise.py