09-09-2015 10:32 PM - edited 09-09-2015 10:45 PM
I need to create an N dimensional gaussian in labview.
Not a true analytical function, but just an N-dimensional array, where each element holds the value of the gaussian for a given i,j,k,... index.
I know the peak positions in each of the N dimensions, and the fwhm in each of the N dimensions. I know the equation for N-dimensional gaussian. In Matlab this is simple; in labview I have yet to figure out a way.
If N is a small number like 3 then we can just use 3 nested 'For' loops. Inside the center loop you evaluate the function using the three 'i' terminals of the three loops.
But what if N=128 as in my case? No longer so tractable.
I thought about using a while loop and incrementing an array of 128 counters (assuming the dimension size of each dimension is M, the 0th counter would increment every time; 1st counter would increment every M-th time, 2nd counter would increment every M*M-th time, etc), but I still couldn't figure out how to increment counters intelligently. Surely there is a simple way to evaluate f(i,j,k,...) of some analytical function??
I mentioned in Matlab this is simple -- Well if I could I'd just use a Matlab script box, generate f(i,j,k,...), and pass this to labview, except the Outputs of that box only allow passing 1- or 2-D variables.
Any ideas?
Thanks!
09-09-2015 11:11 PM
What is a 128 dimension array supposed to represent?
09-09-2015 11:24 PM
Anything you want. It's a general question. The question is: How do you make an N-dimensional array representing a function f(i,j,k,...)?
Gaussians can be 128 dimensional, no problem there.
The actual reason is the following: I have coded up some peak-search algorithms that act on 128 free parameters. The algo will eventually work on measured data. But as a test case for the algo, I want to first test it on a known function -- I chose a gaussian, but it doesn't matter as long as it has a peak. When I feed my peak-search function this N-dimensional gaussian it should climb to the top.
09-10-2015 09:24 AM
Maybe a simpler problem statement:
How do I make a 3D array holding a 3D gaussian, *without* using nested 'for' loops?
Then I can scale it to N dimensions.
09-10-2015 10:44 AM
@dnh37 wrote:
Gaussians can be 128 dimensional, no problem there.
Looks like you want to create some kind of hyper-cube with an array....?
It's quite possible you run out of memory, if your 3d Array cube with x=y=z gets bigger than 256
09-10-2015 11:40 AM - edited 09-10-2015 11:41 AM
I don't think it is possible to create an array of variable dimension in LabVIEW. However, I have written a permutation VI which you could use to create an index for each point of the n-dimensional function f.
This is something which I'm sure could (and probably has) been written far more efficiently by others.
09-10-2015 01:19 PM
I'm not sure I understand the problem. Certainly dealing with 128 dimensions would be difficult -- you'd probably want to have your indices as an array, but you'd still need something "messy" to deal with them. I just created a 6-D array of three elements each and (surprise!) it contained 3^6 = 729 elements. I don't want to calculate 3^128 ...
Do you really want to nest 128 For loops? Are you really working in a 128-dimensional space? Whew!
Bob Schor
09-14-2015 02:37 PM - edited 09-14-2015 02:38 PM
Okay what about this, could Variant Attributes be used? Lets say instead of having 128 dimensions in a single array, what if I had N arrays that are 2D in size? And then using the variant attribute I can set or get each of these 2D arrays using the index number as the key for the value? "[2][4][6][0]" would return a 2D array and "[2][4][6][1]" would return the next 2D array.
That way the data could be read and written in chunks. I think the total amount of memory used would be less, since now each dimension doesn't need to be the same in size as the previous. For instance reading one 2D array could be empty and the other may have 2 rows 3 columns, where normal arrays you can't do that.
Then when it comes to processing you can use a while loop, reading each 2D array, incrementing the key until all dimensions are processed. Still this is a terrible design, even if it could work, you probably shouldn't do this unless you have good reason.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
09-14-2015 03:15 PM
I think there is some ... confusion. Are you looking for an ARRAY of dimension size 128, or are you looking at a FUNCTION of 128 parameters.
Worded another way, is your resulting function a vector field? That is the only way I could see you needing a 128 dimensional array. Based on everything you said, I'm going to assume a function, in which case I think you only need a 2 dimensional array.
In the 2d array, column 0 = f(x0,x1,...,x[n-1],xn) | x1,x2,...,x[n-1],xn. Column 1 = x0, Column 2 = x1 ... and each row is some dX to build the functions.
Yes, it would be build with nested for loops, but only 3.
09-14-2015 04:58 PM
You can populate n dimensional function (below Y=x1^2+x2^2+...). Though you still need to connect 128 wires (index array-reshape array). Still scales better than multiple loops.
Intensity Graph is to view one slice.
There are 2 notes:
1) Above mentioned memory issues. 10 points to see gaussian in each of 128 dimensions, 10^128 array size. Nu-nu.
2) Labview wires have fixed data type. Changing array size means changing block diagram. So I would store N dimensional data in 1D array and write your own index array function. You just need to convert N indexi and N dimensions into "absolute" index. Like if you have 10*10*10 array and want to get element at (2, 1, 0) - least significant first, you need absolute index 11. This function approach is unversal and code will not change for different dimensions.