示例#1
0
  // ////////////////////////////////////////////////////////////////////
  bool NewQFF::
  forecast (stdair::SegmentCabin& ioSegmentCabin,
            const stdair::Date_T& iCurrentDate,
            const stdair::DTD_T& iCurrentDTD,
            const stdair::UnconstrainingMethod& iUnconstrainingMethod,
            const stdair::NbOfSegments_T& iNbOfDepartedSegments) {
    // Retrieve the snapshot table.
    const stdair::SegmentSnapshotTable& lSegmentSnapshotTable =
      ioSegmentCabin.getSegmentSnapshotTable();

    // Browse the list of fare families and execute "Q-forecasting" within
    // each fare family.
    const stdair::FareFamilyList_T& lFFList =
      stdair::BomManager::getList<stdair::FareFamily>(ioSegmentCabin);
    for (stdair::FareFamilyList_T::const_iterator itFF = lFFList.begin();
         itFF != lFFList.end(); ++itFF) {
      stdair::FareFamily* lFF_ptr = *itFF;
      assert (lFF_ptr != NULL);

      forecast (*lFF_ptr,
                iCurrentDate,
                iCurrentDTD,
                iUnconstrainingMethod,
                iNbOfDepartedSegments,
                lSegmentSnapshotTable);
    }

    // Dispatch the demand forecast to the policies.
    dispatchDemandForecastToPolicies (ioSegmentCabin);

    return true;
  }
示例#2
0
void etsforecast(double *x, int *m, int *trend, int *season, double *phi, int *h, double *f)

{
    int j;
    double l, b, s[24];

    if((*m > 24) & (*season > NONE))
        return;
    else if(*m < 1)
        *m = 1;

    // Copy initial state components
    l = x[0];
	b = 0.0;
    if(*trend > NONE)
        b = x[1];
    if(*season > NONE)
    {
        for(j=0; j<(*m); j++)
            s[j] = x[(*trend>NONE)+j+1];
    }

    // Compute forecasts
    forecast(l, b, s, *m, *trend, *season, *phi, f, *h);
}
示例#3
0
void etssimulate(double *x, int *m, int *error, int *trend, int *season,
    double *alpha, double *beta, double *gamma, double *phi, int *h, double *y, double *e)

{
    int i, j, nstates;
    double oldl, l, oldb, b, olds[24], s[24], f[10];

    if((*m > 24) & (*season > NONE))
        return;
	else if(*m < 1)
		*m = 1;

    nstates = (*m)*(*season>NONE) + 1 + (*trend>NONE);

    // Copy initial state components
    l = x[0];
    if(*trend > NONE)
        b = x[1];
    if(*season > NONE)
    {
        for(j=0; j<(*m); j++)
            s[j] = x[(*trend>NONE)+j+1];
    }

    for (i=0; i<(*h); i++)
    {
        // COPY PREVIOUS STATE
        oldl = l;
        if(*trend > NONE)
            oldb = b;
        if(*season > NONE)
        {
            for(j=0; j<(*m); j++)
                olds[j] = s[j];
        }

        // ONE STEP FORECAST
        forecast(oldl, oldb, olds, *m, *trend, *season, *phi, f, 1);
        if(fabs(f[0]-NA) < TOL)
        {
            y[0]=NA;
            return;
        }

        if(*error == ADD)
            y[i] = f[0] + e[i];
        else
            y[i] = f[0]*(1.0+e[i]);

        // UPDATE STATE
        update(&oldl, &l, &oldb, &b, olds, s, *m, *trend, *season, *alpha, *beta, *gamma, *phi, y[i]);
    }
}
示例#4
0
int main() {
    kmeans("./dataset", "./result");
    Forecast forecast("./result");
    HMM hmm = HMM("./dataset", "./dictionnary.txt", forecast);

    hmm.print();
    {
        cout << "Save" << endl;
        std::ofstream ofs("hmm_save");
        boost::archive::text_oarchive oa(ofs);
        oa << hmm;
    }
    
    HMM hmm2 = HMM();
    {
        cout << "Load" << endl;
        std::ifstream ifs("hmm_save");
        boost::archive::text_iarchive ia(ifs);
        ia >> hmm2;
    }
    hmm2.print();    
    return (EXIT_SUCCESS);
}
示例#5
0
void LNLP::run()
{
    prepare_forecast(); // check parameters
    forecast(); // forecast code is in forecast_machine
    return;
}
示例#6
0
void Xmap::run()
{
    prepare_forecast(); // check parameters
    
    // setup data structures and compute maximum lib size
    predicted_stats.clear();
    predicted_lib_sizes.clear();
    std::vector<size_t> full_lib = which_lib;
    size_t max_lib_size = full_lib.size();
    std::mt19937 rng(seed); // init mersenne twister with seed
    // need to update with true random seed
    std::uniform_int_distribution<uint32_t> lib_sampler(0, max_lib_size-1);
    std::uniform_real_distribution<double> unif_01(0, 1);
    std::vector<int> idx;
 
    size_t m;
    size_t t;

    for(auto lib_size: lib_sizes)
    {
        if(lib_size >= max_lib_size && (!random_libs || !replace))
        // no possible lib variation if using all vectors and
        // [no random libs OR (random_libs and sampling without replacement)]
        {
            which_lib = full_lib; // use all lib vectors
            forecast();
            predicted_stats.push_back(make_stats());
            predicted_lib_sizes.push_back(lib_size);
            break;
        }
        else if(random_libs)
        {
            which_lib.resize(lib_size, 0);
            for(size_t k = 0; k < num_samples; ++k)
            {
                if(replace)
                {
                    for(auto& lib: which_lib)
                    {
                        lib = full_lib[lib_sampler(rng)];
                    }
                }
                else
                {
                    // sample without replacement (algorithm from Knuth)
                    m = 0;
                    t = 0;
                    while(m < lib_size)
                    {
                        if(double(max_lib_size - t) * unif_01(rng) >= double(lib_size - m))
                        {
                            ++t;
                        }
                        else
                        {
                            which_lib[m] = full_lib[t];
                            ++t; ++m;
                        }
                    }
                }
                forecast();
                predicted_stats.push_back(make_stats());
                predicted_lib_sizes.push_back(lib_size);
            }
        }
        else
        // no random libs and using contiguous segments
        {
            for(size_t k = 0; k < max_lib_size; ++k)
            {
                if((k + lib_size) > max_lib_size) // need to loop around
                {
                    which_lib.assign(full_lib.begin()+k, full_lib.end()); // k to end
                    which_lib.insert(which_lib.begin(), 
                                     full_lib.begin(), 
                                     full_lib.begin() + lib_size - (max_lib_size-k));
                }
                else
                {
                    which_lib.assign(full_lib.begin()+k, full_lib.begin()+k+lib_size);
                }
                
                forecast();
                predicted_stats.push_back(make_stats());
                predicted_lib_sizes.push_back(lib_size);
            }
        }
    }
    which_lib = full_lib;
    return;
}
示例#7
0
void etscalc(double *y, int *n, double *x, int *m, int *error, int *trend, int *season,
    double *alpha, double *beta, double *gamma, double *phi, double *e, double *lik, double *amse)
{
    int i, j, nstates;
    double oldl, l, oldb, b, olds[24], s[24], f[10], lik2, tmp;

    if((*m > 24) & (*season > NONE))
        return;
    else if(*m < 1)
        *m = 1;

    nstates = (*m)*(*season>NONE) + 1 + (*trend>NONE);

    // Copy initial state components
    l = x[0];
    if(*trend > NONE)
        b = x[1];
    if(*season > NONE)
    {
        for(j=0; j<(*m); j++)
            s[j] = x[(*trend>NONE)+j+1];
    }

    *lik = 0.0;
    lik2 = 0.0;
    for(j=0; j<10; j++)
        amse[j] = 0.0;

    for (i=0; i<(*n); i++)
    {
        // COPY PREVIOUS STATE
        oldl = l;
        if(*trend > NONE)
            oldb = b;
        if(*season > NONE)
        {
            for(j=0; j<(*m); j++)
                olds[j] = s[j];
        }

        // ONE STEP FORECAST
        forecast(oldl, oldb, olds, *m, *trend, *season, *phi, f, 10);
        if(fabs(f[0]-NA) < TOL)
        {
            *lik = NA;
            return;
        }

        if(*error == ADD)
            e[i] = y[i] - f[0];
        else
            e[i] = (y[i] - f[0])/f[0];
        for(j=0; j<10; j++)
        {
            if(i+j<(*n))
            {
                tmp = y[i+j]-f[j];
                amse[j] += (tmp*tmp)/(*n);
            }
        }

        // UPDATE STATE
        update(&oldl, &l, &oldb, &b, olds, s, *m, *trend, *season, *alpha, *beta, *gamma, *phi, y[i]);

        // STORE NEW STATE
        x[nstates*(i+1)] = l;
        if(*trend > NONE)
            x[nstates*(i+1)+1] = b;
        if(*season > NONE)
        {
           for(j=0; j<(*m); j++)
                x[(*trend>NONE)+nstates*(i+1)+j+1] = s[j];
        }
        *lik = *lik + e[i]*e[i];
        lik2 += log(fabs(f[0]));
    }
    *lik = (*n) * log(*lik);
    if(*error == MULT)
        *lik += 2*lik2;
}
示例#8
0
void double_es::future_forecast(const int& c) {
    for(int i = 1; i<=c; i++) {
        _newf.push_back(forecast(i+now(), now()));
    }
}