Main Content

HBOSDistributionDiscriminator

HBOS distribution discriminator

Since R2023a

    Description

    The HBOSDistributionDiscriminator object is a distribution discriminator that uses the histogram based outlier scores (HBOS) method to compute distribution confidence scores. The object contains a threshold that you can use to separate observations into in-distribution (ID) and out-of-distribution (OOD) data sets.

    Creation

    Create a HBOSDistributionDiscriminator object using the networkDistributionDiscriminator function and setting the method input argument to "hbos".

    Note

    The object type depends on the method you specify when you use the networkDistributionDiscriminator function. The method determines how the software computes the distribution confidence scores. You can set the method argument to either "baseline", "odin", "energy", or "hbos". For more information, see Distribution Confidence Scores.

    Properties

    expand all

    This property is read-only.

    Method for computing the distribution confidence scores, returned as "hbos". For more information, see Distribution Confidence Scores.

    This property is read-only.

    Deep learning network, returned as a dlnetwork object.

    This property is read-only.

    Layer names for the HBOS method, returned as a string array.

    The software computes the distribution confidence scores using the principal components from all of the specified layers. For more information, see Density-Based Methods.

    Note

    To compute the histograms, the software must first compute the principal component features for each layer. Computing the principal components can be slow for layers with a large output size and can cause you to run out of memory. If you run out of memory, try specifying layers with a smaller output size. For more information, see Density-Based Methods.

    Example: ["out_1" "out_2"]

    This property is read-only.

    Variance cutoff for the HBOS method, returned as a scalar in the range [0, 1].

    The variance cutoff controls the number of principal component features that the software uses to compute the distribution confidence scores. Using a greater number of features takes more computation time. The closer the VarianceCutoff value is to 1, the fewer principal components the software uses to compute the scores. For more information, see Density-Based Methods.

    Example: 0.01

    Distribution threshold, returned as a scalar in the range [-Inf, 0]. The threshold separates the ID and OOD data using the distribution confidence scores.

    Example: -10

    Object Functions

    isInNetworkDistributionDetermine whether data is within the distribution of the network
    distributionScoresDistribution confidence scores

    Examples

    collapse all

    Load a pretrained regression network.

    load("digitsRegressionMLPNet.mat")

    Load ID data. Convert the data to a dlarray object.

    XID = digitTrain4DArrayData;
    XID = dlarray(XID,"SSCB");

    Modify the ID training data to create an OOD set.

    XOOD = XID.*0.3 + 0.1;

    Create a discriminator using the HBOS method. Set the variance cutoff to 0.0001 and use the penultimate layer to compute the HBOS distribution scores.

    method = "hbos";
    discriminator = networkDistributionDiscriminator(net,XID,XOOD,method, ...
        VarianceCutoff=0.0001, ...
        LayerNames="relu_2")
    discriminator = 
      HBOSDistributionDiscriminator with properties:
    
                Method: "hbos"
               Network: [1×1 dlnetwork]
            LayerNames: "relu_2"
        VarianceCutoff: 1.0000e-04
             Threshold: -54.1244
    
    

    Assess the performance of the discriminator on the OOD data.

    tf = isInNetworkDistribution(discriminator,XOOD);
    accuracy = sum(tf == 0)/numel(tf)
    accuracy = 0.9816
    

    More About

    expand all

    References

    [1] Shalev, Gal, Gabi Shalev, and Joseph Keshet. “A Baseline for Detecting Out-of-Distribution Examples in Image Captioning.” In Proceedings of the 30th ACM International Conference on Multimedia, 4175–84. Lisboa Portugal: ACM, 2022. https://doi.org/10.1145/3503161.3548340.

    [2] Shiyu Liang, Yixuan Li, and R. Srikant, “Enhancing The Reliability of Out-of-distribution Image Detection in Neural Networks” arXiv:1706.02690 [cs.LG], August 30, 2020, http://arxiv.org/abs/1706.02690.

    [3] Weitang Liu, Xiaoyun Wang, John D. Owens, and Yixuan Li, “Energy-based Out-of-distribution Detection” arXiv:2010.03759 [cs.LG], April 26, 2021, http://arxiv.org/abs/2010.03759.

    [4] Markus Goldstein and Andreas Dengel. "Histogram-based outlier score (hbos): A fast unsupervised anomaly detection algorithm." KI-2012: poster and demo track 9 (2012).

    [5] Jingkang Yang, Kaiyang Zhou, Yixuan Li, and Ziwei Liu, “Generalized Out-of-Distribution Detection: A Survey” August 3, 2022, http://arxiv.org/abs/2110.11334.

    [6] Lee, Kimin, Kibok Lee, Honglak Lee, and Jinwoo Shin. “A Simple Unified Framework for Detecting Out-of-Distribution Samples and Adversarial Attacks.” arXiv, October 27, 2018. http://arxiv.org/abs/1807.03888.

    Extended Capabilities

    Version History

    Introduced in R2023a

    expand all