How to force inverse cumulative function to generate positive outputs by using ksdensity?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi!
I'm working to use the ksdensity to compute the inverse cdf. My code can be simplified as follows:
o = ksdensity(wind_data,v,'function','icdf');
In the above code, wind_data is a column vector with some zero elements (the others are positive), and v is a column vector containing probability values at which I want to evaluate the inverse cdf of wind_data.
I want to all my inverse cdfs to be non-negative. However, the above code can sometimes generate negative numbers which is impossible in reality (since the output of wind farms cannot be negative).
I have read the documentation of ksdensity, and I found there is one option named 'support' which is described as support for density.
My question is, whether this option can be specified as 'positive' when I am trying to compute the inverse cdf and thus, to force the inverse cdf to be positive? (see the code below)
o = ksdensity(wind_data,v,'function','icdf','Support','positive');
Besides, how to take into account the zero elements in the input data? Do I have to make them small positive numbers to make the 'support', 'positive' option run?
Thank you for your kind help.
0 commentaires
Réponses (1)
Sachin Lodhi
le 21 Sep 2023
Hi 元熙 吴,
Based on the information provided, it seems that the issue you are facing is related to the presence of negative numbers when evaluating the inverse cumulative distribution function (cdf) of the ‘wind_data’. This is occurring due to the presence of zeros in your data. Additionally, using the ‘Support’ option with a ‘positive’ value is not suitable when the data contains zeros, as it requires the data to be strictly positive.
To address this issue, I recommend defining your zero values as 'eps' instead. By doing so, you can create a second vector to preserve your original data while avoiding the presence of zeros. Once you have replaced the zero values with 'eps', you can then proceed to call the ksdensity function using this modified vector. This adjustment can help resolve the problem you are facing when evaluating the inverse cdf of the wind_data.
new_wind_data = wind_data;
new_wind_data(new_wind_data == 0) = eps;
o = ksdensity(new_wind_data,v,'function','icdf','Support','positive');
I recommend you to go through the following related MATLAB Answers:
I hope this helps in resolving the error.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!