{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/constrained-non-negative-matrix-factorization","title":"Constrained non-negative matrix factorization enabling real-time insights of $\\textit{in situ}$ and high-throughput experiments","arxiv_id":"2104.00864","date":"2021-04-02","proceeding":null,"authors":["Phillip M. Maffettone","Aidan C. Daly","Daniel Olds"],"abstract":"Non-negative Matrix Factorization (NMF) methods offer an appealing unsupervised learning method for real-time analysis of streaming spectral data in time-sensitive data collection, such as $\\textit{in situ}$ characterization of materials. However, canonical NMF methods are optimized to reconstruct a full dataset as closely as possible, with no underlying requirement that the reconstruction produces components or weights representative of the true physical processes. In this work, we demonstrate how constraining NMF weights or components, provided as known or assumed priors, can provide significant improvement in revealing true underlying phenomena. We present a PyTorch based method for efficiently applying constrained NMF and demonstrate this on several synthetic examples. When applied to streaming experimentally measured spectral data, an expert researcher-in-the-loop can provide and dynamically adjust the constraints. This set of interactive priors to the NMF model can, for example, contain known or identified independent components, as well as functional expectations about the mixing of components. We demonstrate this application on measured X-ray diffraction and pair distribution function data from $\\textit{in situ}$ beamline experiments. Details of the method are described, and general guidance provided to employ constrained NMF in extraction of critical information and insights during $\\textit{in situ}$ and high-throughput experiments.","url_abs":"https://arxiv.org/abs/2104.00864v1","url_pdf":"https://arxiv.org/pdf/2104.00864v1.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"constrained-non-negative-matrix-factorization","repo_url":"https://github.com/NSLS-II/constrained-matrix-factorization","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"BSD-3-Clause"}},{"paper_slug":"constrained-non-negative-matrix-factorization","repo_url":"https://github.com/bnl/pub-Maffettone_2021_04","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2104.00864","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2104.00864"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/bnl/pub-Maffettone_2021_04","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/NSLS-II/constrained-matrix-factorization","reach":{"status":"ok","spdx":"BSD-3-Clause"}}],"summary":{"ran_draft_wrong":1,"ran_violates":4,"unverified":16},"by_repo_kind":{"listed":{"samples":21,"ran":5,"repositories":2}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"e30b629762e9c5ce","entry":"construct_overlap","repo":"bnl/pub-Maffettone_2021_04","repo_kind":"listed","path":"constrainednmf/example_scripts/simulation_constraining_weights.py","file_url":"https://github.com/bnl/pub-Maffettone_2021_04/blob/HEAD/constrainednmf/example_scripts/simulation_constraining_weights.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"e30b629762e9c5ce"}},{"code_sha256_prefix":"bfb5a3349111c442","entry":"gaussian","repo":"bnl/pub-Maffettone_2021_04","repo_kind":"listed","path":"constrainednmf/example_scripts/simulation_constraining_weights.py","file_url":"https://github.com/bnl/pub-Maffettone_2021_04/blob/HEAD/constrainednmf/example_scripts/simulation_constraining_weights.py","link_basis":"first_harvest_node","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"bfb5a3349111c442"}},{"code_sha256_prefix":"dc85e687f1fe54a1","entry":"gaussian","repo":"bnl/pub-Maffettone_2021_04","repo_kind":"listed","path":"constrainednmf/example_scripts/simulation_constraining_components.py","file_url":"https://github.com/bnl/pub-Maffettone_2021_04/blob/HEAD/constrainednmf/example_scripts/simulation_constraining_components.py","link_basis":"first_harvest_node","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"dc85e687f1fe54a1"}},{"code_sha256_prefix":"4059f8d130c75434","entry":"lorentzian","repo":"bnl/pub-Maffettone_2021_04","repo_kind":"listed","path":"constrainednmf/example_scripts/simulation_constraining_components.py","file_url":"https://github.com/bnl/pub-Maffettone_2021_04/blob/HEAD/constrainednmf/example_scripts/simulation_constraining_components.py","link_basis":"first_harvest_node","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"4059f8d130c75434"}},{"code_sha256_prefix":"ac3311fb78cb42ee","entry":"tophat","repo":"bnl/pub-Maffettone_2021_04","repo_kind":"listed","path":"constrainednmf/example_scripts/simulation_constraining_components.py","file_url":"https://github.com/bnl/pub-Maffettone_2021_04/blob/HEAD/constrainednmf/example_scripts/simulation_constraining_components.py","link_basis":"first_harvest_node","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"ac3311fb78cb42ee"}},{"code_sha256_prefix":"b4d4a9741a95cdcc","entry":"Euclidean","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"constrainedmf/nmf/metrics.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/constrainedmf/nmf/metrics.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"b4d4a9741a95cdcc"}},{"code_sha256_prefix":"dcb5e69a1cca5494","entry":"IS_divergence","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"constrainedmf/nmf/metrics.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/constrainedmf/nmf/metrics.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"dcb5e69a1cca5494"}},{"code_sha256_prefix":"103628a541cf7a84","entry":"KL_divergence","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"constrainedmf/nmf/metrics.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/constrainedmf/nmf/metrics.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"103628a541cf7a84"}},{"code_sha256_prefix":"6b745b4e35321043","entry":"construct_overlap","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"example_scripts/fixing_weights.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/example_scripts/fixing_weights.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"6b745b4e35321043"}},{"code_sha256_prefix":"efc799ee1501e75a","entry":"decomp_plot","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"constrainedmf/utils/plotting.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/constrainedmf/utils/plotting.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"efc799ee1501e75a"}},{"code_sha256_prefix":"7a63797a121e8bbf","entry":"get_config_from_root","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"versioneer.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/versioneer.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"7a63797a121e8bbf"}},{"code_sha256_prefix":"72940734b1f5958e","entry":"get_data","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"example_scripts/bto.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/example_scripts/bto.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"72940734b1f5958e"}},{"code_sha256_prefix":"d93ac8414c5d548c","entry":"get_data","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"example_scripts/molten_salt.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/example_scripts/molten_salt.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"d93ac8414c5d548c"}},{"code_sha256_prefix":"4513b2bb026b89d2","entry":"normalize","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"constrainedmf/nmf/utils.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/constrainedmf/nmf/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"4513b2bb026b89d2"}},{"code_sha256_prefix":"f12f4dabbeb242eb","entry":"register_vcs_handler","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"versioneer.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/versioneer.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"f12f4dabbeb242eb"}},{"code_sha256_prefix":"86d4ff45d6295e29","entry":"run_command","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"versioneer.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/versioneer.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"86d4ff45d6295e29"}},{"code_sha256_prefix":"c2191e9366151532","entry":"scalar_to_vec","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"constrainedmf/nmf/utils.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/constrainedmf/nmf/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"c2191e9366151532"}},{"code_sha256_prefix":"d28ebfacd8fd4cd1","entry":"sweep_components","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"constrainedmf/nmf/utils.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/constrainedmf/nmf/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"d28ebfacd8fd4cd1"}},{"code_sha256_prefix":"38c0f458a2b3424c","entry":"toy_plot","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"constrainedmf/utils/plotting.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/constrainedmf/utils/plotting.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"38c0f458a2b3424c"}},{"code_sha256_prefix":"b9a1535d27f2a9fb","entry":"versions_from_parentdir","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"constrainedmf/_version.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/constrainedmf/_version.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"b9a1535d27f2a9fb"}},{"code_sha256_prefix":"37b5fda319bf3c0a","entry":"waterfall","repo":"NSLS-II/constrained-matrix-factorization","repo_kind":"listed","path":"constrainedmf/utils/plotting.py","file_url":"https://github.com/NSLS-II/constrained-matrix-factorization/blob/HEAD/constrainedmf/utils/plotting.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"37b5fda319bf3c0a"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}