0

I've got a problem connected with covariance matrix used to implement Fractional Brownian Motion using Cholesky's decomposition.

Code below creates covariance matrix.

for i in range(n):
        for j in range(n):
            cov_matrix[i, j] = 0.5 * (np.abs(i - j) ** (2 * H) + np.abs(i + j) ** (2 * H) - np.abs(i - j) ** (2 * H - 2))

H is Hurst constant needed to proceed with FBM. it should be between 0 and 1. Thus, for n = 10, H= 0.4 we obtain

array([[      -inf, 0.5       , 1.52346349, 2.27443442, 2.93670085,
        3.55142035, 4.13472712, 4.69487561, 5.23679702, 5.76374647],
       [0.5       ,       -inf, 1.20411234, 2.16862949, 2.88227124,
        3.51746564, 4.11110939, 4.67726158, 5.22301048, 5.75256792],
       [1.52346349, 1.20411234,       -inf, 1.81194916, 2.74939428,
        3.44196028, 4.0600001 , 4.63924426, 5.19303249, 5.72797898],
       [2.27443442, 2.16862949, 1.81194916,       -inf, 2.3716382 ,
        3.29192874, 3.97009515, 4.575771  , 5.14421276, 5.68843181],
       [2.93670085, 2.88227124, 2.74939428, 2.3716382 ,       -inf,
        2.89977307, 3.80769964, 4.47506365, 5.07117033, 5.63103975],
       [3.55142035, 3.51746564, 3.44196028, 3.29192874, 2.89977307,
              -inf, 3.40474156, 4.30309897, 4.96189064, 5.55024622],
       [4.13472712, 4.11110939, 4.0600001 , 3.97009515, 3.80769964,
        3.40474156,       -inf, 3.89156856, 4.78217486, 5.43390278],
       [4.69487561, 4.67726158, 4.63924426, 4.575771  , 4.47506365,
        4.30309897, 3.89156856,       -inf, 4.36358069, 5.24770634],
       [5.23679702, 5.22301048, 5.19303249, 5.14421276, 5.07117033,
        4.96189064, 4.78217486, 4.36358069,       -inf, 4.82313193],
       [5.76374647, 5.75256792, 5.72797898, 5.68843181, 5.63103975,
        5.55024622, 5.43390278, 5.24770634, 4.82313193,       -inf]])

With values -inf, I cannot use Cholesky's method correctly, thus decomposition gives me NaNs. Could someone enlighten me on what should i change ?

  • 3
    You're getting ```-inf``` in the diagonal due to this term ```np.abs(i - j) ** (2 * H - 2)``` which is 0 to a negative power when ```i==j``` – Nin17 Jul 01 '23 at 11:54

0 Answers0