pomp
Inference for partially observed Markov processes
Toggle main menu visibility
Main Page
Data Structures
Data Structures
Data Structure Index
Data Fields
All
Variables
Files
File List
Globals
All
_
a
b
c
d
e
f
g
i
k
l
m
n
o
p
r
s
t
u
v
w
x
y
Functions
_
a
b
d
e
f
g
i
l
m
n
o
p
r
s
t
w
Variables
_
a
c
f
m
n
o
p
r
s
Typedefs
a
b
g
l
m
n
p
s
t
u
Enumerations
Enumerator
Macros
a
c
e
f
k
m
n
r
s
t
u
v
w
x
y
•
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
Loading...
Searching...
No Matches
logmeanexp.c
Go to the documentation of this file.
1
// -*- C++ -*-
2
3
#include "
internal.h
"
4
5
// Compute log(mean(exp(X))) accurately,
6
// optionally with one element dropped
7
SEXP
logmeanexp
(
const
SEXP
X
,
const
SEXP Drop) {
8
int
j, n = LENGTH(
X
);
9
int
k = *INTEGER(Drop)-1;
// zero-based index
10
double
*x = REAL(
X
);
11
long
double
m = R_NegInf;
12
long
double
s = 0;
13
for
(j = 0; j < n; j++) {
14
if
(j != k)
15
m = (x[j] > m) ? (
long
double
) x[j] : m;
16
}
17
for
(j = 0; j < n; j++) {
18
if
(j != k)
19
s += expl((
long
double
) x[j] - m);
20
}
21
if
(k >= 0 && k < n) n--;
22
return
ScalarReal(m + log(s/n));
23
}
7
SEXP
logmeanexp
(
const
SEXP
X
,
const
SEXP Drop) {
…
}
X
#define X
Definition
gompertz.c:14
internal.h
logmeanexp
SEXP logmeanexp(const SEXP X, const SEXP Drop)
Definition
logmeanexp.c:7
src
logmeanexp.c
Generated by
1.9.8