void NonGradient::optimize_vertex_positions(PatchData &pd, 
                                            MsqError &err)
{
  MSQ_FUNCTION_TIMER( "NonGradient::optimize_vertex_positions" );
  int numRow = getDimension();
  int numCol = numRow+1;  
  std::vector<double> height(numCol); 

  for(int col = 0; col < numCol; col++)
  {
    height[col] =  evaluate(&simplex[col*numRow], pd, err);//  eval patch stuff
  }
  if(mNonGradDebug > 0)
  {
    printSimplex( simplex, height );
  }

  // standardization
  TerminationCriterion* term_crit=get_inner_termination_criterion();
  int maxNumEval = getMaxNumEval();
  double threshold = getThreshold();
//  double ftol = getTolerance();
  int ilo = 0;  //height[ilo]<=...
  int inhi = 0; //...<=height[inhi]<=
  int ihi = 0;  //<=height[ihi] 
//  double rtol = 2.*ftol;
  double ysave;
  double ytry;
  bool afterEvaluation = false;
  std::vector<double> rowSum(numRow);
  getRowSum( numRow, numCol, simplex, rowSum);
  while( !( term_crit->terminate() ) )
  {

    if(mNonGradDebug > 0)
    {
      printSimplex( simplex, height );
    }
    //std::cout << "rtol " << rtol << " ftol " << ftol << " MesquiteIter " << term_crit->get_iteration_count() << " Done " << term_crit->terminate() << std::endl;

    if( afterEvaluation )   
    {
      // reflect highPt through opposite face
      // height[0] may vanish
/*
      if( !testRowSum( numRow, numCol, &simplex[0], &rowSum[0]) )
      {
        // Before uncommenting here and ... 
        //MSQ_SETERR(err)("Internal check sum test A failed", MsqError::INTERNAL_ERROR);
        //MSQ_ERRRTN(err);
      }
*/
      ytry=amotry(simplex,height,&rowSum[0],ihi,-1.0, pd, err);
/*
      if( !testRowSum( numRow, numCol, &simplex[0], &rowSum[0]) )
      {
         // ... here, determine a maxVal majorizing the previous as well as the current simplex.
         //MSQ_SETERR(err)("Internal check sum test B failed", MsqError::INTERNAL_ERROR);
         //MSQ_ERRRTN(err);
      }   
*/
  
/*
      if( height[0] == 0.)
      {
         MSQ_SETERR(err)("(B) Zero objective function value", MsqError::INTERNAL_ERROR);
         exit(-1);
      }
*/
      if (ytry <= height[ilo])   
      {
        ytry=amotry(simplex,height,&rowSum[0],ihi,-2.0,pd,err);
        if( mNonGradDebug >= 3 ) 
        {      
         std::cout << "Reflect and Expand from highPt " << ytry << std::endl;
        }      
        //MSQ_PRINT(3)("Reflect and Expand from highPt : %e\n",ytry);
      }
      else 
      {
        if (ytry >= height[inhi]) 
        {
          ysave=height[ihi]; // Contract along highPt
          ytry=amotry(simplex,height,&rowSum[0],ihi,0.5,pd,err);
          if (ytry >= ysave)
          { // contract all directions toward lowPt
            for (int col=0;col<numCol;col++)
            {
              if (col != ilo)
              {
                for (int row=0;row<numRow;row++)
                {
                  rowSum[row]=0.5*(simplex[row+col*numRow]+simplex[row+ilo*numRow]);
                  simplex[row+col*numRow]=rowSum[row];
                }
                height[col] = evaluate(&rowSum[0], pd, err); 
                if( mNonGradDebug >= 3 ) 
                {      
                  std::cout << "Contract all directions toward lowPt value( " << col << " ) = " << height[col] << " ilo = " << ilo << std::endl;
                }      
                //MSQ_PRINT(3)("Contract all directions toward lowPt value( %d ) = %e    ilo = %d\n", col, height[col], ilo);
              }
            }
          }
        }   
      } // ytri > h(ilo) 
    } // after evaluation
    ilo=1; // conditional operator or inline if 
    ihi = height[0] > height[1] ? (inhi=1,0) : (inhi=0,1);
    for (int col=0;col<numCol;col++)
    {
      if (height[col] <= height[ilo])
      {
        ilo=col;  // ilo := argmin height
      }
      if (height[col] > height[ihi])
      {
        inhi=ihi;
        ihi=col;
      } 
      else  // height[ihi] >= height[col]
        if (col != ihi && height[col] > height[inhi] ) inhi=col;
    }
//    rtol=2.0*fabs( height[ihi]-height[ilo] )/
//         ( fabs(height[ihi])+fabs(height[ilo])+threshold );
    afterEvaluation = true;
  } //  while not converged 

  // Always set to current best mesh.
  { 
    if( ilo != 0 )
    {
      double yTemp = height[0];
      height[0] = height[ilo]; // height dimension numCol
      height[ilo] = yTemp;
      for (int row=1;row<numRow;row++)
      { 
          yTemp = simplex[row];
          simplex[row] = simplex[row+ilo*numRow];
          simplex[row+ilo*numRow] = yTemp;
      }
    }
  }
  if( pd.num_free_vertices() > 1 )
  {
    MSQ_SETERR(err)("Only one free vertex per patch implemented", MsqError::NOT_IMPLEMENTED);
  }

  Vector3D newPoint( &simplex[0] ); 
  size_t vertexIndex = 0; // fix c.f. freeVertexIndex
  pd.set_vertex_coordinates( newPoint, vertexIndex, err ); 
  pd.snap_vertex_to_domain( vertexIndex, err );
  if( term_crit->terminate() )
  {
    if( mNonGradDebug >= 1 ) 
    {      
         std::cout << "Optimization Termination OptStatus: Max Iter Exceeded" << std::endl;
    }      
    //MSQ_PRINT(1)("Optimization Termination OptStatus: Max Iter Exceeded\n"); 
  }
}
void GaborFilter::getIntegral(const cv::Mat& matrix, cv::Mat& integral) {
	integral.create(matrix.size(), CV_32F);

	cv::Mat rowSum(matrix.size(), CV_32F);
	float* prevRowSumPtr = NULL;
	for (int y = 0; y < matrix.rows; ++y) {
		const float* matrixPtr = matrix.ptr<float> (y);
		float* rowSumPtr = rowSum.ptr<float> (y);
		float* integralPtr = integral.ptr<float> (y);

		for (int x = 0; x < matrix.cols; ++x) {
			rowSumPtr[x] = matrixPtr[x];

			if (prevRowSumPtr) {
				rowSumPtr[x] += prevRowSumPtr[x];
			}

			integralPtr[x] = rowSumPtr[x];

			if (x > 0) {
				integralPtr[x] += integralPtr[x - 1];
			}
		}

		prevRowSumPtr = rowSumPtr;
	}
}
bool
NonGradient::testRowSum( int numRow, int numCol, double* matrix, double* oldRowSum)
{
  bool same = true;
  std::vector<double> rowSum(numRow,0.);
  double maxVal = 0.;
  for (int col=0;col<numCol;col++)    
  {
    for (int row=0;row<numRow;row++)
    {
      rowSum[row] += matrix[row+col*numRow];
      if( fabs( matrix[row+col*numRow] ) > maxVal )
      {
         maxVal = fabs( matrix[row+col*numRow] );
      }
    }
  }
  double machEps = 1.e-14 * static_cast<double>(numRow); // better to use system parameters
  double upperBound = machEps * maxVal + 1.e-15;
  for (int row=0;row<numRow;row++)
  {
    if( fabs( rowSum[row] -  oldRowSum[row]) >  upperBound ) 
    { 
         same = false;
         if( mNonGradDebug >= 2 )
         {
           std::cout << " Warning: NonGradient Row Sum " << row << " Test: value " << rowSum[row] << " Discrepancy " <<  rowSum[row] -  oldRowSum[row] << " maxVal " << maxVal << " numRow " << numRow << " numCol " << numCol <<std::endl;
         }
         MSQ_PRINT(2)("NonGradient Row Sum [%d] Test failure: value %22.15e  difference %22.15e \n", row, rowSum[row], rowSum[row] -  oldRowSum[row]); 
    }
  }
  return(same);
}
Пример #4
0
void ConfusionMatrix::printPrecisionRecall(const char *header) const {
  if (header == NULL) {
    LOG(INFO) << "--- class-specific recall/precision ---";
  } else {
    LOG(INFO) << header;
  }

  // recall
  LOG(INFO) << ROW_BEGIN;
  for (size_t i = 0; i < _matrix.size(); i++) {
    if (i > 0) {
      LOG(INFO) << COL_SEP;
    }
    double r = (_matrix[i].size() > i) ? 
        (double)_matrix[i][i] / (double)rowSum(i) : 0.0;
    LOG(INFO) <<  r;
  }
  LOG(INFO) << ROW_END;

  // precision
  LOG(INFO) << ROW_BEGIN;
  for (size_t i = 0; i < _matrix.size(); i++) {
    if (i > 0) {
      LOG(INFO) << COL_SEP;
    }
    double p = (_matrix[i].size() > i) ? 
         (double)_matrix[i][i] / (double)colSum(i) : 1.0;
    LOG(INFO) << p;
  }
  LOG(INFO) << ROW_END;
}
Пример #5
0
double ConfusionMatrix::jaccard(int n) const {
  CHECK((_matrix.size() > (size_t)n) && (_matrix[n].size() > (size_t)n));
  const double intersectionSize = (double)_matrix[n][n];
  const double unionSize = (double)(rowSum(n) + colSum(n) - _matrix[n][n]);
  return (intersectionSize == unionSize) ? 1.0 :
    intersectionSize / unionSize;
}
Пример #6
0
float smallTable::getMarkov(int row, int col)
{
    float sum = rowSum(row);
    float ratio(0);
    if(sum)
     ratio = (float)(myTable[row][col]/sum);
    return ratio;
}
Пример #7
0
 int minimumTotal(vector<vector<int>>& triangle) {
     if (triangle.size() == 0)
         return 0;
     vector<vector<int> > minSum;
     for (int i = 0; i < triangle.size(); ++i)
     {
         vector<int> rowSum(triangle[i].size(), INT_MAX);
         minSum.push_back(rowSum);
     }
     minPathSum(0, triangle, 0, minSum);
     return minSum[0][0];
 }
Пример #8
0
typename MaxNorm<VectorType, MatrixType>::ScalarType
MaxNorm<VectorType, MatrixType>::operator()(const MatrixType &A) const {
  
  ScalarType maximum(0.);
  for(int i=0;i<A.numberOfRows();i++) {
    // Computes sum of absolute values of entries in given row
    ScalarType rowSum(0.);
    for(int j=0; j<A.numberOfColumns(); ++j){
      rowSum += capd::abs(A[i][j]);
    }
    maximum = capd::max(maximum, rowSum);  
  }
  return maximum;
}
Пример #9
0
double ConfusionMatrix::avgJaccard() const {
  double totalJaccard = 0.0;
  for (size_t i = 0; i < _matrix.size(); i++) {
    if (_matrix[i].size() <= i) continue;
    const double intersectionSize = (double)_matrix[i][i];
    const double unionSize = (double)(rowSum(i) + colSum(i) - _matrix[i][i]);
    if (intersectionSize == unionSize) {
      // avoid divide by zero
      totalJaccard += 1.0;
    } else {
      totalJaccard += intersectionSize / unionSize;
    }
  }
  
  return totalJaccard / (double)_matrix.size();
}
Пример #10
0
void ConfusionMatrix::printJaccard(const char *header) const {
  if (header == NULL) {
    LOG(INFO) << "--- class-specific Jaccard coefficient ---";
  } else {
    LOG(INFO) << header;
  }

  LOG(INFO) << ROW_BEGIN;
  for (size_t i = 0; i < _matrix.size(); i++) {
    if (i > 0) {
      LOG(INFO) << COL_SEP;
    }
    double p = (_matrix[i].size() > i) ? (double)_matrix[i][i] /
         (double)(rowSum(i) + colSum(i) - _matrix[i][i]) : 0.0;
    LOG(INFO) << p;
  }
  LOG(INFO) << ROW_END;
}
Пример #11
0
void ConfusionMatrix::printRowNormalized(const char *header) const {
  if (header == NULL) {
    LOG(INFO) << "--- confusion matrix: (actual, predicted) ---";
  } else {
    LOG(INFO) << header;
  }
  for (size_t i = 0; i < _matrix.size(); i++) {
    double total = rowSum(i);
    LOG(INFO) << ROW_BEGIN;
    for (size_t j = 0; j < _matrix[i].size(); j++) {
      if (j > 0) {
	LOG(INFO) << COL_SEP;
      }
      LOG(INFO) << ((double)_matrix[i][j] / total);
    }
    LOG(INFO) << ROW_END;
  }
}
Пример #12
0
void SystemMatrix::makeZeroRowSums(double* left_over)
{
    const dim_t n = pattern->getNumOutput();
    const dim_t nblk = block_size;
    const dim_t blk = row_block_size;
    const index_t* main_ptr = borrowMainDiagonalPointer();

    rowSum(left_over);
    // left_over now holds the row sum

#pragma omp parallel for
    for (index_t ir=0; ir<n; ir++) {
        for (index_t ib=0; ib<blk; ib++) {
            const index_t irow = ib+blk*ir;
            const double rtmp2 = mainBlock->val[main_ptr[ir]*nblk+ib+blk*ib];
            const double rtmp1 = rtmp2-left_over[irow];
            mainBlock->val[main_ptr[ir]*nblk+ib+blk*ib] = rtmp1;
            left_over[irow]=rtmp2-rtmp1;
        }
    }
}
Пример #13
0
void ConfusionMatrix::printF1Score(const char *header) const {
  if (header == NULL) {
    LOG(INFO) << "--- class-specific F1 score ---";
  } else {
    LOG(INFO) << header;
  }

  LOG(INFO) << ROW_BEGIN;
  for (size_t i = 0; i < _matrix.size(); i++) {
    if (i > 0) {
      LOG(INFO) << COL_SEP;
    }
    // recall
    double r = (_matrix[i].size() > i) ? 
        (double)_matrix[i][i] / (double)rowSum(i) : 0.0;
    // precision
    double p = (_matrix[i].size() > i) ? 
        (double)_matrix[i][i] / (double)colSum(i) : 1.0;
    LOG(INFO) << ((2.0 * p * r) / (p + r));
  }
  LOG(INFO) << ROW_END;
}
Пример #14
0
double ConfusionMatrix::avgRecall(const bool strict) const {
  double totalRecall = 0.0;
  int numClasses = 0;
  for (size_t i = 0; i < _matrix.size(); i++) {
    if (_matrix[i].size() > i) {
      const double classSize = (double)rowSum(i);
      if (classSize > 0.0) {
	totalRecall += (double)_matrix[i][i] / classSize;
	numClasses += 1;
      }
    }
  }
  
  if (strict && numClasses != (int)_matrix.size()) {
    LOG(FATAL) << "not all classes represented in avgRecall()";
  }

  if (numClasses == 0) {
    return 0;
  } else {
    return totalRecall / (double)numClasses;
  }
}
Пример #15
0
boolean isCassette(struct altGraphX *ag, bool **em,  int vs, int ve1, int ve2,
		    int *altBpStartV, int *altBpEndV, int *startV, int *endV)
/* Return TRUE if SIMPLE cassette exon.
   Looking for pattern:
   he--->hs---->he---->hs
     \----------------/

   Use edgesInArea() to investigate that encompasses the common hard
   end and common hard start. Should only be 4 edges in area defined by
   splicing.
   sesese 
   012345 
  0  
  1  + +
  2   + 
  3    +
  4   
  5
*/
{
unsigned char *vTypes = ag->vTypes;
int i=0;
int numAltVerts = 4;
int *vPos = ag->vPositions;
/* Quick check. */
if(vTypes[vs] != ggHardEnd || vTypes[ve1] != ggHardStart || vTypes[ve2] != ggHardStart)
    return FALSE;

if(em[vs][ve1] && em[vs][ve2]) 
    {
    /* Try to find a hard end that connects ve1 and ve2. */
    for(i=0; i<ag->vertexCount; i++)
	{
	if(vTypes[i] == ggHardEnd && em[ve1][i] && em[i][ve2])
	    {
	    /* Make sure that our cassette only connect to downstream. otherwise not
	       so simple...*/
	    if(rowSum(em[i],ag->vTypes,ag->vertexCount) == 1 &&
	       rowSum(em[ve1],ag->vTypes,ag->vertexCount) == 1 &&
	       colSum(em, ag->vTypes, ag->vertexCount, ve1) == 1 &&
	       edgesInArea(ag,em,ve2-1,vs+1) == numAltVerts)
		{
		struct bed bedUp, bedDown, bedAlt;
		/* Initialize some beds for reporting. */
		*startV = findClosestUpstreamVertex(ag, em, vs);
		*endV = findClosestDownstreamVertex(ag, em, ve2);
		bedUp.chrom = bedDown.chrom = bedAlt.chrom = ag->tName;
		bedUp.name = bedDown.name = bedAlt.name = ag->name;
		bedUp.score = bedDown.score = bedAlt.score = altCassette;
		safef(bedUp.strand, sizeof(bedUp.strand), "%s", ag->strand);
		safef(bedDown.strand, sizeof(bedDown.strand), "%s", ag->strand);
		safef(bedAlt.strand, sizeof(bedDown.strand), "%s", ag->strand);
		/* Alt spliced region. */
		bedAlt.chromStart = vPos[ve1];
		bedAlt.chromEnd = vPos[i];

		/* Upstream/down stream */
		if(sameString(ag->strand, "+"))
		    {
		    bedUp.chromStart = vPos[ve1] - flankingSize;
		    bedUp.chromEnd = vPos[ve1];
		    bedDown.chromStart = vPos[i];
		    bedDown.chromEnd = vPos[i] + flankingSize;
		    }
		else 
		    {
		    bedDown.chromStart = vPos[ve1] - flankingSize;
		    bedDown.chromEnd = vPos[ve1];
		    bedUp.chromStart = vPos[i];
		    bedUp.chromEnd = vPos[i] + flankingSize;
		    }
		if(altRegion != NULL)
		    {
		    bedOutputN(&bedAlt, 6, altRegion, '\t','\n');
		    bedOutputN(&bedUp, 6, upStream100, '\t', '\n');
		    bedOutputN(&bedDown, 6, downStream100, '\t', '\n');
		    }
		*altBpStartV = ve1;
		*altBpEndV = i;
		return TRUE;
		}
	    }
	}
    }
return FALSE;
}
Пример #16
0
boolean isAlt5Prime(struct altGraphX *ag, bool **em,  int vs, int ve1, int ve2,
		    int *altBpStart, int *altBpEnd, int *termExonStart, int *termExonEnd)
/* Return TRUE if we have an edge pattern of:
   hs->he----->hs
     \-->he--/
   Which indicates two possible ends to an exon (alt 5' intron starts).

   Use edgesInArea() to investigate an area that begins in the rows with the common
   hard end and finishes with common hard end. 
   esees
   01234 (4 vertices involved in alt splicing)
  0  
  1  ++
  2    +
  3    +
  4   
*/
{
unsigned char *vTypes = ag->vTypes;
int i=0;
int numAltVerts = 4;
/* Quick check. */
if(vTypes[vs] != ggHardStart || vTypes[ve1] != ggHardEnd || vTypes[ve2] != ggHardEnd)
    return FALSE;

if(em[vs][ve1] && em[vs][ve2]) 
    {
    /* Try to find common start for the two hard ends. */
    for(i=0; i<ag->vertexCount; i++)
	{
	if(vTypes[i] == ggHardStart && em[ve1][i] && em[ve2][i])
	    {
	    /* Make sure that they only connect to that one hard start. */
	    if(rowSum(em[ve1],ag->vTypes,ag->vertexCount) == 1 &&
	       rowSum(em[ve2],ag->vTypes,ag->vertexCount) == 1 &&
	       edgesInArea(ag,em,i-1,vs+1) == numAltVerts)
		{
		int *vPos = ag->vPositions;
		struct bed bedUp, bedDown, bedAlt, bedConst;
		
		/* Report the first and last vertexes. */
		*termExonStart = i;
		*termExonEnd = findClosestDownstreamVertex(ag, em, i);
                /* Initialize some beds for reporting. */
		bedConst.chrom = bedUp.chrom = bedDown.chrom = bedAlt.chrom = ag->tName;
		bedConst.name = bedUp.name = bedDown.name = bedAlt.name = ag->name;
		if(sameString(ag->strand, "+"))
		    bedConst.score = bedUp.score = bedDown.score = bedAlt.score = alt5Prime;
		else
		    bedConst.score = bedUp.score = bedDown.score = bedAlt.score = alt3Prime;
		safef(bedConst.strand, sizeof(bedConst.strand), "%s", ag->strand);
		safef(bedUp.strand, sizeof(bedUp.strand), "%s", ag->strand);
		safef(bedDown.strand, sizeof(bedDown.strand), "%s", ag->strand);
		safef(bedAlt.strand, sizeof(bedDown.strand), "%s", ag->strand);

                /* Alt spliced region. */
		bedAlt.chromStart = vPos[ve1];
		bedAlt.chromEnd = vPos[ve2];
		bedConst.chromStart = vPos[vs];
		bedConst.chromEnd = vPos[ve1];

                /* Upstream/down stream */
		if(sameString(ag->strand, "+"))
		    {
		    bedDown.chromStart = vPos[ve2];
		    bedDown.chromEnd = vPos[ve2]+flankingSize;
		    bedUp.chromStart = vPos[vs]-flankingSize;
		    bedUp.chromEnd = vPos[vs];
		    }
		else 
		    {
		    bedUp.chromStart = vPos[ve2];
		    bedUp.chromEnd = vPos[ve2]+flankingSize;
		    bedDown.chromStart = vPos[vs]-flankingSize;
		    bedDown.chromEnd = vPos[vs];
		    }
		if(altRegion)
		    {
		    bedOutputN(&bedConst, 6, constRegion, '\t','\n');
		    bedOutputN(&bedAlt, 6, altRegion, '\t','\n');
		    bedOutputN(&bedDown, 6, downStream100, '\t', '\n');
		    bedOutputN(&bedUp, 6, upStream100, '\t', '\n');
		    }		
		*altBpStart = ve1;
		*altBpEnd = ve2;
		return TRUE;
		}
	    }
	}
    }
return FALSE;
}
Пример #17
0
void lookForAltSplicing(char *db, struct altGraphX *ag, struct altSpliceSite **aSpliceList, 
			int *altSpliceSites, int *altSpliceLoci, int *totalSpliceSites)
/* Walk throught the altGraphX graph and look for evidence of altSplicing. */
{
struct altSpliceSite *notAlt = NULL, *notAltList = NULL;
bool **em = altGraphXCreateEdgeMatrix(ag);
int vCount = ag->vertexCount;
unsigned char *vTypes = ag->vTypes;
int altSpliceSitesOrig = *altSpliceSites;
int i,j,k;
int altCount = 0;
occassionalDot();
totalLoci++;
for(i=0; i<vCount; i++)
    {
    struct altSpliceSite *aSplice = NULL;
    for(j=0; j<vCount; j++)
	{
	if(em[i][j] && areConsSplice(em, vCount, vTypes,i,j) && 
	   (agxEvCount(ag, i,j) >= minConfidence)) 
	    {
	    for(k=j+1; k<vCount; k++)
		{
		if(em[i][k] && areConsSplice(em, vCount, vTypes, i, k) &&
		   (agxEvCount(ag, i,k) >= minConfidence)) 
		    {
		    totalSplices++;
		    if(aSplice == NULL)
			{
			splicedLoci++;
			aSplice = initASplice(ag, em, i, j, k);

			(*altSpliceSites)++;
			}
		    else
			addSpliceSite(ag, em, aSplice, k);
		    }
		}
	    }
	/* Only want non alt-spliced exons for our controls.  Some of
	 these checks are historical and probably redundant....*/
	if(em[i][j] && 
	   rowSum(em[i], ag->vTypes, ag->vertexCount) == 1 &&
	   rowSum(em[j], ag->vTypes, ag->vertexCount) == 1 &&
	   colSum(em, ag->vTypes, ag->vertexCount, j) == 1 &&
	   colSum(em, ag->vTypes, ag->vertexCount, j) == 1 &&
	   altGraphXEdgeVertexType(ag, i, j) == ggExon &&
	   areHard(ag, i, j) && 
	   areConstitutive(ag, em, i, j))
	    {
	    notAlt = initASplice(ag, em, i, j, j);
	    if(altRegion != NULL) 
		outputControlExonBeds(ag, i, j);
	    slAddHead(&notAltList, notAlt);
	    } 
	}
    if(aSplice != NULL) 
	{
	if(altLogFile)
	    fprintf(altLogFile, "%s\n", ag->name);
	slAddHead(aSpliceList, aSplice);
	}
    /* If we have a simple splice classfy it and log it. */
    if(aSplice != NULL && aSplice->altCount == 2)
	{
	altTotalCount++;	
	fixOtherStrand(aSplice);
	logSpliceType(aSplice->spliceTypes[1], abs(aSplice->altBpEnds[1] - aSplice->altBpStarts[1]));
	if(aSplice->spliceTypes[1] == alt3Prime && (aSplice->altBpEnds[1] - aSplice->altBpStarts[1] == 3))
	    reportThreeBpBed(aSplice);
	if(doSScores)
	    fillInSscores(db, aSplice, 1);
	if(RData != NULL)
	    {
	    outputForR(aSplice, 1, RData);
	    }
	}
    /* Otherwise log it as altOther. Start at 1 as 0->1 is the first
     * splice, 1->2 is the first alt spliced.*/
    else if(aSplice != NULL)
	{
	for(altCount=1; altCount<aSplice->altCount; altCount++)
	    {
	    altTotalCount++;
	    altOtherCount++;
	    }
	}
    }
for(notAlt = notAltList; notAlt != NULL; notAlt = notAlt->next)
    {
    if(doSScores)
	fillInSscores(db, notAlt, 1);
    if(RData != NULL)
	{
	fixOtherStrand(notAlt);
	outputForR(notAlt, 1, RDataCont);
	}
    }
if(*altSpliceSites != altSpliceSitesOrig)
    (*altSpliceLoci)++;
altGraphXFreeEdgeMatrix(&em, vCount);
}
Пример #18
0
double ConfusionMatrix::recall(int n) const {
  CHECK(_matrix.size() > (size_t)n);
  return (_matrix[n].size() > (size_t)n) ?
    (double)_matrix[n][n] / (double)rowSum(n) : 0.0;
}
Пример #19
0
void Confusion_getEntropies (Confusion me, double *p_h, double *p_hx, double *p_hy, double *p_hygx, double *p_hxgy, double *p_uygx, double *p_uxgy, double *p_uxy) {
	double h = 0.0, hx = 0.0, hy = 0.0, hxgy = 0.0, hygx = 0.0, uygx = 0.0, uxgy = 0.0, uxy = 0.0;

	autoNUMvector<double> rowSum (1, my numberOfRows);
	autoNUMvector<double> colSum (1, my numberOfColumns);

	double sum = 0.0;
	for (long i = 1; i <= my numberOfRows; i++) {
		for (long j = 1; j <= my numberOfColumns; j++) {
			rowSum[i] += my data[i][j];
			colSum[j] += my data[i][j];
			sum += my data[i][j];
		}
	}
	for (long i = 1; i <= my numberOfRows; i++) {
		if (rowSum[i] > 0.0) {
			hy -= rowSum[i] / sum * NUMlog2 (rowSum[i] / sum);
		}
	}
	for (long j = 1; j <= my numberOfColumns; j++) {
		if (colSum[j] > 0.0) {
			hx -= colSum[j] / sum * NUMlog2 (colSum[j] / sum);
		}
	}
	for (long i = 1; i <= my numberOfRows; i++) {
		for (long j = 1; j <= my numberOfColumns; j++) {
			if (my data[i][j] > 0.0) {
				h -= my data[i][j] / sum * NUMlog2 (my data[i][j] / sum);
			}
		}
	}

	hygx = h - hx;
	hxgy = h - hy;
	uygx = (hy - hygx) / (hy + TINY);
	uxgy = (hx - hxgy) / (hx + TINY);
	uxy = 2.0 * (hx + hy - h) / (hx + hy + TINY);
	if (p_h) {
		*p_h  = h;
	}
	if (p_hx) {
		*p_hx  = hx;
	}
	if (p_hy) {
		*p_hy  = hy;
	}
	if (p_hygx) {
		*p_hygx  = hygx;
	}
	if (p_hxgy) {
		*p_hxgy  = hxgy;
	}
	if (p_uygx) {
		*p_uygx  = uygx;
	}
	if (p_uxgy) {
		*p_uxgy  = uxgy;
	}
	if (p_uxy) {
		*p_uxy  = uxy;
	}
}
int main (){
	int array[][3] = { {1}, {2, 3}, {3, 4, 5}};
	printArray(array);
	rowSum (array, 2);
	return 0;
}