Ejemplo n.º 1
0
///
// Initialize the shader and program object
//
int Init ( ESContext *esContext )
{
   UserData *userData = esContext->userData;
   GLbyte *vShaderStr = read_data_from_file("shader.vert", 4096);
   GLbyte *fShaderStr = read_data_from_file("yuv2.frag", 4096);

   // Load the shaders and get a linked program object
   userData->programObject = esLoadProgram ( vShaderStr, fShaderStr );

   // Get the attribute locations
   userData->positionLoc = glGetAttribLocation ( userData->programObject, "a_position" );
   userData->texCoordLoc = glGetAttribLocation ( userData->programObject, "a_texCoord" );
   
   // Get the sampler location
   userData->baseMapLoc = glGetUniformLocation ( userData->programObject, "s_baseMap" );

   userData->texture_width =  glGetUniformLocation(userData->programObject, "texture_width");
   
   // set the textures
   glGenTextures ( 1, &userData->baseMapTexId );
   glBindTexture ( GL_TEXTURE_2D, userData->baseMapTexId );

   if ( userData->baseMapTexId == 0 )
      return FALSE;

   glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
   return TRUE;
}
/* Now write a function to find the misclassified data */
int main()
{
    read_data_from_file( (char *)"pima_diabetes/pima_diabetes_train.txt", 1);
    read_data_from_file( (char *)"pima_diabetes/pima_diabetes_validation.txt", 2); // copies data into validation_input and validation_output

    printf("Code is running ...\n");
    int inputs, count = 0;
    float error, threshold = 0.1;

    train_network_pool(0.04);


    dnc dnc_instance2(ATTR_NUM, NUM_CLASS, TRAIN_SIZE, 540, 0.001, MAX_NODES, 0.05, 0.8, (char *)"dnc_output.txt", 20.0);
    dnc_instance2.set_monotone_increament(5);

    dnc_instance2.take_validation_data((float *) validation_input, (float *)validation_output, VALIDATION_SIZE); // num of validation data as last argument
    dnc_instance2.execute2((float *)input, (float *)output);

    Marchand marchand_instance(ATTR_NUM, NUM_CLASS_MARCHAND, TRAIN_SIZE, 200, 0.05, MAX_NODES, (char *)"marchand_output.txt", 8.0); //max epoch 200, this call constructs network with 2 output neurons
    marchand_instance.take_validation_data((float *) validation_input, (float *)validation_output, VALIDATION_SIZE);
    marchand_instance.execute((float *)input, (float *)output);


    cout << "I am here" << endl;


    return 0;

}
Ejemplo n.º 3
0
/*
 * Write record described by @node and stored in @fd_in, into @fd_out
 * Copies data from @fd_in to @fd_out by chunk sized by @buffer_size
 * @buffer is used only for data transition
 */
void write_node(int fd_in, int fd_out, compact_header_t * node, void * buffer, size_t buffer_size)
{
    /*Scroll position in fd_in to needed key*/
    if (lseek64(fd_in, node->record_offset, SEEK_SET) < 0) {
        perror("lseek64()");
        exit(EXIT_FAILURE);
    }
    /* Calculate whole data size */
    size_t bytes_to_write = sizeof(header_t) + node->payload_size;
    size_t bytes_written = 0;

    do {
        /* Move data by chunks with fixed size*/
        size_t current_chunk_sz = MIN(bytes_to_write - bytes_written, buffer_size);
        if (read_data_from_file(fd_in, buffer, current_chunk_sz)) {
            fprintf(stderr, "Reading error\n");
            exit(EXIT_FAILURE);
        }
        if (write_data_to_fd(fd_out, buffer, current_chunk_sz)) {
            fprintf(stderr, "Writing error\n");
            exit(EXIT_FAILURE);
        }
        bytes_written += current_chunk_sz;
    } while(bytes_written < bytes_to_write);
}
char *__get_log_env(void) {
	char *log_env = DA_NULL;

	/* environment value has higher priority than configure file */
	log_env = getenv(DA_DEBUG_ENV_KEY);
	if (log_env && strlen(log_env))
		return strdup(log_env);

	if (read_data_from_file(DA_DEBUG_CONFIG_FILE_PATH, &log_env))
		return log_env;

	return DA_NULL;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[]){
  printf("\n");

  if (argc < 2) {
    printf("Worng number of arguments.\nYou may execute with problem size.\n\n./riemann problem_size\n\nYou can also execute with data file\n\n./riemann problem_size filename\n\n");
    return -1;
  }

  int problem_size = atoi(argv[1]);

  char *filename = "data.dat";

  if (argc == 2) 
    create_random_file(filename, problem_size);

  else
    filename = argv[2];
    
  double * data = malloc(sizeof(double) * problem_size * 2);

  read_data_from_file(filename, problem_size, data);

  //printf("Problem size: %d\n", problem_size);
  //print_data(data, problem_size);

  double result;
  clock_t time = clock ();

  result = left_riemann(data, problem_size);
  printf("Left Riemann: %f\n", result);

  result = right_riemann(data, problem_size);
  printf("Right Riemann: %f\n", result);

  result = trapezoidal_riemann(data, problem_size);
  printf("Trapezoidal Riemann: %f\n", result);

  time = clock() - time;

  printf("\nTime spent: %f seconds\n\n", ((double) time / CLOCKS_PER_SEC));

  return 0;
}
Ejemplo n.º 6
0
int read_header_from_file(int fd, header_t * hdr)
{
    return read_data_from_file(fd, (void*)hdr, sizeof(*hdr));
}
Ejemplo n.º 7
0
int main(int argc, char* argv[])
{
	int retcode;
	int pre_day = 5;
	
	for(int i=0; i<argc; i++){
		if(0 == stricmp(argv[i],"-d")){
			pre_day = atoi(argv[++i]);
			if(0 == pre_day){
				pre_day = 5;
			}
		}
	}
	retcode = sqlite3_open("history.db", &pDB);
	if(SQLITE_OK!=retcode){
		printf("retcode of sqlite3_open():%d description:%s", retcode, sqlite3_errmsg(pDB));
		sqlite3_close(pDB);
		return 1;
	}
	
	retcode = sqlite3_exec(pDB, SQLCreateTable, 0, NULL, &errmsg);
	if(SQLITE_OK!=retcode){
		printf("retcode of sqlite3_exec():%d description:%s", retcode, errmsg);
		sqlite3_free(errmsg);
	}
	
	FILE *fp = fopen("trades.csv", "wb");
	if(NULL != fp){
		W3Client w3;
		char url[1024];
		long t = time(NULL);
		t-=60*60*24*pre_day;
		// sprintf(url, "/t/trades.csv?symbol=mtgoxUSD&start=%ld", t);
		sprintf(url, "/v1/trades.csv?symbol=mtgoxUSD");
		
		if(w3.Connect("http://api.bitcoincharts.com")){
			if(w3.Request(url)){
				// 默认获得前五天的数据
				// 如果使用"trades.csv?symbol=mtgoxUSD&start=0",则获取全部数据
				char buf[1024];
				for(;;){
					int len = w3.Response(reinterpret_cast<unsigned char *>(buf), sizeof(buf));
					if(0 == len){
						break;
					}
					buf[len] = '\0';
					printf(buf);
					fwrite(buf, len, 1, fp);
				}
			}
			w3.Close();
		}
		fclose(fp);
	}
	printf("\nFinish http-get ...\n");
	
	read_data_from_file();
	read_data_from_db();
	
	sqlite3_close(pDB);
	
	printf("\nFinish write files.\n");
	return 0;
}