当前位置: 首页>>代码示例>>Python>>正文


Python math.poly1d函数代码示例

本文整理汇总了Python中mystic.math.poly1d函数的典型用法代码示例。如果您正苦于以下问题:Python poly1d函数的具体用法?Python poly1d怎么用?Python poly1d使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了poly1d函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main():
    solver = DifferentialEvolutionSolver(ND, NP)
    solver.SetRandomInitialPoints()
    solver.SetEvaluationLimits(generations=MAX_GENERATIONS)
    solver.SetGenerationMonitor(VerboseMonitor(10))
  
    #strategy = Best1Exp
    #strategy = Best1Bin
    #strategy = Best2Bin
    strategy = Best2Exp

    solver.Solve(ChebyshevCost, termination=VTR(0.0001), strategy=strategy, \
                 CrossProbability=1.0, ScalingFactor=0.6)

    solution = solver.Solution()
  
    print("\nsolved: ")
    print(poly1d(solution))
    print("\ntarget: ")
    print(poly1d(Chebyshev16))
   #print("actual coefficients vs computed:")
   #for actual,computed in zip(Chebyshev16, solution):
   #    print("%f %f" % (actual, computed))

    plot_solution(solution, Chebyshev16)
开发者ID:Magellen,项目名称:mystic,代码行数:25,代码来源:test_ffit2.py

示例2: plot_solution

def plot_solution(params):
    import numpy
    x = numpy.arange(-1.2, 1.2001, 0.01)
    f = poly1d(params)
    y = f(x)
    pylab.plot(x,y,'y-')
    pylab.legend(["Exact","Fitted"])
    pylab.axis([-1.4,1.4,-2,8],'k-')
    return
开发者ID:eriknw,项目名称:mystic,代码行数:9,代码来源:example09.py

示例3: plot_solution

def plot_solution(params,style='y-'):
    import numpy
    x = numpy.arange(-1.2, 1.2001, 0.01)
    f = poly1d(params)
    y = f(x)
    plt.plot(x,y,style)
    plt.legend(["Exact","Fitted"])
    plt.axis([-1.4,1.4,-2,8],'k-')
    plt.draw()
    plt.pause(0.001)
    return
开发者ID:uqfoundation,项目名称:mystic,代码行数:11,代码来源:example08.py

示例4: plot_solution

def plot_solution(func, benchmark=Chebyshev8):
    try:
        import pylab, numpy
        x = numpy.arange(-1.2, 1.2001, 0.01)
        x2 = numpy.array([-1.0, 1.0])
        p = poly1d(func)
        chebyshev = poly1d(benchmark)
        y = p(x)
        exact = chebyshev(x)
        pylab.plot(x,y,'b-',linewidth=2)
        pylab.plot(x,exact,'r-',linewidth=2)
        pylab.plot(x,0*x-1,'k-')
        pylab.plot(x2, 0*x2+1,'k-')
        pylab.plot([-1.2, -1.2],[-1, 10],'k-')
        pylab.plot([1.2, 1.2],[-1, 10],'k-')
        pylab.plot([-1.0, -1.0],[1, 10],'k-')
        pylab.plot([1.0, 1.0],[1, 10],'k-')
        pylab.axis([-1.4, 1.4, -2, 8],'k-')
        pylab.legend(('Fitted','Chebyshev'))
        pylab.show()
    except ImportError:
        print "Install matplotlib/numpy for visualization"
        pass
开发者ID:eriknw,项目名称:mystic,代码行数:23,代码来源:test_ffit.py

示例5: print_solution

 def print_solution(func):
     print poly1d(func)
     return
开发者ID:agamdua,项目名称:mystic,代码行数:3,代码来源:ezmap_desolve.py

示例6: VerboseMonitor

    # configure monitor
    stepmon = VerboseMonitor(50)

    # use DE to solve 8th-order Chebyshev coefficients
    npop = 10*ndim
    solver = DifferentialEvolutionSolver2(ndim,npop)
    solver.SetRandomInitialPoints(min=[-100]*ndim, max=[100]*ndim)
    solver.SetGenerationMonitor(stepmon)
    solver.enable_signal_handler()
    solver.Solve(chebyshev8cost, termination=VTR(0.01), strategy=Best1Exp, \
                 CrossProbability=1.0, ScalingFactor=0.9, \
                 sigint_callback=plot_solution)
    solution = solver.Solution()

    # use monitor to retrieve results information
    iterations = len(stepmon)
    cost = stepmon.y[-1]
    print("Generation %d has best Chi-Squared: %f" % (iterations, cost))

    # use pretty print for polynomials
    print(poly1d(solution))

    # compare solution with actual 8th-order Chebyshev coefficients
    print("\nActual Coefficients:\n %s\n" % poly1d(chebyshev8coeffs))

    # plot solution versus exact coefficients
    plot_solution(solution)
    getch()

# end of file
开发者ID:uqfoundation,项目名称:mystic,代码行数:30,代码来源:example08.py

示例7: _init

                                datefmt='%a, %d %b %Y %H:%M:%S')

    def _init(self):
        Script._init(self)
        return

    def help(self):
        doc =  """
# this will solve the default "example" problem
%(name)s

        """ % {'name' : __file__}
        paginate(doc)
        return



# main
if __name__ == '__main__':
    app = DerunApp()
    app.run()

    # Chebyshev8 polynomial (used with "dummy.py")
    from mystic.models.poly import chebyshev8coeffs as target_coeffs
    from mystic.math import poly1d
    print "target:\n", poly1d(target_coeffs)
    print "\nDE Solution:\n", poly1d(app.solution)


# End of file
开发者ID:cdeil,项目名称:mystic,代码行数:30,代码来源:derun.py

示例8: DifferentialEvolutionSolver2

    # use DE to solve 8th-order Chebyshev coefficients
    npop = 10*ndim
    solver = DifferentialEvolutionSolver2(ndim,npop)
    solver.SetRandomInitialPoints(min=[-100]*ndim, max=[100]*ndim)
    solver.SetEvaluationLimits(generations=999)
    solver.SetEvaluationMonitor(evalmon)
    solver.SetGenerationMonitor(stepmon)
    solver.enable_signal_handler()
    solver.Solve(chebyshev8cost, termination=VTR(0.01), strategy=Best1Exp, \
                 CrossProbability=1.0, ScalingFactor=0.9)
    solution = solver.bestSolution

    # get solved coefficients and Chi-Squared (from solver members)
    iterations = solver.generations
    cost = solver.bestEnergy
    print "Generation %d has best Chi-Squared: %f" % (iterations, cost)
    print "Solved Coefficients:\n %s\n" % poly1d(solver.bestSolution)

    # plot convergence of coefficients per iteration
    plot_frame('iterations')
    plot_params(stepmon) 
    getch()

    # plot convergence of coefficients per function call
    plot_frame('function calls')
    plot_params(evalmon) 
    getch()

# end of file
开发者ID:eriknw,项目名称:mystic,代码行数:29,代码来源:example10.py

示例9: ForwardFactory

    def ForwardFactory(self,coeffs):
        """generates a 1-D polynomial instance from a list of coefficients
using numpy.poly1d(coeffs)"""
        self.__forward__ = poly1d(coeffs)
        return self.__forward__
开发者ID:agamdua,项目名称:mystic,代码行数:5,代码来源:poly.py

示例10: chebyshev8cost

def chebyshev8cost(trial,M=61):
    """The costfunction for order-n Chebyshev fitting.
M evaluation points between [-1, 1], and two end points"""

    from mystic.models.poly import chebyshev8coeffs as target
    from mystic.math import polyeval

    result=0.0
    x=-1.0
    dx = 2.0 / (M-1)
    for i in range(M):
        px = polyeval(trial, x)
        if px<-1 or px>1:
            result += (1 - px) * (1 - px)
        x += dx

    px = polyeval(trial, 1.2) - polyeval(target, 1.2)
    if px<0: result += px*px

    px = polyeval(trial, -1.2) - polyeval(target, -1.2)
    if px<0: result += px*px

    return result

if __name__=='__main__':
    from mystic.models.poly import chebyshev8coeffs as target
    from mystic.math import poly1d
    print(poly1d(target))
    print("")
    print(chebyshev8cost(target))
开发者ID:uqfoundation,项目名称:mystic,代码行数:30,代码来源:raw_chebyshev8.py

示例11: NelderMeadSimplexSolver

    solver = NelderMeadSimplexSolver(ndim)
    solver.SetInitialPoints(x0)
    solver.SetEvaluationLimits(generations=999)
    solver.SetEvaluationMonitor(evalmon)
    solver.SetGenerationMonitor(stepmon)
    solver.SetStrictRanges(min_bounds,max_bounds)
    solver.enable_signal_handler()
    solver.Solve(chebyshev8cost, termination=CRT(1e-4,1e-4), \
                 sigint_callback=plot_solution)
    solution = solver.bestSolution

    # get solved coefficients and Chi-Squared (from solver members)
    iterations = solver.generations
    cost = solver.bestEnergy
    print("Generation %d has best Chi-Squared: %f" % (iterations, cost))
    print("Solved Coefficients:\n %s\n" % poly1d(solver.bestSolution))

    # compare solution with actual 8th-order Chebyshev coefficients
    print("Actual Coefficients:\n %s\n" % poly1d(chebyshev8coeffs))

    # plot solution versus exact coefficients
    plot_solution(solution)
    getch()

    # plot convergence of coefficients per iteration
    plot_frame('iterations')
    plot_params(stepmon)
    getch()

    # plot convergence of coefficients per function call
    plot_frame('function calls')
开发者ID:Magellen,项目名称:mystic,代码行数:31,代码来源:example11.py

示例12: chebyshev8cost

"""

from mystic.models.poly import chebyshev8coeffs as target
from mystic.math import polyeval, poly1d

def chebyshev8cost(trial,M=61):
    """The costfunction for order-n Chebyshev fitting.
M evaluation points between [-1, 1], and two end points"""

    result=0.0
    x=-1.0
    dx = 2.0 / (M-1)
    for i in range(M):
        px = polyeval(trial, x)
        if px<-1 or px>1:
            result += (1 - px) * (1 - px)
        x += dx

    px = polyeval(trial, 1.2) - polyeval(target, 1.2)
    if px<0: result += px*px

    px = polyeval(trial, -1.2) - polyeval(target, -1.2)
    if px<0: result += px*px

    return result

if __name__=='__main__':
    print poly1d(target)
    print ""
    print chebyshev8cost(target)
开发者ID:agamdua,项目名称:mystic,代码行数:30,代码来源:raw_chebyshev8b.py

示例13: _init

                                datefmt='%a, %d %b %Y %H:%M:%S')

    def _init(self):
        Script._init(self)
        return

    def help(self):
        doc =  """
# this will solve the default "example" problem
%(name)s

        """ % {'name' : __file__}
        paginate(doc)
        return



# main
if __name__ == '__main__':
    app = DerunApp()
    app.run()

    # Chebyshev8 polynomial (used with "dummy.py")
    from mystic.models.poly import chebyshev8coeffs as target_coeffs
    from mystic.math import poly1d
    print("target:\n%s" % poly1d(target_coeffs))
    print("\nDE Solution:\n%s" % poly1d(app.solution))


# End of file
开发者ID:Magellen,项目名称:mystic,代码行数:30,代码来源:derun.py


注:本文中的mystic.math.poly1d函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。