-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,329 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
__author__ = 'kevin.sheppard' | ||
from .base import IIDBootstrap, CircularBlockBootstrap, MovingBlockBootstrap, \ | ||
StationaryBootstrap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import numpy as np | ||
cimport numpy as np | ||
cimport cython | ||
|
||
@cython.boundscheck(False) | ||
@cython.wraparound(False) | ||
@cython.cdivision(True) | ||
def stationary_bootstrap_sample(int[:] indices, | ||
double[:] u, | ||
double p): | ||
""" | ||
Parameters | ||
------- | ||
indices: 1-s arrah | ||
Array containing draws from randint with the same size as the data in | ||
the range of [0,nobs) | ||
u : 1-d array | ||
Array of standard uniforms | ||
p : float | ||
Probability that a new block is started in the stationary bootstrap. | ||
The multiplicative reciprocal of the window length | ||
Returns | ||
------- | ||
indices: 1-d array | ||
Indices for an iteration of the stationary bootstrap | ||
""" | ||
cdef Py_ssize_t num_items, i | ||
num_items = indices.shape[0] | ||
|
||
for i in range(1, num_items): | ||
if u[i] > p: | ||
indices[i] = indices[i - 1] + 1 | ||
if indices[i] == num_items: | ||
indices[i] = 0 | ||
|
||
return indices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from __future__ import absolute_import, division | ||
from ..compat.numba import jit | ||
|
||
|
||
@jit | ||
def stationary_bootstrap_sample(indices, u, p): | ||
""" | ||
Parameters | ||
------- | ||
indices: 1-s arrah | ||
Array containing draws from randint with the same size as the data in | ||
the range of [0,nobs) | ||
u : 1-d array | ||
Array of standard uniforms | ||
p : float | ||
Probability that a new block is started in the stationary bootstrap. | ||
The multiplicative reciprocal of the window length | ||
Returns | ||
------- | ||
indices: 1-d array | ||
Indices for an iteration of the stationary bootstrap | ||
""" | ||
num_items = indices.shape[0] | ||
for i in range(1, num_items): | ||
if u[i] > p: | ||
indices[i] = indices[i - 1] + 1 | ||
if indices[i] == num_items: | ||
indices[i] = 0 | ||
|
||
return indices |
Oops, something went wrong.