diff --git a/LICENSE.txt b/LICENSE.txt
index 2f8ed18..d645695 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,374 +1,202 @@
-Mozilla Public License Version 2.0
-==================================
-
-1. Definitions
---------------
-
-1.1. "Contributor"
- means each individual or legal entity that creates, contributes to
- the creation of, or owns Covered Software.
-
-1.2. "Contributor Version"
- means the combination of the Contributions of others (if any) used
- by a Contributor and that particular Contributor's Contribution.
-
-1.3. "Contribution"
- means Covered Software of a particular Contributor.
-
-1.4. "Covered Software"
- means Source Code Form to which the initial Contributor has attached
- the notice in Exhibit A, the Executable Form of such Source Code
- Form, and Modifications of such Source Code Form, in each case
- including portions thereof.
-
-1.5. "Incompatible With Secondary Licenses"
- means
-
- (a) that the initial Contributor has attached the notice described
- in Exhibit B to the Covered Software; or
-
- (b) that the Covered Software was made available under the terms of
- version 1.1 or earlier of the License, but not also under the
- terms of a Secondary License.
-
-1.6. "Executable Form"
- means any form of the work other than Source Code Form.
-
-1.7. "Larger Work"
- means a work that combines Covered Software with other material, in
- a separate file or files, that is not Covered Software.
-
-1.8. "License"
- means this document.
-
-1.9. "Licensable"
- means having the right to grant, to the maximum extent possible,
- whether at the time of the initial grant or subsequently, any and
- all of the rights conveyed by this License.
-
-1.10. "Modifications"
- means any of the following:
-
- (a) any file in Source Code Form that results from an addition to,
- deletion from, or modification of the contents of Covered
- Software; or
-
- (b) any new file in Source Code Form that contains any Covered
- Software.
-
-1.11. "Patent Claims" of a Contributor
- means any patent claim(s), including without limitation, method,
- process, and apparatus claims, in any patent Licensable by such
- Contributor that would be infringed, but for the grant of the
- License, by the making, using, selling, offering for sale, having
- made, import, or transfer of either its Contributions or its
- Contributor Version.
-
-1.12. "Secondary License"
- means either the GNU General Public License, Version 2.0, the GNU
- Lesser General Public License, Version 2.1, the GNU Affero General
- Public License, Version 3.0, or any later versions of those
- licenses.
-
-1.13. "Source Code Form"
- means the form of the work preferred for making modifications.
-
-1.14. "You" (or "Your")
- means an individual or a legal entity exercising rights under this
- License. For legal entities, "You" includes any entity that
- controls, is controlled by, or is under common control with You. For
- purposes of this definition, "control" means (a) the power, direct
- or indirect, to cause the direction or management of such entity,
- whether by contract or otherwise, or (b) ownership of more than
- fifty percent (50%) of the outstanding shares or beneficial
- ownership of such entity.
-
-2. License Grants and Conditions
---------------------------------
-
-2.1. Grants
-
-Each Contributor hereby grants You a world-wide, royalty-free,
-non-exclusive license:
-
-(a) under intellectual property rights (other than patent or trademark)
- Licensable by such Contributor to use, reproduce, make available,
- modify, display, perform, distribute, and otherwise exploit its
- Contributions, either on an unmodified basis, with Modifications, or
- as part of a Larger Work; and
-
-(b) under Patent Claims of such Contributor to make, use, sell, offer
- for sale, have made, import, and otherwise transfer either its
- Contributions or its Contributor Version.
-
-2.2. Effective Date
-
-The licenses granted in Section 2.1 with respect to any Contribution
-become effective for each Contribution on the date the Contributor first
-distributes such Contribution.
-
-2.3. Limitations on Grant Scope
-
-The licenses granted in this Section 2 are the only rights granted under
-this License. No additional rights or licenses will be implied from the
-distribution or licensing of Covered Software under this License.
-Notwithstanding Section 2.1(b) above, no patent license is granted by a
-Contributor:
-
-(a) for any code that a Contributor has removed from Covered Software;
- or
-
-(b) for infringements caused by: (i) Your and any other third party's
- modifications of Covered Software, or (ii) the combination of its
- Contributions with other software (except as part of its Contributor
- Version); or
-
-(c) under Patent Claims infringed by Covered Software in the absence of
- its Contributions.
-
-This License does not grant any rights in the trademarks, service marks,
-or logos of any Contributor (except as may be necessary to comply with
-the notice requirements in Section 3.4).
-
-2.4. Subsequent Licenses
-
-No Contributor makes additional grants as a result of Your choice to
-distribute the Covered Software under a subsequent version of this
-License (see Section 10.2) or under the terms of a Secondary License (if
-permitted under the terms of Section 3.3).
-
-2.5. Representation
-
-Each Contributor represents that the Contributor believes its
-Contributions are its original creation(s) or it has sufficient rights
-to grant the rights to its Contributions conveyed by this License.
-
-2.6. Fair Use
-
-This License is not intended to limit any rights You have under
-applicable copyright doctrines of fair use, fair dealing, or other
-equivalents.
-
-2.7. Conditions
-
-Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
-in Section 2.1.
-
-3. Responsibilities
--------------------
-
-3.1. Distribution of Source Form
-
-All distribution of Covered Software in Source Code Form, including any
-Modifications that You create or to which You contribute, must be under
-the terms of this License. You must inform recipients that the Source
-Code Form of the Covered Software is governed by the terms of this
-License, and how they can obtain a copy of this License. You may not
-attempt to alter or restrict the recipients' rights in the Source Code
-Form.
-
-3.2. Distribution of Executable Form
-
-If You distribute Covered Software in Executable Form then:
-
-(a) such Covered Software must also be made available in Source Code
- Form, as described in Section 3.1, and You must inform recipients of
- the Executable Form how they can obtain a copy of such Source Code
- Form by reasonable means in a timely manner, at a charge no more
- than the cost of distribution to the recipient; and
-
-(b) You may distribute such Executable Form under the terms of this
- License, or sublicense it under different terms, provided that the
- license for the Executable Form does not attempt to limit or alter
- the recipients' rights in the Source Code Form under this License.
-
-3.3. Distribution of a Larger Work
-
-You may create and distribute a Larger Work under terms of Your choice,
-provided that You also comply with the requirements of this License for
-the Covered Software. If the Larger Work is a combination of Covered
-Software with a work governed by one or more Secondary Licenses, and the
-Covered Software is not Incompatible With Secondary Licenses, this
-License permits You to additionally distribute such Covered Software
-under the terms of such Secondary License(s), so that the recipient of
-the Larger Work may, at their option, further distribute the Covered
-Software under the terms of either this License or such Secondary
-License(s).
-
-3.4. Notices
-
-You may not remove or alter the substance of any license notices
-(including copyright notices, patent notices, disclaimers of warranty,
-or limitations of liability) contained within the Source Code Form of
-the Covered Software, except that You may alter any license notices to
-the extent required to remedy known factual inaccuracies.
-
-3.5. Application of Additional Terms
-
-You may choose to offer, and to charge a fee for, warranty, support,
-indemnity or liability obligations to one or more recipients of Covered
-Software. However, You may do so only on Your own behalf, and not on
-behalf of any Contributor. You must make it absolutely clear that any
-such warranty, support, indemnity, or liability obligation is offered by
-You alone, and You hereby agree to indemnify every Contributor for any
-liability incurred by such Contributor as a result of warranty, support,
-indemnity or liability terms You offer. You may include additional
-disclaimers of warranty and limitations of liability specific to any
-jurisdiction.
-
-4. Inability to Comply Due to Statute or Regulation
----------------------------------------------------
-
-If it is impossible for You to comply with any of the terms of this
-License with respect to some or all of the Covered Software due to
-statute, judicial order, or regulation then You must: (a) comply with
-the terms of this License to the maximum extent possible; and (b)
-describe the limitations and the code they affect. Such description must
-be placed in a text file included with all distributions of the Covered
-Software under this License. Except to the extent prohibited by statute
-or regulation, such description must be sufficiently detailed for a
-recipient of ordinary skill to be able to understand it.
-
-5. Termination
---------------
-
-5.1. The rights granted under this License will terminate automatically
-if You fail to comply with any of its terms. However, if You become
-compliant, then the rights granted under this License from a particular
-Contributor are reinstated (a) provisionally, unless and until such
-Contributor explicitly and finally terminates Your grants, and (b) on an
-ongoing basis, if such Contributor fails to notify You of the
-non-compliance by some reasonable means prior to 60 days after You have
-come back into compliance. Moreover, Your grants from a particular
-Contributor are reinstated on an ongoing basis if such Contributor
-notifies You of the non-compliance by some reasonable means, this is the
-first time You have received notice of non-compliance with this License
-from such Contributor, and You become compliant prior to 30 days after
-Your receipt of the notice.
-
-5.2. If You initiate litigation against any entity by asserting a patent
-infringement claim (excluding declaratory judgment actions,
-counter-claims, and cross-claims) alleging that a Contributor Version
-directly or indirectly infringes any patent, then the rights granted to
-You by any and all Contributors for the Covered Software under Section
-2.1 of this License shall terminate.
-
-5.3. In the event of termination under Sections 5.1 or 5.2 above, all
-end user license agreements (excluding distributors and resellers) which
-have been validly granted by You or Your distributors under this License
-prior to termination shall survive termination.
-
-************************************************************************
-* *
-* 6. Disclaimer of Warranty *
-* ------------------------- *
-* *
-* Covered Software is provided under this License on an "as is" *
-* basis, without warranty of any kind, either expressed, implied, or *
-* statutory, including, without limitation, warranties that the *
-* Covered Software is free of defects, merchantable, fit for a *
-* particular purpose or non-infringing. The entire risk as to the *
-* quality and performance of the Covered Software is with You. *
-* Should any Covered Software prove defective in any respect, You *
-* (not any Contributor) assume the cost of any necessary servicing, *
-* repair, or correction. This disclaimer of warranty constitutes an *
-* essential part of this License. No use of any Covered Software is *
-* authorized under this License except under this disclaimer. *
-* *
-************************************************************************
-
-************************************************************************
-* *
-* 7. Limitation of Liability *
-* -------------------------- *
-* *
-* Under no circumstances and under no legal theory, whether tort *
-* (including negligence), contract, or otherwise, shall any *
-* Contributor, or anyone who distributes Covered Software as *
-* permitted above, be liable to You for any direct, indirect, *
-* special, incidental, or consequential damages of any character *
-* including, without limitation, damages for lost profits, loss of *
-* goodwill, work stoppage, computer failure or malfunction, or any *
-* and all other commercial damages or losses, even if such party *
-* shall have been informed of the possibility of such damages. This *
-* limitation of liability shall not apply to liability for death or *
-* personal injury resulting from such party's negligence to the *
-* extent applicable law prohibits such limitation. Some *
-* jurisdictions do not allow the exclusion or limitation of *
-* incidental or consequential damages, so this exclusion and *
-* limitation may not apply to You. *
-* *
-************************************************************************
-
-8. Litigation
--------------
-
-Any litigation relating to this License may be brought only in the
-courts of a jurisdiction where the defendant maintains its principal
-place of business and such litigation shall be governed by laws of that
-jurisdiction, without reference to its conflict-of-law provisions.
-Nothing in this Section shall prevent a party's ability to bring
-cross-claims or counter-claims.
-
-9. Miscellaneous
-----------------
-
-This License represents the complete agreement concerning the subject
-matter hereof. If any provision of this License is held to be
-unenforceable, such provision shall be reformed only to the extent
-necessary to make it enforceable. Any law or regulation which provides
-that the language of a contract shall be construed against the drafter
-shall not be used to construe this License against a Contributor.
-
-10. Versions of the License
----------------------------
-
-10.1. New Versions
-
-Mozilla Foundation is the license steward. Except as provided in Section
-10.3, no one other than the license steward has the right to modify or
-publish new versions of this License. Each version will be given a
-distinguishing version number.
-
-10.2. Effect of New Versions
-
-You may distribute the Covered Software under the terms of the version
-of the License under which You originally received the Covered Software,
-or under the terms of any subsequent version published by the license
-steward.
-
-10.3. Modified Versions
-
-If you create software not governed by this License, and you want to
-create a new license for such software, you may create and use a
-modified version of this License if you rename the license and remove
-any references to the name of the license steward (except to note that
-such modified license differs from this License).
-
-10.4. Distributing Source Code Form that is Incompatible With Secondary
-Licenses
-
-If You choose to distribute Source Code Form that is Incompatible With
-Secondary Licenses under the terms of this version of the License, the
-notice described in Exhibit B of this License must be attached.
-
-Exhibit A - Source Code Form License Notice
--------------------------------------------
-
- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-If it is not possible or desirable to put the notice in a particular
-file, then You may include the notice in a location (such as a LICENSE
-file in a relevant directory) where a recipient would be likely to look
-for such a notice.
-
-You may add additional accurate notices of copyright ownership.
-
-Exhibit B - "Incompatible With Secondary Licenses" Notice
----------------------------------------------------------
-
- This Source Code Form is "Incompatible With Secondary Licenses", as
- defined by the Mozilla Public License, v. 2.0.
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/README.rst b/README.rst
index a44546a..bb761a0 100644
--- a/README.rst
+++ b/README.rst
@@ -6,11 +6,11 @@ For full API reference documentation, visit https://fabiankueppers.github.io/cal
Copyright (C) 2019-2021 Ruhr West University of Applied Sciences, Bottrop, Germany
AND Elektronische Fahrwerksysteme GmbH, Gaimersheim, Germany
-This Source Code Form is subject to the terms of the Mozilla Public
-License, v. 2.0. If a copy of the MPL was not distributed with this
-file, You can obtain one at http://mozilla.org/MPL/2.0/.
+This Source Code Form is subject to the terms of the Apache License 2.0.
+If a copy of the APL2 was not distributed with this
+file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.txt.
-If you use this framework or parts of it for your research, please cite it by::
+**Important: updated references!** If you use this framework (*classification or detection*) or parts of it for your research, please cite it by::
@InProceedings{Kueppers_2020_CVPR_Workshops,
author = {Küppers, Fabian and Kronenberger, Jan and Shantia, Amirhossein and Haselhoff, Anselm},
@@ -20,6 +20,16 @@ If you use this framework or parts of it for your research, please cite it by::
year = {2020}
}
+*If you use Bayesian calibration methods with uncertainty, please cite it by*::
+
+ @InProceedings{Kueppers_2021_IV,
+ author = {Küppers, Fabian and Kronenberger, Jan and Schneider, Jonas and Haselhoff, Anselm},
+ title = {Bayesian Confidence Calibration for Epistemic Uncertainty Modelling},
+ booktitle = {Proceedings of the IEEE Intelligent Vehicles Symposium (IV)},
+ month = {July},
+ year = {2021},
+ }
+
.. contents:: Table of Contents
:depth: 2
@@ -30,6 +40,21 @@ This framework is designed to calibrate the confidence estimates of classifiers
For example: given 100 predictions with a confidence of 80% of each prediction, the observed accuracy should also match 80% (neither more nor less). This behaviour is achievable with several calibration methods.
+Update on version 1.2
+---------------------
+TL;DR:
+- Bayesian confidence calibration: train and infer scaling methods using variational inference (VI) and MCMC sampling
+- New metrics: MMCE [13]_ and PICP [14]_ (*netcal.metrics.MMCE* and *netcal.metrics.PICP*)
+- New regularization methods: MMCE [13]_ and DCA [15]_ (*netcal.regularization.MMCEPenalty* and *netcal.regularization.DCAPenalty*)
+- Updated examples
+- Switched license from MPL2 to APL2
+
+Now you can also use Bayesian methods to obtain uncertainty within a calibration mapping mainly in the *netcal.scaling* package. We adapted Markov-Chain Monte-Carlo sampling (MCMC) as well as Variational Inference (VI) on common calibration methods.
+It is also easily possible to bring the scaling methods to CUDA in order to speed-up the computations. We further provide new metrics to evaluate confidence calibration (MMCE) and to evaluate the quality of prediction intervals (PICP).
+Finally, we updated our framework by new regularization methods that can be used during model training (MMCE and DCA).
+
+Update on version 1.1
+---------------------
This framework can also be used to calibrate object detection models. It has recently been shown that calibration on object detection also depends on the position and/or scale of a predicted object [12]_. We provide calibration methods to perform confidence calibration w.r.t. the additional box regression branch.
For this purpose, we extended the commonly used Histogram Binning [3]_, Logistic Calibration alias Platt scaling [10]_ and the Beta Calibration method [2]_ to also include the bounding box information into a calibration mapping.
Furthermore, we provide two new methods called the *Dependent Logistic Calibration* and the *Dependent Beta Calibration* that are not only able to perform a calibration mapping
@@ -58,12 +83,16 @@ Or simply invoke the following command to install the calibration suite::
Requirements
------------
-- numpy>=1.15
+- numpy>=1.17
- scipy>=1.3
- matplotlib>=3.1
-- scikit-learn>=0.20.0
-- torch>=1.1
-- tqdm
+- scikit-learn>=0.21
+- torch>=1.4
+- torchvision>=0.5.0
+- tqdm>=4.40
+- pyro-ppl>=1.3
+- tikzplotlib>=0.9.8
+- tensorboard>=2.2
Calibration Metrics
@@ -74,10 +103,12 @@ For object detection, we implemented the *Detection Calibration Error* (D-ECE) [
- (Detection) Expected Calibration Error [1]_, [12]_ (*netcal.metrics.ECE*)
- (Detection) Maximum Calibration Error [1]_, [12]_ (*netcal.metrics.MCE*)
- (Detection) Average Calibration Error [11]_, [12]_ (*netcal.metrics.ACE*)
+- Maximum Mean Calibration Error (MMCE) [13]_ (*netcal.metrics.MMCE*) (no position-dependency)
+- Prediction interval coverage probability (PICP) (*netcal.metrics.PICP*) - this score is not a direct measure of confidence calibration but rather to measure the quality of uncertainty prediction intervals.
Methods
-==========
-The calibration methods are separated into binning and scaling methods. The binning methods divide the available information into several bins (like ECE or D-ECE) and perform calibration on each bin. The scaling methods scale the confidence estimates or logits directly to calibrated confidence estimates - on detection calibration, this is done w.r.t. the additional regression branch of a network.
+=======
+The post-hoc calibration methods are separated into binning and scaling methods. The binning methods divide the available information into several bins (like ECE or D-ECE) and perform calibration on each bin. The scaling methods scale the confidence estimates or logits directly to calibrated confidence estimates - on detection calibration, this is done w.r.t. the additional regression branch of a network.
Important: if you use the detection mode, you need to specifiy the flag "detection=True" in the constructor of the according method (this is not necessary for *netcal.scaling.LogisticCalibrationDependent* and *netcal.scaling.BetaCalibrationDependent*).
@@ -106,14 +137,22 @@ Implemented scaling methods are:
- Beta Calibration for classification [2]_ and object detection [12]_ (*netcal.scaling.BetaCalibration*)
- Dependent Beta Calibration for object detection [12]_ (*netcal.scaling.BetaCalibrationDependent*) - on detection, this method is able to capture correlations between all input quantities and should be preferred over Beta Calibration for object detection
+**New on version 1.2:**: you can provide a parameter named "method" to the constructor of each scaling method. This parameter could be one of the following:
+- 'mle': use the method feed-forward with maximum likelihood estimates on the calibration parameters (standard)
+- 'momentum': use non-convex momentum optimization (e.g. default on dependent beta calibration)
+- 'mcmc': use Markov-Chain Monte-Carlo sampling to obtain multiple parameter sets in order to quantify uncertainty in the calibration
+- 'variational': use Variational Inference to obtain multiple parameter sets in order to quantify uncertainty in the calibration
+
Regularization
--------------
-Implemented regularization methods are:
+With some effort, it is also possible to push the model training towards calibrated confidences by regularization. Implemented regularization methods are:
-- Confidence Penalty [8]_ (*netcal.regularization.confidence_penalty*)
+- Confidence Penalty [8]_ (*netcal.regularization.confidence_penalty* and *netcal.regularization.ConfidencePenalty* - the latter one is a PyTorch implementation that might be used as a regularization term)
+- Maximum Mean Calibration Error (MMCE) [13]_ (*netcal.regularization.MMCEPenalty* - PyTorch regularization module)
+- DCA [15]_ (*netcal.regularization.DCAPenalty* - PyTorch regularization module)
Visualization
-================
+=============
For visualization of miscalibration, one can use a Confidence Histograms & Reliability Diagrams. These diagrams are similar to ECE, the output space is divided into equally spaced bins. The calibration gap between bin accuracy and bin confidence is visualized as a histogram.
On detection calibration, the miscalibration can be visualized either along one additional box information (e.g. the x-position of the predictions) or distributed over two additional box information in terms of a heatmap.
@@ -121,7 +160,7 @@ On detection calibration, the miscalibration can be visualized either along one
- Reliability Diagram [1]_, [12]_ (*netcal.presentation.ReliabilityDiagram*)
Examples
-===========
+========
The calibration methods work with the predicted confidence estimates of a neural network and on detection also with the bounding box regression branch.
Classification
@@ -170,7 +209,7 @@ The miscalibration can be visualized with a Reliability Diagram:
Detection
---------
-This is a basic example which uses softmax predictions of a classification task with 10 classes and the given NumPy arrays:
+In this example we use confidence predictions of an object detection model with the according x-position of the predicted bounding boxes. Our ground-truth provided to the calibration algorithm denotes if a bounding box has matched a ground-truth box with a certain IoU and the correct class label.
.. code-block:: python
@@ -187,11 +226,11 @@ This is an example for *netcal.scaling.LogisticCalibration* and *netcal.scaling.
input = np.stack((confidences, relative_x_position), axis=1)
- lr = LogisticCalibration(detection=True) # flag 'detection=True' is mandatory for this method
+ lr = LogisticCalibration(detection=True, use_cuda=False) # flag 'detection=True' is mandatory for this method
lr.fit(input, matched)
calibrated = lr.transform(input)
- lr_dependent = LogisticCalibrationDependent() # flag 'detection=True' is not necessary as this method is only defined for detection
+ lr_dependent = LogisticCalibrationDependent(use_cuda=False) # flag 'detection=True' is not necessary as this method is only defined for detection
lr_dependent.fit(input, matched)
calibrated = lr_dependent.transform(input)
@@ -220,6 +259,89 @@ The miscalibration can be visualized with a Reliability Diagram:
diagram.plot(input, matched) # visualize miscalibration of uncalibrated
diagram.plot(input_calibrated, matched) # visualize miscalibration of calibrated
+Uncertainty in Calibration
+--------------------------
+We can also quantify the uncertainty in a calibration mapping if we use a Bayesian view on the calibration models. We can sample multiple parameter sets using MCMC sampling or VI. In this example, we reuse the data of the previous detection example.
+
+.. code-block:: python
+
+ matched # binary NumPy 1-D array (0, 1) that indicates if a bounding box has matched a ground truth at a certain IoU with the right label - shape: (n_samples,)
+ confidences # NumPy 1-D array with confidence estimates between 0-1 - shape: (n_samples,)
+ relative_x_position # NumPy 1-D array with relative center-x position between 0-1 of each prediction - shape: (n_samples,)
+
+This is an example for *netcal.scaling.LogisticCalibration* and *netcal.scaling.LogisticCalibrationDependent* but also works for every calibration method (remind different constructor parameters):
+
+.. code-block:: python
+
+ import numpy as np
+ from netcal.scaling import LogisticCalibration, LogisticCalibrationDependent
+
+ input = np.stack((confidences, relative_x_position), axis=1)
+
+ # flag 'detection=True' is mandatory for this method
+ # use Variational Inference with 2000 optimization steps for creating this calibration mapping
+ lr = LogisticCalibration(detection=True, method'variational', vi_epochs=2000, use_cuda=False)
+ lr.fit(input, matched)
+
+ # 'num_samples=1000': sample 1000 parameter sets from VI
+ # thus, 'calibrated' has shape [1000, n_samples]
+ calibrated = lr.transform(input, num_samples=1000)
+
+ # flag 'detection=True' is not necessary as this method is only defined for detection
+ # this time, use Markov-Chain Monte-Carlo sampling with 250 warm-up steps, 250 parameter samples and one chain
+ lr_dependent = LogisticCalibrationDependent(method='mcmc',
+ mcmc_warmup_steps=250, mcmc_steps=250, mcmc_chains=1,
+ use_cuda=False)
+ lr_dependent.fit(input, matched)
+
+ # 'num_samples=1000': although we have only sampled 250 different parameter sets,
+ # we can randomly sample 1000 parameter sets from MCMC
+ calibrated = lr_dependent.transform(input)
+
+You can directly pass the output to the D-ECE and PICP instance to measure miscalibration and mask quality:
+.. code-block:: python
+
+ from netcal.metrics import ECE
+ from netcal.metrics import PICP
+
+ n_bins = 10
+ ece = ECE(n_bins, detection=True)
+ picp = PICP(n_bins, detection=True)
+
+ # the following function calls are equivalent:
+ miscalibration = ece.measure(calibrated, matched, uncertainty="mean")
+ miscalibration = ece.measure(np.mean(calibrated, axis=0), matched)
+
+ # now determine uncertainty quality
+ uncertainty = picp.measure(calibrated, matched, uncertainty="mean")
+
+ print("D-ECE:", miscalibration)
+ print("PICP:", uncertainty.picp) # prediction coverage probability
+ print("MPIW:", uncertainty.mpiw) # mean prediction interval width
+
+If we want to measure miscalibration and uncertainty quality by means of the relative x position, we need to broadcast the according information:
+
+.. code-block:: python
+
+ # broadcast and stack x information to calibrated information
+ broadcasted = np.broadcast_to(relative_x_position, calibrated.shape)
+ calibrated = np.stack((calibrated, broadcasted), axis=2)
+
+ n_bins = [10, 10]
+ ece = ECE(n_bins, detection=True)
+ picp = PICP(n_bins, detection=True)
+
+ # the following function calls are equivalent:
+ miscalibration = ece.measure(calibrated, matched, uncertainty="mean")
+ miscalibration = ece.measure(np.mean(calibrated, axis=0), matched)
+
+ # now determine uncertainty quality
+ uncertainty = picp.measure(calibrated, matched, uncertainty="mean")
+
+ print("D-ECE:", miscalibration)
+ print("PICP:", uncertainty.picp) # prediction coverage probability
+ print("MPIW:", uncertainty.mpiw) # mean prediction interval width
+
References
==========
.. [1] Naeini, Mahdi Pakdaman, Gregory Cooper, and Milos Hauskrecht: "Obtaining well calibrated probabilities using bayesian binning." Twenty-Ninth AAAI Conference on Artificial Intelligence, 2015.
@@ -234,3 +356,6 @@ References
.. [10] Platt, John: "Probabilistic outputs for support vector machines and comparisons to regularized likelihood methods." Advances in large margin classifiers, 10(3): 61–74, 1999.
.. [11] Neumann, Lukas, Andrew Zisserman, and Andrea Vedaldi: "Relaxed Softmax: Efficient Confidence Auto-Calibration for Safe Pedestrian Detection." Conference on Neural Information Processing Systems (NIPS) Workshop MLITS, 2018.
.. [12] Fabian Küppers, Jan Kronenberger, Amirhossein Shantia and Anselm Haselhoff: "Multivariate Confidence Calibration for Object Detection"." The IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Workshops, 2020
+.. [13] Kumar, Aviral, Sunita Sarawagi, and Ujjwal Jain: "Trainable calibration measures for neural networks from _kernel mean embeddings." International Conference on Machine Learning. 2018
+.. [14] Jiayu Yao, Weiwei Pan, Soumya Ghosh, and Finale Doshi-Velez: "Quality of Uncertainty Quantification for Bayesian Neural Network Inference." Workshop on Uncertainty and Robustness in Deep Learning, ICML, 2019
+.. [15] Liang, Gongbo, et al.: "Improved trainable calibration method for neural networks on medical imaging classification." arXiv preprint arXiv:2009.04057 (2020)
diff --git a/docs/build/html/.buildinfo b/docs/build/html/.buildinfo
index 515f083..299fd67 100644
--- a/docs/build/html/.buildinfo
+++ b/docs/build/html/.buildinfo
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
-config: 78e6332c97a52e1ea66f816824406211
+config: e4be416fe1fade80beef75b5aa42bfc9
tags: 645f666f9bcd5a90fca523b33c5a78b7
diff --git a/docs/build/html/_autosummary/_autosummary_binning/netcal.binning.BBQ.html b/docs/build/html/_autosummary/_autosummary_binning/netcal.binning.BBQ.html
index 16e9055..7bc505e 100644
--- a/docs/build/html/_autosummary/_autosummary_binning/netcal.binning.BBQ.html
+++ b/docs/build/html/_autosummary/_autosummary_binning/netcal.binning.BBQ.html
@@ -4,7 +4,7 @@
Bayesian Binning into Quantiles (BBQ). This method is originally proposed by 1. This method utilizes multiple HistogramBinning
+
Bayesian Binning into Quantiles (BBQ) 1. This method utilizes multiple HistogramBinning
instances with different amounts of bins and computes a weighted sum of all methods to obtain a
well-calibrated confidence estimate. The scoring function “BDeu”, which is proposed in the original paper,
is currently not supported.
@@ -82,6 +82,8 @@
netcal.binning.BBQ
-
__init__([score_function, detection, …])
+
__init__([score_function, equal_intervals, …])
Constructor.
clear()
@@ -124,10 +126,10 @@
netcal.binning.BBQ
load_model(filename)
-
Load model from saved Pickle instance.
+
Load model from saved torch dump.
save_model(filename)
-
Save model instance as Pickle Object.
+
Save model instance as with torch’s save function as this is safer for torch tensors.
Ensemble of Near Isotonic Regression (ENIR) models. This method is originally proposed by 1. These models allow - in contrast to standard
+
Ensemble of Near Isotonic Regression (ENIR) models 1. These models allow - in contrast to standard
IsotonicRegression method - a violation of the monotony restrictions. Using the modified
Pool-Adjacent-Violators Algorithm (mPAVA), this method build multiple Near Isotonic Regression models
and weights them by a certain score function.
@@ -125,10 +125,10 @@
netcal.binning.ENIR
load_model(filename)
-
Load model from saved Pickle instance.
+
Load model from saved torch dump.
save_model(filename)
-
Save model instance as Pickle Object.
+
Save model instance as with torch’s save function as this is safer for torch tensors.
Simple Histogram Binning calibration method. This method is originally proposed by 1. Each prediction is sorted into a bin
+
Simple Histogram Binning calibration method 1. Each prediction is sorted into a bin
and assigned its calibrated confidence estimate. This method normally works for binary
classification. For multiclass classification, this method is applied into a 1-vs-all manner 2.
-
The bin boundaries are either chosen to be
-equal length intervals or to equalize the number of samples in each bin.
+
The bin boundaries are either chosen to be equal length intervals or to equalize the number of samples in each bin.
On object detection, use a multidimensional binning to include additional information of the box
regression branch 3.
@@ -109,7 +108,7 @@
netcal.binning.HistogramBinning
clear()
Clear model parameters.
-
fit(X, y)
+
fit(X, y[, random_state, tensorboard, log_dir])
Function call to build the calibration model.
fit_transform(X[, y])
@@ -122,10 +121,10 @@
netcal.binning.HistogramBinning
load_model(filename)
-
Load model from saved Pickle instance.
+
Load model from saved torch dump.
save_model(filename)
-
Save model instance as Pickle Object.
+
Save model instance as with torch’s save function as this is safer for torch tensors.
set_params(**params)
Set the parameters of this estimator.
@@ -133,7 +132,7 @@
netcal.binning.HistogramBinning
squeeze_generic(a, axes_to_keep)
Squeeze input array a but keep axes defined by parameter ‘axes_to_keep’ even if the dimension is of size 1.
-
transform(X)
+
transform(X[, num_samples, random_state])
After model calibration, this function is used to get calibrated outputs of uncalibrated confidence estimates.
+transform(X: numpy.ndarray, num_samples: int = 1, random_state: int = None) → numpy.ndarray¶
After model calibration, this function is used to get calibrated outputs of uncalibrated
confidence estimates.
Parameters
-
X (np.ndarray, shape=(n_samples, [n_classes])) – NumPy array with uncalibrated confidence estimates.
-1-D for binary classification, 2-D for multi class (softmax).
+
+
X (np.ndarray, shape=(n_samples, [n_classes])) – NumPy array with uncalibrated confidence estimates.
+1-D for binary classification, 2-D for multi class (softmax).
+
num_samples (int, optional, default: 1000) – Number of samples generated on MCMC sampling or Variational Inference - only for compatibility and
+not used by Histogram Binning!
+
random_state (int, optional, default: None) – Fix the random seed for the random number
+
Returns
NumPy array with calibrated confidence estimates.
@@ -362,7 +367,7 @@
Isotonic Regression method. This method is originally proposed by 1. This method is similar to HistogramBinning but with dynamic bin sizes
+
Isotonic Regression method 1. This method is similar to HistogramBinning but with dynamic bin sizes
and boundaries. A piecewise constant function gets fit to ground truth labels sorted by
given confidence estimates.
@@ -99,10 +99,10 @@
netcal.binning.IsotonicRegression
load_model(filename)
-
Load model from saved Pickle instance.
+
Load model from saved torch dump.
save_model(filename)
-
Save model instance as Pickle Object.
+
Save model instance as with torch’s save function as this is safer for torch tensors.
Perform binning on value (and all additional values passed) based on samples.
+
+
Parameters
+
+
bin_bounds (list, length=samples.shape[1]) – Binning boundaries used for each dimension given in ‘samples’ parameter.
+
samples (np.ndarray of shape (n_samples, n_features)) – Array used to group all samples into bins.
+
*values (instances np.ndarray of shape (n_samples, 1)) – Arrays whose values are binned.
+
nan (float, optional default: 0.0) – If a bin has no samples or less than defined sample_threshold, the according bin is marked as
+NaN. Specify fill float to insert instead of NaN.
+
+
+
Returns
+
+
tuple of length equal to the amount of passed value arrays with binning schemes and an additional histogram
+
with number of samples in each bin as well as an index tuple containing the bin indices.
Measure calibration by given predictions with confidence and the according ground truth.
Assume binary predictions with y=1.
Parameters
-
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+
X (iterable of np.ndarray, or np.ndarray of shape=([n_bayes], n_samples, [n_classes/n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
1-D for binary classification, 2-D for multi class (softmax).
+If 3-D, interpret first dimension as samples from an Bayesian estimator with mulitple data points
+for a single sample (e.g. variational inference or MC dropout samples).
+If this is an iterable over multiple instances of np.ndarray and parameter batched=True,
+interpret this parameter as multiple predictions that should be averaged.
On detection, this array must have 2 dimensions with number of additional box features in last dim.
-
y (np.ndarray, shape=(n_samples, [n_classes])) – NumPy array with ground truth labels.
-Either as label vector (1-D) or as one-hot encoded ground truth array (2-D).
+
y (iterable of np.ndarray with same length as X or np.ndarray of shape=([n_bayes], n_samples, [n_classes])) – NumPy array with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D).
+If 3-D, interpret first dimension as samples from an Bayesian estimator with mulitple data points
+for a single sample (e.g. variational inference or MC dropout samples).
+If iterable over multiple instances of np.ndarray and parameter batched=True,
+interpret this parameter as multiple predictions that should be averaged.
+
batched (bool, optional, default: False) – Multiple predictions can be evaluated at once (e.g. cross-validation examinations) using batched-mode.
+All predictions given by X and y are separately evaluated and their results are averaged afterwards
+for visualization.
+
uncertainty (str, optional, default: False) –
Define uncertainty handling if input X has been sampled e.g. by Monte-Carlo dropout or similar methods
+that output an ensemble of predictions per sample. Choose one of the following options:
+- flatten: treat everything as a separate prediction - this option will yield into a slightly better
+
+
calibration performance but without the visualization of a prediction interval.
+
+
+
+
mean: compute Monte-Carlo integration to obtain a simple confidence estimate for a sample
(mean) with a standard deviation that is visualized.
+
+
+
+
+
return_map (bool, optional, default: False) – If True, return map with miscalibration metric separated into all remaining dimension bins.
return_num_samples (bool, optional, default: False) – If True, also return the number of samples in each bin.
+
return_uncertainty_map (bool, optional, default: False) – If True, also return the average deviation of the confidence within each bin.
Returns
-
Always returns miscalibration metric.
-If ‘return_map’ is False, return ACE only (or num_samples map).
-If ‘return_map’ is True, return tuple with ACE and map over all bins.
-If ‘return_num_samples’ is False, ACE only (or ACE map).
-If ‘return_num_samples’ is True, return tuple with ACE and number of samples in each bin.
+
Always returns Average Calibration Error.
+If ‘return_map’ is True, return tuple and append miscalibration map over all bins.
+If ‘return_num_samples’ is True, return tuple and append the number of samples in each bin (excluding confidence dimension).
+If ‘return_uncertainty’ is True, return tuple and append the average standard deviation of confidence within each bin (excluding confidence dimension).
Return type
-
float or tuple of (float, np.ndarray) or tuple of (float, np.ndarray, np.ndarray)
+
float or tuple of (float, np.ndarray, [np.ndarray, [np.ndarray]])
Determine miscalibration based on passed histograms.
Parameters
-
a (np.ndarray) – NumPy array that should be squeezed.
-
axes_to_keep (int or iterable) – Axes that should be kept even if they have a size of 1.
+
metric (str) – Identifier to specify the used metric. Must be one of ‘ace’, ‘ece’ or ‘mce’.
+
acc_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with average accuracy in each bin.
+
conf_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with average confidence in each bin.
+
variance_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with average variance in each bin. This array is currently not used but
+might be utilized in the future.
+
num_samples_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with number of samples in each bin.
Returns
-
Squeezed array.
-
-
Return type
-
np.ndarray
+
+
tuple of length 6 (miscalibration score, miscalibration map, accuracy map, confidence map, variance map, num samples map)
Calculate the weighted mean on a given histogram based on a dedicated data distribution.
+If ‘reduce_result’ is given, reuse the data distribution of the previous result instead of the distribution
+given by ‘distribution’ parameter.
Perform binning on value (and all additional values passed) based on samples.
+
+
Parameters
+
+
bin_bounds (list, length=samples.shape[1]) – Binning boundaries used for each dimension given in ‘samples’ parameter.
+
samples (np.ndarray of shape (n_samples, n_features)) – Array used to group all samples into bins.
+
*values (instances np.ndarray of shape (n_samples, 1)) – Arrays whose values are binned.
+
nan (float, optional default: 0.0) – If a bin has no samples or less than defined sample_threshold, the according bin is marked as
+NaN. Specify fill float to insert instead of NaN.
+
+
+
Returns
+
+
tuple of length equal to the amount of passed value arrays with binning schemes and an additional histogram
+
with number of samples in each bin as well as an index tuple containing the bin indices.
Measure calibration by given predictions with confidence and the according ground truth.
Assume binary predictions with y=1.
Parameters
-
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+
X (iterable of np.ndarray, or np.ndarray of shape=([n_bayes], n_samples, [n_classes/n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
1-D for binary classification, 2-D for multi class (softmax).
+If 3-D, interpret first dimension as samples from an Bayesian estimator with mulitple data points
+for a single sample (e.g. variational inference or MC dropout samples).
+If this is an iterable over multiple instances of np.ndarray and parameter batched=True,
+interpret this parameter as multiple predictions that should be averaged.
On detection, this array must have 2 dimensions with number of additional box features in last dim.
-
y (np.ndarray, shape=(n_samples, [n_classes])) – NumPy array with ground truth labels.
-Either as label vector (1-D) or as one-hot encoded ground truth array (2-D).
+
y (iterable of np.ndarray with same length as X or np.ndarray of shape=([n_bayes], n_samples, [n_classes])) – NumPy array with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D).
+If 3-D, interpret first dimension as samples from an Bayesian estimator with mulitple data points
+for a single sample (e.g. variational inference or MC dropout samples).
+If iterable over multiple instances of np.ndarray and parameter batched=True,
+interpret this parameter as multiple predictions that should be averaged.
+
batched (bool, optional, default: False) – Multiple predictions can be evaluated at once (e.g. cross-validation examinations) using batched-mode.
+All predictions given by X and y are separately evaluated and their results are averaged afterwards
+for visualization.
+
uncertainty (str, optional, default: False) –
Define uncertainty handling if input X has been sampled e.g. by Monte-Carlo dropout or similar methods
+that output an ensemble of predictions per sample. Choose one of the following options:
+- flatten: treat everything as a separate prediction - this option will yield into a slightly better
+
+
calibration performance but without the visualization of a prediction interval.
+
+
+
+
mean: compute Monte-Carlo integration to obtain a simple confidence estimate for a sample
(mean) with a standard deviation that is visualized.
+
+
+
+
+
return_map (bool, optional, default: False) – If True, return map with miscalibration metric separated into all remaining dimension bins.
return_num_samples (bool, optional, default: False) – If True, also return the number of samples in each bin.
+
return_uncertainty_map (bool, optional, default: False) – If True, also return the average deviation of the confidence within each bin.
Returns
-
Always returns miscalibration metric.
-If ‘return_map’ is False, return ECE only (or num_samples map).
-If ‘return_map’ is True, return tuple with ECE and map over all bins.
-If ‘return_num_samples’ is False, ECE only (or ECE map).
-If ‘return_num_samples’ is True, return tuple with ECE and number of samples in each bin.
+
Always returns Expected Calibration Error.
+If ‘return_map’ is True, return tuple and append miscalibration map over all bins.
+If ‘return_num_samples’ is True, return tuple and append the number of samples in each bin (excluding confidence dimension).
+If ‘return_uncertainty’ is True, return tuple and append the average standard deviation of confidence within each bin (excluding confidence dimension).
Return type
-
float or tuple of (float, np.ndarray) or tuple of (float, np.ndarray, np.ndarray)
+
float or tuple of (float, np.ndarray, [np.ndarray, [np.ndarray]])
Determine miscalibration based on passed histograms.
Parameters
-
a (np.ndarray) – NumPy array that should be squeezed.
-
axes_to_keep (int or iterable) – Axes that should be kept even if they have a size of 1.
+
metric (str) – Identifier to specify the used metric. Must be one of ‘ace’, ‘ece’ or ‘mce’.
+
acc_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with average accuracy in each bin.
+
conf_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with average confidence in each bin.
+
variance_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with average variance in each bin. This array is currently not used but
+might be utilized in the future.
+
num_samples_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with number of samples in each bin.
Returns
-
Squeezed array.
-
-
Return type
-
np.ndarray
+
+
tuple of length 6 (miscalibration score, miscalibration map, accuracy map, confidence map, variance map, num samples map)
Calculate the weighted mean on a given histogram based on a dedicated data distribution.
+If ‘reduce_result’ is given, reuse the data distribution of the previous result instead of the distribution
+given by ‘distribution’ parameter.
Perform binning on value (and all additional values passed) based on samples.
+
+
Parameters
+
+
bin_bounds (list, length=samples.shape[1]) – Binning boundaries used for each dimension given in ‘samples’ parameter.
+
samples (np.ndarray of shape (n_samples, n_features)) – Array used to group all samples into bins.
+
*values (instances np.ndarray of shape (n_samples, 1)) – Arrays whose values are binned.
+
nan (float, optional default: 0.0) – If a bin has no samples or less than defined sample_threshold, the according bin is marked as
+NaN. Specify fill float to insert instead of NaN.
+
+
+
Returns
+
+
tuple of length equal to the amount of passed value arrays with binning schemes and an additional histogram
+
with number of samples in each bin as well as an index tuple containing the bin indices.
Measure calibration by given predictions with confidence and the according ground truth.
+Assume binary predictions with y=1.
+
Parameters
-
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+
X (iterable of np.ndarray, or np.ndarray of shape=([n_bayes], n_samples, [n_classes/n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
1-D for binary classification, 2-D for multi class (softmax).
+If 3-D, interpret first dimension as samples from an Bayesian estimator with mulitple data points
+for a single sample (e.g. variational inference or MC dropout samples).
+If this is an iterable over multiple instances of np.ndarray and parameter batched=True,
+interpret this parameter as multiple predictions that should be averaged.
On detection, this array must have 2 dimensions with number of additional box features in last dim.
-
y (np.ndarray, shape=(n_samples, [n_classes])) – NumPy array with ground truth labels.
-Either as label vector (1-D) or as one-hot encoded ground truth array (2-D).
+
y (iterable of np.ndarray with same length as X or np.ndarray of shape=([n_bayes], n_samples, [n_classes])) – NumPy array with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D).
+If 3-D, interpret first dimension as samples from an Bayesian estimator with mulitple data points
+for a single sample (e.g. variational inference or MC dropout samples).
+If iterable over multiple instances of np.ndarray and parameter batched=True,
+interpret this parameter as multiple predictions that should be averaged.
+
batched (bool, optional, default: False) – Multiple predictions can be evaluated at once (e.g. cross-validation examinations) using batched-mode.
+All predictions given by X and y are separately evaluated and their results are averaged afterwards
+for visualization.
+
uncertainty (str, optional, default: False) –
Define uncertainty handling if input X has been sampled e.g. by Monte-Carlo dropout or similar methods
+that output an ensemble of predictions per sample. Choose one of the following options:
+- flatten: treat everything as a separate prediction - this option will yield into a slightly better
+
+
calibration performance but without the visualization of a prediction interval.
+
+
+
+
mean: compute Monte-Carlo integration to obtain a simple confidence estimate for a sample
(mean) with a standard deviation that is visualized.
+
+
+
+
+
return_map (bool, optional, default: False) – If True, return map with miscalibration metric separated into all remaining dimension bins.
return_num_samples (bool, optional, default: False) – If True, also return the number of samples in each bin.
+
return_uncertainty_map (bool, optional, default: False) – If True, also return the average deviation of the confidence within each bin.
Returns
-
Always returns miscalibration metric.
-If ‘return_map’ is False, return MCE only (or num_samples map).
-If ‘return_map’ is True, return tuple with MCE and map over all bins.
-If ‘return_num_samples’ is False, MCE only (or MCE map).
-If ‘return_num_samples’ is True, return tuple with MCE and number of samples in each bin.
+
Always returns Maximum Calibration Error.
+If ‘return_map’ is True, return tuple and append miscalibration map over all bins.
+If ‘return_num_samples’ is True, return tuple and append the number of samples in each bin (excluding confidence dimension).
+If ‘return_uncertainty’ is True, return tuple and append the average standard deviation of confidence within each bin (excluding confidence dimension).
Return type
-
float or tuple of (float, np.ndarray) or tuple of (float, np.ndarray, np.ndarray)
+
float or tuple of (float, np.ndarray, [np.ndarray, [np.ndarray]])
Determine miscalibration based on passed histograms.
Parameters
-
a (np.ndarray) – NumPy array that should be squeezed.
-
axes_to_keep (int or iterable) – Axes that should be kept even if they have a size of 1.
+
metric (str) – Identifier to specify the used metric. Must be one of ‘ace’, ‘ece’ or ‘mce’.
+
acc_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with average accuracy in each bin.
+
conf_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with average confidence in each bin.
+
variance_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with average variance in each bin. This array is currently not used but
+might be utilized in the future.
+
num_samples_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with number of samples in each bin.
Returns
-
Squeezed array.
-
-
Return type
-
np.ndarray
+
+
tuple of length 6 (miscalibration score, miscalibration map, accuracy map, confidence map, variance map, num samples map)
Calculate the weighted mean on a given histogram based on a dedicated data distribution.
+If ‘reduce_result’ is given, reuse the data distribution of the previous result instead of the distribution
+given by ‘distribution’ parameter.
Maximum Mean Calibration Error (MMCE) 1.
+A differentiable approximation to the Expected Calibration Error (ECE) using a
+reproducing _kernel Hilbert space (RKHS).
+Using a dataset \(\mathcal{D}\) of size \(N\) consisting of the ground truth labels \(\hat{y} \in \{1, ..., K \}\)
+with input \(\hat{y} \in \mathcal{X}\), the MMCE is calculated by using a scoring classifier \(\hat{p}=h(x)\)
+that returns the highest probability for a certain class in conjunction with the predicted label
+information \(y \in \{1, ..., K \}\) and is defined by
detection (bool, default: False) – Detection mode is currently not supported for MMCE!
+If False, the input array ‘X’ is treated as multi-class confidence input (softmax)
+with shape (n_samples, [n_classes]).
+If True, the input array ‘X’ is treated as a box predictions with several box features (at least
+box confidence must be present) with shape (n_samples, [n_box_features]).
Measure calibration by given predictions with confidence and the according ground truth.
+
+
Parameters
+
+
X (iterable of np.ndarray, or np.ndarray of shape=(n_samples, [n_classes])) – NumPy array with confidence values for each prediction on classification with shapes
+1-D for binary classification, 2-D for multi class (softmax).
+If this is an iterable over multiple instances of np.ndarray and parameter batched=True,
+interpret this parameter as multiple predictions that should be averaged.
+
y (iterable of np.ndarray with same length as X or np.ndarray of shape=(n_samples, [n_classes])) – NumPy array with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D).
+If iterable over multiple instances of np.ndarray and parameter batched=True,
+interpret this parameter as multiple predictions that should be averaged.
+
batched (bool, optional, default: False) – Multiple predictions can be evaluated at once (e.g. cross-validation examinations) using batched-mode.
+All predictions given by X and y are separately evaluated and their results are averaged afterwards
+for visualization.
Compute Prediction Interval Coverage Probability (PICP) 1,[2]_ and Mean Prediction Interval Width (MPIW) 2.
+This metric is used for Bayesian models to determine the quality of the uncertainty estimates.
+In Bayesian mode, an uncertainty estimate is attached to each sample. The PICP measures the probability, that
+the true (observed) accuracy falls into the p% prediction interval. The uncertainty is well-calibrated, if
+the PICP is equal to p%. Simultaneously, the MPIW measures the mean width of all prediction intervals to evaluate
+the sharpness of the uncertainty estimates.
+
+
Parameters
+
+
bins (int or iterable, default: 10) – Number of bins used by the Histogram Binning.
+On detection mode: if int, use same amount of bins for each dimension (nx1 = nx2 = … = bins).
+If iterable, use different amount of bins for each dimension (nx1, nx2, … = bins).
+
equal_intervals (bool, optional, default: True) – If True, the bins have the same width. If False, the bins are splitted to equalize
+the number of samples in each bin.
+
detection (bool, default: False) – If False, the input array ‘X’ is treated as multi-class confidence input (softmax)
+with shape (n_samples, [n_classes]).
+If True, the input array ‘X’ is treated as a box predictions with several box features (at least
+box confidence must be present) with shape (n_samples, [n_box_features]).
+
sample_threshold (int, optional, default: 1) – Bins with an amount of samples below this threshold are not included into the process metrics.
Kuleshov, V.; Fenner, N. & Ermon, S.:
+“Accurate Uncertainties for Deep Learning Using Calibrated Regression.”
+International Conference on Machine Learning (ICML), 2018
+Get source online
Jiayu Yao, Weiwei Pan, Soumya Ghosh, and Finale Doshi-Velez:
+“Quality of Uncertainty Quantification for Bayesian Neural Network Inference.”
+Workshop on Uncertainty and Robustness in Deep Learning, ICML, 2019
+Get source online
+
+
+
Methods
+
+
+
+
+
+
+
__init__([bins, equal_intervals, detection, …])
+
Constructor.
+
+
accuracy(X, y[, batched, uncertainty])
+
Measure the accuracy of each point by binning.
+
+
binning(bin_bounds, samples, *values[, nan])
+
Perform binning on value (and all additional values passed) based on samples.
+
+
measure(X, y[, p, use_hpd, batched, …])
+
Measure calibration by given predictions with confidence and the according ground truth.
+
+
prepare(X, y[, batched, uncertainty])
+
Check input data.
+
+
process(metric, acc_hist, conf_hist, …)
+
Determine miscalibration based on passed histograms.
+
+
reduce(histogram, distribution, axis[, …])
+
Calculate the weighted mean on a given histogram based on a dedicated data distribution.
+
+
squeeze_generic(a, axes_to_keep)
+
Squeeze input array a but keep axes defined by parameter ‘axes_to_keep’ even if the dimension is of size 1.
Perform binning on value (and all additional values passed) based on samples.
+
+
Parameters
+
+
bin_bounds (list, length=samples.shape[1]) – Binning boundaries used for each dimension given in ‘samples’ parameter.
+
samples (np.ndarray of shape (n_samples, n_features)) – Array used to group all samples into bins.
+
*values (instances np.ndarray of shape (n_samples, 1)) – Arrays whose values are binned.
+
nan (float, optional default: 0.0) – If a bin has no samples or less than defined sample_threshold, the according bin is marked as
+NaN. Specify fill float to insert instead of NaN.
+
+
+
Returns
+
+
tuple of length equal to the amount of passed value arrays with binning schemes and an additional histogram
+
with number of samples in each bin as well as an index tuple containing the bin indices.
Measure calibration by given predictions with confidence and the according ground truth.
+Assume binary predictions with y=1.
+
+
Parameters
+
+
X (iterable of np.ndarray, or np.ndarray of shape=([n_bayes], n_samples, [n_classes/n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+1-D for binary classification, 2-D for multi class (softmax).
+If 3-D, interpret first dimension as samples from an Bayesian estimator with mulitple data points
+for a single sample (e.g. variational inference or MC dropout samples).
+If this is an iterable over multiple instances of np.ndarray and parameter batched=True,
+interpret this parameter as multiple predictions that should be averaged.
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
+
y (iterable of np.ndarray with same length as X or np.ndarray of shape=([n_bayes], n_samples, [n_classes])) – NumPy array with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D).
+If 3-D, interpret first dimension as samples from an Bayesian estimator with mulitple data points
+for a single sample (e.g. variational inference or MC dropout samples).
+If iterable over multiple instances of np.ndarray and parameter batched=True,
+interpret this parameter as multiple predictions that should be averaged.
+
p (float, optional, default: 0.05) – Confidence level.
+
use_hpd (bool, optional, default: True) – If True, use highest posterior density (HPD) interval to determine the prediction interval width.
+Use variance with Gaussian assumption otherwise.
+
batched (bool, optional, default: False) – Multiple predictions can be evaluated at once (e.g. cross-validation examinations) using batched-mode.
+All predictions given by X and y are separately evaluated and their results are averaged afterwards
+for visualization.
+
uncertainty (str, optional, default: "mean") – Mode to measure mean estimate and uncertainty of the samples in Bayesian mode. Must be one
+of “mean” (mean of all samples), “mode” (mode of all samples), “median” (median of all samples) or
+“flatten” (no uncertainty will be computed, all samples are seen as independent predictions).
+
return_map (bool, optional, default: False) – If True, return map with PICP and MPIW metric separated into all remaining dimension bins.
+
+
+
Returns
+
+
Namedtuple PICPResult with fields “picp” and “mpiw”, where each field either holds the PICP/MPIW score
+
or a tuple of (float, np.ndarray) – Always returns a named tuple with PICP (prediction interval coverage probability) and MPIW
+(mean prediction interval width).
+If ‘return_map’ is True, each field holds a tuple for the metric itself and the PICP/MPIW distribution
+over all bins.
Determine miscalibration based on passed histograms.
+
+
Parameters
+
+
metric (str) – Identifier to specify the used metric. Must be one of ‘ace’, ‘ece’ or ‘mce’.
+
acc_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with average accuracy in each bin.
+
conf_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with average confidence in each bin.
+
variance_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with average variance in each bin. This array is currently not used but
+might be utilized in the future.
+
num_samples_hist (np.ndarray of shape (n_bins, [n_bins, [n_bins, [..]]])) – Histogram with number of samples in each bin.
+
+
+
Returns
+
+
tuple of length 6 (miscalibration score, miscalibration map, accuracy map, confidence map, variance map, num samples map)
Calculate the weighted mean on a given histogram based on a dedicated data distribution.
+If ‘reduce_result’ is given, reuse the data distribution of the previous result instead of the distribution
+given by ‘distribution’ parameter.
Plot Confidence Histogram and Reliability Diagram to visualize miscalibration.
On classification, plot the gaps between average confidence and observed accuracy bin-wise over the confidence
@@ -61,6 +61,8 @@
Reliability diagram to visualize miscalibration. This could be either in classical way for confidences only
or w.r.t. additional properties (like x/y-coordinates of detection boxes, width, height, etc.). The additional
-properties get binned. Afterwards, the ECE will be calculated for each bin. This is visualized as (multiple)
-2-D plots.
+properties get binned. Afterwards, the miscalibration will be calculated for each bin. This is
+visualized as a 2-D plots.
Parameters
-
X (iterable of np.ndarray, or np.ndarray of shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+
X (iterable of np.ndarray, or np.ndarray of shape=([n_bayes], n_samples, [n_classes/n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
1-D for binary classification, 2-D for multi class (softmax).
+If 3-D, interpret first dimension as samples from an Bayesian estimator with mulitple data points
+for a single sample (e.g. variational inference or MC dropout samples).
If this is an iterable over multiple instances of np.ndarray and parameter batched=True,
interpret this parameter as multiple predictions that should be averaged.
On detection, this array must have 2 dimensions with number of additional box features in last dim.
-
y (iterable of np.ndarray with same length as X or np.ndarray of shape=(n_samples, [n_classes])) – NumPy array with ground truth labels.
+
y (iterable of np.ndarray with same length as X or np.ndarray of shape=([n_bayes], n_samples, [n_classes])) – NumPy array with ground truth labels.
Either as label vector (1-D) or as one-hot encoded ground truth array (2-D).
+If 3-D, interpret first dimension as samples from an Bayesian estimator with mulitple data points
+for a single sample (e.g. variational inference or MC dropout samples).
If iterable over multiple instances of np.ndarray and parameter batched=True,
interpret this parameter as multiple predictions that should be averaged.
batched (bool, optional, default: False) – Multiple predictions can be evaluated at once (e.g. cross-validation examinations) using batched-mode.
All predictions given by X and y are separately evaluated and their results are averaged afterwards
for visualization.
+
uncertainty (str, optional, default: False) –
Define uncertainty handling if input X has been sampled e.g. by Monte-Carlo dropout or similar methods
+that output an ensemble of predictions per sample. Choose one of the following options:
+- flatten: treat everything as a separate prediction - this option will yield into a slightly better
+
+
calibration performance but without the visualization of a prediction interval.
+
+
+
+
mean: compute Monte-Carlo integration to obtain a simple confidence estimate for a sample
(mean) with a standard deviation that is visualized.
+
+
+
+
+
filename (str, optional, default: None) – Optional filename to save the plotted figure.
-
**save_args (args) – Additional arguments passed to ‘matplotlib.pyplot.Figure.savefig’ function.
+
tikz (bool, optional, default: False) – If True, use ‘tikzplotlib’ package to return tikz-code for Latex rather than a Matplotlib figure.
+
title_suffix (str, optional, default: None) – Suffix for plot title.
+
feature_names (list, optional, default: None) – Names of the additional features that are attached to the axes of a reliability diagram.
+
**save_args (args) – Additional arguments passed to ‘matplotlib.pyplot.Figure.savefig’ function if ‘tikz’ is False.
+If ‘tikz’ is True, the argument are passed to ‘tikzplotlib.get_tikz_code’ function.
Returns
Return type
-
matplotlib.pyplot.Figure
+
matplotlib.pyplot.Figure if ‘tikz’ is False else str with tikz code.
G. Pereyra, G. Tucker, J. Chorowski, Lukasz Kaiser, and G. Hinton:
+“Regularizing neural networks by penalizing confident output distributions.”
+CoRR, 2017.
+Get source online
Copies parameters and buffers from state_dict into only
+this module, but not its descendants. This is called on every submodule
+in load_state_dict(). Metadata saved for this
+module in input state_dict is provided as local_metadata.
+For state dicts without metadata, local_metadata is empty.
+Subclasses can achieve class-specific backward compatible loading using
+the version number at local_metadata.get(“version”, None).
+
+
Note
+
state_dict is not the same object as the input
+state_dict to load_state_dict(). So
+it can be modified.
+
+
+
Parameters
+
+
state_dict (dict) – a dict containing parameters and
+persistent buffers.
+
prefix (str) – the prefix for parameters and buffers used in this
+module
+
local_metadata (dict) – a dict containing the metadata for this module.
+See
+
strict (bool) – whether to strictly enforce that the keys in
+state_dict with prefix match the names of
+parameters and buffers in this module
+
missing_keys (list of str) – if strict=True, add missing keys to
+this list
+
unexpected_keys (list of str) – if strict=True, add unexpected
+keys to this list
+
error_msgs (list of str) – error messages should be added to this
+list, and will be reported together in
+load_state_dict()
These hooks will be called with arguments: state_dict, prefix,
+local_metadata, strict, missing_keys, unexpected_keys,
+error_msgs, before loading state_dict into self. These arguments
+are exactly the same as those of _load_from_state_dict.
These hooks will be called with arguments: self, state_dict,
+prefix, local_metadata, after the state_dict of self is set.
+Note that only parameters and buffers of self or its children are
+guaranteed to exist in state_dict. The hooks may modify state_dict
+inplace or return a new one.
Saves module state to destination dictionary, containing a state
+of the module, but not its descendants. This is called on every
+submodule in state_dict().
+
In rare cases, subclasses can achieve class-specific behavior by
+overriding this method with custom logic.
+
+
Parameters
+
+
destination (dict) – a dict where state will be stored
+
prefix (str) – the prefix for parameters and buffers used in this
+module
Applies fn recursively to every submodule (as returned by .children())
+as well as self. Typical use includes initializing the parameters of a model
+(see also nn-init-doc).
+
+
Parameters
+
fn (Module -> None) – function to be applied to each submodule
recurse (bool) – if True, then yields buffers of this module
+and all submodules. Otherwise, yields only buffers that
+are direct members of this module.
Moves all model parameters and buffers to the GPU.
+
This also makes associated parameters and buffers different objects. So
+it should be called before constructing optimizer if the module will
+live on GPU while being optimized.
+
+
Parameters
+
device (int, optional) – if specified, all parameters will be
+copied to that device
This has any effect only on certain modules. See documentations of
+particular modules for details of their behaviors in training/evaluation
+mode, if they are affected, e.g. Dropout, BatchNorm,
+etc.
To print customized extra information, you should reimplement
+this method in your own modules. Both single-line and multi-line
+strings are acceptable.
Copies parameters and buffers from state_dict into
+this module and its descendants. If strict is True, then
+the keys of state_dict must exactly match the keys returned
+by this module’s state_dict() function.
+
+
Parameters
+
+
state_dict (dict) – a dict containing parameters and
+persistent buffers.
+
strict (bool, optional) – whether to strictly enforce that the keys
+in state_dict match the keys returned by this module’s
+state_dict() function. Default: True
+
+
+
Returns
+
+
missing_keys is a list of str containing the missing keys
+
unexpected_keys is a list of str containing the unexpected keys
+
+
+
+
Return type
+
NamedTuple with missing_keys and unexpected_keys fields
Returns an iterator over module buffers, yielding both the
+name of the buffer as well as the buffer itself.
+
+
Parameters
+
+
prefix (str) – prefix to prepend to all buffer names.
+
recurse (bool) – if True, then yields buffers of this module
+and all submodules. Otherwise, yields only buffers that
+are direct members of this module.
+
+
+
Yields
+
(string, torch.Tensor) – Tuple containing the name and buffer
Returns an iterator over module parameters, yielding both the
+name of the parameter as well as the parameter itself.
+
+
Parameters
+
+
prefix (str) – prefix to prepend to all parameter names.
+
recurse (bool) – if True, then yields parameters of this module
+and all submodules. Otherwise, yields only parameters that
+are direct members of this module.
+
+
+
Yields
+
(string, Parameter) – Tuple containing the name and parameter
recurse (bool) – if True, then yields parameters of this module
+and all submodules. Otherwise, yields only parameters that
+are direct members of this module.
The grad_input and grad_output may be tuples if the
+module has multiple inputs or outputs. The hook should not modify its
+arguments, but it can optionally return a new gradient with respect to
+input that will be used in place of grad_input in subsequent
+computations.
+
+
Returns
+
a handle that can be used to remove the added hook by calling
+handle.remove()
+
+
Return type
+
torch.utils.hooks.RemovableHandle
+
+
+
+
Warning
+
The current implementation will not have the presented behavior
+for complex Module that perform many operations.
+In some failure cases, grad_input and grad_output will only
+contain the gradients for a subset of the inputs and outputs.
+For such Module, you should use torch.Tensor.register_hook()
+directly on a specific input or output to get the required gradients.
This is typically used to register a buffer that should not to be
+considered a model parameter. For example, BatchNorm’s running_mean
+is not a parameter, but is part of the persistent state.
+
Buffers can be accessed as attributes using given names.
+
+
Parameters
+
+
name (string) – name of the buffer. The buffer can be accessed
+from this module using the given name
The hook will be called every time after forward() has computed an output.
+It should have the following signature:
+
hook(module,input,output)->Noneormodifiedoutput
+
+
+
The hook can modify the output. It can modify the input inplace but
+it will not have effect on forward since this is called after
+forward() is called.
+
+
Returns
+
a handle that can be used to remove the added hook by calling
+handle.remove()
The hook will be called every time before forward() is invoked.
+It should have the following signature:
+
hook(module,input)->Noneormodifiedinput
+
+
+
The hook can modify the input. User can either return a tuple or a
+single modified value in the hook. We will wrap the value into a tuple
+if a single value is returned(unless that value is already a tuple).
+
+
Returns
+
a handle that can be used to remove the added hook by calling
+handle.remove()
Its signature is similar to torch.Tensor.to(), but only accepts
+floating point desired dtype s. In addition, this method will
+only cast the floating point parameters and buffers to dtype
+(if given). The integral parameters and buffers will be moved
+device, if that is given, but with dtypes unchanged. When
+non_blocking is set, it tries to convert/move asynchronously
+with respect to the host if possible, e.g., moving CPU Tensors with
+pinned memory to CUDA devices.
+
See below for examples.
+
+
Note
+
This method modifies the module in-place.
+
+
+
Parameters
+
+
device (torch.device) – the desired device of the parameters
+and buffers in this module
+
dtype (torch.dtype) – the desired floating point type of
+the floating point parameters and buffers in this module
+
tensor (torch.Tensor) – Tensor whose dtype and device are the desired
+dtype and device for all parameters and buffers in this module
+
memory_format (torch.memory_format) – the desired memory
+format for 4D parameters and buffers in this module (keyword
+only argument)
This has any effect only on certain modules. See documentations of
+particular modules for details of their behaviors in training/evaluation
+mode, if they are affected, e.g. Dropout, BatchNorm,
+etc.
+
+
Parameters
+
mode (bool) – whether to set training mode (True) or evaluation
+mode (False). Default: True.
Difference between Confidence and Accuracy (DCA) 1. This regularization returns a single scalar indicating
+the difference between mean confidence and accuracy within a single batch.
Liang, Gongbo, et al.:
+“Improved trainable calibration method for neural networks on medical imaging classification.”
+arXiv preprint arXiv:2009.04057 (2020).
Copies parameters and buffers from state_dict into only
+this module, but not its descendants. This is called on every submodule
+in load_state_dict(). Metadata saved for this
+module in input state_dict is provided as local_metadata.
+For state dicts without metadata, local_metadata is empty.
+Subclasses can achieve class-specific backward compatible loading using
+the version number at local_metadata.get(“version”, None).
+
+
Note
+
state_dict is not the same object as the input
+state_dict to load_state_dict(). So
+it can be modified.
+
+
+
Parameters
+
+
state_dict (dict) – a dict containing parameters and
+persistent buffers.
+
prefix (str) – the prefix for parameters and buffers used in this
+module
+
local_metadata (dict) – a dict containing the metadata for this module.
+See
+
strict (bool) – whether to strictly enforce that the keys in
+state_dict with prefix match the names of
+parameters and buffers in this module
+
missing_keys (list of str) – if strict=True, add missing keys to
+this list
+
unexpected_keys (list of str) – if strict=True, add unexpected
+keys to this list
+
error_msgs (list of str) – error messages should be added to this
+list, and will be reported together in
+load_state_dict()
These hooks will be called with arguments: state_dict, prefix,
+local_metadata, strict, missing_keys, unexpected_keys,
+error_msgs, before loading state_dict into self. These arguments
+are exactly the same as those of _load_from_state_dict.
These hooks will be called with arguments: self, state_dict,
+prefix, local_metadata, after the state_dict of self is set.
+Note that only parameters and buffers of self or its children are
+guaranteed to exist in state_dict. The hooks may modify state_dict
+inplace or return a new one.
Saves module state to destination dictionary, containing a state
+of the module, but not its descendants. This is called on every
+submodule in state_dict().
+
In rare cases, subclasses can achieve class-specific behavior by
+overriding this method with custom logic.
+
+
Parameters
+
+
destination (dict) – a dict where state will be stored
+
prefix (str) – the prefix for parameters and buffers used in this
+module
Applies fn recursively to every submodule (as returned by .children())
+as well as self. Typical use includes initializing the parameters of a model
+(see also nn-init-doc).
+
+
Parameters
+
fn (Module -> None) – function to be applied to each submodule
recurse (bool) – if True, then yields buffers of this module
+and all submodules. Otherwise, yields only buffers that
+are direct members of this module.
Moves all model parameters and buffers to the GPU.
+
This also makes associated parameters and buffers different objects. So
+it should be called before constructing optimizer if the module will
+live on GPU while being optimized.
+
+
Parameters
+
device (int, optional) – if specified, all parameters will be
+copied to that device
This has any effect only on certain modules. See documentations of
+particular modules for details of their behaviors in training/evaluation
+mode, if they are affected, e.g. Dropout, BatchNorm,
+etc.
To print customized extra information, you should reimplement
+this method in your own modules. Both single-line and multi-line
+strings are acceptable.
Copies parameters and buffers from state_dict into
+this module and its descendants. If strict is True, then
+the keys of state_dict must exactly match the keys returned
+by this module’s state_dict() function.
+
+
Parameters
+
+
state_dict (dict) – a dict containing parameters and
+persistent buffers.
+
strict (bool, optional) – whether to strictly enforce that the keys
+in state_dict match the keys returned by this module’s
+state_dict() function. Default: True
+
+
+
Returns
+
+
missing_keys is a list of str containing the missing keys
+
unexpected_keys is a list of str containing the unexpected keys
+
+
+
+
Return type
+
NamedTuple with missing_keys and unexpected_keys fields
Returns an iterator over module buffers, yielding both the
+name of the buffer as well as the buffer itself.
+
+
Parameters
+
+
prefix (str) – prefix to prepend to all buffer names.
+
recurse (bool) – if True, then yields buffers of this module
+and all submodules. Otherwise, yields only buffers that
+are direct members of this module.
+
+
+
Yields
+
(string, torch.Tensor) – Tuple containing the name and buffer
Returns an iterator over module parameters, yielding both the
+name of the parameter as well as the parameter itself.
+
+
Parameters
+
+
prefix (str) – prefix to prepend to all parameter names.
+
recurse (bool) – if True, then yields parameters of this module
+and all submodules. Otherwise, yields only parameters that
+are direct members of this module.
+
+
+
Yields
+
(string, Parameter) – Tuple containing the name and parameter
recurse (bool) – if True, then yields parameters of this module
+and all submodules. Otherwise, yields only parameters that
+are direct members of this module.
The grad_input and grad_output may be tuples if the
+module has multiple inputs or outputs. The hook should not modify its
+arguments, but it can optionally return a new gradient with respect to
+input that will be used in place of grad_input in subsequent
+computations.
+
+
Returns
+
a handle that can be used to remove the added hook by calling
+handle.remove()
+
+
Return type
+
torch.utils.hooks.RemovableHandle
+
+
+
+
Warning
+
The current implementation will not have the presented behavior
+for complex Module that perform many operations.
+In some failure cases, grad_input and grad_output will only
+contain the gradients for a subset of the inputs and outputs.
+For such Module, you should use torch.Tensor.register_hook()
+directly on a specific input or output to get the required gradients.
This is typically used to register a buffer that should not to be
+considered a model parameter. For example, BatchNorm’s running_mean
+is not a parameter, but is part of the persistent state.
+
Buffers can be accessed as attributes using given names.
+
+
Parameters
+
+
name (string) – name of the buffer. The buffer can be accessed
+from this module using the given name
The hook will be called every time after forward() has computed an output.
+It should have the following signature:
+
hook(module,input,output)->Noneormodifiedoutput
+
+
+
The hook can modify the output. It can modify the input inplace but
+it will not have effect on forward since this is called after
+forward() is called.
+
+
Returns
+
a handle that can be used to remove the added hook by calling
+handle.remove()
The hook will be called every time before forward() is invoked.
+It should have the following signature:
+
hook(module,input)->Noneormodifiedinput
+
+
+
The hook can modify the input. User can either return a tuple or a
+single modified value in the hook. We will wrap the value into a tuple
+if a single value is returned(unless that value is already a tuple).
+
+
Returns
+
a handle that can be used to remove the added hook by calling
+handle.remove()
Its signature is similar to torch.Tensor.to(), but only accepts
+floating point desired dtype s. In addition, this method will
+only cast the floating point parameters and buffers to dtype
+(if given). The integral parameters and buffers will be moved
+device, if that is given, but with dtypes unchanged. When
+non_blocking is set, it tries to convert/move asynchronously
+with respect to the host if possible, e.g., moving CPU Tensors with
+pinned memory to CUDA devices.
+
See below for examples.
+
+
Note
+
This method modifies the module in-place.
+
+
+
Parameters
+
+
device (torch.device) – the desired device of the parameters
+and buffers in this module
+
dtype (torch.dtype) – the desired floating point type of
+the floating point parameters and buffers in this module
+
tensor (torch.Tensor) – Tensor whose dtype and device are the desired
+dtype and device for all parameters and buffers in this module
+
memory_format (torch.memory_format) – the desired memory
+format for 4D parameters and buffers in this module (keyword
+only argument)
This has any effect only on certain modules. See documentations of
+particular modules for details of their behaviors in training/evaluation
+mode, if they are affected, e.g. Dropout, BatchNorm,
+etc.
+
+
Parameters
+
mode (bool) – whether to set training mode (True) or evaluation
+mode (False). Default: True.
Copies parameters and buffers from state_dict into only
+this module, but not its descendants. This is called on every submodule
+in load_state_dict(). Metadata saved for this
+module in input state_dict is provided as local_metadata.
+For state dicts without metadata, local_metadata is empty.
+Subclasses can achieve class-specific backward compatible loading using
+the version number at local_metadata.get(“version”, None).
+
+
Note
+
state_dict is not the same object as the input
+state_dict to load_state_dict(). So
+it can be modified.
+
+
+
Parameters
+
+
state_dict (dict) – a dict containing parameters and
+persistent buffers.
+
prefix (str) – the prefix for parameters and buffers used in this
+module
+
local_metadata (dict) – a dict containing the metadata for this module.
+See
+
strict (bool) – whether to strictly enforce that the keys in
+state_dict with prefix match the names of
+parameters and buffers in this module
+
missing_keys (list of str) – if strict=True, add missing keys to
+this list
+
unexpected_keys (list of str) – if strict=True, add unexpected
+keys to this list
+
error_msgs (list of str) – error messages should be added to this
+list, and will be reported together in
+load_state_dict()
These hooks will be called with arguments: state_dict, prefix,
+local_metadata, strict, missing_keys, unexpected_keys,
+error_msgs, before loading state_dict into self. These arguments
+are exactly the same as those of _load_from_state_dict.
These hooks will be called with arguments: self, state_dict,
+prefix, local_metadata, after the state_dict of self is set.
+Note that only parameters and buffers of self or its children are
+guaranteed to exist in state_dict. The hooks may modify state_dict
+inplace or return a new one.
Saves module state to destination dictionary, containing a state
+of the module, but not its descendants. This is called on every
+submodule in state_dict().
+
In rare cases, subclasses can achieve class-specific behavior by
+overriding this method with custom logic.
+
+
Parameters
+
+
destination (dict) – a dict where state will be stored
+
prefix (str) – the prefix for parameters and buffers used in this
+module
Applies fn recursively to every submodule (as returned by .children())
+as well as self. Typical use includes initializing the parameters of a model
+(see also nn-init-doc).
+
+
Parameters
+
fn (Module -> None) – function to be applied to each submodule
recurse (bool) – if True, then yields buffers of this module
+and all submodules. Otherwise, yields only buffers that
+are direct members of this module.
Moves all model parameters and buffers to the GPU.
+
This also makes associated parameters and buffers different objects. So
+it should be called before constructing optimizer if the module will
+live on GPU while being optimized.
+
+
Parameters
+
device (int, optional) – if specified, all parameters will be
+copied to that device
This has any effect only on certain modules. See documentations of
+particular modules for details of their behaviors in training/evaluation
+mode, if they are affected, e.g. Dropout, BatchNorm,
+etc.
To print customized extra information, you should reimplement
+this method in your own modules. Both single-line and multi-line
+strings are acceptable.
Copies parameters and buffers from state_dict into
+this module and its descendants. If strict is True, then
+the keys of state_dict must exactly match the keys returned
+by this module’s state_dict() function.
+
+
Parameters
+
+
state_dict (dict) – a dict containing parameters and
+persistent buffers.
+
strict (bool, optional) – whether to strictly enforce that the keys
+in state_dict match the keys returned by this module’s
+state_dict() function. Default: True
+
+
+
Returns
+
+
missing_keys is a list of str containing the missing keys
+
unexpected_keys is a list of str containing the unexpected keys
+
+
+
+
Return type
+
NamedTuple with missing_keys and unexpected_keys fields
Returns an iterator over module buffers, yielding both the
+name of the buffer as well as the buffer itself.
+
+
Parameters
+
+
prefix (str) – prefix to prepend to all buffer names.
+
recurse (bool) – if True, then yields buffers of this module
+and all submodules. Otherwise, yields only buffers that
+are direct members of this module.
+
+
+
Yields
+
(string, torch.Tensor) – Tuple containing the name and buffer
Returns an iterator over module parameters, yielding both the
+name of the parameter as well as the parameter itself.
+
+
Parameters
+
+
prefix (str) – prefix to prepend to all parameter names.
+
recurse (bool) – if True, then yields parameters of this module
+and all submodules. Otherwise, yields only parameters that
+are direct members of this module.
+
+
+
Yields
+
(string, Parameter) – Tuple containing the name and parameter
recurse (bool) – if True, then yields parameters of this module
+and all submodules. Otherwise, yields only parameters that
+are direct members of this module.
The grad_input and grad_output may be tuples if the
+module has multiple inputs or outputs. The hook should not modify its
+arguments, but it can optionally return a new gradient with respect to
+input that will be used in place of grad_input in subsequent
+computations.
+
+
Returns
+
a handle that can be used to remove the added hook by calling
+handle.remove()
+
+
Return type
+
torch.utils.hooks.RemovableHandle
+
+
+
+
Warning
+
The current implementation will not have the presented behavior
+for complex Module that perform many operations.
+In some failure cases, grad_input and grad_output will only
+contain the gradients for a subset of the inputs and outputs.
+For such Module, you should use torch.Tensor.register_hook()
+directly on a specific input or output to get the required gradients.
This is typically used to register a buffer that should not to be
+considered a model parameter. For example, BatchNorm’s running_mean
+is not a parameter, but is part of the persistent state.
+
Buffers can be accessed as attributes using given names.
+
+
Parameters
+
+
name (string) – name of the buffer. The buffer can be accessed
+from this module using the given name
The hook will be called every time after forward() has computed an output.
+It should have the following signature:
+
hook(module,input,output)->Noneormodifiedoutput
+
+
+
The hook can modify the output. It can modify the input inplace but
+it will not have effect on forward since this is called after
+forward() is called.
+
+
Returns
+
a handle that can be used to remove the added hook by calling
+handle.remove()
The hook will be called every time before forward() is invoked.
+It should have the following signature:
+
hook(module,input)->Noneormodifiedinput
+
+
+
The hook can modify the input. User can either return a tuple or a
+single modified value in the hook. We will wrap the value into a tuple
+if a single value is returned(unless that value is already a tuple).
+
+
Returns
+
a handle that can be used to remove the added hook by calling
+handle.remove()
Its signature is similar to torch.Tensor.to(), but only accepts
+floating point desired dtype s. In addition, this method will
+only cast the floating point parameters and buffers to dtype
+(if given). The integral parameters and buffers will be moved
+device, if that is given, but with dtypes unchanged. When
+non_blocking is set, it tries to convert/move asynchronously
+with respect to the host if possible, e.g., moving CPU Tensors with
+pinned memory to CUDA devices.
+
See below for examples.
+
+
Note
+
This method modifies the module in-place.
+
+
+
Parameters
+
+
device (torch.device) – the desired device of the parameters
+and buffers in this module
+
dtype (torch.dtype) – the desired floating point type of
+the floating point parameters and buffers in this module
+
tensor (torch.Tensor) – Tensor whose dtype and device are the desired
+dtype and device for all parameters and buffers in this module
+
memory_format (torch.memory_format) – the desired memory
+format for 4D parameters and buffers in this module (keyword
+only argument)
This has any effect only on certain modules. See documentations of
+particular modules for details of their behaviors in training/evaluation
+mode, if they are affected, e.g. Dropout, BatchNorm,
+etc.
+
+
Parameters
+
mode (bool) – whether to set training mode (True) or evaluation
+mode (False). Default: True.
Abstract class for all calibration methods that base on logistic regression. We extended common
+scaling calibration methods by Bayesian epistemic uncertainty modelling 1.
+On the one hand, this class supports Maximum Likelihood (MLE) estimates without uncertainty.
+This method is commonly solved by negative log likelihood optimization given by
with samples \(X\), label \(y\), weights \(\theta\) and likelihood \(p(y|X, \theta)\).
+See the implementations of the methods for more details.
+
On the other hand, methods to obtain uncertainty in calibration are currently Variational Inference (VI) and
+Markov-Chain Monte-Carlo (MCMC) sampling. Instead of estimating the weights \(\theta\) of the logistic
+regression directly, we place a probability distribution over the weights by
Since the marginal likelihood cannot be evaluated analytically for logistic regression, we need to approximate the
+posterior by either MCMC sampling or Variational Inference. Using several techniques, we sample multiple times from
+the posterior in order to get multiple related calibration results with a mean and a deviation for each sample.
+
MCMC sampling allows the sampling of a posterior without knowing the marginal likelihood. This method is unbiased
+but computational expensive. In contrast, Variational Inference defines an easy variational
+distribution \(q_\Phi(\theta)\) (e.g. a normal distribution) for each weight parametrized by \(\Phi\).
+The optimization objective is then the minimization of the Kullback-Leibler divergence between the
+variational distribution \(q_\Phi(\theta))\) and the true posterior \(p(\theta | X, y)\).
+This can be solved using the ELBO method 2. Variational Inference is faster than MCMC but also biased.
+
+
Parameters
+
+
method (str, default: "mle") – Method that is used to obtain a calibration mapping:
+- ‘mle’: Maximum likelihood estimate without uncertainty using a convex optimizer.
+- ‘momentum’: MLE estimate using Momentum optimizer for non-convex optimization.
+- ‘variational’: Variational Inference with uncertainty.
+- ‘mcmc’: Markov-Chain Monte-Carlo sampling with uncertainty.
+
momentum_epochs (int, optional, default: 1000) – Number of epochs used by momentum optimizer.
+
mcmc_steps (int, optional, default: 20) – Number of weight samples obtained by MCMC sampling.
+
mcmc_chains (int, optional, default: 1) – Number of Markov-chains used in parallel for MCMC sampling (this will result
+in mcmc_steps * mcmc_chains samples).
+
mcmc_warmup_steps (int, optional, default: 100) – Warmup steps used for MCMC sampling.
+
vi_epochs (int, optional, default: 1000) – Number of epochs used for ELBO optimization.
+
detection (bool, default: False) – If False, the input array ‘X’ is treated as multi-class confidence input (softmax)
+with shape (n_samples, [n_classes]).
+If True, the input array ‘X’ is treated as a box predictions with several box features (at least
+box confidence must be present) with shape (n_samples, [n_box_features]).
+
independent_probabilities (bool, optional, default: False) – Boolean for multi class probabilities.
+If set to True, the probability estimates for each
+class are treated as independent of each other (sigmoid).
+
use_cuda (str or bool, optional, default: False) – Specify if CUDA should be used. If str, you can also specify the device
+number like ‘cuda:0’, etc.
Michael I Jordan, Zoubin Ghahramani, Tommi S Jaakkola, and Lawrence K Saul:
+“An introduction to variational methods for graphical models.” Machine learning, 37(2): 183–233, 1999.
+
+
+
Methods
+
+
+
+
+
+
+
__init__([method, momentum_epochs, …])
+
Create an instance of AbstractLogisticRegression.
+
+
clear()
+
Clear model parameters.
+
+
convex(data, y, tensorboard, log_dir)
+
Convex optimization to find the global optimum of current parameter search.
+
+
fit(X, y[, random_state, tensorboard, log_dir])
+
Build logitic calibration model either conventional with single MLE estimate or with Variational Inference (VI) or Markov-Chain Monte-Carlo (MCMC) algorithm to also obtain uncertainty estimates.
+
+
fit_transform(X[, y])
+
Fit to data, then transform it.
+
+
get_params([deep])
+
Get parameters for this estimator.
+
+
guide([X, y])
+
Variational substitution definition for each parameter.
+
+
load_model(filename)
+
Load model from saved torch dump.
+
+
mask()
+
Seek for all relevant weights whose values are negative.
+
+
mcmc(data, y, tensorboard, log_dir)
+
Perform Markov-Chain Monte-Carlo sampling on the (unknown) posterior.
+
+
model([X, y])
+
Definition of the log regression model.
+
+
momentum(data, y, tensorboard, log_dir)
+
Momentum optimization to find the global optimum of current parameter search.
+
+
prepare(X)
+
Preprocessing of input data before called at the beginning of the fit-function.
+
+
prior()
+
Prior definition of the weights and intercept used for log regression.
+
+
save_model(filename)
+
Save model instance as with torch’s save function as this is safer for torch tensors.
+
+
set_params(**params)
+
Set the parameters of this estimator.
+
+
squeeze_generic(a, axes_to_keep)
+
Squeeze input array a but keep axes defined by parameter ‘axes_to_keep’ even if the dimension is of size 1.
+
+
to(device)
+
Set distribution parameters to the desired device in order to compute either on CPU or GPU.
+
+
transform(X[, num_samples, random_state, …])
+
After model calibration, this function is used to get calibrated outputs of uncalibrated confidence estimates.
Build logitic calibration model either conventional with single MLE estimate or with
+Variational Inference (VI) or Markov-Chain Monte-Carlo (MCMC) algorithm to also obtain uncertainty estimates.
+
+
Parameters
+
+
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+1-D for binary classification, 2-D for multi class (softmax).
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
+
y (np.ndarray, shape=(n_samples, [n_classes])) – NumPy array with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D).
+
random_state (int, optional, default: None) – Fix the random seed for the random number
Variational substitution definition for each parameter. The signature is the same as for the
+“self.model” function but the variables are not used.
+
+
Parameters
+
+
X (torch.Tensor, shape=(n_samples, n_log_regression_features)) – Input data that has been prepared by “self.prepare” function call.
+
y (torch.Tensor, shape=(n_samples, [n_classes])) – Torch tensor with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D) (for multiclass MLE only).
Seek for all relevant weights whose values are negative. Mask those values with optimization constraints
+in the interval [0, 0].
+Constraints on the intercepts might also be set.
+
+
Returns
+
Indices of masked values and list of boundary constraints for optimization.
X (torch.Tensor, shape=(n_samples, n_log_regression_features)) – Input data that has been prepared by “self.prepare” function call.
+
y (torch.Tensor, shape=(n_samples, [n_classes])) – Torch tensor with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D) (for multiclass MLE only).
Momentum optimization to find the global optimum of current parameter search.
+This method is slow but tends to find the global optimum for non-convex optimization.
+
+
Parameters
+
+
data_input (np.ndarray, shape=(n_samples, n_features)) – NumPy 2-D array with data input.
+
y (np.ndarray, shape=(n_samples,)) – NumPy array with ground truth labels as 1-D vector (binary).
Preprocessing of input data before called at the beginning of the fit-function.
+
+
Parameters
+
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+1-D for binary classification, 2-D for multi class (softmax).
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
The method works on simple estimators as well as on nested objects
+(such as pipelines). The latter have parameters of the form
+<component>__<parameter> so that it’s possible to update each
+component of a nested object.
Set distribution parameters to the desired device in order to compute either on CPU or GPU.
+
+
+
+
+transform(X: numpy.ndarray, num_samples: int = 1000, random_state: int = None, mean_estimate: bool = False) → numpy.ndarray¶
+
After model calibration, this function is used to get calibrated outputs of uncalibrated
+confidence estimates.
+
+
Parameters
+
+
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+1-D for binary classification, 2-D for multi class (softmax).
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
+
num_samples (int, optional, default: 1000) – Number of samples generated on MCMC sampling or Variational Inference.
+
random_state (int, optional, default: None) – Fix the random seed for the random number
+
mean_estimate (bool, optional, default: False) – If True, directly return the mean on probabilistic methods like MCMC or VI instead of the full
+distribution. This parameter has no effect on MLE.
+
+
+
Returns
+
+
np.ndarray, shape=(n_samples, [n_classes]) on MLE or on MCMC/VI if ‘mean_estimate’ is True
+
or shape=(n_parameters, n_samples, [n_classes]) on VI, MCMC if ‘mean_estimate’ is False – On MLE without uncertainty, return NumPy array with calibrated confidence estimates.
+1-D for binary classification, 2-D for multi class (softmax).
+On VI or MCMC, return NumPy array with leading dimension as the number of sampled parameters from the
+log regression parameter distribution obtained by VI or MCMC.
On classification, apply the beta calibration method to obtain a calibration mapping. The original method was
proposed by 1.
For the multiclass case, we extended this method to work with multinomial logistic regression instead of a
@@ -58,7 +58,8 @@
netcal.scaling.BetaCalibration2. This calibration scheme
assumes independence between all variables.
-
It is necessary to provide all data in input parameter X as an NumPy array of shape (n_samples,n_features),
+
On detection, it is necessary to provide all data in input parameter X as an NumPy array
+of shape (n_samples,n_features),
whereas the confidence must be the first feature given in the input array. The ground-truth samples y
must be an array of shape (n_samples,) consisting of binary labels \(y \in \{0, 1\}\). Those
labels indicate if the according sample has matched a ground truth box \(\text{m}=1\) or is a false
@@ -97,7 +98,17 @@
Convex optimization to find the global optimum of current parameter search.
+
+
fit(X, y[, random_state, tensorboard, log_dir])
+
Build logitic calibration model either conventional with single MLE estimate or with Variational Inference (VI) or Markov-Chain Monte-Carlo (MCMC) algorithm to also obtain uncertainty estimates.
-
fit_transform(X[, y])
+
fit_transform(X[, y])
Fit to data, then transform it.
-
get_params([deep])
+
get_params([deep])
Get parameters for this estimator.
+
guide([X, y])
+
Variational substitution definition for each parameter.
+
load_model(filename)
-
Load model from saved Pickle instance.
+
Load model from saved torch dump.
+
+
mask()
+
Seek for all relevant weights whose values are negative.
+
+
mcmc(data, y, tensorboard, log_dir)
+
Perform Markov-Chain Monte-Carlo sampling on the (unknown) posterior.
+
+
model([X, y])
+
Definition of the log regression model.
+
+
momentum(data, y, tensorboard, log_dir)
+
Momentum optimization to find the global optimum of current parameter search.
+
+
prepare(X)
+
Preprocessing of input data before called at the beginning of the fit-function.
+
+
prior()
+
Prior definition of the weights used for log regression.
save_model(filename)
-
Save model instance as Pickle Object.
+
Save model instance as with torch’s save function as this is safer for torch tensors.
set_params(**params)
Set the parameters of this estimator.
@@ -156,9 +198,15 @@
netcal.scaling.BetaCalibration
squeeze_generic(a, axes_to_keep)
Squeeze input array a but keep axes defined by parameter ‘axes_to_keep’ even if the dimension is of size 1.
-
transform(X)
+
to(device)
+
Set distribution parameters to the desired device in order to compute either on CPU or GPU.
+
+
transform(X[, num_samples, random_state, …])
After model calibration, this function is used to get calibrated outputs of uncalibrated confidence estimates.
Build logitic calibration model either conventional with single MLE estimate or with
+Variational Inference (VI) or Markov-Chain Monte-Carlo (MCMC) algorithm to also obtain uncertainty estimates.
Variational substitution definition for each parameter. The signature is the same as for the
+“self.model” function but the variables are not used.
+
+
Parameters
+
+
X (torch.Tensor, shape=(n_samples, n_log_regression_features)) – Input data that has been prepared by “self.prepare” function call.
+
y (torch.Tensor, shape=(n_samples, [n_classes])) – Torch tensor with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D) (for multiclass MLE only).
X (torch.Tensor, shape=(n_samples, n_log_regression_features)) – Input data that has been prepared by “self.prepare” function call.
+
y (torch.Tensor, shape=(n_samples, [n_classes])) – Torch tensor with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D) (for multiclass MLE only).
Momentum optimization to find the global optimum of current parameter search.
+This method is slow but tends to find the global optimum for non-convex optimization.
+
+
Parameters
+
+
data_input (np.ndarray, shape=(n_samples, n_features)) – NumPy 2-D array with data input.
+
y (np.ndarray, shape=(n_samples,)) – NumPy array with ground truth labels as 1-D vector (binary).
Preprocessing of input data before called at the beginning of the fit-function.
+
+
Parameters
+
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+1-D for binary classification, 2-D for multi class (softmax).
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
Prior definition of the weights used for log regression. This function has to set the
+variables ‘self.weight_prior_dist’, ‘self.weight_mean_init’ and ‘self.weight_stddev_init’.
+transform(X: numpy.ndarray, num_samples: int = 1000, random_state: int = None, mean_estimate: bool = False) → numpy.ndarray¶
After model calibration, this function is used to get calibrated outputs of uncalibrated
confidence estimates.
Parameters
-
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+
+
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
1-D for binary classification, 2-D for multi class (softmax).
-On detection, this array must have 2 dimensions with number of additional box features in last dim.
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
+
num_samples (int, optional, default: 1000) – Number of samples generated on MCMC sampling or Variational Inference.
+
random_state (int, optional, default: None) – Fix the random seed for the random number
+
mean_estimate (bool, optional, default: False) – If True, directly return the mean on probabilistic methods like MCMC or VI instead of the full
+distribution. This parameter has no effect on MLE.
+
Returns
-
NumPy array with calibrated confidence estimates.
-1-D for binary classification, 2-D for multi class (softmax).
+
+
np.ndarray, shape=(n_samples, [n_classes]) on MLE or on MCMC/VI if ‘mean_estimate’ is True
+
or shape=(n_parameters, n_samples, [n_classes]) on VI, MCMC if ‘mean_estimate’ is False – On MLE without uncertainty, return NumPy array with calibrated confidence estimates.
+1-D for binary classification, 2-D for multi class (softmax).
+On VI or MCMC, return NumPy array with leading dimension as the number of sampled parameters from the
+log regression parameter distribution obtained by VI or MCMC.
This calibration method uses a multivariate variant of a Beta distribution to obtain a
calibration mapping by means of the confidence as well as additional features. This method is originally
proposed by 1. This calibration scheme
@@ -102,13 +102,22 @@
Build dependent Beta Calibration model for multivariate Beta distributions.
+
convex(data, y, tensorboard, log_dir)
+
Convex optimization to find the global optimum of current parameter search.
+
+
fit(X, y[, random_state, tensorboard, log_dir])
+
Build logitic calibration model either conventional with single MLE estimate or with Variational Inference (VI) or Markov-Chain Monte-Carlo (MCMC) algorithm to also obtain uncertainty estimates.
-
fit_transform(X[, y])
+
fit_transform(X[, y])
Fit to data, then transform it.
-
get_params([deep])
+
get_params([deep])
Get parameters for this estimator.
+
guide([X, y])
+
Variational substitution definition for each parameter.
+
load_model(filename)
-
Load model from saved Pickle instance.
+
Load model from saved torch dump.
+
+
mask()
+
Seek for all relevant weights whose values are negative.
+
+
mcmc(data, y, tensorboard, log_dir)
+
Perform Markov-Chain Monte-Carlo sampling on the (unknown) posterior.
+
+
model([X, y])
+
Definition of the log regression model.
+
+
momentum(data, y, tensorboard, log_dir)
+
Momentum optimization to find the global optimum of current parameter search.
+
+
prepare(X)
+
Preprocessing of input data before called at the beginning of the fit-function.
+
+
prior()
+
Prior definition of the weights used for log regression.
save_model(filename)
-
Save model instance as Pickle Object.
+
Save model instance as with torch’s save function as this is safer for torch tensors.
set_params(**params)
Set the parameters of this estimator.
@@ -159,21 +197,54 @@
netcal.scaling.BetaCalibrationDependent
squeeze_generic(a, axes_to_keep)
Squeeze input array a but keep axes defined by parameter ‘axes_to_keep’ even if the dimension is of size 1.
-
transform(X)
+
to(device)
+
Set distribution parameters to the desired device in order to compute either on CPU or GPU.
+
+
transform(X[, num_samples, random_state, …])
After model calibration, this function is used to get calibrated outputs of uncalibrated confidence estimates.
Build logitic calibration model either conventional with single MLE estimate or with
+Variational Inference (VI) or Markov-Chain Monte-Carlo (MCMC) algorithm to also obtain uncertainty estimates.
Variational substitution definition for each parameter. The signature is the same as for the
+“self.model” function but the variables are not used.
+
+
Parameters
+
+
X (torch.Tensor, shape=(n_samples, n_log_regression_features)) – Input data that has been prepared by “self.prepare” function call.
+
y (torch.Tensor, shape=(n_samples, [n_classes])) – Torch tensor with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D) (for multiclass MLE only).
Seek for all relevant weights whose values are negative. Mask those values with optimization constraints
+in the interval [0, 0].
+Constraints on the intercepts might also be set.
+
+
Returns
+
Indices of masked values and list of boundary constraints for optimization.
X (torch.Tensor, shape=(n_samples, n_log_regression_features)) – Input data that has been prepared by “self.prepare” function call.
+
y (torch.Tensor, shape=(n_samples, [n_classes])) – Torch tensor with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D) (for multiclass MLE only).
Momentum optimization to find the global optimum of current parameter search.
+This method is slow but tends to find the global optimum for non-convex optimization.
+
+
Parameters
+
+
data_input (np.ndarray, shape=(n_samples, n_features)) – NumPy 2-D array with data input.
+
y (np.ndarray, shape=(n_samples,)) – NumPy array with ground truth labels as 1-D vector (binary).
Preprocessing of input data before called at the beginning of the fit-function.
+
+
Parameters
+
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+1-D for binary classification, 2-D for multi class (softmax).
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
Prior definition of the weights used for log regression. This function has to set the
+variables ‘self.weight_prior_dist’, ‘self.weight_mean_init’ and ‘self.weight_stddev_init’.
+transform(X: numpy.ndarray, num_samples: int = 1000, random_state: int = None, mean_estimate: bool = False) → numpy.ndarray¶
After model calibration, this function is used to get calibrated outputs of uncalibrated
confidence estimates.
Parameters
-
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+
+
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
1-D for binary classification, 2-D for multi class (softmax).
-On detection, this array must have 2 dimensions with number of additional box features in last dim.
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
+
num_samples (int, optional, default: 1000) – Number of samples generated on MCMC sampling or Variational Inference.
+
random_state (int, optional, default: None) – Fix the random seed for the random number
+
mean_estimate (bool, optional, default: False) – If True, directly return the mean on probabilistic methods like MCMC or VI instead of the full
+distribution. This parameter has no effect on MLE.
+
Returns
-
NumPy array with calibrated confidence estimates.
-1-D for binary classification, 2-D for multi class (softmax).
+
+
np.ndarray, shape=(n_samples, [n_classes]) on MLE or on MCMC/VI if ‘mean_estimate’ is True
+
or shape=(n_parameters, n_samples, [n_classes]) on VI, MCMC if ‘mean_estimate’ is False – On MLE without uncertainty, return NumPy array with calibrated confidence estimates.
+1-D for binary classification, 2-D for multi class (softmax).
+On VI or MCMC, return NumPy array with leading dimension as the number of sampled parameters from the
+log regression parameter distribution obtained by VI or MCMC.
On classification, apply the logistic calibration method aka Platt scaling to obtain a
calibration mapping. This method is originally proposed by 1.
For the multiclass case, we use the Vector scaling proposed in 2.
@@ -93,6 +93,17 @@
Convex optimization to find the global optimum of current parameter search.
+
+
fit(X, y[, random_state, tensorboard, log_dir])
+
Build logitic calibration model either conventional with single MLE estimate or with Variational Inference (VI) or Markov-Chain Monte-Carlo (MCMC) algorithm to also obtain uncertainty estimates.
-
fit_transform(X[, y])
+
fit_transform(X[, y])
Fit to data, then transform it.
-
get_params([deep])
+
get_params([deep])
Get parameters for this estimator.
+
guide([X, y])
+
Variational substitution definition for each parameter.
+
load_model(filename)
-
Load model from saved Pickle instance.
+
Load model from saved torch dump.
+
+
mask()
+
Seek for all relevant weights whose values are negative.
+
+
mcmc(data, y, tensorboard, log_dir)
+
Perform Markov-Chain Monte-Carlo sampling on the (unknown) posterior.
+
+
model([X, y])
+
Definition of the log regression model.
+
+
momentum(data, y, tensorboard, log_dir)
+
Momentum optimization to find the global optimum of current parameter search.
+
+
prepare(X)
+
Preprocessing of input data before called at the beginning of the fit-function.
+
+
prior()
+
Prior definition of the weights used for log regression.
save_model(filename)
-
Save model instance as Pickle Object.
+
Save model instance as with torch’s save function as this is safer for torch tensors.
set_params(**params)
Set the parameters of this estimator.
@@ -157,9 +199,15 @@
netcal.scaling.LogisticCalibration
squeeze_generic(a, axes_to_keep)
Squeeze input array a but keep axes defined by parameter ‘axes_to_keep’ even if the dimension is of size 1.
-
transform(X)
+
to(device)
+
Set distribution parameters to the desired device in order to compute either on CPU or GPU.
+
+
transform(X[, num_samples, random_state, …])
After model calibration, this function is used to get calibrated outputs of uncalibrated confidence estimates.
Build logitic calibration model either conventional with single MLE estimate or with
+Variational Inference (VI) or Markov-Chain Monte-Carlo (MCMC) algorithm to also obtain uncertainty estimates.
Variational substitution definition for each parameter. The signature is the same as for the
+“self.model” function but the variables are not used.
+
+
Parameters
+
+
X (torch.Tensor, shape=(n_samples, n_log_regression_features)) – Input data that has been prepared by “self.prepare” function call.
+
y (torch.Tensor, shape=(n_samples, [n_classes])) – Torch tensor with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D) (for multiclass MLE only).
Seek for all relevant weights whose values are negative. Mask those values with optimization constraints
+in the interval [0, 0].
+Constraints on the intercepts might also be set.
+
+
Returns
+
Indices of masked values and list of boundary constraints for optimization.
X (torch.Tensor, shape=(n_samples, n_log_regression_features)) – Input data that has been prepared by “self.prepare” function call.
+
y (torch.Tensor, shape=(n_samples, [n_classes])) – Torch tensor with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D) (for multiclass MLE only).
Momentum optimization to find the global optimum of current parameter search.
+This method is slow but tends to find the global optimum for non-convex optimization.
+
+
Parameters
+
+
data_input (np.ndarray, shape=(n_samples, n_features)) – NumPy 2-D array with data input.
+
y (np.ndarray, shape=(n_samples,)) – NumPy array with ground truth labels as 1-D vector (binary).
Preprocessing of input data before called at the beginning of the fit-function.
+
+
Parameters
+
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+1-D for binary classification, 2-D for multi class (softmax).
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
Prior definition of the weights used for log regression. This function has to set the
+variables ‘self.weight_prior_dist’, ‘self.weight_mean_init’ and ‘self.weight_stddev_init’.
+transform(X: numpy.ndarray, num_samples: int = 1000, random_state: int = None, mean_estimate: bool = False) → numpy.ndarray¶
After model calibration, this function is used to get calibrated outputs of uncalibrated
confidence estimates.
Parameters
-
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+
+
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
1-D for binary classification, 2-D for multi class (softmax).
-On detection, this array must have 2 dimensions with number of additional box features in last dim.
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
+
num_samples (int, optional, default: 1000) – Number of samples generated on MCMC sampling or Variational Inference.
+
random_state (int, optional, default: None) – Fix the random seed for the random number
+
mean_estimate (bool, optional, default: False) – If True, directly return the mean on probabilistic methods like MCMC or VI instead of the full
+distribution. This parameter has no effect on MLE.
+
Returns
-
NumPy array with calibrated confidence estimates.
-1-D for binary classification, 2-D for multi class (softmax).
+
+
np.ndarray, shape=(n_samples, [n_classes]) on MLE or on MCMC/VI if ‘mean_estimate’ is True
+
or shape=(n_parameters, n_samples, [n_classes]) on VI, MCMC if ‘mean_estimate’ is False – On MLE without uncertainty, return NumPy array with calibrated confidence estimates.
+1-D for binary classification, 2-D for multi class (softmax).
+On VI or MCMC, return NumPy array with leading dimension as the number of sampled parameters from the
+log regression parameter distribution obtained by VI or MCMC.
This calibration method uses multivariate normal distributions to obtain a
-calibration mapping by means of the confidence as well as additional features. This method is originally
-proposed by 1. This calibration scheme
-tries to model several dependencies in the variables given by the input X.
This calibration method is for detection only and uses multivariate normal distributions to obtain a
+calibration mapping by means of the confidence as well as additional features. This calibration scheme
+tries to model several dependencies in the variables given by the input X1.
It is necessary to provide all data in input parameter X as an NumPy array of shape (n_samples,n_features),
whereas the confidence must be the first feature given in the input array. The ground-truth samples y
must be an array of shape (n_samples,) consisting of binary labels \(y \in \{0, 1\}\). Those
@@ -71,7 +70,7 @@
Fabian Küppers, Jan Kronenberger, Amirhossein Shantia and Anselm Haselhoff:
“Multivariate Confidence Calibration for Object Detection.”
The IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Workshops.
Kull, Meelis, Telmo Silva Filho, and Peter Flach:
+“Beta calibration: a well-founded and easily implemented improvement on logistic calibration for binary classifiers”
+Artificial Intelligence and Statistics, PMLR 54:623-631, 2017
+Get source online
+
+
3
+
Fabian Küppers, Jan Kronenberger, Jonas Schneider and Anselm Haselhoff:
+“Bayesian Confidence Calibration for Epistemic Uncertainty Modelling.”
+2021 IEEE Intelligent Vehicles Symposium (IV), 2021
+
Methods
@@ -112,26 +135,50 @@
netcal.scaling.LogisticCalibrationDependent
-
__init__([detection])
-
Constructor.
+
__init__(*args, **kwargs)
+
Create an instance of LogisticCalibrationDependent.
clear()
Clear model parameters.
-
fit(X, y)
-
Build Logistic Calibration model for multivariate normal distributions.
+
convex(data, y, tensorboard, log_dir)
+
Convex optimization to find the global optimum of current parameter search.
-
fit_transform(X[, y])
+
fit(X, y[, random_state, tensorboard, log_dir])
+
Build logitic calibration model either conventional with single MLE estimate or with Variational Inference (VI) or Markov-Chain Monte-Carlo (MCMC) algorithm to also obtain uncertainty estimates.
+
+
fit_transform(X[, y])
Fit to data, then transform it.
-
get_params([deep])
+
get_params([deep])
Get parameters for this estimator.
+
guide([X, y])
+
Variational substitution definition for each parameter.
+
load_model(filename)
-
Load model from saved Pickle instance.
+
Load model from saved torch dump.
+
+
mask()
+
Seek for all relevant weights whose values are negative.
+
+
mcmc(data, y, tensorboard, log_dir)
+
Perform Markov-Chain Monte-Carlo sampling on the (unknown) posterior.
+
+
model([X, y])
+
Definition of the log regression model.
+
+
momentum(data, y, tensorboard, log_dir)
+
Momentum optimization to find the global optimum of current parameter search.
+
+
prepare(X)
+
Preprocessing of input data before called at the beginning of the fit-function.
+
+
prior()
+
Prior definition of the weights used for log regression.
save_model(filename)
-
Save model instance as Pickle Object.
+
Save model instance as with torch’s save function as this is safer for torch tensors.
set_params(**params)
Set the parameters of this estimator.
@@ -139,9 +186,15 @@
netcal.scaling.LogisticCalibrationDependent
squeeze_generic(a, axes_to_keep)
Squeeze input array a but keep axes defined by parameter ‘axes_to_keep’ even if the dimension is of size 1.
-
transform(X)
+
to(device)
+
Set distribution parameters to the desired device in order to compute either on CPU or GPU.
+
+
transform(X[, num_samples, random_state, …])
After model calibration, this function is used to get calibrated outputs of uncalibrated confidence estimates.
Build logitic calibration model either conventional with single MLE estimate or with
+Variational Inference (VI) or Markov-Chain Monte-Carlo (MCMC) algorithm to also obtain uncertainty estimates.
Variational substitution definition for each parameter. The signature is the same as for the
+“self.model” function but the variables are not used.
+
+
Parameters
+
+
X (torch.Tensor, shape=(n_samples, n_log_regression_features)) – Input data that has been prepared by “self.prepare” function call.
+
y (torch.Tensor, shape=(n_samples, [n_classes])) – Torch tensor with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D) (for multiclass MLE only).
Seek for all relevant weights whose values are negative. Mask those values with optimization constraints
+in the interval [0, 0].
+Constraints on the intercepts might also be set.
+
+
Returns
+
Indices of masked values and list of boundary constraints for optimization.
X (torch.Tensor, shape=(n_samples, n_log_regression_features)) – Input data that has been prepared by “self.prepare” function call.
+
y (torch.Tensor, shape=(n_samples, [n_classes])) – Torch tensor with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D) (for multiclass MLE only).
Momentum optimization to find the global optimum of current parameter search.
+This method is slow but tends to find the global optimum for non-convex optimization.
+
+
Parameters
+
+
data_input (np.ndarray, shape=(n_samples, n_features)) – NumPy 2-D array with data input.
+
y (np.ndarray, shape=(n_samples,)) – NumPy array with ground truth labels as 1-D vector (binary).
Preprocessing of input data before called at the beginning of the fit-function.
+
+
Parameters
+
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+1-D for binary classification, 2-D for multi class (softmax).
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
Prior definition of the weights used for log regression. This function has to set the
+variables ‘self.weight_prior_dist’, ‘self.weight_mean_init’ and ‘self.weight_stddev_init’.
+transform(X: numpy.ndarray, num_samples: int = 1000, random_state: int = None, mean_estimate: bool = False) → numpy.ndarray¶
After model calibration, this function is used to get calibrated outputs of uncalibrated
confidence estimates.
Parameters
-
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+
+
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
1-D for binary classification, 2-D for multi class (softmax).
-On detection, this array must have 2 dimensions with number of additional box features in last dim.
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
+
num_samples (int, optional, default: 1000) – Number of samples generated on MCMC sampling or Variational Inference.
+
random_state (int, optional, default: None) – Fix the random seed for the random number
+
mean_estimate (bool, optional, default: False) – If True, directly return the mean on probabilistic methods like MCMC or VI instead of the full
+distribution. This parameter has no effect on MLE.
+
Returns
-
NumPy array with calibrated confidence estimates.
-1-D for binary classification, 2-D for multi class (softmax).
+
+
np.ndarray, shape=(n_samples, [n_classes]) on MLE or on MCMC/VI if ‘mean_estimate’ is True
+
or shape=(n_parameters, n_samples, [n_classes]) on VI, MCMC if ‘mean_estimate’ is False – On MLE without uncertainty, return NumPy array with calibrated confidence estimates.
+1-D for binary classification, 2-D for multi class (softmax).
+On VI or MCMC, return NumPy array with leading dimension as the number of sampled parameters from the
+log regression parameter distribution obtained by VI or MCMC.
Perform Temperature scaling to logits of NN. This method is originally proposed by 1.
-The calibrated probability \(\hat{q}\) is computed by
+
On classification or detection, apply the temperature scaling method described in 1 to obtain a
+calibration mapping. For confidence calibration in classification tasks, a
+confidence mapping \(g\) is applied on top of a miscalibrated scoring classifier \(\hat{p} = h(x)\) to
+deliver a calibrated confidence score \(\hat{q} = g(h(x))\).
+
For detection calibration, we can also use the additional box regression output which we denote as
+\(\hat{r} \in [0, 1]^J\) with \(J\) as the number of dimensions used for the box encoding (e.g.
+\(J=4\) for x position, y position, width and height).
+Therefore, the calibration map is not only a function of the confidence score, but also of \(\hat{r}\).
+To define a general calibration map, we use the the combined input \(s = (\hat{p}, \hat{r})\) of size K
+and perform a temperature scaling defined by
-\[\hat{q} = \sigma_{\text{SM}} (z / T)\]
-
with \(\sigma_{\text{SM}}\) as the softmax operator (or the sigmoid alternatively),
-\(z\) as the logits and \(T\) as the temperature estimated by logistic regression.
-This leds to calibrated confidence estimates.
-This methods can also be applied on object detection tasks with an additional regression output 2.
+\[\hat{q} = \sigma(s / T)\]
+
with the temperature \(T \in \mathbb{R}\) as a single scalar value.
+The function \(\sigma(*)\) is either the sigmoid (on detection or binary classification) or the
+softmax operator (multiclass classification).
+
We utilize standard optimization methods to determine the calibration mapping \(g(s)\).
Parameters
+
method (str, default: "mle") – Method that is used to obtain a calibration mapping:
+- ‘mle’: Maximum likelihood estimate without uncertainty using a convex optimizer.
+- ‘momentum’: MLE estimate using Momentum optimizer for non-convex optimization.
+- ‘variational’: Variational Inference with uncertainty.
+- ‘mcmc’: Markov-Chain Monte-Carlo sampling with uncertainty.
+
momentum_epochs (int, optional, default: 1000) – Number of epochs used by momentum optimizer.
+
mcmc_steps (int, optional, default: 20) – Number of weight samples obtained by MCMC sampling.
+
mcmc_chains (int, optional, default: 1) – Number of Markov-chains used in parallel for MCMC sampling (this will result
+in mcmc_steps * mcmc_chains samples).
+
mcmc_warmup_steps (int, optional, default: 100) – Warmup steps used for MCMC sampling.
+
vi_epochs (int, optional, default: 1000) – Number of epochs used for ELBO optimization.
detection (bool, default: False) – If False, the input array ‘X’ is treated as multi-class confidence input (softmax)
with shape (n_samples, [n_classes]).
If True, the input array ‘X’ is treated as a box predictions with several box features (at least
@@ -69,21 +88,28 @@
Chuan Guo, Geoff Pleiss, Yu Sun and Kilian Q. Weinberger:
“On Calibration of Modern Neural Networks.”
Proceedings of the 34th International Conference on Machine Learning-Volume 70. JMLR. org, 2017.
Get source online
Fabian Küppers, Jan Kronenberger, Amirhossein Shantia and Anselm Haselhoff:
“Multivariate Confidence Calibration for Object Detection.”
-The IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Workshops.
+The IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Workshops, 2020.
+
+
3
+
Fabian Küppers, Jan Kronenberger, Jonas Schneider and Anselm Haselhoff:
+“Bayesian Confidence Calibration for Epistemic Uncertainty Modelling.”
+2021 IEEE Intelligent Vehicles Symposium (IV), 2021
Methods
@@ -93,26 +119,50 @@
netcal.scaling.TemperatureScaling
-
__init__([detection, independent_probabilities])
-
Constructor.
+
__init__(*args, **kwargs)
+
Create an instance of TemperatureScaling.
clear()
Clear model parameters.
-
fit(X, y)
-
Build logitic calibration model.
+
convex(data, y, tensorboard, log_dir)
+
Convex optimization to find the global optimum of current parameter search.
+
+
fit(X, y[, random_state, tensorboard, log_dir])
+
Build logitic calibration model either conventional with single MLE estimate or with Variational Inference (VI) or Markov-Chain Monte-Carlo (MCMC) algorithm to also obtain uncertainty estimates.
-
fit_transform(X[, y])
+
fit_transform(X[, y])
Fit to data, then transform it.
-
get_params([deep])
+
get_params([deep])
Get parameters for this estimator.
+
guide([X, y])
+
Variational substitution definition for each parameter.
+
load_model(filename)
-
Load model from saved Pickle instance.
+
Load model from saved torch dump.
+
+
mask()
+
Seek for all relevant weights whose values are negative.
+
+
mcmc(data, y, tensorboard, log_dir)
+
Perform Markov-Chain Monte-Carlo sampling on the (unknown) posterior.
+
+
model([X, y])
+
Definition of the log regression model.
+
+
momentum(data, y, tensorboard, log_dir)
+
Momentum optimization to find the global optimum of current parameter search.
+
+
prepare(X)
+
Preprocessing of input data before called at the beginning of the fit-function.
+
+
prior()
+
Prior definition of the weights used for log regression.
save_model(filename)
-
Save model instance as Pickle Object.
+
Save model instance as with torch’s save function as this is safer for torch tensors.
set_params(**params)
Set the parameters of this estimator.
@@ -120,9 +170,15 @@
netcal.scaling.TemperatureScaling
squeeze_generic(a, axes_to_keep)
Squeeze input array a but keep axes defined by parameter ‘axes_to_keep’ even if the dimension is of size 1.
-
transform(X)
+
to(device)
+
Set distribution parameters to the desired device in order to compute either on CPU or GPU.
+
+
transform(X[, num_samples, random_state, …])
After model calibration, this function is used to get calibrated outputs of uncalibrated confidence estimates.
Build logitic calibration model either conventional with single MLE estimate or with
+Variational Inference (VI) or Markov-Chain Monte-Carlo (MCMC) algorithm to also obtain uncertainty estimates.
Variational substitution definition for each parameter. The signature is the same as for the
+“self.model” function but the variables are not used.
+
+
Parameters
+
+
X (torch.Tensor, shape=(n_samples, n_log_regression_features)) – Input data that has been prepared by “self.prepare” function call.
+
y (torch.Tensor, shape=(n_samples, [n_classes])) – Torch tensor with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D) (for multiclass MLE only).
Seek for all relevant weights whose values are negative. Mask those values with optimization constraints
+in the interval [0, 0].
+Constraints on the intercepts might also be set.
+
+
Returns
+
Indices of masked values and list of boundary constraints for optimization.
X (torch.Tensor, shape=(n_samples, n_log_regression_features)) – Input data that has been prepared by “self.prepare” function call.
+
y (torch.Tensor, shape=(n_samples, [n_classes])) – Torch tensor with ground truth labels.
+Either as label vector (1-D) or as one-hot encoded ground truth array (2-D) (for multiclass MLE only).
Momentum optimization to find the global optimum of current parameter search.
+This method is slow but tends to find the global optimum for non-convex optimization.
+
+
Parameters
+
+
data_input (np.ndarray, shape=(n_samples, n_features)) – NumPy 2-D array with data input.
+
y (np.ndarray, shape=(n_samples,)) – NumPy array with ground truth labels as 1-D vector (binary).
Preprocessing of input data before called at the beginning of the fit-function.
+
+
Parameters
+
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+1-D for binary classification, 2-D for multi class (softmax).
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
Prior definition of the weights used for log regression. This function has to set the
+variables ‘self.weight_prior_dist’, ‘self.weight_mean_init’ and ‘self.weight_stddev_init’.
+transform(X: numpy.ndarray, num_samples: int = 1000, random_state: int = None, mean_estimate: bool = False) → numpy.ndarray¶
After model calibration, this function is used to get calibrated outputs of uncalibrated
confidence estimates.
Parameters
-
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
+
+
X (np.ndarray, shape=(n_samples, [n_classes]) or (n_samples, [n_box_features])) – NumPy array with confidence values for each prediction on classification with shapes
1-D for binary classification, 2-D for multi class (softmax).
-On detection, this array must have 2 dimensions with number of additional box features in last dim.
+On detection, this array must have 2 dimensions with number of additional box features in last dim.
+
num_samples (int, optional, default: 1000) – Number of samples generated on MCMC sampling or Variational Inference.
+
random_state (int, optional, default: None) – Fix the random seed for the random number
+
mean_estimate (bool, optional, default: False) – If True, directly return the mean on probabilistic methods like MCMC or VI instead of the full
+distribution. This parameter has no effect on MLE.
+
Returns
-
NumPy array with calibrated confidence estimates.
-1-D for binary classification, 2-D for multi class (softmax).
+
+
np.ndarray, shape=(n_samples, [n_classes]) on MLE or on MCMC/VI if ‘mean_estimate’ is True
+
or shape=(n_parameters, n_samples, [n_classes]) on VI, MCMC if ‘mean_estimate’ is False – On MLE without uncertainty, return NumPy array with calibrated confidence estimates.
+1-D for binary classification, 2-D for multi class (softmax).
+On VI or MCMC, return NumPy array with leading dimension as the number of sampled parameters from the
+log regression parameter distribution obtained by VI or MCMC.