lace 0.9.1

A probabilistic cross-categorization engine
Documentation
1
2
3
4
5
6
7
8
9
10
11
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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
mod dataless;
pub mod error;
mod traits;
pub mod utils;
mod validation;

use std::path::Path;

pub use dataless::DatalessOracle;
use serde::Deserialize;
use serde::Serialize;
pub use traits::OracleT;
pub use traits::Variability;

use super::HasCodebook;
use crate::cc::state::State;
use crate::codebook::Codebook;
use crate::data::DataStore;
use crate::data::Datum;
use crate::data::SummaryStatistics;
use crate::metadata::latest::Metadata;
use crate::Engine;
use crate::HasData;
use crate::HasStates;

/// Mutual Information Type
#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    Copy,
    Eq,
    PartialEq,
    Ord,
    PartialOrd,
    Hash,
)]
#[serde(rename_all = "snake_case")]
pub enum MiType {
    /// The Standard, un-normalized variant
    UnNormed,
    /// Normalized by the max MI, which is `min(H(A), H(B))`
    Normed,
    /// Linfoot information Quantity. Derived by computing the mutual
    /// information between the two components of a bivariate Normal with
    /// covariance rho, and solving for rho.
    Linfoot,
    /// Variation of Information. A version of mutual information that
    /// satisfies the triangle inequality.
    Voi,
    /// Jaccard distance between X an Y. Jaccard(X, Y) is in [0, 1].
    Jaccard,
    /// Information Quality Ratio:  the amount of information of a variable
    /// based on another variable against total uncertainty.
    Iqr,
    /// Mutual Information normed the with square root of the product of the
    /// components entropies. Akin to the Pearson correlation coefficient.
    Pearson,
}

/// Holds the components required to compute mutual information
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, PartialOrd)]
pub struct MiComponents {
    /// The entropy of column a, H(A)
    pub h_a: f64,
    /// The entropy of column b, H(B)
    pub h_b: f64,
    /// The joint entropy of columns a and b, H(A, B)
    pub h_ab: f64,
}

impl MiComponents {
    #[inline]
    pub fn compute(&self, mi_type: MiType) -> f64 {
        let mi = (self.h_a + self.h_b - self.h_ab).max(0.0);

        match mi_type {
            MiType::UnNormed => mi,
            MiType::Normed => mi / self.h_a.min(self.h_b),
            MiType::Voi => 2.0_f64.mul_add(-mi, self.h_a + self.h_b),
            MiType::Pearson => mi / (self.h_a * self.h_b).sqrt(),
            MiType::Iqr => mi / self.h_ab,
            MiType::Jaccard => 1.0 - mi / self.h_ab,
            MiType::Linfoot => (1.0 - (-2.0 * mi).exp()).sqrt(),
        }
    }
}

/// The variant on conditional entropy to compute
#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    Copy,
    Eq,
    PartialEq,
    Ord,
    PartialOrd,
    Hash,
)]
pub enum ConditionalEntropyType {
    /// Normal conditional entropy
    UnNormed,
    /// IP(X; Y), The proportion of information in X accounted for by Y
    InfoProp,
}

/// The variant of row similarity to compute
#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    Copy,
    Eq,
    PartialEq,
    Ord,
    PartialOrd,
    Hash,
)]
pub enum RowSimilarityVariant {
    /// Plain row similarity. The proportion of *views* in which the two rows are in the same
    /// category.
    ViewWeighted,
    /// The proportion of *columns* in which the two rows are in the same view.
    ColumnWeighted,
}
/// Oracle answers questions
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields, try_from = "Metadata", into = "Metadata")]
pub struct Oracle {
    /// Vector of states
    pub states: Vec<State>,
    /// Metadata for the rows and columns
    pub codebook: Codebook,
    pub data: DataStore,
}

impl Oracle {
    // TODO: just make this a From trait impl
    /// Convert an `Engine` into an `Oracle`
    pub fn from_engine(engine: Engine) -> Self {
        let data = {
            let data_map = engine.states.first().unwrap().clone_data();
            DataStore::new(data_map)
        };

        // TODO: would be nice to have a draining iterator on the states
        // rather than cloning them
        let states: Vec<State> = engine
            .states
            .iter()
            .map(|state| {
                let mut state_clone = state.clone();
                state_clone.drop_data();
                state_clone
            })
            .collect();

        Self {
            data,
            states,
            codebook: engine.codebook,
        }
    }

    /// Load an Oracle from a .lace file
    pub fn load<P: AsRef<Path>>(
        path: P,
    ) -> Result<Self, crate::metadata::Error> {
        let metadata = crate::metadata::load_metadata(path)?;
        metadata
            .try_into()
            .map_err(|err| crate::metadata::Error::Other(format!("{err}")))
    }
}

impl HasStates for Oracle {
    #[inline]
    fn states(&self) -> &Vec<State> {
        &self.states
    }

    #[inline]
    fn states_mut(&mut self) -> &mut Vec<State> {
        &mut self.states
    }
}

impl HasData for Oracle {
    #[inline]
    fn summarize_feature(&self, ix: usize) -> SummaryStatistics {
        self.data.0[&ix].summarize()
    }

    #[inline]
    fn cell(&self, row_ix: usize, col_ix: usize) -> Datum {
        let x = self.data.get(row_ix, col_ix);
        utils::post_process_datum(x, col_ix, self.codebook())
    }
}

impl HasCodebook for Oracle {
    fn codebook(&self) -> &Codebook {
        &self.codebook
    }
}

#[cfg(test)]
mod tests {
    use std::collections::BTreeMap;
    use std::path::Path;

    use approx::*;
    use rand::Rng;
    use rv::dist::Categorical;
    use rv::dist::Gaussian;
    use rv::dist::Mixture;
    use rv::traits::HasDensity;
    use rv::traits::Sampleable;

    use super::*;
    use crate::cc::feature::FType;
    use crate::cc::feature::Feature;
    use crate::codebook::ColMetadata;
    use crate::codebook::ColType;
    use crate::stats::MixtureType;
    use crate::Given;
    use crate::Oracle;
    use crate::OracleT;

    fn dummy_codebook_from_state(state: &State) -> Codebook {
        Codebook {
            table_name: "my_table".into(),
            state_prior_process: None,
            view_prior_process: None,
            col_metadata: (0..state.n_cols())
                .map(|ix| {
                    let ftr = state.feature(ix);
                    ColMetadata {
                        name: ix.to_string(),
                        notes: None,
                        coltype: match ftr.ftype() {
                            FType::Continuous => ColType::Continuous {
                                hyper: None,
                                prior: None,
                            },
                            FType::Categorical => ColType::Categorical {
                                k: 4,
                                hyper: None,
                                value_map: crate::codebook::ValueMap::UInt(4),
                                prior: None,
                            },
                            FType::Count => ColType::Count {
                                hyper: None,
                                prior: None,
                            },
                            _ => panic!("Unsupported coltype"),
                        },
                        missing_not_at_random: false,
                    }
                })
                .collect::<Vec<_>>()
                .try_into()
                .unwrap(),
            row_names: (0..state.n_rows())
                .map(|ix| ix.to_string())
                .collect::<Vec<String>>()
                .try_into()
                .unwrap(),
            comments: None,
        }
    }

    fn oracle_from_yaml<P: AsRef<Path>>(filenames: Vec<P>) -> Oracle {
        let states = utils::load_states(filenames);
        let data = DataStore::new(states[0].clone_data());
        let codebook = dummy_codebook_from_state(&states[0]);
        println!("CB {}, {}", states[0].n_cols(), codebook.n_cols());
        Oracle {
            states,
            codebook,
            data,
        }
    }

    const TOL: f64 = 1E-8;
    fn get_single_continuous_oracle_from_yaml() -> Oracle {
        let filenames = vec!["resources/test/single-continuous.yaml"];
        oracle_from_yaml(filenames)
    }

    fn get_duplicate_single_continuous_oracle_from_yaml() -> Oracle {
        let filenames = vec![
            "resources/test/single-continuous.yaml",
            "resources/test/single-continuous.yaml",
        ];
        oracle_from_yaml(filenames)
    }

    fn get_oracle_from_yaml() -> Oracle {
        let filenames = vec![
            "resources/test/small/small-state-1.yaml",
            "resources/test/small/small-state-2.yaml",
            "resources/test/small/small-state-3.yaml",
        ];

        oracle_from_yaml(filenames)
    }

    fn get_entropy_oracle_from_yaml() -> Oracle {
        let filenames = vec![
            "resources/test/entropy/entropy-state-1.yaml",
            "resources/test/entropy/entropy-state-2.yaml",
        ];
        oracle_from_yaml(filenames)
    }

    #[test]
    fn single_continuous_column_logp() {
        let oracle = get_single_continuous_oracle_from_yaml();

        let vals = vec![vec![Datum::Continuous(-1.0)]];
        let logp = oracle
            .logp(&[0], &vals, &Given::<usize>::Nothing, None)
            .unwrap()[0];

        assert_relative_eq!(logp, -2.794_105_164_665_195_3, epsilon = TOL);
    }

    #[test]
    fn single_continuous_column_logp_state_0() {
        let oracle = get_oracle_from_yaml();

        let vals = vec![vec![Datum::Continuous(-1.0)]];
        let logp = oracle
            .logp(&[0], &vals, &Given::<usize>::Nothing, Some(&[0]))
            .unwrap()[0];

        assert_relative_eq!(logp, -1.223_532_985_437_053, epsilon = TOL);
    }

    #[test]
    fn single_continuous_column_logp_duplicated_states() {
        let oracle = get_duplicate_single_continuous_oracle_from_yaml();

        let vals = vec![vec![Datum::Continuous(-1.0)]];
        let logp = oracle
            .logp(&[0], &vals, &Given::<usize>::Nothing, None)
            .unwrap()[0];

        assert_relative_eq!(logp, -2.794_105_164_665_195_3, epsilon = TOL);
    }

    #[test]
    #[ignore]
    fn mutual_information_smoke() {
        let oracle = get_oracle_from_yaml();

        let mi_01 = oracle.mi(0, 1, 10_000, MiType::Normed).unwrap();
        let mi_02 = oracle.mi(0, 2, 10_000, MiType::Normed).unwrap();
        let mi_12 = oracle.mi(1, 2, 10_000, MiType::Normed).unwrap();

        assert!(mi_01 > 0.0);
        assert!(mi_02 > 0.0);
        assert!(mi_12 > 0.0);
    }

    #[test]
    fn surpisal_value_1() {
        let oracle = get_oracle_from_yaml();
        let s = oracle
            .surprisal(&Datum::Continuous(1.2), 3, 1, None)
            .unwrap()
            .unwrap();
        assert_relative_eq!(s, 1.773_919_580_331_675_8, epsilon = 10E-7);
    }

    #[test]
    fn surpisal_value_2() {
        let oracle = get_oracle_from_yaml();
        let s = oracle
            .surprisal(&Datum::Continuous(0.1), 1, 0, None)
            .unwrap()
            .unwrap();
        assert_relative_eq!(s, 0.620_843_253_052_312_7, epsilon = 10E-7);
    }

    #[test]
    fn impute_uncertainty_smoke() {
        let oracle = get_oracle_from_yaml();
        let u = oracle._impute_uncertainty(0, 1);
        assert!(u > 0.0);
        assert!(u < 1.0);
    }

    #[test]
    fn predict_uncertainty_smoke_no_given() {
        let oracle = get_oracle_from_yaml();
        let u = oracle._predict_uncertainty(0, &Given::Nothing, None);
        assert!(u > 0.0);
        assert!(u < 1.0);
    }

    #[test]
    fn predict_uncertainty_smoke_with_given() {
        let oracle = get_oracle_from_yaml();
        let given = Given::Conditions(vec![(1, Datum::Continuous(2.5))]);
        let u = oracle._predict_uncertainty(0, &given, None);
        assert!(u > 0.0);
        assert!(u < 1.0);
    }

    #[test]
    fn mixture_and_oracle_logp_equivalence_categorical() {
        let oracle = get_entropy_oracle_from_yaml();

        let mm: Mixture<Categorical> = {
            let mixtures: Vec<_> = oracle
                .states
                .iter()
                .map(|s| s.feature_as_mixture(2))
                .collect();
            match MixtureType::combine(mixtures) {
                MixtureType::Categorical(mm) => mm,
                _ => panic!("bad mixture type"),
            }
        };

        for x in 0..4 {
            let y = Datum::Categorical((x as u32).into());
            let logp_mm = mm.ln_f(&(x as usize));
            let logp_or = oracle
                .logp(&[2], &[vec![y]], &Given::<usize>::Nothing, None)
                .unwrap()[0];
            assert_relative_eq!(logp_or, logp_mm, epsilon = 1E-12);
        }
    }

    #[test]
    fn mixture_and_oracle_logp_equivalence_gaussian() {
        let oracle = get_oracle_from_yaml();
        let mut rng = rand::rng();

        let mm: Mixture<Gaussian> = {
            let mixtures: Vec<_> = oracle
                .states
                .iter()
                .map(|s| s.feature_as_mixture(1))
                .collect();
            match MixtureType::combine(mixtures) {
                MixtureType::Gaussian(mm) => mm,
                _ => panic!("bad mixture type"),
            }
        };

        for _ in 0..1000 {
            let x: f64 = {
                let u: f64 = rng.random();
                u * 3.0
            };
            let y = Datum::Continuous(x);
            let logp_mm = mm.ln_f(&x);
            let logp_or = oracle
                .logp(&[1], &[vec![y]], &Given::<usize>::Nothing, None)
                .unwrap()[0];
            assert_relative_eq!(logp_or, logp_mm, epsilon = 1E-12);
        }
    }

    #[cfg(feature = "examples")]
    mod requiring_examples {
        use super::*;
        #[test]
        fn recreate_doctest_mi_failure() {
            use crate::examples::Example;
            use crate::MiType;

            let oracle = Example::Animals.oracle().unwrap();

            let mi_flippers =
                oracle.mi("swims", "flippers", 1000, MiType::Iqr).unwrap();

            let mi_fast =
                oracle.mi("swims", "fast", 1000, MiType::Iqr).unwrap();

            assert!(mi_flippers > mi_fast);
        }

        #[test]
        fn mixture_and_oracle_logp_equivalence_animals_single_state() {
            use crate::examples::Example;

            let oracle = Example::Animals.oracle().unwrap();

            for (ix, state) in oracle.states.iter().enumerate() {
                for col_ix in 0..oracle.n_cols() {
                    let mm = match state.feature_as_mixture(col_ix) {
                        MixtureType::Categorical(mm) => mm,
                        _ => panic!("Invalid MixtureType"),
                    };
                    for val in 0..2 {
                        let logp_mm = mm.ln_f(&(val as usize));
                        let datum = Datum::Categorical((val as u32).into());
                        let logp_or = oracle
                            .logp(
                                &[col_ix],
                                &[vec![datum]],
                                &Given::<usize>::Nothing,
                                Some(&[ix]),
                            )
                            .unwrap()[0];
                        assert_relative_eq!(logp_or, logp_mm, epsilon = 1E-12);
                    }
                }
            }
        }

        #[test]
        fn pw_and_conditional_entropy_equivalence_animals() {
            use crate::examples::Example;
            let oracle = Example::Animals.oracle().unwrap();

            let n_cols = oracle.n_cols();
            let mut col_pairs: Vec<(usize, usize)> = Vec::new();
            let mut entropies: Vec<f64> = Vec::new();
            for col_a in 0..n_cols {
                for col_b in 0..n_cols {
                    if col_a != col_b {
                        col_pairs.push((col_a, col_b));
                        let ce = oracle
                            .conditional_entropy(col_a, &[col_b], 1000)
                            .unwrap();
                        entropies.push(ce);
                    }
                }
            }

            let entropies_pw = oracle
                .conditional_entropy_pw(
                    &col_pairs,
                    1000,
                    ConditionalEntropyType::UnNormed,
                )
                .unwrap();

            entropies
                .iter()
                .zip(entropies_pw.iter())
                .enumerate()
                .for_each(|(ix, (h, h_pw))| {
                    println!("{ix}");
                    assert_relative_eq!(h, h_pw, epsilon = 1E-12);
                })
        }

        #[test]
        fn pw_and_info_prop_equivalence_animals() {
            use crate::examples::Example;
            let oracle = Example::Animals.oracle().unwrap();

            let n_cols = oracle.n_cols();
            let mut col_pairs: Vec<(usize, usize)> = Vec::new();
            let mut entropies: Vec<f64> = Vec::new();
            for col_a in 0..n_cols {
                for col_b in 0..n_cols {
                    if col_a != col_b {
                        col_pairs.push((col_a, col_b));
                        let ce =
                            oracle.info_prop(&[col_a], &[col_b], 1000).unwrap();
                        entropies.push(ce);
                    }
                }
            }

            let entropies_pw = oracle
                .conditional_entropy_pw(
                    &col_pairs,
                    1000,
                    ConditionalEntropyType::InfoProp,
                )
                .unwrap();

            entropies
                .iter()
                .zip(entropies_pw.iter())
                .for_each(|(h, h_pw)| {
                    assert_relative_eq!(h, h_pw, epsilon = 1E-12);
                })
        }

        #[test]
        fn mi_pw_and_normal_equivalence() {
            use crate::examples::Example;
            let oracle = Example::Animals.oracle().unwrap();

            let n_cols = oracle.n_cols();
            let mut col_pairs: Vec<(usize, usize)> = Vec::new();
            let mut mis: Vec<f64> = Vec::new();
            for col_a in 0..n_cols {
                for col_b in 0..n_cols {
                    if col_a != col_b {
                        col_pairs.push((col_a, col_b));
                        let mi = oracle
                            .mi(col_a, col_b, 1000, MiType::UnNormed)
                            .unwrap();
                        mis.push(mi);
                    }
                }
            }

            let mis_pw =
                oracle.mi_pw(&col_pairs, 1000, MiType::UnNormed).unwrap();

            mis.iter().zip(mis_pw.iter()).for_each(|(mi, mi_pw)| {
                assert_relative_eq!(mi, mi_pw, epsilon = 1E-12);
            })
        }

        // pre v0.20.0 simulate code ripped straight from simulate_unchecked
        fn old_simulate(
            oracle: &Oracle,
            col_ixs: &[usize],
            given: &Given<usize>,
            n: usize,
            states_ixs_opt: Option<Vec<usize>>,
            rng: &mut impl Rng,
        ) -> Vec<Vec<Datum>> {
            let state_ixs: Vec<usize> = match states_ixs_opt {
                Some(state_ixs) => state_ixs,
                None => (0..oracle.n_states()).collect(),
            };

            let states: Vec<&State> =
                state_ixs.iter().map(|&ix| &oracle.states()[ix]).collect();
            let state_ixer = Categorical::uniform(state_ixs.len());
            let weights = utils::given_weights(&states, col_ixs, given);

            (0..n)
                .map(|_| {
                    // choose a random state
                    let draw_ix: usize = state_ixer.draw(rng);
                    let state = states[draw_ix];

                    // for each view
                    //   choose a random component from the weights
                    let mut cpnt_ixs: BTreeMap<usize, usize> = BTreeMap::new();
                    for (view_ix, view_weights) in &weights[draw_ix] {
                        // TODO: use Categorical::new_unchecked when rv 0.9.3 drops.
                        // from_ln_weights checks that the input logsumexp's to 0
                        let component_ixer =
                            Categorical::from_ln_weights(view_weights.clone())
                                .unwrap();
                        let k = component_ixer.draw(rng);
                        cpnt_ixs.insert(*view_ix, k);
                    }

                    // for eacch column
                    //   draw from appropriate component from that view
                    let mut xs: Vec<Datum> = Vec::with_capacity(col_ixs.len());
                    col_ixs.iter().for_each(|col_ix| {
                        let view_ix = state.asgn().asgn[*col_ix];
                        let k = cpnt_ixs[&view_ix];
                        let x = state.views[view_ix].ftrs[col_ix].draw(k, rng);
                        xs.push(x);
                    });
                    utils::post_process_row(xs, col_ixs, oracle.codebook())
                })
                .collect()
        }

        fn simulate_equivalence(
            col_ixs: &[usize],
            given: &Given<usize>,
            state_ixs_opt: Option<Vec<usize>>,
        ) {
            use rand::SeedableRng;
            use rand_xoshiro::Xoshiro256Plus;

            use crate::examples::Example;

            let n: usize = 100;
            let oracle = Example::Satellites.oracle().unwrap();

            let xs_simulator: Vec<Vec<Datum>> = {
                let mut rng = Xoshiro256Plus::seed_from_u64(1337);
                old_simulate(
                    &oracle,
                    col_ixs,
                    given,
                    n,
                    state_ixs_opt.clone(),
                    &mut rng,
                )
            };

            let xs_standard: Vec<Vec<Datum>> = {
                let mut rng = Xoshiro256Plus::seed_from_u64(1337);
                oracle
                    .simulate(col_ixs, given, n, state_ixs_opt, &mut rng)
                    .unwrap()
            };

            for (x, y) in xs_simulator.iter().zip(xs_standard.iter()) {
                assert_eq!(x, y)
            }
        }

        #[test]
        fn seeded_simulate_and_simulator_agree() {
            let col_ixs = [0_usize, 5, 6];
            let given = Given::Nothing;
            simulate_equivalence(&col_ixs, &given, None);
        }

        #[test]
        fn seeded_simulate_and_simulator_agree_state_ixs() {
            let col_ixs = [0_usize, 5, 6];
            let given = Given::Nothing;
            simulate_equivalence(&col_ixs, &given, Some(vec![3, 6]));
        }

        #[test]
        fn seeded_simulate_and_simulator_agree_given() {
            let col_ixs = [0_usize, 5, 6];
            let given = Given::Conditions(vec![(8, Datum::Continuous(100.0))]);
            simulate_equivalence(&col_ixs, &given, None);
        }

        #[test]
        fn seeded_simulate_and_simulator_agree_given_state_ixs() {
            let col_ixs = [0_usize, 5, 6];
            let given = Given::Conditions(vec![(8, Datum::Continuous(100.0))]);
            simulate_equivalence(&col_ixs, &given, Some(vec![3, 6]));
        }
    }
}