MATLAB Answers

Integration for only positive values

조회 수: 13(최근 30일)
Sim Kron
Sim Kron 18 Jun 2020
댓글: Sim Kron 19 Jun 2020
I would like to calculate the integral of an already estimated probability density function. This PDF was estimated with a SPLINE, which is "slightly" negative in certain areas. My SPLINE is saved as a "struct" and integrating it works just fine fnint(PDF). However, the resulting CDF is decreasing in those areas of negative densities, which I would like to avoid by simply replacing those areas of the PDF with 0.
My question: Is it possible to set those regions of the function equal to 0, or to integrate just over the positive values ot this PDF? I would like to avoid transforming the function into a vector of resulting densities, and instead use the (spline) function directly?
Thanks in advance!

  댓글 수: 0

댓글을 달려면 로그인하십시오.


the cyclist
the cyclist 19 Jun 2020
Can you just replace your PDF with max(0,PDF) and proceed?

  댓글 수: 9

표시 이전 댓글 수: 6
Sim Kron
Sim Kron 19 Jun 2020
@Walter Robertson Thanks for your help!
Does this command apply a function on my function? Sry, I'm new here and I don't really know what this is doing...
For your @(x) max(0, PDF(x)) command I get the message
function_handle with value: @(x)max(0,PDF(x))
How do I continue from there? Do I need to define a vector of "x-values" and apply my NNPDF on those values?
Thanks a lot for your help!
the cyclist
the cyclist 19 Jun 2020
It wasn't clear to me which field of the structure you need to modify, but for example if it is coefs,then
PDF.coefs = max(PDF.coefs,0)
Sim Kron
Sim Kron 19 Jun 2020
Sry, I made a mistake: The whole file was too large to upload, so I just uploaded the data of an arbitrary PDF. By sheer coincidence, exatly this data set doesn't exhibit any negative densities... The data set I uploaded now should include negative densities.
Concerning your comment: This command just replaces negative coefficients with 0, right? But my intention would be to replace a potential negative output of each function of the spline with 0. In my case, the different parts of the spline are linear functions, so I would like to adjust the outcome f(x) of each part of the spline and not the coefficients itself.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by