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
fl-analysis
fl-analysis-master/src/util.py
import collections from copy import deepcopy import numpy as np import pandas as pd from os.path import join from tensorflow.python.keras.layers.convolutional import Conv2D from tensorflow.python.keras.layers.core import Dense def log_data(experiment_dir, rounds, accuracy, adv_success): """Logs data.""" df ...
6,070
38.679739
136
py
fl-analysis
fl-analysis-master/src/test_tf_model.py
from unittest import TestCase from src.tf_model import Model from src.tf_data import Dataset from matplotlib import pyplot import tensorflow as tf import numpy as np class TestModel(TestCase): def test_create_model_weight(self): model = Model.create_model("dev") (x_train, y_train), (x_test, y_te...
3,013
36.209877
137
py
fl-analysis
fl-analysis-master/src/__init__.py
0
0
0
py
fl-analysis
fl-analysis-master/src/config_old.py
import sys import configargparse import logging from src.client_attacks import Attack parser = configargparse.ArgumentParser() parser.add('-c', '--config_filepath', required=False, is_config_file=True, help='Path to config file.') # logging configuration parser.add_argument( '-d', '--debug', help="Print deb...
24,879
63.455959
313
py
fl-analysis
fl-analysis-master/src/hyperparameter_tuning.py
import os from tensorboard.plugins.hparams import api as hp import tensorflow as tf import numpy as np from src.federated_averaging import FederatedAveraging from src.tf_model import Model def load_model(args, config): if args.load_model is not None: model = tf.keras.models.load_model(args.load_model) # ...
6,049
52.539823
159
py
fl-analysis
fl-analysis-master/src/config/definitions.py
from dataclasses import dataclass, MISSING, field from typing import Optional, Dict, Any, List from mashumaro.mixins.yaml import DataClassYAMLMixin """ This class defines the configuration schema of the framework. """ @dataclass class Quantization(DataClassYAMLMixin): """ Apply quantization to the client up...
12,695
44.342857
121
py
fl-analysis
fl-analysis-master/src/config/test_config.py
import unittest from config import load_config class ConfigTest(unittest.TestCase): def test_load_config(self): load_config("example_config.yaml") if __name__ == '__main__': unittest.main()
212
14.214286
42
py
fl-analysis
fl-analysis-master/src/config/config.py
from .definitions import Config def load_config(config_name): with open(config_name, "rb") as f: config = Config.from_yaml(f.read()) return config
167
15.8
43
py
fl-analysis
fl-analysis-master/src/config/__init__.py
from .config import load_config from .definitions import Environment
69
22.333333
36
py
fl-analysis
fl-analysis-master/src/aggregation/aggregators.py
from copy import deepcopy import numpy as np import logging class Aggregator: """ Aggregation behavior """ def aggregate(self, global_weights, client_weight_list): """ :type client_weight_list: list[np.ndarray] """ raise NotImplementedError("Subclass") class FedAvg(Aggregato...
4,099
35.607143
127
py
fl-analysis
fl-analysis-master/src/aggregation/trimmed_mean_test.py
import unittest import numpy as np from src.aggregation.aggregators import TrimmedMean class TrimmedMeanTest(unittest.TestCase): def test_aggregates_properly(self): w1 = np.array(((1, 5), (1, 5))) w2 = np.array(((2, 3), (2, 3))) w3 = np.array(((10, 11), (10, 11))) average = Trim...
455
21.8
84
py
fl-analysis
fl-analysis-master/src/aggregation/__init__.py
from .aggregators import FedAvg, TrimmedMean, Aggregator
57
28
56
py
fl-analysis
fl-analysis-master/src/attack/targeted_attack.py
from src.attack.attack import LossBasedAttack import tensorflow as tf import logging import numpy as np from src.data import image_augmentation logger = logging.getLogger(__name__) class TargetedAttack(LossBasedAttack): def generate(self, dataset, model, **kwargs): self.parse_params(**kwargs) ...
3,152
35.241379
135
py
fl-analysis
fl-analysis-master/src/attack/attack.py
from src.data.tf_data import Dataset from src.attack.evasion.evasion_method import EvasionMethod class Attack(object): def __init__(self): pass def generate(self, dataset, model, **kwargs): raise NotImplementedError("Sub-classes must implement generate.") return x def _compute_g...
1,884
26.318841
92
py
fl-analysis
fl-analysis-master/src/attack/framework_attack_wrapper.py
class FrameworkAttackWrapper(object): """Wraps an attack with dict params to invocate later.""" def __init__(self, attack, kwargs): self.attack = attack self.kwargs = kwargs
200
24.125
61
py
fl-analysis
fl-analysis-master/src/attack/anticipate_tf_attack.py
from src.attack.attack import LossBasedAttack import logging import numpy as np import tensorflow as tf from copy import copy logger = logging.getLogger(__name__) # Move this into generate later # from src.torch_compat.anticipate import train_anticipate class AnticipateTfAttack(LossBasedAttack): def generate(...
7,110
40.104046
150
py
fl-analysis
fl-analysis-master/src/attack/parse_config.py
def map_objective(name): """ :param name: str :param evasion: EvasionMethod to be added :return: """ from src import attack cls = getattr(attack, name) return cls() # def load_attacks(attack_file_name): # with open(attack_file_name) as stream: # yaml = YAML(typ='safe') # ...
562
19.107143
45
py
fl-analysis
fl-analysis-master/src/attack/__init__.py
from .targeted_attack import TargetedAttack from .untargeted_attack import UntargetedAttack from .anticipate_tf_attack import AnticipateTfAttack
145
35.5
52
py
fl-analysis
fl-analysis-master/src/attack/untargeted_attack.py
from src.attack.attack import LossBasedAttack import tensorflow as tf import logging logger = logging.getLogger(__name__) class UntargetedAttack(LossBasedAttack): def generate(self, dataset, model, **kwargs): self.parse_params(**kwargs) self.weights = model.get_weights() loss_object_w...
1,636
33.829787
107
py
fl-analysis
fl-analysis-master/src/attack/test/AttackTest.py
import tensorflow as tf import numpy as np from src.data.tf_data_global import IIDGlobalDataset from src.attack.evasion.norm import NormBoundPGDEvasion from src.attack.evasion.trimmed_mean import TrimmedMeanEvasion from src.attack.attack import AttackDatasetBridge from src.attack.untargeted_attack import UntargetedAtt...
6,328
45.19708
138
py
fl-analysis
fl-analysis-master/src/attack/test/__init__.py
0
0
0
py
fl-analysis
fl-analysis-master/src/attack/evasion/evasion_method.py
import tensorflow as tf class EvasionMethod(object): def __init__(self, alpha): """ :type alpha: float|None alpha weight of evasion method. The closer to 1 the more we want to evade. """ self.alpha = alpha def loss_term(self, model): return None def update_after...
418
17.217391
106
py
fl-analysis
fl-analysis-master/src/attack/evasion/trimmed_mean.py
from .evasion_method import EvasionMethod import numpy as np import tensorflow as tf class TrimmedMeanEvasion(EvasionMethod): def __init__(self, benign_updates_this_round, alpha, n_remove_malicious): """ :type benign_updates_this_round: [[np.ndarray]] list of client updates, :type alpha...
2,652
43.966102
132
py
fl-analysis
fl-analysis-master/src/attack/evasion/norm.py
from .evasion_method import EvasionMethod import logging import numpy as np import tensorflow as tf class NormBoundPGDEvasion(EvasionMethod): """ Evades norm bound using PGD. """ def __init__(self, old_weights, norm_type, scale_factor, clipping_bound=None, pgd_factor=None, benign_up...
5,826
42.162963
147
py
fl-analysis
fl-analysis-master/src/attack/evasion/norm_prob_check.py
from . import NormBoundPGDEvasion from .evasion_method import EvasionMethod import logging import numpy as np import tensorflow as tf class NormBoundProbabilisticCheckingEvasion(NormBoundPGDEvasion): """ Adaptive attack for probabilistic checking """ def __init__(self, old_weights, norm_type, scale_fa...
6,332
43.598592
144
py
fl-analysis
fl-analysis-master/src/attack/evasion/__init__.py
from .norm import NormBoundPGDEvasion from .trimmed_mean import TrimmedMeanEvasion from .norm_prob_check import NormBoundProbabilisticCheckingEvasion from .neurotoxin import NeurotoxinEvasion def construct_evasion(classname, **kwargs): """Constructs evasion method""" import src.attack.evasion as ev cls = ...
368
29.75
66
py
fl-analysis
fl-analysis-master/src/attack/evasion/neurotoxin.py
from . import NormBoundPGDEvasion from .evasion_method import EvasionMethod import logging import numpy as np import tensorflow as tf class NeurotoxinEvasion(NormBoundPGDEvasion): """ Adaptive attack for probabilistic checking """ def __init__(self, old_weights, norm_type, scale_factor, topk, last_rou...
2,523
39.063492
129
py
fl-analysis
fl-analysis-master/src/test/DataLoaderTest.py
import tensorflow as tf import numpy as np from src.client_attacks import Attack from src.data import data_loader from src.data.tf_data_global import NonIIDGlobalDataset class DataLoaderTest(tf.test.TestCase): def setUp(self): super(DataLoaderTest, self).setUp() def tearDown(self): pass ...
3,093
37.197531
132
py
fl-analysis
fl-analysis-master/src/test/TfDataTest.py
import tensorflow as tf import numpy as np from src.data.tf_data import ImageGeneratorDataset, Dataset class TfDataTest(tf.test.TestCase): def setUp(self): super(TfDataTest, self).setUp() def tearDown(self): pass def get_dataset(self, aux_size): (x_train, y_train), (x_test, y_te...
1,358
32.146341
79
py
fl-analysis
fl-analysis-master/src/test/__init__.py
0
0
0
py
fl-analysis
fl-analysis-master/src/subspace/__init__.py
0
0
0
py
fl-analysis
fl-analysis-master/src/subspace/general/tfutil.py
# Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, pub...
15,340
39.265092
157
py
fl-analysis
fl-analysis-master/src/subspace/general/image_preproc.py
# Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, pub...
3,582
37.945652
122
py
fl-analysis
fl-analysis-master/src/subspace/general/util.py
# Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, pub...
4,248
27.709459
88
py
fl-analysis
fl-analysis-master/src/subspace/general/__init__.py
# Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, pub...
1,104
51.619048
80
py
fl-analysis
fl-analysis-master/src/subspace/general/stats_buddy.py
# Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, pub...
10,845
41.03876
126
py
fl-analysis
fl-analysis-master/src/subspace/builder/resnet.py
import numpy as np import tensorflow as tf from tensorflow.keras import Model from tensorflow.keras.layers import (Flatten, Input, Activation, Reshape, Dropout, Convolution2D, MaxPooling2D, BatchNormalization, Conv2D, GlobalAveragePooling2D...
27,766
57.21174
116
py
fl-analysis
fl-analysis-master/src/subspace/builder/model_builders.py
import numpy as np import tensorflow as tf from tensorflow.keras import Model from tensorflow.keras.layers import (Dense, Flatten, Input, Activation, Reshape, Dropout, Convolution2D, MaxPooling2D, BatchNormalization, Conv2D, GlobalAveragePo...
18,121
44.762626
202
py
fl-analysis
fl-analysis-master/src/subspace/builder/test_model_builders.py
from unittest import TestCase import tensorflow as tf import numpy as np from tf_data import Dataset from tf_model import Model from .model_builders import build_model_mnist_fc, build_cnn_model_mnist_bhagoji, build_test, build_cnn_model_mnist_dev_conv from ..keras_ext.rproj_layers_util import ThetaPrime import resour...
7,121
33.572816
123
py
fl-analysis
fl-analysis-master/src/subspace/builder/__init__.py
0
0
0
py
fl-analysis
fl-analysis-master/src/subspace/keras_ext/test_layers.py
#! /usr/bin/env python # Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, ...
6,558
34.074866
89
py
fl-analysis
fl-analysis-master/src/subspace/keras_ext/engine.py
# Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, pub...
1,201
51.26087
80
py
fl-analysis
fl-analysis-master/src/subspace/keras_ext/rproj_layers_util.py
#! /usr/bin/env python # Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, ...
28,439
36.970628
136
py
fl-analysis
fl-analysis-master/src/subspace/keras_ext/engine_training.py
# Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, pub...
12,035
39.12
192
py
fl-analysis
fl-analysis-master/src/subspace/keras_ext/engine_topology.py
# Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, pub...
3,056
45.318182
119
py
fl-analysis
fl-analysis-master/src/subspace/keras_ext/layers.py
# Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, pub...
1,235
48.44
99
py
fl-analysis
fl-analysis-master/src/subspace/keras_ext/util.py
# Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, pub...
6,451
38.10303
109
py
fl-analysis
fl-analysis-master/src/subspace/keras_ext/regularizers.py
# Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, pub...
3,830
30.925
80
py
fl-analysis
fl-analysis-master/src/subspace/keras_ext/__init__.py
# Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, pub...
1,104
51.619048
80
py
fl-analysis
fl-analysis-master/src/subspace/keras_ext/rproj_layers.py
# Copyright (c) 2018 Uber Technologies, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, pub...
33,100
41.491656
116
py
fl-analysis
fl-analysis-master/src/data/emnist.py
import os import h5py import tensorflow as tf import numpy as np def load_data(only_digits=True, cache_dir=None): """Loads the Federated EMNIST dataset. Downloads and caches the dataset locally. If previously downloaded, tries to load the dataset from cache. This dataset is derived from the Leaf repository ...
3,842
43.172414
99
py
fl-analysis
fl-analysis-master/src/data/tf_data.py
import itertools import math import numpy as np import tensorflow as tf from tensorflow.python.keras.preprocessing.image import ImageDataGenerator from src.data import image_augmentation from src.data import emnist class Dataset: def __init__(self, x_train, y_train, batch_size=50, x_test=None, y_test=None): ...
18,878
42.802784
135
py
fl-analysis
fl-analysis-master/src/data/image_augmentation.py
import tensorflow as tf import numpy as np from tensorflow.keras.preprocessing.image import apply_affine_transform def augment(image,label): image = tf.image.random_flip_left_right(image) image = tf.numpy_function(shift, [image], tf.float32) image = normalize(image) # debug(image, label) return i...
3,414
28.695652
88
py
fl-analysis
fl-analysis-master/src/data/data_loader.py
from src.attack_dataset_config import AttackDatasetConfig from src.backdoor.edge_case_attack import EdgeCaseAttack from src.client_attacks import Attack from src.data.tf_data import Dataset from src.data.tf_data_global import GlobalDataset, IIDGlobalDataset, NonIIDGlobalDataset, DirichletDistributionDivider from src.co...
17,418
48.768571
118
py
fl-analysis
fl-analysis-master/src/data/leaf_loader.py
"""Loads leaf datasets""" import os import numpy as np import pathlib from src.data.leaf.model_utils import read_data def load_leaf_dataset(dataset, use_val_set=False): eval_set = 'test' if not use_val_set else 'val' base_dir = pathlib.Path(__file__).parent.resolve() train_data_dir = os.path.join(ba...
1,726
22.657534
98
py
fl-analysis
fl-analysis-master/src/data/ardis.py
import os import h5py import tensorflow as tf import numpy as np def load_data(): path = f"{os.path.dirname(os.path.abspath(__file__))}/ARDIS_7.npy" (x_train, y_train), (x_test, y_test) = np.load(path, allow_pickle=True) # Normalize x_train, x_test = x_train / 255.0, x_test / 255.0 x_train, x_test = np.m...
490
27.882353
117
py
fl-analysis
fl-analysis-master/src/data/__init__.py
0
0
0
py
fl-analysis
fl-analysis-master/src/data/tf_data_global.py
from collections import defaultdict import numpy as np from tensorflow.python.keras.preprocessing.image import ImageDataGenerator import tensorflow as tf from src.data import image_augmentation import logging class GlobalDataset: """ A GlobalDataset represents a dataset as a whole. It has two purposes. -...
10,891
41.054054
146
py
fl-analysis
fl-analysis-master/src/data/southwest/__init__.py
import pickle import os import numpy as np def load_data(): cifar_mean = np.array([0.5125891, 0.5335556, 0.5198208, 0.51035565, 0.5311504, 0.51707786, 0.51392424, 0.5343016, 0.5199328, 0.51595825, 0.535995, 0.5210931, 0.51837546, 0.5381541, 0.5226226, 0.5209901, 0.5406102, 0.52463686, 0.52302873, 0.5422941, 0.52...
36,589
1,260.724138
35,628
py
fl-analysis
fl-analysis-master/src/data/leaf/model_utils.py
import json import numpy as np import os from collections import defaultdict def batch_data(data, batch_size, seed): ''' data is a dict := {'x': [numpy array], 'y': [numpy array]} (on one client) returns x, y, which are both numpy array of length: batch_size ''' data_x = data['x'] data_y = dat...
2,067
28.542857
78
py
fl-analysis
fl-analysis-master/src/data/leaf/__init__.py
0
0
0
py
fl-analysis
fl-analysis-master/src/data/leaf/shakespeare/__init__.py
0
0
0
py
fl-analysis
fl-analysis-master/src/data/leaf/shakespeare/preprocess/shake_utils.py
''' helper functions for preprocessing shakespeare data ''' import json import os import re def __txt_to_data(txt_dir, seq_length=80): """Parses text file in given directory into data for next-character model. Args: txt_dir: path to text file seq_length: length of strings in X """ raw...
2,004
28.925373
78
py
fl-analysis
fl-analysis-master/src/data/leaf/shakespeare/preprocess/preprocess_shakespeare.py
"""Preprocesses the Shakespeare dataset for federated training. Copyright 2017 Google Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless requi...
8,701
42.079208
94
py
fl-analysis
fl-analysis-master/src/data/leaf/shakespeare/preprocess/gen_all_data.py
import argparse import json import os from shake_utils import parse_data_in parser = argparse.ArgumentParser() parser.add_argument('--raw', help='include users\' raw .txt data in respective .json files', action="store_true") parser.set_defaults(raw=False) args = parser.parse_args()...
786
29.269231
92
py
fl-analysis
fl-analysis-master/src/data/leaf/shakespeare/preprocess/__init__.py
0
0
0
py
fl-analysis
fl-analysis-master/src/data/leaf/utils/sample.py
''' samples from all raw data; by default samples in a non-iid manner; namely, randomly selects users from raw data until their cumulative amount of data exceeds the given number of datapoints to sample (specified by --fraction argument); ordering of original data points is not preserved in sampled data ''' import a...
6,761
32.475248
91
py
fl-analysis
fl-analysis-master/src/data/leaf/utils/split_data.py
''' splits data into train and test sets ''' import argparse import json import os import random import time import sys from collections import OrderedDict from constants import DATASETS, SEED_FILES def create_jsons_for(user_files, which_set, max_users, include_hierarchy): """used in split-by-user case""" u...
9,200
35.951807
99
py
fl-analysis
fl-analysis-master/src/data/leaf/utils/constants.py
DATASETS = ['sent140', 'femnist', 'shakespeare', 'celeba', 'synthetic'] SEED_FILES = { 'sampling': 'sampling_seed.txt', 'split': 'split_seed.txt' }
148
48.666667
75
py
fl-analysis
fl-analysis-master/src/data/leaf/utils/stats.py
''' assumes that the user has already generated .json file(s) containing data ''' import argparse import json import matplotlib.pyplot as plt import math import numpy as np import os from scipy import io from scipy import stats from constants import DATASETS parser = argparse.ArgumentParser() parser.add_argument('...
2,786
28.967742
139
py
fl-analysis
fl-analysis-master/src/data/leaf/utils/remove_users.py
''' removes users with less than the given number of samples ''' import argparse import json import os from constants import DATASETS parser = argparse.ArgumentParser() parser.add_argument('--name', help='name of dataset to parse; default: sent140;', type=str, choice...
2,288
27.974684
82
py
fl-analysis
fl-analysis-master/src/data/leaf/utils/util.py
import pickle def save_obj(obj, name): with open(name + '.pkl', 'wb') as f: pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL) def load_obj(name): with open(name + '.pkl', 'rb') as f: return pickle.load(f) def iid_divide(l, g): ''' divide list l among g groups each group has either i...
839
25.25
70
py
fl-analysis
fl-analysis-master/src/data/leaf/utils/__init__.py
0
0
0
py
fl-analysis
fl-analysis-master/src/backdoor/edge_case_attack.py
import numpy as np import src.data.ardis as ardis import src.data.southwest as southwest class EdgeCaseAttack: def load(self) -> ((np.ndarray, np.ndarray), (np.ndarray, np.ndarray), (np.ndarray, np.ndarray)): """Loads training and test set""" raise NotImplementedError("Do not instantiate supercla...
10,118
62.641509
1,003
py
fl-analysis
fl-analysis-master/src/backdoor/__init__.py
0
0
0
py
fl-analysis
fl-analysis-master/src/model/resnet.py
from __future__ import print_function import tensorflow as tf from tensorflow.keras.layers import Dense, Conv2D, BatchNormalization, Activation from tensorflow.keras.layers import AveragePooling2D, Input, Flatten from tensorflow.keras.optimizers import Adam from tensorflow.keras.callbacks import ModelCheckpoint, Learni...
15,635
36.317422
81
py
fl-analysis
fl-analysis-master/src/model/modelc.py
import tensorflow.keras as keras from tensorflow.keras.regularizers import l2 from tensorflow.keras import layers def build_modelc(l2_reg): do = 0.2 model = keras.Sequential() # model.add(layers.Dropout(0.2, noise_shape=(32, 32, 3))) model.add(layers.Conv2D(filters=96, kernel_size=3, strides=1, ker...
2,230
73.366667
218
py
fl-analysis
fl-analysis-master/src/model/lenet.py
import tensorflow.keras as keras from tensorflow.keras import layers from tensorflow.keras.regularizers import l2 def build_lenet5(input_shape=(32, 32, 3), l2_reg=None): do = 0.0 regularizer = l2(l2_reg) if l2_reg is not None else None model = keras.Sequential() model.add(layers.Conv2D(filters=6, ...
1,288
46.740741
220
py
fl-analysis
fl-analysis-master/src/model/__init__.py
0
0
0
py
fl-analysis
fl-analysis-master/src/model/test_model.py
import tensorflow.keras as keras from tensorflow.keras import layers from tensorflow.keras.regularizers import l2 def build_test_model(input_shape=(32, 32, 3), l2_reg=None): do = 0.0 regularizer = l2(l2_reg) if l2_reg is not None else None model = keras.Sequential() model.add(layers.Conv2D(filters...
848
37.590909
220
py
fl-analysis
fl-analysis-master/src/model/mobilenet.py
# Implementation by https://github.com/ruchi15/CNN-MobileNetV2-Cifar10 import tensorflow as tf import os import warnings import numpy as np from tensorflow.keras.layers import Input, Activation, Conv2D, Dense, Dropout, BatchNormalization, ReLU, \ DepthwiseConv2D, GlobalAveragePooling2D, GlobalMaxPooling2D, Add f...
6,395
41.357616
129
py
fl-analysis
fl-analysis-master/src/model/stacked_lstm.py
import tensorflow as tf # class StackedLSTM(tf.keras.Model): # def __init__(self, vocab_size, embedding_dim, n_hidden): # super().__init__(self) # self.embedding = tf.keras.layers.Embedding(vocab_size, embedding_dim) # # rnn_cells = [tf.keras.layers.LSTMCell(n_hidden) for _ in range(2)] # stacked_l...
1,762
31.054545
77
py
fl-analysis
fl-analysis-master/src/error/__init__.py
class ConfigurationError(Exception): pass
47
11
36
py
us_hep_funding
us_hep_funding-main/us_hep_funding/constants.py
"""Constants for configuring us_hep_funding""" import pathlib RAW_DATA_PATH = pathlib.Path("/workspaces/us_hep_funding/raw_data/") CLEANED_DBS_PATH = pathlib.Path("/workspaces/us_hep_funding/cleaned_data/") USASPENDING_BASEURL = "https://files.usaspending.gov/award_data_archive/" DOE_CONTRACTS_STR = "_089_Contracts_F...
2,291
53.571429
98
py
us_hep_funding
us_hep_funding-main/us_hep_funding/__init__.py
0
0
0
py
us_hep_funding
us_hep_funding-main/us_hep_funding/clients/create_doe_grants.py
import pandas as pd from us_hep_funding.constants import CLEANED_DBS_PATH, RAW_DATA_PATH from us_hep_funding.data.cleaners import DoeGrantsCleaner def run(): doe_grants2012 = DoeGrantsCleaner( RAW_DATA_PATH / "unzipped" / "DOE-SC_Grants_FY2012.xlsx", 2012, sheet_name="DOE SC Awards FY 20...
2,809
27.383838
87
py
us_hep_funding
us_hep_funding-main/us_hep_funding/clients/ad_hoc.py
data2.loc[ data2["Institution"] == "University of Minnesota", "Congressional District" ] = "MN-05" data4.loc[ data4["Institution"] == "CALIFORNIA INST. OF TECHNOLOGY", "Congressional District *", ] = "CA-27" data3.loc[ data3["Institution"] == "California Institute of Technology (CalTech)", "Congress...
1,189
26.045455
79
py
us_hep_funding
us_hep_funding-main/us_hep_funding/clients/create_suli_data.py
import pandas as pd from us_hep_funding.constants import CLEANED_DBS_PATH from us_hep_funding.data.cleaners import SuliStudentDataCleaner from us_hep_funding.mapping import SuliStudentMapMaker def run(): suli2014 = SuliStudentDataCleaner( "/workspaces/us_hep_funding/raw_data/unzipped/2014-SULI-Terms_Par...
3,362
25.480315
94
py
us_hep_funding
us_hep_funding-main/us_hep_funding/clients/__init__.py
0
0
0
py
us_hep_funding
us_hep_funding-main/us_hep_funding/clients/create_databases.py
"""This will be the top-level API for producing updated data tables.""" from datetime import datetime from us_hep_funding.data.downloaders import ( UsaSpendingDataDownloader, DoeDataDownloader, SuliStudentDataDownloader, ) from us_hep_funding.data.cleaners import DoeContractDataCleaner, NsfGrantsCleaner #...
919
29.666667
81
py
us_hep_funding
us_hep_funding-main/us_hep_funding/clients/create_maps.py
"""This will be the top-level API for creating maps of SULI/CCI/VFP data."""
78
25.333333
52
py
us_hep_funding
us_hep_funding-main/us_hep_funding/data/__init__.py
0
0
0
py
us_hep_funding
us_hep_funding-main/us_hep_funding/data/cleaners/_nsf_grants_cleaner.py
import pandas as pd from us_hep_funding.constants import RAW_DATA_PATH, CLEANED_DBS_PATH class NsfGrantsCleaner: def __init__(self): self.contract_file_list = (RAW_DATA_PATH / "unzipped").glob( "*049_Assistance*.csv" ) def _load_data(self): contract_df_list = [] ...
3,888
39.092784
82
py
us_hep_funding
us_hep_funding-main/us_hep_funding/data/cleaners/_doe_contracts_cleaner.py
import pandas as pd from us_hep_funding.constants import ( CLEANED_DBS_PATH, RAW_DATA_PATH, SC_CONTRACTS_OFFICES, ) class DoeContractDataCleaner: def __init__(self): self.contract_file_list = (RAW_DATA_PATH / "unzipped").glob( "*089_Contracts*.csv" ) def _load_data(se...
3,175
35.505747
88
py
us_hep_funding
us_hep_funding-main/us_hep_funding/data/cleaners/_suli_cci_cleaner.py
import camelot import pandas as pd _LAB_ABBRS_TO_NAMES = { "LBNL": "Lawrence Berkeley National Laboratory", "BNL": "Brookhaven National Laboratory", "ANL": "Argonne National Laboratory", "ORNL": "Oak Ridge National Laboratory", "NREL": "National Renewable Energy Laboratory", "PNNL": "Pacific No...
2,950
33.313953
83
py
us_hep_funding
us_hep_funding-main/us_hep_funding/data/cleaners/__init__.py
from ._doe_contracts_cleaner import DoeContractDataCleaner from ._nsf_grants_cleaner import NsfGrantsCleaner from ._doe_grants_cleaner import DoeGrantsCleaner from ._suli_cci_cleaner import SuliStudentDataCleaner
213
41.8
58
py
us_hep_funding
us_hep_funding-main/us_hep_funding/data/cleaners/_doe_grants_cleaner.py
import re import numpy as np import pandas as pd from titlecase import titlecase class DoeGrantsCleaner: def __init__( self, filepath, fiscal_year, sheet_name=0, skiprows=0, institution_key="Institution", district_key="Congressional District", amoun...
10,169
37.089888
88
py
us_hep_funding
us_hep_funding-main/us_hep_funding/data/downloaders/_doe_downloader.py
import os import requests import warnings import numpy from us_hep_funding.constants import RAW_DATA_PATH, DOE_GRANTS_URLS class DoeDataDownloader: def __init__(self): self.save_path = RAW_DATA_PATH / "unzipped" def run(self, fiscal_year: int): try: url = DOE_GRANTS_URLS[fiscal...
1,107
26.02439
87
py
us_hep_funding
us_hep_funding-main/us_hep_funding/data/downloaders/_usa_spending_downloader.py
"""Classes that download data from usaspending.gov""" import pathlib import warnings import zipfile import requests from us_hep_funding.constants import ( DOE_CONTRACTS_STR, NSF_GRANTS_STR, RAW_DATA_PATH, USASPENDING_BASEURL, ) class UsaSpendingDataDownloader: """A downloader for getting data f...
1,531
26.357143
79
py
us_hep_funding
us_hep_funding-main/us_hep_funding/data/downloaders/_suli_student_data.py
import os import requests import warnings import numpy from us_hep_funding.constants import RAW_DATA_PATH, SULI_STUDENT_URLS class SuliStudentDataDownloader: def __init__(self): self.save_path = RAW_DATA_PATH / "unzipped" def run(self, fiscal_year: int): try: url = SULI_STUDENT...
1,119
26.317073
87
py