def get_phase(grad_x, grad_y, N):
    phase = np.zeros((N, N))
    for i in range(N):
        for j in range(N):
            if grad_x[i, j] > 0 and grad_y[i, j] > 0:
                phase[i, j] = np.arctan(np.division(gradient_y, gradient_x))
            elif grad_x[i, j] < 0 and grad_y[i, j] > 0:
                phase[i, j] = np.arctan(np.division(gradient_y,
                                                    gradient_x)) + np.pi
            elif grad_x[i, j] < 0 and grad_y[i, j] < 0:
                phase[i, j] = np.arctan(np.division(gradient_y,
                                                    gradient_x)) + np.pi
            else:
                phase[i, j] = np.arctan(np.division(gradient_y,
                                                    gradient_x)) + np.pi * 2

    return phase
Beispiel #2
0
def MIMOChannelCapacity(channel,
                        noise_variance=1,
                        covariance=None,
                        bandwidth=1,
                        Complex=True):
    if (isinstance(channel, Channel)):
        H = channel.getChannel()
    else:
        H = channel

    if (Complex == True):
        if (covariance is None):
            M = np.matmul(H, H.getH())
        else:
            M = np.matmul(H, covariance)
            M = np.matmul(M, H.getH())

        s = M.shape
        if (len(s) == 1):
            I = np.identity(1)
        else:
            I = np.identity(s[0])

        Sm = I + np.division(M, noise_variance)
        C = 2 * bandwidth * np.log2(np.linalg.det(Sm))

    else:
        if (covariance is None):
            M = np.matmul(H, H.T)
        else:
            M = np.matmul(H, covariance)
            M = np.matmul(M, H.T)

        s = M.shape
        if (len(s) == 1):
            I = np.identity(1)
        else:
            I = np.identity(s[0])

        Sm = I + np.division(M, noise_variance)
        C = bandwidth * np.log2(np.linalg.det(Sm))
Beispiel #3
0
def gradCE(target, prediction):
    N = target.shape[1]
    return ((-1 / N) * (np.sum(np.division(target, prediction), axis=0))).T
Beispiel #4
0
def calcPresentValue(FV,r,t):
    DF = 1/pow(1+r,t)
    return FV*DF

### Visualize PV ###
# x = np.arange(0,21,1)
# plt.plot(x,calcPresentValue(100,0.0,x),label='r=0%')
# plt.plot(x,calcPresentValue(100,0.05,x),label='r=5%')
# plt.plot(x,calcPresentValue(100,0.1,x),label='r=10%')
# plt.plot(x,calcPresentValue(100,0.15,x),label='r=15%')
# plt.xticks(x)
# plt.xlabel("해(년)",FontProperties=fontprop)
# plt.ylabel("100만원의 현재가치",FontProperties=fontprop)
# plt.title("미래 100만원에 대한 현재가치",FontProperties=fontpropTitle)
# plt.xlim(0,21)
# plt.ylim(0,105)
# plt.legend()
# plt.show()


###Calc PV of different cash flow
# From yr1 to yr10 cashflows
cashFlow = np.array([50,57,75,80,85,92,92,80,68,50])
intRate = np.repeat(1.12,len(cashFlow))
# year 1 to 10
yearArr = np.arange(1,len(cashFlow)+1)
ones = np.ones(len(cashFlow))
print(ones)
DFArr = np.division(ones,np.power(intRate,yearArr))
# print(DFArr)
start = 0
stop = 100
num = 10
step = 20
a = np.linspace(start, stop, num, endpoint=True)  # default true
b = np.arange(start, stop, step)
# 1-d array  + - * / %  scalar        #  all are elementwise.
# 1-d array  + - * / %  1-d array
# 1-d array  + - * / %  2-d array
# 2-d array  + - * / %  scalar
# 2-d array  + - * / %  2-d array
# broadcast can be used when doing these opeartions
np.add()
np.subtract()
np.multiply()
np.division()
np.sqrt()
np.power()
# universal functions a.k.a. ufuncs
np.sin(arr)
np.cos(arr)
np.min(arr)
np.max(arr)
np.sum(arr)
np.mean(arr)
np.std(arr)
'''
linear algebra ---> we are not doing elementwise!
               ---> we have all linear algebra operations 
'''
x1 = np.ones((2, 3), dtype='int')
Beispiel #6
0
def gradCE(target, prediction):
    N = target.shape[0]
    return (-1 / N) * np.sum(np.division(target, prediction))