I want to reduce the runtime of my algorithm. Can anyone suggest ways to reduce its complexity other than using threads or parallel computing.
Algorithm: This algorithm aims to solve Pearson's r where the function is accepting a matrix X, a vector y, and (m, n) sizes. Currently, I am using nested loops to solve the problem but I am trying to find a solution to improve the runtime of this algorithm as currently in theoretical time complexity this requires O(mxn) time. which is when n and m is equal to 100,000 or more, my computer lags or crashes as n and m increases.
def pearson_cor(X, y, m, n):
v = []
for i in range(m):
sum_X = 0
sum_y = 0
sum_Xy = 0
sqSum_X = 0
sqSum_y = 0
for j in range(n):
sum_X = sum_X + X[i][j]
sum_y = sum_y + y[j]
sum_Xy = sum_Xy + (X[i][j] * y[j])
sqSum_X = sqSum_X + X[i][j]**2
sqSum_y = sqSum_y + y[j]**2
v.append((float)((n * sum_Xy) - (sum_X) * (sum_y))/(float)(isqrt(((n * sqSum_X) - sum_X**2)* ((n * sqSum_y) - sum_y**2),2)))
return v