Deterministic simulation of mildly intermittent hydrologic recordsOnline Appendix

Mahesh L. Maskey, Carlos E. Puente*, Bellie Sivakumar

This page contains the following information: (a) MATLAB source codes for the original Fractal-Muiltifractal method and an overlap extension, and (b) interactive demos that allow changing FM patterns to explore other FM sets using as a basis Figures 1 and 2 in the paper. This information fully empowers the interested reader in computing FM sets based on the notion of vertical thresholds.


MATLAB Code

Original FM

  1. function dy = wire(p)
  2. % This subroutine accepts a vector that contains all the
  3. % parameters used in the wire. These parameters do not account
  4. % the smoothing parameter. The number of interpolating points
  5. % is automatically calculated from the vector length.
  6. % Examples:
  7. % pattern = wire([x y d1 d2 p]);
  8. % resolution of the pattern (# bins in histogram)
  9. nbins = 365;
  10. % duration of chaos game
  11. ndots = 2^14;
  12. % # of interpolating points
  13. intp = (7+length(p))/4;
  14. % y in [-5,5]
  15. % d in [-1,1]
  16. % Put the parameters into neat little vectors.
  17. xs = [0 p(1:(intp-2)) 1];
  18. ys = [0 p((intp-1):(2*intp-4)) 1];
  19. d = 2*p((2*intp-3):(3*intp-5));
  20. ps = [0 p((3*intp-4):(4*intp-7)) 1];
  21. % Validation required when >3 interpolating pts
  22. if intp>3
  23. % x-values must be in increasing order
  24. for vx=2:(length(xs)-2)
  25. if xs(vx) >= xs(vx+1)
  26. dy = ones(1,nbins) / nbins;
  27. return
  28. end
  29. end
  30. % p-values must be in increasing order
  31. for vp=2:(length(ps)-2)
  32. if ps(vp) >= ps(vp+1)
  33. dy = ones(1,nbins) / nbins;
  34. return
  35. end
  36. end
  37. end
  38. % Calculate the other parameters of the map.
  39. h = xs(end)-xs(1);
  40. a =(xs(2:end)-xs(1:end-1))/h;
  41. e = xs(1:end-1)-xs(1)*a;
  42. c =(ys(2:end)-ys(1:end-1)-d*(ys(end) - ys(1)))/h;
  43. f = ys(1:end-1)-d*ys(1)-c*xs(1);
  44. % Determine when to use which map during the chaos game.
  45. W = zeros(ndots,1);
  46. prob = rand(ndots,1);
  47. for k=1:(length(ps)-1)
  48. W = W + and(prob<ps(k+1),prob>ps(k))*k;
  49. end
  50. kfun = sum(W,2);
  51. y = zeros(ndots,1);
  52. xold = xs(2);
  53. yold = ys(2);
  54. y(1) = yold;
  55. for i=1:ndots-1
  56. k = max(min(kfun(i),numel(a)),1);
  57. xnew = a(k)*xold + e(k);
  58. ynew = c(k)*xold + d(k)*yold + f(k);
  59. xold = xnew;
  60. yold = ynew;
  61. y(i+1) = ynew;
  62. end
  63. % Create histogram.
  64. dy = hist(y, nbins);
  65. % Normalize histogram so that the area underneath = 1
  66. dy = dy/sum(dy);
  67. % End.

Extension to overlap

  1. function dy = leaf(p)
  2. % This subroutine accepts a vector that contains all the
  3. % parameters used in the overlapped leafy attractor. These
  4. % parameters do not account smoothing one. The number of
  5. % mappings is automatically calculated from the vector length.
  6. % Examples:
  7. % pattern = leaf([x1 x2 y1 y2 d1 d2 p]);
  8. % resolution of the pattern (# bins in histogram)
  9. nbins = 365;
  10. % duration of chaos game
  11. ndots = 2^14;
  12. % # of maps
  13. nobj = (5+length(p))/6;
  14. % y in [-5,5]
  15. % d in [-1,1]
  16. % Put the parameters into neat little vectors.
  17. xs = [0 p(1:(2*nobj-2)) 1];
  18. ys = [0 p((2*nobj-1):(4*nobj-4)) 1];
  19. d = p((4*nobj-3):(5*nobj-4));
  20. ps = [0 p((5*nobj-3):(6*nobj-5)) 1];
  21. % Validation required when >2 maps
  22. if nobj>2
  23. % interval spans must be positive
  24. for vx=3:2:(length(xs)-3)
  25. if xs(vx) >= xs(vx+1)
  26. dy = ones(1,nbins) / nbins;
  27. return
  28. end
  29. end
  30. % p-values must be in increasing order
  31. for vp=2:(length(ps)-2)
  32. if ps(vp) >= ps(vp+1)
  33. dy = ones(1,nbins) / nbins;
  34. return
  35. end
  36. end
  37. end
  38. % Calculate the other parameters of the map.
  39. h = xs(end)-xs(1);
  40. a =(xs(2:2:end)-xs(1:2:end-1))/h;
  41. e = xs(1:2:end-1)-xs(1)*a;
  42. c =(ys(2:2:end)-ys(1:2:end-1)-d*(ys(end)-ys(1)))/h;
  43. f = ys(1:2:end-1)-d*ys(1)-c*xs(1);
  44. % Determine when to use which map during the chaos game.
  45. W = zeros(ndots,1);
  46. prob = rand(ndots,1);
  47. for k=1:(length(ps)-1)
  48. W = W + and(prob<ps(k+1),prob>ps(k))*k;
  49. end
  50. kfun = sum(W,2);
  51. y = zeros(ndots,1);
  52. xold = xs(2);
  53. yold = ys(2);
  54. y(1) = yold;
  55. for i=1:ndots-1
  56. k = max(min(kfun(i),numel(a)),1);
  57. xnew = a(k)*xold + e(k);
  58. ynew = c(k)*xold + d(k)*yold + f(k);
  59. xold = xnew;
  60. yold = ynew;
  61. y(i+1) = ynew;
  62. end
  63. % Create histogram.
  64. dy = hist(y, nbins);
  65. % Normalize histogram so that the area underneath = 1
  66. dy = dy/sum(dy);
  67. % End.

Online Demo

Wire with 2 maps

Parameters below may be modified to draw FM outcomes dys. When the parameter Smoothness equals 1 the raw Fractal-Multifractal shadow dy is found.

X-values
Y-values
Scalings
Proportion
Smoothness

Overlap with 2 maps

Parameters below may be modified to draw FM outcomes dys. When the parameter Smoothness equals 1 the raw Fractal-Multifractal shadow dy is found.

X-values
Y-values
Scalings
Proportion
Smoothness