SceneKit transform values, how are they implemented? - ios

Apple's SceneKit documentation suggests that the transform matrix of an object consists of rotation, position, and scale information. However the transform matrix is a 4x4 matrix, the last column being 0,0,0,1. What are these values exactly and is there a more detailed explanation to this matrix? Like which columns/rows represent what, why is there 4 rows and what is the last column for?
Example code:
for t in 0...3 {
print("\t")
for n in frame.camera.transform[t] {
print(String(format: "%10.1f", n),terminator: "");
}
}
Output:
0.1 -0.7 0.7 0.0
1.0 0.2 -0.1 0.0
-0.1 0.7 0.7 0.0
0.3 -0.1 0.0 1.0

I'm pretty sure this is the CATransform3D:
https://developer.apple.com/documentation/quartzcore/catransform3d
Which is some of the most asinine "documentation" in the history of Apple's notoriously asinine documentation.
Try this, from the wayback machine, when they used to at least talk about things a little more deeply... somewhat: https://web.archive.org/web/20111010140734/http://developer.apple.com/library/mac/#/web/20111012014313/https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/Layers.html
m34 is the most interesting of the entire matrix, as it's usually referred to as being responsible for perspective.
And here's one of the best articles ever written about Core Animation, that explains some aspects of this transform: http://www.thinkandbuild.it/introduction-to-3d-drawing-in-core-animation-part-1/

Related

Why does the Normalization cause different output value?

Why does the Normalization cause different output value?
My program : https://i.imgur.com/rlHqMw9.png
After Normalization, 4.0 becomes 0.8
After Normalization, another 4.0 becomes 1.00
After Normalization, 0.0 has become 0.00
After Normalization, another 0.0 becomes 0.000000
As evident from your image, in mvr1 the precision of 0.75 is more than that of 0.0; hence the precision of the latter is changed to match the precision of all values.

How to well simulate friction between two surfaces on gazebo?

I'm currently working on a project that needs a bit of friction to run the real environment.
But, and it's why i'm here, I have problems.
I'm trying to put a stick on a pad, and I want them to be a bit sticky together, and have some friction between them before the stick falls off.
I precise that i'm new to Gazebo, and i'm open to all of your advices.
Here is the example, were the green pad surface has a friction of mu and mu2 around 10000 (for testing), same for the sphere.
I tried to change the visual and collision geometry to see if the problem came from here, without effect.
There is three frames to illustrate the slipperiness of these surface:
Straight on pad
Begin to fall
Completely out
I performed some tests to understand the differents parameters (such as mu and mu2 here).
The ramp has these parameters for the first test :
mu : 100
mu2: 50
The ramp has these parameters for the second test :
mu : 0.0
mu2: 0.0
I think that these parameters vary between 0 and 1, but when I create a world, the ground has these values.
In each case, cylinders have, in the order, these parameters :
mu : 0.0
mu2: 0.0
mu : 0.1
m2 : 0.1
mu : 0.3
mu2: 0.3
mu : 0.5
mu2: 0.5
mu : 0.8
mu2: 0.8
mu : 1.0
mu2: 1.0
Here, the picture of the first test, when cylinders roll on the ramp :
Test1
Here, the 2 pictures of the second test, the first one shows the cylinders rolling down the ramp, and the second one shows what happens after, on the ground :
Test2_1
Test2_2
In the idea, the result will show that the first cylinder will roll slower than the second one, the second one slower than the third and so one and so one.
However, this is not happened.
These examples show that the lower mu is taken between two object, but why, for the first test, there is no difference for the cylinders between 3 and 6 ?
Plus, how to simulate the friction for my real application ?
I thank you in advance !
Have a nice day !

Determine transformation "kinds" from transformation matrix (reversing)

I'm wondering if I can determine in OpenCV the transformation kinds (rotation, translation, shear, ...) just from a given transformation matrix?
Following up on this article: http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.html
I will get an 2x3 Transformation matrix. E.g.:
[ 0.85, 0.20, 0;
-0.06, 0.37, 253.44]
I know that the third "column" stands for the translation. So in this case x=0, y=253.44
But is there a way of determine if in the first two columns only a rotation or a rotation and a scaling is applied? So what I mean is get the matrix multiplication somehow reversed?
This isn't possible in general. For example, consider the affine transformation:
cos(theta) sin(theta) 0
-sin(theta) cos(theta) 0
If theta = pi, then this evaluates to
-1 0 0
0 -1 0
Is this affine transformation scaling by -1, or rotating by 180 degrees?
Affine transformations can indeed be written as a composition of multiple transformations, but as matrix multiplication is not commutative, the order of these compositions matter. And that even goes for translation. The resulting transformation matrix is different if you rotate and then translate than if you translate and rotate, because rotation happens around the (0, 0) location in your image.
In short, there is no unique decomposition. If you know certain constraints, like scaling is uniform, or shearing is uniform, or the scaling is only positive, etc, then you might be able to get a unique decomposition. See here for the mathematics.

Handling zero rows/columns in covariance matrix during em-algorithm

I tried to implement GMMs but I have a few problems during the em-algorithm.
Let's say I've got 3D Samples (stat1, stat2, stat3) which I use to train the GMMs.
One of my training sets for one of the GMMs has in nearly every sample a "0" for stat1. During training I get really small Numbers (like "1.4456539880060609E-124") in the first row and column of the covariance matrix which leads in the next iteration of the EM-Algorithm to 0.0 in the first row and column.
I get something like this:
0.0 0.0 0.0
0.0 5.0 6.0
0.0 2.0 1.0
I need the inverse covariance matrix to calculate the density but since one column is zero I can't do this.
I thought about falling back to the old covariance matrix (and mean) or to replace every 0 with a really small number.
Or is there a another simple solution to this problem?
Simply your data lies in degenerated subspace of your actual input space, and GMM is not well suited in most generic form for such setting. THe problem is that empirical covariance estimator that you use simply fail for such data (as you said - you cannot inverse it). What you usually do? You chenge covariance estimator to the constrained/regularized ones, which contain:
Constant-based shrinking, thus instead of using Sigma = Cov(X) you do Sigma = Cov(X) + eps * I, where eps is prefedefined small constant, and I is identity matrix. Consequently you never have a zero values on the diagonal, and it is easy to prove that for reasonable epsilon, this will be inversible
Nicely fitted shrinking, like Oracle Covariance Estimator or Ledoit-Wolf Covariance Estimator which find best epsilon based on the data itself.
Constrain your gaussians to for example spherical family, thus N(m, sigma I), where sigma = avg_i( cov( X[:, i] ) is the mean covariance per dimension. This limits you to spherical gaussians, and also solves the above issue
There are many more solutions possible, but all based on the same thing - chenge covariance estimator in such a way, that you have a guarantee of invertability.

Meaning of Histogram on Tensorboard

I am working on Google Tensorboard, and I'm feeling confused about the meaning of Histogram Plot. I read the tutorial, but it seems unclear to me. I really appreciate if anyone could help me figure out the meaning of each axis for Tensorboard Histogram Plot.
Sample histogram from TensorBoard
I came across this question earlier, while also seeking information on how to interpret the histogram plots in TensorBoard. For me, the answer came from experiments of plotting known distributions.
So, the conventional normal distribution with mean = 0 and sigma = 1 can be produced in TensorFlow with the following code:
import tensorflow as tf
cwd = "test_logs"
W1 = tf.Variable(tf.random_normal([200, 10], stddev=1.0))
W2 = tf.Variable(tf.random_normal([200, 10], stddev=0.13))
w1_hist = tf.summary.histogram("weights-stdev_1.0", W1)
w2_hist = tf.summary.histogram("weights-stdev_0.13", W2)
summary_op = tf.summary.merge_all()
init = tf.initialize_all_variables()
sess = tf.Session()
writer = tf.summary.FileWriter(cwd, session.graph)
sess.run(init)
for i in range(2):
writer.add_summary(sess.run(summary_op),i)
writer.flush()
writer.close()
sess.close()
Here is what the result looks like:
.
The horizontal axis represents time steps.
The plot is a contour plot and has contour lines at the vertical axis values of -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, and 1.5.
Since the plot represents a normal distribution with mean = 0 and sigma = 1 (and remember that sigma means standard deviation), the contour line at 0 represents the mean value of the samples.
The area between the contour lines at -0.5 and +0.5 represent the area under a normal distribution curve captured within +/- 0.5 standard deviations from the mean, suggesting that it is 38.3% of the sampling.
The area between the contour lines at -1.0 and +1.0 represent the area under a normal distribution curve captured within +/- 1.0 standard deviations from the mean, suggesting that it is 68.3% of the sampling.
The area between the contour lines at -1.5 and +1-.5 represent the area under a normal distribution curve captured within +/- 1.5 standard deviations from the mean, suggesting that it is 86.6% of the sampling.
The palest region extends a little beyond +/- 4.0 standard deviations from the mean, and only about 60 per 1,000,000 samples will be outside of this range.
While Wikipedia has a very thorough explanation, you can get the most relevant nuggets here.
Actual histogram plots will show several things. The plot regions will grow and shrink in vertical width as the variation of the monitored values increases or decreases. The plots may also shift up or down as the mean of the monitored values increases or decreases.
(You may have noted that the code actually produces a second histogram with a standard deviation of 0.13. I did this to clear up any confusion between the plot contour lines and the vertical axis tick marks.)
#marc_alain, you're a star for making such a simple script for TB, which are hard to find.
To add to what he said the histograms showing 1,2,3 sigma of the distribution of weights. which is equivalent to the 68th,95th, and 98th percentiles. So think if you're model has 784 weights, the histogram shows how the values of those weights change with training.
These histograms are probably not that interesting for shallow models, you could imagine that with deep networks, weights in high layers might take a while to grow because of the logistic function being saturated. Of course I'm just mindlessly parroting this paper by Glorot and Bengio, in which they study the weights distribution through training and show how the logistic function is saturated for the higher layers for quite a while.
When plotting histograms, we put the bin limits on the x-axis and the count on the y-axis. However, the whole point of histogram is to show how a tensor changes over times. Hence, as you may have already guessed, the depth axis (z-axis) containing the numbers 100 and 300, shows the epoch numbers.
The default histogram mode is Offset mode. Here the histogram for each epoch is offset in the z-axis by a certain value (to fit all epochs in the graph). This is like seeing all histograms places one after the other, from one corner of the ceiling of the room (from the mid point of the front ceiling edge to be precise).
In the Overlay mode, the z-axis is collapsed, and the histograms become transparent, so you can move and hover over to highlight the one corresponding to a particular epoch. This is more like the front view of the Offset mode, with only outlines of histograms.
As explained in the documentation here:
tf.summary.histogram
takes an arbitrarily sized and shaped Tensor, and compresses it into a
histogram data structure consisting of many bins with widths and
counts. For example, let's say we want to organize the numbers [0.5,
1.1, 1.3, 2.2, 2.9, 2.99] into bins. We could make three bins:
a bin containing everything from 0 to 1 (it would contain one element, 0.5),
a bin containing everything from 1-2 (it would contain two elements, 1.1 and 1.3),
a bin containing everything from 2-3 (it would contain three elements: 2.2, 2.9 and 2.99).
TensorFlow uses a similar approach to create bins, but unlike in our
example, it doesn't create integer bins. For large, sparse datasets,
that might result in many thousands of bins. Instead, the bins are
exponentially distributed, with many bins close to 0 and comparatively
few bins for very large numbers. However, visualizing
exponentially-distributed bins is tricky; if height is used to encode
count, then wider bins take more space, even if they have the same
number of elements. Conversely, encoding count in the area makes
height comparisons impossible. Instead, the histograms resample the
data into uniform bins. This can lead to unfortunate artifacts in
some cases.
Please read the documentation further to get the full knowledge of plots displayed in the histogram tab.
Roufan,
The histogram plot allows you to plot variables from your graph.
w1 = tf.Variable(tf.zeros([1]),name="a",trainable=True)
tf.histogram_summary("firstLayerWeight",w1)
For the example above the vertical axis would have the units of my w1 variable. The horizontal axis would have units of the step which I think is captured here:
summary_str = sess.run(summary_op, feed_dict=feed_dict)
summary_writer.add_summary(summary_str, **step**)
It may be useful to see this on how to make summaries for the tensorboard.
Don
Each line on the chart represents a percentile in the distribution over the data: for example, the bottom line shows how the minimum value has changed over time, and the line in the middle shows how the median has changed. Reading from top to bottom, the lines have the following meaning: [maximum, 93%, 84%, 69%, 50%, 31%, 16%, 7%, minimum]
These percentiles can also be viewed as standard deviation boundaries on a normal distribution: [maximum, μ+1.5σ, μ+σ, μ+0.5σ, μ, μ-0.5σ, μ-σ, μ-1.5σ, minimum] so that the colored regions, read from inside to outside, have widths [σ, 2σ, 3σ] respectively.

Resources