content
stringlengths
1
1.05M
input_ids
listlengths
1
883k
ratio_char_token
float64
1
22.9
token_count
int64
1
883k
import os import numpy as np import pandas as pd import torch as th from mstarhe.core.nn.models import PrettyFeedForward from MstarHe2R.components.dataloader import Mstar2RDataLoader __IMG_SIZE__ = 128 * 128 def _example(): Net = MSTARNet Net.device = None from components.graphs.graph2 import TestL4MSTARANNetGraph G = [TestL4MSTARANNetGraph] for g, params in G: Net.model_graph_class = g Net.alpha = params["aph"] Net.step = params["stp"] net = Net(3, reg=None, dropout=False) print(net.graph.__class__.__name__) # print(net.get_data_loader(False)) # print(len(net.test_samples_)) net.train(params['n'], 'PQ', checkpoint=params['cp']) if __name__ == '__main__': _example()
[ 11748, 28686, 198, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 19798, 292, 355, 279, 67, 198, 11748, 28034, 355, 294, 198, 198, 6738, 285, 7364, 258, 13, 7295, 13, 20471, 13, 27530, 1330, 20090, 18332, 39746, 198, 6738, 337, 7364, ...
2.346505
329
from abc import ABC, abstractmethod '''Comments In the original solution only functions were used to implement the event system (observer pattern). In this implementation I wanted to write classes (to be as nearest as possible to the pattern (?)). It is surely better to use python first-citizen functions to create the event handles (basically this is what I done, I created handle classes to write different implementations of update method). '''
[ 6738, 450, 66, 1330, 9738, 11, 12531, 24396, 198, 198, 7061, 6, 23903, 198, 818, 262, 2656, 4610, 691, 5499, 547, 973, 284, 198, 320, 26908, 262, 1785, 1080, 357, 672, 15388, 3912, 737, 198, 198, 818, 428, 7822, 314, 2227, 284, 3551...
4.261682
107
#! /usr/bin/env python import time import os import argparse import json import cv2 import sys sys.path += [os.path.abspath('keras-yolo3-master')] from utils.utils import get_yolo_boxes, makedirs from utils.bbox import draw_boxes from tensorflow.keras.models import load_model from tqdm import tqdm import numpy as np from panel_disconnect import disconnect if __name__ == '__main__': argparser = argparse.ArgumentParser(description='Predict with a trained yolo model') argparser.add_argument('-c', '--conf', help='path to configuration file') argparser.add_argument('-i', '--input', help='path to an image, a directory of images, a video, or webcam') argparser.add_argument('-o', '--output', default='output/', help='path to output directory') args = argparser.parse_args() _main_(args)
[ 2, 0, 1220, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 11748, 640, 198, 11748, 28686, 198, 11748, 1822, 29572, 198, 11748, 33918, 198, 11748, 269, 85, 17, 198, 11748, 25064, 198, 17597, 13, 6978, 15853, 685, 418, 13, 6978, 13, 397, ...
2.996337
273
import tensorflow.keras.constraints as constraints from tensorflow.keras.layers import GlobalAveragePooling2D from tensorflow.keras.layers import BatchNormalization from tensorflow.keras.layers import Conv2DTranspose from tensorflow.keras.layers import LeakyReLU from tensorflow.keras.layers import ReLU from tensorflow.keras.layers import Conv2D from tensorflow.keras.layers import Lambda from tensorflow.keras.layers import Layer from tensorflow.keras.layers import Dense from tensorflow.keras.layers import Add from tensorflow_addons.layers import InstanceNormalization from tensorflow_addons.layers import GroupNormalization from tenning.generic_utils import get_object_config from tenning.activations import Swish import tensorflow as tf
[ 11748, 11192, 273, 11125, 13, 6122, 292, 13, 1102, 2536, 6003, 355, 17778, 198, 6738, 11192, 273, 11125, 13, 6122, 292, 13, 75, 6962, 1330, 8060, 26287, 27201, 278, 17, 35, 198, 6738, 11192, 273, 11125, 13, 6122, 292, 13, 75, 6962, ...
3.321429
224
# coding=utf-8 from operator import xor import os import scrypt import time from libs.rediswrapper import UserHelper try: xrange except NameError: xrange = range
[ 2, 19617, 28, 40477, 12, 23, 198, 6738, 10088, 1330, 2124, 273, 198, 11748, 28686, 198, 11748, 629, 6012, 198, 11748, 640, 198, 6738, 9195, 82, 13, 445, 271, 48553, 1330, 11787, 47429, 628, 198, 28311, 25, 198, 220, 220, 220, 2124, ...
3.017544
57
import json from collections import defaultdict import fastavro import pandas as pd from django.contrib import messages from django.http import HttpResponseRedirect from django.urls import reverse from datasets.models import Connection from users.models import User def get_supported_file_types(): """Return a list of the viable file type extensions.""" return ["csv", "avro", "parquet", "xlsx", "xls", "xlsm", "xlsb"] def initialize_connection(datastore, connection_name, connection_owner_id, connection_type, request): """Create a connection and save the datastore on the connection object for later use.""" owner = User.objects.get(id=connection_owner_id) connection = Connection.objects.create(name=connection_name, owner=owner, type=connection_type) connection.datastore = datastore connection.save() messages.success(request, "Connection was created.") return HttpResponseRedirect(reverse("datasets:index")) def get_query(dataset, query): """Go through the potentially None valued given dataset and query and extract the query.""" if query: return query elif dataset.query: return dataset.query else: return f"SELECT * FROM {dataset.table}" def structure_tables_views(table, views): """Return a structured dictionary containing the given tables and views.""" table_dict = defaultdict(list) [table_dict[schema].append({"value": f"{schema}.{table}", "display": table}) for (schema, table) in table] view_dict = defaultdict(list) [view_dict[schema].append({"value": f"{schema}.{view}", "display": view}) for (schema, view) in views] return {"Tables": dict(table_dict), "Views": dict(view_dict)} def convert_to_dataframe(file_type, data): """Convert the given bytes data into a dataframe based on the given file type.""" if file_type == "csv": df = pd.read_csv(data, sep=None) elif file_type == "avro": df = pd.DataFrame.from_records(fastavro.reader(data)) elif file_type == "parquet": df = pd.read_parquet(data) else: df = pd.read_excel(data) return df def get_viable_blob_datasets(blobs, name_attr): """ Used to get the viable datasets for blob datastores. Used for Google Cloud Storage, Azure Blob Storage, Azure Data Lake and Amazon S3 datastores. """ viable_blobs = [] for blob in blobs: if getattr(blob, name_attr).split(".")[-1].lower() in get_supported_file_types(): viable_blobs.append(blob) viable_datasets = defaultdict(list) for blob in viable_blobs: split_path = getattr(blob, name_attr).split("/") parent_folder = split_path[-2] if len(split_path) >= 2 else "root" value = json.dumps({"id": getattr(blob, name_attr), "name": split_path[-1].split(".")[0]}) viable_datasets[parent_folder].append({"value": value, "display": split_path[-1]}) return {"Files": dict(viable_datasets)}
[ 11748, 33918, 198, 6738, 17268, 1330, 4277, 11600, 198, 198, 11748, 3049, 615, 305, 198, 11748, 19798, 292, 355, 279, 67, 198, 6738, 42625, 14208, 13, 3642, 822, 1330, 6218, 198, 6738, 42625, 14208, 13, 4023, 1330, 367, 29281, 31077, 77...
2.77507
1,067
#! /usr/bin/python
[ 2, 0, 1220, 14629, 14, 8800, 14, 29412, 198 ]
2.111111
9
import sys import Sofa import Tools
[ 11748, 25064, 198, 11748, 1406, 13331, 198, 11748, 20003, 628, 628, 220, 220, 220, 220, 220, 220, 220, 220, 198, 220, 220, 220, 220, 220, 220, 220, 220, 198, 220, 220, 220, 220, 220, 220, 220, 220, 198 ]
1.736842
38
import time import os import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.manifold import TSNE from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import f1_score import stellargraph as sg from stellargraph.mapper import CorruptedGenerator, HinSAGENodeGenerator from stellargraph.layer import DeepGraphInfomax, HinSAGE import tensorflow as tf from tensorflow.keras.optimizers import Adam from tensorflow.keras.callbacks import EarlyStopping from tensorflow.keras import Model, optimizers, losses, metrics ''' Runs the entire pipeline: - Takes preprocessed data as input - Outputs predictions on the test_set nodes. '''
[ 11748, 640, 198, 11748, 28686, 198, 11748, 19798, 292, 355, 279, 67, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 198, 198, 6738, 1341, 35720, 13, 805, 361, 727, 1330, 26136, 12161, ...
3.325123
203
from flask import Flask , render_template, request import google_news app = Flask(__name__) outFile = '' if __name__ == "__main__": app.run()
[ 6738, 42903, 1330, 46947, 837, 8543, 62, 28243, 11, 2581, 198, 11748, 23645, 62, 10827, 198, 1324, 796, 46947, 7, 834, 3672, 834, 8, 198, 198, 448, 8979, 796, 10148, 198, 198, 361, 11593, 3672, 834, 6624, 366, 834, 12417, 834, 1298, ...
2.921569
51
# Copyright 2020 DeepMind Technologies Limited. # # 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 required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ """Tests for mujoban_level.""" from absl.testing import absltest from physics_planning_games.mujoban import mujoban_level _LEVEL = """ ##### # @#### # $. # ###$.# # # $.# # # #$. # # ### ######""" _GRID_LEVEL = """******** *..P**** *..BG..* ***BG*.* *..BG*.* *.*BG..* *....*** ******** """ if __name__ == '__main__': absltest.main()
[ 2, 15069, 12131, 10766, 28478, 21852, 15302, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, 13, 198,...
3.278846
312
# Generated by Django 2.2.3 on 2019-07-12 12:51 from django.db import migrations, models import django.db.models.deletion
[ 2, 2980, 515, 416, 37770, 362, 13, 17, 13, 18, 319, 13130, 12, 2998, 12, 1065, 1105, 25, 4349, 198, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 11, 4981, 198, 11748, 42625, 14208, 13, 9945, 13, 27530, 13, 2934, 1616, 295, ...
2.818182
44
""" The given file contains the class to refer to the Site entity """ from quartic_sdk.core.entities.base import Base import quartic_sdk.utilities.constants as Constants
[ 37811, 198, 464, 1813, 2393, 4909, 262, 1398, 284, 3522, 284, 262, 14413, 9312, 198, 37811, 198, 6738, 28176, 291, 62, 21282, 74, 13, 7295, 13, 298, 871, 13, 8692, 1330, 7308, 198, 11748, 28176, 291, 62, 21282, 74, 13, 315, 2410, 13...
3.489796
49
# Generated by Django 2.0.5 on 2019-05-24 15:11 from django.db import migrations, models
[ 2, 2980, 515, 416, 37770, 362, 13, 15, 13, 20, 319, 13130, 12, 2713, 12, 1731, 1315, 25, 1157, 198, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 11, 4981, 628 ]
2.84375
32
from django.views import View from comment.models import BlockedUser, BlockedUserHistory, Comment from comment.mixins import CanBlockUsersMixin from comment.responses import UTF8JsonResponse, DABResponseData from comment.messages import BlockUserError
[ 6738, 42625, 14208, 13, 33571, 1330, 3582, 198, 198, 6738, 2912, 13, 27530, 1330, 1086, 3543, 12982, 11, 1086, 3543, 12982, 18122, 11, 18957, 198, 6738, 2912, 13, 19816, 1040, 1330, 1680, 12235, 14490, 35608, 259, 198, 6738, 2912, 13, 1...
3.923077
65
# -*- coding: utf-8 -*- # Copyright (c) 2015 Brad Newbold (wudan07 [at] gmail.com) # See LICENSE for details. # glyph.py # """wIcon library: glyph provides GlyphObject """ ##from handy import * ##from common import * ### represents a character in a glyphString def glyphstr_length(gls): """ Returns length of glyphstr gls """ length = 0 for gl in gls: length += gl.flash return length - 2 def glyphstr_monospace(gls, wide=6): """ for each GlyphObject in gls, calls .center(wide) """ for gl in gls: gl.center(wide) def glyphstr_center(gls, width=100): """ given a width of an area (such as column heading width) it will adjust the start point of each glyph in a glyphstr_, centering the string """ length = glyphstr_length(gls) glen = len(gls) #addlen = (width-length)/(glen)) print length print width - length hl = (width-length)/2 for i in range(0, glen): gl = gls[i] flash = gl.flash gl._flash(flash+hl) def glyphstr_justify(gls, width=100): """ given a width of an area (such as column heading width) it will adjust the start point of each glyph in a glyphstr_, justifying the string """ length = glyphstr_length(gls) glen = len(gls) #addlen = (width-length)/(glen)) print length print width - length ct = 0 for i in range(0, width-length): if ct >= glen-1: ct = 0 gl = gls[ct] flash = gl.flash gl._flash(flash+1) ct += 1 def glyphstr_bounds_get(string, mono=False): """ Returns 2 len integer array, size and height of string as glyphstr_ """ #xk = 0 #yk = 0 xz = 0 #yz = 10 vals = string.split('\n') yz = len(vals) * 10 for val in vals: gs = glyphstr_get(val) if mono: glyphstr_monospace(gs) sz = glyphstr_length(gs) if sz > xz: xz = sz return [xz, yz] def glyphstr_get(string): """ given a string, Returns glyphs, a list of glyphs """ glyphs = [] i = 0 while i < len(string): letter = string[i:i+1] glyphs.append(GlyphObject(letter)) i += 1 return glyphs
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 15069, 357, 66, 8, 1853, 8114, 968, 36575, 357, 86, 463, 272, 2998, 685, 265, 60, 308, 4529, 13, 785, 8, 198, 2, 4091, 38559, 24290, 329, 3307, 13, 198, 2, 2587...
2.534884
774
import json from paho.mqtt.client import Client from subscriber import Subscriber from datetime import datetime
[ 11748, 33918, 198, 198, 6738, 279, 17108, 13, 76, 80, 926, 13, 16366, 1330, 20985, 198, 6738, 32944, 1330, 3834, 1416, 24735, 198, 6738, 4818, 8079, 1330, 4818, 8079, 628 ]
3.8
30
# Generated by Django 2.2.17 on 2020-12-28 08:13 from django.db import migrations, models
[ 2, 2980, 515, 416, 37770, 362, 13, 17, 13, 1558, 319, 12131, 12, 1065, 12, 2078, 8487, 25, 1485, 201, 198, 201, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 11, 4981, 201, 198, 201, 198 ]
2.594595
37
from webium import BasePage, Finds, Find from selenium.webdriver.common.by import By
[ 6738, 3992, 1505, 1330, 7308, 9876, 11, 9938, 82, 11, 9938, 198, 6738, 384, 11925, 1505, 13, 12384, 26230, 13, 11321, 13, 1525, 1330, 2750, 628 ]
3.307692
26
from __future__ import print_function import argparse import sys import os import shutil import zipfile import urllib parser = argparse.ArgumentParser() ## Required parameters parser.add_argument("--bert_model_name", default = None, type = str, required = True, help = "Name of pretrained BERT model. Possible values: " "uncased_L-12_H-768_A-12,uncased_L-24_H-1024_A-16,cased_L-12_H-768_A-12," "multilingual_L-12_H-768_A-12,chinese_L-12_H-768_A-12") parser.add_argument("--model_dump_path", default = None, type = str, required = True, help = "Path to the output model.") parser.add_argument("--glue_data_path", default = None, type = str, required = True, help = "Path to store downloaded GLUE dataset") args = parser.parse_args() bert_model_url_map = { 'uncased_L-12_H-768_A-12': 'https://storage.googleapis.com/bert_models/2018_10_18/uncased_L-12_H-768_A-12.zip', 'uncased_L-24_H-1024_A-16': 'https://storage.googleapis.com/bert_models/2018_10_18/uncased_L-24_H-1024_A-16.zip', 'cased_L-12_H-768_A-12': 'https://storage.googleapis.com/bert_models/2018_10_18/cased_L-12_H-768_A-12.zip', 'multilingual_L-12_H-768_A-12': 'https://storage.googleapis.com/bert_models/2018_11_03/multilingual_L-12_H-768_A-12.zip', 'chinese_L-12_H-768_A-12': 'https://storage.googleapis.com/bert_models/2018_11_03/chinese_L-12_H-768_A-12.zip' } if args.bert_model_name not in bert_model_url_map: sys.stderr.write('Unknown BERT model name ' + args.bert_model_name) sys.exit(1) pretrained_model_url = bert_model_url_map.get(args.bert_model_name) # make local directory for pretrained tensorflow BERT model tensorflow_model_dir = './tensorflow_model' if not os.path.exists(tensorflow_model_dir): os.makedirs(tensorflow_model_dir) # download and extract pretrained tensorflow BERT model download_file_name = 'tensorflow_model.zip' urllib.request.urlretrieve(pretrained_model_url, filename=download_file_name) print('Extracting pretrained model...') with zipfile.ZipFile(download_file_name, 'r') as z: z.extractall(tensorflow_model_dir) # make destination path if not os.path.exists(args.model_dump_path): os.makedirs(args.model_dump_path) files = ['bert_model.ckpt.meta', 'bert_model.ckpt.index', 'bert_model.ckpt.data-00000-of-00001', 'bert_config.json', 'vocab.txt'] for file in files: shutil.copy(os.path.join(tensorflow_model_dir, args.bert_model_name, file), os.path.join(args.model_dump_path, file)) print('Start to download GLUE dataset...\n') urllib.request.urlretrieve( 'https://gist.githubusercontent.com/W4ngatang/60c2bdb54d156a41194446737ce03e2e/raw/17b8dd0d724281ed7c3b2aeeda662b92809aadd5/download_glue_data.py', filename='download_glue_data.py') if os.system('python download_glue_data.py --data_dir {0} --tasks all'.format(args.glue_data_path)) != 0: sys.exit(1)
[ 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 198, 11748, 1822, 29572, 198, 11748, 25064, 198, 11748, 28686, 198, 11748, 4423, 346, 198, 11748, 19974, 7753, 198, 11748, 2956, 297, 571, 198, 198, 48610, 796, 1822, 29572, 13, 28100, 1713, ...
2.188467
1,422
# -*- coding: utf-8 -*- # Generated by Django 1.11 on 2018-02-21 15:15 from __future__ import unicode_literals from django.db import migrations, models
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 2980, 515, 416, 37770, 352, 13, 1157, 319, 2864, 12, 2999, 12, 2481, 1315, 25, 1314, 198, 6738, 11593, 37443, 834, 1330, 28000, 1098, 62, 17201, 874, 198, 198, 6738...
2.8
55
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. # # 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 # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import cv2 import numpy as np
[ 2, 15069, 357, 66, 8, 12131, 350, 37382, 47, 37382, 46665, 13, 1439, 6923, 33876, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845...
3.754386
171
#!/usr/bin/env python import logging import sys import CloudFlare import os import re from os import path from certbot.plugins import dns_common __author__ = "Endrigo Antonini" __copyright__ = "Copyright 2020, Endrigo Antonini" __license__ = "Apache License 2.0" __version__ = "1.0" __maintainer__ = "Endrigo Antonini" __email__ = "eantonini@eidoscode.com" __status__ = "Production" logger = logging.getLogger(__name__) DEFAULT_CERT_FOLDER = "/etc/letsencrypt/live" CERTBOT_CONF_DIR = "/etc/letsencrypt/renewal" PROPERTIES = {} def read_file(filename): """ Read a file from disk and return all the content :param str filename: File name of the file that is going to read. :raises Exception: if the file doesn't exists """ if not path.isfile(filename): raise Exception("File {} doesn't exists!".format(filename)) with open(filename) as f: return f.read() if __name__ == '__main__': main()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 11748, 18931, 198, 198, 11748, 25064, 198, 11748, 10130, 7414, 533, 198, 11748, 28686, 198, 11748, 302, 198, 198, 6738, 28686, 1330, 3108, 198, 6738, 5051, 13645, 13, 37390, 1330, 288, 5...
2.861538
325
from datetime import datetime from marshmallow import Schema, EXCLUDE import marshmallow.fields as ms_fields
[ 6738, 4818, 8079, 1330, 4818, 8079, 198, 198, 6738, 22397, 42725, 1330, 10011, 2611, 11, 7788, 5097, 52, 7206, 198, 11748, 22397, 42725, 13, 25747, 355, 13845, 62, 25747, 628, 628, 198 ]
3.5625
32
# Till now only Python 3.10 can run match statement x = 1 y = 2 point = (x, y) check_point(point)
[ 2, 17888, 783, 691, 11361, 513, 13, 940, 460, 1057, 2872, 2643, 198, 198, 87, 796, 352, 198, 88, 796, 362, 198, 4122, 796, 357, 87, 11, 331, 8, 198, 9122, 62, 4122, 7, 4122, 8, 198 ]
2.675676
37
# python3 # -*- coding: utf-8 -*- # @Author : lina # @Time : 2018/4/22 21:17 """ code function: define all parameters. """ matched_file_name = "../data/gcn_res.txt" wordvec_path = '../data/word2vec.model' incremental_path = "../data/incremental_res.txt"
[ 2, 21015, 18, 201, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 201, 198, 2, 2488, 13838, 220, 1058, 300, 1437, 201, 198, 2, 2488, 7575, 220, 220, 220, 1058, 2864, 14, 19, 14, 1828, 2310, 25, 1558, 201, 198, ...
2.285714
119
from django.shortcuts import render from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse def root(request): """ Newsletter > Root """ return render(request, 'newsletter/newsletter_root.jade')
[ 6738, 42625, 14208, 13, 19509, 23779, 1330, 8543, 198, 6738, 42625, 14208, 13, 4023, 1330, 367, 29281, 31077, 7738, 1060, 198, 6738, 42625, 14208, 13, 7295, 13, 6371, 411, 349, 690, 1330, 9575, 628, 198, 4299, 6808, 7, 25927, 2599, 198,...
3.153846
78
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. # # 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 # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import absolute_import from __future__ import division from __future__ import print_function import numpy as np import paddle.fluid as fluid from paddle.fluid.param_attr import ParamAttr from .search_space_base import SearchSpaceBase from .base_layer import conv_bn_layer from .search_space_registry import SEARCHSPACE from .utils import compute_downsample_num, check_points, get_random_tokens __all__ = ["MobileNetV1BlockSpace", "MobileNetV2BlockSpace"]
[ 2, 15069, 357, 66, 8, 13130, 220, 350, 37382, 47, 37382, 46665, 13, 1439, 6923, 33876, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 1, 198, 2, 345, 743, 407, 779, 428, 2393, 2...
3.628763
299
"""Middle High German phonology tools """ from typing import List from cltk.phonology.gmh.transcription import Transcriber from cltk.phonology.syllabify import Syllabifier __author__ = ["Clment Besnier <clem@clementbesnier.fr>"]
[ 37811, 34621, 3334, 2679, 32896, 1435, 4899, 198, 37811, 198, 6738, 19720, 1330, 7343, 198, 198, 6738, 537, 30488, 13, 746, 261, 1435, 13, 39870, 71, 13, 7645, 6820, 1330, 3602, 66, 24735, 198, 6738, 537, 30488, 13, 746, 261, 1435, 13...
2.987179
78
import json from html import unescape from bs4 import BeautifulSoup from baiduspider.core._spider import BaseSpider from baiduspider.errors import ParseError
[ 11748, 33918, 198, 6738, 27711, 1330, 555, 41915, 198, 198, 6738, 275, 82, 19, 1330, 23762, 50, 10486, 198, 198, 6738, 275, 1698, 17723, 1304, 13, 7295, 13557, 2777, 1304, 1330, 7308, 41294, 198, 6738, 275, 1698, 17723, 1304, 13, 48277,...
3.5
46
import socket from requests.adapters import HTTPAdapter from requests.compat import urlparse, unquote try: from requests.packages.urllib3.connection import HTTPConnection from requests.packages.urllib3.connectionpool import HTTPConnectionPool except ImportError: from urllib3.connection import HTTPConnection from urllib3.connectionpool import HTTPConnectionPool # The following was adapted from some code from docker-py # https://github.com/docker/docker-py/blob/master/docker/unixconn/unixconn.py
[ 11748, 17802, 198, 198, 6738, 7007, 13, 324, 12126, 1330, 14626, 47307, 198, 6738, 7007, 13, 5589, 265, 1330, 19016, 29572, 11, 555, 22708, 198, 28311, 25, 198, 220, 220, 220, 422, 7007, 13, 43789, 13, 333, 297, 571, 18, 13, 38659, ...
3.561644
146
from django.test import TestCase from jarvis.resume.utils.extractor import get_text from jarvis.resume.utils.parser_helper import get_urls, get_url_response, url_categories, get_github_username, get_stackoverflow_userid, get_stackoverflow_username, get_name, get_id_from_linkedin_url, get_email from unidecode import unidecode path_to_test_data = 'resume/tests/test_data/1.pdf' urls = ['https://github.com/imnithin', 'http://imnithin.github.io', 'https://gist.github.com/imnithin', 'http://stackoverflow.com/users/2231236/nithin', 'https://www.linkedin.com/in/imnithink'] categories = {'blog': ['http://imnithin.github.io'], 'coding': [], 'contributions': ['https://github.com/imnithin', 'https://gist.github.com/imnithin'], 'forums': ['http://stackoverflow.com/users/2231236/nithin'], 'others': [], 'social': ['https://www.linkedin.com/in/imnithink']} url_response = [{'name': 'https://github.com/imnithin', 'type': 'contributions'}, {'name': 'https://gist.github.com/imnithin', 'type': 'contributions'}, {'name': 'https://www.linkedin.com/in/imnithink', 'type': 'social'}, {'name': 'http://imnithin.github.io', 'type': 'blog'}, {'name': 'http://stackoverflow.com/users/2231236/nithin', 'type': 'forums'}]
[ 6738, 42625, 14208, 13, 9288, 1330, 6208, 20448, 198, 6738, 17379, 4703, 13, 411, 2454, 13, 26791, 13, 2302, 40450, 1330, 651, 62, 5239, 198, 6738, 17379, 4703, 13, 411, 2454, 13, 26791, 13, 48610, 62, 2978, 525, 1330, 651, 62, 6371, ...
2.227496
611
from __future__ import print_function from __future__ import division from sklearn.utils import check_random_state from sklearn import preprocessing as prep from utils.data import load_data, show_data_splits, shape_data from utils.evaluation import evaluate from utils.profiles import select_model, show_design, train, fit, compute_scores import theano import lasagne as lg import numpy as np import argparse import os ''' Hybrid music playlist continuation based on a song-to-playlist classifier. We learn a classifier that takes song features as inputs and predicts the playlists songs belong to. Once it is learned, such classifier can be used to populate a matrix of song-playlist scores describing how well a song and a playlist fit together. Thus, a playlist can be extended by selecting the songs with highest score. This approach is "hybrid" in the usual sense in the recommender systems literature, i.e., it combines content (given by the song features) and cf information (given by playlists examples). As it is, this approach only works on the so-called weak generalization setting. That is, the model is trained on the same playlists that will be extended. ''' if __name__ == '__main__': parser = argparse.ArgumentParser(description='Hybrid music playlist continuation based on a song-to-playlist classifier.') parser.add_argument('--model', type=str, help='path to the model specification file', metavar='') parser.add_argument('--dataset', type=str, help='path to the playlists dataset directory', metavar='') parser.add_argument('--msd', type=str, help='path to the MSD directory', metavar='') parser.add_argument('--train', action='store_true', help='train the song-to-playist classifier with monitoring') parser.add_argument('--fit', action='store_true', help='fit the song-to-playlist classifier') parser.add_argument('--test', action='store_true', help='evaluate the playlist continuations') parser.add_argument('--ci', action='store_true', help='compute confidence intervals if True') parser.add_argument('--song_occ', type=int, help='test on songs observed song_occ times during training', nargs='+', metavar='') parser.add_argument('--metrics_file', type=str, help='file name to save metrics', metavar='') parser.add_argument('--seed', type=int, help='set random behavior', metavar='') args = parser.parse_args() # set random behavior rng = check_random_state(args.seed) lg.random.set_rng(rng) # set model configuration model = select_model(args.model) # prepare output directory data_name = os.path.basename(os.path.normpath(args.dataset)) out_dir = os.path.join('params', 'profiles', model.name + '_' + data_name + '_weak') if not os.path.exists(out_dir): os.makedirs(out_dir) # load data: playlists, splits, features and artist info data = load_data(args.dataset, args.msd, model) playlists_coo, split_weak, _, features, song2artist = data # playlists_coo are the playlists stored in coordinate format playlists_idx, songs_idx, _, idx2song = playlists_coo # each playlist is split into a "query" of ~80% of the songs (train_idx + # valid_idx) and a "continuation" of ~20% of the songs (test_idx) train_idx, valid_idx, test_idx = split_weak # define splits for this experiment # train model on the training queries # validate model on the validation queries # fit the model on the full queries # extend all the playlists, using all queries and continuations train_idx = train_idx valid_idx = valid_idx fit_idx = np.hstack((train_idx, valid_idx)) query_idx = fit_idx cont_idx = test_idx # provide data information show_data_splits(playlists_idx, songs_idx, idx2song, song2artist, train_idx, valid_idx, fit_idx, query_idx, cont_idx) # provide model information print('\nNetwork:') show_design(model) if args.train: # # train the hybrid model while validating on withheld playlists # # prepare input song features and playlist targets at training X_train, Y_train = shape_data( playlists_idx, songs_idx, idx2song, features, mode='train', subset=train_idx ) # prepare input song features and playlist targets at validation X_valid, Y_valid = shape_data( playlists_idx, songs_idx, idx2song, features, mode='test', subset=valid_idx ) # preprocess input features if required # use the training song features to standardize the validation data if model.standardize: scaler = prep.RobustScaler() X_train = scaler.fit_transform(X_train) X_valid = scaler.transform(X_valid) if model.normalize: X_train = prep.normalize(X_train, norm=model.normalize) X_valid = prep.normalize(X_valid, norm=model.normalize) # train the classifier train( model=model, train_input=X_train.astype(theano.config.floatX), train_target=Y_train.astype(np.int8), valid_input=X_valid.astype(theano.config.floatX), valid_target=Y_valid.astype(np.int8), out_dir=out_dir, random_state=rng ) if args.fit: # # fit the hybrid model # # prepare input song features and playlist targets at training X_fit, Y_fit = shape_data( playlists_idx, songs_idx, idx2song, features, mode='train', subset=fit_idx ) # preprocess input features if required if model.standardize: X_fit = prep.robust_scale(X_fit) if model.normalize: X_fit = prep.normalize(X_fit, norm=model.normalize) # fit the classifier fit( model=model, fit_input=X_fit.astype(theano.config.floatX), fit_target=Y_fit.astype(np.int8), out_dir=out_dir, random_state=rng ) if args.test: # # extend the playlists in the query split and evaluate the # continuations by comparing them to actual withheld continuations # # prepare input song features and playlist targets at test X_cont, Y_cont = shape_data( playlists_idx, songs_idx, idx2song, features, mode='test', subset=cont_idx ) # preprocess input features if required # use the training song features to standardize the test data if model.standardize: X_fit, _ = shape_data( playlists_idx, songs_idx, idx2song, features, mode='train', subset=fit_idx ) scaler = prep.RobustScaler() scaler.fit(X_fit) X_cont = scaler.transform(X_cont) if model.normalize: X_cont = prep.normalize(X_cont, norm=model.normalize) # songs in the "query" playlists need to be masked to make sure that # they are not recommended as continuations _, Y_query = shape_data( playlists_idx, songs_idx, idx2song, features, mode='test', subset=query_idx ) # get number of song occurrences when fitting for cold-start analysis # Y_fit = Y_query train_occ = np.asarray(Y_query.sum(axis=1)).flatten() # compute the song-playlist scores cont_output = compute_scores( model=model, params_dir=out_dir, cont_input=X_cont.astype(theano.config.floatX), cont_target=Y_cont.astype(np.int8) ) # evaluate the continuations evaluate( scores=[cont_output.T], targets=[Y_cont.T.tocsr()], queries=[Y_query.T.tocsr()], train_occ=[train_occ], k_list=[10, 30, 100], ci=args.ci, song_occ=args.song_occ, metrics_file=args.metrics_file )
[ 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 198, 6738, 11593, 37443, 834, 1330, 7297, 198, 198, 6738, 1341, 35720, 13, 26791, 1330, 2198, 62, 25120, 62, 5219, 198, 6738, 1341, 35720, 1330, 662, 36948, 355, 3143, 198, 198, 6738, 3384,...
2.449527
3,279
from django.contrib import admin from django.db import models from easy_select2.widgets import Select2Multiple from news.models import Entry admin.site.register(Entry, EntryAdmin)
[ 6738, 42625, 14208, 13, 3642, 822, 1330, 13169, 198, 6738, 42625, 14208, 13, 9945, 1330, 4981, 198, 6738, 2562, 62, 19738, 17, 13, 28029, 11407, 1330, 9683, 17, 31217, 198, 6738, 1705, 13, 27530, 1330, 21617, 628, 198, 28482, 13, 15654,...
3.64
50
import analyzer_client as analyzer from tkinter import * from tkinter import filedialog from tkinter import messagebox from tkinter import ttk import json import os from pathlib import Path IP_ADDRESS = "localhost" PORT = "8061" ENGINE_CURR_OPTIONS = {} ANALYZE_CURR_OPTIONS = {'language':'en', 'entities': None, 'correlation_id': None, 'score_threshold': "0.1", 'return_decision_process': "0" } DENY_LIST = {'supported_entities': [], 'valuesList': [], 'length': 0 } REGEX_LIST = {'entities': [], 'names_pattern': [], 'patterns': [], 'scores': [], 'context_words': [], 'length': 0 } root = Tk() app = Frames(root) root.mainloop()
[ 11748, 4284, 9107, 62, 16366, 355, 4284, 9107, 201, 198, 201, 198, 6738, 256, 74, 3849, 1330, 1635, 201, 198, 6738, 256, 74, 3849, 1330, 5717, 498, 519, 201, 198, 6738, 256, 74, 3849, 1330, 3275, 3524, 201, 198, 6738, 256, 74, 3849,...
2.576471
255
# mods 1 import random print(random.randint(1,10))
[ 2, 13743, 352, 198, 11748, 4738, 198, 197, 198, 4798, 7, 25120, 13, 25192, 600, 7, 16, 11, 940, 4008, 198 ]
2.52381
21
from typing import Callable import kge from kge.core import events from kge.core.eventlib import EventMixin from kge.core.events import Event Component = BaseComponent
[ 6738, 19720, 1330, 4889, 540, 201, 198, 201, 198, 11748, 479, 469, 201, 198, 6738, 479, 469, 13, 7295, 1330, 2995, 201, 198, 6738, 479, 469, 13, 7295, 13, 15596, 8019, 1330, 8558, 35608, 259, 201, 198, 6738, 479, 469, 13, 7295, 13, ...
3.033333
60
from pathlib import Path import numpy as np import pickle as pk from itertools import chain, product from collections import OrderedDict from structure import Struct MONKEYS = ['M', 'N'] REGIONS = ['OFC', 'ACC'] TASKVARS = ['value', 'type'] SUBSPACES = [True, False] EVT_WINS = OrderedDict((('cues ON', (-500, 1500)), ('response cue', (-500, 500)), ('rwd', (-400, 400)))) def pp_from_filename(filename): '''Get the preprocessing parameters from a unit data set filename Arguments: filename - str or Path: name or full path of unit data set file ''' fnamestr = filename if isinstance(filename, str) else filename.name params = [paramstr.split('.') for paramstr in fnamestr.split('_')[2:]] preproc_params = {'align': params[0][1], 'binsize': int(params[1][1]), 'smooth': params[2][1], 'smoothsize': int(params[3][1]), 'step': int(params[4][1])} return preproc_params def get_dataset_fname(dataseed, pp): '''Generate the file name of a population data set given data seed and preprocessing parameters Arguments: dataseed - int: the seed of the data set that will be included in the file name pp - dict: the pre-processing parameters of the data set''' fname = "population_dataset_align.{align}_binsize.{binsize}_smooth.{smooth}" fname += "_smoothsize.{smoothsize}_step.{step}_seed.%d.pk" % dataseed fname = fname.format(**pp) return fname def generate_dataset(dataseed, unit_folder, unit_file, save_folder=None): '''Generate a pseudo-population by combining data from monkeys and sessions Arguments: dataseed - int: the seed for pseudo-random selection of the trials to be part of the data set unit_file - str: the path to the file containing the unit data set save_folder - str or Path: optional, a folder to save the generated data set. After being saved once, if the same folder is specified, it will be loaded instead of being generated. Returns: X - Structure: A structure that contains the pseudo-population firing rate data. The structure contains 3 levels: - monkey: which can take values 'M' or 'N' for individual monkey data, or 'both' for the data of both monkeys combined - region: which can take value 'OFC' or 'ACC' - task variable: which can take value 'value' or 'type' for data sets targeted to decoding these variables The elements of the structure are numpy arrays of the shape: trials x bins x neurons Example: X['N', 'ACC', 'value'] contains a matrix of the pseudo-population firing rate of monkey N for region ACC meant to decode value y - Structure: A structure of numpy vectors with the same map as 'X' that contains the ground truth of the related variable for each trial. Example: y['N', 'ACC', 'value'] contains the value of each trials of monkey N for ACC population. delaymask - numpy vector of booleans: A boolean mask for the time bin dimension to select time bins that are part of the delay activity bins - numpy vector of ints: The time of each bin of the firing rate data in the structure X, with events ordered this way: 'cues ON' -> 'response cue' -> 'rwd' ''' events = list(EVT_WINS.keys()) pp = pp_from_filename(unit_file) if save_folder is not None: dataset_fname = get_dataset_fname(dataseed, pp) dataset_fullpath = Path(save_folder)/dataset_fname if dataset_fullpath.exists(): print("Data set already generated, loading...") with open(dataset_fullpath, 'rb') as f: X, y, delaymask, bins = pk.load(f) return X, y, delaymask, bins with open(Path(unit_folder)/unit_file, 'rb') as f: data = pk.load(f) evtxs = data['M']['OFC'][0]['bins'] #### Format the data for decoding ################################# keymap = [MONKEYS, REGIONS, TASKVARS] act = Struct.new_empty(keymap) minntrials = Struct.new_empty(keymap) for monkey, region in product(MONKEYS, REGIONS): act[monkey, region, 'value'] = [[] for _ in range(4)] act[monkey, region, 'type'] = [[], []] minntrials[monkey, region, 'value'] = [[] for _ in range(4)] minntrials[monkey, region, 'type'] = [[], []] datamr = data[monkey][region] ## Select bins that are within the window of interest for each event ## then concatenate the activity of the different events in a single tensor catepochs = [] for sessdata in datamr: if sessdata['fr'] is not None: cattmp = [] for evt in events: included_bins = (evtxs[evt] >= EVT_WINS[evt][0]) & (evtxs[evt] <= EVT_WINS[evt][1]) cattmp.append(sessdata['fr'][evt][included_bins]) catepochs.append(np.concatenate(cattmp)) else: catepochs.append(None) ## Separate trials by value and type for sessfr, sessdata in zip(catepochs, datamr): if sessfr is not None: if sessdata['fr'] is not None: sessvars = sessdata['vars'] for val in range(1, 5): trialbool = (sessvars.value == val) act[monkey, region, 'value'][val-1].append(sessfr[:, :, trialbool]) for itype, type_ in enumerate(['juice', 'bar']): trialbool = (sessvars.type == type_) act[monkey, region, 'type'][itype].append(sessfr[:, :, trialbool]) ## Get the minimum number of trials across all sessions for each value/type minntrials[monkey, region, 'value'] = [np.nanmin([sessfr.shape[2] for sessfr in valdata]) for valdata in act[monkey, region, 'value']] minntrials[monkey, region, 'type'] = [np.nanmin([sessfr.shape[2] for sessfr in typedata]) for typedata in act[monkey, region, 'type']] ## Get the minimum number of trials for pooled data across monkeys minntrials.move_level_(0, 2) mintogether = minntrials.apply(lambda x: [min(valmin) for valmin in zip(*x.values())], depth=2) mintogether = Struct.from_nested_dict({'both': mintogether.ndict}, n_layers=3) minntrials.move_level_(2, 0) minntrials = minntrials.combine(mintogether) # extra trials are discarded after trials are shuffled np.random.seed(dataseed) catactboth = Struct.empty_like(act, values=list) # taskvar, monkey, region = next(product(TASKVARS, MONKEYS, REGIONS)) for taskvar, monkey, region in product(TASKVARS, MONKEYS, REGIONS): keymap = [monkey, region, taskvar] minns = minntrials['both', region, taskvar] # minn, acttmp = next(zip(minns, act[keymap])) for minn, acttmp in zip(minns, act[keymap]): tocat = [] for sessdata in acttmp: ntrials = sessdata.shape[2] trialind = np.arange(ntrials) np.random.shuffle(trialind) tmp = sessdata[:, :, trialind] tocat.append(tmp[:, :, :minn]) catactboth[keymap].append(np.concatenate(tocat, 1)) catact = Struct.empty_like(act, values=list) for taskvar, monkey, region in product(TASKVARS, MONKEYS, REGIONS): keymap = [monkey, region, taskvar] minns = minntrials[keymap] for minn, acttmp in zip(minns, act[keymap]): tocat = [] for sessdata in acttmp: ntrials = sessdata.shape[2] trialind = np.arange(ntrials) np.random.shuffle(trialind) tmp = sessdata[:, :, trialind] tocat.append(tmp[:, :, :minn]) catact[keymap].append(np.concatenate(tocat, 1)) catactboth.move_level_(0, 2) def cat_monkeys(x): '''x: {monkey}[4 (values)] np.array<nbins*nneurons*ntrials>''' return [np.concatenate([x['M'][ival], x['N'][ival]], axis=1) for ival in range(len(x['M']))] catactboth.apply_agg_(cat_monkeys, depth=2) catactboth = Struct.from_nested_dict({'both': catactboth.ndict}, n_layers=3) catact = catact.combine(catactboth) #### Moving data from arrays to a list #### actvallist = catact.apply(get_actvallist) X, y = actvallist.apply(lambda x: x[0]), actvallist.apply(lambda x: x[1]) X.apply_(np.stack) y.apply_(np.array) del(catact, act) #### Defining a boolean mask to get only the bins between cue ON and rwd ######################################################################## cuesON_bins_mask = (evtxs['cues ON'] >= EVT_WINS['cues ON'][0]) & (evtxs['cues ON'] <= EVT_WINS['cues ON'][1]) cuesON_bins = evtxs['cues ON'][cuesON_bins_mask] resp_bins_mask = (evtxs['response cue'] >= EVT_WINS['response cue'][0]) &\ (evtxs['response cue'] <= EVT_WINS['response cue'][1]) resp_bins = evtxs['response cue'][resp_bins_mask] rwd_bins_mask = (evtxs['rwd'] >= EVT_WINS['rwd'][0]) & (evtxs['rwd'] <= EVT_WINS['rwd'][1]) rwd_bins = evtxs['rwd'][rwd_bins_mask] delaymask = np.concatenate((cuesON_bins >= 0, np.ones(resp_bins.shape, dtype=bool), rwd_bins <= 0)) bins = {} for evt, (start, end) in EVT_WINS.items(): xs = evtxs[evt] bins[evt] = xs[(xs >= start) & (xs <= end)] if save_folder is not None: with open(dataset_fullpath, 'wb') as f: pk.dump((X, y, delaymask, bins), f) print(f'data set created and saved in {unit_folder}') return X, y, delaymask, bins # The following is an example. Replace the right hand side of the first three # statements to get a specific data set if __name__ == '__main__': # Data seeds used to generate the pseudo population data for decoding are # listed below: # dataseeds = [634564236, 9453241, 70010207, 43661999, 60410205] dataseed = 634564236 # The following folder path must contain the unit data set file specified # below unit_folder = Path("/home/john/datasets") # The following statement specifies which unit data set (with which # preprocessing parameters) is to be used to generate the population data # set unit_file = "unit_dataset_align.center_binsize.100_smooth.gaussian_smoothsize.100_step.25.pk" # The last argument of the function allows you to save the data set in a # specified folder, or to load an already generated population data set if # it already exists in this folder. In this example the population data set # is saved in the same folder as the unit data set. X, y, delaymask, bins = generate_dataset(dataseed, unit_folder, unit_file, save_folder=unit_folder)
[ 6738, 3108, 8019, 1330, 10644, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 2298, 293, 355, 279, 74, 198, 6738, 340, 861, 10141, 1330, 6333, 11, 1720, 198, 6738, 17268, 1330, 14230, 1068, 35, 713, 198, 198, 6738, 4645, 1330, 32112, ...
2.334254
4,709
import setuptools with open('README.rst', 'r') as f: readme = f.read() with open('version', 'r') as f: version = f.read() if __name__ == '__main__': setuptools.setup( name='ohmlr', version=version, description='One-hot multinomial logisitc regression', long_description=readme, author='Joseph P. McKenna', author_email='joepatmckenna@gmail.com', url='http://joepatmckenna.github.io/ohmlr', download_url='https://pypi.org/project/ohmlr', packages=['ohmlr'], license='MIT', keywords=['inference', 'statistics', 'machine learning'])
[ 11748, 900, 37623, 10141, 198, 198, 4480, 1280, 10786, 15675, 11682, 13, 81, 301, 3256, 705, 81, 11537, 355, 277, 25, 198, 220, 220, 220, 1100, 1326, 796, 277, 13, 961, 3419, 198, 198, 4480, 1280, 10786, 9641, 3256, 705, 81, 11537, ...
2.240283
283
from commands2 import CommandBase, ParallelCommandGroup from subsystems.climbers.leftclimbersubsystem import LeftClimber from subsystems.climbers.rightclimbersubsystem import RightClimber
[ 6738, 9729, 17, 1330, 9455, 14881, 11, 42945, 21575, 13247, 198, 6738, 39335, 82, 13, 565, 320, 1213, 13, 9464, 565, 320, 1213, 549, 10057, 1330, 9578, 34, 2475, 527, 198, 6738, 39335, 82, 13, 565, 320, 1213, 13, 3506, 565, 320, 121...
3.673077
52
import os from flask import Flask import practicer_flask.auth import practicer_flask.exercises import practicer_flask.dashboard import practicer_flask.topic import practicer_flask.model_viewer app = create_app() if __name__ == "__main__": app.run(debug=os.environ.get("DEV", False))
[ 11748, 28686, 198, 198, 6738, 42903, 1330, 46947, 198, 198, 11748, 1970, 16647, 62, 2704, 2093, 13, 18439, 198, 11748, 1970, 16647, 62, 2704, 2093, 13, 1069, 2798, 2696, 198, 11748, 1970, 16647, 62, 2704, 2093, 13, 42460, 3526, 198, 117...
2.84466
103
from models.models import Topic, TopicInTopic import json
[ 6738, 4981, 13, 27530, 1330, 47373, 11, 47373, 818, 33221, 198, 11748, 33918, 628 ]
4.214286
14
# SPDX-FileCopyrightText: 2021 Genome Research Ltd. # # SPDX-License-Identifier: MIT from .base import Base, db
[ 2, 30628, 55, 12, 8979, 15269, 8206, 25, 33448, 5215, 462, 4992, 12052, 13, 198, 2, 198, 2, 30628, 55, 12, 34156, 12, 33234, 7483, 25, 17168, 198, 198, 6738, 764, 8692, 1330, 7308, 11, 20613, 628 ]
3.081081
37
#!/usr/bin/env python3 # # Copyright (c) 2016-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. import os from eden.integration.lib import hgrepo from .lib.hg_extension_test_base import EdenHgTestCase, hg_test from .lib.histedit_command import HisteditCommand
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 198, 2, 15069, 357, 66, 8, 1584, 12, 25579, 11, 3203, 11, 3457, 13, 198, 2, 1439, 2489, 10395, 13, 198, 2, 198, 2, 770, 2723, 2438, 318, 11971, 739, 262, 347, 10305, 12, ...
3.388889
144
import numpy as np import os # Data manipulate
[ 11748, 299, 32152, 355, 45941, 220, 198, 11748, 28686, 220, 198, 198, 2, 6060, 18510, 628 ]
3.1875
16
# Generated by Django 3.0.10 on 2021-02-15 15:09 from django.db import migrations, models import django.db.models.deletion import uuid
[ 2, 2980, 515, 416, 37770, 513, 13, 15, 13, 940, 319, 33448, 12, 2999, 12, 1314, 1315, 25, 2931, 198, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 11, 4981, 198, 11748, 42625, 14208, 13, 9945, 13, 27530, 13, 2934, 1616, 295, ...
2.854167
48
""" File-Name: [app]/serializers.py File-Desc: Rest API serializers for las_util App-Name: las_util Project-Name: Las-Util-Django Copyright: Copyright (c) 2019, DC Slagel License-Identifier: BSD-3-Clause """ from rest_framework import serializers from las_util.models import SectionInfo # TODO: replace view.api_upload with to use this # class UploadSerializer(serializer.ModelSerializer): # """Link ModelSerializer to the Upload model""" # class Meta: # model = Upload # fields = ['filename',]
[ 37811, 198, 8979, 12, 5376, 25, 685, 1324, 60, 14, 46911, 11341, 13, 9078, 198, 8979, 12, 24564, 25, 8324, 7824, 11389, 11341, 329, 39990, 62, 22602, 198, 4677, 12, 5376, 25, 39990, 62, 22602, 198, 16775, 12, 5376, 25, 10123, 12, 18...
2.905028
179
#!/usr/bin/env python # Display a runtext with double-buffering. from samplebase import SampleBase from rgbmatrix import graphics import time import requests import transitfeed import datetime import arrow import schedule today = datetime.date.today() starttime = time.time() schedule = transitfeed.Schedule() url = "http://localhost:5000/by-id/077e" font = graphics.Font() font.LoadFont("../fonts/tom-thumb.bdf") textColor = graphics.Color(0, 110, 0) circleColor = graphics.Color(110, 0, 0) circleNumberColor = graphics.Color(0, 0, 0) # Main function if __name__ == "__main__": run_text = RunText() if (not run_text.process()): run_text.print_help()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 16531, 257, 1057, 5239, 351, 4274, 12, 36873, 1586, 13, 198, 6738, 6291, 8692, 1330, 27565, 14881, 198, 6738, 46140, 6759, 8609, 1330, 9382, 198, 11748, 640, 198, 11748, 7007, 198, ...
2.951542
227
from django.apps import AppConfig
[ 6738, 42625, 14208, 13, 18211, 1330, 2034, 16934, 628 ]
3.888889
9
from random import sample from tile import Tile from utils import neighbours
[ 6738, 4738, 1330, 6291, 198, 6738, 17763, 1330, 47870, 198, 6738, 3384, 4487, 1330, 23788, 628 ]
4.875
16
import smart_imports smart_imports.all()
[ 198, 11748, 4451, 62, 320, 3742, 198, 198, 27004, 62, 320, 3742, 13, 439, 3419, 628, 198 ]
2.647059
17
import numpy as np import math p = np.poly1d([ +0.1429511242e-53, +0.1561712123e-44, -0.2259472298e-35, -0.2669710222e-26, +0.9784247973e-18, +0.1655572013e-8, +0.3991098106e+0, ]) for i in range(1000): k = float(i) / 100 print(sigmoid(k), p(k))
[ 11748, 299, 32152, 355, 45941, 198, 11748, 10688, 198, 198, 79, 796, 45941, 13, 35428, 16, 67, 26933, 198, 10, 15, 13, 1415, 1959, 4349, 1065, 3682, 68, 12, 4310, 11, 198, 10, 15, 13, 21599, 1558, 1065, 10163, 68, 12, 2598, 11, 19...
1.8
140
import psycopg2 import psycopg2.extras import discord from models.BotMention import BotMention from models.UpdatedMessage import UpdatedMessage from forever.Steam import Steam_API, Dota_Match, Dota_Match_Player from forever.Utilities import run_in_executor, log from forever.Warframe import CetusMessage, FissureMessage, SortieMessage, NightwaveMessage, InvasionMessage, SolSystem from forever.Newswire import NewswireMessage from models.Server import Server from forever.Arknights import Formula, Item, Stage from forever.GFL import Doll, Fairy
[ 11748, 17331, 22163, 70, 17, 201, 198, 11748, 17331, 22163, 70, 17, 13, 2302, 8847, 201, 198, 11748, 36446, 201, 198, 6738, 4981, 13, 20630, 44, 1463, 1330, 18579, 44, 1463, 201, 198, 6738, 4981, 13, 17354, 12837, 1330, 19433, 12837, ...
3.583333
156
import keras from keras.layers import Dense, Activation, Conv2D, MaxPool2D, Reshape model = Sequential() model.add(Reshape((3, 32, 32), input_shape=(3*32*32,) )) model.add(Conv2D(filters=32, kernel_size=(3,3), padding='same', activation="relu", data_format='channels_first')) model.add(MaxPool2D()) model.add(Conv2D(filters=64, kernel_size=(3,3), padding='same', activation="relu", data_format='channels_first')) model.add(MaxPool2D()) model.add(Reshape((-1,))) model.add(Dense(units=1024, activation="relu")) model.add(Dense(units=10, activation="softmax")) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) model.fit(train_X, train_Y, validation_split=0.02, batch_size=128, epochs=30) rtn = model.evaluate(test_X, test_Y) print("\ntest accuracy=", rtn[1])
[ 11748, 41927, 292, 198, 6738, 41927, 292, 13, 75, 6962, 1330, 360, 1072, 11, 13144, 341, 11, 34872, 17, 35, 11, 5436, 27201, 17, 35, 11, 1874, 71, 1758, 198, 19849, 796, 24604, 1843, 3419, 198, 19849, 13, 2860, 7, 4965, 71, 1758, ...
2.483384
331
# Dicionarios pessoas = {'nome': 'Igor', 'sexo': 'M', 'idade': 20} print(f'O {pessoas["nome"]} tem {pessoas["idade"]} anos.') print(pessoas.keys()) #chaves do dicionario print(pessoas.values())#valores das chaves print(pessoas.items())#mostra os itens do dicionario print() for k in pessoas.keys(): print(k) for v in pessoas.values(): print(v) for k, v in pessoas.items(): print(k, v) print() for k, v in pessoas.items(): print(f'{k} = {v}') print() del pessoas['sexo']# deleta uma chave pessoas['peso'] = 72# adiciona uma nova chave for k, v in pessoas.items(): print(f'{k} = {v}') print() # Dicionario dentro de uma lista brasil = [] estado1 = {'uf': 'Rio de Janeiro', 'sigla': 'RJ'} estado2 = {'uf': 'So Paulo', 'sigla': 'SP'} brasil.append(estado1) brasil.append(estado2) print(brasil[0]['uf']) print() brasil = list() estado = dict() for c in range(0, 3): estado['uf'] = str(input('Unidade federativa: ')) estado['sigla'] = str(input('Sigla: ')) brasil.append(estado.copy())# cpia de um dicionario for e in brasil: for k, v in e.items(): print(f'{k} = {v}')
[ 2, 360, 47430, 13010, 198, 79, 408, 78, 292, 796, 1391, 6, 77, 462, 10354, 705, 40, 7053, 3256, 705, 8044, 78, 10354, 705, 44, 3256, 705, 312, 671, 10354, 1160, 92, 198, 4798, 7, 69, 6, 46, 1391, 79, 408, 78, 292, 14692, 77, 4...
2.124521
522
""" polyanalyst6api.api ~~~~~~~~~~~~~~~~~~~ This module contains functionality for access to PolyAnalyst API. """ import configparser import contextlib import pathlib import warnings from typing import Any, Dict, List, Tuple, Union, Optional from urllib.parse import urljoin, urlparse import requests import urllib3 from . import __version__ from .drive import Drive from .project import Parameters, Project from .exceptions import APIException, ClientException, _WrapperNotFound __all__ = ['API'] urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) warnings.simplefilter( 'always', UserWarning ) # without this set_parameters will show warnings only once NodeTypes = [ "CSV Exporter/", "DataSource/CSV", "DataSource/EXCEL", "DataSource/FILES", "DataSource/INET", "DataSource/ODBC", "DataSource/RSS", "DataSource/XML", "Dataset/Biased", "Dataset/ExtractTerms", "Dataset/Python", "Dataset/R", "Dataset/ReplaceTerms", "ODBC Exporter/", "PA6TaxonomyResult/TaxonomyResult", "SRLRuleSet/Filter Rows", "SRLRuleSet/SRL Rule", "TmlEntityExtractor/FEX", "Sentiment Analysis", "TmlLinkTerms/", ]
[ 37811, 198, 35428, 272, 21470, 21, 15042, 13, 15042, 198, 27156, 4907, 93, 198, 198, 1212, 8265, 4909, 11244, 329, 1895, 284, 12280, 2025, 21470, 7824, 13, 198, 37811, 198, 11748, 4566, 48610, 198, 11748, 4732, 8019, 198, 11748, 3108, 8...
2.732265
437
from django.contrib import admin from django.http import HttpResponse from django.utils.translation import ugettext as _ from froide.publicbody.models import (PublicBody, FoiLaw, PublicBodyTopic, Jurisdiction) admin.site.register(PublicBody, PublicBodyAdmin) admin.site.register(FoiLaw, FoiLawAdmin) admin.site.register(Jurisdiction, JurisdictionAdmin) admin.site.register(PublicBodyTopic, PublicBodyTopicAdmin)
[ 6738, 42625, 14208, 13, 3642, 822, 1330, 13169, 198, 6738, 42625, 14208, 13, 4023, 1330, 367, 29281, 31077, 198, 6738, 42625, 14208, 13, 26791, 13, 41519, 1330, 334, 1136, 5239, 355, 4808, 198, 198, 6738, 8400, 485, 13, 11377, 2618, 13,...
3.179104
134
n = int(input()) # @return [0]: [1]: L=[] ans=0 for i in range(1,n+1): if(i%2==0): continue else: for j in range(1,n+1): if(i%j==0): L.append(j) if (len(L)==8): ans+=1 L.clear() print(ans) print(divisor(15))
[ 77, 796, 493, 7, 15414, 28955, 628, 198, 2, 2488, 7783, 685, 15, 5974, 685, 16, 5974, 628, 198, 43, 28, 21737, 198, 504, 28, 15, 198, 1640, 1312, 287, 2837, 7, 16, 11, 77, 10, 16, 2599, 198, 220, 220, 220, 611, 7, 72, 4, 17,...
1.611429
175
import serial #TODO: define the gathering of all of the possible data sets being extracted #Biometrics # Heart Rate # STEPS # CALORIES # SKIN TEMP # PERSPIRATION #Activity # Walking # Running # Biking #Sleep # REM # Mind Refresh # Light # Deep # Body Refresh # Interruptions # Toss & Turn
[ 11748, 11389, 628, 198, 198, 2, 51, 3727, 46, 25, 8160, 262, 11228, 286, 477, 286, 262, 1744, 1366, 5621, 852, 21242, 198, 2, 23286, 908, 10466, 198, 197, 2, 8894, 14806, 198, 197, 2, 24483, 3705, 198, 197, 2, 33290, 1581, 11015, ...
2.695652
115
"""ORM models for multinet."""
[ 37811, 1581, 44, 4981, 329, 1963, 42504, 526, 15931, 198 ]
3.1
10
import bs4 import os import re from typing import Iterable from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait # for implicit and explict waits from selenium.webdriver.support import expected_conditions as ec from selenium.webdriver.common.by import By from dataPipelines.gc_crawler.requestors import MapBasedPseudoRequestor from dataPipelines.gc_crawler.exec_model import Crawler, Parser, Pager from dataPipelines.gc_crawler.data_model import Document, DownloadableItem from dataPipelines.gc_crawler.utils import abs_url, close_driver_windows_and_quit from . import SOURCE_SAMPLE_DIR, BASE_SOURCE_URL
[ 11748, 275, 82, 19, 198, 11748, 28686, 198, 11748, 302, 198, 6738, 19720, 1330, 40806, 540, 198, 198, 6738, 384, 11925, 1505, 1330, 3992, 26230, 198, 6738, 384, 11925, 1505, 13, 12384, 26230, 13, 11284, 13, 9019, 1330, 5313, 32103, 2132...
3.284264
197
import re from django.db.models.signals import m2m_changed, post_save, pre_delete from django.dispatch import receiver from django.urls import reverse from .models import Entry, Notification, User
[ 11748, 302, 198, 198, 6738, 42625, 14208, 13, 9945, 13, 27530, 13, 12683, 874, 1330, 285, 17, 76, 62, 40985, 11, 1281, 62, 21928, 11, 662, 62, 33678, 198, 6738, 42625, 14208, 13, 6381, 17147, 1330, 9733, 198, 6738, 42625, 14208, 13, ...
3.40678
59
from unittest.mock import mock_open from unittest.mock import patch import flow.utils.commons as commons commit_example = [ "223342f Adding ability to specify artifactory user [#134082057]", "4326d00 Adding slack channel option for errors [#130798449]", "09c1983 Merge pull request #25 from ci-cd/revert-18-github-version-fix", "445fd02 Revert \"GitHub version fix\"" ] commit_example_nested_brackets = [ "223342f Adding ability to specify artifactory user [#134082057, [bubba]]", "4326d00 Adding slack channel option for errors [#130798449]", "09c1983 Merge pull request #25 from ci-cd/revert-18-github-version-fix", "445fd02 Revert \"GitHub version fix\"" ] commit_example_multiple_per_brackets = [ "223342f Adding ability to specify artifactory user [#134082057,#134082058]", "4326d00 Adding slack channel option for errors [#130798449,123456]", "09c1983 Merge pull request #25 from ci-cd/revert-18-github-version-fix", "445fd02 Revert \"GitHub version fix\"" ] commit_example_dedup = [ "223342f Adding ability to specify artifactory user [#134082057,#134082057]", "4326d00 Adding slack channel option for errors [#134082057,134082057]", "09c1983 Merge pull request #25 from ci-cd/revert-18-github-version-fix", "445fd02 Revert \"GitHub version fix\"" ]
[ 6738, 555, 715, 395, 13, 76, 735, 1330, 15290, 62, 9654, 198, 6738, 555, 715, 395, 13, 76, 735, 1330, 8529, 198, 198, 11748, 5202, 13, 26791, 13, 9503, 684, 355, 36523, 628, 198, 41509, 62, 20688, 796, 685, 198, 1, 1828, 2091, 368...
2.886105
439
# coding: utf-8 """ finAPI RESTful Services finAPI RESTful Services # noqa: E501 OpenAPI spec version: v1.42.1 Generated by: https://github.com/swagger-api/swagger-codegen.git """ import pprint import re # noqa: F401 import six def to_str(self): """Returns the string representation of the model""" return pprint.pformat(self.to_dict()) def __repr__(self): """For `print` and `pprint`""" return self.to_str() def __eq__(self, other): """Returns true if both objects are equal""" if not isinstance(other, ClientConfiguration): return False return self.__dict__ == other.__dict__ def __ne__(self, other): """Returns true if both objects are not equal""" return not self == other
[ 2, 19617, 25, 3384, 69, 12, 23, 198, 198, 37811, 198, 220, 220, 220, 957, 17614, 30617, 913, 6168, 628, 220, 220, 220, 957, 17614, 30617, 913, 6168, 220, 1303, 645, 20402, 25, 412, 33548, 628, 220, 220, 220, 4946, 17614, 1020, 2196,...
2.498462
325
from functools import wraps from flask_jwt_extended import verify_jwt_in_request, get_jwt_claims, exceptions from jwt import exceptions as jwt_exception from utils.custom_response import bad_request
[ 6738, 1257, 310, 10141, 1330, 27521, 198, 6738, 42903, 62, 73, 46569, 62, 2302, 1631, 1330, 11767, 62, 73, 46569, 62, 259, 62, 25927, 11, 651, 62, 73, 46569, 62, 6604, 82, 11, 13269, 198, 6738, 474, 46569, 1330, 13269, 355, 474, 465...
3.389831
59
#!/usr/bin/env python """S/MIME demo. Copyright (c) 2000 Ng Pheng Siong. All rights reserved.""" from M2Crypto import BIO, Rand, SMIME, X509 import sys if __name__ == '__main__': Rand.load_file('../randpool.dat', -1) decrypt_verify(BIO.File(sys.stdin), 'client.pem', 'client2.pem','ca.pem') Rand.save_file('../randpool.dat')
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 37811, 50, 14, 44, 12789, 13605, 13, 198, 198, 15269, 357, 66, 8, 4751, 34786, 350, 31753, 311, 295, 70, 13, 1439, 2489, 10395, 526, 15931, 198, 198, 6738, 337, 17, 23919, 78, ...
2.405594
143
#!/usr/bin/env python """A model for the sky brightness """ from functools import partial from math import pi, cos, acos, sin, sqrt, log10 from datetime import datetime, tzinfo, timedelta from time import strptime from calendar import timegm from copy import deepcopy from sys import argv from collections import namedtuple, OrderedDict from argparse import ArgumentParser try: from ConfigParser import ConfigParser except: from configparser import ConfigParser import numexpr from numexpr import NumExpr import warnings from warnings import warn import numpy as np try: from palpy import rdplan as rdplan_not_vectorized from palpy import gmst as gmst_not_vectorized from palpy import dmoon from palpy import evp except ImportError: from pyslalib.slalib import sla_rdplan as rdplan_not_vectorized from pyslalib.slalib import sla_gmst as gmst_not_vectorized from pyslalib.slalib import sla_dmoon as dmoon from pyslalib.slalib import sla_evp as evp palpy_body = {'sun': 0, 'moon': 3} MAG0 = 23.9 # warnings.simplefilter("always") rdplan = np.vectorize(rdplan_not_vectorized) ## Works and is trivially faster, but less flexible w.r.t. data types # # ang_sep = NumExpr("2*arcsin(sqrt(cos(decl1)*cos(decl2)*(sin(((ra1-ra2)/2))**2) + (sin((decl1-decl2)/2))**2))", # (('ra1', np.float64), ('decl1', np.float64), ('ra2', np.float64), ('decl2', np.float64))) def elongation_not_vectorized(mjd): "Calculate the elongation of the moon in radians" pv = dmoon(mjd) moon_distance = (sum([x**2 for x in pv[:3]]))**0.5 dvb, dpb, dvh, dph = evp(mjd,-1) sun_distance = (sum([x**2 for x in dph[:3]]))**0.5 a = np.degrees(np.arccos( (-pv[0]*dph[0] - pv[1]*dph[1] - pv[2]*dph[2])/ (moon_distance*sun_distance))) return a elongation = np.vectorize(elongation_not_vectorized) def calc_moon_brightness(mjd, moon_elongation=None): """The brightness of the moon (relative to full) The value here matches about what I expect from the value in Astrophysical Quantities corresponding to the elongation calculated by http://ssd.jpl.nasa.gov/horizons.cgi >>> mjd = 51778.47 >>> print "%3.2f" % moon_brightness(mjd) 0.10 """ if moon_elongation is None: moon_elongation = elongation(mjd) alpha = 180.0-moon_elongation # Allen's _Astrophysical Quantities_, 3rd ed., p. 144 return 10**(-0.4*(0.026*abs(alpha) + 4E-9*(alpha**4))) # # Included for backword compatibility with previous implementation # def skymag(m_inf, m_zen, h, g, mie_m, rayl_m, ra, decl, mjd, k, latitude, longitude, offset=0.0, sun_dm=-14.0, twi1=-2.52333, twi2=0.01111): config = ConfigParser() sect = "Observatory Position" config.add_section(sect) config.set(sect, 'longitude', longitude) config.set(sect, 'latitude', latitude) sect = "sky" config.add_section(sect) config.set(sect, 'filters', 'x') config.set(sect, 'k', k) config.set(sect, 'm_inf', m_inf) config.set(sect, 'm_zen', m_zen) config.set(sect, 'h', h) config.set(sect, 'rayl_m', rayl_m) config.set(sect, 'g', g) config.set(sect, 'mie_m', mie_m) config.set(sect, 'sun_dm', sun_dm) config.set(sect, 'twi1', twi1) config.set(sect, 'twi2', twi2) calc_sky = MoonSkyModel(config) sky = calc_sky(mjd, ra, decl, 'x') return sky if __name__=='__main__': parser = ArgumentParser('Estimate the sky brightness') parser.add_argument("-m", "--mjd", type=float, help="Modified Julian Date (float) (UTC)") parser.add_argument("-r", "--ra", type=float, help="the RA (decimal degrees)") parser.add_argument("-d", "--dec", type=float, help="the declination (decimal degrees)") parser.add_argument("-f", "--filter", help="the filter") parser.add_argument("-c", "--config", help="the configuration file") args = parser.parse_args() model_config = ConfigParser() model_config.read(args.config) longitude = model_config.getfloat("Observatory Position", "longitude") latitude = model_config.getfloat("Observatory Position", "latitude") lst = gmst(args.mjd) + np.radians(longitude) print("GMST: %f" % np.degrees(gmst(args.mjd))) print("LST: %f" % np.degrees(lst)) sun_ra, sun_decl, diam = rdplan(args.mjd, 0, np.radians(longitude), np.radians(latitude)) sun_ha = lst - sun_ra sun_zd = np.degrees(calc_zd(np.radians(latitude), sun_ha, sun_decl)) print("Sun zenith distance: %f" % sun_zd) moon_ra, moon_decl, diam = rdplan(args.mjd, 3, longitude, latitude) moon_ha = lst - moon_ra moon_zd = np.degrees(calc_zd(np.radians(latitude), moon_ha, moon_decl)) print("Moon zenith distance: %f" % moon_zd) print("Elongation of the moon: %f" % elongation(args.mjd)) print("Moon brightness: %f" % calc_moon_brightness(args.mjd)) sep = ang_sep(moon_ra, moon_decl, np.radians(args.ra), np.radians(args.dec)) print("Pointing angle with moon: %f" % sep) ha = lst - np.radians(args.ra) print("Hour angle: %f" % np.degrees(ha)) z = calc_zd(np.radians(latitude), ha, np.radians(args.dec)) print("Pointing zenith distance: %f" % np.degrees(z)) print("Airmass: %f" % calc_airmass(np.cos(z))) sky_model = MoonSkyModel(model_config) print("Sky brightness at pointing: %f" % sky_model(args.mjd, args.ra, args.dec, args.filter))
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 37811, 32, 2746, 329, 262, 6766, 22204, 198, 37811, 198, 6738, 1257, 310, 10141, 1330, 13027, 198, 6738, 10688, 1330, 31028, 11, 8615, 11, 936, 418, 11, 7813, 11, 19862, 17034, 11, 260...
2.268813
2,485
# -*- coding: utf-8 -*- import unittest import arima import os import pandas as pd if __name__ == "__main__": unittest.main()
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 11748, 555, 715, 395, 198, 11748, 610, 8083, 198, 11748, 28686, 198, 11748, 19798, 292, 355, 279, 67, 628, 198, 361, 11593, 3672, 834, 6624, 366, 834, 12417, 834, 1298, ...
2.4
55
# -*- coding:utf-8 -*- """ This file is part of OpenSesame. OpenSesame is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenSesame is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenSesame. If not, see <http://www.gnu.org/licenses/>. """ from libopensesame.item import item from libqtopensesame.items.qtautoplugin import qtautoplugin from openexp.canvas import canvas blankText = u'Enter Variable Name Here' blankID = u'****'
[ 2, 532, 9, 12, 19617, 25, 40477, 12, 23, 532, 9, 12, 198, 198, 37811, 198, 1212, 2393, 318, 636, 286, 4946, 50, 34038, 13, 198, 198, 11505, 50, 34038, 318, 1479, 3788, 25, 345, 460, 17678, 4163, 340, 290, 14, 273, 13096, 198, 27...
3.530612
245
#!/usr/bin/env python __author__ = 'Roger Unwin' import socket import time from time import gmtime, strftime import datetime import string import sys import random import asyncore import thread import getopt import select import os ### default values defined below (b/c class is not yet defined) #default_port = 4001 # TCP port to run on. #default_message_rate = 5 # 5 sec between messages when streaming #default_sim=SBE37_random ########### BASE class here handles SBE37 behaviors ########### see below for subclasses that provide different data values def usage(): print "SBE37-SMP Simulator:\n" print "This program simulates a SBE37-SMP sensor deployed by \nbeing connected to a MOXA NPort 5410 Serial Device Server." print "Available options are:" print " -h, --help : Displays this message" print " -p, --port= : Sets the port to listen on (>1024, default = %s)." % default_port def get_opts(): opts, args = getopt.getopt(sys.argv[1:], "c:p:h", ["class=", "port=", "rate="]) out={'rate':default_message_rate,'port':default_port,'simulator':SBE37_random} for o, a in opts: if o in ("-c", "--class"): out['simulator'] = getattr(sys.modules[__name__],a) if o in ("-r", "--rate"): out['message_rate'] = int(a) elif o in ("-p", "--port"): out['port'] = int(a) else: print 'unknown option: '+o return out def main(): try: args = get_opts() except Exception as e: print 'Exception: %s'%e usage() sys.exit() print 'using args: %r'%args SBE37_server(sim_class=args['simulator'], host='', port=args['port'], rate=args['rate']) try: asyncore.loop() except: sys.exit() # Be silent when ^c pressed ################################################################################################ ## ## THESE CLASSES generate different sample values for the simulator # # return tuple of: temperature, conductivity, pressure, salinity, sound velocity import math # vary as sine wave over time # narrower, valid range to help ensure density can be calculated #> Valid ranges for conductivity are 0-7 S/m. Typical values we've seen off the Oregon coast are ~35 mS/cm, which converts to ~3.5 S/m. #> #> Valid ranges for temperature are -2-40 deg_C. Typical values we've seen off the Oregon coast are between 5 and 20 deg_C. 12 deg_C would be absolutely reasonable. #> #> Valid ranges for pressure are 0-7000 dbar. Really, just choose a depth. #> #> I would recommend the simulator produce at C of 3.5 S/m, a T of 12 deg_C and a depth of 10 dbar. Apply sine wave functions with some small fraction of random white noise and let it rip. #> ################################################################################################ default_port = 4001 # TCP port to run on. default_message_rate = 5 # 5 sec between messages when streaming default_sim=SBE37_random if __name__ == '__main__': main()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 834, 9800, 834, 796, 705, 43719, 791, 5404, 6, 628, 198, 11748, 17802, 198, 11748, 640, 198, 6738, 640, 1330, 308, 76, 2435, 11, 965, 31387, 198, 11748, 4818, 8079, 198, 11748, 4731, ...
2.941577
1,027
import matplotlib.pyplot as plt import numpy as np import pandas as pd data = pd.read_csv('results.csv') labels = [1,2,3,4] width = 0.75 x = np.arange(len(labels)) # the label locations fig = plt.figure(figsize=(9,6)) # Number people waiting ax1 = fig.add_subplot(121) y1 = data['av_waiting'].values.flatten() waiting = ax1.bar(x, y1, width, color='b') ax1.set_ylabel('Average number of patients waiting for ASU bed') ax1.set_xlabel('ASUs per region') ax1.set_title('Average number of patients waiting\nfor ASU bed') ax1.set_xticks(x) ax1.set_xticklabels(labels) ax2 = fig.add_subplot(122) y2 = data['av_waiting_days'].values.flatten() days = ax2.bar(x, y2, width, color='r') ax2.set_ylabel('Average waiting time (days)') ax2.set_xlabel('ASUs per region') ax2.set_title('Average waiting time\n(days, for patients who have to wait)') ax2.set_xticks(x) ax2.set_xticklabels(labels) plt.tight_layout(pad=2) plt.savefig('centralisation.png', dpi=300) plt.show()
[ 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 19798, 292, 355, 279, 67, 198, 198, 7890, 796, 279, 67, 13, 961, 62, 40664, 10786, 43420, 13, 40664, 11537, 198, 23912, 1424, 796...
2.427861
402
# -*- coding: utf-8 -*- """ Spyder Editor Amritha Subburayan code for STOUT DDA FULL STACK CASE STUDIES """ import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt import seaborn as sns %matplotlib inline from sklearn import preprocessing import sklearn.metrics as sm data = pd.read_csv(r'//Users//amrithasubburayan//Downloads//loans_full_schema.csv') data.info() data.describe() #Checking missing values data.isna().sum() #removing emp_title, state , num_accounts_120d_past_due , num_accounts_30d_past_due, tax_liens, public_record_bankrupt, # paid_late_fees , total_collection_amount_ever , current_accounts_delinq , num_historical_failed_to_pay # num_collections_last_12m, delinq_2y # check corr and remove this num_mort_accounts #storing data to other temp data2 = data # DATA DESCRIPTION AND ISSUES : #There are two issues in this dataset : #1) Missing values 2) Multi-collinearity #Missing values can be found in the following rows: #1) emp_title 2) emp_length 3) annual_income_joint 4) verification_income_joint # 5) debt_to_income_joint 6) months_since_last_delinq 7) months_since_90d_late #8) months_since_last_credit_inquiry 9) num_accounts_120d_past_due #Multicollinearity can be found between these columns : #1) installment and loan amount - 0.94 2) balance and loan amount - 0.93 # 3) annula income joint and total credit limit - 0.54 #4) Inquires last 12 m and months since last credit inq - 0.51 #5) total credit lines and open credit lines - 0.76 6) #num satisfactory acc and total credit lines - 0.75 #7) total credit lines and num total cc accounts - 0.77 8) #total credit lines and num open cc accounts - 0.62 #Visualizations plt.figure(figsize=(40,35)) sns.heatmap(data2.corr(), annot = True, cmap = "RdYlGn") plt.show() data2['loan_purpose'].value_counts().plot(kind='bar',color=['gray','red','blue','green','purple','yellow','black']).set_title('Loan Purpose') data2.groupby('homeownership').verified_income.value_counts().unstack(0).plot.bar() data2.groupby('homeownership').application_type.value_counts().unstack(0).plot(kind="pie",subplots=True, shadow = True,startangle=90,figsize=(15,10),autopct='%1.1f%%') plt.scatter(data2['installment'],data2['loan_amount']) d = data2.groupby('emp_length') s=[] for key,item in d: if(key!=7.0): s.append(d.get_group(key)['interest_rate'].mean()) dict1={"emp_length":[0,1,2,3,4,5,6,8,9,10],"int_rate":s} plt.plot(dict1['emp_length'],s) df= data2['application_type'] data2.groupby('application_type').loan_purpose.value_counts() data2.groupby('application_type').loan_purpose.value_counts().unstack(0).plot(kind="pie",subplots=True, shadow = True,startangle=90,figsize=(25,20),autopct='%1.1f%%') #Replacing missing rows d = data2.groupby('application_type').loan_purpose.value_counts() #data2["verification_income_joint"] = data2['verification_income_joint'].fillna('Not Verified') for i in range(0, len(data2["verification_income_joint"])): if pd.isna(data2['verification_income_joint'][i]): data2['verification_income_joint'][i] = data2['verified_income'][i] data2["debt_to_income"] = data2['debt_to_income'].fillna(0) #combining annual income with joint annual income for i in range(0, len(data2["annual_income_joint"])): if pd.isna(data2['annual_income_joint'][i]): data2['annual_income_joint'][i] = data2['annual_income'][i] #combining debt income with joint debt income for i in range(0, len(data2["debt_to_income_joint"])): if pd.isna(data2['debt_to_income_joint'][i]): data2['debt_to_income_joint'][i] = data2['debt_to_income'][i] ## Replacing with mean values data2["months_since_last_credit_inquiry"] = data2['months_since_last_credit_inquiry'].fillna(np.mean(data2["months_since_last_credit_inquiry"])) data2["emp_length"] = data2['emp_length'].fillna(np.mean(data2["emp_length"])) #Removing unwanted columns because it has more 0 values which will not impact on building a model data2.drop("emp_title", axis = 1, inplace=True) data2.drop("state", axis = 1, inplace=True) data2.drop("num_accounts_120d_past_due", axis = 1, inplace=True) data2.drop("num_accounts_30d_past_due", axis = 1, inplace=True) data2.drop("tax_liens", axis = 1, inplace=True) data2.drop("public_record_bankrupt", axis = 1, inplace=True) data2.drop("paid_late_fees", axis = 1, inplace=True) data2.drop("total_collection_amount_ever", axis = 1, inplace=True) data2.drop("current_accounts_delinq", axis = 1, inplace=True) data2.drop("num_historical_failed_to_pay", axis = 1, inplace=True) data2.drop("num_collections_last_12m", axis = 1, inplace=True) data2.drop("delinq_2y", axis = 1, inplace=True) data2.drop("verified_income", axis = 1, inplace=True) data2.drop("annual_income", axis = 1, inplace=True) data2.drop("debt_to_income", axis = 1, inplace=True) data2.drop("months_since_90d_late", axis = 1, inplace=True) data2.drop("months_since_last_delinq", axis = 1, inplace=True) data2.drop("issue_month", axis = 1, inplace=True) data2.drop("initial_listing_status", axis = 1, inplace=True) data2.drop("disbursement_method", axis = 1, inplace=True) data2.drop("grade", axis = 1, inplace=True) #removing columns based on correlation data2.drop("total_credit_limit", axis = 1, inplace=True) data2.drop("current_installment_accounts", axis = 1, inplace=True) data2.drop("accounts_opened_24m", axis = 1, inplace=True) data2.drop("open_credit_lines", axis = 1, inplace=True) data2.drop("loan_amount", axis = 1, inplace=True) data2.drop("balance", axis = 1, inplace=True) data2.drop("paid_principal", axis = 1, inplace=True) data2.drop("num_satisfactory_accounts", axis = 1, inplace=True) data2.drop("total_credit_lines", axis = 1, inplace=True) data2.drop("num_active_debit_accounts", axis = 1, inplace=True) data2.drop("num_open_cc_accounts", axis = 1, inplace=True) data2.drop("installment", axis = 1, inplace=True) data2.drop("num_total_cc_accounts", axis = 1, inplace=True) #Removing Outliers based on its Quartile and Max Value data5 = data2 sns.boxplot(data5['paid_interest']) data5 = data5.loc[data5["inquiries_last_12m"] < 15] data5 = data5.loc[data5["total_credit_utilized"] < 400000] data5 = data5.loc[data5["months_since_last_credit_inquiry"] < 20] data5 = data5.loc[data5["total_debit_limit"] < 220000] data5 = data5.loc[data5["num_cc_carrying_balance"] < 20] data5 = data5.loc[data5["num_mort_accounts"] < 10] data5 = data5.loc[data5["paid_total"] < 35000] data5 = data5.loc[data5["paid_interest"] < 3000] # Encoding Categorical Data using LabelEncoder le = preprocessing.LabelEncoder() data5['sub_grade'] = le.fit_transform(data5['sub_grade'].values) data5['verification_income_joint'] = le.fit_transform(data5['verification_income_joint'].values) data5['loan_status'] = le.fit_transform(data5['loan_status'].values) data5['loan_purpose'] = le.fit_transform(data5['loan_purpose'].values) data5['application_type'] = le.fit_transform(data5['application_type'].values) data5['homeownership'] = le.fit_transform(data5['homeownership'].values) data5 = data5.reindex(columns=['emp_length', 'homeownership', 'annual_income_joint', 'verification_income_joint', 'debt_to_income_joint', 'earliest_credit_line', 'inquiries_last_12m', 'total_credit_utilized', 'months_since_last_credit_inquiry', 'total_debit_limit', 'num_cc_carrying_balance', 'num_mort_accounts', 'account_never_delinq_percent', 'loan_purpose', 'application_type', 'term', 'sub_grade', 'loan_status', 'paid_total', 'paid_interest', 'interest_rate']) X = data5.iloc[:, :-1].values y = data5.iloc[:, -1].values y = y.reshape(len(y),1) #Feature Scaling from sklearn.preprocessing import StandardScaler sc_X = StandardScaler() sc_y = StandardScaler() X = sc_X.fit_transform(X) y = sc_y.fit_transform(y) #Train Test Split from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) #Modelling the Data #Support Vector Regression from sklearn.svm import SVR regressor_SVM = SVR(kernel = 'rbf') regressor_SVM.fit(X_train, y_train) #For Training Data SVR_train_pred = regressor_SVM.predict(X_train) score2=r2_score(y_train,SVR_train_pred) score2 print("Mean absolute error =", round(sm.mean_absolute_error(y_train, SVR_train_pred), 2)) print("Mean squared error =", round(sm.mean_squared_error(y_train, SVR_train_pred), 2)) print("Median absolute error =", round(sm.median_absolute_error(y_train, SVR_train_pred), 2)) print("Explain variance score =", round(sm.explained_variance_score(y_train, SVR_train_pred), 2)) #For Testing data SVR_test_pred = regressor_SVM.predict(X_test) score3=r2_score(y_test,SVR_test_pred) score3 print("Mean absolute error =", round(sm.mean_absolute_error(y_test, SVR_test_pred), 2)) print("Mean squared error =", round(sm.mean_squared_error(y_test, SVR_test_pred), 2)) print("Median absolute error =", round(sm.median_absolute_error(y_test, SVR_test_pred), 2)) print("Explain variance score =", round(sm.explained_variance_score(y_test, SVR_test_pred), 2)) #Random Forest Model from sklearn.ensemble import RandomForestRegressor regressor1 = RandomForestRegressor(n_estimators = 10, random_state = 0) regressor1.fit(X_train, y_train) #For Training Data random_train_pred = regressor1.predict(X_train) score1=r2_score(y_train,random_train_pred) score1 print("Mean absolute error =", round(sm.mean_absolute_error(y_train, random_train_pred), 2)) print("Mean squared error =", round(sm.mean_squared_error(y_train, random_train_pred), 2)) print("Median absolute error =", round(sm.median_absolute_error(y_train, random_train_pred), 2)) print("Explain variance score =", round(sm.explained_variance_score(y_train, random_train_pred), 2)) #For Testing Data random_test_pred = regressor1.predict(X_test) score=r2_score(y_test,random_test_pred) score print("Mean absolute error =", round(sm.mean_absolute_error(y_test, random_test_pred), 2)) print("Mean squared error =", round(sm.mean_squared_error(y_test, random_test_pred), 2)) print("Median absolute error =", round(sm.median_absolute_error(y_test, random_test_pred), 2)) print("Explain variance score =", round(sm.explained_variance_score(y_test, random_test_pred), 2))
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 4561, 88, 1082, 12058, 198, 198, 5840, 81, 342, 64, 3834, 6236, 22931, 2438, 329, 3563, 12425, 360, 5631, 34958, 3563, 8120, 42001, 49348, 11015, 198, 198, 3...
2.604979
3,977
""" Datastore is a generic layer of abstraction for data store and database access. It is a **simple** API with the aim to enable application development in a datastore-agnostic way, allowing datastores to be swapped seamlessly without changing application code. Thus, one can leverage different datastores with different strengths without committing the application to one datastore throughout its lifetime. """ __version__ = "0.3.6" __author__ = "Juan Batiz-Benet, Alexander Schlarb" __email__ = "juan@benet.ai, alexander@ninetailed.ninja" __all__ = ( "Key", "Namespace", "BinaryNullDatastore", "BinaryDictDatastore", "ObjectNullDatastore", "ObjectDictDatastore", "Query", "Cursor", "SerializerAdapter", "abc", "typing", "util" ) # import core.key from .core.key import Key from .core.key import Namespace # import core.binarystore, core.objectstore from .core.binarystore import NullDatastore as BinaryNullDatastore from .core.binarystore import DictDatastore as BinaryDictDatastore from .core.objectstore import NullDatastore as ObjectNullDatastore from .core.objectstore import DictDatastore as ObjectDictDatastore # import core.query from .core.query import Query from .core.query import Cursor # import core.serialize from .core.serialize import SerializerAdapter ### Exposed submodules ### from . import abc from . import typing from . import util
[ 37811, 198, 27354, 459, 382, 318, 257, 14276, 7679, 286, 34651, 329, 1366, 3650, 290, 6831, 1895, 13, 198, 1026, 318, 257, 12429, 36439, 1174, 7824, 351, 262, 4031, 284, 7139, 3586, 2478, 287, 257, 198, 19608, 459, 382, 12, 4660, 1513...
3.34878
410
# -*- coding: utf-8 -*- from __future__ import division import random from otree.common import Currency as c, currency_range from . import views from ._builtin import Bot from .models import Constants
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 6738, 11593, 37443, 834, 1330, 7297, 198, 198, 11748, 4738, 198, 198, 6738, 267, 21048, 13, 11321, 1330, 20113, 355, 269, 11, 7395, 62, 9521, 198, 198, 6738, 764, 1330, ...
3.416667
60
#!/usr/bin/env python # -*- coding:utf8 -*- # Copyright 2017, Schuberg Philis BV # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you 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 # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # Romero Galiza Jr. - rgaliza@schubergphilis.com """ This is not part of the Admin API, but it incorporates additional tooling to support statistical analysis of monitored data within a cluster, data center or node """ def get_hs_used_kb(node): """ Receives a node monitor JSON string and returns a list containing the used disk space in KB for each hyperstore disk. :param node: an iterable object :type node: dict :rtype: list """ if 'disksInfo' not in node: raise TypeError('Unsupported input.') # filter function to select only HyperStore disks: f = (lambda n: True if 'HS' in n['storageUse'] else False) hs_disks = filter( f, (d for d in node['disksInfo']['disks']) ) return [abs(int(disk['diskUsedKb'])) for disk in hs_disks] def disk_avg_abs_deviation(node): """ Returns the average absolute deviation for a given set of disks of a given node based entirely on used capacity (expressed in KB). Particularly useful if you want to visualize the average difference between all disks in a given node. The closer the result is to zero the better (less deviation = balanced usage). :param node: an iterable object :type node: dict :rtype: int """ try: disk_usage = get_hs_used_kb(node) except TypeError: return 0 mean = (sum(disk_usage) / len(disk_usage)) deviation = [abs(kb_used - mean) for kb_used in disk_usage] return sum(deviation)/len(deviation)
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 532, 9, 12, 19617, 25, 40477, 23, 532, 9, 12, 198, 198, 2, 220, 220, 220, 220, 220, 15069, 2177, 11, 3059, 84, 3900, 4543, 271, 347, 53, 198, 2, 198, 2, 220, 220, 220, 220, ...
2.824777
896
from os import name from django.db import models from django.contrib.auth.models import User from PIL import Image #Model classes are tables objects in a database. #each variable is a column and its datatype. #__str__ method defines the name of a object (row) in a database table #profile model is meant to be used as an extension to the User model #this is so users can have a profile picture and be connected to a company """ def save(self, *args, **kwargs): super().save(*args, **kwargs) image = Image.open(self.picture.path) if image.width > 300 or image.height > 300: image.thumbnail((300, 300)) image.save(self.picture.path) """
[ 6738, 28686, 1330, 1438, 198, 6738, 42625, 14208, 13, 9945, 1330, 4981, 198, 6738, 42625, 14208, 13, 3642, 822, 13, 18439, 13, 27530, 1330, 11787, 198, 6738, 350, 4146, 1330, 7412, 198, 198, 2, 17633, 6097, 389, 8893, 5563, 287, 257, ...
2.982684
231
#!/usr/bin/env python import RPi.GPIO as GPIO GPIO.setwarnings(False) led_color_gpio = { 'yellow': 0, 'orange': 2, 'red': 3, 'green': 4, 'blue': 5, 'white': 6 } buttons_gpio = { 'red': 28, 'blue': 29, } gpio_to_bcm = { 0: 17, 1: 18, 2: 27, 3: 22, 4: 23, 5: 24, 6: 25, 21: 5, 22: 6, 23: 13, 24: 19, 25: 26, 26: 12, 27: 16, 28: 20, 29: 21, } GPIO.setmode(GPIO.BCM) for gpio in led_color_gpio.values(): bcm_pin = gpio_to_bcm[gpio] GPIO.setup(bcm_pin, GPIO.OUT) GPIO.output(bcm_pin, True) print("Type 'quit' to quit") while True: user_input = raw_input("Enter Color and on/off: ") tokens = user_input.split() if len(tokens) < 1: continue color = tokens[0] if color == "quit": break onoff = 1 if len(tokens) > 1: onoff = tokens[1] if onoff == "on": onoff = 1 elif onoff == "off": onoff = 0 else: onoff = int(onoff) led_color(color, onoff) for gpio in led_color_gpio.values(): bcm_pin = gpio_to_bcm[gpio] GPIO.output(bcm_pin, True)
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 11748, 25812, 72, 13, 16960, 9399, 355, 50143, 198, 198, 16960, 9399, 13, 2617, 40539, 654, 7, 25101, 8, 198, 198, 992, 62, 8043, 62, 31197, 952, 796, 1391, 198, 220, 220, 220, 705, ...
1.827372
643
#!/usr/bin/env python ########################################################################### # # Written in 2009 by Ian Katz <ijk5@mit.edu> # Terms: WTFPL (http://sam.zoy.org/wtfpl/) # See COPYING and WARRANTY files included in this distribution # ########################################################################### # this program launches MOOS processes and verifies that they're up. # this sequential launch method is gentler to low-horsepower CPUs. # # It takes 2 command line arguments: # 1. the MOOS config file to be used # 2. OPTIONALLY the working directory that all apps should launch from import os import sys import time #MAKE ANY CHANGES HERE if __name__ == "__main__": if len(sys.argv) < 2: print "Usage: " + sys.argv[0] + "<MOOS config file name> [working directory]" exit(1) #The app name, and -- optionally -- its ID string moosProcList = desired_MOOS_procs() moosConfigFile = sys.argv[1] if len(sys.argv) == 3: #we want to run all processes in this directory os.chdir(sys.argv[2]) print "Starting MOOSDB...", start_MOOS_process_in_new_screen("MOOSDB", moosConfigFile) #see if we can use pyMOOS to intelligently launch processes try: import pyMOOS pi = pyMOOS.PI # force an error except: #fall back on basic implementation print "Done" print "\nNo pyMOOS detected... falling back on timed launch sequence\n" start_all_MOOSProcesses(moosProcList, moosConfigFile, 5.0) exit(0) #wait for connect myComms = pyMOOS.CMOOSCommClient() if myComms.Run("localhost", 9000, "StartMOOS.py[" + os.uname()[1] + "]"): print "Done!" print "\n\nStarting MOOS processes the SCHMANCY way!\n" else: print "Failed to connect to local MOOSDB." print "You may want to 'killall screen' and try again." exit(1) print "Connecting to MOOSDB...", while not myComms.IsConnected(): tick() print "Done!" #start each process and wait for it to connect start_MOOS_processes_sequentially(moosProcList, moosConfigFile, myComms) print "\nAll MOOS processes successfully launched!"
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 29113, 29113, 7804, 21017, 198, 2, 220, 220, 220, 220, 198, 2, 220, 220, 220, 22503, 287, 3717, 416, 12930, 36290, 1279, 45961, 20, 31, 2781, 13, 15532, 29, 220, 220, 220, 220, 220, ...
2.631214
865
from unittest import TestCase from unittest.mock import patch from word_vectorizer.constants import Constants from word_vectorizer.model_downloading.gensim_model_downloader import \ GensimModelDownloader
[ 6738, 555, 715, 395, 1330, 6208, 20448, 198, 6738, 555, 715, 395, 13, 76, 735, 1330, 8529, 198, 198, 6738, 1573, 62, 31364, 7509, 13, 9979, 1187, 1330, 4757, 1187, 198, 6738, 1573, 62, 31364, 7509, 13, 19849, 62, 15002, 278, 13, 70,...
3.333333
63
#!/usr/bin/python3 # # Copyright 2018, The Android Open Source Project # # 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 # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """MLTS benchmark result generator. Reads a CSV produced by MLTS benchmark and generates an HTML page with results summary. Usage: generate_result [csv input file] [html output file] """ import argparse import collections import csv import os import re import math LatencyResult = collections.namedtuple( 'LatencyResult', ['iterations', 'total_time_sec', 'time_freq_start_sec', 'time_freq_step_sec', 'time_freq_sec']) COMPILATION_TYPES = ['compile_without_cache', 'save_to_cache', 'prepare_from_cache'] BASELINE_COMPILATION_TYPE = COMPILATION_TYPES[0] CompilationResult = collections.namedtuple( 'CompilationResult', ['cache_size_bytes'] + COMPILATION_TYPES) BenchmarkResult = collections.namedtuple( 'BenchmarkResult', ['name', 'backend_type', 'inference_latency', 'max_single_error', 'testset_size', 'evaluator_keys', 'evaluator_values', 'validation_errors', 'compilation_results']) ResultsWithBaseline = collections.namedtuple( 'ResultsWithBaseline', ['baseline', 'other']) BASELINE_BACKEND = 'TFLite_CPU' KNOWN_GROUPS = [ (re.compile('mobilenet_v1.*quant.*'), 'MobileNet v1 Quantized'), (re.compile('mobilenet_v1.*'), 'MobileNet v1 Float'), (re.compile('mobilenet_v2.*quant.*'), 'MobileNet v2 Quantized'), (re.compile('mobilenet_v2.*'), 'MobileNet v2 Float'), (re.compile('mobilenet_v3.*uint8.*'), 'MobileNet v3 Quantized'), (re.compile('mobilenet_v3.*'), 'MobileNet v3 Float'), (re.compile('tts.*'), 'LSTM Text-to-speech'), (re.compile('asr.*'), 'LSTM Automatic Speech Recognition'), ] def parse_csv_input(input_filename): """Parse input CSV file, returns: (benchmarkInfo, list of BenchmarkResult).""" with open(input_filename, 'r') as csvfile: parser = BenchmarkResultParser(csvfile) # First line contain device info benchmark_info = parser.next() results = [] while parser.next(): results.append(parser.read_benchmark_result()) return (benchmark_info, results) def group_results(results): """Group list of results by their name/backend, returns list of lists.""" # Group by name groupings = collections.defaultdict(list) for result in results: groupings[result.name].append(result) # Find baseline for each group, make ResultsWithBaseline for each name groupings_baseline = {} for name, results in groupings.items(): baseline = next(filter(lambda x: x.backend_type == BASELINE_BACKEND, results)) other = sorted(filter(lambda x: x is not baseline, results), key=lambda x: x.backend_type) groupings_baseline[name] = ResultsWithBaseline( baseline=baseline, other=other) # Merge ResultsWithBaseline for known groups known_groupings_baseline = collections.defaultdict(list) for name, results_with_bl in sorted(groupings_baseline.items()): group_name = name for known_group in KNOWN_GROUPS: if known_group[0].match(results_with_bl.baseline.name): group_name = known_group[1] break known_groupings_baseline[group_name].append(results_with_bl) # Turn into a list sorted by name groupings_list = [] for name, results_wbl in sorted(known_groupings_baseline.items()): groupings_list.append((name, results_wbl)) return groupings_list def get_frequency_graph_min_max(latencies): """Get min and max times of latencies frequency.""" mins = [] maxs = [] for latency in latencies: mins.append(latency.time_freq_start_sec) to_add = len(latency.time_freq_sec) * latency.time_freq_step_sec maxs.append(latency.time_freq_start_sec + to_add) return min(mins), max(maxs) def get_frequency_graph(time_freq_start_sec, time_freq_step_sec, time_freq_sec, start_sec, end_sec): """Generate input x/y data for latency frequency graph.""" left_to_pad = (int((time_freq_start_sec - start_sec) / time_freq_step_sec) if time_freq_step_sec != 0 else math.inf) end_time = time_freq_start_sec + len(time_freq_sec) * time_freq_step_sec right_to_pad = (int((end_sec - end_time) / time_freq_step_sec) if time_freq_step_sec != 0 else math.inf) # After pading more that 64 values, graphs start to look messy, # bail out in that case. if (left_to_pad + right_to_pad) < 64: left_pad = (['{:.2f}ms'.format( (start_sec + x * time_freq_step_sec) * 1000.0) for x in range(left_to_pad)], [0] * left_to_pad) right_pad = (['{:.2f}ms'.format( (end_time + x * time_freq_step_sec) * 1000.0) for x in range(right_to_pad)], [0] * right_to_pad) else: left_pad = [[], []] right_pad = [[], []] data = (['{:.2f}ms'.format( (time_freq_start_sec + x * time_freq_step_sec) * 1000.0) for x in range(len(time_freq_sec))], time_freq_sec) return (left_pad[0] + data[0] + right_pad[0], left_pad[1] + data[1] + right_pad[1]) def is_topk_evaluator(evaluator_keys): """Are these evaluator keys from TopK evaluator?""" return (len(evaluator_keys) == 5 and evaluator_keys[0] == 'top_1' and evaluator_keys[1] == 'top_2' and evaluator_keys[2] == 'top_3' and evaluator_keys[3] == 'top_4' and evaluator_keys[4] == 'top_5') def is_melceplogf0_evaluator(evaluator_keys): """Are these evaluator keys from MelCepLogF0 evaluator?""" return (len(evaluator_keys) == 2 and evaluator_keys[0] == 'max_mel_cep_distortion' and evaluator_keys[1] == 'max_log_f0_error') def is_phone_error_rate_evaluator(evaluator_keys): """Are these evaluator keys from PhoneErrorRate evaluator?""" return (len(evaluator_keys) == 1 and evaluator_keys[0] == 'max_phone_error_rate') def generate_accuracy_headers(result): """Accuracy-related headers for result table.""" if is_topk_evaluator(result.evaluator_keys): return ACCURACY_HEADERS_TOPK_TEMPLATE elif is_melceplogf0_evaluator(result.evaluator_keys): return ACCURACY_HEADERS_MELCEPLOGF0_TEMPLATE elif is_phone_error_rate_evaluator(result.evaluator_keys): return ACCURACY_HEADERS_PHONE_ERROR_RATE_TEMPLATE else: return ACCURACY_HEADERS_BASIC_TEMPLATE raise ScoreException('Unknown accuracy headers for: ' + str(result)) def generate_accuracy_values(baseline, result): """Accuracy-related data for result table.""" if is_topk_evaluator(result.evaluator_keys): val = [float(x) * 100.0 for x in result.evaluator_values] if result is baseline: topk = [TOPK_BASELINE_TEMPLATE.format(val=x) for x in val] return ACCURACY_VALUES_TOPK_TEMPLATE.format( top1=topk[0], top2=topk[1], top3=topk[2], top4=topk[3], top5=topk[4] ) else: base = [float(x) * 100.0 for x in baseline.evaluator_values] diff = [a - b for a, b in zip(val, base)] topk = [TOPK_DIFF_TEMPLATE.format( val=v, diff=d, span=get_diff_span(d, 1.0, positive_is_better=True)) for v, d in zip(val, diff)] return ACCURACY_VALUES_TOPK_TEMPLATE.format( top1=topk[0], top2=topk[1], top3=topk[2], top4=topk[3], top5=topk[4] ) elif is_melceplogf0_evaluator(result.evaluator_keys): val = [float(x) for x in result.evaluator_values + [result.max_single_error]] if result is baseline: return ACCURACY_VALUES_MELCEPLOGF0_TEMPLATE.format( max_log_f0=MELCEPLOGF0_BASELINE_TEMPLATE.format( val=val[0]), max_mel_cep_distortion=MELCEPLOGF0_BASELINE_TEMPLATE.format( val=val[1]), max_single_error=MELCEPLOGF0_BASELINE_TEMPLATE.format( val=val[2]), ) else: base = [float(x) for x in baseline.evaluator_values + [baseline.max_single_error]] diff = [a - b for a, b in zip(val, base)] v = [MELCEPLOGF0_DIFF_TEMPLATE.format( val=v, diff=d, span=get_diff_span(d, 1.0, positive_is_better=False)) for v, d in zip(val, diff)] return ACCURACY_VALUES_MELCEPLOGF0_TEMPLATE.format( max_log_f0=v[0], max_mel_cep_distortion=v[1], max_single_error=v[2], ) elif is_phone_error_rate_evaluator(result.evaluator_keys): val = [float(x) for x in result.evaluator_values + [result.max_single_error]] if result is baseline: return ACCURACY_VALUES_PHONE_ERROR_RATE_TEMPLATE.format( max_phone_error_rate=PHONE_ERROR_RATE_BASELINE_TEMPLATE.format( val=val[0]), max_single_error=PHONE_ERROR_RATE_BASELINE_TEMPLATE.format( val=val[1]), ) else: base = [float(x) for x in baseline.evaluator_values + [baseline.max_single_error]] diff = [a - b for a, b in zip(val, base)] v = [PHONE_ERROR_RATE_DIFF_TEMPLATE.format( val=v, diff=d, span=get_diff_span(d, 1.0, positive_is_better=False)) for v, d in zip(val, diff)] return ACCURACY_VALUES_PHONE_ERROR_RATE_TEMPLATE.format( max_phone_error_rate=v[0], max_single_error=v[1], ) else: return ACCURACY_VALUES_BASIC_TEMPLATE.format( max_single_error=result.max_single_error, ) raise ScoreException('Unknown accuracy values for: ' + str(result)) def generate_avg_ms(baseline, latency): """Generate average latency value.""" if latency is None: latency = baseline result_avg_ms = (latency.total_time_sec / latency.iterations)*1000.0 if latency is baseline: return LATENCY_BASELINE_TEMPLATE.format(val=result_avg_ms) baseline_avg_ms = (baseline.total_time_sec / baseline.iterations)*1000.0 diff = (result_avg_ms/baseline_avg_ms - 1.0) * 100.0 diff_val = result_avg_ms - baseline_avg_ms return LATENCY_DIFF_TEMPLATE.format( val=result_avg_ms, diff=diff, diff_val=diff_val, span=get_diff_span(diff, same_delta=1.0, positive_is_better=False)) def generate_latency_graph_entry(tag, latency, tmin, tmax): """Generate a single latency graph.""" return LATENCY_GRAPH_ENTRY_TEMPLATE.format( tag=tag, i=id(latency), freq_data=get_frequency_graph(latency.time_freq_start_sec, latency.time_freq_step_sec, latency.time_freq_sec, tmin, tmax)) def generate_latency_graphs_group(tags, latencies): """Generate a group of latency graphs with the same tmin and tmax.""" tmin, tmax = get_frequency_graph_min_max(latencies) return ''.join( generate_latency_graph_entry(tag, latency, tmin, tmax) for tag, latency in zip(tags, latencies)) def generate_inference_latency_graph_entry(results_with_bl): """Generate a group of latency graphs for inference latencies.""" results = [results_with_bl.baseline] + results_with_bl.other tags = [result.backend_type for result in results] latencies = [result.inference_latency for result in results] return generate_latency_graphs_group(tags, latencies) def generate_compilation_latency_graph_entry(results_with_bl): """Generate a group of latency graphs for compilation latencies.""" tags = [ result.backend_type + ', ' + snake_case_to_title(type) for result in results_with_bl.other for type in COMPILATION_TYPES if getattr(result.compilation_results, type) ] latencies = [ getattr(result.compilation_results, type) for result in results_with_bl.other for type in COMPILATION_TYPES if getattr(result.compilation_results, type) ] return generate_latency_graphs_group(tags, latencies) def generate_validation_errors(entries_group): """Generate validation errors table.""" errors = [] for result_and_bl in entries_group: for result in [result_and_bl.baseline] + result_and_bl.other: for error in result.validation_errors: errors.append((result.name, result.backend_type, error)) if errors: return VALIDATION_ERRORS_TEMPLATE.format( results=''.join( VALIDATION_ERRORS_ENTRY_TEMPLATE.format( name=name, backend=backend, error=error) for name, backend, error in errors)) return '' def generate_result(benchmark_info, data): """Turn list of results into HTML.""" return MAIN_TEMPLATE.format( jsdeps=getchartjs_source(), device_info=DEVICE_INFO_TEMPLATE.format( benchmark_time=benchmark_info[0], device_info=benchmark_info[1], ), results_list=''.join(( RESULT_GROUP_TEMPLATE.format( group_name=entries_name, accuracy_headers=generate_accuracy_headers( entries_group[0].baseline), results=''.join( RESULT_ENTRY_WITH_BASELINE_TEMPLATE.format( baseline=generate_result_entry( result_and_bl.baseline, None), other=''.join( generate_result_entry( result_and_bl.baseline, x) for x in result_and_bl.other) ) for result_and_bl in entries_group), validation_errors=generate_validation_errors(entries_group), latency_graphs=LATENCY_GRAPHS_TEMPLATE.format( results=''.join( LATENCY_GRAPH_ENTRY_GROUP_TEMPLATE.format( name=result_and_bl.baseline.name, results=generate_inference_latency_graph_entry(result_and_bl) ) for result_and_bl in entries_group) ), compilation_results=''.join( COMPILATION_RESULT_ENTRIES_TEMPLATE.format( entries=''.join( generate_compilation_result_entry(x) for x in result_and_bl.other) ) for result_and_bl in entries_group), compilation_latency_graphs=LATENCY_GRAPHS_TEMPLATE.format( results=''.join( LATENCY_GRAPH_ENTRY_GROUP_TEMPLATE.format( name=result_and_bl.baseline.name, results=generate_compilation_latency_graph_entry(result_and_bl) ) for result_and_bl in entries_group) ), ) for entries_name, entries_group in group_results(data)) )) # ----------------- # Templates below MAIN_TEMPLATE = """<!doctype html> <html lang='en-US'> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script> <script>{jsdeps}</script> <title>MLTS results</title> <style> .results {{ border-collapse: collapse; width: 100%; }} .results td, .results th {{ border: 1px solid #ddd; padding: 6px; }} .results tbody.values {{ border-bottom: 8px solid #333; }} span.better {{ color: #070; }} span.worse {{ color: #700; }} span.same {{ color: #000; }} .results tr:nth-child(even) {{background-color: #eee;}} .results tr:hover {{background-color: #ddd;}} .results th {{ padding: 10px; font-weight: bold; text-align: left; background-color: #333; color: white; }} .results tr.failed {{ background-color: #ffc4ca; }} .group {{ padding-top: 25px; }} .group_name {{ padding-left: 10px; font-size: 140%; font-weight: bold; }} .section_name {{ padding: 10px; font-size: 120%; font-weight: bold; }} .latency_results {{ padding: 10px; border: 1px solid #ddd; overflow: hidden; }} .latency_with_baseline {{ padding: 10px; border: 1px solid #ddd; overflow: hidden; }} </style> </head> <body> {device_info} {results_list} </body> </html>""" DEVICE_INFO_TEMPLATE = """<div id='device_info'> Benchmark for {device_info}, started at {benchmark_time} </div>""" RESULT_GROUP_TEMPLATE = """<div class="group"> <div class="group_name">{group_name}</div> <div class="section_name">Inference results</div> <table class="results"> <tr> <th>Name</th> <th>Backend</th> <th>Iterations</th> <th>Test set size</th> <th>Average latency ms</th> {accuracy_headers} </tr> {results} </table> {validation_errors} {latency_graphs} <div class="section_name">Compilation results</div> <table class="results"> <tr> <th rowspan="2">Name</th> <th rowspan="2">Backend</th> <th colspan="2">Compile Without Cache</th> <th colspan="2">Save To Cache</th> <th colspan="2">Prepare From Cache</th> <th rowspan="2">Cache size bytes</th> </tr> <tr> <th>Iterations</th> <th>Average latency ms</th> <th>Iterations</th> <th>Average latency ms</th> <th>Iterations</th> <th>Average latency ms</th> </tr> {compilation_results} </table> {compilation_latency_graphs} </div>""" VALIDATION_ERRORS_TEMPLATE = """ <table class="results"> <tr> <th>Name</th> <th>Backend</th> <th>Error</th> </tr> {results} </table>""" VALIDATION_ERRORS_ENTRY_TEMPLATE = """ <tr class="failed"> <td>{name}</td> <td>{backend}</td> <td>{error}</td> </tr> """ LATENCY_GRAPHS_TEMPLATE = """ <div class="latency_results"> {results} </div> <div style="clear: left;"></div> """ LATENCY_GRAPH_ENTRY_GROUP_TEMPLATE = """ <div class="latency_with_baseline" style="float: left;"> <b>{name}</b> {results} </div> """ LATENCY_GRAPH_ENTRY_TEMPLATE = """ <div class="latency_result" style='width: 350px;'> {tag} <canvas id='latency_chart{i}' class='latency_chart'></canvas> <script> $(function() {{ var freqData = {{ labels: {freq_data[0]}, datasets: [{{ data: {freq_data[1]}, backgroundColor: 'rgba(255, 99, 132, 0.6)', borderColor: 'rgba(255, 0, 0, 0.6)', borderWidth: 1, }}] }}; var ctx = $('#latency_chart{i}')[0].getContext('2d'); window.latency_chart{i} = new Chart(ctx, {{ type: 'bar', data: freqData, options: {{ responsive: true, title: {{ display: false, text: 'Latency frequency' }}, legend: {{ display: false }}, scales: {{ xAxes: [ {{ barPercentage: 1.0, categoryPercentage: 0.9, }}], yAxes: [{{ scaleLabel: {{ display: false, labelString: 'Iterations Count' }} }}] }} }} }}); }}); </script> </div> """ RESULT_ENTRY_WITH_BASELINE_TEMPLATE = """ <tbody class="values"> {baseline} {other} </tbody> """ RESULT_ENTRY_TEMPLATE = """ <tr class={row_class}> <td>{name}</td> <td>{backend}</td> <td>{iterations:d}</td> <td>{testset_size:d}</td> <td>{avg_ms}</td> {accuracy_values} </tr>""" COMPILATION_RESULT_ENTRIES_TEMPLATE = """ <tbody class="values"> {entries} </tbody> """ COMPILATION_RESULT_ENTRY_TEMPLATE = """ <tr class={row_class}> <td>{name}</td> <td>{backend}</td> <td>{compile_without_cache_iterations}</td> <td>{compile_without_cache_avg_ms}</td> <td>{save_to_cache_iterations}</td> <td>{save_to_cache_avg_ms}</td> <td>{prepare_from_cache_iterations}</td> <td>{prepare_from_cache_avg_ms}</td> <td>{cache_size}</td> </tr>""" LATENCY_BASELINE_TEMPLATE = """{val:.2f}ms""" LATENCY_DIFF_TEMPLATE = """{val:.2f}ms <span class='{span}'> ({diff_val:.2f}ms, {diff:.1f}%)</span>""" ACCURACY_HEADERS_TOPK_TEMPLATE = """ <th>Top 1</th> <th>Top 2</th> <th>Top 3</th> <th>Top 4</th> <th>Top 5</th> """ ACCURACY_VALUES_TOPK_TEMPLATE = """ <td>{top1}</td> <td>{top2}</td> <td>{top3}</td> <td>{top4}</td> <td>{top5}</td> """ TOPK_BASELINE_TEMPLATE = """{val:.3f}%""" TOPK_DIFF_TEMPLATE = """{val:.3f}% <span class='{span}'>({diff:.1f}%)</span>""" ACCURACY_HEADERS_MELCEPLOGF0_TEMPLATE = """ <th>Max log(F0) error</th> <th>Max Mel Cep distortion</th> <th>Max scalar error</th> """ ACCURACY_VALUES_MELCEPLOGF0_TEMPLATE = """ <td>{max_log_f0}</td> <td>{max_mel_cep_distortion}</td> <td>{max_single_error}</td> """ MELCEPLOGF0_BASELINE_TEMPLATE = """{val:.2E}""" MELCEPLOGF0_DIFF_TEMPLATE = \ """{val:.2E} <span class='{span}'>({diff:.1f}%)</span>""" ACCURACY_HEADERS_PHONE_ERROR_RATE_TEMPLATE = """ <th>Max phone error rate</th> <th>Max scalar error</th> """ ACCURACY_VALUES_PHONE_ERROR_RATE_TEMPLATE = """ <td>{max_phone_error_rate}</td> <td>{max_single_error}</td> """ PHONE_ERROR_RATE_BASELINE_TEMPLATE = """{val:.3f}""" PHONE_ERROR_RATE_DIFF_TEMPLATE = \ """{val:.3f} <span class='{span}'>({diff:.1f}%)</span>""" ACCURACY_HEADERS_BASIC_TEMPLATE = """ <th>Max single scalar error</th> """ ACCURACY_VALUES_BASIC_TEMPLATE = """ <td>{max_single_error:.2f}</td> """ CHART_JS_FILE = 'Chart.bundle.min.js' if __name__ == '__main__': main()
[ 2, 48443, 14629, 14, 8800, 14, 29412, 18, 198, 2, 198, 2, 15069, 2864, 11, 383, 5565, 4946, 8090, 4935, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, ...
2.167563
10,038
#!/usr/bin/env python # -*- coding: utf-8 -*- # File: Ampel-ZTF/ampel/ztf/dev/DevSkyPortalClient.py # Author: Jakob van Santen <jakob.van.santen@desy.de> # Date: 16.09.2020 # Last Modified Date: 16.09.2020 # Last Modified By: Jakob van Santen <jakob.van.santen@desy.de> import gzip import io from collections import defaultdict from datetime import datetime from typing import Any from collections.abc import Sequence, Generator import numpy as np import requests from ampel.protocol.AmpelAlertProtocol import AmpelAlertProtocol from astropy.io import fits from astropy.time import Time from matplotlib.colors import Normalize from matplotlib.figure import Figure def render_thumbnail(cutout_data: bytes) -> bytes: """ Render gzipped FITS as PNG """ with gzip.open(io.BytesIO(cutout_data), "rb") as f: with fits.open(f) as hdu: header = hdu[0].header img = np.flipud(hdu[0].data) mask = np.isfinite(img) fig = Figure(figsize=(1, 1)) ax = fig.add_axes([0.0, 0.0, 1.0, 1.0]) ax.set_axis_off() ax.imshow( img, # clip pixel values below the median norm=Normalize(*np.percentile(img[mask], [0.5, 99.5])), aspect="auto", origin="lower", ) with io.BytesIO() as buf: fig.savefig(buf, dpi=img.shape[0]) return buf.getvalue()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 9220, 25, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 1703, 30242, 12, 57, 10234,...
2.279675
615
""" Reads in a tsv file with pre-trained bottom up attention features and stores it in HDF5 format. Also store {image_id: feature_idx} as a pickle file. Hierarchy of HDF5 file: { 'image_features': num_images x num_boxes x 2048 array of features 'image_bb': num_images x num_boxes x 4 array of bounding boxes } """ from __future__ import print_function import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import base64 import csv import h5py import cPickle import numpy as np import utils csv.field_size_limit(sys.maxsize) FIELDNAMES = ['image_id', 'image_w', 'image_h', 'num_boxes', 'boxes', 'features'] infile = 'data/test2015_36/test2015_resnet101_faster_rcnn_genome_36.tsv' test_data_file = 'data/test36.hdf5' test_indices_file = 'data/test36_imgid2idx.pkl' test_ids_file = 'data/test_ids.pkl' feature_length = 2048 num_fixed_boxes = 36 if __name__ == '__main__': h_test = h5py.File(test_data_file, "w") if os.path.exists(test_ids_file): test_imgids = cPickle.load(open(test_ids_file)) else: test_imgids = utils.load_imageid('data/test2015') cPickle.dump(test_imgids, open(test_ids_file, 'wb')) test_indices = {} test_img_features = h_test.create_dataset( 'image_features', (len(test_imgids), num_fixed_boxes, feature_length), 'f') test_img_bb = h_test.create_dataset( 'image_bb', (len(test_imgids), num_fixed_boxes, 4), 'f') test_spatial_img_features = h_test.create_dataset( 'spatial_features', (len(test_imgids), num_fixed_boxes, 6), 'f') test_counter = 0 print("reading tsv...") with open(infile, "r+b") as tsv_in_file: reader = csv.DictReader(tsv_in_file, delimiter='\t', fieldnames=FIELDNAMES) for item in reader: item['num_boxes'] = int(item['num_boxes']) image_id = int(item['image_id']) image_w = float(item['image_w']) image_h = float(item['image_h']) bboxes = np.frombuffer( base64.decodestring(item['boxes']), dtype=np.float32).reshape((item['num_boxes'], -1)) box_width = bboxes[:, 2] - bboxes[:, 0] box_height = bboxes[:, 3] - bboxes[:, 1] scaled_width = box_width / image_w scaled_height = box_height / image_h scaled_x = bboxes[:, 0] / image_w scaled_y = bboxes[:, 1] / image_h box_width = box_width[..., np.newaxis] box_height = box_height[..., np.newaxis] scaled_width = scaled_width[..., np.newaxis] scaled_height = scaled_height[..., np.newaxis] scaled_x = scaled_x[..., np.newaxis] scaled_y = scaled_y[..., np.newaxis] spatial_features = np.concatenate( (scaled_x, scaled_y, scaled_x + scaled_width, scaled_y + scaled_height, scaled_width, scaled_height), axis=1) if image_id in test_imgids: test_imgids.remove(image_id) test_indices[image_id] = test_counter test_img_bb[test_counter, :, :] = bboxes test_img_features[test_counter, :, :] = np.frombuffer( base64.decodestring(item['features']), dtype=np.float32).reshape((item['num_boxes'], -1)) test_spatial_img_features[test_counter, :, :] = spatial_features test_counter += 1 else: assert False, 'Unknown image id: %d' % image_id if len(test_imgids) != 0: print('Warning: test_image_ids is not empty') cPickle.dump(test_indices, open(test_indices_file, 'wb')) h_test.close() print("done!")
[ 37811, 198, 5569, 82, 287, 257, 256, 21370, 2393, 351, 662, 12, 35311, 4220, 510, 3241, 3033, 290, 198, 43409, 340, 287, 5572, 37, 20, 5794, 13, 220, 4418, 3650, 1391, 9060, 62, 312, 25, 3895, 62, 312, 87, 92, 198, 355, 257, 2298,...
2.076378
1,833
from . import views from django.urls import path urlpatterns = [ path('', views.profile, name='profile'), path('sign-up', views.sign_up, name='show_sign_up_form') ]
[ 6738, 764, 1330, 5009, 198, 6738, 42625, 14208, 13, 6371, 82, 1330, 3108, 628, 198, 6371, 33279, 82, 796, 685, 198, 220, 220, 220, 3108, 10786, 3256, 5009, 13, 13317, 11, 1438, 11639, 13317, 33809, 198, 220, 220, 220, 3108, 10786, 126...
2.75
64
from tkinter.font import BOLD from PIL import ImageTk from tkinter import* from PIL import Image from tkinter import messagebox from Tools.log_db import*
[ 6738, 256, 74, 3849, 13, 10331, 1330, 347, 15173, 198, 6738, 350, 4146, 1330, 7412, 51, 74, 198, 6738, 256, 74, 3849, 1330, 9, 198, 6738, 350, 4146, 1330, 7412, 198, 6738, 256, 74, 3849, 1330, 3275, 3524, 198, 6738, 20003, 13, 6404,...
2.859649
57
from functools import partial from typing import Optional, List, Tuple import numpy from numpy.typing import ArrayLike from skimage.restoration import denoise_bilateral as skimage_denoise_bilateral from aydin.it.classic_denoisers import _defaults from aydin.util.crop.rep_crop import representative_crop from aydin.util.denoise_nd.denoise_nd import extend_nd from aydin.util.j_invariance.j_invariance import calibrate_denoiser def calibrate_denoise_bilateral( image: ArrayLike, bins: int = 10000, crop_size_in_voxels: Optional[int] = _defaults.default_crop_size_normal.value, optimiser: str = _defaults.default_optimiser.value, max_num_evaluations: int = _defaults.default_max_evals_normal.value, blind_spots: Optional[List[Tuple[int]]] = _defaults.default_blind_spots.value, jinv_interpolation_mode: str = _defaults.default_jinv_interpolation_mode.value, display_images: bool = False, display_crop: bool = False, **other_fixed_parameters, ): """ Calibrates the bilateral denoiser for the given image and returns the optimal parameters obtained using the N2S loss. Note: it seems that the bilateral filter of scikit-image is broken! Parameters ---------- image: ArrayLike Image to calibrate denoiser for. bins: int Number of discrete values for Gaussian weights of color filtering. A larger value results in improved accuracy. (advanced) crop_size_in_voxels: int or None for default Number of voxels for crop used to calibrate denoiser. Increase this number by factors of two if denoising quality is unsatisfactory -- this can be important for very noisy images. Values to try are: 65000, 128000, 256000, 320000. We do not recommend values higher than 512000. optimiser: str Optimiser to use for finding the best denoising parameters. Can be: 'smart' (default), or 'fast' for a mix of SHGO followed by L-BFGS-B. (advanced) max_num_evaluations: int Maximum number of evaluations for finding the optimal parameters. Increase this number by factors of two if denoising quality is unsatisfactory. blind_spots: bool List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden) jinv_interpolation_mode: str J-invariance interpolation mode for masking. Can be: 'median' or 'gaussian'. (advanced) display_images: bool When True the denoised images encountered during optimisation are shown (advanced) (hidden) display_crop: bool Displays crop, for debugging purposes... (advanced) (hidden) other_fixed_parameters: dict Any other fixed parameters Returns ------- Denoising function, dictionary containing optimal parameters, and free memory needed in bytes for computation. """ # Convert image to float if needed: image = image.astype(dtype=numpy.float32, copy=False) # obtain representative crop, to speed things up... crop = representative_crop( image, crop_size=crop_size_in_voxels, display_crop=display_crop ) # Parameters to test when calibrating the denoising algorithm parameter_ranges = {'sigma_spatial': (0.01, 1), 'sigma_color': (0.01, 1)} # Combine fixed parameters: other_fixed_parameters = other_fixed_parameters | {'bins': bins} # Partial function: _denoise_bilateral = partial(denoise_bilateral, **other_fixed_parameters) # Calibrate denoiser best_parameters = ( calibrate_denoiser( crop, _denoise_bilateral, mode=optimiser, denoise_parameters=parameter_ranges, interpolation_mode=jinv_interpolation_mode, max_num_evaluations=max_num_evaluations, blind_spots=blind_spots, display_images=display_images, ) | other_fixed_parameters ) # Memory needed: memory_needed = 2 * image.nbytes return denoise_bilateral, best_parameters, memory_needed def denoise_bilateral( image: ArrayLike, sigma_color: Optional[float] = None, sigma_spatial: float = 1, bins: int = 10000, **kwargs, ): """ Denoises the given image using a <a href="https://en.wikipedia.org/wiki/Bilateral_filter">bilateral filter</a>. The bilateral filter is a edge-preserving smoothing filter that can be used for image denoising. Each pixel value is replaced by a weighted average of intensity values from nearby pixels. The weighting is inversely related to the pixel distance in space but also in the pixels value differences. Parameters ---------- image : ArrayLike Image to denoise sigma_color : float Standard deviation for grayvalue/color distance (radiometric similarity). A larger value results in averaging of pixels with larger radiometric differences. Note, that the image will be converted using the `img_as_float` function and thus the standard deviation is in respect to the range ``[0, 1]``. If the value is ``None`` the standard deviation of the ``image`` will be used. sigma_spatial : float Standard deviation for range distance. A larger value results in averaging of pixels with larger spatial differences. bins : int Number of discrete values for Gaussian weights of color filtering. A larger value results in improved accuracy. kwargs: dict Other parameters Returns ------- Denoised image """ # Convert image to float if needed: image = image.astype(dtype=numpy.float32, copy=False) _skimage_denoise_bilateral = extend_nd(available_dims=[2])( skimage_denoise_bilateral ) return _skimage_denoise_bilateral( image, sigma_color=sigma_color, sigma_spatial=sigma_spatial, bins=bins, mode='reflect', **kwargs, )
[ 6738, 1257, 310, 10141, 1330, 13027, 198, 6738, 19720, 1330, 32233, 11, 7343, 11, 309, 29291, 198, 198, 11748, 299, 32152, 198, 6738, 299, 32152, 13, 774, 13886, 1330, 15690, 7594, 198, 6738, 1341, 9060, 13, 2118, 6944, 1330, 2853, 2567...
2.690436
2,342
import logging import time from .exceptions import HostEntryNotValid from .check import CheckFactory from .alert import AlertFactory from .host import Host from .logging import logger
[ 11748, 18931, 198, 11748, 640, 198, 6738, 764, 1069, 11755, 1330, 14504, 30150, 3673, 47139, 198, 6738, 764, 9122, 1330, 6822, 22810, 198, 6738, 764, 44598, 1330, 23276, 22810, 198, 6738, 764, 4774, 1330, 14504, 198, 6738, 764, 6404, 2667...
4.27907
43
import logging import time from django.test import Client from django.conf import settings from django.urls import reverse from django.db import IntegrityError from django.utils import timezone from rest_framework.parsers import JSONParser from rest_framework import serializers from io import BytesIO import json from ambulance.models import Call, Patient, AmbulanceCall, CallStatus, CallPriority, \ AmbulanceUpdate, AmbulanceStatus, Waypoint, Location, LocationType, WaypointStatus, AmbulanceCallStatus from ambulance.serializers import CallSerializer, AmbulanceCallSerializer, PatientSerializer, \ AmbulanceUpdateSerializer, WaypointSerializer, LocationSerializer from emstrack.tests.util import date2iso, point2str from login.tests.setup_data import TestSetup logger = logging.getLogger(__name__)
[ 11748, 18931, 198, 11748, 640, 198, 198, 6738, 42625, 14208, 13, 9288, 1330, 20985, 198, 6738, 42625, 14208, 13, 10414, 1330, 6460, 198, 6738, 42625, 14208, 13, 6371, 82, 1330, 9575, 198, 198, 6738, 42625, 14208, 13, 9945, 1330, 39348, ...
3.642857
224
import os from bot.TextInput import TextInput from bot.prompt import color_msg
[ 11748, 28686, 201, 198, 6738, 10214, 13, 8206, 20560, 1330, 8255, 20560, 201, 198, 6738, 10214, 13, 16963, 457, 1330, 3124, 62, 19662, 201 ]
3.375
24
from methods.AbstactMethod import AbstractMethod
[ 6738, 5050, 13, 4826, 301, 529, 17410, 1330, 27741, 17410, 628 ]
4.545455
11
# imports from decouple import config import pandas as pd import praw import psycopg2 import schedule from sqlalchemy import create_engine import time # automate script to run at the same time everyday schedule.every().day.at("09:07").do(job) while True: schedule.run_pending() time.sleep(1)
[ 2, 17944, 198, 6738, 875, 43846, 1330, 4566, 198, 11748, 19798, 292, 355, 279, 67, 198, 11748, 279, 1831, 198, 11748, 17331, 22163, 70, 17, 198, 11748, 7269, 198, 6738, 44161, 282, 26599, 1330, 2251, 62, 18392, 198, 11748, 640, 628, 1...
3.134021
97
#!/bin/python #Frame processing and distance estimation for #goal #------------------------------------------------------------------------------- # IMPORTS #------------------------------------------------------------------------------- import cv2 import math import numpy import sys #------------------------------------------------------------------------------- # VARIABLES #------------------------------------------------------------------------------- def cvClr( R, G, B ): """ Color array macro """ return( numpy.array( [R,G,B], numpy.uint8 ) ) #===================================================================== # Approx. The green color range #===================================================================== MASK_LOW = cvClr( 0, 0, 245 ) MASK_HIGH = cvClr( 255, 70, 255 ) #===================================================================== # Approximate Areas for the goal (Pixels) #===================================================================== #MIN_AREA = 250 MIN_AREA = 1600 #MAX_AREA = 4000 MAX_AREA = 5000 #================================================================= # Numbers Determined from experiment apart from 0 and 20 # Straight on to Goal # width and height and area are in pixel area # THIS IS THE COUNTOUR AREA NOT THE CONVEX HULL AREA! #================================================================= goal_lkup = [ { 'dist ft' : 0, 'width' : 200, 'height' : 90, 'area' : 9000, 'ratio w_h' : 1.80 }, #0ft not tested needs to be large { 'dist ft' : 7, 'width' : 151, 'height' : 88, 'area' : 4828, 'ratio w_h' : 1.71 }, { 'dist ft' : 8, 'width' : 141, 'height' : 85, 'area' : 4700, 'ratio w_h' : 1.65 }, { 'dist ft' : 9, 'width' : 132, 'height' : 81, 'area' : 4300, 'ratio w_h' : 1.62 }, { 'dist ft' : 10, 'width' : 123, 'height' : 78, 'area' : 3860, 'ratio w_h' : 1.57 }, { 'dist ft' : 11, 'width' : 114, 'height' : 75, 'area' : 3420, 'ratio w_h' : 1.52 }, { 'dist ft' : 12, 'width' : 108, 'height' : 73, 'area' : 3120, 'ratio w_h' : 1.47 }, { 'dist ft' : 13, 'width' : 102, 'height' : 70, 'area' : 2770, 'ratio w_h' : 1.45 }, { 'dist ft' : 14, 'width' : 96 , 'height' : 68, 'area' : 2357, 'ratio w_h' : 1.41 }, { 'dist ft' : 20, 'width' : 60 , 'height' : 35, 'area' : 1000, 'ratio w_h' : 1.30 } ] #20 ft not tested needs to be small #------------------------------------------------------------------------------- # CLASSES #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # PROCEDURES #------------------------------------------------------------------------------- def find_squares( contours, debug=False ): """ Find square shaped objects """ #================================================================= # The Minimum and Maximum rations for width vs height for the goal # based on experimental results goal is approx 1.5:1 #================================================================= MIN_RATIO = 1.3 MAX_RATIO = 1.8 ret = [] for shape in contours: x, y, w, h = cv2.boundingRect( shape ) w_h_ratio = float( w ) / float( h ) if debug: print "Area", (w * h) print "Width ", w print "Height", h if MIN_RATIO < w_h_ratio and w_h_ratio < MAX_RATIO: ret.append( shape ) return( ret ) def filter_area( contours, debug=False ): """ Filter out contours based on area """ ret = [] for x in contours: area = cv2.contourArea( x ) if area > MIN_AREA and area < MAX_AREA: if debug: print "Area", area ret.append( x ) return( ret ) def find_center( contours ): """ Find the center of a contour based on moments """ ret = [] for x in contours: M = cv2.moments( x ) pt = Point() pt.x = int( M['m10']/M['m00'] ) pt.y = int( M['m01']/M['m00'] ) ret.append( pt ) return( ret ); def convex_hull_area( contours, debug= False ): """ Find the Area of convex Hulls """ ret_areas = [] ret_hulls = [] for c in contours: hull = cv2.convexHull( c ) area = cv2.contourArea( hull ) ret_areas.append( area ) ret_hulls.append( hull ) if( debug ): print( "Hull area: {0}".format( area ) ) return ( ret_areas, ret_hulls ) def angle_from_point( x, img_width=640, fov_angle=44 ): """ Calculate the angle from a point """ return( -( ( img_width / 2 ) - x ) * fov_angle ) def lin_scale( val, x1, y1, x2, y2 ): """ Linearly scale Val to y1 and y2 from x1 and x2 range x1 and y1 are low values """ x_range = (x2 - x1) new_val = 0 if x_range is 0: new_val = y1 else: y_range = ( y2 - y1 ) new_val = ( ( ( val - x1 ) * y_range ) / x_range ) + y1 return new_val def dist_from_goal( area ): """ Calculates the distance to the Goal based on area, x, y Args: area: the area in pixels of the target Returns: Feet from goal """ dist = 99 prev = goal_lkup[ 0 ] for cur in goal_lkup: #============================================================= # If the area is less than the currently selected area, but # greater then the previous area, then the distance is some # where in between. Then do linear interpolation #============================================================= if area > cur[ 'area' ] and area < prev[ 'area' ]: dist = lin_scale( area, cur[ 'area' ], cur[ 'dist ft' ], prev[ 'area' ], prev[ 'dist ft' ] ) return dist prev = cur return dist def proc_frame( frame, debug=False ): """ Process a frame """ #================================================================= # Convert to HSV so we can mask more easily #================================================================= hsv_frame = cv2.cvtColor( frame, cv2.COLOR_BGR2HSV ) #================================================================= # Apply the color mask defined at the top of file #================================================================= if( debug ): hlo = cv2.getTrackbarPos( "H low", "Mask" ) hhi = cv2.getTrackbarPos( "H hi", "Mask" ) slo = cv2.getTrackbarPos( "S low", "Mask" ) shi = cv2.getTrackbarPos( "S hi", "Mask" ) vlo = cv2.getTrackbarPos( "V low", "Mask" ) vhi = cv2.getTrackbarPos( "V hi", "Mask" ) lo = numpy.array( [ hlo, slo, vlo ], numpy.uint8 ) hi = numpy.array( [ hhi, shi, vhi ], numpy.uint8 ) color_mask = cv2.inRange( hsv_frame, lo, hi ) else: color_mask = cv2.inRange( hsv_frame, MASK_LOW, MASK_HIGH ) #================================================================= # Apply our color mask #================================================================= masked_frame = cv2.bitwise_and( hsv_frame, hsv_frame, mask = color_mask ) #================================================================= # Contours stuff # First convert to Gray and find the contours #================================================================= bw_frame = cv2.cvtColor( masked_frame, cv2.COLOR_BGR2GRAY ) contours, hierarchy = cv2.findContours( bw_frame, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE ) #================================================================= # Filter the contours based on area, convex hull area etc... #================================================================= draw = filter_area( contours ) hull_areas, hulls = convex_hull_area( draw ) squares = find_squares( hulls ) centers = find_center( squares ) #================================================================= # If debug mode, show the result of the line finding in a GUI #================================================================= if( debug ): #contours cv2.drawContours( frame, draw, -1, ( 0, 255, 0 ), 3 ) cv2.drawContours( frame, squares, -1, ( 255, 255, 0 ), 3 ) for i in centers: cv2.circle( frame, ( i.x, i.y ), 3, ( 0, 255, 255 ), ) #print "X = {0} Y = {1}".format( i.x, i.y ) cv2.imshow( "Goal", frame ) #cv2.imshow( "Mask", masked_frame ) return dist_from_goal( squares ), angle_from_point( centers[0].x, len( frame[0] ) )
[ 2, 48443, 8800, 14, 29412, 201, 198, 2, 19778, 7587, 290, 5253, 31850, 329, 201, 198, 2, 35231, 201, 198, 201, 198, 2, 10097, 24305, 201, 198, 2, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 22...
2.521836
3,595
i=1 while i<=4: j=16 while j>=i: print(i,end="") j=j-1 print() i=i+1
[ 72, 28, 16, 198, 4514, 1312, 27, 28, 19, 25, 198, 220, 220, 220, 474, 28, 1433, 198, 220, 220, 220, 981, 474, 29, 28, 72, 25, 198, 220, 220, 220, 220, 220, 220, 220, 3601, 7, 72, 11, 437, 2625, 4943, 198, 220, 220, 220, 220,...
1.428571
70
import logging import weakref from threading import Event from threading import Thread try: from Queue import Queue except ImportError: from queue import Queue try: import gevent from gevent import Greenlet as GThread from gevent.event import Event as GEvent from gevent.queue import Queue as GQueue except ImportError: GThread = GQueue = GEvent = None from playhouse.sqlite_ext import SqliteExtDatabase logger = logging.getLogger('peewee.sqliteq') def fetchall(self): return list(self) # Iterating implies waiting until populated. def fetchone(self): self._wait() try: return next(self) except StopIteration: return None THREADLOCAL_ERROR_MESSAGE = ('threadlocals cannot be set to True when using ' 'the Sqlite thread / queue database. All queries ' 'are serialized through a single connection, so ' 'allowing multiple threads to connect defeats ' 'the purpose of this database.') WAL_MODE_ERROR_MESSAGE = ('SQLite must be configured to use the WAL journal ' 'mode when using this feature. WAL mode allows ' 'one or more readers to continue reading while ' 'another connection writes to the database.')
[ 11748, 18931, 198, 11748, 4939, 5420, 198, 6738, 4704, 278, 1330, 8558, 198, 6738, 4704, 278, 1330, 14122, 198, 28311, 25, 198, 220, 220, 220, 422, 4670, 518, 1330, 4670, 518, 198, 16341, 17267, 12331, 25, 198, 220, 220, 220, 422, 168...
2.416523
581
#!/usr/bin/python3 from Common.Straw import Straw import pymongo from pymongo import MongoClient from bson.objectid import ObjectId import os if __name__ == "__main__": db()
[ 2, 48443, 14629, 14, 8800, 14, 29412, 18, 198, 6738, 8070, 13, 1273, 1831, 1330, 27279, 198, 11748, 279, 4948, 25162, 198, 6738, 279, 4948, 25162, 1330, 42591, 11792, 198, 6738, 275, 1559, 13, 15252, 312, 1330, 9515, 7390, 198, 11748, ...
2.95082
61
from django.template import Context from django.template import Template from .test_base import LDAPGroupAuthTestBase from django.contrib.auth.models import AnonymousUser
[ 6738, 42625, 14208, 13, 28243, 1330, 30532, 198, 6738, 42625, 14208, 13, 28243, 1330, 37350, 198, 6738, 764, 9288, 62, 8692, 1330, 27178, 2969, 13247, 30515, 14402, 14881, 198, 6738, 42625, 14208, 13, 3642, 822, 13, 18439, 13, 27530, 1330...
4
43
# Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch import torch.nn as nn from torch.nn import functional as F # In EGG, the game designer must implement the core functionality of the Sender and Receiver agents. These are then # embedded in wrappers that are used to train them to play Gumbel-Softmax- or Reinforce-optimized games. The core # Sender must take the input and produce a hidden representation that is then used by the wrapper to initialize # the RNN or other module that will generate the message. The core Receiver expects a hidden representation # generated by the message-processing wrapper, plus possibly other game-specific input, and it must generate the # game-specific output. # The RecoReceiver class implements the core Receiver agent for the reconstruction game. This is simply a linear layer # that takes as input the vector generated by the message-decoding RNN in the wrapper (x in the forward method) and # produces an output of n_features dimensionality, to be interpreted as a one-hot representation of the reconstructed # attribute-value vector # The Sender class implements the core Sender agent common to both games: it gets the input target vector and produces a hidden layer # that will initialize the message producing RNN
[ 2, 15069, 357, 66, 8, 3203, 11, 3457, 13, 290, 663, 29116, 13, 198, 198, 2, 770, 2723, 2438, 318, 11971, 739, 262, 17168, 5964, 1043, 287, 262, 198, 2, 38559, 24290, 2393, 287, 262, 6808, 8619, 286, 428, 2723, 5509, 13, 198, 198, ...
4.444444
315
import os import shutil import random if __name__ == '__main__': main()
[ 11748, 28686, 198, 11748, 4423, 346, 198, 11748, 4738, 628, 628, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 198, 220, 220, 220, 1388, 3419, 628 ]
2.793103
29
# generated bbox ground truth from pixel-wise segmentation # it currently only generate one bbox from __future__ import print_function import numpy as np import h5py import os import pdb mask_path = '../data/acce' f = h5py.File(os.path.join(mask_path, "resized_label_ac_2d.h5"), 'r') bbox_path = '../data/acce/bbox' if not os.path.exists(bbox_path): os.mkdir(bbox_path) # dim: shape (256, 367, 342), slices, height, width count = 0 for k in f.keys(): #pdb.set_trace() count += 1 print("processing {}-th vol".format(count)) data = f[k][...] # convert to numpy k = k.rsplit('_',1)[0] # strip the '_label' from the vol name with open( os.path.join(bbox_path, k)+'_bbox.txt', 'w') as bbox_file: # iterate through each slice for idx in range(data.shape[0]): mask = data[idx, :, :] # get the mask i,j = np.where(mask) # find positive mask if not i.size: # no positive mask print("{}_{},{}".format(k, idx, 0), file=bbox_file) else: h_min,w_min = np.min(zip(i,j), axis=0) h_max,w_max = np.max(zip(i,j), axis=0) print("{}_{},{},{},{},{},{}".format(k, idx, 1, w_min, h_min, w_max, h_max), file=bbox_file) f.close()
[ 2, 7560, 275, 3524, 2323, 3872, 422, 17465, 12, 3083, 10618, 341, 198, 2, 340, 3058, 691, 7716, 530, 275, 3524, 198, 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 289, 20, 9078, 198, ...
2.065916
622
# some codes refer to Holoclean evaluation function # https://github.com/HoloClean/holoclean import pandas as pd import numpy as np import logging import random import argparse parser = argparse.ArgumentParser(description='Predict on many examples') parser.add_argument("--dataset", type=str, help="dataset path") parser.add_argument("--ground_truth", type=str, help="ground truth path") parser.add_argument("--ground_truth_2", type=str, help="ground truth path") args = parser.parse_args() NULL_REPR = '_nan_' exclude_attr = ['_tid_', 'FName', 'LName'] if __name__ == "__main__": # load dataset adv = DataCleaningAsAdv(args.dataset) f = open("baseline_cleaning_report_1", "a") print(args.dataset, file=f) # evaluate adv.evaluate(gt_fpath=args.ground_truth, tid_col='tid', attr_col='attribute', val_col='correct_val', file=f) if args.ground_truth_2 is not None: adv.evaluate(gt_fpath=args.ground_truth_2, tid_col='tid', attr_col='attribute', val_col='correct_val', file=f)
[ 2, 617, 12416, 3522, 284, 6479, 420, 13087, 12660, 2163, 198, 2, 3740, 1378, 12567, 13, 785, 14, 39, 14057, 32657, 14, 3937, 420, 13087, 198, 198, 11748, 19798, 292, 355, 279, 67, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 18931,...
2.446429
448
import numpy as arr n,m=map(int,input().split()) ar=([list(map(int,input().split()))for _ in range(n)]) arr1=arr.min(ar,axis=1) print(max(arr1))
[ 11748, 299, 32152, 355, 5240, 198, 77, 11, 76, 28, 8899, 7, 600, 11, 15414, 22446, 35312, 28955, 198, 283, 16193, 58, 4868, 7, 8899, 7, 600, 11, 15414, 22446, 35312, 3419, 4008, 1640, 4808, 287, 2837, 7, 77, 8, 12962, 198, 3258, 1...
2.265625
64