Exemplo n.º 1
0
void train_udp_nbc(nbc_t *nbc, FILE *in_normal, FILE *in_attack)
{
   list_t *list = create_list();
   mat_t *mat;

   //printf("TRAINING NORMAL\n");

   load_udpp_file(in_normal, list);

   mat = create_udp_mat(list);

   destroy_list_nodes(list);
   destroy_list(&list);

   //print_mat(mat);
   nbc_train(nbc, 0, mat);

   destroy_mat(&mat);

   //printf("TRAINED NORMAL\n");

   //printf("TRAINING ATTACK\n");

   list = create_list();
   load_udpp_file(in_attack, list);

   mat = create_udp_mat(list);

   destroy_list_nodes(list);
   destroy_list(&list);

   //print_mat(mat);
   nbc_train(nbc, 1, mat);

   destroy_mat(&mat);

   printf("UDP Trained:\n");
   print_mat(nbc->training);

}
Exemplo n.º 2
0
void place_support ()
    {
    int i, j;
    int from_trans = 1;
    ROWP cp, cp2;
    struct matrix * rp, * nrp, * prp;

#ifdef DEBUG
  fprintf(stderr,"  Start of place_support\n");
#endif
    for ( j = 0 ; j++ < trans_num ; ) {
#ifdef DEBUG
{ ROWP cp; struct matrix * rp; int i, j;
printf("\nMATRIX\n");
for ( rp = mat; rp != NULL ; rp = rp->next ) {
for ( i = 0, j = *(cp = rp->rowp), cp++ ; i++ < place_num ; )
if ( (j>0) && (i == (int)(*cp)) ) {
j--; cp++;
printf(" %2d",(int)*(cp++) );
}
else printf("  0");
for ( i = 0 ; i++ < trans_num ; )
if ( (i == (int)(*cp)) ) {
cp++;
printf(" %2d",(int)*(cp++) );
}
else printf("  0");
printf("\n");
}
}
#endif
	{ int ii, ntr=0; ROWP cp; struct matrix * rp; int * ip;

	  for ( ii=trans_num+1, ip=poss_trans ; ii-- ; *(ip++) = FALSE );
	  for ( rp = mat; rp != NULL ; rp = rp->next ) {
	      for ( i = *(cp = rp->rowp), cp++ ; i-- && *cp <= testplace ;
		    cp += 2 )
		  if ( *cp == testplace ) {
		      i = 0;
		      ii = *(cp = rp->rowp); cp += (2 * ii + 1);
		      while ( (ii = *cp) ) {
			  cp += 2;
			  ip = (poss_trans+ii);
			  if ( !(*ip) && !(*(elim_trans+ii)) ) {
#ifdef DEBUG
printf("transition %d possible\n", ii );
#endif
			      *ip = TRUE; ntr++;
			    }
			}
		    }
	    }
	  if ( ! ntr ) {
#ifdef DEBUG
  fprintf(stderr,"  End of place_support\n");
#endif
	      return;
	    }
	}
	{ int first, minval=0, mm, ii;
	  int * ip, * it, * pp, * np;

	  for ( first=TRUE, ii=from_trans, ip=(elim_trans+from_trans),
		it=(poss_trans+from_trans),
		pp=(n_pos+from_trans), np=(n_neg+from_trans);
		ii <= trans_num;
		ip++, it++, pp++, np++, ii++)
	      if ( *it ) {
		  while ( *ip ) {
		      it++; ip++; pp++; np++;
		      if ( ++ii > trans_num ) goto end_test;
		    }
		  mm = (*pp)*(*np) - (*pp) - (*np);
		  if ( first ) {
		      i = ii; minval = mm; first = FALSE;
		    }
		  else if ( mm < minval ) {
		      i = ii; minval = mm;
		    }
		}
	}
end_test:
	elim_trans[i] = TRUE;
	if ( i == from_trans )
	    while ( elim_trans[from_trans] )
		++from_trans;
#ifdef DEBUG
printf("\neliminating transition #%d\n",i);
#endif
	for ( prp = NULL, rp = mat ; rp != NULL ; rp = nrp ) {
	    nrp = rp->next;
	    cp2 = cp = (rp->rowp) + ( 2 * *(rp->rowp) + 1 );
	    while ( ((int)(*cp)<i) && ((int)(*cp)>0) )
		cp += 2;
	    if ( (int)(*cp) == i ) { /* TAKE THE ROW OUT FROM MATRIX LIST */
		while ( (short)(*cp2) != (short)0 ) {
		    if ( (short)(*(cp2+1)) > (short)0 )
			--(n_pos[(int)(*cp2)]);
		    else
			--(n_neg[(int)(*cp2)]);
		    cp2 += 2;
		  }
		if ( rp == mat )
		    mat = nrp;
		else
		    prp->next = nrp;
		if ( (short)(*(++cp)) > (short)0 ) {
		    rp->next = oldmp;
		    oldmp = rp;
		  }
		else {
		    rp->next = oldmm;
		    oldmm = rp;
		  }
	      }
	    else
		prp = rp;
	  }
	if ( oldmp != NULL && oldmm != NULL ) {
	    while ( (rp = oldmp) != NULL ) {
		elim( (short)i );
		oldmp = oldmp->next;
		destroy_mat( rp );
	      }
	  }
	else
	    while ( (rp = oldmp) != NULL ) {
		oldmp = oldmp->next;
		destroy_mat( rp );
	      }
	while ( (rp = oldmm) != NULL ) {
	    oldmm = oldmm->next;
	    destroy_mat( rp );
	  }
      }
#ifdef DEBUG
  fprintf(stderr,"  End of place_support\n");
#endif
}