示例#1
0
 def get_params(self):
     warping = encode_unwrap_parameter(
         mx.nd, self.warping_internal,
         self.encoding).asnumpy().reshape((-1,))
     return {
         'warping_a': warping[0],
         'warping_b': warping[1]}
def negative_log_posterior(likelihood: MarginalLikelihood, X: mx.nd.NDArray,
                           Y: mx.nd.NDArray):
    objective_nd = likelihood(X, Y)
    # Add neg log hyperpriors, whenever some are defined
    for param_int, encoding in likelihood.param_encoding_pairs():
        if encoding.regularizer is not None:
            param = encode_unwrap_parameter(mx.nd, param_int, encoding, X)
            objective_nd = objective_nd + encoding.regularizer(mx.nd, param)
    return objective_nd
    def get_params(self):
        """
        Parameter keys are inv_bw<k> if dimension > 1, and inv_bw if
        dimension == 1.

        """
        inverse_bandwidths = encode_unwrap_parameter(
            mx.nd, self.inverse_bandwidths_internal,
            self.encoding).asnumpy().reshape((-1, ))
        if inverse_bandwidths.size == 1:
            return {'inv_bw': inverse_bandwidths[0]}
        else:
            return {
                'inv_bw{}'.format(k): inverse_bandwidths[k]
                for k in range(inverse_bandwidths.size)
            }
示例#4
0
def param_to_pretty_string(gluon_param, encoding):
    """
    Take a gluon parameter and transform it to a string amenable to plotting
    If need be, the gluon parameter is appropriately encoded (e.g., log-exp transform).

    :param gluon_param: gluon parameter
    :param encoding: object in charge of encoding/decoding the gluon_param
    """

    assert isinstance(gluon_param, gluon.Parameter)
    assert encoding is not None, \
        "encoding of param {} should not be None".format(gluon_param.name)

    param_as_numpy = encode_unwrap_parameter(mx.nd, gluon_param,
                                             encoding).asnumpy()
    return "{}: {}".format(
        gluon_param.name,
        ";".join("{:.6f}".format(value) for value in param_as_numpy))
示例#5
0
 def get_mean_value(self):
     return encode_unwrap_parameter(
         mx.nd, self.mean_value_internal, self.encoding).asscalar()
示例#6
0
 def _get_pars(self, F, X):
     u1 = encode_unwrap_parameter(F, self.u1_internal, self.encoding_u12, X)
     u2 = encode_unwrap_parameter(F, self.u2_internal, self.encoding_u12, X)
     u3 = encode_unwrap_parameter(F, self.u3_internal, self.encoding_u3, X)
     return (u1, u2, u3)
 def _covariance_scale(self, F, X):
     return encode_unwrap_parameter(F, self.covariance_scale_internal,
                                    self.encoding, X)
 def get_noise_variance(self, as_ndarray=False):
     noise_variance = encode_unwrap_parameter(
         mx.nd, self.noise_variance_internal, self.encoding)
     return noise_variance if as_ndarray else noise_variance.asscalar()