Skip to content

Commit

Permalink
edat fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gpanterov committed Jun 29, 2012
1 parent b4815c9 commit 2ccbae0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
1 change: 1 addition & 0 deletions statsmodels/nonparametric/nonparametric2.py
Expand Up @@ -166,6 +166,7 @@ def pdf(self, edat=None):
"""
if edat is None:
edat = self.tdat

return tools.GPKE(self.bw, tdat=self.tdat, edat=edat,
var_type=self.var_type) / self.N

Expand Down
46 changes: 37 additions & 9 deletions statsmodels/nonparametric/np_tools.py
Expand Up @@ -84,19 +84,41 @@ def GPKE(bw, tdat, edat, var_type, ckertype='gaussian',
iscontinuous = np.where(var_type == 'c')[0]
isordered = np.where(var_type == 'o')[0]
isunordered = np.where(var_type == 'u')[0]
K = len(var_type)
edat = np.asarray(edat)
edat = np.squeeze(edat)
## if tdat.ndim > 1:
## N, K = np.shape(tdat)
## else:
## K = 1
## N = np.shape(tdat)[0]
## tdat = tdat.reshape([N, K])

if tdat.ndim > 1:
N, K = np.shape(tdat)
else:
K = 1
N = np.shape(tdat)[0]
tdat = tdat.reshape([N, K])
if tdat.ndim == 1 and K == 1: # one variable many observations
N = np.size(tdat)
#N_edat = np.size(edat)
elif tdat.ndim == 1 and K > 1:
N = 1

if edat.ndim > 1:
N_edat = np.shape(edat)[0]
else:
N, K = np.shape(tdat)
tdat = tdat.reshape([N, K])

## if edat.ndim > 1:
## N_edat = np.shape(edat)[0]
## else:
## N_edat = 1
## edat = edat.reshape([N_edat, K])
if edat.ndim == 1 and K > 1: # one obs many vars
N_edat = 1
edat = edat.reshape([N_edat, K])
elif edat.ndim == 1 and K == 1: # one obs one var
N_edat = np.size(edat)

else:
N_edat = np.shape(edat)[0] # ndim >1 so many obs many vars
assert np.shape(edat)[1] == K

edat = edat.reshape([N_edat, K])

bw = np.reshape(np.asarray(bw), (K,)) # must remain 1-D for indexing to work
dens = np.empty([N_edat, 1])
Expand Down Expand Up @@ -141,6 +163,9 @@ def GPKE2(bw, tdat, edat, var_type, ckertype='gaussian',
isordered = np.where(var_type == 'o')[0]
isunordered = np.where(var_type == 'u')[0]
K = len(var_type)
edat = np.asarray(edat)
edat = np.squeeze(edat)

if tdat.ndim == 1 and K == 1: # one variable many observations
N = np.size(tdat)
#N_edat = np.size(edat)
Expand Down Expand Up @@ -184,6 +209,9 @@ def GPKE3(bw, tdat, edat, var_type, ckertype='gaussian',
isordered = np.where(var_type == 'o')[0]
isunordered = np.where(var_type == 'u')[0]
K = len(var_type)
edat = np.asarray(edat)
edat = np.squeeze(edat)

if tdat.ndim == 1 and K == 1: # one variable many observations
N = np.size(tdat)
#N_edat = np.size(edat)
Expand Down

0 comments on commit 2ccbae0

Please sign in to comment.