How to use the elfi.model.elfi_model.ElfiModel function in elfi

To help you get started, we’ve selected a few elfi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elfi-dev / elfi / elfi / model / elfi_model.py View on Github external
Parameters
    ----------
    name : str
        Name of the model file to load (without the .pkl extension).
    prefix : str
        Path to directory where the model file is located, optional.
    set_default : bool, optional
        Set the loaded model as the default model. Default is True.

    Returns
    -------
    ElfiModel

    """
    model = ElfiModel.load(name, prefix=prefix)
    if set_default:
        set_default_model(model)
    return model
github elfi-dev / elfi / elfi / visualization / visualization.py View on Github external
Notes
    -----
    Requires the optional 'graphviz' library.

    Returns
    -------
    dot
        A GraphViz dot representation of the model.

    """
    try:
        from graphviz import Digraph
    except ImportError:
        raise ImportError("The graphviz library is required for this feature.")

    if isinstance(G, ElfiModel):
        G = G.source_net
    elif isinstance(G, NodeReference):
        G = G.model.source_net

    dot = Digraph(format=format)

    hidden = set()

    for n, state in G.nodes_iter(data=True):
        if not internal and n[0] == '_' and state.get('_class') == Constant:
            hidden.add(n)
            continue
        _format = {'shape': 'circle', 'fillcolor': 'gray80', 'style': 'solid'}
        if state.get('_observable'):
            _format['style'] = 'filled'
        dot.node(n, **_format)
github elfi-dev / elfi / elfi / model / elfi_model.py View on Github external
def set_default_model(model=None):
    """Set the current default ``ElfiModel`` instance.

    New nodes will be placed the given model by default.

    Parameters
    ----------
    model : ElfiModel, optional
        If None, creates a new ``ElfiModel``.

    """
    global _default_model
    if model is None:
        model = ElfiModel()
    if not isinstance(model, ElfiModel):
        raise ValueError('{} is not an instance of ElfiModel'.format(ElfiModel))
    _default_model = model
github elfi-dev / elfi / elfi / methods / parameter_inference.py View on Github external
def _resolve_model(model, target, default_reference_class=NodeReference):
        if isinstance(model, ElfiModel) and target is None:
            raise NotImplementedError("Please specify the target node of the inference method")

        if isinstance(model, NodeReference):
            target = model
            model = target.model

        if isinstance(target, str):
            target = model[target]

        if not isinstance(target, default_reference_class):
            raise ValueError('Unknown target node class')

        return model, target.name
github elfi-dev / elfi / elfi / model / elfi_model.py View on Github external
def set_default_model(model=None):
    """Set the current default ``ElfiModel`` instance.

    New nodes will be placed the given model by default.

    Parameters
    ----------
    model : ElfiModel, optional
        If None, creates a new ``ElfiModel``.

    """
    global _default_model
    if model is None:
        model = ElfiModel()
    if not isinstance(model, ElfiModel):
        raise ValueError('{} is not an instance of ElfiModel'.format(ElfiModel))
    _default_model = model
github elfi-dev / elfi / elfi / model / elfi_model.py View on Github external
def get_default_model():
    """Return the current default ``ElfiModel`` instance.

    New nodes will be added to this model by default.
    """
    global _default_model
    if _default_model is None:
        _default_model = ElfiModel()
    return _default_model
github elfi-dev / elfi / elfi / model / elfi_model.py View on Github external
data (if applicable) of the updating_node. The updating node is then removed
        from the graph.

        Parameters
        ----------
        name : str
        updating_name : str

        """
        update_observed = False
        obs = None
        if updating_name in self.observed:
            update_observed = True
            obs = self.observed.pop(updating_name)

        super(ElfiModel, self).update_node(name, updating_name)

        # Move data to the updated node
        if update_observed:
            self.observed[name] = obs