Skip to content

Commit 3888d88

Browse files
committed
PERT: simplify calculations
The division requiring a special case factors out, and code factors down neatly. See also mc2d R package.
1 parent 3fa9809 commit 3888d88

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

rand_distr/src/pert.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,8 @@ where
9797
}
9898

9999
let range = max - min;
100-
let mu = (min + max + shape * mode) / (shape + F::from(2.).unwrap());
101-
let v = if mu == mode {
102-
shape * F::from(0.5).unwrap() + F::from(1.).unwrap()
103-
} else {
104-
(mu - min) * (F::from(2.).unwrap() * mode - min - max) / ((mode - mu) * (max - min))
105-
};
106-
let w = v * (max - mu) / (mu - min);
100+
let v = F::from(1.0).unwrap() + shape * (mode - min) / range;
101+
let w = F::from(1.0).unwrap() + shape * (max - mode) / range;
107102
let beta = Beta::new(v, w).map_err(|_| PertError::RangeTooSmall)?;
108103
Ok(Pert { min, range, beta })
109104
}

0 commit comments

Comments
 (0)