Advertisement
Danila_lipatov

distribution_from_fitter

Nov 14th, 2023 (edited)
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.86 KB | None | 0 0
  1. """
  2. If it will be helpful, please like this post
  3. """
  4. #https://stats.stackexchange.com/questions/302774/does-uniform-distribution-belong-to-location-and-scale-familya
  5. def get_upd_distr(dict_: dict):
  6.     full_dict = {}
  7.     for key, values in dict_.items():
  8.         if key not in full_dict:
  9.             full_dict[key] = {}
  10.         if key == "norm":
  11.             if 'mean' not in full_dict[key]:
  12.                 full_dict[key]['mean'] = values[0]
  13.             if 'sd' not in full_dict[key]:
  14.                 full_dict[key]['sd'] = values[1]
  15.  
  16.         if key == "cauchy":
  17.             #https://www.itl.nist.gov/div898/handbook/eda/section3/eda3663.htm
  18.             if 't' not in full_dict[key]:
  19.                 full_dict[key]['t'] = values[0]
  20.             if 's' not in full_dict[key]:
  21.                 full_dict[key]['s'] = values[1]
  22.  
  23.         if key == 'expon':
  24.             if 'Xmin' not in full_dict[key]:
  25.                 full_dict[key]['Xmin'] = values[0]
  26.             if '1/lambda' not in full_dict[key]:
  27.                 full_dict[key]['1/lambda'] = values[1]
  28.  
  29.         if key == "chi2":
  30.             #https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
  31.             #https://web.ma.utexas.edu/users/mks/M358KInstr/tDistandDF.pdf
  32.  
  33.             if 'df' not in full_dict[key]:
  34.                 full_dict[key]['df'] = values[0]
  35.             if 'mean' not in full_dict[key]:
  36.                 full_dict[key]['mean'] = values[1]
  37.             if 'sd' not in full_dict[key]:
  38.                 full_dict[key]['sd'] = values[2]
  39.  
  40.  
  41.         if key == "lognorm":
  42.             #https://statisticsbyjim.com/probability/lognormal-distribution/
  43.             #https://stackoverflow.com/questions/8747761/scipy-lognormal-distribution-parameters
  44.             if 'sd' not in full_dict[key]:
  45.                 full_dict[key]['sd'] = values[0]
  46.             if 'mean' not in full_dict[key]:
  47.                 full_dict[key]['mean'] = values[1]
  48.             if 'alpha' not in full_dict[key]:
  49.                 full_dict[key]['alpha'] = values[2]
  50.  
  51.         if key == 'uniform':
  52.             #https://statisticsbyjim.com/probability/gamma-distribution/
  53.             if 'a' not in full_dict[key]:
  54.                 full_dict[key]['a'] = values[0]
  55.             if '|b-a|' not in full_dict[key]:
  56.                 full_dict[key]['|b-a|'] = values[1]
  57.  
  58.         if key == 'rayleigh':
  59.             #https://anylogic.help/advanced/functions/rayleigh.html
  60.             #https://stats.stackexchange.com/questions/224416/parameter-estimation-of-a-rayleigh-random-variable-with-an-offset --useful
  61.             if 'mean' not in full_dict[key]:
  62.                 full_dict[key]['mean'] = values[0]
  63.             if 'sd' not in full_dict[key]:
  64.                 full_dict[key]['sd'] = values[1]
  65.  
  66.         if key == 'powerlaw':   #TODO understand what is it
  67.             if 'alpha' not in full_dict[key]:
  68.                 full_dict[key]['alpha'] = values[0]
  69.  
  70.             if 'Xmin' not in full_dict[key]:
  71.                 full_dict[key]['Xmin'] = values[1]
  72.             if 'D' not in full_dict[key]:
  73.                 full_dict[key]['D'] = values[2]
  74.  
  75.         if key == 'exponpow':   #TODO understand what is it
  76.             if 'b' not in full_dict[key]:
  77.                 full_dict[key]['b'] = values[0]
  78.             if 'loc' not in full_dict[key]:
  79.                 full_dict[key]['loc'] = values[1]
  80.             if 'scale' not in full_dict[key]:
  81.                 full_dict[key]['scale'] = values[2]
  82.  
  83.         if key == 'gamma':
  84.             #https://stackoverflow.com/questions/2896179/fitting-a-gamma-distribution-with-python-scipy
  85.             #https://statisticsbyjim.com/probability/gamma-distribution/
  86.             #https://en.wikipedia.org/wiki/Gamma_distribution
  87.             #https://pythonguides.com/python-scipy-stats-fit/
  88.             if 'alpha' not in full_dict[key]:
  89.                 full_dict[key]['alpha'] = values[0]
  90.             if 'loc' not in full_dict[key]:
  91.                 full_dict[key]['loc'] = values[1]
  92.             if 'beta' not in full_dict[key]:
  93.                 full_dict[key]['beta'] = values[2]
  94.  
  95.         if key == 'beta':
  96.             # https://stats.stackexchange.com/questions/68983/beta-distribution-fitting-in-scipy
  97.  
  98.             if 'alpha' not in full_dict[key]:
  99.                 full_dict[key]['alpha'] = values[0]
  100.             if 'beta' not in full_dict[key]:
  101.                 full_dict[key]['beta'] = values[1]
  102.             if 'lower limit' not in full_dict[key]:
  103.                 full_dict[key]['lower limit'] = values[2]
  104.             if 'upper limit - lower limit' not in full_dict[key]:
  105.                 full_dict[key]['upper limit - lower limit'] = values[3]
  106.         if key == 'burr':
  107.             """
  108.            In terms of mathematical statistics, the loc and scale parameters for the Burr distribution correspond to the shift and scale parameters.
  109.  
  110.            The loc parameter represents a shift (or offset) of the distribution along the axis of values. If loc is a, then the distribution will be shifted by a units to the right (positive value) or to the left (negative value).
  111.            The scale parameter represents the scale that affects the spread of the data. If scale is equal to b, then the distribution will be scaled along the axis of values.
  112.            So you can rewrite the values of loc and scale in terms of mathematical statistics as follows:
  113.  
  114.            Shift (loc):μ=loc
  115.  
  116.            Scale (scale):σ=scale
  117.  
  118.            Here
  119.            μ is the mean (shift), and σ is the standard deviation (scale).
  120.            """
  121.             if 'c' not in full_dict[key]:
  122.                 full_dict[key]['c'] = values[0]
  123.             if 'd' not in full_dict[key]:
  124.                 full_dict[key]['d'] = values[1]
  125.             if 'mean' not in full_dict[key]:
  126.                 full_dict[key]['mean'] = values[2]
  127.             if 'sd' not in full_dict[key]:
  128.                 full_dict[key]['sd'] = values[3]
  129.  
  130.     return full_dict
  131.  
  132.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement