我在使用SKCA时遇到了问题。我试图预测,如果其中一个预测的“源”以给定的方式发生变化,那么“测量的”变量(代码中的X)将是什么。我正在修改这个example。你知道吗
我认为问题是FastICA近似于“混合”矩阵,但是ica.mixing\与我用来生成数据的方法有很大的不同。我知道混合矩阵是未定义的,因为np.dot公司(S,A.T)是相关的,将S改为S*A和A改为A/A将对所有A产生相同的结果!= 0. 你知道吗
有什么想法吗?谢谢你的阅读和帮助
这是我的密码。你知道吗
# this is exactly how the example start
np.random.seed(0)
n_samples = 200
time = np.linspace(0, 8, n_samples)
s1 = np.sin(2 * time) # Signal 1 : sinusoidal signal
s2 = np.sign(np.sin(3 * time)) # Signal 2 : square signal
s3 = signal.sawtooth(2 * np.pi * time) # Signal 3: saw tooth signal
S = np.c_[s1, s2, s3]
S += 0.2 * np.random.normal(size=S.shape) # Add noise
S /= S.std(axis=0) # Standardize data
# Here I'm changing the example. I'm modifying the 'mixing' array
# such that s1 is not mixed with neither s2 nor s3
A = np.array([[1, 0, 0], [0, 2, 1.0], [0, 1.0, 2.0]]) # Mixing matrix
# Mix data,
X = np.dot(S, A.T) # Generate observations
# Compute ICA
ica = FastICA()
S_ = ica.fit_transform(X) # Reconstruct signals
A_ = ica.mixing_ # Get estimated mixing matrix
# We can `prove` that the ICA model applies by reverting the unmixing.
assert np.allclose(X, np.dot(S_, A_.T) + ica.mean_)
# Here is where my real code starts,
# Now modify source s1
s1 *= 1.1
S = np.c_[s1, s2, s3]
S /= S.std(axis=0) # Standardize data
# regenerate observations.
# Note that original code in the example uses np.dot(S, A.T)
# (that doesn't work either). I'm using ica.inverse_transform
# because it is what is documented but also because there is an
# FastICA.mean_ that is not documented and I'm hoping
# inverse_transform uses it in the right way.
# modified_X = np.dot(S, A.T) # does not work either
modified_X = ica.inverse_transform(S)
# check that last 2 observations are not changed
# The original 'mixing' array was defined to mix s2 and s3 but not s1
# Next tests fail
np_testing.assert_array_almost_equal(X[:, 1], modified_X[:, 1])
np_testing.assert_array_almost_equal(X[:, 2], modified_X[:, 2])
我正在发布我的发现,以防对任何人有所帮助。 我认为我发布的代码有两个问题
在拟合独立分量分析时,没有找到精确的“混合”矩阵,因此解决方案会将源1泄漏到所有测量输出中。结果应该很小,有很多数据,但它应该仍然存在。但是,当增加伪造数据的数量或更改FastICA的max\u iter或tol参数时,我看不到行为的变化。
源代码的顺序是不可预测的,在代码中,我假设发现S与S的顺序相同(这是错误的)。在所有源上循环(在fit\u转换之后),一次更改一个,我看到的结果接近我期望的结果。其中两个来源(1和2对于me)对测量变量2和3的影响最大,第三个来源对测量变量1的影响最大,对变量2和3的影响较小。
相关问题 更多 >
编程相关推荐