#NEWLINE# def CalculateAllDataFittingTarget( self , inCoeffs ) : #NEWLINE# #INDENT# if ( not self . AreCoefficientsWithinBounds ( inCoeffs ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( self . upperCoefficientBounds != [ ] ) : #NEWLINE# #INDENT# for i in range ( len ( inCoeffs ) ) : #NEWLINE# #INDENT# if ( self . upperCoefficientBounds [ i ] != None ) : #NEWLINE# #INDENT# if ( inCoeffs [ i ] > self . upperCoefficientBounds [ i ] ) : #NEWLINE# #INDENT# inCoeffs [ i ] = self . upperCoefficientBounds [ i ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( self . lowerCoefficientBounds != [ ] ) : #NEWLINE# #INDENT# for i in range ( len ( inCoeffs ) ) : #NEWLINE# #INDENT# if ( self . lowerCoefficientBounds [ i ] != None ) : #NEWLINE# #INDENT# if ( inCoeffs [ i ] < self . lowerCoefficientBounds [ i ] ) : #NEWLINE# #INDENT# inCoeffs [ i ] = self . lowerCoefficientBounds [ i ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# if ( self . fixedCoefficients != [ ] ) : #NEWLINE# #INDENT# for i in range ( len ( inCoeffs ) ) : #NEWLINE# #INDENT# if ( self . fixedCoefficients [ i ] != None ) : #NEWLINE# #INDENT# inCoeffs [ i ] = self . fixedCoefficients [ i ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . CalculateModelErrors ( inCoeffs , self . dataCache . allDataCacheDictionary ) #NEWLINE# error = self . modelAbsoluteError #NEWLINE# if len ( self . dataCache . allDataCacheDictionary [ 'Weights' ] ) : #NEWLINE# #INDENT# error = ( error * self . dataCache . allDataCacheDictionary [ 'Weights' ] ) #NEWLINE# #UNINDENT# if ( self . fittingTarget == 'SSQABS' ) : #NEWLINE# #INDENT# val = numpy . sum ( numpy . square ( error ) ) #NEWLINE# if numpy . isfinite ( val ) : #NEWLINE# #INDENT# return val #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return 1e+300 #NEWLINE# #UNINDENT# #UNINDENT# if ( self . fittingTarget == 'SSQREL' ) : #NEWLINE# #INDENT# error = ( error / self . dataCache . allDataCacheDictionary [ 'DependentData' ] ) #NEWLINE# val = numpy . sum ( numpy . square ( error ) ) #NEWLINE# if numpy . isfinite ( val ) : #NEWLINE# #INDENT# return val #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return 1e+300 #NEWLINE# #UNINDENT# #UNINDENT# if ( self . fittingTarget == 'ABSABS' ) : #NEWLINE# #INDENT# val = numpy . sum ( numpy . abs ( error ) ) #NEWLINE# if numpy . isfinite ( val ) : #NEWLINE# #INDENT# return val #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return 1e+300 #NEWLINE# #UNINDENT# #UNINDENT# if ( self . fittingTarget == 'LNQREL' ) : #NEWLINE# #INDENT# Q = ( self . modelPredictions / self . dataCache . allDataCacheDictionary [ 'DependentData' ] ) #NEWLINE# sumsqlogQ = numpy . sum ( numpy . square ( numpy . log ( Q ) ) ) #NEWLINE# val = sumsqlogQ #NEWLINE# if numpy . isfinite ( val ) : #NEWLINE# #INDENT# return val #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return 1e+300 #NEWLINE# #UNINDENT# #UNINDENT# if ( self . fittingTarget == 'ABSREL' ) : #NEWLINE# #INDENT# val = numpy . sum ( numpy . abs ( ( error / self . dataCache . allDataCacheDictionary [ 'DependentData' ] ) ) ) #NEWLINE# if numpy . isfinite ( val ) : #NEWLINE# #INDENT# return val #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return 1e+300 #NEWLINE# #UNINDENT# #UNINDENT# if ( self . fittingTarget == 'PEAKABS' ) : #NEWLINE# #INDENT# val = numpy . max ( numpy . abs ( error ) ) #NEWLINE# if numpy . isfinite ( val ) : #NEWLINE# #INDENT# return val #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return 1e+300 #NEWLINE# #UNINDENT# #UNINDENT# if ( self . fittingTarget == 'PEAKREL' ) : #NEWLINE# #INDENT# val = numpy . max ( numpy . abs ( ( error / self . dataCache . allDataCacheDictionary [ 'DependentData' ] ) ) ) #NEWLINE# if numpy . isfinite ( val ) : #NEWLINE# #INDENT# return val #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return 1e+300 #NEWLINE# #UNINDENT# #UNINDENT# if ( self . fittingTarget == 'ODR' ) : #NEWLINE# #INDENT# model = scipy . odr . odrpack . Model ( self . WrapperForODR ) #NEWLINE# if len ( self . dataCache . allDataCacheDictionary [ 'Weights' ] ) : #NEWLINE# #INDENT# data = scipy . odr . odrpack . Data ( self . dataCache . allDataCacheDictionary [ 'IndependentData' ] , self . dataCache . allDataCacheDictionary [ 'DependentData' ] , we = self . dataCache . allDataCacheDictionary [ 'Weights' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data = scipy . odr . odrpack . Data ( self . dataCache . allDataCacheDictionary [ 'IndependentData' ] , self . dataCache . allDataCacheDictionary [ 'DependentData' ] ) #NEWLINE# #UNINDENT# myodr = scipy . odr . odrpack . ODR ( data , error , beta0 = inCoeffs , maxit = 0 ) #NEWLINE# myodr . set_job ( fit_type = 2 ) #NEWLINE# out = myodr . run ( ) #NEWLINE# val = out . sum_square #NEWLINE# if numpy . isfinite ( val ) : #NEWLINE# #INDENT# return val #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return 1e+300 #NEWLINE# #UNINDENT# #UNINDENT# ncoef = ( 1.0 * len ( inCoeffs ) ) #NEWLINE# nobs = ( 1.0 * len ( self . dataCache . allDataCacheDictionary [ 'DependentData' ] ) ) #NEWLINE# ll = ( ( ( - ( nobs * 0.5 ) ) * ( 1.0 + numpy . log ( ( 2.0 * numpy . pi ) ) ) ) - ( ( nobs * 0.5 ) * numpy . log ( ( numpy . dot ( error , error ) / nobs ) ) ) ) #NEWLINE# if ( self . fittingTarget == 'AIC' ) : #NEWLINE# #INDENT# val = ( ( ( ( - 2.0 ) * ll ) / nobs ) + ( ( 2.0 * ncoef ) / nobs ) ) #NEWLINE# if numpy . isfinite ( val ) : #NEWLINE# #INDENT# return val #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return 1e+300 #NEWLINE# #UNINDENT# #UNINDENT# if ( self . fittingTarget == 'BIC' ) : #NEWLINE# #INDENT# val = ( ( ( ( - 2.0 ) * ll ) / nobs ) + ( ( ncoef * numpy . log ( nobs ) ) / nobs ) ) #NEWLINE# if numpy . isfinite ( val ) : #NEWLINE# #INDENT# return val #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return 1e+300 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# return 1e+300