def derivative_G(propensities,V,X,w,deter_vector,stoc_positions, positions, valid,jac):
# just the deterministics
X_d = X[deter_vector,:].copy()
temp_eta = np.zeros((np.sum(deter_vector),X.shape[1]))
j = 0
for i in range(len(stoc_positions)):
# If x-\nu_i is non zero
if stoc_positions[i] == True:
if np.sum(valid[:,j]) != 0:
#print(" X shape: " + str(X.shape))
#print(" w shape: " + str(w.shape))
#print("test :" + str(map(propensities[i],*X[:,positions[valid[:,j]][:,j]])))
# original Terms
temp_eta[:,valid[:,j]] += (X_d[:,positions[valid[:,j]][:,j]]
- X_d[:,valid[:,j]] +
V[i][deter_vector][:,np.newaxis]
)*map(propensities[i],* X[:,positions[valid[:,j]][:,j]])*w[positions[valid[:,j]][:,j]]
# Correction terms
# x terms
temp_eta[:,:] -= jac(X,deter_vector,i)*w[np.newaxis,:] # these should be all the terms which are minusing out.
# x-v_j term.
temp_eta[:,valid[:,j]] += jac(X[:,positions[valid[:,j]][:,j]],deter_vector,i)*w[positions[valid[:,j]][:,j]][np.newaxis,:]
j += 1
else:
temp_eta[:,:] += (V[i][deter_vector][:,np.newaxis])*map(propensities[i],* X)*w
#return_X = np.zeros(X.shape)
#return_X[deter_vector,:] = temp_eta
#return_X[np.invert(deter_vector),:] = X[np.invert(deter_vector),:].copy()
return temp_eta
评论列表
文章目录