Skip to content

Commit

Permalink
Minor work regularizing fit statististics for Simple examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zunzun committed Dec 17, 2016
1 parent 2f69874 commit c9e5a50
Show file tree
Hide file tree
Showing 3 changed files with 300 additions and 5 deletions.
101 changes: 101 additions & 0 deletions Examples/Simple/FitOneNamedEquation_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,104 @@
print("Fitted Parameters:")
for i in range(len(equation.solvedCoefficients)):
print(" %s = %-.16E" % (equation.GetCoefficientDesignators()[i], equation.solvedCoefficients[i]))


equation.CalculateModelErrors(equation.solvedCoefficients, equation.dataCache.allDataCacheDictionary)
print()
for i in range(len(equation.dataCache.allDataCacheDictionary['DependentData'])):
print('X:', equation.dataCache.allDataCacheDictionary['IndependentData'][0][i],)
print('Y:', equation.dataCache.allDataCacheDictionary['IndependentData'][1][i],)
print('Z:', equation.dataCache.allDataCacheDictionary['DependentData'][i],)
print('Model:', equation.modelPredictions[i],)
print('Abs. Error:', equation.modelAbsoluteError[i],)
if not equation.dataCache.DependentDataContainsZeroFlag:
print('Rel. Error:', equation.modelRelativeError[i],)
print('Percent Error:', equation.modelPercentError[i])
else:
print()
print()


##########################################################


equation.CalculateCoefficientAndFitStatistics()

if equation.upperCoefficientBounds or equation.lowerCoefficientBounds:
print('You entered coefficient bounds. Parameter statistics may')
print('not be valid for parameter values at or near the bounds.')
print()

print('Degress of freedom error', equation.df_e)
print('Degress of freedom regression', equation.df_r)

if equation.rmse == None:
print('Root Mean Squared Error (RMSE): n/a')
else:
print('Root Mean Squared Error (RMSE):', equation.rmse)

if equation.r2 == None:
print('R-squared: n/a')
else:
print('R-squared:', equation.r2)

if equation.r2adj == None:
print('R-squared adjusted: n/a')
else:
print('R-squared adjusted:', equation.r2adj)

if equation.Fstat == None:
print('Model F-statistic: n/a')
else:
print('Model F-statistic:', equation.Fstat)

if equation.Fpv == None:
print('Model F-statistic p-value: n/a')
else:
print('Model F-statistic p-value:', equation.Fpv)

if equation.ll == None:
print('Model log-likelihood: n/a')
else:
print('Model log-likelihood:', equation.ll)

if equation.aic == None:
print('Model AIC: n/a')
else:
print('Model AIC:', equation.aic)

if equation.bic == None:
print('Model BIC: n/a')
else:
print('Model BIC:', equation.bic)


print()
print("Individual Parameter Statistics:")
for i in range(len(equation.solvedCoefficients)):
if type(equation.tstat_beta) == type(None):
tstat = 'n/a'
else:
tstat = '%-.5E' % ( equation.tstat_beta[i])

if type(equation.pstat_beta) == type(None):
pstat = 'n/a'
else:
pstat = '%-.5E' % ( equation.pstat_beta[i])

if type(equation.sd_beta) != type(None):
print("Coefficient %s = %-.16E, std error: %-.5E" % (equation.GetCoefficientDesignators()[i], equation.solvedCoefficients[i], equation.sd_beta[i]))
else:
print("Coefficient %s = %-.16E, std error: n/a" % (equation.GetCoefficientDesignators()[i], equation.solvedCoefficients[i]))
print(" t-stat: %s, p-stat: %s, 95 percent confidence intervals: [%-.5E, %-.5E]" % (tstat, pstat, equation.ci[i][0], equation.ci[i][1]))


print()
print("Coefficient Covariance Matrix:")
for i in equation.cov_beta:
print(i)


print()
print('Java Source Code:')
print(pyeq3.outputSourceCodeService().GetOutputSourceCodeJAVA(equation))
104 changes: 102 additions & 2 deletions Examples/Simple/FitUserData_2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,108 @@
##########################################################


print(equation.GetDisplayName(), str(equation.GetDimensionality()) + "D")
print(equation.fittingTargetDictionary[equation.fittingTarget], '=', equation.CalculateAllDataFittingTarget(equation.solvedCoefficients))
print("Equation:", equation.GetDisplayName(), str(equation.GetDimensionality()) + "D")
print("Fitting target of", equation.fittingTargetDictionary[equation.fittingTarget], '=', equation.CalculateAllDataFittingTarget(equation.solvedCoefficients))
print("Fitted Parameters:")
for i in range(len(equation.solvedCoefficients)):
print(" %s = %-.16E" % (equation.GetCoefficientDesignators()[i], equation.solvedCoefficients[i]))


equation.CalculateModelErrors(equation.solvedCoefficients, equation.dataCache.allDataCacheDictionary)
print()
for i in range(len(equation.dataCache.allDataCacheDictionary['DependentData'])):
print('X:', equation.dataCache.allDataCacheDictionary['IndependentData'][0][i],)
print('Y:', equation.dataCache.allDataCacheDictionary['DependentData'][i],)
print('Model:', equation.modelPredictions[i],)
print('Abs. Error:', equation.modelAbsoluteError[i],)
if not equation.dataCache.DependentDataContainsZeroFlag:
print('Rel. Error:', equation.modelRelativeError[i],)
print('Percent Error:', equation.modelPercentError[i])
else:
print()
print()


##########################################################


equation.CalculateCoefficientAndFitStatistics()

if equation.upperCoefficientBounds or equation.lowerCoefficientBounds:
print('You entered coefficient bounds. Parameter statistics may')
print('not be valid for parameter values at or near the bounds.')
print()

print('Degress of freedom error', equation.df_e)
print('Degress of freedom regression', equation.df_r)

if equation.rmse == None:
print('Root Mean Squared Error (RMSE): n/a')
else:
print('Root Mean Squared Error (RMSE):', equation.rmse)

if equation.r2 == None:
print('R-squared: n/a')
else:
print('R-squared:', equation.r2)

if equation.r2adj == None:
print('R-squared adjusted: n/a')
else:
print('R-squared adjusted:', equation.r2adj)

if equation.Fstat == None:
print('Model F-statistic: n/a')
else:
print('Model F-statistic:', equation.Fstat)

if equation.Fpv == None:
print('Model F-statistic p-value: n/a')
else:
print('Model F-statistic p-value:', equation.Fpv)

if equation.ll == None:
print('Model log-likelihood: n/a')
else:
print('Model log-likelihood:', equation.ll)

if equation.aic == None:
print('Model AIC: n/a')
else:
print('Model AIC:', equation.aic)

if equation.bic == None:
print('Model BIC: n/a')
else:
print('Model BIC:', equation.bic)


print()
print("Individual Parameter Statistics:")
for i in range(len(equation.solvedCoefficients)):
if type(equation.tstat_beta) == type(None):
tstat = 'n/a'
else:
tstat = '%-.5E' % ( equation.tstat_beta[i])

if type(equation.pstat_beta) == type(None):
pstat = 'n/a'
else:
pstat = '%-.5E' % ( equation.pstat_beta[i])

if type(equation.sd_beta) != type(None):
print("Coefficient %s = %-.16E, std error: %-.5E" % (equation.GetCoefficientDesignators()[i], equation.solvedCoefficients[i], equation.sd_beta[i]))
else:
print("Coefficient %s = %-.16E, std error: n/a" % (equation.GetCoefficientDesignators()[i], equation.solvedCoefficients[i]))
print(" t-stat: %s, p-stat: %s, 95 percent confidence intervals: [%-.5E, %-.5E]" % (tstat, pstat, equation.ci[i][0], equation.ci[i][1]))


print()
print("Coefficient Covariance Matrix:")
for i in equation.cov_beta:
print(i)


print()
print('Java Source Code:')
print(pyeq3.outputSourceCodeService().GetOutputSourceCodeJAVA(equation))
100 changes: 97 additions & 3 deletions Examples/Simple/FitUserDefinedFunction_2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,103 @@
##########################################################


print(equation.GetDisplayName(), str(equation.GetDimensionality()) + "D")
print('User Defined Function:', functionString)
print(equation.fittingTargetDictionary[equation.fittingTarget], '=', equation.CalculateAllDataFittingTarget(equation.solvedCoefficients))
print("Equation:", equation.GetDisplayName(), str(equation.GetDimensionality()) + "D")
print("Fitting target of", equation.fittingTargetDictionary[equation.fittingTarget], '=', equation.CalculateAllDataFittingTarget(equation.solvedCoefficients))
print("Fitted Parameters:")
for i in range(len(equation.solvedCoefficients)):
print(" %s = %-.16E" % (equation.GetCoefficientDesignators()[i], equation.solvedCoefficients[i]))


equation.CalculateModelErrors(equation.solvedCoefficients, equation.dataCache.allDataCacheDictionary)
print()
for i in range(len(equation.dataCache.allDataCacheDictionary['DependentData'])):
print('X:', equation.dataCache.allDataCacheDictionary['IndependentData'][0][i],)
print('Y:', equation.dataCache.allDataCacheDictionary['DependentData'][i],)
print('Model:', equation.modelPredictions[i],)
print('Abs. Error:', equation.modelAbsoluteError[i],)
if not equation.dataCache.DependentDataContainsZeroFlag:
print('Rel. Error:', equation.modelRelativeError[i],)
print('Percent Error:', equation.modelPercentError[i])
else:
print()
print()


##########################################################


equation.CalculateCoefficientAndFitStatistics()

if equation.upperCoefficientBounds or equation.lowerCoefficientBounds:
print('You entered coefficient bounds. Parameter statistics may')
print('not be valid for parameter values at or near the bounds.')
print()

print('Degress of freedom error', equation.df_e)
print('Degress of freedom regression', equation.df_r)

if equation.rmse == None:
print('Root Mean Squared Error (RMSE): n/a')
else:
print('Root Mean Squared Error (RMSE):', equation.rmse)

if equation.r2 == None:
print('R-squared: n/a')
else:
print('R-squared:', equation.r2)

if equation.r2adj == None:
print('R-squared adjusted: n/a')
else:
print('R-squared adjusted:', equation.r2adj)

if equation.Fstat == None:
print('Model F-statistic: n/a')
else:
print('Model F-statistic:', equation.Fstat)

if equation.Fpv == None:
print('Model F-statistic p-value: n/a')
else:
print('Model F-statistic p-value:', equation.Fpv)

if equation.ll == None:
print('Model log-likelihood: n/a')
else:
print('Model log-likelihood:', equation.ll)

if equation.aic == None:
print('Model AIC: n/a')
else:
print('Model AIC:', equation.aic)

if equation.bic == None:
print('Model BIC: n/a')
else:
print('Model BIC:', equation.bic)


print()
print("Individual Parameter Statistics:")
for i in range(len(equation.solvedCoefficients)):
if type(equation.tstat_beta) == type(None):
tstat = 'n/a'
else:
tstat = '%-.5E' % ( equation.tstat_beta[i])

if type(equation.pstat_beta) == type(None):
pstat = 'n/a'
else:
pstat = '%-.5E' % ( equation.pstat_beta[i])

if type(equation.sd_beta) != type(None):
print("Coefficient %s = %-.16E, std error: %-.5E" % (equation.GetCoefficientDesignators()[i], equation.solvedCoefficients[i], equation.sd_beta[i]))
else:
print("Coefficient %s = %-.16E, std error: n/a" % (equation.GetCoefficientDesignators()[i], equation.solvedCoefficients[i]))
print(" t-stat: %s, p-stat: %s, 95 percent confidence intervals: [%-.5E, %-.5E]" % (tstat, pstat, equation.ci[i][0], equation.ci[i][1]))


print()
print("Coefficient Covariance Matrix:")
for i in equation.cov_beta:
print(i)

0 comments on commit c9e5a50

Please sign in to comment.