def data_error(self, X_data, ph_data, X_D, g_x_func, s, p): """ Calculate the error for a single data point (by summing each element Sigma n-1 at a single phase equilibrium point). (should be in loop: for ph, ind in zip(p.m['Data phases'], range(len(p.m['Data phases']))): """ from ncomp import phase_equilibrium_calculation as pec from ncomp import dual_equal import numpy #Z_0 = sorted(X_D)[len(X_D) // 2] # TODO: Estimate in middle of all equilibrium points in X_data Z_0 = self.d_Z_0(X_data[0], X_data[1]) #dual_equal(s, p, g_x_func, Z_0) X_eq, g_eq, phase_eq = pec(s, p, g_x_func, Z_0) if len(X_eq) < len(X_data): epsilon_x = len(X_data) # Sigma n - 1 elements of data points elif len(X_eq) == len(X_data): #Epsilon_x = [] epsilon_x = 0.0 data_ind = numpy.argsort(ph_data) model_ind = numpy.argsort(phase_eq) #X_data[data_ind] for i in range(len(X_data)): epsilon_x += abs(X_data[data_ind[i]] - X_eq[model_ind[i]]) #for X_sol, ph in zip(X_eq, phase_eq): #for X_sol in X_eq: #for ph in p.m['Data phases']: # epsilon_x += #for ph_eq in phase_eq: # for ph_dat in ph_data: # if ph_eq == ph_dat: # for i in range(p.m['n']): # Epsilon_x.append(abs(X_sol[i] - X_data[i])) # # elif len(X_eq) > len(X_data): # Epsilon_x = [] # for X in X_eq: # for X_sol, ph in zip(X, phase_eq): # if ph == ph_data: # for i in range(p.m['n']): # Epsilon_x.append(abs(X_sol[i] - X_data[i])) # epsilon_x = min(Epsilon_x) elif len(X_eq) > len(X_data): epsilon_x = len(X_data) return epsilon_x
# Simulate specifications if data.P is not None and data.T is not None and data.Z_0 is None: ph_eq, mph_eq, mph_ph = \ psd(g_x_func, s, p, data.P, data.T, n=100, #n_dual=1, LLE_only=data.lle_only, VLE_only=data.vle_only, Plot_Results=True) # Tested/working print('ph_eq = {}'.format(ph_eq)) print('mph_eq = {}'.format(mph_eq)) print('mph_ph = {}'.format(mph_ph)) if data.P is not None and data.T is not None and data.Z_0 is not None: pec(s, p, g_x_func, data.Z_0, k=None, P=data.P, T=data.T, tol=1e-9, Print_Results=True, Plot_Results=data.plot_gibbs) # Not tested if data.plot_gibbs: #TODO: No need for this if we plot in pec? pass # Need to add tie lines #options = plot.plot_options #plot.plot_g_mix(s, p, options, figno=None) #plot.plot_g_mix(s, p, g_x_func)#, figno=None) if data.plot_isotherms is not None: from ncomp import g_mix as g_x_func from plot import IsoDetection iso = IsoDetection(components=data.comps) import time start = time.time()
psd(g_x_func, s, p, data.P, data.T, n=100, #n_dual=1, LLE_only=data.lle_only, VLE_only=data.vle_only, Plot_Results=True) # Tested/working print('ph_eq = {}'.format(ph_eq)) print('mph_eq = {}'.format(mph_eq)) print('mph_ph = {}'.format(mph_ph)) if data.P is not None and data.T is not None and data.Z_0 is not None: pec(s, p, g_x_func, data.Z_0, k=None, P=data.P, T=data.T, tol=1e-9, Print_Results=True, Plot_Results=data.plot_gibbs) # Not tested if data.plot_gibbs: #TODO: No need for this if we plot in pec? pass # Need to add tie lines #options = plot.plot_options #plot.plot_g_mix(s, p, options, figno=None) #plot.plot_g_mix(s, p, g_x_func)#, figno=None) if data.plot_isotherms is not None: from ncomp import g_mix as g_x_func from plot import IsoDetection