Ejemplo n.º 1
0
// Matrix with 'r' rows and 'c' columns and filled with zeros and ones on the diagonal
void Matrix::setMatrix(const unsigned int r, const unsigned int c)
{
   emptyMatrix();

   rows = r;
   cols = c;
   unsigned int arraySize = rows*cols;
   mda = new double[arraySize];

   for (unsigned int i = 0; i < arraySize; i++) {
      mda[i] = 0.0;
   }
}
Ejemplo n.º 2
0
void Matrix::copyData(const Matrix& org, const bool)
{
   BaseClass::copyData(org);

   emptyMatrix();

   rows = org.rows;
   cols = org.cols;
   unsigned int arraySize = rows*cols;
   mda = new double[arraySize];

   for (unsigned int idx = 0; idx < arraySize; idx++) {
      mda[idx] = org.mda[idx];
   }
}
Ejemplo n.º 3
0
// Matrix with 'r' rows and 'c' columns and filled with 'dataSize' values from the 'data' array.
void Matrix::setMatrix(const unsigned int r, const unsigned int c, const float* const data, const unsigned int dataSize)
{
   emptyMatrix();

   rows = r;
   cols = c;
   unsigned int mdaSize = rows*cols;
   mda = new double[mdaSize];

   unsigned int idx = 0;
   while (idx < mdaSize && idx < dataSize) {
      mda[idx] = data[idx];
      idx++;
   }
   while (idx < mdaSize) {
      mda[idx++] = 0;
   }
}
Ejemplo n.º 4
0
int main()
{
//    double m[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
//    double m[] = {1, 2, -3, 4, 1, 2, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};
//    double m[] = {4, 1, -2, 2, 1, 2, 0, 1, -2, 0, 3, -2, 2, 1, -2, -1};
//    double m[] = {2,0,0,0,3,4,0,4,9};
//    double m[] = {2, 0, 0, 0, 1, 4, 0, 0, 0, 1, 3, 0, 0, 0, 1, 5};
    double m[] = {2, 1, 0, 2, 1, 2, 1, 0, 0, 1, 3, 1, 2, 0, 1, 3};
//    double z[] =  {2.2615, -0.0923, 0, 0,  -0.0923, 1.1829, 0.8958, 0 , 0, 0.8958, 5.5556, 3.0000 , 0, 0, 3.0000, -1.0000};
    double b[] = {3, 5, 7, 11, 1, 2, 3, 4};

    Matrix x(4, 4, m, "M");
//    Matrix h(4, 4, z, "H");
    Matrix emptyMatrix(0, 0, "Empty Matrix");
    Matrix y;
    Matrix B(2, 4, b, "B");

    y = x;
    y.print("before");
    y.transposeSelf();
    y.print("after");

    double *d;

    y.eigenSystem(d);
    
    Matrix dd(1, 4, d, "D");  // convert double * to matrix
    dd.print("eigen values");

    y.print("eigen vectors");

    x.print();
    B = B.transpose();
    x.solve(B);
    x.print("inverse");
    B.print("ans");

    x.inverse();
    x.print("re-inverse");
//    x.LU();
//    x.print("original");

    return 0;
}
Ejemplo n.º 5
0
int * generateRandomMatrix(const unsigned char _width,
                          const unsigned char _height)
{
  int * matrix = NULL;
  unsigned long int cicles = 0;
  register int i = 0;
  
  matrix = emptyMatrix(_width, _height);
  if (!matrix)
  {
    return NULL;
  }

  for (i = 0; i < _height * _width; i++)
  {
    cicles = clock();
    srandom(cicles);
    *(matrix + i) = ((int)random()) % 0xff;
  }
  return matrix;
}
Ejemplo n.º 6
0
SSMProcess* GIOutputModeler::compute()
{
    const int g = - Lb(m_ptrData->getDistribution(1,1));
    const int h = Ub(m_ptrData->getDistribution(1,1));
    const ivector u = m_ptrData->getDistribution(1,1);

    // perform Wiener-Hopf factorization
    ComputationParameters whParams;
    whParams.setInt(SMPWienerHopf::PARAM_NUMITERATIONS, 200);
    whParams.setReal(SMPWienerHopf::PARAM_EPSILON, real(1e-14));
    SMPWienerHopf wh(m_ptrData, whParams);
    const ISMPWHFactors* whFactors = wh.compute();

    ivector l = whFactors->getIdleDistributions().getVectorAt(1,1);
    ivector v = whFactors->getPhaseDistributions().getVectorAt(1,1);

    // create SMP model as described by Haßlinger
    // transition probabilities
    imatrix trans = IMatrixUtils::zeros(1,2,1,2);

    // a_00
    for(int i = 1; i<=g; ++i)
        trans[1][1] += u[-i];

    // E(N) = (I-V(1))^-1
    interval v1(0.0);
    for(int i = Lb(v); i<=Ub(v); ++i)
        v1 += v[i];
    interval e_n = 1.0 / (1.0 - v1);

    // a_11
    trans[2][2] = 1.0 - ((1.0 - trans[1][1])/(e_n - 1.0));

    // a_01, a_10
    trans[1][2] = 1.0 - trans[1][1];
    trans[2][1] = 1.0 - trans[2][2];

    // END of transition probabilities.

    // I^(N=1) (z)
    ivector i_n_eq_1(1,g);
    for(int i = 1; i<=g; ++i)
    {
        i_n_eq_1[i] = u[-i] / trans[1][1];
    }

    // I^(N>1) (z)
    ivector i_n_gr_1(1,g);
    for(int i = 1; i<=g; ++i)
    {
        i_n_gr_1[i] = (l[i] - trans[1][1]*i_n_eq_1[i])/(1.0 - trans[1][1]);
    }

    // state-specific distributions
    ivector s = m_ptrData->getServiceProcess()->getDistribution(1,1);
    ivector a00 = IMatrixUtils::conv(i_n_eq_1, s);
    ivector a01 = s;
    ivector a10 = s;
    ivector a11 = IMatrixUtils::conv(i_n_gr_1, s);

    // determine bounds
    int lowerBound = Lb(s);
    int upperBound = Ub(s) + std::max<int>(Ub(i_n_eq_1), Ub(i_n_gr_1));

    IMatrixPolynomial distributions(lowerBound, upperBound,1,2,1,2);
    imatrix emptyMatrix(1,2,1,2);
    emptyMatrix[1][1] = interval(0.0);
    emptyMatrix[1][2] = interval(0.0);
    emptyMatrix[2][1] = interval(0.0);
    emptyMatrix[2][2] = interval(0.0);
    for(int i = lowerBound; i<=upperBound; ++i)
        distributions[i] = emptyMatrix;
    distributions.setVectorAt(1,1,a00);
    distributions.setVectorAt(1,2,a01);
    distributions.setVectorAt(2,1,a10);
    distributions.setVectorAt(2,2,a11);


    // create SMP model
    SMProcess outputModel(trans, distributions);

    // convert to SSMP model
    SSMProcess* ssmpOutputModel = new SSMProcess(outputModel);

    // return
    return ssmpOutputModel;
}
Ejemplo n.º 7
0
void Matrix::deleteData()
{
   emptyMatrix();
}