示例#1
0
def indicator_data(
        indicators: IndicatorCollection) -> Tuple[List[np.ndarray], List[str]]:
    r"""
    Returns a tuple of a list of series and a list of names of series.
    Each series, `S` is a timeseries of histograms of shape `[T, 10]`,
    where `T` is the number of timesteps.
    `S[:, 0]` is the `global_step`.
    `S[:, 1:10]` represents the distribution at basis points
    `0, 6.68, 15.87, 30.85, 50.00, 69.15, 84.13, 93.32, 100.00`.

    Example:
        >>> from labml import analytics
        >>> indicators = analytics.runs('1d3f855874d811eabb9359457a24edc8')
        >>> analytics.indicator_data(indicators)
    """

    series, names = _cache.get_indicators_data(indicators)

    if not series:
        raise ValueError("No series found")

    return series, names
示例#2
0
def binned_heatmap(*args: any,
                   names: Optional[List[str]] = None,
                   x_name: Optional[str] = None,
                   height: int = 400,
                   width: int = 800,
                   height_minimap: int = 100):
    r"""
    Creates a scatter plot with Altair

    This has multiple overloads

    .. function:: binned_heatmap(indicators: IndicatorCollection, x_indicators: IndicatorCollection, *, names: Optional[List[str]] = None, x_name: Optional[str] = None, height: int = 400, width: int = 800, height_minimap: int = 100)
        :noindex:

    .. function:: binned_heatmap(series: List[np.ndarray], x_series: np.ndarray, *, names: Optional[List[str]] = None, x_name: Optional[str] = None, height: int = 400, width: int = 800, height_minimap: int = 100)
        :noindex:

    Arguments:
        indicators(IndicatorCollection): Set of indicators to be plotted
        x_indicators(IndicatorCollection): Indicator for x-axis
        series(List[np.ndarray]): List of series of data
        x_series(np.ndarray): X series of data

    Keyword Arguments:
        names(List[str]): List of names of series
        name(str): Name of X series
        noise: Noise to be added to spread out the scatter plot
        circle_size: size of circles in the plot
        height: height of the visualization
        width: width of the visualization
        height_minimap: height of the view finder

    Return:
        The Altair visualization

    Example:
        >>> from labml import analytics
        >>> indicators = analytics.runs('1d3f855874d811eabb9359457a24edc8')
        >>> analytics.scatter(indicators.validation_loss, indicators.train_loss)
    """

    series = None
    x_series = None

    if len(args) == 2:
        if isinstance(args[0], _IndicatorCollection) and isinstance(
                args[1], _IndicatorCollection):
            series, names_ = _cache.get_indicators_data(args[0])
            x_series, x_name_ = _cache.get_indicators_data(args[1])

            if len(x_series) != 1:
                raise ValueError(
                    "There should be exactly one series for x-axis")
            if not series:
                raise ValueError("No series found")
            x_series = x_series[0]
            if x_name is None:
                x_name = x_name_[0]
            if names is None:
                names = names_
        elif isinstance(args[0], list):
            series = args[0]
            x_series = args[1]

    if series is None:
        raise ValueError(
            "scatter should be called with an indicator collection"
            " or a series. Check documentation for details.")

    if x_name is None:
        x_name = 'x'
    if names is None:
        names = [f'{i + 1}' for i in range(len(series))]

    tables = [_binned_heatmap.data_to_table(s, x_series) for s in series]
    names = _remove_names_prefix(names)

    return _binned_heatmap.render(tables,
                                  names=names,
                                  x_name=x_name,
                                  width=width,
                                  height=height,
                                  height_minimap=height_minimap)
示例#3
0
def distribution(*args: any,
                 names: Optional[List[str]] = None,
                 levels: int = 5,
                 alpha: int = 0.6,
                 height: int = 400,
                 width: int = 800,
                 height_minimap: int = 100):
    r"""
    Creates a distribution plot distribution with Altair

    This has multiple overloads

    .. function:: distribution(indicators: IndicatorCollection, *, names: Optional[List[str]] = None, levels: int = 5, alpha: int = 0.6, height: int = 400, width: int = 800, height_minimap: int = 100)
        :noindex:

    .. function:: distribution(series: Union[np.ndarray, torch.Tensor], *, names: Optional[List[str]] = None, levels: int = 5, alpha: int = 0.6, height: int = 400, width: int = 800, height_minimap: int = 100)
        :noindex:

    .. function:: distribution(series: List[Union[np.ndarray, torch.Tensor]], *, names: Optional[List[str]] = None, levels: int = 5, alpha: int = 0.6, height: int = 400, width: int = 800, height_minimap: int = 100)
        :noindex:

    .. function:: distribution(series: List[Union[np.ndarray, torch.Tensor]], step: np.ndarray, *, names: Optional[List[str]] = None, levels: int = 5, alpha: int = 0.6, height: int = 400, width: int = 800, height_minimap: int = 100)
        :noindex:

    Arguments:
        indicators(IndicatorCollection): Set of indicators to be plotted
        series(List[np.ndarray]): List of series of data
        step(np.ndarray): Steps

    Keyword Arguments:
        names(List[str]): List of names of series
        levels: how many levels of the distribution to be plotted
        alpha: opacity of the distribution
        height: height of the visualization
        width: width of the visualization
        height_minimap: height of the view finder

    Return:
        The Altair visualization

    Example:
        >>> from labml import analytics
        >>> indicators = analytics.runs('1d3f855874d811eabb9359457a24edc8')
        >>> analytics.distribution(indicators)
    """

    series = None
    step = None

    if len(args) == 1:
        if isinstance(args[0], _IndicatorCollection):
            series, names_ = _cache.get_indicators_data(args[0])
            if not series:
                raise ValueError("No series found")
            if names is None:
                names = names_
        elif isinstance(args[0], list):
            series = args[0]
        else:
            series = [args[0]]
    elif len(args) == 2:
        series = args[0]
        step = args[1]

    if names is None:
        names = [f'{i + 1}' for i in range(len(series))]

    if series is None:
        raise ValueError(
            "distribution should be called with an indicator collection"
            " or a series. Check documentation for details.")

    names = _remove_names_prefix(names)
    tables = _density.data_to_table(series, names, step)

    return _density.render(tables,
                           levels=levels,
                           alpha=alpha,
                           width=width,
                           height=height,
                           height_minimap=height_minimap)