Returns a matrix which contains the population consisting of one or more subpopulations. Each row of the matrix represents a sample generated from one of the subpopulations. The value in the first column of a row denotes the subpopulation from which this sample has been generated. If the value is 0 this sample has been created from the first subpopulation (i.e. the first data source that has bee
(&mut self)
| 317 | /// Then, the matrix could look like: |
| 318 | /// |
| 319 | pub fn as_matrix(&mut self) -> Matrix<f64> { |
| 320 | |
| 321 | let mut m = Matrix::new(); |
| 322 | |
| 323 | for (idx, &mut (n, ref mut nd)) in self.normal.iter_mut().enumerate() { |
| 324 | for _ in (0..n) { |
| 325 | let v = nd.next().unwrap().clone(); |
| 326 | let mut x = vec![idx as f64]; |
| 327 | for j in v { |
| 328 | x.push(j); |
| 329 | } |
| 330 | m.add_row(&x); |
| 331 | } |
| 332 | } |
| 333 | m |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | /// Creates a mixture model with normally distributed data sources. |