0

I am trying to calculate the false positive and false negative rate using matlab. I have generated an s-curve, with a threshold (vertical line that cuts the curve at some point). All values under the curve to the left of the threshold are false-positives and all values not under the curve to the right of the threshold are false-negatives. I would have to integrate the areas under the curve for the false positives and area_of_rect_to_right_of_threshold - (area under curve to right of threshold) to calculate false negatives. I am getting a weird error when I try the following code in matlab.

    syms p;
    func = (1 - (1 - p^5)^10);
    areaOfRect = (1-threshold)*1; 
    fn = areaOfRect - int(func,p,0,threshold);
    fp = int(func,p,threshold,1);


fn = 2575908626830580620307480425353828014939901186516550645854841225649977931806217173152793134129 ......

fp = 20989145492538166675017041353401970126067731601439729556868060737768716969716535384....

These outputs are very peculiar which makes me feel I'm not using the integrate function in the right way. Any help would be much appreciated.

anonuser0428
  • 11,789
  • 22
  • 63
  • 86

2 Answers2

3

Looks like you are just getting the exact solutions in rational form a/b, the evaluation to floating point should match the numerical integrations

fn_sym = double(fn)
fn_num = areaOfRect - quadl(@(p)(1 - (1 - p.^5).^10),0.01,threshold)
fp_sym = double(fp)
fp_num = quadl(@(p)(1 - (1 - p.^5).^10),threshold,1.01)
Iban Cereijo
  • 1,675
  • 1
  • 15
  • 28
  • 1
    Use `double` instead of `eval`. `eval` should be avoided whenever possible. – Daniel Mar 15 '14 at 00:35
  • so all I needed to do was I guess cast the fp and fn values to double? Ya and thanks for the check method. They both match indeed. – anonuser0428 Mar 15 '14 at 01:38
0

Your text description says: "All values under the curve to the left of the threshold are false-positives" but your code calculates the integral from your threshold to 1.01, which is the right side. I can't judge which is correct.

Daniel
  • 36,610
  • 3
  • 36
  • 69