stuff
This commit is contained in:
parent
7539c90228
commit
41565e785b
7 changed files with 3268 additions and 77 deletions
|
|
@ -0,0 +1,11 @@
|
|||
{{{1, 0, 0, 0}, {0, 1, 0, 0}, {1, 1, -2, 1}, {1, 1, -3, 2}}, {{2, -3,
|
||||
1, 1}, {1, -2, 1, 1}, {0, 0, 1, 0}, {0, 0, 0, 1}}, {{0, 1, -1,
|
||||
1}, {0, 1, 0, 0}, {0, 0, 1, 0}, {1, -1, 1, 0}}, {{3, -2, -6,
|
||||
6}, {1, 0, -3, 3}, {1, -1, -2, 3}, {0, 0, 0, 1}}, {{1, 0, 0,
|
||||
0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {2, 2, 6, -1}}}
|
||||
|
||||
{-1, 3, 7, 19}
|
||||
|
||||
{{0, 1}, {2, 3}, {1, 2}, {3}, {0, 1, 2}}
|
||||
|
||||
{{0, 2}, {0, 3}, {1, 2}, {1, 3}}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
{
|
||||
{-1, 2, 2, 0},
|
||||
{0, 1, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 0, 1},
|
||||
},
|
||||
{
|
||||
{1, 0, 0, 0},
|
||||
{2, -1, 0, 2},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 0, 1},
|
||||
},
|
||||
{
|
||||
{1, 0, 0, 0},
|
||||
{0, 1, 0, 0},
|
||||
{2, 0, -1, 2},
|
||||
{0, 0, 0, 1},
|
||||
},
|
||||
{
|
||||
{1, 0, 0, 0},
|
||||
{0, 1, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 2, 2, -1},
|
||||
},
|
||||
}
|
||||
|
||||
{-2, 4, 5, 9}
|
||||
|
||||
{{1, 2, 3}, {0, 2, 3}, {0, 1, 3}, {0, 1, 2}}
|
||||
|
||||
{{0, 3}, {1, 2}}
|
||||
|
|
@ -9,7 +9,8 @@ pub fn fractal_dimension(
|
|||
upper_bound: f64,
|
||||
n: usize,
|
||||
debug: bool,
|
||||
generations: usize
|
||||
generations: usize,
|
||||
orthogonal_generators: Vec<Vec<usize>>,
|
||||
) -> Result<f64, linregress::Error> {
|
||||
let mut totals = vec![root.len(); n];
|
||||
let mut current = vec![(root, std::usize::MAX, false)];
|
||||
|
|
@ -25,8 +26,21 @@ pub fn fractal_dimension(
|
|||
next.clear();
|
||||
for (tuple, previous_generator, bad) in ¤t {
|
||||
for (i, generator) in generators.iter().enumerate() {
|
||||
let mut skip = false;
|
||||
for orthogonal_pairs in &orthogonal_generators {
|
||||
if i == orthogonal_pairs[1] && *previous_generator == orthogonal_pairs[0] {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if skip {
|
||||
continue;
|
||||
}
|
||||
if i != *previous_generator {
|
||||
let new_tuple = generator * tuple;
|
||||
if new_tuple.iter().sum::<f64>() <= tuple.iter().sum() {
|
||||
continue;
|
||||
}
|
||||
let mut add = false;
|
||||
for (j, curvature) in new_tuple.iter().enumerate() {
|
||||
let mut skip = false;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ fn main() {
|
|||
|
||||
let beginning = std::time::Instant::now();
|
||||
|
||||
let (generators, root, faces) = read_file(&opt.data_file).unwrap_or_else(|err| {
|
||||
let (generators, root, faces, orthogonal_generators) = read_file(&opt.data_file).unwrap_or_else(|err| {
|
||||
eprintln!("{}", err);
|
||||
process::exit(-1);
|
||||
});
|
||||
|
|
@ -95,10 +95,16 @@ fn main() {
|
|||
opt.data_file
|
||||
);
|
||||
println!("{:?}\n", faces);
|
||||
println!(
|
||||
"{} (parsed from file {}):",
|
||||
Yellow.paint("Orthogonal Generators"),
|
||||
opt.data_file
|
||||
);
|
||||
println!("{:?}\n", orthogonal_generators);
|
||||
}
|
||||
|
||||
let delta =
|
||||
fractal_dimension(generators, root, faces, opt.max, opt.n, debug, generations).unwrap();
|
||||
fractal_dimension(generators, root, faces, opt.max, opt.n, debug, generations, orthogonal_generators).unwrap();
|
||||
let after_computing = std::time::Instant::now();
|
||||
if time {
|
||||
let duration1 = after_computing.duration_since(after_parsing);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::fs;
|
||||
|
||||
use nalgebra::{DMatrix, DVector};
|
||||
use ansi_term::Color::Red;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum TokenType {
|
||||
|
|
@ -215,7 +216,8 @@ fn matrix_to_rust_value_flat(value: &Value) -> Result<Vec<f64>, String> {
|
|||
pub type Generator = DMatrix<f64>;
|
||||
pub type Root = DVector<f64>;
|
||||
pub type FaceList = Vec<Vec<usize>>;
|
||||
pub type Data = (Vec<Generator>, Root, FaceList);
|
||||
pub type OrthogonalGenerators = Vec<Vec<usize>>;
|
||||
pub type Data = (Vec<Generator>, Root, FaceList, OrthogonalGenerators);
|
||||
pub fn read_file(filename: &str) -> Result<Data, String> {
|
||||
let contents = match fs::read_to_string(filename) {
|
||||
Ok(contents) => contents,
|
||||
|
|
@ -245,7 +247,23 @@ pub fn read_file(filename: &str) -> Result<Data, String> {
|
|||
.map(|v| v.iter().map(|x| x.round() as usize).collect())
|
||||
.collect();
|
||||
|
||||
Ok((generators, DVector::from_column_slice(&root), faces))
|
||||
let orthogonal_generators: Vec<Vec<usize>> = if results.len() >= 3 {
|
||||
vec![]
|
||||
} else {
|
||||
matrix_to_rust_value(&results[3])?
|
||||
.iter()
|
||||
.map(|v| v.iter().map(|x| x.round() as usize).collect())
|
||||
.collect()
|
||||
};
|
||||
|
||||
for pair in &orthogonal_generators {
|
||||
if pair.len() != 2 {
|
||||
eprintln!("{}\nGot:\t{:?}", Red.paint(format!("Can only have at most two mutually orthogonal generators for now!")), pair);
|
||||
std::process::exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
Ok((generators, DVector::from_column_slice(&root), faces, orthogonal_generators))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
1942
fractal_dimension/prisms.nb
Normal file
1942
fractal_dimension/prisms.nb
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue