Beispiel #1
0
static void sort_correctness_test(const char* sort_name, pf_sort_func the_sort, 
		TC_TYPE ct,
		TD_TYPE data_type, 
		TD_LENGTH data_length
		) 
{
	citer_dos(begin, NULL);
	citer_dos(end, NULL);
	int length, ulength;

	printf("%s sorting on %s with order %s \n", sort_name, cntr_name(ct), data_order_name(data_type));
	generate_test_data(data_type, data_length, &length, &ulength);

	c = cntr_create(ct);

	for (i = 0; i < length; i ++) cntr_add_back(c, (void*)(intptr_t)rawdata[i]);

	cntr_citer_begin(c, begin);
	cntr_citer_end(c, end);
	
	the_sort(begin, end, cntr_int_compare);
	i = 0;
	citer_for_each(begin, end, assign_z);
	qsort(rawdata, length, sizeof(int), qsort_int_compare);

	judge(length);

	cntr_destroy(c);
}
Beispiel #2
0
static void sort_performance_test(char* sort_name, pf_sort_func the_sort,
		TC_TYPE ct,
		TD_TYPE data_type, 
		TD_LENGTH data_length
		) 
{
	clock_t start_c, end_c;
	int length, ulength;
	citer_dos(begin, NULL);
	citer_dos(end, NULL);

	generate_test_data(data_type, data_length, &length, &ulength);
	c = cntr_create(ct);
	for (i = 0; i < length; i ++) cntr_add_back(c, (void*)(intptr_t)rawdata[i]);

	cntr_citer_begin(c, begin);
	cntr_citer_end(c, end);
	start_c = clock();	
	if (strcmp(sort_name, "default") == 0){
		qsort(rawdata, length, sizeof(int), qsort_int_compare);
	}
	else {
		the_sort(begin, end, cntr_int_compare);
	}
	end_c = clock();
	printf("%s sorting on %s with order %s used %f\n", sort_name, cntr_name(ct), data_order_name(data_type), (float)(end_c - start_c)/CLOCKS_PER_SEC);
	cntr_destroy(c);
}
Beispiel #3
0
int main(){
  long ct_repeat=0;
  long ct_repeat_max=1;
  int ct_return=0;

#ifdef XOPENME
  xopenme_init(1,2);
#endif

  if (getenv("CT_REPEAT_MAIN")!=NULL) ct_repeat_max=atol(getenv("CT_REPEAT_MAIN"));

	// initialization
	byte * test_data = generate_test_data(TEST_SIZE);

#ifdef XOPENME
  xopenme_clock_start(0);
#endif

  for (ct_repeat=0; ct_repeat<ct_repeat_max; ct_repeat++)
  {

	// what we're timing
	int j;
	for(j=0; j<100; j++){
		compdecomp(test_data,TEST_SIZE);
	}

  }

#ifdef XOPENME
  xopenme_clock_end(0);
  xopenme_dump_state();
  xopenme_finish();
#endif


	// release resources
	free(test_data);

	// done
	return 0;
}
static void
generate_test_sound (const gchar * fn, const gchar * launch_string,
    guint num_samples)
{
  GstElement *pipeline, *src, *parse, *enc_bin, *sink;
  GstFlowReturn flow;
  GstMessage *msg;
  GstBuffer *buf;
  GstCaps *caps;

  pipeline = gst_pipeline_new (NULL);

  src = gst_element_factory_make ("appsrc", NULL);

  caps = gst_caps_new_simple ("audio/x-raw",
      "format", G_TYPE_STRING, GST_AUDIO_NE (S16),
      "rate", G_TYPE_INT, SAMPLE_FREQ, "channels", G_TYPE_INT, 2,
      "layout", G_TYPE_STRING, "interleaved",
      "channel-mask", GST_TYPE_BITMASK, (guint64) 3, NULL);
  g_object_set (src, "caps", caps, "format", GST_FORMAT_TIME, NULL);
  gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
  gst_caps_unref (caps);

  /* audioparse to put proper timestamps on buffers for us, without which
   * vorbisenc in particular is unhappy (or oggmux, rather) */
  parse = gst_element_factory_make ("audioparse", NULL);
  if (parse != NULL) {
    g_object_set (parse, "use-sink-caps", TRUE, NULL);
  } else {
    parse = gst_element_factory_make ("identity", NULL);
    g_warning ("audioparse element not available, vorbis/ogg might not work\n");
  }

  enc_bin = gst_parse_bin_from_description (launch_string, TRUE, NULL);

  sink = gst_element_factory_make ("filesink", NULL);
  g_object_set (sink, "location", fn, NULL);

  gst_bin_add_many (GST_BIN (pipeline), src, parse, enc_bin, sink, NULL);

  gst_element_link_many (src, parse, enc_bin, sink, NULL);

  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  buf = generate_test_data (num_samples);
  flow = gst_app_src_push_buffer (GST_APP_SRC (src), buf);
  g_assert (flow == GST_FLOW_OK);

  gst_app_src_end_of_stream (GST_APP_SRC (src));

  /*g_print ("generating test sound %s, waiting for EOS..\n", fn); */

  msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipeline),
      GST_CLOCK_TIME_NONE, GST_MESSAGE_EOS | GST_MESSAGE_ERROR);

  g_assert (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
  gst_message_unref (msg);

  gst_element_set_state (pipeline, GST_STATE_NULL);
  gst_object_unref (pipeline);

  /* g_print ("Done %s\n", fn); */
}
Beispiel #5
0
int main( int argc , char *argv[] )
{
    rng_type rng;
    
    trainings_data_type c;
    generate_test_data( c , -5.0 , 5.0 + 0.1 , 0.4 , []( double x1 , double x2 , double x3 ) {
                        return  1.0 / ( 1.0 + pow( x1 , -4.0 ) ) + 1.0 / ( 1.0 + pow( x2 , -4.0 ) ) + 1.0 / ( 1.0 + pow( x3 , -4.0 ) ); } );
    gpcxx::normalize( c.y );
    

    std::ofstream fout1( "testdata.dat" );
    for( size_t i=0 ; i<c.x[0].size() ; ++i )
        fout1 << c.y[i] << " " << c.x[0][i] << " " << c.x[1][i] << " " << c.x[2][i] << "\n";
    fout1.close();
    

	gpcxx::uniform_symbol< node_type > terminal_gen { std::vector< node_type >{
        node_type { gpcxx::array_terminal< 0 >{} , "x" } ,
        node_type { gpcxx::array_terminal< 1 >{} , "y" } ,
        node_type { gpcxx::array_terminal< 2 >{} , "z" } } };
    gpcxx::uniform_symbol< node_type > unary_gen { std::vector< node_type >{
        node_type { gpcxx::sin_func{} , "s" } ,
        node_type { gpcxx::cos_func{} , "c" } ,
        node_type { gpcxx::exp_func{} , "e" } ,
        node_type { gpcxx::log_func{} , "l" } } };
    gpcxx::uniform_symbol< node_type > binary_gen { std::vector< node_type > {
        node_type { gpcxx::plus_func{} , "+" } ,
        node_type { gpcxx::minus_func{} , "-" } ,
        node_type { gpcxx::multiplies_func{} , "*" } ,
        node_type { gpcxx::divides_func{} , "/" }    
    } };
    
    gpcxx::node_generator< node_type , rng_type , 3 > node_generator {
        { double ( terminal_gen.num_symbols() ) , 0 , terminal_gen } ,
        { double ( unary_gen.num_symbols() ) , 1 , unary_gen } ,
        { double ( binary_gen.num_symbols() ) , 2 , binary_gen } };
    
    size_t population_size = 512;
    size_t generation_size = 20;
    double number_elite = 1;
    double mutation_rate = 0.0;
    double crossover_rate = 0.6;
    double reproduction_rate = 0.3;
    size_t max_tree_height = 8;
    size_t tournament_size = 15;
    

    auto tree_generator = gpcxx::make_basic_generate_strategy( rng , node_generator , max_tree_height , max_tree_height );
    // size_t min_tree_height = 1
    // auto new_tree_generator = gpcxx::make_ramp( rng , node_generator , min_tree_height , max_tree_height , 0.5 );


    typedef gpcxx::static_pipeline< population_type , fitness_type , rng_type > evolver_type;
    evolver_type evolver( number_elite , mutation_rate , crossover_rate , reproduction_rate , rng );
    std::vector< double > fitness( population_size , 0.0 );
    std::vector< tree_type > population( population_size );


    evolver.mutation_function() = gpcxx::make_mutation(
        gpcxx::make_simple_mutation_strategy( rng , node_generator ) ,
        gpcxx::make_tournament_selector( rng , tournament_size ) );
    evolver.crossover_function() = gpcxx::make_crossover( 
        gpcxx::make_one_point_crossover_strategy( rng , max_tree_height ) ,
        gpcxx::make_tournament_selector( rng , tournament_size ) );
    evolver.reproduction_function() = gpcxx::make_reproduce(
        gpcxx::make_tournament_selector( rng , tournament_size ) );
    
    gpcxx::timer timer;
    auto fitness_f = gpcxx::make_regression_fitness( evaluator() );

    // initialize population with random trees and evaluate fitness
    timer.restart();
    for( size_t i=0 ; i<population.size() ; ++i )
    {
        tree_generator( population[i] );
        fitness[i] = fitness_f( population[i] , c );
    }
    std::cout << gpcxx::indent( 0 ) << "Generation time " << timer.seconds() << std::endl;
    std::cout << gpcxx::indent( 1 ) << "Best individuals" << std::endl << gpcxx::best_individuals( population , fitness , 1 , 10 ) << std::endl;
    std::cout << gpcxx::indent( 1 ) << "Statistics : " << gpcxx::calc_population_statistics( population ) << std::endl;
    std::cout << gpcxx::indent( 1 ) << std::endl << std::endl;
    
    write_height_hist( population , "initial_height.hist" );
    write_size_hist( population , "initial_size.hist" );
    
    timer.restart();
    for( size_t generation=1 ; generation<=generation_size ; ++generation )
    {
        gpcxx::timer iteration_timer;
        iteration_timer.restart();
        evolver.next_generation( population , fitness );
        double evolve_time = iteration_timer.seconds();
        iteration_timer.restart();
        std::transform( population.begin() , population.end() , fitness.begin() , [&]( tree_type const &t ) { return fitness_f( t , c ); } );
        double eval_time = iteration_timer.seconds();
        
        write_height_hist( population , "height_" + std::to_string( generation ) + ".hist" );
        write_size_hist( population , "size_" + std::to_string( generation ) + ".hist" );
        
        std::cout << gpcxx::indent( 0 ) << "Generation " << generation << std::endl;
        std::cout << gpcxx::indent( 1 ) << "Evolve time " << evolve_time << std::endl;
        std::cout << gpcxx::indent( 1 ) << "Eval time " << eval_time << std::endl;
        std::cout << gpcxx::indent( 1 ) << "Best individuals" << std::endl << gpcxx::best_individuals( population , fitness , 2 , 10 ) << std::endl;
        std::cout << gpcxx::indent( 1 ) << "Statistics : " << gpcxx::calc_population_statistics( population ) << std::endl << std::endl;
    }
    std::cout << "Overall time : " << timer.seconds() << std::endl;


// 	generate_data();
// 	init_constants();
// 	init_node_types();   // init generators
// 	init_population();
// 	evolve();
// 	report();

    return 0;
}