- tests register1 and register2 passing
This commit is contained in:
1 parent
806571be82
commit
5b7dc18a4d
5 files changed
+887
-114
No files matched your search
+17
-18
@@ -152,7 +152,7 @@ fn parzen(
|
||||
|
||||
enum Sampling {
|
||||
Fixed(Vec<Vec<f64>>),
|
||||
Random((usize, Vec<f64>)),
|
||||
Random((usize, Vec<f64>, RefCell<Vec<Vec<f64>>>)),
|
||||
}
|
||||
|
||||
impl Sampling {
|
||||
@@ -161,19 +161,21 @@ impl Sampling {
|
||||
}
|
||||
|
||||
fn random(n_samples: usize, shape: Vec<f64>) -> Self {
|
||||
Self::Random((n_samples, shape))
|
||||
Self::Random((n_samples, shape, RefCell::new(Vec::new())))
|
||||
}
|
||||
|
||||
fn index(&self) -> Vec<Vec<f64>> {
|
||||
match self {
|
||||
Self::Fixed(index) => index.clone(),
|
||||
Self::Random((n_samples, shape)) => rand::rng()
|
||||
.random_iter::<f64>()
|
||||
.take(n_samples * shape.len())
|
||||
.chunks(shape.len())
|
||||
.into_iter()
|
||||
.map(|c| c.zip_eq(shape.iter()).map(|(i, s)| i * s - 0.5).collect())
|
||||
.collect(),
|
||||
Self::Random((n_samples, shape, _cached)) => {
|
||||
rand::rng()
|
||||
.random_iter::<f64>()
|
||||
.take(n_samples * shape.len())
|
||||
.chunks(shape.len())
|
||||
.into_iter()
|
||||
.map(|c| c.zip_eq(shape.iter()).map(|(i, s)| i * s - 0.5).collect())
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,6 +242,7 @@ where
|
||||
.into_option()
|
||||
.expect("m and f cannot be empty");
|
||||
let minmax = [*min, *max];
|
||||
let ndim = shape.len();
|
||||
let sampling = match sampling {
|
||||
SamplingArg::Fixed(n_samples) => {
|
||||
Sampling::fixed(Sampling::random(n_samples, shape.clone()).index())
|
||||
@@ -253,7 +256,7 @@ where
|
||||
center,
|
||||
fixed,
|
||||
moving,
|
||||
fixed_mu: FixedMu::new_none(sampling.index().len()),
|
||||
fixed_mu: FixedMu::new_none(ndim),
|
||||
minmax,
|
||||
sampling,
|
||||
n_bins,
|
||||
@@ -319,7 +322,7 @@ where
|
||||
let f = fixed.evaluate_at_continuous_index(&u, mem_f)?;
|
||||
let (m, d) = moving
|
||||
.evaluate_value_and_derivative_at_continuous_index(&v, mem_m)?;
|
||||
let j = fixed_mu.extract_variable(&image_jacobian(&v, center, &d));
|
||||
let j = fixed_mu.extract_variable(&image_jacobian(&u, center, &d));
|
||||
let mut k;
|
||||
let mut w = 1.0;
|
||||
let mut ws = Vec::with_capacity(shape.len());
|
||||
@@ -347,7 +350,7 @@ where
|
||||
for (dwi, wi) in dw.iter_mut().zip(ws) {
|
||||
*dwi *= w / wi;
|
||||
}
|
||||
let dw = fixed_mu.extract_variable(&image_jacobian(&v, center, &dw));
|
||||
let dw = fixed_mu.extract_variable(&image_jacobian(&u, center, &dw));
|
||||
Ok(Some((f, ((m, j), (w, dw)))))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -435,12 +438,8 @@ where
|
||||
|
||||
self.metric.replace(IntMut {
|
||||
mu: mu.to_vec(),
|
||||
metric: metric * alpha,
|
||||
derivative: dmetric
|
||||
.iter()
|
||||
.zip_eq(dalpha)
|
||||
.map(|(dm, da)| *dm * alpha + da * metric)
|
||||
.collect(),
|
||||
metric: metric,
|
||||
derivative: dmetric.clone(),
|
||||
});
|
||||
// self.metric.replace(IntMut {
|
||||
// mu: mu.to_vec(),
|
||||
|
||||
Reference in new issue
Block a user