Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 How to optimize between two matrices, one of the matrices is derived from Excel data niloufar Unladen Swallow Posts: 1 Threads: 1 Joined: Nov 2019 Reputation: 0 Likes received: 0 #1 Nov-05-2019, 06:28 PM (This post was last modified: Nov-05-2019, 06:34 PM by niloufar. Edited 4 times in total.) ``` #The matrix code obtained as a formula is as follows: def objective(x): #= params x00 = x[0] y00 = x[1] u_m = x[2] a = x[3] b = x[4] u_mean_real = x[5] A = x[6] B = x[7] H = x[8] if 0.9 < y00 <= 1: alpha = 1.01 elif 0.8 < y00 <= 0.9: alpha = 1.02 elif 0.7 < y00 <= 0.8: alpha = 1.03 elif 0.6 < y00 <= 0.7: alpha = 1.04 elif 0.55 < y00 <= 0.6: alpha = 1.05 elif y00 <= 0.55: alpha = 1.1 if len(x) > 9: alpha = x[9] x = Symbol('x') y = Symbol('y') zeta = Symbol('zeta') sghi = Symbol('sigh') zeta0 = Symbol('zeta0') sghi0 = Symbol('sghi0') umax = Symbol('umax') #alpha = Symbol('alpha') F = Function('F') u = Function('u') GF = Function('GF') G = Symbol('G') ff = (((G**(alpha/(alpha-1)))*(1-2*alpha+alpha*G))/(1-(1/u_m)*(1-alpha)*(2*alpha-1)*(G-1)*(1-G**(alpha/(alpha-1))))) gg = (((1/(alpha*(G-1)*(G**(1-alpha))))*((1-alpha)**(alpha/(alpha-1)))*(1-G**(alpha/(alpha-1))))**(1-alpha)) GF = ff - gg GFF = lambdify(G, GF, modules='numpy') def F(G): return GFF(G) G_val = optimize.fminbound(F,1.0001,2,disp=True) G_val = float(G_val) F = ((1-((zeta - zeta0)/(1 -zeta0))**2)**b)*(1 - ((sghi - sghi0)/((A - sghi0)))**2)**a FF = F.subs([[zeta,x],[sghi, y],[zeta0, x00], [sghi0, y00]]) umax = u_m*u_mean_real u = (umax/(G-1))*((1-(1-G**(alpha/(alpha-1)))*FF)**((alpha-1)/alpha)-1) u_sub = u.subs([[G, G_val]]) xx = np.linspace(0,1,69) yy = np.linspace(0,1,27) uu = np.empty([len(xx), len(yy)]) u_func = lambdify([x,y], u_sub, "numpy") for ii in range(len(xx)): for jj in range(len(yy)): uu[ii,jj] = u_func(xx[ii], yy[jj]) return uu, xx, yy, FF, u_func def normalize (value): #only numpy array return (value - value.min())/(value.max() - value.min()) } #[color=#E74C3C][b] #Where the "uu" is the main matrix , #And the matrix obtained from Excel is as follows where the main matrix is "df_nump":[/b][/color] { path = '100802_1.xlsx' df_main = pd.read_excel(path) df_summarry = df_main.iloc[1:2, 3:15] df_summarry.columns = df_main.iloc[0,3:15] df = df_main.iloc[8:,0:].reset_index() del df['index'] df.columns = ['x_' + str(x) for x in range(np.size(df,1))] df_y = normalize(df.iloc[1:,0]) '''x coordinate #experiment data''' df_y1 = (df.iloc[1:,0]) df_x = normalize(df.iloc[0, 1:]) ''' y coordinate #experiment data ''' df_x1 = (df.iloc[0, 1:]) ''' z coordinate # experiment data ''' df_nump = df.iloc[1:,1:].fillna(0) plt.contour(df_x, df_y, df_nump.to_numpy()) plt.colorbar() DataPointsDomain = [0 ,0.019651515, 0.340909091, 0.386363636, 0.613636364, 0.659090909, 0.980348485, 1] DataPointsRange = [1 ,0.536288881 ,0.536288881, 0 ,0, 0.536288881, 0.536288881, 1] x = symbols('x') y = symbols('y') A1 = interpolating_spline(1, x, DataPointsDomain, DataPointsRange) A2 = interpolating_spline(1, y, DataPointsDomain, DataPointsRange) } #[b][color=#E74C3C]The parameters of the matrix "uu" formula that are known are as follows:[/color][/b] { x0 = 0.5 y0 = 0.85806221 u_mean =0.957175 c=6.6 d= 0.2797 u_max = 1.287 } #[color=#E74C3C][b]And the parameters that are guessed at and only the limit of parameter are known that ("a","b" are Between two numbers 1 and 5 except for even numbers that also contain numbers 1 and 5 , "alpha" is Between two numbers 1.01 and 1.5, which can include numbers that can be either numbers 1.01 and 1.5[/b] [/color] { a = 1.7 b = 1.7 alpha = 1.03 } #[color=#E74C3C][color=#E74C3C][b]And calculate the "uu" matrix according to the above parameters:[/b][/color][/color] { u_unique = np.unique(df_main.iloc[9:45, 1:31].fillna(1.3)) uu, xx1, yy1, FF, u_func = objective([x0 , y0, u_max/u_mean, a, b, u_mean, A1, B, H, alpha]) xx2 = xx1*c yy2 = yy1*d ''' # xx2 => x coordinate # from code #yy2 => y coordinate #from code #uu => z coordinate # from code # 1= 1: #When there are elements in list2 temp_result = abs(list1[i] - list2) #Matrix subtraction min_val = np.amin(temp_result) #Getting the minimum value to get closest element min_val_index = np.where(temp_result == min_val) #To find index of minimum value closest_element = list2[min_val_index] #Actual value of closest element in list2 list2 = list2[list2 != closest_element] #Remove closest element after found print(i, list1[i], min_val_index[0][0], closest_element[0]) #List1 Index, Element to find, List2 Index, Closest Element index_dfy1.append(i) index_xx2.append(min_val_index[0][0]) else: #All elements are already found print(i, list1[i], 'No further closest unique closest elements found in list2') idx_dfy1 = index_dfy1 idx_xx2 = index_xx2 print(idx_dfy1) print(idx_xx2) ################################################### list1=np.array(df_x1) list2=yy2 index_dfx1=[] index_yy2=[] for i in range(len(list1)): if (len(list2)) > 1: #When there are elements in list2 temp_result = abs(list1[i] - list2) #Matrix subtraction min_val = np.amin(temp_result) #Getting the minimum value to get closest element min_val_index = np.where(temp_result == min_val) #To find index of minimum value closest_element = list2[min_val_index] #Actual value of closest element in list2 list2 = list2[list2 != closest_element] #Remove closest element after found print(i, list1[i], min_val_index[0][0], closest_element[0]) #List1 Index, Element to find, List2 Index, Closest Element index_dfx1.append(i) index_yy2.append(min_val_index[0][0]) else: #All elements are already found print(i, list1[i], 'No further closest unique closest elements found in list2') idx_dfx1 = index_dfx1 idx_yy2 = index_yy2 print(idx_dfx1) print(idx_yy2) } ```# #Now I want to optimize between two "uu" , "df_nump" matrix to determine the best value of the "a" , "b" , "alpha" parameters ,And determine the amount of #error based on the square root (R-square) method i attach the excel file #https://drive.google.com/file/d/1tRpKh37MNe3KWsSmFKreipB5Ymv-#V1QY/view?usp=sharing « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post Estimating transition matrices in python Shreya10o 1 370 May-14-2020, 10:41 PM Last Post: Larz60+ excel data erase d8a988 1 182 Apr-27-2020, 05:43 PM Last Post: snippsat scipy.optimize.basinhopping generates unstable output bb19x11 0 183 Mar-09-2020, 04:07 PM Last Post: bb19x11 Python read Excel cell data validation anantpatil 0 353 Jan-31-2020, 04:57 PM Last Post: anantpatil Need Help With Filtering Data For Excel Files Using Pandas eddywinch82 9 1,033 Aug-06-2019, 03:44 PM Last Post: eddywinch82 Aligning excel data gat 1 493 Jun-17-2019, 07:05 PM Last Post: michalmonday Copy raw data in excel to another new excel file keerthiprashanth 5 1,022 Oct-20-2018, 10:13 AM Last Post: volcano63 Solve a system of non-linear equations in Python (scipy.optimize.fsolve) drudox 7 13,769 Aug-18-2018, 02:27 AM Last Post: scidam Pandas dataframe: sum of exponentially weighted correlation matrices per row vvvcvvcv 1 1,115 May-29-2018, 01:09 AM Last Post: scidam minimize with scipy.optimize tobenmoben 0 1,012 Feb-17-2018, 01:47 PM Last Post: tobenmoben

Forum Jump:

Users browsing this thread: 1 Guest(s)