コード例 #1
0
ファイル: SubsetGenerator.cpp プロジェクト: cran/OjaNP
void AllSubsets::reset(Matrix2D* m, Matrix2D& points, Vector& mu)
{
  reset();

  //create first subset matrix
  for(int j = 0; j <= sizeOfSubsample; j++)
    m->setValue(0, j, 1.0);

  for(int i = 1; i <= sizeOfSubsample; i++)
  {
    m->setValue(i, 0, mu.getValue(i-1));
  }

  for(int j = 0; j < sizeOfSubsample - 1; j++)
  {
    selectedElements[j] = j;
    for(int i = 0; i < sizeOfSubsample; i++)
    {
      m->setValue(i+1, j+1, points.getValue(i,j));
    }
  }

  selectedElements[numberOfElements - 1] = sizeOfSubsample - 1;
  for(int i = 0; i < sizeOfSubsample; i++)
    m->setValue(i+1, sizeOfSubsample, points.getValue(i, numberOfElements - 1));
}
コード例 #2
0
ファイル: resolution_ssnr.cpp プロジェクト: I2PC/scipion
//#define DEBUG
void ProgSSNR::run()
{
    show();
    produceSideInfo();

    Matrix2D<double> output;
    if (!radial_avg)
    {
        if (!generate_VSSNR)
            estimateSSNR(1, output);
        else
            estimateSSNR(2, output);
        if (fn_out == "")
        	fn_out=fn_S.insertBeforeExtension("_SSNR").removeLastExtension().addExtension("xmd");
    }
    else
    {
        radialAverage(output);
        if (fn_out == "")
        	fn_out=fn_VSSNR.insertBeforeExtension("_radial_avg").removeLastExtension().addExtension("xmd");
    }
#ifdef DEBUG
    output.write(fn_out);
#endif
    MetaData MD;
    for (size_t i=1; i<MAT_YSIZE(output); ++i)
    {
    	size_t id=MD.addObject();
    	MD.setValue(MDL_RESOLUTION_FREQ,output(i,1),id);
  		MD.setValue(MDL_RESOLUTION_SSNR,output(i,2),id);
    	MD.setValue(MDL_RESOLUTION_FREQREAL,1.0/output(i,1),id);
    }
    MD.write(fn_out);
}
コード例 #3
0
ファイル: matrixbinder.cpp プロジェクト: lsouchet/gideros
int MatrixBinder::setTy(lua_State* L)
{
	Binder binder(L);
	Matrix2D* matrix = static_cast<Matrix2D*>(binder.getInstance("Matrix", 1));

	matrix->setTy(luaL_checknumber(L, 2));

	return 0;
}
コード例 #4
0
ファイル: matrixbinder.cpp プロジェクト: lsouchet/gideros
int MatrixBinder::getTx(lua_State* L)
{
	Binder binder(L);
	Matrix2D* matrix = static_cast<Matrix2D*>(binder.getInstance("Matrix", 1));

	lua_pushnumber(L, matrix->tx());

	return 1;
}
コード例 #5
0
ファイル: TextureTest.cpp プロジェクト: iccthedral/succex
void TextureTest::ProcessEvent(SDL_Event* event)
{
    switch(event->type)
    {
        case SDL_MOUSEBUTTONDOWN:
        {
            if(event->button.button == 4)
            {

            }
            else if(event->button.button == 5)
            {

            }
            break;
        }
        case SDL_KEYDOWN:
        {
            if(event->key.keysym.sym == SDLK_UP)
            {
                Vector2D oldSteer = v->GetVelocity();
                Vector2D temp = v->GetVelocity();
                temp.Normalize();
                v->SetVelocity(oldSteer+temp*16);
                //v->SetHeading(v->GetVelocity());
            }
            if(event->key.keysym.sym == SDLK_DOWN)
            {
                Vector2D oldSteer = v->GetVelocity();
                Vector2D temp = v->GetVelocity();
                temp.Normalize();
                v->SetVelocity(oldSteer-temp*163);
            }
            if(event->key.keysym.sym == SDLK_LEFT)
            {
                Matrix2D mat;
                //Vector2D vec = v->GetVelocity();
                Vector2D vecH = v->GetVelocity();
                //Vec2DRotateAroundO(vecH,angle);
                mat.Rotate(angle);
//
               //mat.Rotate(angle);
                mat.TransformVector(vecH);
//              / mat.TransformVector(vecH);
//                //v->SetVelocity(vec);
//                v->RotateHeadingToFacePosition(vecH);
                //v->SetSteeringForce(vecH);
                v->SetVelocity(vecH);
                angle=0.07;

            }
            break;
        }
        //case SDL_KEYUP
    }
}
コード例 #6
0
void
GaussJordan::print(Matrix2D const & A) const {
    std::cout << std::endl;
    for (IMatrix2D::size_type i = 0; i < A.rows(); ++i) {
        IMatrix2D::size_type row = logicalToPhysicalRowIndex(i);
        for (IMatrix2D::size_type j = 0; j < A.cols(); ++j) {
            std::cout << std::setw(10) << A(row, j);
        }
        std::cout << std::endl;
    }
}
コード例 #7
0
ファイル: matrix2d.cpp プロジェクト: zhou13/refine
/* Interface to numerical recipes: svbksb ---------------------------------- */
void svbksb(Matrix2D<double> &u, Matrix1D<double> &w, Matrix2D<double> &v,
            Matrix1D<double> &b, Matrix1D<double> &x)
{
    // Call to the numerical recipes routine. Results will be stored in X
    svbksb(u.adaptForNumericalRecipes2(),
           w.adaptForNumericalRecipes(),
           v.adaptForNumericalRecipes2(),
           u.mdimy, u.mdimx,
           b.adaptForNumericalRecipes(),
           x.adaptForNumericalRecipes());
}
コード例 #8
0
ファイル: Painter.cpp プロジェクト: dreamsxin/ultimatepp
Matrix2D GetImageLineMatrix(double x1, double y1, double x2, double y2, const Image& image)
{
	Matrix2D m;
	Size sz = image.GetSize();
	m.scale(agg::calc_distance(x1, y1, x2, y2) / sz.cx);
	if(fabs(x2 - x1) < fabs(y2 - y1) * 1e-6)
		m.rotate(y2 > y1 ? M_PI_2 : -M_PI_2);
	else
		m.rotate(atan((y2 - y1) / (x2 - x1)));
	m.translate(x1, y1);
	return m;
}
コード例 #9
0
ファイル: symmetries.cpp プロジェクト: dtegunov/vlion
// Get matrix ==============================================================
void SymList::get_matrices(int i, Matrix2D<DOUBLE> &L, Matrix2D<DOUBLE> &R)
const
{
    int k, l;
    L.initZeros(4, 4);
    R.initZeros(4, 4);
    for (k = 4 * i; k < 4*i + 4; k++)
        for (l = 0; l < 4; l++)
        {
            L(k - 4*i, l) = __L(k, l);
            R(k - 4*i, l) = __R(k, l);
        }
}
コード例 #10
0
	void optimiseTransformationMatrixContinuous()
	{
		// Get coordinates of all pairs:
		Matrix2D<double> Au, Bt;
	    Au.initZeros(3, 3);
	    Bt.initZeros(3, 3);
	    Pass.initZeros(4,4);

	    // Add all pairs to dependent matrices (adapted from add_point in Xmipps micrograph_mark main_widget_mark.cpp)
		for (int t = 0; t < pairs_t2u.size(); t++)
		{
			int u = pairs_t2u[t];
			if (u >= 0)
	        {
				Au(0, 0) += (double)(p_unt[2*u] * p_unt[2*u]);
				Au(0, 1) += (double)(p_unt[2*u] * p_unt[2*u+1]);
				Au(0, 2) += (double)(p_unt[2*u]);
				Au(1, 0) = Au(0, 1);
				Au(1, 1) += (double)(p_unt[2*u+1] * p_unt[2*u+1]);
				Au(1, 2) += (double)(p_unt[2*u+1]);
				Au(2, 0) = Au(0, 2);
				Au(2, 1) = Au(1, 2);
				Au(2, 2) += 1.;

				Bt(0, 0) += (double)(p_til[2*t] * p_unt[2*u]);
				Bt(0, 1) += (double)(p_til[2*t+1] * p_unt[2*u]);
				Bt(0, 2) = Au(0, 2);
				Bt(1, 0) += (double)(p_til[2*t] * p_unt[2*u+1]);
				Bt(1, 1) += (double)(p_til[2*t+1] * p_unt[2*u+1]);
				Bt(1, 2) = Au(1, 2);
				Bt(2, 0) += (double)(p_til[2*t]);
				Bt(2, 1) += (double)(p_til[2*t+1]);
				Bt(2,2) += 1.;
	        }
	    }

	    // Solve equations
	    solve(Au, Bt, Pass);
	    Pass = Pass.transpose();
	    std::cout << " Optimised passing matrix= " << Pass << std::endl;
	    //These values can be complete CRAP. Better not show them at all....
	    //double rotp, tiltp, psip;
	    //tiltp = acos(Pass(1,1));
	    //rotp = acos(Pass(1,0)/sin(tiltp));
	    //psip = acos(Pass(0,1)/-sin(tiltp));
	    //std::cout << " Optimised tilt angle= " << RAD2DEG(tiltp) << std::endl;
	    //std::cout << " Optimised in-plane rot angles= " << RAD2DEG(rotp) <<" and "<< RAD2DEG(psip) << std::endl;
	    // Map using the new matrix
	    mapOntoTilt();

	}
コード例 #11
0
double JPetRecoImageTools::calculateProjection(const Matrix2D& emissionMatrix, double angle, int scanNumber, int nScans,
    InterpolationFunc& interpolationFunction)
{
  int N = scanNumber - nScans / 2 ;
  const int kInputMatrixSize = emissionMatrix.size();
  //if no. nScans is greater than the image width, then scale will be <1
  const double scale = kInputMatrixSize / nScans;
  const double kSin45or125deg = std::sqrt(2) / 2; /// sin(45) deg
  const double kEpsilon = 0.0000001;
  const double kDegToRad = M_PI / 180.;

  double sin = std::sin(angle * kDegToRad - M_PI / 2.);
  sin = setToZeroIfSmall(sin, kEpsilon);
  double cos = std::cos(angle * kDegToRad - M_PI / 2.);
  cos = setToZeroIfSmall(cos, kEpsilon);

  double a = 0.;
  double b = 0.;
  /// The line over which we integrate is perpendicular to any line with the slope = tg(angle), so it is always  -1/tg(angle).
  /// If the angle is between (45 to 125)
  /// we use  y = a * x + b, and we iterate over rows of the matrix (x).
  /// If the angle is between [0 to 45 ] or [125 to 180]
  /// we use x = a* y +b, and we iterate over columns of the matrix (y)
  bool angleRange45To125 = std::abs(sin) > kSin45or125deg;
  double divided = 1.;
  std::function<double(int, int)> matrixGet;

  if (angleRange45To125) {
    assert(sin);
    a = -cos / sin;
    b = (N - cos - sin) / sin;
    b *= scale;
    matrixGet  = matrixGetterFactory(emissionMatrix, false); // The matrix  elements will be taken as (x,y).
    divided = std::abs(sin);
  } else {
    assert(cos);
    a = -sin / cos;
    b = (N - cos - sin) / cos;
    b *= scale;
    matrixGet  = matrixGetterFactory(emissionMatrix, true); // The matrix  elements will be taken as (y, x) - transposed.
    divided = std::abs(cos);
  }
  const int kMatrixCenter = emissionMatrix.size() / 2;
  double value = 0.;
  for (auto i = -kMatrixCenter; i < kMatrixCenter; i++) {
    value += interpolationFunction(i + kMatrixCenter , a * i + b + kMatrixCenter, matrixGet);
  }
  value /= divided;
  return value;
}
コード例 #12
0
ファイル: matrixbinder.cpp プロジェクト: lsouchet/gideros
int MatrixBinder::setElements(lua_State* L)
{
	Binder binder(L);
	Matrix2D* matrix = static_cast<Matrix2D*>(binder.getInstance("Matrix", 1));

	lua_Number m11 = luaL_optnumber(L, 2, 1);
	lua_Number m12 = luaL_optnumber(L, 3, 0);
	lua_Number m21 = luaL_optnumber(L, 4, 0);
	lua_Number m22 = luaL_optnumber(L, 5, 1);
	lua_Number tx = luaL_optnumber(L, 6, 0);
	lua_Number ty = luaL_optnumber(L, 7, 0);

    matrix->set(m11, m12, m21, m22, tx, ty);

	return 0;
}
コード例 #13
0
void
GaussJordan::rearrangeDueToPivoting(Matrix2D & A, Matrix2D & AInverse, Vector & rhs) const {
    decltype(partial_pivoting_map_) physical_map(partial_pivoting_map_.size());
    for (auto i = 0; i < partial_pivoting_map_.size(); ++i) {
        physical_map[i] = physicalToLogicalRowIndex(i);
    }

    for (auto i = 0; i < physical_map.size(); ++i) {
        auto j = std::distance(std::begin(physical_map), std::find(std::begin(physical_map), std::end(physical_map), i));
        if (i == j)
            continue;

        // Swap rows
        for (auto col = 0; col < A.cols(); ++col) {
            std::swap(AInverse(i, col), AInverse(j, col));
            std::swap(A(i, col), A(j, col));
        }

//         AInverse.print();
//         print(AInverse);

        // Swap rows on the r.h.s.
        std::swap(rhs(i), rhs(j));
        std::swap(physical_map[i], physical_map[j]);
    }

//     AInverse.print();
//     print(AInverse);
}
コード例 #14
0
JPetRecoImageTools::Matrix2DProj JPetRecoImageTools::sinogram(Matrix2D& emissionMatrix,
    int nViews, int nScans,
    double angleBeg, double angleEnd,
    InterpolationFunc interpolationFunction,
    RescaleFunc rescaleFunc,
    int minCutoff,
    int scaleFactor
                                                             )
{
  assert(emissionMatrix.size() > 0);
  assert(emissionMatrix.size() == emissionMatrix[0].size());
  assert(nViews > 0);
  assert(nScans > 0);
  assert(angleBeg < angleEnd);
  assert(minCutoff < scaleFactor);

  //create vector of size nViews, initialize it with vector of size nScans
  Matrix2DProj proj(nViews, std::vector<double>(nScans));

  float stepsize = (angleEnd - angleBeg) / nViews;
  assert(stepsize > 0); //maybe != 0 ?

  int viewIndex = 0;
  for (auto phi = angleBeg; phi < angleEnd; phi = phi + stepsize, viewIndex++) {
    for (auto scanNumber = 0; scanNumber < nScans; scanNumber++) {
      proj[viewIndex][nScans  - 1 - scanNumber] = JPetRecoImageTools::calculateProjection(emissionMatrix,
          phi, scanNumber, nScans,
          interpolationFunction);
    }
  }
  rescaleFunc(proj, minCutoff, scaleFactor);
  return proj;
}
コード例 #15
0
Matrix2D operator *( const Matrix2D &first, const Matrix2D &second ) {
   Matrix2D returnVal;
   
   for( int n = 0; n < Matrix2D::SIDE_LENGTH; n++ ) {
      for( int p = 0; p < Matrix2D::SIDE_LENGTH; p++ ) {
         float val = 0.0;
         
         for( int m = 0; m < Matrix2D::SIDE_LENGTH; m++ ) {
            val += first.Get( n, m ) + second.Get( m, p );
         }
         
         returnVal.Set( n, p, val );
      }
   }
   
   return returnVal;
}
コード例 #16
0
ファイル: SubsetGenerator.cpp プロジェクト: cran/OjaNP
void AllSubsets::reset(Matrix2D* m, Matrix2D* m2, Matrix2D& points, Vector& mu)
{
  reset();
  reset(m, points, mu);

  //create first subset matrix
  for(int j = 0; j < sizeOfSubsample; j++)
    m2->setValue(0, j, 1.0);

  for(int j = 0; j < sizeOfSubsample - 1; j++)
  {
    for(int i = 0; i < sizeOfSubsample; i++)
    {
      m2->setValue(i+1, j, points.getValue(i,j));
    }
  }

  for(int i = 0; i < sizeOfSubsample; i++)
    m2->setValue(i+1, sizeOfSubsample - 1, points.getValue(i, numberOfElements - 1));
}
コード例 #17
0
std::function<double(int, int)> JPetRecoImageTools::matrixGetterFactory(const Matrix2D& emissionMatrix, bool isTransposed)
{
  if (!isTransposed) {
    return [& emissionMatrix](int i, int j) {
      if (i >= 0 && i < (int) emissionMatrix[0].size() && j >= 0 && j < (int) emissionMatrix.size() ) {
        return emissionMatrix[i][j];
      } else {
        return 0;
      }
    };
  } else {
    return [& emissionMatrix](int i, int j) {
      if (i >= 0 && i < (int) emissionMatrix.size() && j >= 0 && j < (int) emissionMatrix[0].size() ) {
        return emissionMatrix[j][i];
      } else {
        return 0;
      }
    };
  }
}
コード例 #18
0
double FieldVariableDescriptor::GetComponent(const Matrix2D & m) const
{
	//EK 2012-03-02 assert bug fix - if component_index_1 == FVCI_magnitude, component_index_2 does not matter
	assert(component_index_1 != FVCI_none && component_index_2 != FVCI_magnitude);
	assert(component_index_2 != FVCI_none || component_index_1 == FVCI_magnitude);
	if(component_index_1 == FVCI_magnitude)
		return sqrt(m.InnerProduct(m));
	if(component_index_1 == FVCI_z || component_index_2 == FVCI_z)
		return FIELD_VARIABLE_NO_VALUE;		// this may happen if there are 3D and 2D elements mixed in the system
	return m(component_index_1, component_index_2);
}
コード例 #19
0
ファイル: euler.cpp プロジェクト: dtegunov/liblion
	/* Euler angles --> matrix ------------------------------------------------- */
	void Euler_angles2matrix(DOUBLE alpha, DOUBLE beta, DOUBLE gamma,
		Matrix2D<DOUBLE> &A, bool homogeneous)
	{
		DOUBLE ca, sa, cb, sb, cg, sg;
		DOUBLE cc, cs, sc, ss;

		if (homogeneous)
		{
			A.initZeros(4, 4);
			MAT_ELEM(A, 3, 3) = 1;
		}
		else
			if (MAT_XSIZE(A) != 3 || MAT_YSIZE(A) != 3)
				A.resize(3, 3);

		alpha = DEG2RAD(alpha);
		beta = DEG2RAD(beta);
		gamma = DEG2RAD(gamma);

		ca = cos(alpha);
		cb = cos(beta);
		cg = cos(gamma);
		sa = sin(alpha);
		sb = sin(beta);
		sg = sin(gamma);
		cc = cb * ca;
		cs = cb * sa;
		sc = sb * ca;
		ss = sb * sa;

		A(0, 0) = cg * cc - sg * sa;
		A(0, 1) = cg * cs + sg * ca;
		A(0, 2) = -cg * sb;
		A(1, 0) = -sg * cc - cg * sa;
		A(1, 1) = -sg * cs + cg * ca;
		A(1, 2) = sg * sb;
		A(2, 0) = sc;
		A(2, 1) = ss;
		A(2, 2) = cb;
	}
コード例 #20
0
ファイル: hessianLLE.cpp プロジェクト: I2PC/scipion
void HessianLLE::completeYt(const Matrix2D<double> &V,
		const Matrix2D<double> &Yi, Matrix2D<double> &Yt_complete)
{
    size_t Xdim = 1+MAT_XSIZE(V)+MAT_XSIZE(Yi);
    size_t Ydim = MAT_YSIZE(Yi);
    Yt_complete.resizeNoCopy(Ydim, Xdim);

    for (size_t i=0; i<Ydim; ++i)
    {
    	MAT_ELEM(Yt_complete,i,0)=1.;
    	memcpy(&MAT_ELEM(Yt_complete,i,1),             &MAT_ELEM(V,i,0), MAT_XSIZE(V)*sizeof(double));
    	memcpy(&MAT_ELEM(Yt_complete,i,MAT_XSIZE(V)+1),&MAT_ELEM(Yi,i,0),MAT_XSIZE(Yi)*sizeof(double));
    }
}
コード例 #21
0
ファイル: AddMult.cpp プロジェクト: EthanJamesLew/Matrix2D
void printMatrix(Matrix2D<double> &mat2, string name = "Matrix:")
{
	cout << name << endl;
	for (int i = 0; i < mat2.get_cols(); i++)
	{
		cout << "| ";
		cout << '\t';
		for (int j = 0; j < mat2.get_rows(); j++)
		{
			cout << mat2(j, i);
			if (j != mat2.get_rows() - 1)
			{
				cout << '\t';
			}
	
		}
		cout << '\t';
		cout << " |";
		cout << endl;
	}
	cout << endl;
	cout.clear();
	return;
}
コード例 #22
0
ファイル: matrixbinder.cpp プロジェクト: lsouchet/gideros
int MatrixBinder::getElements(lua_State* L)
{
	Binder binder(L);
	Matrix2D* matrix = static_cast<Matrix2D*>(binder.getInstance("Matrix", 1));

    lua_pushnumber(L, matrix->m11());
    lua_pushnumber(L, matrix->m12());
    lua_pushnumber(L, matrix->m21());
    lua_pushnumber(L, matrix->m22());
	lua_pushnumber(L, matrix->tx());
	lua_pushnumber(L, matrix->ty());

	return 6;
}
コード例 #23
0
bool
SaveMatrixToFile( const Matrix2D<T>& m, std::string fileName )
{
    bool ok = true;

    std::ofstream ofs( fileName.c_str(), ios::out | ios::binary );
    if( ofs.is_open() )
    {
        ok = m.WriteTo( ofs );
        ofs.close();
    }
    else
    {
        std::cerr << "Unable to write matrix to file \'" << fileName << "\'" << std::endl;
        ok = false;
    }
    return ok;
}
コード例 #24
0
bool
ReadMatrixFromFile( Matrix2D<T>& m, std::string fileName )
{
    bool ok = true;

    std::ifstream ifs( fileName.c_str(), ios::in | ios::binary );
    if( ifs.is_open() )
    {
        ok = m.ReadFrom( ifs );
        ifs.close();
    }
    else
    {
        std::cerr << "Unable to read matrix from file \'" << fileName << "\'" << std::endl;
        ok = false;
    }
    return ok;
}
コード例 #25
0
ファイル: Line.cpp プロジェクト: AntonLanghoff/whitecatlib
bool Line::
Collides( const Line &other, const Placement &thisPlacement,
              const Placement &otherPlacement ) const {
   Matrix2D thisTransform = thisPlacement.Get2DMatrix();
   Matrix2D otherTransform = otherPlacement.Get2DMatrix();
   
   Vec2D thisStart = thisTransform.Transform( start - thisPlacement.GetRotationPivot() );
   Vec2D thisEnd = thisTransform.Transform( end - thisPlacement.GetRotationPivot() );
   
   Vec2D otherStart = otherTransform.Transform( other.start - otherPlacement.GetRotationPivot() );
   Vec2D otherEnd = otherTransform.Transform( other.end - otherPlacement.GetRotationPivot() );
   
   return Collides( thisStart, thisEnd, other.origin, otherStart, otherEnd );
}
コード例 #26
0
ファイル: hessianLLE.cpp プロジェクト: I2PC/scipion
void HessianLLE::buildYiHessianEstimator(const Matrix2D<double> &V,
		Matrix2D<double> &Yi, size_t no_dim, size_t dp)
{
    size_t ct = 0;
    Yi.resizeNoCopy(MAT_YSIZE(V),dp);

    for(size_t mm=0; mm<no_dim; mm++)
    {
        size_t length = no_dim-mm;
        size_t indle=mm;
        for(size_t nn=0; nn<length; nn++)
        {
            size_t column = ct+nn;
            for(size_t element = 0; element<MAT_YSIZE(V); element++)
                MAT_ELEM(Yi, element, column) = MAT_ELEM(V, element, mm)*MAT_ELEM(V, element, indle);
            ++indle;
        }
        ct += length;
    }
}
コード例 #27
0
IMatrix2D::size_type
GaussJordan::getPivotElementsRowIndex(Matrix2D const & A, IMatrix2D::size_type column_index) const {
    /* Return the largest element in the column.
     * Note that no row can be pivot row more than once.
     * This is 
     */
    IMatrix2D::size_type max_row = A.rows();
    IMatrix2D::size_type pivot_index = 0;
    double pivot_value = 0;
    double val;
    for (auto row_index = column_index; row_index < max_row; ++row_index) {
        auto mapped_row_index = logicalToPhysicalRowIndex(row_index);
        val = std::fabs(A(mapped_row_index, column_index));
        if (val > pivot_value) {
            pivot_index = mapped_row_index;
            pivot_value = val;
        }
    }
    return pivot_index;
}
コード例 #28
0
ファイル: SubsetGenerator.cpp プロジェクト: cran/OjaNP
void RandomSubsets::reset(Matrix2D* m, Matrix2D* m2, Matrix2D& points, Vector& mu)
{
  reset(m, points, mu);
  reset();

  //create first subset matrix
  for(int j = 0; j < sizeOfSubsample; j++)
    m2->setValue(0, j, 1.0);

  for(int j = 0; j < sizeOfSubsample - 1; j++)
  {
    for(int i = 0; i < sizeOfSubsample; i++)
    {
      m2->setValue(i+1, j, points.getValue(i,j));
    }
  }

  getNextSubset(m,m2,points);
  count=0;
}
コード例 #29
0
void
Initialize<T>::operator()( Matrix2D<T>& mtx )
{
    srand48( seed );

    int nTileRows = mtx.GetNumRows() - 2 * haloWidth;
    if( (rowPeriod != -1) && (rowPeriod < nTileRows) )
    {
        nTileRows = rowPeriod;
    }

    int nTileCols = mtx.GetNumColumns() - 2 * haloWidth;
    if( (colPeriod != -1) && (colPeriod < nTileCols) )
    {
        nTileCols = colPeriod;
    }


    // initialize first tile
    for( unsigned int i = 0; i < nTileRows; i++ )
    {
        for( unsigned int j = 0; j < nTileCols; j++ )
        {
#ifndef READY
            mtx.GetData()[i+haloWidth][j+haloWidth] = i * j;
#else
            mtx.GetData()[i+haloWidth][j+haloWidth] = (T)drand48();
#endif // READY
        }
    }

    // initialize any remaining tiles
    // first we fill along rows a tile at a time,
    // then fill out along columns a row at a time
    if( colPeriod != -1 )
    {
        int nTiles = (mtx.GetNumColumns() - 2*haloWidth) / colPeriod;
        if( (mtx.GetNumColumns() - 2*haloWidth) % colPeriod != 0 )
        {
            nTiles += 1;
        }

        for( unsigned int t = 1; t < nTiles; t++ )
        {
            for( unsigned int i = 0; i < nTileRows; i++ )
            {
                memcpy( &(mtx.GetData()[haloWidth + i][haloWidth + t*nTileCols]),
                        &(mtx.GetData()[haloWidth + i][haloWidth]),
                        nTileCols * sizeof(T) );
            }
        }
    }
    if( rowPeriod != -1 )
    {
        int nTiles = (mtx.GetNumRows() - 2*haloWidth) / rowPeriod;
        if( (mtx.GetNumRows() - 2*haloWidth) % rowPeriod != 0 )
        {
            nTiles += 1;
        }

        for( unsigned int t = 1; t < nTiles; t++ )
        {
            for( unsigned int i = 0; i < nTileRows; i++ )
            {
                memcpy( &(mtx.GetData()[haloWidth + t*nTileRows + i][haloWidth]),
                        &(mtx.GetData()[haloWidth + i][haloWidth]),
                        (mtx.GetNumColumns() - 2*haloWidth) * sizeof(T) );
            }
        }
    }

    // initialize halo
    for( unsigned int i = 0; i < mtx.GetNumRows(); i++ )
    {
        for( unsigned int j = 0; j < mtx.GetNumColumns(); j++ )
        {
            bool inHalo = false;

            if( (i < haloWidth) || (i > mtx.GetNumRows() - 1 - haloWidth) )
            {
                inHalo = true;
            }
            else if( (j < haloWidth) || (j > mtx.GetNumColumns() - 1 - haloWidth) )
            {
                inHalo = true;
            }

            if( inHalo )
            {
                mtx.GetData()[i][j] = haloVal;
            }
        }
    }
}
ModifyConstraintSubactivitiesPreferredStartingTimesForm::ModifyConstraintSubactivitiesPreferredStartingTimesForm(QWidget* parent, ConstraintSubactivitiesPreferredStartingTimes* ctr): QDialog(parent)
{
	setupUi(this);

	okPushButton->setDefault(true);

	connect(preferredTimesTable, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(itemClicked(QTableWidgetItem*)));
	connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
	connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
	connect(setAllAllowedPushButton, SIGNAL(clicked()), this, SLOT(setAllSlotsAllowed()));
	connect(setAllNotAllowedPushButton, SIGNAL(clicked()), this, SLOT(setAllSlotsNotAllowed()));

	centerWidgetOnScreen(this);
	restoreFETDialogGeometry(this);
	
	QSize tmp1=teachersComboBox->minimumSizeHint();
	Q_UNUSED(tmp1);
	QSize tmp2=studentsComboBox->minimumSizeHint();
	Q_UNUSED(tmp2);
	QSize tmp3=subjectsComboBox->minimumSizeHint();
	Q_UNUSED(tmp3);
	QSize tmp4=activityTagsComboBox->minimumSizeHint();
	Q_UNUSED(tmp4);

	this->_ctr=ctr;

	updateTeachersComboBox();
	updateStudentsComboBox(parent);
	updateSubjectsComboBox();
	updateActivityTagsComboBox();
	
	componentNumberSpinBox->setMinimum(1);
	componentNumberSpinBox->setMaximum(MAX_SPLIT_OF_AN_ACTIVITY);
	componentNumberSpinBox->setValue(this->_ctr->componentNumber);

	preferredTimesTable->setRowCount(gt.rules.nHoursPerDay);
	preferredTimesTable->setColumnCount(gt.rules.nDaysPerWeek);

	for(int j=0; j<gt.rules.nDaysPerWeek; j++){
		QTableWidgetItem* item=new QTableWidgetItem(gt.rules.daysOfTheWeek[j]);
		preferredTimesTable->setHorizontalHeaderItem(j, item);
	}
	for(int i=0; i<gt.rules.nHoursPerDay; i++){
		QTableWidgetItem* item=new QTableWidgetItem(gt.rules.hoursOfTheDay[i]);
		preferredTimesTable->setVerticalHeaderItem(i, item);
	}

	Matrix2D<bool> currentMatrix;
	currentMatrix.resize(gt.rules.nHoursPerDay, gt.rules.nDaysPerWeek);
	//bool currentMatrix[MAX_HOURS_PER_DAY][MAX_DAYS_PER_WEEK];
	for(int i=0; i<gt.rules.nHoursPerDay; i++)
		for(int j=0; j<gt.rules.nDaysPerWeek; j++)
			currentMatrix[i][j]=false;
	for(int k=0; k<ctr->nPreferredStartingTimes_L; k++){
		if(ctr->hours_L[k]==-1 || ctr->days_L[k]==-1)
			assert(0);
		int i=ctr->hours_L[k];
		int j=ctr->days_L[k];
		if(i>=0 && i<gt.rules.nHoursPerDay && j>=0 && j<gt.rules.nDaysPerWeek)
			currentMatrix[i][j]=true;
	}

	for(int i=0; i<gt.rules.nHoursPerDay; i++)
		for(int j=0; j<gt.rules.nDaysPerWeek; j++){
			QTableWidgetItem* item= new QTableWidgetItem();
			item->setTextAlignment(Qt::AlignCenter);
			item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
			preferredTimesTable->setItem(i, j, item);

			if(!currentMatrix[i][j])
				item->setText(NO);
			else
				item->setText(YES);
				
			colorItem(item);
		}
		
	preferredTimesTable->resizeRowsToContents();
				
	weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));

	connect(preferredTimesTable->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(horizontalHeaderClicked(int)));
	connect(preferredTimesTable->verticalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(verticalHeaderClicked(int)));

	preferredTimesTable->setSelectionMode(QAbstractItemView::NoSelection);
	
	tableWidgetUpdateBug(preferredTimesTable);
	
	setStretchAvailabilityTableNicely(preferredTimesTable);
}