def test_GenerationOf_MATLAB(self):
        generatedShouldBe = '''% To the best of my knowledge this code is correct.
% If you find any errors or problems please contact
% me directly using [email protected].
%
%      James


% Fitting target: lowest sum of squared absolute error
% Fitting target value = 0.223837322455

function y = Polynomial_Linear_model(x_in)
\ttemp = 0.0;

\t% coefficients
\ta = -8.01913564075E+00;
\tb = 1.52644729419E+00;

\ttemp = temp + a + b .* x_in;

\ty = temp;
'''
        equation = pyeq3.Models_2D.Polynomial.Linear('SSQABS')
        pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(DataForUnitTests.asciiDataInColumns_2D, equation, False)
        equation.Solve()
        generated = pyeq3.outputSourceCodeService().GetOutputSourceCodeMATLAB(equation, inDigitsOfPrecisionString = '11')
        self.assertEqual(generated, generatedShouldBe)
    def test_GenerationOf_PYTHON(self):
        generatedShouldBe = '''# To the best of my knowledge this code is correct.
# If you find any errors or problems please contact
# me directly using [email protected].
#
#      James


import math

# Fitting target: lowest sum of squared absolute error
# Fitting target value = 0.223837322455

def Polynomial_Linear_model(x_in):
    temp = 0.0

    # coefficients
    a = -8.01913564075E+00
    b = 1.52644729419E+00

    temp += a + b * x_in
    return temp
'''
        equation = pyeq3.Models_2D.Polynomial.Linear('SSQABS')
        pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(DataForUnitTests.asciiDataInColumns_2D, equation, False)
        equation.Solve()
        generated = pyeq3.outputSourceCodeService().GetOutputSourceCodePYTHON(equation, inDigitsOfPrecisionString = '11')
        self.assertEqual(generated, generatedShouldBe)
    def test_GenerationOf_CSHARP(self):
        generatedShouldBe = '''// To the best of my knowledge this code is correct.
// If you find any errors or problems please contact
// me directly using [email protected].
//
//      James


using System;

// Fitting target: lowest sum of squared absolute error
// Fitting target value = 0.223837322455

class Polynomial_Linear
{
\tdouble Polynomial_Linear_model(double x_in)
\t{
\t\tdouble temp;
\t\ttemp = 0.0;

\t\t// coefficients
\t\tdouble a = -8.01913564075E+00;
\t\tdouble b = 1.52644729419E+00;

\t\ttemp += a + b * x_in;
\t\treturn temp;
\t}
}
'''
        equation = pyeq3.Models_2D.Polynomial.Linear('SSQABS')
        pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(DataForUnitTests.asciiDataInColumns_2D, equation, False)
        equation.Solve()
        generated = pyeq3.outputSourceCodeService().GetOutputSourceCodeCSHARP(equation, inDigitsOfPrecisionString = '11')
        self.assertEqual(generated, generatedShouldBe)
Example #4
0
    def test_GenerationOf_PYTHON(self):
        generatedShouldBe = '''# To the best of my knowledge this code is correct.
# If you find any errors or problems please contact
# me directly using [email protected].
#
#      James


import math

# Fitting target: lowest sum of squared absolute error
# Fitting target value = 0.223837322455

def Polynomial_Linear_model(x_in):
    temp = 0.0

    # coefficients
    a = -8.01913564075E+00
    b = 1.52644729419E+00

    temp += a + b * x_in
    return temp
'''
        equation = pyeq3.Models_2D.Polynomial.Linear('SSQABS')
        pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(
            DataForUnitTests.asciiDataInColumns_2D, equation, False)
        equation.Solve()
        generated = pyeq3.outputSourceCodeService().GetOutputSourceCodePYTHON(
            equation, inDigitsOfPrecisionString='11')
        self.assertEqual(generated, generatedShouldBe)
Example #5
0
    def test_GenerationOf_MATLAB(self):
        generatedShouldBe = '''% To the best of my knowledge this code is correct.
% If you find any errors or problems please contact
% me directly using [email protected].
%
%      James


% Fitting target: lowest sum of squared absolute error
% Fitting target value = 0.223837322455

function y = Polynomial_Linear_model(x_in)
\ttemp = 0.0;

\t% coefficients
\ta = -8.01913564075E+00;
\tb = 1.52644729419E+00;

\ttemp = temp + a + b .* x_in;

\ty = temp;
'''
        equation = pyeq3.Models_2D.Polynomial.Linear('SSQABS')
        pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(
            DataForUnitTests.asciiDataInColumns_2D, equation, False)
        equation.Solve()
        generated = pyeq3.outputSourceCodeService().GetOutputSourceCodeMATLAB(
            equation, inDigitsOfPrecisionString='11')
        self.assertEqual(generated, generatedShouldBe)
Example #6
0
    def test_GenerationOf_CPP(self):
        generatedShouldBe = '''// To the best of my knowledge this code is correct.
// If you find any errors or problems please contact
// me directly using [email protected].
//
//      James


#include <math.h>

// Fitting target: lowest sum of squared absolute error
// Fitting target value = 0.223837322455

double Polynomial_Linear_model(double x_in)
{
	double temp;
	temp = 0.0;

	// coefficients
	double a = -8.01913564075E+00;
	double b = 1.52644729419E+00;

	temp += a + b * x_in;
	return temp;
}
'''
        equation = pyeq3.Models_2D.Polynomial.Linear('SSQABS')
        pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(
            DataForUnitTests.asciiDataInColumns_2D, equation, False)
        equation.Solve()
        generated = pyeq3.outputSourceCodeService().GetOutputSourceCodeCPP(
            equation, inDigitsOfPrecisionString='11')
        self.assertEqual(generated, generatedShouldBe)
 def test_GenerationOf_CPP_ForAllEquations(self): # ensure no coding errors in source code generation for any equation
     for submodule in inspect.getmembers(pyeq3.Models_2D) + inspect.getmembers(pyeq3.Models_3D):
         if inspect.ismodule(submodule[1]):
             for equationClass in inspect.getmembers(submodule[1]):
                 if inspect.isclass(equationClass[1]):
                     try: # not all equation classes have a fixed number of coefficient designators
                         equation = equationClass[1]()
                         coeffCount = len(equation.GetCoefficientDesignators())
                         equation.solvedCoefficients = [1.0] * len(equation.GetCoefficientDesignators())
                     except:
                         continue
                     generated = pyeq3.outputSourceCodeService().GetOutputSourceCodeCPP(equation)
                     self.assertIs(type(generated), type('')) # must be a striong
                     self.assertTrue(len(generated) > 0) # must have a length > 0
    def test_ConversionFromCppToJAVA(self):
        convertedShouldBe = '''
\t\t// comment
\t\tdouble doubleVariable;
\t\ttemp = a * Math.abs(1.1);
\t\ttemp = a / Math.abs(1.1);
\t\ttemp += Math.pow(temp);
\t\ttemp -= Math.log(temp);
\t\ttemp = Math.log10(temp);
\t\ttemp = Math.exp(temp);
\t\ttemp = Math.sin(temp);
\t\ttemp = Math.cos(temp);
\t\ttemp = Math.tan(temp);
\t\ttemp = Math.tanh(temp);
\t\ttemp = Math.cosh(temp);
'''
        converted = pyeq3.outputSourceCodeService().ConvertCppToJAVA(self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
    def test_ConversionFromCppToMATLAB(self):
        convertedShouldBe = '''
\t% comment
\tdoubleVariable;
\ttemp = a .* abs(1.1);
\ttemp = a ./ abs(1.1);
\ttemp = temp + power(temp);
\ttemp = temp - log(temp);
\ttemp = log10(temp);
\ttemp = exp(temp);
\ttemp = sin(temp);
\ttemp = cos(temp);
\ttemp = tan(temp);
\ttemp = tanh(temp);
\ttemp = cosh(temp);
'''
        converted = pyeq3.outputSourceCodeService().ConvertCppToMATLAB(self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
    def test_ConversionFromCppToPYTHON(self):
        convertedShouldBe = '''
    # comment
    doubleVariable
    temp = a * math.fabs(1.1)
    temp = a / math.fabs(1.1)
    temp += math.pow(temp)
    temp -= math.log(temp)
    temp = math.log10(temp)
    temp = math.exp(temp)
    temp = math.sin(temp)
    temp = math.cos(temp)
    temp = math.tan(temp)
    temp = math.tanh(temp)
    temp = math.cosh(temp)
'''
        converted = pyeq3.outputSourceCodeService().ConvertCppToPYTHON(self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
    def test_ConversionFromCppToVBA(self):
        convertedShouldBe = '''
\t' comment
\tvar doubleVariable
\ttemp = a * Abs(1.1)
\ttemp = a / Abs(1.1)
\ttemp = temp + Application.WorksheetFunction.power(temp)
\ttemp = temp - Application.WorksheetFunction.ln(temp)
\ttemp = Application.WorksheetFunction.log(temp)
\ttemp = Exp(temp)
\ttemp = sin(temp)
\ttemp = cos(temp)
\ttemp = tan(temp)
\ttemp = Application.WorksheetFunction.tanh(temp)
\ttemp = Application.WorksheetFunction.cosh(temp)
'''
        converted = pyeq3.outputSourceCodeService().ConvertCppToVBA(self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
Example #12
0
    def test_ConversionFromCppToPYTHON(self):
        convertedShouldBe = '''
    # comment
    doubleVariable
    temp = a * math.fabs(1.1)
    temp = a / math.fabs(1.1)
    temp += math.pow(temp)
    temp -= math.log(temp)
    temp = math.log10(temp)
    temp = math.exp(temp)
    temp = math.sin(temp)
    temp = math.cos(temp)
    temp = math.tan(temp)
    temp = math.tanh(temp)
    temp = math.cosh(temp)
'''
        converted = pyeq3.outputSourceCodeService().ConvertCppToPYTHON(
            self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
Example #13
0
    def test_ConversionFromCppToVBA(self):
        convertedShouldBe = '''
\t' comment
\tvar doubleVariable
\ttemp = a * Abs(1.1)
\ttemp = a / Abs(1.1)
\ttemp = temp + Application.WorksheetFunction.power(temp)
\ttemp = temp - Application.WorksheetFunction.ln(temp)
\ttemp = Application.WorksheetFunction.log(temp)
\ttemp = Exp(temp)
\ttemp = sin(temp)
\ttemp = cos(temp)
\ttemp = tan(temp)
\ttemp = Application.WorksheetFunction.tanh(temp)
\ttemp = Application.WorksheetFunction.cosh(temp)
'''
        converted = pyeq3.outputSourceCodeService().ConvertCppToVBA(
            self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
Example #14
0
    def test_ConversionFromCppToMATLAB(self):
        convertedShouldBe = '''
\t% comment
\tdoubleVariable;
\ttemp = a .* abs(1.1);
\ttemp = a ./ abs(1.1);
\ttemp = temp + power(temp);
\ttemp = temp - log(temp);
\ttemp = log10(temp);
\ttemp = exp(temp);
\ttemp = sin(temp);
\ttemp = cos(temp);
\ttemp = tan(temp);
\ttemp = tanh(temp);
\ttemp = cosh(temp);
'''
        converted = pyeq3.outputSourceCodeService().ConvertCppToMATLAB(
            self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
Example #15
0
    def test_ConversionFromCppToJAVA(self):
        convertedShouldBe = '''
\t\t// comment
\t\tdouble doubleVariable;
\t\ttemp = a * Math.abs(1.1);
\t\ttemp = a / Math.abs(1.1);
\t\ttemp += Math.pow(temp);
\t\ttemp -= Math.log(temp);
\t\ttemp = Math.log10(temp);
\t\ttemp = Math.exp(temp);
\t\ttemp = Math.sin(temp);
\t\ttemp = Math.cos(temp);
\t\ttemp = Math.tan(temp);
\t\ttemp = Math.tanh(temp);
\t\ttemp = Math.cosh(temp);
'''
        converted = pyeq3.outputSourceCodeService().ConvertCppToJAVA(
            self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
Example #16
0
 def test_GenerationOf_CPP_ForAllEquations(
     self
 ):  # ensure no coding errors in source code generation for any equation
     for submodule in inspect.getmembers(
             pyeq3.Models_2D) + inspect.getmembers(pyeq3.Models_3D):
         if inspect.ismodule(submodule[1]):
             for equationClass in inspect.getmembers(submodule[1]):
                 if inspect.isclass(equationClass[1]):
                     try:  # not all equation classes have a fixed number of coefficient designators
                         equation = equationClass[1]()
                         coeffCount = len(
                             equation.GetCoefficientDesignators())
                         equation.solvedCoefficients = [1.0] * len(
                             equation.GetCoefficientDesignators())
                     except:
                         continue
                     generated = pyeq3.outputSourceCodeService(
                     ).GetOutputSourceCodeCPP(equation)
                     self.assertIs(type(generated),
                                   type(''))  # must be a striong
                     self.assertTrue(
                         len(generated) > 0)  # must have a length > 0
print()
print("Individual Parameter Statistics:")
for i in range(len(equation.solvedCoefficients)):
    if equation.tstat_beta == None:
        tstat = 'n/a'
    else:
        tstat = '%-.5E' %  ( equation.tstat_beta[i])

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

    if equation.sd_beta != 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))
Example #18
0
pythonFileName = sys.argv[0]  # unused
equationInfoFromNodeJS = json.loads(sys.argv[1])
textDataFromNodeJS = json.loads(sys.argv[2])
fittingTargetFromNodeJS = json.loads(sys.argv[3])

moduleName = equationInfoFromNodeJS['pythonModuleName']
className = equationInfoFromNodeJS['pythonClassName']
extendedVersionString = equationInfoFromNodeJS['extendedVersionString']
dimensionality = equationInfoFromNodeJS['dimensionality']

eqStringToEvaluate = 'pyeq3.Models_'
eqStringToEvaluate += str(dimensionality) + 'D.'
eqStringToEvaluate += moduleName + '.'
eqStringToEvaluate += className + '('
eqStringToEvaluate += '"' + fittingTargetFromNodeJS + '",'
eqStringToEvaluate += '"' + extendedVersionString + '")'

equation = eval(eqStringToEvaluate)

pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(
    textDataFromNodeJS, equation, False)

equation.Solve()

# output could include data statistics, error statistics, fit
# and coefficients statistics, etc. from the other Python examples
print(json.dumps(equation.solvedCoefficients.tolist()))
print((json.dumps(
    pyeq3.outputSourceCodeService().GetOutputSourceCodeJAVASCRIPT(equation))))
if -1 != sys.path[0].find('pyeq3-master'):raise Exception('Please rename git checkout directory from "pyeq3-master" to "pyeq3"')
importDir =  os.path.join(os.path.join(sys.path[0][:sys.path[0].rfind(os.sep)], '..'), '..')
if importDir not in sys.path:
    sys.path.append(importDir)
    
import pyeq3



# see IModel.fittingTargetDictionary
equation = pyeq3.Models_2D.Polynomial.Quadratic() # SSQABS by default

data = equation.exampleData
pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(data, equation, False)
equation.Solve()


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


print(pyeq3.outputSourceCodeService().GetOutputSourceCodeCPP(equation))
print(pyeq3.outputSourceCodeService().GetOutputSourceCodeCSHARP(equation))
print(pyeq3.outputSourceCodeService().GetOutputSourceCodeVBA(equation))
print(pyeq3.outputSourceCodeService().GetOutputSourceCodePYTHON(equation))
print(pyeq3.outputSourceCodeService().GetOutputSourceCodeJAVA(equation))
print(pyeq3.outputSourceCodeService().GetOutputSourceCodeJAVASCRIPT(equation))
print(pyeq3.outputSourceCodeService().GetOutputSourceCodeSCILAB(equation))
print(pyeq3.outputSourceCodeService().GetOutputSourceCodeMATLAB(equation))
print(pyeq3.outputSourceCodeService().GetOutputSourceCodeJULIA(equation))
print(pyeq3.outputSourceCodeService().GetOutputSourceCodeFORTRAN90(equation))
Example #20
0
equation.CalculateModelErrors(equation.solvedCoefficients,
                              equation.dataCache.allDataCacheDictionary)

print()
print('\"Best fit\" was', moduleName + "." + className)

print('Fitting target value', equation.fittingTarget + ":",
      equation.CalculateAllDataFittingTarget(equation.solvedCoefficients))

print()
print('Polyfunctional flags:', polyfunctional3DFlags)
print()
for i in range(len(equation.solvedCoefficients)):
    print("Coefficient " + equation.GetCoefficientDesignators()[i] + ": " +
          str(equation.solvedCoefficients[i]))
print()

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

print('Generated source code section commented out')
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeCPP(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeCSHARP(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeVBA(equation))
print(pyeq3.outputSourceCodeService().GetOutputSourceCodePYTHON(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeJAVA(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeJAVASCRIPT(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeSCILAB(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeMATLAB(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeJULIA(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeFORTRAN90(equation))
Example #21
0
equation.solvedCoefficients = solvedCoefficients
equation.dataCache.FindOrCreateAllDataCache(equation)
equation.CalculateModelErrors(equation.solvedCoefficients, equation.dataCache.allDataCacheDictionary)


print()
print('\"Best fit\" was', moduleName + "." + className)

print('Fitting target value', equation.fittingTarget + ":", equation.CalculateAllDataFittingTarget(equation.solvedCoefficients))

print()
print('Polyfunctional flags:', polyfunctional3DFlags)
print()
for i in range(len(equation.solvedCoefficients)):
    print("Coefficient " + equation.GetCoefficientDesignators()[i] + ": " + str(equation.solvedCoefficients[i]))
print()

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

print('Generated source code section commented out')
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeCPP(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeCSHARP(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeVBA(equation))
print(pyeq3.outputSourceCodeService().GetOutputSourceCodePYTHON(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeJAVA(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeJAVASCRIPT(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeSCILAB(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeMATLAB(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeJULIA(equation))
#print(pyeq3.outputSourceCodeService().GetOutputSourceCodeFORTRAN90(equation))
Example #22
0
def SaveSourceCode(in_sourceCodeFilePath,  in_equation):
    
    outputFile = open(in_sourceCodeFilePath, 'w')
        
    outputFile.write('<html><body>\n\n')
    
    try:
        outputFile.write('<b>C++</b><br><textarea rows="20" cols="85" wrap="OFF">')
        outputFile.write(pyeq3.outputSourceCodeService().GetOutputSourceCodeCPP(in_equation))
        outputFile.write('</textarea><br><br>\n\n')
    except:
        pass

    try:
        outputFile.write('<b>CSHARP</b><br><textarea rows="20" cols="85" wrap="OFF">')
        outputFile.write(pyeq3.outputSourceCodeService().GetOutputSourceCodeCSHARP(in_equation))
        outputFile.write('</textarea><br><br>\n\n')
    except:
        pass

    try:
        outputFile.write('<b>VBA</b><br><textarea rows="20" cols="85" wrap="OFF">')
        outputFile.write(pyeq3.outputSourceCodeService().GetOutputSourceCodeVBA(in_equation))
        outputFile.write('</textarea><br><br>\n\n')
    except:
        pass

    try:
        outputFile.write('<b>PYTHON</b><br><textarea rows="20" cols="85" wrap="OFF">')
        outputFile.write(pyeq3.outputSourceCodeService().GetOutputSourceCodePYTHON(in_equation))
        outputFile.write('</textarea><br><br>\n\n')
    except:
        pass

    try:
        outputFile.write('<b>JAVA</b><br><textarea rows="20" cols="85" wrap="OFF">')
        outputFile.write(pyeq3.outputSourceCodeService().GetOutputSourceCodeJAVA(in_equation))
        outputFile.write('</textarea><br><br>\n\n')
    except:
        pass

    try:
        outputFile.write('<b>JAVASCRIPT</b><br><textarea rows="20" cols="85" wrap="OFF">')
        outputFile.write(pyeq3.outputSourceCodeService().GetOutputSourceCodeJAVASCRIPT(in_equation))
        outputFile.write('</textarea><br><br>\n\n')
    except:
        pass

    try:
        outputFile.write('<b>JULIA</b><br><textarea rows="20" cols="85" wrap="OFF">')
        outputFile.write(pyeq3.outputSourceCodeService().GetOutputSourceCodeJULIA(in_equation))
        outputFile.write('</textarea><br><br>\n\n')
    except:
        pass

    try:
        outputFile.write('<b>FORTRAN90</b><br><textarea rows="20" cols="85" wrap="OFF">')
        outputFile.write(pyeq3.outputSourceCodeService().GetOutputSourceCodeFORTRAN90(in_equation))
        outputFile.write('</textarea><br><br>\n\n')
    except:
        pass

    try:
        outputFile.write('<b>SCILAB</b><br><textarea rows="20" cols="85" wrap="OFF">')
        outputFile.write(pyeq3.outputSourceCodeService().GetOutputSourceCodeSCILAB(in_equation))
        outputFile.write('</textarea><br><br>\n\n')
    except:
        pass

    try:
        outputFile.write('<b>MATLAB</b><br><textarea rows="20" cols="85" wrap="OFF">')
        outputFile.write(pyeq3.outputSourceCodeService().GetOutputSourceCodeMATLAB(in_equation))
        outputFile.write('</textarea><br><br>\n\n')
    except:
        pass

    outputFile.write('</body></html>\n')
    
    outputFile.close()
Example #23
0
    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))
Example #24
0
import pyeq3


pythonFileName = sys.argv[0] # unused
equationInfoFromNodeJS = json.loads(sys.argv[1])
textDataFromNodeJS = json.loads(sys.argv[2])
fittingTargetFromNodeJS = json.loads(sys.argv[3])

moduleName = equationInfoFromNodeJS['pythonModuleName']
className = equationInfoFromNodeJS['pythonClassName']
extendedVersionString = equationInfoFromNodeJS['extendedVersionString']
dimensionality = equationInfoFromNodeJS['dimensionality']

eqStringToEvaluate = 'equation = pyeq3.Models_'
eqStringToEvaluate += str(dimensionality) + 'D.'
eqStringToEvaluate += moduleName + '.'
eqStringToEvaluate += className + '('
eqStringToEvaluate += '"' + fittingTargetFromNodeJS + '",'
eqStringToEvaluate += '"' + extendedVersionString + '")'

exec(eqStringToEvaluate)

pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(textDataFromNodeJS, equation, False)

equation.Solve()

# output could include data statistics, error statistics, fit
# and coefficients statistics, etc. from the other Python examples
print(json.dumps(equation.solvedCoefficients.tolist()))
print((json.dumps(pyeq3.outputSourceCodeService().GetOutputSourceCodeJAVASCRIPT(equation))))