コード例 #1
0
    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 = pyeq2.Models_2D.Polynomial.Linear('SSQABS')
        pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(DataForUnitTests.asciiDataInColumns_2D, equation, False)
        equation.Solve()
        generated = pyeq2.outputSourceCodeService().GetOutputSourceCodeCSHARP(equation, inDigitsOfPrecisionString = '11')
        self.assertEqual(generated, generatedShouldBe)
コード例 #2
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 = pyeq2.Models_2D.Polynomial.Linear('SSQABS')
        pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(DataForUnitTests.asciiDataInColumns_2D, equation, False)
        equation.Solve()
        generated = pyeq2.outputSourceCodeService().GetOutputSourceCodeMATLAB(equation, inDigitsOfPrecisionString = '11')
        self.assertEqual(generated, generatedShouldBe)
コード例 #3
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 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 = pyeq2.Models_2D.Polynomial.Linear('SSQABS')
        pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(
            DataForUnitTests.asciiDataInColumns_2D, equation, False)
        equation.Solve()
        generated = pyeq2.outputSourceCodeService().GetOutputSourceCodeCPP(
            equation, inDigitsOfPrecisionString='11')
        self.assertEqual(generated, generatedShouldBe)
コード例 #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 = pyeq2.Models_2D.Polynomial.Linear('SSQABS')
        pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(DataForUnitTests.asciiDataInColumns_2D, equation, False)
        equation.Solve()
        generated = pyeq2.outputSourceCodeService().GetOutputSourceCodePYTHON(equation, inDigitsOfPrecisionString = '11')
        self.assertEqual(generated, generatedShouldBe)
コード例 #5
0
    def test_GenerationOf_VBA(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

Public Function Linear_model(x_in)
\ttemp = 0.0

\t' coefficients
\tConst a = -8.01913564075E+00
\tConst b = 1.52644729419E+00

\ttemp = temp + a + b * x_in
\tLinear_model = temp
End Function
"""
        equation = pyeq2.Models_2D.Polynomial.Linear("SSQABS")
        pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(
            DataForUnitTests.asciiDataInColumns_2D, equation, False
        )
        equation.Solve()
        generated = pyeq2.outputSourceCodeService().GetOutputSourceCodeVBA(equation, inDigitsOfPrecisionString="11")
        self.assertEqual(generated, generatedShouldBe)
コード例 #6
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 Linear_model(x_in):
    temp = 0.0

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

    temp += a + b * x_in
    return temp
'''
        equation = pyeq2.Models_2D.Polynomial.Linear('SSQABS')
        pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(
            DataForUnitTests.asciiDataInColumns_2D, equation, False)
        equation.Solve()
        generated = pyeq2.outputSourceCodeService().GetOutputSourceCodePYTHON(
            equation, inDigitsOfPrecisionString='11')
        self.assertEqual(generated, generatedShouldBe)
コード例 #7
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 = 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 = pyeq2.Models_2D.Polynomial.Linear('SSQABS')
        pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(
            DataForUnitTests.asciiDataInColumns_2D, equation, False)
        equation.Solve()
        generated = pyeq2.outputSourceCodeService().GetOutputSourceCodeMATLAB(
            equation, inDigitsOfPrecisionString='11')
        self.assertEqual(generated, generatedShouldBe)
コード例 #8
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 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 = pyeq2.Models_2D.Polynomial.Linear("SSQABS")
        pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(
            DataForUnitTests.asciiDataInColumns_2D, equation, False
        )
        equation.Solve()
        generated = pyeq2.outputSourceCodeService().GetOutputSourceCodeCPP(equation, inDigitsOfPrecisionString="11")
        self.assertEqual(generated, generatedShouldBe)
コード例 #9
0
 def test_GenerationOf_CPP_ForAllEquations(self): # ensure no coding errors in source code generation for any equation
     for submodule in inspect.getmembers(pyeq2.Models_2D) + inspect.getmembers(pyeq2.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 = pyeq2.outputSourceCodeService().GetOutputSourceCodeCPP(equation)
                     self.assertIs(type(generated), type('')) # must be a striong
                     self.assertTrue(len(generated) > 0) # must have a length > 0
コード例 #10
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 = pyeq2.outputSourceCodeService().ConvertCppToMATLAB(self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
コード例 #11
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 = pyeq2.outputSourceCodeService().ConvertCppToPYTHON(self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
コード例 #12
0
    def test_ConversionFromCppToCSHARP(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 = pyeq2.outputSourceCodeService().ConvertCppToCSHARP(self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
コード例 #13
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 = pyeq2.outputSourceCodeService().ConvertCppToJAVA(self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
コード例 #14
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 = pyeq2.outputSourceCodeService().ConvertCppToVBA(self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
コード例 #15
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.log(temp)
\ttemp = Application.WorksheetFunction.log10(temp)
\ttemp = Exp(temp)
\ttemp = sin(temp)
\ttemp = cos(temp)
\ttemp = tan(temp)
\ttemp = Application.WorksheetFunction.tanh(temp)
\ttemp = Application.WorksheetFunction.cosh(temp)
'''
        converted = pyeq2.outputSourceCodeService().ConvertCppToVBA(
            self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
コード例 #16
0
    def test_ConversionFromCppToPYTHON(self):
        convertedShouldBe = '''
    # comment
    # double 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 = pyeq2.outputSourceCodeService().ConvertCppToPYTHON(
            self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
コード例 #17
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 = pyeq2.outputSourceCodeService().ConvertCppToMATLAB(
            self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
コード例 #18
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 = pyeq2.outputSourceCodeService().ConvertCppToJAVA(
            self.cppStringForTestingLanguageConversions)
        self.assertEqual(converted, convertedShouldBe)
コード例 #19
0
 def test_GenerationOf_CPP_ForAllEquations(
     self
 ):  # ensure no coding errors in source code generation for any equation
     for submodule in inspect.getmembers(
             pyeq2.Models_2D) + inspect.getmembers(pyeq2.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 = pyeq2.outputSourceCodeService(
                     ).GetOutputSourceCodeCPP(equation)
                     self.assertIs(type(generated),
                                   type(''))  # must be a striong
                     self.assertTrue(
                         len(generated) > 0)  # must have a length > 0
コード例 #20
0
ファイル: Spline_3D.py プロジェクト: llchen223/pyeq2
pyeq2IimportDirectory = os.path.join(os.path.join(exampleFileDirectory, '..'),
                                     '..')
if pyeq2IimportDirectory not in sys.path:
    sys.path.append(pyeq2IimportDirectory)

import pyeq2

# parameters are smoothing, xOrder, yOrder
equation = pyeq2.Models_3D.Spline.Spline(1.0, 3, 3)  # cubic 3D spline

data = equation.exampleData

pyeq2.dataConvertorService().ConvertAndSortColumnarASCII(data, equation, False)
equation.Solve()

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

print("Equation:", equation.GetDisplayName(),
      str(equation.GetDimensionality()) + "D")
print("Fitting target of",
      equation.fittingTargetDictionary[equation.fittingTarget], '=',
      equation.CalculateAllDataFittingTarget(equation.solvedCoefficients))

print()

# at present, only these four languages are supported for spline-specific code
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeCPP(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodePYTHON(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJAVA(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJAVASCRIPT(equation))
コード例 #21
0
# ensure pyeq2 can be imported
if -1 != sys.path[0].find('pyeq2-master'):
    raise Exception(
        'Please rename git checkout directory from "pyeq2-master" to "pyeq2"')
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 pyeq2

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

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

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

print(pyeq2.outputSourceCodeService().GetOutputSourceCodeCPP(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeCSHARP(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeVBA(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodePYTHON(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJAVA(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJAVASCRIPT(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeSCILAB(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeMATLAB(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJULIA(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeFORTRAN90(equation))
コード例 #22
0
ファイル: interface.py プロジェクト: vdt/pyeq2
import pyeq2


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 = pyeq2.Models_'
eqStringToEvaluate += str(dimensionality) + 'D.'
eqStringToEvaluate += moduleName + '.'
eqStringToEvaluate += className + '('
eqStringToEvaluate += '"' + fittingTargetFromNodeJS + '",'
eqStringToEvaluate += '"' + extendedVersionString + '")'

exec(eqStringToEvaluate)

pyeq2.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(pyeq2.outputSourceCodeService().GetOutputSourceCodeJAVASCRIPT(equation)))
コード例 #23
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(
            pyeq2.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(
            pyeq2.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(
            pyeq2.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(
            pyeq2.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(
            pyeq2.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(
            pyeq2.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(
            pyeq2.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(
            pyeq2.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(
            pyeq2.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(
            pyeq2.outputSourceCodeService().GetOutputSourceCodeMATLAB(
                in_equation))
        outputFile.write('</textarea><br><br>\n\n')
    except:
        pass

    outputFile.write('</body></html>\n')

    outputFile.close()
コード例 #24
0
if -1 != sys.path[0].find('pyeq2-master'):raise Exception('Please rename git checkout directory from "pyeq2-master" to "pyeq2"')
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 pyeq2



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

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


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


print(pyeq2.outputSourceCodeService().GetOutputSourceCodeCPP(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeCSHARP(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeVBA(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodePYTHON(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJAVA(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJAVASCRIPT(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeSCILAB(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeMATLAB(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJULIA(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodeFORTRAN90(equation))
コード例 #25
0
            pstat = "n/a"
        else:
            pstat = "%-.5E" % (equation.pstat_beta[i])

        if equation.sd_beta != None:
            print "Coefficient %s = %-.16E, std error squared: %-.5E" % (
                equation.GetCoefficientDesignators()[i],
                equation.solvedCoefficients[i],
                equation.sd_beta[i],
            )
        else:
            print "Coefficient %s = %-.16E, std error squared: 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 pyeq2.outputSourceCodeService().GetOutputSourceCodeJAVA(equation)
コード例 #26
0
ファイル: TextUtils.py プロジェクト: agulbronson/pyeq2
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(pyeq2.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(pyeq2.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(pyeq2.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(pyeq2.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(pyeq2.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(pyeq2.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(pyeq2.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(pyeq2.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(pyeq2.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(pyeq2.outputSourceCodeService().GetOutputSourceCodeMATLAB(in_equation))
        outputFile.write('</textarea><br><br>\n\n')
    except:
        pass

    outputFile.write('</body></html>\n')
    
    outputFile.close()
コード例 #27
0
    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 squared: %-.5E" % (
                equation.GetCoefficientDesignators()[i],
                equation.solvedCoefficients[i], equation.sd_beta[i])
        else:
            print "Coefficient %s = %-.16E, std error squared: 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 pyeq2.outputSourceCodeService().GetOutputSourceCodeJAVA(equation)
コード例 #28
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(pyeq2.outputSourceCodeService().GetOutputSourceCodeCPP(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeCSHARP(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeVBA(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodePYTHON(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJAVA(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJAVASCRIPT(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeSCILAB(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeMATLAB(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJULIA(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeFORTRAN90(equation))
コード例 #29
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(pyeq2.outputSourceCodeService().GetOutputSourceCodeCPP(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeCSHARP(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeVBA(equation))
print(pyeq2.outputSourceCodeService().GetOutputSourceCodePYTHON(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJAVA(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJAVASCRIPT(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeSCILAB(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeMATLAB(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeJULIA(equation))
#print(pyeq2.outputSourceCodeService().GetOutputSourceCodeFORTRAN90(equation))