Question

Hello I have 2d matrix data saved in the ILArray < double >. This matrix represents the weights of the neural network from one neuron and i want to see how the weights looks with ilnumerics. Any idea how can i do this? I find many examples for 3d plotting but nothing for plotting 2d image data representation.

Was it helpful?

Solution

Image data are currently best (simplest) visualized by utilizing ILSurface. Since this is a 3D plot, you may not get the optimal performance for large image data. Fortunately, ILNumerics' scene graph makes it easy to improve this with your own implementation.

The most simple attempt would take an ILPoints shape, arrange the needed number of points in a grid and let every point visualize the value of the corresponding element within the input matrix - let's say by color (or size).

private void ilPanel1_Load(object sender, EventArgs e) {
    using (ILScope.Enter()) {
        // some 'input matrix'
        ILArray<float> Z = ILSpecialData.sincf(40, 50);
        // do some reordering: prepare vertices
        ILArray<float> Y = 1, X = ILMath.meshgrid(
                            ILMath.vec<float>(1, Z.S[1]), 
                            ILMath.vec<float>(1,Z.S[0]),
                            Y); 
        // reallocate the vertex positions matrix
        ILArray<float> pos = ILMath.zeros<float>(3, X.S.NumberOfElements); 
        // fill in values
        pos["0;:"] = X[":"]; 
        pos["1;:"] = Y[":"]; 
        pos["2;:"] = Z[":"]; 

        // colormap used to map the values to colors
        ILColormap cmap = new ILColormap(Colormaps.Hot);
        // setup the scene
        ilPanel1.Scene.Add(new ILPlotCube {
            new ILPoints() {
                Positions = pos, 
                Colors = cmap.Map(Z).T, 
                Color = null
            }
        }); 
    }
}

enter image description here

Obviously, the resulting points do not scale with the form. So the 'image' suffers from larger gaps between the points when the form size is increased. So, for a better implementation you may adapt the approach to utilize ILTriangles instead of ILPoints, in order to assemble adjacent rectangles.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top