How can I get my data (Pandas Dataframe) to align properly in my Flet (Python) app output?

Question: So I'm building a data entry app for shop floor operators (manufacturing) to use so they can log inventory tags that are entered into our main inventory system.  Users enter the requested data and the program appends the data to a CSV file.  The CSV file is connected to Excel to provide the supervisor with a real-time view of tags entered.  However, I also want to provide a view of entered tags so that the user has a list built within the app.  To do this, I'm using Pandas to re-import the CSV into the app and display the X number of tags entered.  If I print the variable with the pandas dataframe assigned, the data is nicely organized into columns and rows (with header) in my VS Code terminal.
The problem: even though the data displays in my app, the data isn't really organized (aligned) in nice even columns. Is there something I'm not doing or am doing wrong?  If needed, I can provide code...but one should be familiar with Flet.
Thank you!!
Answer: visualizing a pandas dataframe usually works better with the display built-in function rather than print, but without any code it's hard to see if that would help here. Another option might be to get it created as an image first and then displayed.


Absolute value of Brownian motion

Question: I need to show that $$R_t=\frac{1}{|B_t|}$$ is bounded in $\mathcal{L^2}$ for $(t \ge 1)$, where $B_t$ is a 3-dimensional standard Brownian motion.
I am trying to find a bound for $\mathbb{E}[\int_{t=1}^{\infty}R^2_t]$.
Asymptotically $B_t^i$ is between $\sqrt{t}$ and $t$. I also know that $|B_t| \to \infty$, but the rate is not clear.
Hints would be helpful.
Answer: Since $B_t$ and $\sqrt{t}B_1$ are identically distributed, $\mathrm E(R_t^2)=t^{-1}\mathrm E(R_1^2)$, hence $\mathrm E(R_t^2)\leqslant\mathrm E(R_1^2)$ for every $t\geqslant1$ and it remains to show that $\mathrm E(R_1^2)$ is finite. Now, the density of the distribution of $B_1$ is proportional to $\mathrm e^{-\|x\|^2/2}$ and $B_1$ has dimension $3$ hence the density of the distribution of $Y=\|B_1\|$ is proportional to $\varphi(y)=y^{3-1}\mathrm e^{-y^2/2}=y^2\mathrm e^{-y^2/2}$ on $y\gt0$. Since the function $y\mapsto y^{-2}\varphi(y)=\mathrm e^{-y^2/2}$ is Lebesgue integrable, the random variable $Y^{-2}=R_1^2$ is integrable.
On the other hand, $\mathrm E\left(\int\limits_1^{+\infty}R_t^2\mathrm dt\right)$ is infinite.
Edit The distribution of $B_1$ yields the distribution of $Y=\|B_1\|$ by the usual change of variables technique. To see this, note that in dimension $n$ and for every test function $u$,
$$
\mathrm E(u(Y))\propto\int_{\mathbb R^n} u(\|x\|)\mathrm e^{-\|x\|^2/2}\mathrm dx\propto\int_0^{+\infty}\int_{S^{n-1}}u(y)\mathrm e^{-y^2/2}y^{n-1}\mathrm d\sigma_{n-1}(\theta)\mathrm dy,
$$
where $\sigma_{n-1}$ denotes the uniform distribution on the unit sphere $S^{n-1}$ and $(y,\theta)\mapsto y^{n-1}$ is proportional to the Jacobian of the transformation $x\mapsto(y,\theta)$ from $\mathbb R^n\setminus\{0\}$ to $\mathbb R_+^*\times S^{n-1}$. Hence,
$$
\mathrm E(u(Y))\propto\int_0^{+\infty}u(y)y^{n-1}\mathrm e^{-y^2/2}\mathrm dy,
$$
which proves by identification that the distribution of $Y$ has a density proportional to $y^{n-1}\mathrm e^{-y^2/2}$ on $y\gt0$.
Comment: These are sometimes called [hyperspherical coordinates](http://en.wikipedia.org/wiki/Hypersphere#Hyperspherical_coordinates). // Yes, the post shows $E(R_t^2)$ is finite and how to compute its value, and shows that $\int E(R_t^2)dt=E(\int R_t^2dt)$ is infinite.
Comment: Firstly I should note that I was asked about $\mathcal{L}^2(\Omega,\mathbb{P})$ as opposed to $\mathcal{L}^2(\Omega \times\mathbb{R},\mathbb{P\times\lambda})$.
Could you expand on how you calculated density of $BES_0(3)=Y$ process?
Comment: *I was asked about $\mathcal{L}^2(\Omega,\mathbb{P})$ as opposed to $\mathcal{L}^2(\Omega \times\mathbb{R},\mathbb{P\times\lambda})$*... ??
Comment: Thank you very much for you incredible input. I am still trying to figure out the transformation. Didn't see $d\sigma$ before. By $\mathcal{L}^2$ I meant to say that you calculated $\mathbb{E}[R_t^2]$, I was doing $\mathbb{E}[\int{R_t^2dt}]$.
Comment: I'd love see a proper answer to the true question conserning the bound to $\mathbb{B} \left\{\int_1 ^{\infty} R_s^2ds \right \}$
Comment: @Paul What do you call *a proper answer* about a bound on a quantity which happens to be infinite?

Absolute value of Brownian motion


Como verificar o uso de memória no Visual Studio?

Question: Estou há pouco tempo desenvolvendo um projeto asp.net mvc 5.
Quando eu chamo uma view (uma página), a memória RAM esgota pra 0MB. Aí o PC ferra.
Quando a memória RAM  volta para normal, ele mostra página view.
Alguém pode me dizer se um Visual Studio existe essa ferramenta para detectar o consumo de memória, ver quem faz ele esgotar memória.
Answer: O Visual Studio tem uma janela específica para diagnósticos chamada Diagnostic Tools. Que entre outras funções de monitoramento, mostra a quantidade de memória utilizada pela aplicação.
Sempre que você executa seu projeto pressionando F5, ela deve aparecer automaticamente.
Você também pode fazê-la surgir acessando Debug > Windows > Show Diagnostic Tools ou pressionando Ctrl + Alt + F2


Projective Space v.s. Quotient Space v.s. Fibration

Question: What are the more precise relations between (a) projective space, (b) quotient space and (c) the base manifold under certain fibration?

(1) Can every projective space (e.g. $\mathbb{RP}^n$, $\mathbb{CP}^n$, $\mathbb{HP}^n$, and many others) can be constructed as a quotient space?

(In some cases, there are the quotient space of spheres over spheres. Say $\mathbb{RP}^n=S^{n}/\mathbb{Z}_2$, $\mathbb{CP}^n=S^{2n+1}/S^1$, $\mathbb{HP}^n=S^{4n+3}/Sp(1)=S^{4n+3}/S^3$, yes?)

(2) Can every quotient space can be constructed as a projective space?
(3) It looks that (b) and (c) all involve a relation of modding out or quotient out certain space (e.g. the fiber for the later case (c)). How are (b) and (c) related, or are they exactly the same? Or which one is more general?
Comment: what is your definition of a projective space, quotient space, and fibration?
Comment: [this](https://math.stackexchange.com/questions/100173/real-projective-space-the-quotient-map-and-covering-projection?rq=1) might help
Comment: @ Andres Mejia, mine is based on the Wikipedia one unfortunately, due to my ignorance -- but maybe experts have better way to define them --- this is also implicitly part of the question
Comment: Well, I mean: what would it mean for every quotient to be constructed as a topological space? You could quotient the real numbers by the rational numbers if you wanted to. I just don't really understand. In select cases, certain quotients are fiber bundles. It seems that the question should be: what is a projective space, and how is it related to quotient spaces and fiber bundles.
Comment: That is fine - if you can answer that - that will help - in a general ground .
Comment: Be careful, normally in a quotient space $X / Y$ you just collapse $Y$ to a single point.  However, in a fiber bundle you individually collapse every fiber, not just a single fiber, in the total space to a point to get the base space.
Comment: @JHF, thanks - this is a nice comment. Can we be furthermore explicit?
Answer:
There aren't that many other projective spaces other than the ones you've already listed.  Some people might also include the "octonionic projective plane" (which can be constructed as a quotient space) and its generalizations, but this might not be conventional depending on the setting.  Of course, you can also easily define projective spaces over any field (and if you know some algebraic geometry, over any commutative ring) using the same quotient definition.
Unless I'm misunderstanding you, this question doesn't really make sense.  Every nonempty space is a quotient space (e.g., take $X / \{x\}$ for $x \in X$).
In a fiber bundle $F \to E \xrightarrow{p} B$, say with $p$ surjective, $B$ can be identified with the quotient $E/\sim$, where $\sim$ is the equivalence relation $x \sim y$ if $p(x) = p(y)$.  In fact, this is true for any onto map $p$, but in the case of a fiber bundle, each equivalence class is equipped with a topology that makes it homeomorphic to $F$.

The point I was trying to make in the comments is most easily seen in the case of topological groups.  Let $H$ be a subgroup of $G$, and consider the expression $G / H$.  If one thinks purely topologically, then by definition this is the space $G$ with just the identity coset $H \subseteq G$ collapsed to a point.  However, what most people mean by $G / H$ is to collapse every coset of $H$ in $G$ to a point, so that $G / H$ is the space of cosets of $H$.   The "quotient" in a fiber bundle is more like the latter and not the former.
Comment: thanks JHF - this helps +1


Probability of distributions

Question: A particular question says the average body temperature is 98.2F with standard deviation of 0.7 with normal distribution, allowing us to find probability with z-tables.
However, an additional question asks that if 10 people were selected at random (independent of each other) and X represents the number of people who have body temperatures exceeding 98.6F. What is the probability that at least 2 people have temperatures that exceed 98.6F?
Would this distribution still be Normal, as the parameters of mean and SD still apply, or is it binomial? As there is a fixed amount of trials and success/failure as limits. But then the parameters for n and p, what would be p?
Answer: Given the normal distribution, $N(98.2, 0.7^2)$, the probability of someone having temp higher than 98.6 is $\hat{p}=1-\Phi(\frac{98.6-98.2}{0.7})= 0.2838546$.
Sample size is $n=10$ and the probability of at least two people having higher temp is: $P = 1 - P(X=0) - P(X=1)$, where $X$ is distributed as Binomial$(n,\hat{p})$. Thus, $P = 1 - (1-\hat{p})^{10} - 10 \hat{p}(1-\hat{p})^{9} = 0.8238783.$
Comment: The OP question states that the average is $98.2$ while the threshold of interest is $98.6$, so this is an unfair coin.
Comment: Oops, I didn't notice, thanks. Will fix presently...
Comment: I dont blame you.  My mom has always told me the average is $98.6$, i.e. my mom disagrees with the premise of this question.  :)
Comment: Moms are usually right :)
Comment: Thanks. I understand the first steps, but I thought the formula for binomial distributions was n Choose x, so how does that work?
Comment: So, what's n-choose-zero and n-choose-1?
Comment: Oh yeh I see. He skipped that step and went straight to the numbers. Haha. So to calculate p you use the normal formula X - mean/SD. And even though its a sample you don't divide 0.7 by the square root of 10?
Comment: Yes, use the parameters of the normal to calculate $\hat{p}$ and then use binomial with parameters $n$ and $\hat{p}$ to get final probabilities.
Comment: I seem to get 0.4285 for p-hat though
Comment: All the details are spelled out in the solution -- compare your steps with these.
Answer: Hint: You need to use both the Normal and the Binomial in different parts of the computation.

Probability of distributions


Commerce Product Display or just Views Display of line items?

Question: I will be presenting the products in one view and don't need the display nodes as they wont be seen.
Do I have to create display nodes for each product or can I just use views to display the line items in a table for example?
Is there any catch with doing this?
Answer: You can't see products because the permission to see products is disabled by default.
Just enable it at /admin/people/permissions. E.g. enable View any product of any type if you want to permit users to see directly entities.
But also have a look at the module Inline entity form. you can edit both node display and attached product entities in one form.
Comment: ofcourse you can use only products entities. It's up to you
Comment: thanks for the comment but I don't want to show or hide the product displays. I want to know if I have to create the product displays at all or can I just use the products in a Views table?
Comment: but the disadvantage of using products entities that you don't have page with full information of single product from the box
Comment: Can you clarify "you don't have page with full information of single product from the box"

Is there any other disadvantage to not having separate display pages for each product, reporting etc?
Comment: on my opinion there are no more disadvantages


calculation of Kendall-Theil-Sen intercept

Question: There are two approaches for estimating the Kendall-Theil-Sen intercept b0.
Approach 1
β0 = Median{yi - β1*xi : 1 ≤ i ≤ n}
Approach 2
β0 = Y_median - β1*X_median
where X_median is the median of the x values and
Y_median is the median of the y values
Given Dataset
x   8   26  29  30  32  34  35  36  37  39
y   33  15  26  16  20  32  21  30  29  35
I get the slope 5/6 now using the slope I will calculate the possible intercepts
β0 = 33 - 5/6(8) = 79/3
β0 = 15 - 5/6(26) = -20/3
β0 = 26 - 5/6(29) = 11/6
β0 = 16 - 5/6(30) = -9
β0 = 20 - 5/6(32) = -20/3
β0 = 32 - 5/6(34) = 11/3
β0 = 21 - 5/6(35) = -49/6
β0 = 30 - 5/6(36) = 0
β0 = 29 - 5/6(37) = -11/6
β0 = 35 - 5/6(39) = 5/2
Arranging all these values in ascending order
-9, -49/6, -20/3, -20/3, -11/6, 0, 11/6,  5/2,  11/3,  79/3
Since n = 10 which is even hence
Median= (5^th term + 6^th term)/2 = ((-11/6) + 0) / 2 = -11/12
However the intercept is given as -20/3 so clearly there is something wrong with the calculations but I cant seem to find it. Need Help!
Also if I use method 2 the median of x is 33 and the median of y is 27.5 therefore
β0 = 27.5 - 5/6(33) = 0
which clearly does not match with approach 1 value which is the real answer
Comment: How do you know -20/3 is "the real answer"?  Don't trust what people tell you.  Plot the data and the two lines and judge for yourself which solutions make sense.
Comment: please click on the link. This example was taken from this journal. https://dergipark.org.tr/en/download/article-file/1986084
Comment: Even peer-reviewed journal articles contain errors.
Comment: There's an infinite number of approaches to choosing an intercept to go with a Theil-Sen slope, though perhaps 3 are relatively common; several more have perfectly sensible justifications. [Both](https://i.stack.imgur.com/N9pRU.png) of the intercept estimates you mention seem to offer pretty sensible fits to these data, though one might ponder if a linear fit makes the best choice of model.
Comment: Dietz lists ten possibilities for intercepts here: http://web.archive.org/web/20190705013611/https://www.stat.ncsu.edu/information/library/mimeo.archive/ISMS_1987_1690R.pdf though naturally that's not exhaustive
Answer: RStudio says you were correct, the intercept is indeed -11/12:
<code>> library("RobustLinearReg")
> x = c(8 ,26 ,29 ,30 ,32 ,34 ,35 ,36 ,37 ,39)
> y = c(33 ,15 ,26 ,16 ,20 ,32 ,21 ,30 ,29 ,35)
> theil_sen_regression(y ~ x)$coefficients
(Intercept)           x
 -0.9166667   0.8333333
</code>
Comment: Please tell us also (as an eit to the post) from which R package is `theil_sen_regression`.  U usefull way to tell it is in the code use `PACKAGE_NAME::theil_sen_regression`
Comment: @kjetilbhalvorsen Sure.
Comment: can you provide the link of the RStudio compiler you used to get these answers
Comment: RStudio had nothing to do with this calculation, which was performed by `R`.  See https://cran.r-project.org/.


Joomla: Problems when migrating from PHP 5.2 to 5.3

Question: My hoster will stop supporting PHP 5.2 in a few weeks, which is why I have to switch to PHP 5.3. I'm using Joomla 2.5 to manage the content of a site. In the backend of the hoster, I switched to the new PHP version with the click of a button, but that made the site crash with the error below.
Apparently, my code is not ready for PHP 5.3. How can I update the joomla code to the new PHP? Or should joomla handle the new PHP version without a problem and something I added actually causes the error? The only code that is from me is the template that loads a custom design.
I'm kind of stuck here and don't really see the connection between joomla, PHP and also how the hoster backend new that I was using an old PHP. Any suggestions whould be appreciated....

The error. Note: this is copied from another site, I loaded a backup to fix the error on my site, but apart from the paths it was exactly the same:
jos-Error: Application Instantiation Error

JFactory :: getApplication() @ /home/parolevo/public_html/tiptopart/index.php:28
JApplication :: getInstance() @ /home/parolevo/public_html/tiptopart/libraries/joomla/factory.php:102
JSite -> __construct() @ /home/parolevo/public_html/tiptopart/libraries/joomla/application/application.php:208
JApplication -> __construct() @ /home/parolevo/public_html/tiptopart/includes/application.php:48
JApplication -> _createSession() @ /home/parolevo/public_html/tiptopart/libraries/joomla/application/application.php:173
JFactory :: getSession() @ /home/parolevo/public_html/tiptopart/libraries/joomla/application/application.php:1046
JFactory :: createSession() @ /home/parolevo/public_html/tiptopart/libraries/joomla/factory.php:152
JSession :: getInstance() @ /home/parolevo/public_html/tiptopart/libraries/joomla/factory.php:661
JSession -> __construct() @ /home/parolevo/public_html/tiptopart/libraries/joomla/session/session.php:155
JSession -> _start() @ /home/parolevo/public_html/tiptopart/libraries/joomla/session/session.php:118
session_start() @ /home/parolevo/public_html/tiptopart/libraries/joomla/session/session.php:492
JSessionStorageDatabase -> read()
JFactory :: getDbo() @ /home/parolevo/public_html/tiptopart/libraries/joomla/session/storage/database.php:67
JFactory :: createDbo() @ /home/parolevo/public_html/tiptopart/libraries/joomla/factory.php:308
JError :: raiseError() @ /home/parolevo/public_html/tiptopart/libraries/joomla/factory.php:723
JError :: raise() @ /home/parolevo/public_html/tiptopart/libraries/joomla/error/error.php:251
JError :: throwError() @ /home/parolevo/public_html/tiptopart/libraries/joomla/error/error.php:176
call_user_func_array() @ /home/parolevo/public_html/tiptopart/libraries/joomla/error/error.php:214
JError :: handleMessage()
JFactory :: getApplication() @ /home/parolevo/public_html/tiptopart/libraries/joomla/error/error.php:705
JError :: raiseError() @ /home/parolevo/public_html/tiptopart/libraries/joomla/factory.php:99
JError :: raise() @ /home/parolevo/public_html/tiptopart/libraries/joomla/error/error.php:251

Answer: As you can see from the technical requirements page for Joomla! version 2.5 recommends PHP 5.3.
I can also confirm that all of our (+ client) 2.5 sites run on PHP 5.3 without problem so, the only conclusion is that it's something you've added to the base install or changed in the core Joomla! code.
Looking at the error log isn't very helpful but I can tell you that it's appears to be having a problem connecting to the database. I would check your configuration.php file for possible issues - confirm that the database & connection type settings are correct.
Comment: It actually was the configuration file! Thanks so much... What I did was to let the hoster back-end create a fresh joomla installation for me, and from there I copied the parts in the configuration file that were different in mine. I'm not entierly sure what was wrong, but now it works.


Scaling iframes for responsive design CSS-only

Question: A lot of sites have embedded Youtube videos. Youtube works on phones now. If responsive design is going to be a thing, why shouldn't it be a thing for iframes that contain Youtube videos?
After searching for days (on and off) I couldn't find a clear, simple solution to the problem (I'm new to HTML/CSS). It's easy to scale iframe width, but to keep height relative I found chunks of javascript, jQuery, and php, all pretty esoteric to a beginner at web design. I wanted a simple method of scaling an iframe's height to always keep a certain aspect ratio, no matter how the width changes.
To keep this from being an unanswered question, the method's below. Here are the initial settings for your iframe:

That's it.
I was wondering if anyone had any other solutions as well.
Comment: See also [this post](http://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php)
Comment: possible duplicate of [Shrink a Youtube video to responsive width](http://stackoverflow.com/questions/15844500/shrink-a-youtube-video-to-responsive-width)
Comment: Now I feel stupid for not having found those when I needed them.
Answer: The solution was nested divs. A little hackey, I know, but it's a really easy solution to a problem that had too many solutions. Youtube videos keep an aspect ratio of 16:9 in this example. Your HTML should look like this:

And your stylesheet:
#outer{
max-width: 640px;
max-height: 360px;
width: 100%;
height: 100%;
}

#inner{
    height: 0px;
    padding-bottom: 56.25%;
}

#inner iframe{
    width: 100%;
    height: 100%;
}

The outer div sets the maximum height and width and allows itself to scale, while the inner div uses the padding attribute to match its height to the width of the containing div (I'm pretty sure). The value should be set at (height*100/width)%, the ratio of the height to the width. The iframe then stretches to fill the whole containing div. Whitespace fills on web, so you should be just fine putting text underneath.
I can't remember exactly where I found it. It was done with images somewhere else on Stack Overflow, but I think it's relevant to have it set up to work for iframes since embedded Youtube videos are so common.
Here's a JSfiddle with the working thing.
Comment: You need to set the inner division to have a relative position and the iframe to have an absolute position to get it to work.
Also if you add the margin of zero for the top and bottom and auto for the left and right to the outer division it will centre it.
Comment: Richard Young is correct, see this article to fill in the gaps.

https://stackoverflow.com/questions/25302836/responsive-video-iframes-keeping-aspect-ratio-with-only-css
Answer: With the introduction of the aspect-ratio property in CSS, you don't need any clever workarounds, wrappers, or JS.
iframe {
    aspect-ratio: 16 / 9;
    height: auto;
    width: 100%;
}

The property already has excellent support across browsers making it suitable for the majority of sites: https://caniuse.com/mdn-css_properties_aspect-ratio
Working Example


Sus Chords - Whole Step Or Half?

Question: Is the fourth in a sus4 chord always a whole step away from the third? Or is it based on what diatonic note is next in the scale?
Example:
In the key of C major:
Dm sus4 = D G A
It is a whole step resolution from G to F
But, what about a chord that has a half step diatonic fourth near the third?
C sus4 = C F G
It is only a half step resolution from F to E
Which begs the question, what would a sus4 chord mean if you were playing the whole tone scale, or perhaps the blues scale?
(After looking at this, I don't understand what the difference is from a F 6/4 and a Csus4).
Comment: Csus4 is C F G. Which is the difference between that and F 6/4 because that's still C F A.
Comment: @ToddWilcox I seem to always spell things wrong. :( edited
Answer: Despite the votes on this question (and answers so far), I don't believe anyone has actually answered the question:

Which begs the question, what would a sus4 chord mean if you were playing the whole tone scale, or perhaps the blues scale?

First, we have to understand what a suspension is:
Suspensions have three parts:

Preparation - introduces a non-chord tone
Suspension - sustains that non-chord tone (often through a harmonic change)
Resolution - resolves the non-chord tone to a chord tone (almost always downward by step)

In the example, we begin with an Em6/4 (second-inversion), but on beat 4 the E moves to F, a note that does not fit in an E minor triad. The new note is sustained through a harmonic change (it still does not fit into this new chord), and then finally resolves downward by step to a chord tone. In this case, it happens to be a C major triad.
So, back to the question, What would a sus4 chord mean if you were playing the whole tone scale, or perhaps the blues scale?
Well, using suspension predicate the idea of tension and release. You create tension by moving from a chord tone to a non-chord tone, changing the chord, and then bringing it back.
Blues is a predominately tonal musical genre, and like most genres, is not rigid. Midnight Waltz by Cedar Walton, is a 24-bar blues in 3/4 that makes extensive use of suspensions. In this context, suspensions (4-3 suspension) is used as an Upper Neighbor Tone that prolongs the larger harmonic regions forward, creating a sense of movement:

In music that uses whole-tone elements, you would need to handle it differently. The whole tone scale is by its own invention and purpose, non-functional, harmonically speaking. Suspensions, as we have established, serve a harmonic function. So, in order to use a harmonic-functioning device in a predominately non-functional context, you would have to manufacture the impression of harmonic function. Otherwise, the effect is meaningless. The answer to that question, is for another time.
So, to summarize, as another stack user said quite succinctly:

"An argument can be made that any sus chord that satisfies these theoretical elements is valid. In the blues context, both a half step above the third and a whole step above the third could theoretically achieve this. Midnight Waltz provides an example where a whole step is used. Other examples probably exist where a half step is used." - jdjazz
Comment: I think this is an outstanding answer that could be improved with one small addition to summarily answer the Q. Maybe something like: "An argument can be made that any sus chord that satisfies these theoretical elements is valid. In the blues context, both a half step above the third and a whole step above the third could theoretically achieve this. Midnight Waltz provides an example where a whole step is used. Other examples probably exist where a half step is used." I'm sure Brad Mehldau has resolved a major third to a minor third in a blues context, but I'll have to dig to find an example.
Comment: Regarding whole tone, I think what you're saying is that the whole tone chord isn't supposed to sound resolved in the first place, & the chord tones themselves are designed to produce the tension one would hope to achieve from a sus chord. I think an argument can be made that if a song establishes a whole tone chord in the listener's ear, then you can now create a sus sound for that whole tone chord. For ex: resolving `G Db♭ E♭` to `G B E♭` or even `G Db♭ F` to `G B E♭`. I don't hear the same effect from `G C E♭` to `G B E♭` because this sounds like a i-V (e.g., Cmin – G7alt).
Comment: @jdjazz Wonderful, thanks for the comment! (If you like, then please upvote!) :)

I'm going to leave your comment / my answer as-is so that people can see your comment. If I were to edit my answer, I would just copy/paste your words as they are succinct and descriptive.
Comment: If you think my comment as is would be a nice addition, I say go for it and edit it into your answer. On other stackexchange sites, I know comments are periodically deleted/meant to be temporary. Your answer gave me a way to think about how one might successfully produce a whole tone sus sound, which is really cool. Thanks! (On a separate note, this is a great example of why music theory has value!)
Comment: @jdjazz With whole-tone scales, the point is to emphasize all notes equally. This thinking is inherently non-functional, harmonically speaking. Functional harmony establishes a hierarchy of pitch-importance. Music incorporating whole-tone scales achieves tension and resolution through other means, like texture, density, orchestration, and rhythm, for example.
Comment: Ah, I see. Thanks for the clarification. That makes perfect sense.
Answer: For starters, C F A cannot be a sus: it's F major in second inversion! Whole tone and blues scales don't use the same 'rules' as diatonics - they can't, due to their make-up.
Sus chords, be they 2 or 4, are in one way like 'power chords'. They have lost the defining third, making them neither major nor minor. The fact that the sus 4 note is a semitone away from that 3rd in major but a tone from it in minor is beside the point. It is the 4th note, hence sus 4, in a way replacing that third, which will usually be returned sooner rather than later. So, writing a sus as Dsus4 or Dm sus4 becomes somewhat academic.
Answer: The 'sus' note is a semitone above the major 3rd, a tone above the minor 3rd.  Which one will you resolve it to?  Or will you just leave it there?  Your choice!
F 6/4 is a second inversion F chord.  C, F, A.   Csus is C, F, G.
Comment: Csus*4* is C F G. Csus*2* is C D G. Csus doesn't really exist as such. And - C F G can also be Fsus 2, and C D G can also be Gsus4.
Comment: I've seen plenty of music where "sus" with no numeral is assumed by the publisher/engraver to be understood as sus4.

Sus Chords - Whole Step Or Half?


How do I read this chart about a FIFA World Cup game from Google?

Question: Throughout the World Cup the Google Doodle has been FIFA themed, and clicking it takes you to a search for the latest game. Today it's United States vs Portugal.
The search brings up a chart which appears to be a summary of the game. It looks like it should be obvious what everything means but I can't make heads or tails of it.
Is this a standard football (soccer) game chart?
If so, how is it meant to be read?
Is there a key available?
Full chart reproduced below in case Google results change.
Answer: The timeline shows the major events in the match.
I will try to explain by using few events as shown in your example timeline.
The number in bracket always indicates the respective player's jersey number.

5'  Nani (#17) 0 – 1 Portugal: a goal was scored by Nani for Portugal.
16' Portugal made a subtitution, in which Hélder Postiga (#23) was replaced by Éder (#11).
46' Portugal made a subtitution, in which André Almeida (#19) was replaced by William (#6).
64' Jermaine Jones (#13) United States 1 – 1: a goal was scored by Jermaine Jones for USA.
75' Jermaine Jones (#13) gets a yellow card (see the color of the card shown)
90+1' First minute of stoppage time, USA makes a substitution.
90+5' Fifth minute of stoppage time --> a second goal was scored by Silvestre Varela (#18) for Portugal.

There is additional time allotted after the standard 90 minutes are over.
Please refer to this question.
The rest of the timeline can be read using the above examples.
I believe this is a pretty standard timeline chart for a football match.
Comment: That helps but there are still questions. In the timeline, what does "90 + 1'" mean? What is the boxed event with Jermaine Jones at 75'? And is this a standard way to chart a soccer game or is it something Google just made up?
Comment: @Robert the boxed events are just because of the videos.


update attribute for property element in hibernate

Question: The property element of Hibernate has attributes update, insert and as per documentation it states that - http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/mapping.html#mapping-declaration-property

update, insert (optional - defaults to true): specifies that the
  mapped columns should be included in SQL UPDATE and/or INSERT
  statements. Setting both to false allows a pure "derived" property
  whose value is initialized from some other property that maps to the
  same column(s), or by a trigger or other application.

Please help me in understanding how it behaves if its value is set as 'false' instead of 'true'. What is the derived property here?
Answer: You can see the difference in an example - if you create an entity and persist it using default insert settings, all fields that the entity has set will be persisted, and you will see in Hibernate log the expected generated insert SQL statement. Something like:
Hibernate: insert into SCHEMA1.User (id, firstName, lastName) values (default, ?, ?)

But if you set insert for some property to false, even if the field has value in the entity, the generated SQL will have the appropriate column excluded, so the value for it won't be persisted. If the firstName has insert set to false, the generated SQL is:
Hibernate: insert into SCHEMA1.User (id, lastName) values (default, ?)

This will work if firstName is nullable, and fail otherwise.
The described principle also applies to update.
Setting these attributes to false makes sense in the case mentioned in docs, where you deal with a derived (calculated) property that you do not persist. It is in fact a read-only property with value computed at fetch time (computation is declared as an SQL expression which translates to a SELECT subquery). You can check this post for an example and links for more information about derived properties.


Find if $\sum_{n=1}^\infty \frac{(-1)^n}{n(2+(-1)^n)}$ converges

Question: Find if the following series is convergent or divergent, justify.
$$\sum_{n=1}^\infty  \frac{(-1)^n}{n(2+(-1)^n)}$$
My first idea was to use absolute convergence to get rid of both $(-1)^n$, take $1/2$ out to be left with the harmonic series but I don't think the absolute value will get rid of the $(-1)^n$ in the denominator.
Where do I go from there?
Comment: yes. Are you suggesting that the alternating series test is the way to go? Figured it wouldn't work since it isn't decreasing.
Comment: Is it alternating? i.e. does the sign alternate?
Comment: Hmm yeah. Maybe you can try combining two consecutive terms and looking at that expression
Comment: Does this answer your question? [How can I show whether the series $\sum\limits_{n=1}^\infty \frac{(-1)^n}{n(2+(-1)^n)} $ converges or diverges?](https://math.stackexchange.com/questions/402900/how-can-i-show-whether-the-series-sum-limits-n-1-infty-frac-1nn2)
Answer: Since
\begin{align}
\sum_{n=1}^\infty  \frac{(-1)^n}{n(2+(-1)^n)} &= \sum_{n=1}^{\infty} \frac{(-1)^n (2 - (-1)^n)}{n \, (2 + (-1)^{n})(2 - (-1)^n)} \\
&= \frac{1}{3} \, \sum_{n=1}^{\infty} \left( \frac{2 \, (-1)^n}{n} - \frac{1}{n} \right) \\
&= - \frac{2}{3} \, \ln(2) - \lim_{n \to \infty} H_{n},
\end{align}
where $H_{n}$ is the Harmonic number. Since the Harmonic number diverges as $n \to \infty$ then the series diverges.
Answer: Hint: Writing out the first few terms, we get
$$-\frac{1}{1}+\frac{1}{6}-\frac{1}{3}+\frac{1}{12}-\frac{1}{5}+\frac{1}{18}-\frac{1}{7}+\frac{1}{24}-...$$
Can you find a comparison to use to simplify the relations between the terms to show that the negative terms are "too large" for the series to converge?
Answer: The terms go to zero
and the sum of the
first $2m$ terms is
$\begin{array}\\
\sum_{n=1}^{2m}  \frac{(-1)^n}{n(2+(-1)^n)}
&=\sum_{n=1}^{m}  \left(\frac{(-1)^{2n-1}}{(2n-1)(2+(-1)^{2n-1})}+\frac{(-1)^{2n}}{(2n)(2+(-1)^{2n})}\right)\\
&=\sum_{n=1}^{m}  \left(\frac{-1}{(2n-1)(2-1)}+\frac{1}{(2n)(2+1)}\right)\\
&=\sum_{n=1}^{m}  \left(\frac{-1}{2n-1}+\frac{1}{6n}\right)\\
&=\sum_{n=1}^{m}  \left(\frac{(-6n)+(2n-1)}{(2n-1)(6n)}\right)\\
&=-\sum_{n=1}^{m}  \frac{4n+1}{(2n-1)(6n)}\\
\end{array}
$
and the sum of this diverges since
$\frac{4n+1}{(2n-1)(6n)}
\gt \frac{4n}{(2n)(6n)}
= \frac{1}{3n}
$.


Override buildForm() in another module

Question: I would like to override the buildForm() method of the Comment module in my custom module.
The method is defined in core/modules/comment/src/Form/CommentAdminOverview.php.
To achieve this, I've created myModuleName/src/Form/MyModuleNameCommentAdminOverview.php, whose first lines are the following.
namespace Drupal\myModuleName\Form;

use Drupal\comment\CommentInterface;
use Drupal\comment\Form\CommentAdminOverview;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\user\PrivateTempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;

class myModuleNameCommentAdminOverview  extends CommentAdminOverview {
  public function buildForm(array $form, FormStateInterface $form_state, $type = 'new') {
    // ...
  }
}

In myModuleName.info.yml I have these lines.
 dependencies:
  - comment:comment

My code is not working. What am I doing wrong?
I have read the following, but I don't understand what I'm doing wrong.

Need to override single Drupal 8 plugin function
Override or extend function of a contributed module
Overriding the function of a module in another module
Answer: These are the two routes for the original form class:
comment.routing.yml:
comment.admin:
  path: '/admin/content/comment'
  defaults:
    _title: 'Comments'
    _form: '\Drupal\comment\Form\CommentAdminOverview'
    type: 'new'
  requirements:
    _permission: 'administer comments'

comment.admin_approval:
  path: '/admin/content/comment/approval'
  defaults:
    _title: 'Unapproved comments'
    _form: '\Drupal\comment\Form\CommentAdminOverview'
    type: 'approval'
  requirements:
    _permission: 'administer comments'

You have to alter both routes like this
  protected function alterRoutes(RouteCollection $collection) {
    if ($route = $collection->get('comment.admin')) {
      $route->setDefault('_form', '\Drupal\mymodule\Form\MyForm');
    }
  }

in a RouteSubscriber.
Comment: Just run the command myself and found out, that in D8.4 a view has replaced this route. So if you want that your code runs, you have to disable this view, see https://www.drupal.org/node/2898013
Comment: Many thanks by your answer. The problem persists. alterRoute() is called and It's works but my buildform() method hasn't been called.
Comment: What you should check first is the router table, you can use the module Devel (/devel/routes) or Drupal Console: `drupal debug:router comment.admin`

Override buildForm() in another module


mysql my.cnf for a 50GB of RAM server

Question: I am having load problems on my database server (dual quad core 50 GB RAM)
load average: 4.26, 6.78, 11.25
here is the current my.cnf, can i optimize it?
<code>[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
    basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
language        = /usr/share/mysql/english
skip-external-locking

key_buffer              = 150M
key_buffer_size = 512M
max_allowed_packet      = 16M
thread_stack            = 128K
thread_cache_size       = 128
open-files              = 8192

myisam-recover          = BACKUP
max_connections        = 1000
table_cache            = 8096
join_buffer_size        = 2M
tmp_table_size          = 10G
max_heap_table_size     = 10G
innodb_buffer_pool_size = 10G
innodb_additional_mem_pool_size = 128M
innodb_log_file_size = 100M
log-slow-queries        = /var/log/mysql/slow.log
sort_buffer_size        = 5M
net_buffer_length       = 5M
read_buffer_size        = 2M
read_rnd_buffer_size    = 12M
thread_concurrency     = 16
ft_max_word_len = 30
ft_min_word_len = 2

query_cache_limit       = 4M
query_cache_size        = 512M
</code>
The website has about 2000 users online.
Answer: Use mysqltuner.pl: http://mysqltuner.pl/mysqltuner.pl http://blog.mysqltuner.com/

mysql my.cnf for a 50GB of RAM server


Gerar números aleatórios em Python sem repetir

Question: Tenho a seguinte situação:
Possuo um vetor com 4 índices. Em cada índice é gerado um valor aleatório de 0 até 100.
Possuo um código que faz isso perfeitamente, porém, as vezes os números se repetem.
Abaixo o código:

from random import randint

AP_X = [randint(0, 100), randint(0, 100), randint(0, 100), randint(0, 100)]
print AP_X

Desejo que NUNCA sejam gerados números repetidos. Por exemplo: [4,4,6,7]
Como posso fazer isso?
Answer: import random
result = random.sample(range(0,100), 4)

Comment: Obrigado! Funcionou corretamente.
Answer: Basta verificar se o valor sorteado já não pertence à lista e, se pertencer, sorteie outro. Algo como:
result = []
while len(result) != 4:
    r = randint(0, 100)
    if r not in result:
        result.append(r)

Desta forma o código é executado até que a lista tenha 4 elementos e só é inserido um novo quando o mesmo já não estiver na lista.
Comment: @GermanoBarcelos porque assim você não garante que serão 4 valores distintos
Comment: Obrigado! Funcionou perfeitamente.
Comment: Por que não guardar os valores em um set e depois transformá-la em uma lista?
Answer: Para você sortear 4 valores de dentro do intervalo [0, 100], sem repetições, você precisa implementar o range(0, 101), utilizando o método sample da biblioteca random.
Então, o código pode ser montado da seguinte forma:
from random import sample

sorteados = sample(range(0, 101), 4)
print(sorteados)

Desta forma podemos sortear 4 valores dentre o range(0, 101) sem repetições.
Answer: Se vocês estiverem trabalhando com dicionários no python:
aleatorio = randint(1, 6)
test = NomeDict.values()

if aleatorio not in test:
    NomeDict.update({chave: valor})

Comment: Não faz sentido como resposta, o autor da pergunta apenas quer uma lista de quatro números aleatórios entre zero e cem que não se repitam ou seja `random.sample(range(0,100), 4)`.


Real world datasets using Markov Chains

Question: I understand that Markov Chains are very important in modeling phenomena such as intergenerational socio-economic status, weather, random walks, memory-less board games, etc... But I'm struggling to find real, empirical data that satisfies a Markov Chain.
For example, I see a lot of..."imagine that if it rained yesterday, then it will rain today with probability 0.8". Where is this 0.8 from? I can't find anything that references a study, or some dataset upon which these figures are based. Not just weather, but any Markov Chain based model. Anyone have resources or suggestions on where to locate these? I searched the footnotes of a lot of these examples but they haven't revealed anything.
Edit Just because some people have provided answers to this, let me clarify and ask it in a different way: Are there processes in nature, and accompanying datasets, that satisfy the Markov Property to a "high" degree, rather than just toy examples that illustrate it?
Comment: All models are wrong!
Comment: look at www.amstat.org/publications/jse/v18n3/rotondi.pdf
Comment: you can find some other papers by googling "markov chain real data" .    but they were too advanced for me so i did not post them here .
Answer: Usually these kinds of models are trained using some empirical data. In your example, if you have data about the weather for several years, you can estimate the probability of a rainy day given that previous day was rainy, or given that the previous day was sunny, etc.
Comment: Right. Can you point me to where such a study exists? I can't seem to find one.
Answer: I would agree on Xi'an's comment All Models Are Wrong.
However, these models (assumptions) enable us to have "describe data effectively". Without these (strong) assumptions, it is impossible to compute anything.
Let's use Markov Chain as an example. Suppose we want to model a length $100$ sequence, $(X_1, X_2, \cdots, X_{100})$, and you have say $5000$ sequences. And let's assume all symbols in the sequence is binary.
Without the Markov assumption, how can we describe the joint distribution $P(X_1, X_2, \cdots, X_{100})$? If you think about using a table, that is $2^{100}$ rows, and $2^{100}-1$ free parameters (needs to sum to $1.0$). There is no way we can do that with computer from computational perspective. On the other hand, to fit those number of parameters, we need much much more data. So, $5000$ sequences seems to be nothing...
With the Markov assumption,
$$P(X_1, X_2, \cdots, X_{100})=P(X_1)\prod_{n=2}^{100}P(X_n|X_{n-1})$$
We only have very few parameters:

Initial distribution: 1 free parameter
Transition matrix 2 free parameters

Such assumption (constrain) enables us to have a joint in a traceable way.

To your edit, even all the real world data does not satisfy Markov property in a reasonable degree, we still need reasonable strong assumptions. Because it is the assumption make the modeling work doable.

Real world datasets using Markov Chains


SSRS expression - remove line breaks when field contains no data

Question: I have an SSRS report that is a calendar, and it shows each persons different activity for each day. I currently do this via .vbcrlf to create the line break.
What I would like to do is only return a line break when there is data in the specific value.
My current expression is:
=Fields!DayOfMonth.Value
        & Constants.vbcrlf
        & Constants.vbcrlf
        & Fields!Shift.Value
        & Constants.vbcrlf
        & Fields!OT.Value
        & Constants.vbcrlf
        & Fields!Holiday.Value
        & Constants.vbcrlf
        & Fields!AbsenceType.Value
        & Constants.vbcrlf
        & Fields!ClockIn.Value

So if there is no Holiday I would like to remove that line and the break meaning Absence and In/Out would move up the text box. I've tried using isNothing but cant get the syntax right.
Answer: It sees the data as NULL values, which can alter the way it treats text.
You can use iif(isnothing(Field!Thing.Value), "", Constants.vbcrlf & Field!Thing.Value) around each one to replace null values with blanks.
There may be a more elegant solution available.
Comment: @GPH You can do it like `=iif(isnothing(Field!Thing1.Value), "", Constants.vbcrlf & Field!Thing1.Value) & iif(isnothing(Field!Thing2.Value), "", Constants.vbcrlf & Field!Thing2.Value) & iif(isnothing(Field!Thing3.Value), "", Constants.vbcrlf & Field!Thing3.Value)`
Comment: Specifically, wouldn't [GPH](http://stackoverflow.com/users/2250361/gph) want: `iif(isnothing(Field!Thing.Value), "", Constants.vbcrlf & Field!Thing.Value)`, so a line break is included when the value itself **is** being returned?
Comment: I was thinking that you can keep the vbcrlf in, just replace the fields with blanks when they're empty.
Comment: The problem then is that it won't give the desired behaviour - as I understand the question, [GPH](http://stackoverflow.com/users/2250361/gph) wants to suppress the empty lines when a value is not present for whatever would otherwise have gone on that line.
Comment: @BishNaboB - this seems like what I'm after. Don't suppose you know how i can do multiple iffs?
Comment: @BishNaboB yeah just got it! Thanks a lot!
Answer: The syntax which worked for me in VS 2017 with SQL Server Data Tools:
=IIf(Fields!Holiday.Value Is "", "", Fields!Holiday.Value + Environment.NewLine)
+ IIf(Fields!AbsenceType.Value Is "", "", Fields!AbsenceType.Value + Environment.NewLine)

Code is pretty much self explanatory - if there is no value for Holiday, result is empty string or else if it has value, show value and line break. For latest syntax of any function, just refer to the examples given in the Expression window.


Regression Analysis

Question: Can someone help me with this problem? I am using R, so what functions I should use?
Comment: Hi Yuto, welcome to CrossValidated. Routine bookwork questions can be posted, but they are treated differently. See the link in Nick's comment above - please read it carefully - and then modify your question as appropriate (that is, we're not going to tell you directly how to do this - if you explain what you've tried and where your specific difficulties lie we will be able to give you some hints and suggestions. As Nick says, you fit regression with `lm`, but if you didn't know even that, CV will not be a suitable place for you to learn about basic use of R.
Comment: Please see [the self-study tag wiki](http://stats.stackexchange.com/tags/self-study/info). P.S. `lm` ^_^
Answer: Ater doing some self study I got this answer. I appreciate your feedback.
<code>>  # data frame for table in the picture above
>rt  <- data.frame(read.table("heightweight.txt"))
>rt2 <- rt[-3,]
>rt3 <- lm(rt2)
>plot(rt2$V2, rt2$V1)
>abline(lm(rt2))
>y = 143.413 + x*0.438  # where is y=175
>answer <- 72.11
</code>
Comment: (i) You don't need to remove the third row - the NA will cause the fit to ignore it. (ii) You can then extract the fitted value for the missing observation from the fit of the linear model, whether direct from the object or via the `fitted` function. (iii) It's best to specify the model in your call to `lm` or you're relying on the columns being in the right order.

Regression Analysis


Number of ways to divide students into groups of 4 with additional conditions

Question: Ok, I have this question:

I have the answers available but I'm struggling to get my around a few parts of the answer.
So far I believe:
Q1a)
$(4n)!$ dictates the number possible ways of ordering all of the students
Dividing by $n!$ puts the students into groups of $4$,   $(4n)! / n!$.
With that I need to cancel the repeat combinations so that I don't have duplicate groups which I do by dividing by $4!^n$
Thus $$q1a =  \dfrac{(4n)!}{ n!  (4!)^n }$$
I know the answer is correct, but I'm not sure if my logic is correct?
Then on q1b)
The answer is $(4n)! / (4!)^n$      - Is this due to the rule of permutations with repetitions where it equals $\dfrac{n!}{ q_1!q_2! \cdots q_k!}$    where $q_1 + q_2 + \dots + q_k = n$ ?
Comment: ad a): $n!$ is the possible orderings of the n groups. And $(4!)^n$ is the possible orderings of 4n students into n groups. This would be my interpretation. ad b) the reasoning sounds good.
Comment: See [math notation guide](http://math.stackexchange.com/help/notation) and try [writing better titles](http://meta.math.stackexchange.com/q/9959) in the future.
Answer: Consider the row
$$\underbrace{a_1a_2a_3a_4|a_5a_6a_7a_8|a_9a_{10}a_{11}a_{12}|\ldots|a_{4n-3}a_{4n-2}a_{4n-1}a_{4n}}_{n \text{ groups}}$$
You can see $n$ groups, each consisting of $4$ people.
All the $a$'s can be re-arranged in $(4n)!$ ways.
$a),b)$ Each group consists of $4$, and it doesn't matter in which order those $4$ people appear inside the groups, hence we divide $(4n)!$ by $\underbrace{4!\cdot 4!\cdots 4!}_{n}=(4!)^n$.
$a)$ It does not matter in which order those groups appear in the row, hence we additionally divide the numbers of ways by $n!$ and the answer is $\frac{(4n)!}{n!(4!)^n}$.
$b)$ It does matter in which order those groups appear in the row - we can say that the first group that appears in the row has a project $h_1$, the one that appears second - project $h_2$, and so on. Hence we do not divide by $n!$ as we do in the $a)$ case. Hence the answer is just $\frac{(4n)!}{(4!)^n}$.
$c_1)$ If we assume each group has its own project, then the order in which people appear inside the groups does matter, and the order in which the groups appear in the row does matter as well, hence it is just $(4n)!$.
$c_2)$ However, if we assume each group does not have its own project, as in $a)$, then the order in which groups appear in the row does not matter, hence we divide $(4n)!$ by $n!$, since there are $n$ groups. The order in which people appear inside the groups does matter, hence we're left with $\frac{(4n)!}{n!}$, we do not divide anything by $(4!)^n$.


How to approach and model these data - choosing an appropriate model

Question: I have group data where each observation within group is time continuous. (named time in the sample data provided bellow`)
Further, I have price value in given time, appr appreciation/depreciation value, mean1, which is diff(log(mean_values_1) and further mean2 and mean3 which are mean values (mean of price) over different time period.
Further, I have variables distance_mean_1_2 and distance_mean_2_3, which are the distances between mean1and mean2 and distance betweenmean2andmean3`.
What I would like to find out is at what level is the dependent variable appreciation, possitive and highest. Or better at which levels is the dependent variable appr maximised.
Also helful would be to find at which levels is the dependent value appr converging to possitive values fastest.
How to approch this. I have long format data. Would I have to turn the data into wide format? So taht each group has one 1 entry per row?
What model (time series?) to use?
I'm using software R.
EDIT: I'm thinking to model each of the independent (explanatory) variable one by one, using survival analysis. Would that be good approach?
EDIT 2: Here is some explanation and hopefully answers the questions raised in answer provided.
1) Why is "convergence" either useful or helpful to know?
The first row in given group is the starting point of measurement. Where appr is always zero. Based on simple command "stop if appr is >100" the measurement process is stopped. The final value is therefore equal or greater than 100. It is desired that the process stops (reaches level 100)
as soon as possible. So possbily I misused the word "convergence" here but what I meant is that the appr value reaches the desired value of 100 (or greater) over time as soon as possible.
Based on this I would like to find the appropriate covariate levels that would either maximize the number of possitive values in the given group or reaches the desired appr value of 100 in shorter period of time.
So I would like to know at which levels is the best chance of achiving this.
2 ) Issue with variable selection, Which of the predictors are most useful and/or predictive of appr?
It is possible that some of the covariates are not significant in explaning the process of appr. So I would like to find out which covariates are significant. Of course fewer covariates in explaning the maximization or "convergence" would be desired so that the model is parsimonious.
Here is example: samp is the sample data (dput) provided bellow.
samp <- transform(samp, flag=with(samp, ifelse(appr<0, TRUE, FALSE)))

samp$appr <- round(samp$appr, -1)
samp$distance12 <- as.factor(round(samp$distance_mean_1_2, 2))
samp$distance23 <- as.factor(round(samp$distance_mean_2_3, 2))

Model fitted:
fittedsurv <- survfit(Surv(time=samp$time, samp$flag)~samp$distance12)

Here is sample data dput().

structure(list(group = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
  2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
  3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), time = c(1L,
  2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
  16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 1L, 2L, 3L,
  4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
  13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L),
      price = c(1.131975, 1.12895, 1.13415, 1.148075, 1.13455,
      1.1477, 1.13155, 1.132425, 1.132075, 1.1337, 1.140325, 1.139275,
      1.135375, 1.1411, 1.139725, 1.136825, 1.138125, 1.13345,
      1.134025, 1.13605, 1.1198, 1.1196, 1.11835, 1.11765, 1.10785,
      1.04955, 1.05675, 1.059725, 1.086375, 1.06595, 1.0822, 1.0889,
      1.0833, 1.07315, 1.076325, 1.087975, 1.097175, 1.0922, 1.081475,
      1.07805, 1.065925, 1.06045, 1.056725, 1.06545, 1.0684, 1.07615,
      1.0807, 1.073775, 1.07355, 1.072425, 1.082375, 1.087875,
      1.08915, 1.0981, 1.112825), appr = c(0, 2.67948093361093,
      -3.8354714984791, -40.1759466933778, 7.02921863293823, -50.3398100548923,
      20.3040077769427, 16.4249288032318, 17.9758408232671, 10.7832759989417,
      -18.3281082147637, -13.736806302254, 3.39095012660988, -21.7115064411535,
      -15.7055430037954, -2.99078574098922, -8.69851729818822,
      11.8884820680219, 9.34723661294901, 0.418115399850166, 72.981782461154,
      73.8879957127547, 79.5591719944562, 82.7405717353372, 127.702306268899,
      0, 6.81334279630953, 12.4088796621765, 85.6978483488664,
      35.695858154697, 110.238403252633, 0, -5.16938982737935,
      -24.134557144854, -15.2138062388219, 27.7809692318295, 80.0920545947553,
      57.681743270464, 8.66871633648522, -7.18890589490256, -64.1461641297459,
      -90.2918572304211, -108.235349783529, -66.4038669106945,
      -52.4148259078991, -16.029363936254, 5.08929397612705, -27.1239319224231,
      -28.1775418005677, -33.4522227661605, 12.8190322208116, 38.0328622314146,
      43.8415277969066, 84.2364083416819, 149.282232156898), mean1 = c(0,
      -0.000125909452303286, 0.000480767625671563, 0.00174112688697965,
      0.000197216307187068, 0.00121615479085431, -0.000174056350265378,
      -8.79262923791369e-05, -9.74266755982556e-05, 1.11326494046937e-05,
      0.000374958733439235, 0.000276277046605489, 5.45242034129256e-05,
      0.000314368832739276, 0.00022227302140948, 7.9401611874419e-05,
      0.000124234137939244, -6.56366814974774e-05, -3.90626893718993e-05,
      3.54238189215206e-05, -0.000518055394024303, -0.000486452734504011,
      -0.000491306161860133, -0.00809928321939048, -0.00388792727271271,
      -0.0475850358518138, -0.00148495851609912, -0.000766072854589614,
      0.00218079377247371, -0.000170151521123416, 0.00124375135307889,
      0.020066061096198, -0.000953967459985092, -0.00188206997886047,
      -0.00283135384960903, 0.000273465517020816, 0.00247455080838277,
      0.000367782277040249, -0.000447368358715838, -0.000608727159220307,
      -0.00226018102656933, -0.00121764245969647, -0.00127198932686792,
      -0.0125519550862929, -0.00204247878661268, -0.00029715125999033,
      0.00203360767447708, 0.000712653091219526, 0.00137546738904835,
      0.000213035364990496, 0.000951874176837356, 0.00119929844733625,
      0.0065522202860582, 0.00191263631850579, 0.00818748986560495
      ), mean2 = c(0, -0.00704195826131931, -0.00627500719528225,
      -0.00498670169640732, -0.0017388799915012, -0.000170151521123416,
      0.00124375135307889, 0.0019985812499813, 0.00153382827948782,
      0.0016153716745991, 0.0008664183062876, 0.000786538278354385,
      0.00957930055086824, -0.00135328922328085, 0.00106180888463094,
      0.000158790614197574, 0.000899337518020904, 0.000367782277040249,
      -0.000447368358715838, -0.000608727159220307, -0.00127240852760666,
      -0.00143039032774157, -0.00146627716701067, -0.000856747310940417,
      -0.000623484107310557, -0.0075061543615107, 0.00111165484916645,
      0.00187789269737494, 0.00584401222055937, 0.00765319531854193,
      0.00466933643850007, 0.0210108262695513, -0.000278402833809296,
      0.000241605996257777, 0.00125095354341931, 0.00318688670096776,
      0.00147784903483378, 0.00039605384433157, -0.000632727654295839,
      -0.000866696154246824, -0.000668468141698117, -0.00108958570139681,
      -0.00113790320780324, -0.00238803637527786, -0.00112351686458498,
      -0.0112841232271361, -0.00329564306271869, -0.00225120329744991,
      0.00153773392023647, 0.00227537488894973, 0.00161864874852717,
      0.00117748472348102, 0.00142481132443494, 0.00119852645921323,
      0.00127765117220648), mean3 = c(0, -0.00149598876645349,
      -0.00441931783382968, -0.0076488409828849, -0.00113846821320018,
      -0.00163004372170902, -0.00225524378260492, -0.000608260910848812,
      -0.0023984593618408, -0.00121508194174377, -0.000987657107139134,
      -0.00478254128195757, -0.00753865101960935, -0.00587250593537236,
      -0.00213942676875745, -0.0063543836257087, -0.00136629361348317,
      0.000197312324906024, -0.000909369742590177, -0.000377384448124907,
      -0.00682093942827186, -0.00582763856655152, -0.00522235547636016,
      -0.00112828300967641, 0.000362339162043451, -0.0258114034483171,
      0.000480767625671563, 0.00174112688697965, 0.00581915353017895,
      0.00395788514502121, -0.00260335810375681, -0.00270979229966919,
      -0.000160469009492153, 0.000285748828725535, 0.000148759967614098,
      -5.45749504993476e-05, 2.88816280240856e-05, -0.000231586631810748,
      -0.000174642513644796, -5.63259988011489e-05, -0.00232587852123847,
      -0.00827312250145883, -0.00525754196268011, -0.000357446051793123,
      -0.00196824040279832, -0.00202446609436205, -0.0144237434071857,
      -0.00690479568146037, -0.0102274404029469, -0.00582252570132376,
      -0.0101565300751118, -0.00637225436126534, 0.0001992556525688,
      0.000682692009971946, 0.00572777812205827), distance_mean_1_2 = c(-0.0365579095629866,
      -0.0434739583720054, -0.0502297331929546, -0.0569575617763408,
      -0.058893658075035, -0.0602799643870113, -0.0588621566836718,
      -0.0567756491413051, -0.0551443941862192, -0.05354015516103,
      -0.0530486955881793, -0.0525384343564295, -0.043013658008976,
      -0.0446813160649942, -0.0438417802017707, -0.0437623911994467,
      -0.0429872878193627, -0.0425538688608303, -0.0429621745301677,
      -0.043606325508318, -0.0443606786418921, -0.0453046162351342,
      -0.0462795872402859, -0.0390370513318403, -0.0357726081664306,
      0.00430627332387412, 0.00690288668913117, 0.00954685224110112,
      0.0132100706891893, 0.0210334175288501, 0.0244590026142726,
      0.0254037677876287, 0.0260793324138063, 0.028203008388918,
      0.0322853157819468, 0.0351987369658929, 0.0342020351923428,
      0.0342303067596357, 0.0340449474640598, 0.0337869784690358,
      0.0353786913539018, 0.0355067481122096, 0.0356408342312711,
      0.0458047529422805, 0.0467237148643095, 0.0357367428971703,
      0.0304074921599643, 0.027443635771299, 0.0276059023024871,
      0.0296682418264462, 0.0303350163981333, 0.0303132026742835,
      0.0251857937126607, 0.0244716838533682, 0.017561845159964
      ), distance_mean_2_3 = c(-0.09726297804778, -0.0958928987336336,
      -0.0909928132741315, -0.0816028454042668, -0.0802671608838797,
      -0.0774209623713145, -0.0753397749389736, -0.0748194403205009,
      -0.0725184076342605, -0.0712921930431132, -0.0699295772025403,
      -0.0648707588739723, -0.0572775836509485, -0.0510907088828391,
      -0.0487290090926736, -0.0422952238550939, -0.0408046961036684,
      -0.0410676451100696, -0.0401973380568562, -0.0397845297898041,
      -0.0334816457555634, -0.0281404599235143, -0.0234094106090121,
      -0.0303804108187229, -0.0346306772534791, -0.0564043096569832,
      -0.0583700357987467, -0.0608772355403157, -0.064515595298027,
      -0.0686436319641656, -0.0647965225073362, -0.0420206691114687,
      -0.0428141675619625, -0.0449819863695446, -0.0479621001867693,
      -0.0476340597192499, -0.0451883905388889, -0.0445890216300379,
      -0.0448617474751081, -0.0454141486355312, -0.0453484511408505,
      -0.0382929710990994, -0.0343074184632867, -0.0465019274977842,
      -0.0465761658815954, -0.0448488510472269, -0.0283914999655629,
      -0.0207740511928841, -0.00917114340088911, -0.00313558233457029,
      0.00797282191737423, 0.0155443747259729, 0.0218973393594655,
      0.0231272836679962, 0.0255869954115449)), .Names = c("group",
  "time", "price", "appr", "mean1", "mean2", "mean3", "distance_mean_1_2",
  "distance_mean_2_3"), row.names = c(NA, 55L), class = "data.frame")
Answer: Some aspects of your question aren't clear. While I think your first concern about the "levels" at which appr is "positive and highest" is clear and addressable, I don't know what is meant by your second question, "at which values appr converging to possitive (sic) values fastest." Perhaps more importantly, why is "convergence" either useful or helpful to know?
You are lucky in that your data isn't large. I wouldn't make this analysis too complicated. There is no reason why a classic ANOVA wouldn't deliver a reasonable answer to your question, in other words, I don't see how survival analysis can help you. Flattening, pushing down the stack or "widening" your file to create a single record would be variance-destroying and not a good idea. You do have an issue with variable selection -- which of the predictors are most useful and/or predictive of appr? I can't imagine that you would need all of them to fit a model, unless there is some theoretical reason that needs to be articulated.
Wrt your first concern about the "levels" which maximize appr, assuming that you are referring to the 3 possible groups, treating group as a qualitative predictor in an ANOVA and, perhaps, dropping the intercept you could obtain coefficients that would be your best indicator of the level where appr is maximized. It would also be worth your while to explore a few of the possible interactions, e.g., price by group, to obtain more representative estimates of the effects.
EDIT 2 Thoughts ************
I see what you mean by convergence now. This is a question that applies to the sequencing of the process. In examining time series line plots containing appr and price for the 3 groups, three things stand out suggesting very different processes at work for each group: first, price for group 2 is much higher than for the other 2 groups, second, price is positively related to appr for groups 2 and 3 and negatively related for group 1 and, finally, I'm left wondering why there is any nonlinear variability in price at all given how it's linearly related to appr in group 2 vs the others. In other words, as the sequence for a process unfolds, why doesn't price change as a linear function for each group instead of only for group 2? That would seem to suggest an immediate solution to the longer sequences for groups 1 and 3 as well as an answer to your question about convergence since the maximal value for appr would be reached with fewer steps.
In terms of variable selection, there are many approaches to that (everybody has an opinion about which approach is best). I rely on the Lasso. You can use one of the widely available R modules for this. On the other hand, the sheer number of possible covariates and their interactions are so few that you can almost do this step by hand and in the absence of some automatic routine. In fact, a careful specification of the predictors and their combinations might lead to better results.
Comment: Thank you very much for looking into this. I have now included answers to the questions you raised under `EDIT 2`. I would be grateful if you could extend your answer by reflecting on this new information. Thank you!


Object.toString() Returns "[blob data]"

Question: I have a simple http server running in Node as a systemd service that receives data via a tcp socket (not a WS socket). Here's the code:
const net = require('net');

const HOST = '0.0.0.0';
const PORT = 6968;

const server = net.createServer();
server.listen(PORT, HOST);
console.log('Server listening on', PORT);

server.on('connection', function(sock) {
    console.log('CONNECTED:');
    sock.on('data', function (data) {
      let message = data.toString().trim();
      console.log('message is', message);
      console.log('data is', data);
      console.log('message type is', typeof(message));
      console.log('data is', typeof(data));
    });
});

An example of the type of data sent to this server is the following string:
Grateful Dead^LSugaree^L005:37^L0251-001^LM\r\n
The specific problem I'm having is that "let message = data.toString().trim()" is not returning the string that was sent to me. Instead, I'll get something that looks like this:
"[67B blob data]"
The console.log for the object ("data") received by the server shows something like this:
"<Buffer 44 72 61 67 67 69 6e 20 [etc.]>"
The typeof(message) is "string".
The typeof(data) is "object".
I have been researching this all day and have tried many different things but nothing I've tried will return to me the string I'm looking for, though I can see the string by just looking at the port by entering the terminal command:
"socat TCP4-listen:6968,reuseaddr,fork -"
Does anyone see what I'm doing wrong?
Comment: As specified in the question, the value returned by data is something like "", and the typeof(data) is "Object".
Comment: What value is being returned as `data`? What is the object type?
Answer: Here is an example stolen from this website: https://riptutorial.com/node-js/example/22405/a-simple-tcp-server
const net = require("net");

const HOST = "0.0.0.0";
const PORT = 6968;

const server = net.createServer();

server.listen(PORT, HOST);
console.log("Server listening on", PORT);

server.on("connection", function (socket) {
  console.log("A new connection has been established.");

  // Now that a TCP connection has been established, the server can send data to
  // the client by writing to its socket.
  socket.write("Hello, client.");

  // The server can also receive data from the client by reading from its socket.
  socket.on("data", function (chunk) {
    console.log(`Data received from client: ${chunk.toString().trim()}.`);
  });

  // When the client requests to end the TCP connection with the server, the server
  // ends the connection.
  socket.on("end", function () {
    console.log("Closing connection with the client");
  });

  // Don't forget to catch error, for your own sake.
  socket.on("error", function (err) {
    console.log(`Error: ${err}`);
  });
});

Comment: Thank you for your suggestion. Sadly, though, the server behavior is the same. Here's the console.log:

Mar 25 19:29:36 [host name] node[37722]: A new connection has been established.

Mar 25 19:32:58 [host name] node[37722]: [79B blob data]

Mar 25 19:33:01 [host name] node[37722]: [85B blob data]

The weird thing is that, while it logs the "blob data" part, it does not log the "Data received from client" part.
Answer: In case any future person stumbles on this, the problem was (is) I'm an idiot. The simple solution was to use "message" to create an array:
let dataArray = message.split('\f');

(I happened to know that the data being sent to me used "\f" as a delimiter.)
Then I could use the array to process the data as I wished.
Comment: Or, even more concisely, change "let message = data.toString().trim();" to "let message = data.toString().trim().split('\f');"  Why that makes the difference, I do not know.

Object.toString() Returns "[blob data]"


GridView - Images,Text and ItemClick

Question: my friends
I am a new in android and I wanted to do an example (code) like the picture
GridView - Images,Text and ItemClick
Thanks to all
Comment: You should start to looking for online tutorial ... question is too broad for SO
Comment: Go on Fiverr and pay someone to make it for you
Comment: Don't go on fiverr and let someone do it for you, they will do it in the easiest quickest way without taking in account future issues.
Answer: You are looking for RecyclerView. Create a layout and add recyclerView to it then create another layout file for the rows of the recyclerview as below:
 <RelativeLayout
                android:id="@+id/relativeLayout2"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>

 </RelativeLayout>

Create another layout row_layout.xml
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

     <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@mipmap/ic_launcher" />

     <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"/>

</RelativeLayout>

Then in your MainActivity, add following lines of code:
 RecyclerView recyclerView = findViewById(R.id.recyclerView);
 recyclerView.setHasFixedSize(true);
 RecyclerView.LayoutManager gridLayoutManager = new GridLayoutManager(this, 2, false);
 recyclerView.setLayoutManager(gridLayoutManager);

After this, create an Adapter according to your specific need for the recyclerView which can be found with a quick google search. Just remmeber to infalte your row_layout in the adapter's onCreateViewHolder. After creating the adapter just set it to your recyclerView.
recyclerView.setAdapter(your_custom_adapter);

This is just a gist of what you ought to do. It'll get you started in the right direction. The rest is just a search away.

GridView - Images,Text and ItemClick


Is Smart Table compatible with Angular 2.0?

Question: I was looking at the documentation for Smart Table (https://lorenzofox3.github.io/smart-table-website/) and all the examples seem to use Angular 1.0.  I was wondering if Smart Table can be used with Angular 2.0?
(Note that I found another product that supports tables in Angular 2 called ng2-smart-table [https://github.com/akveo/ng2-smart-table], but it appears to have no relation to the original Smart Table, which I'd like to still be able to use when I migrate to Angular 2.0)
Comment: your link to smarttable throws 404. What is that you are looking for?
Answer: Currently, I am migrating the existing web application from angularJS to angular V4.03 and would like to help you understand that there is really a large structural difference between v2 and v4 but functionality remains the same. ng2-smart-table/akveo is perfectly stable with both the version.
You might find it difficult to customize the style at first but a little practice with ::ng-deep will overcome your troubles. Also, you will find an active team support with the product.
Hope this helps.
Answer: I was also hunting for smart tables and found both the tables you have mentioned. I believe angular-smart-table is for AngularJS. I check their repo carefully. The last commit is shown on 5th September 2016. And author is promoting new ambitious project. I concluded that he doesnt want to upgrade current project for sure.
Now for the ng2-smart-table, the name is bit deceiving. Their current versions expect you to be using Angular 4. You have to use their 0.6.x version with Angular 2. The biggest drawback is, these tables doesnt support datasource from server side. Data has to be statically defined. They are working on API/Server datasource. I am watching the repo!!!


How to show $a^{2^n}+1 \mid a^{2^m}-1$?

Question: I've been struggling with this all day today. I imagine it's not very hard, but my algebra skills are terrible. So, how can I show that if $m>n$ and $a$ is a positive integer, then
$$a^{2^n}+1 \mid a^{2^m}-1.$$
I just can't get a coherent picture of what I'm supposed to do. If this too (see yesterday's question) boils down to the Unique Factorization Theorem, I would be very grateful for any intuition on how to think about this!
Comment: It always comes down to a race of fingers with these sorts of questions...
Answer: First you could try to show that: $x-1\mid x^k-1$ for any integer $x$ and any positive integer $k\ge 1$. (This follows from the well-known equality $x^k-1=(x-1)\cdot(\ldots)$; try to fill in the dots.)
Now you can use:
$(a^{2^n}-1)(a^{2^n}+1)=(a^{2^n})^2-1=a^{2^{n+1}}-1$
This means that $a^{2^n}+1 \mid a^{2^{n+1}}-1$ and using the above result for $x=a^{2^{n+1}}$ and $k=2^{m-(n+1)}$ you get $a^{2^{n+1}}-1\mid a^{2^m}-1$.
(Note that $(a^{2^{n+1}})^{2^{m-(n+1)}} = a^{2^{n+1}.2^{m-(n+1)}} = a^{2^m}$.)
Answer: $$(a^{2^n}+1)(a^{2^n}-1)(a^{2^{n+1}}+1)(a^{2^{n+2}}+1)\cdots(a^{2^{m-1}}+1) = a^{2^m}-1$$
Answer: Hint $ $ Below put $\rm\ X = a^{\large 2^{\Large N}}, \ 2K = 2^{M-N}\ $ (cf. coprimality of Fermat numbers)
The Factor Theorem $\rm\, \Rightarrow\, X+1\mid X^{\large2K}-1\ $ since $\rm\ X = -1\ $ is a root of the latter.
Alternatively $\ \rm\bmod\ X+1\!:\ \ \color{#c00}{X\equiv -1}\, \Rightarrow\ \color{#c00}X^{\large 2K}\!\equiv (\color{#c00}{-1})^{\large2K}\!\equiv 1\, $ via Congruence Power Rule.
Note in particular how the use of modular arithmetic enables one to reduce the proof to the triviality that $\rm\ (-1)^2 = 1.\,$ Such order $\,2\,$ cyclicity is ubiquitous, e.g. the test for divisibility by $11,\, $ where $\rm\ 10\equiv -1\ \Rightarrow\ 10^{\large 2K}\equiv 1,\:\ 10^{2K+1}\equiv -1.$
Comment: Thanks for the added explanation! By the way, do you have any tips for getting a better grasp of algebraic manipulations? I sometimes (often) have difficulties seeing "the next natural step".

How to show $a^{2^n}+1 \mid a^{2^m}-1$?


Is it possible to prove the uniqueness of a point in space?

Question: Is it possible to prove the uniqueness of a point in space?
Well. I know this might be a silly question, but some response would be nice.
Comment: What do you mean?  What is your definition of a point in space?
Comment: And what is your definition of uniqueness?
Comment: If you ask whether a point is the only point where a certain line intersects a certain circle, one can answer something like that.  That's the kind of thing addressed by proofs of uniqueness.  I.e. you need to specify a point before the question means anything.
Comment: Ok. If you take the point (3,4,1) how do you know that it is unique? That there exists no other (3,4,1) ?
Answer: In the comments, the problem has been clarified: how does one know that the point $(3,4,1)$ (say) is unique, that there is no other $(3,4,1)$.
I would say the question is unnecessarily complicated. The problem it raises for space already comes up on the line. So I ask OP, how do we know the number 17 is unique? How do we know there is no other 17?
If you can find an answer to that question, an answer that satisfies you, then you should have no trouble with points in space.
Comment: Thank you for the clarification.
Answer: It's clear that what is important is not the space itself but the structure and arguments we impose and use on space. For instance, if we model space as R^3 and think of distance as the Euclidean norm then this problem is done.
What you really need to ask is, is it acceptable to assume there is a bijection between R^3 and space (or, to be slightly stronger we want an Isomorphism of sufficient depth)? Once you accept that, uniqueness is trivial (as points in R^3 are unique).


How can Monitor Linux zimbra mail traffic ( in and cout )?

Question: I configured zimbra mail server in linux. Is there any way to monitor e-mail traffic through linux server. Or any way to monitor spam activities on this zimbra mail server.
Thanks for the great help.
Answer: You can monitor a great deal through the zimbra admin console - https://[your domain here]:7071/zimbraAdmin/.  From the monitoring panel there you can view graphs for email traffic and spam activity.  You are also able to view and export various metrics through the advanced tab.
For more detailed reports of email in and out, you can view the admin report which is automatically mailed to the admin account you set up with the server.
Comment: Thanks for the help. But my intention is monitor spam activity in the linux / zimbra running server. Through that i try to monitor unwanted generation of mails from the local mail server. Any way to monitor this like activities ?


postgresql, My query is too slow. What's the problem? (Takes more than 1 minute)

Question: Below is the query that I use.
I want to see the results within 2 or 3 seconds, but it takes more than a minute.
with meta as (
    select
        item_name
        , item_sp
        , grade
    from
        meta_info
    where
        item_sp = 'Bc_1'
        and grade_no = (
            select
                max(grade_no)
            from
                meta_info
            where
                item_sp = 'Bc_1'
        )
) select
    *
from (
    select
        m.grade
        , i.item_sp
        , i.regist_date
        , i.serial_key
        , row_number() over(partition by i.serial_key order by m.grade) as serial_key_number
    from
        item_info i, meta m
    where
        i.item_sp = 'Bc_1'
        and i.regist_date = '20210314'
        and i.regist = true
        and i.item_name = m.item_name
        and i.item_sp = m.item_sp
    ) i
where
    not exists (select
                    serial_key
                from
                    item_info ii
                where
                    ii.item_sp = 'Bc_1'
                    and ii.regist_date < '20210314'
                    and i.serial_key = ii.serial_key)
    and i.serial_key_number = 1;

The total number of tables used is meta_info and item_info.
meta_info contains the basic information of the product, and item_info is a table that stores the grade and serial key of each product by date.
In the item_info table, the serial key by product is not a key value, so it can be duplicated.
Here's the problem.
A query that compares all serial keys prior to a particular registration date to look up unregistered serial keys once, and extracts only the highest-rated serial key values because there are duplicates of the serial key values by grade.
But there are more than 10 million item_info data.
Below is the table structure.
1. meta_info
item_sp    grade    item_name    grade_no
 ac_1        A         BOOK         2
 ac_1        B         FOOD         2
 bc_1        A         WATER        2
 cc_1        C         MOUSE        2
  .          .           .          .
  .          .           .          .
  .          .           .          .

2. item_info
item_no(key)    item_sp    item_name    serial_key      regist_date    regist
   1              ac_1       BOOK       fgd5756ffdsf     20210314       true
   2              ac_1       FOOD        bnffdhtj        20210314       true
   3              bc_1       WATER      fdfh4fsdfsf      20210314       true
   4              cc_1       MOUSE      htt55434         20210314       true
   .               .           .           .                .            .
   .               .           .           .                .            .
   .               .           .           .                .            .
   .               .           .           .                .            .

Comment: This took 13 seconds, which is quite a bit less than one minute.  Please show the plan as text, not an image.
Answer: Almost all of the time is going to the last index scan in your plan.  You should be able to greatly improve it by adding an index on item_info (serial_key, item_sp, regist_date)
Comment: Thank you. It's my first time dealing with large data, so I don't know many things. Thank you for your answer.


Solving $\frac{dx}{dt}=\frac{xt}{x^2+t^2},\ x(0)=1$

Question: I have started self-studying differential equations and I have come across the following initial value problem
$$\frac{dx}{dt}=\frac{xt}{x^2+t^2}, \quad x(0)=1$$
Now, since $f(t,x)=\frac{xt}{x^2+t^2}$ is such that $f(rt,rx)=f(t,x)$ for every $r\in\mathbb{R}\setminus\{0\}$, we can use the change of variables $y=\frac{x}{t}$ to rewrite it in the form
\begin{align}
y+t\frac{dy}{dt} &=\frac{t^2 y}{t^2(1+y^2)} \\
&=\frac{y}{1+y^2} \\
\implies t\frac{dy}{dt} &=\frac{y}{1+y^2}-y \\
&=-\frac{y^3}{1+y^2} \\
\implies \frac{dy}{dt} &= \left(-\frac{y^3}{1+y^2}\right)\cdot\frac{1}{t}
\end{align}
which is separable, and becomes:
\begin{align}
\left(\frac{1+y^2}{y^3}\right)dy &= -\frac{dt}{t} \\
\implies \int_{y_1}^{y_2} \left(\frac{1+y^2}{y^3}\right) dy &= -\int_{t_1}^{t_2} \frac{dt}{t} \\
\implies -\frac{1}{2y_2^2}+\ln \left\lvert \frac{y_2}{y_1} \right\rvert + \frac{1}{2y_1^2} &= -\ln \left\lvert \frac{t_2}{t_1} \right\rvert
\end{align}
but now I don't see how to go forward and find $y(t)$. Also, I integrated from a generic time $t_1$ to a generic time $t_2$ because the right hand side wouldn't have converged otherwise.
So, I would appreciate any hint about how to go forward in solving this IVP.
Thanks
Comment: Go back to $x(t)=ty(t)$ and you combine the Ln parts and get everything in terms of t and $x(t)$. A bit concerning that $y(0)$ is not defined during the algebra but maybe the answer approach below gets around that?
Answer: With homogeneous equations, you have two choices for the substitution.
Here we have
$$(x^2+t^2)\,dx=xt\,dt  $$
You made the substitution $x=yt$, but you also had the choice of letting $t=ux$. As a general rule, the substitution which makes the algebraic simplification easier also makes the integration easier. So lets investigate the substitution $t=ux$
\begin{eqnarray}
(x^2+u^2x^2)\,dx&=&ux^2(udx+xdu)\\
x^2\,dx&=&ux^3\,du\\
\frac{1}{x}\,dx&=&u\,du\\
\ln|x|+c_1&=&\frac{u^2}{2}\\
\ln x^2+c_2&=&\frac{t^2}{x^2}\\
t^2&=&x^2(\ln x^2+c_2)
\end{eqnarray}
The initial condition then gives $c_2=0$. So
$$ t^2=x^2\ln x^2 $$
Answer: You got that
$$\dfrac{1+y^2}{y^3}dy=-\frac{1}{t}dt$$
This implies that, putting $y'(t)=\frac{dy(t)}{dt}$,
$$\dfrac{1+y(t)^2}{y(t)^3}y'(t)=-\frac{1}{t}$$
where this equality is as functions of $t$. In particular, since they are the same function, both sides of the equality must have the same primitive, ie
$$\int \dfrac{1+y(t)^2}{y(t)^3}y'(t) dt=\int -\frac{1}{t} dt$$
(but not a definite integral!)
On the left side, you can distribute the denominator and get that $$\int \dfrac{1+y(t)^2}{y(t)^3}y'(t) dt=-\frac{1}{2}y^{-2}(t)+\ln(|y(t)|)+C$$
And the right side remains $$\int -\frac{1}{t} dt=-\ln(t)+C$$
Therefore the solution satisfies the implicit equation $$-\frac{1}{2}y^{-2}(t)+\ln(|y(t)|)=-\ln(t)+C$$
The problem is that the initial data is at $t=0$ where this equality is not defined. Note that the substitution $x=ty$ is not valid for the initial data you have because $1\neq x(0)=0\cdot y =0 $
Answer: $$\frac{dx}{dt}=\frac{xt}{x^2+t^2},\ x(0)=1$$
Multiply by $2x$:
$$2x{dx}=\frac{2x^2t}{x^2+t^2}dt$$
$${dx^2}=\frac{x^2}{x^2+t^2}dt^2$$
Substitute $u=x^2,v=t^2$:
$${du}=\frac{udv}{u+v}$$
This is a first order linear DE $uv'=u+v$ that you can also solv as this:
$$u{du}={udv}-vdu$$
$$\dfrac {du}u=\dfrac {udv-vdu}{u^2}$$
$$\dfrac {du}u=d \left (\dfrac       {v}{u}\right)$$
Integrate:
$$\ln u=\dfrac {v}{u}+C$$
$$\ln x^2= \dfrac{t^2}{x^2}+C$$
Apply initial condition.
$$x(0)=1  \implies C=0$$
$$\ln x^2= \dfrac{t^2}{x^2}$$


tpl.php files in subfolders

Question: I am creating a big Drupal theme with lots of node types and lots of custom templates. Each having a very diffent look and feel. This is something I can not get round because the design was signed off before Drupal was decided as a platform. I wish to organise my files into folders.
templates/content_type/node-content_type.tpl.php

So for example
templates/page/node-page.tpl.php
templates/blog/node-blog.tpl.php
templates/node.tpl.php

The problem is drupal only scans for the templates files in the same folder as node.tpl.php.
Is it possible to get Drupal to scan into subfolders? Even if I need to hardcode where to look I don't mind.
Views does something which means it can look in subfolders but I don't know if that is because it defines its own type rather then a core type (node/page).
Comment: The Views module is not using a content type to show its results.
Comment: Sorry I meant that views can define tempalte files in subfolder locations and they are picked up and used.
Answer: In D6, any custom templates (from core, such as node or page) must be in the same folder as the base tpl file in order to use the auto-recognition of theme files.
You may be able to specify additional template files (in D7 they're called theme hook suggestions) in a preprocess function in your theme's template.php. See the first code example at http://drupal.org/node/249726 to get you started.

tpl.php files in subfolders


Appending extra columns to Views table

Question: Can anyone tell me if there's a way to use hook_form_alter, or some other approach, to insert an extra column with to a views generated table.
I am trying to insert some buttons which will update node data when a user clicks on a relevant button.
Comment: It's very easy through the UI, why do you need to do it programatically?
Answer: There are multiple ways you can add an extra column or a field to each row of your views output. And you can choose what is best for your use case.
For a Drupal 7 site you can use -

https://drupal.org/project/computed_field
https://drupal.org/project/views_php
for extra fields in plain text, you can refer this answer.

If you need to pass any kind of dynamic context to your custom extra field, say a node id, there are multiple ways to do that too.

Appending extra columns to Views table


Expected Value Reformulation

Question: I have the following problem:
Show that E[X] = $\int_0^\infty [1 - F_x(x)]dx$ where x is a continuous, non-negative random variable.
The solution is as follows:
$$\int_0^\infty [1 - F_x(x)]dx = \int_0^\infty P(X \gt x)dx \qquad(1)$$
$$ = \int_0^\infty \int_x^\infty f_x(y)dydx \qquad(2) $$
$$ = \int_0^\infty \int_0^y dx f_x(y)dy \qquad(3) $$
$$= \int_0^\infty yf_x(y)dy = E[X] \qquad(4)$$
I get the train of thought but I don't understand how the coefficients on the inner integral go from x to infinity in step 2 to 0 to y in step 3.
Answer: $y$ ranges from $x$ to $\infty$ as $x$ ranges from $0$ to $\infty$ $\equiv$ $x$ ranges from $0$ to $y$ as $y$ ranges from $0$ to $\infty$.
Thus with the interchange of integrals the boundaries of integration changed.
$$\int_{0}^{\infty}\left[\int_{x}^{\infty}f_x(y)dy\right]dx=\int_{0}^{\infty}\left[\int_{0}^{y}dx\right]f_{x}(y)dy$$

Expected Value Reformulation


How do I migrate images?

Question: I have to migrate my blogs (Drupal 7) to Drupal 8. I tried and succeed in field migration but I am not able to migrate my image field. I have tried by process plugin, nothing happened. Files migration already been done.
This is configuration file
id: custom_blogs
label: Custom Blogs Migration

source:
  plugin: custom_blogs

destination:
  plugin: entity:node

process:
  # Field mappings and transformations will go here. We will get to this in a minute.
  nid: nid
  type:
    plugin: default_value
    default_value: ct_blogs
  langcode:
    plugin: static_map
    bypass: true
    source: language
    map:
      und: en
  title: title
  uid: uid
  status: status
  'body/value': body_value
  'body/format':
    plugin: static_map
    bypass: true
    source: body_format
    map:
      1: plain_text
      2: basic_html
      3: full_html
  'body/summary': teaser
  'field_ct_blog_image_caption/value': field_blog_image_caption_value
  'field_ct_blog_image_caption/format':
    plugin: static_map
    bypass: true
    source: field_blog_image_caption_format
    map:
      1: plain_text
      2: basic_html
      3: full_html
      4: filtered_html
  'field_ct_blog_image_caption/summary': field_blog_image_caption_teaser
  field_ct_blogs_tags: tags
  field_ct_blogs_image: # Image field name in Drupal 8 site
    plugin: iterator
    source: field_image # Image field name in Drupal 7 site
    process:
      target_id:
        plugin: migration
        migration: custom_blogs_images
        source: fid
      alt: field_image_alt
      title: field_image_alt
      width: field_image_width
      height: field_image_height

This is process plugin
<?php
/**
 * @file
 * Contains \Drupal\migrate_custom\Plugin\migrate\source\Blogs.
 */

namespace Drupal\custom_migration\Plugin\migrate\source;

use Drupal\migrate\Row;
use Drupal\migrate\Plugin\migrate\source\SqlBase;

/**
 * Extract users from Drupal 7 database.
 *
 * @MigrateSource(
 *   id = "custom_blogs"
 * )
 */
class Blogs extends SqlBase {

  /**
   * {@inheritdoc}
   */
  public function query() {
    $query = $this->select('node', 'n')
      ->condition('n.type', 'blog')
      ->fields('n', array(
        'nid',
        'vid',
        'type',
        'language',
        'title',
        'uid',
        'status',
        'created',
        'changed',
        'promote',
        'sticky',
      ));

    $query->orderBy('nid');
    return $query;
  }

  /**
   * {@inheritdoc}
   */
  public function fields() {
    return [
      'nid' => $this->t('Node ID'),
      'vid' => $this->t('Version ID'),
      'type' => $this->t('Type'),
      'title' => $this->t('Title'),
      'format' => $this->t('Format'),
      'teaser' => $this->t('Teaser'),
      'uid' => $this->t('Authored by (uid)'),
      'created' => $this->t('Created timestamp'),
      'changed' => $this->t('Modified timestamp'),
      'status' => $this->t('Published'),
      'promote' => $this->t('Promoted to front page'),
      'sticky' => $this->t('Sticky at top of lists'),
      'language' => $this->t('Language (fr, en, ...)'),
      'body/value' => $this->t('Value of body'),
      'body/format' => $this->t('Format of body'),
      'body/summary' => $this->t('Summary of body'),
      'field_blog_image_caption/value' => $this->t('Value of Image Caption'),
      'field_blog_image_caption/format' => $this->t('Format of Image Caption'),
      'field_blog_image_caption/summary' => $this->t('Summary of Image Caption'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    // Find parents for this row.
    $nid = $row->getSourceProperty('nid');

    $result = $this->getDatabase()->query('
      SELECT
        fld.body_value,
        fld.body_format,
        fld.body_summary
      FROM
        {field_data_body} fld
      WHERE
        fld.entity_id = :nid
    ', array(':nid' => $nid));
    foreach ($result as $record) {
      $row->setSourceProperty('body_value', $record->body_value );
      $row->setSourceProperty('body_format', $record->body_format );
      $row->setSourceProperty('teaser', $record->body_summary );
    }

    // Image Caption
    $result = $this->getDatabase()->query('
      SELECT
        fld.field_blog_image_caption_value,
        fld.field_blog_image_caption_format,
        fld.field_blog_image_caption_summary
      FROM
        {field_data_field_blog_image_caption} fld
      WHERE
        fld.entity_id = :nid
    ', array(':nid' => $nid));
    foreach ($result as $record) {
      $row->setSourceProperty('field_blog_image_caption_value', $record->field_blog_image_caption_value );
      $row->setSourceProperty('field_blog_image_caption_format', $record->field_blog_image_caption_format );
      $row->setSourceProperty('field_blog_image_caption_teaser', $record->field_blog_image_caption_summary );
    }

    // Images
    $result = $this->getDatabase()->query('
      SELECT
        -- fld.field_image_fid,
        fld.field_image_alt,
        fld.field_image_title,
        fld.field_image_width,
        fld.field_image_height
      FROM
        {field_data_field_image} fld
      WHERE
        fld.entity_id = :nid
    ', array(':nid' => $nid));
    // Create an associative array for each row in the result. The keys
    // here match the last part of the column name in the field table.
    $images = [];
    foreach ($result as $record) {
      $images[] = [
        // 'target_id' => $record->field_files_fid,
        'field_image_alt' => $record->field_image_alt,
        'field_image_title' => $record->field_image_title,
        'field_image_width' => $record->field_image_width,
        'field_image_height' => $record->field_image_height,
      ];
    }
    $row->setSourceProperty('field_image', $images);

    // Tags
    $result = $this->getDatabase()->query('
      SELECT
        GROUP_CONCAT(fld.field_tags_tid) as tids
      FROM
        {field_data_field_tags} fld
      WHERE
        fld.entity_id = :nid
    ', array(':nid' => $nid));
    foreach ($result as $record) {
      if (!is_null($record->tids)) {
        $row->setSourceProperty('tags', explode(',', $record->tids) );
      }
    }

    return parent::prepareRow($row);
  }

  /**
   * {@inheritdoc}
   */
  public function getIds() {
    $ids['nid']['type'] = 'integer';
    $ids['nid']['alias'] = 'n';
    return $ids;
  }
}

Any idea about what I am doing wrong?
Answer: You might try using 'migration_lookup' instead of 'migration' as your process plugin. Here's what I used to migrate into an image field 'field_image'.
  field_image:
    plugin: iterator
    source: field_image
    process:
      target_id:
        plugin: migration_lookup
        migration: id_of_file_migration
        source: fid
      alt: alt
      title: title
      height: height
      width: width

Comment: Note that `iterator` plugin has been removed in Drupal 9.
https://www.drupal.org/node/2880427
Comment: In details: https://understanddrupal.com/lessons/introduction-migration-dependencies-drupal/
Answer: There is a example project at https://github.com/jigarius/drupal-migration-example/ that can help you fixing your problem.
This example module is explained in Drupal 8 Migration: Migrating Files / Images (Part 3). This is an important part that you need to knoww:

First we need to create file entities for each file. This is because
  Drupal treats files as file entities which have their own ID. Then
  Drupal treats node-file associations as entity references, referring
  to the file entities with their IDs.
Comment: Thanks Adrian, Actually example and blog is using csv method but i have done migration for other fields without csv, Is there any other method that can be implemented for images field.
Comment: @Aman, this is the only example that I know about this. But if you find the answer please write it here :-)

How do I migrate images?


Select XML nodes that contain substring in VB.net axis notation

Question: Using the VB.net axis operators (..././@)  how can I select/iterate nodes with a specific substring.
E.g.
Take some XML snippet like this:
<Route name="Fly from London Heathrow" distance="1192.88" duration="355">
 <IndicativePrice price="163" currency="USD" isFreeTransfer="0"/>
 <Stop name="Surbiton" pos="51.39301,-0.30677" kind="town"/>
 <Stop name="Kingston Upon Thames, Kingston" pos="51.41182,-0.3006" kind="station"/>
 <Stop name="London Heathrow" pos="51.47034,-0.45342" kind="airport" code="LHR"/>
 <Stop name="Barcelona" pos="41.30373,2.07315" kind="airport" code="BCN"/>
 <Stop name="Barcelona" pos="41.38702,2.17004" kind="city"/>
 [SO-point 1]
 <TransitSegment kind="bus" subkind="bus" vehicle="bus" isMajor="0" isImperial="1" ..."></TransitSegment>
 <TransitSegment kind="bus" subkind="bus" vehicle="bus" isMajor="0" isImperial="1" distance="18.4 ..."></TransitSegment>
 <FlightSegment kind="flight" isMajor="1" distance="1146.72" duration="120" sCode="LHR" tCode="BCN"></FlightSegment>
 <TransitSegment kind="train" subkind="train" vehicle="train" isMajor="0" isImperial="0" distance="25.07" duration="25" sName="Aeropuerto de Prat" sPos="41.30426,2.07352" sCode="7172400" tName="Barcelona P.Gracia" tPos="41.38725,2.16866" tCode="7100063" path=".."></TransitSegment>
 [SO-point 2]
</Route>

I can iterate the Stops like this:
For Each routeStop In route.<ns:Stop>
                Dim nextStop As New r2rSearchResponseRoutes.r2rSearchResponseStops
                nextStop.kind = routeStop.@kind
                nextStop.name = routeStop.@name
                nextStop.code = routeStop.@code
                nextStop.pos = routeStop.@pos

                nextRoute.listOfStops.Add(nextStop)
            Next

How would I select against any node that had a substring e.g. "Segment" in the node name like the example above?  Shown in above from [SO-point 1] to  [SO-point 2]
Answer: You need to use LINQ methods to filter XML nodes, for example :
For Each s As XElement In route.Elements().Where(Function(x) x.Name.LocalName.Contains("Segment"))
    Console.WriteLine(s.ToString())
Next