Ejemplo n.º 1
0
int main(int argc, char **argv)
{
    int     i;
    int     errors;
    DataSet *train_set;
    DataSet *test_set;
    Network *adultnn = create_network(14);
    double  e;
    double  acc;
    Class   predicted, desired;

    // training
    train_set = read_dataset("adult.train");

    if (train_set == NULL) {
        fprintf(stderr, "Error reading training set\n");
        exit(1);
    }

    add_layer(adultnn, 28);  // hidden layer
    add_layer(adultnn, 2);  // output layer
    initialize_weights(adultnn, SEED);
    print_network_structure(adultnn);

    printf("Training network with %d epochs...\n", EPOCHS);
    e = batch_train(adultnn, train_set, LEARNING_RATE, EPOCHS,
                   sigmoid, dsigmoid);
    printf("Training finished, approximate final SSE: %f\n", e);

    print_network_structure(adultnn);

    // testing
    test_set = read_dataset("adult.test");

    if (test_set == NULL) {
        fprintf(stderr, "Error reading test set\n");
        exit(1);
    }

    errors = 0;
    printf("Testing with %d cases...\n", test_set->n_cases);
    for (i = 0; i < test_set->n_cases; ++i) {
        predicted = predict_class(adultnn, test_set->input[i]);
        desired = output_to_class(test_set->output[i]);
        if (predicted != desired)
            ++errors;
        printf("Case %d | predicted: %s, desired: %s, outputs: %4.3f %4.3f \n", i,
               class_to_string(predicted), class_to_string(desired),
               adultnn->output_layer->y[0], adultnn->output_layer->y[1]);
    }

    acc = 100.0 - (100.0 * errors / test_set->n_cases);
    printf("Testing accuracy: %f\n", acc);
    printf("Total classificarion errors: %d\n", errors);

    destroy_dataset(train_set);
    destroy_dataset(test_set);

    return 0;
}
H5Converter::H5Converter(const std::string& h5_fname, const std::string& out_dir) :
  out_dir_(out_dir)
{
  file_id_ = H5Fopen(h5_fname.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
  root_ = H5Gopen(file_id_, "/", H5P_DEFAULT);
  aux_ = H5Gopen(file_id_, "/aux", H5P_DEFAULT);

  // <aux info>
  // read target ids
  read_dataset(aux_, "ids", targ_ids_);
  std::cerr << "[h5dump] number of targets: " << targ_ids_.size() << 
    std::endl;

  n_targs_ = targ_ids_.size();

  read_dataset(aux_, "lengths", lengths_);
  assert( n_targs_ == lengths_.size() );

  read_dataset(aux_, "eff_lengths", eff_lengths_);
  assert( n_targs_ == eff_lengths_.size() );

  // read bootstrap info
  std::vector<int> n_bs_vec;
  read_dataset(aux_, "num_bootstrap", n_bs_vec);
  n_bs_ = n_bs_vec[0];

  std::cerr << "[h5dump] number of bootstraps: " << n_bs_ << std::endl;
  // </aux info>
  if (n_bs_ > 0) {
    bs_ = H5Gopen(file_id_, "/bootstrap", H5P_DEFAULT);
  }

  std::vector<std::string> tmp;
  read_dataset(aux_, "kallisto_version", tmp);
  kal_version_ = tmp[0];
  tmp.clear();
  std::cerr << "[h5dump] kallisto version: " << kal_version_ << std::endl;

  std::vector<int> idx_version;
  read_dataset(aux_, "index_version", idx_version);
  idx_version_ = static_cast<size_t>(idx_version[0]);
  std::cerr << "[h5dump] index version: " << idx_version_ << std::endl;

  read_dataset(aux_, "start_time", tmp);
  start_time_ = tmp[0];
  tmp.clear();
  std::cerr << "[h5dump] start time: " << start_time_ << std::endl;

  read_dataset(aux_, "call", tmp);
  call_ = tmp[0];
  tmp.clear();
  std::cerr << "[h5dump] shell call: " << call_ << std::endl;

  alpha_buf_.resize( n_targs_, 0.0 );
  assert( n_targs_ == alpha_buf_.size() );

  tpm_buf_.resize( n_targs_, 0.0 );
  assert( n_targs_ == tpm_buf_.size() );
}
Ejemplo n.º 3
0
typename boost::enable_if<is_multi_array<T>, void>::type
read_dataset(dataset & data_set, T & array, slice const& file_slice)
{
    // --- create memory dataspace for the complete input array
    h5xx::dataspace memspace = h5xx::create_dataspace(array);
    // --- create file dataspace and select the slice (hyperslab) from it
    h5xx::dataspace filespace(data_set);
    filespace.select(file_slice);
    // ---
    read_dataset(data_set, array, memspace, filespace);
}
Ejemplo n.º 4
0
static int read_sensor_altitude(void *user_data, harp_array data)
{
    ingest_info *info = (ingest_info *)user_data;

    if (read_dataset(info->geo_data_cursor, "satellite_altitude", info->num_scanlines, data) != 0)
    {
        return -1;
    }

    broadcast_array_float(info->num_scanlines, info->num_pixels, data.float_data);

    return 0;
}
Ejemplo n.º 5
0
floatingtype_t read_floatingtype(hid_t loc_id, const char *path)
{
    floatingtype_t ft;

    ft.floatingtype = get_type_ft(loc_id, path);
    if (ft.floatingtype == E_SINGLE_REAL)
        ft.singlereal = read_singlereal(loc_id, path);
    else if (ft.floatingtype == E_SINGLE_COMPLEX)
        ft.singlecomplex = read_singlecomplex(loc_id, path);
    else if (ft.floatingtype == E_VECTOR)
        ft.vector = read_vector(loc_id, path);
    else if (ft.floatingtype == E_DATA_SET)
        ft.dataset = read_dataset(loc_id, path);
    else if (ft.floatingtype == E_ARRAY_SET)
        ft.arrayset = read_arrayset(loc_id, path);
    return ft;
}
Ejemplo n.º 6
0
/*
 * This recursive function opens all the groups in vertical direction and
 * checks the data.
 */
void recursive_read_group(hid_t memspace, hid_t filespace, hid_t gid,
                          int counter)
{
    hid_t child_gid;
    int   mpi_rank, err_num=0;
    char  gname[64];

    MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
#ifdef BARRIER_CHECKS
    if((counter+1) % 10)
        MPI_Barrier(MPI_COMM_WORLD);
#endif /* BARRIER_CHECKS */

    if( (err_num = read_dataset(memspace, filespace, gid)) )
        nerrors += err_num;

    if( counter < GROUP_DEPTH ) {
        sprintf(gname, "%dth_child_group", counter+1);
        child_gid = H5Gopen(gid, gname);
        VRFY((child_gid>0), gname);
        recursive_read_group(memspace, filespace, child_gid, counter+1);
        H5Gclose(child_gid);
    }
}
Ejemplo n.º 7
0
void H5Converter::rw_from_counts(hid_t group_id, const std::string& count_name, const std::string& out_fname) {
  std::vector<double> alpha;
  read_dataset(group_id, count_name.c_str(), alpha);

  plaintext_writer(out_fname, targ_ids_, alpha, eff_lengths_, lengths_);
}
Ejemplo n.º 8
0
typename boost::enable_if<is_multi_array<T>, void>::type
read_dataset(h5xxObject const& object, std::string const& name, T & array, slice const& file_slice)
{
    dataset data_set(object, name);
    read_dataset(data_set, array, file_slice);
}
Ejemplo n.º 9
0
static int read_viewing_zenith_angle(void *user_data, harp_array data)
{
    ingest_info *info = (ingest_info *)user_data;

    return read_dataset(info->geo_data_cursor, "viewing_zenith_angle", info->num_scanlines * info->num_pixels, data);
}
Ejemplo n.º 10
0
static int read_latitude_bounds(void *user_data, harp_array data)
{
    ingest_info *info = (ingest_info *)user_data;

    return read_dataset(info->geo_data_cursor, "latitude_bounds", info->num_scanlines * info->num_pixels * 4, data);
}
Ejemplo n.º 11
0
static int read_longitude(void *user_data, harp_array data)
{
    ingest_info *info = (ingest_info *)user_data;

    return read_dataset(info->geo_data_cursor, "longitude", info->num_scanlines * info->num_pixels, data);
}
Ejemplo n.º 12
0
/*
 * This function is to verify the data from multiple group testing.  It opens
 * every dataset in every group and check their correctness.
 *
 * Changes:     Updated function to use a dynamically calculated size,
 *              instead of the old SIZE #define.  This should allow it
 *              to function with an arbitrary number of processors.
 *
 *                                              JRM - 8/11/04
 */
void multiple_group_read(void)
{
    int      mpi_rank, mpi_size, error_num, size;
    int      m;
    hbool_t  use_gpfs = FALSE;
    char     gname[64];
    hid_t    plist, fid, gid, memspace, filespace;
    hsize_t  chunk_origin[DIM];
    hsize_t  chunk_dims[DIM], file_dims[DIM], count[DIM];
    const H5Ptest_param_t *pt;
    char	*filename;
    int		ngroups;

    pt = GetTestParameters();
    filename = pt->name;
    ngroups = pt->count;

    MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
    MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);

    size = get_size();

    plist = create_faccess_plist(MPI_COMM_WORLD, MPI_INFO_NULL, facc_type, use_gpfs);
    fid = H5Fopen(filename, H5F_ACC_RDONLY, plist);
    H5Pclose(plist);

    /* decide hyperslab for each process */
    get_slab(chunk_origin, chunk_dims, count, file_dims, size);

    /* select hyperslab for memory and file space */
    memspace  = H5Screate_simple(DIM, file_dims, NULL);
    H5Sselect_hyperslab(memspace, H5S_SELECT_SET, chunk_origin, chunk_dims,
                        count, chunk_dims);
    filespace = H5Screate_simple(DIM, file_dims, NULL);
    H5Sselect_hyperslab(filespace, H5S_SELECT_SET, chunk_origin, chunk_dims,
                        count, chunk_dims);

    /* open every group under root group. */
    for(m=0; m<ngroups; m++) {
        sprintf(gname, "group%d", m);
        gid = H5Gopen(fid, gname);
        VRFY((gid > 0), gname);

        /* check the data. */
        if(m != 0)
            if( (error_num = read_dataset(memspace, filespace, gid))>0)
	        nerrors += error_num;

        /* check attribute.*/
        error_num = 0;
        if( (error_num = read_attribute(gid, is_group, m))>0 )
	    nerrors += error_num;

        H5Gclose(gid);

#ifdef BARRIER_CHECKS
        if(!((m+1)%10))
            MPI_Barrier(MPI_COMM_WORLD);
#endif /* BARRIER_CHECKS */
    }

    /* open all the groups in vertical direction. */
    gid = H5Gopen(fid, "group0");
    VRFY((gid>0), "group0");
    recursive_read_group(memspace, filespace, gid, 0);
    H5Gclose(gid);

    H5Sclose(filespace);
    H5Sclose(memspace);
    H5Fclose(fid);

}