Пример #1
0
Файл: sqrt.c Проект: elbing/apex
void sqrt(int p2)
{
	static int af = 0;
	int nps;	/* point size for radical */
	double radscale = 0.95;

	if (ttype == DEVPOST)
		radscale = 1.05;
	nps = ps * radscale * eht[p2] / EM(1.0,ps) + 0.99;	/* kludgy */
	nps = max(EFFPS(nps), ps);
	yyval = p2;
	if (ttype == DEVCAT || ttype == DEVAPS)
		eht[yyval] = EM(1.2, nps);
	else if (ttype == DEVPOST)
		eht[yyval] = EM(1.15, nps);
	else		/* DEV202, DEVPOST */
		eht[yyval] = EM(1.15, nps);
	dprintf(".\tS%d <- sqrt S%d;b=%g, h=%g, nps=%d\n",
		yyval, p2, ebase[yyval], eht[yyval], nps);
	printf(".as %d \\|\n", yyval);
	nrwid(p2, ps, p2);
	if (af++ == 0)
		printf(".af 10 01\n");	/* make it two digits when it prints */
	printf(".nr 10 %.3fu*\\n(.su/10\n", 9.2*eht[p2]);	/* this nonsense */
			/* guesses point size corresponding to height of stuff */
	printf(".ds %d \\v'%gm'\\s(\\n(10", yyval, REL(ebase[p2],ps));
	if (ttype == DEVCAT || ttype == DEVAPS)
		printf("\\v'-.2m'\\(sr\\l'\\n(%du\\(rn'\\v'.2m'", p2);
	else		/* DEV202, DEVPOST so far */
		printf("\\(sr\\l'\\n(%du\\(rn'", p2);
	printf("\\s0\\v'%gm'\\h'-\\n(%du'\\^\\*(%d\n", REL(-ebase[p2],ps), p2, p2);
	lfont[yyval] = rfont[yyval] = ROM;
}
Пример #2
0
void
lpile(int type, int p1, int p2) {
	int i, nlist, nlist2, mid;
#ifndef	NEQN
	float h, b, bi, hi, gap;
#else	/* NEQN */
	int h, b, bi, hi, gap;
#endif	/* NEQN */
	yyval.token = oalloc();
#ifndef NEQN
	gap = VERT(EM(0.4, ps)); /* 4/10 m between blocks */
#else /* NEQN */
	gap = VERT(1);
#endif /* NEQN */
	if( type=='-' ) gap = 0;
	nlist = p2 - p1;
	nlist2 = (nlist+1)/2;
	mid = p1 + nlist2 -1;
	h = 0;
	for( i=p1; i<p2; i++ )
		h += eht[lp[i]];
	eht[yyval.token] = h + (nlist-1)*gap;
	b = 0;
	for( i=p2-1; i>mid; i-- )
		b += eht[lp[i]] + gap;
	ebase[yyval.token] = (nlist%2) ? b + ebase[lp[mid]]
#ifndef NEQN
			: b - VERT(EM(0.5, ps)) - gap;
#else /* NEQN */
			: b - VERT(1) - gap;
Пример #3
0
void setintegral(void)
{
	yyval = salloc();
	printf(".ds %d %s\n", yyval, lookup(deftbl, "int_def")->cval);
	eht[yyval] = EM(Intht, ps+Intps);
	ebase[yyval] = EM(Intbase, ps);
	lfont[yyval] = rfont[yyval] = ROM;
}
Пример #4
0
    void rateclass_t::learn(
            double & lg_L,
            double & aicc,
            vector< pair< double, double > > & params,
            const int nrestart
            ) const
    {
        params.clear();
        params.push_back( make_pair( 1.0, 0.5 ) );
        lg_L = EM( data, params );
        aicc = _aicc( 1, lg_L, data.size() / factor );

        for ( int i = 2; ; ++i ) {
            double old_lg_L, old_aicc;
            vector< pair< double, double > > old_params = params;

            old_params.push_back( make_pair( 1.0, 0.5 ) );

            initialize_params( old_params, 0 );
            old_lg_L = EM( data, old_params );

            for ( int j = 1; j < nrestart; ++j ) {
                double new_lg_L;
                vector< pair< double, double > > new_params = old_params;

                initialize_params( new_params, j );
                new_lg_L = EM( data, new_params );

                if ( new_lg_L > old_lg_L ) {
                    old_lg_L = new_lg_L;
                    old_params = new_params;
                }
            }

            old_aicc = _aicc( 2 * i, old_lg_L, data.size() / factor );

            // if our AICc doesn't improve, we're done
            if ( old_aicc >= aicc )
                break;

            aicc = old_aicc;
            lg_L = old_lg_L;
            params = old_params;
        }

        // we've actually rates corresponding to the majority,
        // but we really want the inverse
        for ( unsigned i = 0; i < params.size(); ++i )
            params[ i ].second = 1.0 - params[ i ].second;

        sort( params.begin(), params.end(), rate_cmp );
    }
Пример #5
0
void
putout(int p1) {
#ifndef	NEQN
	float before, after;
	if(dbg)printf(".\tanswer <- S%d, h=%g,b=%g\n",p1, eht[p1], ebase[p1]);
#else	/* NEQN */
	int before, after;
	if(dbg)printf(".\tanswer <- S%d, h=%d,b=%d\n",p1, eht[p1], ebase[p1]);
#endif	/* NEQN */
	eqnht = eht[p1];
	printf(".ds %d ", p1);
	/* suppposed to leave room for a subscript or superscript */
#ifndef NEQN
	before = eht[p1] - ebase[p1] - VERT(EM(1.2, ps));
#else /* NEQN */
	before = eht[p1] - ebase[p1] - VERT(3);	/* 3 = 1.5 lines */
#endif /* NEQN */
	if (spaceval != NULL)
		printf("\\x'0-%s'", spaceval);
	else if (before > 0)
#ifndef	NEQN
		printf("\\x'0-%gp'", before);
#else	/* NEQN */
		printf("\\x'0-%du'", before);
#endif	/* NEQN */
	printf("\\f%c\\s%s\\*(%d%s\n",
		gfont, tsize(gsize), p1, ital(rfont[p1]) ? "\\|" : "");
	printf(".ie \\n(.X=0 .as %d \\s\\n(99\n", p1);
	printf(".el .as %d \\s[\\n(99]\n", p1);
	printf(".as %d \\f\\n(98", p1);
#ifndef NEQN
	after = ebase[p1] - VERT(EM(0.2, ps));
#else /* NEQN */
	after = ebase[p1] - VERT(1);
#endif /* NEQN */
	if (spaceval == NULL && after > 0)
#ifndef	NEQN
		printf("\\x'%gp'", after);
#else	/* NEQN */
		printf("\\x'%du'", after);
#endif	/* NEQN */
	putchar('\n');
	eqnreg = p1;
	if (spaceval != NULL) {
		free(spaceval);
		spaceval = NULL;
	}

}
Пример #6
0
void boverb(int p1, int p2)
{
	int treg;
	double h, b, d, d1, d2;
	extern double Overgap, Overwid, Overline;

	treg = salloc();
	yyval = p1;
	d = EM(Overgap, ps);
	h = eht[p1] + eht[p2] + d;
	b = eht[p2] - d;
	dprintf(".\tS%d <- %d over %d; b=%g, h=%g\n", 
		yyval, p1, p2, b, h);
	nrwid(p1, ps, p1);
	nrwid(p2, ps, p2);
	printf(".nr %d \\n(%d\n", treg, p1);
	printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
	printf(".nr %d \\n(%d+%gm\n", treg, treg, Overwid);
	d2 = eht[p2]-ebase[p2]-d;	/* denom */
	printf(".ds %d \\v'%gm'\\h'\\n(%du-\\n(%du/2u'\\*(%d\\v'%gm'\\\n", 
		yyval, REL(d2,ps), treg, p2, p2, REL(-d2,ps));
	d1 = 2 * d + ebase[p1];		/* num */
	printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%gm'\\*(%d\\v'%gm'\\\n", 
		p2, p1, REL(-d1,ps), p1, REL(d1,ps));
	printf("\\h'-\\n(%du-\\n(%du/2u+%gm'\\v'%gm'\\l'\\n(%du-%gm'\\h'%gm'\\v'%gm'\n", 
		treg, p1, Overline, REL(-d,ps),
		treg, 2*Overline, Overline, REL(d,ps));
	ebase[yyval] = b;
	eht[yyval] = h;
	lfont[yyval] = rfont[yyval] = 0;
	sfree(p2);
	sfree(treg);
}
Пример #7
0
void
sqrt(int p2) {
#ifndef NEQN
	float nps;

	nps = (int)(EFFPS(((eht[p2]*9)/10+(resolution/POINT-1))/(resolution/POINT)));
#endif /* NEQN */
	yyval.token = p2;
#ifndef NEQN
	eht[yyval.token] = VERT(EM(1.2, nps));
	if(dbg)printf(".\tsqrt: S%d <- S%d;b=%g, h=%g\n", 
		yyval.token, p2, ebase[yyval.token], eht[yyval.token]);
	if (ital(rfont[yyval.token]))
		printf(".as %d \\|\n", yyval.token);
#endif /* NEQN */
	nrwid(p2, ps, p2);
#ifndef NEQN
	printf(".ds %d \\v'%gp'\\s%s\\v'-.2m'\\(sr\\l'\\n(%du\\(rn'\\v'.2m'\\s%s", 
		yyval.token, ebase[p2], tsize(nps), p2, tsize(ps));
	printf("\\v'%gp'\\h'-\\n(%du'\\*(%d\n", -ebase[p2], p2, p2);
	lfont[yyval.token] = ROM;
#else /* NEQN */
	printf(".ds %d \\v'%du'\\e\\L'%du'\\l'\\n(%du'",
		p2, ebase[p2], -eht[p2], p2);
	printf("\\v'%du'\\h'-\\n(%du'\\*(%d\n", eht[p2]-ebase[p2], p2, p2);
	eht[p2] += VERT(1);
	if(dbg)printf(".\tsqrt: S%d <- S%d;b=%d, h=%d\n", 
		p2, p2, ebase[p2], eht[p2]);
#endif /* NEQN */
}
Пример #8
0
double CSurface2D::operator()(double X)
  {
  if (!m_UseSurface)
    return m_fnY(X);

  long Ix;
  double Fx;
  X2Map(X, Ix, Fx);

  ASSERT(Ix<m_Elements.GetSize());
//  int iFx=(int)floor(Fx*m_iDX);
//  if (m_DoSmoothing && (iFx==0 || iFx==(m_iDX-1))
  if (m_DoSmoothing)
    {
    long IxM, IxP;
    double FxM, FxP;
    GetDX(Ix, Fx, m_DX, m_nDivs, IxM, FxM, IxP, FxP);
    CSurface2DElement &EM=GetElement(IxM);
    CSurface2DElement &EP=GetElement(IxP);

    //if (m_ForceFn) // Force Use Of Function
    //  return m_fnY(X);
  
    return m_fnYO(0.5*(EM(FxM)+EP(FxP)));
    }

  CSurface2DElement &E=GetElement(Ix);
  
  //if (m_ForceFn) // Force Use Of Function
  //  return m_fnY(X);
  return m_fnYO(E(Fx));
  };
Пример #9
0
void bshiftb(int p1, int dir, int p2)
{
	int subps, n;
	double shval, d1, h1, b1, h2, b2;
	char *sh1, *sh2;

	yyval = p1;
	h1 = eht[p1];
	b1 = ebase[p1];
	h2 = eht[p2];
	b2 = ebase[p2];
	subps = ps;
	ps += deltaps;
	if (dir == SUB) {
		/* base .2m below bottom of main box */
		shval = b1 + EM(Subbase, ps);
		ebase[yyval] = shval + b2;
		eht[yyval] = max(h1-b1+shval+b2, h2);
		if (rfont[p1] == ITAL && lfont[p2] == ROM)
			n = 2;		/* Sub1space */
		else
			n = max(2, class[rclass[p1]][lclass[p2]]);
		sh1 = pad(n);
		rclass[p1] = OTHER;	/* OTHER leaves too much after sup */
	} else {	/* superscript */
Пример #10
0
void bridge_EM(double *betap,
	       const double *yp,
	       const double *Xp,
	       const double *ratio,
	       const double *alpha,
	       const int *P,
	       const int *N,
	       const double *lambda_max,
	       const double *tol,
	             int *max_iter,
	       const bool *use_cg)
{
  Matrix beta(*P, 1);

  Matrix y(yp, *N, 1);
  Matrix X(Xp, *N, *P);

  if (*use_cg) printf("Using conjugate gradient method.\n");

  int total_iter = EM(beta, y, X, *ratio, *alpha, *lambda_max, *tol, *max_iter, *use_cg);
  *max_iter = total_iter;

  MatrixFrame beta_mf(betap, *P);
  beta_mf.copy(beta);
}
Пример #11
0
/*
* PSSR Encode Operation
*/
secure_vector<byte> PSSR::encoding_of(const secure_vector<byte>& msg,
                                      size_t output_bits,
                                      RandomNumberGenerator& rng)
{
    const size_t HASH_SIZE = m_hash->output_length();

    if(msg.size() != HASH_SIZE)
        throw Encoding_Error("PSSR::encoding_of: Bad input length");
    if(output_bits < 8*HASH_SIZE + 8*m_SALT_SIZE + 9)
        throw Encoding_Error("PSSR::encoding_of: Output length is too small");

    const size_t output_length = (output_bits + 7) / 8;

    secure_vector<byte> salt = rng.random_vec(m_SALT_SIZE);

    for(size_t j = 0; j != 8; ++j)
        m_hash->update(0);
    m_hash->update(msg);
    m_hash->update(salt);
    secure_vector<byte> H = m_hash->final();

    secure_vector<byte> EM(output_length);

    EM[output_length - HASH_SIZE - m_SALT_SIZE - 2] = 0x01;
    buffer_insert(EM, output_length - 1 - HASH_SIZE - m_SALT_SIZE, salt);
    mgf1_mask(*m_hash, H.data(), HASH_SIZE, EM.data(), output_length - HASH_SIZE - 1);
    EM[0] &= 0xFF >> (8 * ((output_bits + 7) / 8) - output_bits);
    buffer_insert(EM, output_length - 1 - HASH_SIZE, H);
    EM[output_length-1] = 0xBC;

    return EM;
}
Пример #12
0
void
setintegral(void) {
	const char *f;

	yyval.token = oalloc();
	f = "\\(is";
#ifndef NEQN
	printf(".ds %d \\s%s\\v'.1m'\\s+4%s\\s-4\\v'-.1m'\\s%s\n", 
		yyval.token, tsize(ps), f, tsize(ps));
	eht[yyval.token] = VERT(EM(1.15, ps+4));
	ebase[yyval.token] = VERT(EM(0.3, ps));
#else /* NEQN */
	printf(".ds %d %s\n", yyval.token, f);
	eht[yyval.token] = VERT(2);
	ebase[yyval.token] = 0;
#endif /* NEQN */
	lfont[yyval.token] = rfont[yyval.token] = ROM;
}
Пример #13
0
void text(int t, char *p1)	/* convert text string p1 of type t */
{
    int c;
    char *p;
    tbl *tp;

    yyval = salloc();
    ebase[yyval] = 0;
    eht[yyval] = EM(1.0, ps);	/* ht in ems of orig size */
    lfont[yyval] = rfont[yyval] = ROM;
    lclass[yyval] = rclass[yyval] = OTHER;
    if (t == QTEXT) {
        for (p = p1; *p; p++)	/* scan for embedded \f's */
            if (*p == '\\' && *(p+1) == 'f')
                break;
        if (*p)		/* if found \f, leave it alone and hope */
            p = p1;
        else {
            sprintf(cs, "\\f%s%s\\fP", ftp->name, p1);
            p = cs;
        }
    } else if (t == SPACE)
        p = "\\ ";
    else if (t == THIN)
        p = "\\|";
    else if (t == TAB)
        p = "\\t";
    else if ((tp = lookup(restbl, p1)) != NULL) {
        p = tp->cval;
    } else {
        lf = rf = 0;
        lastft = 0;
        nclass = NONE;	/* get started with no class == no pad */
        csp = cs;
        for (psp = p1; (c = textc()) != '\0'; ) {
            nextft = ft;
            pclass = nclass;
            rf = trans(c, p1);
            if (lf == 0) {
                lf = rf;	/* left stuff is first found */
                lclass[yyval] = nclass;
            }
            if (csp-cs > CSSIZE)
                ERROR "converted token %.25s... too long", p1 FATAL ;
        }
        sadd("\\fP");
        *csp = '\0';
        p = cs;
        lfont[yyval] = lf;
        rfont[yyval] = rf;
        rclass[yyval] = nclass;
    }
    dprintf(".\t%dtext: S%d <- %s; b=%g,h=%g,lf=%c,rf=%c,ps=%d\n",
            t, yyval, p, ebase[yyval], eht[yyval], lfont[yyval], rfont[yyval], ps);
    printf(".ds %d \"%s\n", yyval, p);
}
Пример #14
0
	void ChoiceForm::UpdateChoicePanel(String shaderName)
	{
		glFinish();
		if (shaderName.Length())
			SetText(L"Choice Control - " + shaderName);
		currentShaderName = shaderName;
		scrollPanel->ClearChildren();
		existingChoices.Clear();
		additionalAttribs.Clear();
		auto choices = choiceControl->GetChoices(shaderName, existingChoices);
		int line = 0;
		comboBoxChoiceNames.Clear();
		choiceComboBoxes.Clear();
		choiceCheckBoxes.Clear();
		existingChoices.Clear();
		scrollPanel->SetLayout(GraphicsUI::ContainerLayoutType::Stack);
		for (auto & choice : choices)
		{
			if (choice.Options.Count() == 1)
				continue;
			auto wrapper = new GraphicsUI::Container(scrollPanel);
			wrapper->AutoHeight = true;
			wrapper->Padding = EM(0.1f);
			auto lbl = new GraphicsUI::CheckBox(wrapper);
			lbl->SetText(choice.ChoiceName);
			lbl->Top = EM(0.2f);
			choiceCheckBoxes.Add(choice.ChoiceName, lbl);
			auto cmb = new GraphicsUI::ComboBox(wrapper);
			cmb->AddTextItem(L"(auto) " + choice.DefaultValue);
			for (auto & opt : choice.Options)
			{
				cmb->AddTextItem(opt.ToString());
			}
			comboBoxChoiceNames[cmb] = choice.ChoiceName;
			choiceComboBoxes[choice.ChoiceName] = cmb;
			cmb->SetSelectedIndex(0);
			cmb->OnChanged.Bind(this, &ChoiceForm::ChoiceComboBox_Changed);
			cmb->Posit(0, 0, EM(7.0f), EM(1.5f));
			cmb->DockStyle = GraphicsUI::Control::dsRight;
			line++;
		}
		SizeChanged();
	}
Пример #15
0
 double MixMod::LRS()
{
double lrs,llnull;
int tmpnumstep=1;
k=1;
EM(tmpnumstep);
llnull=likelihood();
lrs=-2.0*(llnull-ll);
if(lrs < 0.) lrs=0.;
return lrs;
}
Пример #16
0
void
boverb(int p1, int p2) {
	int treg;
#ifndef	NEQN
	float h, b, d;
#else	/* NEQN */
	int h, b, d;
#endif	/* NEQN */

	treg = oalloc();
	yyval.token = p1;
#ifndef NEQN
	d = VERT(EM(0.3, ps));
	h = eht[p1] + eht[p2] + d;
#else /* NEQN */
	d = VERT(1);
	h = eht[p1] + eht[p2];
#endif /* NEQN */
	b = eht[p2] - d;
#ifndef	NEQN
	if(dbg)printf(".\tb:bob: S%d <- S%d over S%d; b=%g, h=%g\n", 
		yyval.token, p1, p2, b, h);
#else	/* NEQN */
	if(dbg)printf(".\tb:bob: S%d <- S%d over S%d; b=%d, h=%d\n", 
		yyval.token, p1, p2, b, h);
#endif	/* NEQN */
	nrwid(p1, ps, p1);
	nrwid(p2, ps, p2);
	printf(".nr %d \\n(%d\n", treg, p1);
	printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
#ifndef NEQN
	printf(".nr %d \\n(%d+\\s%s.5m\\s0\n", treg, treg, tsize(EFFPS(ps)));
	printf(".ds %d \\v'%gp'\\h'\\n(%du-\\n(%du/2u'\\*(%d\\\n", 
		yyval.token, eht[p2]-ebase[p2]-d, treg, p2, p2);
	printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%gp'\\*(%d\\\n", 
		p2, p1, -(eht[p2]-ebase[p2]+d+ebase[p1]), p1);
	printf("\\h'-\\n(%du-\\n(%du/2u+.1m'\\v'%gp'\\l'\\n(%du-.2m'\\h'.1m'\\v'%gp'\n", 
		 treg, p1, ebase[p1]+d, treg, d);
#else /* NEQN */
	printf(".ds %d \\v'%du'\\h'\\n(%du-\\n(%du/2u'\\*(%d\\\n", 
		yyval.token, eht[p2]-ebase[p2]-d, treg, p2, p2);
	printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%du'\\*(%d\\\n", 
		p2, p1, -eht[p2]+ebase[p2]-ebase[p1], p1);
	printf("\\h'-\\n(%du-\\n(%du-2u/2u'\\v'%du'\\l'\\n(%du'\\v'%du'\n", 
		 treg, p1, ebase[p1], treg, d);
#endif /* NEQN */
	ebase[yyval.token] = b;
	eht[yyval.token] = h;
	lfont[yyval.token] = rfont[yyval.token] = 0;
	ofree(p2);
	ofree(treg);
}
Пример #17
0
void funny(int n)
{
	char *f = 0;

	yyval = salloc();
	switch (n) {
	case SUM:
		f = lookup(deftbl, "sum_def")->cval; break;
	case UNION:
		f = lookup(deftbl, "union_def")->cval; break;
	case INTER:	/* intersection */
		f = lookup(deftbl, "inter_def")->cval; break;
	case PROD:
		f = lookup(deftbl, "prod_def")->cval; break;
	default:
		ERROR "funny type %d in funny", n FATAL;
	}
	printf(".ds %d %s\n", yyval, f);
	eht[yyval] = EM(1.0, ps+Funnyps) - EM(Funnyht, ps);
	ebase[yyval] = EM(Funnybase, ps);
	dprintf(".\tS%d <- %s; h=%g b=%g\n", 
		yyval, f, eht[yyval], ebase[yyval]);
	lfont[yyval] = rfont[yyval] = ROM;
}
Пример #18
0
void em_sub(const int id, ExamMgr& ExM, TFlt& alpha, TFltV& ThV){
	int NSuc = 0; TIntPrV gV;
	for (int rpt=0; rpt<ExM.Rpt; rpt++){
		printf("[%d] rpt = %d\n", id, rpt);
		ExM.Sample(gV);
		TCEMBetaBinomGeneral EM(ExM.W, ExM.BoundW, ExM.GetPdUU(), ExM.alpha, gV);
		if (EM.Run()) {
			alpha += EM.alpha;
			for (int i=0; i<=ExM.W; i++) ThV[i] += EM.ThV[i];
			NSuc++;
		}
	}
	alpha /= NSuc;
	for (int i=0; i<ThV.Len(); i++) ThV[i] /= NSuc;
	printf("[%d] Experiment repeats %d times, and %d succeeded.\n", id, ExM.Rpt, NSuc);
}
Пример #19
0
void move(int dir, int amt, int p)
{
	double a;

	yyval = p;
	a = EM(amt/100.0, ps);
	printf(".ds %d ", yyval);
	if (dir == FWD || dir == BACK)
		printf("\\h'%s%gm'\\*(%d\n", (dir==BACK) ? "-" : "", a, p);
	else if (dir == UP)
		printf("\\v'-%gm'\\*(%d\\v'%gm'\n", a, p, a);
	else if (dir == DOWN)
		printf("\\v'%gm'\\*(%d\\v'-%gm'\n", a, p, a);
	dprintf(".\tmove %d dir %d amt %g; h=%g b=%g\n", 
		p, dir, a, eht[yyval], ebase[yyval]);
}
Пример #20
0
void
text(int t, char *p1)
{
	int c;
	char *p;
	tbl *tp, *lookup();
	extern tbl *restbl[];

	yyval = oalloc();
	ebase[yyval] = 0;
#ifndef NEQN
	eht[yyval] = VERT(EM(1.0, EFFPS(ps)));	/* ht in machine units */
#else	/* NEQN */
	eht[yyval] = VERT(2);	/* 2 half-spaces */
#endif	/* NEQN */
	lfont[yyval] = rfont[yyval] = ROM;
	if (t == QTEXT)
		p = p1;
	else if (t == SPACE)
		p = "\\ ";
	else if (t == THIN)
		p = "\\|";
	else if (t == TAB)
		p = "\\t";
	else if ((tp = lookup(restbl, p1, NULL)) != NULL)
		p = tp->defn;
	else {
		lf = rf = 0;
		for (csp = psp = 0; (c = p1[psp++]) != '\0'; ) {
			rf = trans(c, p1);
			if (lf == 0)
				lf = rf;	/* save first */
			if (csp > CSSIZE)
				error(FATAL, gettext(
				    "converted token %.25s... too long"), p1);
		}
		cs[csp] = '\0';
		p = cs;
		lfont[yyval] = lf;
		rfont[yyval] = rf;
	}
	if (dbg)
		printf(".\t%dtext: S%d <- %s; b=%d,h=%d,lf=%c,rf=%c\n",
		    t, yyval, p, ebase[yyval], eht[yyval], lfont[yyval],
		    rfont[yyval]);
	printf(".ds %d \"%s\n", yyval, p);
}
Пример #21
0
void MixMod::Compute(int * NUMK, double * LL, double * P, double * T, double * COMP_VAR)
{ 
 int numk,i;
// MessageBox (0, "0", "START", MB_ICONINFORMATION);
 Grid();   // construct grid of potential subpopulation means 
 CalcMat(); // calculation of mxing kernel density
 vem();   // VEM algorithm
 Update(); // Find subpoplations with positve weight, i.e. p > 0.01
 EM(numstep); // refiend soultion with EM algorithm

 numk=Combine(); // final solution: combine close components
 if (dens==0) COMP_VAR[0] = compvar;
 NUMK[0] = numk;
 LL[0] = ll;
 for(i=0;i<numk;i++){
 P[i] = p[i];
 T[i] = t[i];      
 }
 
}
Пример #22
0
	void ChoiceForm::InitUI()
	{
		auto leftPanel = new GraphicsUI::Container(this);
		leftPanel->DockStyle = GraphicsUI::Control::dsLeft;
		leftPanel->Posit(0, 0, EM(5.2f), EM(10.0f));
		leftPanel->Padding = EM(0.2f);
		shaderBox = new GraphicsUI::ListBox(leftPanel);
		shaderBox->DockStyle = GraphicsUI::Control::dsFill;
		shaderBox->OnChanged.Bind(this, &ChoiceForm::SelectedShaderChanged);
		auto toolFlowPanel = new GraphicsUI::Container(this);
		toolFlowPanel->SetLayout(GraphicsUI::ContainerLayoutType::Flow);
		toolFlowPanel->DockStyle = GraphicsUI::Control::dsTop;
		toolFlowPanel->AutoHeight = true;
		auto editButton = new GraphicsUI::Button(toolFlowPanel, L"Edit");
		editButton->Margin = EM(0.2f);
		editButton->OnClick.Bind(this, &ChoiceForm::EditButton_Clicked);
		applyButton = new GraphicsUI::Button(toolFlowPanel, L"Recompile");
		applyButton->Margin = EM(0.2f);
		applyButton->OnClick.Bind(this, &ChoiceForm::ApplyButton_Clicked);
		resetButton = new GraphicsUI::Button(toolFlowPanel, L"Reset");
		resetButton->Margin = EM(0.2f);
		resetButton->OnClick.Bind(this, &ChoiceForm::ResetButton_Clicked);
		autoRecompileCheckBox = new GraphicsUI::CheckBox(toolFlowPanel);
		autoRecompileCheckBox->SetText(L"Auto Recompile");
		autoRecompileCheckBox->Margin = EM(0.2f);
		autoRecompileCheckBox->Margin.Top = EM(0.3f);
		autoRecompileCheckBox->Checked = true;
#ifdef ENABLE_AUTO_TUNE
		timeBudgetTextBox = new GraphicsUI::TextBox(toolFlowPanel);
		timeBudgetTextBox->SetText(L"10");
		timeBudgetTextBox->Posit(0, 0, EM(3.0f), EM(1.5f));
		timeBudgetTextBox->Margin = EM(0.2f);
		timeBudgetTextBox->Margin.Top = EM(0.3f);
		autoTuneButton = new GraphicsUI::Button(toolFlowPanel, L"Autotune");
		autoTuneButton->Margin = EM(0.2f);
		autoTuneButton->OnClick.Bind(this, &ChoiceForm::AutotuneButton_Clicked);
		autoTuneTexButton = new GraphicsUI::Button(toolFlowPanel, L"Tune Texture");
		autoTuneTexButton->Margin = EM(0.2f);
		autoTuneTexButton->OnClick.Bind(this, &ChoiceForm::AutotuneTexButton_Clicked);
		saveScheduleButton = new GraphicsUI::Button(toolFlowPanel, L"Save");
		saveScheduleButton->Margin = EM(0.2f);
		saveScheduleButton->OnClick.Bind(this, &ChoiceForm::SaveScheduleButton_Clicked);
#endif
		scrollPanel = new GraphicsUI::VScrollPanel(this);
		scrollPanel->DockStyle = GraphicsUI::Control::dsFill;
	}
Пример #23
0
void
bshiftb(int p1, int dir, int p2)
{
	int shval, d1, h1, b1, h2, b2;
#ifndef NEQN
	int diffps, effps, effps2;
	char *sh1, *sh2;
#endif	/* NEQN */

	yyval = p1;
	h1 = eht[p1];
	b1 = ebase[p1];
	h2 = eht[p2];
	b2 = ebase[p2];
#ifndef NEQN
	effps = EFFPS(ps);
	effps2 = EFFPS(ps+deltaps);
	diffps = deltaps;
	sh1 = sh2 = "";
#endif	/* NEQN */
	if (dir == SUB) {	/* subscript */
#ifndef NEQN
		/* top 1/2m above bottom of main box */
		d1 = VERT(EM(0.5, effps2));
#else	/* NEQN */
		d1 = VERT(1);
#endif	/* NEQN */
		shval = - d1 + h2 - b2;
		if (d1+b1 > h2) /* move little sub down */
			shval = b1-b2;
		ebase[yyval] = b1 + max(0, h2-b1-d1);
		eht[yyval] = h1 + max(0, h2-b1-d1);
#ifndef NEQN
		if (rfont[p1] == ITAL && lfont[p2] == ROM)
			sh1 = "\\|";
		if (rfont[p2] == ITAL)
			sh2 = "\\|";
#endif	/* NEQN */
	} else {	/* superscript */
#ifndef NEQN
		/* 4/10 up main box */
		d1 = VERT(EM(0.2, effps));
#else	/* NEQN */
		d1 = VERT(1);
#endif	/* NEQN */
		ebase[yyval] = b1;
#ifndef NEQN
		shval = -VERT((4 * (h1-b1)) / 10) - b2;
		if (VERT(4*(h1-b1)/10) + h2 < h1-b1)	/* raise little super */
#else	/* NEQN */
		shval = -VERT(1) - b2;
		if (VERT(1) + h2 < h1-b1)	/* raise little super */
#endif	/* NEQN */
			shval = -(h1-b1) + h2-b2 - d1;
#ifndef NEQN
		eht[yyval] = h1 + max(0, h2-VERT((6*(h1-b1))/10));
		if (rfont[p1] == ITAL)
			sh1 = "\\|";
		if (rfont[p2] == ITAL)
			sh2 = "\\|";
#else	/* NEQN */
		eht[yyval] = h1 + max(0, h2 - VERT(1));
#endif	/* NEQN */
	}
	if (dbg)
		printf(".\tb:b shift b: S%d <- S%d vert %d S%d vert %d; "
		    "b=%d, h=%d\n", yyval, p1, shval, p2, -shval,
		    ebase[yyval], eht[yyval]);
#ifndef NEQN
	printf(".as %d \\v'%du'\\s-%d%s\\*(%d\\s+%d%s\\v'%du'\n",
	    yyval, shval, diffps, sh1, p2, diffps, sh2, -shval);
	ps += deltaps;
	if (rfont[p2] == ITAL)
		rfont[p1] = 0;
	else
		rfont[p1] = rfont[p2];
#else	/* NEQN */
	printf(".as %d \\v'%du'\\*(%d\\v'%du'\n",
	    yyval, shval, p2, -shval);
#endif	/* NEQN */
	ofree(p2);
}
Пример #24
0
void
shift2(int p1, int p2, int p3)
{
	int effps, h1, h2, h3, b1, b2, b3, subsh, d1, d2, supsh, treg;
#ifndef NEQN
	int effps2;
#endif	/* NEQN */

	treg = oalloc();
	yyval = p1;
	if (dbg) printf(".\tshift2 s%d <- %d %d %d\n", yyval, p1, p2, p3);
	effps = EFFPS(ps+deltaps);
#ifndef NEQN
	eht[p3] = h3 = VERT((eht[p3] * effps) / EFFPS(ps));
	ps += deltaps;
	effps2 = EFFPS(ps+deltaps);
#endif	/* NEQN */
	h1 = eht[p1]; b1 = ebase[p1];
	h2 = eht[p2]; b2 = ebase[p2];
#ifndef NEQN
	b3 = ebase[p3];
	d1 = VERT(EM(0.5, effps2));
#else	/* NEQN */
	h3 = eht[p3]; b3 = ebase[p3];
	d1 = VERT(1);
#endif	/* NEQN */
	subsh = -d1+h2-b2;
	if (d1+b1 > h2) /* move little sub down */
		subsh = b1-b2;
#ifndef NEQN
	supsh = -VERT((4*(h1-b1))/10) - b3;
	d2 = VERT(EM(0.2, effps));
	if (VERT(4*(h1-b1)/10)+h3 < h1-b1)
#else	/* NEQN */
	supsh = - VERT(1) - b3;
	d2 = VERT(1);
	if (VERT(1)+h3 < h1-b1)
#endif	/* NEQN */
		supsh = -(h1-b1) + (h3-b3) - d2;
#ifndef NEQN
	eht[yyval] = h1 + max(0, h3-VERT((6*(h1-b1))/10)) + max(0, h2-b1-d1);
#else	/* NEQN */
	eht[yyval] = h1 + max(0, h3-VERT(1)) + max(0, h2-b1-d1);
#endif	/* NEQN */
	ebase[yyval] = b1+max(0, h2-b1-d1);
#ifndef NEQN
	if (rfont[p1] == ITAL && lfont[p2] == ROM)
		printf(".ds %d \\|\\*(%d\n", p2, p2);
	if (rfont[p2] == ITAL)
		printf(".as %d \\|\n", p2);
#endif	/* NEQN */
	nrwid(p2, effps, p2);
#ifndef NEQN
	if (rfont[p1] == ITAL && lfont[p3] == ROM)
		printf(".ds %d \\|\\|\\*(%d\n", p3, p3);
	else
		printf(".ds %d \\|\\*(%d\n", p3, p3);
#endif	/* NEQN */
	nrwid(p3, effps, p3);
	printf(".nr %d \\n(%d\n", treg, p3);
	printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
#ifndef NEQN
	printf(".as %d \\v'%du'\\s%d\\*(%d\\h'-\\n(%du'\\v'%du'\\\n",
	    p1, subsh, effps, p2, p2, -subsh+supsh);
	printf("\\s%d\\*(%d\\h'-\\n(%du+\\n(%du'\\s%d\\v'%du'\n",
	    effps, p3, p3, treg, effps2, -supsh);
#else	/* NEQN */
	printf(".as %d \\v'%du'\\*(%d\\h'-\\n(%du'\\v'%du'\\\n",
	    p1, subsh, p2, p2, -subsh+supsh);
	printf("\\*(%d\\h'-\\n(%du+\\n(%du'\\v'%du'\n",
	    p3, p3, treg, -supsh);
#endif	/* NEQN */
	ps += deltaps;
#ifndef NEQN
	if (rfont[p2] == ITAL)
		rfont[yyval] = 0;	/* lie */
#endif	/* NEQN */
	ofree(p2); ofree(p3); ofree(treg);
}
Пример #25
0
void paren(int leftc, int p1, int rightc)
{
	int n, m, j;
	double h1, b1;
	double v, bv;	/* v = shift of inside, bv = shift of brackets */
	extern double Parenbase, Parenshift, Parenheight;

	bv = ttype == DEVPOST ? Parenshift : 0;	/* move brackets down this much */
	h1 = eht[p1];
	b1 = ebase[p1];
	yyval.token = p1;
	lfont[yyval.token] = rfont[yyval.token] = 0;
	n = REL(h1,ps) + 0.99;	/* ceiling */
	if (n < 2)
		n = 1;
	m = n - 2;
	if (leftc == '{' || rightc == '}') {
		n = n%2 ? n : ++n;
		if (n < 3)
			n = 3;
		m = n-3;
	}
	eht[yyval.token] = EM((double) n + Parenheight, ps);
	ebase[yyval.token] = eht[yyval.token]/2 - EM(Parenbase, ps);

	/* try to cope with things that are badly centered */
	/* (top heavy or bottom heavy) */
	if (abs(h1/2 - b1) >= EM(0.5, ps))
		v = REL(-ebase[yyval.token] + (eht[yyval.token]-h1)/2 + b1, ps);
	else
		v = 0;	/* don't shift it at all */

	printf(".ds %d \\^", yyval.token);	/* was \| */
	if (bv)
		printf("\\v'%gm'", bv);
	switch (leftc) {
	case 'n':	/* nothing */
	case '\0':
		break;
	case 'f':	/* floor */
		if (n <= 1)
			printf("\\(lf");
		else
			brack(m, "\\(bv", "\\(bv", "\\(lf");
		break;
	case 'c':	/* ceiling */
		if (n <= 1)
			printf("\\(lc");
		else
			brack(m, "\\(lc", "\\(bv", "\\(bv");
		break;
	case '{':
		printf("\\b'\\(lt");
		for(j = 0; j < m; j += 2) printf("\\(bv");
		printf("\\(lk");
		for(j = 0; j < m; j += 2) printf("\\(bv");
		printf("\\(lb'");
		break;
	case '(':
		brack(m, "\\(lt", "\\(bv", "\\(lb");
		break;
	case '[':
		brack(m, "\\(lc", "\\(bv", "\\(lf");
		break;
	case '|':
		brack(m, "|", "|", "|");
		break;
	default:
		brack(m, (char *) &leftc, (char *) &leftc, (char *) &leftc);
		break;
	}
	if (bv)
		printf("\\v'%gm'", -bv);
	if (v)
		printf("\\v'%gm'\\*(%d\\v'%gm'", -v, p1, v);
	else
		printf("\\*(%d", p1);
	if (rightc) {
		if (bv)
			printf("\\v'%gm'", bv);
		switch (rightc) {
		case 'f':	/* floor */
			if (n <= 1)
				printf("\\(rf");
			else
				brack(m, "\\(bv", "\\(bv", "\\(rf");
			break;
		case 'c':	/* ceiling */
			if (n <= 1)
				printf("\\(rc");
			else
				brack(m, "\\(rc", "\\(bv", "\\(bv");
			break;
		case '}':
			printf("\\b'\\(rt");
			for(j = 0; j < m; j += 2) printf("\\(bv");
			printf("\\(rk");
			for(j = 0; j < m; j += 2) printf("\\(bv");
			printf("\\(rb'");
			break;
		case ']':
			brack(m, "\\(rc", "\\(bv", "\\(rf");
			break;
		case ')':
			brack(m, "\\(rt", "\\(bv", "\\(rb");
			break;
		case '|':
			brack(m, "|", "|", "|");
			break;
		default:
			brack(m, (char *) &rightc, (char *) &rightc, (char *) &rightc);
			break;
		}
		if (bv)
			printf("\\v'%gm'", -bv);
	}
	printf("\n");
	dprintf(".\tcurly: h=%g b=%g n=%d v=%g l=%c, r=%c\n", 
		eht[yyval.token], ebase[yyval.token], n, v, leftc, rightc);
}
Пример #26
0
void
paren(int leftc, int p1, int rightc)
{
	int n, m, h1, j, b1, v;
	h1 = eht[p1]; b1 = ebase[p1];
	yyval = p1;
#ifndef NEQN
	lfont[yyval] = rfont[yyval] = 0;
	n = (h1 + EM(1.0, EFFPS(ps)) - 1) / EM(1.0, EFFPS(ps));
#else	/* NEQN */
	n = max(b1+VERT(1), h1-b1-VERT(1)) / VERT(1);
#endif	/* NEQN */
	if (n < 2) n = 1;
	m = n-2;
	if (leftc == '{' || rightc == '}') {
		if ((n % 2) == 0) {
			n++;
		}
		if (n < 3) n = 3;
		m = n-3;
	}
#ifndef NEQN
	eht[yyval] = VERT(EM(n, ps));
	ebase[yyval] = b1 + (eht[yyval]-h1)/2;
	v = b1 - h1/2 + VERT(EM(0.4, ps));
#else	/* NEQN */
	eht[yyval] = VERT(2 * n);
	ebase[yyval] = (n)/2 * VERT(2);
	if (n%2 == 0)
		ebase[yyval] -= VERT(1);
	v = b1 - h1/2 + VERT(1);
#endif	/* NEQN */
	printf(".ds %d \\|\\v'%du'", yyval, v);
	switch (leftc) {
		case 'n':	/* nothing */
		case '\0':
			break;
		case 'f':	/* floor */
			if (n <= 1)
				printf("\\(lf");
			else
				brack(m, "\\(bv", "\\(bv", "\\(lf");
			break;
		case 'c':	/* ceiling */
			if (n <= 1)
				printf("\\(lc");
			else
				brack(m, "\\(lc", "\\(bv", "\\(bv");
			break;
		case '{':
			printf("\\b'\\(lt");
			for (j = 0; j < m; j += 2) printf("\\(bv");
			printf("\\(lk");
			for (j = 0; j < m; j += 2) printf("\\(bv");
			printf("\\(lb'");
			break;
		case '(':
			brack(m, "\\(lt", "\\(bv", "\\(lb");
			break;
		case '[':
			brack(m, "\\(lc", "\\(bv", "\\(lf");
			break;
		case '|':
			brack(m, "\\(bv", "\\(bv", "\\(bv");
			break;
		default:
			brack(m, (char *)&leftc, (char *)&leftc,
			    (char *)&leftc);
			break;
		}
	printf("\\v'%du'\\*(%d", -v, p1);
	if (rightc) {
		printf("\\|\\v'%du'", v);
		switch (rightc) {
			case 'f':	/* floor */
				if (n <= 1)
					printf("\\(rf");
				else
					brack(m, "\\(bv", "\\(bv", "\\(rf");
				break;
			case 'c':	/* ceiling */
				if (n <= 1)
					printf("\\(rc");
				else
					brack(m, "\\(rc", "\\(bv", "\\(bv");
				break;
			case '}':
				printf("\\b'\\(rt");
				for (j = 0; j < m; j += 2) printf("\\(bv");
				printf("\\(rk");
				for (j = 0; j < m; j += 2) printf("\\(bv");
				printf("\\(rb'");
				break;
			case ']':
				brack(m, "\\(rc", "\\(bv", "\\(rf");
				break;
			case ')':
				brack(m, "\\(rt", "\\(bv", "\\(rb");
				break;
			case '|':
				brack(m, "\\(bv", "\\(bv", "\\(bv");
				break;
			default:
				brack(m, (char *)&rightc, (char *)&rightc,
				    (char *)&rightc);
				break;
		}
		printf("\\v'%du'", -v);
	}
	printf("\n");
	if (dbg)
		printf(".\tcurly: h=%d b=%d n=%d v=%d l=%c, r=%c\n",
		    eht[yyval], ebase[yyval], n, v, leftc, rightc);
}
Пример #27
0
void
lpile(int type, int p1, int p2)
{
	int bi, hi, i, gap, h, b, nlist, nlist2, mid;
	yyval = oalloc();
#ifndef NEQN
	gap = VERT(EM(0.4, ps)); /* 4/10 m between blocks */
#else	/* NEQN */
	gap = VERT(1);
#endif	/* NEQN */
	if (type == '-') gap = 0;
	nlist = p2 - p1;
	nlist2 = (nlist+1)/2;
	mid = p1 + nlist2 -1;
	h = 0;
	for (i = p1; i < p2; i++)
		h += eht[lp[i]];
	eht[yyval] = h + (nlist-1)*gap;
	b = 0;
	for (i = p2-1; i > mid; i--)
		b += eht[lp[i]] + gap;
#ifndef NEQN
	ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
	    : b - VERT(EM(0.5, ps)) - gap;
#else	/* NEQN */
	ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
	    : b - VERT(1) - gap;
#endif	/* NEQN */
	if (dbg) {
		printf(".\tS%d <- %c pile of:", yyval, type);
		for (i = p1; i < p2; i++)
			printf(" S%d", lp[i]);
		printf(";h=%d b=%d\n", eht[yyval], ebase[yyval]);
	}
	nrwid(lp[p1], ps, lp[p1]);
	printf(".nr %d \\n(%d\n", yyval, lp[p1]);
	for (i = p1+1; i < p2; i++) {
		nrwid(lp[i], ps, lp[i]);
		printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
		    lp[i], yyval, yyval, lp[i]);
	}
	printf(".ds %d \\v'%du'\\h'%du*\\n(%du'\\\n", yyval, ebase[yyval],
	    type == 'R' ? 1 : 0, yyval);
	for (i = p2-1; i >= p1; i--) {
		hi = eht[lp[i]];
		bi = ebase[lp[i]];
	switch (type) {

	case 'L':
		printf("\\v'%du'\\*(%d\\h'-\\n(%du'\\v'0-%du'\\\n",
		    -bi, lp[i], lp[i], hi-bi+gap);
		continue;
	case 'R':
		printf("\\v'%du'\\h'-\\n(%du'\\*(%d\\v'0-%du'\\\n",
		    -bi, lp[i], lp[i], hi-bi+gap);
		continue;
	case 'C':
	case '-':
		printf("\\v'%du'\\h'\\n(%du-\\n(%du/2u'\\*(%d",
		    -bi, yyval, lp[i], lp[i]);
		printf("\\h'-\\n(%du-\\n(%du/2u'\\v'0-%du'\\\n",
		    yyval, lp[i], hi-bi+gap);
		continue;
		}
	}
	printf("\\v'%du'\\h'%du*\\n(%du'\n", eht[yyval]-ebase[yyval]+gap,
	    type != 'R' ? 1 : 0, yyval);
	for (i = p1; i < p2; i++)
		ofree(lp[i]);
	lfont[yyval] = rfont[yyval] = 0;
}
Пример #28
0
void MixMod::EMCG()
{
int i,icount,numem=5,nump,ii;
double s,s11,ymax,b,alpha,beta=0.;
std::vector<double>change(k);
std::vector<double>gradq(k);
std::vector<double>grad1q(k);
std::vector<double>d(k);
int l;


// Number of mixing weights
l=k-1;

// Number of parameters in the model
nump=2*k-1;


initchange(change);
EM(numem);
getchange(change);
numem=1;  // Perform one EM-iteration

 // initialise delta 
 for(i=0;i<nump;i++)
   {
d[i]=change[i];
   }
 // start CG-algorithm

 for(icount=0;icount<maxstep;icount++)
 {
	// delta Psi also serves as starting value fro the direction d

// end of delta PSI


// 1. Compute the gradient of  LogL() 



gradcg(gradq,p,t);
alpha=stepjj(gradq,d);

// end of step-length choice

// 3. Update of PSI = PSI+alpha*d
s=0.;
ii=l;
s=0.;
for(i=0;i<l;i++)
{
 p[i]=p[i]+alpha*d[i];
 if(p[i]<1.E-4)p[i]=0;
 s=s+p[i];
}

p[l]=1.-s;
 ii=l;
   for(i=0;i<k;i++)
  {
   t[i]=t[i]+alpha*d[ii];
   ii++;
  }
// end of update
// Using the updated parameter vector get the result of the nextEM-step
initchange(change);
EM(numem);
getchange(change); 
// 4. compute beta
gradcg(grad1q,p,t); // get the gradient for the new parameter vector
s=0.;
s11=0.;

for(i=0;i<nump;i++)
 { 
  b=grad1q[i]-gradq[i];
  s=s+b*change[i];
  s11=s11+b*d[i];
 }
if(fabs(s11) > 1.E-10) beta=s/s11;

  
//Compute the direction d

if(icount%nump ==0)
{
 for(i=0;i<nump;i++)d[i]=change[i];
   }
else
  {
s=0.;
for(i=0;i<nump;i++)
  {
 d[i]=change[i]-beta*d[i]; 
 s=s+d[i];
  }
  }
if(fabs(s) > 1.E-1) for(i=0;i<nump;i++)d[i]=change[i];
    ll=likelihood();
           maxderiv (ymax);
	    if ( (fabs(double(ymax-1.0)) <acc) && (icount > 2 )) break;
  } 
 } 
Пример #29
0
 int MixMod::Combine()
{
 int i,j,jj,tempk,tmpnumstep=1;
 std::vector<int>count(k);
 std::vector<double>tempp(k);
 std::vector<double>tempt(k);
 double diff;

	for (i=0;i<k;i++)
	{
	tempt[i] =1.E+8;
	tempp[i] =0.;
        count[i]=-1;
        }


	jj=-1;

//  find identical parameters and store their index
	for (i=0;i<k-1;i++)
        {
	diff=t[i+1]-t[i];
 	 if(fabs(diff)<limit)
	 {
	  jj++;
	  count[jj]=i+1;
	 }
	   }
           jj=jj+1;
         tempk=k-jj;
	j=0;
	jj=-1;
/*cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c      Find remaining different parameters  and update mixing weights
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc*/


	for (i=0;i<k;i++)
	{

	 if ( i==count[j] )
	 {
	  j++;
	  tempp[jj]=tempp[jj]+p[i];
          } // end if
	  else
	  {
	  jj++;
	  tempt[jj]=t[i];
	  tempp[jj]=p[i];
          }         // end else

        } // end for loop

/*cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c    done!
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc*/
	k=tempk;
        
	for (i=0;i<k;i++)
        {
	p[i]=tempp[i];
	t[i]=tempt[i];
          
	}
    CalcMat();
    Gradient();
    EM(tmpnumstep);
    ll=likelihood();
    return tempk;

}
Пример #30
0
 */


#include <stdlib.h>

#include <freefare.h>

#include "freefare_internal.h"

#define EM(e) { e, #e }

static struct error_message {
    uint8_t code;
    const char *message;
} error_messages[] = {
    EM(OPERATION_OK),
    EM(NO_CHANGES),
    EM(OUT_OF_EEPROM_ERROR),
    EM(ILLEGAL_COMMAND_CODE),
    EM(INTEGRITY_ERROR),
    EM(NO_SUCH_KEY),
    EM(LENGTH_ERROR),
    EM(PERMISSION_ERROR),
    EM(PARAMETER_ERROR),
    EM(APPLICATION_NOT_FOUND),
    EM(APPL_INTEGRITY_ERROR),
    EM(AUTHENTICATION_ERROR),
    EM(ADDITIONAL_FRAME),
    EM(BOUNDARY_ERROR),
    EM(PICC_INTEGRITY_ERROR),
    EM(COMMAND_ABORTED),