def kf_update(u, sigma, z): F = np.matrix('1 1; 0 1') H = np.matrix('0 1') I = np.diag([1, 1]) #u_of_t : Previous state #z_of_t : current measurement #Sigma_x : movement uncertainty : G * G^T * little_sigma^2_x. Should be [deltaT^2 ; deltaT / 2] --> G [ 1 ; 1/2 ] #Sigma_z : measurement uncertainty : little_sigma^2_z (std. deviation of measurement noise) #Sigma : location uncertainty #Calculate the Kalman gain Fsigma_t = np.multiply(F, sigma) Fsigma_tF_T = np.multiply(Fsigma_t, F.T) G = np.matrix([1; .5]) GG_T = np.multiply(G, G.T) Sigma_x = GG_T K_tplus1 = (Fsigma_tF_T + ) #location mean information Fmu_t = np.multiply(F, u) HF = np.multipy(H, F) HFmu_t = np.multiply(HF, u) mu_tplus1 = Fmu_t + K_tplus1(z_tplus1 - HFmu_t) print('u_tplus1 : {u_tplus1}\n'.format(u_tplus1=u_tplus1)) print('sigma : {sigma}\n'.format(sigma=sigma)) print('z : {z}\n'.format(z=z)) return [u, sigma]
def sigmoid_function(data, derivative=False): data = np.clip(data, -500, 500) data = expit(data) if derivative: return np.multipy(data, 1-data) else: return data
def SMA_CHANNEL(close, n, high_n, low_n): sma = [np.mean(close[i:i + n]) for i in range(0, len(close) - n + 1)] upper_channel = np.multipy(sma, high_n) lower_channel = np.multiply(sma, low_n) return (upper_channel, lower_channel)
def adaBoostTrainDs(dataArr,classLabels,numIt=40): weakClassArr = [] m = np.shape(dataArr)[0] D = np.mat(np.ones((m,1))) aggClassEst = np.mat(np.zeros((m,1))) for i in range(numIt): bestStump,error,classEst = buildStump(dataArr,classLabels,D) print "D:",D.T alpha = float(0.5*np.log((1.0-error)/max(error,1e-16))) bestStump['alpha'] = alpha weakClassArr.append(bestStump) print "classEst: ",classEst.T expon = np.multipy(-1*alpha*np.mat(classLabels).T,classEst) D = np.multipy(D,np.exp(expon)) D = D/D.sum() aggClassEst += alpha * classEst print "aggClassEst: ",aggClassEst.T aggErrors = np.multipy(sign(aggClassEst) != np.mat(classLabels).T,np.ones((m,1))) errorRate = aggErrors.sum()/m print "total error: ",errorRate,"\n" if errorRate == 0.0: break return weakClassArr
def inverse_transform(self, data): """ Performs an inverse transform on the data using the params stored params: data: a normalized numpy array returns: full_data: a denormalized numpy array """ copy = np.copy(data) (mean, std) = self.params.get('1d') copy = np.multipy(copy, std, where=std!=0) copy += mean return copy
def times(a, b): """ Multiply a by b. Parameters ---------- a : `numpy.ndarray` Array one. b : `numpy.ndarray` Array two Returns ------- result : `numpy.ndarray` ``a`` multiplied by ``b`` """ return np.multipy(a, b)
def updateOutput(self, input): # Your code goes here. ################################################ self.output = np.add(np.multiply(input > 0, input), np.multipy(input <= 0, self.alpha * np.exp(input) - self.alpha))
def multiply(a, b): return np.multipy(a, b)
import numpy as np from I_Rainfall import I_RainDoY import config I_MultiplierEvapoTrans = [ np.zeros(config.SUBCATCHMENT) for i in range(config.MONTH) ] I_EvapoTrans = [0 for i in range(config.MONTH)] I_FracArea = np.multipy(I_FracVegClassNow, I_RelArea) I_TimeEvap = 0 if I_RainDoY == 0 else 365 if I_RainDoY % 365 == 0 else I_RainDoY % 365 I_MoY = 0 if I_RainDoY == 0 else int(I_TimeEvap / 30.5) + 1 if config.I_EvapotransMethod == 1: I_PotEvapTransp = np.multily( I_EvapoTrans[I_MoY], np.multiply(I_MultiplierEvapoTrans[I_MoY], I_FracArea)) else: I_PotEvapTransp = np.multiply( I_Daily_Evapotrans, np.multiply(MultiplierEvapoTrans, I_FracArea)) I_MaxInfSubSAreaClass = config.I_MaxInfSSoil * I_FracArea I_MaxInfArea = config.I_MaxInf * np.multiply( I_FracArea, np.power( np.divide(0.7, I_BD_BDRefVegNow, out=np.zeros_like(I_BD_BDRefVegNow), where=I_BD_BDRefVegNow != 0), config.I_PowerInfiltRed)) I_CanIntercAreaClass = np.multiply(I_InterceptClass, I_FracArea) I_AvailWaterClass = (config.I_AvailWaterConst * I_FracArea if config.I_SoilPropConst_ else np.multiply(
def lineSegmentIntersect(XY1, XY2): #LINESEGMENTINTERSECT Intersections of line segments. # OUT = LINESEGMENTINTERSECT(XY1,XY2) finds the 2D Cartesian Coordinates of # intersection points between the set of line segments given in XY1 and XY2. # # XY1 and XY2 are N1x4 and N2x4 matrices. Rows correspond to line segments. # Each row is of the form [x1 y1 x2 y2] where (x1,y1) is the start point and # (x2,y2) is the end point of a line segment: # # Line Segment # o--------------------------------o # ^ ^ # (x1,y1) (x2,y2) # # OUT is a structure with fields: # # 'intAdjacencyMatrix' : N1xN2 indicator matrix where the entry (i,j) is 1 if # line segments XY1(i,:) and XY2(j,:) intersect. # # 'intMatrixX' : N1xN2 matrix where the entry (i,j) is the X coordinate of the # intersection point between line segments XY1(i,:) and XY2(j,:). # # 'intMatrixY' : N1xN2 matrix where the entry (i,j) is the Y coordinate of the # intersection point between line segments XY1(i,:) and XY2(j,:). # # 'intNormalizedDistance1To2' : N1xN2 matrix where the (i,j) entry is the # normalized distance from the start point of line segment XY1(i,:) to the # intersection point with XY2(j,:). # # 'intNormalizedDistance2To1' : N1xN2 matrix where the (i,j) entry is the # normalized distance from the start point of line segment XY1(j,:) to the # intersection point with XY2(i,:). # # 'parAdjacencyMatrix' : N1xN2 indicator matrix where the (i,j) entry is 1 if # line segments XY1(i,:) and XY2(j,:) are parallel. # # 'coincAdjacencyMatrix' : N1xN2 indicator matrix where the (i,j) entry is 1 # if line segments XY1(i,:) and XY2(j,:) are coincident. # Version: 1.00, April 03, 2010 # Version: 1.10, April 10, 2010 # Author: U. Murat Erdem. This file is updated to do calculate intersections even faster by Hesham Eraqi. # # CHANGELOG: # # # Ver. 1.00: # -Initial release. # # Ver. 1.10: # - Changed the input parameters. Now the function accepts two sets of line # segments. The intersection analysis is done between these sets and not in # the same set. # - Changed and added fields of the output. Now the analysis provides more # information about the intersections and line segments. # - Performance tweaks. # I opted not to call this 'curve intersect' because it would be misleading # unless you accept that curves are pairwise linear constructs. # I tried to put emphasis on speed by vectorizing the code as much as possible. # There should still be enough room to optimize the code but I left those out # for the sake of clarity. # The math behind is given in: # http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/ # If you really are interested in squeezing as much horse power as possible out # of this code I would advise to remove the argument checks and tweak the # creation of the OUT a little bit. ### Argument check. #------------------------------------------------------------------------------- #validateattributes(XY1,{'numeric'},{'2d','finite'}) #validateattributes(XY2,{'numeric'},{'2d','finite'}) [n_rows_1, n_cols_1] = numpy.size(XY1) [n_rows_2, n_cols_2] = numpy.size(XY2) if n_cols_1 != 4 or n_cols_2 != 4: print('Arguments must be a Nx4 matrices.') ### Prepare matrices for vectorized computation of line intersection points. #------------------------------------------------------------------------------- X1 = repmat(XY1[:, 1], 1, n_rows_2) X2 = repmat(XY1[:, 3], 1, n_rows_2) Y1 = repmat(XY1[:, 2], 1, n_rows_2) Y2 = repmat(XY1[:, 4], 1, n_rows_2) XY2 = XY2 X3 = repmat(XY2[1, :], n_rows_1, 1) X4 = repmat(XY2[3, :], n_rows_1, 1) Y3 = repmat(XY2[2, :], n_rows_1, 1) Y4 = repmat(XY2[4, :], n_rows_1, 1) X4_X3 = (X4 - X3) Y1_Y3 = (Y1 - Y3) Y4_Y3 = (Y4 - Y3) X1_X3 = (X1 - X3) X2_X1 = (X2 - X1) Y2_Y1 = (Y2 - Y1) numerator_a = numpy.multiply(X4_X3, Y1_Y3) - numpy.multiply(Y4_Y3, X1_X3) numerator_b = numpy.multiply(X2_X1, Y1_Y3) - numpy.multiply(Y2_Y1, X1_X3) denominator = numpy.multiply(Y4_Y3, X2_X1) - numpy.multiply(X4_X3, Y2_Y1) u_a = numpy.divide(numerator_a, denominator) u_b = numpy.divide(numerator_b, denominator) # Find the adjacency matrix A of intersecting lines. INT_X = numpy.multiply(X1 + X2_X1, u_a) INT_Y = numpy.multipy(Y1 + Y2_Y1, u_a) INT_B = (u_a >= 0) & (u_a <= 1) & (u_b >= 0) & (u_b <= 1) PAR_B = denominator == 0 COINC_B = (numerator_a == 0 & numerator_b == 0 & PAR_B) # Arrange output. out = [ INT_B, numpy.multiply(INT_X, INT_B), numpy.multipliy(INT_Y, INT_B), u_a, u_b, PAR_B, COINC_B ] #intAdjacencyMatrix , intMatrixX , intMatrixY, intNormalizedDistance1To2, intNormalizedDistance2To1 , parAdjacencyMatrix , coincAdjacencyMatrix return out
np.exp(a1) a1=np.inf a1=np.nan np.isnan(a1) a2[0]=90 a2[3]=89 a2.sort() np.insert(a2,1,67) a6.cumsum(axis=0) np.delete(a2,[3]) np.append(a2,[90,67,78]) a2[1].size() aaa=np.add(a2,a6) np.subtract(a2,a6) np.multipy() np.split(a,6) a2>20 af=a6.ravel() np.concatenate((aa,aaa), axis=1) #-------------------------------------------------------------------------- #PANDAS #--------------------------------------------- import pandas as pd import numpy as np labels=['a','b','c','d'] data=[10,20,30,40]
############## 演算 tf.add([1, 2], [3, 4]) tf.multiply(x, y) #要素積 tf.square(5) #25 tf.reduce_sum([1, 2, 3]) #->6, shape=はなし(整数) #reshape tf.reshape(x, (5, 5)) #キャスト tf.cast(x, tf.float32) ############# numpyとの互換性 np.multipy(a, b) tf.multiply(numpy, 3) a.numpy() #->numpy型で返す ############# keras Layer # Dot レイヤー x = np.arange(10).reshape(1, 5, 2) print(x.shape) #->(1,5,2) y = np.arange(10, ).reshape(1, 2, 5) print(y.shape) #-> (1,2,5) dotted = tf.keras.layers.Dot(axes=(1, 2))( [x, y]) #xのaxis=2(5次元ベクトル) と yのaxis=2(5次元ベクトル)の内積をとる print(dotted.shape) #(1,2,2) print(x) print(y)
def output_torque( inertial_moment, radial_acceleration): return np.multipy( inertial_moment, radial_acceleration)