--please have a look at my third post in this thread! there I explained it more clearly--
Hey guys.
I posted a complex problem few days back. No reply! :|
Here is simplified question:
I have a matrix with 0/1:
I wanna randomize it 1000 times (or even more!) and have matrices with the same sum for each row and column as it is in input file.
This is probably not as easy as it sounds. You only have 0 and 1 as elements and a fixed number of 1s in every row and column as a further limiting factors. The number of possible permutations is well below 1000 - for a single 4-element field for example it is:
4 with 1 1-field
6 with 2 1-fields
4 with 3 1-fields
1 with 4 1-fields
This is probably solvable with the same sort of algorithm as the "8-queens-problem" (for which there are also only 96 distinct solutions and even of these 3/4 of them are axial- and/or mirror-symmetrical variants).
To solve this, you need to find
submatrices which you can permute so not to break your constant-row-and-col-sum side condition. I can see one single of these (on first sight):
in row 2 & 4, col 1 & 3. No chance for 1000 permutations...
@Rudic: The actual input data that I have is much bigger than this! It might be possible to have 1000 permutations.
Actually my worries is if it's possible to do this simulation and repeat it million times for instance. If it does not make sense I have no other choice rather than disregarding the similarity for sum of each rows and just check for similar sums for each column.
@bakunin: the difference between this problem and "8-queens-problem" is that first: in 8-queens there is just one position for each row and column to have value '1', but here it's more and varies. Second: Here we take those variants which are symmetrical or mirror as well since each column has different meaning.
What do you need? distinct eignevectors, eigenvalues, or columns && rows?
What kinds of matrix operations do you need to perform - more specifically what the heck are you trying to do? Please -NOT- how you think you should do it? We can see that, sort of.
Why did I say this? Because up to now this looks rather off-the-wall, i.e., squaring the circle. ...to be polite.
You are damn right Jim! I like how you described it... cool!!
I found an algorithm how to randomize my -rather complex to explain- data.
I explain it here:
Suppose I have the following input file:
First of all I would like to store it in a hash or 2 dimensional array which is like this:
As you can see the first column represents as many as headers that we had value '1' for them in input file. Second column is just a random number between 0-1.
Then we initiate an empty matrix with the same size as input file and start filling it with respect to previous table contained headers and random numbers.
The script should first sort the above table by the numbers (2nd column). therefore in each iteration we gonna have random order for headers in first column. Additionally, for each header a value '1' should be located in the corresponding column in our empty table.
to make sure that we don't make a mistake, each time that we take a header a value of 1 should be added to that row (in an additional third column). next time when we want to pick another header, we check the value in third column. If it was 1 we skip it since we know that it has been taken.
This goes repeatedly until the sum of the first row in our recently empty table turns equal to sum of the first row in input file. Then it goes to the second row and continue filling the rows until we have used all the headers.
Hi there, friends!
Writing exams again! This time my wish would be to randomize certain columns in a csv file. Given a file containing records consisting of 3 columns tab-separated:
A B C
A B C
A B C
I would love to get the columns of each record in random order...separated by a tab as... (12 Replies)
Hi,
I have a large file that looks like this:
@FCC189PACXX:2:1101:1420:2139/1
AGCGAGACTCCGTCTCAAAAAGAAAAAATTTTTCAAAATATTGCAATGGGCTTGTAATTTCTGCTTAAATGTCAGGAGGTCTGAGCCATT
+
bbbeeeceggggghiiiiiiiiiihfihihiiihhhghiihhihifhihiihhhhhhhhiiigfggggdceeeeebdcc^``bbcbccbb... (3 Replies)
Hi,
Is there a tool somewhat parallel to rev, but which randomizes instead of reverses?
I've tried rl, but I can only get it to randomize words.
I was hoping for something like this
echo "hello" | ran
leolh
less simpler solutions are also welcome.
Sorry if the question is... (21 Replies)
Hi everyone
I am very new at awk but think that that might be the best strategy for this. I have a matrix very similar to a correlation matrix and in practical terms I need to convert it into a list containing the values from the matrix (one value per line) with the first field of the line (row... (5 Replies)
I have the code below in C++ and am trying to understand what these do and how to call them.
template <class Type>
class Matrix {
public:
Matrix();
Matrix(
const int m,
const int n );
Matrix(
const Matrix& A );
~Matrix(); (0 Replies)
Hi all,
Is there a way to convert full data matrix to linearised left data matrix?
e.g full data matrix
Bh1 Bh2 Bh3 Bh4 Bh5 Bh6 Bh7
Bh1 0 0.241058 0.236129 0.244397 0.237479 0.240767 0.245245
Bh2 0.241058 0 0.240594 0.241931 0.241975 ... (8 Replies)
Hi All
I would like to merge multiple files with the same row and column size into a matrix format
In a folder I have multiple files in the following format
vi 12.txt
a 1
b 5
c 7
d 0
vi 45.txt
a 3
b 6
c 9
d 2
vi 9.txt
a 4 (7 Replies)