5656from scipy .special import gamma
5757from scipy import optimize
5858
59- __version__ = "0.9 "
59+ __version__ = "1.0 "
6060
6161# Some constants of the program.
6262# Dimensions: 0 - x, 1 - alpha, 2 - beta
7474}
7575default = [1.5 , 0.0 , 0.0 , 1.0 ] # default values of the parameters for fit.
7676default = {k : {par_names [k ][i ]: default [i ] for i in range (4 )} for k in par_names .keys ()}
77-
7877f_bounds = [
7978 lambda x : _reflect (x , * par_bounds [0 ]),
8079 lambda x : _reflect (x , * par_bounds [1 ]),
@@ -159,6 +158,15 @@ def _interpolate(points, grid, lower, upper):
159158 return np .reshape (result , point_shape )
160159
161160
161+ def _psi (alpha ):
162+ return np .pi / 2 * (alpha - 1 - np .sign (alpha - 1 ))
163+
164+
165+ def _phi (alpha , beta ):
166+ """ Common function. """
167+ return beta * np .tan (np .pi * alpha / 2.0 )
168+
169+
162170convert_to_par0 = {
163171 '0' : lambda x : x ,
164172 '1' : lambda x : np .array ([
@@ -209,7 +217,7 @@ def _interpolate(points, grid, lower, upper):
209217 ]),
210218 'B' : lambda x : np .array ([
211219 x [0 ],
212- np .arctan (_phi (x [0 ], x [1 ]) / (( x [0 ] - 1 - np . sign ( x [ 0 ] - 1 )) * np . pi / 2 ) ),
220+ np .arctan (_phi (x [0 ], x [1 ])) / _psi ( x [0 ]),
213221 (x [2 ] / (x [3 ] ** x [0 ]) - _phi (x [0 ], x [1 ])) * np .cos (np .arctan (_phi (x [0 ], x [1 ]))),
214222 x [3 ] ** x [0 ] / np .cos (np .arctan (_phi (x [0 ], x [1 ])))
215223 ])
@@ -233,9 +241,14 @@ def convert(cls, pars, par_in, par_out):
233241 Use to convert a parameter array from one parametrization to another.
234242
235243 Examples:
236- >>> a = np.array([1.5, 0.5, 0, 1.2])
237- >>> Parameters.convert(a, '1', 'B')
238- array([1.5 , 0.5669115 , 0.03896531, 1.46969385])
244+ >>> a = np.array([1.6, 0.5, 0.3, 1.2])
245+ >>> b = Parameters.convert(a, '1', 'B')
246+ >>> b
247+ array([1.6 , 0.55457302, 0.2460079 , 1.4243171 ])
248+ >>> c = Parameters.convert(b, 'B', '1')
249+ >>> c
250+ array([1.6, 0.5, 0.3, 1.2])
251+ >>> np.testing.assert_allclose(a, c)
239252
240253 :param pars: array of parameters to be converted
241254 :type x: :class:`~numpy.ndarray`
@@ -268,14 +281,13 @@ def get(self, par_out=None):
268281 Examples:
269282 >>> p = Parameters(par='1', alpha=1.5, beta=0.5, mu=0, sigma=1.2) # to convert
270283 >>> p.get('B') # returns the parameters in the parametrization B
271- array([1.5 , 0.5669115 , 0.03896531, 1.46969385])
284+ array([1.5 , 0.59033447 , 0.03896531, 1.46969385])
272285
273286 """
274287 if par_out is None :
275288 par_out = self .par
276289 return Parameters .convert (self ._x , self .par , par_out )
277290
278-
279291 def __str__ (self ):
280292 txt = ', ' .join (['{{0[{0}]}}: {{1[{1}]:.2f}}' .format (i , i ) for i in range (4 )])
281293 txt += '. Parametrization: {2}.'
@@ -299,15 +311,6 @@ def x(self, values):
299311 self ._x [i ] = f_bounds [self .par ][self .pnames [i ]](vals [j ])
300312
301313
302- def _phi (alpha , beta ):
303- """ Common function. """
304- return beta * np .tan (np .pi * alpha / 2.0 )
305-
306-
307- def _psi (alpha ):
308- return np .pi / 2 * (alpha - 1 - np .sign (alpha - 1 ))
309-
310-
311314def _calculate_levy (x , alpha , beta , cdf = False ):
312315 """
313316 Calculation of Levy stable distribution via numerical integration.
@@ -587,7 +590,7 @@ def random(alpha, beta, mu=0.0, sigma=1.0, shape=()):
587590
588591 Example:
589592 >>> x = random(1.5, 0, shape=100) # parametrization 0 is implicit
590- >>> x = random(*Parameters.convert([1.5, 1.2 , 0.1 , 1.2 ] , 'B' ,'0')) # example with conversion
593+ >>> x = random(*Parameters.convert([1.5, 0.905 , 0.707 , 1.414 ] ,'B' ,'0'), shape=100 ) # example with conversion
591594
592595 :param alpha: alpha
593596 :type alpha: float
0 commit comments