Displaying 2 results from an estimated 2 matches for "create_pop_2".
2009 Apr 26
3
3 questions regarding matrix copy/shuffle/compares
Hello all,
I have the following function call to create a matrix of POP_SIZE rows
and fill it with bit strings of size LEN:
pop=create_pop_2(POP_SIZE, LEN)
I have 3 questions:
(1) If I did
keep_pop[1:POP_SIZE] == pop[1:POP_SIZE]
to keep a copy of the original data structure before manipulating
'pop' potentially, would this make a deep copy or just shallow? Ie
if I change something in 'pop' would i...
2010 Mar 11
2
Comparing matrices
...of the
data? I tried a few tests that seem to confirm this, but I'd
rather be sure.
------- code ------------
# create a binary vector of size "len"
create_bin_Chromosome <- function(len)
{
sample(0:1, len, replace=T)
}
# create popsize members, each of length len
create_pop_2 <- function(popsize, len)
{
datasize=len*popsize
npop <- matrix(0, popsize, len, byrow=T)
for(i in 1:popsize)
npop[i,] = create_bin_Chromosome(len)
npop
}
POP_SIZE = 3
LEN = 8
pop = create_pop_2(POP_SIZE, LEN)
pop2 = pop
print(pop==pop2)
if (pop==pop2) { cat('equal...