ChainManager

class xspec.ChainManager

Monte Carlo Markov Chain container.

PyXspec automatically creates a single object of this class, named AllChains.

Methods

  • __call__ (the '()' operator)

  • __iadd__ (the '+=' operator)

  • __isub__ (the '-=' operator)

  • best

  • clear

  • dic

  • margin

  • marginResults

  • show

  • stat

Attributes

These are the values which will be used when creating new Chain objects, unless they are explicitly overridden as arguments to the Chain class constructor. For more detail, see the descriptions for the corresponding attributes in the Chain class doc.

  • defAlgorithm

  • defBurn

  • defFileType

  • defLength

  • defProposal

  • defRand

  • defRescale

  • defTemperature

  • defWalkers

__call__(index)

Get a Chain object from the AllChains container.

Args:
index: The index of a currently loaded chain file. The list

of currently loaded chains can be seen with the AllChains.show() method. The valid range is: 1 <= index <= nLoadedChains.

Note that the returned Chain object's modifiable attributes will be initialized with the current AllChains def<attribute> settings:

# Example: Load 2 chains from pre-existing files:
AllChains += "chain1.fits"
AllChains += "chain2.fits"
# and use the __call__ method to retrieve a Chain object 
#   for the 2nd chain:
c2 = AllChains(2)
__iadd__(chain)

Load a pre-existing chain into the AllChains container.

Args:
chain: may be a currently existing chain object which had been

unloaded earlier:

>>> AllChains += myChain1

the filename of an existing chain file:

>>> AllChains += "chainFile.fits"

or the filename of a new chain:

>>> AllChains += "newChainFile.fits"

The last example will also perform a chain run using the default settings.

__init__()
__isub__(chain)

Unload one or more chain objects from container.

Args:

chain: may either be a chain object:

>>> AllChains -= myChain1

a filename:

>>> AllChains -= "chainFile.fits"

the chain's current index [int] in the AllChains container:

>>> AllChains -= 2

or a '*' to unload ALL chains (equivalent to AllChains.clear()):

>>> AllChains -= '*'
best()

Return the best-fit parameters and statistic in the loaded chains.

The values are returned in a tuple with the best-fit statistic appearing at the end.

clear()

Unload all chains from container

dic()

Calculate the deviance information criterion from all chains

margin(argString)

Calculate a multi-dimensional probability distribution.

Args:

argString: [string]

This uses identical syntax to the standard interactive XSPEC margin command. "<step spec> [<step spec> ...]" where:

<step spec> ::= [<log|nolog>] [<modName>:]<param index>

<low value> <high value> <# steps>

See the XSPEC manual for a more detailed description of specs.

Examples:

# Calculate a 2-D probability distribution of parameter 1
# from 10.0-12.0 in 20 linear bins, and parameter 3 from
# 1.0-10.0 in 5 logarithmic bins. 
AllChains.margin("1 10.0 12.0 20 log 3 1.0 10.0 5")
# Now calculate for parameter 2 in 10 log bins and parameter 4
# in 10 linear bins.
AllChains.margin("2 10.0 100.0 10 nolog 4 20. 30. 10")
marginResults(arg)

Retrieve values from the most recent margin calculation.

Args:

arg:

argument should either be 'probability' or a parameter specifier. A parameter specifier should be a string of the form:

'[<modName>:]<parNum>'

or simply an integer <parNum>.

Returns the requested values as a list of floats.

show()

Display information for current attributes and loaded chains.

stat(parIdx)

Display statistical information on a particular chain parameter.

Args:
parIdx: The parameter index number, including optional model

name: [<modName>:]<idx>. May be entered as a string or int (if no model name).

property defAlgorithm

Default chain algorithm (orig = 'gw').

property defBurn

Default burn length for new Chain objects (orig = 0).

property defFileType

Default output file format (orig = 'fits').

property defLength

Default chain length (orig = 100).

property defProposal

Default chain proposal (orig = 'gaussian fit').

property defRand

Default randomization setting (orig = False).

property defRescale

Default covariance rescale fraction (orig = None).

property defTemperature

Default chain temperature (orig = 1.0).

property defWalkers

Default walkers parameter for 'gw' chains (orig = 10).