Beispiel #1
0
void model_parameters::userfunction(void)
{
  obj_fun =0.0;
  int Gtype, L;
  FMpar = mfexp(logFM); // estimated F/M
  SL50 = mfexp(logSL50);
  Delta = mfexp(logDelta);
  Vul = 1.0/(1+mfexp(-log(19)*(LenBins-SL50)/Delta));
  MkL = Mk * pow(Linf/LenBins, Mpow);
  FkL = FMpar * Mk * Vul;
  for (Gtype=1;Gtype<=NGTG;Gtype++) {
	MKLMat(Gtype) = MkL + kslope*(DiffLinfs(Gtype) - Linf);
    ZKLMat(Gtype) = MKLMat(Gtype) + FkL;
	currMkL = MKLMat(Gtype);
	currZkL = ZKLMat(Gtype);
    PUnFished = 0;
    PFished = 0;
    NUnFished = 0;
    NFished = 0 ;
    PUnFished(1) = RecProbs(Gtype);
    PFished(1) = RecProbs(Gtype);
    GTGLinf = DiffLinfs(Gtype);
    for (L=2;L<=NLenMids+1;L++) {
     if (LenBins(L) < GTGLinf) {
       PUnFished(L) = PUnFished(L-1) * pow(((GTGLinf-LenBins(L))/(GTGLinf-LenBins(L-1))),currMkL(L-1));
       PFished(L) = PFished(L-1) * pow(((GTGLinf-LenBins(L))/(GTGLinf-LenBins(L-1))),currZkL(L-1));
     }
     if (LenBins(L) >= GTGLinf) {
       PUnFished(L) = 0;
       PFished(L) = 0;
     }
   }
   for (L=1;L<=NLenMids;L++) {
 	NUnFished(L)  = (PUnFished(L) - PUnFished(L+1))/currMkL(L);
 	NFished(L) =  (PFished(L) - PFished(L+1))/currZkL(L);
   }
  UnfishedMatrix(Gtype) =  NUnFished;
  FishedMatrix(Gtype) = NFished;
  EP0_gtg(Gtype) = sum(elem_prod(NUnFished, Fec));
  EPf_gtg(Gtype) = sum(elem_prod(NFished, Fec));
  }
  EP0 = sum(EP0_gtg);
  EPf = sum(EPf_gtg);
  SPR =  EPf/EP0;
  PredUnfishedComp = colsum(UnfishedMatrix);
  PredUnfishedComp = PredUnfishedComp/sum(PredUnfishedComp);
  // cout<<"hello"<<endl;
  PredFishedComp = colsum(FishedMatrix);
  PredFishedComp = PredFishedComp/sum(PredFishedComp);
  PredLenComp = colsum(FishedMatrix);
  PredLenComp =  elem_prod(PredLenComp,  1.0/(1+mfexp(-log(19)*(LenMids-SL50)/Delta)));
  PredLenComp = PredLenComp/sum(PredLenComp);
  SL95 = SL50 + Delta;
  obj_fun = -sum(elem_prod(ObsLength, log(elem_div(PredLenComp+0.00000001,ObsLength+0.00000001)))); // AP from ADMB living doc
}
void SetNewExtraColumnCount()
{
	int newcount;

	GetVisColumns();
	newcount=colsum(0,EXTRACOLUMNCOUNT-1);
	DBWriteContactSettingByte(NULL,CLUIFrameModule,"EnabledColumnCount",(BYTE)newcount);
	EnabledColumnCount=newcount;
	SendMessage(pcli->hwndContactTree,CLM_SETEXTRACOLUMNS,EnabledColumnCount,0);
}
void SetNewExtraColumnCount()
{
	int newcount;
	LoadPositionsFromDB(ExtraOrder);
	GetVisColumns();
	newcount=colsum(0,EXTRACOLUMNCOUNT-1);
	ModernWriteSettingByte(NULL,CLUIFrameModule,"EnabledColumnCount",(BYTE)newcount);
	EnabledColumnCount=newcount;
	SendMessage(pcli->hwndContactTree,CLM_SETEXTRACOLUMNS,EnabledColumnCount,0);
};
Beispiel #4
0
void ContingencyTable_entropies (ContingencyTable me, double *h, double *hx, double *hy, double *hygx, double *hxgy, double *uygx, double *uxgy, double *uxy) {
	*h = *hx = *hy = *hxgy = *hygx = *uygx = *uxgy = *uxy = 0;

	autoNUMvector<double> rowsum (1, my numberOfRows);
	autoNUMvector<double> colsum (1, my numberOfColumns);

	// row and column totals

	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 += rowsum[i];
	}

	// Entropy of x distribution

	for (long j = 1; j <= my numberOfColumns; j++) {
		if (colsum[j] > 0.0) {
			double p = colsum[j] / sum;
			*hx -= p * NUMlog2 (p);
		}
	}

	// Entropy of y distribution

	for (long i = 1; i <= my numberOfRows; i++) {
		if (rowsum[i] > 0.0) {
			double p = rowsum[i] / sum;
			*hy -= p * NUMlog2 (p);
		}
	}

	// Total entropy

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

	// Conditional entropies

	*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);
}
int ExtraToColumnNum(int extra)
{
	int cnt=EnabledColumnCount-1;
	int extracnt=EXTRACOLUMNCOUNT-1;
	
	switch(extra)
	{
	case EXTRA_ICON_WEB:	if (!visar[0])return(-1);break;
    case EXTRA_ICON_ADV1:	if (!visar[1])return(-1);break;
	case EXTRA_ICON_ADV2:	if (!visar[2])return(-1);break;
	case EXTRA_ICON_SMS:	if (!visar[3])return(-1);break;
	case EXTRA_ICON_EMAIL:	if (!visar[4])return(-1);break;
	case EXTRA_ICON_PROTO:	if (!visar[5])return(-1);break;
    case EXTRA_ICON_CLIENT:	if (!visar[6])return(-1);break;
	};

	switch(extra)
	{
    case EXTRA_ICON_WEB:    if (extracnt-5>=0) return(cnt-colsum(extracnt-5,extracnt));
	case EXTRA_ICON_ADV1:   if (extracnt-4>=0) return(cnt-colsum(extracnt-4,extracnt));
	case EXTRA_ICON_ADV2:   if (extracnt-3>=0) return(cnt-colsum(extracnt-3,extracnt));	
	case EXTRA_ICON_SMS:    if (extracnt-2>=0) return(cnt-colsum(extracnt-2,extracnt));
	case EXTRA_ICON_EMAIL:  if (extracnt-1>=0) return(cnt-colsum(extracnt-1,extracnt));
	case EXTRA_ICON_PROTO:  return(cnt-colsum(extracnt,extracnt));  
    case EXTRA_ICON_CLIENT: return(cnt);      
	};
	return(-1);
};
Mat calculateImageSymmetryScore(const Mat& image) {
    Mat gray_img ;
    
    if (image.channels() == 3) {
        cvtColor(image, gray_img, CV_BGR2GRAY);
    } else {
        gray_img = image.clone();
    }
    
//    gray_img = magicEqualHist(gray_img);
//    imshow("histed",gray_img);
    if (gray_img.cols %2 == 1) {
        hconcat(gray_img, gray_img.col(gray_img.cols-1), gray_img);
    }
    
    gray_img.convertTo(gray_img, CV_32FC1);

    Mat score(gray_img.cols,gray_img.cols,CV_32FC1,Scalar::all(0));
    Mat temp(1,1,CV_32FC1), base(1,1,CV_32FC1),colsum(1,1,CV_32FC1);
    
    
    for (int i = 0 ; i < gray_img.cols/2; i++) {
        temp = gray_img.colRange(0, i+1).clone();
        flip(temp, temp, 1);
        base = gray_img.colRange(i+1, gray_img.cols).clone();
        base.colRange(0, temp.cols) += temp;
        reduce(base, colsum, 0, CV_REDUCE_SUM,CV_32FC1);
        colsum =  colsum.t();
        colsum.copyTo(score.colRange(i, i+1).rowRange(0, colsum.rows));
    }
    
    flip(score, score, 1);
    flip(gray_img, gray_img, 1);
    
    for (int i = 0 ; i < gray_img.cols/2; i++) {
        temp = gray_img.colRange(0, i+1).clone();
        flip(temp, temp, 1);
        base = gray_img.colRange(i+1, gray_img.cols).clone();
        base.colRange(0, temp.cols) += temp;
        reduce(base, colsum, 0, CV_REDUCE_SUM,CV_32FC1);
        colsum =  colsum.t();
        colsum.copyTo(score.colRange(i, i+1).rowRange(0, colsum.rows));
    }
    
    flip(score, score, 1);
    gray_img.release();
    base.release();
    temp.release();
    return score;
}
int ExtraImage_ExtraIDToColumnNum(int extra)
{
	if (HasExtraIconsService())
	{
		if (extra < 1 || extra > EXTRACOLUMNCOUNT) 
			return -1;
		else
			return extra-1;
	}

	int ord=ExtraOrder[extra-1];
    if (!visar[ord]) return -1;
	return (colsum(0,ord)-1);
};
void ContingencyTable_chisq (ContingencyTable me, double *chisq, long *df) {
	long nr = my numberOfRows, nc = my numberOfColumns;

	*chisq = 0; *df = 0;

	autoNUMvector<double> rowsum (1, nr);
	autoNUMvector<double> colsum (1, nc);

	/*
		row and column marginals
	*/

	double sum = 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 += rowsum[i];
	}

	for (long i = 1; i <= my numberOfRows; i++) {
		if (rowsum[i] == 0) {
			--nr;
		}
	}
	for (long j = 1; j <= my numberOfColumns; j++) {
		if (colsum[j] == 0) {
			--nc;
		}
	}

	*df = (nr - 1) * (nc - 1);
	for (long i = 1; i <= my numberOfRows; i++) {
		if (rowsum[i] == 0) {
			continue;
		}
		for (long j = 1; j <= my numberOfColumns; j++) {
			if (colsum[j] == 0) {
				continue;
			}
			double expt = rowsum[i] * colsum[j] / sum;
			double tmp = my data[i][j] - expt;
			*chisq += tmp * tmp / expt;
		}
	}
}
int ExtraToColumnNum(int extra)
{
	if (HasExtraIconsService())
	{
		if (extra < 1 || extra > EXTRACOLUMNCOUNT) 
			return -1;
		else
			return extra-1;
	}
	else
	{
		int cnt=EnabledColumnCount;
		int extracnt=EXTRACOLUMNCOUNT-1;
		int ord=ExtraOrder[extra-1];
		if (!visar[ord]) return -1;
		return (colsum(0,ord)-1);
	}
};