Example #1
0
int MixMod::Update()
{
 int i,j;
 std::vector<double> tempt(k);
 std::vector<double> tempp(k);


 for (i=0;i<k;i++)
 {
  tempt[i]=0.;
  tempp[i]=0.;
  }
   j=0;
	for(i=0;i<k;i++)
	{
	 if (p[i] > 1.E-3)
	 {
	 tempp[j]=p[i];
	 tempt[j]=t[i];
         j++;
	 }
        }
	
  //reset weights and parameters
 	for (i=0;i<k;i++)
       {
  	 p[i]=0.;
         t[i]=0.;
       }
	for (i=0;i<j;i++)
        {
	 p[i]=tempp[i];
	 t[i]=tempt[i];
  	}
        k=j;
  	return j;
}
Example #2
0
 int MixMod::Combine()
{
 int i,j,jj,tempk,tmpnumstep=1;
 std::vector<int>count(k);
 std::vector<double>tempp(k);
 std::vector<double>tempt(k);
 double diff;

	for (i=0;i<k;i++)
	{
	tempt[i] =1.E+8;
	tempp[i] =0.;
        count[i]=-1;
        }


	jj=-1;

//  find identical parameters and store their index
	for (i=0;i<k-1;i++)
        {
	diff=t[i+1]-t[i];
 	 if(fabs(diff)<limit)
	 {
	  jj++;
	  count[jj]=i+1;
	 }
	   }
           jj=jj+1;
         tempk=k-jj;
	j=0;
	jj=-1;
/*cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c      Find remaining different parameters  and update mixing weights
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc*/


	for (i=0;i<k;i++)
	{

	 if ( i==count[j] )
	 {
	  j++;
	  tempp[jj]=tempp[jj]+p[i];
          } // end if
	  else
	  {
	  jj++;
	  tempt[jj]=t[i];
	  tempp[jj]=p[i];
          }         // end else

        } // end for loop

/*cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c    done!
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc*/
	k=tempk;
        
	for (i=0;i<k;i++)
        {
	p[i]=tempp[i];
	t[i]=tempt[i];
          
	}
    CalcMat();
    Gradient();
    EM(tmpnumstep);
    ll=likelihood();
    return tempk;

}
  Voxels& Voxels::anisotropicDiffusion(unsigned int iterations)
  {
    CVC::ThreadInfo ti(BOOST_CURRENT_FUNCTION);

    double cn, cs, ce, cw, cu, cd;
    double delta_n, delta_s, delta_e, delta_w, delta_u, delta_d;
    double K_para = 3;
    double Lamda_para = 0.16f;
    unsigned int m;
    VolMagick::uint64 i,j,k, stepnum = 0;
    Voxels tempt(*this);

    if(_vosm) _vosm->start(this, VoxelOperationStatusMessenger::AnisotropicDiffusion, ZDim()*iterations);

    uint64 numSteps = ZDim()*iterations;

    for (m=0; m<iterations; m++)
      {
        for (k=0; k<ZDim(); k++)
	  {
	    for (j=0; j<YDim(); j++) 
	      for (i=0; i<XDim(); i++)
		{
		if (j < YDim()-1)
		  delta_s = (*this)(i,j+1,k) - (*this)(i,j,k);
		else
		  delta_s = 0.0;
		if (j > 0)
		  delta_n = (*this)(i,j-1,k) - (*this)(i,j,k);
		else 
		  delta_n = 0.0;
		if (i < XDim()-1)
		  delta_e = (*this)(i+1,j,k) - (*this)(i,j,k);
		else 
		  delta_e = 0.0;
		if (i > 0)
		  delta_w = (*this)(i-1,j,k) - (*this)(i,j,k);
		else
		  delta_w = 0.0;
		if (k < ZDim()-1)
		  delta_u = (*this)(i,j,k+1) - (*this)(i,j,k);
		else 
		  delta_u = 0.0;
		if (k > 0)
		  delta_d = (*this)(i,j,k-1) - (*this)(i,j,k);
		else
		  delta_d = 0.0;
		
		cn = 1.0f / (1.0f + ((delta_n * delta_n) / (K_para * K_para)));
		cs = 1.0f / (1.0f + ((delta_s * delta_s) / (K_para * K_para)));
		ce = 1.0f / (1.0f + ((delta_e * delta_e) / (K_para * K_para)));
		cw = 1.0f / (1.0f + ((delta_w * delta_w) / (K_para * K_para)));
		cu = 1.0f / (1.0f + ((delta_u * delta_u) / (K_para * K_para)));
		cd = 1.0f / (1.0f + ((delta_d * delta_d) / (K_para * K_para)));
	  
		tempt(i,j,k, 
		      (*this)(i,j,k) + 
		      Lamda_para * (cn * delta_n + cs * delta_s + ce * delta_e + 
				    cw * delta_w + cu * delta_u + cd * delta_d));
		}
	    
	    if(_vosm) _vosm->step(this, VoxelOperationStatusMessenger::AnisotropicDiffusion, stepnum);
            cvcapp.threadProgress(float(stepnum)/float(numSteps));
            stepnum++;
	  }
    
	(*this) = tempt;
      }

    if(_vosm) _vosm->end(this, VoxelOperationStatusMessenger::AnisotropicDiffusion);
    cvcapp.threadProgress(1.0f);

    return *this;
  }