query
stringlengths
9
3.4k
document
stringlengths
9
87.4k
metadata
dict
negatives
listlengths
4
101
negative_scores
listlengths
4
101
document_score
stringlengths
3
10
document_rank
stringclasses
102 values
Print the data in slice iz, row ix of an image to standard out.
def print_image_col(input, ix=0, iz=0): image=get_image(input) nx = image.get_xsize() ny = image.get_ysize() nz = image.get_zsize() print "(z = %d slice, x = %d row)" % (iz, ix) line = [] for iy in xrange(ny): line.append("%12.5g " % (image.get_value_at(ix,iy,iz))) if ((iy + 1) % 5 == 0): line.append("\n ") line.append("\n") print "".join(line)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def print_row(input, ix=0, iz=0):\n\timage=get_image(input)\n\tnx = image.get_xsize()\n\tny = image.get_ysize()\n\tnz = image.get_zsize()\n\tprint \"(z = %d slice, x = %d row)\" % (iz, ix)\n\tline = []\n\tfor iy in xrange(ny):\n\t\tline.append(\"%12.5g \" % (image.get_value_at(ix,iy,iz)))\n\t\tif ((iy + 1) % 5 ==...
[ "0.76172984", "0.75990057", "0.7544907", "0.74450433", "0.73937047", "0.7347187", "0.7033798", "0.68403655", "0.6811467", "0.66571254", "0.6630757", "0.6279358", "0.6275334", "0.61232245", "0.60401046", "0.5973948", "0.5973784", "0.5965042", "0.59583265", "0.59162855", "0.589...
0.7349031
5
Print the data in slice iz, column iy of an image to standard out.
def print_image_row(input, iy=0, iz=0): image=get_image(input) nx = image.get_xsize() ny = image.get_ysize() nz = image.get_zsize() print "(z = %d slice, y = %d col)" % (iz, iy) line = [] for ix in xrange(nx): line.append("%12.5g " % (image.get_value_at(ix,iy,iz))) if ((ix + 1) % 5 == 0): line.append("\n ") line.append("\n") print "".join(line)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def print_image_col(input, ix=0, iz=0):\n\timage=get_image(input)\n\tnx = image.get_xsize()\n\tny = image.get_ysize()\n\tnz = image.get_zsize()\n\tprint \"(z = %d slice, x = %d row)\" % (iz, ix)\n\tline = []\n\tfor iy in xrange(ny):\n\t\tline.append(\"%12.5g \" % (image.get_value_at(ix,iy,iz)))\n\t\tif ((iy + 1) ...
[ "0.77487314", "0.75519806", "0.750461", "0.73919225", "0.7150529", "0.7141496", "0.7027633", "0.6667874", "0.66633767", "0.6654244", "0.6348636", "0.621092", "0.6179944", "0.60063565", "0.59464717", "0.59386533", "0.5911687", "0.58938134", "0.5851181", "0.58338124", "0.580308...
0.7496404
3
Print the data in slice iz of an image to standard out in a format that agrees with v2
def print_image_slice(input, iz=0): image=get_image(input) nx = image.get_xsize() ny = image.get_ysize() nz = image.get_zsize() print "(z = %d slice)" % (iz) line = [] for iy in xrange(ny-1,-1,-1): line.append("Row ") line.append("%4i " % iy) for ix in xrange(nx): line.append("%12.5g " % (image.get_value_at(ix,iy,iz))) if ((ix + 1) % 5 == 0): line.append("\n ") line.append(" ") line.append("\n") if(nx%5 != 0): line.append("\n") print "".join(line)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def print_image(input):\n\timage=get_image(input)\n\tnz = image.get_zsize()\n\tfor iz in xrange(nz): print_slice(input, iz)", "def print_slice(input, iz=0):\n\timage=get_image(input)\n\tnx = image.get_xsize()\n\tny = image.get_ysize()\n\tnz = image.get_zsize()\n\tprint \"(z = %d slice)\" % (iz)\n\tline = []\n\tf...
[ "0.7314874", "0.72975045", "0.7103524", "0.7012286", "0.6931774", "0.67332554", "0.6709795", "0.6601998", "0.6534724", "0.6502416", "0.6426161", "0.6281741", "0.6222216", "0.6221346", "0.6040175", "0.60378903", "0.59890413", "0.594744", "0.5930997", "0.5928868", "0.5903941", ...
0.7488905
0
Print the data in slice iz of an image to standard out in a format that agrees with v2
def print_image_slice_3d(input, num=0,direction="z"): #print "print slice at 3 directions" image=get_image(input) nx = image.get_xsize() ny = image.get_ysize() nz = image.get_zsize() if(direction=="x"): #print "xxxxx" ix=num print "(x = %d slice)" % (ix) line = [] for iz in xrange(nz-1,-1,-1): line.append("Z ") line.append("%4i " % iz) for iy in xrange(ny): line.append("%12.5g " % (image.get_value_at(ix,iy,iz))) if ((iy + 1) % 5 == 0): line.append("\n ") line.append(" ") line.append("\n") if(ny%5 != 0): line.append("\n") print "".join(line) elif(direction=="y"): #print "yyy" iy=num print "(y = %d slice)" % (iy) line = [] for iz in xrange(nz-1,-1,-1): line.append("Z ") line.append("%4i " % iz) for ix in xrange(nx): line.append("%12.5g " % (image.get_value_at(ix,iy,iz))) if ((ix + 1) % 5 == 0): line.append("\n ") line.append(" ") line.append("\n") if(nx%5 != 0): line.append("\n") print "".join(line) else: #print "zzzz" iz=num print "(z = %d slice)" % (iz) line = [] for iy in xrange(ny-1,-1,-1): line.append("Row ") line.append("%4i " % iy) for ix in xrange(nx): line.append("%12.5g " % (image.get_value_at(ix,iy,iz))) if ((ix + 1) % 5 == 0): line.append("\n ") line.append(" ") line.append("\n") if(nx%5 != 0): line.append("\n") print "".join(line)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def print_image_slice(input, iz=0):\n\timage=get_image(input)\n\tnx = image.get_xsize()\n\tny = image.get_ysize()\n\tnz = image.get_zsize()\n\tprint \"(z = %d slice)\" % (iz)\n\tline = []\n\tfor iy in xrange(ny-1,-1,-1):\n\t\tline.append(\"Row \")\n\t\tline.append(\"%4i \" % iy)\n\t\tfor ix in xrange(nx):\n\t\t\tl...
[ "0.7489223", "0.7313441", "0.72980666", "0.7102297", "0.70125145", "0.6931557", "0.6733379", "0.67101216", "0.6534789", "0.65026045", "0.6426267", "0.62820506", "0.6222731", "0.6221045", "0.6040338", "0.6038878", "0.59879136", "0.594753", "0.593031", "0.59290165", "0.5902861"...
0.6602657
8
Read a columnlisted txt file.
def read_text_row(fnam, format="", skip=";"): from string import split inf = file(fnam, "r") strg = inf.readline() x = [] data = [] while (len(strg) > 0): com_line = False for j in xrange(len(strg)): if(strg[j] == skip): com_line = True if com_line == False: word=split(strg) if format == "s" : key = int(word[1]) if key != len(word) - 2: del word word = [] word.append(strg[0 : 5]) word.append(strg[6 : 7]) for k in xrange(key): k_start = 7 + k*13 k_stop = k_start + 13 word.append(strg[k_start : k_stop]) line=[] for i in xrange(len(word)): line.append(float(word[i])) data.append(line) strg=inf.readline() inf.close return data
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def read_text_file(file_name, ncol = 0):\n\t\n\tfrom string import split\n\tinf = file(file_name, \"r\")\n\tline = inf.readline()\n\tdata = []\n\twhile len(line) > 0:\n\t\tif ncol == -1:\n\t\t\tvdata = split(line)\n\t\t\tif data == []:\n\t\t\t\tfor i in xrange(len(vdata)):\n\t\t\t\t\tdata.append([float(vdata[i])])...
[ "0.7060434", "0.6964561", "0.69441533", "0.67769", "0.6769207", "0.67402285", "0.6630263", "0.6448201", "0.6428578", "0.6414579", "0.628006", "0.6256943", "0.61892265", "0.6181183", "0.6084818", "0.6000709", "0.59918183", "0.5988072", "0.59837323", "0.5958952", "0.59168094", ...
0.0
-1
Write to an ASCII file a list of lists containing floats.
def write_text_row(data, file_name): import types outf = open(file_name, "w") if (type(data[0]) == types.ListType): # It is a list of lists for i in xrange(len(data)): for j in xrange(len(data[i])): outf.write(" %12.5g"%data[i][j]) outf.write("\n") else: # Single list for j in xrange(len(data)): outf.write(" %12.5g"%data[j]) outf.write(" \n") outf.close()
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def writeFloatListToFile(ldata, prec, filePath):\n\twith open(filePath, \"w\") as fh:\n\t\tfor d in ldata:\n\t\t\tfh.write(formatFloat(prec, d) + \"\\n\")", "def write_float32_list(self, float_list: List[float]) -> None:\n self.write_int32(len(float_list))\n for f in float_list:\n self.w...
[ "0.7385591", "0.6873358", "0.6700241", "0.6473418", "0.6448024", "0.64338905", "0.6403743", "0.62480605", "0.6234932", "0.6223964", "0.61342627", "0.61157817", "0.60960627", "0.6086933", "0.607191", "0.59942085", "0.5985232", "0.5915316", "0.59132415", "0.5909576", "0.5845459...
0.5709758
30
Read data from text file, if ncol = 1, read all columns if ncol >= 0, just read the (ncol+1)th column.
def read_text_file(file_name, ncol = 0): from string import split inf = file(file_name, "r") line = inf.readline() data = [] while len(line) > 0: if ncol == -1: vdata = split(line) if data == []: for i in xrange(len(vdata)): data.append([float(vdata[i])]) else: for i in xrange(len(vdata)): data[i].append(float(vdata[i])) else: vdata = float(split(line)[ncol]) data.append(vdata) line = inf.readline() return data
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def readOFColumnData(dataFile,nCol):\n fileCheck(dataFile) # does the file exists ? Stop if not.\n #\n # Init list\n data = []\n #\n for line in fileinput.input(dataFile):\n # remove parenthesis if any\n line = line.replace('(', '')\n line = line.replace(')', '') \n ...
[ "0.69048285", "0.6310644", "0.6242134", "0.61760336", "0.6040689", "0.60290545", "0.6026688", "0.60042155", "0.587215", "0.58236593", "0.5762683", "0.5731496", "0.5718888", "0.5706086", "0.5696076", "0.5676739", "0.56515324", "0.56390595", "0.56192374", "0.55811644", "0.55722...
0.73864484
0
Write to an ASCII file a list of lists containing floats.
def write_text_file(data, file_name): import types outf = open(file_name, "w") if (type(data[0]) == types.ListType): # It is a list of lists for i in xrange(len(data[0])): for j in xrange(len(data)): if type(data[j][i]) == type(0): outf.write(" %12d"%data[j][i]) else: outf.write(" %12.5g"%data[j][i]) outf.write("\n") else: # Single list for j in xrange(len(data)): if type(data[j]) == type(0): outf.write(" %12d\n"%data[j]) else: outf.write(" %12.5g\n"%data[j]) outf.close()
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def writeFloatListToFile(ldata, prec, filePath):\n\twith open(filePath, \"w\") as fh:\n\t\tfor d in ldata:\n\t\t\tfh.write(formatFloat(prec, d) + \"\\n\")", "def write_float32_list(self, float_list: List[float]) -> None:\n self.write_int32(len(float_list))\n for f in float_list:\n self.w...
[ "0.73861384", "0.6875439", "0.6696524", "0.64751726", "0.64447385", "0.64314556", "0.62464565", "0.62336665", "0.62258744", "0.6136174", "0.61130786", "0.60936034", "0.6083807", "0.6069135", "0.5993641", "0.59823793", "0.59138167", "0.5911231", "0.59085566", "0.584276", "0.58...
0.6402331
6
Rotate about a different center
def rotate_about_center(alpha, cx, cy): cmp1 = compose_transform2(0, -cx, -cy, 1, alpha, 0, 0, 1) cmp2 = compose_transform2(cmp1[0], cmp1[1], cmp1[2], cmp1[3], 0, cx, cy, 1) # return compalpha, comptrans.at(0),comptrans.at(1), compscale return cmp2[0], cmp2[1], cmp2[2], cmp2[3]
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def rotation_center(self, *args, **kwargs) -> Any:\n pass", "def rotate(self,center, angle):\n \n self.coord = [x-np.repeat([[center[0],center[1]]],[x.shape[0]],axis = 0) for x in self.coord]\n\n alpha = angle\n R = np.array([[np.cos(alpha),-np.sin(alpha)],[np.sin(alpha),np.cos...
[ "0.75949824", "0.74933934", "0.7462114", "0.74131936", "0.738581", "0.7327082", "0.7053461", "0.70344794", "0.69995296", "0.69260097", "0.69119567", "0.69119567", "0.68725055", "0.676936", "0.67615163", "0.6755245", "0.6707772", "0.6677421", "0.6677066", "0.667549", "0.667108...
0.6676087
19
linearly interpolate a 1D power spectrum to required length with required Pixel size input_object a 1D list with a 1D curve to be interpolated length_current half size of the image size (in case of power spectrum, it can be different from the length of the input_object) length_interpolated length of the interpolated 1D curve Pixel_size_current pixel size of the input 1D list Pixel_size_interpolated pixel size of the target 1D list One can either input the two lengths or two respective pixel sizes
def reshape_1d(input_object, length_current=0, length_interpolated=0, Pixel_size_current = 0., Pixel_size_interpolated = 0.): interpolated = [] if length_current == 0: length_current = len(input_object) lt = len(input_object) - 2 if length_interpolated == 0: if( Pixel_size_interpolated != Pixel_size_current): length_interpolated = int(length_current*Pixel_size_current/Pixel_size_interpolated + 0.5) else: ERROR("Incorrect input parameters","reshape_1d",1) return [] if Pixel_size_current == 0.: Pixel_size_current = 1. Pixel_size_interpolated = Pixel_size_current*float(length_current)/float(length_interpolated) qt =Pixel_size_interpolated/Pixel_size_current for i in xrange(length_interpolated): xi = float(i)*qt ix = min(int(xi),lt) df = xi -ix xval = (1.0-df)*input_object[ix] + df*input_object[ix+1] interpolated.append(xval) return interpolated
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def interpolate(signal, new_length):\n assert len(signal) > 1 and len(signal[0]) > 1\n current_length = len(signal)\n signal = np.array(signal).T\n new_signal = []\n x_array = get_x_array(current_length, new_length)\n\n for l in range(len(signal)):\n fp = signal[l]\n xp = list(range...
[ "0.59042335", "0.5510684", "0.5495997", "0.543274", "0.54308456", "0.5368978", "0.53469396", "0.5295205", "0.5252446", "0.5242712", "0.51369417", "0.5123754", "0.5104273", "0.5101531", "0.5047771", "0.50370836", "0.5025036", "0.50159943", "0.49947384", "0.49876678", "0.497830...
0.6795765
0
Calculate 1D rotationally averaged power spectra from image stack listed in a directory
def rops_dir(indir, output_dir = "1dpw2_dir"): from EMAN2 import periodogram import os flist = os.listdir(indir) print flist if os.path.exists(output_dir) is False: os.mkdir(output_dir) for i, v in enumerate(flist): (filename, filextension) = os.path.splitext(v) nima = EMUtil.get_image_count(os.path.join(indir,v)) print nima for im in xrange(nima): e = EMData() file_name = os.path.join(indir,v) e.read_image(file_name, im) tmp1 = periodogram(e) tmp = tmp1.rotavg() if im == 0: sum_ima = model_blank(tmp.get_xsize()) sum_ima += tmp else : sum_ima += tmp table = [] nr = sum_ima.get_xsize() for ir in xrange(nr): table.append([sum_ima.get_value_at(ir)]) drop_spider_doc(os.path.join(output_dir, "1dpw2_"+filename+".txt"), table)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def spectra_stacker(file_name):\n file_data = read_file(file_name)\n image_data = file_data[1]\n\n data_shape = np.shape(image_data)\n ra_axis = data_shape[2]\n dec_axis = data_shape[1]\n wl_axis = data_shape[0]\n\n pxl_total = ra_axis * dec_axis\n \n data_unwrap = [] \n...
[ "0.61825204", "0.5834751", "0.5748448", "0.5740321", "0.5725463", "0.57223636", "0.56904304", "0.5681795", "0.5607029", "0.5605107", "0.55935085", "0.55795133", "0.5555331", "0.55550176", "0.5546603", "0.55278903", "0.5524576", "0.546944", "0.54588705", "0.54191047", "0.54079...
0.0
-1
Gather the a list of EMData on all nodes to the main node, we assume the list has the same length on each node.
def gather_EMData(data, number_of_proc, myid, main_node): from mpi import MPI_COMM_WORLD, MPI_INT, MPI_TAG_UB from mpi import mpi_send, mpi_recv l = len(data) gathered_data = [] inc = 1 # A temp measure if myid == main_node: for i in xrange(0, number_of_proc*inc, inc): if i == main_node: for k in xrange(l): gathered_data.append(data[k]) else: for k in xrange(l): im = recv_EMData(i, i*l+k) mem_len = mpi_recv(1, MPI_INT, i, MPI_TAG_UB, MPI_COMM_WORLD) members = mpi_recv(int(mem_len[0]), MPI_INT, i, MPI_TAG_UB, MPI_COMM_WORLD) members = map(int, members) im.set_attr('members', members) gathered_data.append(im) else: for k in xrange(l): send_EMData(data[k], main_node, myid*l+k) mem = data[k].get_attr('members') mpi_send(len(mem), 1, MPI_INT, main_node, MPI_TAG_UB, MPI_COMM_WORLD) mpi_send(mem, len(mem), MPI_INT, main_node, MPI_TAG_UB, MPI_COMM_WORLD) return gathered_data
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def gather(self, node):\n\n return []", "def _data_parallel_master(self, intermediates):\n\n # Always using same \"device order\" makes the ReduceAdd operation faster.\n # Thanks to:: Tete Xiao (http://tetexiao.com/)\n intermediates = sorted(intermediates, key=lambda i: i[1].sum.get_d...
[ "0.6460555", "0.5887683", "0.56105876", "0.56016797", "0.5551757", "0.5506774", "0.5503824", "0.5480824", "0.54083604", "0.5394268", "0.5391553", "0.53643715", "0.5339283", "0.5328205", "0.5325319", "0.5300631", "0.52970463", "0.52842844", "0.52776074", "0.526741", "0.5261743...
0.67186177
0
number_to_send has to be predefined in each node
def bcast_number_to_all(number_to_send, source_node = 0): from mpi import mpi_bcast, MPI_INT, MPI_COMM_WORLD, MPI_FLOAT import types if type(number_to_send) is types.IntType: TMP = mpi_bcast(number_to_send, 1, MPI_INT, source_node, MPI_COMM_WORLD) return int(TMP[0]) elif type(number_to_send) is types.FloatType: TMP = mpi_bcast(number_to_send, 1, MPI_FLOAT, source_node, MPI_COMM_WORLD) return float(TMP[0]) else: print " ERROR in bcast_number_to_all"
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def sendnum(self, n):\n self.sendline(str(n))", "def send(self, x):\n print x", "def send(value):\r\n return value", "def numeric(self, source, numeric, target, *args):\n\n if numeric == ERR_NICKNAMEINUSE:\n self.fire(NICK(\"{0:s}_{1:d}\".format(args[0], randint(0, 32768))))\...
[ "0.6436164", "0.5802865", "0.55402374", "0.5511573", "0.5425965", "0.5417966", "0.5417966", "0.5406537", "0.5385631", "0.5377031", "0.5364401", "0.5363881", "0.53416944", "0.53416944", "0.53416944", "0.53416944", "0.53416944", "0.53416944", "0.5333438", "0.5325405", "0.532461...
0.53139603
21
write headers from files in data into a disk file called filename. The filename has to be either hdf or bdb. lima list with positions in the disk files into which headers will be written, i.e., header from data[k] will be written into file number lima[k]
def write_headers(filename, data, lima): from utilities import file_type from EMAN2db import db_open_dict ftp = file_type(filename) if ftp == "bdb": # For unknown reasons this does not work on Linux, but works on Mac ??? Really? DB = db_open_dict(filename) for i in range(len(lima)): DB.set_header(lima[i], data[i]) DB.close() #for i in range(len(lima)): # data[i].write_image(filename, lima[i]) elif ftp == "hdf": for i in range(len(lima)): data[i].write_image(filename, lima[i], EMUtil.ImageType.IMAGE_HDF, True) else: ERROR("Unacceptable file format","write_headers",1)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def write_header(filename, data, lima):\n\tfrom utilities import file_type\n\tfrom EMAN2db import db_open_dict\n\n\tftp = file_type(filename)\n\tif ftp == \"bdb\":\n\t\tDB = db_open_dict(filename)\n\t\tDB.set_header(lima, data)\n\telif ftp == \"hdf\":\n\t\tdata.write_image(filename, lima, EMUtil.ImageType.IMAGE_HD...
[ "0.81443864", "0.65365857", "0.6521095", "0.642603", "0.6422746", "0.6345552", "0.63141286", "0.622469", "0.6156558", "0.6150772", "0.6104141", "0.60294604", "0.5993755", "0.5916143", "0.58797914", "0.58024967", "0.57776046", "0.57631105", "0.5731549", "0.57286596", "0.571765...
0.8396805
0
write header from a single file data into a disk file called filename. The filename has to be either hdf or bdb. lima position in the disk files into which header will be written, i.e., header from data will be written into file number lima
def write_header(filename, data, lima): from utilities import file_type from EMAN2db import db_open_dict ftp = file_type(filename) if ftp == "bdb": DB = db_open_dict(filename) DB.set_header(lima, data) elif ftp == "hdf": data.write_image(filename, lima, EMUtil.ImageType.IMAGE_HDF, True) else: ERROR("Unacceptable file format","write_headers",1)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def write_headers(filename, data, lima):\n\tfrom utilities import file_type\n\tfrom EMAN2db import db_open_dict\n\n\tftp = file_type(filename)\n\tif ftp == \"bdb\":\n\t\t# For unknown reasons this does not work on Linux, but works on Mac ??? Really?\n\t\tDB = db_open_dict(filename)\n\t\tfor i in range(len(lima)):...
[ "0.7826132", "0.70860624", "0.6762291", "0.6738056", "0.67234135", "0.67085034", "0.66346943", "0.6610399", "0.6607992", "0.6557405", "0.6481333", "0.6448737", "0.64438635", "0.6427536", "0.64213383", "0.6419421", "0.6363067", "0.63381046", "0.631573", "0.63024944", "0.629878...
0.8375335
0
retrieve 2D alignment parameters from the header alpha tx ty mirror scale
def get_params2D(ima, xform = "xform.align2d"): t = ima.get_attr(xform) d = t.get_params("2D") return d["alpha"],d["tx"],d["ty"],d["mirror"],d["scale"]
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def get_alignment_params(self, s, w):\n\n\n X1 = s.__get_X(w)\n X2 = self.__get_X(w)\n Y1 = s.__get_Y(w)\n Y2 = self.__get_Y(w)\n Z = self.__get_Z(w)\n W = sum(w)\n C1 = self.__get_C1(w, s)\n C2 = self.__get_C2(w, s)\n\n a = np.array([[ X2, -Y2, W, ...
[ "0.6123718", "0.6082262", "0.5826465", "0.56437796", "0.5509969", "0.5504308", "0.5343178", "0.5336521", "0.5331882", "0.5322334", "0.5322334", "0.5299092", "0.524463", "0.524463", "0.524463", "0.5240063", "0.51976395", "0.5196707", "0.5196707", "0.5196707", "0.5195092", "0...
0.5867003
2
set 2D alignment parameters in the header alpha tx ty mirror scale
def set_params2D(ima, p, xform = "xform.align2d"): t = Transform({"type":"2D","alpha":p[0],"tx":p[1],"ty":p[2],"mirror":p[3],"scale":p[4]}) ima.set_attr(xform, t)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def align(self):\n ...", "def parameters_ui(layout, params):\n\n r = layout.row()\n r.prop(params, \"rotation_axis\")\n\n if 'auto' not in params.rotation_axis.lower():\n r = layout.row()\n text = \"Auto align Foot\"\n r.prop(params, \"auto_align_extremity\", text=text)\n\n ...
[ "0.5652911", "0.5642781", "0.5243032", "0.51255065", "0.5104375", "0.5091596", "0.5088672", "0.5071364", "0.50606203", "0.5045389", "0.5044001", "0.50383675", "0.50192225", "0.5016494", "0.5012836", "0.50028354", "0.49517918", "0.49404538", "0.4933246", "0.49027255", "0.48972...
0.55857396
2
retrieve 3D alignment parameters from the header phi theta psi tx ty tz mirror scale
def get_params3D(ima, xform = "xform.align3d"): t = ima.get_attr(xform) d = t.get_params("spider") return d["phi"],d["theta"],d["psi"],d["tx"],d["ty"],d["tz"],d["mirror"],d["scale"]
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def params_3D_2D(phi, theta, psi, s2x, s2y):\n\tif theta > 90.0:\n\t\tmirror = 1\n\t\talpha, sx, sy, scalen = compose_transform2(0, s2x, s2y, 1.0, 540.0-psi, 0, 0, 1.0)\n\telse:\n\t\tmirror = 0\n\t\talpha, sx, sy, scalen = compose_transform2(0, s2x, s2y, 1.0, 360.0-psi, 0, 0, 1.0)\n\treturn alpha, sx, sy, mirror"...
[ "0.6369768", "0.63076174", "0.57975394", "0.5729281", "0.5533436", "0.551851", "0.5500369", "0.5439547", "0.5422399", "0.54033196", "0.5388639", "0.5361121", "0.53491545", "0.53419423", "0.531873", "0.53108954", "0.53095436", "0.53085315", "0.5303664", "0.5303664", "0.5302264...
0.7157893
0
set 3D alignment parameters in the header phi theta psi tx ty tz mirror scale
def set_params3D(ima, p, xform = "xform.align3d"): t = Transform({"type":"spider","phi":p[0],"theta":p[1],"psi":p[2],"tx":p[3],"ty":p[4],"tz":p[5],"mirror":p[6],"scale":p[7]}) ima.set_attr(xform, t)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def get_params3D(ima, xform = \"xform.align3d\"):\n\tt = ima.get_attr(xform)\n\td = t.get_params(\"spider\")\n\treturn d[\"phi\"],d[\"theta\"],d[\"psi\"],d[\"tx\"],d[\"ty\"],d[\"tz\"],d[\"mirror\"],d[\"scale\"]", "def setCameraRotation3D(ang):\n dislin.vup3d(ang)", "def params_3D_2D(phi, theta, psi, s2x, s...
[ "0.59650105", "0.593235", "0.5929709", "0.58860916", "0.5739548", "0.5691223", "0.56045157", "0.5573526", "0.55701107", "0.5569729", "0.55564326", "0.55041516", "0.5470599", "0.5299311", "0.5288693", "0.5281004", "0.5277822", "0.52361757", "0.5231874", "0.5215359", "0.5197185...
0.65861595
0
retrieve projection alignment parameters from the header phi theta psi s2x s2y
def get_params_proj(ima, xform = "xform.projection"): t = ima.get_attr(xform) d = t.get_params("spider") return d["phi"],d["theta"],d["psi"],-d["tx"],-d["ty"]
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def params_3D_2D(phi, theta, psi, s2x, s2y):\n\tif theta > 90.0:\n\t\tmirror = 1\n\t\talpha, sx, sy, scalen = compose_transform2(0, s2x, s2y, 1.0, 540.0-psi, 0, 0, 1.0)\n\telse:\n\t\tmirror = 0\n\t\talpha, sx, sy, scalen = compose_transform2(0, s2x, s2y, 1.0, 360.0-psi, 0, 0, 1.0)\n\treturn alpha, sx, sy, mirror"...
[ "0.61034876", "0.60535675", "0.6002323", "0.55047", "0.53491384", "0.53456676", "0.5342712", "0.5333783", "0.5266437", "0.52358764", "0.52249706", "0.5206061", "0.5192297", "0.51854604", "0.5182782", "0.51370823", "0.51352656", "0.512739", "0.5105829", "0.50973487", "0.508592...
0.6081615
1
set projection alignment parameters in the header phi theta psi s2x s2y
def set_params_proj(ima, p, xform = "xform.projection"): from EMAN2 import Vec2f t = Transform({"type":"spider","phi":p[0],"theta":p[1],"psi":p[2]}) t.set_trans(Vec2f(-p[3], -p[4])) ima.set_attr(xform, t)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def params_3D_2D(phi, theta, psi, s2x, s2y):\n\tif theta > 90.0:\n\t\tmirror = 1\n\t\talpha, sx, sy, scalen = compose_transform2(0, s2x, s2y, 1.0, 540.0-psi, 0, 0, 1.0)\n\telse:\n\t\tmirror = 0\n\t\talpha, sx, sy, scalen = compose_transform2(0, s2x, s2y, 1.0, 360.0-psi, 0, 0, 1.0)\n\treturn alpha, sx, sy, mirror"...
[ "0.59060866", "0.5602356", "0.54695225", "0.531587", "0.5250702", "0.51489925", "0.512252", "0.51054573", "0.50826424", "0.50823313", "0.50728947", "0.5068519", "0.5064257", "0.50619185", "0.504671", "0.5043761", "0.5035546", "0.5006031", "0.49904823", "0.49792513", "0.496036...
0.5937973
0
recover numerical values of CTF parameters from EMAN2 CTF object stored in a header of the input image
def get_ctf(ima): from EMAN2 import EMAN2Ctf ctf_params = ima.get_attr("ctf") return ctf_params.defocus, ctf_params.cs, ctf_params.voltage, ctf_params.apix, ctf_params.bfactor, ctf_params.ampcont, ctf_params.dfdiff, ctf_params.dfang
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def get_aperture_coeffs_in_header(head):\n\n coeffs = {}\n for key, value in head.items():\n exp = '^GAMSE TRACE CHANNEL [A-Z] APERTURE \\d+ COEFF \\d+$'\n if re.match(exp, key) is not None:\n g = key.split()\n channel = g[3]\n aperture = int(g[5])\n ...
[ "0.56780773", "0.56284475", "0.55668586", "0.5510405", "0.5448828", "0.5425909", "0.5414353", "0.54138607", "0.541011", "0.54011285", "0.5374928", "0.5361909", "0.5342145", "0.533246", "0.5314134", "0.5313142", "0.525259", "0.52504194", "0.5208928", "0.520613", "0.5202701", ...
0.60774076
0
generate EMAN2 CTF object using values of CTF parameters given in the list p
def generate_ctf(p): from EMAN2 import EMAN2Ctf defocus = p[0] cs = p[1] voltage = p[2] pixel_size = p[3] bfactor = p[4] amp_contrast = p[5] if defocus > 100: # which means it is very likely in Angstrom, therefore we are using the old convention defocus *= 1e-4 if amp_contrast < 1.0: from math import sqrt amp_contrast = amp_contrast*100/sqrt(2*amp_contrast**2-2*amp_contrast+1) ctf = EMAN2Ctf() if(len(p) == 6): ctf.from_dict({"defocus":defocus, "cs":cs, "voltage":voltage, "apix":pixel_size, "bfactor":bfactor, "ampcont":amp_contrast}) else: ctf.from_dict({"defocus":defocus, "cs":cs, "voltage":voltage, "apix":pixel_size, "bfactor":bfactor, "ampcont":amp_contrast,'dfdiff':p[6],'dfang':p[7]}) return ctf
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def from_thermo(T_C, p):\n\ty = y_from_p(p)\n\tx = x_from_Tp(T_C+C_to_K, p)\n\treturn x, y", "def construct_param_dict(params,K_RC,K_CP,m_P):\n ###scaling constants\n w=params['w']\n pd=params['pd'] # in 3D and 0.21 in 2D\n pv=params['pv']\n Er=params['Er'] ;Ek=params['Ek']\n ER=params['ER'];EC...
[ "0.5515874", "0.5445426", "0.5421652", "0.54088384", "0.5321685", "0.5316981", "0.5300015", "0.52771187", "0.52574724", "0.5255685", "0.52163506", "0.5180207", "0.5175576", "0.51701", "0.5159775", "0.51574296", "0.51267034", "0.51238847", "0.5120029", "0.5111619", "0.5101273"...
0.77108574
0
set EMAN2 CTF object in the header of input image using values of CTF parameters given in the list p
def set_ctf(ima, p): from utilities import generate_ctf ctf = generate_ctf( p ) ima.set_attr( "ctf", ctf )
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def generate_ctf(p):\n\tfrom EMAN2 import EMAN2Ctf\n\n\tdefocus = p[0]\n\tcs = p[1]\n\tvoltage = p[2]\n\tpixel_size = p[3]\n\tbfactor = p[4]\n\tamp_contrast = p[5]\n\t\n\tif defocus > 100: # which means it is very likely in Angstrom, therefore we are using the old convention\n\t\tdefocus *= 1e-4\n\t\n\tif amp_con...
[ "0.6119822", "0.52715033", "0.52555937", "0.521904", "0.5153852", "0.5145439", "0.50969875", "0.5046172", "0.5035334", "0.5006989", "0.49636608", "0.49189067", "0.49184573", "0.4891116", "0.4880313", "0.4876546", "0.48572096", "0.4852319", "0.48459044", "0.4828242", "0.482119...
0.60989493
1
Find all occurences of val on list lo Returns a list of indices of val on lo.
def findall(lo,val): u = [] i = -1 while( i < len(lo)-1): try: i = lo.index(val,i+1) u.append(i) except: i += 1 return u
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def findall(l, o):\n return [i for i, u in enumerate(l) if u==o]", "def getIndexes(self, val):\n # Find where this value is listed. \n valNdx = (self.values == val).nonzero()[0]\n \n # If this value is not actually in those listed, then we \n # must return empty indexes\n ...
[ "0.70793176", "0.7071109", "0.66156113", "0.6319743", "0.6250533", "0.620535", "0.62024206", "0.619781", "0.6169729", "0.60985184", "0.6077737", "0.6067603", "0.5907215", "0.5842827", "0.58379203", "0.5817054", "0.58101517", "0.5786621", "0.577902", "0.5734879", "0.5654707", ...
0.8087934
0
Find overall phi angle and z shift difference between two sets of projection parameters for helical structure. The two sets have to be of the same length and it is assume that k'th element on the first list corresponds to the k'th element on the second list.
def helical_consistency(p2i, p1): from pixel_error import angle_diff from math import cos,pi from utilities import getvec from pixel_error import angle_error from EMAN2 import Vec2f n =len(p1[0]) print n qtm = -1.0e10 for lf in xrange(0,181,180): p2 = [] p2.extend(p2i) if( lf == 180): tflip = Transform({"type":"spider","theta":180.0}) for j in xrange(n): t2 = Transform({"type":"spider","phi":p2[0][j],"theta":p2[1][j],"psi":p2[2][j]}) t2.set_trans( Vec2f( -p2[3][j], -p2[4][j] ) ) t2 = t2*tflip d = t2.get_params("spider") p2[0][j] = d["phi"] p2[1][j] = d["theta"] p2[2][j] = d["psi"] p2[3][j] = -d["tx"] p2[4][j] = -d["ty"] tt1 = [0.0]*n tt2 = [0.0]*n mirror = [False]*n ln = 0 for j in xrange( n ): t1 = getvec(p1[0][j],p1[1][j]) t2 = getvec(p2[0][j],p2[1][j]) tm = getvec(180.0+p2[0][j],180.0-p2[1][j]) tt1[j] = t1[0]*t2[0]+t1[1]*t2[1]+t1[2]*t2[2] tt2[j] = t1[0]*tm[0]+t1[1]*tm[1]+t1[2]*tm[2] if(abs(tt1[j])<1.0e-7): tt1[j] = 0.0 if(abs(tt2[j])<1.0e-7): tt2[j] = 0.0 if(tt1[j]>tt2[j]): mirror[j] = True ln+=1 print " FLIP ",lf if(ln < n//2): print "mirror ",ln for j in xrange( n ): p2[0][j] += 180.0 p2[1][j] = 180.0-p2[1][j] p2[2][j] = -p2[2][j] p2[4][j] = -p2[4][j] mirror[j] = not(mirror[j]) else: print " straight", ln phi1 = [] phi2 = [] agree = [] for j in xrange(n): if(mirror[j]): phi1.append(p1[0][j]) phi2.append(p2[0][j]) agree.append(j) print len(phi1) delta_phi = angle_diff( phi2, phi1 ) print "close form diff===", delta_phi phi1 = [] phi2 = [] errorm = [] for j in xrange( len( p1[0]) ): p2[0][j] = (p2[0][j] + delta_phi + 360)%360.0 if(mirror[j]): phi1.append(p1[0][j]) phi2.append(p2[0][j]) errorm.append(angle_error( [ p2[0][j] ], [ p1[0][j] ])) qt = sum(errorm)/len(errorm) print len(errorm),qt if(qt > qtm): qtm = qt p2o = [] p2o.extend(p2) errormo = [] phi1o = [] phi2o = [] errormo.extend(errorm) phi1o.extend(phi1) phi2o.extend(phi2) return p2o, errormo, agree, delta_phi, phi1o, phi2o
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def rotation_between_anglesets(agls1, agls2):\n\tfrom math import sin, cos, pi, sqrt, atan2, acos, atan\n\tfrom numpy import array, linalg, matrix\n\timport types\n\n\tdeg2rad = pi/180.0\n\n\tdef ori2xyz(ori):\n\t\tif(type(ori) == types.ListType):\n\t\t\tphi, theta, psi = ori[:3]\n\t\telse:\n\t\t\t# it has to be ...
[ "0.614044", "0.5826733", "0.5789848", "0.5688521", "0.5658761", "0.56020504", "0.5570326", "0.5457091", "0.54170704", "0.54091537", "0.5399414", "0.5383706", "0.53525215", "0.5337892", "0.53332806", "0.5322254", "0.5320831", "0.53138745", "0.53113425", "0.5300493", "0.5291562...
0.5451437
8
Find overall 3D rotation (phi theta psi) between two sets of Eulerian angles. The two sets have to be of the same length and it is assume that k'th element on the first list corresponds to the k'th element on the second list.
def rotation_between_anglesets(agls1, agls2): from math import sin, cos, pi, sqrt, atan2, acos, atan from numpy import array, linalg, matrix import types deg2rad = pi/180.0 def ori2xyz(ori): if(type(ori) == types.ListType): phi, theta, psi = ori[:3] else: # it has to be Transformation object d = ori.get_params("spider") phi = d["phi"] theta = d["theta"] psi = d["psi"] """ # This makes no sense here! PAP 09/2011 if theta > 90.0: phi += 180.0 theta = 180.0-theta """ phi *= deg2rad theta *= deg2rad x = sin(theta) * sin(phi) y = sin(theta) * cos(phi) z = cos(theta) return [x, y, z] N = len(agls1) if N != len(agls2): print 'Both lists must have the same length' return -1 if N < 2: print 'At least two orientations are required in each list' return -1 U1, U2 = [], [] for n in xrange(N): p1 = ori2xyz(agls1[n]) p2 = ori2xyz(agls2[n]) U1.append(p1) U2.append(p2) # compute all Suv with uv = {xx, xy, xz, yx, ..., zz} Suv = [0] * 9 c = 0 nbori = len(U1) for i in xrange(3): for j in xrange(3): for s in xrange(nbori): Suv[c] += (U2[s][i] * U1[s][j]) c += 1 # create matrix N N = array([[Suv[0]+Suv[4]+Suv[8], Suv[5]-Suv[7], Suv[6]-Suv[2], Suv[1]-Suv[3]], [Suv[5]-Suv[7], Suv[0]-Suv[4]-Suv[8], Suv[1]+Suv[3], Suv[6]+Suv[2]], [Suv[6]-Suv[2], Suv[1]+Suv[3], -Suv[0]+Suv[4]-Suv[8], Suv[5]+Suv[7]], [Suv[1]-Suv[3], Suv[6]+Suv[2], Suv[5]+Suv[7], -Suv[0]-Suv[4]+Suv[8]]]) # eigenvector corresponding to the most positive eigenvalue val, vec = linalg.eig(N) q0, qx, qy, qz = vec[:, val.argmax()] # create quaternion Rot matrix r = [q0*q0-qx*qx+qy*qy-qz*qz, 2*(qy*qx+q0*qz), 2*(qy*qz-q0*qx), 0.0, 2*(qx*qy-q0*qz), q0*q0+qx*qx-qy*qy-qz*qz, 2*(qx*qz+q0*qy), 0.0, 2*(qz*qy+q0*qx), 2*(qz*qx-q0*qy), q0*q0-qx*qx-qy*qy+qz*qz, 0.0] R = Transform(r) dictR = R.get_rotation('SPIDER') return dictR['phi'], dictR['theta'], dictR['psi']
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def find_rotation(a, b):\n a.shape = (3,)\n b.shape = (3,)\n\n a /= np.linalg.norm(a)\n b /= np.linalg.norm(b)\n \n v = np.cross(a, b)\n \n angle_AB = -1*vector_angle(a, b) \n \n print(angle_AB)\n s = np.linalg.norm(v) * np.sin(angle_AB)\n \n c = np.dot(a, b) * np.cos(angle_A...
[ "0.61534816", "0.6057964", "0.6041564", "0.6022013", "0.5908641", "0.5882892", "0.5800431", "0.57707256", "0.5706791", "0.56642485", "0.56599987", "0.5649005", "0.5628651", "0.5623927", "0.56015086", "0.5588204", "0.55626535", "0.5548194", "0.55238026", "0.5522772", "0.551259...
0.7362805
0
Retrieve pixel size from the header. We check attribute Pixel_size and also pixel size from ctf object, if exisits. If the two are different or if the pixel size is not set, return 1.0 and print a warning.
def get_pixel_size(img): p1 = img.get_attr_default("apix_x", -1.0) cc = img.get_attr_default("ctf", None) if cc == None: p2 = -1.0 else: p2 = round(cc.apix, 3) if p1 == -1.0 and p2 == -1.0: ERROR("Pixel size not set", "get_pixel_size", 0) return -1.0 elif p1 > -1.0 and p2 > -1.0: if abs(p1-p2) >= 0.001: ERROR("Conflict between pixel size in attribute and in ctf object", "get_pixel_size", 0) # pixel size is positive, so what follows omits -1 problem return max(p1, p2) else: return max(p1, p2)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def pixelsize(self):\n if hasattr(self, \"_pixelsize\"):\n return self._pixelsize\n\n try:\n return self.header[\"PixSize\"] # [arcsec]\n except KeyError:\n try:\n return abs(self.header[\"CDELT1\"]) * 3600 # [deg] -> [arcsec]\n exce...
[ "0.72802687", "0.68242306", "0.68130434", "0.677174", "0.6668118", "0.6537701", "0.6535796", "0.6514242", "0.6482996", "0.64115053", "0.63932556", "0.6321486", "0.6316444", "0.6295255", "0.62676024", "0.62676024", "0.62564975", "0.6233684", "0.6221311", "0.6203486", "0.61531"...
0.69274837
1
Set pixel size in the header. Set attribute Pixel_size and also pixel size in ctf object, if exists.
def set_pixel_size(img, pixel_size): nz = img.get_zsize() img.set_attr("apix_x", round(pixel_size, 3)) img.set_attr("apix_y", round(pixel_size, 3)) img.set_attr("apix_z", round(pixel_size, 3)) cc = img.get_attr_default("ctf", None) if(cc): cc.apix = pixel_size img.set_attr("ctf", cc)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def set_pixel_size(self, pixel_size):\n raise NotImplementedError", "def set_size(self, w, h):\n\t\tpass", "def set_size(self, value='S'):\n upper = value.upper()\n\n if upper == 'M': # Medium: double height\n # size = 0x01\n # charHeight = 48\n # maxColum...
[ "0.6878347", "0.6856726", "0.6558465", "0.6309463", "0.6261243", "0.6204648", "0.61168814", "0.6115968", "0.61134034", "0.60657334", "0.60597295", "0.60385007", "0.60327333", "0.6032628", "0.6013194", "0.59783244", "0.5973719", "0.5945691", "0.5938708", "0.59118575", "0.59118...
0.67625564
2
For an input directory, create a dictionary mapping output names to input ROOT files.
def build_groupings(idir: str) -> dict: bkg_group = {key: [ifile for ifile in glob(f'{idir}/*_{key}_*.root')] for key in bkgs} pw_group = {key: [ifile for ifile in glob(f'{idir}/{key}*.root')] for key in powhegs} wh_pw_group = [ifile for name in wh_powhegs for ifile in glob(f'{idir}/{name}*.root')] ungrouped = [ifile for ifile in glob(f'{idir}/*.root') if 'madgraph' in ifile or 'JHU' in ifile] group = {} for key, files in bkg_group.items(): if len(files) > 0: group[key] = files for key, files in pw_group.items(): if len(files) > 0: group[key] = files for ifile in ungrouped: name = ifile.split('/')[-1].replace('.root', '') name = name.split('_SYST')[0].replace('-', '_') name = name.replace('_ggH125', '').replace('_VBF125', '').replace('_WH125', '').replace('_ZH125', '') group[name] = [ifile] if len(wh_pw_group) > 0: group['wh125_powheg'] = wh_pw_group return group
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def _output_paths(outputs: Dict[str, str]) -> Dict[str, Path]:\n out_paths = dict()\n for name in outputs:\n target_dir = _BASE_PATH / name\n target_dir.mkdir()\n out_paths[name] = target_dir / 'data.json'\n return out_paths", "def treat(input, output):\n files = find(input)\n ...
[ "0.6456172", "0.64561534", "0.63940656", "0.63858587", "0.63171786", "0.62454695", "0.61177707", "0.6060311", "0.60519314", "0.6003057", "0.5944946", "0.5938714", "0.59148794", "0.5861261", "0.5858004", "0.5832426", "0.5809002", "0.5801422", "0.5792834", "0.57921237", "0.5737...
0.53595054
76
Build the dictionary of all files to be processed in appropriate groupings.
def build_filelist(input_dir: str, syst: bool = False) -> dict: filedict = { idir.split('SYST_')[-1].split('/')[0]: {} for idir in glob('{}/*'.format(input_dir)) if 'SYST_' in idir } filedict['nominal'] = build_groupings(f'{input_dir}/NOMINAL') if syst: for idir in filedict.keys(): if idir == 'nominal': continue elif 'Rivet' in idir: continue filedict[idir] = build_groupings(f'{input_dir}/SYST_{idir}') else: filedict = {'nominal': filedict['nominal']} pprint(filedict, width=150) return filedict
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def build_groupings(idir: str) -> dict:\n bkg_group = {key: [ifile for ifile in glob(f'{idir}/*_{key}_*.root')] for key in bkgs}\n pw_group = {key: [ifile for ifile in glob(f'{idir}/{key}*.root')] for key in powhegs}\n wh_pw_group = [ifile for name in wh_powhegs for ifile in glob(f'{idir}/{name}*.root')]\...
[ "0.7275469", "0.71176326", "0.7100193", "0.70664155", "0.7045975", "0.70392615", "0.6858053", "0.6840117", "0.6648288", "0.66272867", "0.64521015", "0.6448374", "0.6421026", "0.6416618", "0.63611877", "0.6361177", "0.63366175", "0.6319295", "0.6307999", "0.62980103", "0.62935...
0.66944414
8
For the given grouping, convert ROOT files into DataFrames merging groups together. Return a dictionary mapping file names to DataFrames.
def process_group(directory: str, files: dict, channel: str, year: str) -> dict: if len(files) == 0: raise Exception('empty file list for directory {}'.format(directory)) + 1 dataframes = {} for name, ifile in files.items(): # equivalent of hadding update_dfs = uproot.pandas.iterate(ifile, f'{channel}_tree') current_dfs = [] for update_df in update_dfs: update_df.fillna(-999, inplace=True) current_dfs.append(update_df) if len(current_dfs) > 0: dataframes[name] = pd.concat(current_dfs) dataframes['metadata'] = pd.DataFrame({'channel': [channel], 'year': [year]}) return dataframes
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def get_processed_data(self, group_directory):\n processed_dir = [x for x in group_directory.iterdir()\n if x.is_dir() and 'processed' in x.name][0]\n\n task_dirs = [x for x in processed_dir.iterdir()\n if x.is_dir() and 'task' in x.name]\n\n files =...
[ "0.6541141", "0.60830426", "0.6062187", "0.59850407", "0.5894021", "0.5629577", "0.56196886", "0.5457541", "0.5436698", "0.5417699", "0.5383131", "0.53697276", "0.5362166", "0.5328199", "0.5324665", "0.5262586", "0.52602506", "0.5259905", "0.52521104", "0.5234652", "0.5222199...
0.64353156
1
Reweight JHU and Madgraph signals to different coupling scenarios.
def ac_reweighting(dataframes: dict, reweight: bool, config: dict) -> dict: vbf = pd.concat([df for key, df in dataframes.items() if 'vbf125_JHU' in key]) wh = pd.concat([df for key, df in dataframes.items() if 'wh125_JHU' in key]) zh = pd.concat([df for key, df in dataframes.items() if 'zh125_JHU' in key]) # scale evtwt with appropriate reweighting factor and give a new name for weight, name in config['jhu_ac_reweighting_map']['vbf']: df = vbf.copy(deep=True) df['evtwt'] *= df[weight] dataframes[name] = df for weight, name in config['jhu_ac_reweighting_map']['wh']: df = wh.copy(deep=True) df['evtwt'] *= df[weight] dataframes[name] = df for weight, name in config['jhu_ac_reweighting_map']['zh']: df = zh.copy(deep=True) df['evtwt'] *= df[weight] dataframes[name] = df if reweight: # add couplings together then apply weights ggh = pd.concat([df for key, df in dataframes.items() if 'ggh125_madgraph' in key]) for weight, name in config['mg_ac_reweighting_map']['ggh']: df = ggh.copy(deep=True) df['evtwt'] *= df[weight] dataframes[name] = df else: # just add couplings without weighting dataframes['reweighted_ggH_htt_0PM125'] = pd.concat([ df for key, df in dataframes.items() if 'ggh125_madgraph' in key and 'a1_filtered' in key ]) dataframes['reweighted_ggH_htt_0M125'] = pd.concat([ df for key, df in dataframes.items() if 'ggh125_madgraph' in key and 'a3_filtered' in key ]) dataframes['reweighted_ggH_htt_0Mf05ph0125'] = pd.concat([ df for key, df in dataframes.items() if 'ggh125_madgraph' in key and 'a3int_filtered' in key ]) return dataframes
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def backward_shimmey(self):\n for x in range(6):\n self.right(primary=-70, counter=-30)\n time.sleep(.5)\n self.left(primary=-70, counter=-30)\n time.sleep(.5)\n self.stop()", "def backward_shimmey(self):\n for x in range(6):\n self.righ...
[ "0.5252793", "0.5252793", "0.52396435", "0.51686776", "0.50035083", "0.49548638", "0.49380127", "0.49380127", "0.49380127", "0.49363765", "0.4932626", "0.49048656", "0.4897503", "0.48733047", "0.48726597", "0.48689917", "0.48130462", "0.47945935", "0.47870296", "0.47869524", ...
0.0
-1
Store information for NN training (signal labels, scaled evtwts, and info for standardization.
def nn_preprocess(dataframes: dict) -> dict: from sklearn.preprocessing import MinMaxScaler for name, df in dataframes.items(): if name == 'metadata': continue # store signal label for NN training if 'ggh125' in name or 'vbf125' in name: df['signalLabel'] = np.ones(len(df)) else: df['signalLabel'] = np.zeros(len(df)) # normalize sample weights df['scaled_evtwt'] = MinMaxScaler(feature_range=(1., 2.)).fit_transform(df.evtwt.values.reshape(-1, 1)) return dataframes
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def training_info(self):\n pass", "def _training_vars(self):\n self.vars = dict()\n # Temperature params\n self.vars['TInit'] = -1\n self.vars['TDecayRate'] = 0.05\n # Bowl params\n self.vars['q_init'] = 16.58 # initial strength for the bowl\n self.vars['q...
[ "0.6854838", "0.6442424", "0.61368126", "0.607955", "0.5979329", "0.596864", "0.5946029", "0.5927915", "0.5915242", "0.59119564", "0.5895071", "0.58685416", "0.5860887", "0.5857673", "0.5857673", "0.5851298", "0.5837819", "0.5815968", "0.5808178", "0.5806393", "0.5806393", ...
0.0
-1
Write JSON in a consistent, humanreadable way.
def json_dumps(o: Any) -> bytes: return json.dumps( o, indent=4, sort_keys=True, ensure_ascii=True, separators=(",", ": "), cls=NumberEncoder ).encode("ascii")
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def write(self):\n self.json_o.write()", "def _write_json(self):\n with open(self._file_path, 'w') as f:\n json.dump(self._content, f, indent=4, separators=None,\n encoding='utf-8', sort_keys=False)", "def write(self, _filepath=None):\n if _filepath is None:...
[ "0.73995405", "0.73701173", "0.7319848", "0.7299197", "0.7268811", "0.71151686", "0.7094368", "0.6901286", "0.6872474", "0.6859761", "0.68393916", "0.67960197", "0.67669374", "0.6747494", "0.6735324", "0.67135006", "0.6681034", "0.6619973", "0.66117257", "0.66088766", "0.6588...
0.0
-1
Read JSON in a consistent way.
def json_loads(s: Union[bytes, str]) -> Dict[str, Any]: return json.loads(ensure_text(s, "utf-8"))
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def read_json(self):\n self._fopen.seek(self._json_start, 0)\n return json.loads(self._fopen.read().decode('utf-8'))", "def read_json(self, *args, **kwargs):\n with self.open('rb') as f:\n return json.load(f, *args, **kwargs)", "def reading_json(json_file):\n with open(json_f...
[ "0.72466516", "0.71838474", "0.7122567", "0.70307904", "0.70307904", "0.7005705", "0.7005705", "0.69405353", "0.6842769", "0.6829329", "0.6786115", "0.6777155", "0.67250484", "0.6718409", "0.6713313", "0.6706307", "0.6697732", "0.6672447", "0.6669862", "0.6629288", "0.6623848...
0.0
-1
Convenience function to normalize the `shape` argument.
def normalize_shape(shape: Union[int, Tuple[int, ...], None]) -> Tuple[int, ...]: if shape is None: raise TypeError("shape is None") # handle 1D convenience form if isinstance(shape, numbers.Integral): shape = (int(shape),) # normalize shape = cast(Tuple[int, ...], shape) shape = tuple(int(s) for s in shape) return shape
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def normalize(shape):\n s = shape\n matrix = Shape.get_matrix(s.get_vector())\n norm_x = math.sqrt(sum(matrix[:, 0] ** 2))\n norm_y = math.sqrt(sum(matrix[:, 1] ** 2))\n for pt in s.pts:\n pt.x /= norm_x\n pt.y /= norm_y\n return s", "def _normalize_shape(shape):\n\n if isinsta...
[ "0.7858332", "0.7624819", "0.69473106", "0.6248372", "0.61092657", "0.60909945", "0.6038357", "0.60316885", "0.6010704", "0.587052", "0.5844497", "0.5780181", "0.57371706", "0.5733882", "0.5694286", "0.56934756", "0.5677857", "0.5620248", "0.56186056", "0.55923927", "0.558957...
0.73496735
2
Guess an appropriate chunk layout for an array, given its shape and the size of each element in bytes. Will allocate chunks only as large as MAX_SIZE. Chunks are generally close to some powerof2 fraction of each axis, slightly favoring bigger values for the last index. Undocumented and subject to change without warning.
def guess_chunks(shape: Tuple[int, ...], typesize: int) -> Tuple[int, ...]: ndims = len(shape) # require chunks to have non-zero length for all dimensions chunks = np.maximum(np.array(shape, dtype="=f8"), 1) # Determine the optimal chunk size in bytes using a PyTables expression. # This is kept as a float. dset_size = np.prod(chunks) * typesize target_size = CHUNK_BASE * (2 ** np.log10(dset_size / (1024.0 * 1024))) if target_size > CHUNK_MAX: target_size = CHUNK_MAX elif target_size < CHUNK_MIN: target_size = CHUNK_MIN idx = 0 while True: # Repeatedly loop over the axes, dividing them by 2. Stop when: # 1a. We're smaller than the target chunk size, OR # 1b. We're within 50% of the target chunk size, AND # 2. The chunk is smaller than the maximum chunk size chunk_bytes = np.prod(chunks) * typesize if ( chunk_bytes < target_size or abs(chunk_bytes - target_size) / target_size < 0.5 ) and chunk_bytes < CHUNK_MAX: break if np.prod(chunks) == 1: break # Element size larger than CHUNK_MAX chunks[idx % ndims] = math.ceil(chunks[idx % ndims] / 2.0) idx += 1 return tuple(int(x) for x in chunks)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def split_chunk(chunk, sizes, max_iter=1000, rng=None):\n assert len(chunk) == sum(sizes), f\"{len(chunk)} != {sum(sizes)}\"\n if not isinstance(rng, random.Random):\n rng = random\n # Precompute neighbors for each cube in the chunk\n neighbors = dict()\n for c in chunk:\n neighbors[c]...
[ "0.644044", "0.629798", "0.61731964", "0.60461324", "0.598301", "0.5948597", "0.59229267", "0.5806321", "0.57971877", "0.5785244", "0.57549477", "0.56843406", "0.5641695", "0.5637497", "0.56076527", "0.5582129", "0.55698544", "0.556121", "0.55578834", "0.5544379", "0.5536151"...
0.7806975
0
Convenience function to normalize the `chunks` argument for an array with the given `shape`.
def normalize_chunks(chunks: Any, shape: Tuple[int, ...], typesize: int) -> Tuple[int, ...]: # N.B., expect shape already normalized # handle auto-chunking if chunks is None or chunks is True: return guess_chunks(shape, typesize) # handle no chunking if chunks is False: return shape # handle 1D convenience form if isinstance(chunks, numbers.Integral): chunks = tuple(int(chunks) for _ in shape) # handle bad dimensionality if len(chunks) > len(shape): raise ValueError("too many dimensions in chunks") # handle underspecified chunks if len(chunks) < len(shape): # assume chunks across remaining dimensions chunks += shape[len(chunks) :] # handle None or -1 in chunks if -1 in chunks or None in chunks: chunks = tuple(s if c == -1 or c is None else int(c) for s, c in zip(shape, chunks)) chunks = tuple(int(c) for c in chunks) return chunks
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def _normalize_shape(shape):\n\n if isinstance(shape, (np.integer, int)):\n if shape < 1:\n raise ValueError(\"shape value must be greater than 0: %d\"\n % shape)\n shape = (shape,) # N is a shorthand for (N,)\n try:\n shape = tuple(shape)\n exc...
[ "0.61362606", "0.60389656", "0.58118457", "0.5734301", "0.5696832", "0.5670947", "0.5670829", "0.5670006", "0.56443065", "0.5637183", "0.56079644", "0.55675006", "0.5559034", "0.55089456", "0.5506106", "0.5494193", "0.54827696", "0.5472908", "0.54428035", "0.54304826", "0.542...
0.7882431
0
Determine whether `item` specifies a complete slice of array with the given `shape`. Used to optimize __setitem__ operations on the Chunk class.
def is_total_slice(item, shape: Tuple[int]) -> bool: # N.B., assume shape is normalized if item == Ellipsis: return True if item == slice(None): return True if isinstance(item, slice): item = (item,) if isinstance(item, tuple): return all( ( isinstance(it, slice) and ((it == slice(None)) or ((it.stop - it.start == sh) and (it.step in [1, None]))) ) for it, sh in zip(item, shape) ) else: raise TypeError("expected slice or tuple of slices, found %r" % item)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def __contains__(self, item):\n if len(item) != len(self.sizes):\n raise ValueError('Point dimension does not match grid dimension')\n for i in range(len(self.sizes)):\n if not 1 <= item[i] < self.sizes[i] - 1:\n return False\n return True", "def roi_is_f...
[ "0.5930391", "0.5894886", "0.5701367", "0.56653273", "0.5539224", "0.54814374", "0.54136163", "0.54108244", "0.5387186", "0.5382678", "0.5344155", "0.5341929", "0.53009504", "0.5299111", "0.52924687", "0.5279965", "0.52784073", "0.52331346", "0.5224626", "0.51978904", "0.5183...
0.780188
0
Make several attempts to invoke the callable. If one of the given exceptions is raised, wait the given period of time and retry up to the given number of retries.
def retry_call( callabl: Callable, args=None, kwargs=None, exceptions: Tuple[Any, ...] = (), retries: int = 10, wait: float = 0.1, ) -> Any: if args is None: args = () if kwargs is None: kwargs = {} for attempt in range(1, retries + 1): try: return callabl(*args, **kwargs) except exceptions: if attempt < retries: time.sleep(wait) else: raise
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def call_with_retries(function, max_retries=10,\n exception_types=(Exception),\n _args=(), _kwargs={}):\n assert max_retries >= 0\n\n retries = 0\n last_exc = Exception('Unknown exception')\n while retries <= max_retries:\n try:\n return funct...
[ "0.790463", "0.7765928", "0.7565526", "0.7538731", "0.75145954", "0.7512866", "0.7507025", "0.7504739", "0.74817264", "0.7449125", "0.7426998", "0.73940426", "0.7380012", "0.73608816", "0.7356993", "0.73083615", "0.7303313", "0.72958124", "0.7114819", "0.70131445", "0.7012791...
0.7604029
2
Test if all the elements of an array are equivalent to a value. If `value` is None, then this function does not do any comparison and returns False.
def all_equal(value: Any, array: Any): if value is None: return False if not value: # if `value` is falsey, then just 1 truthy value in `array` # is sufficient to return False. We assume here that np.any is # optimized to return on the first truthy value in `array`. try: return not np.any(array) except (TypeError, ValueError): # pragma: no cover pass if np.issubdtype(array.dtype, np.object_): # we have to flatten the result of np.equal to handle outputs like # [np.array([True,True]), True, True] return all(flatten(np.equal(value, array, dtype=array.dtype))) else: # Numpy errors if you call np.isnan on custom dtypes, so ensure # we are working with floats before calling isnan if np.issubdtype(array.dtype, np.floating) and np.isnan(value): return np.all(np.isnan(array)) else: # using == raises warnings from numpy deprecated pattern, but # using np.equal() raises type errors for structured dtypes... return np.all(value == array)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def all_equal(array):\n if not array:\n raise ValueError(\"Array is empty\")\n\n first_item = array[0]\n\n if any(item != first_item for item in array):\n return False\n\n return True", "def has_equal_values_vec(x):\n return jnp.all(x == x[0])", "def check_array(self, array: ArrayD...
[ "0.6699362", "0.6486526", "0.6385027", "0.6280364", "0.61277896", "0.612132", "0.6043027", "0.60365415", "0.5891498", "0.5891476", "0.5875021", "0.5753058", "0.5749066", "0.57388574", "0.5702565", "0.56945324", "0.5661426", "0.56569785", "0.56512713", "0.56494707", "0.5626120...
0.7799601
0
Convenience function to coerce `buf` to ndarraylike array or bytes. First check if `buf` can be zerocopy converted to a contiguous array. If not, `buf` will be copied to a newly allocated `bytes` object.
def ensure_contiguous_ndarray_or_bytes(buf) -> Union[NDArrayLike, bytes]: try: return ensure_contiguous_ndarray_like(buf) except TypeError: # An error is raised if `buf` couldn't be zero-copy converted return ensure_bytes(buf)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def buffer_to_bytes(buf):\n if not isinstance(buf, bytes):\n buf = bytes(buf)\n return buf", "def test_array_as_buffer(parser):\n doc = parser.parse(b'''{\n \"d\": [1.2, 2.3, 3.4],\n \"i\": [-1, 2, -3, 4],\n \"u\": [1, 2, 3, 4, 5],\n \"x\": [1, 2, 3, \"not valid\"]\n ...
[ "0.6886174", "0.6035865", "0.5953554", "0.55916303", "0.5561849", "0.54923177", "0.5430941", "0.53742135", "0.51953775", "0.5164276", "0.51263016", "0.5078041", "0.507584", "0.5072293", "0.50700045", "0.5063474", "0.50496", "0.5039605", "0.5037979", "0.50145006", "0.49787346"...
0.8558664
0
This function prints and plots the confusion matrix. Normalization can be applied by setting `normalize=True`.
def plot_confusion_matrix(cm,classes,normalize=False,title='Confusion Matrix', cmap=plt.cm.Blues): if normalize: cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis] cm=np.around(cm,decimals=2) plt.imshow(cm, interpolation='nearest', cmap=cmap) plt.title(title) plt.colorbar() tick_marks = np.arange(len(classes)) plt.xticks(tick_marks, classes, rotation=90) plt.yticks(tick_marks, classes) thresh = cm.max() / 2. for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])): plt.text(j, i, cm[i, j],horizontalalignment="center",color="white" if cm[i, j] > thresh else "black") plt.tight_layout() plt.ylabel('True label') plt.xlabel('Predicted label')
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def plot_confusion_matrix(cm, classes=[0,1], normalize=False, title='Confusion matrix', print_matrix=False):\n\n if normalize:\n cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]\n print(\"Normalized confusion matrix\")\n else:\n print('Confusion matrix, without normalization')\n\n...
[ "0.81925154", "0.8093376", "0.8027219", "0.80169857", "0.7991475", "0.7988959", "0.79785", "0.7973596", "0.7959107", "0.7956459", "0.793519", "0.79322356", "0.79320693", "0.79289055", "0.79240024", "0.79221827", "0.792161", "0.79209834", "0.7920566", "0.7919846", "0.791543", ...
0.0
-1
Decompose transformation matrix into parts
def trans_matrix_inv(m:numpy.ndarray): was2d = False if m.shape[1] == 3: was2d = True m = numpy.asarray([ [1.0, 0.0, 0.0, 0.0], [0.0, m[0,0], m[0,1], m[0,2]], [0.0, m[1,0], m[1,1], m[1,2]], [0.0, 0.0, 0.0, 1.0]], numpy.float64) trans = m[0:3,3] rotate = numpy.zeros(3, numpy.float64) r = m[0:3,0:3] rc = numpy.linalg.cholesky(numpy.matmul(r.T, r)).T scale = numpy.diagonal(rc) if numpy.linalg.det(r) < 0.0: scale[0] *= -1.0 rcd = rc * numpy.eye(3, dtype=numpy.float64) rc = numpy.linalg.solve(rcd, rc) shear = numpy.asarray([rc[0,1], rc[0,2], rc[1,2]], numpy.float64) r0 = trans_matrix({'rotate': rotate, 'scale': scale, 'shear': shear})[0:3,0:3] r0 = numpy.linalg.solve(numpy.linalg.inv(r), numpy.linalg.inv(r0)) rotate[1] = numpy.arcsin(_frone(r0[0,2])) if numpy.abs((numpy.abs(rotate[1]) - (numpy.pi / 2.0))) < 1.0e-6: rotate[0] = 0.0 rotate[2] = numpy.arctan2(-_frone(r0[1,0]), _frone(-r0[2,0] / r0[0,2])) else: rc = numpy.cos(rotate[1]) rotate[0] = numpy.arctan2(_frone(r0[1,2] / rc), _frone(r0[2,2] / rc)) rotate[2] = numpy.arctan2(_frone(r0[0,1] / rc), _frone(r0[0,0] / rc)) if was2d: trans = trans[1:] rotate = rotate[0:1] scale = scale[1:] shear = shear[2:3] return (trans, rotate, scale, shear)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def xform_from_transformation_matrix(transformation_matrix):\n transform = Transform(1.0)\n for i in range(0, 4):\n for j in range(0, 4):\n transform[i, j] = transformation_matrix[i][j]\n return transform", "def _derive_transformation_matrices(self):\n\n if hasattr(self, '_prima...
[ "0.6168927", "0.6069243", "0.6052449", "0.6051412", "0.5990401", "0.5962151", "0.59120136", "0.58908314", "0.58383477", "0.57767695", "0.57475996", "0.57253575", "0.572462", "0.57190764", "0.56800544", "0.56527287", "0.56141245", "0.55945146", "0.55739355", "0.55634975", "0.5...
0.0
-1
Ask a yes no question
def ask_yes_no(question): answer = None while answer not in ("y","n"): answer = input(question).lower() return answer
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def ask_Yes_no(question, **kwargs):\n return ask_yes_no(question, default=\"y\", **kwargs)", "def ask_yes_No(question, **kwargs):\n return ask_yes_no(question, default=\"n\", **kwargs)", "def ask_yes_no(question):\r\n\tresponse = None\r\n\twhile response not in (\"y\", \"n\"):\r\n\t\tresponse = input(que...
[ "0.8196788", "0.8141998", "0.8027091", "0.79333156", "0.78017837", "0.7636633", "0.75908566", "0.75773454", "0.7574332", "0.7567365", "0.75321203", "0.7493373", "0.7484439", "0.74384576", "0.7435376", "0.7426852", "0.7407709", "0.73929524", "0.7383109", "0.7374345", "0.735202...
0.7771797
5
Clears the terminal screen.
def clear_screen(): # Clear command as function of OS command = "cls" if system_name().lower()=="windows" else "clear" # Action system_call(command)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def clear_screen() -> None:\n os.system(\"cls\" if os.name == \"nt\" else \"clear\")", "def clear_screen():\n os.system('cls')", "def clear_screen():\n\tprint(\"\\033[H\\033[J\")", "def clear_screen(self):\n os.system('cls' if os.name == 'nt' else 'clear')", "def clear_screen(self):\n o...
[ "0.89045364", "0.8903247", "0.8894391", "0.8885713", "0.8885713", "0.88519347", "0.88519347", "0.88374126", "0.8820877", "0.8814398", "0.8805836", "0.87480396", "0.874027", "0.86738855", "0.866956", "0.8638429", "0.85816944", "0.84902024", "0.83856225", "0.8375647", "0.836616...
0.87332195
15
Read and preprocess an image with data augmentation (random transform).
def read_for_training(p, augmentation=False): img = imread(TRAIN + p, mode='RGB') msk = img if mode == 'background': data = {'image': img} elif mode == 'instance' or mode == 'code': msk = imread(TRAIN_MASK + p.replace('.jpg', '.png')) data = {'image': img, 'mask': msk} if augmentation: data_aug = strong_aug()(**data) img = data_aug['image'] if 'mask' in data_aug: msk = data_aug['mask'] if mode == 'instance' or mode == 'code': img[~msk.astype(np.bool)] = 0 img, msk = size_normalization(img, msk) if mode == 'code': img = encode(img, msk) return img, msk
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def preprocess(self, img):\n img_ = image.load_img(img, target_size=(299, 299))\n img_ = image.img_to_array(img_)\n img_ = np.expand_dims(img_, axis=0)\n img_ = preprocess_input(img_)\n return img_", "def data_augmentation(image, aug):\n if (aug == \"random_crop\") and (rand...
[ "0.6944267", "0.6885695", "0.6801366", "0.6746409", "0.6730426", "0.6700084", "0.6674317", "0.6642256", "0.6604827", "0.65799797", "0.65796673", "0.6575271", "0.6572347", "0.6542871", "0.6535678", "0.6521868", "0.64719284", "0.64391285", "0.6430673", "0.6425564", "0.6418553",...
0.70998
0
Helper function to visualize mask on the top of the car
def mask_overlay(image, mask, color=(0, 255, 0)): mask = np.dstack((mask, mask, mask)) * np.array(color) mask = mask.astype(np.uint8) weighted_sum = cv2.addWeighted(mask, 0.5, image, 0.5, 0.) img = image.copy() ind = mask[:, :, 1] > 0 img[ind] = weighted_sum[ind] return img
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def show_mask(image, mask): \n plt.subplot(1,2,1)\n plt.title('image')\n plt.imshow(image)\n plt.subplot(1,2,2)\n plt.title('mask')\n plt.imshow(mask)\n plt.show()", "def mask_show(image, mask, groups, name=\"image\"):\n img = cv2.addWeighted(image, 0.4, mask, 0.6, 0)\n img = sg.mar...
[ "0.71640295", "0.67468154", "0.6488188", "0.63977045", "0.62672323", "0.6256299", "0.623426", "0.62271696", "0.6222103", "0.6217956", "0.6209555", "0.6123184", "0.6110045", "0.6090729", "0.6049397", "0.6028649", "0.59504765", "0.5926747", "0.5888969", "0.5847702", "0.5817907"...
0.0
-1
Parse the first YAML document in a stream and produce the corresponding Python object.
def load(stream, schema=None): stream_type = str(type(stream)) if stream_type not in ("<type 'unicode'>", "<type 'str'>", "<class 'str'>"): raise TypeError("StrictYAML can only read a string of valid YAML.") document = ruamelyaml.load(stream, Loader=ruamelyaml.RoundTripLoader) # Document is single item (string, int, etc.) if type(document) not in (CommentedMap, CommentedSeq): document = stream for token in ruamelyaml.scan(stream): if type(token) == ruamelyaml.tokens.TagToken: raise exceptions.TagTokenDisallowed( document, token.start_mark.line + 1, token.end_mark.line + 1 ) if type(token) == ruamelyaml.tokens.FlowMappingStartToken: raise exceptions.FlowMappingDisallowed( document, token.start_mark.line + 1, token.end_mark.line + 1 ) if type(token) == ruamelyaml.tokens.AnchorToken: raise exceptions.AnchorTokenDisallowed( document, token.start_mark.line + 1, token.end_mark.line + 1 ) if schema is None: schema = Any() return schema(document)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def read(self, stream):\n ret = yaml.load(stream)\n self.validate(ret)\n return (ret, self.make_order(ret))", "def construct_yaml_stream(in_stream):\n\n global _yaml_initialized\n\n logger.info('Request to construct yaml')\n\n if not _yaml_initialized:\n def _object_creator(loader, node,...
[ "0.7405631", "0.6758382", "0.64881027", "0.6360592", "0.63516474", "0.63164014", "0.6199864", "0.606954", "0.604542", "0.60424024", "0.60077196", "0.5979247", "0.594493", "0.5858309", "0.5854879", "0.584637", "0.584421", "0.5775051", "0.5773475", "0.5768689", "0.57418305", ...
0.6677856
2
Attention based temporal attention forward pass
def forward(self, src, src_t, seq, seq_t, seq_e, mask, vars_dict): src_ext = torch.unsqueeze(src, dim=1) # src [B, 1, D] src_e_ph = torch.zeros_like(src_ext) q = torch.cat([src_ext, src_e_ph, src_t], dim=2) # [B, 1, D + De + Dt] -> [B, 1, D] k = torch.cat([seq, seq_e, seq_t], dim=2) # [B, 1, D + De + Dt] -> [B, 1, D] mask = torch.unsqueeze(mask, dim=2) # mask [B, N, 1] mask = mask.permute([0, 2, 1]) # mask [B, 1, N] # # target-attention output, attn = self.multi_head_target(q=q, k=k, v=k, vars_dict=vars_dict, mask=mask) # output: [B, 1, D + Dt], attn: [B, 1, N] # print('src.shape', src.shape) output = output.squeeze(1) # print('output.shape', output.shape) # print('output', output) # print('output.squeeze().shape', output.shape) attn = attn.squeeze() # output = self.merger(output, src) x = torch.cat([output, src], dim=1) # x = self.layer_norm(x) x = F.relu(F.linear(x, vars_dict['w1_agg_fc'])) output = F.linear(x, vars_dict['w2_agg_fc']) return output, attn
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def forward(self, encoder_state, context, context_lens):\n attn = self.attention(context, encoder_state.squeeze(0), context_lens)\n return attn", "def _Attention(self, name, is_causal=True):\n p = self.params\n tr_atten_p = TransformerAttentionLayer.Params().Set(\n name='transformer_at...
[ "0.6917411", "0.67771304", "0.67337334", "0.64585733", "0.6420011", "0.63664645", "0.63517004", "0.63190645", "0.6295559", "0.62826264", "0.6252782", "0.6198423", "0.61942375", "0.6190378", "0.6135776", "0.61074287", "0.6046608", "0.598789", "0.59875965", "0.59709185", "0.596...
0.5559464
78
Actions before each test.
def setUp(self): self.brow = webdriver.Firefox() staging_server = os.environ.get('STAGING_SERVER') if staging_server: self.live_server_url = "http://" + staging_server
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def before_run_tests(cls):\n pass", "def before_test(self, func, *args, **kwargs):\n pass", "def do_before(self):\r\n pass", "def beforeTest(self, test):\n self.setupLoghandler()", "def before(self) -> None:\n pass", "def setUp(self):\r\n # nothing to do, all tes...
[ "0.7848565", "0.7659674", "0.7591663", "0.7281655", "0.7241673", "0.7141255", "0.70754164", "0.7027952", "0.7027952", "0.7026638", "0.70223314", "0.6992696", "0.69685715", "0.6968439", "0.6968439", "0.6968439", "0.6968439", "0.6968439", "0.6968439", "0.6968439", "0.6968439", ...
0.0
-1
Actions after each test.
def tearDown(self): self.brow.quit()
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def after_test(self, test_results):\n pass", "def after_test(self, func, *args, **kwargs):\n pass", "def after(self):\n pass", "def after(self):\n pass", "def after_all(self) -> None:", "def finished_tests(self):\n self.testing = 0", "def tearDown(self):\n\t\tprint(\"...
[ "0.83760184", "0.79627854", "0.76740867", "0.76740867", "0.764812", "0.75801444", "0.7479539", "0.7362819", "0.73584396", "0.7329822", "0.72882223", "0.7255437", "0.7153491", "0.70499015", "0.7021705", "0.6966801", "0.6941674", "0.6791313", "0.677205", "0.6720164", "0.6713851...
0.0
-1
Get servers local IP address so it can be accessed inside this network.
def print_local_ip(): spacer = '-' * 50 local_ip = gethostbyname(gethostname()) print('\n{}\nLocal IP address is: {}\n{}'.format(spacer, local_ip, spacer))
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def localip(self) :\n\t\ttry :\n\t\t\treturn self._localip\n\t\texcept Exception as e:\n\t\t\traise e", "def get_local_host_ip(self) -> str:", "def get_local_ip():\n sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n sock.connect((\"8.8.8.8\", 80))\n local_ip = sock.getsockname()[0]\n sock.c...
[ "0.8273781", "0.8249747", "0.8185857", "0.8137731", "0.80874467", "0.80454546", "0.80384547", "0.8009976", "0.7990402", "0.7969245", "0.7930696", "0.7782699", "0.77280563", "0.7713387", "0.7654462", "0.75452614", "0.75112414", "0.75089806", "0.7462935", "0.7451744", "0.744139...
0.7378908
22
Amount which will increase x until it's divisible evenly by 64
def padlen_64(x: int): return (64 - (x % 64)) % 64
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def modReduce(self, x):\n\n assert 0 <= x < pow(self.mod, 2), 'out of range.'\n q = (x * self.u) >> (2 * self.M_bit)\n r = x - q * self.mod\n while r >= self.mod:\n r -= self.mod\n return r", "def taille(x):\n n = 0\n \n while (2**n) -1 < x :\n n+=1\n...
[ "0.64682055", "0.6353813", "0.63322943", "0.6308356", "0.6298304", "0.62941134", "0.61767954", "0.61767954", "0.61669123", "0.61343306", "0.61135375", "0.60509366", "0.59431607", "0.5926209", "0.5924908", "0.5908529", "0.5902806", "0.5896249", "0.58734715", "0.5857224", "0.58...
0.6562799
0
Simulate an SHA256 ending pad (1 bit, zero bad, 64bit length)
def end_shastream(length: int): padlen = padlen_64(length + 1 + 8) return bytes([0x80]) + bytes(padlen) + int.to_bytes(length * 8, 8, 'big')
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def SHA256(self) -> _n_0_t_3[_n_0_t_9]:", "def _sha256(sha256):\n if not sha256:\n sha256 = \"0\" * 64\n\n return sha256", "def shake256(data=None, digest_size=512):\n return SpongeHash(512, digest_size, data, \"SHAKE256\", KeccakSponge, PAD_SHAKE)", "def sha256(message: bytes):\n # conver...
[ "0.7570556", "0.7199887", "0.6765323", "0.64624476", "0.6452416", "0.6417613", "0.63762766", "0.634967", "0.6248739", "0.62149316", "0.6214463", "0.61732584", "0.61626583", "0.61307865", "0.61083645", "0.6072602", "0.60649854", "0.6037192", "0.5975247", "0.5962065", "0.593303...
0.0
-1
Returns None on success, otherwise an explanation string
def test(self, values: Dict[str, Any]) -> Optional[str]: # This is always True if self.cond == '#': return None def why(cond, field, explanation) -> Optional[str]: if cond: return None return '{}: {}'.format(field, explanation) # If it's missing, it's only True if it's a missing test. if self.field not in values: # Default to ignoring id field as long as no version. if self.field == '': return why('-' not in self.value, 'id', 'unknown version {}'.format(self.value)) return why(self.cond == '!', self.field, 'is missing') # If they supply a function, hand it to them. if callable(values[self.field]): return values[self.field](self) val = str(values[self.field]) if self.cond == '!': return why(False, self.field, 'is present') elif self.cond == '=': return why(val == self.value, self.field, '!= {}'.format(self.value)) elif self.cond == '/': return why(val != self.value, self.field, '= {}'.format(self.value)) elif self.cond == '^': return why(val.startswith(self.value), self.field, 'does not start with {}'.format(self.value)) elif self.cond == '$': return why(val.endswith(self.value), self.field, 'does not end with {}'.format(self.value)) elif self.cond == '~': return why(self.value in val, self.field, 'does not contain {}'.format(self.value)) elif self.cond == '<': try: actual_int = int(val) except ValueError: return why(False, self.field, "not an integer field") try: restriction_val = int(self.value) except ValueError: return why(False, self.field, "not a valid integer") return why(actual_int < restriction_val, self.field, ">= {}".format(restriction_val)) elif self.cond == '>': try: actual_int = int(val) except ValueError: return why(False, self.field, "not an integer field") try: restriction_val = int(self.value) except ValueError: return why(False, self.field, "not a valid integer") return why(actual_int > restriction_val, self.field, "<= {}".format(restriction_val)) elif self.cond == '{': return why(val < self.value, self.field, 'is the same or ordered after {}'.format(self.value)) elif self.cond == '}': return why(val > self.value, self.field, 'is the same or ordered before {}'.format(self.value)) else: # We checked this in init! assert False
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def description():", "def describe(self):\n return ''", "def help(self):\n res = \"\"", "def _get_problem_str(self):\n return ''", "def summary_str(self):\n if not self.results:\n return self.summary.empty() or ''\n elif self.state == Ok:\n return self.s...
[ "0.6749599", "0.6595771", "0.65909255", "0.6580674", "0.6552211", "0.65474534", "0.65056944", "0.6464271", "0.6464271", "0.6463483", "0.6435495", "0.6418199", "0.6409962", "0.63947475", "0.6379907", "0.6308825", "0.62577033", "0.62099546", "0.6208194", "0.6198969", "0.6187488...
0.0
-1
Pull an Alternative from encoded string, return remainder
def decode(cls, encstr: str) -> Tuple['Alternative', str]: cond = None end_off = 0 # Swallow field up to conditiona while end_off < len(encstr): if encstr[end_off] in string.punctuation: cond = encstr[end_off] break end_off += 1 if cond is None: raise ValueError('{} does not contain any operator' .format(encstr)) field = encstr[:end_off] end_off += 1 value = '' while end_off < len(encstr): if encstr[end_off] == '|': # We swallow this end_off += 1 break if encstr[end_off] == '&': break if encstr[end_off] == '\\': end_off += 1 value += encstr[end_off] end_off += 1 return cls(field, cond, value), encstr[end_off:]
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def decode(cls, encstr: str) -> Tuple['Restriction', str]:\n alts = []\n while len(encstr) != 0:\n if encstr.startswith('&'):\n encstr = encstr[1:]\n break\n alt, encstr = Alternative.decode(encstr)\n alts.append(alt)\n return cls(...
[ "0.66574126", "0.6132067", "0.6132067", "0.5771838", "0.5631769", "0.5482572", "0.5471471", "0.54456496", "0.54365635", "0.537955", "0.5371491", "0.53414893", "0.5331267", "0.52930796", "0.52915156", "0.52808076", "0.527762", "0.5274057", "0.5274057", "0.5270972", "0.5267768"...
0.59058076
3
Turns this userreadable string into an Alternative (no escaping)
def from_str(cls, encstr: str) -> 'Alternative': encstr = re.sub(r'\s+', '', encstr) return cls(*re.split('([' + string.punctuation + '])', encstr, maxsplit=1))
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def T(value):\n return (value if isinstance(value, basestring) else\n str(value) if isinstance(value, AltText) else \"\")", "def decode(cls, encstr: str) -> Tuple['Alternative', str]:\n cond = None\n end_off = 0\n\n # Swallow field up to conditiona\n while end_off < len(encs...
[ "0.5630695", "0.5217001", "0.5198397", "0.5186945", "0.5184185", "0.51392734", "0.51312214", "0.50683737", "0.50631917", "0.5061903", "0.5048459", "0.50467837", "0.50248337", "0.49875286", "0.4931769", "0.49110556", "0.48986942", "0.48867592", "0.48742884", "0.4862726", "0.48...
0.5572365
1
Returns None on success, otherwise a string of all the failures
def test(self, values: Dict[str, Any]) -> Optional[str]: reasons = [] for alt in self.alternatives: reason = alt.test(values) if reason is None: return None reasons.append(reason) return " AND ".join(reasons)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def get_error_message(self):\n msg = 'Test case: ' + self.benchmark + '.yaml + ' + self.producer + '.yaml failed. '\n info = ''\n if not self.directory:\n info = 'No results directory found. The benchmark probably failed'\n elif not self.reports:\n info = 'No resul...
[ "0.7311255", "0.6805091", "0.6787462", "0.67572325", "0.66535556", "0.66410094", "0.66374403", "0.653866", "0.6504157", "0.64584297", "0.64362466", "0.6418307", "0.63620204", "0.6343835", "0.62825376", "0.62660265", "0.62512654", "0.6249964", "0.6241896", "0.6228709", "0.6224...
0.0
-1
Pull a Restriction from encoded string, return remainder
def decode(cls, encstr: str) -> Tuple['Restriction', str]: alts = [] while len(encstr) != 0: if encstr.startswith('&'): encstr = encstr[1:] break alt, encstr = Alternative.decode(encstr) alts.append(alt) return cls(alts), encstr
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def from_str(cls, encstr: str) -> 'Restriction':\n encstr = re.sub(r'\\s+', '', encstr)\n ret, remainder = cls.decode(encstr)\n if len(remainder) != 0:\n raise ValueError(\"Restriction had extrs characters at end: {}\"\n .format(remainder))\n retur...
[ "0.6682689", "0.5536616", "0.54848987", "0.5409332", "0.5409332", "0.5249636", "0.52139443", "0.51220363", "0.5092601", "0.5083486", "0.50243723", "0.49601397", "0.4911395", "0.48801553", "0.48710787", "0.48674506", "0.48674506", "0.48620152", "0.4848582", "0.4832647", "0.479...
0.61234236
1
Returns a Restriction from an escaped string (ignoring whitespace)
def from_str(cls, encstr: str) -> 'Restriction': encstr = re.sub(r'\s+', '', encstr) ret, remainder = cls.decode(encstr) if len(remainder) != 0: raise ValueError("Restriction had extrs characters at end: {}" .format(remainder)) return ret
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def _assign_regex(literal, regex):\n if regex:\n return regex.lower().strip()\n else:\n return r'\\b%s\\b'%literal.lower().strip()", "def interpret_requirement(string):\n string_list = split(string, sep=' ')\n \n requirement = Requirement(points, degree, majors, levels, max_non_degre...
[ "0.5168612", "0.5026671", "0.49126112", "0.48980483", "0.4877988", "0.485538", "0.48332566", "0.48306048", "0.4796996", "0.47644973", "0.4762547", "0.47521722", "0.4743869", "0.47309223", "0.47302634", "0.4718924", "0.47140232", "0.47117367", "0.4668038", "0.46525672", "0.463...
0.6378927
0
Helper to produce an id 'restriction'
def unique_id(cls, unique_id: Union[int, str], version: Optional[Union[int, str]] = None) -> 'Restriction': idstr = str(unique_id) if '-' in idstr: raise ValueError('Hyphen not allowed in unique_id {}'.format(idstr)) if version: idstr += '-{}'.format(version) # We use the empty field for this, since it's always present. return cls([Alternative('', '=', idstr)])
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def friendly_id(self):\n id = f\"{self.annotator_id}_{self.document_title.split('_')[0]}\"\n\n try: # try making an sentence identifier if there is an in_sentence attrib\n sen_id = \",\".join(str(se.element_id + 1) for se in self.in_sentence)\n id += f\"_s{sen_id}\"\n ex...
[ "0.6390797", "0.59261435", "0.5828868", "0.58210576", "0.57121724", "0.56987214", "0.56987214", "0.5654812", "0.56331956", "0.5582573", "0.5568012", "0.55624306", "0.55531055", "0.5549231", "0.55474275", "0.5540417", "0.5539157", "0.5539157", "0.5516462", "0.55037725", "0.549...
0.5554285
12
Tests the restrictions against the values dict given. Normally values are treated strings, but conditions only work if they're actually integers. Returns (True, '') if everything is good. Otherwise, returns (False, reasonstring)
def are_restrictions_met(self, values: Dict[str, Any]) -> Tuple[bool, str]:, for r in self.restrictions: reasons = r.test(values) if reasons is not None: return False, reasons return True, ''
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def test(self, values: Dict[str, Any]) -> Optional[str]:\n # This is always True\n if self.cond == '#':\n return None\n\n def why(cond, field, explanation) -> Optional[str]:\n if cond:\n return None\n return '{}: {}'.format(field, explanation)\n\...
[ "0.67283416", "0.66373456", "0.63170063", "0.6068614", "0.60020655", "0.5946913", "0.57890636", "0.5788082", "0.57537967", "0.57021195", "0.56713057", "0.5626302", "0.5622262", "0.5609995", "0.5586753", "0.55860853", "0.5585117", "0.5569001", "0.5539537", "0.5532167", "0.5508...
0.76134247
0
Perform a shallow copy
def copy(self) -> 'Rune': return self.__copy__()
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def shallow_copy(self):\n # TODO: Rename this to __copy__()?\n raise NotImplementedError(\"shallow_copy is not implemented\")", "def copy(self):\n import copy as pcopy\n return pcopy.deepcopy(self)", "def copy(self):", "def _copy_(self):\n return copy.copy(self)", "def copy(self)...
[ "0.87317777", "0.80810803", "0.79437435", "0.79085433", "0.7848419", "0.78046805", "0.7762016", "0.7748258", "0.77443546", "0.774237", "0.774237", "0.774237", "0.772365", "0.7720509", "0.76456845", "0.76456845", "0.76456845", "0.76456845", "0.76456845", "0.76456845", "0.76456...
0.0
-1
sha256.sha256 doesn't implement pickle
def __deepcopy__(self, memo=None) -> 'Rune': return Rune(self.shaobj.state[0], copy.deepcopy(self.restrictions))
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def SHA256(self) -> _n_0_t_3[_n_0_t_9]:", "def hash(obj):\n \n import hashlib\n import pickle\n \n sha = hashlib.sha256()\n sha.update(pickle.dumps(obj))\n \n return sha.hexdigest()", "def pickle_and_hash(obj: Any) -> str:\n try:\n s = dill.dumps(obj)\n except:\n rai...
[ "0.68457127", "0.6561299", "0.6373584", "0.62677026", "0.62606", "0.603708", "0.60351026", "0.60149497", "0.5985192", "0.5962576", "0.5938484", "0.59240323", "0.58729625", "0.5839949", "0.582465", "0.5806277", "0.57929254", "0.57929254", "0.57687783", "0.5719801", "0.57143664...
0.0
-1
Perform a shallow copy
def copy(self) -> 'Rune': return self.__copy__()
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def shallow_copy(self):\n # TODO: Rename this to __copy__()?\n raise NotImplementedError(\"shallow_copy is not implemented\")", "def copy(self):\n import copy as pcopy\n return pcopy.deepcopy(self)", "def copy(self):", "def _copy_(self):\n return copy.copy(self)", "def copy(self)...
[ "0.8731979", "0.80809754", "0.79425305", "0.79085165", "0.7848546", "0.7804359", "0.7762183", "0.77476215", "0.7744951", "0.77417994", "0.77417994", "0.77417994", "0.77240235", "0.7720835", "0.76460147", "0.76460147", "0.76460147", "0.76460147", "0.76460147", "0.76460147", "0...
0.0
-1
sha256.sha256 doesn't implement pickle
def __deepcopy__(self, memo=None) -> 'MasterRune': ret = MasterRune(bytes()) ret.restrictions = copy.deepcopy(self.restrictions) ret.shaobj.state = self.shaobj.state ret.shabase = self.shabase ret.seclen = self.seclen return ret
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def SHA256(self) -> _n_0_t_3[_n_0_t_9]:", "def hash(obj):\n \n import hashlib\n import pickle\n \n sha = hashlib.sha256()\n sha.update(pickle.dumps(obj))\n \n return sha.hexdigest()", "def pickle_and_hash(obj: Any) -> str:\n try:\n s = dill.dumps(obj)\n except:\n rai...
[ "0.68457127", "0.6561299", "0.6373584", "0.62677026", "0.62606", "0.603708", "0.60351026", "0.60149497", "0.5985192", "0.5962576", "0.5938484", "0.59240323", "0.58729625", "0.5839949", "0.582465", "0.5806277", "0.57929254", "0.57929254", "0.57687783", "0.5719801", "0.57143664...
0.0
-1
This is faster than adding the restrictions onebyone and checking the final authcode (but equivalent)
def is_rune_authorized(self, other: Rune) -> bool: # Make copy, as we're going to update state. sha = self.shabase.copy() totlen = self.seclen for r in other.restrictions: pad = end_shastream(totlen) sha.update(pad) totlen += len(pad) enc = bytes(r.encode(), encoding='utf8') sha.update(enc) totlen += len(enc) return other.authcode() == sha.digest()
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def validate_code(request):\n user_id = api.keystone.get_user_id(request)\n print \"USER CHECK\"\n print user_id\n user = api.keystone.user_get(request, user_id)\n user_auth_code = request.GET.get('auth_code', None)\n secret = request.GET.get('secret', None)\n\n #Generate ...
[ "0.6526628", "0.6414991", "0.60478854", "0.5907109", "0.5845477", "0.57069147", "0.5651448", "0.55606484", "0.5527734", "0.546124", "0.54302317", "0.54030454", "0.53964144", "0.5381553", "0.53508997", "0.5312594", "0.52762026", "0.52541846", "0.52534354", "0.5245636", "0.5223...
0.5466636
9
Allinone check that a runestring is valid, derives from this MasterRune and passes all its conditions against the given dictionary of values or callables
def check_with_reason(self, b64str: str, values: Dict[str, Any]) -> Tuple[bool, str]: try: rune = Rune.from_base64(b64str) except: # noqa: E722 return False, "runestring invalid" if not self.is_rune_authorized(rune): return False, "rune authcode invalid" return rune.are_restrictions_met(values)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def check_with_reason(secret: bytes, b64str: str, values: Dict[str, Any]) -> Tuple[bool, str]:\n return MasterRune(secret).check_with_reason(b64str, values)", "def test_any_rune(self):\n rule = 'alert (name:\"rune\"; regex:\".{64}\";)'\n\n tests = {\n \"A\"*64: [\"proxying connection ...
[ "0.6080785", "0.5750079", "0.5702773", "0.5655834", "0.54935133", "0.5481613", "0.5304172", "0.52878016", "0.5247526", "0.5234183", "0.523374", "0.52119046", "0.5198196", "0.51774484", "0.5176261", "0.517611", "0.51729107", "0.5167192", "0.51573974", "0.51418495", "0.5130349"...
0.64300054
0
Convenience function that the b64str runestring is valid, derives from our secret, and passes against these values. If you want to check many runes, it's more efficient to create the MasterRune first then check them, but this is fine if you're only checking one.
def check_with_reason(secret: bytes, b64str: str, values: Dict[str, Any]) -> Tuple[bool, str]: return MasterRune(secret).check_with_reason(b64str, values)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def check_with_reason(self, b64str: str, values: Dict[str, Any]) -> Tuple[bool, str]:\n try:\n rune = Rune.from_base64(b64str)\n except: # noqa: E722\n return False, \"runestring invalid\"\n if not self.is_rune_authorized(rune):\n return False, \"rune authcode...
[ "0.67954326", "0.6076462", "0.56105393", "0.55704355", "0.5488138", "0.54298264", "0.5401579", "0.5401579", "0.5336335", "0.5291665", "0.5288441", "0.5265383", "0.522915", "0.5190011", "0.51790816", "0.51719004", "0.51499397", "0.51450264", "0.51145905", "0.50659394", "0.5063...
0.7233146
0
Convenience function that the b64str runestring is valid, derives from our secret, and passes against these values. If you want to check many runes, it's more efficient to create the MasterRune first then check them, but this is fine if you're only checking one. Unlike check_with_reason(), this discards the reason and returns a simple True or False.
def check(secret: bytes, b64str: str, values: Dict[str, Any]) -> bool: return check_with_reason(secret, b64str, values)[0]
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def check_with_reason(secret: bytes, b64str: str, values: Dict[str, Any]) -> Tuple[bool, str]:\n return MasterRune(secret).check_with_reason(b64str, values)", "def check_with_reason(self, b64str: str, values: Dict[str, Any]) -> Tuple[bool, str]:\n try:\n rune = Rune.from_base64(b64str)\n ...
[ "0.8024349", "0.75399673", "0.5762778", "0.5715149", "0.56168044", "0.56168044", "0.543279", "0.54015696", "0.52972245", "0.5295794", "0.52827865", "0.5269401", "0.52549756", "0.5223828", "0.5214541", "0.5210419", "0.5160051", "0.5159024", "0.5144563", "0.5132561", "0.5131473...
0.6641542
2
Determines whether fileToCheck is an appropriately formatted FASTA file. An appropriately formatted FASTA file is returned in correctFormatting.
def main(fileToCheck, minLength=-1, maxLength=-1): # Initialise variables. lineCount = 1 # The number of the line being examined. Used for displaying error messages. protDescription = True # Whether or not we are currently expecting a line starting with >. firstLine = True # Whether or not we are currently examining the first line of the file. proteinsInFile = {} # A dictionary indexed by the protein description line of the FASTA file. # The value of each entry is the correctly formatted protein sequence corresponding to the index. # Strip off all excess whitespace, and split the string into the individual lines of the file. checking = fileToCheck.rstrip() checking = checking.lstrip() checking = checking.split('\n') for line in checking: line = line.rstrip() if firstLine: # True if we have just started parsing the file string, and haven;t yet examined any lines. if line[0] == '>': currentProt = line # Record the description line of the protein which is about to have its sequence inspected. currentSeq = '' # Initialise the sequence of the protein. protDescription = False # We are now expecting a protein sequence, not a protein description. firstLine = False else: # The first line of the file MUST be a protein description line (i.e. start with '>'). If the line was not # the beginning of a protein record, terminate the program. errorMessage = "Expected line " + str(lineCount) + " to start with a >, but instead got: " + line return 1, errorMessage elif protDescription: # This is true only if a line beginning with a '>' is expected. if line[0] == '>': # Expected a protein description line, and found a protein description line. This means that the entire sequence # of the currentProt protein has been found (i.e. we have finished inspecting the sequence of a protein, and # have found the protein to be valid). Now determine if the length of the sequence is within the user # specified bounds. if minLength == -1: if maxLength == -1: # If there are no restrictions on the protein sequence length, then record the protein and its sequence. proteinsInFile[currentProt] = currentSeq elif len(currentSeq) <= maxLength: # If there is no minimum length restriction, and the protein sequence is not longer than the maximum # sequence length permitted, then record the protein and its sequence. proteinsInFile[currentProt] = currentSeq elif len(currentSeq) >= minLength: if maxLength == -1: # If there is no maximum length restriction, and the protein sequence is not shorter than the minimum # sequence length permitted, then record the protein and its sequence. proteinsInFile[currentProt] = currentSeq elif len(currentSeq) <= maxLength: # If the protein sequence is not shorter than the minimum sequence length permitted and not longer # than the maximum length permitted, then record the protein and its sequence. proteinsInFile[currentProt] = currentSeq currentProt = line # Record the description line of the protein which is about to have its sequence inspected. currentSeq = '' # Initialise the sequence of the protein. protDescription = False # We are now expecting a protein sequence, not a protein description. else: # If the line does not begin with a '>', and it is expected to, it is possible that the amino acid sequence # is split over multiple lines. if line.isalpha(): # If every character on the line is a letter, then the line contains a valid portion of the sequence. # Add the uppercase version of the sequence portion to the sequence currently being recorded. currentSeq += line.upper() else: # If the line did not contain only letters, terminate the program. errorMessage = "Expected line " + str(lineCount) + " to start with a >, but instead got: " + line return 1, errorMessage else: # If an amino acid sequence is expected. if line.isalpha(): # If the line is all alphabetic characters, write the line out and indicate that we are expecting a # protein description line next (i.e. one beginning with a '>'). currentSeq += line.upper() protDescription = True else: # If the line did not contain only letters, terminate the program. errorMessage = "Expected line " + str(lineCount) + " to contain only letters, but instead got: " + line return 2, errorMessage lineCount += 1 # Catch the final protein from the file, and determine whether it should be recorded. if minLength == -1: if maxLength == -1: proteinsInFile[currentProt] = currentSeq elif len(currentSeq) <= maxLength: proteinsInFile[currentProt] = currentSeq elif len(currentSeq) >= minLength: if maxLength == -1: proteinsInFile[currentProt] = currentSeq elif len(currentSeq) <= maxLength: proteinsInFile[currentProt] = currentSeq if len(proteinsInFile.keys()) < 2: # There are too few protein sequences entered errorMessage = ("Not enough unique protein sequences have been entered." + " This is possibly caused by not enough sequences of the required minimum and maximum length being provided." ) return 3, errorMessage elif protDescription: # Return an indication that the FASTA file is correctly formatted. outputString = '' for i in proteinsInFile.keys(): outputString += i + '\n' + proteinsInFile[i] + '\n' return 0, outputString[:-1] else: # The file did not end with a protein sequence. errorMessage = "Reached the end of the file, but no protein sequence found for the final protein." return 3, errorMessage
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def _check_style(file_path, style_config):\n\n with open(file_path, 'r') as f:\n content = f.read()\n is_valid_header = (len(content) == 0 or content.startswith(\n PythonFormatter.standard_header))\n\n _, _, changed = yapf.yapflib.yapf_api.FormatFile(\n ...
[ "0.62929124", "0.6227019", "0.5895204", "0.56863064", "0.56821287", "0.5661317", "0.56600463", "0.5612253", "0.55521023", "0.55268717", "0.5512988", "0.5505371", "0.54996324", "0.5447883", "0.5413568", "0.5376837", "0.5368521", "0.53608316", "0.5308955", "0.52947026", "0.5244...
0.55602217
8
Parse read and quality strings from a FASTQ file with sequencing reads.
def readFastq(filename): sequences = [] qualities = [] with open(filename) as fh: while True: fh.readline() # skip name line seq = fh.readline().rstrip() #read base sequence fh.readline() # skip placeholder line qual = fh.readline().rstrip() # base quality line if len(seq) == 0: break sequences.append(seq) qualities.append(qual) return sequences, qualities
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def readFastq(filename):\n\tsequences = []\n\tqualities = []\n\twith open(filename, 'r') as f:\n\t\twhile True: \n\t\t\tf.readline() # skip name line\n\t\t\tseq = f.readline().rstrip()\n\t\t\tf.readline() # skip place holder line \n\t\t\tq = f.readline().rstrip()\n\t\t\tif len(seq) ==0:\n\t\t\t\tbreak \n\t\t\tsequ...
[ "0.72407734", "0.7033901", "0.69433504", "0.67568797", "0.6737888", "0.66820616", "0.65858674", "0.653524", "0.652288", "0.6501695", "0.6497522", "0.64846104", "0.64839154", "0.646596", "0.63651484", "0.63603467", "0.63447005", "0.6319669", "0.63027084", "0.6278591", "0.62545...
0.74991745
0
Create a hash map between kmers and readings.
def kmerHashMap(reads, k): kmers_dict = {} # loop through all reads for i in range(len(reads)): # loop read's bases, except for the last k, to obtain its kmers for j in range(1+len(reads[i])-k): kmer = reads[i][j:k+j] if kmers_dict.has_key(kmer): kmers_dict[kmer].add(i) else: kmers_dict[kmer] = set([i]) return kmers_dict
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def count_kmers_observed(read, k):\n counts = {}\n num_kmers = len(read) - k + 1\n for i in range (num_kmers):\n kmer= read[i:i+k]\n if kmer not in counts:\n counts[kmer] = 0\n counts[kmer] +=1\n return len(counts)", "def count_kmers_possible(read, k):\n num_kmers = {}\n num_kmers1 ...
[ "0.59770435", "0.5825306", "0.5625832", "0.5522428", "0.5472376", "0.5450063", "0.54420954", "0.5432603", "0.5386902", "0.5372055", "0.5325172", "0.5304393", "0.53000337", "0.5292728", "0.5285071", "0.5272437", "0.52629334", "0.5260887", "0.5257762", "0.5255245", "0.5242287",...
0.7121498
0
Loads MNIST files into 3D numpy arrays
def load_mnist(dataset="training", digits=np.arange(10), path="."): if dataset == "training": fname_img = os.path.join(path, 'train-images-idx3-ubyte') fname_lbl = os.path.join(path, 'train-labels-idx1-ubyte') elif dataset == "testing": fname_img = os.path.join(path, 't10k-images-idx3-ubyte') fname_lbl = os.path.join(path, 't10k-labels-idx1-ubyte') else: raise ValueError("dataset must be 'testing' or 'training'") flbl = open(fname_lbl, 'rb') magic_nr, size = struct.unpack(">II", flbl.read(8)) lbl = pyarray("b", flbl.read()) flbl.close() fimg = open(fname_img, 'rb') magic_nr, size, rows, cols = struct.unpack(">IIII", fimg.read(16)) img = pyarray("B", fimg.read()) fimg.close() ind = [ k for k in range(size) if lbl[k] in digits ] N = len(ind) images = zeros((N, rows, cols), dtype=uint8) labels = zeros((N, 1), dtype=int8) for i in range(len(ind)): images[i] = array(img[ ind[i]*rows*cols : (ind[i]+1)*rows*cols ]).reshape((rows, cols)) labels[i] = lbl[ind[i]] return images, labels
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def load_mnist(kind='train'):\r\n with open('%s-labels.idx1-ubyte' % kind, 'rb') as lbpath:\r\n magic, n = struct.unpack('>II', lbpath.read(8))\r\n labels = np.fromfile(lbpath, dtype=np.uint8)\r\n\r\n with open('%s-images.idx3-ubyte' % kind, 'rb') as imgpath:\r\n magic, num, rows, cols =...
[ "0.6996989", "0.69236135", "0.68585235", "0.6848802", "0.68018305", "0.6801796", "0.6785937", "0.67511636", "0.6737762", "0.6649627", "0.6620649", "0.6572148", "0.65664387", "0.6564884", "0.6544595", "0.65435225", "0.6539307", "0.65093267", "0.6489088", "0.6486471", "0.646639...
0.64559424
21
Calculate the squared L2 norm of the pattern.
def l2_norm(pattern): return np.linalg.norm(pattern)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def L2_norm(self):\n analyticals = self.analytical(self.x_values, self.C, self.D)\n error = analyticals - self.numerical\n self.L2 = np.sqrt((1/self.gp)*np.sum(error**2))", "def L2norm(m):\n return np.sqrt(np.sum(m**2))", "def squared_norm(self) -> float:\n return self.__real**2 ...
[ "0.7689054", "0.7469105", "0.7411847", "0.7393104", "0.73873013", "0.73019034", "0.7256206", "0.72420824", "0.71961755", "0.7140405", "0.71325195", "0.71182483", "0.71150076", "0.7069896", "0.7034822", "0.7023806", "0.7019462", "0.69990593", "0.69920164", "0.69680566", "0.695...
0.8329601
0
Calculate the l2 norm of a stack of patterns.
def l2_norm_batch(pattern_stack): return np.linalg.norm(pattern_stack, axis=0)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def l2_norm(pattern):\n return np.linalg.norm(pattern)", "def l2(weights):\n\treturn np.sqrt(np.sum(weights * weights))", "def l2_norm(params):\n flattened, _ = flatten(params)\n return np.dot(flattened, flattened)", "def L2norm(m):\n return np.sqrt(np.sum(m**2))", "def L2_norm(self):\n ...
[ "0.74098885", "0.6808609", "0.67808706", "0.67259216", "0.65520793", "0.65451896", "0.6460118", "0.64029825", "0.6392266", "0.62797666", "0.627647", "0.626877", "0.62292206", "0.6221982", "0.6214867", "0.62103754", "0.61965305", "0.61522037", "0.6128999", "0.6110056", "0.6074...
0.83394605
0
Calculate the inner product of the two patterns as a vecter.
def inner_product(pattern_one, pattern_two): return np.sum(np.multiply(pattern_one, pattern_two))
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def inner_product_batch(pattern_stack_one, pattern_num_one, pattern_stack_two, pattern_num_two):\n\n \"\"\"\n Notice that the two stacks can be different. So we can not deduce the lower triangular pattern from the \n other half.\n \"\"\"\n holder = np.zeros((pattern_num_one, pattern_num_two))\n f...
[ "0.6906152", "0.6847398", "0.68069786", "0.67931485", "0.6750435", "0.6661231", "0.665229", "0.6584153", "0.6543558", "0.6477087", "0.645507", "0.64223343", "0.64149445", "0.64062977", "0.64052427", "0.6394551", "0.6389129", "0.6387153", "0.6369647", "0.6364393", "0.6364216",...
0.83498394
0
Calculate the inner product pair of each pattern in batch one and batch two. Notice that the pattern_stack_one variable represent the pattern along the zero dimension while the pattern_stack_two variable represent patterns along dimension one in the final distance matrix.
def inner_product_batch(pattern_stack_one, pattern_num_one, pattern_stack_two, pattern_num_two): """ Notice that the two stacks can be different. So we can not deduce the lower triangular pattern from the other half. """ holder = np.zeros((pattern_num_one, pattern_num_two)) for l in range(pattern_num_one): for m in range(pattern_num_two): holder[l, m] = np.sum(np.multiply(pattern_stack_one[l], pattern_stack_two[m])) return holder
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def inner_product(pattern_one, pattern_two):\n\n return np.sum(np.multiply(pattern_one, pattern_two))", "def l2_norm_batch(pattern_stack):\n\n return np.linalg.norm(pattern_stack, axis=0)", "def generate_pattern_grid(words1, words2):\n # Convert word lists to integer arrays\n w1, w2 = (\n np...
[ "0.773317", "0.5649336", "0.5526998", "0.54341394", "0.53960305", "0.5378274", "0.5336186", "0.5309336", "0.529776", "0.5289525", "0.5283448", "0.52754015", "0.52056116", "0.5135578", "0.50863296", "0.5050334", "0.5024294", "0.49954486", "0.4992397", "0.49735647", "0.49717188...
0.87116134
0
This function extract the squared l2 norm from the inner product matrix.
def l2_square_from_inner_product(matrix): return np.diag(matrix)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def inner_product_to_normalized_L2_square(matrix):\n\n length = matrix.shape[0]\n norm = np.divide(1, np.sqrt(l2_square_from_inner_product(matrix)))\n\n normalized_inner_product = np.multiply(np.multiply(np.reshape(norm, [length, 1]), matrix),\n np.reshape(norm, [...
[ "0.8038655", "0.79935986", "0.7481027", "0.7333756", "0.71862626", "0.7168722", "0.71422154", "0.71272767", "0.7005889", "0.6986283", "0.6936558", "0.689807", "0.6859919", "0.68299115", "0.6818152", "0.678622", "0.67799747", "0.6730021", "0.67066455", "0.6701476", "0.6701306"...
0.7382337
3
Turns the inner product matrix into the |pattern1 pattern2|_{2}^2 matrix. The matrix has to be a square matrix
def inner_product_to_L2_square(matrix): length = matrix.shape[0] squared_norm = np.reshape(np.diag(matrix), (length, 1)) return squared_norm + np.transpose(squared_norm) - 2 * matrix
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def inner_product(pattern_one, pattern_two):\n\n return np.sum(np.multiply(pattern_one, pattern_two))", "def inner_product_batch(pattern_stack_one, pattern_num_one, pattern_stack_two, pattern_num_two):\n\n \"\"\"\n Notice that the two stacks can be different. So we can not deduce the lower triangular pa...
[ "0.74826276", "0.7294018", "0.6634914", "0.6595926", "0.62142396", "0.5985415", "0.59326464", "0.58786714", "0.5865172", "0.5857749", "0.58491534", "0.5798571", "0.5797253", "0.57930493", "0.57865286", "0.57813066", "0.57709336", "0.57322204", "0.5704064", "0.5663638", "0.565...
0.6709533
2
Turns the inner product matrix into the |pattern1 pattern2|_{2}^2 matrix. Here the pattern is normalized. Therefore, it can be reformulated into |pattern1 pattern2|_{2}^2 = 2 2 / |pattern1||pattern2|
def inner_product_to_normalized_L2_square(matrix): length = matrix.shape[0] norm = np.divide(1, np.sqrt(l2_square_from_inner_product(matrix))) normalized_inner_product = np.multiply(np.multiply(np.reshape(norm, [length, 1]), matrix), np.reshape(norm, [1, length])) return 2 - 2 * normalized_inner_product
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def inner_product(pattern_one, pattern_two):\n\n return np.sum(np.multiply(pattern_one, pattern_two))", "def inner_product_batch(pattern_stack_one, pattern_num_one, pattern_stack_two, pattern_num_two):\n\n \"\"\"\n Notice that the two stacks can be different. So we can not deduce the lower triangular pa...
[ "0.7459909", "0.69026655", "0.62501264", "0.59727603", "0.58457905", "0.56935406", "0.56712896", "0.5659509", "0.5638323", "0.562021", "0.55866134", "0.5575207", "0.5560609", "0.55025274", "0.5491025", "0.5439844", "0.5381539", "0.53541124", "0.5343363", "0.53310347", "0.5323...
0.5993504
3
Apply np.exp( matrix/two_sigma_square) elementwise.
def gaussian_dense(matrix, two_sigma_square): return np.exp(- matrix / two_sigma_square)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def exp(tensor):\n return _elementary_op(tensor, np.exp, np.exp)", "def expval(op, dm):\n return np.tensordot(op, dm, ([0, 1], [0, 1]))", "def Exp(A, B):\n return A.dot(expm(B))", "def kernel_sqExp(a,b, ls=1, sv=1):\n a = a.T/ls\n b = b.T/ls\n D, n = np.shape(a)\n d, m = np.shape(b)\n s...
[ "0.60777706", "0.6070397", "0.6037772", "0.60048586", "0.59793174", "0.58501387", "0.58492404", "0.58091897", "0.57963014", "0.57812047", "0.57540333", "0.57262975", "0.57174045", "0.5708458", "0.5661374", "0.5589162", "0.55674833", "0.5548229", "0.5532804", "0.5519702", "0.5...
0.7608249
0
Each row of the matrix, let's say the jth row, represents the distance between the other data point from the jth point. This function returns the indexes for the points with the smallest distances with respect to each point represented by that specified row. By row, I mean the 0th dimension. Also notice that this function does not include the target particle, i.e. the diagonal element along the matrix is set to zero.
def nearest_points_indexes_without_self(matrix, num_to_keep): # Set the diagonal to 0 np.fill_diagonal(matrix, 0) # Get the position for the resulted values sort_arg = np.argsort(matrix, axis=1) return sort_arg[:, : num_to_keep]
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def nearest_min(dist_matrix):\n # much faster than np.where\n i, j = np.unravel_index(\n np.argmin(dist_matrix), \n dims=dist_matrix.shape\n )\n return i, j", "def nearest_points_indexes_with_self(matrix, num_to_keep):\n\n # Set the diagonal to 1\n np.fill_diagonal(matrix, 1)\n ...
[ "0.76758415", "0.73902124", "0.64999825", "0.6483356", "0.6479489", "0.64227754", "0.6417629", "0.6413701", "0.6329621", "0.63124496", "0.6312059", "0.6303333", "0.6287571", "0.62725973", "0.6206513", "0.6193971", "0.61772275", "0.61472964", "0.6100118", "0.60979205", "0.6076...
0.72165185
2
Each row of the matrix, let's say the jth row, represents the distance between the other data point from the jth point. This function returns the indexes for the points with the smallest distances with respect to each point represented by that specified row. By row, I mean the 0th dimension. Also notice that this function includes the target particle, i.e. the diagonal element along the matrix is set to 1.
def nearest_points_indexes_with_self(matrix, num_to_keep): # Set the diagonal to 1 np.fill_diagonal(matrix, 1) # Get the position for the resulted values sort_arg = np.argsort(matrix, axis=1) return sort_arg[:, : num_to_keep]
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def nearest_min(dist_matrix):\n # much faster than np.where\n i, j = np.unravel_index(\n np.argmin(dist_matrix), \n dims=dist_matrix.shape\n )\n return i, j", "def nearest_points_indexes_without_self(matrix, num_to_keep):\n\n # Set the diagonal to 0\n np.fill_diagonal(matrix, 0)\n...
[ "0.76846826", "0.7152678", "0.65159774", "0.6458269", "0.64570606", "0.6453487", "0.64491487", "0.6418172", "0.6344188", "0.6331945", "0.62991154", "0.62834746", "0.62771547", "0.62474954", "0.6215967", "0.6195537", "0.6191709", "0.6147389", "0.6129545", "0.6113139", "0.60623...
0.7358082
1
Each row of the matrix, let's say the jth row, represents the distance between the other data point from the jth point. This function returns the indexes for the points with the smallest distances with respect to each point represented by that specified row. By row, I mean the 0th dimension. Also notice that this function does not include the target particle, i.e. the diagonal element along the matrix is set to zero.
def nearest_points_values_without_self(matrix, num_to_keep): # Set the diagonal to 0 np.fill_diagonal(matrix, 0) # Get the position for the resulted values sort = np.sort(matrix, axis=1) return sort[:, : num_to_keep]
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def nearest_min(dist_matrix):\n # much faster than np.where\n i, j = np.unravel_index(\n np.argmin(dist_matrix), \n dims=dist_matrix.shape\n )\n return i, j", "def nearest_points_indexes_with_self(matrix, num_to_keep):\n\n # Set the diagonal to 1\n np.fill_diagonal(matrix, 1)\n ...
[ "0.7677283", "0.7389674", "0.7215832", "0.65018827", "0.64853066", "0.6480093", "0.64236856", "0.6417016", "0.64140975", "0.6329937", "0.63131666", "0.63109416", "0.63027555", "0.62869954", "0.6206853", "0.6192381", "0.6176218", "0.61489695", "0.6099502", "0.60955817", "0.607...
0.62730277
14
Each row of the matrix, let's say the jth row, represents the distance between the other data point from the jth point. This function returns the indexes for the points with the smallest distances with respect to each point represented by that specified row. By row, I mean the 0th dimension. Also notice that this function includes the target particle, i.e. the diagonal element along the matrix is set to 1.
def nearest_points_values_with_self(matrix, num_to_keep): # Set the diagonal to 1 np.fill_diagonal(matrix, 1) # Get the position for the resulted values sort = np.sort(matrix, axis=1) return sort[:, : num_to_keep]
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def nearest_min(dist_matrix):\n # much faster than np.where\n i, j = np.unravel_index(\n np.argmin(dist_matrix), \n dims=dist_matrix.shape\n )\n return i, j", "def nearest_points_indexes_with_self(matrix, num_to_keep):\n\n # Set the diagonal to 1\n np.fill_diagonal(matrix, 1)\n ...
[ "0.76830524", "0.7358047", "0.715276", "0.6513678", "0.64565593", "0.645209", "0.64473367", "0.64161915", "0.6344284", "0.6331053", "0.629967", "0.6284017", "0.62775195", "0.6246845", "0.6215876", "0.6197371", "0.61904216", "0.614493", "0.6127443", "0.61131895", "0.6061455", ...
0.6456699
4
Convert the degree vector to degree function.
def degree_vector_to_matrix(vector): return np.diag(vector)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def vecToFunc(vector):\n def f(x):\n f = 0\n for i in range(len(vector)):\n f += vector[i]*x**i\n return f\n return f", "def degree_v(self):\n return self._degree_v", "def degree(x):\n return x*(180.0/math.pi)", "def laplacian(degree_vector, weight_matrix):\n ...
[ "0.6630002", "0.63732994", "0.61321235", "0.608381", "0.6005241", "0.600304", "0.5996289", "0.5975939", "0.5958366", "0.5938791", "0.5896974", "0.5866529", "0.58305264", "0.58234054", "0.58143467", "0.5772291", "0.5767484", "0.57465386", "0.5737111", "0.5736712", "0.5721935",...
0.58353925
12
Construct the fundamental Laplacian matrix.
def laplacian(degree_vector, weight_matrix): return np.diag(degree_vector) - weight_matrix
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def _get_Laplacian_matrix(self, X):\n self.laplacian_mat, self.laplacian_sym_mat, self.laplacian_weights = self.laplacian.compute_laplacian(\n self.get_Affinity_matrix(X)\n )", "def LaplacianMatrix(adjmatrix):\n if adjmatrix.dtype in [np.uint, np.uint0, np.uint8, np.u...
[ "0.680923", "0.6638274", "0.62569284", "0.62069863", "0.61390823", "0.6101195", "0.59771115", "0.58065456", "0.5798872", "0.5760791", "0.5729921", "0.5715687", "0.56979316", "0.5615754", "0.55505806", "0.55295897", "0.55295897", "0.55002135", "0.5498201", "0.5496341", "0.5495...
0.0
-1
Construct the normalized laplacian matrix.
def normalized_laplacian(degree_vector, weight_matrix, length): holders = np.zeros((length, 1)) holders[:, 0] = 1 / degree_vector return np.eye(length) - holders * weight_matrix
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def laplacian_matrix(A, normalized=False):\n n, m = A.shape\n D = degree_matrix(A)\n L = D - A\n if normalized:\n degs = _flat(A.sum(axis=1))\n rootD = sps.spdiags(np.power(degs, -1 / 2), [0], n, n, format=\"csr\")\n L = rootD * L * rootD\n return L", "def normalize(self, lam)...
[ "0.6907984", "0.6711874", "0.62322444", "0.6217343", "0.620613", "0.6196674", "0.6158735", "0.6132494", "0.61195916", "0.61195916", "0.6036492", "0.594732", "0.59065795", "0.5906229", "0.58959603", "0.5889874", "0.5884998", "0.58620787", "0.5861111", "0.5846933", "0.58036464"...
0.6199283
5
Construct the normalized laplacian matrix.
def symmetrized_normalized_laplacian(degree_vector, weight_matrix, length): holders = np.zeros((length, 1)) holders[:, 0] = np.sqrt(1 / degree_vector) return np.eye(length) - holders * weight_matrix * holders.T
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def laplacian_matrix(A, normalized=False):\n n, m = A.shape\n D = degree_matrix(A)\n L = D - A\n if normalized:\n degs = _flat(A.sum(axis=1))\n rootD = sps.spdiags(np.power(degs, -1 / 2), [0], n, n, format=\"csr\")\n L = rootD * L * rootD\n return L", "def normalize(self, lam)...
[ "0.6905368", "0.6712484", "0.6235044", "0.62139124", "0.62099594", "0.6200239", "0.61991894", "0.6155274", "0.6130805", "0.6119615", "0.6119615", "0.6039203", "0.594853", "0.5903943", "0.5903158", "0.58970135", "0.5886368", "0.58848", "0.58638287", "0.58587956", "0.58482677",...
0.56505066
34
Solve for several eigenvectors.
def solve_for_eigenvectors(matrix, num, mode="general"): # Construct a sparse matrix if mode == "general": return linalg.eigs(matrix, num) if mode == "symmetric": return linalg.eigsh(matrix, num)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def eigsolve(self,**kwargs):\n return eigsolve(self,**kwargs)", "def _solve_eigen(self, X, y):\n self.means_, self.neighbor_means_ = _class_means_and_neighbor_means(\n X, y, self.within_between_ratio, self.nearest_neighbor_ratio)\n \n Sw = _class_cov(X, y) # within class co...
[ "0.72855383", "0.6691216", "0.66405857", "0.661532", "0.6592952", "0.6520123", "0.6501074", "0.6423186", "0.64160115", "0.6396994", "0.63655776", "0.6349273", "0.63411045", "0.633906", "0.63198537", "0.62777245", "0.62247896", "0.6177474", "0.61190665", "0.6048089", "0.603536...
0.6650587
2
Returns weight and bias tensors for each layer of the RNN. These tensors are views on the underlying weight buffer allocated by CuDNN.
def get_parameters(fn, handle, weight_buf): cudnn_methods = [ cudnn.lib.cudnnGetRNNLinLayerMatrixParams, cudnn.lib.cudnnGetRNNLinLayerBiasParams ] params = [] num_linear_layers = _num_linear_layers(fn) num_layers = fn.num_directions * fn.num_layers for layer in range(num_layers): layer_params = [] for cudnn_method in cudnn_methods: for linear_id in range(num_linear_layers): lin_layer_mat_desc = cudnn.FilterDescriptor() matrix_pointer = ctypes.c_void_p() check_error(cudnn_method( handle, fn.rnn_desc, layer, fn.x_descs[0], fn.w_desc, ctypes.c_void_p(weight_buf.data_ptr()), linear_id, lin_layer_mat_desc, ctypes.byref(matrix_pointer))) data_type = ctypes.c_int() format = ctypes.c_int() nb_dims = ctypes.c_int() min_dim = 3 filter_dim_a = torch.IntTensor(min_dim) check_error(cudnn.lib.cudnnGetFilterNdDescriptor( lin_layer_mat_desc, min_dim, ctypes.byref(data_type), ctypes.byref(format), ctypes.byref(nb_dims), ctypes.c_void_p(filter_dim_a.data_ptr()))) filter_dim_a.resize_(nb_dims.value) elem_size = cudnn._sizeofmap[fn.datatype] offset_bytes = (matrix_pointer.value - weight_buf.data_ptr()) assert(offset_bytes % elem_size == 0) offset = offset_bytes // elem_size # for all the RNN types provided by CUDNN, all the ih weights # are the same size and are allocated in a contiguous chunk # (same for the hh weights, and the ih and hh biases). # Since we're storing all the weights in a single tensor anyway, # might as well merge the CUDNN ones into a single tensor as well if linear_id == 0 or linear_id == num_linear_layers / 2: assert(filter_dim_a.prod() == filter_dim_a[0]) param = fn.weight_buf.new().set_( weight_buf.storage(), offset, filter_dim_a[0] * num_linear_layers // 2, filter_dim_a[2]) layer_params.append(param) else: assert(cur_offset == offset) cur_offset = offset + filter_dim_a[0] params.append(layer_params) return params
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def process_weights_and_bias(self, rnn_weights, rnn_props):\n # from code of tensorflow GRU cell, it can be known that shape of hidden_kernel(or candidate_kernel)\n # is (input_size+hidden_unit, hidden_unit)\n hidden_size = rnn_weights[\"hidden_kernel\"].value.shape[1]\n input_size = rn...
[ "0.7037132", "0.6992914", "0.695443", "0.69183373", "0.68530166", "0.6803836", "0.6534791", "0.64984447", "0.64839584", "0.64703405", "0.6404171", "0.6397448", "0.63523", "0.6348087", "0.6256905", "0.62384343", "0.62384343", "0.62112504", "0.62057334", "0.6160526", "0.6132221...
0.60313946
34
Redirect to home page on url /
def index(): return redirect(url_for("home"))
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def home_page():\n return redirect(url_for(_DEFAULT_ROUTE, _external=True))", "def homepage():\n return redirect('index.html')", "def homepage():\n if g.user:\n return redirect(f\"/user/{g.user.id}\")\n else:\n return redirect(\"/landing\")", "def start_page():\n if not _home:\n ...
[ "0.8391641", "0.80959", "0.8045699", "0.8035703", "0.8035703", "0.78215", "0.7814849", "0.7806786", "0.75715935", "0.755005", "0.755005", "0.755005", "0.745654", "0.7446087", "0.73788244", "0.7322582", "0.73209256", "0.7203898", "0.71697754", "0.71356803", "0.7109369", "0.7...
0.77726823
8
Renders the index template
def home(): this_dir = os.path.dirname(__file__) home_file = app.config['HOME_PAGE_FOLDER'] + 'homepage.html' try: homepage = open(os.path.join(this_dir, home_file), "r").read() # Store configuration file values except FileNotFoundError: homepage = '' # Keep preset values resp = make_response(render_template("home.html", page="index", homedoc=homepage, err=request.args.get('err', default=None))) if request.cookies.get('lang') is None: lang = get_locale() resp.set_cookie('lang', lang) return resp
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def index(self):\n\t\treturn render_template('index.html')", "def index():\r\n return render_template('index.html')", "def index(self):\n return render_template('main/index.html')", "def index():\n return render_template('index.html')", "def index():\n return render_temp...
[ "0.8663074", "0.8416551", "0.8395232", "0.8383464", "0.83140826", "0.83140826", "0.8239054", "0.82325274", "0.8220168", "0.82151866", "0.82151866", "0.8183771", "0.8143425", "0.808803", "0.808803", "0.808803", "0.808803", "0.808803", "0.808803", "0.808803", "0.808803", "0.8...
0.0
-1
Function to modify the homepage
def modify_homepage(): this_dir = os.path.dirname(__file__) home_file = app.config['HOME_PAGE_FOLDER'] + 'homepage.html' value = "" if request.form.get("newHome"): value = request.form.get("newHome") if not os.path.isdir(os.path.join(this_dir, app.config['HOME_PAGE_FOLDER'])): os.mkdir(os.path.join(this_dir, app.config['HOME_PAGE_FOLDER'])) homeFile= open(os.path.join(this_dir, home_file), "w+") homeFile.write(value) homeFile.flush() files = request.files.getlist("Attachments") for file in files: print(file.filename, file=sys.stdout) nameFile = secure_filename(file.filename) file.save(os.path.join(this_dir, app.config['HOME_PAGE_FOLDER'], nameFile)) return jsonify(result=True)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def homepage():\n\treturn render_template(\"home/a_homepage.html\", title=\"Welcome\")", "def homepage():\n\n return render_template('rosemead_homepage.html')", "def homepage():\n return render_template('home/index.html', \n title=\"Bem vindo!\")", "def a_homepage():\n\n\tret...
[ "0.7403166", "0.7383433", "0.7320676", "0.730273", "0.722838", "0.722588", "0.7190989", "0.71861947", "0.7157216", "0.7157216", "0.71296996", "0.71152425", "0.7102618", "0.7062718", "0.7043081", "0.6962566", "0.69548315", "0.6911093", "0.69107646", "0.6907873", "0.6875526", ...
0.0
-1
Generate an identity key pair. Clients should only do this once, at install time. the generated IdentityKeyPair.
def generateIdentityKeyPair(): keyPair = Curve.generateKeyPair() publicKey = IdentityKey(keyPair.getPublicKey()) serialized = '0a21056e8936e8367f768a7bba008ade7cf58407bdc7a6aae293e2c' \ 'b7c06668dcd7d5e12205011524f0c15467100dd603e0d6020f4d293' \ 'edfbcd82129b14a88791ac81365c' serialized = binascii.unhexlify(serialized.encode()) identityKeyPair = IdentityKeyPair(publicKey, keyPair.getPrivateKey()) return identityKeyPair # return IdentityKeyPair(serialized=serialized)
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def gen_key_pair(self, keysize, cb):\n\n def gen_key_pair_pub_cb(data, ctx):\n if not data:\n warning('keymanagement: Could not generate a key pair\\n')\n cb(None, None)\n else:\n cb(ctx, data)\n\n def gen_key_pair_priv_cb(data, ctx):...
[ "0.71120954", "0.68204904", "0.65850353", "0.6553852", "0.65218014", "0.6443924", "0.6378423", "0.63755655", "0.6358998", "0.6324435", "0.63147116", "0.6309187", "0.62952316", "0.6251726", "0.61868006", "0.61828184", "0.61474425", "0.6133282", "0.61287004", "0.60888094", "0.6...
0.8180875
0
Generate a registration ID. Clients should only do this once, at install time.
def generateRegistrationId(): regId = KeyHelper.getRandomSequence() return regId
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def generate_id():\n return uuid4().get_hex()", "def generateID(self):\n\n return str(uuid.uuid1())", "def get_id(self) -> str:\n return self._register_id", "def makeid(cls):\n return str(uuid.uuid4().hex)", "def generate_id():\n\treturn \"%s-%s\" % (str(uuid.uuid4())[:4],random...
[ "0.7785231", "0.7583207", "0.74686027", "0.74049723", "0.7362628", "0.72884035", "0.72758955", "0.72758955", "0.7264104", "0.7262016", "0.72611034", "0.72470003", "0.7220589", "0.721949", "0.7148431", "0.71448946", "0.7102137", "0.7092246", "0.70777285", "0.7075378", "0.70580...
0.8603011
0
Generate a list of PreKeys. Clients should do this at install time, and subsequently any time the list of PreKeys stored on the server runs low. PreKey IDs are shorts, so they will eventually be repeated. Clients should store PreKeys in a circular buffer, so that they are repeated as infrequently as possible. start The starting PreKey ID, inclusive. count The number of PreKeys to generate. the list of generated PreKeyRecords.
def generatePreKeys(start, count): results = [] start -= 1 for i in range(0, count): preKeyId = ((start + i) % (Medium.MAX_VALUE - 1)) + 1 results.append(PreKeyRecord(preKeyId, Curve.generateKeyPair())) return results
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def generate_keys(self):\n self.keys = []\n key = string_to_bit_array(self.passwd)\n key = self.permutation(key, CP_1) # Perform initial permutation on the key\n g, d = split_into_n(key, 28) # Split into g (LEFT) & d (RIGHT)\n for i in range(16): # Apply the 16 rounds\n ...
[ "0.6100436", "0.57589746", "0.5668012", "0.56462705", "0.5632386", "0.55703026", "0.5561076", "0.5519232", "0.5507431", "0.5470912", "0.546842", "0.54056185", "0.52409744", "0.5236303", "0.5193606", "0.5192819", "0.51398957", "0.50818324", "0.5079338", "0.5055663", "0.5039773...
0.87624663
0