コード例 #1
0
ファイル: SingleFlowFit.cpp プロジェクト: vswilliamson/TS
void single_flow_optimizer::FitKrateOneFlow(int fnum, float *evect, BeadParams *p, error_track *err_t, float *signal_corrected, float *signal_predicted, int NucID, float *lnucRise, int l_i_start,
                                            int flow_block_start, TimeCompression &time_c, EmphasisClass &emphasis_data,RegionTracker &my_regions)
{

  oneFlowFitKrate->SetWeightVector (evect);
  oneFlowFitKrate->SetLambdaStart (1E-20);
  oneFlowFitKrate->calc_trace.SetWellRegionParams (p,&my_regions.rp,fnum,
                                                   NucID, flow_block_start + fnum,
                                                   l_i_start,lnucRise);
  if (my_regions.rp.use_log_taub)
      oneFlowFitKrate->calc_trace.GuessLogTaub(signal_corrected,p,fnum,&my_regions.rp);   // replaces tauB in setWellRegionParams()
  oneFlowFitKrate->SetFvalCacheEnable (use_fval_cache);

  p->kmult[fnum] = local_min_param[KMULT];
  oneFlowFitKrate->InitParams();

  // float start_guess = p->Ampl[fnum];
  oneFlowFitKrate->calc_trace.ResetEval();

  int max_fit_iter = gauss_newton_fit ? NUMSINGLEFLOWITER_GAUSSNEWTON : NUMSINGLEFLOWITER_LEVMAR;
  oneFlowFitKrate->Fit (gauss_newton_fit, max_fit_iter, signal_corrected);
  // cur_hits = oneFlowFitKrate->calc_trace.GetEvalCount();
  p->Ampl[fnum] = oneFlowFitKrate->ReturnNthParam (AMPLITUDE);
  p->kmult[fnum] = oneFlowFitKrate->ReturnNthParam (KMULT);
  oneFlowFitKrate->ReturnPredicted(signal_predicted, use_fval_cache);
  //float  posf=0.0f, negf=0.0f;

  const float kmult_at_bottom = 0.01f;
  const float fit_error_too_high = 20.0f; //@TODO: this does not scale with signal!!!!
  const float final_minimum_kmult = 0.3f;
  const float extend_emphasis_amount = 2.0f;

  if(fabs( p->kmult[fnum]-local_min_param[KMULT])<kmult_at_bottom){
    float errx=sqrt (oneFlowFitKrate->GetMeanSquaredError (signal_corrected,use_fval_cache));
    if (errx>fit_error_too_high){ //if the fit error is  high it could be a slow incorporation

      //fprintf(stdout,"/n>mapx=%f,%f,%f\n",errx, p->kmult[fnum],p->Ampl[fnum]);
      //oneFlowFitKrate->InitParams();
      oneFlowFitKrate->calc_trace.ResetEval();
      local_max_param[KMULT] =local_min_param[KMULT];
      p->kmult[fnum] = final_minimum_kmult;
      local_min_param[KMULT]=final_minimum_kmult;
      oneFlowFitKrate->SetParamMin (&local_min_param[0]);
      oneFlowFitKrate->SetParamMax (&local_max_param[0]);
      emphasis_data.CustomEmphasis (evect, p->Ampl[fnum]+extend_emphasis_amount);
      oneFlowFitKrate->Fit (gauss_newton_fit, max_fit_iter, signal_corrected);
    }
  }
  cur_hits = oneFlowFitKrate->calc_trace.GetEvalCount();
  p->Ampl[fnum] = oneFlowFitKrate->ReturnNthParam (AMPLITUDE);
  p->kmult[fnum] = oneFlowFitKrate->ReturnNthParam (KMULT);
  p->tauB[fnum] = oneFlowFitKrate->calc_trace.tauB; // save tauB for output to trace.h5

  // store output for later
  oneFlowFitKrate->SetWeightVector (emphasis_data.EmphasisVectorByHomopolymer[emphasis_data.numEv-1]);
  err_t->mean_residual_error[fnum] = sqrt (oneFlowFitKrate->GetMeanSquaredError (signal_corrected,use_fval_cache)); // backwards compatibility
  oneFlowFitKrate->ReturnPredicted(signal_predicted, use_fval_cache);
}
コード例 #2
0
ファイル: SingleFlowFit.cpp プロジェクト: iqalab/TS
int single_flow_optimizer::FitStandardPath (int fnum, float *evect, BeadParams *p,  error_track *err_t, float *signal_corrected, float *signal_predicted, int NucID, float *lnucRise, int l_i_start,
                                            int flow_block_start, TimeCompression &time_c, EmphasisClass &emphasis_data,RegionTracker &my_regions)
{
  float A_start = p->Ampl[fnum];
  bool done = false;
  int retry_count = 0;
  int fitType = 0;
  SetLowerLimitAmplFit (pmin_param[0],pmin_param[1]);
  SetUpperLimitAmplFit (pmax_param[0],pmax_param[1]);

  while (!done && (retry_count <=retry_limit))
  {
    emphasis_data.CustomEmphasis (evect, p->Ampl[fnum]+AdjustEmphasisForKmult(p->kmult[fnum],retry_count));

    bool krate_fit = ( ( (p->Copies*p->Ampl[fnum]) > decision_threshold)); // this may not be the best way of deciding this
    krate_fit = krate_fit || var_kmult_only;
    fitType = krate_fit ? 1:0;

    //printf("single_flow_optimizer::FitStandardPath... krate_fit=%d\n",krate_fit);
    if (krate_fit)
    {
      FitKrateOneFlow (fnum,evect,p,err_t, signal_corrected,signal_predicted, NucID, lnucRise, l_i_start,flow_block_start,time_c,emphasis_data,my_regions);
    }
    else
    {
      //  if (use_projection_search_ampl_fit)
      //    FitProjection (fnum,evect,p, err_t, signal_corrected,NucID, lnucRise, l_i_start,my_flow,time_c,emphasis_data,my_regions);
      //  else
      FitThisOneFlow (fnum,evect,p, err_t, signal_corrected,signal_predicted, NucID, lnucRise, l_i_start,flow_block_start,time_c,emphasis_data,my_regions);
    }


    float amplitude_delta = A_start - p->Ampl[fnum];
    float kmult_above_bottom = (p->kmult[fnum]-local_min_param[KMULT]);

    const float amplitude_step_minimum = 0.1f;
    const float kmult_near_bottom = 0.1f;

    if ((fabs(amplitude_delta) > amplitude_step_minimum)||((fabs(kmult_above_bottom)<kmult_near_bottom)&&krate_fit))
      A_start = p->Ampl[fnum];
    else
      done = true;

    retry_count++;
  }
  return (fitType);
}