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
lm-intervention
lm-intervention-master/attention_figures1.py
""" Creates figures for attention intervention analysis from JSON files: - Stacked bar chart with direct/indirect/total effects - Heatmap for head-level effects - Barplot for layer-level effects - Combined heatmap/barplot for head- and layer-level effects """ import json import os import numpy as np i...
11,984
46.371542
174
py
lm-intervention
lm-intervention-master/analysis.py
import os import numpy as np import pandas as pd from glob import glob from tqdm import tqdm import matplotlib.pyplot as plt import sys import seaborn as sns sns.set_context('talk') sns.set_style('whitegrid') PATH = sys.argv[1] FIGURES_PATH = sys.argv[2] by_feather = sys.argv[3].lower() == 'true' MODELS = ['Distil', ...
6,514
37.779762
78
py
lm-intervention
lm-intervention-master/attention_intervention_model.py
""" Changes the huggingface transformer attention module to allow interventions in the attention distribution. """ import torch import torch.nn as nn import torch.nn.functional as F import math class AttentionOverride(nn.Module): """A copy of `modeling_gpt2.Attention` class, but with overridden attention values"...
29,231
39.998597
127
py
lm-intervention
lm-intervention-master/utils_num_agreement.py
import pandas as pd from copy import deepcopy def batch(iterable, bsize=1): total_len = len(iterable) for ndx in range(0, total_len, bsize): yield list(iterable[ndx:min(ndx + bsize, total_len)]) def convert_results_to_pd(interventions, intervention_results, layer_fixed=None, neuron_fixed=None): ...
3,316
43.226667
101
py
lm-intervention
lm-intervention-master/attention_intervention_structural.py
"""Performs attention intervention on Winobias samples and saves results to JSON file.""" import json import os import random import sys from pandas import DataFrame from transformers import ( GPT2Tokenizer, TransfoXLTokenizer, XLNetTokenizer ) from attention_utils import perform_interventions, get_odds_ratio fr...
8,648
46.262295
149
py
lm-intervention
lm-intervention-master/attention_figures2.py
""" Creates figures for attention intervention analysis from JSON files: - Stacked bar chart with direct/indirect/total effects - Heatmap for head-level effects - Barplot for layer-level effects - Combined heatmap/barplot for head- and layer-level effects """ import json import os import numpy as np i...
14,418
45.067093
174
py
lm-intervention
lm-intervention-master/make_feathers.py
import os import pandas as pd from glob import glob from tqdm import tqdm import sys PATH = sys.argv[1] MODELS = ['Distil', 'Small', 'Medium', 'Large', 'XL'] CHUNKSIZE = 100000 EXAMPLE_TYPES = ['None', 'Distractor', 'Plural attractor', 'Singular attractor'] def get_size(f): for m in MODELS: if m....
2,629
33.155844
77
py
lm-intervention
lm-intervention-master/featherify.py
import pandas as pd import os, sys from glob import glob from tqdm import tqdm PATH = sys.argv[1] dtypes = { 'word': 'category', 'base_string': 'category', 'alt_string1': 'category', 'candidate1': 'category', 'candidate2': 'category', 'layer': 'int32', 'neuron': 'int32', } files = list(filter(lambda x:...
488
21.227273
68
py
lm-intervention
lm-intervention-master/heatmaps.py
import pandas as pd import matplotlib.pyplot as plt import sys import seaborn as sns sns.set() PATH = sys.argv[1] FIGURES_PATH = sys.argv[2] MODELS = ['Distil', 'Small', 'Medium', 'Large', 'XL'] EXAMPLE_TYPES = ['None', 'Distractor', 'Plural attractor', 'Singular attractor'] FORMAT = '.pdf' def draw_heatmap...
1,188
28
72
py
lm-intervention
lm-intervention-master/transformers_modified/modeling_transfo_xl.py
""" A copy of transformers/modeling_transfo_xl.py from the Huggingface transformers library modified so that the attention module is called with non-keyword arguments (to make those arguments accessible to the hook). """ # coding=utf-8 # Copyright 2018 Google AI, Google Brain and Carnegie Mellon University Auth...
40,378
42.795011
151
py
lm-intervention
lm-intervention-master/transformers_modified/modeling_xlnet.py
""" A copy of transformers/modeling_xlnet.py from the Huggingface transformers library modified so that the attention module is called with non-keyword arguments (to make those arguments accessible to the hook). """ # coding=utf-8 # Copyright 2018 Google AI, Google Brain and Carnegie Mellon University Authors a...
79,781
47.946012
304
py
icml2022-mips
icml2022-mips-main/src/synthetic/main_n_val.py
from logging import getLogger from pathlib import Path from time import time import warnings import hydra import numpy as np from obp.dataset import linear_reward_function from obp.dataset import SyntheticBanditDatasetWithActionEmbeds from obp.ope import RegressionModel from omegaconf import DictConfig from ope import...
6,247
37.331288
88
py
icml2022-mips
icml2022-mips-main/src/synthetic/main_n_actions.py
from logging import getLogger from pathlib import Path from time import time import warnings import hydra import numpy as np from obp.dataset import linear_reward_function from obp.dataset import SyntheticBanditDatasetWithActionEmbeds from obp.ope import RegressionModel from omegaconf import DictConfig from ope import...
5,801
36.432258
88
py
icml2022-mips
icml2022-mips-main/src/synthetic/main_n_def_actions.py
from logging import getLogger from pathlib import Path from time import time import warnings import hydra import numpy as np from obp.dataset import linear_reward_function from obp.dataset import SyntheticBanditDatasetWithActionEmbeds from obp.ope import RegressionModel from omegaconf import DictConfig from ope import...
5,899
37.064516
88
py
icml2022-mips
icml2022-mips-main/src/synthetic/main_eps.py
from logging import getLogger from pathlib import Path from time import time import warnings import hydra import numpy as np from obp.dataset import linear_reward_function from obp.dataset import SyntheticBanditDatasetWithActionEmbeds from obp.ope import RegressionModel from omegaconf import DictConfig from ope import...
5,750
36.103226
88
py
icml2022-mips
icml2022-mips-main/src/synthetic/ope.py
from typing import Dict from typing import Optional import numpy as np from obp.ope import DirectMethod as DM from obp.ope import DoublyRobust as DR from obp.ope import DoublyRobustWithShrinkageTuning as DRos from obp.ope import InverseProbabilityWeighting as IPS from obp.ope import MarginalizedInverseProbabilityWeigh...
3,080
35.678571
88
py
icml2022-mips
icml2022-mips-main/src/synthetic/main_beta.py
from logging import getLogger from pathlib import Path from time import time import warnings import hydra import numpy as np from obp.dataset import linear_reward_function from obp.dataset import SyntheticBanditDatasetWithActionEmbeds from obp.ope import RegressionModel from omegaconf import DictConfig from ope import...
5,764
36.193548
88
py
icml2022-mips
icml2022-mips-main/src/synthetic/policy.py
import numpy as np def gen_eps_greedy( expected_reward: np.ndarray, is_optimal: bool = True, eps: float = 0.0, ) -> np.ndarray: "Generate an evaluation policy via the epsilon-greedy rule." base_pol = np.zeros_like(expected_reward) if is_optimal: a = np.argmax(expected_reward, axis=1) ...
565
23.608696
64
py
icml2022-mips
icml2022-mips-main/src/synthetic/plots.py
import matplotlib.pyplot as plt import seaborn as sns registered_colors = { "MIPS": "tab:gray", "MIPS (true)": "tab:orange", "MIPS (w/ SLOPE)": "tab:green", "IPS": "tab:red", "DR": "tab:blue", "DM": "tab:purple", "SwitchDR": "tab:brown", r"DR-$\lambda$": "tab:olive", "DRos": "tab:p...
9,993
28.480826
96
py
icml2022-mips
icml2022-mips-main/src/synthetic/main_noise.py
from logging import getLogger from pathlib import Path from time import time import warnings import hydra import numpy as np from obp.dataset import linear_reward_function from obp.dataset import SyntheticBanditDatasetWithActionEmbeds from obp.ope import RegressionModel from omegaconf import DictConfig from ope import...
5,775
36.264516
88
py
icml2022-mips
icml2022-mips-main/src/synthetic/main_n_unobs_cat_dim.py
from logging import getLogger from pathlib import Path from time import time import warnings import hydra import numpy as np from obp.dataset import linear_reward_function from obp.dataset import SyntheticBanditDatasetWithActionEmbeds from obp.ope import RegressionModel from omegaconf import DictConfig from ope import...
5,962
36.980892
88
py
icml2022-mips
icml2022-mips-main/src/real/main.py
from dataclasses import dataclass from logging import getLogger from pathlib import Path from time import time from typing import Optional import warnings import hydra import matplotlib.pyplot as plt import numpy as np from obp.dataset import OpenBanditDataset from obp.ope import RegressionModel from obp.policy import...
8,837
30.791367
82
py
icml2022-mips
icml2022-mips-main/src/real/ope.py
import itertools from typing import Dict from typing import Optional import numpy as np from obp.ope import BaseOffPolicyEstimator from obp.ope import DirectMethod as DM from obp.ope import DoublyRobust as DR from obp.ope import DoublyRobustWithShrinkageTuning as DRos from obp.ope import InverseProbabilityWeighting as...
8,411
33.904564
96
py
litemangle
litemangle-master/litemangle.py
#!/usr/bin/env python # import numpy as N import os import sys import re import string class LiteMangle: """ LiteMangle: A Python class to implement some very basic mangle routines which allow us to manipulate a mangle mask. This is a subset of the more complicated Python-based Mangle package, ...
8,796
33.229572
79
py
randCache
randCache-main/Type-III/main.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 16:54:52 2021 @author: anirban """ import argparse from simulator import Simulator from collections import OrderedDict import configparser import random def parse_cli_args(): parser = argparse.ArgumentParser() parser.add_argument( ...
2,865
24.81982
88
py
randCache
randCache-main/Type-III/word_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:57:06 2021 @author: anirban """ class WordAddress(int): def get_consecutive_words(self, num_words_per_block): offset = self % num_words_per_block return [(self - offset + i) for i in range(num_words_per_block)]
309
22.846154
72
py
randCache
randCache-main/Type-III/getHM.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri May 28 14:29:38 2021 @author: anirban """ import matplotlib.pyplot as plt import numpy as np with open("timing_nopart_rand_cache.txt", 'r') as f1: file = f1.readlines() timing = list(filter(None, list(map(lambda each:each.strip("\n"), file)))...
1,109
23.666667
79
py
randCache
randCache-main/Type-III/table.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 19 15:26:46 2021 @author: anirban """ class Table(object): alignment_symbols = { 'left': '<', 'center': '^', 'right': '>' } def __init__(self, num_cols, width, alignment='left', title=No...
1,235
27.744186
153
py
randCache
randCache-main/Type-III/bin_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:44:28 2021 @author: anirban """ import random from present import Present class BinaryAddress(str): partition = None def __new__(cls, bin_addr=None, word_addr=None, num_addr_bits=0): if word_addr is not None: retur...
2,227
31.289855
85
py
randCache
randCache-main/Type-III/simulator.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:00:37 2021 @author: anirban """ import math import shutil from collections import OrderedDict from cache import Cache from bin_addr import BinaryAddress from reference import Reference from table import Table REF_COL_NAMES = ('WordAddr', 'B...
4,679
35.850394
163
py
randCache
randCache-main/Type-III/cache.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:53:27 2021 @author: anirban """ from bin_addr import BinaryAddress from word_addr import WordAddress from reference import ReferenceCacheStatus import random class Cache(dict): partition = None cal_index = None def __init__(self, ...
5,073
36.865672
132
py
randCache
randCache-main/Type-III/present.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 23:59:35 2021 @author: anirban """ class Present: def __init__(self,key,rounds=32): """Create a PRESENT cipher object key: the key as a 128-bit or 80-bit rawstring rounds: the number o...
5,630
34.415094
100
py
randCache
randCache-main/Type-III/reference.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 21:12:52 2021 @author: anirban """ from collections import OrderedDict from enum import Enum from bin_addr import BinaryAddress from word_addr import WordAddress class Reference(object): def __init__(self, word_addr, num_addr_bits, n...
1,499
27.301887
132
py
randCache
randCache-main/Type-I/main.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 16:54:52 2021 @author: anirban """ import argparse from simulator import Simulator from collections import OrderedDict import configparser import random def parse_cli_args(): parser = argparse.ArgumentParser() parser.add_argument( ...
2,865
24.81982
88
py
randCache
randCache-main/Type-I/word_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:57:06 2021 @author: anirban """ class WordAddress(int): def get_consecutive_words(self, num_words_per_block): offset = self % num_words_per_block return [(self - offset + i) for i in range(num_words_per_block)]
309
22.846154
72
py
randCache
randCache-main/Type-I/getHM.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri May 28 14:29:38 2021 @author: anirban """ import matplotlib.pyplot as plt import numpy as np with open("timing_nopart_norand.txt", 'r') as f1: file = f1.readlines() timing = list(filter(None, list(map(lambda each:each.strip("\n"), file)))) c...
1,073
22.866667
74
py
randCache
randCache-main/Type-I/table.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 19 15:26:46 2021 @author: anirban """ class Table(object): alignment_symbols = { 'left': '<', 'center': '^', 'right': '>' } def __init__(self, num_cols, width, alignment='left', title=No...
1,235
27.744186
153
py
randCache
randCache-main/Type-I/bin_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:44:28 2021 @author: anirban """ import random class BinaryAddress(str): partition = None def __new__(cls, bin_addr=None, word_addr=None, num_addr_bits=0): if word_addr is not None: return super().__new__(cls, bin(w...
1,945
29.40625
85
py
randCache
randCache-main/Type-I/simulator.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:00:37 2021 @author: anirban """ import math import shutil from collections import OrderedDict from cache import Cache from bin_addr import BinaryAddress from reference import Reference from table import Table REF_COL_NAMES = ('WordAddr', 'B...
4,679
35.850394
163
py
randCache
randCache-main/Type-I/cache.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:53:27 2021 @author: anirban """ from bin_addr import BinaryAddress from word_addr import WordAddress from reference import ReferenceCacheStatus import random class Cache(dict): partition = None cal_index = None def __init__(self, ...
5,073
36.865672
132
py
randCache
randCache-main/Type-I/reference.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 21:12:52 2021 @author: anirban """ from collections import OrderedDict from enum import Enum from bin_addr import BinaryAddress from word_addr import WordAddress class Reference(object): def __init__(self, word_addr, num_addr_bits, n...
1,499
27.301887
132
py
randCache
randCache-main/Variant B (SAE)/main.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 16:54:52 2021 @author: anirban """ import argparse from simulator import Simulator from collections import OrderedDict import configparser from ast import literal_eval import random def parse_cli_args(): parser = argparse.ArgumentParser()...
2,869
24.855856
73
py
randCache
randCache-main/Variant B (SAE)/word_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:57:06 2021 @author: anirban """ class WordAddress(int): def get_consecutive_words(self, num_words_per_block): offset = self % num_words_per_block return [(self - offset + i) for i in range(num_words_per_block)]
309
22.846154
72
py
randCache
randCache-main/Variant B (SAE)/table.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 19 15:26:46 2021 @author: anirban """ class Table(object): alignment_symbols = { 'left': '<', 'center': '^', 'right': '>' } def __init__(self, num_cols, width, alignment='left', title=No...
1,235
27.744186
153
py
randCache
randCache-main/Variant B (SAE)/bin_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:44:28 2021 @author: anirban """ import random from present import Present class BinaryAddress(str): def __new__(cls, bin_addr=None, word_addr=None, num_addr_bits=0): if word_addr is not None: return super().__new__(cls...
2,351
31.666667
80
py
randCache
randCache-main/Variant B (SAE)/simulator.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:00:37 2021 @author: anirban """ import math import shutil from collections import OrderedDict from cache import Cache #from cache import DataStore from bin_addr import BinaryAddress from reference import Reference from table import Table ...
5,288
35.475862
311
py
randCache
randCache-main/Variant B (SAE)/filehandler.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu Aug 12 23:58:45 2021 @author: anirban """ class writeFile(object): def write_address(plaintext, ciphertext): with open('address_list.txt', 'a') as filehandle: filehandle.writelines(str(plaintext)) filehandle.writeli...
1,112
31.735294
71
py
randCache
randCache-main/Variant B (SAE)/cache.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:53:27 2021 @author: anirban """ from bin_addr import BinaryAddress from word_addr import WordAddress from reference import ReferenceCacheStatus from reference import ReferenceEvictionStatus from filehandler import writeFile import random impo...
9,582
44.417062
238
py
randCache
randCache-main/Variant B (SAE)/present.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 23:59:35 2021 @author: anirban """ class Present: def __init__(self,key,rounds=32): """Create a PRESENT cipher object key: the key as a 128-bit or 80-bit rawstring rounds: the number o...
5,630
34.415094
100
py
randCache
randCache-main/Variant B (SAE)/plotter.py
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Sun Oct 30 21:19:51 2022 @author: anirban """ import matplotlib.pyplot as plt import numpy as np with open("outfile.txt", 'r') as f1: file = f1.readlines() X = []; Y = [] for line in file: cache_size = line.strip("\n").split(":")[0] throw...
1,638
33.145833
82
py
randCache
randCache-main/Variant B (SAE)/rand_num_gen.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Jul 1 12:16:04 2022 @author: anirban """ import random import os import math outfile = "outfile.txt" eviction_file = "eviction_status.txt" base = 16777216 if os.path.exists(outfile): os.remove(outfile) with open("config.ini", "r") as f: ...
1,426
23.186441
81
py
randCache
randCache-main/Variant B (SAE)/reference.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 21:12:52 2021 @author: anirban """ from collections import OrderedDict from enum import Enum from bin_addr import BinaryAddress from word_addr import WordAddress class Reference(object): def __init__(self, word_addr, num_addr_bits, ...
1,829
25.911765
132
py
randCache
randCache-main/mirage_bucket_and_balls/plotter.py
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Sun Oct 30 21:19:51 2022 @author: anirban """ import matplotlib.pyplot as plt import numpy as np with open("mirage_bucket_ball_data.txt", 'r') as f1: file = f1.readlines() timing = list(map(int, list(map(lambda each:each.strip("\n"), file)))) ...
815
23.727273
79
py
randCache
randCache-main/Variant A/main.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 16:54:52 2021 @author: anirban """ import argparse from simulator import Simulator from collections import OrderedDict import configparser import random def parse_cli_args(): parser = argparse.ArgumentParser() parser.add_argument( ...
2,737
24.830189
68
py
randCache
randCache-main/Variant A/word_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:57:06 2021 @author: anirban """ class WordAddress(int): def get_consecutive_words(self, num_words_per_block): offset = self % num_words_per_block return [(self - offset + i) for i in range(num_words_per_block)]
309
22.846154
72
py
randCache
randCache-main/Variant A/table.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 19 15:26:46 2021 @author: anirban """ class Table(object): alignment_symbols = { 'left': '<', 'center': '^', 'right': '>' } def __init__(self, num_cols, width, alignment='left', title=No...
1,235
27.744186
153
py
randCache
randCache-main/Variant A/bin_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:44:28 2021 @author: anirban """ import random from present import Present class BinaryAddress(str): partition = None def __new__(cls, bin_addr=None, word_addr=None, num_addr_bits=0): if word_addr is not None: retur...
2,227
31.289855
85
py
randCache
randCache-main/Variant A/simulator.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:00:37 2021 @author: anirban """ import math import shutil from collections import OrderedDict from cache import Cache from bin_addr import BinaryAddress from reference import Reference from table import Table REF_COL_NAMES = ('WordAddr', 'B...
4,679
35.850394
163
py
randCache
randCache-main/Variant A/getHM_ppp.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri May 28 14:29:38 2021 @author: anirban """ import matplotlib.pyplot as plt import numpy as np with open("timing_ppp_algorithm_run_4.txt", 'r') as f1: file = f1.readlines() timing = list(filter(None, list(map(lambda each:each.strip("\n"), file)...
1,118
23.866667
79
py
randCache
randCache-main/Variant A/getHM_new.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri May 28 14:29:38 2021 @author: anirban """ import matplotlib.pyplot as plt import numpy as np with open("timing_new_algorithm_run_4.txt", 'r') as f1: file = f1.readlines() timing = list(filter(None, list(map(lambda each:each.strip("\n"), file)...
1,118
23.866667
79
py
randCache
randCache-main/Variant A/cache.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:53:27 2021 @author: anirban """ from bin_addr import BinaryAddress from word_addr import WordAddress from reference import ReferenceCacheStatus import random class Cache(dict): partition = None cal_index = None def __init__(self, ...
5,073
36.865672
132
py
randCache
randCache-main/Variant A/present.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 23:59:35 2021 @author: anirban """ class Present: def __init__(self,key,rounds=32): """Create a PRESENT cipher object key: the key as a 128-bit or 80-bit rawstring rounds: the number o...
5,630
34.415094
100
py
randCache
randCache-main/Variant A/reference.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 21:12:52 2021 @author: anirban """ from collections import OrderedDict from enum import Enum from bin_addr import BinaryAddress from word_addr import WordAddress class Reference(object): def __init__(self, word_addr, num_addr_bits, n...
1,499
27.301887
132
py
randCache
randCache-main/Variant B/main.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 16:54:52 2021 @author: anirban """ import argparse from simulator import Simulator from collections import OrderedDict import configparser import random from ast import literal_eval def parse_cli_args(): parser = argparse.ArgumentParser()...
2,931
25.414414
86
py
randCache
randCache-main/Variant B/word_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:57:06 2021 @author: anirban """ class WordAddress(int): def get_consecutive_words(self, num_words_per_block): offset = self % num_words_per_block return [(self - offset + i) for i in range(num_words_per_block)]
309
22.846154
72
py
randCache
randCache-main/Variant B/getHM.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri May 28 14:29:38 2021 @author: anirban """ import matplotlib.pyplot as plt with open("timing_new_algorithm_run_4.txt", 'r') as f1: file = f1.readlines() timing = list(filter(None, list(map(lambda each:each.strip("\n"), file)))) count_hits = [0...
1,096
24.511628
79
py
randCache
randCache-main/Variant B/table.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 19 15:26:46 2021 @author: anirban """ class Table(object): alignment_symbols = { 'left': '<', 'center': '^', 'right': '>' } def __init__(self, num_cols, width, alignment='left', title=No...
1,235
27.744186
153
py
randCache
randCache-main/Variant B/bin_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:44:28 2021 @author: anirban """ import random from present import Present class BinaryAddress(str): def __new__(cls, bin_addr=None, word_addr=None, num_addr_bits=0): if word_addr is not None: return super().__new__(cls...
2,353
30.810811
80
py
randCache
randCache-main/Variant B/simulator.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:00:37 2021 @author: anirban """ import math import shutil from collections import OrderedDict from cache import Cache from bin_addr import BinaryAddress from reference import Reference from table import Table REF_COL_NAMES = ('WordAddr', ...
5,014
36.706767
311
py
randCache
randCache-main/Variant B/cache.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:53:27 2021 @author: anirban """ from bin_addr import BinaryAddress from word_addr import WordAddress from reference import ReferenceCacheStatus from reference import ReferenceEvictionStatus import random class Cache(dict): partition = Non...
6,699
40.875
257
py
randCache
randCache-main/Variant B/present.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 23:59:35 2021 @author: anirban """ class Present: def __init__(self,key,rounds=32): """Create a PRESENT cipher object key: the key as a 128-bit or 80-bit rawstring rounds: the number o...
5,630
34.415094
100
py
randCache
randCache-main/Variant B/reference.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 21:12:52 2021 @author: anirban """ from collections import OrderedDict from enum import Enum from bin_addr import BinaryAddress from word_addr import WordAddress class Reference(object): def __init__(self, word_addr, num_addr_bits, ...
1,851
25.084507
132
py
randCache
randCache-main/Variant_B_SAE_rptr_invalidation/main.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 16:54:52 2021 @author: anirban """ import argparse from simulator import Simulator from collections import OrderedDict import configparser from ast import literal_eval import random import os def parse_cli_args(): parser = argparse.Argume...
3,156
25.090909
73
py
randCache
randCache-main/Variant_B_SAE_rptr_invalidation/word_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:57:06 2021 @author: anirban """ class WordAddress(int): def get_consecutive_words(self, num_words_per_block): offset = self % num_words_per_block return [(self - offset + i) for i in range(num_words_per_block)]
309
22.846154
72
py
randCache
randCache-main/Variant_B_SAE_rptr_invalidation/table.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 19 15:26:46 2021 @author: anirban """ class Table(object): alignment_symbols = { 'left': '<', 'center': '^', 'right': '>' } def __init__(self, num_cols, width, alignment='left', title=No...
1,235
27.744186
153
py
randCache
randCache-main/Variant_B_SAE_rptr_invalidation/bin_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:44:28 2021 @author: anirban """ import random from present import Present class BinaryAddress(str): def __new__(cls, bin_addr=None, word_addr=None, num_addr_bits=0): if word_addr is not None: return super().__new__(cls...
2,351
31.666667
80
py
randCache
randCache-main/Variant_B_SAE_rptr_invalidation/simulator.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:00:37 2021 @author: anirban """ import math import shutil from collections import OrderedDict from cache import Cache from bin_addr import BinaryAddress from reference import Reference from table import Table REF_COL_NAMES = ('WordAddr', ...
5,607
39.345324
311
py
randCache
randCache-main/Variant_B_SAE_rptr_invalidation/filehandler.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu Aug 12 23:58:45 2021 @author: anirban """ class writeFile(object): def write_address(plaintext, ciphertext): with open('address_list.txt', 'a') as filehandle: filehandle.writelines(str(plaintext)) filehandle.writeli...
1,112
31.735294
71
py
randCache
randCache-main/Variant_B_SAE_rptr_invalidation/cache.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:53:27 2021 @author: anirban """ from bin_addr import BinaryAddress from word_addr import WordAddress from reference import ReferenceCacheStatus from reference import ReferenceEvictionStatus from filehandler import writeFile import random impo...
12,603
55.267857
238
py
randCache
randCache-main/Variant_B_SAE_rptr_invalidation/present.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 23:59:35 2021 @author: anirban """ class Present: def __init__(self,key,rounds=32): """Create a PRESENT cipher object key: the key as a 128-bit or 80-bit rawstring rounds: the number o...
5,630
34.415094
100
py
randCache
randCache-main/Variant_B_SAE_rptr_invalidation/reference.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 21:12:52 2021 @author: anirban """ from collections import OrderedDict from enum import Enum from bin_addr import BinaryAddress from word_addr import WordAddress class Reference(object): def __init__(self, word_addr, num_addr_bits, ...
1,829
25.911765
132
py
randCache
randCache-main/Type-II/main.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 16:54:52 2021 @author: anirban """ import argparse from simulator import Simulator from collections import OrderedDict import configparser import random def parse_cli_args(): parser = argparse.ArgumentParser() parser.add_argument( ...
2,780
24.990654
88
py
randCache
randCache-main/Type-II/word_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:57:06 2021 @author: anirban """ class WordAddress(int): def get_consecutive_words(self, num_words_per_block): offset = self % num_words_per_block return [(self - offset + i) for i in range(num_words_per_block)]
309
22.846154
72
py
randCache
randCache-main/Type-II/getHM.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri May 28 14:29:38 2021 @author: anirban """ import matplotlib.pyplot as plt import numpy as np with open("timing_new_part_no_rand.txt", 'r') as f1: file = f1.readlines() timing = list(filter(None, list(map(lambda each:each.strip("\n"), file))))...
1,082
23.066667
74
py
randCache
randCache-main/Type-II/table.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 19 15:26:46 2021 @author: anirban """ class Table(object): alignment_symbols = { 'left': '<', 'center': '^', 'right': '>' } def __init__(self, num_cols, width, alignment='left', title=No...
1,235
27.744186
153
py
randCache
randCache-main/Type-II/bin_addr.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 19:44:28 2021 @author: anirban """ import random from present import Present class BinaryAddress(str): partition = None def __new__(cls, bin_addr=None, word_addr=None, num_addr_bits=0): if word_addr is not None: retur...
1,973
29.369231
85
py
randCache
randCache-main/Type-II/simulator.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:00:37 2021 @author: anirban """ import math import shutil from collections import OrderedDict from cache import Cache from bin_addr import BinaryAddress from reference import Reference from table import Table REF_COL_NAMES = ('WordAddr', 'B...
4,696
35.695313
163
py
randCache
randCache-main/Type-II/cache.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 17:53:27 2021 @author: anirban """ from bin_addr import BinaryAddress from word_addr import WordAddress from reference import ReferenceCacheStatus import random class Cache(dict): partition = None cal_index = None def __init__(self, ...
5,073
36.865672
132
py
randCache
randCache-main/Type-II/present.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 23:59:35 2021 @author: anirban """ class Present: def __init__(self,key,rounds=32): """Create a PRESENT cipher object key: the key as a 128-bit or 80-bit rawstring rounds: the number o...
5,630
34.415094
100
py
randCache
randCache-main/Type-II/reference.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue May 18 21:12:52 2021 @author: anirban """ from collections import OrderedDict from enum import Enum from bin_addr import BinaryAddress from word_addr import WordAddress class Reference(object): def __init__(self, word_addr, num_addr_bits, n...
1,499
27.301887
132
py
FPI
FPI-master/readData.py
import tensorflow as tf import os import numpy as np import nibabel as nib class data_frame: """ A single character class. """ def __init__(self, batch_dim, primary_axis): #this helps keep data handling consistent self.batch_dim = batch_dim self.primary_axis = primary_axis ...
5,318
35.9375
135
py
FPI
FPI-master/self_sup_task.py
import numpy as np import tensorflow as tf to_categorical = tf.keras.utils.to_categorical ''' def to_categorical(y,num_classes): onehot = np.zeros((len(y), num_classes)) onehot[np.arange(len(y)),y] = 1 return onehot ''' def create_interp_mask(ima,patch_center,patch_width,patch_interp): dims=np.shape(i...
2,950
34.987805
119
py
FPI
FPI-master/fpiSubmit.py
import numpy as np import itertools import copy from datetime import datetime import os import pickle from sklearn.metrics import average_precision_score import tensorflow as tf import readData import self_sup_task from models.wide_residual_network import create_wide_residual_network_selfsup from scipy.signal import ...
9,435
34.078067
122
py
FPI
FPI-master/utils.py
import os import numpy as np from sklearn.metrics import roc_curve, precision_recall_curve, auc, average_precision_score def save_roc_pr_curve_data(scores, labels, file_path=None): scores = scores.flatten() labels = labels.flatten() scores_pos = scores[labels == 1] scores_neg = scores[labels != 1] ...
1,690
32.82
104
py
FPI
FPI-master/train_simple.py
import os import nibabel as nib import numpy as np import fpiSubmit def train_folder(input_dir,output_dir,mode,data): fpiSubmit.train_folder(input_dir,output_dir,mode,data) return if __name__ == "__main__": import argparse parser = argparse.ArgumentParser() parser.add_argument("-i", "--input", ...
825
24.030303
118
py
FPI
FPI-master/evalresults.py
import json import os import random import traceback import nibabel as nib import numpy as np from sklearn import metrics class InvalidPredictionException(Exception): pass class CouldNotProcessException(Exception): pass def process_file_pixelwise(pred_path, label_path): pred_list, label_list = [], [...
6,387
28.437788
115
py
FPI
FPI-master/var_ops.py
""" Tools for manipulating sets of variables. """ import numpy as np from keras import backend as K import tensorflow as tf import copy def interpolate_vars(old_vars, new_vars, epsilon): """ Interpolate between two sequences of variables. """ return add_vars(old_vars, scale_vars(subtract_vars(new_vars...
1,366
23.410714
143
py
FPI
FPI-master/pred_simple.py
import os import nibabel as nib import numpy as np import fpiSubmit def predict_folder(input_dir,output_dir,mode,data): fpiSubmit.predict_folder(input_dir,output_dir,mode,data) return if __name__ == "__main__": import argparse parser = argparse.ArgumentParser() parser.add_argument("-i", "--inpu...
831
24.212121
118
py
FPI
FPI-master/eval_simple.py
import os import nibabel as nib import numpy as np import fpiSubmit import evalresults def eval_folder(output_dir,label_dir,mode,data): evalresults.eval_dir(output_dir,label_dir,mode=mode,save_file=os.path.join(output_dir,data+"_"+mode+"_score.txt")) return if __name__ == "__main__": import argparse ...
902
25.558824
118
py
FPI
FPI-master/models/wide_residual_network.py
#using code from https://github.com/asmith26/wide_resnets_keras.git from __future__ import absolute_import from __future__ import division from __future__ import print_function from six.moves import range import os import logging logging.basicConfig(level=logging.DEBUG) import sys #sys.stdout = sys.stderr # Prevent ...
12,583
43.624113
164
py