Skip to content

Commit

Permalink
fix(lib): adapt to upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Aug 19, 2016
1 parent a89dd2c commit 350bcaa
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 158 deletions.
8 changes: 5 additions & 3 deletions src/analysis/compare.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use stats::ttest::{TDistribution, TwoTailed};
use stats::ttest::{TDistribution, Tails};
use stats::{Stats, mod};
use time;

use Criterion;
use estimate::{Distributions, Estimate, Estimates, Mean, Median};
use estimate::Statistic::{Mean, Median};
use estimate::{Distributions, Estimate, Estimates};
use format;
use fs;
use plot;
use report;
use self::ComparisonResult::{Improved, NonSignificant, Regressed};

// Common comparison procedure
pub fn common(
Expand Down Expand Up @@ -67,7 +69,7 @@ fn t_test(id: &str, times: &[f64], base_times: &[f64], criterion: &Criterion) ->
let t_distribution = elapsed!(
"Bootstrapping the T distribution",
TDistribution::new(times, base_times, nresamples));
let p_value = t_distribution.p_value(t_statistic, TwoTailed);
let p_value = t_distribution.p_value(t_statistic, Tails::Two);
let different_mean = p_value < sl;

println!(" > p = {}", p_value);
Expand Down
18 changes: 10 additions & 8 deletions src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ use estimate::{
Distributions,
Estimate,
Estimates,
Mean,
Median,
MedianAbsDev,
StdDev,
mod,
};
use estimate::Statistic;
use format;
use fs;
use plot;
Expand Down Expand Up @@ -119,8 +115,8 @@ fn common<R: Routine>(id: &str, routine: &mut R, criterion: &Criterion) {
let (distribution, slope) = regression(id, pairs_f64, criterion);
let (mut distributions, mut estimates) = estimates(times, criterion);

estimates.insert(estimate::Slope, slope);
distributions.insert(estimate::Slope, distribution);
estimates.insert(Statistic::Slope, slope);
distributions.insert(Statistic::Slope, distribution);

if criterion.plotting.is_enabled() {
elapsed!(
Expand Down Expand Up @@ -235,7 +231,13 @@ fn estimates(

vec![a, b, c, d]
};
let distributions: Distributions = [Mean, Median, MedianAbsDev, StdDev].iter().map(|&x| {
let statistics = [
Statistic::Mean,
Statistic::Median,
Statistic::MedianAbsDev,
Statistic::StdDev,
];
let distributions: Distributions = statistics.iter().map(|&x| {
x
}).zip(distributions.into_iter()).collect();
let estimates = Estimate::new(&distributions, points[], cl);
Expand Down
10 changes: 5 additions & 5 deletions src/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ pub enum Statistic {
impl Show for Statistic {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self {
Mean => f.pad("mean"),
Median => f.pad("median"),
MedianAbsDev => f.pad("MAD"),
Slope => f.pad("slope"),
StdDev => f.pad("SD"),
Statistic::Mean => f.pad("mean"),
Statistic::Median => f.pad("median"),
Statistic::MedianAbsDev => f.pad("MAD"),
Statistic::Slope => f.pad("slope"),
Statistic::StdDev => f.pad("SD"),
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ enum Plotting {
impl Plotting {
fn is_enabled(&self) -> bool {
match *self {
Enabled => true,
Plotting::Enabled => true,
_ => false,
}
}
Expand All @@ -111,11 +111,11 @@ impl Criterion {
#[experimental]
pub fn default() -> Criterion {
let plotting = if simplot::version().is_ok() {
Enabled
Plotting::Enabled
} else {
println!("Gnuplot not found, disabling plotting");

NotAvailable
Plotting::NotAvailable
};

Criterion {
Expand Down Expand Up @@ -255,8 +255,8 @@ impl Criterion {
#[experimental]
pub fn with_plots(&mut self) -> &mut Criterion {
match self.plotting {
NotAvailable => {},
_ => self.plotting = Enabled,
Plotting::NotAvailable => {},
_ => self.plotting = Plotting::Enabled,
}

self
Expand All @@ -266,8 +266,8 @@ impl Criterion {
#[experimental]
pub fn without_plots(&mut self) -> &mut Criterion {
match self.plotting {
NotAvailable => {},
_ => self.plotting = Disabled,
Plotting::NotAvailable => {},
_ => self.plotting = Plotting::Disabled,
}

self
Expand All @@ -276,7 +276,7 @@ impl Criterion {
/// Checks if plotting is possible
pub fn can_plot(&self) -> bool {
match self.plotting {
NotAvailable => false,
Plotting::NotAvailable => false,
_ => true,
}
}
Expand Down
41 changes: 20 additions & 21 deletions src/plot/both.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use simplot::axis::{BottomX, LeftY, RightY};
use simplot::curve::Lines;
use simplot::grid::Major;
use simplot::key::{Inside, Left, LeftJustified, Outside, Right, SampleText, Top};
use simplot::{Figure, Solid};
use simplot::curve::Style::{Lines};
use simplot::key::{Horizontal, Justification, Order, Position, Vertical};
use simplot::{Axis, Figure, Grid, LineType};
use stats::ConfidenceInterval;
use std::iter::Repeat;
use std::num::Float;
use std::str;
use test::stats::Stats;

use estimate::{Estimate, Estimates, Slope};
use estimate::{Estimate, Estimates};
use estimate::Statistic::Slope;
use kde;
use super::scale_time;
use super::{DARK_BLUE, DARK_RED};
Expand Down Expand Up @@ -82,19 +81,19 @@ pub fn regression(
output(path).
size(PLOT_SIZE).
title(id.to_string()).
axis(BottomX, |a| a.
grid(Major, |g| g.
axis(Axis::BottomX, |a| a.
grid(Grid::Major, |g| g.
show()).
// FIXME (unboxed closures) remove cloning
label(x_label.to_string())).
axis(LeftY, |a| a.
grid(Major, |g| g.
axis(Axis::LeftY, |a| a.
grid(Grid::Major, |g| g.
show()).
label(format!("Total time ({}s)", prefix))).
key(|k| k.
justification(LeftJustified).
order(SampleText).
position(Inside(Top, Left))).
justification(Justification::Left).
order(Order::SampleText).
position(Position::Inside(Vertical::Top, Horizontal::Left))).
filled_curve([0., max_iters].iter(), [0., base_lb].iter(), [0., base_ub].iter(), |c| c.
color(DARK_RED).
opacity(0.25)).
Expand All @@ -104,12 +103,12 @@ pub fn regression(
curve(Lines, [0., max_iters].iter(), [0., base_point].iter(), |c| c.
color(DARK_RED).
label("Base sample").
line_type(Solid).
line_type(LineType::Solid).
linewidth(2.)).
curve(Lines, [0., max_iters].iter(), [0., new_point].iter(), |c| c.
color(DARK_BLUE).
label("New sample").
line_type(Solid).
line_type(LineType::Solid).
linewidth(2.)).
draw().unwrap();

Expand Down Expand Up @@ -137,16 +136,16 @@ pub fn pdfs(base: &[f64], new: &[f64], id: &str) {
output(path).
size(PLOT_SIZE).
title(id.to_string()).
axis(BottomX, |a| a.
axis(Axis::BottomX, |a| a.
label(format!("Average time ({}s)", prefix))).
axis(LeftY, |a| a.
axis(Axis::LeftY, |a| a.
label("Density (a.u.)")).
axis(RightY, |a| a.
axis(Axis::RightY, |a| a.
hide()).
key(|k| k.
justification(LeftJustified).
order(SampleText).
position(Outside(Top, Right))).
justification(Justification::Left).
order(Order::SampleText).
position(Position::Outside(Vertical::Top, Horizontal::Right))).
filled_curve(base_xs, base_ys, zeros, |c| c.
color(DARK_RED).
label("Base PDF").
Expand Down
Loading

0 comments on commit 350bcaa

Please sign in to comment.