crflynn / fbm Goto Github PK
View Code? Open in Web Editor NEWExact methods for simulating fractional Brownian motion and fractional Gaussian noise in python
License: MIT License
Exact methods for simulating fractional Brownian motion and fractional Gaussian noise in python
License: MIT License
Thanks for providing both fbm
and stochastic
for everyone to use :-)
Can you please clarify the relationship between the two packages? I have the impression that fbm is basically a subset of stochastic, except that stochastic does not provide the Cholesky method (which could be ported there). Am I missing anything?
First of all, I really appreciate your API here. One thing is that, this project is fractional, not multifractional. Right now I just add a method insdie of "_autocovariance" so the hurst value get updated continously based on a ramp function etc. It will be greate if support for multifractional can be added, because this project is one of the few out there in python. Great Work!!
def _autocovariance(self, k):
self.adjust_hurst(k)
"""The autocovariance for fgn."""
return 0.5 * (abs(k - 1) ** (2 * self.hurst) -
2 * abs(k) ** (2 * self.hurst) +
abs(k + 1) ** (2 * self.hurst))
Thanks for the library. I needed to generate multiple FBM instances at the same time. I used your original implementation, but it appeared too slow since there is too much preliminary work.
My implementation than generates [m x n] matrix:
def _hosking(self, gn):
"""Generate a fGn realization using Hosking's method.
Method of generation is Hosking's method (exact method) from his paper:
Hosking, J. R. (1984). Modeling persistence in hydrological time series
using fractional differencing. Water resources research, 20(12),
1898-1908.
"""
fgn = np.zeros((self.m, self.n))
phi = np.zeros(self.n)
psi = np.zeros(self.n)
# Monte carlo consideration
if self._cov is None or self._changed:
self._cov = np.array([self._autocovariance(i) for i in range(self.n)])
self._changed = False
# First increment from stationary distribution
fgn[:, 0] = gn[:, 0]
v = 1
phi[0] = 0
# Generate fgn realization with n increments of size 1
for i in range(1, self.n):
phi[i - 1] = self._cov[i]
for j in range(i - 1):
psi[j] = phi[j]
phi[i - 1] -= psi[j] * self._cov[i - j - 1]
phi[i - 1] /= v
for j in range(i - 1):
phi[j] = psi[j] - phi[i - 1] * psi[i - j - 2]
v *= 1 - phi[i - 1] * phi[i - 1]
for j in range(i):
fgn[:, i] += phi[j] * fgn[:, i - j - 1]
fgn[:, i] += np.sqrt(v) * gn[:, i]
return fgn
Feel free to include it to your codebase if you wish.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.