Arrays
Posted: Fri Aug 13, 2010 11:45 am
Hi all,
I'm trying to write a program that simulates a theory of memory and I've run into some problems. Up till now I've been able to get by with repeat loops and if statements, but the magnitude of the data I'm dealing with means that one run of my simulation would take 70 hours or so, which is way too long for my purposes. I think I need to use arrays!
There are two problems I have, so I'll split these into two sections
1) Creating the arrays.
At the moment I have a variable that creates a number of lines populated with 1s and -1s. So imagine I want to have 3 lines that look like this:
1, -1, 1, 1
1, 1, -1, 1
1, -1, 1, 1
At the moment I simply define the parameters for the number of lines and the number of items in each line, then generate the numbers randomly. So in this case I've got 3 lines with 4 items in each. Having randomly generated these 3 lines, I then append a non-random sequence of numbers onto the end, lets say -1, -1 in this case. So I end up with 3 lines with 6 items each. How do I convert this to an array? I tried to use but because all the entries are either 1 or -1, this didn't work.
2) Analysing the arrays
In my simulation I will have two arrays - lets call them the memory array and the word array. The memory array will in practice be quite big - around 1000-2000 lines, whilst the word array will be around 120 lines. Each line in the memory array will be a series of 1s, 0s and -1s. So if the memory array was 5 lines it might look like:
1, 0, 1, 1, 0, -1
1, 1, 0, 1, -1, -1
1, -1, 0, 1, -1, 0
1, -1, 0, 1, -1, 0
1, -1, 0, 1, -1, 0
The word array will consist of 1s, and -1s and each line will be of the same length as the lines in the memory array (so if each line in the memory array has 6 items as here, then so will each line in the word array). What I need to do is the following steps:
i) Take the first line of the word array
ii) Take the first line of the memory array
iii) Multiply each item in the word line sequence by it's companion item in memory line sequence. So if the first line of the word array is 1, 1, 1 and the first line of the memory array is -1, 0, 1 then I want to do three multiplications: 1*-1, 1*0 and 1*1.
iv) Add up these values (lets call this tMatches)
v) Divide tMatches by the number of non-zero entries in the memory line sequence
vi) Add this number to a running total (lets call this tIntensity)
vii) Take the second line of the memory array, perform the same process with the first line of the word array, and then add this to the tIntensity running value
viii) Once the first line of the word array has been compared to all lines of the memory array, the current value of tIntensity is written to a file (I can do this bit!) and tIntensity is reset
ix) Take the second line of the word array and the first line of the memory array and do the whole process again
So in other words the first line of the word array will be compared to all lines of the memory array, then the second line of the word array will be compared to all lines of the memory array and so on until I have a tIntensity value for each line in the word array.
Any help on this would be very much appreciated. I've tried programming this using repeat loops, and predictably the whole thing is just way too slow due to the size of the memory array. I've tried looking in the help files and tutorials about arrays, but I can't find what I'm looking for there. Even a prod towards the right things to read would be appreciated - I've read everything I can find in the manual and online tutorials about arrays and I can't even figure out how to make the array in the first place let alone start on the array comparisons!
Sorry for the long post.
I'm trying to write a program that simulates a theory of memory and I've run into some problems. Up till now I've been able to get by with repeat loops and if statements, but the magnitude of the data I'm dealing with means that one run of my simulation would take 70 hours or so, which is way too long for my purposes. I think I need to use arrays!
There are two problems I have, so I'll split these into two sections
1) Creating the arrays.
At the moment I have a variable that creates a number of lines populated with 1s and -1s. So imagine I want to have 3 lines that look like this:
1, -1, 1, 1
1, 1, -1, 1
1, -1, 1, 1
At the moment I simply define the parameters for the number of lines and the number of items in each line, then generate the numbers randomly. So in this case I've got 3 lines with 4 items in each. Having randomly generated these 3 lines, I then append a non-random sequence of numbers onto the end, lets say -1, -1 in this case. So I end up with 3 lines with 6 items each. How do I convert this to an array? I tried to use
Code: Select all
split gNumberVar by comma and return
2) Analysing the arrays
In my simulation I will have two arrays - lets call them the memory array and the word array. The memory array will in practice be quite big - around 1000-2000 lines, whilst the word array will be around 120 lines. Each line in the memory array will be a series of 1s, 0s and -1s. So if the memory array was 5 lines it might look like:
1, 0, 1, 1, 0, -1
1, 1, 0, 1, -1, -1
1, -1, 0, 1, -1, 0
1, -1, 0, 1, -1, 0
1, -1, 0, 1, -1, 0
The word array will consist of 1s, and -1s and each line will be of the same length as the lines in the memory array (so if each line in the memory array has 6 items as here, then so will each line in the word array). What I need to do is the following steps:
i) Take the first line of the word array
ii) Take the first line of the memory array
iii) Multiply each item in the word line sequence by it's companion item in memory line sequence. So if the first line of the word array is 1, 1, 1 and the first line of the memory array is -1, 0, 1 then I want to do three multiplications: 1*-1, 1*0 and 1*1.
iv) Add up these values (lets call this tMatches)
v) Divide tMatches by the number of non-zero entries in the memory line sequence
vi) Add this number to a running total (lets call this tIntensity)
vii) Take the second line of the memory array, perform the same process with the first line of the word array, and then add this to the tIntensity running value
viii) Once the first line of the word array has been compared to all lines of the memory array, the current value of tIntensity is written to a file (I can do this bit!) and tIntensity is reset
ix) Take the second line of the word array and the first line of the memory array and do the whole process again
So in other words the first line of the word array will be compared to all lines of the memory array, then the second line of the word array will be compared to all lines of the memory array and so on until I have a tIntensity value for each line in the word array.
Any help on this would be very much appreciated. I've tried programming this using repeat loops, and predictably the whole thing is just way too slow due to the size of the memory array. I've tried looking in the help files and tutorials about arrays, but I can't find what I'm looking for there. Even a prod towards the right things to read would be appreciated - I've read everything I can find in the manual and online tutorials about arrays and I can't even figure out how to make the array in the first place let alone start on the array comparisons!
Sorry for the long post.