コード例 #1
0
    def create(path, density):
        """ Write a new MixtureDensity object to disk.

        :param path: Path to the storage location, which will be created as a directory.
        :type path: str
        :param density: Mixture density.
        :type density: pypmc.density.MixtureDensity
        """
        description = {}
        description['version'] = eos.version()
        description['type'] = 'MixtureDensity'
        description['components'] = []
        for c in density.components:
            if type(c) is pypmc.density.gauss.Gauss:
                description['components'].append({
                    'type': 'gauss',
                    'mu': c.mu.tolist(),
                    'sigma': c.sigma.tolist()
                })
            else:
                raise RuntimeError(
                    'Unsupported type of MixtureDensity component: {}'.format(
                        type(c)))
        description['weights'] = density.weights.tolist()

        os.makedirs(path, exist_ok=True)
        with open(os.path.join(path, 'description.yaml'),
                  'w') as description_file:
            yaml.dump(description, description_file, default_flow_style=False)
コード例 #2
0
ファイル: plotter.py プロジェクト: Nico-Tang/eos
    def plot_eos_watermark(self, item):
        xdelta, ydelta = (0.04, 0.04)

        hpos, vpos = item['position'] if 'position' in item else ['right', 'top']

        if hpos == 'right':
            x = 1 - xdelta
        elif hpos == 'left':
            x = xdelta
        elif hpos == 'center':
            x = 0.5
        else:
            raise ValueError('invalid horizontal position \'{}\''.format(hpos))

        if vpos == 'bottom':
            y = 0 + ydelta
        elif vpos == 'top':
            y = 1 - ydelta
        elif vpos == 'center':
            y = 0.5
        else:
            raise ValueError('invalid vertical position \'{}\''.format(hpos))

        logofont = matplotlib.font_manager.FontProperties(family='sans-serif', size='15')
        ax = plt.gca()
        ax.text(x, y, r'\textsf{{\textbf{{EOS v{version}}}}}'.format(version=eos.version()),
                transform=ax.transAxes, fontproperties=logofont,
                color='OrangeRed', alpha=0.5, bbox=dict(facecolor='white', alpha=0.5, lw=0),
                horizontalalignment=hpos, verticalalignment=vpos, zorder=+5)
コード例 #3
0
ファイル: plotter.py プロジェクト: Alchemist21/eos
        def plot(self):
            item = self.item
            xdelta, ydelta = (0.04, 0.04)

            hpos, vpos = item['position'] if 'position' in item else ['right', 'top']

            if hpos == 'right':
                x = 1 - xdelta
            elif hpos == 'left':
                x = xdelta
            elif hpos == 'center':
                x = 0.5
            else:
                raise ValueError('invalid horizontal position \'{}\''.format(hpos))

            if vpos == 'bottom':
                y = 0 + ydelta
            elif vpos == 'top':
                y = 1 - ydelta
            elif vpos == 'center':
                y = 0.5
            else:
                raise ValueError('invalid vertical position \'{}\''.format(hpos))

            ax = plt.gca()
            color = 'OrangeRed'
            version = 'v{version}'.format(version=eos.version())
            if 'preliminary' in item and item['preliminary']:
                color = 'red'
                version = 'Preliminary'
            ax.text(x, y, r'\textsf{{\textbf{{EOS {version}}}}}'.format(version=version),
                    transform=ax.transAxes,
                    color=color, alpha=0.5, bbox=dict(facecolor='white', alpha=0.5, lw=0),
                    horizontalalignment=hpos, verticalalignment=vpos, zorder=+5)
コード例 #4
0
    def create(path, parameters, samples, weights, proposal):
        """ Write a new PMCSampler object to disk.

        :param path: Path to the storage location, which will be created as a directory.
        :type path: str
        :param parameters: Parameter descriptions as a 1D array of shape (N, ).
        :type parameters: list or iterable of eos.Parameter
        :param samples: Samples as a 2D array of shape (N, P).
        :type samples: 2D numpy array
        :param weights: Weights on a linear scale as a 2D array of shape (N, 1).
        :type weights: 1D numpy array, optional
        """
        description = {}
        description['version'] = eos.version()
        description['type'] = 'PMCSampler'
        description['parameters'] = [{
            'name': p.name(),
            'min': p.min(),
            'max': p.max()
        } for p in parameters]
        description['proposal'] = {
            'components': [{
                'mu': c.mu.tolist(),
                'sigma': c.sigma.tolist()
            } for c in proposal.components],
            'weights':
            proposal.weights.tolist()
        }

        if not samples.shape[1] == len(parameters):
            raise RuntimeError(
                'Shape of samples {} incompatible with number of parameters {}'
                .format(samples.shape, len(parameters)))

        if not weights is None and not samples.shape[0] == weights.shape[0]:
            raise RuntimeError(
                'Shape of weights {} incompatible with shape of samples {}'.
                format(weights.shape, samples.shape))

        os.makedirs(path, exist_ok=True)
        with open(os.path.join(path, 'description.yaml'),
                  'w') as description_file:
            yaml.dump(description, description_file, default_flow_style=False)
        _np.save(os.path.join(path, 'samples.npy'), samples)
        _np.save(os.path.join(path, 'weights.npy'), weights)
コード例 #5
0
    def create(path, observables, samples, weights):
        """ Write a new Prediction object to disk.

        :param path: Path to the storage location, which will be created as a directory.
        :type path: str
        :param observables: Observables as a 1D array of shape (O, ).
        :type observables: list or iterable of eos.Observable
        :param samples: Samples as a 2D array of shape (N, O).
        :type samples: 2D numpy array
        :param weights: Weights on a linear scale as a 1D array of shape (N, ).
        :type weights: 1D numpy array
        """
        description = {}
        description['version'] = eos.version()
        description['type'] = 'Prediction'
        description['observables'] = [{
            'name': str(o.name()),
            'kinematics': {k.name(): float(k)
                           for k in o.kinematics()}
        } for o in observables]

        if not samples.shape[1] == len(observables):
            raise RuntimeError(
                'Shape of samples {} incompatible with number of observables {}'
                .format(samples.shape, len(observables)))

        if not samples.shape[0] == weights.shape[0]:
            raise RuntimeError(
                'Shape of weights {} incompatible with shape of samples {}'.
                format(weights.shape, samples.shape))

        os.makedirs(path, exist_ok=True)
        with open(os.path.join(path, 'description.yaml'),
                  'w') as description_file:
            yaml.dump(description, description_file, default_flow_style=False)
        _np.save(os.path.join(path, 'samples.npy'), samples)
        _np.save(os.path.join(path, 'weights.npy'), weights)
コード例 #6
0
ファイル: observables.rst.py プロジェクト: romyoc/eos
import eos
import re

observables = eos.Observables()

def latex_to_rst(s):
    return(re.sub(r'\$([^\$]*)\$', r':math:`\1`', s))

all_data = []
page_title = 'List of Observables'
print('#' * len(page_title))
print(page_title)
print('#' * len(page_title))
print('\n')
print('The following is a list of observables that is available in EOS v{}.\n\n'.format(eos.version()))
for section in observables.sections():
    section_title = latex_to_rst(section.name())
    print('*' * len(section_title))
    print(section_title)
    print('*' * len(section_title))

    for group in section:
        group_title = latex_to_rst(group.name())
        print(group_title)
        print('=' * len(group_title))

        print('\n')
        translation = {
            ord(':'): 'co', ord('@'): 'at', ord('/'): 'sl', ord('_'): 'un',
            ord('('): 'po', ord(')'): 'pc', ord('+'): 'pp', ord('-'): 'mm',
コード例 #7
0
ファイル: conf.py プロジェクト: romyoc/eos
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))

# -- Project information -----------------------------------------------------

import eos

project = 'EOS'
copyright = '2019, Danny van Dyk and others'
author = 'Danny van Dyk and others'
master_doc = 'index'

# The full version, including alpha/beta/rc tags
release = eos.version()

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.mathjax',
    'sphinx.ext.todo',
    'sphinx.ext.autosectionlabel',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
コード例 #8
0
ファイル: references.rst.py プロジェクト: mreboud/eos
def id_to_eprint_url(eprint_id):
    if eprint_id.startswith('oai:arXiv.org:'):
        return 'arXiv:' + eprint_id.lstrip(
            'oai:arXiv.org:'), 'https://arxiv.org/abs/' + eprint_id.lstrip(
                'oai:arXiv.org:')

    return None, None


page_title = 'List of References'
print('#' * len(page_title))
print(page_title)
print('#' * len(page_title))
print('\n')
print(
    'The following the full list of parameters and their values as of EOS v{}.\n\n'
    .format(eos.version()))
for handle, reference in eos.References():
    title = latex_to_rst(reference.title())
    eprint, url = id_to_eprint_url(reference.eprint_id())
    print('.. [{handle}] {authors} {delim}'.format(
        handle=handle,
        authors=reference.authors(),
        delim='--' if title else ''))
    print('   {title} {delim}'.format(title=title,
                                      delim='--' if eprint else ''))
    if eprint:
        print('   `{eprint} <{url}>`_'.format(eprint=eprint, url=url))
    print()
コード例 #9
0
ファイル: references.rst.py プロジェクト: romyoc/eos
    result = s
    for regexp, repl in replacements:
        result = regexp.sub(repl, result)

    return(result)


def id_to_eprint_url(eprint_id):
    if eprint_id.startswith('oai:arXiv.org:'):
        return 'arXiv:' + eprint_id.lstrip('oai:arXiv.org:'), 'https://arxiv.org/abs/' + eprint_id.lstrip('oai:arXiv.org:')

    return None, None


page_title = 'List of References'
print('#' * len(page_title))
print(page_title)
print('#' * len(page_title))
print('\n')
print('''
The following is the full list of references that were used to implement theory codes and provide likelihood constraints
or parameter values within EOS v{}.\n\n'''.format(eos.version()))
for handle, reference in eos.References():
    title = latex_to_rst(reference.title())
    eprint, url = id_to_eprint_url(reference.eprint_id())
    print('.. [{handle}] {authors} {delim}'.format(handle=handle, authors=reference.authors(), delim='--' if title else ''))
    print('   {title} {delim}'.format(title=title, delim='--' if eprint else ''))
    if eprint:
        print('   `{eprint} <{url}>`_'.format(eprint=eprint,url=url))
    print()