コード例 #1
0
double run_optim_full_calcA2(const genome &g,const std::vector<perChr>&pc,para&p){
  toOptim2 *to = new toOptim2(g,pc);
  double tsk[4];//tmparray used of saving stackpointers
  to->tsk = tsk;
  double pars[2]; pars[0]=myRand(0,1);pars[1]=myRand(0,1-pars[0]);
  //fix last pars
  double lbd[2]={0.000001,0.000001};
  double ubd[2]={0.999999,0.999999};
  int nbd[2]={2,2};
  double opt= -findmax_bfgs(2,pars,(void *)to, bfgs_call_full_calcA2,NULL,lbd, ubd,nbd, -1);
  p.k0=pars[0];
  p.k1=pars[1];
  p.k2=1-pars[0]-pars[1];
  p.a=calculateA(p.k0,p.k1,p.k2,PHI);
  return opt;
}
コード例 #2
0
//pars is k0,k1
double bfgs_call_full_calcA2(const double* pars,const void *dats){
  //fprintf(stderr,"[%s] %f %f %f\n",__FUNCTION__,pars[0],pars[1],pars[2]);
  toOptim2 *to = (toOptim2*)dats;
  double *inV = to->tsk;
  if(pars[0]+pars[1]>1)
    return DBL_MAX;

  inV[1]=pars[0];
  inV[2]=pars[1];
  inV[3]=1-inV[1]-inV[2];
  inV[0]= calculateA(inV[1],inV[2],inV[3],PHI);
  if(std::isnan(inV[0]))
    return DBL_MAX;
  double lik=-calcLike(inV,to->g,to->pc);
  //  fprintf(stderr,"lik=%f\n",lik);
  return lik;
}
コード例 #3
0
//case of CalcA==TRUE and k2==0. So only one free parameter
double bfgs_call_k2zero_calcA2(const double* pars,const void *dats){
  //fprintf(stderr,"[%s] %f %f %f\n",__FUNCTION__,pars[0],pars[1],pars[2]);
  toOptim2 *to = (toOptim2*)dats;

  double *inV = to->tsk;
  inV[1]=pars[0];
  inV[2]=1-inV[1];
  inV[3]=0;
  inV[0]= calculateA(inV[1],inV[2],inV[3],PHI);
  if(0&&(inV[0]<alim[0]||inV[0]>alim[1])){
    fprintf(stderr,"CalcA is outside bounds\n");
    return DBL_MAX;
  }
  double lik=-calcLike(inV,to->g,to->pc);
  //  fprintf(stderr,"lik=%f\n",lik);
  return lik;
}
コード例 #4
0
double run_optim_k2zero_calcA2(const genome &g,const std::vector<perChr>&pc,para&p){
  toOptim2 *to = new toOptim2(g,pc);
  double tsk[4];//tmparray used of saving stackpointers
  to->tsk = tsk;
 
  double pars[1]={myRand(0,1)};
  //  fprintf(stderr,"pars=%f\n",pars[0]);
  double lbd[1]={0.000001};
  double ubd[1]={0.999999};
  int nbd[1]={2};

  double opt= -findmax_bfgs(1,pars,(void *)to, bfgs_call_k2zero_calcA2,NULL,lbd, ubd,nbd, -1);
  p.k0=pars[0];
  p.k1=1-p.k0;
  p.k2=0;
  p.a=calculateA(p.k0,p.k1,p.k2,PHI);
  return opt;
}
コード例 #5
0
int OSM_Model400::calculate( )
{
    // Return value, assume successful
    int retVal = 0;

    // Vectors for internal component streams
    OSM_Vector x( nSize() );       // net crusher contents
    OSM_Vector y( nSize() );       // material classified for breakage
    OSM_Vector z( nSize() );       // breakage products of y

    // Calculate classification function: C[]
    calculateC( );

    // Create contents matrix if required
    if( contents.rows()!=nComp() || contents.columns()!=nSize() )
    {
        contents.dimension( nComp(), nSize() );
    }

    //-- Main Loop - loop over components in the feed -----------------------

    for( int comp=0; comp<nComp(); comp++ )
    {
        // Aliases to component vectors
        OSM_Vector& feedC = feed()[comp];
        OSM_Vector& prodC = product()[comp];
        OSM_Vector& x     = contents[comp];

        if( feedC.sum() > 0 )                   // Component present ?
        {
            calculateA( comp );                 // Make appearance function
            double misconvergence = 1e20;       // Force misconvergence
            long iteration = 0;                 // No iterations yet

            //-- Iteration Loop - until converged or maximum iterations -----

            while( misconvergence>tolerance && iteration<maxIteration )
            {
                // classify material for breakage y = C(x)
                y.loadProduct( C, x );

                // obtain breakage products z = A(y)
                makeDaughters( y, z );

                // obtain next iteration of recycle: x = feed + z
                misconvergence = x.loadSumWithCompare( feedC, z );

                // a successful iteration (hopefully)
                iteration++;
            }
            // product component by balance
            prodC.loadSubtraction( x, y );
        }
        else
        {
            // product component is 0
            prodC = 0;
        }
    }
    // indicate success
    return retVal;
}