Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
functions.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file numeric/statistics/functions.hh
11 /// @brief a collection of various functions to compute statistics. feel free to add your own
12 /// @author Florian Richter (floric@u.washington.edu), sep 08
13 
14 
15 #ifndef INCLUDED_numeric_statistics_functions_hh
16 #define INCLUDED_numeric_statistics_functions_hh
17 
18 
19 #include <numeric/types.hh>
20 #include <utility/vector1.hh>
21 
22 // C++ headers
23 #include <cmath>
24 #include <complex>
25 
26 
27 namespace numeric {
28 namespace statistics {
29 
30 /// @brief mean value of an input vector
31 template< class Iterator, typename T>
32 inline
33 T
34 mean( Iterator first, Iterator last, T )
35 {
36  T mean = T(0);
37  int size(0);
38  for ( ; first != last; ++first ) {
39  mean += *first;
40  size++;
41  // std::cout << "D2H " << *first << " " << size << std::endl;
42  }
43  return mean / size;
44 }
45 
46 
47 template< class Iterator, typename T>
48 inline
49 T
50 std_dev_with_provided_mean( Iterator first, Iterator last, T mean )
51 {
52  T std_dev2 = T(0);
53  int size(0);
54  for ( ; first != last; ++first ) {
55  T meandev = *first - mean;
56  std_dev2 += (meandev * meandev);
57  size++;
58  }
59  std_dev2 /= size;
60  return sqrt( std_dev2 );
61 }
62 
63 template< class Iterator, typename T>
64 inline
65 T
66 std_dev( Iterator first, Iterator last, T )
67 {
68  T meanval = mean( first, last, *first );
69  return std_dev_with_provided_mean( first, last, meanval );
70 }
71 
72 //FPD erf and erfc with real & imaginary arguments
73 // code borrowed from http://ab-initio.mit.edu/Faddeeva
74 
75 // compute w(z) = exp(-z^2) erfc(-iz) [ Faddeeva / scaled complex error func ]
76 std::complex<double> w(std::complex<double> z,double relerr=0);
77 double w_im(double x); // special-case code for Im[w(x)] of real x
78 
79 // compute erfcx(z) = exp(z^2) erfc(z)
80 std::complex<double> errfcx(std::complex<double> z, double relerr=0);
81 double errfcx(double x);
82 
83 // compute erf(z), the error function of complex arguments
84 std::complex<double> errf(std::complex<double> z, double relerr=0);
85 double errf(double x);
86 
87 // compute erfi(z) = -i erf(iz), the imaginary error function
88 std::complex<double> errfi(std::complex<double> z, double relerr=0);
89 double errfi(double x);
90 
91 // compute erfc(z) = 1 - erf(z), the complementary error function
92 std::complex<double> errfc(std::complex<double> z, double relerr=0);
93 double errfc(double x);
94 
95 // compute Dawson(z) = sqrt(pi)/2 * exp(-z^2) * erfi(z)
96 std::complex<double> Dawson(std::complex<double> z, double relerr=0);
97 double Dawson(double x); // special case for real x
98 
99 /// @brief Returns the Kullback-Leibler divergence (aka relative entropy)
100 /// between two discrete probability distributions.
102  utility::vector1< numeric::Real > const & prior,
103  utility::vector1< numeric::Real > const & posterior
104 );
105 
106 
108 corrcoef(
110  utility::vector1< numeric::Real > const & vec2);
111 
115  numeric::Real m1,
116  numeric::Real sd1,
118  numeric::Real m2,
119  numeric::Real sd2);
120 
122 cov(
124  utility::vector1< numeric::Real > const & vec2);
125 
129  numeric::Real m1,
131  numeric::Real m2);
132 
133 
134 } // namespace statistics
135 } // namespace numeric
136 
137 
138 #endif // INCLUDED_numeric_statistics_functions_HH
double Dawson(double x)
Definition: functions.cc:297
dictionary size
Definition: amino_acids.py:44
double errf(double x)
Definition: functions.cc:131
cmplx w(cmplx z, double relerr)
Definition: functions.cc:470
def x
cmplx errfcx(cmplx z, double relerr)
Definition: functions.cc:126
numeric::Real kl_divergence(utility::vector1< numeric::Real > const &prior, utility::vector1< numeric::Real > const &posterior)
Returns the Kullback-Leibler divergence (aka relative entropy) between two discrete probability distr...
Definition: functions.cc:38
cmplx errfi(cmplx z, double relerr)
Definition: functions.cc:240
numeric::Real corrcoef_with_provided_mean_and_std_dev(utility::vector1< numeric::Real > const &vec1, numeric::Real m1, numeric::Real sd1, utility::vector1< numeric::Real > const &vec2, numeric::Real m2, numeric::Real sd2)
Definition: functions.cc:71
def z
numeric::Real corrcoef(utility::vector1< numeric::Real > const &vec1, utility::vector1< numeric::Real > const &vec2)
Definition: functions.cc:58
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
numeric::Real cov(utility::vector1< numeric::Real > const &vec1, utility::vector1< numeric::Real > const &vec2)
Definition: functions.cc:91
rosetta project type declarations. Should be kept updated with core/types.hh. This exists because num...
double w_im(double x)
Definition: functions.cc:1596
double Real
Definition: types.hh:39
T std_dev(Iterator first, Iterator last, T)
Definition: functions.hh:66
T mean(Iterator first, Iterator last, T)
mean value of an input vector
Definition: functions.hh:34
T std_dev_with_provided_mean(Iterator first, Iterator last, T mean)
Definition: functions.hh:50
vector1: std::vector with 1-based indexing
double errfc(double x)
Definition: functions.cc:252
void statistics(std::string filename)
numeric::Real cov_with_provided_mean(utility::vector1< numeric::Real > const &vec1, numeric::Real m1, utility::vector1< numeric::Real > const &vec2, numeric::Real m2)
Definition: functions.cc:101