예제 #1
0
void XEMModel::FixKnownPartition(XEMPartition *& knownPartition) {
    // update Nk if knownLabel
    if (knownPartition!=NULL) {
        int64_t     ** knownPartitionValue = knownPartition->_tabValue;
        int64_t      * knownPartition_i;
        double    ** p_cik = _tabCik;
        int64_t  ** p_zikKnown = _tabZikKnown;
        //double ** p_tik = _tabTik;
        int64_t  k;
        int64_t  i;
        double sumLabel = 0.0;
        for (i=0; i<_nbSample; i++) {
            sumLabel     = 0.0;
            knownPartition_i = *knownPartitionValue;

            for (k=0; k<_nbCluster; k++) {
                sumLabel += knownPartition_i[k];
            }
            if (sumLabel != 0.0) {
                _tabZiKnown[i] = true;
                recopyTab(knownPartition_i,*p_cik,_nbCluster);
                recopyTab(knownPartition_i,*p_zikKnown,_nbCluster);
                //recopyTab(knownLabel_i,*p_tik,_nbCluster);
            }
            knownPartitionValue++;
            p_cik++;
            //p_tik++;
            p_zikKnown++;
        }

        //
        computeNk();
    }//endif
}
예제 #2
0
/*--------------------------------------------------------------------------------------------
  C step
  ------
  Classification Step

  Note : Cstep follows an Estep
  ----

  already updated :
  - _tabFik, _tabCik, _tabTik, _tabNk, _parameter

  updated in this method :
  - _tabCik, _tabNk
  --------------------------------------------------------------------------------------------*/
void XEMModel::Cstep() {
    int64_t  k, kMax;
    int64_t  i;
    double tikMax = 0;
    for (i=0; i<_nbSample; i++) {
        if (!_tabZiKnown[i]) {
            kMax = 0;
            tikMax = _tabTik[i][0];
            for (k=1; k<_nbCluster; k++) {
                if (_tabTik[i][k] > tikMax) {
                    tikMax = _tabTik[i][k];
                    kMax = k;
                }
            }
            for (k=0; k<_nbCluster; k++) {
                _tabCik[i][k] = 0;
            }
            _tabCik[i][kMax] = 1;
        }
    }


    //update _tabNk
    if(_algoName == UNKNOWN_ALGO_NAME)
        throw;

    if(_algoName != MAP) {
        computeNk();
    }
}
예제 #3
0
/*--------------------------------------------------------------------------------------------
  E step : Expectation
  ------

  Note : Estep follows a Mstep or an initialsation (so _parameter is updated)
  ----

  already updated :
  - _parameter

  updated in this method :
  - _tabFik, _tabCik, _tabTik, _tabNk

  --------------------------------------------------------------------------------------------*/
void XEMModel::Estep() {

    // 1. compute fik
    //---------------
    computeFik();

    //2. compute tik (conditional probabilities (posteriori probabilities))
    //---------------
    int64_t  k;
    int64_t  i;
    for (i=0; i<_nbSample; i++) {
        if (_tabSumF[i]==0.0) {
            _parameter->computeTikUnderflow(i, _tabTik);
        }
        else {
            for (k=0; k<_nbCluster; k++) {
                _tabTik[i][k] = _tabFik[i][k] / _tabSumF[i] ;
            }
        }

        // 3. compute cik
        //---------------
        if (!_tabZiKnown[i]) {
            for (k=0; k<_nbCluster; k++) {
                _tabCik[i][k] = _tabTik[i][k];
            }
        }
    }
    //4. compute nk
    //------------
    computeNk();
}
예제 #4
0
파일: vpHinkley.cpp 프로젝트: tswang/visp
/*!

  Perform the Hinkley test. A downward jump is detected if \f$ M_k - S_k >
  \alpha \f$. An upward jump is detected if \f$ T_k - N_k > \alpha \f$.

  \param signal : Observed signal \f$ s(t) \f$.

  \sa setDelta(), setAlpha(), testDownwardJump(), testUpwardJump()

*/
vpHinkley::vpHinkleyJumpType vpHinkley::testDownUpwardJump(double signal)
{

  vpHinkleyJumpType jump = noJump;

  nsignal ++; // Signal length

  if (nsignal == 1) mean = signal;

  // Calcul des variables cumulees
  computeSk(signal);
  computeTk(signal);

  computeMk();
  computeNk();

  vpCDEBUG(2) << "alpha: " << alpha << " dmin2: " << dmin2
	      << " signal: " << signal
	      << " Sk: " << Sk << " Mk: " << Mk
	      << " Tk: " << Tk << " Nk: " << Nk << std::endl;

  // teste si les variables cumulees excedent le seuil
  if ((Mk - Sk) > alpha)
    jump = downwardJump;
  else if ((Tk - Nk) > alpha)
    jump = upwardJump;

#ifdef VP_DEBUG
  if (VP_DEBUG_MODE >= 2) {
    switch(jump) {
    case noJump:
      std::cout << "noJump " << std::endl;
     break;
    case downwardJump:
      std::cout << "downWardJump " << std::endl;
      break;
    case upwardJump:
      std::cout << "upwardJump " << std::endl;
      break;
    }
  }
#endif

  computeMean(signal);

  if ((jump == upwardJump) || (jump == downwardJump)) {
    vpCDEBUG(2) << "\n*** Reset the Hinkley test  ***\n";

    Sk = 0; Mk = 0; Tk = 0; Nk = 0;  nsignal = 0;
    // Debut modif FS le 03/09/2003
    mean = signal;
    // Fin modif FS le 03/09/2003
  }

  return (jump);
}
예제 #5
0
/*--------------------------------------------------------------------------------------------
  S step
  ------
  // S Step : Stochastic Classification

  Note : Sstep follows an Estep
  ----

  already updated :
  - _tabFik, _tabCik, _tabTik, _tabNk, _parameter

  updated in this method :
  - _tabCik, _tabNk
  --------------------------------------------------------------------------------------------*/
void XEMModel::Sstep() {
    int64_t  i;
    int64_t  k;
    double ** cumTabT = new double*[_nbSample];

    for (i=0; i<_nbSample; i++) {
        cumTabT[i]    = new double[_nbCluster];
        cumTabT[i][0] = _tabTik[i][0];
    }
    for (k=1; k<_nbCluster; k++) {
        for (i=0; i<_nbSample; i++) {
            cumTabT[i][k] = _tabTik[i][k] + cumTabT[i][k-1];
        }
    }

    double * tabRnd = new double[_nbSample];
    for (i=0; i<_nbSample; i++) {
        tabRnd[i] = rnd();
    }

    for (i=0; i<_nbSample; i++) {
        if (!_tabZiKnown[i]) {
            for (k=0; k<_nbCluster; k++) {
                _tabCik[i][k] = 0;
            }
            k=0;
            while ((k<_nbCluster) && (tabRnd[i] > cumTabT[i][k])) {
                k++;
            }
            if (tabRnd[i] <= cumTabT[i][k]) {
                _tabCik[i][k] = 1;
            }
            else {
                throw internalMixmodError;
            }
        }
    }

    for (i=0; i<_nbSample; i++) {
        delete[] cumTabT[i];
    }
    delete[] cumTabT;
    delete[] tabRnd;

    //update _tabNk
    computeNk();
}
예제 #6
0
파일: vpHinkley.cpp 프로젝트: tswang/visp
/*!

  Perform the Hinkley test. An upward jump is detected if \f$ T_k - N_k >
  \alpha \f$.

  \param signal : Observed signal \f$ s(t) \f$.

  \sa setDelta(), setAlpha(), testDownwardJump()

*/
vpHinkley::vpHinkleyJumpType vpHinkley::testUpwardJump(double signal)
{

  vpHinkleyJumpType jump = noJump;

  nsignal ++; // Signal length

  if (nsignal == 1) mean = signal;

  // Calcul des variables cumulees
  computeTk(signal);

  computeNk();

  vpCDEBUG(2) << "alpha: " << alpha << " dmin2: " << dmin2
	    << " signal: " << signal << " Tk: " << Tk << " Nk: " << Nk;

  // teste si les variables cumulees excedent le seuil
  if ((Tk - Nk) > alpha)
    jump = upwardJump;

#ifdef VP_DEBUG
  if (VP_DEBUG_MODE >= 2) {
    switch(jump) {
    case noJump:
      std::cout << "noJump " << std::endl;
     break;
    case downwardJump:
      std::cout << "downWardJump " << std::endl;
      break;
    case upwardJump:
      std::cout << "upWardJump " << std::endl;
      break;
    }
  }
#endif
  computeMean(signal);

  if (jump == upwardJump)  {
    vpCDEBUG(2) << "\n*** Reset the Hinkley test  ***\n";

    Tk = 0; Nk = 0;  nsignal = 0;
  }

  return (jump);
}