How can i apply a machine learning model to predict scatter plot data of a non linear 2D shape? - machine-learning

I created a dataset with mathlab, dataset has data for 5000 random non-linear 2D shapes with 100 known point each and their scatter plot.
Sheet imag has data for imaginary coordinates of nonlinear shapes, there're 100 points for each shape as columns.
Sheet real has data for real coordinates of nonlinear shapes, there're 100 points for each shape as columns.
Sheet x has data for x coordinates of scatter plots, there're 100 points for each shapes scatter plot as columns.
Sheet y has data for y coordinates of scatter plots, there're 100 points for each shapes scatter plot as columns.
Keep in mind that cell [i,j] of sheet imag and [i,j] of sheet real is the coordinate for i'th point of j'th shape, cell [i,j] of sheet x and cell [i,j] for sheet y is the coordinate for i'th point of j'th shape's scattered point.
For example real's [0,1] is -0,894608922831653, imag's [0,1] is -0,176637219642649, x's [0,1] is 1,00827206904887 is 0,987842977394785, y's [0,1] 0,0634351017253583; this means first shape's second point is (-0,894608922831653 -0,176637219642649j) and it's scattered to (1,00827206904887, 0,987842977394785)
I want to create a machine learning model to train with this dataset. Which method should i use and any tips on suggested method would be great.
I tried a regression model for start but results were way off, i was sort of expecting it because of complex numbers. I'm thinking about k nearest neighbor now but i'm open for everything.

Related

the histograms in Joint Plot

I want to plot a Scatterplot using joint plot where I am using Hue. But the KDE plots on the axes are not desired. Instead of those, I need to plot the histogram containing the aggregate count in the range of specific x and y. How can I do that?
In the above Image, instead of these kde plots, I need histogram plotted for aggregate number of count of points in that x and y range

I have a set of N deformed circles made of lines. How to generate similar circle?

I have a set of N deformed circles made of lines. Each circle can have difrent amount of lines defining it. They are deformed in difrent manner but one could see the similarities between them. How to generate a new similar circle having desired lines count K - which ML algorithms it is better to look into?
A circle that pass near of given vertices (in general case, it isn't possible to pass through all vertices) can be estimated with some maths. For example see here
An aproximation can be achieved by:
Get the coordinates of the centroid,
two simple (x,y) average.
The radius can be estimated by the average of the distances from vertices to the centroid.

Plot Camera Trajectory

Given a set of 4x4 pose matrices, one can derive the camera's euclidean coordinate system location as the following:
where R is the 3x3 rotation matrix and t is the translation vector of the pose, as per this question.
When the set of poses is treated in a sequential manner, such as when each refers to a camera's pose at some time step, the rotation and translation components can be accumulated as follows:
and
Where both can be plugged in to the first equation to yield the camera's relative position at a given time step.
My question is how to plot such points using OpenCV or a similar tool. For a camera moving around an object in a circular motion, the output plot should be circular, with the origin at the starting point of the trajectory.
An example is shown below:-
Though my question is not explicitly about plotting the axes as shown above, it would be a bonus.
TL;DR: Given a set of poses, how can we generate a plot like the one above with common tools such as OpenCV, VTK, Matplotlib, MATLAB etc.
obtain axises vectors X,Y,Z and position O for each plot point
simply extract them form matrix. See Understanding 4x4 homogenous transform matrices. Now I do not know if your matrices are already inverse or not. So if your matrices represent camera coordinate system (not inverted) extract needed info directly. If not first invert the matrix and then extract.
If you got homogenuous transform matrix then you can do pseudo inverse by exploiting transpose operation. For more info see full pseudo inverse matrix.
Render each plot point
so first plot the axises as lines:
red_line(O,O+a*X);
green_line(O,O+a*Y);
blue_line(O,O+a*Z);
where a is axis lines size. And after this plot a dot for the position
black_circle(O,r);
Where r is some radius. You can use any gfx lib/engine for the plot. I would go for GDI or OpenGL but that depends solely on what are you familiar with.
BTW. to improve avarenes of the time line you can modulate the colors intensity (start with dark and end with bright colors so you see where the motion starts and ends ...)

How do I reconstruct 3D points from rectified images at different horizontal and vertical positions?

I am familiar with reconstruction of 3D points from stereo rectified pairs. The equations for calculating coordinate estimates are:
Z = fB/D
X = uZ/f
Y = vZ/f
Where f = focal length, B = baseline, D = disparity, (u,v) are the 2D projected image coordinates.
Say I now have four cameras in a 2x2 grid. I have identified and matched fiducial markers in each image. I now want to estimate 3D point position from these projected points.
My question has two parts:
1) How does the triangulation equation change when images are not on the same horizontal baseline?
2) How do I derive an estimate from multiple pair-wise estimates?
What you are looking for is triangulation. A good starting point is to read the paper by Hartley and Sturm. There is a nice implementation in MATLAB's image processing toolbox, a number of googlable others out there, and, finally, it's not hard to write one's own on the basis of the abovementioned paper.

U-matrix and self organizing maps

I am trying to understand SOMs. I am confused about when people post images representing
the image of data gotten my using SOM to map data to the map space. It is said that the U-matrix is used. But we have a finite grid of neurons so how do you get a "continous" image ?
For example starting with a 40x40 grid there are 1600 neurons. Now compute U-matrix but how do you plot these numbers now to get visualization ?
Links:
SOM tutorial with visualization
SOM from Wikipedia
The U-matrix stands for unified distance and contains in each cell the euclidean distance (in the input space) between neighboring cells. Small values in this matrix mean that SOM nodes are close together in the input space, whereas larger values mean that SOM nodes are far apart, even if they are close in the output space. As such, the U-matrix can be seen as summary of the probability density function of the input matrix in a 2D space. Usually, those distance values are discretized, color-coded based on intensity and displayed as a kind of heatmap.
Quoting the Matlab SOM toolbox,
Compute and return the unified distance matrix of a SOM.
For example a case of 5x1 -sized map:
m(1) m(2) m(3) m(4) m(5)
where m(i) denotes one map unit. The u-matrix is a 9x1 vector:
u(1) u(1,2) u(2) u(2,3) u(3) u(3,4) u(4) u(4,5) u(5)
where u(i,j) is the distance between map units m(i) and m(j)
and u(k) is the mean (or minimum, maximum or median) of the
surrounding values, e.g. u(3) = (u(2,3) + u(3,4))/2.
Apart from the SOM toolbox, you may have a look at the kohonen R package (see help(plot.kohonen) and use type="dist.neighbours").

Resources