Exemplo n.º 1
0
int green_serv(int argc, const char* argv[]) {
	MYSQL * conn;
	struct gs_scope campaign;

	/*You must initialize the library on the main thread. 
	 *the only time threaded_db should be undef-ed is if you're
	 *unit testing and don't want a threaded environment for some
	 *weird reason.
	*/
	#ifdef THREADED_DB
	BOOT_LOG_STR("Initializing MySQL Library.","");
	mysql_library_init(0, NULL, NULL);
	#endif

	conn = _getMySQLConnection();
	if(!conn){
		fprintf(stderr, "%s\n", "Could not connect to mySQL");
		return 1;
	}

	/* Setup Campaign for all querying. */
	db_getScopeById(CAMPAIGN_ID, &campaign, conn);
	parseArgs(argc,argv,&campaign,conn);
	mysql_close(conn);
	
	/* Set global campaign id for this Server instance */
	_shared_campaign_id = campaign.id;
	(void)_shared_campaign_id; /*http://stackoverflow.com/a/394568/1808164*/

	/*What a silly cast we have to make...*/
	BOOT_LOG_STR("Running Network Interface:", "");
	run_network((void*(*)(void*))&doNetWork);
	BOOT_LOG_STR("Finished Network Interface.","");
	/*Clean Up database connection*/
	mysql_library_end();

	
	close(STDIN_FILENO);
	close(STDOUT_FILENO);
	close(STDERR_FILENO);
	return 0;
}
Exemplo n.º 2
0
int main(int argc, char * args[]){
    char data[50]; //Arbitrary length
	char path[100];
	char settings[100] = "networks/settings.cfg";
	int num_networks, i, num_iterations=10000;
	FILE * settingsFile, * results;
	char network[100];

	settingsFile = fopen(settings, "r");
	fscanf(settingsFile, "networks:%d", &num_networks);
	fclose(settingsFile);

	results = fopen(PATH_TO_RESULTS, "w");
	fprintf(results, "#Hidden Units\tresult\ttime (useconds)\n");
	for(i=0; i<num_networks; i++){
		printf("Testing network%d\n", i+1);
		sprintf(network, "%s%d.net", PATH_TO_NETWORKS, i+1);
		run_network(network, num_iterations, results, i+1);
	}
	fclose(results);
}
Exemplo n.º 3
0
void run_simulation(table *data) {
    FILE *fout = fopen("epoch-error.txt", "w+");
    
    size_t *feature_indices = malloc(data->column_count * sizeof(double));
    size_t index, class_index = -1, feature_count = 0;
    for(index = 0; index < data->column_count; index++) {
        if(data->column_types[index] == CONTINUOUS) {
            feature_indices[feature_count++] = index;
        }
        if(data->column_flags[index] == CLASS) {
            class_index = index;
        }
    }
    
    feature_indices = realloc(feature_indices, feature_count * sizeof(double));
    double *weights = calloc(feature_count + 1, sizeof(double));
    double learning_rate = 0.0001, error = 99999;
    // 0.0005 -> 373.7
    
    /*
    // Approximate weights
    weights[0] = -2.135869;
    weights[1] = 0.005530;
    weights[2] = 0.015483;
    weights[3] = -0.040691;
    weights[4] = 0.038882;
    weights[5] = -0.007324;
    weights[6] = -0.156527;
    weights[7] = -0.219943;
    */
    
    long epoch = 0;
    while(error > 10 && epoch < 1000000) {
        error = 0.0;
        for(index = 0; index < data->length; index++) {
            error += run_network(weights, data->instances[index], 
                feature_count, feature_indices, class_index, learning_rate);
        }
        
        printf("Epoch %lu: W -> ", epoch);
        for(index = 0; index < feature_count + 1; index++) {
            printf("%.8f ", weights[index]);
        }
        printf(" E -> %f\n", error);
        fprintf(fout, "%f\n", error);
        
        epoch++;
    }
    
    fclose(fout);
    
    /*
    size_t i, j;
    double input, sum, output, actual;
    size_t feature_index;
    instance inst;
    
    for(j = 0; j < data->length; j++) {
        inst = data->instances[j];
        sum = weights[0];
        for(i = 0; i < feature_count; i++) {
            feature_index = feature_indices[i];
            input = *((double *)inst[feature_index]);
            if(!isnan(input)) {
                sum += weights[index + 1] * input;
            }
        }
        
        output = sigmoid(sum);
        actual = (double)(((char *)inst[class_index])[0] == 'D');
        printf("%f %f\n", actual, output);
    }
    */
}