예제 #1
0
	void
	process_before(T const& /*value*/) noexcept {
		std::cout
			<< '\n'
			<< tabulate(m_depth)
			<< '[' << demangle<T>() << "] "
		;
	}
예제 #2
0
 void WhileExpressionSyntax::stringify(stringstream* stream, int tabulation)
 {
     tabulate(stream, tabulation);
     *stream << (_isWhile ? "while (" : "until (");
     _cond->stringify(stream, 0);
     *stream << ") ";
     _expr->stringify(stream, 0);
 }
예제 #3
0
파일: tests_zinm.c 프로젝트: ezorita/zerone
void
test_tabulate
(void)
{

   int x1[12] = {1,2,3,4,1,2,3,4,1,2,3,4};
   tab_t *tab;
   tab = tabulate(x1, 12);
   test_assert_critical(tab != NULL);
   test_assert(tab->size == 4);
   test_assert(tab->val[0] == 1);
   test_assert(tab->val[1] == 2);
   test_assert(tab->val[2] == 3);
   test_assert(tab->val[3] == 4);
   for (int i = 0 ; i < 4 ; i++) {
      test_assert(tab->num[i] == 3);
   }
   free(tab);

   int x2[4] = {4096,2048,1024,512};
   tab = tabulate(x2, 4);
   test_assert_critical(tab != NULL);
   test_assert(tab->size == 4);
   test_assert(tab->val[0] == 512);
   test_assert(tab->val[1] == 1024);
   test_assert(tab->val[2] == 2048);
   test_assert(tab->val[3] == 4096);
   for (int i = 0 ; i < 4 ; i++) {
      test_assert(tab->num[i] == 1);
   }
   free(tab);

   int x3[5] = {-1,2,3,-1,2};
   tab = tabulate(x3, 5);
   test_assert_critical(tab != NULL);
   test_assert(tab->size == 2);
   test_assert(tab->val[0] == 2);
   test_assert(tab->val[1] == 3);
   test_assert(tab->num[0] == 2);
   test_assert(tab->num[1] == 1);
   free(tab);

   return;

}
예제 #4
0
파일: fmt.c 프로젝트: alhazred/onarm
static void
oflush(void)
{
	if (outp == NOSTR)
		return;
	*outp = L'\0';
	tabulate(outbuf);
	outp = NOSTR;
}
예제 #5
0
파일: getpars.c 프로젝트: JOravetz/SeisUnix
bool initauxtbl(char *aux) {
     char *filename;
     FILE * fp ;
     int pflen, nread, pfargc, targc, i, j ;
     char *argstr, **targv ;

     if( !getnpar(0,aux,"s",&filename) ) {
	fprintf(stderr,"Can't get auxiliary input %s definition\n",aux) ;
        return 0 ;
     }
     fp = fopen(filename, "r") ;
     if( fp == NULL ) {
        fprintf(stderr,"Can't open auxiliary input file %s=%s\n",aux,filename);
        return 0 ;
     }

     /* Get the length */
     efseek(fp, 0, SEEK_END);
     pflen = eftell(fp);
     rewind(fp);
     argstr = (char *) ealloc1(1+pflen+1, 1);

     /* Read the parfile */
     nread = efread(argstr+1, 1, pflen, fp);
     if (nread != pflen) {
   	  err("%s: fread only %d bytes out of %d from %s",
	      __FILE__,nread,pflen,filename);
     }
     efclose(fp);

     /* Zap whites in parfile to help in parsing */
     argstr[0] = '\0' ;
     pfargc = white2null(argstr, pflen);
     targc = pfargc ;

     /* Allocate space for total arg pointers */
     targv = (char **) ealloc1(targc, sizeof(char*));

     /* Parse the parfile.  Skip over multiple NULLs */
     for( j=1, i=0; j < pflen; j++) {
	if( argstr[j] && !argstr[j-1] ) {
	       targv[i++] = argstr + j;
	}
     }

     /* Allocate space for the pointer table */
     argtbl = (ArgStruct*) ealloc1(targc, sizeof(ArgStruct));

      /* Tabulate targv */
     tabulate(targc, targv);
     return 1 ;
}
        void BinaryOperatorExpressionSyntax::stringify(stringstream* stream, int tabulation)
        {
            tabulate(stream, tabulation);

            if (_left->getPrecedence() > getPrecedence()) *stream << "(";
            _left->stringify(stream, 0);
            if (_left->getPrecedence() > getPrecedence()) *stream << ")";

            *stream << " " << getOperatorSymbol() << " ";

            if (_right->getPrecedence() > getPrecedence()) *stream << "(";
            _right->stringify(stream, 0);
            if (_right->getPrecedence() > getPrecedence()) *stream << ")";
        }
예제 #7
0
	void
	operator()(P&&... args) {
		std::cout << "{";
		++m_depth;
		base_type::process(std::forward<P>(args)...);
		--m_depth;
		std::cout
			<< '\n'
			<< tabulate(m_depth)
			<< "}"
		;
		if (0 == m_depth) {
			std::cout << std::endl;
		}
	}
예제 #8
0
파일: videoDriver.c 프로젝트: SKOLZ/noxOS
size_t putchar(char c) {
    switch (c) {
        case '\n':
            breakLine();
            return 0;
        case '\b':
            backSpace();
            return 0;
        case '\t':
            tabulate();
            return 0;
        default:
            return putc(c, STDOUT);
            break;
    }
}
예제 #9
0
파일: tests_zinm.c 프로젝트: ezorita/zerone
void
test_eval_zinb_g
(void)
{

   tab_t *tab;
   // 0:14, 1:5, 2:4, 3:1, 5:1
   int x1[25] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                  1,1,1,1,1,2,2,2,2,3,5 };
   tab = tabulate(x1, 25);
   test_assert_critical(tab != NULL);
   test_assert(fabs(eval_zinb_g(1, .5, tab)+0.1325713) < 1e-6);
   free(tab);

   return;

}
예제 #10
0
파일: tests_zinm.c 프로젝트: ezorita/zerone
void
test_eval_zinb_dgda
(void)
{

   tab_t *tab;
   // 0:14, 1:5, 2:4, 3:1, 5:1
   int x1[25] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                  1,1,1,1,1,2,2,2,2,3,5 };
   tab = tabulate(x1, 25);
   test_assert_critical(tab != NULL);
   test_assert(fabs(eval_zinb_dgda(1, .5, tab)+2.2547559) < 1e-6);
   test_assert(fabs(eval_zinb_dgda(2, .5, tab)+1.2605630) < 1e-6);
   test_assert(fabs(eval_zinb_dgda(2, .3, tab)+1.8764955) < 1e-6);
   free(tab);

   return;

}
예제 #11
0
파일: tests_zinm.c 프로젝트: ezorita/zerone
void
test_ll_zinb
(void)
{

   tab_t *tab;
   // 0:14, 1:5, 2:4, 3:1, 5:1
   int x1[25] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                  1,1,1,1,1,2,2,2,2,3,5 };
   tab = tabulate(x1, 25);
   test_assert_critical(tab != NULL);
   test_assert(fabs(ll_zinb(1, .5, 1, tab)+22.5329303) < 1e-6);
   test_assert(fabs(ll_zinb(1, .5, .7, tab)+22.7832550) < 1e-6);
   test_assert(fabs(ll_zinb(2, .5, .7, tab)+23.7608409) < 1e-6);
   test_assert(fabs(ll_zinb(2, .3, .7, tab)+31.6978553) < 1e-6);
   free(tab);

   return;

}
예제 #12
0
파일: phangorn.c 프로젝트: Q-KIM/phangorn
void C_reorder(int *from, int *to, int *n, int *sumNode,  int *neworder, int *root){ 
    int i, j, sum=0, k, Nnode, ind, *ord, *csum, *tips, *stack, z=0;  // l, 
    double *parent;
    int m=sumNode[0];
    parent = (double *) R_alloc((*n), sizeof(double));
    tips = (int *) R_alloc(m, sizeof(int));
    ord = (int *) R_alloc((*n), sizeof(int));
    csum = (int *) R_alloc( (m+1), sizeof(int));
    stack = (int *) R_alloc(m, sizeof(int));
    for(j=0;j<(*n);j++) parent[j] = (double)from[j];
   
    for(j=0;j<(*n);j++) ord[j] = j;
    for(j=0;j<m;j++) tips[j] = 0;
        
    rsort_with_index(parent, ord, *n);
    tabulate(from, n, sumNode, tips);
    csum[0]=0;
    for(i=0;i<(*sumNode);i++){
        sum+=tips[i];                 
        csum[i+1] = sum;                        
    }      
    k = (*n)-1;
    Nnode = 0;
    stack[0] = *root;
    
    while(z > -1){
        j=stack[z];          
        if(tips[j]>0){   
            for(i=csum[j];i<csum[j+1];i++){
                ind = ord[i];                     
                neworder[k] = ind + 1;        
                stack[z] = to[ind]-1;
                k -=1;
                z++;                            
            }         
            Nnode += 1; 
            }
        z--;       
    }                
    root[0]=Nnode;     
}
예제 #13
0
파일: tests_zinm.c 프로젝트: ezorita/zerone
void
test_eval_nb_dfda
(void)
{

   // 0:14, 1:5, 2:4, 3:1, 5:1
   int x[25] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    1,1,1,1,1,2,2,2,2,3,5 };
   tab_t *tab = tabulate(x, 25);
   test_assert(fabs(eval_nb_dfda(1.0, tab)+1.41167874) < 1e-6);
   test_assert(fabs(eval_nb_dfda(1.2, tab)+0.58911102) < 1e-6);
   test_assert(fabs(eval_nb_dfda(1.3, tab)+0.36790287) < 1e-6);
   test_assert(fabs(eval_nb_dfda(1.4, tab)+0.21643981) < 1e-6);
   test_assert(fabs(eval_nb_dfda(1.5, tab)+0.11168877) < 1e-6);
   test_assert(fabs(eval_nb_dfda(2.0, tab)-0.08773865) < 1e-6);

   free(tab);

   return;

}
예제 #14
0
void traverseDOMTree( const DOMNode* doc, int depth )
{
  const DOMNodeList* lst = doc->getChildNodes();

  for ( unsigned int i=0; i<lst->getLength(); ++i )
  {
    const DOMNode* node = lst->item(i);

    std::cout << tabulate(depth) << node->getNodeType() << " ";
    std::cout << node->getNodeName() << " ";

    if ( node->getNodeType() == DOMNode::TEXT_NODE )
    {
      std::cout << node->getNodeValue() ;
    }

    std::cout << std::endl ;

    traverseDOMTree( node, depth+1 );
  }
}
예제 #15
0
파일: tests_zinm.c 프로젝트: ezorita/zerone
void
test_eval_nb_f
(void)
{

   // 0:14, 1:5, 2:4, 3:1, 5:1
   int x[25] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                     1,1,1,1,1,2,2,2,2,3,5 };
   tab_t *tab = tabulate(x, 25);
   test_assert(fabs(eval_nb_f(1.0, tab)+0.12747262) < 1e-6);
   test_assert(fabs(eval_nb_f(1.1, tab)+0.24215981) < 1e-6);
   test_assert(fabs(eval_nb_f(1.2, tab)+0.31636395) < 1e-6);
   test_assert(fabs(eval_nb_f(1.3, tab)+0.36350700) < 1e-6);
   test_assert(fabs(eval_nb_f(1.4, tab)+0.39225466) < 1e-6);
   test_assert(fabs(eval_nb_f(1.5, tab)+0.40834322) < 1e-6);
   test_assert(fabs(eval_nb_f(2.0, tab)+0.39975512) < 1e-6);

   free(tab);

   return;

}
예제 #16
0
파일: zinb.c 프로젝트: rlim19/Biotools
zinb_par_t *
mle_nb
(
   int *x,
   unsigned int nobs
)
{

   tab_t *tab = tabulate(x, nobs);
   double a = nb_est_alpha(tab);

   // Return NULL if failed.
   if (a < 0) return NULL;

   // Allocate return struct.
   zinb_par_t *par = calloc(1, sizeof(zinb_par_t));
   if (par == NULL) {
      fprintf(stderr, "memory error: %s:%d\n", __FILE__, __LINE__);
      return NULL;
   }

   double sum = 0.0;
   unsigned int nona = 0;
   for (size_t i = 0 ; i < tab->size ; i++) {
      nona += tab->num[i];
      sum += tab->val[i]*tab->num[i];
   }

   free(tab);

   par->a = a;
   par->p = a / (a + (sum/nona));

   return par;

}
예제 #17
0
파일: mcss.hpp 프로젝트: channgo2203/pasl
value_type mcss_par(const sparray& xs) {
  sparray ys = prefix_sums_incl(xs);
  scan_excl_result m = scan_excl(min_fct, 0l, ys);
  sparray zs = tabulate([&] (long i) { return ys[i]-m.partials[i]; }, xs.size());
  return max(zs);
}
int
algorithm_d(struct gto *g, struct node *t, int subject_node_count, int pat_path_cnt, const char *abstr_var_name)
{
	int top = 1;
	int matched = 0;
	int breadth_counter = 0;
	int next_state;
	const char *p;
	struct node *exact_match_node = NULL;

	++subject_node_count; /* 0-indexed arrays, first element at index 1 */

	if (subject_node_count > stack_sz)
	{
		if (subject_node_count < 100)
			stack_sz = 100;
		else
			stack_sz = subject_node_count;
		if (count) free(count);
		count = malloc(stack_sz * sizeof(int));
		if (stack) free(stack);
		stack = malloc(stack_sz * sizeof(struct stack_elem));
	}

	memset(count, 0, stack_sz * sizeof(int));

	next_state = 0;
	p = (t->name != abstr_var_name)? t->name: abstr_meta_var;
	while (*p)
		next_state = g->delta[next_state][(int)*p++];

	stack[top].n = t;
	stack[top].state_at_n = next_state;
	stack[top].visited = 0;
	stack[top].node_number = breadth_counter++;

	matched += tabulate(g, stack, top, next_state, pat_path_cnt, count);

	if (!matched)
	{
		if (any_var_in_tree(t))
		{
		  	if (var_in_tree(t, abstr_var_name))
				next_state = g->delta[0][(int)'+'];
			else
				next_state = g->delta[0][(int)'-'];
			matched += tabulate(g, stack, top, next_state, pat_path_cnt, count);
		} else {
			next_state = g->delta[0][(int)'!'];
			matched += tabulate(g, stack, top, next_state, pat_path_cnt, count);
			if (!matched)
			{
				next_state = g->delta[0][(int)'-'];
				matched += tabulate(g, stack, top, next_state, pat_path_cnt, count);
			}
		}
	}

	while (!matched && top > 0)
	{
		struct node *next_node, *this_node = stack[top].n;
		int intstate, nxt_st, this_state = stack[top].state_at_n;
		int visited = stack[top].visited;

		if (visited == 2 || this_node->typ == ATOM || top > g->max_node_count)
			--top;
		else {
			++visited;
			stack[top].visited = visited;

			intstate = g->delta[this_state][visited == 1?'1':'2'];
			matched += tabulate(g, stack, top, intstate, pat_path_cnt, count);

			next_node = (visited == 1)? this_node->left: this_node->right;
			nxt_st = intstate;

			p = (next_node->name != abstr_var_name)? next_node->name: abstr_meta_var;
			while (*p)
				nxt_st = g->delta[nxt_st][(int)*p++];

			++top;
			stack[top].n = next_node;
			stack[top].state_at_n = nxt_st;
			stack[top].visited = 0;
			stack[top].node_number = breadth_counter++;

			if (top <= g->max_node_count)
			{
				matched += tabulate(g, stack, top, nxt_st, pat_path_cnt, count);

				if (!matched)
				{
					nxt_st = g->delta[intstate][(int)'^'];
					if (nxt_st)
					{
						if (exact_match_node)
						{
							if (equivalent_graphs(exact_match_node, next_node))
								matched += tabulate(g, stack, top, nxt_st, pat_path_cnt, count);
						} else {
							/* XXX - what about a 3-way match?
							 * should increment count[something] here, as we found it. */
							exact_match_node = next_node;
							matched += tabulate(g, stack, top, nxt_st, pat_path_cnt, count);
						}
					}
				}

				if (!matched)
				{
					if (any_var_in_tree(next_node))
					{
						if (var_in_tree(next_node, abstr_var_name))
							nxt_st = g->delta[intstate][(int)'+'];
						else
							nxt_st = g->delta[intstate][(int)'-'];
					} else {
						nxt_st = g->delta[intstate][(int)'!'];
						if (0 == nxt_st)
							nxt_st = g->delta[intstate][(int)'-'];
					}

					matched += tabulate(g, stack, top, nxt_st, pat_path_cnt, count);
				}
			}
		}
	}

	exact_match_node = NULL;

	return matched;
}
예제 #19
0
파일: roff.c 프로젝트: ysei/h-compiler
int readline()
{
    int startline;
    int doingword;
    isrequest = 0;
    startline = 1;
    doingword = 0;
    c = suck();
    if (c == '\n') {
        o_sp = 1;
        writebreak();
        goto out;
    } else if (isspace(c))
        writebreak();
    while(1) {
        if (c == EOF) {
            if (doingword) bumpword();
            break;
        }
        if (isspace(c)) {
            if (doingword == 0) {
                startline = 0;
                if (c==' ') {
                    assyline[assylen] = ' ';
                    assylen++;
                }
                if (c=='\t') {
                    tabulate();
                }
                if (c=='\n')	goto out;
                c = suck();
                continue;
            }
        }
        if (isspace(c)) {
            if (doingword) {
                bumpword();
                if (c == '\t')
                    tabulate();
                else if (assylen) {
                    assyline[assylen] = ' ';
                    assylen++;
                }
                doingword = 0;
                if (c == '\n') break;
            }
        }
        if (isspace(c) == 0) {
            if (doingword) {
                if (o_ul)
                    *holdp = c | UNDERL;
                else
                    *holdp = c;
                holdp++;
                goto readline1;
            }
            if (startline) {
                if (c == o_cc) {
                    isrequest = 1;
                    return(readreq());
                }
            }
            doingword = 1;
            holdp = holdword;
            if (o_ul)
                *holdp = c | UNDERL;
            else
                *holdp = c;
            holdp++;
        }
readline1:
        startline = 0;
        c = suck();
    }
out:
    if (o_ul) o_ul--;
    if (c != EOF)
        return(1);
    else
        return(0);
}
예제 #20
0
파일: getpars.c 프로젝트: JOravetz/SeisUnix
/* Initialize getpar */
static int getparinit (void)
{
	static int targc;	/* total number of args			*/
	static char **targv;	/* pointer to arg strings		*/
	static char *pfname;	/* name of parameter file		*/
	FILE *pffd;		/* file id of parameter file		*/
	int pflen;		/* length of parameter file in bytes	*/ 
	static int pfargc;	/* arg count from parameter file	*/
	bool parfile;		/* parfile existence flag		*/
	int argstrlen;
	char *argstr, *pargstr;	/* storage for command line and
						parameter file args	*/
	int nread;		/* bytes fread				*/
	int i, j;		/* counters				*/
	char *getpfname();	/* return name of parameter file	*/
	int white2null();	/* deliminate arg strings from parameter
				   file with (possibly multiple) NULLs
				   and return a count of the strings	*/
	int tabulate();		/* install symbol table			*/


	tabled = true;		/* remember table is built		*/

	/* Check if xargc was initiated */
	if(!xargc)
		err("%s: xargc=%d -- not initiated in main", __FILE__, xargc);

	/* Space needed for command lines */
	for (i = 1, argstrlen = 0; i < xargc; i++) {
		argstrlen += strlen(xargv[i]) + 1;
	}

	/* Get parfile name if there is one */
	/* parfile = (pfname = getpfname()) ? true : false; */
	if (pfname = getpfname()) {
		parfile = true;
	} else {
		parfile = false;
	}

	if (parfile) {
	 	pffd = efopen(pfname, "r");

		/* Get the length */
		efseek(pffd, 0, SEEK_END);
		pflen = eftell(pffd);
		rewind(pffd);
		argstrlen += pflen;
	} else {
		pflen = 0;
	}

	/* Allocate space for command line and parameter file
		plus nulls at the ends to help with parsing. */
	/* argstr = (char *) calloc((size_t) (1+argstrlen+1), 1); */
	argstr = (char *) ealloc1(1+argstrlen+1, 1);

	if (parfile) {
		/* Read the parfile */
		nread = efread(argstr + 1, 1, pflen, pffd);
  		if (nread != pflen) {
  	 	    err("%s: fread only %d bytes out of %d from %s",
  					__FILE__,  nread, pflen, pfname);
		}
		efclose(pffd);

		/* Zap whites in parfile to help in parsing */
		argstr[0] = '\0' ;
		pfargc = white2null(argstr, pflen);

	} else {
		pfargc = 0;
	}

	/* Total arg count */
	targc = pfargc + xargc - 1;

	/* Allocate space for total arg pointers */
	targv = (char **) ealloc1(targc, sizeof(char*));

	if (parfile) {
		/* Parse the parfile.  Skip over multiple NULLs */
		for (j = 1, i = 0; j < pflen; j++) {
			if (argstr[j] && !argstr[j-1]) {
			       targv[i++] = argstr + j;
			}
		}
	} else {
		i = 0;
	}

	/* Copy command line arguments */
	for (j = 1, pargstr = argstr + pflen + 2; j < xargc; j++) {
		strcpy(pargstr,xargv[j]);
		targv[i++] = pargstr;
		pargstr += strlen(xargv[j]) + 1;
	}

	/* Allocate space for the pointer table */
	argtbl = (ArgStruct*) ealloc1(targc, sizeof(ArgStruct));

	/* Tabulate targv */
	tabulate(targc, targv);
}
예제 #21
0
파일: zinb.c 프로젝트: rlim19/Biotools
zinb_par_t *
mle_zinb
(
   int *x,
   unsigned int nobs
)
{

   tab_t *tab = tabulate(x, nobs);

   double sum = 0.0;
   unsigned int nona = 0;
   for (size_t i = 0 ; i < tab->size ; i++) {
      sum += tab->val[i]*tab->num[i];
      nona += tab->num[i];
   }

   // Extract the number of all-zero observaions.
   const unsigned int z0 = tab->val[0] == 0 ? tab->num[0] : 0;

   double deficit[11] = {0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1};
   double init_a[12] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1};
   double init_p[12] = {0,0,0,0,0,0,0,0,0,0,0,.5};

   // Deplete some 0s from the observations, compute alpha
   // and p0 with standard negative binomial estimation
   // and keep the values to be used as initial conditions.
   for (size_t i = 0 ; i < 11 ; i++) {
      if (tab->val[0] == 0) tab->num[0] = z0 * (1-deficit[i]);
      double newmean = sum / nona / (1.0 - z0*deficit[i]/nobs);
      double alpha = nb_est_alpha(tab);
      init_a[i] = alpha;
      init_p[i] = alpha / (alpha + newmean);
   }

   // Reset 'tab'.
   if (tab->val[0] == 0) tab->num[0] = z0;

   zinb_par_t *par = calloc(1, sizeof(zinb_par_t));
   if (par == NULL) {
      fprintf(stderr, "memory error: %s:%d\n", __FILE__, __LINE__);
      return NULL;
   }

   // Try initial conditions. Number 12 is a safety in case
   // all the rest failed during the first phase.
   double max_loglik = -1.0/0.0;
   for (size_t i = 0 ; i < 12 ; i++) {

      if (init_a[i] < 0) continue;  // Skip failures.

      double a = init_a[i];
      double p = init_p[i];

      double grad;
      unsigned int iter = 0;

      double f = eval_zinb_f(a, p, nobs-z0, sum);
      double g = eval_zinb_g(a, p, tab);

      // Newton-Raphson iterations.
      while ((grad = f*f+g*g) > sq(ZINM_TOL) && iter++ < ZINM_MAXITER) {

         double dfda, dfdp, dgda, dgdp;
         dfda = dgdp = eval_zinb_dfda(a, p, nobs-z0);
         dfdp = eval_zinb_dfdp(a, p, nobs-z0, sum);
         dgda = eval_zinb_dgda(a, p, tab);

         double denom = dfdp*dgda - dfda*dgdp;
         double da = (f*dgdp - g*dfdp) / denom;
         double dp = (g*dfda - f*dgda) / denom;
         // Maintain 'a' and 'p' in their domain of definition.
         while (a+da < 0 || p+dp < 0 || p+dp > 1) {
            da /= 2;
            dp /= 2;
         }
         f = eval_zinb_f(a+da, p+dp, nobs-z0, sum);
         g = eval_zinb_g(a+da, p+dp, tab);
         // Backtrack if necessary.
         for (int j = 0 ; j < ZINM_MAXITER && f*f+g*g > grad ; j++) {
            da /= 2;
            dp /= 2;
            f = eval_zinb_f(a+da, p+dp, nobs-z0, sum);
            g = eval_zinb_g(a+da, p+dp, tab);
         }

         a = a+da;
         p = p+dp;

      }

      double pi = (nobs-z0) / (1-pow(p,a)) / nobs;
      if (pi > 1) pi = 1.0;
      if (pi < 0) pi = 0.0;
      double loglik = ll_zinb(a, p, pi, tab);
      if (loglik > max_loglik) {
         max_loglik = loglik;
         par->a = a;
         par->pi = pi;
         par->p = p;
      }
            
   }

   free(tab);

   return par;

}
예제 #22
0
int main(int argc, char **argv)
{
    Params params;
    params.m = 1;
    params.r = 2;
    params.Pr = 60;
    params.Pi = 60;
    params.peps = 0.2;
    params.t = 0.0;
    params.smear = 0;
    params.sigma = 0.0;

    const char* opt_prefix = "";
    int opt_select = OPT_SELECT_INTEGRAL;
    int opt_contour = OPT_CONTOUR_M;
    gsl_complex opt_z0 = { { 0.0 } };
    gsl_complex opt_z1 = { { 0.0 } };
    int opt_n = 10000;

    const char* const short_options = "";

    const struct option long_options[] = {
      { "help",         0, NULL, 'h' },
      { "envelope",     0, &opt_select, OPT_SELECT_ENVELOPE },
      { "integrand",    0, &opt_select, OPT_SELECT_INTEGRAND },
      { "bessel",       0, &opt_select, OPT_SELECT_BESSEL },
      { "contour-II",   0, &opt_contour, OPT_CONTOUR_II },
      { "contour-IUI",  0, &opt_contour, OPT_CONTOUR_IUI },
      { "d",            1, NULL, 'd' },
      { "n",            1, NULL, 'n' },
      { "m",            1, NULL, 'm' },
      { "prefix",       1, NULL, 'p' },
      { "r",            1, NULL, 'r' },
      { "t",            1, NULL, 't' },
      { "z0",           1, NULL, '0' },
      { "z1",           1, NULL, '1' },
      { "Pr",           1, NULL, 'P' },
      { "Pi",           1, NULL, 'I' },
      { "smear",        1, NULL, 's' },
      { NULL,           0, NULL, 0   } /* end */
    };

    int next_option;
    do {
        next_option = getopt_long(argc, argv, short_options,
                long_options, NULL);
        switch (next_option)
        {
            case 'h':
                print_usage(stdout, 0);

            case 'd':
                parse_double(optarg, &params.d);
                break;

            case 'm':
                parse_double(optarg, &params.m);
                break;

            case 'n':
                opt_n = atoi(optarg);
                if (opt_n < 1)
                    opt_n = 1;
                break;

            case 'p':
                opt_prefix = optarg;
                break;

            case 'r':
                parse_double(optarg, &params.r);
                break;

            case 's':
                parse_double(optarg, &params.sigma);
                params.smear = 1;
                break;

            case 't':
                parse_double(optarg, &params.t);
                break;

            case '?':
                // invalid option
                print_usage(stderr, 1);

            case '0':
                parse_complex(optarg, &opt_z0);
                break;

            case '1':
                parse_complex(optarg, &opt_z1);
                break;

            case 'P':
                parse_double(optarg, &params.Pr);
                break;

            case 'I':
                parse_double(optarg, &params.Pi);
                break;

            case 0:  break; // flag handled
            case -1: break; // end of options

            default:
                abort();
        }
    }
    while (next_option != -1);

    PlotContext ctx;
    memset(&ctx, 0, sizeof(ctx));
    ctx.filename_contour = alloc_sprintf("%sCONTOUR.dat", opt_prefix);
    ctx.filename_data = alloc_sprintf("%sFUNCTION.dat", opt_prefix);

    if (opt_select != OPT_SELECT_INTEGRAL)
    {
        FILE *os = fopen(ctx.filename_data, "w");
        ComplexFunction func;
        switch (opt_select)
        {
            case OPT_SELECT_ENVELOPE : func = (ComplexFunction) &f_envelope; break;
            case OPT_SELECT_INTEGRAND: func = (ComplexFunction) &f_integrand; break;
            case OPT_SELECT_BESSEL   : func = (ComplexFunction) &f_bessel; break;
            default: abort();
        }
        tabulate(os, func, &params, opt_z0, opt_z1, opt_n);
        fclose(os);

        Contour contour;
        define_contour_line_segment(opt_z0, opt_z1, &contour);

        os = fopen(ctx.filename_contour, "w");
        emit_contour_points(&params, &contour, os);
        fclose(os);
    }
    else
    {
        Contour contour;
        switch (opt_contour)
        {
            case OPT_CONTOUR_II:
                define_contour_II(&params, params.d, &contour);
                break;
            case OPT_CONTOUR_IUI:
                define_contour_M(&params, params.d, 1, &contour);
                break;
            case OPT_CONTOUR_M:
                define_contour_M(&params, params.d, 0, &contour);
                break;
            default: abort();
        }

        FILE *os = fopen(ctx.filename_data, "w");
        tabulate_integral(
            &params,
            &contour,
            GSL_REAL(opt_z0), GSL_REAL(opt_z1),
            opt_n, os);
        fclose(os);

        os = fopen(ctx.filename_contour, "w");
        emit_contour_points(&params, &contour, os);
        fclose(os);
    }

    return 0;
}
예제 #23
0
 void ULongLiteralSyntax::stringify(stringstream* stream, int tabulation)
 {
     tabulate(stream, tabulation);
     *stream << getValue() << "ul";
 }
예제 #24
0
int main(void){
    tabulate(-1.1, 0.0, 0.05, f);
}
예제 #25
0
파일: runtests.c 프로젝트: gui11aume/zinm
void
test_tabulate
(void)
{

   uint32_t x[] = {1,2,3,4,5,6,7,8,9,10,11,12};
   tab_t *tab;
   tab = tabulate(x, 3, 4);
   test_assert_critical(tab != NULL);
   test_assert(tab->size == 4);
   test_assert(tab->val[0] == 15);
   test_assert(tab->val[1] == 18);
   test_assert(tab->val[2] == 21);
   test_assert(tab->val[3] == 24);
   for (int i = 0 ; i < 4 ; i++) {
      test_assert(tab->num[i] == 1);
   }
   free(tab);

   tab = tabulate(x, 4, 3);
   test_assert_critical(tab != NULL);
   test_assert(tab->size == 3);
   test_assert(tab->val[0] == 22);
   test_assert(tab->val[1] == 26);
   test_assert(tab->val[2] == 30);
   for (int i = 0 ; i < 3 ; i++) {
      test_assert(tab->num[i] == 1);
   }
   free(tab);

   uint32_t y[] = {4096,2048,1024,512};
   tab = tabulate(y, 1, 4);
   test_assert_critical(tab != NULL);
   test_assert(tab->size == 4);
   test_assert(tab->val[0] == 512);
   test_assert(tab->val[1] == 1024);
   test_assert(tab->val[2] == 2048);
   test_assert(tab->val[3] == 4096);
   for (int i = 0 ; i < 4 ; i++) {
      test_assert(tab->num[i] == 1);
   }
   free(tab);

   tab = tabulate(y, 2, 2);
   test_assert_critical(tab != NULL);
   test_assert(tab->size == 2);
   test_assert(tab->val[0] == 2560);
   test_assert(tab->val[1] == 5120);
   for (int i = 0 ; i < 2 ; i++) {
      test_assert(tab->num[i] == 1);
   }
   free(tab);

   uint32_t z[] = {1,2,23784983};
   tab = tabulate(z, 1, 3);
   test_assert_critical(tab != NULL);
   test_assert(tab->size == 3);
   test_assert(tab->val[0] == 1);
   test_assert(tab->val[1] == 2);
   test_assert(tab->val[2] == 23784983);

   free(tab);
   return;

}
예제 #26
0
파일: tests_zinm.c 프로젝트: ezorita/zerone
void
test_nb_est_alpha
(void)
{

   tab_t *tab;
   // 0:14, 1:5, 2:4, 3:1, 5:1
   int x1[25] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                  1,1,1,1,1,2,2,2,2,3,5 };
   tab = tabulate(x1, 25);
   test_assert_critical(tab != NULL);
   test_assert(fabs(nb_est_alpha(tab)-0.9237) < 1e-3);
   free(tab);

   // 0:27, 1:12, 2:8, 3:1, 4:1, 5:1
   int x2[50] = {3,0,1,2,0,0,1,0,0,0,0,1,1,0,0,1,2,2,0,0,0,1,2,
      0, 0,0,0,0,4,0,0,0,1,5,1,0,1,2,1,2,2,2,0,0,0,1,0,1,0,0};
   tab = tabulate(x2, 50);
   test_assert_critical(tab != NULL);
   test_assert(fabs(nb_est_alpha(tab)-1.3436) < 1e-3);
   free(tab);

   // 0:12, 1:7, 2:13, 3:4, 4:6, 5:2, 6:1, 7:3, 8:1, 9:1
   int x3[50] = {4,5,2,1,2,4,2,2,0,4,2,1,3,6,0,0,7,3,0,8,4,2,0,
      0,2,3,2,3,7,9,2,4,0,4,2,0,0,2,5,1,1,2,1,0,0,0,1,2,1,7};
   tab = tabulate(x3, 50);
   test_assert_critical(tab != NULL);
   test_assert(fabs(nb_est_alpha(tab)-1.7969) < 1e-3);
   free(tab);

   // 0:39, 1:8, 2:2, 3:1
   int x4[50] = {1,0,0,0,0,0,3,1,0,1,0,0,0,0,0,0,0,1,0,0,0,2,0,
      2,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0};
   tab = tabulate(x4, 50);
   test_assert_critical(tab != NULL);
   test_assert(fabs(nb_est_alpha(tab)-0.7073) < 1e-3);
   free(tab);

   // 0:59, 1:83, 2:99, 3:67, 4:67, 5:49, 6:27, 7:22, 8:11, 9:6
   // 10:6, 11:3, 12:2, 13:3
   int x5[500] = {1,0,0,1,1,2,1,0,5,7,1,3,3,1,6,0,2,5,7,0,5,2,1,
       10,5,3,4,5,7,0,8,6,3,0,2,1,1,0,2,3,7,2,3,2,2,1,0,4,4,2,4,2,
       0,6,3,2,5,2,1,4,3,4,2,2,5,3,2,0,2,8,1,3,1,7,5,1,4,1,1,0,2,
       2,4,1,1,1,4,1,3,4,4,10,5,2,0,7,1,6,1,3,6,4,0,2,4,1,12,2,5,
       6,5,4,1,11,0,1,3,2,4,2,0,2,3,4,0,2,9,9,7,4,2,1,3,3,3,4,2,9,
       2,4,3,2,2,4,2,5,3,0,1,3,2,0,3,3,4,1,3,3,5,7,3,3,2,1,5,5,4,
       6,1,1,1,2,9,5,1,2,4,0,2,1,0,3,2,4,3,1,4,2,1,4,1,6,0,6,5,3,
       5,2,0,1,2,1,0,5,3,2,7,6,4,3,2,5,7,5,5,1,1,3,10,2,0,5,0,1,2,
       0,5,1,2,3,6,4,0,3,1,2,2,4,3,0,3,2,5,4,10,1,2,4,4,2,13,4,3,
       1,5,4,8,5,6,2,3,4,3,1,5,5,1,8,2,0,5,7,3,2,2,4,2,3,1,5,3,7,
       13,1,4,7,5,5,0,3,0,4,2,3,1,2,4,2,8,1,2,5,6,1,1,0,7,2,2,3,5,
       12,2,2,2,0,3,3,4,0,2,5,1,10,0,7,6,5,0,11,2,3,7,3,5,4,2,1,2,
       4,0,2,2,2,0,6,2,3,4,2,3,7,3,5,2,5,0,4,4,6,3,1,2,7,3,0,2,5,
       7,2,2,0,0,0,6,3,0,1,1,5,5,2,6,2,4,6,0,1,2,3,2,2,2,3,4,1,1,
       4,0,2,0,1,3,4,1,2,2,3,1,4,4,3,4,4,1,5,2,13,4,10,5,6,1,0,5,
       0,0,5,6,0,1,8,5,1,3,1,8,1,8,1,6,7,2,8,2,2,3,3,0,4,2,1,9,6,
       0,6,7,1,8,2,2,1,11,3,0,4,2,5,1,6,8,3,4,7,0,4,2,4,1,1,1,6,0,
       4,4,6,2,1,3,1,0,4,9,3,1,4,2,2,0,1};
   tab = tabulate(x5, 500);
   test_assert_critical(tab != NULL);
   test_assert(fabs(nb_est_alpha(tab)-3.0057) < 1e-3);
   free(tab);
}
예제 #27
0
 void UIntegerLiteralSyntax::stringify(stringstream* stream, int tabulation)
 {
     tabulate(stream, tabulation);
     *stream << getValue() << "u";
 }