-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'data_exploration' of github.com:yoann-dufresne/rHashGen…
… into data_exploration
- Loading branch information
Showing
8 changed files
with
308 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
library(Rcpp) | ||
setwd("~/git/rHashGen/data_exploration") | ||
# Chargez le fichier C++ (remplacez le chemin par celui du fichier .cpp) | ||
sourceCpp("hash_functions_rcpp.cpp") | ||
# Exemple d'utilisation des fonctions | ||
val <- 12345 | ||
hashed_value <- hash_R(val) | ||
inverted_value <- inverted_hash_R(hashed_value) | ||
cat("Valeur hashée :", hashed_value, "\n") | ||
cat("Valeur inversée :", inverted_value, "\n") | ||
x <- "ATTAC" | ||
input <- "ATTACA" | ||
inpulist <- strsplit(input, "")[[1]] | ||
inpulist | ||
?switch | ||
i = 1 | ||
transfo <- function(input) { | ||
inpulist <- strsplit(input, "")[[1]] | ||
out <- rep(NA, length(inpulist)) | ||
for (i in seq_along(inpulist)) { | ||
charac.i <- inputlist[[i]] | ||
out[i] <- switch(charac.i, A = 0, T = 1, G = 2, C = 3) | ||
} | ||
return(out) | ||
} | ||
transfo(x) | ||
transfo <- function(input) { | ||
inputlist <- strsplit(input, "")[[1]] | ||
out <- rep(NA, length(inputlist)) | ||
for (i in seq_along(inputlist)) { | ||
charac.i <- inputlist[[i]] | ||
out[i] <- switch(charac.i, A = 0, T = 1, G = 2, C = 3) | ||
} | ||
return(out) | ||
} | ||
transfo(x) | ||
31/7 | ||
31/11 | ||
31/13 | ||
31/2 | ||
31/3 | ||
31/5 | ||
31/7 | ||
encode_nucl <- function(nucl) { | ||
return(switch(nucl, A = 0, T = 1, G = 2, C = 3)) | ||
} | ||
encode_kmer <- function(seq_k) { | ||
encoded_kmer <- 0 | ||
for (nucl in seq_k) { | ||
encoded_kmer <- encoded_kmer * 4 + encode_nucl(nucl) | ||
} | ||
return(encoded_kmer) | ||
} | ||
encode_kmer("GATTACA") | ||
encode_kmer <- function(seq_k) { | ||
seq_k <- unlist(strsplit(seq_k, "")[[1]]) | ||
encoded_kmer <- 0 | ||
for (nucl in seq_k) { | ||
encoded_kmer <- encoded_kmer * 4 + encode_nucl(nucl) | ||
} | ||
return(encoded_kmer) | ||
} | ||
encode_nucl <- function(nucl) { | ||
return(switch(nucl, "A" = 0, "T" = 1, "G" = 2, "C" = 3)) | ||
} | ||
encode_kmer <- function(seq_k) { | ||
seq_k <- unlist(strsplit(seq_k, "")[[1]]) | ||
encoded_kmer <- 0 | ||
for (nucl in seq_k) { | ||
encoded_kmer <- encoded_kmer * 4 + encode_nucl(nucl) | ||
} | ||
return(encoded_kmer) | ||
} | ||
encode_kmer("GATTACA") | ||
3 & 4 | ||
??bitwise | ||
bitAnd(3, 2) | ||
bitops::bitAnd(3, 2) | ||
encode_next_kmer <- function(prev_kmer, new_nucl, k) { | ||
encoded_kmer <- prev_kmer | ||
encoded_kmer <- bitwAnd(encoded_kmer, 4**(k-1) - 1) | ||
encoded_kmer <- encoded_kmer * 4 + encode_nucl(new_nucl) | ||
return(encoded_kmer) | ||
} | ||
enco_gattaca <- encode_kmer(seq_k = "GATTACA") | ||
encode_next_kmer <- function(prev_kmer, new_nucl, k) { | ||
encoded_kmer <- prev_kmer | ||
encoded_kmer <- bitwAnd(encoded_kmer, 4**(k-1) - 1) | ||
encoded_kmer <- encoded_kmer * 4 + encode_nucl(new_nucl) | ||
return(encoded_kmer) | ||
} | ||
encode_next_kmer(prev_kmer = enco_gattaca, new_nucl = "T", k = 7) | ||
??yield | ||
?yield | ||
??"flip one bit" | ||
flip_bit <- function(x, n) { | ||
# n is the bit position (0-based index) | ||
# bitwShiftL(1, n) creates a mask where only the nth bit is set to 1 | ||
# bitwXor flips that specific bit in x | ||
flipped_x <- bitwXor(x, bitwShiftL(1, n)) | ||
return(flipped_x) | ||
} | ||
# Let's flip the 2nd bit (0-based) of the number 5 (binary: 101) | ||
x <- 5 # binary: 101 | ||
n <- 1 # 0-based index, flip the 2nd bit (which is 1) | ||
flipped_x <- flip_bit(x, n) | ||
cat("Original number:", x, "\n") # Output: 5 | ||
cat("After flipping the 2nd bit:", flipped_x, "\n") # Output: 7 (binary: 111) | ||
# Let's flip the 2nd bit (0-based) of the number 5 (binary: 101) | ||
x <- 234 # binary: 101 | ||
n <- 4 # 0-based index, flip the 2nd bit (which is 1) | ||
flipped_x <- flip_bit(x, n) | ||
cat("Original number:", x, "\n") # Output: 5 | ||
cat("After flipping the 2nd bit:", flipped_x, "\n") # Output: 7 (binary: 111) | ||
bitwXor(345, flip_bit(345)) | ||
bitwXor(345, flip_bit(345, 3)) | ||
a <- 345 # entier intitial | ||
a <- 345 # entier intitial | ||
flipa3 <- flip_bit(345, 3) # entier flippé | ||
bitwXor(hash_R(a), hash_R(flipa3)) | ||
hash_R(a) | ||
hash_R(flipa3) | ||
which(lambda != 0) | ||
lambda <- c(NA, NA, 1, 0) | ||
which(lambda != 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,12 @@ | |
*.exe | ||
*.out | ||
*.app | ||
.Rproj.user | ||
|
||
# Rproj and Maceries | ||
.DS_Store | ||
*.Rproj* | ||
**/.Rproj* | ||
|
||
# build | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//Hash function | ||
template <typename myuint> | ||
myuint hash(myuint val) | ||
{ | ||
val *= 9; | ||
val ^= val << 17; | ||
val ^= val << 5; | ||
val += val << 19; | ||
val &= 0x7fffffff; | ||
val ^= val >> 3; | ||
val *= 9; | ||
val &= 0x7fffffff; | ||
return val; | ||
} | ||
|
||
//Inverted function: | ||
template <typename myuint> | ||
myuint inverted_hash(myuint val) | ||
{ | ||
val *= 954437177; | ||
val &= 0x7fffffff; | ||
val ^= val >> 3; | ||
val ^= val >> 6; | ||
val ^= val >> 12; | ||
val ^= val >> 24; | ||
val *= 2146959361; | ||
val ^= val << 5; | ||
val ^= val << 10; | ||
val ^= val << 20; | ||
val ^= val << 17; | ||
val &= 0x7fffffff; | ||
val *= 954437177; | ||
val &= 0x7fffffff; | ||
return val; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <Rcpp.h> | ||
#include <cstdint> // pour uint32_t | ||
|
||
// Hash function | ||
uint32_t hash(uint32_t val) { | ||
val *= 9; | ||
val ^= val << 17; | ||
val ^= val << 5; | ||
val += val << 19; | ||
val &= 0x7fffffff; | ||
val ^= val >> 3; | ||
val *= 9; | ||
val &= 0x7fffffff; | ||
return val; | ||
} | ||
|
||
// Inverted hash function | ||
uint32_t inverted_hash(uint32_t val) { | ||
val *= 954437177; | ||
val &= 0x7fffffff; | ||
val ^= val >> 3; | ||
val ^= val >> 6; | ||
val ^= val >> 12; | ||
val ^= val >> 24; | ||
val *= 2146959361; | ||
val ^= val << 5; | ||
val ^= val << 10; | ||
val ^= val << 20; | ||
val ^= val << 17; | ||
val &= 0x7fffffff; | ||
val *= 954437177; | ||
val &= 0x7fffffff; | ||
return val; | ||
} | ||
|
||
// Expose the functions to R using Rcpp | ||
// [[Rcpp::export]] | ||
uint32_t hash_R(uint32_t val) { | ||
return hash(val); | ||
} | ||
|
||
// [[Rcpp::export]] | ||
uint32_t inverted_hash_R(uint32_t val) { | ||
return inverted_hash(val); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
library(Rcpp) | ||
|
||
# Chargez le fichier C++ (remplacez le chemin par celui du fichier .cpp) | ||
sourceCpp("hash_functions_rcpp.cpp") | ||
|
||
# Exemple d'utilisation des fonctions | ||
val <- 12345 | ||
|
||
hashed_value <- hash_R(val) | ||
inverted_value <- inverted_hash_R(hashed_value) | ||
|
||
cat("Valeur hashée :", hashed_value, "\n") | ||
cat("Valeur inversée :", inverted_value, "\n") | ||
|
||
|
||
x <- "ATTACA" | ||
|
||
babytransfo <- function(input) { | ||
inputlist <- strsplit(input, "")[[1]] | ||
out <- rep(NA, length(inputlist)) | ||
for (i in seq_along(inputlist)) { | ||
charac.i <- inputlist[[i]] | ||
out[i] <- switch(charac.i, A = 0, T = 1, G = 2, C = 3) | ||
} | ||
return(out) | ||
} | ||
|
||
encode_nucl <- function(nucl) { | ||
return(switch(nucl, "A" = 0, "T" = 1, "G" = 2, "C" = 3)) | ||
} | ||
|
||
encode_kmer <- function(seq_k) { | ||
seq_k <- unlist(strsplit(seq_k, "")[[1]]) | ||
encoded_kmer <- 0 | ||
for (nucl in seq_k) { | ||
encoded_kmer <- encoded_kmer * 4 + encode_nucl(nucl) | ||
} | ||
return(encoded_kmer) | ||
} | ||
|
||
enco_gattaca <- encode_kmer(seq_k = "GATTACA") | ||
|
||
encode_next_kmer <- function(prev_kmer, new_nucl, k) { | ||
encoded_kmer <- prev_kmer | ||
encoded_kmer <- bitwAnd(encoded_kmer, 4**(k-1) - 1) | ||
encoded_kmer <- encoded_kmer * 4 + encode_nucl(new_nucl) | ||
return(encoded_kmer) | ||
} | ||
|
||
encode_next_kmer( | ||
prev_kmer = enco_gattaca, | ||
new_nucl = "T", | ||
k = 7) | ||
|
||
|
||
flip_bit <- function(x, n) { | ||
# n is the bit position (0-based index) | ||
# bitwShiftL(1, n) creates a mask where only the nth bit is set to 1 | ||
# bitwXor flips that specific bit in x | ||
flipped_x <- bitwXor(x, bitwShiftL(1, n)) | ||
return(flipped_x) | ||
} | ||
|
||
|
||
# Let's flip the 2nd bit (0-based) of the number 5 (binary: 101) | ||
x <- 234 # binary: 101 | ||
n <- 4 # 0-based index, flip the 2nd bit (which is 1) | ||
flipped_x <- flip_bit(x, n) | ||
|
||
cat("Original number:", x, "\n") # Output: 5 | ||
cat("After flipping the 2nd bit:", flipped_x, "\n") # Output: 7 (binary: 111) | ||
|
||
a <- 345 # entier intitial | ||
flipa3 <- flip_bit(345, 3) # entier flippé | ||
|
||
bitwXor(hash_R(a), hash_R(flipa3)) | ||
|
||
# La matrice individuelle correspond au lien | ||
# entre un entier hashé (hasha), et le même entier | ||
# flippé hashé (hashaflippé). Ligne à ligne, pour chaque | ||
# bit de hasha, on met un 1 là où ce bit | ||
# correspond à un bit de hashaflippé. | ||
|
||
# But de l'opération : pour tous les a possibles, | ||
# créer les matrices de lien avec tous les hashaflippés | ||
# possible et en déduire si les hashaflippés sont bien | ||
# les plus éloignés possibles du hasha. | ||
|
||
|
||
|
||
|
Submodule paradiseo
updated
25 files
+0 −5 | eo/src/eo | |
+5 −5 | eo/src/eoEvalUserTimeThrowException.h | |
+1 −1 | eo/src/eoExceptions.h | |
+1 −4 | eo/src/eoInt.h | |
+0 −74 | eo/src/eoRealToIntInit.h | |
+0 −73 | eo/src/eoRealToIntMonOp.h | |
+0 −94 | eo/src/eoRealToIntQuadOp.h | |
+0 −1 | eo/src/es/eoReal.h | |
+5 −11 | eo/src/utils/eoGnuplot.cpp | |
+2 −4 | eo/src/utils/eoParallel.cpp | |
+0 −2 | eo/src/utils/eoParallel.h | |
+2 −3 | eo/src/utils/selectors.h | |
+0 −2 | eo/test/CMakeLists.txt | |
+9 −9 | eo/test/t-eoAlgoFoundryFastGA.cpp | |
+0 −28 | eo/test/t-eoRealToIntMonOp.cpp | |
+0 −35 | eo/test/t-eoRealToIntQuadOp.cpp | |
+1 −1 | eo/test/t-forge-FastGA.cpp | |
+0 −14 | mo/src/algo/moSA.h | |
+1 −4 | mo/src/mo.h | |
+0 −218 | mo/src/problems/partition/moBinaryPartition.h | |
+0 −223 | mo/src/problems/partition/moBinaryPartitionSwapNeighbor.h | |
+0 −157 | mo/src/problems/partition/moBinaryPartitionSwapNeighborhood.h | |
+0 −1 | mo/test/CMakeLists.txt | |
+0 −88 | mo/test/t-moBinaryPartition.cpp | |
+10 −9 | moeo/src/archive/moeoSPEA2Archive.h |