This commit is contained in:
William Ball 2021-07-26 13:58:45 -04:00
parent bdd9098d28
commit 5c81993668
4 changed files with 71 additions and 54 deletions

View file

@ -1,32 +1,31 @@
{{{1., 0., 0., 0., 0., 0., 0., 0.}, {0., 1., 0., 0., 0., 0., 0.,
0.}, {1., 3., 0., -1., 2., 0., 0., 0.}, {2., 2., 0., -1., 2., 0.,
0., 0.}, {0., 0., 0., 0., 1., 0., 0., 0.}, {-1., 1., 0., 0., 1.,
0., 0., 0.}, {0., 3., 0., -1., 3., 0., 0., 0.}, {1., 2., 0., -1.,
3., 0., 0., 0.}}, {{1., 0., 0., 0., 0., 0., 0., 0.}, {1., 0.,
1., -1., 0., 0., 0., 0.}, {0., 0., 1., 0., 0., 0., 0., 0.}, {0.,
0., 0., 1., 0., 0., 0., 0.}, {4., 0., 2., 0., -1., 0., 0.,
0.}, {4., 0., 3., -1., -1., 0., 0., 0.}, {3., 0., 3., 0., -1., 0.,
0., 0.}, {3., 0., 2., 1., -1., 0., 0., 0.}}, {{1., 0., 0., 0., 0.,
0., 0., 0.}, {4., -1., 0., 0., 0., 0., 0., 2.}, {4., -1., 0.,
0., -1., 0., 0., 3.}, {1., 0., 0., 0., -1., 0., 0., 1.}, {0., 0.,
0., 0., 1., 0., 0., 0.}, {3., -1., 0., 0., 1., 0., 0.,
2.}, {3., -1., 0., 0., 0., 0., 0., 3.}, {0., 0., 0., 0., 0., 0.,
0., 1.}}, {{-1., 2., 2., 0., 0., 2., 0., 0.}, {0., 1., 0., 0., 0.,
0., 0., 0.}, {0., 0., 1., 0., 0., 0., 0., 0.}, {-1., 1., 3., 0.,
0., 2., 0., 0.}, {-1., 1., 2., 0., 0., 3., 0., 0.}, {0., 0., 0.,
0., 0., 1., 0., 0.}, {0., -1., 1., 0., 0., 1., 0., 0.}, {-1., 0.,
3., 0., 0., 3., 0., 0.}}, {{0., -1., 0., 4., 0., 0.,
3., -1.}, {0., -1., 0., 4., 0., 0., 4., -2.}, {0., 0., 0., 1., 0.,
0., 1., -1.}, {0., 0., 0., 1., 0., 0., 0., 0.}, {0., -1., 0., 3.,
0., 0., 3., 0.}, {0., -1., 0., 3., 0., 0., 4., -1.}, {0., 0., 0.,
0., 0., 0., 1., 0.}, {0., 0., 0., 0., 0., 0., 0., 1.}}, {{0., -1.,
0., 0., 0., 4., -1., 3.}, {0., -1., 0., 0., 0., 4., 0.,
2.}, {0., -1., 0., 0., 0., 3., 1., 2.}, {0., -1., 0., 0., 0., 3.,
0., 3.}, {0., 0., 0., 0., 0., 1., -1., 1.}, {0., 0., 0., 0., 0.,
1., 0., 0.}, {0., 0., 0., 0., 0., 0., 1., 0.}, {0., 0., 0., 0., 0.,
0., 0., 1.}}}
{{{2., 1., 2.8284271247461903, 0.}, {1., 2.,
2.8284271247461903,
0.}, {-1.4142135623730951, -1.4142135623730951, -3.,
0.}, {0., 0., 0., 1.}}, {{18., 1., 8.485281374238571,
0.}, {289., 18., 144.2497833620557,
0.}, {-72.12489168102785, -4.242640687119286, -35., 0.}, {0.,
0., 0., 1.}}, {{1., 0., 0., 0.}, {4., 1.,
0., -4.}, {0., 0., 1., 0.}, {2., 0., 0., -1.}}, {{1.,
0., 0., 0.}, {4., 1., 0., 4.}, {0., 0., 1., 0.}, {-2.,
0., 0., -1.}}, {{33., 4., 22.627416997969522, 4.}, {256.,
33., 181.01933598375618,
32.}, {-90.50966799187809, -11.313708498984761, -63.,
-11.313708498984761}, {-16., -2., -11.313708498984761, -1.}},
{{33., 4., 22.627416997969522, -4.}, {256., 33.,
181.01933598375618, -32.}, {-90.50966799187809,
-11.313708498984761, -63., 11.313708498984761}, {16., 2.,
11.313708498984761, -1.}}}
{-1, 4, 7, 2, 7, 12, 15, 10}
{{0., 8.485281374238571, -1., 0.}, {0., -2.8284271247461903,
1., 0.}, {1.4142135623730951, 18.38477631085024, -5.,
1.4142135623730951}, {1.4142135623730951,
7.0710678118654755, -3.,
1.4142135623730951}, {1.4142135623730951,
18.38477631085024, -5., -1.4142135623730951},
{1.4142135623730951,
7.0710678118654755, -3., -1.4142135623730951},
{2.8284271247461903, 16.970562748477143, -7.,
0.}, {2.8284271247461903, 28.284271247461902, -9., 0.}}
{{0, 1, 5, 4}, {0, 3, 2, 1}, {0, 4, 7, 3}, {1, 2, 6, 5}, {2, 3, 7,
6}, {4, 5, 6, 7}}

View file

@ -1,15 +1,28 @@
{{{1.33333, 1.16068, -2.1547, -1.24402}, {0.095729,
1.33333, -0.618802, -0.357266}, {0.309401,
1.07735, -1., -1.1547}, {0.178633, 0.622008, -1.1547,
0.333333}}, {{1.33333, 1.16068, 2.1547, -1.24402}, {0.095729,
1.33333, 0.618802, -0.357266}, {-0.309401, -1.07735, -1.,
1.1547}, {0.178633, 0.622008, 1.1547, 0.333333}}, {{0., 0.25, 0.,
{{{1.3333333333333333,
1.160683602522959, -2.1547005383792515, -1.2440169358562922},
{0.09572902629932163,
1.3333333333333333, -0.6188021535170058, -0.3572655899081637},
{0.3094010767585029,
1.0773502691896257, -1., -1.1547005383792517},
{0.17863279495408185, 0.6220084679281461, -1.1547005383792517,
0.3333333333333333}}, {{1.3333333333333333, 1.160683602522959,
2.1547005383792515, -1.2440169358562922}, {0.09572902629932163,
1.3333333333333333,
0.6188021535170058, -0.3572655899081637}, {-0.3094010767585029,
-1.0773502691896257, -1.,
1.1547005383792517}, {0.17863279495408185, 0.6220084679281461,
1.1547005383792517, 0.3333333333333333}}, {{0., 0.25, 0.,
0.}, {4., 0., 0., 0.}, {0., 0., 1., 0.}, {0., 0., 0.,
1.}}, {{1.33333, 1.16068, 0., 2.48803}, {0.095729, 1.33333, 0.,
0.714531}, {0., 0., 1., 0.}, {-0.357266, -1.24402, 0., -1.66667}}}
1.}}, {{1.3333333333333333, 1.160683602522959, 0.,
2.4880338717125845}, {0.09572902629932163, 1.3333333333333333,
0., 0.7145311798163274}, {0., 0., 1.,
0.}, {-0.3572655899081637, -1.2440169358562922,
0., -1.6666666666666667}}}
{{-1.86603, 0.535898, 0., 0.}, {0.288675, 1.1547, 0.,
1.1547}, {0.288675, 1.1547, 1., -0.57735}, {0.288675,
1.1547, -1., -0.57735}}
{{1.8660254037844386, -0.5358983848622456, 0.,
0.}, {0.2886751345948129, 1.1547005383792517, 0.,
1.1547005383792517}, {0.2886751345948129, 1.1547005383792517,
1., -0.5773502691896258}, {0.2886751345948129,
1.1547005383792517, -1., -0.5773502691896258}}
{{1, 2, 3}, {0, 2, 3}, {0, 1, 3}, {0, 1, 2}}

View file

@ -11,15 +11,15 @@ pub fn fractal_dimension(
n: usize,
debug: bool,
generations: usize,
orthogonal_generators: Vec<Vec<usize>>,
_orthogonal_generators: Vec<Vec<usize>>,
) -> Result<f64, linregress::Error> {
let xs: Vec<f64> = (1..=n)
.map(|x| (x as f64 * upper_bound / (2.0 * n as f64) + upper_bound / 2.0))
.collect();
let mut searcher = Searcher::new(&xs, &generators);
let mut searcher = Searcher::new(&xs, &generators, generations, root.len() as u64);
for circle in root {
searcher.search(&circle, std::usize::MAX, 0, generations);
searcher.search(&circle, std::usize::MAX, 0);
}
if debug {

View file

@ -4,25 +4,28 @@ pub struct Searcher<'a> {
pub counts: Vec<u64>,
maxes: &'a Vec<f64>,
generators: &'a Vec<DMatrix<f64>>,
max_depth: usize,
tolerance: f64,
}
impl<'a> Searcher<'a> {
pub fn new(maxes: &'a Vec<f64>, generators: &'a Vec<DMatrix<f64>>) -> Self {
pub fn new(
maxes: &'a Vec<f64>,
generators: &'a Vec<DMatrix<f64>>,
max_depth: usize,
n: u64,
) -> Self {
Self {
counts: vec![0; maxes.len()],
counts: vec![n; maxes.len()],
maxes,
generators,
max_depth,
tolerance: 1e-4,
}
}
pub fn search(
&mut self,
circle: &DVector<f64>,
previous_generator: usize,
generations: usize,
max_generations: usize,
) {
if generations > max_generations {
pub fn search(&mut self, circle: &DVector<f64>, previous_generator: usize, depth: usize) {
if self.max_depth > 0 && depth > self.max_depth {
return;
}
for (i, generator) in self.generators.iter().enumerate() {
@ -31,7 +34,9 @@ impl<'a> Searcher<'a> {
{
let mut seen = false;
for (j, max) in self.maxes.iter().enumerate() {
if seen || new_circle[1] > circle[1] && circle[1] < *max {
if seen
|| new_circle[1] - circle[1] > self.tolerance && new_circle[1] < *max
{
seen = true;
self.counts[j] += 1;
}
@ -40,7 +45,7 @@ impl<'a> Searcher<'a> {
continue;
}
} // ensure seen is dropped before recursive call to minimize stack frame size
self.search(&new_circle, i, generations + 1, max_generations);
self.search(&new_circle, i, depth + 1);
}
}
}