Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't add values of a vector into a dataset #221

Open
8enjam1n opened this issue Apr 30, 2024 · 0 comments
Open

I can't add values of a vector into a dataset #221

8enjam1n opened this issue Apr 30, 2024 · 0 comments

Comments

@8enjam1n
Copy link

I'm trying to add values of a vector into a dataset with the library "hdf5r". I have any errors but when I open the .h5 created there are any values.

I have this code :

...

##### Création des N fichiers HDF5 de noms file_name + num_echantillon{1,2,...,N} #####

file_name <- toString(args[length(args)-1])
# Création dossier
dir.create(file_name)

for (i in 1:N) {
  
  # Nom du fichier
  current_file_name <- paste(file_name,toString(i),".h5",sep = "")
  
  # Création du fichier
  file.h5 <- H5File$new(paste(file_name,current_file_name, sep = "/"), mode = "w")
  
  # Groupe "group_data"
  ### Création du groupe
  browser()
  group_data <- file.h5$create_group("group_data")
  ### Création des datasets contenant les données

  group_data[["times_c_i"]] <- data[,1,i]
  group_data[["types_u_i"]] <- as.integer(data[,2,i])

  ### Création des attributs du groupe
  h5attr(group_data,"num_model") <- as.integer(num_model)
  h5attr(group_data,"alpha") <- alpha
  h5attr(group_data,"beta") <- beta
  h5attr(group_data,"rho_p") <- rho_p
  h5attr(group_data,"rho_c") <- rho_c
  
  # Groupe "group_gibbs"
  ### Création du groupe
  group_gibbs <- file.h5$create_group("group_gibbs")
  ### Création des attributs du groupe
  h5attr(group_gibbs,"hyperparameter_a_alpha") <- a
  h5attr(group_gibbs,"hyperparameter_b_alpha") <- b
  h5attr(group_gibbs,"hyperparameter_A_mu") <- A
  h5attr(group_gibbs,"hyperparameter_B_mu") <- B
  h5attr(group_gibbs,"hyperparameter_beta1") <- beta1
  h5attr(group_gibbs,"hyperparameter_beta2") <- beta2
  h5attr(group_gibbs,"hyperparameter_c_good") <- c.good
  h5attr(group_gibbs,"hyperparameter_c_bad") <- c.bad
  h5attr(group_gibbs,"hyperparameter_d_good") <- d.good
  h5attr(group_gibbs,"hyperparameter_d_bad") <- d.bad
  h5attr(group_gibbs,"hyperparameter_e_good") <- e.good
  h5attr(group_gibbs,"hyperparameter_e_bad") <- e.bad
  h5attr(group_gibbs,"hyperparameter_f_good") <- f.good
  h5attr(group_gibbs,"hyperparameter_f_bad") <- f.bad
  h5attr(group_gibbs,"K") <- as.integer(K)
  h5attr(group_gibbs,"var_norm_alpha") <- variance.alpha
  h5attr(group_gibbs,"var_norm_beta") <- variance.beta
  h5attr(group_gibbs,"var_norm_rho_p") <- variance.rho_p
  h5attr(group_gibbs,"var_norm_rho_c") <- variance.rho_c
  h5attr(group_gibbs,"alpha_guess") <- first_guess[1]
  h5attr(group_gibbs,"beta_guess") <- first_guess[2]
  h5attr(group_gibbs,"rho_p_guess") <- first_guess[3]
  h5attr(group_gibbs,"rho_c_guess") <- first_guess[4]
  h5attr(group_gibbs,"alpha_lb") <- lower_bound[1]
  h5attr(group_gibbs,"beta_lb") <- lower_bound[2]
  h5attr(group_gibbs,"rho_p_lb") <- lower_bound[3]
  h5attr(group_gibbs,"rho_c_lb") <- lower_bound[4]
  h5attr(group_gibbs,"alpha_ub") <- upper_bound[1]
  h5attr(group_gibbs,"beta_ub") <- upper_bound[2]
  h5attr(group_gibbs,"rho_p_ub") <- upper_bound[3]
  h5attr(group_gibbs,"rho_c_ub") <- upper_bound[4]
  
  ### Création des sous-groupes correspondant aux valeurs de k contenues dans k_values
  for (j in 1:length(k_values)) {
    ### Nom du sous-groupe
    sub_group <- group_gibbs$create_group(paste("k_",toString(k_values[j]),sep = ""))
    ### Attributs du sous-groupe
    h5attr(sub_group,"sample_size_k") <- as.integer(k_values[j])
    h5attr(sub_group,"mle_alpha") <- MLE[1,i,j]
    h5attr(sub_group,"mle_beta") <- MLE[2,i,j]
    h5attr(sub_group,"mle_rho_p") <- MLE[3,i,j]
    h5attr(sub_group,"mle_rho_c") <- MLE[4,i,j]
  }
  
  # Fermeture du fichier
  file.h5$close_all()
}

My problem is when I try to read the .h5 created by this code (with HDFView), there are any values in the dataset "times_c_i" and "types_u_i".

I think there is a problem in these lines :

  group_data[["times_c_i"]] <- data[,1,i]
  group_data[["types_u_i"]] <- as.integer(data[,2,i])

example of values ​​that the vector data[,1,i] can contain :

> data[,1,i]
  [1]  0.8258851  1.4898464  1.5000000  2.2605879  2.2640803  2.5020958
  [7]  2.5890448  2.7000000  3.2389167  3.7387764  3.8616307  3.9000000
 [13]  5.0574391  5.1000000  5.5981803  5.7282240  6.0622762  6.2323953
 [19]  6.3000000  7.0642759  7.1736511  7.4790911  7.5000000  7.8588190
 [25]  8.7000000  9.7152009  9.7590361  9.9000000 11.0669508 11.1000000
 [31] 11.4342187 11.6739783 11.8061122 12.0576542 12.0747612 12.3000000
 [37] 13.5000000 14.2537350 14.6131121 14.7000000 15.5930556 15.7290091
 [43] 15.9000000 16.0634172 16.0832570 16.6063925 16.6295700 16.7572605
 [49] 17.1000000 17.8266231 18.1570437 18.2567156 18.3000000 19.2852903
 [55] 19.5000000 20.0147245 20.2025478 20.2309070 20.7000000 21.9000000
 [61] 22.5268647 22.9415651 22.9722680 23.1000000 23.8449595 24.0401392
 [67] 24.3000000 24.6910140 24.8478986 25.0194589 25.3495213 25.5000000
 [73] 26.0714114 26.3702690 26.7000000 27.1796439 27.3564974 27.8096135
 [79] 27.9000000 28.2688860 28.7806835 28.8386886 29.1000000 29.5302013
 [85] 29.5626446 30.1781182 30.2806275 30.3000000 30.7949669 30.9330990
 [91] 31.3539911 31.5000000 31.6525604 32.5629835 32.6323252 32.7000000
 [97] 33.4804817 33.5906494 33.7808474 33.8894542 33.9000000 35.1000000
[103] 35.2496861 36.0144945 36.2139226 36.2586044 36.3000000 37.0093688
[109] 37.5000000 37.9781293 38.5489836 38.7000000 39.4395932 39.9000000
[115] 40.2809636 40.9169951 40.9988477 41.0928473 41.1000000 41.4778715
[121] 42.1073901 42.1857813 42.3000000 42.5890039 43.5000000 44.1142600
[127] 44.2597847 44.4114762 44.7000000 44.7730086 45.4129467 45.5549823
[133] 45.7732903 45.9000000 46.2135473 46.7031791 47.0522962 47.0787334
[139] 47.1000000 47.9857202 48.3000000 48.9580267 49.3381191 49.5000000
[145] 49.9298268 50.1820815 50.7000000 51.3875456 51.5819874 51.9000000
[151] 52.0563755 52.9369843 52.9955903 53.1000000 53.6208764 53.8511680
[157] 54.0002807 54.3000000 55.0548511 55.1746419 55.4733860 55.5000000
[163] 56.1192683 56.2573998 56.7000000 57.0713957 57.6645477 57.9000000
[169] 58.3843054 58.4384633 58.6346060 59.0447386 59.1000000 60.3000000
[175] 61.4390690 61.4984819 61.5000000 62.0637622 62.6003038 62.7000000
[181] 62.7503963 63.1205986 63.2177602 63.3156724 63.5037971 63.9000000
[187] 64.3017132 64.7739082 64.9553474 65.0965801 65.1000000 65.7972497
[193] 66.1872171 66.2049385 66.3000000 66.3877323 67.3929530 67.4351721
[199] 67.5000000 68.0738919

and a example of values ​​that the vector as.integer(data[,2,i]) can contain :

[```
1] 0 0 1 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 1 0 0 0 1 0 1 0 0 1 0 1 0 0 0 0
[35] 0 1 1 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 1 0 0 0 1 0 0 1 0
[69] 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1
[103] 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 0 0 0 1 0 0
[137] 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0
[171] 0 0 1 1 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 1 0


[the problem](https://i.sstatic.net/MdlUQYpB.png)

I want the first console output to be stored in the 'times_c_i' dataset, and the second console output to be stored in the 'types_u_i' dataset. However, currently, only these two datasets are empty, while everything else is functioning properly (so the issue is not related to the generation of the .h5 file)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant