How to use the zfit.z.unstack_x function in zfit

To help you get started, we’ve selected a few zfit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zfit / zfit / tests / test_integrate.py View on Github external
def func3_2deps(x):
    a, b = z.unstack_x(x)
    return a ** 2 + b ** 2
github zfit / zfit / examples / custom_pdf_simple.py View on Github external
def _unnormalized_pdf(self, x):  # implement function
        data = z.unstack_x(x)
        alpha = self.params['alpha']

        return z.exp(alpha * data)
github zfit / zfit / zfit / core / space.py View on Github external
def inside_rect_limits(x, rect_limits):
    if not x.shape.ndims > 1:
        raise ValueError("x has ndims <= 1, which is most probably not wanted. The default shape for array-like"
                         " structures is (nevents, n_obs).")
    lower, upper = z.unstack_x(rect_limits, axis=0)
    lower = z.convert_to_tensor(lower)
    upper = z.convert_to_tensor(upper)
    below_upper = tf.reduce_all(input_tensor=tf.less_equal(x, upper), axis=-1)  # if all obs inside
    above_lower = tf.reduce_all(input_tensor=tf.greater_equal(x, lower), axis=-1)
    inside = tf.logical_and(above_lower, below_upper)
    return inside
github zfit / zfit / zfit / models / basic.py View on Github external
def exp_icdf(x, params, model):
    lambd = params['lambda']
    x = z.unstack_x(x)
    x = model._shift_x(x)
    return z.log(lambd * x) / lambd
github zfit / zfit / zfit / models / dist_tfp.py View on Github external
def _analytic_integrate(self, limits, norm_range):
        lower, upper = limits._rect_limits_tf
        lower = z.unstack_x(lower)
        upper = z.unstack_x(upper)
        tf.debugging.assert_all_finite((lower, upper), "Are infinite limits needed? Causes troubles with NaNs")
        integral = self.distribution.cdf(upper) - self.distribution.cdf(lower)
        return integral
github zfit / zfit / zfit / models / kde.py View on Github external
upper limits. This can cause NaNs in case datapoints are outside of the limits.
            name: Name of the PDF
        """
        if bandwidth is None:
            bandwidth = 'silverman'

        if isinstance(data, ZfitData):
            if data.weights is not None:
                if weights is not None:
                    raise OverdefinedError("Cannot specify weights and use a `ZfitData` with weights.")
                else:
                    weights = data.weights

            if data.n_obs > 1:
                raise ShapeIncompatibleError(f"KDE is 1 dimensional, but data {data} has {data.n_obs} observables.")
            data = z.unstack_x(data)

        # create fraction for the sum
        shape_data = tf.shape(data)
        size = tf.cast(shape_data[0], dtype=ztypes.float)
        if weights is not None:
            probs = weights / tf.reduce_sum(weights)
        else:
            probs = tf.broadcast_to(1 / size, shape=(tf.cast(size, tf.int32),))
        categorical = tfd.Categorical(probs=probs)  # no grad -> no need to recreate

        # estimate bandwidth
        bandwidth_param = bandwidth
        if isinstance(bandwidth, str):
            bw_method = self._bandwidth_methods.get(bandwidth)
            if bw_method is None:
                raise ValueError(f"Cannot use {bandwidth} as a bandwidth method. Use a numerical value or one of"