Example #1
0
    def __init__(self, iterable):
        dict.__init__(self, iterable)
        ContainerBase.__init__(self, iterable)
        self._value = copy(iterable)
        file_items(self, iterable)

        self.val_keys = []
        self.val_obj = []
        self.nonval_keys = []
        self.nonval_obj = []
        self._value = {}
        for key, obj in self.iteritems():
            if isinstance(obj, Variable) or isinstance(obj, ContainerBase):
                self.val_keys.append(key)
                self.val_obj.append(obj)
            else:
                self.nonval_keys.append(key)
                self.nonval_obj.append(obj)
        # In case val_obj is only a single array, avert confusion.
        # Leave this even though it's confusing!
        self.val_obj.append(None)
        self.nonval_obj.append(None)

        self.n_val = len(self.val_keys)
        self.val_keys = array(self.val_keys, dtype=object)
        self.val_obj = array(self.val_obj, dtype=object)
        self.n_nonval = len(self.nonval_keys)
        self.nonval_keys = array(self.nonval_keys, dtype=object)
        self.nonval_obj = array(self.nonval_obj, dtype=object)
        self.DCValue = DCValue(self)
Example #2
0
    def __init__(self, iterable):
        dict.__init__(self, iterable)
        ContainerBase.__init__(self, iterable)
        self._value = copy(iterable)
        file_items(self, iterable)

        self.val_keys = []
        self.val_obj = []
        self.nonval_keys = []
        self.nonval_obj = []
        self._value = {}
        for key, obj in self.iteritems():
            if isinstance(obj, Variable) or isinstance(obj, ContainerBase):
                self.val_keys.append(key)
                self.val_obj.append(obj)
            else:
                self.nonval_keys.append(key)
                self.nonval_obj.append(obj)
        # In case val_obj is only a single array, avert confusion.
        # Leave this even though it's confusing!
        self.val_obj.append(None)
        self.nonval_obj.append(None)

        self.n_val = len(self.val_keys)
        self.val_keys = array(self.val_keys, dtype=object)
        # self.val_obj = array(self.val_obj, dtype=object)
        self.n_nonval = len(self.nonval_keys)
        self.nonval_keys = array(self.nonval_keys, dtype=object)
        self.nonval_obj = array(self.nonval_obj, dtype=object)
        self.DCValue = DCValue(self)
Example #3
0
class DictContainer(ContainerBase, dict):
    """
    DictContainers are containers that wrap dictionaries.
    Modules are converted into DictContainers, and variables' and potentials'
    Parents objects are DictContainers also.

    :Parameters:
      iterable : dictionary or object with a __dict__.

    :Attributes:
      value : dictionary
        A copy of self, with all variables replaced with their values.
      nodes : set
        All the stochastics, deterministics and potentials self contains.
      deterministics : set
        All the deterministics self contains.
      stochastics : set
        All the stochastics self contains with observed=False.
      potentials : set
        All the potentials self contains.
      observed_stochastics : set
        All the stochastics self contains with observed=True.
      containers : list
        All the containers self contains.

    :Note:
      - nodes, deterministics, etc. include all the objects in nested
        containers.
      - value replaces objects in nested containers.

    :SeeAlso:
      Container, ListContainer, TupleContainer, ArrayContainer, SetContainer,
      ObjectContainer
    """
    change_methods = ['__setitem__', '__delitem__', 'clear', 'pop', 'popitem', 'update']
    containing_classes = [dict]
    register=True
    def __init__(self, iterable):
        dict.__init__(self, iterable)
        ContainerBase.__init__(self, iterable)
        self._value = copy(iterable)
        file_items(self, iterable)

        self.val_keys = []
        self.val_obj = []
        self.nonval_keys = []
        self.nonval_obj = []
        self._value = {}
        for key, obj in self.iteritems():
            if isinstance(obj, Variable) or isinstance(obj, ContainerBase):
                self.val_keys.append(key)
                self.val_obj.append(obj)
            else:
                self.nonval_keys.append(key)
                self.nonval_obj.append(obj)
        # In case val_obj is only a single array, avert confusion.
        # Leave this even though it's confusing!
        self.val_obj.append(None)
        self.nonval_obj.append(None)

        self.n_val = len(self.val_keys)
        self.val_keys = array(self.val_keys, dtype=object)
        # self.val_obj = array(self.val_obj, dtype=object)
        self.n_nonval = len(self.nonval_keys)
        self.nonval_keys = array(self.nonval_keys, dtype=object)
        self.nonval_obj = array(self.nonval_obj, dtype=object)
        self.DCValue = DCValue(self)

    def replace(self, key, new_container):
        dict.__setitem__(self, key, new_container)

    def get_value(self):
        # DCValue(self)
        self.DCValue.run()
        return self._value

    value = property(fget = get_value, doc=value_doc)
Example #4
0
class DictContainer(ContainerBase, dict):
    """
    DictContainers are containers that wrap dictionaries.
    Modules are converted into DictContainers, and variables' and potentials'
    Parents objects are DictContainers also.

    :Parameters:
      iterable : dictionary or object with a __dict__.

    :Attributes:
      value : dictionary
        A copy of self, with all variables replaced with their values.
      nodes : set
        All the stochastics, deterministics and potentials self contains.
      deterministics : set
        All the deterministics self contains.
      stochastics : set
        All the stochastics self contains with observed=False.
      potentials : set
        All the potentials self contains.
      observed_stochastics : set
        All the stochastics self contains with observed=True.
      containers : list
        All the containers self contains.

    :Note:
      - nodes, deterministics, etc. include all the objects in nested
        containers.
      - value replaces objects in nested containers.

    :SeeAlso:
      Container, ListContainer, TupleContainer, ArrayContainer, SetContainer,
      ObjectContainer
    """
    change_methods = [
        '__setitem__', '__delitem__', 'clear', 'pop', 'popitem', 'update'
    ]
    containing_classes = [dict]
    register = True

    def __init__(self, iterable):
        dict.__init__(self, iterable)
        ContainerBase.__init__(self, iterable)
        self._value = copy(iterable)
        file_items(self, iterable)

        self.val_keys = []
        self.val_obj = []
        self.nonval_keys = []
        self.nonval_obj = []
        self._value = {}
        for key, obj in self.iteritems():
            if isinstance(obj, Variable) or isinstance(obj, ContainerBase):
                self.val_keys.append(key)
                self.val_obj.append(obj)
            else:
                self.nonval_keys.append(key)
                self.nonval_obj.append(obj)
        # In case val_obj is only a single array, avert confusion.
        # Leave this even though it's confusing!
        self.val_obj.append(None)
        self.nonval_obj.append(None)

        self.n_val = len(self.val_keys)
        self.val_keys = array(self.val_keys, dtype=object)
        self.val_obj = array(self.val_obj, dtype=object)
        self.n_nonval = len(self.nonval_keys)
        self.nonval_keys = array(self.nonval_keys, dtype=object)
        self.nonval_obj = array(self.nonval_obj, dtype=object)
        self.DCValue = DCValue(self)

    def replace(self, key, new_container):
        dict.__setitem__(self, key, new_container)

    def get_value(self):
        # DCValue(self)
        self.DCValue.run()
        return self._value

    value = property(fget=get_value, doc=value_doc)