use crate::PenaltyMatrix;
use crate::block_spec::ParameterBlockSpec;
use gam_linalg::matrix::{DenseDesignMatrix, DesignMatrix};
use ndarray::{Array1, Array2, array};
pub struct BinomialLocationScaleBaseFixture {
pub n: usize,
pub y: Array1<f64>,
pub weights: Array1<f64>,
pub threshold_design: DesignMatrix,
pub log_sigma_design: DesignMatrix,
pub threshold_spec: ParameterBlockSpec,
pub log_sigma_spec: ParameterBlockSpec,
}
pub fn binomial_location_scale_base_fixture() -> BinomialLocationScaleBaseFixture {
let n = 7usize;
let y = Array1::from_vec(vec![0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0]);
let weights = Array1::from_vec(vec![1.0; n]);
let threshold_design =
DesignMatrix::Dense(DenseDesignMatrix::from(Array2::from_elem((n, 1), 1.0)));
let log_sigma_design =
DesignMatrix::Dense(DenseDesignMatrix::from(Array2::from_elem((n, 1), 1.0)));
let threshold_spec = ParameterBlockSpec {
name: "threshold".to_string(),
design: threshold_design.clone(),
offset: Array1::zeros(n),
penalties: vec![PenaltyMatrix::Dense(Array2::eye(1))],
nullspace_dims: vec![],
initial_log_lambdas: array![0.0],
initial_beta: Some(array![0.2]),
gauge_priority: 100,
jacobian_callback: None,
stacked_design: None,
stacked_offset: None,
};
let log_sigma_spec = ParameterBlockSpec {
name: "log_sigma".to_string(),
design: log_sigma_design.clone(),
offset: Array1::zeros(n),
penalties: vec![PenaltyMatrix::Dense(Array2::eye(1))],
nullspace_dims: vec![],
initial_log_lambdas: array![-0.2],
initial_beta: Some(array![-0.1]),
gauge_priority: 100,
jacobian_callback: None,
stacked_design: None,
stacked_offset: None,
};
BinomialLocationScaleBaseFixture {
n,
y,
weights,
threshold_design,
log_sigma_design,
threshold_spec,
log_sigma_spec,
}
}
pub fn spec_from_dense(name: &str, design: Array2<f64>) -> ParameterBlockSpec {
let n = design.nrows();
ParameterBlockSpec {
name: name.to_string(),
design: DesignMatrix::Dense(DenseDesignMatrix::from(design)),
offset: Array1::<f64>::zeros(n),
penalties: Vec::new(),
nullspace_dims: Vec::new(),
initial_log_lambdas: Array1::<f64>::zeros(0),
initial_beta: None,
gauge_priority: 100,
jacobian_callback: None,
stacked_design: None,
stacked_offset: None,
}
}
pub fn spec_from_dense_with_priority(
name: &str,
design: Array2<f64>,
priority: u8,
) -> ParameterBlockSpec {
let mut s = spec_from_dense(name, design);
s.gauge_priority = priority;
s
}