本文整理汇总了Python中pyeq3.dataConvertorService函数的典型用法代码示例。如果您正苦于以下问题:Python dataConvertorService函数的具体用法?Python dataConvertorService怎么用?Python dataConvertorService使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dataConvertorService函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SetParametersAndFit
def SetParametersAndFit(equationString, inFittingTargetString, inExtendedVersionString, inTextData):
# individual cluster nodes must be able to import pyeq3
import pyeq3
exec('equation = ' + equationString +'("' + inFittingTargetString + '", "' + inExtendedVersionString + '")')
pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(inTextData, equation, False)
try:
# check for number of coefficients > number of data points to be fitted
if len(equation.GetCoefficientDesignators()) > len(equation.dataCache.allDataCacheDictionary['DependentData']):
return None
# check for functions requiring non-zero nor non-negative data such as 1/x, etc.
if equation.ShouldDataBeRejected(equation):
return None
equation.Solve()
fittedTarget = equation.CalculateAllDataFittingTarget(equation.solvedCoefficients)
if fittedTarget > 1.0E290: # error too large
return None
except:
return None
return [fittedTarget, equation.GetDisplayName(), equation.solvedCoefficients, equationString, inExtendedVersionString]
示例2: test_SolveUsingLevenbergMarquardt_2D
def test_SolveUsingLevenbergMarquardt_2D(self):
coefficientsShouldBe = numpy.array([-8.01913565, 1.5264473])
model = pyeq3.Models_2D.Polynomial.Linear('SSQABS')
model.estimatedCoefficients = numpy.array([-4.0, 2.0]) # starting values for the simplex solver
pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(DataForUnitTests.asciiDataInColumns_2D, model, False)
coefficients = pyeq3.solverService().SolveUsingSelectedAlgorithm(model, inAlgorithmName="Levenberg-Marquardt")
self.assertTrue(numpy.allclose(coefficients, coefficientsShouldBe, rtol=1.0E-06, atol=1.0E-300))
示例3: test_SolveUsingODR_3D
def test_SolveUsingODR_3D(self):
coefficientsShouldBe = numpy.array([-0.04925, -0.90509, 1.28076])
model = pyeq3.Models_3D.Polynomial.Linear('ODR')
model.estimatedCoefficients = numpy.array([0.2, -1.0, 1.0]) # starting values for the ODR solver
pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(DataForUnitTests.asciiDataInColumns_3D, model, False)
coefficients = pyeq3.solverService().SolveUsingODR(model)
self.assertTrue(numpy.allclose(coefficients, coefficientsShouldBe, rtol=1.0E-03, atol=1.0E-300))
示例4: test_SolveUsingSimplex_SSQREL_2D
def test_SolveUsingSimplex_SSQREL_2D(self):
coefficientsShouldBe = numpy.array([-6.74510573, 1.32459622])
model = pyeq3.Models_2D.Polynomial.Linear('SSQREL')
model.estimatedCoefficients = numpy.array([1.0, 1.0]) # starting values for the simplex solver
pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(DataForUnitTests.asciiDataInColumns_2D, model, False)
coefficients = pyeq3.solverService().SolveUsingSimplex(model)
self.assertTrue(numpy.allclose(coefficients, coefficientsShouldBe, rtol=1.0E-06, atol=1.0E-300))
示例5: test_SolveUsingSimplex_3D
def test_SolveUsingSimplex_3D(self):
coefficientsShouldBe = numpy.array([0.28658383, -0.90215775, 1.15483864])
model = pyeq3.Models_3D.Polynomial.Linear('SSQABS')
model.estimatedCoefficients = numpy.array([1.0, 1.0, 1.0]) # starting values for the simplex solver
pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(DataForUnitTests.asciiDataInColumns_3D, model, False)
coefficients = pyeq3.solverService().SolveUsingSimplex(model)
self.assertTrue(numpy.allclose(coefficients, coefficientsShouldBe, rtol=1.0E-06, atol=1.0E-300))
示例6: test_SolveUsingDE_3D
def test_SolveUsingDE_3D(self):
coefficientsShouldBe = numpy.array([-2.05105972, -0.49194959, 1.77817475])
model = pyeq3.Models_3D.UserDefinedFunction.UserDefinedFunction('SSQABS', 'Default', 'a + b*X + c*Y')
pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(DataForUnitTests.asciiDataInColumns_3D_small, model, False)
coefficients = pyeq3.solverService().SolveUsingDE(model)
fittingTarget = model.CalculateAllDataFittingTarget(coefficients)
self.assertTrue(fittingTarget <= 0.1)
示例7: test_GenerationOf_MATLAB
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)
示例8: test_GenerationOf_CSHARP
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)
示例9: test_GenerationOf_PYTHON
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)
示例10: OnFit_3D
def OnFit_3D(self):
textData = self.text_3D.get("1.0", tk.END)
equationSelection = dfc.exampleEquationList_3D[self.equationSelect_3D.get()]
fittingTargetSelection = dfc.fittingTargetList[self.fittingTargetSelect_3D.get()]
# the GUI's fitting target string contains what we need - extract it
fittingTarget = fittingTargetSelection.split('(')[1].split(')')[0]
if equationSelection == 'Linear Polynomial':
self.equation = pyeq3.Models_3D.Polynomial.Linear(fittingTarget)
if equationSelection == 'Full Quadratic Polynomial':
self.equation = pyeq3.Models_3D.Polynomial.FullQuadratic(fittingTarget)
if equationSelection == 'Full Cubic Polynomial':
self.equation = pyeq3.Models_3D.Polynomial.FullCubic(fittingTarget)
if equationSelection == 'Monkey Saddle A':
self.equation = pyeq3.Models_3D.Miscellaneous.MonkeySaddleA(fittingTarget)
if equationSelection == 'Gaussian Curvature Of Whitneys Umbrella A':
self.equation = pyeq3.Models_3D.Miscellaneous.GaussianCurvatureOfWhitneysUmbrellaA(fittingTarget)
if equationSelection == 'NIST Nelson Autolog':
self.equation = pyeq3.Models_3D.NIST.NIST_NelsonAutolog(fittingTarget)
if equationSelection == 'Custom Polynomial One':
self.equation = pyeq3.Models_3D.Polynomial.UserSelectablePolynomial(fittingTarget, "Default", 3, 1)
# convert text to numeric data checking for log of negative numbers, etc.
try:
pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(textData, self.equation, False)
except:
tk_mbox.showerror("Error", self.equation.reasonWhyDataRejected)
return
# check for number of coefficients > number of data points to be fitted
coeffCount = len(self.equation.GetCoefficientDesignators())
dataCount = len(self.equation.dataCache.allDataCacheDictionary['DependentData'])
if coeffCount > dataCount:
tk_mbox.showerror("Error", "This equation requires a minimum of " + str(coeffCount) + " data points, you have supplied " + repr(dataCount) + ".")
return
# Now the status dialog is used. Disable fitting buttons until thread completes
self.buttonFit_2D.config(state=tk.DISABLED)
self.buttonFit_3D.config(state=tk.DISABLED)
# create simple topl-level text dialog to display status as fitting progresses
# when the fitting thread completes, it will close the status box
self.statusBox = tk.Toplevel()
self.statusBox.title("Fitting Status")
self.statusBox.text = tk.Text(self.statusBox)
self.statusBox.text.pack()
# in tkinter the status box must be manually centered
self.statusBox.update_idletasks()
width = self.statusBox.winfo_width()
height = self.statusBox.winfo_height()
x = (self.statusBox.winfo_screenwidth() // 2) - (width // 2) # integer division
y = (self.statusBox.winfo_screenheight() // 2) - (height // 2) # integer division
self.statusBox.geometry('{}x{}+{}+{}'.format(width, height, x, y))
# thread will automatically start to run
# "status update" handler will re-enable buttons
self.fittingWorkerThread = FittingThread.FittingThread(self, self.equation)
示例11: test_SplineSolve_3D
def test_SplineSolve_3D(self):
resultShouldBe = (numpy.array([0.607, 0.607, 0.607, 3.017, 3.017, 3.017]),
numpy.array([1.984, 1.984, 1.984, 3.153, 3.153, 3.153]),
numpy.array([2.33418963, 1.80079612, 5.07902936, 0.54445029, 1.04110843, 2.14180324, 0.26992805, 0.39148852, 0.8177307])
)
model = pyeq3.Models_3D.Spline.Spline(inSmoothingFactor = 1.0, inXOrder = 2, inYOrder = 2)
pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(model.exampleData, model, False)
result = model.Solve()
self.assertTrue(numpy.allclose(result[0], resultShouldBe[0], rtol=1.0E-06, atol=1.0E-300))
self.assertTrue(numpy.allclose(result[1], resultShouldBe[1], rtol=1.0E-06, atol=1.0E-300))
self.assertTrue(numpy.allclose(result[2], resultShouldBe[2], rtol=1.0E-06, atol=1.0E-300))
示例12: test_SplineSolve_2D
def test_SplineSolve_2D(self):
resultShouldBe = (numpy.array([5.357, 5.357, 5.357, 5.357, 9.861, 9.861, 9.861, 9.861]),
numpy.array([0.38297001, 1.95535226, 4.59605664, 7.16162379, 0.0, 0.0, 0.0, 0.0]),
3
)
model = pyeq3.Models_2D.Spline.Spline(inSmoothingFactor = 1.0, inXOrder = 3)
pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(model.exampleData, model, False)
result = model.Solve()
self.assertTrue(numpy.allclose(result[0], resultShouldBe[0], rtol=1.0E-06, atol=1.0E-300))
self.assertTrue(numpy.allclose(result[1], resultShouldBe[1], rtol=1.0E-06, atol=1.0E-300))
self.assertEqual(result[2], resultShouldBe[2])
示例13: fitEquationUsingDispyCluster
def fitEquationUsingDispyCluster(inEquationString, inFittingTargetString, inExtendedVersionString, inTextData):
# individual cluster nodes must be able to import pyeq3
import pyeq3
exec('equation = ' + inEquationString +'("' + inFittingTargetString + '", "' + inExtendedVersionString + '")')
pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(inTextData, equation, False)
equation.Solve()
fittedTarget = equation.CalculateAllDataFittingTarget(equation.solvedCoefficients)
# this result list allows easy sorting of multiple results later
return [fittedTarget, inEquationString, equation.solvedCoefficients]
示例14: SetParametersAndFit
def SetParametersAndFit(inEquation, inPrintStatus): # utility function
global globalDataCache
global globalReducedDataCache
global globalRawData
inEquation.dataCache = globalDataCache
if inEquation.dataCache.allDataCacheDictionary == {}:
pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(globalRawData, inEquation, False)
inEquation.dataCache.CalculateNumberOfReducedDataPoints(inEquation)
if inEquation.numberOfReducedDataPoints in globalReducedDataCache:
inEquation.dataCache.reducedDataCacheDictionary = globalReducedDataCache[inEquation.numberOfReducedDataPoints]
else:
inEquation.dataCache.reducedDataCacheDictionary = {}
try:
# check for number of coefficients > number of data points to be fitted
if len(inEquation.GetCoefficientDesignators()) > len(inEquation.dataCache.allDataCacheDictionary['DependentData']):
return None
# check for functions requiring non-zero nor non-negative data such as 1/x, etc.
if inEquation.ShouldDataBeRejected(inEquation):
return None
if inPrintStatus:
print('Process ID', str(os.getpid()), 'Fitting', inEquation.__module__, "'" + inEquation.GetDisplayName() + "'")
inEquation.Solve()
if inEquation.numberOfReducedDataPoints not in globalReducedDataCache:
globalReducedDataCache[inEquation.numberOfReducedDataPoints] = inEquation.dataCache.reducedDataCacheDictionary
target = inEquation.CalculateAllDataFittingTarget(inEquation.solvedCoefficients)
if target > 1.0E290: # error too large
return None
except:
print("Exception in " + inEquation.__class__.__name__ + '\n' + str(sys.exc_info()[0]) + '\n' + str(sys.exc_info()[1]) + '\n')
return None
t0 = copy.deepcopy(inEquation.__module__)
t1 = copy.deepcopy(inEquation.__class__.__name__)
t2 = copy.deepcopy(inEquation.extendedVersionHandler.__class__.__name__.split('_')[1])
t3 = copy.deepcopy(target)
t4 = copy.deepcopy(inEquation.solvedCoefficients)
t5 = copy.deepcopy(inEquation.polyfunctional2DFlags)
t6 = copy.deepcopy(inEquation.xPolynomialOrder)
t7 = copy.deepcopy(inEquation.rationalNumeratorFlags)
t8 = copy.deepcopy(inEquation.rationalDenominatorFlags)
return [t0,t1,t2,t3,t4,t5,t6,t7,t8]
示例15: test_SolveUsingSpline_2D
def test_SolveUsingSpline_2D(self):
knotPointsShouldBe = numpy.array([5.357, 5.357, 5.357, 5.357, 9.861, 9.861, 9.861, 9.861])
coefficientsShouldBe = numpy.array([ 0.38297001, 1.95535226, 4.59605664, 7.16162379, 0.0, 0.0, 0.0, 0.0])
testEvaluationShouldBe = numpy.array([4.02361487093])
model = pyeq3.Models_2D.Spline.Spline(inSmoothingFactor = 1.0, inXOrder = 3)
pyeq3.dataConvertorService().ConvertAndSortColumnarASCII(DataForUnitTests.asciiDataInColumns_2D, model, False)
fittedParameters = pyeq3.solverService().SolveUsingSpline(model)
# example of later using the saved spline knot points and coefficients
unFittedSpline = scipy.interpolate.fitpack2.UnivariateSpline(model.dataCache.allDataCacheDictionary['X'], model.dataCache.allDataCacheDictionary['DependentData'], s=model.smoothingFactor, k=model.xOrder)
unFittedSpline._eval_args = fittedParameters
testEvaluation = unFittedSpline(numpy.array([8.0]))
self.assertTrue(numpy.allclose(testEvaluation, testEvaluationShouldBe, rtol=1.0E-10, atol=1.0E-300))
self.assertTrue(numpy.equal(fittedParameters[0], knotPointsShouldBe).all())
self.assertTrue(numpy.allclose(fittedParameters[1], coefficientsShouldBe, rtol=1.0E-06, atol=1.0E-300))