F-correlation
By using utils.f_correlation
, which implements the F-correlation [1], we can compute the nonlinear correlation between two variables.
References
Import and settings
import numpy as np
import matplotlib.pyplot as plt
from lingam.utils import f_correlation
Test data
def linear_data(n, r):
a = np.random.randn(n)
e1 = np.random.randn(n)
e2 = np.random.randn(n)
if r < 0:
r = -r
x = -np.sqrt(r)*a - np.sqrt(1-r)*e1
else:
x = np.sqrt(r)*a + np.sqrt(1-r)*e1
y = np.sqrt(r)*a + np.sqrt(1-r)*e2
return x, y
def x2_data(n):
x = np.random.uniform(-5, 5, n)
e = np.random.randn(n)
y = 0.5 * (x ** 2) + e
return x, y
def sin_data(n):
e = np.random.randn(n)
x = np.random.uniform(-5, 5, n)
y = 5 * np.sin(x) + e
return x, y