new stopping condition

This commit is contained in:
William Ball 2021-07-20 10:59:28 -04:00
parent 2330879748
commit 749ea72cfe

View file

@ -13,12 +13,11 @@ pub fn fractal_dimension(
orthogonal_generators: Vec<Vec<usize>>, orthogonal_generators: Vec<Vec<usize>>,
) -> Result<f64, linregress::Error> { ) -> Result<f64, linregress::Error> {
let mut totals = vec![root.len(); n]; let mut totals = vec![root.len(); n];
let mut current = vec![(root, std::usize::MAX, false)]; let mut current = vec![(root, std::usize::MAX)];
let mut next = vec![]; let mut next = vec![];
let mut nodes: u64 = 1; let mut nodes: u64 = 1;
let xs: Vec<f64> = (1..=n) let xs: Vec<f64> = (1..=n)
// .map(|x| (x as f64 * upper_bound / (n as f64)))
.map(|x| (x as f64 * upper_bound / (2.0 * n as f64) + upper_bound / 2.0)) .map(|x| (x as f64 * upper_bound / (2.0 * n as f64) + upper_bound / 2.0))
.collect(); .collect();
@ -26,7 +25,9 @@ pub fn fractal_dimension(
loop { loop {
next.clear(); next.clear();
for (tuple, previous_generator, bad) in &current { for (tuple, previous_generator) in &current {
let mut add_children = false;
let mut children = vec![];
for (i, generator) in generators.iter().enumerate() { for (i, generator) in generators.iter().enumerate() {
let mut skip = false; let mut skip = false;
for orthogonal_pairs in &orthogonal_generators { for orthogonal_pairs in &orthogonal_generators {
@ -63,16 +64,19 @@ pub fn fractal_dimension(
} }
} }
if add { if add {
next.push((new_tuple, i, false)); add_children = true;
nodes += 1; children.push((new_tuple, i));
} else { } else {
if !bad { children.push((new_tuple, i));
next.push((new_tuple, i, true));
nodes += 1;
}
} }
} }
} }
if add_children {
nodes += 1;
for child in children {
next.push(child);
}
}
} }
std::mem::swap(&mut current, &mut next); std::mem::swap(&mut current, &mut next);