function
stringlengths
11
56k
repo_name
stringlengths
5
60
features
list
def buildbounds(self, verbose = True): """ Build bounds for bok. By default I will make those bounds as wide as possible, still respecting epsilon. The parameter epsilon is the minimum distance two knots can have. If you give me a window size, I will not make the bounds as wide as possible, but only put them ...
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def bok(self, bokmethod="BF", verbose=True, trace=False): """ We optimize the positions of knots by some various techniques. We use fixed bounds for the exploration, run buildbounds (with low epsilon) first. This means that I will not move my bounds.
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def score(intknots, index, value): modifknots = intknots.copy() modifknots[index] = value return si.splrep(self.datapoints.jds, self.datapoints.mags, w=weights, xb=None, xe=None, k=self.k, task=-1, s=None, t=modifknots, full_output=1, per=0, quiet=1)[1]
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def target(value): return score(intknots, i, value)
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def target(modifknots):
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def getintt(self): """ Returns the internal knots (i.e., not even the datapoints extrema) This is what you need to feed into splrep ! There are nint - 1 such knots """ return self.t[(self.k+1):-(self.k+1)].copy() # We cut the outer knots.
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def getinttex(self): """ Same as above, but we include the extremal points "once". """ return self.t[(self.k):-(self.k)].copy()
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def knotstats(self): """ Returns a string describing the knot spacing """ knots = self.getinttex() spacings = knots[1:] - knots[:-1] return " ".join(["%.1f" % (spacing) for spacing in sorted(spacings)])
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def setintt(self, intt): """ Give me some internal knots (not even containing the datapoints extrema), and I build the correct total knot vector t for you. I add the extremas, with appropriate multiplicity.
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def setinttex(self, inttex): """ Including extremal knots """ #pro = self.datapoints.jds[0] * np.ones(self.k) #post = self.datapoints.jds[-1] * np.ones(self.k) pro = inttex[0] * np.ones(self.k) post = inttex[-1] * np.ones(self.k)
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def getnint(self): """ Returns the number of intervals """ return(len(self.t) - 2* (self.k + 1) + 1)
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def getc(self, m=0): """ Returns all active coefficients of the spline, the ones it makes sense to play with. The length of this guy is number of intervals - 2 ! """ return self.c[m:-(self.k + 1 + m)].copy()
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def setc(self, c, m=0): """ Puts the coeffs from getc back into place. """ self.c[m:-(self.k + 1 + m)] = c
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def getco(self, m=0): """ Same as getc, but reorders the coeffs in a way more suited for nonlinear optimization """ c = self.getc(m=m) mid = int(len(c)/2.0) return np.concatenate([c[mid:], c[:mid][::-1]])
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def setco(self, c, m=0): """ The inverse of getco. """ mid = int(len(c)/2.0) self.setc(np.concatenate([c[mid+1:][::-1], c[:mid+1]]), m=m)
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def setcflat(self, c): """ Give me coeffs like those from getc(m=1), I will set the coeffs so that the spline extremas are flat (i.e. slope = 0). """
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def setcoflat(self, c): """ idem, but for reordered coeffs. """ mid = int(len(c)/2.0) self.setcflat(np.concatenate([c[mid:][::-1], c[:mid]]))
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def r2(self, nostab=True, nosquare=False): """ Evaluates the spline, compares it with the data points and returns a weighted sum of residuals r2.
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def tv(self): """ Returns the total variation of the spline. Simple ! http://en.wikipedia.org/wiki/Total_variation
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def optc(self): """ Optimize the coeffs, don't touch the knots This is the fast guy, one reason to use splines :-) Returns the chi2 in case you want it (including stabilization points) !
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def optcflat(self, verbose = False): """ Optimizes only the "border coeffs" so to get zero slope at the extrema Run optc() first ... This has to be done with an iterative optimizer """
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def setp(p): full[[0, 1, -2, -1]] = p self.setcflat(full)
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def errorfct(p): setp(p) return self.r2(nostab=False) # To get the same as optc would return !
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def eval(self, jds = None, nostab = True): """ Evaluates the spline at jds, and returns the corresponding mags-like vector. By default, we exclude the stabilization points ! If jds is not None, we use them instead of our own jds (in this case excludestab makes no sense) """ if jds is None: if nostab: ...
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def display(self, showbounds = True, showdatapoints = True, showerrorbars=True, figsize=(16,8)): """ A display of the spline object, with knots, jds, stab points, etc. For debugging and checks. """
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def fit(lcs, knotstep=20.0, n=None, knots=None, stab=True, stabext=300.0, stabgap=20.0, stabstep=5.0, stabmagerr=-2.0, stabrampsize=0, stabrampfact=1.0, bokit=1, bokeps=2.0, boktests=5, bokwindow=None, k=3, verbose=True): """ The highlevel function to make a spline fit.
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def seasonknots(lcs, knotstep, ingap, seasongap=60.0): """ A little helper to get some knot locations inside of seasons only
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def r2(lcs, spline, nosquare=False): """ I do not modify the spline (not even its datapoints) ! Just evaluate the quality of the match, returning an r2 (without any stab points, of course). This is used if you want to optimize something on the lightcurves without touching the spline.
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def mltv(lcs, spline, weight=True): """ Calculates the TV norm of the difference between a lightcurve (disregarding any microlensing !) and the spline. I return the sum over the curves in lcs.
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def optcmltv(lcs, spline, verbose=True): """ I will optimize the coefficients of the spline so to minimize the mltv. I do not use the microlensing of the lcs at all !
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def setc(c): spline.setc(c, m=2)
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def errorfct(c): setc(c) (tv, dist) = mltv(lcs, spline, weight=False) print "put weight" return tv + 0.1*spline.tv()
COSMOGRAIL/PyCS
[ 4, 4, 4, 14, 1454429374 ]
def serve(procs, port=None, addr='tcp://*', context=None, debug=False): """Make some procedures available for remote calls via ØMQ.""" if context is None: context = zmq.Context.instance() with context.socket(zmq.REP) as socket: if port is None: port = socket.bind_to_random_port...
doctaphred/phredutils
[ 8, 1, 8, 12, 1453410109 ]
def __init__(self, file_loc, data_type='c', init_params=None, block_unit_size=0, disk_sector_size=0, open_c_reader=True, **kwargs): """ :param file_loc: location of the file :param da...
1a1a11a/mimircache
[ 33, 14, 33, 5, 1460551932 ]
def read_complete_req(self): """ read the complete line, including request and its all related info :return: a list of all info of the request """ super().read_one_req() line = self.trace_file.readline().decode() while line and len(line.strip()) == 0: ...
1a1a11a/mimircache
[ 33, 14, 33, 5, 1460551932 ]
def lines(self): """ a generator for reading all the information of current request/line :return: a tuple of current request """ line = self.trace_file.readline().decode() while line and len(line.strip()) == 0: line = self.trace_file.readline().decode() ...
1a1a11a/mimircache
[ 33, 14, 33, 5, 1460551932 ]
def skip_n_req(self, n): """ skip N requests from current position :param n: the number of requests to skip """ for i in range(n): self.read_one_req()
1a1a11a/mimircache
[ 33, 14, 33, 5, 1460551932 ]
def copy(self, open_c_reader=False): """ reader a deep copy of current reader with everything reset to initial state, the returned reader should not interfere with current reader :param open_c_reader: whether open_c_reader_or_not, default not open :return: a copied reader ...
1a1a11a/mimircache
[ 33, 14, 33, 5, 1460551932 ]
def __next__(self): # Python 3 super().__next__() element = self.read_one_req() if element is not None: return element else: raise StopIteration
1a1a11a/mimircache
[ 33, 14, 33, 5, 1460551932 ]
def test_name(self): self.assertEqual(self.col.name, self.NAME, 'A Column does not store its name correctly')
TMiguelT/PandasSchema
[ 180, 36, 180, 37, 1480922541 ]
def test_outputs(self): results = self.col.validate(self.ser) # There should be 6 errors, 2 for each row self.assertEqual(len(results), 2 * len(self.ser), 'A Column produces the wrong number of errors') for i in range(2): in_row = [r for r in results if r.row == i] ...
TMiguelT/PandasSchema
[ 180, 36, 180, 37, 1480922541 ]
def ListAll_xx(): temp = [] for lang in LANGUAGES: temp.append(lang['ISO639']) return temp
matachi/subdownloader
[ 4, 1, 4, 1, 1433450532 ]
def ListAll_locale(): temp = [] for lang in LANGUAGES: temp.append(lang['locale']) return temp
matachi/subdownloader
[ 4, 1, 4, 1, 1433450532 ]
def xx2xxx(xx): for lang in LANGUAGES: if lang['ISO639'] == xx: return lang['SubLanguageID']
matachi/subdownloader
[ 4, 1, 4, 1, 1433450532 ]
def xxx2name(xxx): for lang in LANGUAGES: if lang['SubLanguageID'] == xxx: return lang['LanguageName']
matachi/subdownloader
[ 4, 1, 4, 1, 1433450532 ]
def xx2name(xx): for lang in LANGUAGES: if lang['ISO639'] == xx: return lang['LanguageName']
matachi/subdownloader
[ 4, 1, 4, 1, 1433450532 ]
def name2xxx(name): for lang in LANGUAGES: if lang['LanguageName'].lower() == name.lower(): return lang['SubLanguageID']
matachi/subdownloader
[ 4, 1, 4, 1, 1433450532 ]
def _validate_template_filename(filename: Union[str, Path]) -> Path: if isinstance(filename, str): filename = Path(filename) suffix = filename.suffix if not suffix: suffix = '.crtx' if suffix != '.crtx': raise ValueError(f"Extension for the excel template file must be '.crtx' ins...
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def __init__(self, template_dir=None, template=None, graphs_per_row=1): self.template_dir = template_dir self.template = template self.default_items_size = _default_items_size.copy() self.graphs_per_row = graphs_per_row
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def template_dir(self): r""" Set the path to the directory containing the Excel template files (with '.crtx' extension). This method is mainly useful if your template files are located in several directories, otherwise pass the template directory directly the ExcelReport constructor. ...
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def template_dir(self, template_dir): if template_dir is not None: if isinstance(template_dir, str): template_dir = Path(template_dir) if not isinstance(template_dir, Path): raise TypeError(f"Expected a string or a pathlib.Path object. " ...
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def template(self): r""" Set a default Excel template file. Parameters ---------- template : str or Path Name of the template to be used as default template. The extension '.crtx' will be added if not given. The full path to the template file ...
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def template(self, template): if template is not None: if self.template_dir is None: raise RuntimeError("Please set 'template_dir' first") filename = _validate_template_filename(template) template = self.template_dir / filename self._template = templat...
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def graphs_per_row(self): r""" Default number of graphs per row. Parameters ---------- graphs_per_row: int See Also -------- ReportSheet.newline """ return self._graphs_per_row
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def graphs_per_row(self, graphs_per_row): _positive_integer(graphs_per_row) self._graphs_per_row = graphs_per_row
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def add_title(self, title, width=None, height=None, fontsize=11): r""" Add a title item to the current sheet. Note that the current method only add a new item to the list of items to be generated. The report Excel file is generated only when the :py:obj:`~ExcelReport.to_excel` is called....
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def add_graphs(self, array_per_title, axis_per_loop_variable, template=None, width=None, height=None, graphs_per_row=1, min_y=None, max_y=None, xticks_spacing=None, customize_func=None, customize_kwargs=None): r""" Add multiple graph items to the current sheet. This...
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def new_sheet(self, sheet_name): r""" Add a new empty output sheet. This sheet will contain only graphical elements, all data are exported to a dedicated separate sheet. Parameters ---------- sheet_name : str name of the current sheet. Return...
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def to_excel(self, filepath, data_sheet_name='__data__', overwrite=True): r""" Generate the report Excel file. Parameters ---------- filepath : str or Path Path of the report file for the dump. data_sheet_name : str, optional name of the Excel she...
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def __init__(self, width, height): self.width = width self.height = height
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def width(self): return self._width
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def width(self, width): _positive_integer(width) self._width = width
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def height(self): return self._height
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def height(self, height): _positive_integer(height) self._height = height
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def __init__(self, text, fontsize, top, left, width, height): ItemSize.__init__(self, width, height) self.top = top self.left = left self.text = str(text) _positive_integer(fontsize) self.fontsize = fontsize
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def __init__(self, data, title, template, top, left, width, height, min_y, max_y, xticks_spacing, customize_func, customize_kwargs): ItemSize.__init__(self, width, height) self.top = top self.left = left self.title = str(title) if title is not None el...
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def __init__(self, excel_report, name, template_dir=None, template=None, graphs_per_row=1): name = _translate_sheet_name(name) self.excel_report = excel_report self.name = name self.items = [] self.top = 0 self.left = 0 self.position_in...
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def add_graph(self, data, title=None, template=None, width=None, height=None, min_y=None, max_y=None, xticks_spacing=None, customize_func=None, customize_kwargs=None): if width is None: width = self.default_items_size['graph'].width if height is None: ...
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def newline(self): self.top += self.curline_height self.curline_height = 0 self.left = 0 self.position_in_row = 1
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def __init__(self, template_dir=None, template=None, graphs_per_row=1): AbstractExcelReport.__init__(self, template_dir, template, graphs_per_row) self.sheets = {}
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def __getitem__(self, key): return self.sheets[key]
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def __setitem__(self, key, value, warn_stacklevel=2): if not isinstance(value, ReportSheet): raise ValueError(f"Expected ReportSheet object. Got {type(value).__name__} object instead.") if key in self.sheet_names(): warnings.warn(f"Sheet '{key}' already exists in ...
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def __repr__(self): return f'sheets: {self.sheet_names()}'
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def to_excel(self, filepath, data_sheet_name='__data__', overwrite=True): with open_excel(filepath, overwrite_file=overwrite) as wb: # from here on, we use pure win32com objects instead of # larray.excel or xlwings objects as this is faster xl_wb = wb.api ...
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def __init__(self): raise Exception("ReportSheet class cannot be instantiated because xlwings is not installed")
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def __init__(self): raise Exception("ExcelReport class cannot be instantiated because xlwings is not installed")
liam2/larray
[ 8, 5, 8, 228, 1392806323 ]
def my_add(a,b): ''' This is the function for addition of numbers and strings ''' print "value of a is {}".format(a) print "value of b is {}".format(b) return a+b
tuxfux-hlp-notes/python-batches
[ 5, 15, 5, 2, 1481601578 ]
def my_div(a,b): ''' This is the function for division ''' return a/b
tuxfux-hlp-notes/python-batches
[ 5, 15, 5, 2, 1481601578 ]
def my_sub(a,b): ''' This is the function for substraction ''' if a > b: return a - b elif b > a: return b - a
tuxfux-hlp-notes/python-batches
[ 5, 15, 5, 2, 1481601578 ]
def my_mul(a,b): ''' This is the function for multiplication ''' return a * b
tuxfux-hlp-notes/python-batches
[ 5, 15, 5, 2, 1481601578 ]
def checkInputs(): #Check to be sure that SHGC and VT are between 0 and 1. checkData = True
mostaphaRoudsari/Honeybee
[ 118, 145, 118, 98, 1384492853 ]
def checkBtwZeroAndOne(variable, default, variableName): if variable == None: newVariable = default else: if variable <= 1 and variable >= 0: newVariable = variable else: newVariable = 0 checkData = False warning = variableName + " ...
mostaphaRoudsari/Honeybee
[ 118, 145, 118, 98, 1384492853 ]
def main(name, roughness, R_Value, thermAbsp, solAbsp, visAbsp):
mostaphaRoudsari/Honeybee
[ 118, 145, 118, 98, 1384492853 ]
def __init__(self, blockname=None, **kwargs): ModTool.__init__(self, blockname, **kwargs) self.info['pattern'] = blockname
marcusmueller/gnuradio
[ 1, 1, 1, 1, 1369304746 ]
def setup(): print "SETUP!"
anaoprea/iDibo
[ 1, 1, 1, 8, 1416675207 ]
def __init__(self, filter_size, compiled=True): LayerBase.__init__(self, activation="linear", trainable=False) if compiled: from ..llatomic.lltensor_op import MaxPoolOp else: from ..atomic import MaxPoolOp self.fdim = filter_size self.filter = None ...
csxeba/brainforge
[ 113, 12, 113, 2, 1483437073 ]
def feedforward(self, questions): self.output, self.filter = self.op.forward(questions, self.fdim) return self.output
csxeba/brainforge
[ 113, 12, 113, 2, 1483437073 ]
def outshape(self): return self.output.shape[-3:]
csxeba/brainforge
[ 113, 12, 113, 2, 1483437073 ]
def __init__(self, nfilters, filterx=3, filtery=3, compiled=True, **kw): super().__init__(compiled=compiled, **kw) self.nfilters = nfilters self.fx = filterx self.fy = filtery self.depth = 0 self.stride = 1 self.inshape = None self.op = None
csxeba/brainforge
[ 113, 12, 113, 2, 1483437073 ]
def feedforward(self, X): self.inputs = X self.output = self.activation.forward(self.op.forward(X, self.weights, "valid")) self.output += self.biases return self.output
csxeba/brainforge
[ 113, 12, 113, 2, 1483437073 ]
def outshape(self): oy, ox = tuple(ix - fx + 1 for ix, fx in zip(self.inshape[-2:], (self.fx, self.fy))) return self.nfilters, ox, oy
csxeba/brainforge
[ 113, 12, 113, 2, 1483437073 ]
def __init__(self): LayerBase.__init__(self) NoParamMixin.__init__(self) self.repeats = 0
csxeba/brainforge
[ 113, 12, 113, 2, 1483437073 ]
def backpropagate(self, delta): m = len(delta) delta = np.repeat(delta / scalX(self.repeats), self.repeats) delta = delta.reshape((m,) + self.inshape) return delta
csxeba/brainforge
[ 113, 12, 113, 2, 1483437073 ]
def __init__( self, alphabet: Optional[ Union[TCounter[str], Sequence[str], Set[str], int] ] = None, tokenizer: Optional[_Tokenizer] = None, intersection_type: str = 'crisp', **kwargs: Any
chrislit/abydos
[ 154, 26, 154, 63, 1398235847 ]
def sim(self, src: str, tar: str) -> float: """Return the Tarantula similarity of two strings. Parameters ---------- src : str Source string (or QGrams/Counter objects) for comparison tar : str Target string (or QGrams/Counter objects) for comparison ...
chrislit/abydos
[ 154, 26, 154, 63, 1398235847 ]
def __init__(self, config, emitter, name='wikidata'): self.config = config self.process = None self.emitter = emitter self.name = name self.emitter.on('WikidataKnowledgeAdquire', self._adquire)
ElliotTheRobot/LILACS-mycroft-core
[ 4, 1, 4, 19, 1491303887 ]
def adquire(self, subject): logger.info('Call WikidataKnowledgeAdquire') self.emitter.emit(Message('WikidataKnowledgeAdquire', {"subject": subject}))
ElliotTheRobot/LILACS-mycroft-core
[ 4, 1, 4, 19, 1491303887 ]
def stop(self): logger.info('WikidataKnowledge_Stop') if self.process: self.process.terminate() self.process = None
ElliotTheRobot/LILACS-mycroft-core
[ 4, 1, 4, 19, 1491303887 ]
def test_get_subscriptions(self): self.prepare_json_response("GET", "/ws/subscriptions", { "subscriptions": [ "subscriptions/a", "subscriptions/b", ] }) subs = self.wva.get_subscriptions() self.assertEqual(len(subs), 2) self...
digidotcom/python-wvalib
[ 5, 3, 5, 3, 1427831267 ]
def test_delete(self): self.prepare_response("DELETE", "/ws/subscriptions/short-name", "") sub = self.wva.get_subscription("short-name") sub.delete() self.assertEqual(self._get_last_request().method, "DELETE") self.assertEqual(self._get_last_request().path, "/ws/subscriptions/sho...
digidotcom/python-wvalib
[ 5, 3, 5, 3, 1427831267 ]