How to get parameter arguments from frozen spicy.stats distribution?

Frozen spread

In scipy.statsyou can create a frozen distribution that allows you to parameterize (shape, location and scale) the distributions that will be permanently set for this instance.

For example, you can create a gamma distribution ( scipy.stats.gamma) with parameters a, locand scalefreeze them so that they do not need to be transmitted every time distribution is required.

import scipy.stats as stats

# Parameters for this particular gamma distribution
a, loc, scale = 3.14, 5.0, 2.0

# Do something with the general distribution parameterized
print 'gamma stats:', stats.gamma(a, loc=loc, scale=scale).stats()

# Create frozen distribution
rv = stats.gamma(a, loc=loc, scale=scale)

# Do something with the specific, already parameterized, distribution
print 'rv stats   :', rv.stats()

gamma stats: (array(11.280000000000001), array(12.56))
rv stats   : (array(11.280000000000001), array(12.56))

Available options rv?

Since the parameters will most likely not be passed as a result of this function, is there a way to return these values ​​only from the frozen distribution,, rvlater?

+4
1

rv

, , , . args kwds. , .

import scipy.stats as stats

# Parameters for this particular alpha distribution
a, loc, scale = 3.14, 5.0, 2.0

# Create frozen distribution
rv1 = stats.gamma(a, loc, scale)
rv2 = stats.gamma(a, loc=loc, scale=scale)

# Do something with frozen parameters
print 'positional and keyword'
print 'frozen args : {}'.format(rv1.args)
print 'frozen kwds : {}'.format(rv1.kwds)
print
print 'positional only'
print 'frozen args : {}'.format(rv2.args)
print 'frozen kwds : {}'.format(rv2.kwds)

positional and keyword
frozen args : (3.14, 5.0, 2.0)
frozen kwds : {}

positional only
frozen args : (3.14,)
frozen kwds : {'loc': 5.0, 'scale': 2.0}

: , args, kwds

.dist._parse_args(), .

# Get the original parameters regardless of argument type
shape1, loc1, scale1 = rv1.dist._parse_args(*rv1.args, **rv1.kwds)
shape2, loc2, scale2 = rv2.dist._parse_args(*rv2.args, **rv2.kwds)

print 'positional and keyword'
print 'frozen parameters: shape={}, loc={}, scale={}'.format(shape1, loc1, scale1)
print
print 'positional only'
print 'frozen parameters: shape={}, loc={}, scale={}'.format(shape2, loc2, scale2)

positional and keyword
frozen parameters: shape=(3.14,), loc=5.0, scale=2.0

positional only
frozen parameters: shape=(3.14,), loc=5.0, scale=2.0

Caveat

, - , , , API , , , , - Python :).

+3

All Articles