Scoring Functions¶
scoring
¶
Legacy scoring functions for Q2MM objective function evaluation.
Ported from q2mm.compare — the core scoring logic used by the legacy
optimizer loop. The main function is :func:compare_data, which computes:
.. math:: \chi^2 = w^2 (x_r - x_c)^2
where :math:w is a weight, :math:x_r is the reference data point's
value, and :math:x_c is the calculated (force field) value.
compare_data
¶
Compute the legacy chi-squared objective function score.
Scoring formula per data point
- Energy types (e, eo, ea, eao): score = w² × diff² / total_num_energy
- Hessian type (h): score = w² × diff² / N_hessian
- Other types: score = w² × diff² / N_type
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r_dict
|
dict[str, ndarray]
|
Reference data grouped by type. |
required |
c_dict
|
dict[str, ndarray]
|
Calculated data grouped by type. |
required |
output
|
str | None
|
Optional file path to write formatted output. |
None
|
doprint
|
bool
|
If |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Total objective function score. |
Source code in q2mm/optimizers/scoring.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
correlate_energies
¶
Align calculated energies to reference by setting the minimum to zero.
Finds the minimum in the reference dataset, then shifts all calculated energies so the corresponding calculated value is zero.
Both datasets must be aligned (same ordering).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r_data
|
ndarray
|
Reference energy data points. |
required |
c_data
|
ndarray
|
Calculated energy data points (modified in place). |
required |
Source code in q2mm/optimizers/scoring.py
select_group_of_energies
¶
Yield index arrays for each group of energies in the dataset.
Handles all energy types: relative (e, eo) and absolute
(ea, eao). Previously only e/eo were iterated,
so ea/eao silently passed through correlate_energies
uncorrelated — a bug inherited from upstream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Array of Datum objects with energy types. |
required |
Yields:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Index array for each energy group within the dataset. |
Source code in q2mm/optimizers/scoring.py
import_weights
¶
Set weights on data points from the default WEIGHTS table.
Only sets weights on data points where datum.wht is None.
Eigenvalue data gets special handling based on diagonal/off-diagonal
and frequency value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Array of Datum objects whose weights may be updated in place. |
required |