Exemplo n.º 1
0
    def _update_measurement(self, var, measurement, member):
        """
        Returns an updated_measurement.
        
        This is used to update :class:`LazyDict` instances.
        """

        if not member:
            if var in self.transforms:
                transform = self.transforms[var]
            else:
                # attempt to parse var as a tuple of vars
                # and construct derived product transform if
                # successful
                product_t = [self.transforms[v] for v in var]

                def transform(state):
                    """
                    product transform function, generated by recorder
                    """
                    return sum((t(state) for t in product_t), ())

            measurement = Measurement(var, transform)
        start = len(measurement)
        end = len(self.times)
        for i in range(start, end):
            measurement.write(self.times[i], self.distributions[i])
        return measurement
Exemplo n.º 2
0
 def _update_measurement(self, var, measurement, member):
     """
     Returns an updated_measurement.
     
     This is used to update :class:`LazyDict` instances.
     """
     
     if not member:
         if var in self.transforms:
             transform = self.transforms[var]
         else:
             # attempt to parse var as a tuple of vars
             # and construct derived product transform if
             # successful
             product_t = [self.transforms[v] for v in var]
             def transform(state):
                 """
                 product transform function, generated by recorder
                 """
                 return sum((t(state) for t in product_t), ())
         measurement = Measurement(var, transform)
     start = len(measurement)
     end = len(self.times)
     for i in xrange(start, end):
         measurement.write(self.times[i], self.distributions[i])
     return measurement
Exemplo n.º 3
0
 def test_attribute_trickery(self):
     m = Measurement()
     m.write(0.0, Distribution({(0, ) : 1.0, (1, ) : 0.0}))
     m.write(0.5, Distribution({(0, ) : 0.5, (1, ) : 0.5}))
     m.write(1.0, Distribution({(0, ) : 0.0, (1, ) : 1.0}))
     
     assert_almost_equal(numpy.array(m.expectation),
                         [[0], [0.5], [1]])
     
     assert_almost_equal(numpy.array(m.variance),
                         [0, 0.25, 0])
Exemplo n.º 4
0
    def test_attribute_trickery(self):
        m = Measurement()
        m.write(0.0, Distribution({(0, ): 1.0, (1, ): 0.0}))
        m.write(0.5, Distribution({(0, ): 0.5, (1, ): 0.5}))
        m.write(1.0, Distribution({(0, ): 0.0, (1, ): 1.0}))

        assert_almost_equal(numpy.array(m.expectation), [[0], [0.5], [1]])

        assert_almost_equal(numpy.array(m.variance), [0, 0.25, 0])