Utilities
deepgboost.common.utils.bootstrap_sampler(n_samples, n_layers, layer_idx, subsample_min_frac=0.3, rng=None)
Dynamic bootstrap sampler (paper sec. 3.1.3).
Sample size grows linearly from subsample_min_frac * n_samples at
layer 0 to n_samples at the last layer. This avoids over-fitting in
early boosting steps while allowing the final layers to see the whole
dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
Total number of training samples. |
required |
n_layers
|
int
|
Total number of boosting layers. |
required |
layer_idx
|
int
|
Index of the current layer (0-based). |
required |
subsample_min_frac
|
float
|
Minimum fraction of samples used at layer 0. |
0.3
|
rng
|
Generator or None
|
Random number generator for reproducibility. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray of shape (size,)
|
Row indices to use for training. |
Source code in src/deepgboost/common/utils.py
12 13 14 15 16 17 18 19 20 21 22 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 | |
deepgboost.common.utils.weight_solver(tree_pred, y_real, method='nnls', sample_weight=None)
Compute combination weights for the T bagged trees in a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree_pred
|
np.ndarray of shape (n_samples, n_trees)
|
Each column is one bagged tree's prediction on the full dataset. |
required |
y_real
|
np.ndarray of shape (n_samples,)
|
Pseudo-residuals target (used only when |
required |
method
|
(nnls, uniform)
|
|
"nnls"
|
sample_weight
|
np.ndarray of shape (n_samples,) or None
|
Optional per-sample weights. When provided, both |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray of shape (n_trees,)
|
Non-negative weights summing to 1. |
Source code in src/deepgboost/common/utils.py
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 | |
deepgboost.common.utils.sigmoid(x)
Numerically stable sigmoid function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array of any shape. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Element-wise sigmoid values in (0, 1). |
Source code in src/deepgboost/common/utils.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
deepgboost.common.utils.softmax(x, axis=-1)
Row-wise softmax with numerical stability via max subtraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array of any shape. |
required |
axis
|
int
|
Axis along which softmax is computed. |
-1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of the same shape as |
Source code in src/deepgboost/common/utils.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |