我试图运行一个代码片段,看起来像,
import numpy as np
import time
def estimate_mutual_info(X, neurons, bins = 5):
xy = np.histogram2d(X, neurons, bins)[0]
x = np.histogram(X, bins)[0]
y = np.histogram(neurons, bins)[0]
ent_x = -1 * np.sum( x / np.sum(x) * np.log( x / np.sum(x)))
ent_y = -1 * np.sum( y / np.sum(y) * np.log( y / np.sum(y)))
ent_xy = -1 * np.sum( xy / np.sum(xy) * np.log( xy / np.sum(xy)))
return (ent_x + ent_y - ent_xy)
tic = time.time()
X = np.random.rand(12000, 1200)
Y = np.random.rand(12000, 10)
for j in Y.T:
mi = 0
for i in range(X.shape[1]):
mi += estimate_mutual_info(X.T[i], j, bins = 2)
print(mi)
toc = time.time()
print(str(toc - tic)+" seconds")
为了提高速度,我使用了float16
,希望看到一些改进,但是float16
比float32
and float64
.
X = np.random.rand(12000, 1200).astype('float16')
Y = np.random.rand(12000, 10).astype('float16')
将它们更改为float16
结果执行时间为84.57 seconds
, 然而float64
and float32
被执行为36.27 seconds
and 33.25 seconds
分别。我不确定是什么导致了这种糟糕的表现flaot16
。我的处理器是64 bit
, using python3.7
and numpy-1.16.2
。我认为 64 位处理器不会对所有 16 位、32 位和 64 位处理器无动于衷。非常感谢任何纠正和见解。