Ejemplo n.º 1
0
 def make_simple_gluon_model(self):
     net = self.make_net()
     m = Model()
     m.x = Variable(shape=(1, 1))
     m.f = MXFusionGluonFunction(net, num_outputs=1)
     m.y = m.f(m.x)
     return m
Ejemplo n.º 2
0
    def test_set_parameters(self):

        class SetValue(InferenceAlgorithm):
            def __init__(self, x, y, model, observed, extra_graphs=None):
                self.x_val = x
                self.y_val = y
                super(SetValue, self).__init__(
                    model=model, observed=observed, extra_graphs=extra_graphs)

            def compute(self, F, variables):
                self.set_parameter(variables, self.model.x, self.x_val)
                self.set_parameter(variables, self.model.y, self.y_val)

        m = Model()
        m.x = Variable(shape=(2,))
        m.y = Variable(shape=(3, 4))

        dtype = 'float64'

        np.random.seed(0)
        x_np = np.random.rand(2)
        y_np = np.random.rand(3, 4)
        x_mx = mx.nd.array(x_np, dtype=dtype)
        y_mx = mx.nd.array(y_np, dtype=dtype)

        infr = Inference(SetValue(x_mx, y_mx, m, []), dtype=dtype)
        infr.run()
        x_res = infr.params[m.x]
        y_res = infr.params[m.y]

        assert np.allclose(x_res.asnumpy(), x_np)
        assert np.allclose(y_res.asnumpy(), y_np)
Ejemplo n.º 3
0
    def test_gluon_parameters(self):
        self.setUp()

        m = Model()
        m.x = Variable(shape=(1, 1))
        m.f = MXFusionGluonFunction(self.net, num_outputs=1)
        m.y = m.f(m.x)

        infr = Inference(ForwardSamplingAlgorithm(m, observed=[m.x]))
        infr.run(x=mx.nd.ones((1, 1)))
        assert all([
            v.uuid in infr.params.param_dict for v in m.f.parameters.values()
        ])