|
11 | 11 | # See LICENSE.txt for license information. |
12 | 12 | # |
13 | 13 | ############################################################################## |
14 | | -"""Defines BaseFunction, the base class for mathematical functions in srmise.""" |
| 14 | +"""Defines BaseFunction, the base class for mathematical functions in |
| 15 | +srmise.""" |
15 | 16 |
|
16 | 17 | import logging |
17 | 18 | import re |
|
25 | 26 |
|
26 | 27 |
|
27 | 28 | class BaseFunction(object): |
28 | | - """Base class for mathematical functions which model numeric sequences. |
| 29 | + """Base class for mathematical functions which model numeric |
| 30 | + sequences. |
29 | 31 |
|
30 | 32 | Attributes |
31 | 33 | ------------- |
@@ -76,7 +78,7 @@ def __init__( |
76 | 78 | base=None, |
77 | 79 | Cache=None, |
78 | 80 | ): |
79 | | - """Set parameterdict defined by subclass |
| 81 | + """Set parameterdict defined by subclass. |
80 | 82 |
|
81 | 83 | Parameters |
82 | 84 | ---------- |
@@ -159,32 +161,50 @@ def __init__( |
159 | 161 | # "Virtual" class methods #### |
160 | 162 |
|
161 | 163 | def actualize(self, *args, **kwds): |
162 | | - """Create ModelPart instance of self with given parameters. ("Virtual" method)""" |
| 164 | + """Create ModelPart instance of self with given parameters. |
| 165 | +
|
| 166 | + ("Virtual" method) |
| 167 | + """ |
163 | 168 | emsg = "actualize() must be implemented in a BaseFunction subclass." |
164 | 169 | raise NotImplementedError(emsg) |
165 | 170 |
|
166 | 171 | def estimate_parameters(self, *args, **kwds): |
167 | | - """Estimate BaseFunction parameters from supplied data. ("Virtual" method)""" |
| 172 | + """Estimate BaseFunction parameters from supplied data. |
| 173 | +
|
| 174 | + ("Virtual" method) |
| 175 | + """ |
168 | 176 | emsg = "estimate_parameters() must be implemented in a BaseFunction subclass." |
169 | 177 | raise NotImplementedError(emsg) |
170 | 178 |
|
171 | 179 | def _jacobianraw(self, *args, **kwds): |
172 | | - """Calculate the jacobian. ("Virtual" method)""" |
| 180 | + """Calculate the jacobian. |
| 181 | +
|
| 182 | + ("Virtual" method) |
| 183 | + """ |
173 | 184 | emsg = "_jacobianraw() must be implemented in a BaseFunction subclass." |
174 | 185 | raise NotImplementedError(emsg) |
175 | 186 |
|
176 | 187 | def _transform_derivativesraw(self, *args, **kwds): |
177 | | - """Convert BaseFunction parameters to another form. ("Virtual" method)""" |
| 188 | + """Convert BaseFunction parameters to another form. |
| 189 | +
|
| 190 | + ("Virtual" method) |
| 191 | + """ |
178 | 192 | emsg = "transform_parameters() must be implemented in a BaseFunction subclass." |
179 | 193 | raise NotImplementedError(emsg) |
180 | 194 |
|
181 | 195 | def _transform_parametersraw(self, *args, **kwds): |
182 | | - """Convert BaseFunction parameters to another form. ("Virtual" method)""" |
| 196 | + """Convert BaseFunction parameters to another form. |
| 197 | +
|
| 198 | + ("Virtual" method) |
| 199 | + """ |
183 | 200 | emsg = "transform_parameters() must be implemented in a BaseFunction subclass." |
184 | 201 | raise NotImplementedError(emsg) |
185 | 202 |
|
186 | 203 | def _valueraw(self, *args, **kwds): |
187 | | - """Calculate value of function. ("Virtual" method)""" |
| 204 | + """Calculate value of function. |
| 205 | +
|
| 206 | + ("Virtual" method) |
| 207 | + """ |
188 | 208 | emsg = "_valueraw must() be implemented in a BaseFunction subclass." |
189 | 209 | raise NotImplementedError(emsg) |
190 | 210 |
|
@@ -225,7 +245,8 @@ def jacobian(self, p, r, rng=None): |
225 | 245 | return self._jacobianraw(p.pars, r, p.free) |
226 | 246 |
|
227 | 247 | def transform_derivatives(self, pars, in_format=None, out_format=None): |
228 | | - """Return gradient matrix for pars converted from in_format to out_format. |
| 248 | + """Return gradient matrix for pars converted from in_format to |
| 249 | + out_format. |
229 | 250 |
|
230 | 251 | Parameters |
231 | 252 | ---------- |
@@ -266,7 +287,8 @@ def transform_derivatives(self, pars, in_format=None, out_format=None): |
266 | 287 | return self._transform_derivativesraw(pars, in_format=in_format, out_format=out_format) |
267 | 288 |
|
268 | 289 | def transform_parameters(self, pars, in_format=None, out_format=None): |
269 | | - """Return new sequence with pars converted from in_format to out_format. |
| 290 | + """Return new sequence with pars converted from in_format to |
| 291 | + out_format. |
270 | 292 |
|
271 | 293 | Also restores parameters to a preferred range if it permits multiple |
272 | 294 | values that correspond to the same physical result. |
@@ -310,7 +332,8 @@ def transform_parameters(self, pars, in_format=None, out_format=None): |
310 | 332 | return self._transform_parametersraw(pars, in_format=in_format, out_format=out_format) |
311 | 333 |
|
312 | 334 | def value(self, p, r, rng=None): |
313 | | - """Calculate value of ModelPart over r, possibly restricted by range. |
| 335 | + """Calculate value of ModelPart over r, possibly restricted by |
| 336 | + range. |
314 | 337 |
|
315 | 338 | Parameters |
316 | 339 | ---------- |
@@ -345,7 +368,8 @@ def value(self, p, r, rng=None): |
345 | 368 | return self._valueraw(p.pars, r) |
346 | 369 |
|
347 | 370 | def pgradient(self, p, format): |
348 | | - """Return gradient matrix of parameterization in specified format wrt "internal" format at p. |
| 371 | + """Return gradient matrix of parameterization in specified |
| 372 | + format wrt "internal" format at p. |
349 | 373 |
|
350 | 374 | Consider the "internal" parameterization given by (i0, i1, ..., in). |
351 | 375 | Each parameter in a different format, say (o0, o1, ..., om), is a |
@@ -373,7 +397,7 @@ def pgradient(self, p, format): |
373 | 397 | return |
374 | 398 |
|
375 | 399 | def getmodule(self): |
376 | | - """Return 'diffpy.srmise.basefunction'""" |
| 400 | + """Return 'diffpy.srmise.basefunction'.""" |
377 | 401 | return "diffpy.srmise.basefunction" |
378 | 402 |
|
379 | 403 | def writestr(self, baselist): |
@@ -473,22 +497,25 @@ def factory(functionstr, baselist): |
473 | 497 |
|
474 | 498 | @staticmethod |
475 | 499 | def safefunctionlist(fs): |
476 | | - """Return list of BaseFunction instances where any dependencies occur earlier in list. |
| 500 | + """Return list of BaseFunction instances where any dependencies |
| 501 | + occur earlier in list. |
477 | 502 |
|
478 | 503 | Any functions with hidden dependent functions (i.e. those not in fs) |
479 | 504 | are included in the returned list. This list provides an order that |
480 | 505 | is guaranteed to be safe for saving/reinstantiating peak functions. |
481 | 506 |
|
482 | 507 | Parameters |
483 | | - fs: List of BaseFunction instances.""" |
| 508 | + fs: List of BaseFunction instances. |
| 509 | + """ |
484 | 510 | fsafe = [] |
485 | 511 | for f in fs: |
486 | 512 | BaseFunction.safefunction(f, fsafe) |
487 | 513 | return fsafe |
488 | 514 |
|
489 | 515 | @staticmethod |
490 | 516 | def safefunction(f, fsafe): |
491 | | - """Append BaseFunction instance f to fsafe, but adding dependent functions first. |
| 517 | + """Append BaseFunction instance f to fsafe, but adding dependent |
| 518 | + functions first. |
492 | 519 |
|
493 | 520 | Does not handle circular dependencies. |
494 | 521 |
|
|
0 commit comments