Beispiel #1
0
int pairalign_seq(int istart, int iend, int jstart, int jend)
{
   int i, n, m, si, sj;
   int len1, len2, maxres;
   double gg, mm_score;
   int    *mat_xref, *matptr;

   matptr   = gon250mt;
   mat_xref = def_aa_xref;
   maxres = get_matrix(matptr, mat_xref, 10);
   if (maxres == 0) return(-1);

   for (si = 0; si < nseqs; si++) {
      if ((n = seqlen_array[si+1]) != 0){
         for (i = 1, len1 = 0; i <= n; i++) {
            char c = seq_array[si+1][i];
            if ((c != gap_pos1) && (c != gap_pos2)) len1++;
         }

         for (sj = si + 1; sj < nseqs; sj++) {
            if ((m = seqlen_array[sj+1]) != 0){
               int se1, se2, sb1, sb2, maxscore, seq1, seq2, g, gh;
               int displ[2*MAX_ALN_LENGTH+1];
               int print_ptr, last_print;

               for (i = 1, len2 = 0; i <= m; i++) {
                  char c = seq_array[sj+1][i];
                  if ((c != gap_pos1) && (c != gap_pos2)) len2++;
               }

               gh = 10 * pw_ge_penalty;
               gg = pw_go_penalty + log((double) MIN(n, m));
               g  = (mat_avscore <= 0) ? 20 * gg : 2 * mat_avscore * gg;

               seq1 = si + 1;
               seq2 = sj + 1;

               forward_pass(&seq_array[seq1][0], &seq_array[seq2][0], n, m, &se1, &se2, &maxscore, g, gh);
               reverse_pass(&seq_array[seq1][0], &seq_array[seq2][0], se1, se2, &sb1, &sb2, maxscore, g, gh);

               print_ptr  = 1;
               last_print = 0;

               diff(sb1-1, sb2-1, se1-sb1+1, se2-sb2+1, 0, 0, &print_ptr, &last_print, displ, seq1, seq2, g, gh);
               mm_score = tracepath(sb1, sb2, &print_ptr, &last_print, displ, seq1, seq2);

               if (len1 == 0 || len2 == 0) mm_score  = 0.0;
               else                        mm_score /= (double) MIN(len1,len2);

               seq_output[si*nseqs+sj] = mm_score;
            }
         }
      }
   }
   return 0;
}
Beispiel #2
0
void test()
{
  int i,k,j;
  element_t=0;
  example_t=0;
  epoch_err=0;
  class_err=0;
  seq_cor=1;
  seq_err=0;
  test_end=0;

  while (test_end==0)
    {

      /* executing the environment
	 and setting the input
	 */
      execute_act_test();

      /* forward pass */

      forward_pass();


      if (targ==1) /* only if target for this input */
	{
	  /* compute error */

	  for (k=hi_in_mod,j=0;k<ges_mod;k++,j++)
	    {
	      error[j]=  target_a[j] - Yk_mod_new[k];
	    };

	  /* Training error */

	  comp_err();
	}

      /* set old activations */
      for (i=0;i<ges_mod;i++)
	{
	  Yk_mod_old[i] = Yk_mod_new[i];
        }

    }

  fp1=fopen(outfile, "a");
  fprintf(fp1,"TEST: epochs:%d sequences:%d\n",epoch+1,numb_seq);
  fprintf(fp1,"TEST: MSE:%.4f\n",epoch_err/(1.0*test_size));
  fprintf(fp1,"TEST: misclassifications:%d (out of %d test examples)\n",class_err,test_size);
  fprintf(fp1,"\n");
  fclose(fp1);

  
}
Beispiel #3
0
/*!\brief Compute outputs of a network for given inputs.
 * \param net Pointer to a neural network.
 * \param input Pointer to sequence of floating point numbers.
 * \param output Pointer to sequence of floating point numbers or NULL.
 *
 * Compute outputs of a neural network for given inputs by forward
 * propagating the inputs through the layers. If output is non-NULL, the
 * outputs are copied to output (otherwise they are only stored
 * internally in the network). Note that the outputs of the neural
 * network will always lie in the interval (0,1); the caller will have to
 * rescale them if neccesary.
 */
void
net_compute (network_t *net, const float *input, float *output)
{
  assert (net != NULL);
  assert (input != NULL);

  set_input (net, input);
  forward_pass (net);
  if (output != NULL) {
    get_output (net, output);
  }
}
double TimeEstimateCalculator::calculate()
{
    reverse_pass();
    forward_pass();
    recalculate_trapezoids();
    
    double totalTime = 0;
    for(unsigned int n=0; n<blocks.size(); n++)
    {
        double plateau_distance = blocks[n].decelerate_after - blocks[n].accelerate_until;
        
        totalTime += acceleration_time_from_distance(blocks[n].initial_feedrate, blocks[n].accelerate_until, blocks[n].acceleration);
        totalTime += plateau_distance / blocks[n].nominal_feedrate;
        totalTime += acceleration_time_from_distance(blocks[n].final_feedrate, (blocks[n].distance - blocks[n].decelerate_after), blocks[n].acceleration);
    }
    return totalTime;
}
Beispiel #5
0
int main() {
    vf input, hidden;
    vf computed_output, actual_output;
    vf weights_ih, weights_ho;
    float t_ini,t_end;

    std::cout << "Loading vector." << std::endl;
    load_matrix(input, INPUT_FILE);

    std::cout << "Loading weight_ih." << std::endl;
    load_matrix(weights_ih, WEIGHTS_IH_FILE);

    std::cout << "Loading weight_ho." << std::endl;
    load_matrix(weights_ho, WEIGHTS_HO_FILE);

    std::cout << "Loading actual output." << std::endl;
    load_matrix(actual_output, OUTPUT_FILE);

    assert(input.size() == INPUT_SIZE);
    assert(weights_ih.size() == INPUT_SIZE * HIDDEN_SIZE);
    assert(weights_ho.size() == HIDDEN_SIZE * OUTPUT_SIZE);
    assert(actual_output.size() == OUTPUT_SIZE);

    hidden.resize(HIDDEN_SIZE);
    computed_output.resize(OUTPUT_SIZE);

    std::cout << "Forward pass." << std::endl;
    t_ini = omp_get_wtime();
    for(int i = 0; i < N_TIME; i++) {
        forward_pass(INPUT_SIZE, HIDDEN_SIZE, OUTPUT_SIZE,
                     &input[0], &hidden[0], &computed_output[0],
                     &weights_ih[0], &weights_ho[0]);
    }
    t_end = omp_get_wtime();

    std::cout << "First values of computed output: " << std::endl;
    print_matrix(computed_output, 1, 8);

    std::cout << "Actual first values: " << std::endl;
    print_matrix(actual_output, 1, 8);

    std::cout << "Forward Pass Time: " << std::endl;
    std::cout << (t_end - t_ini)/(float)N_TIME << std::endl;

}
Beispiel #6
0
    Matrix auto_forward_pass(Matrix& w, Matrix& x) {
        ASSERT(x.n_rows == in_size);
        size_t n_batches = x.n_columns;
        size_t n_slices = x.n_slices;

        MatrixContainer* fwd_state = create_empty_fwd_state_view(n_batches, n_slices);

        size_t weight_size = get_weight_size();
        ASSERT(w.size == weight_size);
        MatrixContainer* parameters = create_parameter_view(w);

        Matrix y = create_empty_out_view(n_batches, n_slices);

        forward_pass(*parameters, *fwd_state, x, y, false);
        delete fwd_state;
        delete parameters;
        return y;
    }
Beispiel #7
0
void main()
{

	int i, j, k,
	trialnr;

    
	/* input pars */
	getpars();

	/* input training set and test set */
	getsets();

	if (maxtrials>20)
		maxtrials=20;

	if (bias1==1)
		in_mod++;
	
	if (bias2==1)
		hid_mod++;

	hi_in_mod = in_mod+hid_mod;
	cell_mod=hi_in_mod;

	for (i=0;i<num_blocks;i++)
		cell_mod+=(2+block_size[i]);

	ges_mod = cell_mod+out_mod;
	if (ges_mod>max_units)
	{
		printf("Program terminated!\n");
		printf("You have to set the constant max_units at begin\n");
		printf("of the program file greater or equal %d and then\n",ges_mod);
		printf("compile the program again.\n");
		exit(0);
	}

	srand(ran_sta);
	for (trialnr=0;trialnr<maxtrials;trialnr++)
	{


		outfile = outf[trialnr];

		weightfile = weig[trialnr];

		fp1 = fopen(outfile, "w");
		fprintf(fp1,"Trial Nr.:%.1d\n",trialnr);
		fclose(fp1);

		fp2 = fopen(weightfile, "w");
		fprintf(fp2,"Trial Nr.:%.1d\n",trialnr);
		fclose(fp2);


		initia();

		examples=0;
		epoch=0;

		maxepoch=maxepoch_init;

		stop_learn=0;
		learn = 1;

		while (learn == 1)
		{

			/* executing the environment
				and setting the input
				*/
			execute_act();

			/* forward pass */
			forward_pass();


			if (targ==1) /* only if target for this input */
			{
				/* compute error */
				for (k=cell_mod,j=0;k<ges_mod;k++,j++)
				{
					error[j]=  target_a[j] - Yk_mod_new[k];
				};
				/* Training error */
				comp_err();
			}

			/* backward pass */
			if (targ==1) /* only if target for this input */
			{
				backward_pass();
			}
			else
			{
				derivatives();
			}
	

			/* set old activations */
			for (i=0;i<ges_mod;i++)
			{
				Yk_mod_old[i] = Yk_mod_new[i];
			}


			/* update weights */
			if (weight_up==1)
			{
				weight_up=0;
				weight_update();
			}

			/* stop if maxepoch reached */
			if (epoch>maxepoch)
				learn=0;
		}

		weight_out();
		test();
	}

	exit(0);
}
Beispiel #8
0
sint pairalign(sint istart, sint iend, sint jstart, sint jend)
{
  short	 *mat_xref;
  static sint    si, sj, i;
  static sint    n,m,len1,len2;
  static sint    maxres;
  static short    *matptr;
  static char   c;
  static float gscale,ghscale;

  displ = (sint *)ckalloc((2*max_aln_length+1) * sizeof(sint));
  HH = (pwint *)ckalloc((max_aln_length) * sizeof(pwint));
  DD = (pwint *)ckalloc((max_aln_length) * sizeof(pwint));
  RR = (pwint *)ckalloc((max_aln_length) * sizeof(pwint));
  SS = (pwint *)ckalloc((max_aln_length) * sizeof(pwint));
		
#ifdef MAC
  int_scale = 10;
#else
  int_scale = 100;
#endif
  gscale=ghscale=1.0;
  if (dnaflag)
    {
      if (debug>1) fprintf(stdout,"matrix %s\n",pw_dnamtrxname);
      if (strcmp(pw_dnamtrxname, "iub") == 0)
	{ 
	  matptr = swgapdnamt;
	  mat_xref = def_dna_xref;
	}
      else if (strcmp(pw_dnamtrxname, "clustalw") == 0)
	{ 
	  matptr = clustalvdnamt;
	  mat_xref = def_dna_xref;
	  gscale=0.6667;
	  ghscale=0.751;
	}
      else
	{
	  matptr = pw_userdnamat;
	  mat_xref = pw_dna_xref;
	}
      maxres = get_matrix(matptr, mat_xref, matrix, TRUE, int_scale);
      if (maxres == 0) return((sint)-1);

      matrix[0][4]=transition_weight*matrix[0][0];
      matrix[4][0]=transition_weight*matrix[0][0];
      matrix[2][11]=transition_weight*matrix[0][0];
      matrix[11][2]=transition_weight*matrix[0][0];
      matrix[2][12]=transition_weight*matrix[0][0];
      matrix[12][2]=transition_weight*matrix[0][0];
    }
  else
    {
      if (debug>1) fprintf(stdout,"matrix %s\n",pw_mtrxname);
      if (strcmp(pw_mtrxname, "blosum") == 0)
	{
	  matptr = blosum30mt;
	  mat_xref = def_aa_xref;
	}
      else if (strcmp(pw_mtrxname, "pam") == 0)
	{
	  matptr = pam350mt;
	  mat_xref = def_aa_xref;
	}
      else if (strcmp(pw_mtrxname, "gonnet") == 0)
	{
	  matptr = gon250mt;
	  int_scale /= 10;
	  mat_xref = def_aa_xref;
	}
      else if (strcmp(pw_mtrxname, "id") == 0)
	{
	  matptr = idmat;
	  mat_xref = def_aa_xref;
	}
      else
	{
	  matptr = pw_usermat;
	  mat_xref = pw_aa_xref;
	}

      maxres = get_matrix(matptr, mat_xref, matrix, TRUE, int_scale);
      if (maxres == 0) return((sint)-1);
    }


  for (si=MAX(0,istart);si<nseqs && si<iend;si++)
    {
      n = seqlen_array[si+1];
      len1 = 0;
      for (i=1;i<=n;i++) {
	c = seq_array[si+1][i];
	if ((c!=gap_pos1) && (c != gap_pos2)) len1++;
      }

      for (sj=MAX(si+1,jstart+1);sj<nseqs && sj<jend;sj++)
	{
	  m = seqlen_array[sj+1];
	  if(n==0 || m==0) {
	    tmat[si+1][sj+1]=1.0;
	    tmat[sj+1][si+1]=1.0;
	    continue;
	  }
	  len2 = 0;
	  for (i=1;i<=m;i++) {
	    c = seq_array[sj+1][i];
	    if ((c!=gap_pos1) && (c != gap_pos2)) len2++;
	  }

	  if (dnaflag) {
	    g = 2 * (float)pw_go_penalty * int_scale*gscale;
	    gh = pw_ge_penalty * int_scale*ghscale;
	  }
	  else {
	    if (mat_avscore <= 0)
              g = 2 * (float)(pw_go_penalty + log((double)(MIN(n,m))))*int_scale;
	    else
              g = 2 * mat_avscore * (float)(pw_go_penalty +
					    log((double)(MIN(n,m))))*gscale;
	    gh = pw_ge_penalty * int_scale;
	  }

	  if (debug>1) fprintf(stdout,"go %d ge %d\n",(pint)g,(pint)gh);

	  /*
	    align the sequences
	  */
	  seq1 = si+1;
        seq2 = sj+1;

        forward_pass(&seq_array[seq1][0], &seq_array[seq2][0],
           n, m);

        reverse_pass(&seq_array[seq1][0], &seq_array[seq2][0]);

        last_print = 0;
	print_ptr = 1;
/*
        sb1 = sb2 = 1;
        se1 = n-1;
        se2 = m-1;
*/

/* use Myers and Miller to align two sequences */

        maxscore = diff(sb1-1, sb2-1, se1-sb1+1, se2-sb2+1, 
        (sint)0, (sint)0);
 
/* calculate percentage residue identity */

        mm_score = tracepath(sb1,sb2);

		if(len1==0 || len2==0) mm_score=0;
		else
			mm_score /= (float)MIN(len1,len2);

        tmat[si+1][sj+1] = ((float)100.0 - mm_score)/(float)100.0;
        tmat[sj+1][si+1] = ((float)100.0 - mm_score)/(float)100.0;

if (debug>1)
{
        fprintf(stdout,"Sequences (%d:%d) Aligned. Score: %d CompScore:  %d\n",
                           (pint)si+1,(pint)sj+1, 
                           (pint)mm_score, 
                           (pint)maxscore/(MIN(len1,len2)*100));
}
else
{
        info("Sequences (%d:%d) Aligned. Score:  %d",
                                      (pint)si+1,(pint)sj+1, 
                                      (pint)mm_score);
}

   }
  }
   displ=ckfree((void *)displ);
   HH=ckfree((void *)HH);
   DD=ckfree((void *)DD);
   RR=ckfree((void *)RR);
   SS=ckfree((void *)SS);


  return((sint)1);
}
Beispiel #9
0
/*
 * Recalculate the motion plan according to the following algorithm:
 *
 *   1. Go over every block in reverse order...
 *
 *      Calculate a junction speed reduction (block_t.entry_factor) so:
 *
 *      a. The junction jerk is within the set limit, and
 *
 *      b. No speed reduction within one block requires faster
 *         deceleration than the one, true constant acceleration.
 *
 *   2. Go over every block in chronological order...
 *
 *      Dial down junction speed reduction values if:
 *      a. The speed increase within one block would require faster
 *         acceleration than the one, true constant acceleration.
 *
 * After that, all blocks will have an entry_factor allowing all speed changes to
 * be performed using only the one, true constant acceleration, and where no junction
 * jerk is jerkier than the set limit, Jerky. Finally it will:
 *
 *   3. Recalculate "trapezoids" for all blocks.
 */
void Planner::recalculate() {
  reverse_pass();
  forward_pass();
  recalculate_trapezoids();
}
Beispiel #10
0
int pairalign(int istart, int iend, int jstart, int jend)
{
   int i, n, m, si, sj;
   int len1, len2, maxres;
   double gg, mm_score;
   int    *mat_xref, *matptr;

   matptr   = gon250mt;
   mat_xref = def_aa_xref;
   maxres = get_matrix(matptr, mat_xref, 10);
   if (maxres == 0) return(-1);

   bots_message("Start aligning ");
   #pragma omp parallel
   {
   #pragma omp single private(i,n,si,sj,len1,m)
      for (si = 0; si < nseqs; si++) {
         if ((n = seqlen_array[si+1]) != 0){
            for (i = 1, len1 = 0; i <= n; i++) {
               char c = seq_array[si+1][i];
               if ((c != gap_pos1) && (c != gap_pos2)) len1++;
            }

            for (sj = si + 1; sj < nseqs; sj++) 
            {
               if ((m = seqlen_array[sj+1]) != 0)
               {
                  #pragma omp task untied \
                  private(i,gg,len2,mm_score) firstprivate(m,n,si,sj,len1) \
                  shared(nseqs, bench_output,seqlen_array,seq_array,gap_pos1,gap_pos2,pw_ge_penalty,pw_go_penalty,mat_avscore)
                  {
                  int se1, se2, sb1, sb2, maxscore, seq1, seq2, g, gh;
                  int displ[2*MAX_ALN_LENGTH+1];
                  int print_ptr, last_print;

                  for (i = 1, len2 = 0; i <= m; i++) {
                     char c = seq_array[sj+1][i];
                     if ((c != gap_pos1) && (c != gap_pos2)) len2++;
                  }

                  gh = 10 * pw_ge_penalty;
                  gg = pw_go_penalty + log((double) MIN(n, m));
                  g  = (mat_avscore <= 0) ? 20 * gg : 2 * mat_avscore * gg;

                  seq1 = si + 1;
                  seq2 = sj + 1;

                  forward_pass(&seq_array[seq1][0], &seq_array[seq2][0], n, m, &se1, &se2, &maxscore, g, gh);
                  reverse_pass(&seq_array[seq1][0], &seq_array[seq2][0], se1, se2, &sb1, &sb2, maxscore, g, gh);

                  print_ptr  = 1;
                  last_print = 0;

                  diff(sb1-1, sb2-1, se1-sb1+1, se2-sb2+1, 0, 0, &print_ptr, &last_print, displ, seq1, seq2, g, gh);
                  mm_score = tracepath(sb1, sb2, &print_ptr, &last_print, displ, seq1, seq2);

                  if (len1 == 0 || len2 == 0) mm_score  = 0.0;
                  else                        mm_score /= (double) MIN(len1,len2);

                  bench_output[si*nseqs+sj] = mm_score;
                  }
               }
            }
         }
      }
   }
   bots_message(" completed!\n");
   return 0;
}