Beispiel #1
0
DataFrame LNLP::get_stats()
{
    PredStats output = make_stats();
    PredStats const_output = make_const_stats();
    return DataFrame::create( Named("num_pred") = output.num_pred, 
                              Named("rho") = output.rho, 
                              Named("mae") = output.mae, 
                              Named("rmse") = output.rmse,
                              Named("perc") = output.perc, 
                              Named("const_pred_num_pred") = const_output.num_pred, 
                              Named("const_pred_rho") = const_output.rho, 
                              Named("const_pred_mae") = const_output.mae, 
                              Named("const_pred_rmse") = const_output.rmse, 
                              Named("const_pred_perc") = const_output.perc);
}
Beispiel #2
0
int main(int argc, char *argv[]) {
	GtkWidget *box, *button, *poz, *reg_b, *frame;
	GtkStyle *style;
	GdkPixmap *bg;
	char buffer[buffsize];

	if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) {
		fprintf(stderr, "WSAStartup() failed");
		exit(1);
	}

	if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
		puts("socket() failed");

	memset(&server, 0, sizeof(server)); /* Zero out structure */
	server.sin_family = AF_INET; /* Internet address family */
	server.sin_addr.s_addr = inet_addr("127.0.0.1"); /* Server IP address */
	server.sin_port = htons(21); /* Server port */
	if (connect(sock, (struct sockaddr *) &server, sizeof(server)) < 0) /* Establish the connection to the server */
	puts("connect() failed");

	gtk_init(&argc, &argv);
	//start GTK+

	pixbuf = gdk_pixbuf_new_from_file_utf8("bgm.jpg", error);     //read background
	gdk_pixbuf_render_pixmap_and_mask(pixbuf, &bg, NULL, 0);
	style = gtk_style_new();
	style->bg_pixmap[0] = bg;

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);     //create window
	//gtk_window_set_default_size(GTK_WINDOW(window), 1280, 720);
	pixbuf = gdk_pixbuf_new_from_file_utf8("logo.gif", error);     //read logo
	gtk_window_set_icon(GTK_WINDOW (window), pixbuf);     //set logo
	gtk_container_set_border_width(GTK_CONTAINER (window), 10);
	//create close window event
	g_signal_connect(window, "delete-event", G_CALLBACK (delete_event), NULL);
	gtk_widget_set_style(GTK_WIDGET(window), GTK_STYLE(style));     //set background
	box = gtk_vbox_new(FALSE, 0);     //the mess of positioning
	poz = gtk_hbox_new(FALSE, 0);
	logbox = gtk_vbox_new(FALSE, 0);
	gamebox = gtk_vbox_new(FALSE, 0);     //positioning ends here

	//Setting up used Widgets -> buttons, input fields, ...
	//image = gtk_image_new_from_file_utf8("maemo.png");
	pixbuf = gdk_pixbuf_new_from_file_at_scale_utf8("pic/0.jpg", 500, 500, TRUE,     //read shown image
			error);
	image = gtk_image_new_from_pixbuf(pixbuf);     //set image
	frame = gtk_frame_new(NULL);
	gtk_frame_set_shadow_type((GtkFrame *) frame, GTK_SHADOW_ETCHED_IN);
	gtk_container_add(GTK_CONTAINER (frame), image);
	gtk_container_add(GTK_CONTAINER (poz), frame);
	gtk_widget_show(frame);

	gtk_box_pack_start(GTK_BOX (poz), box, FALSE, FALSE, 10);     //a bit of positioning
	gtk_box_pack_start(GTK_BOX (box), logbox, FALSE, FALSE, 10);
	gtk_box_pack_start(GTK_BOX (box), gamebox, FALSE, FALSE, 10);     //end

	logname = gtk_entry_new();
	gtk_box_pack_start(GTK_BOX (logbox), logname, FALSE, FALSE, 10);
	gtk_widget_show(logname);

	pass = gtk_entry_new();
	gtk_box_pack_start(GTK_BOX (logbox), pass, FALSE, FALSE, 10);
	gtk_widget_show(pass);

	button = gtk_button_new_with_label("login");
	g_signal_connect(button, "clicked", G_CALLBACK (login), (gpointer) NULL);
	gtk_box_pack_start(GTK_BOX (logbox), button, FALSE, FALSE, 10);
	gtk_widget_show(button);

	reg_b = gtk_button_new_with_label("Register");
	g_signal_connect(reg_b, "clicked", G_CALLBACK (reg), (gpointer) "NULL");
	gtk_box_pack_start(GTK_BOX (logbox), reg_b, FALSE, FALSE, 10);
	gtk_widget_show(reg_b);

	cbutton = gtk_button_new_with_label(buffer);
	g_signal_connect(cbutton, "clicked", G_CALLBACK (lan), (gpointer) buffer);
	gtk_box_pack_start(GTK_BOX (gamebox), cbutton, FALSE, FALSE, 10);

	button = gtk_button_new_with_label("picture");
	g_signal_connect(button, "clicked", G_CALLBACK (set_image), "pic");
	gtk_box_pack_start(GTK_BOX (gamebox), button, FALSE, FALSE, 10);

	stats = make_stats();
	gtk_box_pack_start(GTK_BOX (gamebox), stats, FALSE, FALSE, 10);

	status = gtk_toggle_button_new_with_label("connected");
	gtk_toggle_button_set_active((GtkToggleButton *) status, TRUE);
	g_signal_connect(status, "toggled", G_CALLBACK (clcon), (gpointer) NULL);
	gtk_box_pack_start(GTK_BOX (box), status, FALSE, FALSE, 10);
	gtk_container_add(GTK_CONTAINER (window), poz);

	//showing the parts of the window
	gtk_widget_show(status);
	gtk_widget_show(image);
	gtk_widget_show(logbox);
	gtk_widget_show(poz);
	gtk_widget_show(box);
	gtk_widget_show(window);
	gtk_main();

	return EXIT_SUCCESS;
}
Beispiel #3
0
void Xmap::run()
{
    prepare_forecast(); // check parameters
    
    // setup data structures and compute maximum lib size
    predicted_stats.clear();
    predicted_lib_sizes.clear();
    std::vector<size_t> full_lib = which_lib;
    size_t max_lib_size = full_lib.size();
    std::mt19937 rng(seed); // init mersenne twister with seed
    // need to update with true random seed
    std::uniform_int_distribution<uint32_t> lib_sampler(0, max_lib_size-1);
    std::uniform_real_distribution<double> unif_01(0, 1);
    std::vector<int> idx;
 
    size_t m;
    size_t t;

    for(auto lib_size: lib_sizes)
    {
        if(lib_size >= max_lib_size && (!random_libs || !replace))
        // no possible lib variation if using all vectors and
        // [no random libs OR (random_libs and sampling without replacement)]
        {
            which_lib = full_lib; // use all lib vectors
            forecast();
            predicted_stats.push_back(make_stats());
            predicted_lib_sizes.push_back(lib_size);
            break;
        }
        else if(random_libs)
        {
            which_lib.resize(lib_size, 0);
            for(size_t k = 0; k < num_samples; ++k)
            {
                if(replace)
                {
                    for(auto& lib: which_lib)
                    {
                        lib = full_lib[lib_sampler(rng)];
                    }
                }
                else
                {
                    // sample without replacement (algorithm from Knuth)
                    m = 0;
                    t = 0;
                    while(m < lib_size)
                    {
                        if(double(max_lib_size - t) * unif_01(rng) >= double(lib_size - m))
                        {
                            ++t;
                        }
                        else
                        {
                            which_lib[m] = full_lib[t];
                            ++t; ++m;
                        }
                    }
                }
                forecast();
                predicted_stats.push_back(make_stats());
                predicted_lib_sizes.push_back(lib_size);
            }
        }
        else
        // no random libs and using contiguous segments
        {
            for(size_t k = 0; k < max_lib_size; ++k)
            {
                if((k + lib_size) > max_lib_size) // need to loop around
                {
                    which_lib.assign(full_lib.begin()+k, full_lib.end()); // k to end
                    which_lib.insert(which_lib.begin(), 
                                     full_lib.begin(), 
                                     full_lib.begin() + lib_size - (max_lib_size-k));
                }
                else
                {
                    which_lib.assign(full_lib.begin()+k, full_lib.begin()+k+lib_size);
                }
                
                forecast();
                predicted_stats.push_back(make_stats());
                predicted_lib_sizes.push_back(lib_size);
            }
        }
    }
    which_lib = full_lib;
    return;
}