コード例 #1
0
ファイル: smoothspline_impl.cpp プロジェクト: CueMol/cuemol2
  void spline1dfitpenalizedw(const real_1d_array &x,
			     const real_1d_array &y,
			     const real_1d_array &w,
			     const ae_int_t m,
			     const double rho,
			     ae_int_t &info,
			     spline1dinterpolant &s,
			     spline1dfitreport &rep)
  {
    alglib_impl::ae_state _alglib_env_state;    
    ae_int_t n;
    if( (x.length()!=y.length()) || (x.length()!=w.length()))
      throw ap_error("Error while calling 'spline1dfitpenalizedw': looks like one of arguments has wrong size");
    n = x.length();
    alglib_impl::ae_state_init(&_alglib_env_state);
    try {
        alglib_impl::spline1dfitpenalizedw(const_cast<alglib_impl::ae_vector*>(x.c_ptr()),
					   const_cast<alglib_impl::ae_vector*>(y.c_ptr()),
					   const_cast<alglib_impl::ae_vector*>(w.c_ptr()),
					   n, m, rho, &info,
					   const_cast<alglib_impl::spline1dinterpolant*>(s.c_ptr()),
					   const_cast<alglib_impl::spline1dfitreport*>(rep.c_ptr()),
					   &_alglib_env_state);

        alglib_impl::ae_state_clear(&_alglib_env_state);
        return;
    }
    catch(alglib_impl::ae_error_type) {
      throw ap_error(_alglib_env_state.error_msg);
    }
    catch(...) {
      throw;
    }
  }
コード例 #2
0
/*************************************************************************
Cash-Karp adaptive ODE solver.

This subroutine solves ODE  Y'=f(Y,x)  with  initial  conditions  Y(xs)=Ys
(here Y may be single variable or vector of N variables).

INPUT PARAMETERS:
    Y       -   initial conditions, array[0..N-1].
                contains values of Y[] at X[0]
    N       -   system size
    X       -   points at which Y should be tabulated, array[0..M-1]
                integrations starts at X[0], ends at X[M-1],  intermediate
                values at X[i] are returned too.
                SHOULD BE ORDERED BY ASCENDING OR BY DESCENDING!
    M       -   number of intermediate points + first point + last point:
                * M>2 means that you need both Y(X[M-1]) and M-2 values at
                  intermediate points
                * M=2 means that you want just to integrate from  X[0]  to
                  X[1] and don't interested in intermediate values.
                * M=1 means that you don't want to integrate :)
                  it is degenerate case, but it will be handled correctly.
                * M<1 means error
    Eps     -   tolerance (absolute/relative error on each  step  will  be
                less than Eps). When passing:
                * Eps>0, it means desired ABSOLUTE error
                * Eps<0, it means desired RELATIVE error.  Relative errors
                  are calculated with respect to maximum values of  Y seen
                  so far. Be careful to use this criterion  when  starting
                  from Y[] that are close to zero.
    H       -   initial  step  lenth,  it  will  be adjusted automatically
                after the first  step.  If  H=0,  step  will  be  selected
                automatically  (usualy  it  will  be  equal  to  0.001  of
                min(x[i]-x[j])).

OUTPUT PARAMETERS
    State   -   structure which stores algorithm state between  subsequent
                calls of OdeSolverIteration. Used for reverse communication.
                This structure should be passed  to the OdeSolverIteration
                subroutine.

SEE ALSO
    AutoGKSmoothW, AutoGKSingular, AutoGKIteration, AutoGKResults.


  -- ALGLIB --
     Copyright 01.09.2009 by Bochkanov Sergey
*************************************************************************/
void odesolverrkck(const real_1d_array &y, const real_1d_array &x, const double eps, const double h, odesolverstate &state)
{
    alglib_impl::ae_state _alglib_env_state;    
    ae_int_t n;
    ae_int_t m;

    n = y.length();
    m = x.length();
    alglib_impl::ae_state_init(&_alglib_env_state);
    try
    {
        alglib_impl::odesolverrkck(const_cast<alglib_impl::ae_vector*>(y.c_ptr()), n, const_cast<alglib_impl::ae_vector*>(x.c_ptr()), m, eps, h, const_cast<alglib_impl::odesolverstate*>(state.c_ptr()), &_alglib_env_state);

        alglib_impl::ae_state_clear(&_alglib_env_state);
        return;
    }
    catch(alglib_impl::ae_error_type)
    {
        throw ap_error(_alglib_env_state.error_msg);
    }
}
コード例 #3
0
void function1_grad(const real_1d_array &x, double &func, real_1d_array &grad, void *ptr){

  CasADi::SXFunction &fun = ((CasADi::SXFunction*)ptr)[0];
  CasADi::SXFunction &grad_fun = ((CasADi::SXFunction*)ptr)[1];

  VectorXd eig_x(x.length());
  for (int i = 0; i < eig_x.size(); ++i)
	eig_x[i] = x[i];
  
  static VectorXd f,g;
  CASADI::evaluate(fun, eig_x, f);
  CASADI::evaluate(grad_fun, eig_x, g);
  assert_eq(f.size(),1);
  assert_eq(g.size(), grad.length());
  assert_eq(g.norm(), g.norm());
  assert_eq(f[0], f[0]);

  func = f[0];
  for (int i = 0; i < g.size(); ++i)
    grad[i] = g[i];

  DEBUG_LOG("f = "<<func);
}
コード例 #4
0
CostCalculator_eigen::CostCalculator_eigen(const real_1d_array expectReturn,
                                           const real_2d_array &varMatrix,
                                           const real_1d_array &tradingCost,
                                           const real_1d_array &currentWeight) {
    assert(expectReturn.length() == varMatrix.rows());
    assert(varMatrix.rows() == varMatrix.cols());
    assert(tradingCost.length() == varMatrix.rows());
    assert(currentWeight.length() == varMatrix.rows());
    variableNumber_ = expectReturn.length();

    xReal_.resize(variableNumber_, 1);
    varMatrix_.resize(variableNumber_, variableNumber_);
    expectReturn_.resize(variableNumber_);
    tradingCost_.resize(variableNumber_);
    currentWeight_.resize(variableNumber_);

    for (int i = 0; i != variableNumber_; ++i) {
        expectReturn_(i) = expectReturn[i];
        tradingCost_(i) = tradingCost[i];
        currentWeight_(i) = currentWeight[i];
        for (int j = 0; j != variableNumber_; ++j)
            varMatrix_(i, j) = varMatrix[i][j];
    }
}