def draw(self, equation): if not self.parent.x_data: self.parent.x_data = equation.dataCache.allDataCacheDictionary['IndependentData'][0] if not self.parent.y_data: self.parent.y_data = equation.dataCache.allDataCacheDictionary['IndependentData'][1] if not self.parent.z_data: self.parent.z_data = equation.dataCache.allDataCacheDictionary['DependentData'] from mpl_toolkits.mplot3d import Axes3D # 3D apecific from matplotlib import cm # to colormap from blue to red if not self.parent.Z: xModel = numpy.linspace(min(self.parent.x_data), max(self.parent.x_data), 20) yModel = numpy.linspace(min(self.parent.y_data), max(self.parent.y_data), 20) self.parent.X, self.parent.Y = numpy.meshgrid(xModel, yModel) tempcache = equation.dataCache equation.dataCache = pyeq2.dataCache() equation.dataCache.allDataCacheDictionary['IndependentData'] = numpy.array([self.parent.X, self.parent.Y]) equation.dataCache.FindOrCreateAllDataCache(equation) self.parent.Z = equation.CalculateModelPredictions(equation.solvedCoefficients, equation.dataCache.allDataCacheDictionary) equation.dataCache = tempcache self.axes = self.figure.gca(projection='3d') self.axes.plot_surface(self.parent.X, self.parent.Y, self.parent.Z, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=1, antialiased=True) self.axes.scatter(self.parent.x_data, self.parent.y_data, self.parent.z_data) self.axes.set_title('Surface Plot (click-drag with mouse)') # add a title for surface plot self.axes.set_xlabel('X Data') # X axis data label self.axes.set_ylabel('Y Data') # Y axis data label self.axes.set_zlabel('Z Data') # Z axis data label
def draw(self, equation): if not self.parent.x_data: self.parent.x_data = equation.dataCache.allDataCacheDictionary['IndependentData'][0] if not self.parent.y_data: self.parent.y_data = equation.dataCache.allDataCacheDictionary['IndependentData'][1] if not self.parent.z_data: self.parent.z_data = equation.dataCache.allDataCacheDictionary['DependentData'] if not self.parent.Z: xModel = numpy.linspace(min(self.parent.x_data), max(self.parent.x_data), 20) yModel = numpy.linspace(min(self.parent.y_data), max(self.parent.y_data), 20) self.parent.X, self.parent.Y = numpy.meshgrid(xModel, yModel) tempcache = equation.dataCache equation.dataCache = pyeq2.dataCache() equation.dataCache.allDataCacheDictionary['IndependentData'] = numpy.array([self.parent.X, self.parent.Y]) equation.dataCache.FindOrCreateAllDataCache(equation) self.parent.Z = equation.CalculateModelPredictions(equation.solvedCoefficients, equation.dataCache.allDataCacheDictionary) equation.dataCache = tempcache self.axes.plot(self.parent.x_data, self.parent.y_data, 'o') self.axes.set_title('Contour Plot') # add a title for contour plot self.axes.set_xlabel('X Data') # X axis data label self.axes.set_ylabel('Y Data') # Y axis data label numberOfContourLines = 16 CS = matplotlib.pyplot.contour(self.parent.X, self.parent.Y, self.parent.Z, numberOfContourLines, colors='k') matplotlib.pyplot.clabel(CS, inline=1, fontsize=10) # labels for contours
def SurfacePlot(dataObject, inFileName): # raw data for scatterplot x_data = dataObject.IndependentDataArray[0] y_data = dataObject.IndependentDataArray[1] z_data = dataObject.DependentDataArray # create X, Y, Z mesh grid for surface plot xModel = numpy.linspace(min(x_data), max(x_data), 20) yModel = numpy.linspace(min(y_data), max(y_data), 20) X, Y = numpy.meshgrid(xModel, yModel) tempcache = dataObject.equation.dataCache # temporarily store cache dataObject.equation.dataCache = pyeq2.dataCache() dataObject.equation.dataCache.allDataCacheDictionary[ 'IndependentData'] = numpy.array([X, Y]) dataObject.equation.dataCache.FindOrCreateAllDataCache(dataObject.equation) Z = dataObject.equation.CalculateModelPredictions( dataObject.equation.solvedCoefficients, dataObject.equation.dataCache.allDataCacheDictionary) dataObject.equation.dataCache = tempcache # restore cache # matplotlib specific code for the plots fig = plt.figure(figsize=(float(dataObject.graphWidth) / 100.0, float(dataObject.graphHeight) / 100.0), dpi=100) fig.patch.set_visible(False) ax = fig.gca(projection='3d') # create a surface plot using the X, Y, Z mesh data created above ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=1, antialiased=True) # create a scatter plot of the raw data if dataObject.dataPointSize3D == 0.0: # auto ax.scatter(x_data, y_data, z_data) else: ax.scatter(x_data, y_data, z_data, s=dataObject.dataPointSize3D) ax.set_title("Surface Plot") # add a title for surface plot ax.set_xlabel(dataObject.IndependentDataName1) # X axis data label ax.set_ylabel(dataObject.IndependentDataName2) # Y axis data label ax.set_zlabel(dataObject.DependentDataName) # Z axis data label if not inFileName: return [fig, ax, plt] # for use in creating animations else: fig.savefig(inFileName[:-3] + 'png', format='png') if not dataObject.pngOnlyFlag: # function finder results are png-only fig.savefig( inFileName[:-3] + 'svg', format='svg', ) plt.close('all')
def SaveModelScatterConfidence(in_filePath, in_equation, in_title, in_xAxisLabel, in_yAxisLabel): # raw data x_data = in_equation.dataCache.allDataCacheDictionary['IndependentData'][0] y_data = in_equation.dataCache.allDataCacheDictionary['DependentData'] # now create data for the fitted in_equation plot xModel = numpy.linspace(min(x_data), max(x_data)) tempcache = in_equation.dataCache in_equation.dataCache = pyeq2.dataCache() in_equation.dataCache.allDataCacheDictionary['IndependentData'] = numpy.array([xModel, xModel]) in_equation.dataCache.FindOrCreateAllDataCache(in_equation) yModel = in_equation.CalculateModelPredictions(in_equation.solvedCoefficients, in_equation.dataCache.allDataCacheDictionary) in_equation.dataCache = tempcache # now use matplotlib to create the PNG file fig = plt.figure(figsize=(5, 4)) ax = fig.add_subplot(1,1,1) # first the raw data as a scatter plot ax.plot(x_data, y_data, 'D') # now the model as a line plot ax.plot(xModel, yModel) # now calculate confidence intervals # http://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_nlin_sect026.htm # http://www.staff.ncl.ac.uk/tom.holderness/software/pythonlinearfit mean_x = numpy.mean(x_data) # mean of x n = in_equation.nobs # number of samples in the origional fit t_value = scipy.stats.t.ppf(0.975, in_equation.df_e) # (1.0 - (a/2)) is used for two-sided t-test critical value, here a = 0.05 confs = t_value * numpy.sqrt((in_equation.sumOfSquaredErrors/in_equation.df_e)*(1.0/n + (numpy.power((xModel-mean_x),2.0)/ ((numpy.sum(numpy.power(x_data,2)))-n*(numpy.power(mean_x,2.0)))))) # get lower and upper confidence limits based on predicted y and confidence intervals upper = yModel + abs(confs) lower = yModel - abs(confs) # mask off any numbers outside the existing plot limits booleanMask = yModel > matplotlib.pyplot.ylim()[0] booleanMask &= (yModel < matplotlib.pyplot.ylim()[1]) # color scheme improves visibility on black background lines or points ax.plot(xModel[booleanMask], lower[booleanMask], linestyle='solid', color='white') ax.plot(xModel[booleanMask], upper[booleanMask], linestyle='solid', color='white') ax.plot(xModel[booleanMask], lower[booleanMask], linestyle='dashed', color='blue') ax.plot(xModel[booleanMask], upper[booleanMask], linestyle='dashed', color='blue') ax.set_title(in_title) # add a title ax.set_xlabel(in_xAxisLabel) # X axis data label ax.set_ylabel(in_yAxisLabel) # Y axis data label plt.tight_layout() # prevents cropping axis labels fig.savefig(in_filePath) # create PNG file plt.close('all')
def SurfaceAndContourPlots(in_filePathSurface, in_filePathContour, in_equation, in_surfaceTitle, in_contourTitle, in_xAxisLabel, in_yAxisLabel, in_zAxisLabel): # raw data x_data = in_equation.dataCache.allDataCacheDictionary['IndependentData'][0] y_data = in_equation.dataCache.allDataCacheDictionary['IndependentData'][1] z_data = in_equation.dataCache.allDataCacheDictionary['DependentData'] from mpl_toolkits.mplot3d import Axes3D # 3D apecific from matplotlib import cm # to colormap from blue to red fig = plt.figure() ax = fig.gca(projection='3d') xModel = numpy.linspace(min(x_data), max(x_data), 20) yModel = numpy.linspace(min(y_data), max(y_data), 20) X, Y = numpy.meshgrid(xModel, yModel) tempcache = in_equation.dataCache in_equation.dataCache = pyeq2.dataCache() in_equation.dataCache.allDataCacheDictionary['IndependentData'] = numpy.array([X, Y]) in_equation.dataCache.FindOrCreateAllDataCache(in_equation) Z = in_equation.CalculateModelPredictions(in_equation.solvedCoefficients, in_equation.dataCache.allDataCacheDictionary) in_equation.dataCache = tempcache ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=1, antialiased=True) ax.scatter(x_data, y_data, z_data) ax.set_title(in_surfaceTitle) # add a title for surface plot ax.set_xlabel(in_xAxisLabel) # X axis data label ax.set_ylabel(in_yAxisLabel) # Y axis data label ax.set_zlabel(in_zAxisLabel) # Y axis data label plt.tight_layout() # prevents cropping axis labels fig.savefig(in_filePathSurface) # create PNG file plt.close('all') # contour plot here fig = plt.figure(figsize=(5, 4)) ax = fig.add_subplot(1,1,1) ax.plot(x_data, y_data, 'o', color='0.8', markersize=4) # draw these first so contour lines overlay. Color=number is grayscale ax.set_title(in_contourTitle) # add a title for contour plot ax.set_xlabel(in_xAxisLabel) # X data label ax.set_ylabel(in_yAxisLabel) # Y data label numberOfContourLines = 16 CS = plt.contour(X, Y, Z, numberOfContourLines, colors='k') plt.clabel(CS, inline=1, fontsize=10) # labels for contours plt.tight_layout() # prevents cropping axis labels fig.savefig(in_filePathContour) # create PNG file plt.close('all')
def draw(self, equation): if not self.parent.y_data: self.parent.y_data = equation.dataCache.allDataCacheDictionary['DependentData'] if not self.parent.x_data: self.parent.x_data = equation.dataCache.allDataCacheDictionary['IndependentData'][0] # now create data for the fitted equation plot xModel = numpy.linspace(min(self.parent.x_data), max(self.parent.x_data)) tempcache = equation.dataCache equation.dataCache = pyeq2.dataCache() equation.dataCache.allDataCacheDictionary['IndependentData'] = numpy.array([xModel, xModel]) equation.dataCache.FindOrCreateAllDataCache(equation) yModel = equation.CalculateModelPredictions(equation.solvedCoefficients, equation.dataCache.allDataCacheDictionary) equation.dataCache = tempcache # first the raw data as a scatter plot self.axes.plot(self.parent.x_data, self.parent.y_data, 'D') # now the model as a line plot self.axes.plot(xModel, yModel) # now calculate confidence intervals # http://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_nlin_sect026.htm # http://www.staff.ncl.ac.uk/tom.holderness/software/pythonlinearfit mean_x = numpy.mean(self.parent.x_data) # mean of x n = equation.nobs # number of samples in the origional fit t_value = scipy.stats.t.ppf(0.975, equation.df_e) # (1.0 - (a/2)) is used for two-sided t-test critical value, here a = 0.05 confs = t_value * numpy.sqrt((equation.sumOfSquaredErrors/equation.df_e)*(1.0/n + (numpy.power((xModel-mean_x),2.0)/ ((numpy.sum(numpy.power(self.parent.x_data,2)))-n*(numpy.power(mean_x,2.0)))))) # get lower and upper confidence limits based on predicted y and confidence intervals upper = yModel + abs(confs) lower = yModel - abs(confs) # mask off any numbers outside the existing plot limits booleanMask = yModel > matplotlib.pyplot.ylim()[0] booleanMask &= (yModel < matplotlib.pyplot.ylim()[1]) # color scheme improves visibility on black background lines or points self.axes.plot(xModel[booleanMask], lower[booleanMask], linestyle='solid', color='white') self.axes.plot(xModel[booleanMask], upper[booleanMask], linestyle='solid', color='white') self.axes.plot(xModel[booleanMask], lower[booleanMask], linestyle='dashed', color='blue') self.axes.plot(xModel[booleanMask], upper[booleanMask], linestyle='dashed', color='blue') self.axes.set_title('Model With 95% Confidence Limits') # add a title self.axes.set_xlabel('X Data') # X axis data label self.axes.set_ylabel('Y Data') # Y axis data label
def draw(self, equation): if not self.parent.x_data: self.parent.x_data = equation.dataCache.allDataCacheDictionary[ 'IndependentData'][0] if not self.parent.y_data: self.parent.y_data = equation.dataCache.allDataCacheDictionary[ 'IndependentData'][1] if not self.parent.z_data: self.parent.z_data = equation.dataCache.allDataCacheDictionary[ 'DependentData'] from mpl_toolkits.mplot3d import Axes3D # 3D apecific from matplotlib import cm # to colormap from blue to red if not self.parent.Z: xModel = numpy.linspace(min(self.parent.x_data), max(self.parent.x_data), 20) yModel = numpy.linspace(min(self.parent.y_data), max(self.parent.y_data), 20) self.parent.X, self.parent.Y = numpy.meshgrid(xModel, yModel) tempcache = equation.dataCache equation.dataCache = pyeq2.dataCache() equation.dataCache.allDataCacheDictionary[ 'IndependentData'] = numpy.array( [self.parent.X, self.parent.Y]) equation.dataCache.FindOrCreateAllDataCache(equation) self.parent.Z = equation.CalculateModelPredictions( equation.solvedCoefficients, equation.dataCache.allDataCacheDictionary) equation.dataCache = tempcache self.axes = self.figure.gca(projection='3d') self.axes.plot_surface(self.parent.X, self.parent.Y, self.parent.Z, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=1, antialiased=True) self.axes.scatter(self.parent.x_data, self.parent.y_data, self.parent.z_data) self.axes.set_title('Surface Plot (click-drag with mouse)' ) # add a title for surface plot self.axes.set_xlabel('X Data') # X axis data label self.axes.set_ylabel('Y Data') # Y axis data label self.axes.set_zlabel('Z Data') # Z axis data label
def SurfacePlot(dataObject, inFileName): # raw data for scatterplot x_data = dataObject.IndependentDataArray[0] y_data = dataObject.IndependentDataArray[1] z_data = dataObject.DependentDataArray # create X, Y, Z mesh grid for surface plot xModel = numpy.linspace(min(x_data), max(x_data), 20) yModel = numpy.linspace(min(y_data), max(y_data), 20) X, Y = numpy.meshgrid(xModel, yModel) tempcache = dataObject.equation.dataCache # temporarily store cache dataObject.equation.dataCache = pyeq2.dataCache() dataObject.equation.dataCache.allDataCacheDictionary['IndependentData'] = numpy.array([X, Y]) dataObject.equation.dataCache.FindOrCreateAllDataCache(dataObject.equation) Z = dataObject.equation.CalculateModelPredictions(dataObject.equation.solvedCoefficients, dataObject.equation.dataCache.allDataCacheDictionary) dataObject.equation.dataCache = tempcache # restore cache # matplotlib specific code for the plots fig = plt.figure(figsize=(float(dataObject.graphWidth) / 100.0, float(dataObject.graphHeight) / 100.0), dpi=100) fig.patch.set_visible(False) ax = fig.gca(projection='3d') # create a surface plot using the X, Y, Z mesh data created above ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=1, antialiased=True) # create a scatter plot of the raw data if dataObject.dataPointSize3D == 0.0: # auto ax.scatter(x_data, y_data, z_data) else: ax.scatter(x_data, y_data, z_data, s=dataObject.dataPointSize3D) ax.set_title("Surface Plot") # add a title for surface plot ax.set_xlabel(dataObject.IndependentDataName1) # X axis data label ax.set_ylabel(dataObject.IndependentDataName2) # Y axis data label ax.set_zlabel(dataObject.DependentDataName) # Z axis data label if not inFileName: return [fig, ax, plt] # for use in creating animations else: fig.savefig(inFileName[:-3] + 'png', format = 'png') if not dataObject.pngOnlyFlag: # function finder results are png-only fig.savefig(inFileName[:-3] + 'svg', format = 'svg', ) plt.close('all')
def draw(self, equation): if not self.parent.x_data: self.parent.x_data = equation.dataCache.allDataCacheDictionary[ 'IndependentData'][0] if not self.parent.y_data: self.parent.y_data = equation.dataCache.allDataCacheDictionary[ 'IndependentData'][1] if not self.parent.z_data: self.parent.z_data = equation.dataCache.allDataCacheDictionary[ 'DependentData'] if not self.parent.Z: xModel = numpy.linspace(min(self.parent.x_data), max(self.parent.x_data), 20) yModel = numpy.linspace(min(self.parent.y_data), max(self.parent.y_data), 20) self.parent.X, self.parent.Y = numpy.meshgrid(xModel, yModel) tempcache = equation.dataCache equation.dataCache = pyeq2.dataCache() equation.dataCache.allDataCacheDictionary[ 'IndependentData'] = numpy.array( [self.parent.X, self.parent.Y]) equation.dataCache.FindOrCreateAllDataCache(equation) self.parent.Z = equation.CalculateModelPredictions( equation.solvedCoefficients, equation.dataCache.allDataCacheDictionary) equation.dataCache = tempcache self.axes.plot(self.parent.x_data, self.parent.y_data, 'o') self.axes.set_title('Contour Plot') # add a title for contour plot self.axes.set_xlabel('X Data') # X axis data label self.axes.set_ylabel('Y Data') # Y axis data label numberOfContourLines = 16 CS = matplotlib.pyplot.contour(self.parent.X, self.parent.Y, self.parent.Z, numberOfContourLines, colors='k') matplotlib.pyplot.clabel(CS, inline=1, fontsize=10) # labels for contours
def SaveModelScatterConfidence(in_filePath, in_equation, in_title, in_xAxisLabel, in_yAxisLabel): # raw data x_data = in_equation.dataCache.allDataCacheDictionary['IndependentData'][0] y_data = in_equation.dataCache.allDataCacheDictionary['DependentData'] # now create data for the fitted in_equation plot xModel = numpy.linspace(min(x_data), max(x_data)) tempcache = in_equation.dataCache in_equation.dataCache = pyeq2.dataCache() in_equation.dataCache.allDataCacheDictionary[ 'IndependentData'] = numpy.array([xModel, xModel]) in_equation.dataCache.FindOrCreateAllDataCache(in_equation) yModel = in_equation.CalculateModelPredictions( in_equation.solvedCoefficients, in_equation.dataCache.allDataCacheDictionary) in_equation.dataCache = tempcache # now use matplotlib to create the PNG file fig = plt.figure(figsize=(5, 4)) ax = fig.add_subplot(1, 1, 1) # first the raw data as a scatter plot ax.plot(x_data, y_data, 'D') # now the model as a line plot ax.plot(xModel, yModel) # now calculate confidence intervals # http://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_nlin_sect026.htm # http://www.staff.ncl.ac.uk/tom.holderness/software/pythonlinearfit mean_x = numpy.mean(x_data) # mean of x n = in_equation.nobs # number of samples in the origional fit t_value = scipy.stats.t.ppf( 0.975, in_equation.df_e ) # (1.0 - (a/2)) is used for two-sided t-test critical value, here a = 0.05 confs = t_value * numpy.sqrt( (in_equation.sumOfSquaredErrors / in_equation.df_e) * (1.0 / n + (numpy.power((xModel - mean_x), 2.0) / ((numpy.sum(numpy.power(x_data, 2))) - n * (numpy.power(mean_x, 2.0)))))) # get lower and upper confidence limits based on predicted y and confidence intervals upper = yModel + abs(confs) lower = yModel - abs(confs) # mask off any numbers outside the existing plot limits booleanMask = yModel > matplotlib.pyplot.ylim()[0] booleanMask &= (yModel < matplotlib.pyplot.ylim()[1]) # color scheme improves visibility on black background lines or points ax.plot(xModel[booleanMask], lower[booleanMask], linestyle='solid', color='white') ax.plot(xModel[booleanMask], upper[booleanMask], linestyle='solid', color='white') ax.plot(xModel[booleanMask], lower[booleanMask], linestyle='dashed', color='blue') ax.plot(xModel[booleanMask], upper[booleanMask], linestyle='dashed', color='blue') ax.set_title(in_title) # add a title ax.set_xlabel(in_xAxisLabel) # X axis data label ax.set_ylabel(in_yAxisLabel) # Y axis data label plt.tight_layout() # prevents cropping axis labels fig.savefig(in_filePath) # create PNG file plt.close('all')
def ParallelFittingFunction(rawData, fittingTargetText, smoothnessControl, modulus, modulusRemainder): processID = str(os.getpid()) # this function yields a single item to inspect after completion bestResult = [] # we are using the same data set repeatedly, so create a cache external to the equations externalCache = pyeq2.dataCache() reducedDataCache = {} equationCountForModulus = 0 ########################## # add named equations here print print 'Process ID', processID, 'fitting named equations:' for submodule in inspect.getmembers(pyeq2.Models_2D): if inspect.ismodule(submodule[1]): for equationClass in inspect.getmembers(submodule[1]): if inspect.isclass(equationClass[1]): # special classes if equationClass[1].splineFlag or \ equationClass[1].userSelectablePolynomialFlag or \ equationClass[1].userSelectablePolyfunctionalFlag or \ equationClass[1].userSelectableRationalFlag or \ equationClass[1].userDefinedFunctionFlag: continue for extendedVersion in ['Default', 'Offset']: if (extendedVersion == 'Offset') and ( equationClass[1].autoGenerateOffsetForm == False): continue if equationCountForModulus % modulus != modulusRemainder: equationCountForModulus += 1 continue equationCountForModulus += 1 equationInstance = equationClass[1](fittingTargetText, extendedVersion) if len(equationInstance.GetCoefficientDesignators() ) > smoothnessControl: continue equationInstance.dataCache = externalCache # re-use the external cache if equationInstance.dataCache.allDataCacheDictionary == {}: pyeq2.dataConvertorService( ).ConvertAndSortColumnarASCII( rawData, equationInstance, False) equationInstance.dataCache.CalculateNumberOfReducedDataPoints( equationInstance) if reducedDataCache.has_key( equationInstance.numberOfReducedDataPoints): equationInstance.dataCache.reducedDataCacheDictionary = reducedDataCache[ equationInstance.numberOfReducedDataPoints] else: equationInstance.dataCache.reducedDataCacheDictionary = {} result = SetParametersAndFit(equationInstance, bestResult, True, processID) if result: bestResult = result if not reducedDataCache.has_key( equationInstance.numberOfReducedDataPoints): reducedDataCache[ equationInstance. numberOfReducedDataPoints] = equationInstance.dataCache.reducedDataCacheDictionary ########################## # fit polyfunctionals here print print 'Process ID', processID, 'fitting polyfunctionals:' equationCount = 0 maxPolyfunctionalCoefficients = 4 # this value was chosen to make this example more convenient polyfunctionalEquationList = pyeq2.PolyFunctions.GenerateListForPolyfunctionals_2D( ) functionIndexList = range(len(polyfunctionalEquationList) ) # make a list of function indices to permute for coeffCount in range(1, maxPolyfunctionalCoefficients + 1): functionCombinations = UniqueCombinations(functionIndexList, coeffCount) for functionCombination in functionCombinations: if len(functionCombination) > smoothnessControl: continue if equationCountForModulus % modulus != modulusRemainder: equationCountForModulus += 1 continue equationCountForModulus += 1 equationInstance = pyeq2.Models_2D.Polyfunctional.UserSelectablePolyfunctional( fittingTargetText, 'Default', functionCombination, polyfunctionalEquationList) equationInstance.dataCache = externalCache # re-use the external cache if equationInstance.dataCache.allDataCacheDictionary == {}: pyeq2.dataConvertorService().ConvertAndSortColumnarASCII( rawData, equationInstance, False) equationInstance.dataCache.CalculateNumberOfReducedDataPoints( equationInstance) if reducedDataCache.has_key( equationInstance.numberOfReducedDataPoints): equationInstance.dataCache.reducedDataCacheDictionary = reducedDataCache[ equationInstance.numberOfReducedDataPoints] else: equationInstance.dataCache.reducedDataCacheDictionary = {} result = SetParametersAndFit(equationInstance, bestResult, False) if result: bestResult = result if not reducedDataCache.has_key( equationInstance.numberOfReducedDataPoints): reducedDataCache[ equationInstance. numberOfReducedDataPoints] = equationInstance.dataCache.reducedDataCacheDictionary equationCount += 1 if (equationCount % 50) == 0: print ' Process ID', processID, 'fitted', equationCount, 'equations...' ###################### # fit user-selectable polynomials here print print 'Process ID', processID, 'fitting user-selectable polynomials:' maxPolynomialOrderX = 5 # this value was chosen to make this example more convenient for polynomialOrderX in range(maxPolynomialOrderX + 1): if (polynomialOrderX + 1) > smoothnessControl: continue if equationCountForModulus % modulus != modulusRemainder: equationCountForModulus += 1 continue equationCountForModulus += 1 equationInstance = pyeq2.Models_2D.Polynomial.UserSelectablePolynomial( fittingTargetText, 'Default', polynomialOrderX) equationInstance.dataCache = externalCache # re-use the external cache if equationInstance.dataCache.allDataCacheDictionary == {}: pyeq2.dataConvertorService().ConvertAndSortColumnarASCII( rawData, equationInstance, False) equationInstance.dataCache.CalculateNumberOfReducedDataPoints( equationInstance) if reducedDataCache.has_key( equationInstance.numberOfReducedDataPoints): equationInstance.dataCache.reducedDataCacheDictionary = reducedDataCache[ equationInstance.numberOfReducedDataPoints] else: equationInstance.dataCache.reducedDataCacheDictionary = {} result = SetParametersAndFit(equationInstance, bestResult, False) if result: bestResult = result if not reducedDataCache.has_key( equationInstance.numberOfReducedDataPoints): reducedDataCache[ equationInstance. numberOfReducedDataPoints] = equationInstance.dataCache.reducedDataCacheDictionary ###################### # fit user-selectable rationals here print print 'Process ID', processID, 'fitting user-selectable rationals:' equationCount = 0 maxCoeffs = smoothnessControl # arbitrary choice of maximum total coefficients for this example functionList = pyeq2.PolyFunctions.GenerateListForRationals_2D() functionIndexList = range( len(functionList)) # make a list of function indices for numeratorCoeffCount in range(1, maxCoeffs): numeratorComboList = UniqueCombinations(functionIndexList, numeratorCoeffCount) for numeratorCombo in numeratorComboList: for denominatorCoeffCount in range(1, maxCoeffs): denominatorComboList = UniqueCombinations2( functionIndexList, denominatorCoeffCount) for denominatorCombo in denominatorComboList: for extendedVersion in ['Default', 'Offset']: extraCoeffs = 0 if extendedVersion == 'Offset': extraCoeffs = 1 if (len(numeratorCombo) + len(denominatorCombo) + extraCoeffs) > smoothnessControl: continue if equationCountForModulus % modulus != modulusRemainder: equationCountForModulus += 1 continue equationCountForModulus += 1 equationInstance = pyeq2.Models_2D.Rational.UserSelectableRational( fittingTargetText, extendedVersion, numeratorCombo, denominatorCombo, functionList) equationInstance.dataCache = externalCache # re-use the external cache if equationInstance.dataCache.allDataCacheDictionary == {}: pyeq2.dataConvertorService( ).ConvertAndSortColumnarASCII( rawData, equationInstance, False) equationInstance.dataCache.CalculateNumberOfReducedDataPoints( equationInstance) if reducedDataCache.has_key( equationInstance.numberOfReducedDataPoints): equationInstance.dataCache.reducedDataCacheDictionary = reducedDataCache[ equationInstance.numberOfReducedDataPoints] else: equationInstance.dataCache.reducedDataCacheDictionary = {} result = SetParametersAndFit(equationInstance, bestResult, False) if result: bestResult = result if not reducedDataCache.has_key( equationInstance.numberOfReducedDataPoints): reducedDataCache[ equationInstance. numberOfReducedDataPoints] = equationInstance.dataCache.reducedDataCacheDictionary equationCount += 1 if (equationCount % 5) == 0: print ' ', 'Process ID', processID + ',', equationCount, 'rationals, current flags:', equationInstance.rationalNumeratorFlags, equationInstance.rationalDenominatorFlags, if extendedVersion == 'Offset': print 'with offset' else: print print 'Process ID', processID, 'has completed' return bestResult
def __init__(self, inFittingTarget = 'SSQABS', inExtendedVersionName = 'Default'): if inExtendedVersionName == '': inExtendedVersionName = 'Default' if inFittingTarget not in self.fittingTargetDictionary.keys(): raise Exception, str(inFittingTarget) + ' is not in the IModel class fitting target dictionary.' self.extendedVersionHandler = eval('pyeq2.ExtendedVersionHandlers.ExtendedVersionHandler_' + inExtendedVersionName.replace(' ', '') + '.ExtendedVersionHandler_' + inExtendedVersionName.replace(' ', '') + '()') self.dataCache = pyeq2.dataCache() self.upperCoefficientBounds = [] self.lowerCoefficientBounds = [] self.estimatedCoefficients = [] self.fixedCoefficients = [] self.solvedCoefficients = [] self.polyfunctional2DFlags = [] self.polyfunctional3DFlags = [] self.xPolynomialOrder = None self.yPolynomialOrder = None self.rationalNumeratorFlags = [] self.rationalDenominatorFlags = [] self.fittingTarget = inFittingTarget self.deEstimatedCoefficients = [] self.independentData1CannotContainZeroFlag = False self.independentData1CannotContainPositiveFlag = False self.independentData1CannotContainNegativeFlag = False self.independentData2CannotContainZeroFlag = False self.independentData2CannotContainPositiveFlag = False self.independentData2CannotContainNegativeFlag = False try: if self._dimensionality == 2: self.exampleData = ''' X Y 5.357 0.376 5.457 0.489 5.797 0.874 5.936 1.049 6.161 1.327 6.697 2.054 6.731 2.077 6.775 2.138 8.442 4.744 9.769 7.068 9.861 7.104 ''' else: self.exampleData = ''' X Y Z 3.017 2.175 0.320 2.822 2.624 0.629 2.632 2.839 0.950 2.287 3.030 1.574 2.207 3.057 1.725 2.048 3.098 2.035 1.963 3.115 2.204 1.784 3.144 2.570 1.712 3.153 2.721 2.972 2.106 0.313 2.719 2.542 0.643 2.495 2.721 0.956 2.070 2.878 1.597 1.969 2.899 1.758 1.768 2.929 2.088 1.677 2.939 2.240 1.479 2.957 2.583 1.387 2.963 2.744 2.843 1.984 0.315 2.485 2.320 0.639 2.163 2.444 0.954 1.687 2.525 1.459 1.408 2.547 1.775 1.279 2.554 1.927 1.016 2.564 2.243 0.742 2.568 2.581 0.607 2.571 2.753 ''' except: pass
def ContourPlot(in_DataObject, in_FileNameAndPath): gridResolution = (in_DataObject.graphWidth + in_DataObject.graphHeight) / 20 gxmin = in_DataObject.gxmin gxmax = in_DataObject.gxmax gymin = in_DataObject.gymin gymax = in_DataObject.gymax if in_DataObject.equation.independentData1CannotContainNegativeFlag and gxmin < 0.0: gxmin = 0.0 if in_DataObject.equation.independentData1CannotContainZeroFlag and gxmin == 0.0: gxmin = 1.0E-300 if in_DataObject.equation.independentData1CannotContainPositiveFlag and gxmax > 0.0: gxmax = 0.0 if in_DataObject.equation.independentData1CannotContainZeroFlag and gxmax == 0.0: gxmax = 1.0E-300 if in_DataObject.equation.independentData2CannotContainNegativeFlag and gymin < 0.0: gymin = 0.0 if in_DataObject.equation.independentData2CannotContainZeroFlag and gymin == 0.0: gymin = 1.0E-300 if in_DataObject.equation.independentData2CannotContainPositiveFlag and gymax > 0.0: gymax = 0.0 if in_DataObject.equation.independentData2CannotContainZeroFlag and gymax == 0.0: gymax = 1.0E-300 deltax = (gxmax - gxmin) / float(gridResolution) deltay = (gymax - gymin) / float(gridResolution) xRange = numpy.arange(gxmin, gxmax + deltax, deltax) yRange = numpy.arange(gymin, gymax + deltay / 2.0, deltay) minZ = min(in_DataObject.DependentDataArray) maxZ = max(in_DataObject.DependentDataArray) X, Y = numpy.meshgrid(xRange, yRange) boundingRectangle = matplotlib.patches.Rectangle([gxmin, gymin], gxmax - gxmin, gymax - gymin, facecolor=(0.975, 0.975, 0.975), edgecolor=(0.9, 0.9, 0.9)) Z = [] tempDataCache = in_DataObject.equation.dataCache for i in range(len(X)): in_DataObject.equation.dataCache = pyeq2.dataCache() in_DataObject.equation.dataCache.allDataCacheDictionary[ 'IndependentData'] = numpy.array([X[i], Y[i]]) in_DataObject.equation.dataCache.FindOrCreateAllDataCache( in_DataObject.equation) Z.append( in_DataObject.equation.CalculateModelPredictions( in_DataObject.equation.solvedCoefficients, in_DataObject.equation.dataCache.allDataCacheDictionary)) in_DataObject.equation.dataCache = tempDataCache Z = numpy.array(Z) Z = numpy.clip(Z, minZ, maxZ) tempData = [ in_DataObject.IndependentDataArray[0], in_DataObject.IndependentDataArray[1], in_DataObject.DependentDataArray ] ContourPlot_NoDataObject( X, Y, Z, tempData, in_FileNameAndPath, in_DataObject.IndependentDataName1, in_DataObject.IndependentDataName2, in_DataObject.graphWidth, in_DataObject.graphHeight, 'UseOffset_ON', 'ScientificNotation_X_AUTO', 'ScientificNotation_Y_AUTO', in_DataObject.pngOnlyFlag, boundingRectangle) plt.close()
def __init__(self, inFittingTarget='SSQABS', inExtendedVersionName='Default'): if inExtendedVersionName == '': inExtendedVersionName = 'Default' if inFittingTarget not in list(self.fittingTargetDictionary.keys()): raise Exception( str(inFittingTarget) + ' is not in the IModel class fitting target dictionary.') self.fittingTarget = inFittingTarget inExtendedVersionName = inExtendedVersionName.replace(' ', '') if inExtendedVersionName not in pyeq2.ExtendedVersionHandlers.extendedVersionHandlerNameList: raise Exception( inExtendedVersionName + ' is not in the list of extended version handler names.') allowedExtendedVersion = True if (-1 != inExtendedVersionName.find('Offset')) and ( self.autoGenerateOffsetForm == False): allowedExtendedVersion = False if (-1 != inExtendedVersionName.find('Reciprocal')) and ( self.autoGenerateReciprocalForm == False): allowedExtendedVersion = False if (-1 != inExtendedVersionName.find('Inverse')) and ( self.autoGenerateInverseForms == False): allowedExtendedVersion = False if (-1 != inExtendedVersionName.find('Growth')) and ( self.autoGenerateGrowthAndDecayForms == False): allowedExtendedVersion = False if (-1 != inExtendedVersionName.find('Decay')) and ( self.autoGenerateGrowthAndDecayForms == False): allowedExtendedVersion = False if allowedExtendedVersion == False: raise Exception( 'This equation does not allow an extended version named "' + inExtendedVersionName + '".') self.extendedVersionHandler = eval( 'pyeq2.ExtendedVersionHandlers.ExtendedVersionHandler_' + inExtendedVersionName + '.ExtendedVersionHandler_' + inExtendedVersionName + '()') self.dataCache = pyeq2.dataCache() self.upperCoefficientBounds = [] self.lowerCoefficientBounds = [] self.estimatedCoefficients = [] self.fixedCoefficients = [] self.solvedCoefficients = [] self.polyfunctional2DFlags = [] self.polyfunctional3DFlags = [] self.xPolynomialOrder = None self.yPolynomialOrder = None self.rationalNumeratorFlags = [] self.rationalDenominatorFlags = [] self.deEstimatedCoefficients = [] try: if self._dimensionality == 2: self.exampleData = ''' X Y 5.357 0.376 5.457 0.489 5.797 0.874 5.936 1.049 6.161 1.327 6.697 2.054 6.731 2.077 6.775 2.138 8.442 4.744 9.769 7.068 9.861 7.104 ''' else: self.exampleData = ''' X Y Z 3.017 2.175 0.320 2.822 2.624 0.629 2.632 2.839 0.950 2.287 3.030 1.574 2.207 3.057 1.725 2.048 3.098 2.035 1.963 3.115 2.204 1.784 3.144 2.570 1.712 3.153 2.721 2.972 2.106 0.313 2.719 2.542 0.643 2.495 2.721 0.956 2.070 2.878 1.597 1.969 2.899 1.758 1.768 2.929 2.088 1.677 2.939 2.240 1.479 2.957 2.583 1.387 2.963 2.744 2.843 1.984 0.315 2.485 2.320 0.639 2.163 2.444 0.954 1.687 2.525 1.459 1.408 2.547 1.775 1.279 2.554 1.927 1.016 2.564 2.243 0.742 2.568 2.581 0.607 2.571 2.753 ''' except: pass
def __init__(self, inFittingTarget='SSQABS', inExtendedVersionName='Default'): self.dataCache = pyeq2.dataCache() self._dimensionality = 3
def ScatterPlotWithOptionalModel_NoDataObject( in_DataToPlot, in_FileNameAndPath, in_DataNameX, in_DataNameY, in_WidthInPixels, in_HeightInPixels, in_Equation, in_UseOffsetIfNeeded, in_ReverseXY, in_X_UseScientificNotationIfNeeded, in_Y_UseScientificNotationIfNeeded, in_GraphBounds, in_LogY, in_LogX, inPNGOnlyFlag, inConfidenceIntervalsFlag): # decode ends of strings ('XYZ_ON', 'XYZ_OFF', 'XYZ_AUTO', etc.) to boolean values scientificNotationX = DetermineScientificNotationFromString( in_DataToPlot[0], in_X_UseScientificNotationIfNeeded) scientificNotationY = DetermineScientificNotationFromString( in_DataToPlot[1], in_Y_UseScientificNotationIfNeeded) useOffsetIfNeeded = DetermineOnOrOffFromString(in_UseOffsetIfNeeded) reverseXY = DetermineOnOrOffFromString(in_ReverseXY) if in_Equation: # make model data for plotting, clipping at boundaries lowerXbound = in_GraphBounds[0] upperXbound = in_GraphBounds[1] if in_Equation.independentData1CannotContainNegativeFlag and lowerXbound < 0.0: lowerXbound = 0.0 if in_Equation.independentData1CannotContainZeroFlag and lowerXbound == 0.0: lowerXbound = 1.0E-300 if in_Equation.independentData1CannotContainPositiveFlag and upperXbound > 0.0: upperXbound = 0.0 if in_Equation.independentData1CannotContainZeroFlag and upperXbound == 0.0: upperXbound = 1.0E-300 xRange = numpy.arange( lowerXbound, upperXbound, (upperXbound - lowerXbound) / (20.0 * float(in_WidthInPixels + in_HeightInPixels)) ) # make this 'reverse-xy-independent' tempDataCache = in_Equation.dataCache in_Equation.dataCache = pyeq2.dataCache() in_Equation.dataCache.allDataCacheDictionary[ 'IndependentData'] = numpy.array([xRange, xRange]) in_Equation.dataCache.FindOrCreateAllDataCache(in_Equation) yRange = in_Equation.CalculateModelPredictions( in_Equation.solvedCoefficients, in_Equation.dataCache.allDataCacheDictionary) in_Equation.dataCache = tempDataCache if reverseXY: fig, ax = CommonPlottingCode(in_WidthInPixels, in_HeightInPixels, in_DataNameX, in_DataNameY, useOffsetIfNeeded, scientificNotationY, scientificNotationX, 0.0, 0.0, 1.0, 1.0) ax.plot(numpy.array([in_GraphBounds[2], in_GraphBounds[3]]), numpy.array([in_GraphBounds[0], in_GraphBounds[1] ])) # first ax.plot() is only with extents newLeft, newBottom, newRight, newTop, numberOfMajor_X_TickMarks = YieldNewExtentsAndNumberOfMajor_X_TickMarks( fig, ax, in_WidthInPixels, in_HeightInPixels, scientificNotationY or useOffsetIfNeeded) fig, ax = CommonPlottingCode(in_WidthInPixels, in_HeightInPixels, in_DataNameX, in_DataNameY, useOffsetIfNeeded, scientificNotationY, scientificNotationX, newLeft, newBottom, newRight, newTop) if in_LogY == 'LOG' and in_LogX == 'LOG': loglinplot = ax.loglog elif in_LogY == 'LIN' and in_LogX == 'LOG': loglinplot = ax.semilogx elif in_LogY == 'LOG' and in_LogX == 'LIN': loglinplot = ax.semilogy else: loglinplot = ax.plot if len(ax.get_xticklabels()) > numberOfMajor_X_TickMarks: ax.xaxis.set_major_locator( matplotlib.ticker.MaxNLocator(numberOfMajor_X_TickMarks)) loglinplot(numpy.array([in_GraphBounds[2], in_GraphBounds[3]]), numpy.array([in_GraphBounds[0], in_GraphBounds[1]]), visible=False) loglinplot(in_DataToPlot[1], in_DataToPlot[0], 'o', markersize=3) if (min(in_DataToPlot[0]) < in_GraphBounds[0]) or (max( in_DataToPlot[0]) > in_GraphBounds[1]): matplotlib.pyplot.ylim(in_GraphBounds[0], in_GraphBounds[1]) if (min(in_DataToPlot[1]) < in_GraphBounds[2]) or (max( in_DataToPlot[1]) > in_GraphBounds[3]): matplotlib.pyplot.xlim(in_GraphBounds[2], in_GraphBounds[3]) else: fig, ax = CommonPlottingCode(in_WidthInPixels, in_HeightInPixels, in_DataNameX, in_DataNameY, useOffsetIfNeeded, scientificNotationX, scientificNotationY, 0.0, 0.0, 1.0, 1.0) ax.plot(numpy.array([in_GraphBounds[0], in_GraphBounds[1]]), numpy.array([in_GraphBounds[2], in_GraphBounds[3] ])) # first ax.plot() is only with extents newLeft, newBottom, newRight, newTop, numberOfMajor_X_TickMarks = YieldNewExtentsAndNumberOfMajor_X_TickMarks( fig, ax, in_WidthInPixels, in_HeightInPixels, scientificNotationY or useOffsetIfNeeded) fig, ax = CommonPlottingCode(in_WidthInPixels, in_HeightInPixels, in_DataNameX, in_DataNameY, useOffsetIfNeeded, scientificNotationX, scientificNotationY, newLeft, newBottom, newRight, newTop) if in_LogY == 'LOG' and in_LogX == 'LOG': loglinplot = ax.loglog elif in_LogY == 'LIN' and in_LogX == 'LOG': loglinplot = ax.semilogx elif in_LogY == 'LOG' and in_LogX == 'LIN': loglinplot = ax.semilogy else: loglinplot = ax.plot if len(ax.get_xticklabels()) > numberOfMajor_X_TickMarks: ax.xaxis.set_major_locator( matplotlib.ticker.MaxNLocator(numberOfMajor_X_TickMarks)) loglinplot(numpy.array([in_GraphBounds[0], in_GraphBounds[1]]), numpy.array([in_GraphBounds[2], in_GraphBounds[3]]), visible=False) loglinplot(in_DataToPlot[0], in_DataToPlot[1], 'o', markersize=3) if (min(in_DataToPlot[0]) <= in_GraphBounds[0]) or (max( in_DataToPlot[0]) >= in_GraphBounds[1]): matplotlib.pyplot.xlim(in_GraphBounds[0], in_GraphBounds[1]) if (min(in_DataToPlot[1]) <= in_GraphBounds[2]) or (max( in_DataToPlot[1]) >= in_GraphBounds[3]): matplotlib.pyplot.ylim(in_GraphBounds[2], in_GraphBounds[3]) if in_Equation: booleanMask = yRange > matplotlib.pyplot.ylim()[0] booleanMask &= (yRange < matplotlib.pyplot.ylim()[1]) booleanMask &= (xRange > matplotlib.pyplot.xlim()[0]) booleanMask &= (xRange < matplotlib.pyplot.xlim()[1]) loglinplot(xRange[booleanMask], yRange[booleanMask], 'k') # model on top of data points if inConfidenceIntervalsFlag: # now calculate confidence intervals for new test x-series # http://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_nlin_sect026.htm # http://www.staff.ncl.ac.uk/tom.holderness/software/pythonlinearfit mean_x = numpy.mean(in_DataToPlot[0]) # mean of x n = in_Equation.nobs # number of samples in origional fit if len(in_Equation.dataCache.allDataCacheDictionary['Weights'] ): t_value = scipy.stats.t.ppf( 0.975, in_Equation.df_e_weighted ) # (1.0 - (a/2)) is used for two-sided t-test critical value, here a = 0.05 confs = t_value * numpy.sqrt( (in_Equation.sumOfSquaredErrors_weighted / in_Equation.df_e_weighted) * (1.0 / n + (numpy.power((xRange - mean_x), 2) / ((numpy.sum(numpy.power(in_DataToPlot[0], 2))) - n * (numpy.power(mean_x, 2)))))) else: t_value = scipy.stats.t.ppf( 0.975, in_Equation.df_e ) # (1.0 - (a/2)) is used for two-sided t-test critical value, here a = 0.05 confs = t_value * numpy.sqrt( (in_Equation.sumOfSquaredErrors / in_Equation.df_e) * (1.0 / n + (numpy.power((xRange - mean_x), 2) / ((numpy.sum(numpy.power(in_DataToPlot[0], 2))) - n * (numpy.power(mean_x, 2)))))) # get lower and upper confidence limits based on predicted y and confidence intervals upper = yRange + abs(confs) lower = yRange - abs(confs) booleanMask &= (numpy.array(yRange) < 1.0E290) booleanMask &= (upper < 1.0E290) booleanMask &= (lower < 1.0E290) # color scheme improves visibility on black background lines or points loglinplot(xRange[booleanMask], lower[booleanMask], linestyle='solid', color='white') loglinplot(xRange[booleanMask], upper[booleanMask], linestyle='solid', color='white') loglinplot(xRange[booleanMask], lower[booleanMask], linestyle='dashed', color='blue') loglinplot(xRange[booleanMask], upper[booleanMask], linestyle='dashed', color='blue') fig.savefig(in_FileNameAndPath[:-3] + 'png', format='png') if not inPNGOnlyFlag: fig.savefig(in_FileNameAndPath[:-3] + 'svg', format='svg') plt.close()
pyeq2.dataConvertorService().ConvertAndSortColumnarASCII( equation.exampleData, equation, False) equation.Solve() # raw data for scatterplot x_data = equation.dataCache.allDataCacheDictionary['IndependentData'][0] y_data = equation.dataCache.allDataCacheDictionary['IndependentData'][1] z_data = equation.dataCache.allDataCacheDictionary['DependentData'] # create X, Y, Z mesh grid for surface plot print "Creating mesh grid data" xModel = numpy.linspace(min(x_data), max(x_data), 20) yModel = numpy.linspace(min(y_data), max(y_data), 20) X, Y = numpy.meshgrid(xModel, yModel) tempcache = equation.dataCache equation.dataCache = pyeq2.dataCache() equation.dataCache.allDataCacheDictionary['IndependentData'] = numpy.array( [X, Y]) equation.dataCache.FindOrCreateAllDataCache(equation) Z = equation.CalculateModelPredictions( equation.solvedCoefficients, equation.dataCache.allDataCacheDictionary) equation.dataCache = tempcache # matplotlib specific code for the plots fig = plt.figure(figsize=(float(graphWidth) / 100.0, float(graphHeight) / 100.0), dpi=100) ax = fig.gca(projection='3d') print "Creating matplotlib graph objects" # create a surface plot using the X, Y, Z mesh data created above
def serialWorker(inputQueue, outputQueue): for func, args in iter(inputQueue.get, 'STOP'): # iter() has different behaviors depending on number of parameters outputQueue.put(func(*args)) inputQueue.task_done() if inputQueue.unfinished_tasks == 0: break if __name__ == "__main__": os.nice(10) ####################### I use this during development global globalDataCache globalDataCache = pyeq2.dataCache() global globalReducedDataCache globalReducedDataCache = {} global globalRawData globalRawData = ''' 5.357 0.376 5.457 0.489 5.797 0.874 5.936 1.049 6.161 1.327 6.697 2.054 6.731 2.077 6.775 2.138 8.442 4.744
8.442 4.744 9.769 7.068 9.861 7.104 ''' # this example yields a single item to inspect after completion bestResult = [] # Standard lowest sum-of-squared errors in this example, see IModel.fittingTargetDictionary fittingTargetText = 'SSQABS' if fittingTargetText == 'ODR': raise Exception('ODR cannot use multiple fitting algorithms') # we are using the same data set repeatedly, so create a cache external to the equations externalCache = pyeq2.dataCache() reducedDataCache = {} ##################################################### # this value is used to make the example run faster # ##################################################### smoothnessControl = 3 ########################## # fit named equations here print print 'Fitting named equations that use non-linear solvers for a fitting target of', fittingTargetText for submodule in inspect.getmembers(pyeq2.Models_2D): if inspect.ismodule(submodule[1]): for equationClass in inspect.getmembers(submodule[1]): if inspect.isclass(equationClass[1]):
1.408 2.547 1.775 1.279 2.554 1.927 1.016 2.564 2.243 0.742 2.568 2.581 0.607 2.571 2.753 """ # this example yields a sorted output list to inspect after completion resultList = [] # Standard lowest sum-of-squared errors in this example, see IModel.fittingTargetDictionary fittingTargetText = "SSQABS" # we are using the same data set repeatedly, so create a cache external to the equations externalCache = pyeq2.dataCache() reducedDataCache = {} ##################################################### # this value is used to make the example run faster # ##################################################### smoothnessControl = 3 ########################## # fit named equations here for submodule in inspect.getmembers(pyeq2.Models_3D): if inspect.ismodule(submodule[1]): for equationClass in inspect.getmembers(submodule[1]): if inspect.isclass(equationClass[1]):
def __init__(self, inFittingTarget = 'SSQABS', inExtendedVersionName = 'Default'): if inExtendedVersionName == '': inExtendedVersionName = 'Default' if inFittingTarget not in list(self.fittingTargetDictionary.keys()): raise Exception(str(inFittingTarget) + ' is not in the IModel class fitting target dictionary.') self.fittingTarget = inFittingTarget inExtendedVersionName = inExtendedVersionName.replace(' ', '') if inExtendedVersionName not in pyeq2.ExtendedVersionHandlers.extendedVersionHandlerNameList: raise Exception(inExtendedVersionName + ' is not in the list of extended version handler names.') allowedExtendedVersion = True if (-1 != inExtendedVersionName.find('Offset')) and (self.autoGenerateOffsetForm == False): allowedExtendedVersion = False if (-1 != inExtendedVersionName.find('Reciprocal')) and (self.autoGenerateReciprocalForm == False): allowedExtendedVersion = False if (-1 != inExtendedVersionName.find('Inverse')) and (self.autoGenerateInverseForms == False): allowedExtendedVersion = False if (-1 != inExtendedVersionName.find('Growth')) and (self.autoGenerateGrowthAndDecayForms == False): allowedExtendedVersion = False if (-1 != inExtendedVersionName.find('Decay')) and (self.autoGenerateGrowthAndDecayForms == False): allowedExtendedVersion = False if allowedExtendedVersion == False: raise Exception('This equation does not allow an extended version named "' + inExtendedVersionName + '".') self.extendedVersionHandler = eval('pyeq2.ExtendedVersionHandlers.ExtendedVersionHandler_' + inExtendedVersionName + '.ExtendedVersionHandler_' + inExtendedVersionName + '()') self.dataCache = pyeq2.dataCache() self.upperCoefficientBounds = [] self.lowerCoefficientBounds = [] self.estimatedCoefficients = [] self.fixedCoefficients = [] self.solvedCoefficients = [] self.polyfunctional2DFlags = [] self.polyfunctional3DFlags = [] self.xPolynomialOrder = None self.yPolynomialOrder = None self.rationalNumeratorFlags = [] self.rationalDenominatorFlags = [] self.deEstimatedCoefficients = [] try: if self._dimensionality == 2: self.exampleData = ''' X Y 5.357 0.376 5.457 0.489 5.797 0.874 5.936 1.049 6.161 1.327 6.697 2.054 6.731 2.077 6.775 2.138 8.442 4.744 9.769 7.068 9.861 7.104 ''' else: self.exampleData = ''' X Y Z 3.017 2.175 0.320 2.822 2.624 0.629 2.632 2.839 0.950 2.287 3.030 1.574 2.207 3.057 1.725 2.048 3.098 2.035 1.963 3.115 2.204 1.784 3.144 2.570 1.712 3.153 2.721 2.972 2.106 0.313 2.719 2.542 0.643 2.495 2.721 0.956 2.070 2.878 1.597 1.969 2.899 1.758 1.768 2.929 2.088 1.677 2.939 2.240 1.479 2.957 2.583 1.387 2.963 2.744 2.843 1.984 0.315 2.485 2.320 0.639 2.163 2.444 0.954 1.687 2.525 1.459 1.408 2.547 1.775 1.279 2.554 1.927 1.016 2.564 2.243 0.742 2.568 2.581 0.607 2.571 2.753 ''' except: pass
def draw(self, equation): if not self.parent.y_data: self.parent.y_data = equation.dataCache.allDataCacheDictionary[ 'DependentData'] if not self.parent.x_data: self.parent.x_data = equation.dataCache.allDataCacheDictionary[ 'IndependentData'][0] # now create data for the fitted equation plot xModel = numpy.linspace(min(self.parent.x_data), max(self.parent.x_data)) tempcache = equation.dataCache equation.dataCache = pyeq2.dataCache() equation.dataCache.allDataCacheDictionary[ 'IndependentData'] = numpy.array([xModel, xModel]) equation.dataCache.FindOrCreateAllDataCache(equation) yModel = equation.CalculateModelPredictions( equation.solvedCoefficients, equation.dataCache.allDataCacheDictionary) equation.dataCache = tempcache # first the raw data as a scatter plot self.axes.plot(self.parent.x_data, self.parent.y_data, 'D') # now the model as a line plot self.axes.plot(xModel, yModel) # now calculate confidence intervals # http://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_nlin_sect026.htm # http://www.staff.ncl.ac.uk/tom.holderness/software/pythonlinearfit mean_x = numpy.mean(self.parent.x_data) # mean of x n = equation.nobs # number of samples in the origional fit t_value = scipy.stats.t.ppf( 0.975, equation.df_e ) # (1.0 - (a/2)) is used for two-sided t-test critical value, here a = 0.05 confs = t_value * numpy.sqrt( (equation.sumOfSquaredErrors / equation.df_e) * (1.0 / n + (numpy.power((xModel - mean_x), 2.0) / ((numpy.sum(numpy.power(self.parent.x_data, 2))) - n * (numpy.power(mean_x, 2.0)))))) # get lower and upper confidence limits based on predicted y and confidence intervals upper = yModel + abs(confs) lower = yModel - abs(confs) # mask off any numbers outside the existing plot limits booleanMask = yModel > matplotlib.pyplot.ylim()[0] booleanMask &= (yModel < matplotlib.pyplot.ylim()[1]) # color scheme improves visibility on black background lines or points self.axes.plot(xModel[booleanMask], lower[booleanMask], linestyle='solid', color='white') self.axes.plot(xModel[booleanMask], upper[booleanMask], linestyle='solid', color='white') self.axes.plot(xModel[booleanMask], lower[booleanMask], linestyle='dashed', color='blue') self.axes.plot(xModel[booleanMask], upper[booleanMask], linestyle='dashed', color='blue') self.axes.set_title('Model With 95% Confidence Limits') # add a title self.axes.set_xlabel('X Data') # X axis data label self.axes.set_ylabel('Y Data') # Y axis data label
def SurfaceAndContourPlots(in_filePathSurface, in_filePathContour, in_equation, in_surfaceTitle, in_contourTitle, in_xAxisLabel, in_yAxisLabel, in_zAxisLabel): # raw data x_data = in_equation.dataCache.allDataCacheDictionary['IndependentData'][0] y_data = in_equation.dataCache.allDataCacheDictionary['IndependentData'][1] z_data = in_equation.dataCache.allDataCacheDictionary['DependentData'] from mpl_toolkits.mplot3d import Axes3D # 3D apecific from matplotlib import cm # to colormap from blue to red fig = plt.figure() ax = fig.gca(projection='3d') xModel = numpy.linspace(min(x_data), max(x_data), 20) yModel = numpy.linspace(min(y_data), max(y_data), 20) X, Y = numpy.meshgrid(xModel, yModel) tempcache = in_equation.dataCache in_equation.dataCache = pyeq2.dataCache() in_equation.dataCache.allDataCacheDictionary[ 'IndependentData'] = numpy.array([X, Y]) in_equation.dataCache.FindOrCreateAllDataCache(in_equation) Z = in_equation.CalculateModelPredictions( in_equation.solvedCoefficients, in_equation.dataCache.allDataCacheDictionary) in_equation.dataCache = tempcache ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=1, antialiased=True) ax.scatter(x_data, y_data, z_data) ax.set_title(in_surfaceTitle) # add a title for surface plot ax.set_xlabel(in_xAxisLabel) # X axis data label ax.set_ylabel(in_yAxisLabel) # Y axis data label ax.set_zlabel(in_zAxisLabel) # Y axis data label plt.tight_layout() # prevents cropping axis labels fig.savefig(in_filePathSurface) # create PNG file plt.close('all') # contour plot here fig = plt.figure(figsize=(5, 4)) ax = fig.add_subplot(1, 1, 1) ax.plot( x_data, y_data, 'o', color='0.8', markersize=4 ) # draw these first so contour lines overlay. Color=number is grayscale ax.set_title(in_contourTitle) # add a title for contour plot ax.set_xlabel(in_xAxisLabel) # X data label ax.set_ylabel(in_yAxisLabel) # Y data label numberOfContourLines = 16 CS = plt.contour(X, Y, Z, numberOfContourLines, colors='k') plt.clabel(CS, inline=1, fontsize=10) # labels for contours plt.tight_layout() # prevents cropping axis labels fig.savefig(in_filePathContour) # create PNG file plt.close('all')
def ContourPlot(in_DataObject, in_FileNameAndPath): gridResolution = (in_DataObject.graphWidth + in_DataObject.graphHeight) / 20 gxmin = in_DataObject.gxmin gxmax = in_DataObject.gxmax gymin = in_DataObject.gymin gymax = in_DataObject.gymax if in_DataObject.equation.independentData1CannotContainNegativeFlag and gxmin < 0.0: gxmin = 0.0 if in_DataObject.equation.independentData1CannotContainZeroFlag and gxmin == 0.0: gxmin = 1.0e-300 if in_DataObject.equation.independentData1CannotContainPositiveFlag and gxmax > 0.0: gxmax = 0.0 if in_DataObject.equation.independentData1CannotContainZeroFlag and gxmax == 0.0: gxmax = 1.0e-300 if in_DataObject.equation.independentData2CannotContainNegativeFlag and gymin < 0.0: gymin = 0.0 if in_DataObject.equation.independentData2CannotContainZeroFlag and gymin == 0.0: gymin = 1.0e-300 if in_DataObject.equation.independentData2CannotContainPositiveFlag and gymax > 0.0: gymax = 0.0 if in_DataObject.equation.independentData2CannotContainZeroFlag and gymax == 0.0: gymax = 1.0e-300 deltax = (gxmax - gxmin) / float(gridResolution) deltay = (gymax - gymin) / float(gridResolution) xRange = numpy.arange(gxmin, gxmax + deltax, deltax) yRange = numpy.arange(gymin, gymax + deltay / 2.0, deltay) minZ = min(in_DataObject.DependentDataArray) maxZ = max(in_DataObject.DependentDataArray) X, Y = numpy.meshgrid(xRange, yRange) boundingRectangle = matplotlib.patches.Rectangle( [gxmin, gymin], gxmax - gxmin, gymax - gymin, facecolor=(0.975, 0.975, 0.975), edgecolor=(0.9, 0.9, 0.9) ) Z = [] tempDataCache = in_DataObject.equation.dataCache for i in range(len(X)): in_DataObject.equation.dataCache = pyeq2.dataCache() in_DataObject.equation.dataCache.allDataCacheDictionary["IndependentData"] = numpy.array([X[i], Y[i]]) in_DataObject.equation.dataCache.FindOrCreateAllDataCache(in_DataObject.equation) Z.append( in_DataObject.equation.CalculateModelPredictions( in_DataObject.equation.solvedCoefficients, in_DataObject.equation.dataCache.allDataCacheDictionary ) ) in_DataObject.equation.dataCache = tempDataCache Z = numpy.array(Z) Z = numpy.clip(Z, minZ, maxZ) tempData = [ in_DataObject.IndependentDataArray[0], in_DataObject.IndependentDataArray[1], in_DataObject.DependentDataArray, ] ContourPlot_NoDataObject( X, Y, Z, tempData, in_FileNameAndPath, in_DataObject.IndependentDataName1, in_DataObject.IndependentDataName2, in_DataObject.graphWidth, in_DataObject.graphHeight, "UseOffset_ON", "ScientificNotation_X_AUTO", "ScientificNotation_Y_AUTO", in_DataObject.pngOnlyFlag, boundingRectangle, ) plt.close()
def ScatterPlotWithOptionalModel_NoDataObject( in_DataToPlot, in_FileNameAndPath, in_DataNameX, in_DataNameY, in_WidthInPixels, in_HeightInPixels, in_Equation, in_UseOffsetIfNeeded, in_ReverseXY, in_X_UseScientificNotationIfNeeded, in_Y_UseScientificNotationIfNeeded, in_GraphBounds, in_LogY, in_LogX, inPNGOnlyFlag, inConfidenceIntervalsFlag, ): # decode ends of strings ('XYZ_ON', 'XYZ_OFF', 'XYZ_AUTO', etc.) to boolean values scientificNotationX = DetermineScientificNotationFromString(in_DataToPlot[0], in_X_UseScientificNotationIfNeeded) scientificNotationY = DetermineScientificNotationFromString(in_DataToPlot[1], in_Y_UseScientificNotationIfNeeded) useOffsetIfNeeded = DetermineOnOrOffFromString(in_UseOffsetIfNeeded) reverseXY = DetermineOnOrOffFromString(in_ReverseXY) if in_Equation: # make model data for plotting, clipping at boundaries lowerXbound = in_GraphBounds[0] upperXbound = in_GraphBounds[1] if in_Equation.independentData1CannotContainNegativeFlag and lowerXbound < 0.0: lowerXbound = 0.0 if in_Equation.independentData1CannotContainZeroFlag and lowerXbound == 0.0: lowerXbound = 1.0e-300 if in_Equation.independentData1CannotContainPositiveFlag and upperXbound > 0.0: upperXbound = 0.0 if in_Equation.independentData1CannotContainZeroFlag and upperXbound == 0.0: upperXbound = 1.0e-300 xRange = numpy.arange( lowerXbound, upperXbound, (upperXbound - lowerXbound) / (20.0 * float(in_WidthInPixels + in_HeightInPixels)) ) # make this 'reverse-xy-independent' tempDataCache = in_Equation.dataCache in_Equation.dataCache = pyeq2.dataCache() in_Equation.dataCache.allDataCacheDictionary["IndependentData"] = numpy.array([xRange, xRange]) in_Equation.dataCache.FindOrCreateAllDataCache(in_Equation) yRange = in_Equation.CalculateModelPredictions( in_Equation.solvedCoefficients, in_Equation.dataCache.allDataCacheDictionary ) in_Equation.dataCache = tempDataCache if reverseXY: fig, ax = CommonPlottingCode( in_WidthInPixels, in_HeightInPixels, in_DataNameX, in_DataNameY, useOffsetIfNeeded, scientificNotationY, scientificNotationX, 0.0, 0.0, 1.0, 1.0, ) ax.plot( numpy.array([in_GraphBounds[2], in_GraphBounds[3]]), numpy.array([in_GraphBounds[0], in_GraphBounds[1]]) ) # first ax.plot() is only with extents newLeft, newBottom, newRight, newTop, numberOfMajor_X_TickMarks = YieldNewExtentsAndNumberOfMajor_X_TickMarks( fig, ax, in_WidthInPixels, in_HeightInPixels, scientificNotationY or useOffsetIfNeeded ) fig, ax = CommonPlottingCode( in_WidthInPixels, in_HeightInPixels, in_DataNameX, in_DataNameY, useOffsetIfNeeded, scientificNotationY, scientificNotationX, newLeft, newBottom, newRight, newTop, ) if in_LogY == "LOG" and in_LogX == "LOG": loglinplot = ax.loglog elif in_LogY == "LIN" and in_LogX == "LOG": loglinplot = ax.semilogx elif in_LogY == "LOG" and in_LogX == "LIN": loglinplot = ax.semilogy else: loglinplot = ax.plot if len(ax.get_xticklabels()) > numberOfMajor_X_TickMarks: ax.xaxis.set_major_locator(matplotlib.ticker.MaxNLocator(numberOfMajor_X_TickMarks)) loglinplot( numpy.array([in_GraphBounds[2], in_GraphBounds[3]]), numpy.array([in_GraphBounds[0], in_GraphBounds[1]]), visible=False, ) loglinplot(in_DataToPlot[1], in_DataToPlot[0], "o", markersize=3) if (min(in_DataToPlot[0]) < in_GraphBounds[0]) or (max(in_DataToPlot[0]) > in_GraphBounds[1]): matplotlib.pyplot.ylim(in_GraphBounds[0], in_GraphBounds[1]) if (min(in_DataToPlot[1]) < in_GraphBounds[2]) or (max(in_DataToPlot[1]) > in_GraphBounds[3]): matplotlib.pyplot.xlim(in_GraphBounds[2], in_GraphBounds[3]) else: fig, ax = CommonPlottingCode( in_WidthInPixels, in_HeightInPixels, in_DataNameX, in_DataNameY, useOffsetIfNeeded, scientificNotationX, scientificNotationY, 0.0, 0.0, 1.0, 1.0, ) ax.plot( numpy.array([in_GraphBounds[0], in_GraphBounds[1]]), numpy.array([in_GraphBounds[2], in_GraphBounds[3]]) ) # first ax.plot() is only with extents newLeft, newBottom, newRight, newTop, numberOfMajor_X_TickMarks = YieldNewExtentsAndNumberOfMajor_X_TickMarks( fig, ax, in_WidthInPixels, in_HeightInPixels, scientificNotationY or useOffsetIfNeeded ) fig, ax = CommonPlottingCode( in_WidthInPixels, in_HeightInPixels, in_DataNameX, in_DataNameY, useOffsetIfNeeded, scientificNotationX, scientificNotationY, newLeft, newBottom, newRight, newTop, ) if in_LogY == "LOG" and in_LogX == "LOG": loglinplot = ax.loglog elif in_LogY == "LIN" and in_LogX == "LOG": loglinplot = ax.semilogx elif in_LogY == "LOG" and in_LogX == "LIN": loglinplot = ax.semilogy else: loglinplot = ax.plot if len(ax.get_xticklabels()) > numberOfMajor_X_TickMarks: ax.xaxis.set_major_locator(matplotlib.ticker.MaxNLocator(numberOfMajor_X_TickMarks)) loglinplot( numpy.array([in_GraphBounds[0], in_GraphBounds[1]]), numpy.array([in_GraphBounds[2], in_GraphBounds[3]]), visible=False, ) loglinplot(in_DataToPlot[0], in_DataToPlot[1], "o", markersize=3) if (min(in_DataToPlot[0]) <= in_GraphBounds[0]) or (max(in_DataToPlot[0]) >= in_GraphBounds[1]): matplotlib.pyplot.xlim(in_GraphBounds[0], in_GraphBounds[1]) if (min(in_DataToPlot[1]) <= in_GraphBounds[2]) or (max(in_DataToPlot[1]) >= in_GraphBounds[3]): matplotlib.pyplot.ylim(in_GraphBounds[2], in_GraphBounds[3]) if in_Equation: booleanMask = yRange > matplotlib.pyplot.ylim()[0] booleanMask &= yRange < matplotlib.pyplot.ylim()[1] booleanMask &= xRange > matplotlib.pyplot.xlim()[0] booleanMask &= xRange < matplotlib.pyplot.xlim()[1] loglinplot(xRange[booleanMask], yRange[booleanMask], "k") # model on top of data points if inConfidenceIntervalsFlag: # now calculate confidence intervals for new test x-series # http://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_nlin_sect026.htm # http://www.staff.ncl.ac.uk/tom.holderness/software/pythonlinearfit mean_x = numpy.mean(in_DataToPlot[0]) # mean of x n = in_Equation.nobs # number of samples in origional fit if len(in_Equation.dataCache.allDataCacheDictionary["Weights"]): t_value = scipy.stats.t.ppf( 0.975, in_Equation.df_e_weighted ) # (1.0 - (a/2)) is used for two-sided t-test critical value, here a = 0.05 confs = t_value * numpy.sqrt( (in_Equation.sumOfSquaredErrors_weighted / in_Equation.df_e_weighted) * ( 1.0 / n + ( numpy.power((xRange - mean_x), 2) / ((numpy.sum(numpy.power(in_DataToPlot[0], 2))) - n * (numpy.power(mean_x, 2))) ) ) ) else: t_value = scipy.stats.t.ppf( 0.975, in_Equation.df_e ) # (1.0 - (a/2)) is used for two-sided t-test critical value, here a = 0.05 confs = t_value * numpy.sqrt( (in_Equation.sumOfSquaredErrors / in_Equation.df_e) * ( 1.0 / n + ( numpy.power((xRange - mean_x), 2) / ((numpy.sum(numpy.power(in_DataToPlot[0], 2))) - n * (numpy.power(mean_x, 2))) ) ) ) # get lower and upper confidence limits based on predicted y and confidence intervals upper = yRange + abs(confs) lower = yRange - abs(confs) booleanMask &= numpy.array(yRange) < 1.0e290 booleanMask &= upper < 1.0e290 booleanMask &= lower < 1.0e290 # color scheme improves visibility on black background lines or points loglinplot(xRange[booleanMask], lower[booleanMask], linestyle="solid", color="white") loglinplot(xRange[booleanMask], upper[booleanMask], linestyle="solid", color="white") loglinplot(xRange[booleanMask], lower[booleanMask], linestyle="dashed", color="blue") loglinplot(xRange[booleanMask], upper[booleanMask], linestyle="dashed", color="blue") fig.savefig(in_FileNameAndPath[:-3] + "png", format="png") if not inPNGOnlyFlag: fig.savefig(in_FileNameAndPath[:-3] + "svg", format="svg") plt.close()
def ParallelFittingFunction(rawData, fittingTargetText, smoothnessControl, modulus, modulusRemainder): processID = str(os.getpid()) # this function yields a single item to inspect after completion bestResult = [] # we are using the same data set repeatedly, so create a cache external to the equations externalCache = pyeq2.dataCache() reducedDataCache = {} equationCountForModulus = 0 ########################## # add named equations here print() print('Process ID', processID, 'fitting named equations:') for submodule in inspect.getmembers(pyeq2.Models_2D): if inspect.ismodule(submodule[1]): for equationClass in inspect.getmembers(submodule[1]): if inspect.isclass(equationClass[1]): # special classes if equationClass[1].splineFlag or \ equationClass[1].userSelectablePolynomialFlag or \ equationClass[1].userCustomizablePolynomialFlag or \ equationClass[1].userSelectablePolyfunctionalFlag or \ equationClass[1].userSelectableRationalFlag or \ equationClass[1].userDefinedFunctionFlag: continue for extendedVersion in ['Default', 'Offset']: if (extendedVersion == 'Offset') and (equationClass[1].autoGenerateOffsetForm == False): continue if equationCountForModulus % modulus != modulusRemainder: equationCountForModulus += 1 continue equationCountForModulus += 1 equationInstance = equationClass[1](fittingTargetText, extendedVersion) if len(equationInstance.GetCoefficientDesignators()) > smoothnessControl: continue equationInstance.dataCache = externalCache # re-use the external cache if equationInstance.dataCache.allDataCacheDictionary == {}: pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(rawData, equationInstance, False) equationInstance.dataCache.CalculateNumberOfReducedDataPoints(equationInstance) if reducedDataCache.has_key(equationInstance.numberOfReducedDataPoints): equationInstance.dataCache.reducedDataCacheDictionary = reducedDataCache[equationInstance.numberOfReducedDataPoints] else: equationInstance.dataCache.reducedDataCacheDictionary = {} result = SetParametersAndFit(equationInstance, bestResult, True, processID) if result: bestResult = result if not reducedDataCache.has_key(equationInstance.numberOfReducedDataPoints): reducedDataCache[equationInstance.numberOfReducedDataPoints] = equationInstance.dataCache.reducedDataCacheDictionary ########################## # fit polyfunctionals here () print('Process ID', processID, 'fitting polyfunctionals:') equationCount = 0 maxPolyfunctionalCoefficients = 4 # this value was chosen to make this example more convenient polyfunctionalEquationList = pyeq2.PolyFunctions.GenerateListForPolyfunctionals_2D() functionIndexList = range(len(polyfunctionalEquationList)) # make a list of function indices to permute for coeffCount in range(1, maxPolyfunctionalCoefficients+1): functionCombinations = UniqueCombinations(functionIndexList, coeffCount) for functionCombination in functionCombinations: if len(functionCombination) > smoothnessControl: continue if equationCountForModulus % modulus != modulusRemainder: equationCountForModulus += 1 continue equationCountForModulus += 1 equationInstance = pyeq2.Models_2D.Polyfunctional.UserSelectablePolyfunctional(fittingTargetText, 'Default', functionCombination, polyfunctionalEquationList) equationInstance.dataCache = externalCache # re-use the external cache if equationInstance.dataCache.allDataCacheDictionary == {}: pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(rawData, equationInstance, False) equationInstance.dataCache.CalculateNumberOfReducedDataPoints(equationInstance) if reducedDataCache.has_key(equationInstance.numberOfReducedDataPoints): equationInstance.dataCache.reducedDataCacheDictionary = reducedDataCache[equationInstance.numberOfReducedDataPoints] else: equationInstance.dataCache.reducedDataCacheDictionary = {} result = SetParametersAndFit(equationInstance, bestResult, False) if result: bestResult = result if not reducedDataCache.has_key(equationInstance.numberOfReducedDataPoints): reducedDataCache[equationInstance.numberOfReducedDataPoints] = equationInstance.dataCache.reducedDataCacheDictionary equationCount += 1 if (equationCount % 50) == 0: print(' Process ID', processID, 'fitted', equationCount, 'equations...') ###################### # fit user-selectable polynomials here print() print('Process ID', processID, 'fitting user-selectable polynomials:') maxPolynomialOrderX = 5 # this value was chosen to make this example more convenient for polynomialOrderX in range(maxPolynomialOrderX+1): if (polynomialOrderX + 1) > smoothnessControl: continue if equationCountForModulus % modulus != modulusRemainder: equationCountForModulus += 1 continue equationCountForModulus += 1 equationInstance = pyeq2.Models_2D.Polynomial.UserSelectablePolynomial(fittingTargetText, 'Default', polynomialOrderX) equationInstance.dataCache = externalCache # re-use the external cache if equationInstance.dataCache.allDataCacheDictionary == {}: pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(rawData, equationInstance, False) equationInstance.dataCache.CalculateNumberOfReducedDataPoints(equationInstance) if reducedDataCache.has_key(equationInstance.numberOfReducedDataPoints): equationInstance.dataCache.reducedDataCacheDictionary = reducedDataCache[equationInstance.numberOfReducedDataPoints] else: equationInstance.dataCache.reducedDataCacheDictionary = {} result = SetParametersAndFit(equationInstance, bestResult, False) if result: bestResult = result if not reducedDataCache.has_key(equationInstance.numberOfReducedDataPoints): reducedDataCache[equationInstance.numberOfReducedDataPoints] = equationInstance.dataCache.reducedDataCacheDictionary ###################### # fit user-selectable rationals here print print('Process ID', processID, 'fitting user-selectable rationals:') equationCount = 0 maxCoeffs = smoothnessControl # arbitrary choice of maximum total coefficients for this example functionList = pyeq2.PolyFunctions.GenerateListForRationals_2D() functionIndexList = range(len(functionList)) # make a list of function indices for numeratorCoeffCount in range(1, maxCoeffs): numeratorComboList = UniqueCombinations(functionIndexList, numeratorCoeffCount) for numeratorCombo in numeratorComboList: for denominatorCoeffCount in range(1, maxCoeffs): denominatorComboList = UniqueCombinations2(functionIndexList, denominatorCoeffCount) for denominatorCombo in denominatorComboList: for extendedVersion in ['Default', 'Offset']: extraCoeffs = 0 if extendedVersion == 'Offset': extraCoeffs = 1 if (len(numeratorCombo) + len(denominatorCombo) + extraCoeffs) > smoothnessControl: continue if equationCountForModulus % modulus != modulusRemainder: equationCountForModulus += 1 continue equationCountForModulus += 1 equationInstance = pyeq2.Models_2D.Rational.UserSelectableRational(fittingTargetText, extendedVersion, numeratorCombo, denominatorCombo, functionList) equationInstance.dataCache = externalCache # re-use the external cache if equationInstance.dataCache.allDataCacheDictionary == {}: pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(rawData, equationInstance, False) equationInstance.dataCache.CalculateNumberOfReducedDataPoints(equationInstance) if reducedDataCache.has_key(equationInstance.numberOfReducedDataPoints): equationInstance.dataCache.reducedDataCacheDictionary = reducedDataCache[equationInstance.numberOfReducedDataPoints] else: equationInstance.dataCache.reducedDataCacheDictionary = {} result = SetParametersAndFit(equationInstance, bestResult, False) if result: bestResult = result if not reducedDataCache.has_key(equationInstance.numberOfReducedDataPoints): reducedDataCache[equationInstance.numberOfReducedDataPoints] = equationInstance.dataCache.reducedDataCacheDictionary equationCount += 1 if (equationCount % 5) == 0: print(' ', 'Process ID', processID + ',', equationCount, 'rationals, current flags:', equationInstance.rationalNumeratorFlags, equationInstance.rationalDenominatorFlags,) if extendedVersion == 'Offset': print('with offset') else: print() print('Process ID', processID, 'has completed') return bestResult
def SaveModelScatterConfidence(in_fileName, in_equation, in_Ymax, in_Ymin): # raw data x_data = in_equation.dataCache.allDataCacheDictionary['IndependentData'][0] y_data = in_equation.dataCache.allDataCacheDictionary['DependentData'] # now create data for the fitted in_equation plot xModel = numpy.linspace(min(x_data), max(x_data)) tempcache = in_equation.dataCache in_equation.dataCache = pyeq2.dataCache() in_equation.dataCache.allDataCacheDictionary['IndependentData'] = numpy.array([xModel, xModel]) in_equation.dataCache.FindOrCreateAllDataCache(in_equation) yModel = in_equation.CalculateModelPredictions(in_equation.solvedCoefficients, in_equation.dataCache.allDataCacheDictionary) in_equation.dataCache = tempcache # now use matplotlib to create the PNG file if -1 != in_fileName.find('_large'): # large animation frame fig = plt.figure(figsize=(float(largeAnimationGraphWidth ) / 100.0, float(largeAnimationGraphHeight ) / 100.0), dpi=100) else: # small animation frame fig = plt.figure(figsize=(float(smallAnimationGraphWidth ) / 100.0, float(smallAnimationGraphHeight ) / 100.0), dpi=100) ax = fig.add_subplot(1,1,1) # first the raw data as a scatter plot if -1 != in_fileName.find('_small'): # small animation frame ax.plot(x_data, y_data, 'D', markersize = 2) else: ax.plot(x_data, y_data, 'D') # now the model as a line plot ax.plot(xModel, yModel, label = 'Fitted Equation') # now calculate confidence intervals # http://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_nlin_sect026.htm # http://www.staff.ncl.ac.uk/tom.holderness/software/pythonlinearfit mean_x = numpy.mean(x_data) # mean value of x n = len(x_data) # number of samples t_value = scipy.stats.t.ppf(0.975, in_equation.df_e) # (1.0 - (a/2)) is used for two-sided t-test critical value, here a = 0.05 confs = t_value * numpy.sqrt((in_equation.sumOfSquaredErrors/in_equation.df_e)*(1.0/n + (numpy.power((xModel-mean_x),2.0)/ ((numpy.sum(numpy.power(x_data,2)))-n*(numpy.power(mean_x,2.0)))))) # get lower and upper confidence limits based on predicted y and confidence intervals upper = yModel + abs(confs) lower = yModel - abs(confs) # mask off any numbers outside the existing plot limits booleanMask = yModel > matplotlib.pyplot.ylim()[0] booleanMask &= (yModel < matplotlib.pyplot.ylim()[1]) # color scheme improves visibility on black background lines or points ax.plot(xModel[booleanMask], lower[booleanMask], linestyle='solid', color='white') ax.plot(xModel[booleanMask], upper[booleanMask], linestyle='solid', color='white') ax.plot(xModel[booleanMask], lower[booleanMask], linestyle='dashed', color='blue') ax.plot(xModel[booleanMask], upper[booleanMask], linestyle='dashed', color='blue', label = '95% Confidence Intervals') if -1 != in_fileName.find('_small'): # small animation frame ax.set_ylabel("Y Data", size='small') # Y axis data label ax.set_xlabel("X Data", size='small') # X axis data label else: ax.set_ylabel("Y Data") # Y axis data label ax.set_xlabel("X Data") # X axis data label if -1 != in_fileName.find('_small'): # small animation frame for xlabel_i in ax.get_xticklabels(): xlabel_i.set_fontsize(xlabel_i.get_fontsize() * 0.5) for ylabel_i in ax.get_yticklabels(): ylabel_i.set_fontsize(ylabel_i.get_fontsize() * 0.5) plt.ylim(in_Ymin, in_Ymax) # legends on large images # http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.legend if -1 != in_fileName.find('large'): # large animation frame ax.legend(loc=2, fontsize='small') fig.tight_layout() fig.savefig(in_fileName) # create PNG file plt.close('all') # clear pyplot else memory use becomes large
def GenerateListOfOutputReports(self): if self.debug: print "**** FF Results GenerateListOfOutputReports 1" self.textReports = [] self.graphReports = [] externalDataCache = pyeq2.dataCache( ) # reuse this to speed up some caching for i in range(self.numberOfEquationsToDisplay): if self.debug: print "**** FF Results GenerateListOfOutputReports 2.1: i=", str( i) listItem = self.functionFinderResultsList[i + self.rank - 1] if self.debug: print "**** FF Results GenerateListOfOutputReports 2.2: i=", str( i) reportDataObject = copy.deepcopy(self.dataObject) if self.debug: print "**** FF Results GenerateListOfOutputReports 2.3: i=", str( i) # find the equation instance for the incoming dimensionality, equation family name and equation name - 404 if not found reportDataObject.equation = eval(listItem[1] + "." + listItem[2] + "('SSQABS', '" + listItem[3] + "')") if self.debug: print "**** FF Results GenerateListOfOutputReports 2.4: i=", str( i ), 'equation name =', reportDataObject.equation.GetDisplayName( ) if externalDataCache.allDataCacheDictionary == {}: # This should only run for the first equation temp = reportDataObject.textDataEditor # comma conversions if reportDataObject.commaConversion == "D": # decimal separator temp = temp.replace(",", ".") elif reportDataObject.commaConversion == "I": # as if they don't exist temp = temp.replace(",", "") else: temp = temp.replace( ",", " ") # default to the original default conversion # replace these characters with spaces for use by float() temp = temp.replace("$", " ") temp = temp.replace("%", " ") temp = temp.replace("(", " ") temp = temp.replace(")", " ") temp = temp.replace("{", " ") temp = temp.replace("}", " ") temp = temp.replace('\r\n', '\n') temp = temp.replace('\r', '\n') # replace HTML spaces and tabs with spaces temp = temp.replace(" ", " ") temp = temp.replace("	", " ") temp = temp.replace("	", " ") temp = temp.replace(" ", " ") pyeq2.dataConvertorService().ConvertAndSortColumnarASCII( temp, reportDataObject.equation, False) externalDataCache = reportDataObject.equation.dataCache reportDataObject.equation.polyfunctional2DFlags = listItem[4] reportDataObject.equation.polyfunctional3DFlags = listItem[5] reportDataObject.equation.xPolynomialOrder = listItem[6] reportDataObject.equation.yPolynomialOrder = listItem[7] reportDataObject.equation.rationalNumeratorFlags = listItem[8] reportDataObject.equation.rationalDenominatorFlags = listItem[9] reportDataObject.equation.fittingTarget = listItem[10] reportDataObject.equation.solvedCoefficients = listItem[11] targetValue = listItem[0] reportDataObject.equation.dataCache = externalDataCache reportDataObject.equation.dataCache.FindOrCreateAllDataCache( reportDataObject.equation) externalDataCache = reportDataObject.equation.dataCache # add a bit more extrapolation for the function finder result displays reportDataObject.Extrapolation_x = 0.05 reportDataObject.Extrapolation_y = 0.05 reportDataObject.Extrapolation_z = 0.05 # needed here for graph boundary calculation reportDataObject.graphWidth = 280 reportDataObject.graphHeight = 240 # 3D rotation angles reportDataObject.altimuth3D = 45.0 reportDataObject.azimuth3D = 45.0 reportDataObject.CalculateDataStatistics() reportDataObject.CalculateErrorStatistics() reportDataObject.CalculateGraphBoundaries() reportDataObject.equation.CalculateCoefficientAndFitStatistics() if self.debug: print "**** FF Results GenerateListOfOutputReports 2.5: i=", str( i ), 'equation name =', reportDataObject.equation.GetDisplayName( ) graphs = [] # Different graphs for 2D and 3D reportDataObject.pngOnlyFlag = True if reportDataObject.equation.GetDimensionality() == 2: graph = ReportsAndGraphs.DependentDataVsIndependentData1_ModelPlot( reportDataObject) graph.rank = i + self.rank graph.PrepareForReportOutput() self.graphReports.append(graph) graphs.append(graph.websiteFileLocation) else: graph = ReportsAndGraphs.SurfacePlot(reportDataObject) graph.rank = i + self.rank graph.PrepareForReportOutput() self.graphReports.append(graph) graphs.append(graph.websiteFileLocation) graph = ReportsAndGraphs.ContourPlot(reportDataObject) graph.rank = i + self.rank graph.PrepareForReportOutput() graphs.append(graph.websiteFileLocation) self.graphReports.append(graph) if reportDataObject.equation.fittingTarget[-3:] != "REL": graph = ReportsAndGraphs.AbsoluteErrorVsDependentData_ScatterPlot( reportDataObject) graph.rank = i + self.rank graph.PrepareForReportOutput() self.graphReports.append(graph) graphs.append(graph.websiteFileLocation) else: graph = ReportsAndGraphs.RelativeErrorVsDependentData_ScatterPlot( reportDataObject) graph.rank = i + self.rank graph.PrepareForReportOutput() graphs.append(graph.websiteFileLocation) self.graphReports.append(graph) if self.debug: print "**** FF Results GenerateListOfOutputReports 2.6: i=", str( i ), 'equation name =', reportDataObject.equation.GetDisplayName( ) dataForOneEquation = {} splitted = listItem[1].split('.') dataForOneEquation['moduleName'] = splitted[-1] dataForOneEquation[ 'displayName'] = reportDataObject.equation.GetDisplayName() dataForOneEquation['URLQuotedModuleName'] = urllib.quote( splitted[-1]) dataForOneEquation['URLQuotedDisplayName'] = urllib.quote( reportDataObject.equation.GetDisplayName()) dataForOneEquation[ 'displayHTML'] = reportDataObject.equation.GetDisplayHTML() dataForOneEquation['graphWebSiteLocations'] = graphs dataForOneEquation['rank'] = i + self.rank dataForOneEquation['dimensionality'] = self.dimensionality dataForOneEquation[ 'fittingTarget'] = reportDataObject.equation.fittingTarget dataForOneEquation['fittingTargetValue'] = targetValue if reportDataObject.fittingTarget[ -3:] != "REL": # only non-relative error fits get RMSE displayed dataForOneEquation['rmseString'] = '<br>RMSE: ' + str( reportDataObject.equation.rmse) + '<br>' else: dataForOneEquation['rmseString'] = '<br>' self.equationDataForDjangoTemplate.append(dataForOneEquation) if self.debug: print "**** FF Results GenerateListOfOutputReports 2.7: i=", str( i ), 'equation name =', reportDataObject.equation.GetDisplayName( )
def GenerateListOfOutputReports(self): if self.debug: print "**** FF Results GenerateListOfOutputReports 1" self.textReports = [] self.graphReports = [] externalDataCache = pyeq2.dataCache() # reuse this to speed up some caching for i in range(self.numberOfEquationsToDisplay): if self.debug: print "**** FF Results GenerateListOfOutputReports 2.1: i=", str(i) listItem = self.functionFinderResultsList[i + self.rank-1] if self.debug: print "**** FF Results GenerateListOfOutputReports 2.2: i=", str(i) reportDataObject = copy.deepcopy(self.dataObject) if self.debug: print "**** FF Results GenerateListOfOutputReports 2.3: i=", str(i) # find the equation instance for the incoming dimensionality, equation family name and equation name - 404 if not found reportDataObject.equation = eval(listItem[1] + "." + listItem[2] + "('SSQABS', '" + listItem[3] + "')") if self.debug: print "**** FF Results GenerateListOfOutputReports 2.4: i=", str(i), 'equation name =', reportDataObject.equation.GetDisplayName() if externalDataCache.allDataCacheDictionary == {}: # This should only run for the first equation temp = reportDataObject.textDataEditor # comma conversions if reportDataObject.commaConversion == "D": # decimal separator temp = temp.replace(",",".") elif reportDataObject.commaConversion == "I": # as if they don't exist temp = temp.replace(",","") else: temp = temp.replace(","," ") # default to the original default conversion # replace these characters with spaces for use by float() temp = temp.replace("$"," ") temp = temp.replace("%"," ") temp = temp.replace("("," ") temp = temp.replace(")"," ") temp = temp.replace("{"," ") temp = temp.replace("}"," ") temp = temp.replace('\r\n','\n') temp = temp.replace('\r','\n') # replace HTML spaces and tabs with spaces temp = temp.replace(" "," ") temp = temp.replace("	"," ") temp = temp.replace("	"," ") temp = temp.replace(" "," ") pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(temp, reportDataObject.equation, False) externalDataCache = reportDataObject.equation.dataCache reportDataObject.equation.polyfunctional2DFlags = listItem[4] reportDataObject.equation.polyfunctional3DFlags = listItem[5] reportDataObject.equation.xPolynomialOrder = listItem[6] reportDataObject.equation.yPolynomialOrder = listItem[7] reportDataObject.equation.rationalNumeratorFlags = listItem[8] reportDataObject.equation.rationalDenominatorFlags = listItem[9] reportDataObject.equation.fittingTarget = listItem[10] reportDataObject.equation.solvedCoefficients = listItem[11] targetValue = listItem[0] reportDataObject.equation.dataCache = externalDataCache reportDataObject.equation.dataCache.FindOrCreateAllDataCache(reportDataObject.equation) externalDataCache = reportDataObject.equation.dataCache # add a bit more extrapolation for the function finder result displays reportDataObject.Extrapolation_x = 0.05 reportDataObject.Extrapolation_y = 0.05 reportDataObject.Extrapolation_z = 0.05 # needed here for graph boundary calculation reportDataObject.graphWidth = 280 reportDataObject.graphHeight = 240 # 3D rotation angles reportDataObject.altimuth3D = 45.0 reportDataObject.azimuth3D = 45.0 reportDataObject.CalculateDataStatistics() reportDataObject.CalculateErrorStatistics() reportDataObject.CalculateGraphBoundaries() reportDataObject.equation.CalculateCoefficientAndFitStatistics() if self.debug: print "**** FF Results GenerateListOfOutputReports 2.5: i=", str(i), 'equation name =', reportDataObject.equation.GetDisplayName() graphs = [] # Different graphs for 2D and 3D reportDataObject.pngOnlyFlag = True if reportDataObject.equation.GetDimensionality() == 2: graph = ReportsAndGraphs.DependentDataVsIndependentData1_ModelPlot(reportDataObject) graph.rank = i + self.rank graph.PrepareForReportOutput() self.graphReports.append(graph) graphs.append(graph.websiteFileLocation) else: graph = ReportsAndGraphs.SurfacePlot(reportDataObject) graph.rank = i + self.rank graph.PrepareForReportOutput() self.graphReports.append(graph) graphs.append(graph.websiteFileLocation) graph = ReportsAndGraphs.ContourPlot(reportDataObject) graph.rank = i + self.rank graph.PrepareForReportOutput() graphs.append(graph.websiteFileLocation) self.graphReports.append(graph) if reportDataObject.equation.fittingTarget[-3:] != "REL": graph = ReportsAndGraphs.AbsoluteErrorVsDependentData_ScatterPlot(reportDataObject) graph.rank = i + self.rank graph.PrepareForReportOutput() self.graphReports.append(graph) graphs.append(graph.websiteFileLocation) else: graph = ReportsAndGraphs.RelativeErrorVsDependentData_ScatterPlot(reportDataObject) graph.rank = i + self.rank graph.PrepareForReportOutput() graphs.append(graph.websiteFileLocation) self.graphReports.append(graph) if self.debug: print "**** FF Results GenerateListOfOutputReports 2.6: i=", str(i), 'equation name =', reportDataObject.equation.GetDisplayName() dataForOneEquation = {} splitted = listItem[1].split('.') dataForOneEquation['moduleName'] = splitted[-1] dataForOneEquation['displayName'] = reportDataObject.equation.GetDisplayName() dataForOneEquation['URLQuotedModuleName'] = urllib.quote(splitted[-1]) dataForOneEquation['URLQuotedDisplayName'] = urllib.quote(reportDataObject.equation.GetDisplayName()) dataForOneEquation['displayHTML'] = reportDataObject.equation.GetDisplayHTML() dataForOneEquation['graphWebSiteLocations'] = graphs dataForOneEquation['rank'] = i + self.rank dataForOneEquation['dimensionality'] = self.dimensionality dataForOneEquation['fittingTarget'] = reportDataObject.equation.fittingTarget dataForOneEquation['fittingTargetValue'] = targetValue if reportDataObject.fittingTarget[-3:] != "REL": # only non-relative error fits get RMSE displayed dataForOneEquation['rmseString'] = '<br>RMSE: ' + str(reportDataObject.equation.rmse) + '<br>' else: dataForOneEquation['rmseString'] = '<br>' self.equationDataForDjangoTemplate.append(dataForOneEquation) if self.debug: print "**** FF Results GenerateListOfOutputReports 2.7: i=", str(i), 'equation name =', reportDataObject.equation.GetDisplayName()
def __init__(self, inFittingTarget = 'SSQABS', inExtendedVersionName = 'Default'): self.dataCache = pyeq2.dataCache() self._dimensionality = 3
equation.Solve() # raw data for scatterplot x_data = equation.dataCache.allDataCacheDictionary['IndependentData'][0] y_data = equation.dataCache.allDataCacheDictionary['IndependentData'][1] z_data = equation.dataCache.allDataCacheDictionary['DependentData'] # create X, Y, Z mesh grid for surface plot print "Creating mesh grid data" xModel = numpy.linspace(min(x_data), max(x_data), 20) yModel = numpy.linspace(min(y_data), max(y_data), 20) X, Y = numpy.meshgrid(xModel, yModel) tempcache = equation.dataCache equation.dataCache = pyeq2.dataCache() equation.dataCache.allDataCacheDictionary['IndependentData'] = numpy.array([X, Y]) equation.dataCache.FindOrCreateAllDataCache(equation) Z = equation.CalculateModelPredictions(equation.solvedCoefficients, equation.dataCache.allDataCacheDictionary) equation.dataCache = tempcache # matplotlib specific code for the plots fig = plt.figure(figsize=(float(graphWidth ) / 100.0, float(graphHeight ) / 100.0), dpi=100) ax = fig.gca(projection='3d') print "Creating matplotlib graph objects" # create a surface plot using the X, Y, Z mesh data created above ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=1, antialiased=True)
def serialWorker(inputQueue, outputQueue): for func, args in iter(inputQueue.get, 'STOP'): # iter() has different behaviors depending on number of parameters outputQueue.put(func(*args)) inputQueue.task_done() if inputQueue.unfinished_tasks == 0: break os.nice(10) ####################### I use this during development global globalDataCache globalDataCache = pyeq2.dataCache() global globalReducedDataCache globalReducedDataCache = {} global globalRawData globalRawData = ''' 5.357 0.376 5.457 0.489 5.797 0.874 5.936 1.049 6.161 1.327 6.697 2.054 6.731 2.077 6.775 2.138 8.442 4.744
def __init__(self, inFittingTarget='SSQABS', inExtendedVersionName='Default'): if inExtendedVersionName == '': inExtendedVersionName = 'Default' if inFittingTarget not in self.fittingTargetDictionary.keys(): raise Exception, str( inFittingTarget ) + ' is not in the IModel class fitting target dictionary.' self.extendedVersionHandler = eval( 'pyeq2.ExtendedVersionHandlers.ExtendedVersionHandler_' + inExtendedVersionName.replace(' ', '') + '.ExtendedVersionHandler_' + inExtendedVersionName.replace(' ', '') + '()') self.dataCache = pyeq2.dataCache() self.upperCoefficientBounds = [] self.lowerCoefficientBounds = [] self.estimatedCoefficients = [] self.fixedCoefficients = [] self.solvedCoefficients = [] self.polyfunctional2DFlags = [] self.polyfunctional3DFlags = [] self.xPolynomialOrder = None self.yPolynomialOrder = None self.rationalNumeratorFlags = [] self.rationalDenominatorFlags = [] self.fittingTarget = inFittingTarget self.independentData1CannotContainZeroFlag = False self.independentData1CannotContainPositiveFlag = False self.independentData1CannotContainNegativeFlag = False self.independentData2CannotContainZeroFlag = False self.independentData2CannotContainPositiveFlag = False self.independentData2CannotContainNegativeFlag = False try: if self._dimensionality == 2: self.exampleData = ''' X Y 5.357 0.376 5.457 0.489 5.797 0.874 5.936 1.049 6.161 1.327 6.697 2.054 6.731 2.077 6.775 2.138 8.442 4.744 9.769 7.068 9.861 7.104 ''' else: self.exampleData = ''' X Y Z 3.017 2.175 0.320 2.822 2.624 0.629 2.632 2.839 0.950 2.287 3.030 1.574 2.207 3.057 1.725 2.048 3.098 2.035 1.963 3.115 2.204 1.784 3.144 2.570 1.712 3.153 2.721 2.972 2.106 0.313 2.719 2.542 0.643 2.495 2.721 0.956 2.070 2.878 1.597 1.969 2.899 1.758 1.768 2.929 2.088 1.677 2.939 2.240 1.479 2.957 2.583 1.387 2.963 2.744 2.843 1.984 0.315 2.485 2.320 0.639 2.163 2.444 0.954 1.687 2.525 1.459 1.408 2.547 1.775 1.279 2.554 1.927 1.016 2.564 2.243 0.742 2.568 2.581 0.607 2.571 2.753 ''' except: pass