• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# lsfitstate类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



lsfitstate类属于命名空间,在下文中一共展示了lsfitstate类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: lsfitcreatefgh

    public static void lsfitcreatefgh(double[,] x, double[] y, double[] c, out lsfitstate state)
    {
        int n;
        int m;
        int k;
        if( (ap.rows(x)!=ap.len(y)))
            throw new alglibexception("Error while calling 'lsfitcreatefgh': looks like one of arguments has wrong size");
        state = new lsfitstate();
        n = ap.rows(x);
        m = ap.cols(x);
        k = ap.len(c);
        lsfit.lsfitcreatefgh(x, y, c, n, m, k, state.innerobj);

        return;
    }
开发者ID:Ring-r,项目名称:opt,代码行数:15,代码来源:interpolation.cs


示例2: LSFitNonlinearWFGH

        /*************************************************************************
        Nonlinear least squares fitting using gradient/Hessian without  individual
        weights. See LSFitNonlinearWFGH() for more information.


          -- ALGLIB --
             Copyright 17.08.2009 by Bochkanov Sergey
        *************************************************************************/
        public static void lsfitnonlinearfgh(ref double[,] x,
            ref double[] y,
            ref double[] c,
            int n,
            int m,
            int k,
            ref lsfitstate state)
        {
            int i = 0;
            int i_ = 0;

            state.n = n;
            state.m = m;
            state.k = k;
            lsfitnonlinearsetcond(ref state, 0.0, 0.0, 0);
            lsfitnonlinearsetstpmax(ref state, 0.0);
            state.cheapfg = true;
            state.havehess = true;
            if( n>=1 & m>=1 & k>=1 )
            {
                state.taskx = new double[n, m];
                state.tasky = new double[n];
                state.w = new double[n];
                state.c = new double[k];
                for(i_=0; i_<=k-1;i_++)
                {
                    state.c[i_] = c[i_];
                }
                for(i=0; i<=n-1; i++)
                {
                    for(i_=0; i_<=m-1;i_++)
                    {
                        state.taskx[i,i_] = x[i,i_];
                    }
                    state.tasky[i] = y[i];
                    state.w[i] = 1;
                }
            }
            state.rstate.ia = new int[4+1];
            state.rstate.ra = new double[1+1];
            state.rstate.stage = -1;
        }
开发者ID:palefacer,项目名称:TelescopeOrientation,代码行数:50,代码来源:lsfit.cs


示例3: exp

        /*************************************************************************
        This function sets maximum step length

        INPUT PARAMETERS:
            State   -   structure which stores algorithm state between calls and
                        which is used for reverse communication. Must be
                        initialized with LSFitNonLinearCreate???()
            StpMax  -   maximum step length, >=0. Set StpMax to 0.0,  if you don't
                        want to limit step length.

        Use this subroutine when you optimize target function which contains exp()
        or  other  fast  growing  functions,  and optimization algorithm makes too
        large  steps  which  leads  to overflow. This function allows us to reject
        steps  that  are  too  large  (and  therefore  expose  us  to the possible
        overflow) without actually calculating function value at the x+stp*d.

        NOTE: non-zero StpMax leads to moderate  performance  degradation  because
        intermediate  step  of  preconditioned L-BFGS optimization is incompatible
        with limits on step size.

          -- ALGLIB --
             Copyright 02.04.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void lsfitnonlinearsetstpmax(ref lsfitstate state,
            double stpmax)
        {
            System.Diagnostics.Debug.Assert((double)(stpmax)>=(double)(0), "LSFitNonlinearSetStpMax: StpMax<0!");
            state.stpmax = stpmax;
        }
开发者ID:palefacer,项目名称:TelescopeOrientation,代码行数:29,代码来源:lsfit.cs


示例4: LSFitFit

        /*************************************************************************
        Nonlinear least squares fitting results.

        Called after return from LSFitFit().

        INPUT PARAMETERS:
            State   -   algorithm state

        OUTPUT PARAMETERS:
            Info    -   completion code:
                            * -7    gradient verification failed.
                                    See LSFitSetGradientCheck() for more information.
                            *  1    relative function improvement is no more than
                                    EpsF.
                            *  2    relative step is no more than EpsX.
                            *  4    gradient norm is no more than EpsG
                            *  5    MaxIts steps was taken
                            *  7    stopping conditions are too stringent,
                                    further improvement is impossible
            C       -   array[0..K-1], solution
            Rep     -   optimization report. On success following fields are set:
                        * R2                non-adjusted coefficient of determination
                                            (non-weighted)
                        * RMSError          rms error on the (X,Y).
                        * AvgError          average error on the (X,Y).
                        * AvgRelError       average relative error on the non-zero Y
                        * MaxError          maximum error
                                            NON-WEIGHTED ERRORS ARE CALCULATED
                        * WRMSError         weighted rms error on the (X,Y).
                        
        ERRORS IN PARAMETERS                
                        
        This  solver  also  calculates different kinds of errors in parameters and
        fills corresponding fields of report:
        * Rep.CovPar        covariance matrix for parameters, array[K,K].
        * Rep.ErrPar        errors in parameters, array[K],
                            errpar = sqrt(diag(CovPar))
        * Rep.ErrCurve      vector of fit errors - standard deviations of empirical
                            best-fit curve from "ideal" best-fit curve built  with
                            infinite number of samples, array[N].
                            errcurve = sqrt(diag(J*CovPar*J')),
                            where J is Jacobian matrix.
        * Rep.Noise         vector of per-point estimates of noise, array[N]

        IMPORTANT:  errors  in  parameters  are  calculated  without  taking  into
                    account boundary/linear constraints! Presence  of  constraints
                    changes distribution of errors, but there is no  easy  way  to
                    account for constraints when you calculate covariance matrix.
                    
        NOTE:       noise in the data is estimated as follows:
                    * for fitting without user-supplied  weights  all  points  are
                      assumed to have same level of noise, which is estimated from
                      the data
                    * for fitting with user-supplied weights we assume that  noise
                      level in I-th point is inversely proportional to Ith weight.
                      Coefficient of proportionality is estimated from the data.
                    
        NOTE:       we apply small amount of regularization when we invert squared
                    Jacobian and calculate covariance matrix. It  guarantees  that
                    algorithm won't divide by zero  during  inversion,  but  skews
                    error estimates a bit (fractional error is about 10^-9).
                    
                    However, we believe that this difference is insignificant  for
                    all practical purposes except for the situation when you  want
                    to compare ALGLIB results with "reference"  implementation  up
                    to the last significant digit.
                    
        NOTE:       covariance matrix is estimated using  correction  for  degrees
                    of freedom (covariances are divided by N-M instead of dividing
                    by N).

          -- ALGLIB --
             Copyright 17.08.2009 by Bochkanov Sergey
        *************************************************************************/
        public static void lsfitresults(lsfitstate state,
            ref int info,
            ref double[] c,
            lsfitreport rep)
        {
            int i = 0;
            int j = 0;
            int i_ = 0;

            info = 0;
            c = new double[0];

            clearreport(rep);
            info = state.repterminationtype;
            rep.varidx = state.repvaridx;
            if( info>0 )
            {
                c = new double[state.k];
                for(i_=0; i_<=state.k-1;i_++)
                {
                    c[i_] = state.c[i_];
                }
                rep.rmserror = state.reprmserror;
                rep.wrmserror = state.repwrmserror;
                rep.avgerror = state.repavgerror;
                rep.avgrelerror = state.repavgrelerror;
//.........这里部分代码省略.........
开发者ID:KBrus,项目名称:nton-rbm,代码行数:101,代码来源:interpolation.cs


示例5: LSFitNonlinearIteration

        /*************************************************************************
        Nonlinear least squares fitting results.

        Called after LSFitNonlinearIteration() returned False.

        INPUT PARAMETERS:
            State   -   algorithm state (used by LSFitNonlinearIteration).

        OUTPUT PARAMETERS:
            Info    -   completetion code:
                            * -1    incorrect parameters were specified
                            *  1    relative function improvement is no more than
                                    EpsF.
                            *  2    relative step is no more than EpsX.
                            *  4    gradient norm is no more than EpsG
                            *  5    MaxIts steps was taken
            C       -   array[0..K-1], solution
            Rep     -   optimization report. Following fields are set:
                        * Rep.TerminationType completetion code:
                        * RMSError          rms error on the (X,Y).
                        * AvgError          average error on the (X,Y).
                        * AvgRelError       average relative error on the non-zero Y
                        * MaxError          maximum error
                                            NON-WEIGHTED ERRORS ARE CALCULATED


          -- ALGLIB --
             Copyright 17.08.2009 by Bochkanov Sergey
        *************************************************************************/
        public static void lsfitnonlinearresults(ref lsfitstate state,
            ref int info,
            ref double[] c,
            ref lsfitreport rep)
        {
            int i_ = 0;

            info = state.repterminationtype;
            if( info>0 )
            {
                c = new double[state.k];
                for(i_=0; i_<=state.k-1;i_++)
                {
                    c[i_] = state.c[i_];
                }
                rep.rmserror = state.reprmserror;
                rep.avgerror = state.repavgerror;
                rep.avgrelerror = state.repavgrelerror;
                rep.maxerror = state.repmaxerror;
            }
        }
开发者ID:palefacer,项目名称:TelescopeOrientation,代码行数:50,代码来源:lsfit.cs


示例6: lsfitsetxrep

        /*************************************************************************
        This function turns on/off reporting.

        INPUT PARAMETERS:
            State   -   structure which stores algorithm state
            NeedXRep-   whether iteration reports are needed or not
            
        When reports are needed, State.C (current parameters) and State.F (current
        value of fitting function) are reported.


          -- ALGLIB --
             Copyright 15.08.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void lsfitsetxrep(lsfitstate state,
            bool needxrep)
        {
            state.xrep = needxrep;
        }
开发者ID:KBrus,项目名称:nton-rbm,代码行数:19,代码来源:interpolation.cs


示例7: default

        /*************************************************************************
        This function sets boundary constraints for underlying optimizer

        Boundary constraints are inactive by default (after initial creation).
        They are preserved until explicitly turned off with another SetBC() call.

        INPUT PARAMETERS:
            State   -   structure stores algorithm state
            BndL    -   lower bounds, array[K].
                        If some (all) variables are unbounded, you may specify
                        very small number or -INF (latter is recommended because
                        it will allow solver to use better algorithm).
            BndU    -   upper bounds, array[K].
                        If some (all) variables are unbounded, you may specify
                        very large number or +INF (latter is recommended because
                        it will allow solver to use better algorithm).

        NOTE 1: it is possible to specify BndL[i]=BndU[i]. In this case I-th
        variable will be "frozen" at X[i]=BndL[i]=BndU[i].

        NOTE 2: unlike other constrained optimization algorithms, this solver  has
        following useful properties:
        * bound constraints are always satisfied exactly
        * function is evaluated only INSIDE area specified by bound constraints

          -- ALGLIB --
             Copyright 14.01.2011 by Bochkanov Sergey
        *************************************************************************/
        public static void lsfitsetbc(lsfitstate state,
            double[] bndl,
            double[] bndu)
        {
            int i = 0;
            int k = 0;

            k = state.k;
            alglib.ap.assert(alglib.ap.len(bndl)>=k, "LSFitSetBC: Length(BndL)<K");
            alglib.ap.assert(alglib.ap.len(bndu)>=k, "LSFitSetBC: Length(BndU)<K");
            for(i=0; i<=k-1; i++)
            {
                alglib.ap.assert(math.isfinite(bndl[i]) || Double.IsNegativeInfinity(bndl[i]), "LSFitSetBC: BndL contains NAN or +INF");
                alglib.ap.assert(math.isfinite(bndu[i]) || Double.IsPositiveInfinity(bndu[i]), "LSFitSetBC: BndU contains NAN or -INF");
                if( math.isfinite(bndl[i]) && math.isfinite(bndu[i]) )
                {
                    alglib.ap.assert((double)(bndl[i])<=(double)(bndu[i]), "LSFitSetBC: BndL[i]>BndU[i]");
                }
                state.bndl[i] = bndl[i];
                state.bndu[i] = bndu[i];
            }
        }
开发者ID:KBrus,项目名称:nton-rbm,代码行数:50,代码来源:interpolation.cs


示例8: LSFitFit

    /*************************************************************************
    Nonlinear least squares fitting results.

    Called after return from LSFitFit().

    INPUT PARAMETERS:
        State   -   algorithm state

    OUTPUT PARAMETERS:
        Info    -   completetion code:
                        *  1    relative function improvement is no more than
                                EpsF.
                        *  2    relative step is no more than EpsX.
                        *  4    gradient norm is no more than EpsG
                        *  5    MaxIts steps was taken
                        *  7    stopping conditions are too stringent,
                                further improvement is impossible
        C       -   array[0..K-1], solution
        Rep     -   optimization report. Following fields are set:
                    * Rep.TerminationType completetion code:
                    * RMSError          rms error on the (X,Y).
                    * AvgError          average error on the (X,Y).
                    * AvgRelError       average relative error on the non-zero Y
                    * MaxError          maximum error
                                        NON-WEIGHTED ERRORS ARE CALCULATED


      -- ALGLIB --
         Copyright 17.08.2009 by Bochkanov Sergey
    *************************************************************************/
    public static void lsfitresults(lsfitstate state, out int info, out double[] c, out lsfitreport rep)
    {
        info = 0;
        c = new double[0];
        rep = new lsfitreport();
        lsfit.lsfitresults(state.innerobj, ref info, ref c, rep.innerobj);
        return;
    }
开发者ID:Ring-r,项目名称:opt,代码行数:38,代码来源:interpolation.cs


示例9: min

        /*************************************************************************
        Nonlinear least squares fitting using gradient/Hessian, without individial
        weights.

        Nonlinear task min(F(c)) is solved, where

            F(c) = ((f(c,x[0])-y[0]))^2 + ... + ((f(c,x[n-1])-y[n-1]))^2,

            * N is a number of points,
            * M is a dimension of a space points belong to,
            * K is a dimension of a space of parameters being fitted,
            * x is a set of N points, each of them is an M-dimensional vector,
            * c is a K-dimensional vector of parameters being fitted

        This subroutine uses f(c,x[i]), its gradient and its Hessian.

        INPUT PARAMETERS:
            X       -   array[0..N-1,0..M-1], points (one row = one point)
            Y       -   array[0..N-1], function values.
            C       -   array[0..K-1], initial approximation to the solution,
            N       -   number of points, N>1
            M       -   dimension of space
            K       -   number of parameters being fitted

        OUTPUT PARAMETERS:
            State   -   structure which stores algorithm state


          -- ALGLIB --
             Copyright 17.08.2009 by Bochkanov Sergey
        *************************************************************************/
        public static void lsfitcreatefgh(double[,] x,
            double[] y,
            double[] c,
            int n,
            int m,
            int k,
            lsfitstate state)
        {
            int i = 0;
            int i_ = 0;

            ap.assert(n>=1, "LSFitCreateFGH: N<1!");
            ap.assert(m>=1, "LSFitCreateFGH: M<1!");
            ap.assert(k>=1, "LSFitCreateFGH: K<1!");
            ap.assert(ap.len(c)>=k, "LSFitCreateFGH: length(C)<K!");
            ap.assert(apserv.isfinitevector(c, k), "LSFitCreateFGH: C contains infinite or NaN values!");
            ap.assert(ap.len(y)>=n, "LSFitCreateFGH: length(Y)<N!");
            ap.assert(apserv.isfinitevector(y, n), "LSFitCreateFGH: Y contains infinite or NaN values!");
            ap.assert(ap.rows(x)>=n, "LSFitCreateFGH: rows(X)<N!");
            ap.assert(ap.cols(x)>=m, "LSFitCreateFGH: cols(X)<M!");
            ap.assert(apserv.apservisfinitematrix(x, n, m), "LSFitCreateFGH: X contains infinite or NaN values!");
            state.n = n;
            state.m = m;
            state.k = k;
            lsfitsetcond(state, 0.0, 0.0, 0);
            lsfitsetstpmax(state, 0.0);
            lsfitsetxrep(state, false);
            state.taskx = new double[n, m];
            state.tasky = new double[n];
            state.w = new double[n];
            state.c = new double[k];
            state.h = new double[k, k];
            state.x = new double[m];
            state.g = new double[k];
            for(i_=0; i_<=k-1;i_++)
            {
                state.c[i_] = c[i_];
            }
            for(i=0; i<=n-1; i++)
            {
                for(i_=0; i_<=m-1;i_++)
                {
                    state.taskx[i,i_] = x[i,i_];
                }
                state.tasky[i] = y[i];
                state.w[i] = 1;
            }
            minlm.minlmcreatefgh(k, state.c, state.optstate);
            lsfitclearrequestfields(state);
            state.rstate.ia = new int[4+1];
            state.rstate.ra = new double[1+1];
            state.rstate.stage = -1;
        }
开发者ID:Ring-r,项目名称:opt,代码行数:84,代码来源:interpolation.cs


示例10: lsfititeration

    /*************************************************************************
    This function provides reverse communication interface
    Reverse communication interface is not documented or recommended to use.
    See below for functions which provide better documented API
    *************************************************************************/
    public static bool lsfititeration(lsfitstate state)
    {

        bool result = lsfit.lsfititeration(state.innerobj);
        return result;
    }
开发者ID:Ring-r,项目名称:opt,代码行数:11,代码来源:interpolation.cs


示例11: lsfitfit

 public static void lsfitfit(lsfitstate state, ndimensional_pfunc func, ndimensional_pgrad grad, ndimensional_phess hess, ndimensional_rep rep, object obj)
 {
     if( func==null )
         throw new alglibexception("ALGLIB: error in 'lsfitfit()' (func is null)");
     if( grad==null )
         throw new alglibexception("ALGLIB: error in 'lsfitfit()' (grad is null)");
     if( hess==null )
         throw new alglibexception("ALGLIB: error in 'lsfitfit()' (hess is null)");
     while( alglib.lsfititeration(state) )
     {
         if( state.needf )
         {
             func(state.c, state.x, ref state.innerobj.f, obj);
             continue;
         }
         if( state.needfg )
         {
             grad(state.c, state.x, ref state.innerobj.f, state.innerobj.g, obj);
             continue;
         }
         if( state.needfgh )
         {
             hess(state.c, state.x, ref state.innerobj.f, state.innerobj.g, state.innerobj.h, obj);
             continue;
         }
         if( state.innerobj.xupdated )
         {
             if( rep!=null )
                 rep(state.innerobj.x, state.innerobj.f, obj);
             continue;
         }
         throw new alglibexception("ALGLIB: error in 'lsfitfit' (some derivatives were not provided?)");
     }
 }
开发者ID:Ring-r,项目名称:opt,代码行数:34,代码来源:interpolation.cs


示例12: lsfitsetxrep

    /*************************************************************************
    This function turns on/off reporting.

    INPUT PARAMETERS:
        State   -   structure which stores algorithm state
        NeedXRep-   whether iteration reports are needed or not

    When reports are needed, State.C (current parameters) and State.F (current
    value of fitting function) are reported.


      -- ALGLIB --
         Copyright 15.08.2010 by Bochkanov Sergey
    *************************************************************************/
    public static void lsfitsetxrep(lsfitstate state, bool needxrep)
    {

        lsfit.lsfitsetxrep(state.innerobj, needxrep);
        return;
    }
开发者ID:Ring-r,项目名称:opt,代码行数:20,代码来源:interpolation.cs


示例13: exp

    /*************************************************************************
    This function sets maximum step length

    INPUT PARAMETERS:
        State   -   structure which stores algorithm state
        StpMax  -   maximum step length, >=0. Set StpMax to 0.0,  if you don't
                    want to limit step length.

    Use this subroutine when you optimize target function which contains exp()
    or  other  fast  growing  functions,  and optimization algorithm makes too
    large  steps  which  leads  to overflow. This function allows us to reject
    steps  that  are  too  large  (and  therefore  expose  us  to the possible
    overflow) without actually calculating function value at the x+stp*d.

    NOTE: non-zero StpMax leads to moderate  performance  degradation  because
    intermediate  step  of  preconditioned L-BFGS optimization is incompatible
    with limits on step size.

      -- ALGLIB --
         Copyright 02.04.2010 by Bochkanov Sergey
    *************************************************************************/
    public static void lsfitsetstpmax(lsfitstate state, double stpmax)
    {

        lsfit.lsfitsetstpmax(state.innerobj, stpmax);
        return;
    }
开发者ID:Ring-r,项目名称:opt,代码行数:27,代码来源:interpolation.cs


示例14: selection

    /*************************************************************************
    Stopping conditions for nonlinear least squares fitting.

    INPUT PARAMETERS:
        State   -   structure which stores algorithm state
        EpsF    -   stopping criterion. Algorithm stops if
                    |F(k+1)-F(k)| <= EpsF*max{|F(k)|, |F(k+1)|, 1}
        EpsX    -   stopping criterion. Algorithm stops if
                    |X(k+1)-X(k)| <= EpsX*(1+|X(k)|)
        MaxIts  -   stopping criterion. Algorithm stops after MaxIts iterations.
                    MaxIts=0 means no stopping criterion.

    NOTE

    Passing EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to automatic
    stopping criterion selection (according to the scheme used by MINLM unit).


      -- ALGLIB --
         Copyright 17.08.2009 by Bochkanov Sergey
    *************************************************************************/
    public static void lsfitsetcond(lsfitstate state, double epsf, double epsx, int maxits)
    {

        lsfit.lsfitsetcond(state.innerobj, epsf, epsx, maxits);
        return;
    }
开发者ID:Ring-r,项目名称:opt,代码行数:27,代码来源:interpolation.cs


示例15: counted

        /*************************************************************************
        Stopping conditions for nonlinear least squares fitting.

        INPUT PARAMETERS:
            State   -   structure which stores algorithm state
            EpsF    -   stopping criterion. Algorithm stops if
                        |F(k+1)-F(k)| <= EpsF*max{|F(k)|, |F(k+1)|, 1}
            EpsX    -   >=0
                        The subroutine finishes its work if  on  k+1-th  iteration
                        the condition |v|<=EpsX is fulfilled, where:
                        * |.| means Euclidian norm
                        * v - scaled step vector, v[i]=dx[i]/s[i]
                        * dx - ste pvector, dx=X(k+1)-X(k)
                        * s - scaling coefficients set by LSFitSetScale()
            MaxIts  -   maximum number of iterations. If MaxIts=0, the  number  of
                        iterations   is    unlimited.   Only   Levenberg-Marquardt
                        iterations  are  counted  (L-BFGS/CG  iterations  are  NOT
                        counted because their cost is very low compared to that of
                        LM).

        NOTE

        Passing EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to automatic
        stopping criterion selection (according to the scheme used by MINLM unit).


          -- ALGLIB --
             Copyright 17.08.2009 by Bochkanov Sergey
        *************************************************************************/
        public static void lsfitsetcond(lsfitstate state,
            double epsf,
            double epsx,
            int maxits)
        {
            alglib.ap.assert(math.isfinite(epsf), "LSFitSetCond: EpsF is not finite!");
            alglib.ap.assert((double)(epsf)>=(double)(0), "LSFitSetCond: negative EpsF!");
            alglib.ap.assert(math.isfinite(epsx), "LSFitSetCond: EpsX is not finite!");
            alglib.ap.assert((double)(epsx)>=(double)(0), "LSFitSetCond: negative EpsX!");
            alglib.ap.assert(maxits>=0, "LSFitSetCond: negative MaxIts!");
            state.epsf = epsf;
            state.epsx = epsx;
            state.maxits = maxits;
        }
开发者ID:KBrus,项目名称:nton-rbm,代码行数:43,代码来源:interpolation.cs


示例16: min

            /*************************************************************************
            Weighted nonlinear least squares fitting using gradient only.

            Nonlinear task min(F(c)) is solved, where

                F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^2,
            
                * N is a number of points,
                * M is a dimension of a space points belong to,
                * K is a dimension of a space of parameters being fitted,
                * w is an N-dimensional vector of weight coefficients,
                * x is a set of N points, each of them is an M-dimensional vector,
                * c is a K-dimensional vector of parameters being fitted
            
            This subroutine uses only f(c,x[i]) and its gradient.
            
            INPUT PARAMETERS:
                X       -   array[0..N-1,0..M-1], points (one row = one point)
                Y       -   array[0..N-1], function values.
                W       -   weights, array[0..N-1]
                C       -   array[0..K-1], initial approximation to the solution,
                N       -   number of points, N>1
                M       -   dimension of space
                K       -   number of parameters being fitted
                CheapFG -   boolean flag, which is:
                            * True  if both function and gradient calculation complexity
                                    are less than O(M^2).  An improved  algorithm  can
                                    be  used  which corresponds  to  FGJ  scheme  from
                                    MINLM unit.
                            * False otherwise.
                                    Standard Jacibian-bases  Levenberg-Marquardt  algo
                                    will be used (FJ scheme).

            OUTPUT PARAMETERS:
                State   -   structure which stores algorithm state

            See also:
                LSFitResults
                LSFitCreateFG (fitting without weights)
                LSFitCreateWFGH (fitting using Hessian)
                LSFitCreateFGH (fitting using Hessian, without weights)

              -- ALGLIB --
                 Copyright 17.08.2009 by Bochkanov Sergey
            *************************************************************************/
            public static void lsfitcreatewfg(double[,] x,
                double[] y,
                double[] w,
                double[] c,
                int n,
                int m,
                int k,
                bool cheapfg,
                lsfitstate state) {
                int i = 0;
                int i_ = 0;

                ap.assert(n >= 1, "LSFitCreateWFG: N<1!");
                ap.assert(m >= 1, "LSFitCreateWFG: M<1!");
                ap.assert(k >= 1, "LSFitCreateWFG: K<1!");
                ap.assert(ap.len(c) >= k, "LSFitCreateWFG: length(C)<K!");
                ap.assert(apserv.isfinitevector(c, k), "LSFitCreateWFG: C contains infinite or NaN values!");
                ap.assert(ap.len(y) >= n, "LSFitCreateWFG: length(Y)<N!");
                ap.assert(apserv.isfinitevector(y, n), "LSFitCreateWFG: Y contains infinite or NaN values!");
                ap.assert(ap.len(w) >= n, "LSFitCreateWFG: length(W)<N!");
                ap.assert(apserv.isfinitevector(w, n), "LSFitCreateWFG: W contains infinite or NaN values!");
                ap.assert(ap.rows(x) >= n, "LSFitCreateWFG: rows(X)<N!");
                ap.assert(ap.cols(x) >= m, "LSFitCreateWFG: cols(X)<M!");
                ap.assert(apserv.apservisfinitematrix(x, n, m), "LSFitCreateWFG: X contains infinite or NaN values!");
                state.npoints = n;
                state.nweights = n;
                state.wkind = 1;
                state.m = m;
                state.k = k;
                lsfitsetcond(state, 0.0, 0.0, 0);
                lsfitsetstpmax(state, 0.0);
                lsfitsetxrep(state, false);
                state.taskx = new double[n, m];
                state.tasky = new double[n];
                state.w = new double[n];
                state.c = new double[k];
                state.x = new double[m];
                state.g = new double[k];
                for(i_ = 0; i_ <= k - 1; i_++) {
                    state.c[i_] = c[i_];
                }
                for(i_ = 0; i_ <= n - 1; i_++) {
                    state.w[i_] = w[i_];
                }
                for(i = 0; i <= n - 1; i++) {
                    for(i_ = 0; i_ <= m - 1; i_++) {
                        state.taskx[i, i_] = x[i, i_];
                    }
                    state.tasky[i] = y[i];
                }
                state.s = new double[k];
                state.bndl = new double[k];
                state.bndu = new double[k];
                for(i = 0; i <= k - 1; i++) {
                    state.s[i] = 1.0;
//.........这里部分代码省略.........
开发者ID:tpb3d,项目名称:TPB3D,代码行数:101,代码来源:interpolation.cs


示例17: exp

        /*************************************************************************
        This function sets maximum step length

        INPUT PARAMETERS:
            State   -   structure which stores algorithm state
            StpMax  -   maximum step length, >=0. Set StpMax to 0.0,  if you don't
                        want to limit step length.

        Use this subroutine when you optimize target function which contains exp()
        or  other  fast  growing  functions,  and optimization algorithm makes too
        large  steps  which  leads  to overflow. This function allows us to reject
        steps  that  are  too  large  (and  therefore  expose  us  to the possible
        overflow) without actually calculating function value at the x+stp*d.

        NOTE: non-zero StpMax leads to moderate  performance  degradation  because
        intermediate  step  of  preconditioned L-BFGS optimization is incompatible
        with limits on step size.

          -- ALGLIB --
             Copyright 02.04.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void lsfitsetstpmax(lsfitstate state,
            double stpmax)
        {
            alglib.ap.assert((double)(stpmax)>=(double)(0), "LSFitSetStpMax: StpMax<0!");
            state.stpmax = stpmax;
        }
开发者ID:KBrus,项目名称:nton-rbm,代码行数:27,代码来源:interpolation.cs


示例18: f

            /*************************************************************************
            NOTES:

            1. this algorithm is somewhat unusual because it works with  parameterized
               function f(C,X), where X is a function argument (we  have  many  points
               which are characterized by different  argument  values),  and  C  is  a
               parameter to fit.

               For example, if we want to do linear fit by f(c0,c1,x) = c0*x+c1,  then
               x will be argument, and {c0,c1} will be parameters.
           
               It is important to understand that this algorithm finds minimum in  the
               space of function PARAMETERS (not arguments), so it  needs  derivatives
               of f() with respect to C, not X.
           
               In the example above it will need f=c0*x+c1 and {df/dc0,df/dc1} = {x,1}
               instead of {df/dx} = {c0}.

            2. Callback functions accept C as the first parameter, and X as the second

            3. If  state  was  created  with  LSFitCreateFG(),  algorithm  needs  just
               function   and   its   gradient,   but   if   state   was  created with
               LSFitCreateFGH(), algorithm will need function, gradient and Hessian.
           
               According  to  the  said  above,  there  ase  several  versions of this
               function, which accept different sets of callbacks.
           
               This flexibility opens way to subtle errors - you may create state with
               LSFitCreateFGH() (optimization using Hessian), but call function  which
               does not accept Hessian. So when algorithm will request Hessian,  there
               will be no callback to call. In this case exception will be thrown.
           
               Be careful to avoid such errors because there is no way to find them at
               compile time - you can see them at runtime only.

              -- ALGLIB --
                 Copyright 17.08.2009 by Bochkanov Sergey
            *************************************************************************/
            public static bool lsfititeration(lsfitstate state) {
                bool result = new bool();
                int n = 0;
                int m = 0;
                int k = 0;
                int i = 0;
                int j = 0;
                double v = 0;
                double vv = 0;
                double relcnt = 0;
                int i_ = 0;


                //
                // Reverse communication preparations
                // I know it looks ugly, but it works the same way
                // anywhere from C++ to Python.
                //
                // This code initializes locals by:
                // * random values determined during code
                //   generation - on first subroutine call
                // * values from previous call - on subsequent calls
                //
                if(state.rstate.stage >= 0) {
                    n = state.rstate.ia[0];
                    m = state.rstate.ia[1];
                    k = state.rstate.ia[2];
                    i = state.rstate.ia[3];
                    j = state.rstate.ia[4];
                    v = state.rstate.ra[0];
                    vv = state.rstate.ra[1];
                    relcnt = state.rstate.ra[2];
                } else {
                    n = -983;
                    m = -989;
                    k = -834;
                    i = 900;
                    j = -287;
                    v = 364;
                    vv = 214;
                    relcnt = -338;
                }
                if(state.rstate.stage == 0) {
                    goto lbl_0;
                }
                if(state.rstate.stage == 1) {
                    goto lbl_1;
                }
                if(state.rstate.stage == 2) {
                    goto lbl_2;
                }
                if(state.rstate.stage == 3) {
                    goto lbl_3;
                }
                if(state.rstate.stage == 4) {
                    goto lbl_4;
                }
                if(state.rstate.stage == 5) {
                    goto lbl_5;
                }
                if(state.rstate.stage == 6) {
                    goto lbl_6;
//.........这里部分代码省略.........
开发者ID:tpb3d,项目名称:TPB3D,代码行数:101,代码来源:interpolation.cs


示例19: conditions

        /*************************************************************************
        This function sets scaling coefficients for underlying optimizer.

        ALGLIB optimizers use scaling matrices to test stopping  conditions  (step
        size and gradient are scaled before comparison with tolerances).  Scale of
        the I-th variable is a translation invariant measure of:
        a) "how large" the variable is
        b) how large the step should be to make significant changes in  

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# luaL_Buffer类代码示例发布时间:2022-05-24
下一篇:
C# lsfitreport类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap