Skip to content

Commit

Permalink
modified: src/fitter/gaussian.rs
Browse files Browse the repository at this point in the history
	modified:   src/histoer/histogram1d.rs
  • Loading branch information
alconley committed May 22, 2024
1 parent 663ec5d commit a3e0e30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/fitter/gaussian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ impl GaussianFitter {
}
}

fn linear(x: &DVector<f64>, b: f64) -> DVector<f64> {
x.map(|x_val| (x_val * b ))
}

fn linear_pd(x: &DVector<f64>, b: f64) -> DVector<f64> {

Check failure on line 92 in src/fitter/gaussian.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused variable: `b`

Check warning on line 92 in src/fitter/gaussian.rs

View workflow job for this annotation

GitHub Actions / Check

unused variable: `b`

Check warning on line 92 in src/fitter/gaussian.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `b`
x.map(|x_val| ( x_val ))
}

fn gaussian(x: &DVector<f64>, mean: f64, sigma: f64) -> DVector<f64> {
x.map(|x_val| (-((x_val - mean).powi(2)) / (2.0 * sigma.powi(2))).exp())
}
Expand Down Expand Up @@ -150,6 +158,8 @@ impl GaussianFitter {
let mut builder_proxy = SeparableModelBuilder::<f64>::new(parameter_names)
.initial_parameters(initial_guess)
.independent_variable(x_data)
.function(&["b"], Self::linear)
.partial_deriv("b", Self::linear_pd)
.function(&["mean0", "sigma"], Self::gaussian)
.partial_deriv("mean0", Self::gaussian_pd_mean)
.partial_deriv("sigma", Self::gaussian_pd_std_dev);
Expand Down
6 changes: 3 additions & 3 deletions src/histoer/histogram1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::fitter::fitter::{FitModel, Fitter};
pub struct PlotSettings {
#[serde(skip)]
pub cursor_position: Option<egui_plot::PlotPoint>,

pub info: bool,
pub color: egui::Color32,
}
Expand Down Expand Up @@ -249,7 +248,7 @@ impl Histogram {

// get background subtracted data
let x_data = self.get_bin_centers_between(self.markers.region_markers[0], self.markers.region_markers[1]);
let mut y_data = self.get_bin_counts_between(self.markers.region_markers[0], self.markers.region_markers[1]);
let y_data = self.get_bin_counts_between(self.markers.region_markers[0], self.markers.region_markers[1]);

let mut fitter = Fitter::new(FitModel::Gaussian(peak_positions));
fitter.x_data = x_data;
Expand Down Expand Up @@ -324,7 +323,8 @@ impl Histogram {
.allow_zoom(false)
.allow_boxed_zoom(true)
.auto_bounds(egui::Vec2b::new(true, true))
.allow_scroll(false);
.allow_scroll(false)
.show_grid(false);

let color = if ui.ctx().style().visuals.dark_mode {
egui::Color32::LIGHT_BLUE
Expand Down

0 comments on commit a3e0e30

Please sign in to comment.