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
-
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.fmincon module¶
A module to facilitate testing GPkit against fmincon
-
gpkit.tools.fmincon.
generate_mfiles
(model, algorithm='interior-point', guesstype='ones', gradobj='on', gradconstr='on', writefiles=True)¶ A method for preparing fmincon input files to run a GPkit program
- INPUTS:
model [GPkit model] The model to replicate in fmincon
- algorithm: [string] Algorithm used by fmincon
- ‘interior-point’: uses the interior point solver ‘SQP’: uses the sequential quadratic programming solver
- guesstype: [string] The type of initial guess used
‘ones’: One for each variable ‘order-of-magnitude-floor’: The “log-floor” order of
magnitude of the GP/SP optimal solution (i.e. O(99)=10)- ‘order-of-magnitude-round’: The “log-nearest” order of
- magnitude of the GP/SP optimal solution (i.e. O(42)=100)
- ‘almost-exact-solution’: The GP/SP optimal solution rounded
- to 1 significant figure
- gradconstr: [string] Include analytical constraint gradients?
- ‘on’: Yes ‘off’: No
- gradobj: [string] Include analytical objective gradients?
- ‘on’: Yes ‘off’: No
writefiles: [Boolean] whether or not to actually write the m files
-
gpkit.tools.fmincon.
make_initial_guess
(model, newlist, guesstype='ones')¶ Returns initial guess
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.
composite_objective
(*objectives, **kwargs)¶ Creates a cost function that sweeps between multiple objectives.
-
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