Replaces zero ternary coordinates with delta and normalize the new triplets (a, b, c). Parameters ---------- ternary_data : ndarray of shape (N, 3) delta : float Small float to regularize logarithm. Notes ----- Implements a method by J. A. Martin-
(ternary_data, delta=0.0005)
| 53 | |
| 54 | |
| 55 | def _replace_zero_coords(ternary_data, delta=0.0005): |
| 56 | """ |
| 57 | Replaces zero ternary coordinates with delta and normalize the new |
| 58 | triplets (a, b, c). |
| 59 | |
| 60 | Parameters |
| 61 | ---------- |
| 62 | |
| 63 | ternary_data : ndarray of shape (N, 3) |
| 64 | |
| 65 | delta : float |
| 66 | Small float to regularize logarithm. |
| 67 | |
| 68 | Notes |
| 69 | ----- |
| 70 | Implements a method |
| 71 | by J. A. Martin-Fernandez, C. Barcelo-Vidal, V. Pawlowsky-Glahn, |
| 72 | Dealing with zeros and missing values in compositional data sets |
| 73 | using nonparametric imputation, Mathematical Geology 35 (2003), |
| 74 | pp 253-278. |
| 75 | """ |
| 76 | zero_mask = ternary_data == 0 |
| 77 | is_any_coord_zero = np.any(zero_mask, axis=0) |
| 78 | |
| 79 | unity_complement = 1 - delta * is_any_coord_zero |
| 80 | if np.any(unity_complement) < 0: |
| 81 | raise ValueError( |
| 82 | "The provided value of delta led to negative" |
| 83 | "ternary coords.Set a smaller delta" |
| 84 | ) |
| 85 | ternary_data = np.where(zero_mask, delta, unity_complement * ternary_data) |
| 86 | return ternary_data |
| 87 | |
| 88 | |
| 89 | def _ilr_transform(barycentric): |