gpkit.tools package¶
Submodules¶
gpkit.tools.autosweep module¶
Tools for optimal fits to GP sweeps
-
class
gpkit.tools.autosweep.
BinarySweepTree
(bounds, sols, sweptvar, costposy)¶ Bases:
object
Spans a line segment. May contain two subtrees that divide the segment.
- bounds : two-element list
- The left and right boundaries of the segment
- sols : two-element list
- The left and right solutions of the segment
- costs : array
- The left and right logcosts of the segment
- splits : None or two-element list
- If not None, contains the left and right subtrees
- splitval : None or float
- The worst-error point, where the split will be if tolerance is too low
- splitlb : None or float
- The cost lower bound at splitval
- splitub : None or float
- The cost upper bound at splitval
-
add_split
(splitval, splitsol)¶ Creates subtrees from bounds[0] to splitval and splitval to bounds[1]
-
add_splitcost
(splitval, splitlb, splitub)¶ Adds a splitval, lower bound, and upper bound
-
cost_at
(_, value, bound=None)¶ Logspace interpolates between split and costs. Guaranteed bounded.
-
min_bst
(value)¶ Returns smallest bst around value.
-
posy_at
(posy, value)¶ Logspace interpolates between sols to get posynomial values.
No guarantees, just like a regular sweep.
-
sample_at
(values)¶ Creates a SolutionOracle at a given range of values
-
save
(filename='autosweep.p')¶ Pickles the autosweep and saves it to a file.
- The saved autosweep is identical except for two things:
- the cost is made unitless
- each solution’s ‘program’ attribute is removed
Solution can then be loaded with e.g.: >>> import cPickle as pickle >>> pickle.load(open(“autosweep.p”))
-
solarray
¶ Returns a solution array of all the solutions in an autosweep
-
sollist
¶ Returns a list of all the solutions in an autosweep
-
class
gpkit.tools.autosweep.
SolutionOracle
(bst, sampled_at)¶ Bases:
object
Acts like a SolutionArray for autosweeps
-
cost_lb
()¶ Gets cost lower bounds from the BST and units them
-
cost_ub
()¶ Gets cost upper bounds from the BST and units them
-
plot
(posys=None, axes=None)¶ Plots the sweep for each posy
-
solarray
¶ Returns a solution array of all the solutions in an autosweep
-
-
gpkit.tools.autosweep.
autosweep_1d
(model, logtol, sweepvar, bounds, **solvekwargs)¶ Autosweep a model over one sweepvar
-
gpkit.tools.autosweep.
get_tol
(costs, bounds, sols, variable)¶ Gets the intersection point and corresponding bounds from two solutions.
-
gpkit.tools.autosweep.
recurse_splits
(model, bst, variable, logtol, solvekwargs, sols)¶ Recursively splits a BST until logtol is reached
gpkit.tools.docstring module¶
Docstring-parsing methods
-
gpkit.tools.docstring.
check_and_parse_flag
(string, flag, errorcatch, declaration_func=None)¶ Checks for instances of flag in string and parses them.
-
gpkit.tools.docstring.
constant_declare
(string, flag, idx2, countstr)¶ Turns Variable declarations into Constant ones
-
gpkit.tools.docstring.
expected_unbounded
(instance, doc)¶ Gets expected-unbounded variables from a string
-
gpkit.tools.docstring.
parse_variables
(string, errorcatch=True)¶ Parses a string to determine what variables to create from it
-
gpkit.tools.docstring.
variable_declaration
(nameval, units, label, line, errorcatch=True)¶ Turns parsed output into a Variable declaration
-
gpkit.tools.docstring.
vv_declare
(string, flag, idx2, countstr)¶ Turns Variable declarations into VectorVariable ones
gpkit.tools.fmincon module¶
gpkit.tools.spdata module¶
Implements SPData class
-
class
gpkit.tools.spdata.
SPData
(model)¶ Bases:
gpkit.nomials.data.NomialData
Generates matrices describing an SP.
>>> spdata = SPData(m) >>> spdata.save('example_sp.h5')
-
save
(filename)¶ Save spdata to an h5 file.
-
gpkit.tools.tools module¶
Non-application-specific convenience methods for GPkit
-
gpkit.tools.tools.
mdmake
(filename, make_tex=True)¶ Make a python file and (optional) a pandoc-ready .tex.md file
-
gpkit.tools.tools.
mdparse
(filename, return_tex=False)¶ Parse markdown file, returning as strings python and (optionally) .tex.md
-
gpkit.tools.tools.
te_exp_minus1
(posy, nterm)¶ Taylor expansion of e^{posy} - 1
- posy : gpkit.Posynomial
- Variable or expression to exponentiate
- nterm : int
- Number of non-constant terms in resulting Taylor expansion
- gpkit.Posynomial
- Taylor expansion of e^{posy} - 1, carried to nterm terms
-
gpkit.tools.tools.
te_secant
(var, nterm)¶ Taylor expansion of secant(var).
- var : gpkit.monomial
- Variable or expression argument
- nterm : int
- Number of non-constant terms in resulting Taylor expansion
- gpkit.Posynomial
- Taylor expansion of secant(x), carried to nterm terms
-
gpkit.tools.tools.
te_tangent
(var, nterm)¶ Taylor expansion of tangent(var).
- var : gpkit.monomial
- Variable or expression argument
- nterm : int
- Number of non-constant terms in resulting Taylor expansion
- gpkit.Posynomial
- Taylor expansion of tangent(x), carried to nterm terms
Module contents¶
Contains miscellaneous tools including fmincon comparison tool