Ejemplo n.º 1
0
void
lsmatch(char *cp)
{
	char *save = smalloc(LBSIZE);
	register char *sp = save;
	register char *scurs = cursor;

	wcursor = cp;
	lcpy(sp, linebuf, LBSIZE);
	*wcursor = 0;
	strcpy(cursor, genbuf);
	cursor = strend(linebuf) - 1;
	if (lmatchp(dot - vcline)) {
		register int i = insmode;
		register int c = outcol;
		register int l = outline;

		if (!MI)
			endim();
		vgoto(splitw ? WECHO : LINE(wdot - llimit), column(wcursor) - 1);
		flush();
		sleep(1);
		vgoto(l, c);
		if (i)
			goim();
	}
	else {
		strcLIN(sp);
		strcpy(scurs, genbuf);
		if (!lmatchp((line *) 0))
			beep();
	}
	strcLIN(sp);
	wdot = 0;
	wcursor = 0;
	cursor = scurs;
	free(save);
}
Ejemplo n.º 2
0
int main() {
    int k = 1, err = 10, iter = 0;
    float ratio = 0;
    int A[4][5] = {
                { 1, 1, 1, 1, 1},
                { 1, 0, 0, 0, 1},
                { 1, 1, 1, 1, 1},
                { 1, 0, 0, 0, 1} };
    int C[4][5] = {
                { 1, 1, 1, 1, 1},
                { 1, 0, 0, 0, 0},
                { 1, 0, 0, 0, 0},
                { 1, 1, 1, 1, 1} };
    int L[4][5];
    int last_used_matrix[4][5] = {
                { -1, -1, -1, -1, -1},
                { -1, -1, -1, -1, -1},
                { -1, -1, -1, -1, -1},
                { -1, -1, -1, -1, -1} };
    t_neuron d_neuron = { .potential = 0, .threshold = 0.5, .output = 0 };
    t_synapse synapses[20];

    // Création du réseau
    for (int i = 0; i < 20; i++) {
        synapses[i].source = create_sensor();
        synapses[i].target = &d_neuron;
        synapses[i].weight = 0;
    }


    // Phase d'apprentissage
    do {
        feed_neural_network(&synapses, A);
        learning_phase(&synapses, EPSILON, 1, 0);

        feed_neural_network(&synapses, C);
        learning_phase(&synapses, EPSILON, 0, 1);
        
        feed_neural_network(&synapses, A);
        calculate_potential(&synapses, &d_neuron);
        if (d_neuron.output != 1)
            err++;

        feed_neural_network(&synapses, C);
        calculate_potential(&synapses, &d_neuron);
        if (d_neuron.output != 0)
            err++;

        iter++;
        ratio = (float) iter / (float) err;
        
        //printf("iter: %d && err: %d\n", iter, err);
        //printf("ratio:%f\n", ratio);
    } while ( ratio < 0.8);


    // Phase de test pour A
    while (k < 20) {
        int i = 0;
        int success = 0;
        while (i < 100000) {
            while (true) {
                // Generer copie d'une lettre
                lcpy(&L, &A);
                // Generer du bruit sur cette copie
                generate_noise(&L, k);
                //print_letter(L);
                //printf("\n");
                if (!matrices_are_equal(L, last_used_matrix)) {
                    lcpy(&last_used_matrix, &L);
                    break;
                }
            }

            feed_neural_network(&synapses, L);
            calculate_potential(&synapses, &d_neuron);
            if (d_neuron.output == 1)
                success++;
            
            i++;
        }
        success /= 1000;
        printf("%d%% de succes sur %d essais avec %d%% de bruit.\n", success, i, k*5);
        k++;
    }

    // Phase de test pour C
    k = 1;
    while (k < 20) {
        int i = 0;
        int success = 0;
        while (i < 100000) {
            while (true) {
                // Generer copie d'une lettre
                lcpy(&L, &C);
                // Generer du bruit sur cette copie
                generate_noise(&L, k);
                if (!matrices_are_equal(L, last_used_matrix)) {
                    lcpy(&last_used_matrix, &L);
                    break;
                }
            }

            feed_neural_network(&synapses, L);
            calculate_potential(&synapses, &d_neuron);
            if (d_neuron.output == 0)
                success++;
            
            i++;
        }
        success /= 1000;
        printf("%d%% de succes sur %d essais avec %d%% de bruit.\n", success, i, k*5);
        k++;
    }
}
Ejemplo n.º 3
0
void
setterm(char *type)
{
	register int unknown;
	char ltcbuf[TCBUFSIZE];

	if (type[0] == 0)
		type = "xx";
	unknown = 0;
	putpad(TE);
	if (tgetent(ltcbuf, type) != 1) {
		unknown++;
		lcpy(ltcbuf, "xx|dumb:", sizeof ltcbuf);
	}
	gettmode(); /* must call gettmode() before setsize(). GR */
	setsize();
	aoftspace = tspace;
	zap();
	/*
	 * Initialize keypad arrow keys.
	 */
	addmac1(KU, "k", "up", arrows, 1);
	addmac1(KD, "j", "down", arrows, 1);
	addmac1(KL, "h", "left", arrows, 1);
	addmac1(KR, "l", "right", arrows, 1);
	addmac1(KH, "H", "home", arrows, 1);

	/*
	 * Handle funny termcap capabilities
	 */
	if (xCS && SC && RC) {
		if (AL==NULL) AL="";
		if (DL==NULL) DL="";
	}
	if (AL_PARM && AL==NULL) AL="";
	if (DL_PARM && DL==NULL) DL="";
	if (IC && IM==NULL) IM="";
	if (IC && EI==NULL) EI="";
	if (!GT) BT=NULL;	/* If we can't tab, we can't backtab either */

#ifdef	TIOCLGET
#define	HAS_JOB_CONTROL
#endif
#ifdef	_SC_JOB_CONTROL
#define	HAS_JOB_CONTROL
#endif
#ifdef	HAS_JOB_CONTROL
	/*
	 * Now map users susp char to ^Z, being careful that the susp
	 * overrides any arrow key, but only for hackers (=new tty driver).
	 */
	{
		static char sc[2];
		int i /* , fnd */;

		if (sysconf(_SC_JOB_CONTROL) != -1)
		{
			/*
			 * If a system supports job control but no job
			 * control shell is used, only one method of
			 * detection remains: Our session id equals our
			 * process group id. Any job control shell would
			 * have created at least one new process group.
			 * But as the VSUSP key may be active, we have
			 * to override arrow keys either.
			 */
#ifndef	_CRAY	/* getsid() is a bad syscall on UNICOS */
			if (getsid(0) != getpgid(0))
#endif	/* !_CRAY */
				ldisc = 2;	/* value of NTTYDISC */
			sc[0] = tty.c_cc[VSUSP];
			sc[1] = 0;
			if (tty.c_cc[VSUSP] == CTRL('z')) {
				for (i=0; i<=4; i++)
					if (arrows[i].cap &&
					    arrows[i].cap[0] == CTRL('z'))
						addmac(sc, NULL, NULL, arrows);
			} else if (sc[0]
#ifdef	_PC_VDISABLE
					&& sc[0] != fpathconf(1, _PC_VDISABLE)
#endif
					)
				addmac(sc, "\32", "susp", arrows);
		}
	}
#endif	/* HAS_JOB_CONTROL */

	if (CM != 0) {
		if (tgoto(CM, 2, 2)[0] == 'O')	/* OOPS */
			CA = 0, CM = 0;
		else
			CA = 1, costCM = cost(tgoto(CM, 8, 10));
	} else {
		CA = 0, CM = 0;
	}
	costSR = cost(SR);
	costAL = cost(AL);
	costDP = cost(tgoto(DOWN_PARM, 10, 10));
	costLP = cost(tgoto(LEFT_PARM, 10, 10));
	costRP = cost(tgoto(RIGHT_PARM, 10, 10));
	PC = xPC ? xPC[0] : 0;
	aoftspace = tspace;
	safecp(ttylongname, gettlongname(ltcbuf, type), sizeof ttylongname,
			"Terminal name too long");
	/* proper strings to change tty type */
	termreset();
	gettmode();
	value(REDRAW) = AL && DL;
	value(OPTIMIZE) = !CA && !GT;
	if (ospeed == B1200 && !value(REDRAW))
		value(SLOWOPEN) = 1;	/* see also gettmode above */
	if (unknown)
		serror(catgets(catd, 1, 191,
				"%s: Unknown terminal type"), type);
}
Ejemplo n.º 4
0
/*
 * Find over structure, repeated count times.
 * Don't go past line limit.  F is the operation to
 * be performed eventually.  If pastatom then the user said {}
 * rather than (), implying past atoms in a list (or a paragraph
 * rather than a sentence.
 */
int
llfind(bool pastatom, int cnt, void (*f)(int), line *limit)
{
#ifdef	LISPCODE
	register int c;
#endif
	register int rc = 0;
	char *save = smalloc(LBSIZE);

	/*
	 * Initialize, saving the current line buffer state
	 * and computing the limit; a 0 argument means
	 * directional end of file.
	 */
	wasend = 0;
	lf = f;
	lcpy(save, linebuf, LBSIZE);
	if (limit == 0)
		limit = dir < 0 ? one : dol;
	llimit = limit;
	wdot = dot;
	wcursor = cursor;

	if (pastatom >= 2) {
		while (cnt > 0 && word(f, cnt))
			cnt--;
		if (pastatom == 3)
			eend(f);
		if (dot == wdot) {
			wdot = 0;
			if (cursor == wcursor)
				rc = -1;
		}
	}
#ifdef LISPCODE
	else if (!value(LISP)) {
#else
	else {
#endif
		char *icurs;
		line *idot;

		if (linebuf[0] == 0) {
			do
				if (!lnext())
					goto ret;
			while (linebuf[0] == 0);
			if (dir > 0) {
				wdot--;
				linebuf[0] = 0;
				wcursor = linebuf;
				/*
				 * If looking for sentence, next line
				 * starts one.
				 */
				if (!pastatom) {
					icurs = wcursor;
					idot = wdot;
					goto begin;
				}
			}
		}
		icurs = wcursor;
		idot = wdot;

		/*
		 * Advance so as to not find same thing again.
		 */
		if (dir > 0) {
			if (!lnext()) {
				rc = -1;
				goto ret;
			}
		} else
			ignore(lskipa1(""));

		/*
		 * Count times find end of sentence/paragraph.
		 */
begin:
		for (;;) {
			while (!endsent(pastatom))
				if (!lnext())
					goto ret;
			if (!pastatom || (wcursor == linebuf && endPS()))
				if (--cnt <= 0)
					break;
			if (linebuf[0] == 0) {
				do
					if (!lnext())
						goto ret;
				while (linebuf[0] == 0);
			} else
				if (!lnext())
					goto ret;
		}

		/*
		 * If going backwards, and didn't hit the end of the buffer,
		 * then reverse direction.
		 */
		if (dir < 0 && (wdot != llimit || wcursor != linebuf)) {
			dir = 1;
			llimit = dot;
			/*
			 * Empty line needs special treatement.
			 * If moved to it from other than begining of next line,
			 * then a sentence starts on next line.
			 */
			if (linebuf[0] == 0 && !pastatom && 
			   (wdot != dot - 1 || cursor != linebuf)) {
				lnext();
				goto ret;
			}
		}

		/*
		 * If we are not at a section/paragraph division,
		 * advance to next.
		 */
		if ((wcursor == icurs && wdot == idot) || wcursor != linebuf || !endPS())
			ignore(lskipa1(""));
	}
#ifdef LISPCODE
	else {
		c = *wcursor;
		/*
		 * Startup by skipping if at a ( going left or a ) going
		 * right to keep from getting stuck immediately.
		 */
		if ((dir < 0 && c == '(') || (dir > 0 && c == ')')) {
			if (!lnext()) {
				rc = -1;
				goto ret;
			}
		}
		/*
		 * Now chew up repitition count.  Each time around
		 * if at the beginning of an s-exp (going forwards)
		 * or the end of an s-exp (going backwards)
		 * skip the s-exp.  If not at beg/end resp, then stop
		 * if we hit a higher level paren, else skip an atom,
		 * counting it unless pastatom.
		 */
		while (cnt > 0) {
			c = *wcursor;
			if ((dir < 0 && c == ')') || (dir > 0 && c == '(')) {
				if (!lskipbal("()"))
					goto ret;
				/*
 				 * Unless this is the last time going
				 * backwards, skip past the matching paren
				 * so we don't think it is a higher level paren.
				 */
				if (dir < 0 && cnt == 1)
					goto ret;
				if (!lnext() || !ltosolid())
					goto ret;
				--cnt;
			} else if ((dir < 0 && c == '(') || (dir > 0 && c == ')'))
				/* Found a higher level paren */
				goto ret;
			else {
				if (!lskipatom())
					goto ret;
				if (!pastatom)
					--cnt;
			}
		}
	}
#endif
ret:
	strcLIN(save);
	free(save);
	return (rc);
}