Example #1
0
gTexture::gTexture(int width, int height, gTexture::gImageDefaults aType)
: mWidth(width)
, mHeight(height)
{
	initialize();
	allocateSpace(aType, width, height);
}
MidiMessage::MidiMessage (const MidiMessage& other, const double newTimeStamp)
   : timeStamp (newTimeStamp), size (other.size)
{
    if (isHeapAllocated())
        memcpy (allocateSpace (size), other.getData(), (size_t) size);
    else
        packedData.allocatedData = other.packedData.allocatedData;
}
MidiMessage::MidiMessage (const void* const d, const int dataSize, const double t)
   : timeStamp (t), size (dataSize)
{
    jassert (dataSize > 0);
    // this checks that the length matches the data..
    jassert (dataSize > 3 || *(uint8*)d >= 0xf0 || getMessageLengthFromFirstByte (*(uint8*)d) == size);

    memcpy (allocateSpace (dataSize), d, (size_t) dataSize);
}
Example #4
0
/*
void gTexture::allocate(gImageDefaults aType, int width, int height, const void *data, bool mipMaps)
{
    mWidth = width;
    mHeight = height;
    allocate(aType, data, mipMaps);
}

void gTexture::allocate(gTexture::gImageDefaults aType, const void *data, bool mipMaps)
{
	switch (aType) {
		case gDepth:
			allocate(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT, data, mipMaps);
			break;
		case gData:
			allocate(GL_RGB32F_ARB, GL_RGB, GL_FLOAT, data, mipMaps);
			break;
		case gData4:
			allocate(GL_RGBA32F_ARB, GL_RGBA, GL_FLOAT, data, mipMaps);
            break;

		default:
			allocate(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, data, mipMaps);
			break;
	}
}

void gTexture::allocate(GLint internalFormat, GLint format, GLint type, const void *data, bool mipMaps)
{
	engage();
	
	mFormat = format;
	mType = type;
	
    if (data && mipMaps) {
        //glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0, mFormat, mType, data);
        //glGenerateMipmap(GL_TEXTURE_2D);
        gluBuild2DMipmaps(GL_TEXTURE_2D, internalFormat, mWidth, mHeight, mFormat, mType, data);
    } else {
        glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0, mFormat, mType, data);
    }
	
	disengage();
}
*/
void gTexture::allocateSpace(gImageDefaults aType, int width, int height)
{
    switch (aType) {
		case gDepth:
            allocateSpace(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT, width, height);
			break;
		case gData:
            allocateSpace(GL_RGB32F_ARB, GL_RGB, GL_FLOAT, width, height);
			break;
		case gData4:
            allocateSpace(GL_RGBA32F_ARB, GL_RGBA, GL_FLOAT, width, height);
            break;
            
		case gDefault: default:
            allocateSpace(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, width, height);
			break;
	}
}
Example #5
0
// Perform EM Algorithm
void EMClassifier::train() {
  allocateSpace();

  unsigned int iterations = 0;
  do {
    m_p = m_pnew;

    E_Step();

    M_Step();
  } while( !converged() );

  print();
}
MidiMessage::MidiMessage (const void* srcData, int sz, int& numBytesUsed, const uint8 lastStatusByte,
                          double t, bool sysexHasEmbeddedLength)
    : timeStamp (t)
{
    auto src = static_cast<const uint8*> (srcData);
    auto byte = (unsigned int) *src;

    if (byte < 0x80)
    {
        byte = (unsigned int) lastStatusByte;
        numBytesUsed = -1;
    }
    else
    {
        numBytesUsed = 0;
        --sz;
        ++src;
    }

    if (byte >= 0x80)
    {
        if (byte == 0xf0)
        {
            auto d = src;
            bool haveReadAllLengthBytes = ! sysexHasEmbeddedLength;
            int numVariableLengthSysexBytes = 0;

            while (d < src + sz)
            {
                if (*d >= 0x80)
                {
                    if (*d == 0xf7)
                    {
                        ++d;  // include the trailing 0xf7 when we hit it
                        break;
                    }

                    if (haveReadAllLengthBytes) // if we see a 0x80 bit set after the initial data length
                        break;                  // bytes, assume it's the end of the sysex

                    ++numVariableLengthSysexBytes;
                }
                else if (! haveReadAllLengthBytes)
                {
                    haveReadAllLengthBytes = true;
                    ++numVariableLengthSysexBytes;
                }

                ++d;
            }

            src += numVariableLengthSysexBytes;
            size = 1 + (int) (d - src);

            auto dest = allocateSpace (size);
            *dest = (uint8) byte;
            memcpy (dest + 1, src, (size_t) (size - 1));

            numBytesUsed += (numVariableLengthSysexBytes + size);  // (these aren't counted in the size)
        }
        else if (byte == 0xff)
        {
            int n;
            const int bytesLeft = readVariableLengthVal (src + 1, n);
            size = jmin (sz + 1, n + 2 + bytesLeft);

            auto dest = allocateSpace (size);
            *dest = (uint8) byte;
            memcpy (dest + 1, src, (size_t) size - 1);

            numBytesUsed += size;
        }
        else
        {
            size = getMessageLengthFromFirstByte ((uint8) byte);
            packedData.asBytes[0] = (uint8) byte;

            if (size > 1)
            {
                packedData.asBytes[1] = (sz > 0 ? src[0] : 0);

                if (size > 2)
                    packedData.asBytes[2] = (sz > 1 ? src[1] : 0);
            }

            numBytesUsed += jmin (size, sz + 1);
        }
    }
    else
    {
        packedData.allocatedData = nullptr;
        size = 0;
    }
}
Example #7
0
Structure::Structure(string &filename,Random &ran,int oneDelta)
{
  ifstream in;
  in.open(filename.c_str());
//  if (in.fail())
//    {
//      //cout << "ERROR: Unable to open file " << filename.c_str() << ". Aborting.\n\n";
//      //exit(-1);
//    }

  Q = 0;
  in >> Q;
//  if (Q <= 0)
//    {
//      cout << "ERROR: Illegal number of studies, Q = " << Q << ", read in file " << filename << ". Aborting.\n\n";
//      exit(-1);
//    }
  S.resize(Q);

  vector<string> fileData(Q);
  vector<string> filePsi(Q);
  int q;
  for (q = 0; q < Q; q++)
    {
      in >> fileData[q];
//      if (in.fail())
//	{
//	  cout << "ERROR: Unable to read expression value file number " << q + 1 << " from file " << filename << ". Aborting.\n\n";
//	  exit(-1);
//	}

      in >> filePsi[q];
//      if (in.fail())
//	{
//	  cout << "ERROR: Unable to read clinical value file number " << q + 1 << " from file " << filename << ". Aborting.\n\n";
//	  exit(-1);
//	}
    }
  in.close();

  for (q = 0; q < Q; q++)
    {
      ifstream inData;
      inData.open(fileData[q].c_str());
//      if (inData.fail())
//	{
//	  cout << "ERROR: Error when reading " << filename.c_str() << ". Unable to open file " << fileData[q] << ". Aborting.\n\n";
//	  exit(-1);
//	}

      ifstream inPsi;
      inPsi.open(filePsi[q].c_str());
//      if (inPsi.fail())
//	{
//	  cout << "ERROR: Error when reading " << filename.c_str() << ". Unable to open file " << filePsi[q] << ". Aborting.\n\n";
//	  exit(-1);
//	}

      int GG = 0;
      inData >> GG;
//      if (GG <= 0)
//	{
//	  cout << "ERROR: Illegal number of genes, G = " << G << ", read in file " << fileData[q] << ". Aborting.\n\n";
//	  exit(-1);
//	}
      if (q == 0)
	G = GG;
      //      else
      //	{
//	  if (GG != G)
//	    {
//	      cout << "ERROR: Inconsistent number of genes in file " << fileData[0] << " and file " << fileData[q] << ". Aborting.\n\n";
//	      exit(-1);
//	    }
//	}


      S[q] = 0;
      inData >> S[q];
//      if (S[q] <= 0)
//	{
//	  cout << "ERROR: Illegal number of samples, S = " << S[q] << ", read from " << fileData[q] << ". Aborting.\n\n";
//	  exit(-1);
//	}
      int SS = 0;
      inPsi >> SS;
//      if (SS <= 0)
//	{
//	  cout << "ERROR: Illegal number of samples, S = " << SS << ", read from " << filePsi[q] << ". Aborting.\n\n";
//	  exit(-1);
//	}
//      if (SS != S[q])
//	{
//	  cout << "ERROR: Inconsistent number of samples read in " << fileData[q] << " and " << filePsi[q] << ". Aborting.\n\n";
//	  exit(-1);
//	}
      inData.close();
      inPsi.close();
    }

  //
  // Print data size
  //

//  cout << "Size of data set:\n\n";
//  cout << "P: " << Q << "\n";
//  cout << "G: " << G << "\n";
//  cout << "S: ";
//  for (q = 0; q < Q; q++)
//    cout << S[q] << " ";
//  cout << "\n\n\n";

  //
  // allocate neccesary space
  //

  allocateSpace();

  //
  // read expression values from files
  //

  for (q = 0; q < Q; q++)
    {
      ifstream in;
      in.open(fileData[q].c_str());
      int GG,SS;
      in >> GG;
      in >> SS;
      int g,s;
      for (g = 0; g < G; g++)
	for (s = 0; s < S[q]; s++)
	  in >> x[q][g][s];

      in.close();
    }

  //
  // read clinical variables from files
  //

  for (q = 0; q < Q; q++)
    {
      ifstream in;
      in.open(filePsi[q].c_str());
      int SS;
      in >> SS;
      int s;
      for (s = 0; s < S[q]; s++)
	{
	  in >> psi[q][s];
//	  if (psi[q][s] != 0 && psi[q][s] != 1)
//	    {
//	      cout << "ERROR: value different from 0 or 1 found in \"" << filePsi[q] << "\". Aborting.\n";
//	      exit(-1);
//	    }
	}

      in.close();
    }

  //
  // initialise remaining variables
  //

  initialiseVariables(ran,oneDelta);

  return;
}
Example #8
0
Structure::Structure(int Q,int G,int *S,double *x,int *psi,Random &ran,int checkinput,int oneDelta)
{
  this->Q = Q;
  this->G = G;
  this->S.resize(this->Q);
  int q;
  for (q = 0; q < this->Q; q++)
    this->S[q] = S[q];

  //
  // allocate necessary space
  //

  allocateSpace();

  //
  // set expression values
  //

  int g,s;
  int nr = 0;
  for (q = 0; q < this->Q; q++)
    for (g = 0; g < this->G; g++)
      for (s = 0; s < this->S[q]; s++)
	{
	  this->x[q][g][s] = x[nr];
	  nr++;
	}

  //
  // set clinical variables
  //

  nr = 0;
  for (q = 0; q < this->Q; q++)
    for (s = 0; s < this->S[q]; s++)
      {
	this->psi[q][s] = psi[nr];
	nr++;
      }

  //  if (checkinput)
  //    {
      //cout << "Expression values:\n";
//      for (q = 0; q < this->Q; q++)
//	{
//	  cout << "first values of study " << q << "\n";
//	  cout << this->x[q][0][0] << " " << this->x[q][0][1] << "\n";
//	  cout << this->x[q][1][0] << " " << this->x[q][1][1] << "\n";
//	}
//      cout << "\n";

//      cout << "Clinical values:\n";
//      for (q = 0; q < this->Q; q++)
//	{
//	  cout << "study " << q << ": ";
//	  for (s = 0; s < this->S[q]; s++)
//	    cout << this->psi[q][s] << " ";
//	  cout << "\n";
//	}
//      cout << "\n";
//    }

  //
  // initialise remaining parameters
  //

  initialiseVariables(ran,oneDelta);

  return;
}
Example #9
0
/*************************************************************
 *************************************************************
 Initializes a chromosome with random values without adding rule
 *************************************************************
 **************************************************************/
void chromosome::inizializewithoutrule() {
	rank = 1;
	crowd_dist = 0;
	//unsigned maxpart;
	int ingressi=numVar;
	numFeat=0;
	if (CLASSIFICATION)
		ingressi--;

	allocateSpace();

	float space;
	bool trovato;
	for (int i = 0; i < ingressi; i++)
	{	if (TuningPW)
		{	space = (double) 1 / (numParts[i]-2 + 1);// half of support of a fuzzy set in a uniform partition
			for (int j = 0; j < numParts[i]-2 ; j++) {
				if (vinc == true) //constrained version
				{
					pwLT_lim[0][i][j] = space * (j + 1) - space / 2;
					pwLT_lim[1][i][j] = space * (j + 1) + space / 2
							- (double) 1 / GrDig;
					//pwLT[i][j] = Randint(pwLT_lim[0][i][j] * GrDig,	pwLT_lim[1][i][j] * GrDig);
					pwLT[i][j]= space*(j+1)*GrDig;
					pwLT[i][j] /= (double) GrDig;
				} else {
					pwLT_lim[0][i][j] = 0.01;
					pwLT_lim[1][i][j] = 0.99;
					do {
						pwLT[i][j] = Randint(1, GrDig - 1);
						pwLT[i][j] /= (double) GrDig;
						trovato = false;
						for (int k = 0; k < j; k++)
							if (pwLT[i][j] == 0 || pwLT[i][j] == 1 || (j != 0
									&& abs(pwLT[i][j] - pwLT[i][k])
											< (double) (1 / GrDig))) //to ensure that two genes cannot be equal and
							{
								trovato = true;
								break;
							}
					} while (trovato);

				}

				pwLT_lim[2][i][j] = space * (j + 1);// centroids of the uniform partition in [0,1]
			}
			if (!vinc)
				ordina(pwLT[i], numParts[i]-2 );
		}
		for (int i=0;i<numVar;i++)
			realPart[i]=numParts[i];

	}

	numRul = realNumRule = 0;
	for (int i = 0; i < maxRule; i++)
		for (int j = 0; j < numVar;j++)
			matR[i][j] = 0;

	for (int i = 0; i < sizeObjTot; i++)
	{	objTot[i] = 56456465;
		objAlg[i]=56456465;
	}
}