Example #1
0
 def nonlinear_fit(d, e, p0):
     """
     ======== ===========================================================
     Name     Description
     ======== ===========================================================
     d        list of values of the (single) discretization
              parameter in each experiment:
              ``d[i]`` provides the values of the discretization,
              parameter in experiement no. i.
     e        list of error values; ``e = (e_1, e_2, ...)``,
              ``e[i]`` is the error associated with the parameters
              ``d[i]``
     p0       starting values for the unknown parameters vector
     return   r, C; r is the exponent, C is the factor in front
     ======== ===========================================================
     """
     if len(d) != len(e):
         raise ValueError('d and e must have the same length')
     if not isinstance(d[0], (float,int)):
         raise TypeError('d must be an array of numbers, not %s' % \
                         str(type(d[0])))
     # transform d and e to the data format required by
     # the Scientific package:
     data = []
     for d_i, e_i in zip(d, e):
         data.append(((d_i,) , e_i))  # recall (a,) conversion to tuple
     leastSquaresFit = import_module('Scientific.Functions.LeastSquares',
                                     'leastSquaresFit')
     sol = leastSquaresFit(OneDiscretizationPrm.error_model, p0, data)
     C = sol[0][0]
     a = sol[0][1]
     return a, C
Example #2
0
 def nonlinear_fit(d, e, initial_guess):
     """
     ============== ================================================
     Argument       Description
     ============== ================================================
     d              list of values of the set of discretization
                    parameters in each experiment:
                    ``d = ((d_1,d_2,d_3),(d_1,d_2,d_3,),...)``;
                    ``d[i]`` provides the values of the
                    discretization parameters in experiement no. i.
     e              list of error values; ``e = (e_1, e_2, ...)``:
                    ``e[i]`` is the error associated with the
                    parameters ``d[i]``
     initial_guess  the starting value for the unknown
                    parameters vector
     return         list of fitted parameters
     ============== ================================================
     """
     if len(d) != len(e):
         raise ValueError('len(d) != len(e)')
     # transform d and e to the data format required by
     # the Scientific package:
     data = []
     for d_i, e_i in zip(d, e):
         if isinstance(d_i, (float, int)):
             data.append(((d_i,), e_i))
         else:  # d_i is tuple, list, array, NumArray, ...
             data.append((d_i, e_i))
     leastSquaresFit = import_module('Scientific.Functions.LeastSquares',
                                     'leastSquaresFit')
     sol = leastSquaresFit(ManyDiscretizationPrm.error_model,
                           initial_guess, data)
     # return list of fitted parameters (p in error_model)
     # (sol[1] is a measure of the quality of the fit)
     return sol[0]
Example #3
0
 def nonlinear_fit(d, e, p0):
     """
     ======== ===========================================================
     Name     Description
     ======== ===========================================================
     d        list of values of the (single) discretization
              parameter in each experiment:
              ``d[i]`` provides the values of the discretization,
              parameter in experiement no. i.
     e        list of error values; ``e = (e_1, e_2, ...)``,
              ``e[i]`` is the error associated with the parameters
              ``d[i]``
     p0       starting values for the unknown parameters vector
     return   r, C; r is the exponent, C is the factor in front
     ======== ===========================================================
     """
     if len(d) != len(e):
         raise ValueError('d and e must have the same length')
     if not isinstance(d[0], (float, int)):
         raise TypeError('d must be an array of numbers, not %s' % \
                         str(type(d[0])))
     # transform d and e to the data format required by
     # the Scientific package:
     data = []
     for d_i, e_i in zip(d, e):
         data.append(((d_i, ), e_i))  # recall (a,) conversion to tuple
     leastSquaresFit = import_module('Scientific.Functions.LeastSquares',
                                     'leastSquaresFit')
     sol = leastSquaresFit(OneDiscretizationPrm.error_model, p0, data)
     C = sol[0][0]
     a = sol[0][1]
     return a, C
Example #4
0
 def nonlinear_fit(d, e, initial_guess):
     """
     ============== ================================================
     Argument       Description
     ============== ================================================
     d              list of values of the set of discretization
                    parameters in each experiment:
                    ``d = ((d_1,d_2,d_3),(d_1,d_2,d_3,),...)``;
                    ``d[i]`` provides the values of the
                    discretization parameters in experiement no. i.
     e              list of error values; ``e = (e_1, e_2, ...)``:
                    ``e[i]`` is the error associated with the
                    parameters ``d[i]``
     initial_guess  the starting value for the unknown
                    parameters vector
     return         list of fitted parameters
     ============== ================================================
     """
     if len(d) != len(e):
         raise ValueError('len(d) != len(e)')
     # transform d and e to the data format required by
     # the Scientific package:
     data = []
     for d_i, e_i in zip(d, e):
         if isinstance(d_i, (float, int)):
             data.append(((d_i, ), e_i))
         else:  # d_i is tuple, list, array, NumArray, ...
             data.append((d_i, e_i))
     leastSquaresFit = import_module('Scientific.Functions.LeastSquares',
                                     'leastSquaresFit')
     sol = leastSquaresFit(ManyDiscretizationPrm.error_model, initial_guess,
                           data)
     # return list of fitted parameters (p in error_model)
     # (sol[1] is a measure of the quality of the fit)
     return sol[0]
Example #5
0
    def __init__(self, data):
        self.data = data  # (x,y,f) data for an f(x,y) function

        from scitools.misc import import_module
        InterpolatingFunction = import_module(
            'Scientific.Functions.Interpolation', 'InterpolatingFunction')
        import Scientific
        v = Scientific.__version__
        target = '2.9.1'
        if v < target:
            raise ImportError(
                'ScientificPython is in (old) version %s, need %s'
                % (v, target))

        self.interpolating_function = \
            InterpolatingFunction(self.data[:-1], self.data[-1])
        self.ndims = len(self.data[:-1])  # no of spatial dim.
Example #6
0
    def __init__(self, data):
        self.data = data  # (x,y,f) data for an f(x,y) function

        from scitools.misc import import_module
        InterpolatingFunction = import_module(
            'Scientific.Functions.Interpolation', 'InterpolatingFunction')
        import Scientific
        v = Scientific.__version__
        target = '2.9.1'
        if v < target:
            raise ImportError(
                'ScientificPython is in (old) version %s, need %s' %
                (v, target))

        self.interpolating_function = \
            InterpolatingFunction(self.data[:-1], self.data[-1])
        self.ndims = len(self.data[:-1])  # no of spatial dim.