1 """
2 Defines abstract samplers.
3 """
4
5 import numpy as np
6 import csb.core
7
8 from abc import ABCMeta, abstractmethod, abstractproperty
13
15 """
16 Abstract interface for sampling algorithms.
17 """
18
19 __metaclass__ = ABCMeta
20
21 @abstractmethod
23 """
24 Draw a sample.
25 @rtype: L{AbstractState}
26 """
27 pass
28
30 """
31 Represents a point in phase-space.
32 """
33
34 __metaclass__ = ABCMeta
35
36 @abstractproperty
39
40 @abstractproperty
43
44 -class State(AbstractState):
45 """
46 Represents a point in phase-space.
47 """
48
49 @staticmethod
51 """
52 Check whether arguments are flat, one-dimensional numpy arrays.
53 """
54
55 for q in args:
56 if not isinstance(q, np.ndarray):
57 raise TypeError(q, 'numpy.ndarray expected!')
58
59 if not len(q.squeeze().shape) <= 1:
60 raise DimensionError(q, '1d numpy.ndarray expected!')
61
62 @staticmethod
64 """
65 Check whether arguments have equal length.
66 """
67
68 if len(q) != len(p):
69 raise DimensionError(p, 'momentum needs to have the same dimension as coordinates!')
70
71 - def __init__(self, position, momentum=None):
78
79 @property
81 return self._position.copy()
82 @position.setter
84 State.check_flat_array(value)
85 self._position = np.array(value)
86
87 @property
89 if self._momentum is None:
90 return None
91 else:
92 return self._momentum.copy()
93 @momentum.setter
101
107
108 -class EnsembleState(csb.core.BaseCollectionContainer, AbstractState):
109 """
110 Defines an Ensemble Monte Carlo state; it is a read-only collection
111 of State objects.
112
113 @param items: initialization list of states
114 @type items: list of L{States}
115 """
116
118 super(EnsembleState, self).__init__(items, type=State)
119
120 @property
122 return np.array([s.position for s in self])
123
124 @property
127