Unlabeled prior-shift adaptation
neureptrace.decoding.prior_shift adapts target probability traces when a source-trained decoder is evaluated on a held-out target batch with a different class prior.
The method is Category 2 / unlabeled target-adaptive. It uses target probability rows, and optionally a source training prior, but it does not accept held-out target labels.
Typical use:
from neureptrace.decoding.prior_shift import adapt_probabilities_for_prior_shift
result = adapt_probabilities_for_prior_shift(
target_probabilities,
source_prior=[0.5, 0.5],
)
adapted_probabilities = result.probabilities
For run-wise or block-wise shifts, use adapt_probability_blocks_for_prior_shift with a block id per target row. The block-wise protocol is still target-label-free, but it should be reported separately from strict source-only decoding because the held-out target probability distribution is used for adaptation.
neureptrace.decoding.prior_shift
Unlabeled target prior-shift adaptation for probability traces.
PriorShiftAdaptationResult
dataclass
Probability rows after unlabeled prior-shift adaptation.
Source code in src/neureptrace/decoding/prior_shift.py
16 17 18 19 20 21 22 23 24 25 26 27 | |
PriorShiftBlockResult
dataclass
Block-wise prior-shift adaptation output.
Source code in src/neureptrace/decoding/prior_shift.py
30 31 32 33 34 35 36 | |
adapt_probabilities_for_prior_shift(probabilities, *, source_prior=None, initial_target_prior=None, target_prior=None, max_iter=100, tol=1e-08, smoothing=1e-06, damping=1.0, epsilon=EPSILON)
Estimate a target class prior from unlabeled probability rows and reweight.
The function accepts source-model posteriors for target rows and optionally a
source training prior. It never accepts target class labels. If target_prior
is supplied, EM is skipped and only prior-ratio reweighting is applied.
Source code in src/neureptrace/decoding/prior_shift.py
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 | |
adapt_probability_blocks_for_prior_shift(probabilities, block_ids, *, source_prior=None, min_block_rows=2, **kwargs)
Run prior-shift adaptation separately for each target block.
Source code in src/neureptrace/decoding/prior_shift.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
reweight_probabilities_by_prior(probabilities, *, source_prior, target_prior, epsilon=EPSILON)
Reweight posterior rows by target_prior / source_prior.
Source code in src/neureptrace/decoding/prior_shift.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
prior_from_labels(labels, classes=None, *, smoothing=0.0)
Compute an empirical prior from source labels.
Source code in src/neureptrace/decoding/prior_shift.py
168 169 170 171 172 173 174 175 176 | |