repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
tBuLi/symfit
symfit/core/minimizers.py
ScipyMinimize._pack_output
def _pack_output(self, ans): """ Packs the output of a minimization in a :class:`~symfit.core.fit_results.FitResults`. :param ans: The output of a minimization as produced by :func:`scipy.optimize.minimize` :returns: :class:`~symfit.core.fit_results.FitResults` ...
python
def _pack_output(self, ans): """ Packs the output of a minimization in a :class:`~symfit.core.fit_results.FitResults`. :param ans: The output of a minimization as produced by :func:`scipy.optimize.minimize` :returns: :class:`~symfit.core.fit_results.FitResults` ...
[ "def", "_pack_output", "(", "self", ",", "ans", ")", ":", "# Build infodic", "infodic", "=", "{", "'nfev'", ":", "ans", ".", "nfev", ",", "}", "best_vals", "=", "[", "]", "found", "=", "iter", "(", "np", ".", "atleast_1d", "(", "ans", ".", "x", ")"...
Packs the output of a minimization in a :class:`~symfit.core.fit_results.FitResults`. :param ans: The output of a minimization as produced by :func:`scipy.optimize.minimize` :returns: :class:`~symfit.core.fit_results.FitResults`
[ "Packs", "the", "output", "of", "a", "minimization", "in", "a", ":", "class", ":", "~symfit", ".", "core", ".", "fit_results", ".", "FitResults", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/minimizers.py#L355-L392
tBuLi/symfit
symfit/core/minimizers.py
ScipyConstrainedMinimize.scipy_constraints
def scipy_constraints(self, constraints): """ Returns all constraints in a scipy compatible format. :param constraints: List of either MinimizeModel instances (this is what is provided by :class:`~symfit.core.fit.Fit`), :class:`~symfit.core.fit.BaseModel`, or :clas...
python
def scipy_constraints(self, constraints): """ Returns all constraints in a scipy compatible format. :param constraints: List of either MinimizeModel instances (this is what is provided by :class:`~symfit.core.fit.Fit`), :class:`~symfit.core.fit.BaseModel`, or :clas...
[ "def", "scipy_constraints", "(", "self", ",", "constraints", ")", ":", "cons", "=", "[", "]", "types", "=", "{", "# scipy only distinguishes two types of constraint.", "sympy", ".", "Eq", ":", "'eq'", ",", "sympy", ".", "Ge", ":", "'ineq'", ",", "}", "for", ...
Returns all constraints in a scipy compatible format. :param constraints: List of either MinimizeModel instances (this is what is provided by :class:`~symfit.core.fit.Fit`), :class:`~symfit.core.fit.BaseModel`, or :class:`sympy.core.relational.Relational`. :return: dict of...
[ "Returns", "all", "constraints", "in", "a", "scipy", "compatible", "format", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/minimizers.py#L477-L517
tBuLi/symfit
symfit/core/minimizers.py
TrustConstr._get_jacobian_hessian_strategy
def _get_jacobian_hessian_strategy(self): """ Figure out how to calculate the jacobian and hessian. Will return a tuple describing how best to calculate the jacobian and hessian, repectively. If None, it should be calculated using the available analytical method. :return...
python
def _get_jacobian_hessian_strategy(self): """ Figure out how to calculate the jacobian and hessian. Will return a tuple describing how best to calculate the jacobian and hessian, repectively. If None, it should be calculated using the available analytical method. :return...
[ "def", "_get_jacobian_hessian_strategy", "(", "self", ")", ":", "if", "self", ".", "jacobian", "is", "not", "None", "and", "self", ".", "hessian", "is", "None", ":", "jacobian", "=", "None", "hessian", "=", "'cs'", "elif", "self", ".", "jacobian", "is", ...
Figure out how to calculate the jacobian and hessian. Will return a tuple describing how best to calculate the jacobian and hessian, repectively. If None, it should be calculated using the available analytical method. :return: tuple of jacobian_method, hessian_method
[ "Figure", "out", "how", "to", "calculate", "the", "jacobian", "and", "hessian", ".", "Will", "return", "a", "tuple", "describing", "how", "best", "to", "calculate", "the", "jacobian", "and", "hessian", "repectively", ".", "If", "None", "it", "should", "be", ...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/minimizers.py#L566-L584
tBuLi/symfit
symfit/core/minimizers.py
BasinHopping.execute
def execute(self, **minimize_options): """ Execute the basin-hopping minimization. :param minimize_options: options to be passed on to :func:`scipy.optimize.basinhopping`. :return: :class:`symfit.core.fit_results.FitResults` """ if 'minimizer_kwargs' not in m...
python
def execute(self, **minimize_options): """ Execute the basin-hopping minimization. :param minimize_options: options to be passed on to :func:`scipy.optimize.basinhopping`. :return: :class:`symfit.core.fit_results.FitResults` """ if 'minimizer_kwargs' not in m...
[ "def", "execute", "(", "self", ",", "*", "*", "minimize_options", ")", ":", "if", "'minimizer_kwargs'", "not", "in", "minimize_options", ":", "minimize_options", "[", "'minimizer_kwargs'", "]", "=", "{", "}", "if", "'method'", "not", "in", "minimize_options", ...
Execute the basin-hopping minimization. :param minimize_options: options to be passed on to :func:`scipy.optimize.basinhopping`. :return: :class:`symfit.core.fit_results.FitResults`
[ "Execute", "the", "basin", "-", "hopping", "minimization", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/minimizers.py#L719-L748
tBuLi/symfit
symfit/core/minimizers.py
MINPACK.execute
def execute(self, **minpack_options): """ :param \*\*minpack_options: Any named arguments to be passed to leastsqbound """ popt, pcov, infodic, mesg, ier = leastsqbound( self.objective, # Dfun=self.jacobian, x0=self.initial_guesses, bounds=...
python
def execute(self, **minpack_options): """ :param \*\*minpack_options: Any named arguments to be passed to leastsqbound """ popt, pcov, infodic, mesg, ier = leastsqbound( self.objective, # Dfun=self.jacobian, x0=self.initial_guesses, bounds=...
[ "def", "execute", "(", "self", ",", "*", "*", "minpack_options", ")", ":", "popt", ",", "pcov", ",", "infodic", ",", "mesg", ",", "ier", "=", "leastsqbound", "(", "self", ".", "objective", ",", "# Dfun=self.jacobian,", "x0", "=", "self", ".", "initial_gu...
:param \*\*minpack_options: Any named arguments to be passed to leastsqbound
[ ":", "param", "\\", "*", "\\", "*", "minpack_options", ":", "Any", "named", "arguments", "to", "be", "passed", "to", "leastsqbound" ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/minimizers.py#L760-L783
tBuLi/symfit
symfit/core/printing.py
SymfitNumPyPrinter._print_MatMul
def _print_MatMul(self, expr): """ Matrix multiplication printer. The sympy one turns everything into a dot product without type-checking. """ from sympy import MatrixExpr links = [] for i, j in zip(expr.args[1:], expr.args[:-1]): if isinstance(i, Matr...
python
def _print_MatMul(self, expr): """ Matrix multiplication printer. The sympy one turns everything into a dot product without type-checking. """ from sympy import MatrixExpr links = [] for i, j in zip(expr.args[1:], expr.args[:-1]): if isinstance(i, Matr...
[ "def", "_print_MatMul", "(", "self", ",", "expr", ")", ":", "from", "sympy", "import", "MatrixExpr", "links", "=", "[", "]", "for", "i", ",", "j", "in", "zip", "(", "expr", ".", "args", "[", "1", ":", "]", ",", "expr", ".", "args", "[", ":", "-...
Matrix multiplication printer. The sympy one turns everything into a dot product without type-checking.
[ "Matrix", "multiplication", "printer", ".", "The", "sympy", "one", "turns", "everything", "into", "a", "dot", "product", "without", "type", "-", "checking", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/printing.py#L34-L50
tBuLi/symfit
symfit/core/printing.py
SymfitNumPyPrinter._print_DiracDelta
def _print_DiracDelta(self, expr): """ Replaces a DiracDelta(x) by np.inf if x == 0, and 0 otherwise. This is wrong, but the only thing we can do by the time we are printing. To prevent mistakes, integrate before printing. """ return "{0}({1}, [{1} == 0 , {1} != 0], [{2},...
python
def _print_DiracDelta(self, expr): """ Replaces a DiracDelta(x) by np.inf if x == 0, and 0 otherwise. This is wrong, but the only thing we can do by the time we are printing. To prevent mistakes, integrate before printing. """ return "{0}({1}, [{1} == 0 , {1} != 0], [{2},...
[ "def", "_print_DiracDelta", "(", "self", ",", "expr", ")", ":", "return", "\"{0}({1}, [{1} == 0 , {1} != 0], [{2}, 0])\"", ".", "format", "(", "self", ".", "_module_format", "(", "'numpy.piecewise'", ")", ",", "self", ".", "_print", "(", "expr", ".", "args", "["...
Replaces a DiracDelta(x) by np.inf if x == 0, and 0 otherwise. This is wrong, but the only thing we can do by the time we are printing. To prevent mistakes, integrate before printing.
[ "Replaces", "a", "DiracDelta", "(", "x", ")", "by", "np", ".", "inf", "if", "x", "==", "0", "and", "0", "otherwise", ".", "This", "is", "wrong", "but", "the", "only", "thing", "we", "can", "do", "by", "the", "time", "we", "are", "printing", ".", ...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/printing.py#L60-L69
tBuLi/symfit
symfit/contrib/interactive_guess/interactive_guess.py
InteractiveGuess.execute
def execute(self, **kwargs): """ Execute the interactive guessing procedure. :param show: Whether or not to show the figure. Useful for testing. :type show: bool :param block: Blocking call to matplotlib :type show: bool Any additional keyword arguments are pass...
python
def execute(self, **kwargs): """ Execute the interactive guessing procedure. :param show: Whether or not to show the figure. Useful for testing. :type show: bool :param block: Blocking call to matplotlib :type show: bool Any additional keyword arguments are pass...
[ "def", "execute", "(", "self", ",", "*", "*", "kwargs", ")", ":", "show", "=", "kwargs", ".", "pop", "(", "'show'", ")", "if", "show", ":", "# self.fig.show() # Apparently this does something else,", "# see https://github.com/matplotlib/matplotlib/issues/6138", "plt", ...
Execute the interactive guessing procedure. :param show: Whether or not to show the figure. Useful for testing. :type show: bool :param block: Blocking call to matplotlib :type show: bool Any additional keyword arguments are passed to matplotlib.pyplot.show().
[ "Execute", "the", "interactive", "guessing", "procedure", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L99-L115
tBuLi/symfit
symfit/contrib/interactive_guess/interactive_guess.py
InteractiveGuess._set_up_figure
def _set_up_figure(self, x_mins, x_maxs, y_mins, y_maxs): """ Prepare the matplotlib figure: make all the subplots; adjust their x and y range; plot the data; and plot an putative function. """ self.fig = plt.figure() # Make room for the sliders: bot = 0.1 + 0.05...
python
def _set_up_figure(self, x_mins, x_maxs, y_mins, y_maxs): """ Prepare the matplotlib figure: make all the subplots; adjust their x and y range; plot the data; and plot an putative function. """ self.fig = plt.figure() # Make room for the sliders: bot = 0.1 + 0.05...
[ "def", "_set_up_figure", "(", "self", ",", "x_mins", ",", "x_maxs", ",", "y_mins", ",", "y_maxs", ")", ":", "self", ".", "fig", "=", "plt", ".", "figure", "(", ")", "# Make room for the sliders:", "bot", "=", "0.1", "+", "0.05", "*", "len", "(", "self"...
Prepare the matplotlib figure: make all the subplots; adjust their x and y range; plot the data; and plot an putative function.
[ "Prepare", "the", "matplotlib", "figure", ":", "make", "all", "the", "subplots", ";", "adjust", "their", "x", "and", "y", "range", ";", "plot", "the", "data", ";", "and", "plot", "an", "putative", "function", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L117-L156
tBuLi/symfit
symfit/contrib/interactive_guess/interactive_guess.py
InteractiveGuess._set_up_sliders
def _set_up_sliders(self): """ Creates an slider for every parameter. """ i = 0.05 self._sliders = {} for param in self.model.params: if not param.fixed: axbg = 'lightgoldenrodyellow' else: axbg = 'red' #...
python
def _set_up_sliders(self): """ Creates an slider for every parameter. """ i = 0.05 self._sliders = {} for param in self.model.params: if not param.fixed: axbg = 'lightgoldenrodyellow' else: axbg = 'red' #...
[ "def", "_set_up_sliders", "(", "self", ")", ":", "i", "=", "0.05", "self", ".", "_sliders", "=", "{", "}", "for", "param", "in", "self", ".", "model", ".", "params", ":", "if", "not", "param", ".", "fixed", ":", "axbg", "=", "'lightgoldenrodyellow'", ...
Creates an slider for every parameter.
[ "Creates", "an", "slider", "for", "every", "parameter", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L158-L186
tBuLi/symfit
symfit/contrib/interactive_guess/interactive_guess.py
InteractiveGuess._update_plot
def _update_plot(self, _): """Callback to redraw the plot to reflect the new parameter values.""" # Since all sliders call this same callback without saying who they are # I need to update the values for all parameters. This can be # circumvented by creating a seperate callback function ...
python
def _update_plot(self, _): """Callback to redraw the plot to reflect the new parameter values.""" # Since all sliders call this same callback without saying who they are # I need to update the values for all parameters. This can be # circumvented by creating a seperate callback function ...
[ "def", "_update_plot", "(", "self", ",", "_", ")", ":", "# Since all sliders call this same callback without saying who they are", "# I need to update the values for all parameters. This can be", "# circumvented by creating a seperate callback function for each", "# parameter.", "for", "pa...
Callback to redraw the plot to reflect the new parameter values.
[ "Callback", "to", "redraw", "the", "plot", "to", "reflect", "the", "new", "parameter", "values", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L200-L209
tBuLi/symfit
symfit/contrib/interactive_guess/interactive_guess.py
InteractiveGuess._eval_model
def _eval_model(self): """ Convenience method for evaluating the model with the current parameters :return: named tuple with results """ arguments = self._x_grid.copy() arguments.update({param: param.value for param in self.model.params}) return self.model(**key2...
python
def _eval_model(self): """ Convenience method for evaluating the model with the current parameters :return: named tuple with results """ arguments = self._x_grid.copy() arguments.update({param: param.value for param in self.model.params}) return self.model(**key2...
[ "def", "_eval_model", "(", "self", ")", ":", "arguments", "=", "self", ".", "_x_grid", ".", "copy", "(", ")", "arguments", ".", "update", "(", "{", "param", ":", "param", ".", "value", "for", "param", "in", "self", ".", "model", ".", "params", "}", ...
Convenience method for evaluating the model with the current parameters :return: named tuple with results
[ "Convenience", "method", "for", "evaluating", "the", "model", "with", "the", "current", "parameters" ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L211-L219
tBuLi/symfit
symfit/contrib/interactive_guess/interactive_guess.py
Strategy2D.plot_data
def plot_data(self, proj, ax): """ Creates and plots a scatter plot of the original data. """ x, y = proj ax.scatter(self.ig.independent_data[x], self.ig.dependent_data[y], c='b')
python
def plot_data(self, proj, ax): """ Creates and plots a scatter plot of the original data. """ x, y = proj ax.scatter(self.ig.independent_data[x], self.ig.dependent_data[y], c='b')
[ "def", "plot_data", "(", "self", ",", "proj", ",", "ax", ")", ":", "x", ",", "y", "=", "proj", "ax", ".", "scatter", "(", "self", ".", "ig", ".", "independent_data", "[", "x", "]", ",", "self", ".", "ig", ".", "dependent_data", "[", "y", "]", "...
Creates and plots a scatter plot of the original data.
[ "Creates", "and", "plots", "a", "scatter", "plot", "of", "the", "original", "data", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L241-L247
tBuLi/symfit
symfit/contrib/interactive_guess/interactive_guess.py
Strategy2D.plot_model
def plot_model(self, proj, ax): """ Plots the model proposed for the projection proj on ax. """ x, y = proj y_vals = getattr(self.ig._eval_model(), y.name) x_vals = self.ig._x_points[x] plot, = ax.plot(x_vals, y_vals, c='red') return plot
python
def plot_model(self, proj, ax): """ Plots the model proposed for the projection proj on ax. """ x, y = proj y_vals = getattr(self.ig._eval_model(), y.name) x_vals = self.ig._x_points[x] plot, = ax.plot(x_vals, y_vals, c='red') return plot
[ "def", "plot_model", "(", "self", ",", "proj", ",", "ax", ")", ":", "x", ",", "y", "=", "proj", "y_vals", "=", "getattr", "(", "self", ".", "ig", ".", "_eval_model", "(", ")", ",", "y", ".", "name", ")", "x_vals", "=", "self", ".", "ig", ".", ...
Plots the model proposed for the projection proj on ax.
[ "Plots", "the", "model", "proposed", "for", "the", "projection", "proj", "on", "ax", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L249-L257
tBuLi/symfit
symfit/contrib/interactive_guess/interactive_guess.py
Strategy2D.update_plot
def update_plot(self, indep_var, dep_var): """ Updates the plot of the proposed model. """ evaluated_model = self.ig._eval_model() plot = self.ig._plots[(indep_var, dep_var)] y_vals = getattr(evaluated_model, dep_var.name) x_vals = self.ig._x_points[indep_var] ...
python
def update_plot(self, indep_var, dep_var): """ Updates the plot of the proposed model. """ evaluated_model = self.ig._eval_model() plot = self.ig._plots[(indep_var, dep_var)] y_vals = getattr(evaluated_model, dep_var.name) x_vals = self.ig._x_points[indep_var] ...
[ "def", "update_plot", "(", "self", ",", "indep_var", ",", "dep_var", ")", ":", "evaluated_model", "=", "self", ".", "ig", ".", "_eval_model", "(", ")", "plot", "=", "self", ".", "ig", ".", "_plots", "[", "(", "indep_var", ",", "dep_var", ")", "]", "y...
Updates the plot of the proposed model.
[ "Updates", "the", "plot", "of", "the", "proposed", "model", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L259-L267
tBuLi/symfit
symfit/contrib/interactive_guess/interactive_guess.py
StrategynD.plot_data
def plot_data(self, proj, ax): """ Creates and plots the contourplot of the original data. This is done by evaluating the density of projected datapoints on a grid. """ x, y = proj x_data = self.ig.independent_data[x] y_data = self.ig.dependent_data[y] pro...
python
def plot_data(self, proj, ax): """ Creates and plots the contourplot of the original data. This is done by evaluating the density of projected datapoints on a grid. """ x, y = proj x_data = self.ig.independent_data[x] y_data = self.ig.dependent_data[y] pro...
[ "def", "plot_data", "(", "self", ",", "proj", ",", "ax", ")", ":", "x", ",", "y", "=", "proj", "x_data", "=", "self", ".", "ig", ".", "independent_data", "[", "x", "]", "y_data", "=", "self", ".", "ig", ".", "dependent_data", "[", "y", "]", "proj...
Creates and plots the contourplot of the original data. This is done by evaluating the density of projected datapoints on a grid.
[ "Creates", "and", "plots", "the", "contourplot", "of", "the", "original", "data", ".", "This", "is", "done", "by", "evaluating", "the", "density", "of", "projected", "datapoints", "on", "a", "grid", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L278-L302
tBuLi/symfit
symfit/contrib/interactive_guess/interactive_guess.py
StrategynD.plot_model
def plot_model(self, proj, ax): """ Plots the model proposed for the projection proj on ax. """ x, y = proj evaluated_model = self.ig._eval_model() y_vals = getattr(evaluated_model, y.name) x_vals = self.ig._x_grid[x] plot = ax.errorbar(x_vals, y_vals, xer...
python
def plot_model(self, proj, ax): """ Plots the model proposed for the projection proj on ax. """ x, y = proj evaluated_model = self.ig._eval_model() y_vals = getattr(evaluated_model, y.name) x_vals = self.ig._x_grid[x] plot = ax.errorbar(x_vals, y_vals, xer...
[ "def", "plot_model", "(", "self", ",", "proj", ",", "ax", ")", ":", "x", ",", "y", "=", "proj", "evaluated_model", "=", "self", ".", "ig", ".", "_eval_model", "(", ")", "y_vals", "=", "getattr", "(", "evaluated_model", ",", "y", ".", "name", ")", "...
Plots the model proposed for the projection proj on ax.
[ "Plots", "the", "model", "proposed", "for", "the", "projection", "proj", "on", "ax", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L304-L313
tBuLi/symfit
symfit/contrib/interactive_guess/interactive_guess.py
StrategynD.update_plot
def update_plot(self, indep_var, dep_var): """ Updates the plot of the proposed model. """ evaluated_model = self.ig._eval_model() y_vals = getattr(evaluated_model, dep_var.name) x_vals = self.ig._x_grid[indep_var] x_plot_data = [] y_plot_data = [] ...
python
def update_plot(self, indep_var, dep_var): """ Updates the plot of the proposed model. """ evaluated_model = self.ig._eval_model() y_vals = getattr(evaluated_model, dep_var.name) x_vals = self.ig._x_grid[indep_var] x_plot_data = [] y_plot_data = [] ...
[ "def", "update_plot", "(", "self", ",", "indep_var", ",", "dep_var", ")", ":", "evaluated_model", "=", "self", ".", "ig", ".", "_eval_model", "(", ")", "y_vals", "=", "getattr", "(", "evaluated_model", ",", "dep_var", ".", "name", ")", "x_vals", "=", "se...
Updates the plot of the proposed model.
[ "Updates", "the", "plot", "of", "the", "proposed", "model", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L315-L351
tBuLi/symfit
symfit/distributions.py
Gaussian
def Gaussian(x, mu, sig): """ Gaussian pdf. :param x: free variable. :param mu: mean of the distribution. :param sig: standard deviation of the distribution. :return: sympy.Expr for a Gaussian pdf. """ return sympy.exp(-(x - mu)**2/(2*sig**2))/sympy.sqrt(2*sympy.pi*sig**2)
python
def Gaussian(x, mu, sig): """ Gaussian pdf. :param x: free variable. :param mu: mean of the distribution. :param sig: standard deviation of the distribution. :return: sympy.Expr for a Gaussian pdf. """ return sympy.exp(-(x - mu)**2/(2*sig**2))/sympy.sqrt(2*sympy.pi*sig**2)
[ "def", "Gaussian", "(", "x", ",", "mu", ",", "sig", ")", ":", "return", "sympy", ".", "exp", "(", "-", "(", "x", "-", "mu", ")", "**", "2", "/", "(", "2", "*", "sig", "**", "2", ")", ")", "/", "sympy", ".", "sqrt", "(", "2", "*", "sympy",...
Gaussian pdf. :param x: free variable. :param mu: mean of the distribution. :param sig: standard deviation of the distribution. :return: sympy.Expr for a Gaussian pdf.
[ "Gaussian", "pdf", ".", ":", "param", "x", ":", "free", "variable", ".", ":", "param", "mu", ":", "mean", "of", "the", "distribution", ".", ":", "param", "sig", ":", "standard", "deviation", "of", "the", "distribution", ".", ":", "return", ":", "sympy"...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/distributions.py#L11-L19
tBuLi/symfit
symfit/distributions.py
BivariateGaussian
def BivariateGaussian(x, y, mu_x, mu_y, sig_x, sig_y, rho): """ Bivariate Gaussian pdf. :param x: :class:`symfit.core.argument.Variable` :param y: :class:`symfit.core.argument.Variable` :param mu_x: :class:`symfit.core.argument.Parameter` for the mean of `x` :param mu_y: :class:`symfit.core.arg...
python
def BivariateGaussian(x, y, mu_x, mu_y, sig_x, sig_y, rho): """ Bivariate Gaussian pdf. :param x: :class:`symfit.core.argument.Variable` :param y: :class:`symfit.core.argument.Variable` :param mu_x: :class:`symfit.core.argument.Parameter` for the mean of `x` :param mu_y: :class:`symfit.core.arg...
[ "def", "BivariateGaussian", "(", "x", ",", "y", ",", "mu_x", ",", "mu_y", ",", "sig_x", ",", "sig_y", ",", "rho", ")", ":", "exponent", "=", "-", "1", "/", "(", "2", "*", "(", "1", "-", "rho", "**", "2", ")", ")", "exponent", "*=", "(", "x", ...
Bivariate Gaussian pdf. :param x: :class:`symfit.core.argument.Variable` :param y: :class:`symfit.core.argument.Variable` :param mu_x: :class:`symfit.core.argument.Parameter` for the mean of `x` :param mu_y: :class:`symfit.core.argument.Parameter` for the mean of `y` :param sig_x: :class:`symfit.co...
[ "Bivariate", "Gaussian", "pdf", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/distributions.py#L21-L40
tBuLi/symfit
symfit/core/fit.py
variabletuple
def variabletuple(typename, variables, *args, **kwargs): """ Create a :func:`~collections.namedtuple` using :class:`~symfit.core.argument.Variable`'s whoses names will be used as `field_names`. The main reason for using this object is the `_asdict()` method: whereas a ``namedtuple`` initiates such ...
python
def variabletuple(typename, variables, *args, **kwargs): """ Create a :func:`~collections.namedtuple` using :class:`~symfit.core.argument.Variable`'s whoses names will be used as `field_names`. The main reason for using this object is the `_asdict()` method: whereas a ``namedtuple`` initiates such ...
[ "def", "variabletuple", "(", "typename", ",", "variables", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "def", "_asdict", "(", "self", ")", ":", "return", "OrderedDict", "(", "zip", "(", "variables", ",", "self", ")", ")", "field_names", "=", ...
Create a :func:`~collections.namedtuple` using :class:`~symfit.core.argument.Variable`'s whoses names will be used as `field_names`. The main reason for using this object is the `_asdict()` method: whereas a ``namedtuple`` initiates such an :class:`collections.OrderedDict` with the ``field_names`` as k...
[ "Create", "a", ":", "func", ":", "~collections", ".", "namedtuple", "using", ":", "class", ":", "~symfit", ".", "core", ".", "argument", ".", "Variable", "s", "whoses", "names", "will", "be", "used", "as", "field_names", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L35-L67
tBuLi/symfit
symfit/core/fit.py
r_squared
def r_squared(model, fit_result, data): """ Calculates the coefficient of determination, R^2, for the fit. (Is not defined properly for vector valued functions.) :param model: Model instance :param fit_result: FitResults instance :param data: data with which the fit was performed. """ ...
python
def r_squared(model, fit_result, data): """ Calculates the coefficient of determination, R^2, for the fit. (Is not defined properly for vector valued functions.) :param model: Model instance :param fit_result: FitResults instance :param data: data with which the fit was performed. """ ...
[ "def", "r_squared", "(", "model", ",", "fit_result", ",", "data", ")", ":", "# First filter out the dependent vars", "y_is", "=", "[", "data", "[", "var", "]", "for", "var", "in", "model", "if", "var", "in", "data", "]", "x_is", "=", "[", "value", "for",...
Calculates the coefficient of determination, R^2, for the fit. (Is not defined properly for vector valued functions.) :param model: Model instance :param fit_result: FitResults instance :param data: data with which the fit was performed.
[ "Calculates", "the", "coefficient", "of", "determination", "R^2", "for", "the", "fit", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1431-L1448
tBuLi/symfit
symfit/core/fit.py
_partial_diff
def _partial_diff(var, *params): """ Sympy does not handle repeated partial derivation correctly, e.g. D(D(y, a), a) = D(y, a, a) but D(D(y, a), b) = 0. Use this function instead to prevent evaluation to zero. """ if isinstance(var, sympy.Derivative): return sympy.Derivative(var.expr, *(...
python
def _partial_diff(var, *params): """ Sympy does not handle repeated partial derivation correctly, e.g. D(D(y, a), a) = D(y, a, a) but D(D(y, a), b) = 0. Use this function instead to prevent evaluation to zero. """ if isinstance(var, sympy.Derivative): return sympy.Derivative(var.expr, *(...
[ "def", "_partial_diff", "(", "var", ",", "*", "params", ")", ":", "if", "isinstance", "(", "var", ",", "sympy", ".", "Derivative", ")", ":", "return", "sympy", ".", "Derivative", "(", "var", ".", "expr", ",", "*", "(", "var", ".", "variables", "+", ...
Sympy does not handle repeated partial derivation correctly, e.g. D(D(y, a), a) = D(y, a, a) but D(D(y, a), b) = 0. Use this function instead to prevent evaluation to zero.
[ "Sympy", "does", "not", "handle", "repeated", "partial", "derivation", "correctly", "e", ".", "g", ".", "D", "(", "D", "(", "y", "a", ")", "a", ")", "=", "D", "(", "y", "a", "a", ")", "but", "D", "(", "D", "(", "y", "a", ")", "b", ")", "=",...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1682-L1691
tBuLi/symfit
symfit/core/fit.py
_partial_subs
def _partial_subs(func, func2vars): """ Partial-bug proof substitution. Works by making the substitutions on the expression inside the derivative first, and then rebuilding the derivative safely without evaluating it using `_partial_diff`. """ if isinstance(func, sympy.Derivative): new_f...
python
def _partial_subs(func, func2vars): """ Partial-bug proof substitution. Works by making the substitutions on the expression inside the derivative first, and then rebuilding the derivative safely without evaluating it using `_partial_diff`. """ if isinstance(func, sympy.Derivative): new_f...
[ "def", "_partial_subs", "(", "func", ",", "func2vars", ")", ":", "if", "isinstance", "(", "func", ",", "sympy", ".", "Derivative", ")", ":", "new_func", "=", "func", ".", "expr", ".", "xreplace", "(", "func2vars", ")", "new_variables", "=", "tuple", "(",...
Partial-bug proof substitution. Works by making the substitutions on the expression inside the derivative first, and then rebuilding the derivative safely without evaluating it using `_partial_diff`.
[ "Partial", "-", "bug", "proof", "substitution", ".", "Works", "by", "making", "the", "substitutions", "on", "the", "expression", "inside", "the", "derivative", "first", "and", "then", "rebuilding", "the", "derivative", "safely", "without", "evaluating", "it", "u...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1693-L1705
tBuLi/symfit
symfit/core/fit.py
jacobian_from_model
def jacobian_from_model(model, as_functions=False): """ Build a :class:`~symfit.core.fit.CallableModel` representing the Jacobian of ``model``. This function make sure the chain rule is correctly applied for interdependent variables. :param model: Any symbolical model-type. :param as_funct...
python
def jacobian_from_model(model, as_functions=False): """ Build a :class:`~symfit.core.fit.CallableModel` representing the Jacobian of ``model``. This function make sure the chain rule is correctly applied for interdependent variables. :param model: Any symbolical model-type. :param as_funct...
[ "def", "jacobian_from_model", "(", "model", ",", "as_functions", "=", "False", ")", ":", "# Inverse dict so we can turn functions back into vars in the end", "functions_as_vars", "=", "dict", "(", "(", "v", ",", "k", ")", "for", "k", ",", "v", "in", "model", ".", ...
Build a :class:`~symfit.core.fit.CallableModel` representing the Jacobian of ``model``. This function make sure the chain rule is correctly applied for interdependent variables. :param model: Any symbolical model-type. :param as_functions: If `True`, the result is returned using :class:`sy...
[ "Build", "a", ":", "class", ":", "~symfit", ".", "core", ".", "fit", ".", "CallableModel", "representing", "the", "Jacobian", "of", "model", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1707-L1746
tBuLi/symfit
symfit/core/fit.py
BaseModel.as_constraint
def as_constraint(cls, constraint, model, constraint_type=None, **init_kwargs): """ Initiate a Model which should serve as a constraint. Such a constraint-model should be initiated with knowledge of another ``BaseModel``, from which it will take its parameters:: model = Mode...
python
def as_constraint(cls, constraint, model, constraint_type=None, **init_kwargs): """ Initiate a Model which should serve as a constraint. Such a constraint-model should be initiated with knowledge of another ``BaseModel``, from which it will take its parameters:: model = Mode...
[ "def", "as_constraint", "(", "cls", ",", "constraint", ",", "model", ",", "constraint_type", "=", "None", ",", "*", "*", "init_kwargs", ")", ":", "allowed_types", "=", "[", "sympy", ".", "Eq", ",", "sympy", ".", "Ge", ",", "sympy", ".", "Le", "]", "i...
Initiate a Model which should serve as a constraint. Such a constraint-model should be initiated with knowledge of another ``BaseModel``, from which it will take its parameters:: model = Model({y: a * x + b}) constraint = Model.as_constraint(Eq(a, 1), model) ``constrain...
[ "Initiate", "a", "Model", "which", "should", "serve", "as", "a", "constraint", ".", "Such", "a", "constraint", "-", "model", "should", "be", "initiated", "with", "knowledge", "of", "another", "BaseModel", "from", "which", "it", "will", "take", "its", "parame...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L107-L165
tBuLi/symfit
symfit/core/fit.py
BaseModel.with_dependencies
def with_dependencies(cls, model_expr, dependency_model, **init_kwargs): """ Initiate a model whose components depend on another model. For example:: >>> x, y, z = variables('x, y, z') >>> dependency_model = Model({y: x**2}) >>> model_dict = {z: y**2} >>>...
python
def with_dependencies(cls, model_expr, dependency_model, **init_kwargs): """ Initiate a model whose components depend on another model. For example:: >>> x, y, z = variables('x, y, z') >>> dependency_model = Model({y: x**2}) >>> model_dict = {z: y**2} >>>...
[ "def", "with_dependencies", "(", "cls", ",", "model_expr", ",", "dependency_model", ",", "*", "*", "init_kwargs", ")", ":", "model", "=", "cls", "(", "model_expr", ",", "*", "*", "init_kwargs", ")", "# Initiate model instance.", "if", "any", "(", "var", "in"...
Initiate a model whose components depend on another model. For example:: >>> x, y, z = variables('x, y, z') >>> dependency_model = Model({y: x**2}) >>> model_dict = {z: y**2} >>> model = Model.with_dependencies(model_dict, dependency_model) >>> print(model) ...
[ "Initiate", "a", "model", "whose", "components", "depend", "on", "another", "model", ".", "For", "example", "::" ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L168-L216
tBuLi/symfit
symfit/core/fit.py
BaseModel._init_from_dict
def _init_from_dict(self, model_dict): """ Initiate self from a model_dict to make sure attributes such as vars, params are available. Creates lists of alphabetically sorted independent vars, dependent vars, sigma vars, and parameters. Finally it creates a signature for this model so it...
python
def _init_from_dict(self, model_dict): """ Initiate self from a model_dict to make sure attributes such as vars, params are available. Creates lists of alphabetically sorted independent vars, dependent vars, sigma vars, and parameters. Finally it creates a signature for this model so it...
[ "def", "_init_from_dict", "(", "self", ",", "model_dict", ")", ":", "sort_func", "=", "lambda", "symbol", ":", "symbol", ".", "name", "self", ".", "model_dict", "=", "OrderedDict", "(", "sorted", "(", "model_dict", ".", "items", "(", ")", ",", "key", "="...
Initiate self from a model_dict to make sure attributes such as vars, params are available. Creates lists of alphabetically sorted independent vars, dependent vars, sigma vars, and parameters. Finally it creates a signature for this model so it can be called nicely. This signature only contains ...
[ "Initiate", "self", "from", "a", "model_dict", "to", "make", "sure", "attributes", "such", "as", "vars", "params", "are", "available", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L273-L310
tBuLi/symfit
symfit/core/fit.py
BaseModel.vars_as_functions
def vars_as_functions(self): """ :return: Turn the keys of this model into :class:`~sympy.core.function.Function` objects. This is done recursively so the chain rule can be applied correctly. This is done on the basis of `connectivity_mapping`. Example: f...
python
def vars_as_functions(self): """ :return: Turn the keys of this model into :class:`~sympy.core.function.Function` objects. This is done recursively so the chain rule can be applied correctly. This is done on the basis of `connectivity_mapping`. Example: f...
[ "def", "vars_as_functions", "(", "self", ")", ":", "vars2functions", "=", "{", "}", "key", "=", "lambda", "arg", ":", "[", "isinstance", "(", "arg", ",", "Parameter", ")", ",", "str", "(", "arg", ")", "]", "# Iterate over all symbols in this model in topologic...
:return: Turn the keys of this model into :class:`~sympy.core.function.Function` objects. This is done recursively so the chain rule can be applied correctly. This is done on the basis of `connectivity_mapping`. Example: for ``{y: a * x, z: y**2 + a}`` this returns ...
[ ":", "return", ":", "Turn", "the", "keys", "of", "this", "model", "into", ":", "class", ":", "~sympy", ".", "core", ".", "function", ".", "Function", "objects", ".", "This", "is", "done", "recursively", "so", "the", "chain", "rule", "can", "be", "appli...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L313-L337
tBuLi/symfit
symfit/core/fit.py
BaseModel.function_dict
def function_dict(self): """ Equivalent to ``self.model_dict``, but with all variables replaced by functions if applicable. Sorted by the evaluation order according to ``self.ordered_symbols``, not alphabetical like ``self.model_dict``! """ func_dict = OrderedDict() ...
python
def function_dict(self): """ Equivalent to ``self.model_dict``, but with all variables replaced by functions if applicable. Sorted by the evaluation order according to ``self.ordered_symbols``, not alphabetical like ``self.model_dict``! """ func_dict = OrderedDict() ...
[ "def", "function_dict", "(", "self", ")", ":", "func_dict", "=", "OrderedDict", "(", ")", "for", "var", ",", "func", "in", "self", ".", "vars_as_functions", ".", "items", "(", ")", ":", "expr", "=", "self", ".", "model_dict", "[", "var", "]", ".", "x...
Equivalent to ``self.model_dict``, but with all variables replaced by functions if applicable. Sorted by the evaluation order according to ``self.ordered_symbols``, not alphabetical like ``self.model_dict``!
[ "Equivalent", "to", "self", ".", "model_dict", "but", "with", "all", "variables", "replaced", "by", "functions", "if", "applicable", ".", "Sorted", "by", "the", "evaluation", "order", "according", "to", "self", ".", "ordered_symbols", "not", "alphabetical", "lik...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L340-L350
tBuLi/symfit
symfit/core/fit.py
BaseModel.connectivity_mapping
def connectivity_mapping(self): """ :return: This property returns a mapping of the interdepencies between variables. This is essentially the dict representation of a connectivity graph, because working with this dict results in cleaner code. Treats variables and para...
python
def connectivity_mapping(self): """ :return: This property returns a mapping of the interdepencies between variables. This is essentially the dict representation of a connectivity graph, because working with this dict results in cleaner code. Treats variables and para...
[ "def", "connectivity_mapping", "(", "self", ")", ":", "connectivity", "=", "{", "}", "for", "var", ",", "expr", "in", "self", ".", "items", "(", ")", ":", "vars", ",", "params", "=", "seperate_symbols", "(", "expr", ")", "connectivity", "[", "var", "]"...
:return: This property returns a mapping of the interdepencies between variables. This is essentially the dict representation of a connectivity graph, because working with this dict results in cleaner code. Treats variables and parameters on the same footing.
[ ":", "return", ":", "This", "property", "returns", "a", "mapping", "of", "the", "interdepencies", "between", "variables", ".", "This", "is", "essentially", "the", "dict", "representation", "of", "a", "connectivity", "graph", "because", "working", "with", "this",...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L353-L364
tBuLi/symfit
symfit/core/fit.py
BaseModel.ordered_symbols
def ordered_symbols(self): """ :return: list of all symbols in this model, topologically sorted so they can be evaluated in the correct order. Within each group of equal priority symbols, we sort by the order of the derivative. """ key_func = lambda s...
python
def ordered_symbols(self): """ :return: list of all symbols in this model, topologically sorted so they can be evaluated in the correct order. Within each group of equal priority symbols, we sort by the order of the derivative. """ key_func = lambda s...
[ "def", "ordered_symbols", "(", "self", ")", ":", "key_func", "=", "lambda", "s", ":", "[", "isinstance", "(", "s", ",", "sympy", ".", "Derivative", ")", ",", "isinstance", "(", "s", ",", "sympy", ".", "Derivative", ")", "and", "s", ".", "derivative_cou...
:return: list of all symbols in this model, topologically sorted so they can be evaluated in the correct order. Within each group of equal priority symbols, we sort by the order of the derivative.
[ ":", "return", ":", "list", "of", "all", "symbols", "in", "this", "model", "topologically", "sorted", "so", "they", "can", "be", "evaluated", "in", "the", "correct", "order", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L367-L381
tBuLi/symfit
symfit/core/fit.py
BaseModel.vars
def vars(self): """ :return: Returns a list of dependent, independent and sigma variables, in that order. """ return self.independent_vars + self.dependent_vars + [self.sigmas[var] for var in self.dependent_vars]
python
def vars(self): """ :return: Returns a list of dependent, independent and sigma variables, in that order. """ return self.independent_vars + self.dependent_vars + [self.sigmas[var] for var in self.dependent_vars]
[ "def", "vars", "(", "self", ")", ":", "return", "self", ".", "independent_vars", "+", "self", ".", "dependent_vars", "+", "[", "self", ".", "sigmas", "[", "var", "]", "for", "var", "in", "self", ".", "dependent_vars", "]" ]
:return: Returns a list of dependent, independent and sigma variables, in that order.
[ ":", "return", ":", "Returns", "a", "list", "of", "dependent", "independent", "and", "sigma", "variables", "in", "that", "order", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L384-L388
tBuLi/symfit
symfit/core/fit.py
BaseModel.bounds
def bounds(self): """ :return: List of tuples of all bounds on parameters. """ bounds = [] for p in self.params: if p.fixed: if p.value >= 0.0: bounds.append([np.nextafter(p.value, 0), p.value]) else: ...
python
def bounds(self): """ :return: List of tuples of all bounds on parameters. """ bounds = [] for p in self.params: if p.fixed: if p.value >= 0.0: bounds.append([np.nextafter(p.value, 0), p.value]) else: ...
[ "def", "bounds", "(", "self", ")", ":", "bounds", "=", "[", "]", "for", "p", "in", "self", ".", "params", ":", "if", "p", ".", "fixed", ":", "if", "p", ".", "value", ">=", "0.0", ":", "bounds", ".", "append", "(", "[", "np", ".", "nextafter", ...
:return: List of tuples of all bounds on parameters.
[ ":", "return", ":", "List", "of", "tuples", "of", "all", "bounds", "on", "parameters", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L391-L404
tBuLi/symfit
symfit/core/fit.py
BaseModel.shared_parameters
def shared_parameters(self): """ :return: bool, indicating if parameters are shared between the vector components of this model. """ if len(self) == 1: # Not a vector return False else: params_thusfar = [] for component in self.val...
python
def shared_parameters(self): """ :return: bool, indicating if parameters are shared between the vector components of this model. """ if len(self) == 1: # Not a vector return False else: params_thusfar = [] for component in self.val...
[ "def", "shared_parameters", "(", "self", ")", ":", "if", "len", "(", "self", ")", "==", "1", ":", "# Not a vector", "return", "False", "else", ":", "params_thusfar", "=", "[", "]", "for", "component", "in", "self", ".", "values", "(", ")", ":", "vars",...
:return: bool, indicating if parameters are shared between the vector components of this model.
[ ":", "return", ":", "bool", "indicating", "if", "parameters", "are", "shared", "between", "the", "vector", "components", "of", "this", "model", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L407-L423
tBuLi/symfit
symfit/core/fit.py
BaseCallableModel.eval_components
def eval_components(self, *args, **kwargs): """ :return: evaluated lambda functions of each of the components in model_dict, to be used in numerical calculation. """ bound_arguments = self.__signature__.bind(*args, **kwargs) kwargs = bound_arguments.arguments # Only ...
python
def eval_components(self, *args, **kwargs): """ :return: evaluated lambda functions of each of the components in model_dict, to be used in numerical calculation. """ bound_arguments = self.__signature__.bind(*args, **kwargs) kwargs = bound_arguments.arguments # Only ...
[ "def", "eval_components", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "bound_arguments", "=", "self", ".", "__signature__", ".", "bind", "(", "*", "args", ",", "*", "*", "kwargs", ")", "kwargs", "=", "bound_arguments", ".", "argum...
:return: evaluated lambda functions of each of the components in model_dict, to be used in numerical calculation.
[ ":", "return", ":", "evaluated", "lambda", "functions", "of", "each", "of", "the", "components", "in", "model_dict", "to", "be", "used", "in", "numerical", "calculation", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L559-L575
tBuLi/symfit
symfit/core/fit.py
BaseGradientModel.finite_difference
def finite_difference(self, *args, **kwargs): """ Calculates a numerical approximation of the Jacobian of the model using the sixth order central finite difference method. Accepts a `dx` keyword to tune the relative stepsize used. Makes 6*n_params calls to the model. :re...
python
def finite_difference(self, *args, **kwargs): """ Calculates a numerical approximation of the Jacobian of the model using the sixth order central finite difference method. Accepts a `dx` keyword to tune the relative stepsize used. Makes 6*n_params calls to the model. :re...
[ "def", "finite_difference", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# See also: scipy.misc.derivative. It might be convinced to work, but", "# it will make way too many function evaluations", "dx", "=", "kwargs", ".", "pop", "(", "'dx'", ")", ...
Calculates a numerical approximation of the Jacobian of the model using the sixth order central finite difference method. Accepts a `dx` keyword to tune the relative stepsize used. Makes 6*n_params calls to the model. :return: A numerical approximation of the Jacobian of the model as a ...
[ "Calculates", "a", "numerical", "approximation", "of", "the", "Jacobian", "of", "the", "model", "using", "the", "sixth", "order", "central", "finite", "difference", "method", ".", "Accepts", "a", "dx", "keyword", "to", "tune", "the", "relative", "stepsize", "u...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L637-L699
tBuLi/symfit
symfit/core/fit.py
BaseGradientModel.eval_jacobian
def eval_jacobian(self, *args, **kwargs): """ :return: The jacobian matrix of the function. """ Ans = variabletuple('Ans', self) return Ans(*self.finite_difference(*args, **kwargs))
python
def eval_jacobian(self, *args, **kwargs): """ :return: The jacobian matrix of the function. """ Ans = variabletuple('Ans', self) return Ans(*self.finite_difference(*args, **kwargs))
[ "def", "eval_jacobian", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "Ans", "=", "variabletuple", "(", "'Ans'", ",", "self", ")", "return", "Ans", "(", "*", "self", ".", "finite_difference", "(", "*", "args", ",", "*", "*", "kw...
:return: The jacobian matrix of the function.
[ ":", "return", ":", "The", "jacobian", "matrix", "of", "the", "function", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L701-L706
tBuLi/symfit
symfit/core/fit.py
CallableModel.numerical_components
def numerical_components(self): """ :return: lambda functions of each of the analytical components in model_dict, to be used in numerical calculation. """ Ans = variabletuple('Ans', self.keys()) # All components must feature the independent vars and params, that's ...
python
def numerical_components(self): """ :return: lambda functions of each of the analytical components in model_dict, to be used in numerical calculation. """ Ans = variabletuple('Ans', self.keys()) # All components must feature the independent vars and params, that's ...
[ "def", "numerical_components", "(", "self", ")", ":", "Ans", "=", "variabletuple", "(", "'Ans'", ",", "self", ".", "keys", "(", ")", ")", "# All components must feature the independent vars and params, that's", "# the API convention. But for those components which also contain"...
:return: lambda functions of each of the analytical components in model_dict, to be used in numerical calculation.
[ ":", "return", ":", "lambda", "functions", "of", "each", "of", "the", "analytical", "components", "in", "model_dict", "to", "be", "used", "in", "numerical", "calculation", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L753-L769
tBuLi/symfit
symfit/core/fit.py
GradientModel.jacobian
def jacobian(self): """ :return: Jacobian filled with the symbolic expressions for all the partial derivatives. Partial derivatives are of the components of the function with respect to the Parameter's, not the independent Variable's. The return shape is a list over t...
python
def jacobian(self): """ :return: Jacobian filled with the symbolic expressions for all the partial derivatives. Partial derivatives are of the components of the function with respect to the Parameter's, not the independent Variable's. The return shape is a list over t...
[ "def", "jacobian", "(", "self", ")", ":", "jac", "=", "[", "]", "for", "var", ",", "expr", "in", "self", ".", "items", "(", ")", ":", "jac_row", "=", "[", "]", "for", "param", "in", "self", ".", "params", ":", "partial_dv", "=", "D", "(", "var"...
:return: Jacobian filled with the symbolic expressions for all the partial derivatives. Partial derivatives are of the components of the function with respect to the Parameter's, not the independent Variable's. The return shape is a list over the models components, filled...
[ ":", "return", ":", "Jacobian", "filled", "with", "the", "symbolic", "expressions", "for", "all", "the", "partial", "derivatives", ".", "Partial", "derivatives", "are", "of", "the", "components", "of", "the", "function", "with", "respect", "to", "the", "Parame...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L788-L803
tBuLi/symfit
symfit/core/fit.py
GradientModel.eval_jacobian
def eval_jacobian(self, *args, **kwargs): """ :return: Jacobian evaluated at the specified point. """ eval_jac_dict = self.jacobian_model(*args, **kwargs)._asdict() # Take zero for component which are not present, happens for Constraints jac = [[np.broadcast_to(eval_jac_d...
python
def eval_jacobian(self, *args, **kwargs): """ :return: Jacobian evaluated at the specified point. """ eval_jac_dict = self.jacobian_model(*args, **kwargs)._asdict() # Take zero for component which are not present, happens for Constraints jac = [[np.broadcast_to(eval_jac_d...
[ "def", "eval_jacobian", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "eval_jac_dict", "=", "self", ".", "jacobian_model", "(", "*", "args", ",", "*", "*", "kwargs", ")", ".", "_asdict", "(", ")", "# Take zero for component which are no...
:return: Jacobian evaluated at the specified point.
[ ":", "return", ":", "Jacobian", "evaluated", "at", "the", "specified", "point", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L805-L824
tBuLi/symfit
symfit/core/fit.py
HessianModel.hessian
def hessian(self): """ :return: Hessian filled with the symbolic expressions for all the second order partial derivatives. Partial derivatives are taken with respect to the Parameter's, not the independent Variable's. """ return [[[sympy.diff(partial_dv, param) fo...
python
def hessian(self): """ :return: Hessian filled with the symbolic expressions for all the second order partial derivatives. Partial derivatives are taken with respect to the Parameter's, not the independent Variable's. """ return [[[sympy.diff(partial_dv, param) fo...
[ "def", "hessian", "(", "self", ")", ":", "return", "[", "[", "[", "sympy", ".", "diff", "(", "partial_dv", ",", "param", ")", "for", "param", "in", "self", ".", "params", "]", "for", "partial_dv", "in", "comp", "]", "for", "comp", "in", "self", "."...
:return: Hessian filled with the symbolic expressions for all the second order partial derivatives. Partial derivatives are taken with respect to the Parameter's, not the independent Variable's.
[ ":", "return", ":", "Hessian", "filled", "with", "the", "symbolic", "expressions", "for", "all", "the", "second", "order", "partial", "derivatives", ".", "Partial", "derivatives", "are", "taken", "with", "respect", "to", "the", "Parameter", "s", "not", "the", ...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L842-L849
tBuLi/symfit
symfit/core/fit.py
HessianModel.eval_hessian
def eval_hessian(self, *args, **kwargs): """ :return: Hessian evaluated at the specified point. """ # Evaluate the hessian model and use the resulting Ans namedtuple as a # dict. From this, take the relevant components. eval_hess_dict = self.hessian_model(*args, **kwargs)...
python
def eval_hessian(self, *args, **kwargs): """ :return: Hessian evaluated at the specified point. """ # Evaluate the hessian model and use the resulting Ans namedtuple as a # dict. From this, take the relevant components. eval_hess_dict = self.hessian_model(*args, **kwargs)...
[ "def", "eval_hessian", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# Evaluate the hessian model and use the resulting Ans namedtuple as a", "# dict. From this, take the relevant components.", "eval_hess_dict", "=", "self", ".", "hessian_model", "(", "...
:return: Hessian evaluated at the specified point.
[ ":", "return", ":", "Hessian", "evaluated", "at", "the", "specified", "point", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L851-L871
tBuLi/symfit
symfit/core/fit.py
TakesData._model_sanity
def _model_sanity(model): """ Perform some basic sanity checking on the model to warn users when they might be trying something ill advised. :param model: model instance. """ if not isinstance(model, ODEModel) and not isinstance(model, BaseNumericalModel): # ...
python
def _model_sanity(model): """ Perform some basic sanity checking on the model to warn users when they might be trying something ill advised. :param model: model instance. """ if not isinstance(model, ODEModel) and not isinstance(model, BaseNumericalModel): # ...
[ "def", "_model_sanity", "(", "model", ")", ":", "if", "not", "isinstance", "(", "model", ",", "ODEModel", ")", "and", "not", "isinstance", "(", "model", ",", "BaseNumericalModel", ")", ":", "# Such a model should probably not contain derivatives", "for", "var", ",...
Perform some basic sanity checking on the model to warn users when they might be trying something ill advised. :param model: model instance.
[ "Perform", "some", "basic", "sanity", "checking", "on", "the", "model", "to", "warn", "users", "when", "they", "might", "be", "trying", "something", "ill", "advised", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1014-L1028
tBuLi/symfit
symfit/core/fit.py
TakesData.dependent_data
def dependent_data(self): """ Read-only Property :return: Data belonging to each dependent variable as a dict with variable names as key, data as value. :rtype: collections.OrderedDict """ return OrderedDict((var, self.data[var]) ...
python
def dependent_data(self): """ Read-only Property :return: Data belonging to each dependent variable as a dict with variable names as key, data as value. :rtype: collections.OrderedDict """ return OrderedDict((var, self.data[var]) ...
[ "def", "dependent_data", "(", "self", ")", ":", "return", "OrderedDict", "(", "(", "var", ",", "self", ".", "data", "[", "var", "]", ")", "for", "var", "in", "self", ".", "model", ".", "dependent_vars", ")" ]
Read-only Property :return: Data belonging to each dependent variable as a dict with variable names as key, data as value. :rtype: collections.OrderedDict
[ "Read", "-", "only", "Property" ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1031-L1040
tBuLi/symfit
symfit/core/fit.py
TakesData.independent_data
def independent_data(self): """ Read-only Property :return: Data belonging to each independent variable as a dict with variable names as key, data as value. :rtype: collections.OrderedDict """ return OrderedDict((var, self.data[var]) for var in self.mode...
python
def independent_data(self): """ Read-only Property :return: Data belonging to each independent variable as a dict with variable names as key, data as value. :rtype: collections.OrderedDict """ return OrderedDict((var, self.data[var]) for var in self.mode...
[ "def", "independent_data", "(", "self", ")", ":", "return", "OrderedDict", "(", "(", "var", ",", "self", ".", "data", "[", "var", "]", ")", "for", "var", "in", "self", ".", "model", ".", "independent_vars", ")" ]
Read-only Property :return: Data belonging to each independent variable as a dict with variable names as key, data as value. :rtype: collections.OrderedDict
[ "Read", "-", "only", "Property" ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1043-L1051
tBuLi/symfit
symfit/core/fit.py
TakesData.sigma_data
def sigma_data(self): """ Read-only Property :return: Data belonging to each sigma variable as a dict with variable names as key, data as value. :rtype: collections.OrderedDict """ sigmas = self.model.sigmas return OrderedDict((sigmas[var], self....
python
def sigma_data(self): """ Read-only Property :return: Data belonging to each sigma variable as a dict with variable names as key, data as value. :rtype: collections.OrderedDict """ sigmas = self.model.sigmas return OrderedDict((sigmas[var], self....
[ "def", "sigma_data", "(", "self", ")", ":", "sigmas", "=", "self", ".", "model", ".", "sigmas", "return", "OrderedDict", "(", "(", "sigmas", "[", "var", "]", ",", "self", ".", "data", "[", "sigmas", "[", "var", "]", "]", ")", "for", "var", "in", ...
Read-only Property :return: Data belonging to each sigma variable as a dict with variable names as key, data as value. :rtype: collections.OrderedDict
[ "Read", "-", "only", "Property" ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1054-L1064
tBuLi/symfit
symfit/core/fit.py
TakesData.data_shapes
def data_shapes(self): """ Returns the shape of the data. In most cases this will be the same for all variables of the same type, if not this raises an Exception. Ignores variables which are set to None by design so we know that those None variables can be assumed to have the sa...
python
def data_shapes(self): """ Returns the shape of the data. In most cases this will be the same for all variables of the same type, if not this raises an Exception. Ignores variables which are set to None by design so we know that those None variables can be assumed to have the sa...
[ "def", "data_shapes", "(", "self", ")", ":", "independent_shapes", "=", "[", "]", "for", "var", ",", "data", "in", "self", ".", "independent_data", ".", "items", "(", ")", ":", "if", "data", "is", "not", "None", ":", "independent_shapes", ".", "append", ...
Returns the shape of the data. In most cases this will be the same for all variables of the same type, if not this raises an Exception. Ignores variables which are set to None by design so we know that those None variables can be assumed to have the same shape as the other in calculatio...
[ "Returns", "the", "shape", "of", "the", "data", ".", "In", "most", "cases", "this", "will", "be", "the", "same", "for", "all", "variables", "of", "the", "same", "type", "if", "not", "this", "raises", "an", "Exception", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1067-L1088
tBuLi/symfit
symfit/core/fit.py
TakesData.initial_guesses
def initial_guesses(self): """ :return: Initial guesses for every parameter. """ return np.array([param.value for param in self.model.params])
python
def initial_guesses(self): """ :return: Initial guesses for every parameter. """ return np.array([param.value for param in self.model.params])
[ "def", "initial_guesses", "(", "self", ")", ":", "return", "np", ".", "array", "(", "[", "param", ".", "value", "for", "param", "in", "self", ".", "model", ".", "params", "]", ")" ]
:return: Initial guesses for every parameter.
[ ":", "return", ":", "Initial", "guesses", "for", "every", "parameter", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1091-L1095
tBuLi/symfit
symfit/core/fit.py
HasCovarianceMatrix.covariance_matrix
def covariance_matrix(self, best_fit_params): """ Given best fit parameters, this function finds the covariance matrix. This matrix gives the (co)variance in the parameters. :param best_fit_params: ``dict`` of best fit parameters as given by .best_fit_params() :return: covarianc...
python
def covariance_matrix(self, best_fit_params): """ Given best fit parameters, this function finds the covariance matrix. This matrix gives the (co)variance in the parameters. :param best_fit_params: ``dict`` of best fit parameters as given by .best_fit_params() :return: covarianc...
[ "def", "covariance_matrix", "(", "self", ",", "best_fit_params", ")", ":", "cov_matrix", "=", "self", ".", "_covariance_matrix", "(", "best_fit_params", ",", "objective", "=", "self", ".", "objective", ")", "if", "cov_matrix", "is", "None", ":", "# If the covari...
Given best fit parameters, this function finds the covariance matrix. This matrix gives the (co)variance in the parameters. :param best_fit_params: ``dict`` of best fit parameters as given by .best_fit_params() :return: covariance matrix.
[ "Given", "best", "fit", "parameters", "this", "function", "finds", "the", "covariance", "matrix", ".", "This", "matrix", "gives", "the", "(", "co", ")", "variance", "in", "the", "parameters", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1145-L1179
tBuLi/symfit
symfit/core/fit.py
Fit._determine_minimizer
def _determine_minimizer(self): """ Determine the most suitable minimizer by the presence of bounds or constraints. :return: a subclass of `BaseMinimizer`. """ if self.constraints: return SLSQP elif any([bound is not None for pair in self.model.bounds ...
python
def _determine_minimizer(self): """ Determine the most suitable minimizer by the presence of bounds or constraints. :return: a subclass of `BaseMinimizer`. """ if self.constraints: return SLSQP elif any([bound is not None for pair in self.model.bounds ...
[ "def", "_determine_minimizer", "(", "self", ")", ":", "if", "self", ".", "constraints", ":", "return", "SLSQP", "elif", "any", "(", "[", "bound", "is", "not", "None", "for", "pair", "in", "self", ".", "model", ".", "bounds", "for", "bound", "in", "pair...
Determine the most suitable minimizer by the presence of bounds or constraints. :return: a subclass of `BaseMinimizer`.
[ "Determine", "the", "most", "suitable", "minimizer", "by", "the", "presence", "of", "bounds", "or", "constraints", ".", ":", "return", ":", "a", "subclass", "of", "BaseMinimizer", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1317-L1329
tBuLi/symfit
symfit/core/fit.py
Fit._init_minimizer
def _init_minimizer(self, minimizer, **minimizer_options): """ Takes a :class:`~symfit.core.minimizers.BaseMinimizer` and instantiates it, passing the jacobian and constraints as appropriate for the minimizer. :param minimizer: :class:`~symfit.core.minimizers.BaseMinimizer` to ...
python
def _init_minimizer(self, minimizer, **minimizer_options): """ Takes a :class:`~symfit.core.minimizers.BaseMinimizer` and instantiates it, passing the jacobian and constraints as appropriate for the minimizer. :param minimizer: :class:`~symfit.core.minimizers.BaseMinimizer` to ...
[ "def", "_init_minimizer", "(", "self", ",", "minimizer", ",", "*", "*", "minimizer_options", ")", ":", "if", "isinstance", "(", "minimizer", ",", "BaseMinimizer", ")", ":", "return", "minimizer", "if", "issubclass", "(", "minimizer", ",", "BasinHopping", ")", ...
Takes a :class:`~symfit.core.minimizers.BaseMinimizer` and instantiates it, passing the jacobian and constraints as appropriate for the minimizer. :param minimizer: :class:`~symfit.core.minimizers.BaseMinimizer` to instantiate. :param **minimizer_options: Further options to ...
[ "Takes", "a", ":", "class", ":", "~symfit", ".", "core", ".", "minimizers", ".", "BaseMinimizer", "and", "instantiates", "it", "passing", "the", "jacobian", "and", "constraints", "as", "appropriate", "for", "the", "minimizer", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1331-L1374
tBuLi/symfit
symfit/core/fit.py
Fit._init_constraints
def _init_constraints(self, constraints, model): """ Takes the user provided constraints and converts them to a list of ``type(model)`` objects, which are extended to also have the parameters of ``model``. :param constraints: iterable of :class:`~sympy.core.relational.Relation`...
python
def _init_constraints(self, constraints, model): """ Takes the user provided constraints and converts them to a list of ``type(model)`` objects, which are extended to also have the parameters of ``model``. :param constraints: iterable of :class:`~sympy.core.relational.Relation`...
[ "def", "_init_constraints", "(", "self", ",", "constraints", ",", "model", ")", ":", "con_models", "=", "[", "]", "for", "constraint", "in", "constraints", ":", "if", "hasattr", "(", "constraint", ",", "'constraint_type'", ")", ":", "con_models", ".", "appen...
Takes the user provided constraints and converts them to a list of ``type(model)`` objects, which are extended to also have the parameters of ``model``. :param constraints: iterable of :class:`~sympy.core.relational.Relation` objects. :return: list of :class:`~symfit.core.f...
[ "Takes", "the", "user", "provided", "constraints", "and", "converts", "them", "to", "a", "list", "of", "type", "(", "model", ")", "objects", "which", "are", "extended", "to", "also", "have", "the", "parameters", "of", "model", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1376-L1405
tBuLi/symfit
symfit/core/fit.py
Fit.execute
def execute(self, **minimize_options): """ Execute the fit. :param minimize_options: keyword arguments to be passed to the specified minimizer. :return: FitResults instance """ minimizer_ans = self.minimizer.execute(**minimize_options) try: # to build...
python
def execute(self, **minimize_options): """ Execute the fit. :param minimize_options: keyword arguments to be passed to the specified minimizer. :return: FitResults instance """ minimizer_ans = self.minimizer.execute(**minimize_options) try: # to build...
[ "def", "execute", "(", "self", ",", "*", "*", "minimize_options", ")", ":", "minimizer_ans", "=", "self", ".", "minimizer", ".", "execute", "(", "*", "*", "minimize_options", ")", "try", ":", "# to build covariance matrix", "cov_matrix", "=", "minimizer_ans", ...
Execute the fit. :param minimize_options: keyword arguments to be passed to the specified minimizer. :return: FitResults instance
[ "Execute", "the", "fit", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1407-L1428
tBuLi/symfit
symfit/core/fit.py
ODEModel._ncomponents
def _ncomponents(self): """ :return: The `numerical_components` for an ODEModel. This differs from the traditional `numerical_components`, in that these component can also contain dependent variables, not just the independent ones. Each of these components does not c...
python
def _ncomponents(self): """ :return: The `numerical_components` for an ODEModel. This differs from the traditional `numerical_components`, in that these component can also contain dependent variables, not just the independent ones. Each of these components does not c...
[ "def", "_ncomponents", "(", "self", ")", ":", "return", "[", "sympy_to_py", "(", "expr", ",", "self", ".", "independent_vars", "+", "self", ".", "dependent_vars", "+", "self", ".", "params", ")", "for", "expr", "in", "self", ".", "values", "(", ")", "]...
:return: The `numerical_components` for an ODEModel. This differs from the traditional `numerical_components`, in that these component can also contain dependent variables, not just the independent ones. Each of these components does not correspond to e.g. `y(t) = ...`, ...
[ ":", "return", ":", "The", "numerical_components", "for", "an", "ODEModel", ".", "This", "differs", "from", "the", "traditional", "numerical_components", "in", "that", "these", "component", "can", "also", "contain", "dependent", "variables", "not", "just", "the", ...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1558-L1569
tBuLi/symfit
symfit/core/fit.py
ODEModel._njacobian
def _njacobian(self): """ :return: The `numerical_jacobian` of the components of the ODEModel with regards to the dependent variables. This is not to be confused with the jacobian of the model as a whole, which is 2D and computed with regards to the dependent vars and...
python
def _njacobian(self): """ :return: The `numerical_jacobian` of the components of the ODEModel with regards to the dependent variables. This is not to be confused with the jacobian of the model as a whole, which is 2D and computed with regards to the dependent vars and...
[ "def", "_njacobian", "(", "self", ")", ":", "return", "[", "[", "sympy_to_py", "(", "sympy", ".", "diff", "(", "expr", ",", "var", ")", ",", "self", ".", "independent_vars", "+", "self", ".", "dependent_vars", "+", "self", ".", "params", ")", "for", ...
:return: The `numerical_jacobian` of the components of the ODEModel with regards to the dependent variables. This is not to be confused with the jacobian of the model as a whole, which is 2D and computed with regards to the dependent vars and the fit parameters, and the O...
[ ":", "return", ":", "The", "numerical_jacobian", "of", "the", "components", "of", "the", "ODEModel", "with", "regards", "to", "the", "dependent", "variables", ".", "This", "is", "not", "to", "be", "confused", "with", "the", "jacobian", "of", "the", "model", ...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1572-L1588
tBuLi/symfit
symfit/core/fit.py
ODEModel.eval_components
def eval_components(self, *args, **kwargs): """ Numerically integrate the system of ODEs. :param args: Ordered arguments for the parameters and independent variables :param kwargs: Keyword arguments for the parameters and independent variables :return: ...
python
def eval_components(self, *args, **kwargs): """ Numerically integrate the system of ODEs. :param args: Ordered arguments for the parameters and independent variables :param kwargs: Keyword arguments for the parameters and independent variables :return: ...
[ "def", "eval_components", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "bound_arguments", "=", "self", ".", "__signature__", ".", "bind", "(", "*", "args", ",", "*", "*", "kwargs", ")", "t_like", "=", "bound_arguments", ".", "argum...
Numerically integrate the system of ODEs. :param args: Ordered arguments for the parameters and independent variables :param kwargs: Keyword arguments for the parameters and independent variables :return:
[ "Numerically", "integrate", "the", "system", "of", "ODEs", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1590-L1660
tBuLi/symfit
symfit/core/operators.py
call
def call(self, *values, **named_values): """ Call an expression to evaluate it at the given point. Future improvements: I would like if func and signature could be buffered after the first call so they don't have to be recalculated for every call. However, nothing can be stored on self as sympy use...
python
def call(self, *values, **named_values): """ Call an expression to evaluate it at the given point. Future improvements: I would like if func and signature could be buffered after the first call so they don't have to be recalculated for every call. However, nothing can be stored on self as sympy use...
[ "def", "call", "(", "self", ",", "*", "values", ",", "*", "*", "named_values", ")", ":", "independent_vars", ",", "params", "=", "seperate_symbols", "(", "self", ")", "# Convert to a pythonic function", "func", "=", "sympy_to_py", "(", "self", ",", "independen...
Call an expression to evaluate it at the given point. Future improvements: I would like if func and signature could be buffered after the first call so they don't have to be recalculated for every call. However, nothing can be stored on self as sympy uses __slots__ for efficiency. This means there is no ...
[ "Call", "an", "expression", "to", "evaluate", "it", "at", "the", "given", "point", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/operators.py#L48-L92
tBuLi/symfit
symfit/core/fit_results.py
FitResults.variance
def variance(self, param): """ Return the variance in a given parameter as found by the fit. :param param: ``Parameter`` Instance. :return: Variance of ``param``. """ param_number = self.model.params.index(param) try: return self.covariance_matrix[par...
python
def variance(self, param): """ Return the variance in a given parameter as found by the fit. :param param: ``Parameter`` Instance. :return: Variance of ``param``. """ param_number = self.model.params.index(param) try: return self.covariance_matrix[par...
[ "def", "variance", "(", "self", ",", "param", ")", ":", "param_number", "=", "self", ".", "model", ".", "params", ".", "index", "(", "param", ")", "try", ":", "return", "self", ".", "covariance_matrix", "[", "param_number", ",", "param_number", "]", "exc...
Return the variance in a given parameter as found by the fit. :param param: ``Parameter`` Instance. :return: Variance of ``param``.
[ "Return", "the", "variance", "in", "a", "given", "parameter", "as", "found", "by", "the", "fit", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit_results.py#L99-L111
tBuLi/symfit
symfit/core/fit_results.py
FitResults.covariance
def covariance(self, param_1, param_2): """ Return the covariance between param_1 and param_2. :param param_1: ``Parameter`` Instance. :param param_2: ``Parameter`` Instance. :return: Covariance of the two params. """ param_1_number = self.model.params.index(para...
python
def covariance(self, param_1, param_2): """ Return the covariance between param_1 and param_2. :param param_1: ``Parameter`` Instance. :param param_2: ``Parameter`` Instance. :return: Covariance of the two params. """ param_1_number = self.model.params.index(para...
[ "def", "covariance", "(", "self", ",", "param_1", ",", "param_2", ")", ":", "param_1_number", "=", "self", ".", "model", ".", "params", ".", "index", "(", "param_1", ")", "param_2_number", "=", "self", ".", "model", ".", "params", ".", "index", "(", "p...
Return the covariance between param_1 and param_2. :param param_1: ``Parameter`` Instance. :param param_2: ``Parameter`` Instance. :return: Covariance of the two params.
[ "Return", "the", "covariance", "between", "param_1", "and", "param_2", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit_results.py#L113-L123
tBuLi/symfit
symfit/core/fit_results.py
FitResults._array_safe_dict_eq
def _array_safe_dict_eq(one_dict, other_dict): """ Dicts containing arrays are hard to compare. This function uses numpy.allclose to compare arrays, and does normal comparison for all other types. :param one_dict: :param other_dict: :return: bool """ ...
python
def _array_safe_dict_eq(one_dict, other_dict): """ Dicts containing arrays are hard to compare. This function uses numpy.allclose to compare arrays, and does normal comparison for all other types. :param one_dict: :param other_dict: :return: bool """ ...
[ "def", "_array_safe_dict_eq", "(", "one_dict", ",", "other_dict", ")", ":", "for", "key", "in", "one_dict", ":", "try", ":", "assert", "one_dict", "[", "key", "]", "==", "other_dict", "[", "key", "]", "except", "ValueError", "as", "err", ":", "# When deali...
Dicts containing arrays are hard to compare. This function uses numpy.allclose to compare arrays, and does normal comparison for all other types. :param one_dict: :param other_dict: :return: bool
[ "Dicts", "containing", "arrays", "are", "hard", "to", "compare", ".", "This", "function", "uses", "numpy", ".", "allclose", "to", "compare", "arrays", "and", "does", "normal", "comparison", "for", "all", "other", "types", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit_results.py#L126-L147
tBuLi/symfit
symfit/contrib/__init__.py
_import_submodules
def _import_submodules(package_name): """ Import all submodules of a module, recursively Adapted from: http://stackoverflow.com/a/25083161 :param package_name: Package name :type package_name: str :rtype: dict[types.ModuleType] """ package = sys.modules[package_name] out = {} for lo...
python
def _import_submodules(package_name): """ Import all submodules of a module, recursively Adapted from: http://stackoverflow.com/a/25083161 :param package_name: Package name :type package_name: str :rtype: dict[types.ModuleType] """ package = sys.modules[package_name] out = {} for lo...
[ "def", "_import_submodules", "(", "package_name", ")", ":", "package", "=", "sys", ".", "modules", "[", "package_name", "]", "out", "=", "{", "}", "for", "loader", ",", "name", ",", "is_pkg", "in", "pkgutil", ".", "walk_packages", "(", "package", ".", "_...
Import all submodules of a module, recursively Adapted from: http://stackoverflow.com/a/25083161 :param package_name: Package name :type package_name: str :rtype: dict[types.ModuleType]
[ "Import", "all", "submodules", "of", "a", "module", "recursively", "Adapted", "from", ":", "http", ":", "//", "stackoverflow", ".", "com", "/", "a", "/", "25083161" ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/__init__.py#L5-L22
tBuLi/symfit
examples/fourier_series.py
fourier_series
def fourier_series(x, f, n=0): """ Returns a symbolic fourier series of order `n`. :param n: Order of the fourier series. :param x: Independent variable :param f: Frequency of the fourier series """ # Make the parameter objects for all the terms a0, *cos_a = parameters(','.join(['a{}'.f...
python
def fourier_series(x, f, n=0): """ Returns a symbolic fourier series of order `n`. :param n: Order of the fourier series. :param x: Independent variable :param f: Frequency of the fourier series """ # Make the parameter objects for all the terms a0, *cos_a = parameters(','.join(['a{}'.f...
[ "def", "fourier_series", "(", "x", ",", "f", ",", "n", "=", "0", ")", ":", "# Make the parameter objects for all the terms", "a0", ",", "", "*", "cos_a", "=", "parameters", "(", "','", ".", "join", "(", "[", "'a{}'", ".", "format", "(", "i", ")", "for"...
Returns a symbolic fourier series of order `n`. :param n: Order of the fourier series. :param x: Independent variable :param f: Frequency of the fourier series
[ "Returns", "a", "symbolic", "fourier", "series", "of", "order", "n", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/examples/fourier_series.py#L5-L19
tBuLi/symfit
examples/callable_numerical_model.py
nonanalytical_func
def nonanalytical_func(x, a, b): """ This can be any pythonic function which should be fitted, typically one which is not easily written or supported as an analytical expression. """ # Do your non-trivial magic here. In this case a Piecewise, although this # could also be done symbolically. ...
python
def nonanalytical_func(x, a, b): """ This can be any pythonic function which should be fitted, typically one which is not easily written or supported as an analytical expression. """ # Do your non-trivial magic here. In this case a Piecewise, although this # could also be done symbolically. ...
[ "def", "nonanalytical_func", "(", "x", ",", "a", ",", "b", ")", ":", "# Do your non-trivial magic here. In this case a Piecewise, although this", "# could also be done symbolically.", "y", "=", "np", ".", "zeros_like", "(", "x", ")", "y", "[", "x", ">", "b", "]", ...
This can be any pythonic function which should be fitted, typically one which is not easily written or supported as an analytical expression.
[ "This", "can", "be", "any", "pythonic", "function", "which", "should", "be", "fitted", "typically", "one", "which", "is", "not", "easily", "written", "or", "supported", "as", "an", "analytical", "expression", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/examples/callable_numerical_model.py#L5-L15
tBuLi/symfit
symfit/core/leastsqbound.py
_internal2external_grad
def _internal2external_grad(xi, bounds): """ Calculate the internal (unconstrained) to external (constained) parameter gradiants. """ grad = empty_like(xi) for i, (v, bound) in enumerate(zip(xi, bounds)): lower, upper = bound if lower is None and upper is None: # No constraints ...
python
def _internal2external_grad(xi, bounds): """ Calculate the internal (unconstrained) to external (constained) parameter gradiants. """ grad = empty_like(xi) for i, (v, bound) in enumerate(zip(xi, bounds)): lower, upper = bound if lower is None and upper is None: # No constraints ...
[ "def", "_internal2external_grad", "(", "xi", ",", "bounds", ")", ":", "grad", "=", "empty_like", "(", "xi", ")", "for", "i", ",", "(", "v", ",", "bound", ")", "in", "enumerate", "(", "zip", "(", "xi", ",", "bounds", ")", ")", ":", "lower", ",", "...
Calculate the internal (unconstrained) to external (constained) parameter gradiants.
[ "Calculate", "the", "internal", "(", "unconstrained", ")", "to", "external", "(", "constained", ")", "parameter", "gradiants", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/leastsqbound.py#L11-L27
tBuLi/symfit
symfit/core/leastsqbound.py
_internal2external_func
def _internal2external_func(bounds): """ Make a function which converts between internal (unconstrained) and external (constrained) parameters. """ ls = [_internal2external_lambda(b) for b in bounds] def convert_i2e(xi): xe = empty_like(xi) xe[:] = [l(p) for l, p in zip(ls, xi)]...
python
def _internal2external_func(bounds): """ Make a function which converts between internal (unconstrained) and external (constrained) parameters. """ ls = [_internal2external_lambda(b) for b in bounds] def convert_i2e(xi): xe = empty_like(xi) xe[:] = [l(p) for l, p in zip(ls, xi)]...
[ "def", "_internal2external_func", "(", "bounds", ")", ":", "ls", "=", "[", "_internal2external_lambda", "(", "b", ")", "for", "b", "in", "bounds", "]", "def", "convert_i2e", "(", "xi", ")", ":", "xe", "=", "empty_like", "(", "xi", ")", "xe", "[", ":", ...
Make a function which converts between internal (unconstrained) and external (constrained) parameters.
[ "Make", "a", "function", "which", "converts", "between", "internal", "(", "unconstrained", ")", "and", "external", "(", "constrained", ")", "parameters", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/leastsqbound.py#L30-L42
tBuLi/symfit
symfit/core/leastsqbound.py
_internal2external_lambda
def _internal2external_lambda(bound): """ Make a lambda function which converts a single internal (uncontrained) parameter to a external (constrained) parameter. """ lower, upper = bound if lower is None and upper is None: # no constraints return lambda x: x elif upper is None: ...
python
def _internal2external_lambda(bound): """ Make a lambda function which converts a single internal (uncontrained) parameter to a external (constrained) parameter. """ lower, upper = bound if lower is None and upper is None: # no constraints return lambda x: x elif upper is None: ...
[ "def", "_internal2external_lambda", "(", "bound", ")", ":", "lower", ",", "upper", "=", "bound", "if", "lower", "is", "None", "and", "upper", "is", "None", ":", "# no constraints", "return", "lambda", "x", ":", "x", "elif", "upper", "is", "None", ":", "#...
Make a lambda function which converts a single internal (uncontrained) parameter to a external (constrained) parameter.
[ "Make", "a", "lambda", "function", "which", "converts", "a", "single", "internal", "(", "uncontrained", ")", "parameter", "to", "a", "external", "(", "constrained", ")", "parameter", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/leastsqbound.py#L45-L59
tBuLi/symfit
symfit/core/leastsqbound.py
_external2internal_func
def _external2internal_func(bounds): """ Make a function which converts between external (constrained) and internal (unconstrained) parameters. """ ls = [_external2internal_lambda(b) for b in bounds] def convert_e2i(xe): xi = empty_like(xe) xi[:] = [l(p) for l, p in zip(ls, xe)]...
python
def _external2internal_func(bounds): """ Make a function which converts between external (constrained) and internal (unconstrained) parameters. """ ls = [_external2internal_lambda(b) for b in bounds] def convert_e2i(xe): xi = empty_like(xe) xi[:] = [l(p) for l, p in zip(ls, xe)]...
[ "def", "_external2internal_func", "(", "bounds", ")", ":", "ls", "=", "[", "_external2internal_lambda", "(", "b", ")", "for", "b", "in", "bounds", "]", "def", "convert_e2i", "(", "xe", ")", ":", "xi", "=", "empty_like", "(", "xe", ")", "xi", "[", ":", ...
Make a function which converts between external (constrained) and internal (unconstrained) parameters.
[ "Make", "a", "function", "which", "converts", "between", "external", "(", "constrained", ")", "and", "internal", "(", "unconstrained", ")", "parameters", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/leastsqbound.py#L62-L74
tBuLi/symfit
symfit/core/objectives.py
LeastSquares.eval_jacobian
def eval_jacobian(self, ordered_parameters=[], **parameters): """ Jacobian of :math:`S` in the :class:`~symfit.core.argument.Parameter`'s (:math:`\\nabla_\\vec{p} S`). :param parameters: values of the :class:`~symfit.core.argument.Parameter`'s to evaluate :math:`\\nabla_\\ve...
python
def eval_jacobian(self, ordered_parameters=[], **parameters): """ Jacobian of :math:`S` in the :class:`~symfit.core.argument.Parameter`'s (:math:`\\nabla_\\vec{p} S`). :param parameters: values of the :class:`~symfit.core.argument.Parameter`'s to evaluate :math:`\\nabla_\\ve...
[ "def", "eval_jacobian", "(", "self", ",", "ordered_parameters", "=", "[", "]", ",", "*", "*", "parameters", ")", ":", "evaluated_func", "=", "super", "(", "LeastSquares", ",", "self", ")", ".", "__call__", "(", "ordered_parameters", ",", "*", "*", "paramet...
Jacobian of :math:`S` in the :class:`~symfit.core.argument.Parameter`'s (:math:`\\nabla_\\vec{p} S`). :param parameters: values of the :class:`~symfit.core.argument.Parameter`'s to evaluate :math:`\\nabla_\\vec{p} S` at. :return: ``np.array`` of length equal to the number of paramet...
[ "Jacobian", "of", ":", "math", ":", "S", "in", "the", ":", "class", ":", "~symfit", ".", "core", ".", "argument", ".", "Parameter", "s", "(", ":", "math", ":", "\\\\", "nabla_", "\\\\", "vec", "{", "p", "}", "S", ")", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/objectives.py#L272-L298
tBuLi/symfit
symfit/core/objectives.py
LeastSquares.eval_hessian
def eval_hessian(self, ordered_parameters=[], **parameters): """ Hessian of :math:`S` in the :class:`~symfit.core.argument.Parameter`'s (:math:`\\nabla_\\vec{p}^2 S`). :param parameters: values of the :class:`~symfit.core.argument.Parameter`'s to evaluate :math:`\\nabla_\\ve...
python
def eval_hessian(self, ordered_parameters=[], **parameters): """ Hessian of :math:`S` in the :class:`~symfit.core.argument.Parameter`'s (:math:`\\nabla_\\vec{p}^2 S`). :param parameters: values of the :class:`~symfit.core.argument.Parameter`'s to evaluate :math:`\\nabla_\\ve...
[ "def", "eval_hessian", "(", "self", ",", "ordered_parameters", "=", "[", "]", ",", "*", "*", "parameters", ")", ":", "evaluated_func", "=", "super", "(", "LeastSquares", ",", "self", ")", ".", "__call__", "(", "ordered_parameters", ",", "*", "*", "paramete...
Hessian of :math:`S` in the :class:`~symfit.core.argument.Parameter`'s (:math:`\\nabla_\\vec{p}^2 S`). :param parameters: values of the :class:`~symfit.core.argument.Parameter`'s to evaluate :math:`\\nabla_\\vec{p} S` at. :return: ``np.array`` of length equal to the number of parame...
[ "Hessian", "of", ":", "math", ":", "S", "in", "the", ":", "class", ":", "~symfit", ".", "core", ".", "argument", ".", "Parameter", "s", "(", ":", "math", ":", "\\\\", "nabla_", "\\\\", "vec", "{", "p", "}", "^2", "S", ")", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/objectives.py#L300-L334
tBuLi/symfit
symfit/core/objectives.py
HessianObjectiveJacApprox.eval_hessian
def eval_hessian(self, ordered_parameters=[], **parameters): """ :return: Zeros with the shape of the Hessian of the model. """ result = super(HessianObjectiveJacApprox, self).__call__( ordered_parameters, **parameters ) num_params = len(self.model.params) ...
python
def eval_hessian(self, ordered_parameters=[], **parameters): """ :return: Zeros with the shape of the Hessian of the model. """ result = super(HessianObjectiveJacApprox, self).__call__( ordered_parameters, **parameters ) num_params = len(self.model.params) ...
[ "def", "eval_hessian", "(", "self", ",", "ordered_parameters", "=", "[", "]", ",", "*", "*", "parameters", ")", ":", "result", "=", "super", "(", "HessianObjectiveJacApprox", ",", "self", ")", ".", "__call__", "(", "ordered_parameters", ",", "*", "*", "par...
:return: Zeros with the shape of the Hessian of the model.
[ ":", "return", ":", "Zeros", "with", "the", "shape", "of", "the", "Hessian", "of", "the", "model", "." ]
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/objectives.py#L356-L367
tBuLi/symfit
symfit/core/objectives.py
LogLikelihood.eval_jacobian
def eval_jacobian(self, ordered_parameters=[], **parameters): """ Jacobian for log-likelihood is defined as :math:`\\nabla_{\\vec{p}}( \\log( L(\\vec{p} | \\vec{x})))`. :param parameters: values for the fit parameters. :param apply_func: Function to apply to each component before return...
python
def eval_jacobian(self, ordered_parameters=[], **parameters): """ Jacobian for log-likelihood is defined as :math:`\\nabla_{\\vec{p}}( \\log( L(\\vec{p} | \\vec{x})))`. :param parameters: values for the fit parameters. :param apply_func: Function to apply to each component before return...
[ "def", "eval_jacobian", "(", "self", ",", "ordered_parameters", "=", "[", "]", ",", "*", "*", "parameters", ")", ":", "apply_func", "=", "parameters", ".", "pop", "(", "'apply_func'", ")", "evaluated_func", "=", "super", "(", "LogLikelihood", ",", "self", ...
Jacobian for log-likelihood is defined as :math:`\\nabla_{\\vec{p}}( \\log( L(\\vec{p} | \\vec{x})))`. :param parameters: values for the fit parameters. :param apply_func: Function to apply to each component before returning it. The default is to sum away along the datapoint dimension using...
[ "Jacobian", "for", "log", "-", "likelihood", "is", "defined", "as", ":", "math", ":", "\\\\", "nabla_", "{", "\\\\", "vec", "{", "p", "}}", "(", "\\\\", "log", "(", "L", "(", "\\\\", "vec", "{", "p", "}", "|", "\\\\", "vec", "{", "x", "}", ")))...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/objectives.py#L388-L414
tBuLi/symfit
symfit/core/objectives.py
LogLikelihood.eval_hessian
def eval_hessian(self, ordered_parameters=[], **parameters): """ Hessian for log-likelihood is defined as :math:`\\nabla^2_{\\vec{p}}( \\log( L(\\vec{p} | \\vec{x})))`. :param parameters: values for the fit parameters. :return: array of length number of ``Parameter``'s in the mo...
python
def eval_hessian(self, ordered_parameters=[], **parameters): """ Hessian for log-likelihood is defined as :math:`\\nabla^2_{\\vec{p}}( \\log( L(\\vec{p} | \\vec{x})))`. :param parameters: values for the fit parameters. :return: array of length number of ``Parameter``'s in the mo...
[ "def", "eval_hessian", "(", "self", ",", "ordered_parameters", "=", "[", "]", ",", "*", "*", "parameters", ")", ":", "evaluated_func", "=", "super", "(", "LogLikelihood", ",", "self", ")", ".", "__call__", "(", "ordered_parameters", ",", "*", "*", "paramet...
Hessian for log-likelihood is defined as :math:`\\nabla^2_{\\vec{p}}( \\log( L(\\vec{p} | \\vec{x})))`. :param parameters: values for the fit parameters. :return: array of length number of ``Parameter``'s in the model, with all partial derivatives evaluated at p, data.
[ "Hessian", "for", "log", "-", "likelihood", "is", "defined", "as", ":", "math", ":", "\\\\", "nabla^2_", "{", "\\\\", "vec", "{", "p", "}}", "(", "\\\\", "log", "(", "L", "(", "\\\\", "vec", "{", "p", "}", "|", "\\\\", "vec", "{", "x", "}", "))...
train
https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/objectives.py#L416-L444
mixcloud/django-experiments
experiments/admin_utils.py
points_with_surrounding_gaps
def points_with_surrounding_gaps(points): """ This function makes sure that any gaps in the sequence provided have stopper points at their beginning and end so a graph will be drawn with correct 0 ranges. This is more efficient than filling in all points up to the maximum value. For example: input:...
python
def points_with_surrounding_gaps(points): """ This function makes sure that any gaps in the sequence provided have stopper points at their beginning and end so a graph will be drawn with correct 0 ranges. This is more efficient than filling in all points up to the maximum value. For example: input:...
[ "def", "points_with_surrounding_gaps", "(", "points", ")", ":", "points_with_gaps", "=", "[", "]", "last_point", "=", "-", "1", "for", "point", "in", "points", ":", "if", "last_point", "+", "1", "==", "point", ":", "pass", "elif", "last_point", "+", "2", ...
This function makes sure that any gaps in the sequence provided have stopper points at their beginning and end so a graph will be drawn with correct 0 ranges. This is more efficient than filling in all points up to the maximum value. For example: input: [1,2,3,10,11,13] output [1,2,3,4,9,10,11,12,13]
[ "This", "function", "makes", "sure", "that", "any", "gaps", "in", "the", "sequence", "provided", "have", "stopper", "points", "at", "their", "beginning", "and", "end", "so", "a", "graph", "will", "be", "drawn", "with", "correct", "0", "ranges", ".", "This"...
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/admin_utils.py#L61-L82
mixcloud/django-experiments
experiments/admin.py
ExperimentAdmin.get_fieldsets
def get_fieldsets(self, request, obj=None): """ Slightly different fields are shown for Add and Change: - default_alternative can only be changed - name can only be set on Add """ main_fields = ('description', 'start_date', 'end_date', 'state') if obj: ...
python
def get_fieldsets(self, request, obj=None): """ Slightly different fields are shown for Add and Change: - default_alternative can only be changed - name can only be set on Add """ main_fields = ('description', 'start_date', 'end_date', 'state') if obj: ...
[ "def", "get_fieldsets", "(", "self", ",", "request", ",", "obj", "=", "None", ")", ":", "main_fields", "=", "(", "'description'", ",", "'start_date'", ",", "'end_date'", ",", "'state'", ")", "if", "obj", ":", "main_fields", "+=", "(", "'default_alternative'"...
Slightly different fields are shown for Add and Change: - default_alternative can only be changed - name can only be set on Add
[ "Slightly", "different", "fields", "are", "shown", "for", "Add", "and", "Change", ":", "-", "default_alternative", "can", "only", "be", "changed", "-", "name", "can", "only", "be", "set", "on", "Add" ]
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/admin.py#L21-L42
mixcloud/django-experiments
experiments/admin.py
ExperimentAdmin.get_form
def get_form(self, request, obj=None, **kwargs): """ Add the default alternative dropdown with appropriate choices """ if obj: if obj.alternatives: choices = [(alternative, alternative) for alternative in obj.alternatives.keys()] else: ...
python
def get_form(self, request, obj=None, **kwargs): """ Add the default alternative dropdown with appropriate choices """ if obj: if obj.alternatives: choices = [(alternative, alternative) for alternative in obj.alternatives.keys()] else: ...
[ "def", "get_form", "(", "self", ",", "request", ",", "obj", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "obj", ":", "if", "obj", ".", "alternatives", ":", "choices", "=", "[", "(", "alternative", ",", "alternative", ")", "for", "alternative...
Add the default alternative dropdown with appropriate choices
[ "Add", "the", "default", "alternative", "dropdown", "with", "appropriate", "choices" ]
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/admin.py#L46-L61
mixcloud/django-experiments
experiments/admin.py
ExperimentAdmin.set_alternative_view
def set_alternative_view(self, request): """ Allows the admin user to change their assigned alternative """ if not request.user.has_perm('experiments.change_experiment'): return HttpResponseForbidden() experiment_name = request.POST.get("experiment") alternat...
python
def set_alternative_view(self, request): """ Allows the admin user to change their assigned alternative """ if not request.user.has_perm('experiments.change_experiment'): return HttpResponseForbidden() experiment_name = request.POST.get("experiment") alternat...
[ "def", "set_alternative_view", "(", "self", ",", "request", ")", ":", "if", "not", "request", ".", "user", ".", "has_perm", "(", "'experiments.change_experiment'", ")", ":", "return", "HttpResponseForbidden", "(", ")", "experiment_name", "=", "request", ".", "PO...
Allows the admin user to change their assigned alternative
[ "Allows", "the", "admin", "user", "to", "change", "their", "assigned", "alternative" ]
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/admin.py#L112-L128
mixcloud/django-experiments
experiments/admin.py
ExperimentAdmin.set_state_view
def set_state_view(self, request): """ Changes the experiment state """ if not request.user.has_perm('experiments.change_experiment'): return HttpResponseForbidden() try: state = int(request.POST.get("state", "")) except ValueError: re...
python
def set_state_view(self, request): """ Changes the experiment state """ if not request.user.has_perm('experiments.change_experiment'): return HttpResponseForbidden() try: state = int(request.POST.get("state", "")) except ValueError: re...
[ "def", "set_state_view", "(", "self", ",", "request", ")", ":", "if", "not", "request", ".", "user", ".", "has_perm", "(", "'experiments.change_experiment'", ")", ":", "return", "HttpResponseForbidden", "(", ")", "try", ":", "state", "=", "int", "(", "reques...
Changes the experiment state
[ "Changes", "the", "experiment", "state" ]
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/admin.py#L130-L156
mixcloud/django-experiments
experiments/templatetags/experiments.py
experiment
def experiment(parser, token): """ Split Testing experiment tag has the following syntax : {% experiment <experiment_name> <alternative> %} experiment content goes here {% endexperiment %} If the alternative name is neither 'test' nor 'control' an exception is raised during render...
python
def experiment(parser, token): """ Split Testing experiment tag has the following syntax : {% experiment <experiment_name> <alternative> %} experiment content goes here {% endexperiment %} If the alternative name is neither 'test' nor 'control' an exception is raised during render...
[ "def", "experiment", "(", "parser", ",", "token", ")", ":", "try", ":", "token_contents", "=", "token", ".", "split_contents", "(", ")", "experiment_name", ",", "alternative", ",", "weight", ",", "user_variable", "=", "_parse_token_contents", "(", "token_content...
Split Testing experiment tag has the following syntax : {% experiment <experiment_name> <alternative> %} experiment content goes here {% endexperiment %} If the alternative name is neither 'test' nor 'control' an exception is raised during rendering.
[ "Split", "Testing", "experiment", "tag", "has", "the", "following", "syntax", ":", "{", "%", "experiment", "<experiment_name", ">", "<alternative", ">", "%", "}", "experiment", "content", "goes", "here", "{", "%", "endexperiment", "%", "}", "If", "the", "alt...
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/templatetags/experiments.py#L80-L101
mixcloud/django-experiments
experiments/significance.py
mann_whitney
def mann_whitney(a_distribution, b_distribution, use_continuity=True): """Returns (u, p_value)""" MINIMUM_VALUES = 20 all_values = sorted(set(a_distribution) | set(b_distribution)) count_so_far = 0 a_rank_sum = 0 b_rank_sum = 0 a_count = 0 b_count = 0 variance_adjustment = 0 ...
python
def mann_whitney(a_distribution, b_distribution, use_continuity=True): """Returns (u, p_value)""" MINIMUM_VALUES = 20 all_values = sorted(set(a_distribution) | set(b_distribution)) count_so_far = 0 a_rank_sum = 0 b_rank_sum = 0 a_count = 0 b_count = 0 variance_adjustment = 0 ...
[ "def", "mann_whitney", "(", "a_distribution", ",", "b_distribution", ",", "use_continuity", "=", "True", ")", ":", "MINIMUM_VALUES", "=", "20", "all_values", "=", "sorted", "(", "set", "(", "a_distribution", ")", "|", "set", "(", "b_distribution", ")", ")", ...
Returns (u, p_value)
[ "Returns", "(", "u", "p_value", ")" ]
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/significance.py#L4-L58
mixcloud/django-experiments
experiments/significance.py
chi_square_p_value
def chi_square_p_value(matrix): """ Accepts a matrix (an array of arrays, where each child array represents a row) Example from http://math.hws.edu/javamath/ryan/ChiSquare.html: Suppose you conducted a drug trial on a group of animals and you hypothesized that the animals receiving the drug would ...
python
def chi_square_p_value(matrix): """ Accepts a matrix (an array of arrays, where each child array represents a row) Example from http://math.hws.edu/javamath/ryan/ChiSquare.html: Suppose you conducted a drug trial on a group of animals and you hypothesized that the animals receiving the drug would ...
[ "def", "chi_square_p_value", "(", "matrix", ")", ":", "try", ":", "num_rows", "=", "len", "(", "matrix", ")", "num_columns", "=", "len", "(", "matrix", "[", "0", "]", ")", "except", "TypeError", ":", "return", "None", "if", "num_rows", "!=", "num_columns...
Accepts a matrix (an array of arrays, where each child array represents a row) Example from http://math.hws.edu/javamath/ryan/ChiSquare.html: Suppose you conducted a drug trial on a group of animals and you hypothesized that the animals receiving the drug would survive better than those that did not r...
[ "Accepts", "a", "matrix", "(", "an", "array", "of", "arrays", "where", "each", "child", "array", "represents", "a", "row", ")" ]
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/significance.py#L61-L137
mixcloud/django-experiments
experiments/utils.py
WebUser.enroll
def enroll(self, experiment_name, alternatives, force_alternative=None): """ Enroll this user in the experiment if they are not already part of it. Returns the selected alternative force_alternative: Optionally force a user in an alternative at enrollment time """ chosen_alterna...
python
def enroll(self, experiment_name, alternatives, force_alternative=None): """ Enroll this user in the experiment if they are not already part of it. Returns the selected alternative force_alternative: Optionally force a user in an alternative at enrollment time """ chosen_alterna...
[ "def", "enroll", "(", "self", ",", "experiment_name", ",", "alternatives", ",", "force_alternative", "=", "None", ")", ":", "chosen_alternative", "=", "conf", ".", "CONTROL_GROUP", "experiment", "=", "experiment_manager", ".", "get_experiment", "(", "experiment_name...
Enroll this user in the experiment if they are not already part of it. Returns the selected alternative force_alternative: Optionally force a user in an alternative at enrollment time
[ "Enroll", "this", "user", "in", "the", "experiment", "if", "they", "are", "not", "already", "part", "of", "it", ".", "Returns", "the", "selected", "alternative" ]
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/utils.py#L66-L100
mixcloud/django-experiments
experiments/utils.py
WebUser.get_alternative
def get_alternative(self, experiment_name): """ Get the alternative this user is enrolled in. """ experiment = None try: # catching the KeyError instead of using .get so that the experiment is auto created if desired experiment = experiment_manager[experim...
python
def get_alternative(self, experiment_name): """ Get the alternative this user is enrolled in. """ experiment = None try: # catching the KeyError instead of using .get so that the experiment is auto created if desired experiment = experiment_manager[experim...
[ "def", "get_alternative", "(", "self", ",", "experiment_name", ")", ":", "experiment", "=", "None", "try", ":", "# catching the KeyError instead of using .get so that the experiment is auto created if desired", "experiment", "=", "experiment_manager", "[", "experiment_name", "]...
Get the alternative this user is enrolled in.
[ "Get", "the", "alternative", "this", "user", "is", "enrolled", "in", "." ]
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/utils.py#L102-L119
mixcloud/django-experiments
experiments/utils.py
WebUser.set_alternative
def set_alternative(self, experiment_name, alternative): """Explicitly set the alternative the user is enrolled in for the specified experiment. This allows you to change a user between alternatives. The user and goal counts for the new alternative will be increment, but those for the old one w...
python
def set_alternative(self, experiment_name, alternative): """Explicitly set the alternative the user is enrolled in for the specified experiment. This allows you to change a user between alternatives. The user and goal counts for the new alternative will be increment, but those for the old one w...
[ "def", "set_alternative", "(", "self", ",", "experiment_name", ",", "alternative", ")", ":", "experiment", "=", "experiment_manager", ".", "get_experiment", "(", "experiment_name", ")", "if", "experiment", ":", "self", ".", "_set_enrollment", "(", "experiment", ",...
Explicitly set the alternative the user is enrolled in for the specified experiment. This allows you to change a user between alternatives. The user and goal counts for the new alternative will be increment, but those for the old one will not be decremented. The user will be enrolled in the exp...
[ "Explicitly", "set", "the", "alternative", "the", "user", "is", "enrolled", "in", "for", "the", "specified", "experiment", "." ]
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/utils.py#L121-L129
mixcloud/django-experiments
experiments/utils.py
WebUser.goal
def goal(self, goal_name, count=1): """Record that this user has performed a particular goal This will update the goal stats for all experiments the user is enrolled in.""" for enrollment in self._get_all_enrollments(): if enrollment.experiment.is_displaying_alternatives(): ...
python
def goal(self, goal_name, count=1): """Record that this user has performed a particular goal This will update the goal stats for all experiments the user is enrolled in.""" for enrollment in self._get_all_enrollments(): if enrollment.experiment.is_displaying_alternatives(): ...
[ "def", "goal", "(", "self", ",", "goal_name", ",", "count", "=", "1", ")", ":", "for", "enrollment", "in", "self", ".", "_get_all_enrollments", "(", ")", ":", "if", "enrollment", ".", "experiment", ".", "is_displaying_alternatives", "(", ")", ":", "self", ...
Record that this user has performed a particular goal This will update the goal stats for all experiments the user is enrolled in.
[ "Record", "that", "this", "user", "has", "performed", "a", "particular", "goal" ]
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/utils.py#L131-L137
mixcloud/django-experiments
experiments/utils.py
WebUser.incorporate
def incorporate(self, other_user): """Incorporate all enrollments and goals performed by the other user If this user is not enrolled in a given experiment, the results for the other user are incorporated. For experiments this user is already enrolled in the results of the other user are...
python
def incorporate(self, other_user): """Incorporate all enrollments and goals performed by the other user If this user is not enrolled in a given experiment, the results for the other user are incorporated. For experiments this user is already enrolled in the results of the other user are...
[ "def", "incorporate", "(", "self", ",", "other_user", ")", ":", "for", "enrollment", "in", "other_user", ".", "_get_all_enrollments", "(", ")", ":", "if", "not", "self", ".", "_get_enrollment", "(", "enrollment", ".", "experiment", ")", ":", "self", ".", "...
Incorporate all enrollments and goals performed by the other user If this user is not enrolled in a given experiment, the results for the other user are incorporated. For experiments this user is already enrolled in the results of the other user are discarded. This takes a relatively l...
[ "Incorporate", "all", "enrollments", "and", "goals", "performed", "by", "the", "other", "user" ]
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/utils.py#L143-L158
mixcloud/django-experiments
experiments/utils.py
WebUser.visit
def visit(self): """Record that the user has visited the site for the purposes of retention tracking""" for enrollment in self._get_all_enrollments(): if enrollment.experiment.is_displaying_alternatives(): # We have two different goals, VISIT_NOT_PRESENT_COUNT_GOAL and VISIT_...
python
def visit(self): """Record that the user has visited the site for the purposes of retention tracking""" for enrollment in self._get_all_enrollments(): if enrollment.experiment.is_displaying_alternatives(): # We have two different goals, VISIT_NOT_PRESENT_COUNT_GOAL and VISIT_...
[ "def", "visit", "(", "self", ")", ":", "for", "enrollment", "in", "self", ".", "_get_all_enrollments", "(", ")", ":", "if", "enrollment", ".", "experiment", ".", "is_displaying_alternatives", "(", ")", ":", "# We have two different goals, VISIT_NOT_PRESENT_COUNT_GOAL ...
Record that the user has visited the site for the purposes of retention tracking
[ "Record", "that", "the", "user", "has", "visited", "the", "site", "for", "the", "purposes", "of", "retention", "tracking" ]
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/utils.py#L160-L177
mixcloud/django-experiments
experiments/utils.py
WebUser.is_enrolled
def is_enrolled(self, experiment_name, alternative): """Enroll this user in the experiment if they are not already part of it. Returns the selected alternative""" """Test if the user is enrolled in the supplied alternative for the given experiment. The supplied alternative will be added to the ...
python
def is_enrolled(self, experiment_name, alternative): """Enroll this user in the experiment if they are not already part of it. Returns the selected alternative""" """Test if the user is enrolled in the supplied alternative for the given experiment. The supplied alternative will be added to the ...
[ "def", "is_enrolled", "(", "self", ",", "experiment_name", ",", "alternative", ")", ":", "\"\"\"Test if the user is enrolled in the supplied alternative for the given experiment.\n\n The supplied alternative will be added to the list of possible alternatives for the\n experiment if...
Enroll this user in the experiment if they are not already part of it. Returns the selected alternative
[ "Enroll", "this", "user", "in", "the", "experiment", "if", "they", "are", "not", "already", "part", "of", "it", ".", "Returns", "the", "selected", "alternative" ]
train
https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/utils.py#L192-L200
jgrassler/mkdocs-pandoc
mkdocs_pandoc/filters/xref.py
XrefFilter.run
def run(self, lines): """Filter method""" ret = [] for line in lines: while True: match = re.search(r'\[(.*?)\]\((.*?\.md)\)', line) if match != None: title = match.group(1) line = re.sub(r'\[.*?\]\(.*?\.md\)', t...
python
def run(self, lines): """Filter method""" ret = [] for line in lines: while True: match = re.search(r'\[(.*?)\]\((.*?\.md)\)', line) if match != None: title = match.group(1) line = re.sub(r'\[.*?\]\(.*?\.md\)', t...
[ "def", "run", "(", "self", ",", "lines", ")", ":", "ret", "=", "[", "]", "for", "line", "in", "lines", ":", "while", "True", ":", "match", "=", "re", ".", "search", "(", "r'\\[(.*?)\\]\\((.*?\\.md)\\)'", ",", "line", ")", "if", "match", "!=", "None",...
Filter method
[ "Filter", "method" ]
train
https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/filters/xref.py#L24-L37
jgrassler/mkdocs-pandoc
mkdocs_pandoc/pandoc_converter.py
PandocConverter.flatten_pages
def flatten_pages(self, pages, level=1): """Recursively flattens pages data structure into a one-dimensional data structure""" flattened = [] for page in pages: if type(page) is list: flattened.append( { 'f...
python
def flatten_pages(self, pages, level=1): """Recursively flattens pages data structure into a one-dimensional data structure""" flattened = [] for page in pages: if type(page) is list: flattened.append( { 'f...
[ "def", "flatten_pages", "(", "self", ",", "pages", ",", "level", "=", "1", ")", ":", "flattened", "=", "[", "]", "for", "page", "in", "pages", ":", "if", "type", "(", "page", ")", "is", "list", ":", "flattened", ".", "append", "(", "{", "'file'", ...
Recursively flattens pages data structure into a one-dimensional data structure
[ "Recursively", "flattens", "pages", "data", "structure", "into", "a", "one", "-", "dimensional", "data", "structure" ]
train
https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/pandoc_converter.py#L68-L96
jgrassler/mkdocs-pandoc
mkdocs_pandoc/pandoc_converter.py
PandocConverter.convert
def convert(self): """User-facing conversion method. Returns pandoc document as a list of lines.""" lines = [] pages = self.flatten_pages(self.config['pages']) f_exclude = mkdocs_pandoc.filters.exclude.ExcludeFilter( exclude=self.exclude) f_include = mk...
python
def convert(self): """User-facing conversion method. Returns pandoc document as a list of lines.""" lines = [] pages = self.flatten_pages(self.config['pages']) f_exclude = mkdocs_pandoc.filters.exclude.ExcludeFilter( exclude=self.exclude) f_include = mk...
[ "def", "convert", "(", "self", ")", ":", "lines", "=", "[", "]", "pages", "=", "self", ".", "flatten_pages", "(", "self", ".", "config", "[", "'pages'", "]", ")", "f_exclude", "=", "mkdocs_pandoc", ".", "filters", ".", "exclude", ".", "ExcludeFilter", ...
User-facing conversion method. Returns pandoc document as a list of lines.
[ "User", "-", "facing", "conversion", "method", ".", "Returns", "pandoc", "document", "as", "a", "list", "of", "lines", "." ]
train
https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/pandoc_converter.py#L98-L167
jgrassler/mkdocs-pandoc
mkdocs_pandoc/filters/headlevels.py
HeadlevelFilter.run
def run(self, lines): """Filter method""" ret = [] for line in lines: ret.append(re.sub(r'^#', '#' + ('#' * self.offset), line)) return ret
python
def run(self, lines): """Filter method""" ret = [] for line in lines: ret.append(re.sub(r'^#', '#' + ('#' * self.offset), line)) return ret
[ "def", "run", "(", "self", ",", "lines", ")", ":", "ret", "=", "[", "]", "for", "line", "in", "lines", ":", "ret", ".", "append", "(", "re", ".", "sub", "(", "r'^#'", ",", "'#'", "+", "(", "'#'", "*", "self", ".", "offset", ")", ",", "line", ...
Filter method
[ "Filter", "method" ]
train
https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/filters/headlevels.py#L34-L40
jgrassler/mkdocs-pandoc
mkdocs_pandoc/filters/tables.py
TableFilter.blocks
def blocks(self, lines): """Groups lines into markdown blocks""" state = markdown.blockparser.State() blocks = [] # We use three states: start, ``` and '\n' state.set('start') # index of current block currblock = 0 for line in lines: line +=...
python
def blocks(self, lines): """Groups lines into markdown blocks""" state = markdown.blockparser.State() blocks = [] # We use three states: start, ``` and '\n' state.set('start') # index of current block currblock = 0 for line in lines: line +=...
[ "def", "blocks", "(", "self", ",", "lines", ")", ":", "state", "=", "markdown", ".", "blockparser", ".", "State", "(", ")", "blocks", "=", "[", "]", "# We use three states: start, ``` and '\\n'", "state", ".", "set", "(", "'start'", ")", "# index of current bl...
Groups lines into markdown blocks
[ "Groups", "lines", "into", "markdown", "blocks" ]
train
https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/filters/tables.py#L31-L57
jgrassler/mkdocs-pandoc
mkdocs_pandoc/filters/tables.py
TableFilter.convert_table
def convert_table(self, block): """"Converts a table to grid table format""" lines_orig = block.split('\n') lines_orig.pop() # Remove extra newline at end of block widest_cell = [] # Will hold the width of the widest cell for each column widest_word = [] # Will hold the width of ...
python
def convert_table(self, block): """"Converts a table to grid table format""" lines_orig = block.split('\n') lines_orig.pop() # Remove extra newline at end of block widest_cell = [] # Will hold the width of the widest cell for each column widest_word = [] # Will hold the width of ...
[ "def", "convert_table", "(", "self", ",", "block", ")", ":", "lines_orig", "=", "block", ".", "split", "(", "'\\n'", ")", "lines_orig", ".", "pop", "(", ")", "# Remove extra newline at end of block", "widest_cell", "=", "[", "]", "# Will hold the width of the wide...
Converts a table to grid table format
[ "Converts", "a", "table", "to", "grid", "table", "format" ]
train
https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/filters/tables.py#L60-L169
jgrassler/mkdocs-pandoc
mkdocs_pandoc/filters/tables.py
TableFilter.run
def run(self, lines): """Filter method: Passes all blocks through convert_table() and returns a list of lines.""" ret = [] for block in self.blocks(lines): ret.extend(self.convert_table(block)) return ret
python
def run(self, lines): """Filter method: Passes all blocks through convert_table() and returns a list of lines.""" ret = [] for block in self.blocks(lines): ret.extend(self.convert_table(block)) return ret
[ "def", "run", "(", "self", ",", "lines", ")", ":", "ret", "=", "[", "]", "for", "block", "in", "self", ".", "blocks", "(", "lines", ")", ":", "ret", ".", "extend", "(", "self", ".", "convert_table", "(", "block", ")", ")", "return", "ret" ]
Filter method: Passes all blocks through convert_table() and returns a list of lines.
[ "Filter", "method", ":", "Passes", "all", "blocks", "through", "convert_table", "()", "and", "returns", "a", "list", "of", "lines", "." ]
train
https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/filters/tables.py#L172-L179
jgrassler/mkdocs-pandoc
mkdocs_pandoc/filters/tables.py
TableFilter.ruler_line
def ruler_line(self, widths, linetype='-'): """Generates a ruler line for separating rows from each other""" cells = [] for w in widths: cells.append(linetype * (w+2)) return '+' + '+'.join(cells) + '+'
python
def ruler_line(self, widths, linetype='-'): """Generates a ruler line for separating rows from each other""" cells = [] for w in widths: cells.append(linetype * (w+2)) return '+' + '+'.join(cells) + '+'
[ "def", "ruler_line", "(", "self", ",", "widths", ",", "linetype", "=", "'-'", ")", ":", "cells", "=", "[", "]", "for", "w", "in", "widths", ":", "cells", ".", "append", "(", "linetype", "*", "(", "w", "+", "2", ")", ")", "return", "'+'", "+", "...
Generates a ruler line for separating rows from each other
[ "Generates", "a", "ruler", "line", "for", "separating", "rows", "from", "each", "other" ]
train
https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/filters/tables.py#L182-L187
jgrassler/mkdocs-pandoc
mkdocs_pandoc/filters/tables.py
TableFilter.wrap_row
def wrap_row(self, widths, row, width_default=None): """Wraps a single line table row into a fixed width, multi-line table.""" lines = [] longest = 0 # longest wrapped column in row if not width_default: width_default = self.width_default # Wrap column contents ...
python
def wrap_row(self, widths, row, width_default=None): """Wraps a single line table row into a fixed width, multi-line table.""" lines = [] longest = 0 # longest wrapped column in row if not width_default: width_default = self.width_default # Wrap column contents ...
[ "def", "wrap_row", "(", "self", ",", "widths", ",", "row", ",", "width_default", "=", "None", ")", ":", "lines", "=", "[", "]", "longest", "=", "0", "# longest wrapped column in row", "if", "not", "width_default", ":", "width_default", "=", "self", ".", "w...
Wraps a single line table row into a fixed width, multi-line table.
[ "Wraps", "a", "single", "line", "table", "row", "into", "a", "fixed", "width", "multi", "-", "line", "table", "." ]
train
https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/filters/tables.py#L190-L234
jgrassler/mkdocs-pandoc
mkdocs_pandoc/filters/chapterhead.py
ChapterheadFilter.run
def run(self, lines): """Filter method""" head = [('#' * self.headlevel) + ' ' + self.title, ''] head.extend(lines) return head
python
def run(self, lines): """Filter method""" head = [('#' * self.headlevel) + ' ' + self.title, ''] head.extend(lines) return head
[ "def", "run", "(", "self", ",", "lines", ")", ":", "head", "=", "[", "(", "'#'", "*", "self", ".", "headlevel", ")", "+", "' '", "+", "self", ".", "title", ",", "''", "]", "head", ".", "extend", "(", "lines", ")", "return", "head" ]
Filter method
[ "Filter", "method" ]
train
https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/filters/chapterhead.py#L26-L33
jgrassler/mkdocs-pandoc
mkdocs_pandoc/filters/images.py
ImageFilter.run
def run(self, lines): """Filter method""" # Nothing to do in this case if (not self.adjust_path) and (not self.image_ext): return lines ret = [] for line in lines: processed = {} while True: alt = '' img_name =...
python
def run(self, lines): """Filter method""" # Nothing to do in this case if (not self.adjust_path) and (not self.image_ext): return lines ret = [] for line in lines: processed = {} while True: alt = '' img_name =...
[ "def", "run", "(", "self", ",", "lines", ")", ":", "# Nothing to do in this case", "if", "(", "not", "self", ".", "adjust_path", ")", "and", "(", "not", "self", ".", "image_ext", ")", ":", "return", "lines", "ret", "=", "[", "]", "for", "line", "in", ...
Filter method
[ "Filter", "method" ]
train
https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/filters/images.py#L30-L89
jgrassler/mkdocs-pandoc
mkdocs_pandoc/filters/toc.py
TocFilter.run
def run(self, lines): """Filter method""" ret = [] for line in lines: ret.append(re.sub(r'^\s*\[TOC\]\s*', '', line)) return ret
python
def run(self, lines): """Filter method""" ret = [] for line in lines: ret.append(re.sub(r'^\s*\[TOC\]\s*', '', line)) return ret
[ "def", "run", "(", "self", ",", "lines", ")", ":", "ret", "=", "[", "]", "for", "line", "in", "lines", ":", "ret", ".", "append", "(", "re", ".", "sub", "(", "r'^\\s*\\[TOC\\]\\s*'", ",", "''", ",", "line", ")", ")", "return", "ret" ]
Filter method
[ "Filter", "method" ]
train
https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/filters/toc.py#L21-L27