示例#1
0
def predict(func, x):
    '''
    Predict y value using fitting function and x value.
    
    :param func: (*Fitting function object*) Fitting function.
    :param x: (*float*) x value.
    
    :returns: (*float*) y value.
    '''
    if isinstance(x, (int, float, long)):
        return func.predict(x)

    if isinstance(x, list):
        x = NDArray(ArrayUtil.array(x))
    return NDArray(FittingUtil.predict(x.asarray(), func))
示例#2
0
def expfit(x, y, func=False):
    '''
    Exponent fitting.
    
    :param x: (*array_like*) x data array.
    :param y: (*array_like*) y data array.
    :param func: (*boolean*) Return fit function (for predict function) or not. Default is ``False``.
    
    :returns: Fitting parameters and function (optional).
    '''
    if isinstance(x, list):
        x = NDArray(ArrayUtil.array(x))
    if isinstance(y, list):
        y = NDArray(ArrayUtil.array(y))
    r = FittingUtil.expFit(x.asarray(), y.asarray())
    if func:
        return r[0], r[1], r[2], r[3]
    else:
        return r[0], r[1], r[2]
示例#3
0
def polyfit(x, y, degree, func=False):
    '''
    Polynomail fitting.
    
    :param x: (*array_like*) x data array.
    :param y: (*array_like*) y data array.
    :param func: (*boolean*) Return fit function (for predict function) or not. Default is ``False``.
    
    :returns: Fitting parameters and function (optional).
    '''
    if isinstance(x, list):
        x = MIArray(ArrayUtil.array(x))
    if isinstance(y, list):
        y = MIArray(ArrayUtil.array(y))
    r = FittingUtil.polyFit(x.asarray(), y.asarray(), degree)
    if func:
        return r[0], r[1], r[2]
    else:
        return r[0], r[1]