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
DACBench
DACBench-main/dacbench/agents/dynamic_random_agent.py
from gymnasium import spaces from dacbench.abstract_agent import AbstractDACBenchAgent class DynamicRandomAgent(AbstractDACBenchAgent): def __init__(self, env, switching_interval): self.sample_action = env.action_space.sample self.switching_interval = switching_interval self.count = 0 ...
884
26.65625
87
py
DACBench
DACBench-main/dacbench/agents/simple_agents.py
from gymnasium import spaces from dacbench.abstract_agent import AbstractDACBenchAgent class RandomAgent(AbstractDACBenchAgent): def __init__(self, env): self.sample_action = env.action_space.sample self.shortbox = isinstance(env.action_space, spaces.Box) if self.shortbox: sel...
934
23.605263
76
py
DACBench
DACBench-main/dacbench/agents/__init__.py
from dacbench.agents.dynamic_random_agent import DynamicRandomAgent from dacbench.agents.generic_agent import GenericAgent from dacbench.agents.simple_agents import RandomAgent, StaticAgent __all__ = ["StaticAgent", "RandomAgent", "GenericAgent", "DynamicRandomAgent"]
270
44.166667
78
py
DACBench
DACBench-main/dacbench/challenge_benchmarks/reward_quality_challenge/reward_functions.py
import numpy as np def easy_sigmoid(self): sigmoids = [ np.abs(self._sig(self.c_step, slope, shift)) for slope, shift in zip(self.shifts, self.slopes) ] action = [] for i in range(len(self.action_vals)): best_action = None dist = 100 for a in range(self.action_v...
3,014
29.454545
88
py
DACBench
DACBench-main/dacbench/challenge_benchmarks/state_space_challenge/random_states.py
import numpy as np def small_random_luby_state(self): core_state = self.get_default_state(None) num_random_elements = 20 - len(core_state) for i in range(num_random_elements): core_state.append(np.random.normal(3, 2.5)) return core_state def random_luby_state(self): core_state = self.get...
1,928
31.15
59
py
DACBench
DACBench-main/dacbench/instance_sets/geometric/SampleGeometricInstances.py
from __future__ import generators import os import random from typing import Dict import numpy as np FILE_PATH = os.path.dirname(__file__) # Configure amount of different layers FUNCTION_CONFIG = { "sigmoid": 1, "linear": 1, "parabel": 1, "cubic": 1, "logarithmic": 1, "constant": 1, "sin...
3,827
24.019608
103
py
DACBench
DACBench-main/dacbench/wrappers/policy_progress_wrapper.py
import matplotlib.pyplot as plt import numpy as np from gymnasium import Wrapper class PolicyProgressWrapper(Wrapper): """ Wrapper to track progress towards optimal policy. Can only be used if a way to obtain the optimal policy given an instance can be obtained. """ def __init__(self, env, compu...
2,968
25.274336
93
py
DACBench
DACBench-main/dacbench/wrappers/performance_tracking_wrapper.py
from collections import defaultdict import matplotlib.pyplot as plt import numpy as np import seaborn as sb from gymnasium import Wrapper sb.set_style("darkgrid") current_palette = list(sb.color_palette()) class PerformanceTrackingWrapper(Wrapper): """ Wrapper to track episode performance. Includes int...
6,372
29.203791
103
py
DACBench
DACBench-main/dacbench/wrappers/state_tracking_wrapper.py
import matplotlib.pyplot as plt import numpy as np import seaborn as sb from gymnasium import Wrapper, spaces from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas sb.set_style("darkgrid") current_palette = list(sb.color_palette()) class StateTrackingWrapper(Wrapper): """ Wrapper to tra...
9,299
30.103679
98
py
DACBench
DACBench-main/dacbench/wrappers/observation_wrapper.py
import numpy as np from gymnasium import Wrapper, spaces class ObservationWrapper(Wrapper): """ Wrapper covert observations spaces to spaces.Box for convenience. Currently only supports Dict -> Box """ def __init__(self, env): """ Initialize wrapper. Parameters -...
2,894
24.848214
76
py
DACBench
DACBench-main/dacbench/wrappers/episode_time_tracker.py
import time import matplotlib.pyplot as plt import numpy as np import seaborn as sb from gymnasium import Wrapper from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas sb.set_style("darkgrid") current_palette = list(sb.color_palette()) class EpisodeTimeWrapper(Wrapper): """ Wrapper to ...
7,576
29.187251
97
py
DACBench
DACBench-main/dacbench/wrappers/multidiscrete_action_wrapper.py
import itertools import numpy as np from gymnasium import Wrapper, spaces class MultiDiscreteActionWrapper(Wrapper): """Wrapper to cast MultiDiscrete action spaces to Discrete. This should improve usability with standard RL libraries.""" def __init__(self, env): """ Initialize wrapper. ...
1,018
28.970588
124
py
DACBench
DACBench-main/dacbench/wrappers/instance_sampling_wrapper.py
import numpy as np from gymnasium import Wrapper from scipy.stats import norm class InstanceSamplingWrapper(Wrapper): """ Wrapper to sample a new instance at a given time point. Instances can either be sampled using a given method or a distribution infered from a given list of instances. """ def...
3,253
25.672131
114
py
DACBench
DACBench-main/dacbench/wrappers/reward_noise_wrapper.py
import numpy as np from gymnasium import Wrapper class RewardNoiseWrapper(Wrapper): """ Wrapper to add noise to the reward signal. Noise can be sampled from a custom distribution or any distribution in numpy's random module. """ def __init__( self, env, noise_function=None, noise_dist="s...
3,248
24.582677
97
py
DACBench
DACBench-main/dacbench/wrappers/__init__.py
from dacbench.wrappers.action_tracking_wrapper import ActionFrequencyWrapper from dacbench.wrappers.episode_time_tracker import EpisodeTimeWrapper from dacbench.wrappers.instance_sampling_wrapper import InstanceSamplingWrapper from dacbench.wrappers.multidiscrete_action_wrapper import MultiDiscreteActionWrapper from da...
996
42.347826
85
py
DACBench
DACBench-main/dacbench/wrappers/action_tracking_wrapper.py
import matplotlib.pyplot as plt import numpy as np import seaborn as sb from gymnasium import Wrapper, spaces from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas sb.set_style("darkgrid") current_palette = list(sb.color_palette()) class ActionFrequencyWrapper(Wrapper): """ Wrapper to a...
8,280
30.249057
103
py
DACBench
DACBench-main/tests/test_multi_agent_interface.py
import unittest import numpy as np from dacbench.benchmarks import ModCMABenchmark, SigmoidBenchmark, ToySGDBenchmark from dacbench.envs import SigmoidEnv, ToySGDEnv class TestMultiAgentInterface(unittest.TestCase): def test_make_env(self): bench = SigmoidBenchmark() bench.config["multi_agent"] ...
2,587
34.452055
82
py
DACBench
DACBench-main/tests/test_abstract_benchmark.py
import json import os import tempfile import unittest import numpy as np from gymnasium.spaces import Box, Dict, Discrete, MultiBinary, MultiDiscrete from dacbench.abstract_benchmark import AbstractBenchmark, objdict from dacbench.challenge_benchmarks.reward_quality_challenge.reward_functions import ( random_rewa...
5,714
32.816568
88
py
DACBench
DACBench-main/tests/test_logger.py
import json import tempfile import unittest from pathlib import Path import numpy as np from gymnasium import spaces from gymnasium.spaces import Box, Dict, Discrete, MultiDiscrete from dacbench.agents.simple_agents import RandomAgent from dacbench.benchmarks import SigmoidBenchmark from dacbench.logger import Logger...
10,418
31.457944
84
py
DACBench
DACBench-main/tests/test_runner.py
import os import tempfile import unittest from pathlib import Path import matplotlib import numpy as np import pytest from gymnasium import spaces from dacbench.abstract_agent import AbstractDACBenchAgent # import shutil from dacbench.runner import run_dacbench # , plot_results matplotlib.use("Agg") class TestRu...
2,053
27.136986
72
py
DACBench
DACBench-main/tests/test_run_baselines.py
import tempfile import unittest from pathlib import Path from dacbench.logger import load_logs, log2dataframe from dacbench.run_baselines import ( DISCRETE_ACTIONS, main, run_dynamic_policy, run_optimal, run_random, run_static, ) class TestRunBaselines(unittest.TestCase): def run_random_t...
5,654
35.019108
86
py
DACBench
DACBench-main/tests/test_abstract_env.py
import unittest import numpy as np from gymnasium import spaces from dacbench.abstract_env import AbstractEnv class TestAbstractEnv(unittest.TestCase): def test_not_implemented_methods(self): env = self.make_env() with self.assertRaises(NotImplementedError): env.step(0) with...
5,931
31.955556
78
py
DACBench
DACBench-main/tests/benchmarks/test_fd_benchmark.py
import json import os import unittest from dacbench.benchmarks import FastDownwardBenchmark from dacbench.envs import FastDownwardEnv class TestFDBenchmark(unittest.TestCase): def test_get_env(self): bench = FastDownwardBenchmark() env = bench.get_environment() self.assertTrue(issubclass(...
2,809
36.972973
84
py
DACBench
DACBench-main/tests/benchmarks/test_luby_benchmark.py
import json import os import unittest import numpy as np from dacbench.benchmarks import LubyBenchmark from dacbench.envs import LubyEnv from dacbench.wrappers import RewardNoiseWrapper class TestLubyBenchmark(unittest.TestCase): def test_get_env(self): bench = LubyBenchmark() env = bench.get_en...
2,762
34.883117
81
py
DACBench
DACBench-main/tests/benchmarks/test_sgd_benchmark.py
import json import os import unittest from dacbench.benchmarks import SGDBenchmark from dacbench.envs import SGDEnv class TestSGDBenchmark(unittest.TestCase): def test_get_env(self): bench = SGDBenchmark() env = bench.get_environment() self.assertTrue(issubclass(type(env), SGDEnv)) d...
1,916
32.631579
89
py
DACBench
DACBench-main/tests/benchmarks/test_cma_benchmark.py
import json import os import unittest from dacbench.benchmarks import CMAESBenchmark from dacbench.envs import CMAESEnv class TestCMABenchmark(unittest.TestCase): def test_get_env(self): bench = CMAESBenchmark() env = bench.get_environment() self.assertTrue(issubclass(type(env), CMAESEnv)...
1,985
33.241379
78
py
DACBench
DACBench-main/tests/benchmarks/test_sigmoid_benchmark.py
import json import os import unittest from dacbench.benchmarks import SigmoidBenchmark from dacbench.envs import SigmoidEnv class TestSigmoidBenchmark(unittest.TestCase): def test_get_env(self): bench = SigmoidBenchmark() env = bench.get_environment() self.assertTrue(issubclass(type(env),...
2,104
34.083333
73
py
DACBench
DACBench-main/tests/envs/test_sgd.py
import os import unittest import numpy as np from dacbench import AbstractEnv from dacbench.abstract_benchmark import objdict from dacbench.benchmarks.sgd_benchmark import SGD_DEFAULTS, SGDBenchmark from dacbench.envs.sgd import Reward, SGDEnv from dacbench.wrappers import ObservationWrapper class TestSGDEnv(unitte...
6,344
35.257143
85
py
DACBench
DACBench-main/tests/envs/test_cma.py
import unittest import numpy as np from dacbench import AbstractEnv from dacbench.benchmarks.cma_benchmark import CMAES_DEFAULTS, CMAESBenchmark class TestCMAEnv(unittest.TestCase): def make_env(self): bench = CMAESBenchmark() env = bench.get_environment() return env def test_setup(...
3,546
33.77451
76
py
DACBench
DACBench-main/tests/envs/test_fd.py
import unittest from dacbench import AbstractEnv from dacbench.benchmarks.fast_downward_benchmark import FastDownwardBenchmark class TestFDEnv(unittest.TestCase): def make_env(self): bench = FastDownwardBenchmark() env = bench.get_environment() return env def test_setup(self): ...
1,239
27.837209
77
py
DACBench
DACBench-main/tests/envs/test_deterministic.py
import unittest import numpy as np from numpy.testing import assert_almost_equal from dacbench import benchmarks, run_baselines def assert_state_space_equal(state1, state2): assert type(state1) == type(state2) if isinstance(state1, np.ndarray): assert_almost_equal(state1, state2) elif isinstanc...
2,971
33.16092
84
py
DACBench
DACBench-main/tests/envs/test_theory_env.py
import unittest import gymnasium as gym from dacbench.benchmarks import TheoryBenchmark class TestTheoryEnv(unittest.TestCase): def test_discrete_env(self): bench = TheoryBenchmark( config={ "discrete_action": True, "action_choices": [1, 2, 4, 8], ...
2,430
30.166667
78
py
DACBench
DACBench-main/tests/envs/test_luby.py
import unittest import numpy as np from dacbench import AbstractEnv from dacbench.benchmarks.luby_benchmark import LUBY_DEFAULTS from dacbench.envs import LubyEnv class TestLubyEnv(unittest.TestCase): def make_env(self): config = LUBY_DEFAULTS config["instance_set"] = {0: [1, 1]} env = L...
2,769
34.512821
81
py
DACBench
DACBench-main/tests/envs/test_modcma.py
import unittest import numpy as np from gymnasium import spaces from dacbench import AbstractEnv from dacbench.abstract_benchmark import objdict from dacbench.envs import ModCMAEnv class TestModCMAEnv(unittest.TestCase): def make_env(self): config = objdict({}) config.budget = 20 config....
1,751
31.444444
85
py
DACBench
DACBench-main/tests/envs/test_geometric.py
import os import unittest from typing import Dict import numpy as np from dacbench import AbstractEnv from dacbench.abstract_benchmark import objdict from dacbench.benchmarks import GeometricBenchmark from dacbench.envs import GeometricEnv FILE_PATH = os.path.dirname(__file__) DEFAULTS_STATIC = objdict( { ...
7,332
36.035354
149
py
DACBench
DACBench-main/tests/envs/test_sigmoid.py
import unittest from unittest import mock import numpy as np from dacbench import AbstractEnv from dacbench.benchmarks.sigmoid_benchmark import SIGMOID_DEFAULTS from dacbench.envs import SigmoidEnv class TestSigmoidEnv(unittest.TestCase): def make_env(self): config = SIGMOID_DEFAULTS config["ins...
2,676
35.175676
85
py
DACBench
DACBench-main/tests/container/test_container_utils.py
import json import unittest from gymnasium.spaces import Box, Dict, Discrete, MultiBinary, MultiDiscrete, Tuple from dacbench.container.container_utils import Decoder, Encoder class TestEncoder(unittest.TestCase): def test_spaces(self): box = Box(low=-1, high=1, shape=(2,)) multi_discrete = Mult...
1,542
34.068182
86
py
DACBench
DACBench-main/tests/agents/test_dynamic_random_agent.py
import unittest import numpy as np from dacbench.agents import DynamicRandomAgent from dacbench.benchmarks import SigmoidBenchmark from dacbench.wrappers import MultiDiscreteActionWrapper class MyTestCase(unittest.TestCase): def get_agent(self, switching_interval): env = SigmoidBenchmark().get_benchmark...
1,788
29.322034
78
py
DACBench
DACBench-main/tests/wrappers/test_state_tracking_wrapper.py
import tempfile import unittest from itertools import groupby from pathlib import Path import gymnasium as gym import numpy as np from dacbench.agents import StaticAgent from dacbench.benchmarks import CMAESBenchmark, LubyBenchmark from dacbench.logger import Logger, load_logs, log2dataframe from dacbench.runner impo...
9,003
31.157143
77
py
DACBench
DACBench-main/tests/wrappers/test_instance_sampling_wrapper.py
import unittest import numpy as np from sklearn.metrics import mutual_info_score from dacbench.benchmarks import LubyBenchmark from dacbench.wrappers import InstanceSamplingWrapper class TestInstanceSamplingWrapper(unittest.TestCase): def test_init(self): bench = LubyBenchmark() bench.config.ins...
2,074
30.439394
79
py
DACBench
DACBench-main/tests/wrappers/test_time_tracking_wrapper.py
import tempfile import unittest from pathlib import Path import numpy as np from dacbench.agents import StaticAgent from dacbench.benchmarks import LubyBenchmark from dacbench.logger import Logger, load_logs, log2dataframe from dacbench.runner import run_benchmark from dacbench.wrappers import EpisodeTimeWrapper cl...
4,449
33.765625
80
py
DACBench
DACBench-main/tests/wrappers/test_performance_tracking_wrapper.py
import unittest from unittest import mock import numpy as np from dacbench.benchmarks import LubyBenchmark from dacbench.wrappers import PerformanceTrackingWrapper class TestPerformanceWrapper(unittest.TestCase): def test_init(self): bench = LubyBenchmark() env = bench.get_environment() ...
5,701
38.874126
87
py
DACBench
DACBench-main/tests/wrappers/test_observation_wrapper.py
import unittest import numpy as np from dacbench import AbstractEnv from dacbench.benchmarks import CMAESBenchmark from dacbench.wrappers import ObservationWrapper class TestObservationTrackingWrapper(unittest.TestCase): def get_test_env(self) -> AbstractEnv: bench = CMAESBenchmark() env = bench...
1,523
30.75
81
py
DACBench
DACBench-main/tests/wrappers/test_reward_noise_wrapper.py
import unittest from dacbench.benchmarks import LubyBenchmark from dacbench.wrappers import RewardNoiseWrapper class TestRewardNoiseWrapper(unittest.TestCase): def test_init(self): bench = LubyBenchmark() env = bench.get_environment() wrapped = RewardNoiseWrapper(env) self.assertF...
2,460
33.661972
85
py
DACBench
DACBench-main/tests/wrappers/test_action_tracking_wrapper.py
import tempfile import unittest from pathlib import Path import gymnasium as gym import numpy as np import pandas as pd from dacbench.agents import StaticAgent from dacbench.benchmarks import ( CMAESBenchmark, FastDownwardBenchmark, LubyBenchmark, ModCMABenchmark, ) from dacbench.logger import Logger,...
10,052
32.622074
87
py
DACBench
DACBench-main/tests/wrappers/test_policy_progress_wrapper.py
import unittest from unittest import mock import numpy as np from dacbench.benchmarks import SigmoidBenchmark from dacbench.wrappers import PolicyProgressWrapper def _sig(x, scaling, inflection): return 1 / (1 + np.exp(-scaling * (x - inflection))) def compute_optimal_sigmoid(instance): sig_values = [_sig...
2,155
35.542373
84
py
DACBench
DACBench-main/docs/conf.py
# Configuration file for the Sphinx documentation builder. # # This file only contains a selection of the most common options. For a full # list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html # -- Path setup -------------------------------------------------------------- # If ex...
1,883
33.888889
89
py
cvnn
cvnn-master/setup.py
from setuptools import setup import versioneer requirements = [ 'tensorflow>=2.0', 'tensorflow-probability', # tfp for the Batch Norm (covariance) # 'tensorflow-addons', 'numpy', 'six', 'packaging', 'pandas', 'scipy', # Data 'colorlog', 'openpyxl', # Logging 't...
1,413
30.422222
112
py
cvnn
cvnn-master/versioneer.py
# Version: 0.18 """The Versioneer - like a rocketeer, but for versions. The Versioneer ============== * like a rocketeer, but for versions! * https://github.com/warner/python-versioneer * Brian Warner * License: Public Domain * Compatible With: python2.6, 2.7, 3.2, 3.3, 3.4, 3.5, 3.6, and pypy * [![Latest Version] ...
68,742
36.667397
79
py
cvnn
cvnn-master/debug/having_same_result_two_runs.py
import tensorflow as tf import tensorflow_datasets as tfds import numpy as np import os tfds.disable_progress_bar() def normalize_img(image, label): """Normalizes images: `uint8` -> `float32`.""" return tf.cast(image, tf.float32) / 255., label def get_dataset(): (ds_train, ds_test), ds_info = tfds.load...
2,405
31.08
95
py
cvnn
cvnn-master/debug/ComplexDense_example.py
import numpy as np import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras import layers from tensorflow.keras.optimizers import Adam from tensorflow.keras import datasets from layers.__init__ import ComplexDense, ComplexFlatten from pdb import set_trace (train_images, train_labels...
946
31.655172
115
py
cvnn
cvnn-master/debug/conv_memory_script.py
import sys import tensorflow as tf from tensorflow.keras import datasets from time import perf_counter import numpy as np from pdb import set_trace import sys ENABLE_MEMORY_GROWTH = True # https://stackoverflow.com/questions/36927607/how-can-i-solve-ran-out-of-gpu-memory-in-tensorflow DEBUG_CONV = False TEST_KERAS...
25,639
61.689487
418
py
cvnn
cvnn-master/debug/mwe_testing_learning_algo.py
import tensorflow as tf import numpy as np from pdb import set_trace BATCH_SIZE = 10 def get_dataset(): fashion_mnist = tf.keras.datasets.fashion_mnist (train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data() return (train_images, train_labels), (test_images, test_labels) de...
2,133
37.8
101
py
cvnn
cvnn-master/debug/testing_learning_algo.py
import numpy as np from pathlib import Path from pdb import set_trace path = Path("/home/barrachina/Documents/cvnn/log/montecarlo/2021/03March/10Wednesday/run-15h12m52") # init_weight = np.load(path / "initial_weights.npy", allow_pickle=True) init_debug_weight = np.load(path / "initial_debug_weights.npy", allow_pickle...
990
37.115385
113
py
cvnn
cvnn-master/debug/monte_carlo_tests.py
from cvnn.montecarlo import MonteCarlo import tensorflow as tf import layers.__init__ as layers import numpy as np fashion_mnist = tf.keras.datasets.fashion_mnist (train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data() own_model = tf.keras.Sequential([ layers.ComplexFlatten(input_sh...
1,245
34.6
105
py
cvnn
cvnn-master/debug/gradient_tape_complex.py
import tensorflow as tf # https://www.tensorflow.org/guide/autodiff x = tf.Variable(tf.complex([2., 2.], [2., 2.])) with tf.GradientTape() as tape: y = tf.abs(tf.reduce_sum(x))**2 print(y) dy_dx = tape.gradient(y, x) print(dy_dx)
241
19.166667
47
py
cvnn
cvnn-master/debug/fft_testing.py
import tensorflow as tf import numpy as np from layers.__init__ import Convolutional from pdb import set_trace import sys from scipy import signal from scipy import linalg COMPARE_TF_AND_NP = False TWO_DIM_TEST = True ONE_DIM_TEST = False STACKOVERFLOW_EXAMPLE = False if COMPARE_TF_AND_NP: # Results are not exac...
4,086
31.181102
117
py
cvnn
cvnn-master/examples/u_net_example.py
import tensorflow as tf from cvnn import layers from pdb import set_trace import tensorflow_datasets as tfds # https://medium.com/analytics-vidhya/training-u-net-from-scratch-using-tensorflow2-0-fad541e2eaf1 BATCH_SIZE = 64 BUFFER_SIZE = 1000 INPUT_SIZE = (572, 572) MASK_SIZE = (388, 388) def _downsample_tf(inputs, ...
6,265
38.1625
114
py
cvnn
cvnn-master/examples/fashion_mnist_example.py
# TensorFlow and tf.keras import tensorflow as tf # Helper libraries import numpy as np import matplotlib.pyplot as plt from cvnn import layers print(tf.__version__) def get_fashion_mnist_dataset(): fashion_mnist = tf.keras.datasets.fashion_mnist (train_images, train_labels), (test_images, test_labels) = fas...
3,211
41.826667
119
py
cvnn
cvnn-master/examples/random_noise_publication.py
from cvnn.montecarlo import run_gaussian_dataset_montecarlo run_gaussian_dataset_montecarlo(iterations=20, m=10000, n=128, param_list=None, validation_split=0.2, epochs=150, batch_size=100, display_freq=1, optimizer='sgd', shape_raw=[64], activation='cart...
860
77.272727
116
py
cvnn
cvnn-master/examples/cifar410_example.py
import tensorflow as tf from tensorflow.keras import datasets, layers, models import cvnn.layers as complex_layers import numpy as np from pdb import set_trace (train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data() # Normalize pixel values to be between 0 and 1 train_images, test_image...
7,167
52.492537
119
py
cvnn
cvnn-master/examples/mnist_dataset_example.py
import tensorflow as tf import tensorflow_datasets as tfds from cvnn import layers import numpy as np import timeit import datetime from pdb import set_trace try: import plotly.graph_objects as go import plotly PLOTLY = True except ModuleNotFoundError: PLOTLY = False # tf.enable_v2_behavior() # tfds.di...
7,789
36.63285
118
py
cvnn
cvnn-master/tests/test_dropout.py
import tensorflow as tf import tensorflow_datasets as tfds import numpy as np from pdb import set_trace import cvnn.layers as complex_layers from cvnn.montecarlo import run_montecarlo def normalize_img(image, label): """Normalizes images: `uint8` -> `float32`.""" return tf.cast(image, tf.float32) / 255., labe...
9,706
42.142222
120
py
cvnn
cvnn-master/tests/test_doc_cvnn_example.py
import numpy as np import cvnn.layers as complex_layers import tensorflow as tf from pdb import set_trace def get_dataset(): (train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.cifar10.load_data() train_images = train_images.astype(dtype=np.complex64) / 255.0 test_images = test_im...
2,912
44.515625
109
py
cvnn
cvnn-master/tests/test_functional_api.py
from cvnn.layers import ComplexUnPooling2D, complex_input, ComplexMaxPooling2DWithArgmax, \ ComplexUpSampling2D, ComplexMaxPooling2D import tensorflow as tf import numpy as np from pdb import set_trace def get_img(): img_r = np.array([[ [0, 1, 2], [0, 2, 2], [0, 5, 7] ], [ ...
1,792
25.761194
118
py
cvnn
cvnn-master/tests/test_initialization.py
import tensorflow as tf from cvnn import logger import cvnn.initializers as initializers from pdb import set_trace import sys shape = (3, 3, 3) dtype = tf.dtypes.float32 def compare(key, tf_init, my_init): tf_version = tf_init(seed=100)(shape=shape, dtype=dtype) my_version = my_init(seed=100)(shape=shape, dt...
1,191
28.8
89
py
cvnn
cvnn-master/tests/test_custom_layers.py
import numpy as np from cvnn.layers import ComplexDense, ComplexFlatten, ComplexInput, ComplexConv2D, ComplexMaxPooling2D, \ ComplexAvgPooling2D, ComplexConv2DTranspose, ComplexUnPooling2D, ComplexMaxPooling2DWithArgmax, \ ComplexUpSampling2D, ComplexBatchNormalization, ComplexAvgPooling1D, ComplexPolarAvgPooli...
22,749
40.288566
234
py
cvnn
cvnn-master/tests/test_tf_vs_cvnn.py
from examples.cifar410_example import test_cifar10 from examples.fashion_mnist_example import test_fashion_mnist from examples.mnist_dataset_example import test_mnist from examples.u_net_example import test_unet from importlib import reload import os import tensorflow as tf def test_tf_vs_cvnn(): """ This mod...
798
27.535714
115
py
cvnn
cvnn-master/tests/test_output_dtype.py
import tensorflow as tf import numpy as np import cvnn.layers as complex_layers from pdb import set_trace def all_layers_model(): """ Creates a model using all possible layers to assert no layer changes the dtype to real. """ input_shape = (4, 28, 28, 3) x = tf.cast(tf.random.normal(input_shape), ...
1,280
34.583333
111
py
cvnn
cvnn-master/tests/test_losses.py
from cvnn.losses import ComplexAverageCrossEntropy, ComplexWeightedAverageCrossEntropy, \ ComplexAverageCrossEntropyIgnoreUnlabeled import numpy as np import tensorflow as tf from tensorflow.keras.losses import CategoricalCrossentropy from cvnn.layers import ComplexDense, complex_input from pdb import set_trace d...
3,533
31.722222
120
py
cvnn
cvnn-master/tests/test_metrics.py
import numpy as np from tensorflow.keras.metrics import CategoricalAccuracy import tensorflow as tf from pdb import set_trace from cvnn.metrics import ComplexAverageAccuracy, ComplexCategoricalAccuracy def test_with_tf(): classes = 3 y_true = tf.cast(tf.random.uniform(shape=(34, 54, 12), maxval=classes), dtyp...
6,381
27.364444
111
py
cvnn
cvnn-master/tests/test_dataset_conversion.py
from cvnn.utils import transform_to_real_map_function import numpy as np from pdb import set_trace import tensorflow as tf def test_image_real_conversion(): img_r = np.array([[ [0, 1, 2], [0, 2, 2], [0, 5, 7] ], [ [0, 7, 5], [3, 7, 9], [4, 5, 3] ]]).astype(n...
1,114
24.340909
67
py
cvnn
cvnn-master/tests/test_capacity_real_equivalent.py
import numpy as np import cvnn.layers as layers from time import sleep from cvnn.layers import ComplexDense from cvnn.real_equiv_tools import get_real_equivalent_multiplier from tensorflow.keras.models import Sequential from tensorflow.keras.losses import categorical_crossentropy def shape_tst(input_size, output_size...
5,079
43.955752
121
py
cvnn
cvnn-master/tests/test_several_datasets.py
import tensorflow as tf import numpy as np import os import tensorflow_datasets as tfds from tensorflow.keras import datasets, models from cvnn.initializers import ComplexGlorotUniform from cvnn.layers import ComplexDense, ComplexFlatten, ComplexInput import cvnn.layers as complex_layers from cvnn import layers from pd...
7,601
41.233333
117
py
cvnn
cvnn-master/tests/test_activation_functions.py
import tensorflow as tf from cvnn import layers, activations if __name__ == '__main__': for activation in activations.act_dispatcher.keys(): print(activation) model = tf.keras.Sequential([ layers.ComplexInput(4), layers.ComplexDense(1, activation=activation), lay...
371
32.818182
58
py
cvnn
cvnn-master/docs/conf.py
# Configuration file for the Sphinx documentation builder. # # This file only contains a selection of the most common options. For a full # list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html # -- Path setup -------------------------------------------------------------- # If ex...
2,002
35.418182
79
py
cvnn
cvnn-master/cvnn/initializers.py
from abc import abstractmethod import numpy as np import tensorflow as tf from tensorflow.python.ops import random_ops from tensorflow.python.ops import stateless_random_ops from tensorflow.keras.initializers import Initializer import sys from pdb import set_trace # Typing from typing import Optional INIT_TECHNIQUES =...
10,508
35.237931
143
py
cvnn
cvnn-master/cvnn/tb.py
from tensorflow.keras.callbacks import TensorBoard from tensorflow import GradientTape import tensorflow as tf # This extends TensorBoard to save gradients as histogram # ExtendedTensorBoard can then be used in replace of tf.keras.callbacks.TensorBoard. class ExtendedTensorBoard(TensorBoard): def _log_gradients(s...
1,546
44.5
99
py
cvnn
cvnn-master/cvnn/losses.py
import tensorflow as tf from tensorflow.keras import backend from tensorflow.keras.losses import Loss, categorical_crossentropy class ComplexAverageCrossEntropy(Loss): def call(self, y_true, y_pred): real_loss = categorical_crossentropy(y_true, tf.math.real(y_pred)) if y_pred.dtype.is_complex: ...
3,061
40.378378
100
py
cvnn
cvnn-master/cvnn/__main__.py
from cvnn import cli import sys import logging from pdb import set_trace cli.cli()
84
11.142857
25
py
cvnn
cvnn-master/cvnn/utils.py
import numpy as np from datetime import datetime from pathlib import Path from pdb import set_trace import sys from tensorflow.python.keras import Model import tensorflow as tf # TODO: Imported only for dtype import os from os.path import join from scipy.io import loadmat # To test logger: import cvnn import loggin...
7,066
31.869767
120
py
cvnn
cvnn-master/cvnn/_version.py
__version__ = '2.0'
20
9.5
19
py
cvnn
cvnn-master/cvnn/cli.py
from argparse import ArgumentParser from cvnn import __version__ def cli(args=None): p = ArgumentParser( description="Library to help implement a complex-valued neural network (cvnn) using tensorflow as back-end", conflict_handler='resolve' ) p.add_argument( '-V', '--version', ...
791
26.310345
116
py
cvnn
cvnn-master/cvnn/metrics.py
import tensorflow as tf from tensorflow.keras.metrics import Accuracy, CategoricalAccuracy, Precision, Recall, Mean from tensorflow_addons.metrics import F1Score, CohenKappa from tensorflow.python.keras import backend class ComplexAccuracy(Accuracy): def __init__(self, name='complex_accuracy', dtype=tf.complex64...
8,397
50.521472
120
py
cvnn
cvnn-master/cvnn/activations.py
import tensorflow as tf from tensorflow.keras.layers import Activation from typing import Union, Callable, Optional from tensorflow import Tensor from numpy import pi """ This module contains many complex-valued activation functions to be used by CVNN class. """ # logger = logging.getLogger(cvnn.__name__) t_activatio...
24,929
39.080386
127
py
cvnn
cvnn-master/cvnn/__init__.py
import logging import colorlog import re import os from cvnn.utils import create_folder from tensorflow.keras.utils import get_custom_objects from cvnn.activations import act_dispatcher from cvnn.initializers import init_dispatcher get_custom_objects().update(act_dispatcher) # Makes my activation functions usable ...
2,139
32.968254
117
py
cvnn
cvnn-master/cvnn/real_equiv_tools.py
import sys import numpy as np from tensorflow.keras import Sequential from pdb import set_trace from cvnn import logger import cvnn.layers as layers from cvnn.layers.core import ComplexLayer from typing import Type, List from typing import Optional EQUIV_TECHNIQUES = { "np", "alternate_tp", "ratio_tp", "none" } ...
9,341
53.631579
131
py
cvnn
cvnn-master/cvnn/layers/pooling.py
import tensorflow as tf from packaging import version from tensorflow.keras.layers import Layer from tensorflow.python.keras import backend from tensorflow.python.keras.utils import conv_utils if version.parse(tf.__version__) < version.parse("2.6.0"): from tensorflow.python.keras.engine.input_spec import InputSpec...
24,753
47.253411
138
py
cvnn
cvnn-master/cvnn/layers/convolutional.py
import six import functools import tensorflow as tf from packaging import version from tensorflow.keras import activations from tensorflow.keras import backend from tensorflow.keras import constraints from tensorflow.keras import initializers from tensorflow.keras import regularizers from tensorflow.keras.layers impor...
51,395
49.636453
141
py
cvnn
cvnn-master/cvnn/layers/core.py
from abc import ABC, abstractmethod import numpy as np import tensorflow as tf from tensorflow.keras.layers import Flatten, Dense, InputLayer, Layer from tensorflow.python.keras import backend as K from tensorflow.keras import initializers import tensorflow_probability as tfp from tensorflow import TensorShape, Tensor ...
29,931
49.560811
135
py
cvnn
cvnn-master/cvnn/layers/upsampling.py
import tensorflow as tf from tensorflow.keras import backend from tensorflow.keras.layers import UpSampling2D from typing import Optional, Union, Tuple from cvnn.layers.core import ComplexLayer from cvnn.layers.core import DEFAULT_COMPLEX_TYPE class ComplexUpSampling2D(UpSampling2D, ComplexLayer): def __init__(s...
3,007
43.895522
114
py
cvnn
cvnn-master/cvnn/layers/__init__.py
# https://stackoverflow.com/questions/24100558/how-can-i-split-a-module-into-multiple-files-without-breaking-a-backwards-compa/24100645 from cvnn.layers.pooling import ComplexMaxPooling2D, ComplexAvgPooling2D, ComplexAvgPooling3D, ComplexPolarAvgPooling2D from cvnn.layers.pooling import ComplexUnPooling2D, ComplexMaxPo...
1,039
53.736842
135
py
eco-dqn
eco-dqn-master/src/__init__.py
0
0
0
py
eco-dqn
eco-dqn-master/src/networks/mpnn.py
import torch import torch.nn as nn import torch.nn.functional as F class MPNN(nn.Module): def __init__(self, n_obs_in=7, n_layers=3, n_features=64, tied_weights=False, n_hid_readout=[],): super().__init__() self....
5,994
36.704403
161
py
eco-dqn
eco-dqn-master/src/networks/__init__.py
0
0
0
py
eco-dqn
eco-dqn-master/src/envs/core.py
from src.envs.spinsystem import SpinSystemFactory def make(id, *args, **kwargs): if id == "SpinSystem": env = SpinSystemFactory.get(*args, **kwargs) else: raise NotImplementedError() return env
225
19.545455
52
py
eco-dqn
eco-dqn-master/src/envs/spinsystem.py
from abc import ABC, abstractmethod from collections import namedtuple from operator import matmul import numpy as np import torch.multiprocessing as mp from numba import jit, float64, int64 from src.envs.utils import (EdgeType, RewardSignal, ExtraAction, ...
30,398
41.279555
173
py
eco-dqn
eco-dqn-master/src/envs/utils.py
import random from abc import ABC, abstractmethod from enum import Enum import networkx as nx import numpy as np class EdgeType(Enum): UNIFORM = 1 DISCRETE = 2 RANDOM = 3 class RewardSignal(Enum): DENSE = 1 BLS = 2 SINGLE = 3 CUSTOM_BLS = 4 class ExtraAction(Enum): PASS = 1 RA...
14,455
33.09434
128
py
eco-dqn
eco-dqn-master/src/envs/__init__.py
0
0
0
py
eco-dqn
eco-dqn-master/src/agents/__init__.py
0
0
0
py