Esempio n. 1
0
StreamInfo Chroma2::init(const ParameterMap& params, const StreamInfo& in)
{
	m_cqtSize = in.size;
	m_cqtMinFreq = getDoubleParam("CQTMinFreq",params);
	m_cqtMaxFreq = getDoubleParam("CQTMaxFreq",params);
	m_cqtNbBins = getIntParam("CQTBinsPerOctave",params);
	m_nbBinsSemitone = getIntParam("CZBinsPerSemitone",params);
	m_nbBins = getIntParam("CZNbCQTBinsAggregatedToPCPBin",params);
	if (m_nbBins<0)
		m_nbBins = m_cqtNbBins / 24;
	m_tuning = getDoubleParam("CZTuning",params);

	m_deviation = m_cqtNbBins * log2(m_tuning / m_cqtMinFreq);
	double deviationRealPart = m_deviation - floor(m_deviation);
	m_cqtMinFreq = m_cqtMinFreq * pow(2.0, deviationRealPart / m_cqtNbBins);
	m_tuningBin = 1 + ((int) floor(m_deviation) - 1) % (m_cqtNbBins / 12);
	m_Q = 1 / (pow(2.0, 1.0 / (double) m_cqtNbBins) - 1);
	m_K = log2(m_cqtMaxFreq / m_cqtMinFreq);
	m_nbNote = (int) floor(m_cqtSize * 12.0 * m_nbBinsSemitone / m_cqtNbBins);
	m_notePartial.resize(m_nbNote);
	m_notePartialA = (int) floor((double) m_nbBins / 2.0);
	if (m_tuningBin > (m_cqtNbBins / 12 - m_notePartialA))
		m_tuningBin = m_tuningBin - m_cqtNbBins / 12;
	m_notePartialFactor = m_cqtNbBins / (12 * m_nbBinsSemitone);
	m_pcpSize = 12 * m_nbBinsSemitone;
	m_pcp.resize(m_pcpSize);

	int firstCode = (int) round(m_nbBinsSemitone * (69.0 + 12.0 * log2(m_cqtMinFreq
			* pow(2.0, ((double)m_tuningBin / m_cqtNbBins)) / m_tuning )));
	m_pcpShift = firstCode % m_pcpSize;

    return StreamInfo(in,m_pcpSize);
}
bool FrameTokenizer::init(const ParameterMap& params, const Ports<StreamInfo>& inp)
{
	assert(inp.size()==1);
	const StreamInfo& in = inp[0].data;

    if (in.size > 1)
    {
        cerr << "ERROR: input of FrameTokenizer should be of size 1" << endl;
        return false;
    }
    m_blockSize = getIntParam("blockSize", params);
    if (m_blockSize<=0) {
    	cerr << "ERROR: invalid blockSize parameter !" << endl;
    }
    m_stepSize = getIntParam("stepSize", params);
    if (m_stepSize<=0) {
    	cerr << "ERROR: invalid stepSize parameter !" << endl;
    	return false;
    }

    outStreamInfo().add(StreamInfo());
	StreamInfo& outInfo = outStreamInfo()[0].data;
	outInfo.sampleRate = in.sampleRate;
	outInfo.frameLength = m_blockSize * in.frameLength;
	outInfo.sampleStep = m_stepSize * in.sampleStep;
	outInfo.size = m_blockSize;

    return true;
}
Esempio n. 3
0
void parseCommand(const String& command)
{
	String returnString = "";
	String tail = "";
	String opcode = command.substring(0, command.indexOf(" "));
	tail = command.substring(command.indexOf(" "));
	tail.trim();

	//Debug:
	//serial.print("opcode = ");
	//serial.println(opcode);
	//serial.print("command = ");
	//serial.println(tail);

	if (opcode == "motors")
	{
		int power0 = 0, power1 = 0;
		if (getIntParam(power0, tail, -100, 100))
		{
			if (getIntParam(power1, tail, -100, 100))
			{
				//serial.print("command = "); //Debug.
				//serial.println(tail); //Debug.
				robot.motor0(power0);
				robot.motor1(power1);
				returnString = "["+ opcode + " " + power0 + " " + power1 + " " + millis() + "]";
				serial.println(returnString);
			}
		}
	}
	else if (opcode == "tone")
	{
		int freq = 0, duration = 0;
		if (getIntParam(freq, tail, 0, 10000))
		{
			if (getIntParam(duration, tail, 0, 3000))
			{
				tone(BuzzerPin, freq, duration);
				returnString = "["+ opcode + " " + freq + " " + duration + " " + millis() + "]";
				serial.println(returnString);
			}
		}
	}
	else if (opcode == "stop")
	{
		stopAll();
		returnString = "["+ opcode + " " + millis() + "]";
		serial.println(returnString);
	}
	else if (opcode == "")
	{
	}
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
  double sq_distance_from_initial_pt;
  int i;

  // overhead

  setCommandLineParameters(argc, argv);
  verbose = getFlagParam("-verbose");
  getIntParam("-seed", &seed);
  if (getFlagParam("-randomize")) randomize();
  else initializeRandomNumberGenerator();

  getVectorParam("-box", &box_x, &box_y, &box_z);
  getDoubleParam("-verlet_cutoff", &verlet_cutoff);
  getDoubleParam("-sea_level", &sea_level);
  getDoubleParam("-test_diameter", &test_diameter);
  getDoubleParam("-test_epsilon", &test_epsilon);
  getIntParam("-n", &number_of_samples);

  if (getFlagParam("-usage"))
  {
    printf("\nusage:\t-box [ 10 10 10 ]\n");
    printf("      \t-verlet_cutoff [ 64.0 ]\n");
    printf("      \t-sea_level [ 347.0 ]\n");
    printf("      \t-test_diameter [ 1.0 ]\n");
    printf("      \t-test_epsilon [ 1.0 ]\n");
    printf("      \t-n [ 100 ]\n\n");
    exit(0);
  }

  x_increment=box_x/(0.0 + number_of_samples);
  y_increment=box_y/(0.0 + number_of_samples);
  z_increment=box_z/(0.0 + number_of_samples);

  readConfiguration();
  for (i=0; i<number_of_molecules; i++)
  {
    while (x[i] >= box_x) x[i] -= box_x;
    while (y[i] >= box_y) y[i] -= box_y;
    while (z[i] >= box_z) z[i] -= box_z;
    while (x[i] < 0) x[i] += box_x;
    while (y[i] < 0) y[i] += box_y;
    while (z[i] < 0) z[i] += box_z;
  }
  
  for (test_x=0; test_x < box_x; test_x += x_increment)
    for (test_y=0; test_y < box_y; test_y += y_increment)
      for (test_z=0; test_z < box_z; test_z += z_increment)
        if (calculateEnergy(test_diameter) < sea_level) printf("%lf\t%lf\t%lf\t%lf\n", test_x, test_y, test_z, test_diameter);

  return 0;
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
  double sq_distance_from_initial_pt;
  double step_number;
  double dx, dy, dz;

  // overhead

  setCommandLineParameters(argc, argv);
  verbose = getFlagParam("-verbose");
  getIntParam("-seed", &seed);
  if (getFlagParam("-randomize")) randomize();
  else initializeRandomNumberGeneratorTo(seed);

  getVectorParam("-box", &box_x, &box_y, &box_z);
  getDoubleParam("-step_size_factor", &step_size_factor);
  getDoubleParam("-verlet_cutoff", &verlet_cutoff);
  getDoubleParam("-test_diameter", &test_diameter);
  getDoubleParam("-T", &T);
  getIntParam("-n", &number_of_samples);
  getIntParam("-n_steps", &n_steps);

  beta=1/(kB*T);

  readConfiguration();
  
  while (number_of_samples-- > 0)
  {
    generateTestPoint();
    successes=0;
    drift_x=drift_y=drift_z=0;
    
    for (step_number=0; step_number<n_steps; step_number++)
    {
      attemptRandomStep();
      dx=test_x - verlet_center_x;
      dy=test_y - verlet_center_y;
      dz=test_z - verlet_center_z;
      if (dx*dx + dy*dy + dz*dz > .01 * verlet_cutoff) makeVerletList();
    }
  
    dx = test_x - test_x0 + drift_x;
    dy = test_y - test_y0 + drift_y;
    dz = test_z - test_z0 + drift_z;

    printf("%lf\t%d\n", sqrt(dx*dx + dy*dy + dz*dz), successes);
  }

  return 0;
}
StreamInfo FFT::init(const ParameterMap& params, const StreamInfo& in)
{
    int len = getIntParam("FFTLength", params);
    if (len == 0)
        len = in.size;
    string w = getStringParam("FFTWindow", params);
    if (w != "None")
    {
        if (w == "Hanning")
            m_window = ehanningPeriodic(in.size);
        else if (w == "Hamming")
            m_window = ehammingPeriodic(in.size);
        else
        {
            cerr << "FFT: invalid Window parameter value " << w << " ignore it !" << endl;
        }
    }
    // init plan
    m_nfft = len;
#ifdef WITH_FFTW3
    double* inFFT = (double*) fftw_malloc(m_nfft*sizeof(double));
    complex<double>* outFFT = (complex<double>*) fftw_malloc((m_nfft/2+1)*sizeof(complex<double>));
    m_plan = fftw_plan_dft_r2c_1d(m_nfft,inFFT,(fftw_complex*)outFFT,FFTW_MEASURE);
    fftw_free(inFFT);
    fftw_free(outFFT);
#else
    VectorXd infft(m_nfft);
    VectorXcd outfft(m_nfft/2+1);
    m_plan.fwd(outfft.data(),infft.data(),m_nfft);
#endif

    return StreamInfo(in,len+2);
}
Esempio n. 7
0
/*
  Delete one or more column names. Quietly fail if firstNdx is less than zero
  or if firstNdx+len is greater than the number of columns.
*/
void OsiSolverInterface::deleteColNames (int tgtStart, int len)

{ int nameDiscipline ;
/*
  Determine how we're handling names. It's possible that the underlying solver
  has overridden getIntParam, but doesn't recognise OsiNameDiscipline. In that
  case, we want to default to auto names
*/
  bool recognisesOsiNames = getIntParam(OsiNameDiscipline,nameDiscipline) ;
  if (recognisesOsiNames == false)
  { nameDiscipline = 0 ; }
/*
  If the name discipline is auto, we're done.
*/
  if (nameDiscipline == 0)
  { return ; }
/*
  Trim the range to names that exist in the name vector. If we're doing lazy
  names, it's quite likely that we don't need to do any work.
*/
  int lastNdx = static_cast<int>(colNames_.size()) ;
  if (tgtStart < 0 || tgtStart >= lastNdx)
  { return ; }
  if (tgtStart+len > lastNdx)
  { len = lastNdx-tgtStart ; }
/*
  Erase the names.
*/
  OsiNameVec::iterator firstIter,lastIter ;
  firstIter = colNames_.begin()+tgtStart ;
  lastIter = firstIter+len ;
  colNames_.erase(firstIter,lastIter) ;

  return ; }
// Read arguments ==========================================================
void ProgClassifyCL2DCore::readParams()
{
    fnRoot = getParam("--root");
    fnODir = getParam("--dir");
    if (checkParam("--computeCore"))
    {
        thPCAZscore = getDoubleParam("--computeCore",0);
        NPCA = getIntParam("--computeCore",1);
        action=COMPUTE_CORE;
    }
    else if (checkParam("--computeStableCore"))
    {
        tolerance = getIntParam("--computeStableCore",0);
        action=COMPUTE_STABLE_CORE;
    }
}
Esempio n. 9
0
 void readParams()
 {
     if (checkParam("--extract"))
     {
         operation = HEADER_EXTRACT;
         produces_a_metadata = true;
     }
     else if (checkParam("--assign"))
         operation = HEADER_ASSIGN;
     else if (checkParam("--reset"))
         operation = HEADER_RESET;
     else if (checkParam("--sampling_rate"))
     {
         operation = HEADER_SAMPLINGRATE;
         sampling = getDoubleParam("--sampling_rate");
         allow_time_bar = false;
     }
     else if (checkParam("--tree"))
     {
         operation = HEADER_TREE;
         decompose_stacks = false;
     }
     else
     {
         operation = HEADER_PRINT;
         allow_time_bar = false;
         decompose_stacks = getIntParam("--print") == 1;
     }
     XmippMetadataProgram::readParams();
     round_shifts = checkParam("--round_shifts");
     if (operation != HEADER_EXTRACT && checkParam("-o"))
         REPORT_ERROR(ERR_PARAM_INCORRECT, "Argument -o is not valid for this operation");
     params.datamode = HEADER;
 }
Esempio n. 10
0
void ProgSSNR::readParams()
{
    radial_avg = checkParam("--radial_avg");
    fourierProjections = checkParam("--fourierProjections");
    if (!radial_avg)
    {
        fn_S = getParam("-S");
        fn_N = getParam("-N");
        fn_S_sel = getParam("--sel_signal");
        fn_N_sel = getParam("--sel_noise");
        generate_VSSNR = checkParam("--gen_VSSNR");
        if (generate_VSSNR)
        {
            fn_VSSNR = getParam("--VSSNR");
            fn_out_images = getParam("--oroot");
            sym=getParam("--sym");
            Nthreads=getIntParam("--thr");
        }
    }
    else
        fn_VSSNR = getParam("--VSSNR");

    ring_width = getDoubleParam("--ring");
    Tm = getDoubleParam("--sampling_rate");
    min_power = getDoubleParam("--min_power");
    fn_out = getParam("-o");
}
bool CSVWriter::init(const ParameterMap& params, const Ports<StreamInfo>& inp)
{
	assert(inp.size()==1);
	const StreamInfo& in = inp[0].data;

	string outputFile = getStringParam("File", params);
	m_precision = getIntParam("Precision",params);
	if (m_precision > (BUFSIZE-10)) {
		cerr << "WARNING: precision is too large ! use precision " << BUFSIZE - 10 << endl;
		m_precision = BUFSIZE - 10;
	}

	int res = preparedirs(outputFile.c_str());
	if (res!=0)
		return false;

	m_fout.open(outputFile.c_str(), ios_base::trunc);
	if (!m_fout.is_open() || m_fout.bad())
		return false;

	if (getStringParam("Metadata",params)=="True") {
		// write metadata at the beginnig of the file
		string paramStr = getStringParam("Attrs",params);
		map<string,string> params = decodeAttributeStr(paramStr);
		ostringstream oss;
		for (map<string,string>::const_iterator it=params.begin();it!=params.end();it++)
			oss << "% " << it->first << "=" << it->second << endl;
		m_fout.write(oss.str().c_str(),oss.str().size());
	}

	return true;
}
Esempio n. 12
0
  bool MelFilterBank::init(const ParameterMap& params, const Ports<StreamInfo>& inp)
  {
    assert(inp.size()==1);
    const StreamInfo& in = inp[0].data;

    // build mel filter bank
    m_size = in.size;
    int nbMelFilters = getIntParam("MelNbFilters",params);
    double sampleRate = in.sampleRate;
    double freqMin = getDoubleParam("MelMinFreq",params);
    double freqMax = getDoubleParam("MelMaxFreq",params);
    // set freqMax to Nyquist frequency if greater than nyquist frequency
    freqMax = min(freqMax, sampleRate/2.0);
    double melFreqMin = 1127 * log(1 + freqMin / 700);
    double melFreqMax = 1127 * log(1 + freqMax / 700);

    VectorXd melPeak(nbMelFilters+2);
    VectorXd freqs(nbMelFilters+2);

    melPeak = VectorXd::LinSpaced(nbMelFilters+2,melFreqMin,melFreqMax);
    freqs = ((melPeak / 1127).array().exp() - 1.0) * 700.0;
    VectorXd fftFreqs(m_size);
    fftFreqs = VectorXd::LinSpaced(m_size,0,m_size-1) * sampleRate / ((m_size-1)*2);
    for (int b=1;b<nbMelFilters+1;b++)
    {
      double norm = 2.0 / (freqs(b+1)-freqs(b-1));
      VectorXd fullfilt(m_size);
      //		fullfilt.setZero(m_size);
      //		firstIndex i;
      //		fullfilt += where((fftFreqs(i)>freqs(b-1)) && (fftFreqs(i)<=freqs(b)),norm*(fftFreqs(i)-freqs(b-1))/(freqs(b)-freqs(b-1)),0.0);
      //		fullfilt += where((fftFreqs(i)>freqs(b)) && (fftFreqs(i)<freqs(b+1)),norm*(freqs(b+1)-fftFreqs(i))/(freqs(b+1)-freqs(b)),0.0);
      double ffmin = freqs(b-1);
      double ffmiddle = freqs(b);
      double ffmax = freqs(b+1);
      for (int i=0;i<m_size;i++) {
        if ((fftFreqs(i)<ffmin) || (fftFreqs(i)>ffmax)) {
          fullfilt(i) = 0;
          continue;
        }
        if (fftFreqs(i)<ffmiddle)
          fullfilt(i) = norm*(fftFreqs(i)-ffmin)/(ffmiddle-ffmin);
        else
          fullfilt(i) = norm*(ffmax-fftFreqs(i))/(ffmax-ffmiddle);
      }

      int fStart=0;
      while (fullfilt(fStart)==0.0) fStart++;
      int fEnd=fStart+1;
      while ((fEnd<m_size) && (fullfilt(fEnd)!=0.0)) fEnd++;
      m_filterStart.push_back(fStart);
      m_filters.push_back(RowVectorXd());
      m_filters.back() = fullfilt.segment(fStart,fEnd-fStart);
    }

    outStreamInfo().add(StreamInfo(in, m_filters.size()));
    return true;
  }
void
OsiTestSolverInterface::solveFromHotStart()
{
   int itlimOrig = volprob_.parm.maxsgriters;
   getIntParam(OsiMaxNumIterationHotStart, volprob_.parm.maxsgriters);
   CoinDisjointCopyN(rowpriceHotStart_, getNumRows(), rowprice_);
   resolve();
   volprob_.parm.maxsgriters = itlimOrig;
}
bool AC2LPC::init(const ParameterMap& params, const Ports<StreamInfo>& inp)
{
	assert(inp.size()==1);
	const StreamInfo& in = inp[0].data;

	m_nbCoeffs = getIntParam("LPCNbCoeffs",params);
	outStreamInfo().add(StreamInfo(in,m_nbCoeffs));
    return true;
}
Esempio n. 15
0
/*
  Install the name information from a CoinLpIO object. Nearly identical to the
  previous routine, but we start from a different object.
*/
void OsiSolverInterface::setRowColNames (CoinLpIO &mod)

{ int nameDiscipline,m,n ;
/*
  Determine how we're handling names. It's possible that the underlying solver
  has overridden getIntParam, but doesn't recognise OsiNameDiscipline. In that
  case, we want to default to auto names
*/
  bool recognisesOsiNames = getIntParam(OsiNameDiscipline,nameDiscipline) ;
  if (recognisesOsiNames == false)
  { nameDiscipline = 0 ; }
/*
  Whatever happens, we're about to clean out the current name vectors. Decide
  on an appropriate size and call reallocRowColNames to adjust capacity.
*/
  if (nameDiscipline == 0)
  { m = 0 ;
    n = 0 ; }
  else
  { m = mod.getNumRows() ;
    n = mod.getNumCols() ; }
  reallocRowColNames(rowNames_,m,colNames_,n) ;
/*
  If name discipline is auto, we're done already. Otherwise, load 'em
  up. I have no idea whether we can guarantee valid names for all rows and
  columns, so we need to pay attention.
*/
  if (nameDiscipline != 0)
  { int maxRowNdx=-1, maxColNdx=-1 ;
    const char *const *names = mod.getRowNames() ;
    rowNames_.resize(m) ;
    for (int i = 0 ; i < m ; i++)
    { std::string nme = names[i] ;
      if (nme.length() == 0)
      { if (nameDiscipline == 2)
	{ nme = dfltRowColName('r',i) ; } }
      if (nme.length() > 0)
      { maxRowNdx = i ; }
      rowNames_[i] = nme ; }
    rowNames_.resize(maxRowNdx+1) ;
    objName_ = mod.getObjName() ;
    names = mod.getColNames() ;
    colNames_.resize(n) ;
    for (int j = 0 ; j < n ; j++)
    { std::string nme = names[j] ;
      if (nme.length() == 0)
      { if (nameDiscipline == 2)
	{ nme = dfltRowColName('c',j) ; } }
      if (nme.length() > 0)
      { maxColNdx = j ; }
      colNames_[j] = nme ; }
    colNames_.resize(maxColNdx+1) ; }
/*
  And we're done.
*/
  return ; }
void ProgSortByStatistics::readParams()
{
    fn = getParam("-i");
    fn_out = getParam("-o");
    addToInput = checkParam("--addToInput");
    fn_train = getParam("--train");
    cutoff = getDoubleParam("--zcut");
    per = getDoubleParam("--percent");
    targetXdim = getIntParam("--dim");
}
Esempio n. 17
0
 void readParams()
 {
     fnIn=getParam("-i");
     fnOroot=getParam("--oroot");
     _r1=getDoubleParam("--r1");
     _r2=getDoubleParam("--r2");
     _r3=getDoubleParam("--r3");
     _r4=getDoubleParam("--r4");
     if (checkParam("--x0"))
         x0=getDoubleParam("--x0");
     else
         x0=-1;
     if (checkParam("--y0"))
         y0=getDoubleParam("--y0");
     else
         y0=-1;
     _ncic=getIntParam("--harm");
     _indmul=getIntParam("--opt");
 }
Esempio n. 18
0
int main(int argc, char *argv[])
{
  instream = stdin;

  setCommandLineParameters(argc, argv);
  getVectorParam("-box", &box_x, &box_y, &box_z);
  verbose = getFlagParam("-verbose");
  if (getFlagParam("-randomize")) randomize();
  else initializeRandomNumberGenerator();

  getDoubleParam("-c_convergence_ratio", &c_convergence_ratio);
  getDoubleParam("-d_step_size", &d_step_size);
  getIntParam("-n", &number_of_samples);
  getIntParam("-n_trials", &n_trials);
  volume_sampling = getFlagParam("-volume_sampling");

  readConfiguration();
  sampleCavities();
  return 0;
}
Esempio n. 19
0
// Read arguments ==========================================================
void ProgVolumePCA::readParams()
{
    fnVols = getParam("-i");
    fnVolsOut = getParam("-o");
    NPCA = getIntParam("--Npca");
    fnBasis = getParam("--saveBasis");
    fnAvgVol = getParam("--avgVolume");
    fnOutStack = getParam("--opca");
    if (checkParam("--generatePCAVolumes"))
        getListParam("--generatePCAVolumes",listOfPercentiles);
    if (checkParam("--mask"))
        mask.readParams(this);
}
Esempio n. 20
0
// Read arguments ==========================================================
void ProgXrayImport::readParams()
{

    if (checkParam("--mistral"))
    {
        fnInput = getParam("--mistral");
        fnFlat = "NXtomo/instrument/bright_field/data@" + fnInput;
        dSource = MISTRAL;
    }
    else if (checkParam("--bessy"))
    {
        fnInput = getParam("--bessy", 0);
        tIni = getIntParam("--bessy", 1);
        tEnd = getIntParam("--bessy", 2);
        fIni = getIntParam("--bessy", 3);
        fEnd = getIntParam("--bessy", 4);
        fnFlat = fnInput;
        dSource = BESSY;
    }
    else
    {
        fnInput = getParam("--input");
        dSource = GENERIC;
    }
    // If --flat is passed it forces the use of this flatfield
    if (checkParam("--flat"))
    {
        fnFlat = getParam("--flat");
        extFlat = true;
    }

    fnRoot    = getParam("--oroot");
    cropSizeX  = getIntParam("--crop");

    if ( STR_EQUAL(getParam("--crop", 1), "sizeX") )
        cropSizeY = cropSizeX;
    else
        cropSizeY = getIntParam("--crop",1);


    thrNum    = getIntParam("--thr");

    String tempString = getParam("--bad_pixels");
    if (tempString == "factor")
        BPFactor = getDoubleParam("--bad_pixels", 1);
    else if (tempString == "mask")
        fnBPMask  = getParam("--bad_pixels",1);
    else
        BPFactor = -1;

    selfAttFix   = checkParam("--correct");
    logFix   = (selfAttFix)? true : checkParam("--log");
}
 void readParams()
 {
     fnIn = getParam("-i");
     fnOut = getParam("-o");
     type = getParam("-o",1);
     if (type=="chimera")
     {
         R=getDoubleParam("-o",2);
         rmax=getDoubleParam("-o",3);
         shift_center=getIntParam("-o",4);
     }
     else if (type=="ps")
     {
         R=getDoubleParam("-o",2);
         rmax=getDoubleParam("-o",3);
         rot_view=getDoubleParam("-o",4);
         tilt_view=getDoubleParam("-o",5);
         solid_sphere=getIntParam("-o",6);
     }
     else if (type=="histogram")
         steps = getIntParam("-o",2);
     up_down_correction = checkParam("--up_down_correction");
 }
Esempio n. 22
0
/**
  This routine sets the objective cutoff value used for fathoming and
  determining monotonic variables.

  If the fathoming discipline is strict, a small tolerance is added to the
  new cutoff. This avoids problems due to roundoff when the target value
  is exact. The common example would be an IP with only integer variables in
  the objective. If the target is set to the exact value z of the optimum,
  it's possible to end up fathoming an ancestor of the solution because the
  solver returns z+epsilon.

  Determining if strict fathoming is needed is best done by analysis.
  In sbb, that's analyseObjective. The default is false.

  In sbb we always minimize so add epsilon
*/
void DcModel::setCutoff (double value)
{
    double tol = 0;
    int fathomStrict = getIntParam(DcFathomDiscipline);
    double direction = solver_->getObjSense();
    if (fathomStrict == 1) {
	solver_->getDblParam(OsiDualTolerance, tol);
	tol = tol * (1 + fabs(value));
	value += tol;
    }

    // Solvers know about direction
    solver_->setDblParam(OsiDualObjectiveLimit, value * direction);
}
Esempio n. 23
0
bool AdvancedFrameTokenizer::init(const YAAFE::ParameterMap& params, const YAAFE::Ports<YAAFE::StreamInfo>& inp)
{
	assert(inp.size()==1);
	const StreamInfo& in = inp[0].data;

    if (in.size > 1)
    {
        cerr << "ERROR: input of AdvancedFrameTokenizer should be of size 1" << endl;
        return false;
    }

	m_outSampleRate = getDoubleParam("outSampleRate",params);
	m_blockSize = getIntParam("blockSize",params);
	m_outStepSize = getIntParam("outStepSize",params);

	StreamInfo out;
	out.frameLength = (int) floor(in.frameLength*m_blockSize*m_outSampleRate/in.sampleRate + 0.5);
	out.sampleRate = m_outSampleRate;
	out.sampleStep = m_outStepSize;
	out.size = m_blockSize;
	outStreamInfo().add(out);

	return true;
}
Esempio n. 24
0
  bool Cepstrum::init(const ParameterMap& params, const Ports<StreamInfo>& inp)
  {
    assert(inp.size()==1);
    const StreamInfo& in = inp[0].data;

    m_ignoreFirst = getIntParam("CepsIgnoreFirstCoeff",params);
    m_nbCoeffs = getIntParam("CepsNbCoeffs",params);
    if (m_nbCoeffs+m_ignoreFirst>in.size)
    {
      cerr << "Warning: cannot compute " << m_nbCoeffs << " for input of size " << in.size << endl;
      m_nbCoeffs = in.size - m_ignoreFirst;
      cerr << "compute only " << m_nbCoeffs << " coefficients" << endl;
    }

    m_dctPlan.resize(in.size,in.size);
    for (int j=0;j<in.size;j++)
      m_dctPlan(0,j) = 1.0 / sqrt((double)in.size);
    for (int i=1;i<in.size;i++)
      for (int j=0;j<in.size;j++)
        m_dctPlan(i,j) = sqrt(2.0 / in.size) * cos(PI * (j + 0.5) * i / in.size);

    outStreamInfo().add(StreamInfo(in, m_nbCoeffs));
    return true;
  }
Esempio n. 25
0
/*
  Return a row name, according to the current name discipline, truncated if
  necessary. If the row index is out of range, the name becomes an error
  message. By definition, ndx = getNumRows() (i.e., one greater than the
  largest valid row index) is the objective function.
*/
std::string OsiSolverInterface::getRowName (int ndx, unsigned maxLen) const

{ int nameDiscipline ;
  std::string name ;
/*
  Check for valid row index.
*/
  int m = getNumRows() ;
  if (ndx < 0 || ndx > m)
  { name = invRowColName('r',ndx) ;
    return (name) ; }
/*
  The objective is kept separately, so we don't always have an entry at
  index m in the names vector. If no name is set, return the default.
*/
  if (ndx == m)
  { return (getObjName(maxLen)) ; }
/*
  Determine how we're handling names. It's possible that the underlying solver
  has overridden getIntParam, but doesn't recognise OsiNameDiscipline. In that
  case, we want to default to auto names
*/
  bool recognisesOsiNames = getIntParam(OsiNameDiscipline,nameDiscipline) ;
  if (recognisesOsiNames == false)
  { nameDiscipline = 0 ; }
/*
  Find/generate the proper name, based on discipline.
*/
  switch (nameDiscipline)
  { case 0:
    { name = dfltRowColName('r',ndx) ;
      break ; }
    case 1:
    case 2:
    { name = "" ;
      if (static_cast<unsigned>(ndx) < rowNames_.size())
	name = rowNames_[ndx] ;
      if (name.length() == 0)
	name = dfltRowColName('r',ndx) ;
      break ; }
    default:
    { name = invRowColName('d',nameDiscipline) ;
      return (name) ; } }
/*
  Return the (possibly truncated) substring. The default for maxLen is npos
  (no truncation).
*/
  return (name.substr(0,maxLen)) ; }
Esempio n. 26
0
    void run()
    {
        size_t ms = getIntParam("--time") * 1000; // time in mili-seconds

        Timer t;
        t.tic();

        while (true)
        {
            // Just waste some cpu cycles
            for (int i = 0; i < 100000000; ++i);

            if (t.elapsed() >= ms)
                break;
        }
    }
bool Difference::init(const ParameterMap& params, const Ports<StreamInfo>& inp)
{
	assert(inp.size()==1);
	const StreamInfo& in = inp[0].data;

	m_nbCoeffs = getIntParam("DiffNbCoeffs",params);
	if (m_nbCoeffs==0)
		m_nbCoeffs = in.size - 1;
	if (m_nbCoeffs > in.size-1)
	{
		cerr << "Warning: cannot compute " << m_nbCoeffs << " difference coefficients from input of size " << in.size << endl;
		m_nbCoeffs = in.size - 1;
		cerr << "take only " << m_nbCoeffs << " coefficients" << endl;
	}

	outStreamInfo().add(StreamInfo(in,m_nbCoeffs));
    return true;
}
Esempio n. 28
0
/*
  Return a column name, according to the current name discipline, truncated if
  necessary. If the column index is out of range, the name becomes an error
  message.
*/
std::string OsiSolverInterface::getColName (int ndx, unsigned maxLen) const

{ int nameDiscipline ;
  std::string name ;
/*
  Check for valid column index.
*/
  if (ndx < 0 || ndx >= getNumCols())
  { name = invRowColName('c',ndx) ;
    return (name) ; }
/*
  Determine how we're handling names. It's possible that the underlying solver
  has overridden getIntParam, but doesn't recognise OsiNameDiscipline. In that
  case, we want to default to auto names
*/
  bool recognisesOsiNames = getIntParam(OsiNameDiscipline,nameDiscipline) ;
  if (recognisesOsiNames == false)
  { nameDiscipline = 0 ; }
/*
  Find/generate the proper name, based on discipline.
*/
  switch (nameDiscipline)
  { case 0:
    { name = dfltRowColName('c',ndx) ;
      break ; }
    case 1:
    case 2:
    { name = "" ;
      if (static_cast<unsigned>(ndx) < colNames_.size())
	name = colNames_[ndx] ;
      if (name.length() == 0)
	name = dfltRowColName('c',ndx) ;
      break ; }
    default:
    { name = invRowColName('d',nameDiscipline) ;
      return (name) ; } }
/*
  Return the (possibly truncated) substring. The default for maxLen is npos
  (no truncation).
*/
  return (name.substr(0,maxLen)) ; }
Esempio n. 29
0
/*
  Return the vector of row names. The vector we need depends on the name
  discipline:
    0: return a vector of length 0
    1: return rowNames_, no tweaking required
    2: Check that rowNames_ is complete. Generate a complete vector on
       the spot if we need it.
*/
const OsiSolverInterface::OsiNameVec &OsiSolverInterface::getRowNames ()

{ int nameDiscipline ;
/*
  Determine how we're handling names. It's possible that the underlying solver
  has overridden getIntParam, but doesn't recognise OsiNameDiscipline. In that
  case, we want to default to auto names
*/
  bool recognisesOsiNames = getIntParam(OsiNameDiscipline,nameDiscipline) ;
  if (recognisesOsiNames == false)
  { nameDiscipline = 0 ; }
/*
  Return the proper vector, as described at the head of the routine. If we
  need to generate a full vector, resize the existing vector and scan, filling
  in entries as required.
*/
  switch (nameDiscipline)
  { case 0:
    { return (zeroLengthNameVec) ; }
    case 1:
    { return (rowNames_) ; }
    case 2:
    { int m = getNumRows() ;
      if (rowNames_.size() < static_cast<unsigned>(m+1))
      { rowNames_.resize(m+1) ; }
      for (int i = 0 ; i < m ; i++)
      { if (rowNames_[i].length() == 0)
	{ rowNames_[i] = dfltRowColName('r',i) ; } }
      if (rowNames_[m].length() == 0)
      { rowNames_[m] = getObjName() ; }
      return (rowNames_) ; }
    default:
    { /* quietly fail */
      return (zeroLengthNameVec) ; } }
/*
  We should never reach here.
*/
  assert(false) ;

  return (zeroLengthNameVec) ; }
Esempio n. 30
0
/*
  Set a run of column names. Quietly fail if the specified indices are
  invalid.

  On the target side, [tgtStart, tgtStart+len-1] must be in the range
  [0,n-1], where n is the number of columns.  On the source side, srcStart
  must be zero or greater. If we run off the end of srcNames, we just
  generate default names.
*/
void OsiSolverInterface::setColNames (OsiNameVec &srcNames,
				      int srcStart, int len, int tgtStart)

{ int nameDiscipline ;
/*
  Determine how we're handling names. It's possible that the underlying solver
  has overridden getIntParam, but doesn't recognise OsiNameDiscipline. In that
  case, we want to default to auto names
*/
  bool recognisesOsiNames = getIntParam(OsiNameDiscipline,nameDiscipline) ;
  if (recognisesOsiNames == false)
  { nameDiscipline = 0 ; }
/*
  If the name discipline is auto, we're already done.
*/
  if (nameDiscipline == 0)
  { return ; }
/*
  A little self-protection. Check that we're within [0,m-1] on the target side,
  and that srcStart is zero or greater. Quietly fail if the indices don't fit.
*/
  int n = getNumCols() ;
  if (tgtStart < 0 || tgtStart+len > n)
  { return ; }
  if (srcStart < 0)
  { return ; }
  int srcLen = static_cast<int>(srcNames.size()) ;
/*
  Load 'em up.
*/
  int srcNdx = srcStart ;
  int tgtNdx = tgtStart ;
  for ( ; tgtNdx < tgtStart+len ; srcNdx++,tgtNdx++)
  { if (srcNdx < srcLen)
    { setColName(tgtNdx,srcNames[srcNdx]) ; }
    else
    { setColName(tgtNdx,dfltRowColName('c',tgtNdx)) ; } }

  return ; }