ImageColor WaterShedDecomposer::filterGaussSinglePass(ImageColor const & image, int r) const {
   r = std::max(1, r);
   int n = (r<<1) + 1;

   // create kernel
   unsigned long long * kernel = new unsigned long long[n];
   for (int i=0; i<r; ++i) {
      kernel[i] = kernel[n-i-1] = nCr(n-1, i);
   }
   kernel[r] = nCr(n-1, r);

   ImageColor filtered(image.height(), image.width());
   for (int y=0; y<image.height(); ++y) {
      for (int x=0; x<image.width(); ++x) {
         Color color;
         unsigned long long weights = 0;
         for (int i=0; i<n; ++i) {
            if (x-r+i >= 0 && x-r+i < image.width()) {
               color += image.at(x-r+i, y) * kernel[i];
               weights += kernel[i];
            }
         }
         filtered.at(y, x) = color / double(weights);
      }
   }

   delete[] kernel;

   return filtered;
}
Exemple #2
0
int nCr(int n, int r){
  if(r==0){
    return 1;
  }
  else if(r==n){
    return 1;
  }
  else{
    nCr(n-1, r-1) + nCr(n-1,r);
  }
}
int nCr(int n, int r)
{
    if(r==0 || r==n)
        return 1;
    if(r==1 || r==n-1)
        return n;

    if(ara[n][r]!=-1)
        return ara[n][r];
    else
    {
        ara[n][r]=nCr(n-1,r)+nCr(n-1,r-1);
        return ara[n][r];
    }
}
float                              /* RET - time (seconds)                   */
  old_probs_estimate(
    TREE *tree,         /* IN  - tree                             */
    int max_order,      /* IN  - number of cut sets               */
    int min_term,       /* IN  - min number of terms to evaluate  */
    int max_term)       /* IN  - max number of terms to evaluate  */
{
    int num_mcs;   /* number of cut sets used */
    float t = 0;
    int i;
/*     TimeEstimate Base; */

 /* find out how many cut sets are actually used */
    num_mcs = ExprCountOrder(tree->mcs_expr, max_order);

    for (i = min_term; i <= max_term; i++) {
/*         t += (CONST_A + CONST_B * i) * nCr(num_mcs, i); */
        t += nCr(num_mcs, i);
    }
/*     return t * tree->num_bas; */
/*     return t * tree->num_bas * ( BaseTimeEstimate() / 2500.0 ); */
/*     return t * tree->num_bas * ( Base.ReferenceEstimate() / 2500.0 ); */
    return t * tree->num_bas * ( ReferenceEstimate() / 2500.0 );

} /* probs_estimate */
Exemple #5
0
double PostCal::totalLikelihood(double * stat, double NCP) {	
	int num = 0;
	double sumLikelihood = 0;
	double tmp_likelihood = 0;
	long int total_iteration = 0 ;
	int * configure = (int *) malloc (snpCount * sizeof(int *)); // original data	

	for(long int i = 0; i <= maxCausalSNP; i++)
		total_iteration = total_iteration + nCr(snpCount, i);

	for(long int i = 0; i < snpCount; i++) 
		configure[i] = 0;
	for(long int i = 0; i < total_iteration; i++) {
                tmp_likelihood = likelihood(configure, stat, NCP) * (pow(SMALL, num))*(pow(1-SMALL, snpCount-num));
                sumLikelihood += tmp_likelihood;
		for(int j = 0; j < snpCount; j++) {
                        postValues[j] = postValues[j] + tmp_likelihood * configure[j];
		}
		histValues[num] = histValues[num] + tmp_likelihood;
                num = nextBinary(configure, snpCount);
       		if(i % 1000 == 0)
			cout << i << " "  << sumLikelihood << endl;
	}
	for(int i = 0; i <= maxCausalSNP; i++)
		histValues[i] = histValues[i]/sumLikelihood;
        free(configure);
        return(sumLikelihood);
}
main()
{
    int N = 50;
    int R = 5;
    int *x, *z;
    int n;
    int i;

    n = nCr(N, R);
    printf("%dC%d = %d\n", N, R, n);
/*
    n = nPr(N, R);
    printf("%dP%d = %d\n", N, R, n);
*/

    if ( (x = (int *)malloc( N * sizeof(int) )) == NULL ) {
        printf("*** malloc failed for x\n");
        exit(1);
    }
    for(i=0; i<N; i++) {
        x[i] = i+1;
    }
    if ( (z = (int *)malloc( N * sizeof(int) )) == NULL ) {
        printf("*** malloc failed for z\n");
        exit(1);
    }
    
    combs(x, N, R, z, 0, comb_count, &n);
 /* perms(x, N, R, z, 0, vec_print, NULL); */

}
/*---------------------------------------------------------------
 Routine : nKr
 Purpose : Calculate sum of nCi, for i = 0 to r.

 Direct sum
---------------------------------------------------------------*/
float
  nKr( int n, int r)
{
    float result = 0;
    while( r >= 0 ) {
        result += nCr(n, r--);
    }
    return result;
} /* nKr */
Exemple #8
0
void gvp_space::get_score(float* &dataset_score)
{
    // For each dataset
    for (space_freq_iter space_freq_it = space_freq.begin(); space_freq_it != space_freq.end(); space_freq_it++)
    {
        size_t dataset_id = space_freq_it->first;
        float score = 0.0f;

        // Prepare score space and initialize
        float* score_list = new float[total_space];
        for (int score_id = 0; score_id < total_space; score_id++)
            score_list[score_id] = 0.0f;

        /// Accumulate score from each space
        for (int space_id = 0; space_id < total_space; space_id++)
        {
            ncr_score space_bin_score = space_freq[dataset_id][space_id];
            if (space_bin_score >= (ncr_score)_gvp_length)
            {
                //cout << "space[space_id]:" << space[space_id] << " space_id:" << space_id << " _gvp_length:" << _gvp_length << endl;
                ///-- tf for frequency is necessary for too big value, wtf = 1 + log10(freq)
                ///-- idf is necessary for emphasizing the important word
                //score_list[space_id] = (1 + log10(nCr(space_bin_score - 1, _gvp_length - 1))) * space_idf[dataset_id][space_id];   // tf-idf with ncr minus 1
                //score_list[space_id] = (1 + log10(nCr(space_b in_score - 1, _gvp_length - 1))) * space_idf[dataset_id][space_id];   // tf-idf
                //score_list[space_id] = nCr(space_bin_score, _gvp_length) * space_idf[dataset_id][space_id];   // idf
                //score_list[space_id] = 1 + log10(nCr(space_bin_score, _gvp_length));   // tf
                score_list[space_id] = log10(nCr(space_bin_score, _gvp_length) * space_idf[dataset_id][space_id]);   // tf-idf
                //score_list[space_id] = log10(nCr(space_bin_score, _gvp_length));   // tf
            }
        }


        /// Normalization
        // Unit length
        float sum_of_square = 0.0f;
        float unit_length = 0.0f;
        for (int score_id = 0; score_id < total_space; score_id++)
            sum_of_square += score_list[score_id] * score_list[score_id];
        unit_length = sqrt(sum_of_square);

        // Normalizing
        for (int score_id = 0; score_id < total_space; score_id++)
            score_list[score_id] = score_list[score_id] / unit_length;


        /// Calculate total score
        for (int score_id = 0; score_id < total_space; score_id++)
            score += score_list[score_id];


        // Release memory
        delete[] score_list;

        //cout << "score:" << score << endl;
        dataset_score[dataset_id] = score;
    }
}
Exemple #9
0
int main() {
    ullong total = 0;
    for(long long x = 0; x <= 5; ++x) {
        for(long long y = 0; y <= 5; ++y) {
            if((isPerfectSquare(y)) && (isPerfectSquare(x)) && (isPerfectSquare(x+y))) {
                ++total;
                std::cout << '(' << x << ", " << y << ")\n";
            }
        }
    }
    std::cout << total << "\nnCr: " << nCr(10, 5);
}
Exemple #10
0
int main()
{
	int t;
	i64 n, r;
	scanf("%d", &t);
	while(t--)
	{
		scanf("%llu %llu", &n, &r);
		printf("%llu\n", nCr(n-1, r-1));
	}
	return 0;
}
Exemple #11
0
int main()
{
    int c,n,t,p;
    scanf("%d",&c);
    nCr(141,71);
    while(c--)
    {
        scanf("%d %d %d",&n,&t,&p);
        printf("%llu\n",comb[t-n*p+n-1][n-1]);
    }
    return 0;
}
unsigned long long WaterShedDecomposer::nCr(int n, int r) const {
   if (r<<1 > n) {
      return nCr(n, n-r);
   }
   else {
      unsigned long long result = 1;
      for (int i=1; i<=r; ++i) {
         result *= n - r + i;
         result /= i;
      }
      return result;
   }
}
Exemple #13
0
int main(int argc, char* argv[]){
	int n,r;
	int count = 0;
	int check = 0;
	for(n=1;n <= 100;n++){
		for(r=n;r >0;r--){
			if(nCr(n,r) > 1000000){
				count++;
			}
		}
	}
	printf("count = %d\n",count);
	return 0;
}
Exemple #14
0
int _Problem053() {
	int n, r;
	int count = 0;
	int val;

	for(n=1;n<100;n++) {
		for(r=1;r<n;r++) {
			val = nCr(n,r);
			if(val>1000000) {
				count++;
	}	}	}

	printf("%30d", count);
	return 0;
}
Exemple #15
0
int nCr(int n, int r, int start, int prev_val)
{
    static int count =0;
    int j;
    if(start ==r)
    {
        count++;
        return count;
    }
    for(j= prev_val;j<=(n-(r-start));j++)
    {
        nCr(n,r,start+1,j+1);
    }
    return count;
}
int main()
{
    int i,j,n,r;

    memset(ara,-1,sizeof(ara));

    while(scanf("%d%d",&n,&r)==2)
    {
        if(n==0 || r==0)break;

        printf("%d\n",nCr(n,r));
    }

    return 0;
}
double molecule_t::calculateAbundance(composition_t composition)
{
    double totalAbundance = 1;
    for (composition_t::iterator it = composition.begin(); it != composition.end(); it++)
    {
        if (it.key()->isotopeOf() != NULL && it.key()->isotopeOf() > 0) // If an isotope of an element is present, calculate its count and abundance
        {
            int countThisIsotope = it.value();
            int countParentElement = composition.find(it.key()->isotopeOf()).value();
            double abundance = it.key()->abundance();
            totalAbundance = (totalAbundance * pow(abundance,countThisIsotope) * nCr(countParentElement+countThisIsotope,countThisIsotope));
        }
    }
    return totalAbundance;
}
Exemple #18
0
int main(int argc, char *argv[])
{
	int n;
	printf("Enter the number of rows\n");
	scanf("%d", &n);
	int i, j, k;
	for (i=0;i<n;i++){
		for(j=n-i;j>0;j--){ // Insert white space total number of rows - row that is currently printed 
			printf(" ");
		}
		for(k=0;k<=i;k++){
			printf("%d ", nCr(i,k));
		}
		printf("\n");
	}
}
Exemple #19
0
/* A sample main function */
int main()
{
    LLI n,m,l;
    while(scanf("%lld%lld%lld",&l,&n,&m)!=EOF)
    {
        l=l*l;
        LLI sum=0;
        for( LLI i=n; i<=m; i++ )
        {
            //printf("35 %lld\n",nCr(l,i));
            for( int j=l; j>=i; j-- )
            sum=((sum%mod)+nCr(j,1)%mod)%mod;
            printf("38 %lld\n",sum);
        }
    }
    return 0;
}
Exemple #20
0
int main(int argc, char** argv) {
	struct timeval start, end;
	gettimeofday(&start, NULL);
	
	if (argc < 2) {
		fprintf(stderr,"Not enough arguments\n");
		return 0;
	}
	else if (argc > 2) {
		fprintf(stderr,"Too many arguments\n");
		return 0;
	}
	if (strcmp(argv[1],"-h") == 0) {
		printf("Usage: formula <positive integer>\n");
		return 0;
	}	
		
	curr_state = mightBeDecFirstNum;
	if (checkInt(argv[1]) == 1) {
		fprintf(stderr,"Input not in positive integer form\n");
		return 0;
	}	
	int n = atoi(argv[1]);
	
	if (factorial(n) == 0) {
		fprintf(stderr,"Overflow detected\n");
		return 0;
	}
	
	printf("(1 + x)^%d = 1",n);
	
	int i = 1, fact;
	for (i; i <= n; i++) {
		fact = nCr(n,i);
		printf(" + %d*x^%d",fact,i);
	}
	printf("\n");
	gettimeofday(&end, NULL);
	
	printf("%ld microseconds\n", ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));

	return 0;
}
Exemple #21
0
int main()
{	
	init();
	unsigned long int n;
	int ans;
	
	scanf("%ld",&n);
	if(n<13)
		ans=0;
	else
	{
		n-=13;
		if (n&1)
			n-=1;
		n=n>>1;
		ans=nCr(n+7-1,n);
	}	
	printf("%d\n",ans);

	return 0;
}
Exemple #22
0
int main()
{
	int t, r, n;
	int N, T, P;

	//freopen( "in.in", "r", stdin );

	scanf( "%d", &t );
	
	while ( t-- )
	{
		scanf( "%d %d %d", &N, &T, &P );

		r = T - N * P;
		n = N;

		printf( "%lld\n", nCr( n + r - 1, r ) );
	}

	return 0;
}
Exemple #23
0
int Account1(long double &a,long double b,char c)//双目算术运算
{
    switch(c)
    {
    case'+':
        a+=b;
        break;
    case'-':
        a-=b;
        break;
    case'*':
        a*=b;
        break;
    case'/':
    {
        if(b==0)
            return 0;
        a/=b;
        break;
    }
    case'%':
    {
        if(b==0)
            return 0;
        a=fmod(a,b);
        break;
    }
    case'^':
        a=pow(a,b);
        break;
    case'A':
        return nAr(a,a,b);
    case'C':
        return nCr(a,a,b);
    default:
        return 0;
    }
    return 1;
}
int main(){
	int n,m;	
	scanf("%d %d", &n, &m);
	int index;
	permutations[0] = 1;
	for(index = 0; index <= m; index ++){
		calpermutations(index, m);
		
	}
	permutations2[0][0] = 1;
	permutations2[1][0] = 1;
	int i,j;
	for(i = 2; i <= 4000; i++){
		permutations2[i][0] = 1;
		for(j = 1; j <= i; j ++){
			permutations2[i][j] = nCr(i, j);
		}
	}

	printf("\n%lld\n",permutations[8]);
	printf("\n%lld\n",permutations2[57][8]);
	return 0;
}
float                              /* RET - time (seconds)                   */
  probs_estimate(
    TREE *tree,         /* IN  - tree                             */
    int max_order,      /* IN  - number of cut sets               */
    int min_term,       /* IN  - min number of terms to evaluate  */
    int max_term)       /* IN  - max number of terms to evaluate  */
{
    int num_mcs;   /* number of cut sets used */
    float t = 0;
    int i,j;
    Group **index; /* index to the groups   */
	int *z;
    Group  *p;     /* pointer               */
    clock_t time1, time2;
    BitArray *stop = BitCreate(1);  /* 1-bit zero */
	float *probs;
	
	/*     TimeEstimate Base; */

    /* find out how many cut sets are actually used */
    num_mcs = ExprCountOrder(tree->mcs_expr, max_order);

	/* make sure that max_term does not exceed number of mcs */
	/* if number of mcs is zero then return 0 */
	if(num_mcs == 0) {
		return 0.0f;
	} else if (max_term > num_mcs) {
		max_term = num_mcs;
	}

	/* allocate memory required for testing */
    if ( !fNewMemory( (void *)&probs, ( tree->num_bas * sizeof(float) ) ) ) 
    {
        exit(1);
    }
    if ( !fNewMemory( (void *)&index, ( num_mcs * sizeof(Group *) ) ) )
    {
      exit( 1 );
    }
    if ( !fNewMemory( (void *)&z, ( num_mcs * sizeof(int) ) ) )
    {
      exit( 1 );
    }

	/* populate the arrays with default data */
	for(i=0, p=tree->mcs_expr; i<num_mcs; i++, p=p->next) {
		index[i] = p;
		z[i] = i;
	}	

	/* fill the probs array */
    get_probs( probs );


	/* set the static variables to sensible values */
	set_basic_n(tree->num_bas);
	set_prob_term(0.0);	
	set_basic_prob(probs);

	/* The function that takes most of the time is calc_sub_term().
	   Run this function for each number of terms required. Run it
	   enough times for the CPU clock to change. */
    for (i = min_term; i <= max_term; i++) {
		time1 = clock();
		j = 0;
		do {
			calc_sub_term(z, i, index);
			j++;
			time2 = clock();
		} while(time1 == time2);

        t += nCr(num_mcs, i) * (time2 - time1) / j;
    }

    FreeMemory(index);
	FreeMemory(z);
	FreeMemory(probs);

    return t/CLOCKS_PER_SEC;

} /* probs_estimate */
Exemple #26
0
int main(int argc, char ** argv){
	//check for extra arguements
	if(argc != 2){ 
		fprintf(stderr, "Incorrect number of arguements\n");
		return -1;
	}
	char *input = argv[1];
	int j ;
	
	//check for usage flag
	if(strlen(input) > 1){
		if(input[0] == '-' && input[1] == 'h'){
			fprintf(stderr, "Usage: formula <positive integer>\n\n");
			return -1;
		} 
	}
	//check for error	
	for(j = 0; j < strlen(input); j++){
		if(isdigit(input[j]) == 0){
			fprintf(stderr, "Incorrect input\n\n");
			return -1;
		} 
	}
	struct timeval start, end;
	int val = atoi(argv[1]);
	if(val < 0){
		fprintf(stderr, "Incorrect input \n\n");
		return -1;
	}
	if(val > 20){
		fprintf(stderr, "Overflow\n\n");
		return 0;
	}
	//check for overflow
	
	printf("(1 + x)^%d =  1", val);
	gettimeofday(&start, NULL);
	
	
	//calculates coeffecient and prints it
	if(val == 0){ 
		printf("\n");
		gettimeofday(&end, NULL);
		printf("%ld Milliseconds \n", ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));
		return 0;
	}
	else{ 
		int i;
		int coeff;
		for(i = 1; i <= val; i++){
			coeff = nCr(val, i);
			printf(" + %d*x^%d", coeff, i);
		}
		printf("\n");
	}
	gettimeofday(&end, NULL);
	//prints time
	printf("%ld Milliseconds \n", ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));
	
	return 0;
}
Exemple #27
0
int main  () {
	int i;
	printf("gi");
	printf("%d\n", Factorial(5));
	printf("%d\n", nCr(5, 2));
}
/*---------------------------------------------------------------
 Routine : calculate_probs
 Purpose : Calculate the probabilities for the tree, based upon
 the minimal cut sets.
---------------------------------------------------------------*/
BOOL
  calculate_probs(
    char *filename,       /* IN - filename to write report to */
    TREE *tree,           /* IN - tree                         */
    int   max_order,      /* IN - max order of cut sets to use */
    int   prob_n_terms,   /* IN - number of terms in expansion */
    float unit_time )     /* IN - unit time factor to be applied */
{
    BitArray *stop = BitCreate(1);  /* 1-bit zero */
    FILE  *file;
    Expr   e;
    Group *g;
    float *probs, *cp, *imp;
    float  p;
    int    num_bas, num_mcs, i, j;
/*     char  *mcs_file; */
/*     int    order; */
    clock_t time1, time2;
    time_t tp;
    BOOL success = TRUE;
	float one_increment /* value for one increment of the progress bar */;

 /* start clock */
    time1 = clock();

    if ( (file = fopen(filename, "w")) == NULL) {
        printf("*** calculate_probs : error opening file\n");
        return FALSE;
    }

/*     printf("calculate_probs()\n"); */

 /* include transfered-in trees and build the primary event list
  *
  * We need to do something different to deal with Common Cause Analysis
  * We don't need the tree, but we do need the primary event list.
  * Need to add the common cause events into the primary event list.
  */
 /* if necessary, expand tree */
    expand_tree(tree);

 /* set probs in BASLIST from the events database */
    set_bas_prob( unit_time );

 /* get number of primary events */
    if ((num_bas = tree->num_bas) == 0) {
fclose( file );
        return FALSE;
    }

  if (GenerateNumericalProbabilityCheckForInterrupt()) {
    success = FALSE;
fclose( file );
    return success;
  }

 /* create array of probabilities of primary events */
    if ( !fNewMemory( (void *)&probs, ( num_bas * sizeof(float) ) ) ) 
    {
        printf("\n*** calculate_probs 1 : malloc failed ***\n");
        exit(1);
    }

    if ( !fNewMemory( (void *)&imp, ( num_bas * sizeof(float) ) ) ) 
    {
        printf("\n*** calculate_probs : malloc failed ***\n");
        exit(1);
    }

 /* fill array */
    get_probs( probs );

 /* get mcs list */
    e = tree->mcs_expr;

    /* num_mcs =  ExprCount(e); */

    /* how many mcs are actually used? */
	num_mcs = ExprCountOrder(tree->mcs_expr, max_order);

	/* make sure that max_term does not exceed number of mcs */
	/* if number of mcs is zero then return FALSE */
	if(num_mcs == 0) {
		return FALSE;
	} else if (prob_n_terms > num_mcs) {
		prob_n_terms = num_mcs;
	}

	/* initialise Working dialog */
	/* most of the cpu time is taken up in the ExprProb() function */
	/* the working dialog is incremented in the combs() function */
	one_increment = 0.0;
	for(i = 1; i <= prob_n_terms; i++) {
		one_increment += nCr(num_mcs, i);
	}

	/* set up progress bar */
	one_increment /= 100.0;
    set_one_increment(one_increment);
	GenerateNumericalProbabilitySetProgressBarMax(100);


/*  ExprPrint(e);   */

 /* print header */
    fprintf(file,
        "Probabilities Analysis\n"
        "======================\n\n");
    fprintf(file, "Tree   : %s\n", tree->name);
    time(&tp);
    fprintf(file, "Time   : %s\n", ctime(&tp));

    fprintf(file, "Number of primary events   = %d\n",   num_bas);
    fprintf(file, "Number of minimal cut sets = %d\n",   num_mcs);
    fprintf(file, "Order of minimal cut sets  = %d\n",   tree->max_order);
    if (max_order < tree->max_order) {
        fprintf(file, "               (order <= %d used)\n\n", max_order);
    } else {
        fprintf(file, "\n");
    }

    fprintf(file, "Unit time span         = %f\n\n",   unit_time);

 /* calculate cut set probabilities - use ALL the cut sets */
    cp = ExprCutsetProbs(e, probs);

    fprintf(file, "Minimal cut set probabilities :\n\n");

    i = 0;
    for(g=e; !BitEquals(g->b, stop); g=g->next) {
        char **fp = BitPara( g->b, 30 );

/*         printf("(%3d) %s %-20s - %E\n", */
/*                i+1, */
/*                BitString(g->b), */
/*                fp[0], */
/*                cp[i]); */
/*  */
/*         for (j = 1; fp[j] != NULL; j++) { */
/*             printf("       %-20s\n", fp[j]); */
/*         } */

        if (GenerateNumericalProbabilityCheckForInterrupt()) {
            success = FALSE;
            CleanUpOperations(
                file,
                probs,
                cp,
                imp,
				stop);
			ParaDestroy(fp);
            return success;
		}

        fprintf(file,
               "%3d   %-30s   %E\n",
               i+1,
               fp[0],
               cp[i]);

        for (j = 1; fp[j] != NULL; j++) {
            fprintf(file,
                   "      %-20s\n", fp[j]);
        }

        ParaDestroy(fp);
        i++;
    }

 /* calculate top level probability  - use only up to max_order cut sets */
    fprintf(file, "\n\n"
                  "Probability of top level event "
                  "(minimal cut sets up to order %d used):\n\n", max_order);

    p = 0;

	

    for (i = 1; i <= prob_n_terms && i <= num_mcs && !GenerateNumericalProbabilityCheckForInterrupt(); i++) {
        float term;
        char *sign, *s, *bound;

        p += (term = ExprProb(e, probs, max_order, i));
        sign       = ((i % 2) ? "+" :  "-" );
        s          = ((i > 1) ? "s" :  " " );
        bound      = ((i % 2) ? "upper" :  "lower" );

        fprintf(file, "%2d term%s   %s%E   = %E (%s bound)\n",
                i, s, sign, fabs(term), p, bound);
    }

    if (prob_n_terms >= num_mcs) {
        fprintf(file, "\nExact value : %E\n", p);
    }

    if (GenerateNumericalProbabilityCheckForInterrupt()) {
        success = FALSE;
        CleanUpOperations(
            file,
            probs,
            cp,
            imp,
			stop);
        return success;
	}

 /* calculate importances of individual events */

    for (j = 0; j < num_bas; j++) {
        imp[j] = 0;
    }

    i = 0;
    for(g=e; !BitEquals(g->b, stop); g=g->next) {
        for (j = 0; j < g->b->n; j++) {
            if ( BitGet(g->b, (g->b->n-1) - j) ) {
               imp[j] += cp[i];
            }
        }
        i++;
    }

    if (GenerateNumericalProbabilityCheckForInterrupt()) {
        success = FALSE;
        CleanUpOperations(
            file,
            probs,
            cp,
            imp,
			stop);
        return success;
	}

    fprintf(file, "\n\nPrimary Event Analysis:\n\n");

    fprintf(file, " Event          "
                  "Failure contrib.    "
                  "Importance\n\n");

    for (i = 0; i < num_bas; i++) {
        char *fs = BasicString(num_bas, i);
        fprintf(file, "%-15s %E            %5.2f%%\n",
                fs, imp[i], 100 * imp[i] / p);
        strfree(fs);
    }

    time2 = clock();

/*     printf("calculate_probs : num_terms = %d : time = %f\n",   */
/*            prob_n_terms, (time2-time1)/(float)CLOCKS_PER_SEC);   */

    CleanUpOperations(
        file,
        probs,
        cp,
        imp,
		stop);
/*     fclose(file); */
/*     FreeMemory(probs); */
/*     free(cp); */
/*     FreeMemory(imp); */

    return ( TRUE );

} /* calculate_probs */