mailr19879 - in /branches/relax_disp: ./ lib/statistics.py test_suite/shared_data/relaxation_data/white_noise/


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on June 05, 2013 - 23:16:
Author: bugman
Date: Wed Jun  5 23:16:07 2013
New Revision: 19879

URL: http://svn.gna.org/viewcvs/relax?rev=19879&view=rev
Log:
Merged revisions 19875-19878 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk

........
  r19875 | bugman | 2013-06-05 22:24:22 +0200 (Wed, 05 Jun 2013) | 7 lines
  
  Added some more functions to the lib.statistics module.
  
  These include the bucket() function for creating a discrete distribution 
from a list of floating
  point numbers, and the gaussian() function for calculating the probability 
of a point on a Gaussian
  distribution.
........
  r19876 | bugman | 2013-06-05 22:31:56 +0200 (Wed, 05 Jun 2013) | 5 lines
  
  Added a directory and files for testing the white noise in relaxation data.
  
  This includes scripts and graphs.
........
  r19877 | bugman | 2013-06-05 22:33:35 +0200 (Wed, 05 Jun 2013) | 3 lines
  
  Removed a useless junk script.
........
  r19878 | bugman | 2013-06-05 22:42:14 +0200 (Wed, 05 Jun 2013) | 5 lines
  
  The initial parameters are now the real parameter rather than the optimised 
ones.
  
  This is for the script for testing white noise in relaxation data.
........

Added:
    branches/relax_disp/test_suite/shared_data/relaxation_data/white_noise/
      - copied from r19878, 
trunk/test_suite/shared_data/relaxation_data/white_noise/
Modified:
    branches/relax_disp/   (props changed)
    branches/relax_disp/lib/statistics.py

Propchange: branches/relax_disp/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed Jun  5 23:16:07 2013
@@ -1,1 +1,1 @@
-/trunk:1-19871
+/trunk:1-19878

Modified: branches/relax_disp/lib/statistics.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/lib/statistics.py?rev=19879&r1=19878&r2=19879&view=diff
==============================================================================
--- branches/relax_disp/lib/statistics.py (original)
+++ branches/relax_disp/lib/statistics.py Wed Jun  5 23:16:07 2013
@@ -23,7 +23,77 @@
 """Module for calculating simple statistics."""
 
 # Python module imports.
-from math import sqrt
+from math import exp, pi, sqrt
+
+
+def bucket(values=None, lower=0.0, upper=200.0, inc=100, verbose=False):
+    """Generate a discrete probability distribution for the given values.
+
+    @keyword values:    The list of values to convert.
+    @type values:       list of float
+    @keyword lower:     The lower bound of the distribution.
+    @type lower:        float
+    @keyword upper:     The upper bound of the distribution.
+    @type upper:        float
+    @keyword inc:       The number of discrete increments for the 
distribution between the lower and upper bounds.
+    @type inc:          int
+    @keyword verbose:   A flag which if True will enable printouts.
+    @type verbose:      bool
+    @return:            The discrete probability distribution.
+    @rtype:             list of lists of float
+    """
+
+    # The bin width.
+    bin_width = (upper - lower)/float(inc)
+
+    # Init the dist object.
+    dist = []
+    for i in range(inc):
+        dist.append([bin_width*i+lower, 0])
+
+    # Loop over the values.
+    for val in values:
+        # The bin.
+        bin = int((val - lower)/bin_width)
+
+        # Outside of the limits.
+        if bin < 0 or bin >= inc:
+            if verbose:
+                print("Outside of the limits: '%s'" % val)
+            continue
+
+        # Increment the count.
+        dist[bin][1] = dist[bin][1] + 1
+
+    # Convert the counts to frequencies.
+    total_pr = 0.0
+    for i in range(inc):
+        dist[i][1] = dist[i][1] / float(len(values))
+        total_pr = total_pr + dist[i][1]
+
+    # Printout.
+    if verbose:
+        print("Total Pr: %s" % total_pr)
+
+    # Return the dist.
+    return dist
+
+
+def gaussian(x=None, mu=0.0, sigma=1.0):
+    """Calculate the probability for a Gaussian probability distribution for 
a given x value.
+
+    @keyword x:     The x value to calculate the probability for.
+    @type x:        float
+    @keyword mu:    The mean of the distribution.
+    @type mu:       float
+    @keyword sigma: The standard deviation of the distribution.
+    @type sigma:    float
+    @return:        The probability corresponding to x.
+    @rtype:         float
+    """
+
+    # Calculate and return the probability.
+    return exp(-(x-mu)**2 / (2.0*sigma**2)) / (sigma * sqrt(2.0 * pi))
 
 
 def std(values=None, skip=None, dof=1):




Related Messages


Powered by MHonArc, Updated Thu Jun 06 09:20:02 2013