| Total Complexity | 7 |
| Total Lines | 22 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | #!/usr/bin/env python |
||
| 9 | class SampleMultivariateGaussian(gof.Op): |
||
| 10 | __props__ = () |
||
| 11 | |||
| 12 | def make_node(self, x, cov): |
||
| 13 | if x.type.ndim != 1: |
||
| 14 | raise TypeError('x must be a 1-d vector') |
||
| 15 | if cov.type.ndim != 2: |
||
| 16 | raise TypeError('cov must be a 2-d matrix') |
||
| 17 | return gof.Apply(self, [x, cov], [T.vector(dtype="float32")]) |
||
| 18 | |||
| 19 | def perform(self, node, inp, out): |
||
| 20 | x, cov = inp |
||
| 21 | z, = out |
||
| 22 | z[0] = np.random.multivariate_normal(x, cov, 1)[0].astype("float32") |
||
| 23 | |||
| 24 | def grad(self, inputs, outputs): |
||
| 25 | return [outputs[0], T.zeros_like(inputs[1])] |
||
| 26 | |||
| 27 | def R_op(self, inputs, eval_points): |
||
| 28 | if eval_points[0] is None: |
||
| 29 | return eval_points |
||
| 30 | return self.grad(inputs, eval_points) |