11# This file is part of BurnMan - a thermoelastic and thermodynamic toolkit for
22# the Earth and Planetary Sciences
3- # Copyright (C) 2012 - 2021 by the BurnMan team, released under the GNU
3+ # Copyright (C) 2012 - 2025 by the BurnMan team, released under the GNU
44# GPL v2 or later.
55
66from __future__ import absolute_import
77
88import numpy as np
99from copy import deepcopy
10- from collections import namedtuple
1110from .linear_fitting import weighted_constrained_least_squares
1211from ..utils .chemistry import dictionarize_formula
1312from ..utils .chemistry import process_solution_chemistry
1615
1716class DummyCompositionSolution (Solution ):
1817 """
19- This is a dummy base class for a solution object to
20- facilitate composition fitting when no solution model has
21- been prepared. The model is initialized with appropriate
18+ A mock Solution class to enable compositional fitting when no thermodynamic
19+ model is available. Useful for pure composition analysis.
20+
21+ The model is initialized with appropriate
2222 chemical formulae for each endmember, and can do all basic
2323 compositional processing that doesn't involve any material
2424 properties.
@@ -51,10 +51,8 @@ def fit_composition_to_solution(
5151 normalize = True ,
5252):
5353 """
54- Takes a Solution object and a set of variable names and
55- associates values and covariances and finds the molar fractions of the
56- solution which provide the best fit (in a least-squares sense)
57- to the variable values.
54+ Fit a set of molar fractions to a solution model that best matches
55+ observed compositional variables (in a least-squares sense).
5856
5957 The fitting applies appropriate non-negativity constraints
6058 (i.e. no species can have a negative occupancy on a site).
@@ -83,13 +81,21 @@ def fit_composition_to_solution(
8381 would impose a constraint that the amount of Mg would be equal on
8482 the first and second site in the solution.
8583 :type variable_conversions: dict of dict, or None
86-
87- :param normalize: If True, normalizes the optimized molar fractions to sum to unity.
88- :type normalize: bool
89-
90- :returns: Optimized molar fractions, corresponding covariance matrix and the
91- weighted residual.
84+ :param normalize: Whether to normalize the molar fractions to sum to one.
85+ :type normalize: bool, default=True
86+
87+ :returns: (molar_fractions, covariance_matrix, weighted_residual)
88+ - molar_fractions: Optimized molar fractions of endmembers.
89+ - covariance_matrix: Covariance matrix of the optimized fractions,
90+ computed from the pseudo-inverse of the weighted design matrix.
91+ - weighted_residual: The weighted residual of the fit, calculated as the
92+ square root of the weighted sum of squared differences
93+ between observed and modeled variables.
9294 :rtype: tuple of 1D numpy.array, 2D numpy.array and float
95+
96+ .. seealso::
97+ :func:`burnman.optimize.linear_fitting.weighted_constrained_least_squares` -
98+ Performs the weighted constrained least squares optimization used internally.
9399 """
94100
95101 solution_variables = deepcopy (solution .elements )
@@ -170,8 +176,8 @@ def fit_composition_to_solution(
170176
171177def fit_phase_proportions_to_bulk_composition (phase_compositions , bulk_composition ):
172178 """
173- Performs weighted constrained least squares on a set of phase compositions
174- to find the amount of those phases that best-fits a given bulk composition .
179+ Determine the proportions of phases that best fit a given bulk composition
180+ (in a weighted constrained least squares sense) .
175181
176182 The fitting applies appropriate non-negativity constraints
177183 (i.e. no phase can have a negative abundance in the bulk).
@@ -184,9 +190,18 @@ def fit_phase_proportions_to_bulk_composition(phase_compositions, bulk_compositi
184190 Must be in the same units as the phase compositions.
185191 :type bulk_composition: numpy.array
186192
187- :returns: Optimized molar fractions, corresponding covariance matrix and the
188- weighted residual.
193+ :returns: (phase_proportions, covariance_matrix, weighted_residual)
194+ - phase_proportions: Optimized proportions of each phase.
195+ - covariance_matrix: Covariance matrix of the optimized phase proportions,
196+ computed from the pseudo-inverse of the weighted design matrix.
197+ - weighted_residual: The weighted residual of the fit, representing the square root
198+ of the weighted sum of squared differences between observed
199+ and modeled bulk compositions.
189200 :rtype: tuple of 1D numpy.array, 2D numpy.array and float
201+
202+ .. seealso::
203+ :func:`burnman.optimize.linear_fitting.weighted_constrained_least_squares` -
204+ Performs the weighted constrained least squares optimization used internally.
190205 """
191206
192207 n_phases = len (phase_compositions [0 ])
0 commit comments