(v: &[f32], x: usize)
| 105 | } |
| 106 | |
| 107 | fn project_vector_to_x(v: &[f32], x: usize) -> Vec<ProjectedValue> { |
| 108 | let mut projected = v |
| 109 | .chunks(2) |
| 110 | .map(|chunk| { |
| 111 | if chunk.len() == 2 { |
| 112 | ProjectedValue { |
| 113 | value: chunk[0], |
| 114 | weight: if is_sensitive_pair(chunk[0], chunk[1]) { |
| 115 | calculate_weight(1) |
| 116 | } else { |
| 117 | 0.0 |
| 118 | }, |
| 119 | iterations: 1, |
| 120 | } |
| 121 | } else { |
| 122 | ProjectedValue { |
| 123 | value: chunk[0], |
| 124 | weight: 0.0, |
| 125 | iterations: 1, |
| 126 | } |
| 127 | } |
| 128 | }) |
| 129 | .collect::<Vec<_>>(); |
| 130 | |
| 131 | let mut iteration: u8 = 2; |
| 132 | while projected.len() > x { |
| 133 | if projected.len() / 2 < x { |
| 134 | let pairs_to_project = projected.len() - x; |
| 135 | let mut new_projected = Vec::new(); |
| 136 | |
| 137 | for i in 0..pairs_to_project { |
| 138 | let z = project_to_3d(projected[2 * i].value, projected[2 * i + 1].value); |
| 139 | let inherited_weight = projected[2 * i].weight + projected[2 * i + 1].weight; |
| 140 | let sensitivity_weight = |
| 141 | if is_sensitive_pair(projected[2 * i].value, projected[2 * i + 1].value) { |
| 142 | calculate_weight(iteration) |
| 143 | } else { |
| 144 | 0.0 |
| 145 | }; |
| 146 | let new_weight = inherited_weight + sensitivity_weight; |
| 147 | |
| 148 | new_projected.push(ProjectedValue { |
| 149 | value: z, |
| 150 | weight: new_weight, |
| 151 | iterations: iteration, |
| 152 | }); |
| 153 | } |
| 154 | |
| 155 | new_projected.extend_from_slice(&projected[pairs_to_project * 2..]); |
| 156 | projected = new_projected; |
| 157 | } else { |
| 158 | projected = projected |
| 159 | .chunks(2) |
| 160 | .map(|chunk| { |
| 161 | let z = project_to_3d(chunk[0].value, chunk[1].value); |
| 162 | let inherited_weight = chunk[0].weight + chunk[1].weight; |
| 163 | let sensitivity_weight = if is_sensitive_pair(chunk[0].value, chunk[1].value) { |
| 164 | calculate_weight(iteration) |
no test coverage detected