~ubuntu-branches/ubuntu/oneiric/catools/oneiric

« back to all changes in this revision

Viewing changes to man/sum.exact.Rd

  • Committer: Bazaar Package Importer
  • Author(s): Charles Plessy
  • Date: 2011-03-22 13:24:12 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110322132412-0drnv9b0q2s9mndo
Tags: 1.11-1
* Team upload.
* New upstream version.
* debian/copyright:
  - corrected GPL-3 long description (not GPL-3+);
  - converted to DEP-5 format.
* Corrected Vcs-Svn field in debian/control.
* Use Debhelper 8 (debian/control, debian/compat).
* Renamed README.Debian README.test to better reflect its contents.
* Incremented Standards-Version to reflect conformance with Policy 3.9.1.
  (debian/control, no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
\name{sum.exact, cumsum.exact & runsum.exact}
2
 
\alias{sum.exact}
3
 
\alias{cumsum.exact}
4
 
\alias{runsum.exact}
5
 
\title{Basic Sum Operations without Round-off Errors}
6
 
\description{
7
 
  Functions for performing basic sum operations without round-off errors
8
 
}
9
 
\usage{
10
 
  sum.exact(..., na.rm = FALSE)
11
 
  cumsum.exact(x)
12
 
  runsum.exact(x,k)
13
 
}
14
 
 
15
 
\arguments{
16
 
  \item{x}{numeric vector}
17
 
  \item{...}{numeric vector(s), numbers or other objects to be summed}
18
 
  \item{na.rm}{logical. Should missing values be removed?}
19
 
  \item{k}{width of moving window; must be an odd integer between one and n }
20
 
}
21
 
 
22
 
\details{
23
 
 All three functions use full precision summation using multiple doubles for 
24
 
 intermediate values. The sum of numbers x & y is a=x+y with error term 
25
 
 b=error(a+b). That way a+b is equal exactly x+y, so sum of 2 numbers is stored
26
 
 as 2 or fewer values, which when added would under-flow. By extension sum of n 
27
 
 numbers is calculated with intermediate results stored as array of numbers 
28
 
 that can not be added without introducing an error. Only final result is 
29
 
 converted to a single number
30
 
}
31
 
 
32
 
\value{
33
 
  Function \code{sum.exact} returns single number. Function \code{cumsum.exact} 
34
 
  returns vector of the same length as \code{x}. Function \code{runsum.exact} 
35
 
  returns vector of length \code{length(x)-k} and attribute "count" containing
36
 
  number of finite (as in \code{\link{is.finite}}) elements in each window. 
37
 
}
38
 
 
39
 
\references{
40
 
  Round-off error correction is based on:
41
 
  Shewchuk, Jonathan, \emph{Adaptive Precision Floating-Point Arithmetic and  
42
 
    Fast Robust Geometric Predicates},  
43
 
   \url{http://www-2.cs.cmu.edu/afs/cs/project/quake/public/papers/robust-arithmetic.ps}
44
 
   and its implementation found at:
45
 
   \url{http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/393090} 
46
 
   
47
 
   McCullough, D.B., (1998) \emph{Assessing the Reliability of Statistical 
48
 
     Software, Part I}, The American Statistician, Vol. 52 No 4, 
49
 
     \url{http://www.amstat.org/publications/tas/mccull-1.pdf}
50
 
   
51
 
   McCullough, D.B., (1999) \emph{Assessing the Reliability of Statistical 
52
 
     Software, Part II}, The American Statistician, Vol. 53 No 2
53
 
     \url{http://www.amstat.org/publications/tas/mccull.pdf}
54
 
     
55
 
   NIST Statistical Reference Datasets (StRD) website 
56
 
   \url{http://www.nist.gov/itl/div898/strd}
57
 
 
58
 
59
 
 
60
 
\author{Jarek Tuszynski (SAIC) \email{jaroslaw.w.tuszynski@saic.com} based on
61
 
  code by Vadim Ogranovich, which is based on algorithms described in 
62
 
  references, pointed out by Gabor Grothendieck. 
63
 
64
 
 
65
 
\seealso{
66
 
 \itemize{       
67
 
   \item \code{\link[base]{sum}} is faster but not error-save version of 
68
 
         \code{sum.exact}
69
 
   \item \code{\link[base]{cumsum}} is equivalent to \code{cumsum.exact}
70
 
   \item \code{\link{runmean}(x,k,endrule="trim")} is similar to 
71
 
         \code{runsum.exact}.
72
 
 }
73
 
}
74
 
 
75
 
\examples{
76
 
  x = c(1, 1e20, 1e40, -1e40, -1e20, -1)
77
 
  a = sum(x);          print(a)
78
 
  b = sum.exact(x);    print(b)
79
 
  stopifnot(b==0)
80
 
  a = cumsum(x);       print(a)
81
 
  b = cumsum.exact(x); print(b)
82
 
  stopifnot(b[6]==0)
83
 
}
84
 
\keyword{ts}
85
 
\keyword{smooth}
86
 
\keyword{array}
87
 
\keyword{utilities}
88
 
\concept{sum with no round-off errors}
89
 
\concept{cumulative sum with no round-off errors}
90
 
\concept{moving sum with no round-off errors}
91
 
\concept{rolling sum with no round-off errors}
92
 
\concept{running sum with no round-off errors}
93