Can I use Principal Curves Analysis to fit a Vector Cloud instead of a Point Cloud?

Question: I have recently discovered Principal Curves while trying to solve the problem I will describe below.
The principle of Principal Curves is to fit a cloud point to find the "path" running along that points.
My goal is to use something like this to fit a set of GPS tracklogs running along a road, so that the result would be a statistical aproximation of the "real" road (or, more precisely, the region of the road where people - bikers in this case - ACTUALLY ride, which most probably would be side lanes and road shoulders).
The problem is: while classical Principal Curves Analysis consider the point set to have independent points, I believe it would be more appropriate to consider each track to be composed of dependent vectors.
When using points, for example, a track segment with high sampling rate might cause a bias when compared to another with lower sampling rate, although each of them describe only ONE trajectory each, and I am more interested in weighting the trajectories with one another instead of the individual points. (by the way, does that rationale of mine make sense?)
I posted a question on the same topic, but with different formulation, in the Gis.StackExchange site, with some representative pictures:
https://gis.stackexchange.com/questions/70623/how-can-i-statistically-calculate-the-real-road-from-a-set-of-gps-tracks
Thanks for reading!
Answer: This sounds like a functional data problem; the individual paths could be see as realisations from some underlying smooth curve (function) that you wish to estimate.
Jim Ramsay has a nice website on FDA with various examples, which may give you a flavour of what FDA is and what it can do.
Looking at @whuber's comment (in the gis.se Q&A) regarding the autocorrelation, that reminds me of some work of Rob Hyndman (@RobHyndman, also of this parish) on functional time series. This is not the same thing as @whuber mentions (the functional timeseries would view the individual realisations as being observed sequentially in time, i.e. the series of tracks represent a time series), but might give you ideas for how to consider handling the autocorrelation in the data.
As for principal curves, the smoothers that are fitted to each variable and that describe the location of the curve along that dimension are essentially plugin components of the technique, at least in the way Hastie & Steutzle originally described the method. You could quite easily adapt the principal curve code in the R package princurve to use a plugin smoother that fitted curves allowing for residual correlation, for example by basing the smoother plugin on the gamm() function from the mgcv package, which can apply certain correlation structures for the covariance matrix of the fitted model. Doing this is not too hard, technically; I've done this myself recently to use Poisson GAMs as the smoothers instead of simple smoothing splines.
If this looks like some half-baked suggestions, it is; I offer them as some observations seeing as the Question hadn't been Answered yet.
Comment: +1 This expresses some of the thoughts I had when I made that comment on GIS.SE. To go further, one can include data from a streets dataset which would (in effect) give strong information about what each GPS track is "trying" to approximate. Note that the *images* of GPS tracks on a map often are not smooth curves, but the tracks themselves *as functions of time* are smooth. Thus the timestamp (that automatically comes with GPS data, at least originally) is of crucial value in any analysis: that's one key way in which this is not exactly a "point cloud" fitting problem.
Comment: Gavin and @whuber you are helping me a hell of a lot! I will take a careful look at this as soon as I have some spare time (it's a hobby project). And, regarding timestamps, I believe they don't hold the "essence" of the track information, since equal tracks could be created with devices at different but complimentary speed vs sample-rate configurations. What is really important is the ORDER (the sequence) of points, I think. Thanks for now!


Why I cannot export vocabulary terms via Features?

Question: Ok, I've installed features, uuid, uuid_features.
According to docs vocab terms shouls be exported too when creating taxonomy feature.
So I run a command:

drush fe my_feature taxonomy:tags

but every time inside feature there is no such thing like terms. Only vocabulary is exported. What I am doing wrong?
From code review I see that only hook_taxonomy_default_vocabularies is implemented.
Comment: Ok, I've found way: https://anthonythecoder.wordpress.com/2014/06/10/exporting-taxonomy-terms-in-drupal-7/
Answer: You need to use the module uuid_features.
It is both possible to export individual terms by listing the ones you want or you can export all terms with the vocabulary:

Enable uuid_features
Go to admin/config/content/uuid_features
Check the boxes of the Vocabularies under "Exportable Taxonomy term bundles"

If you want to export all terms then check the "Auto detect uuid terms" option, so future additions / changes will be added.

If you didn't select the "Auto detect uuid terms" option: Do a drush fc and you will see a new item "uuid_term", get the list of components and do a drush fe FEATURENAME uuid_term:THETERMSUUID1 uuid_term:THETERMSUUID2 (gets really long, hence the "Auto detect uuid terms" option)
If you selected the "Auto detect uuid terms" option: you just need to export the taxonomy so do a  drush fe FEATURENAME taxonomy:VOCABNAME

Sorry about the odd bulletted list, trying to represent two options in one list.
Answer: The best way to export taxonomy terms without any extra modules is with update_hook_N() in your .install file.
Here's the code I use:
<code>/**
 * Insert terms for MYVOCAB vocabulary.
 */
function MYMODULE_update_7101() {
  $terms = array(
    'Term #1',
    'Term #2',
    'Term #3',
    '...',
  );
  // Check if term exists in vocabulary and add it if not.
  MYMODULE_safe_add_terms($terms, 'MYVOCAB');
}

/**
 * Helper function for adding terms to existing vocabularies.
 *
 * @param array $term_names
 * @param string $vocabulary_machine_name
 * @param int $weight
 */
function MYMODULE_safe_add_terms($term_names = array(), $vocabulary_machine_name = '', $weight = 100) {
  //  Make sure the vocabulary exists.  This won't apply all desired options
  //  (description, etc.) but that's okay.  Features will do that later.
  //  For now, we just need somewhere to stuff the terms.
  $vocab = taxonomy_vocabulary_machine_name_load($vocabulary_machine_name);

  // Load the vocabulary.
  // Check if field already exists and add it if not existing.
  if (is_object($vocab) && property_exists($vocab, 'vid') && $vocab->vid > 0) {
    //  Load each term.
    $i = 0;
    foreach ($term_names as $term_name) {
      $term = taxonomy_get_term_by_name($term_name, $vocabulary_machine_name);
      // Check if term exists and if it doesn't exist create a new one.
      if (count($term) == 0) {
        $term = (object)array(
          'name' => $term_name,
          'vid' => $vocab->vid,
          'weight' => $weight + $i,
        );
        // Save new term.
        taxonomy_term_save($term);
        $i++;
      }
    }
    drush_log($i . ' terms added to ' . $vocabulary_machine_name . ' vocabulary', 'notice');
  }
  else {
    drush_log('Vocabulary "' . $vocabulary_machine_name . '"" not found', 'error');
  }
}
</code>
Comment: That will only work if you already have the module enabled, since hook_update_N isn't called on install. hook_install doesn't work, because the vocabularies haven't been created by the feature yet.
Comment: Of course. That's why you first need to have the vocabulary created (with features or manually).
Having this hook_update_N() (even if you have it in the module where your features exports are - for the vocabulary) is good because you would be calling "drush features-revert-all" and after that "drush updb" to get the updates in.
Comment: But the feature defining the vocabulary has to have been enabled before adding the hook_update with the terms. You can't enable a new feature module that will both define the vocabulary AND add the terms without creating the vocabulary as part of hook_install.


How do I sketch (on paper) the scatter plot with given covariance matrix and expectation vector?

Question: I have found some information concerning my problem, but I am too unfamiliar with statistics to fully grasp the concepts explained. Also, much of the explanations are written for python/Matlab/R code, which I do not need. I hope you can help me out.
I am trying to answer a question from an exercise on multivariable normal distributions. The question is: based on the following expectation vectors and their corresponding covariance matrices, sketch (on paper!) the scatter plots that would appear if you'd take a large number of samples from the distributions. Given are:
$\mu_1 = \begin{pmatrix}0 \\ 0 \end{pmatrix}, \Sigma_1 = \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}$
$\mu_2 = \begin{pmatrix}3 \\ 2 \end{pmatrix}, \Sigma_2 = \begin{pmatrix} 4 & 0 \\ 0 & 1\end{pmatrix}$
$\mu_3 = \begin{pmatrix}3 \\ 2 \end{pmatrix}, \Sigma_3 = \frac{1}{\sqrt{10}}\begin{pmatrix} 1 & -3 \\ 3 & 1\end{pmatrix}\begin{pmatrix} 4 & 0 \\ 0 & 1\end{pmatrix}\frac{1}{\sqrt{10}}\begin{pmatrix} 1 & -3 \\ 3 & 1\end{pmatrix}^T$
I am at a loss how to start with the first one, which should be the easiest. However, I do recognise that the third covariance matrix is written in the form $UDU^T$. I do not wish the answer to this question, as I try to learn how to do it. Some help, though, would be much appreciated!
Answer: First you must understand the meaning of each entry in the mean vector and covariance matrix. Say, in case 1, the means are zero and the variables are uncorrelated (and independent as they are Gaussian). So, when you plot the variables on an X-Y axis (where X corresponds to the first variable and Y to the second), the x value will be determined independently of the second. This is what the off diagonals tell you, and they are zero.
So you will draw (no pun intended) samples from a zero-mean distribution and then you'll have your x value for the scatter plot, and you'll determine the y value similarly. Obviously, you see that if, for instance, your point has a high x value, it has no affect on the y value - it can be high, low, close to zero, etc.
Furthermore, we need to look at the diagonal value. In case 1, the variances of the variables are equal. Meaning, the effective 'width' or spread of the points on paper will be the same - so that if you, say, rotate the paper by 90 degrees, you'll see the same shape.
Now, what would happen if the means aren't zero? this is rather simple - the center of mass of your points will shift from the center to the mean, for each variable. Slightly more difficult is what happens if the variances are not equal. In this case, you'll need to draw the variable with the higher variance in a more 'spread' manner, regardless of its dependence in the other variable.
Finally, the most difficult part is the off diagonals in the covariance matrix - Say you have positive covariance between X and Y. Then, a high x value will likely go with a high y value, and vice versa - if they have negative correlation, then they'll tend to have values on opposite sides w.r.t the means (if the means are zero, negative correlation implies that when x is positive, y will tend to be negative, etc.).
Comment: Okay, thanks! I now understand that the expectation vector determines the center of my plot (in case of the first (0,0)), so that's a start. I also understand from your answer that the shape is dependent on the covariance matrix: if the matrix has the same values, it's a circle, right? However, how do I determine the radius of the circle?
Comment: This is what I meant by width or spread - the diagonals in the covariance determine the radius. If they're equal then it's a circle, and if they're unequal then it's an ellipse.
Comment: Right! So I figured the first one should be a circle with radius 3, the second one an ellipse with axis 3 and 6 (because that would be determined by the standarddeviation i.e sqrt(variance)). However, the last one is a bit tricky now.. what does the 1/sqrt(10) mean, and how to I draw the ellipse? (thank you for helping me out, anyway!)
Comment: One of the ways to interpret this is to calculate the matrix multiplication and then use the covariance matrix you obtain to draw what will be the rotated elipse describing the distribution.


How to change native-base Picker fontSize and fontFamily in React Native

Question: I have a Picker in my component. Is there any way to set fontSize and fontFamily?
I tried:
style={{fontFamily:'iransans',fontSize:14}}

and
itemTextStyle={{fontFamily:'iransans',fontSize:14}}

but neither of them worked for me.
<Picker
note
mode="dropdown"
style={{fontFamily:'iransans',fontSize:14 }}
itemTextStyle={{fontSize:16}} ...

Answer: `

`
Comment: Please read "[Explaining entirely code-based answers](https://meta.stackoverflow.com/q/392712/128421)". While this might be technically correct it doesn't explain why it solves the problem or should be the selected answer. We should educate in addition to help solve the problem.


Two infinite series converge, prove product converges

Question: If $$\sum_{k=1}^\infty a_k^2$$
and
$$\sum_{k=1}^\infty b_k^2$$
are both convergent.
Prove that the following infinite series is convergent:
$$\sum_{k=1}^\infty a_kb_k$$
$\\$
I am not fully sure how to go about this. This is all the info given in the problem and I think I'm just missing some sort of fundamental concept. Could anyone please explain the general idea behind this? I'd appreciate if you didn't just explicitly give me the answer, but maybe just a foundational piece to get me going as I really want to get this one by myself!
Comment: Do you know the Cauchy Schwarz inequality? This follows from that
Comment: Yes, geometric-quadratic mean works also, resp. the summation of $0\le(b-a)^2\implies ab\le\frac12(a^2+b^2)$.
Comment: We haven't used that in this chapter yet. Could I also try using the AM-GM inequality?? I think I just tried that and it worked out if at the end I apply the comparison test!
Comment: I do not know whether the AM-GM is sufficient for solving this question. I won't say don't give it a try, but I'm skeptical about it.
Comment: @LutzL It would be better to write this $|ab|\leq \dfrac12(a^2+b^2)$, in the present case, but it's a good hint!
Comment: I used the wrong name. The one mentioned by LutzL and Jean-Claude above is what I used! I figured it out. Thanks for the verification and help. I appreciate everyone's replies.
Answer: The standard way of doing this is via the Cauchy-Schwarz inequality: https://en.wikipedia.org/wiki/Cauchy%E2%80%93Schwarz_inequality


When solving a system of equations for a game theory question, can the solutions be negative?

Question: I have a homework question on solving a game matrix geometrically.
$m =$ $\begin{bmatrix}1 & 11\\7 & 2\end{bmatrix}$
(after adding the constant $k$ to ensure it's a positive matrix)
The first of the linear programming problem I got from this was:
$Minimize$
$$C = x + y$$
$Subject$ $to$
$$x + 7y >= 1$$
$$11x + 2y >= 1$$
$$x + y >= 0$$
I then rearranged the equations, solved for the intersections algebraically, and got the following solution "corners":
$$x = 1/15, y = 2/15, x + y = 3/15 $$
$$x = -1/6, y = 1/6, x + y = 0 $$
$$x = 1/9, y = -1/9, x + y = 0 $$
Since the goal is to minimize $x + y$, the bottom 2 solutions seem to both be equally correct (since they're both $0$). When I checked the answer using the following calculator though, it's saying that the answer is the first solution I got ($x = 1/15, y = 2/15$):
Simplex Solver
I haven't supplied any constraints saying that either $x$ or $y$ can't be negative. Why is the first solution the correct one?
Comment: Whoops! I'm sorry. I forgot the ensure the original constraints were met. I just graphed it, and both of the 0 resulting solutions violate one of the constraints. My bad.
Answer: The conditions $x\ge0,y\ge0$ are stronger than the condition $x+y\ge 0$.
If your maximum over all $(x,y)$ such that $x+y\ge0$ happens to have both $x$ and $y$ positive, then it is also feasible when you maximize over all $(x,y)$ such that $x\ge0,y\ge0$.
It also is better than any $(x,y)$ where $x\ge 0,y\ge 0$, since all of these points are included in the set of all $(x,y)$ such that $x+y\ge 0$.
So it's the maximum over the smaller set as well.


Number of elements in a squared set

Question:
If $S= \{\emptyset, 5, \{1,5\}\}$, how many elements does $S^2$ have?

The answer to this question was given to be $9$, as $S$ has three elements so $S^2$ will have $9$, however, for example, by the principles of a cartesian product, there will be an element in which $\emptyset$ is multiplied by $\emptyset$, which I understand just to be $\emptyset$, which would mean that there would be less than $9$ elements.
Is my understanding flawed and there are indeed $9$ elements?
Comment: Can you quote which principle of a cartesian product you are referring to? It would appear you have a misunderstanding.
Comment: "There will be an element in which $\emptyset$ is **multiplied by** $\emptyset$"  uhm... no?  Nothing is being multiplied here...  there are only things being put into pairs.
Comment: Ah that would be it. Thanks
Comment: Take for smaller example $\color{red}{A=\{\emptyset,1\}}$ and $\color{blue}{B=\{2,\{3\}\}}$.  One would have $\color{red}{A}\times\color{blue}{B}=\{(\color{red}{\emptyset},\color{blue}{2}),(\color{red}{\emptyset},\color{blue}{\{3\}}),(\color{red}{1},\color{blue}{2}),(\color{red}{1},\color{blue}{\{3\}})\}$
Answer: The Cartesian product merely assembles the elements of two sets in order. Here's is an excerpt from Wikipedia:

... for sets $A$ and $B$, the Cartesian product $A \times B$ is the set of all ordered pairs $(a, b)$ where $a \in A$ and $b \in B$.

In your specific example, the product will consist of the nine pairs $(\varnothing,\varnothing),(\varnothing,5),(\varnothing,\{1,5\}), (5,\varnothing), (5,5), (5, \{1,5\}), (\{1,5\},\varnothing), (\{1,5\}, 5),$ and $(\{1,5\},\{1,5\})$.
In general, the notion of "multiplication" between set elements is ill-defined.

Number of elements in a squared set


Absolutely continuous, integral, limit

Question: This is exercise from Folland (chapter 6. excercise 34.):
If f is absolutely continuous on $[\epsilon, 1]$ for $0<\epsilon<1$ and $\int_0^1 x|f'(x)|^p dx<\infty$, then:

$\lim_{x\rightarrow\infty}f(x)$ exists (and is finite) if $p>2$,
$\frac{|f(x)|}{|\log x|^{1/2}}\rightarrow 0$ as $x\rightarrow 0$ if $p=2$, and
$\frac{|f(x)|}{x^{1-2/p}}\rightarrow 0$ as $x\rightarrow 0$ if $p<2$.

I don't know how to start, and would appreciate some hints.
Answer: You want to understand the behavior of $f(x)$ as $x\to 0$, knowing something about $f'$. It is natural to  begin with FTC and triangle inequality:
$$|f(x)|=\left|f(b)-\int_x^b f'(t)\,dt\right| \le |f(b)|+\int_x^b \left|f'(t)\right|\,dt \tag1$$
Then

 relate the integral on the right side of (1) to $\int_x^b t|f'(t)|^p dt$ using Hölder's inequality.

While doing so,

 you may have to decide whether to keep $b$ fixed (good enough for getting an upper bound on $|f|$) or to make it close to $0$ (may be able to get the Cauchy property, hence the existence of limit).
Comment: @Ana All you know (and need to know) about $\int t|f'(t)|^p dt$ is that it's some finite number. The fact that it's raised to power $1/p$ is of no importance. If $C$ is a number you don't know, then $C^{1/p}$ is just another number you don't know. Well, perhaps in some cases you will choose $b$ small to make the integral small; then the integral to $1/p$ will be small too.... But the important integral is the other one that you get from Holder's inequality, with $|f'|$ and other things in it. The behavior of this integral depends on $p$.
Comment: I'm trying to write it down but don't see how to deal with $1/p$ I get on $\left(\int t|f'(t)|^p dt\right)^{1/p}$ after applying Holder. Also why are there conditions on values of p?
Comment: I've thought about that but then I'm not doing the other integral right because i get this: $\int_{\epsilon}^1|f'(x)|dx \leq \int_0^1|f'(x)|dx=\int_0^1x^px^{1/p}|f'(x)|dx\leq \left(\int_0^1x^{pq}dx\right)^{1/q}\left(\int_0^1x|f'(x)|^pdx\right)^{1/p}$. Then I focus on $\int_0^1x^{pq}dx$, which is bounded if $p\cdot q=\frac{p-1}{p^2+p-1}>0$, but I don't get $p>2$??? Guess I'm doing something wrong?

Absolutely continuous, integral, limit


Add alert to tradingview plotshape

Question: I have this code  and i want to add an alert condition every time the plotshape signal is show.
    //@version=4
study("Bollinger Band Bounce", overlay=true)

//Bollinger Band
source = close
length = input(15, minval=1), mult = input(2.0, minval=0.001, maxval=50)
basis = sma(source, length)
dev = mult * stdev(source, length)
upper = basis + dev
lower = basis - dev
//plot(basis, color=#FF0000)
p1 = plot(upper, color=#0000FF)
p2 = plot(lower, color=#0000FF)
fill(p1, p2)

BBB=iff(((open-lower)/(upper-lower)*100)<30 and (close>close[1]),open,0)

plotshape(BBB,color=#0000ff ,style=shape.labeldown)

Any help would be appreciated
Answer: Is this the code you want?
Because the alert will show once per bar, so if you are on the timeframe 4H, you should do this:
BBB4H =  security(syminfo.tickerid, "240", BBB, barmerge.gaps_off, barmerge.lookahead_on)

and then go to 1 minute chart to set the alert
if (BBB4H)
    alert("Alert", alert.freq_once_per_bar)

Add alert to tradingview plotshape


Prevent radiobutton click

Question: I have a win form, on which there are several radionbuttons and labels and some other controls wich I am generating at run time. Not what I want when I check a radiobutton, all the radionbutton should be unchecked except the one I checked. This applies to every radiobutton. In short, I want one radionbutton checked at a time.
 private RadioButton GenerateRadioButton(string id)
        {
            RadioButton _radioButton = new RadioButton();
            _radioButton.Location = new Point(32, 20);
            _radioButton.Margin = new Padding(4, 4, 4, 4);
            _radioButton.Size = new Size(130, 36);
            _radioButton.Name = id;
            _radioButton.AutoSize = true;
            _radioButton.Font = new Font("Arial", 16, FontStyle.Bold);
            _radioButton.CheckedChanged += new System.EventHandler(RadioButton_CheckedChanged);
            return _radioButton;
        }

  private void RadioButton_CheckedChanged(object sender, EventArgs e)
        {
          HandleRadioButtinClick(((RadioButton)sender).Name);
            ((RadioButton)sender).Checked = true;
        }

     private void HandleRadioButtinClick(string ctrlId)
            {
                FrmSpace objFrmSpace = new FrmSpace();
                foreach (Control ctrl in pictureBox1.Controls)
                {
                    if (ctrl is Panel)
                    {
                        foreach (Control ctl in ctrl.Controls)
                        {
                            if (ctl is RadioButton && ctl.Name != ctrlId)
                                ((RadioButton)ctl).Checked = false;
                        }
                    }
                }
            }

Here is the code above. The problem with this code is that, when I check a radiobutton, if there is any other radiobutton that is checked, and I try to uncheck it, its checkedchanged event is also fired, that causes all the radiobutton unchecked again. I hope I am clear what I want to convey.
Please provide some solution.
Thanks
Comment: Why are you manually un-checking the radio buttons? Why don't you group them which will handle this part.
Comment: I would love to do that. But could you please tell, how to group them while generating them at run time?
Comment: While adding them to form add them to a group box instead to a form.
Comment: Like Jeremy has posted below.
Comment: Its not working with groupbox either.
Answer: Have you tried using a groupbox for all of the radiobuttons? This is the default function you are asking for.
EDIT : to clarify your questions
        // some function
        GroupBox g = createGBox();
        this.Controls.Add(g);
        g.Controls.Add(radioButton1);
        g.Controls.Add(radioButton2);
    }

    public GroupBox createGBox()
    {
        GroupBox gBox = new GroupBox();
        gBox.Location = new System.Drawing.Point(72, 105);
        gBox.Name = "BOX";
        gBox.Size = new System.Drawing.Size(200, 100);
        gBox.Text = "This is a group box";
        return gBox;
    }

Comment: I have a picturebox, then I create panels at run time and add it to picture box. Then I create label and radiobutton then I add them in panel. Each panel has a set of one radiobutton and one label.
Comment: Groupbox will still be able to work. Just replace groupbox instead of the panel that holds the radiobuttons. Check out the link. Groupbox has a label built-in you can use too.
Comment: Is there any property for groupbox, that I need to setup. Actually its not working. Same result as panel.
Comment: Check the edit. Did you remove the event that you created for your radiobuttons? If this answer helped please mark as so.
Comment: Thanks alot. Not fully full filled my requirement but it helped. I am accepting your answer.
Answer: Put all radiobuttons into the same GroupBox control, which you can create at runtime too. In this case the expected behaviour should be handled by control itself, without need of coding.
Hope this helps.
Comment: If I take a groupbox at design time and add panels (containing radiobutton and labels) at run time to this groupbox . It will work?
Comment: Imo, no, you need GroupBox, like a prime parent. Why do you wan to use a Panel? Add directly to GroupBox.

Prevent radiobutton click


When is distance covariance less appropriate than linear covariance?

Question: I've just been introduced (vaguely) to brownian/distance covariance/correlation. It seems particularly useful in many non-linear situations, when testing for dependence. But it doesn't seem to be used very often, even though covariance/correlation are often used for non-linear/chaotic data.
That has me thinking that there might be some drawbacks to distance covariance. So what are they, and why doesn't everyone just always use distance covariance?
Comment: For reference, I created a [distance correlation version](https://en.wikipedia.org/wiki/Distance_correlation) of the [correlation graph on wikipedia](https://en.wikipedia.org/wiki/Correlation)
Comment: I read that you were using dcov to compare non linear time series and combine them with weight..I was wondering if what you did is using a weighted distance covariance..meaning that you gave different weights to your data using a weight vector to calculate the distance correlation? I'm trying to do that but I'm not sure if introducing a weight vector into the distance correlation formulas is the right way to go.
Comment: No, sorry @user3757561, I was just trying distance correlation as a replacement for correlation, and then creating weights based on that. But I didn't end up using it anyway...
Answer: I have tried to collect a few remarks on distance covariance based on my impressions from reading the references listed below. However, I do not consider myself an
expert on this topic. Comments, corrections, suggestions, etc. are welcome.
The remarks are (strongly) biased towards
potential drawbacks, as requested in the original question.
As I see it, the potential drawbacks are as follows:

The methodology is new. My guess is that this is the single
 biggest factor regarding lack of popularity at this time. The
 papers outlining distance covariance start in the mid 2000s and
 progress up to present day. The paper cited above is the one that
 received the most attention (hype?) and it is less than three years
 old. In contrast, the theory and results on correlation and
 correlation-like measures have over a century of work already
 behind them.
The basic concepts are more challenging. Pearson's
 product-moment correlation, at an operational level, can be
 explained to college freshman without a calculus background
 pretty readily. A simple "algorithmic" viewpoint can be laid
 out and the geometric intuition is easy to describe. In contrast, in the case of distance covariance, even the notion of sums of products of pairwise Euclidean
 distances is quite a bit more difficult and the notion of
 covariance with respect to a stochastic process goes far beyond
 what could reasonably be explained to such an audience.
It is computationally more demanding. The basic algorithm for
 computing the test statistic is $O(n^2)$ in the sample size as
 opposed to $O(n)$ for standard correlation metrics. For small
 sample sizes this is not a big deal, but for larger ones it
 becomes more important.
The test statistic is not distribution free, even
 asymptotically. One might hope that for a test statistic that is
 consistent against all alternatives, that the
 distribution—at least asymptotically—might be
 independent of the underlying distributions of $X$ and $Y$ under
 the null hypothesis. This is not the case for distance covariance
 as the distribution under the null depends on the underlying
 distribution of $X$ and $Y$ even as the sample size tends to
 infinity. It is true that the distributions are uniformly
 bounded by a $\chi^2_1$ distribution, which allows for the
 calculation of a conservative critical value.
The distance correlation is a one-to-one transform of $|\rho|$ in
 the bivariate normal case. This is not really a drawback, and
 might even be viewed as a strength. But, if one accepts a
 bivariate normal approximation to the data, which can be quite
 common in practice, then little, if anything, is gained from
 using distance correlation in place of standard procedures.
Unknown power properties. Being consistent against all
 alternatives essentially guarantees that distance covariance must
 have very low power against some alternatives. In many cases, one
 is willing to give up generality in order to gain additional
 power against particular alternatives of interest. The original
 papers show some examples in which they claim high power relative
 to standard correlation metrics, but I believe that, going back
 to (1.) above, its behavior against alternatives is not yet well
 understood.

To reiterate, this answer probably comes across quite negative. But,
that is not the intent. There are some very beautiful and interesting
ideas related to distance covariance and the relative novelty of it
also opens up research avenues for understanding it more fully.
References:

G. J. Szekely and M. L. Rizzo (2009), Brownian distance
covariance, Ann. Appl. Statist., vol. 3, no. 4, 1236–1265.
G. J. Szekely, M. L. Rizzo and N. K. Bakirov (2007), Measuring and
testing independence by correlation of distances, Ann. Statist.,
vol. 35, 2769–2794.
R. Lyons (2012), Distance covariance in metric spaces,
Ann. Probab. (to appear).
Comment: When both random variables are univariate the distance correlation can be computed in $\mathcal{O}(n \log n)$ time, see https://www.tandfonline.com/doi/abs/10.1080/00401706.2015.1054435 for example.
Comment: See also Summary and discussion of: "Brownian Distance Covariance"
Statistics Journal Club, 36-825 Benjamin Cowley and Giuseppe Vinci
October 27, 2014 http://www.stat.cmu.edu/~ryantibs/journalclub/dcov.pdf
Comment: Excellent answer, thank you. Some of it is a bit over my head, but I think I'll be able to remedy that myself :)
Answer: I could well be missing something, but just having a quantification of the nonlinear dependence between two variables doesn't seem to have much of a payoff.  It won't tell you the shape of the relationship.  It won't give you any means to predict one variable from the other.  By analogy, when doing exploratory data analysis one sometimes uses a loess curve (locally weighted scatterplot smoother) as a first step towards seeing whether the data are best modeled with a straight line, a quadratic, a cubic, etc.  But the loess in and of itself is not a very useful predictive tool.  It's just a first approximation on the way to finding a workable equation to describe a bivariate shape.  That equation, unlike the loess (or the distance covariance result), can form the basis of a confirmatory model.
Comment: @PraneethVepakomma: check out my answer at http://stats.stackexchange.com/questions/562/when-to-use-multiple-models-for-prediction/25127#25127
Comment: Also, if you know the general form of dependence (e.g., polynomial equation), then you may quantify the strength of the dependence using the coefficient of determination, see, e.g., [Computing Adjusted R2 for Polynomial Regressions](https://www.mathworks.com/help/matlab/data_analysis/linear-regression.html#bswinlz)
Comment: For my purposes, it does have a payoff. I'm not using dcov() for predicting anything, rather, comparing multiple non-linear time-series in an ensemble, and combining them with weights based on their dependence. In this situation, dcov() has potentially large benefits.
Comment: @naught101 Can you put in some m ore info.- when you say -'combine'? This sounds interesting to me in terms of weighting based on nonlinear dependence. Do you mean- categorizing the time series into groups? Also-what do high and low weights emphasize in this scenario?


Question missing condition in Royden Exercise 7.42 b, about Baire Category

Question: In Royden's Real Analysis  P164 Q7.42b,
   It assumes that $X$ and $Y$ are complete metric spaces. Let $O$ be a dense open set in $X \times Y$.
   Assertion: Then there is a $G \subset X$ which is a dense $G_\delta$ such that $E_x = \{  y \in Y : (x,y) \in O \}$ is a dense open subset of $Y$ for each $x \in G$.
My question is: I think there is a missing condition in the question.
For general $Y$, I am not sure that this holds. However, if we assume $Y$ is second countable, then the assertion holds.
I think this is just a version of the Kuratowski-Ulam Theorem. In the Oxtoby book, there is some requirements on $Y$.
Thanks.
Comment: There's a pretty substantial list of errata on the new coauthor's site (Fitzpatrick, I think the name is?). Did you check there?
Comment: Errata for the 1st printing of the 4th ed. are [here](http://www-users.math.umd.edu/~pmf/RAE.pdf); this appears to be a different edition from yours, but I didn't see anything obviously corresponding to this question.
Comment: Yes. I have already checked the 4th edition. This question is not there.
Answer: Yes, a hypothesis is definitely missing. The usual proof requires that $Y$ have a countable $\pi$-base, i.e., a countable family $\mathscr{C}$ of non-empty open sets such that every non-empty open subset of $Y$ contains a member of $\mathscr{C}$; here's an example showing that the result can fail in the absence of such a hypothesis.
Let $Y=[0,1]\times[0,1]$, and define a metric $d$ on $Y$ as follows:
$$d\Big(\langle x,a\rangle,\langle y,b\rangle\Big)=\begin{cases}
|x-y|,&\text{if }a=b\\
2,&\text{if }a\ne b\;.
\end{cases}$$
It's easy to check that $d$ is a complete metric. It will be convenient to let $Y_a=\{\langle x,a\rangle:x\in[0,1]\}$ for each $a\in[0,1]$; note that $Y_a$ is open in $Y$.
Let $X=[0,1]$ with the usual topology; $X\times Y$ is the disjoint union of the clopen subsets $X\times Y_a$ for $a\in[0,1]$, and each of these subsets is homeomorphic to $[0,1]\times[0,1]$ with the usual topology.
Now let
$$O=\left\{\Big\langle x,\langle y,a\rangle\Big\rangle\in X\times Y:x\ne a\right\}\;.$$
For each $a\in[0,1]$, $O\cap\Big(X\times Y_a\Big)$ is homeomorphic to $\Big([0,1]\setminus\{a\}\Big)\times[0,1]$ with the usual topology and therefore is dense and open in $X\times Y$, so $O$ itself is dense and open in $X\times Y$. But for each $x\in X$, $E_x=\{\langle y,a\rangle\in Y:a\ne x\}$, which is disjoint from $Y_x$ and therefore not dense in $Y$. That is, $\{x\in X:E_x\text{ is dense and open in }Y\}=\varnothing$.
Comment: Thanks for your answer. Here is a slightly simplified example:  Let $Y$ be $[0,1]$ with the discrete topology, i.e. $d(x,y) = 2$ if $x \ne y$, and let $X$ be $[0,1]$ with the usual metric. Then $O = \{(x,y) | x \ne y \}$ is an open and dense set in $X \times Y$. Hence, for any $x \in X$, $ E_x = \{y \in Y | y \ne x \} $ is an open and closed set in $Y$.


C# Have to run code twice to work - Geo locator

Question: im programming some code which when a button is pressed, it will output your gps co ordinates. For some reason it only works when i click it twice or more. even if i wait a minuite and then click it, i have to click it again for it to work and im not sure why. here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Device.Location;

namespace Location
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        GetLocation();
    }

    static void GetLocation()
    {
        GeoCoordinateWatcher GEOWatcher = new GeoCoordinateWatcher();

        GEOWatcher.TryStart(false, TimeSpan.FromMilliseconds(1000));

        GeoCoordinate Coordinates = GEOWatcher.Position.Location;

        if (Coordinates.IsUnknown != true)
        {
            Console.WriteLine("Latitude: " + Coordinates.Latitude + ", Longitude: " + Coordinates.Longitude);
            Console.WriteLine("https://www.google.co.uk/#q=" + Coordinates.Latitude + "," + Coordinates.Longitude);

            GEOWatcher.Dispose();
        }
        else
        {
            Console.WriteLine("Location currently unavaliable");
        }
    }
}
}

any help is appriciated, also if you have any tips or improvments on my code please comment them, thanks
Comment: Have you tried increasing the time out value?
Comment: yes that doesnt do anything
Answer: When you indicate it "does not work" what are you actually saying?
Are you saying that you get the message "Location currently unavailable"? If so, this is probably because it takes some time for the GPS unit in the device to get locks on the satellites.
Edit below to explain my comment below:
The GeoCoordinateWatcher will need some time to lock onto the satellites and provide a consistent result. Moving the GeoCoordinateWatcher into the class itself (so it doesn't get garbage collected when the button click event ends) will provide some relief, but it still wont be able to give you a result as soon as you start the app. Something like this:
public partial class Form1 : Form
{
    GeoCoordinateWatcher GEOWatcher;

    public Form1()
    {
        InitializeComponent();
        // this will start the GeoCoordinateWatcher when the app starts
        GEOWatcher = new GeoCoordinateWatcher();
        GEOWatcher.TryStart(false, TimeSpan.FromMilliseconds(1000));
    }

    private void button1_Click(object sender, EventArgs e)
    {
        GetLocation();
    }

    static void GetLocation()
    {
        GeoCoordinate Coordinates = GEOWatcher.Position.Location;

        if (Coordinates.IsUnknown != true)
        {
            Console.WriteLine("Latitude: " + Coordinates.Latitude + ", Longitude: " + Coordinates.Longitude);
            Console.WriteLine("https://www.google.co.uk/#q=" + Coordinates.Latitude + "," + Coordinates.Longitude);

        }
        else
        {
            Console.WriteLine("Location currently unavaliable");
        }
    }
}

Comment: Yeh thats what i meant. but even so i can give it a minuite or 2 and press it once and it still says unavaliable till i click it again
Comment: @Will as you have the GeoCoordinateWatcher in the same scope as the button, the GeoCoordinateWatcher will need to start from scratch again every time you click the button. Try moving the GeoCoordinateWatcher into the class itself.
Comment: oh thats fixed it, i moved the geowatcher outside the button and it works everytime now, thanks


How do I graph a transformed rational function?

Question: If the function is $-\frac{5}{x+3} + 2$ how would I graph that without using a table of values? Do I just use the asymptotes $x=-3$, and $y= 2$ and draw the general shape? Do I use "mapping points" like $(x-3, -5y+2)$?
Comment: The asymptote would be $x=-3$, not $x=3$
Comment: Woops, ok, x=-3. Now what?
Answer: One way to graph the function
$$f(x) = -\frac{5}{x + 3} + 2$$
is to apply the series of transformations
$$\frac{1}{x} \to -\frac{1}{x} \to -\frac{5}{x} \to -\frac{5}{x + 3} \to -\frac{5}{x + 3} + 2$$
We start with the graph of $y = 1/x$.  The $x$- and $y$-axes are, respectively, the horizontal and vertical asymptotes of the graph.

We can obtain the graph of $y = -1/x$ from the graph of $y = 1/x$ by reflecting the graph in the $x$-axis.

We can obtain the graph of $y = -5/x$ from the graph of $y = -1/x$ by stretching the graph of $y = -1/x$ vertically by a factor of $5$.

We can obtain the graph of $y = -5/(x + 3)$ from the graph of $y = -5/x$ by shifting the graph of $y = -5/x$ to the left by three units.  The vertical line $x = -3$ that is shown in red is the translated vertical asymptote.

Finally, we can obtain the graph of the function
$$f(x) = -\frac{5}{x + 3} + 2$$
from the graph of $y = -5/(x + 3)$ by translating the graph of $y = -5/(x + 3)$ upwards by two units.  The horizontal line $y = 2$ is the translated horizontal asymptote.  The vertical line $x = 3$ is the vertical asymptote.

I opted to use a larger graph for the final function in order to illustrate its asymptotic behavior.
Alternate Method:  We solve for the intercepts and asymptotes, then perform a line analysis.
$x$-intercept:  Setting $f(x) = 0$ yields
\begin{align*}
-\frac{5}{x + 3} + 2 & = 0\\
2 & = \frac{5}{x + 3}\\
2x + 6 & = 5\\
2x & = -1\\
x & = -\frac{1}{2}
\end{align*}
$y$-intercept:  Evaluating the function at $x = 0$ yields
\begin{align*}
f(0) & = -\frac{5}{0 + 3} + 2\\
     & = -\frac{5}{3} + \frac{6}{3}\\
     & = \frac{1}{3}
\end{align*}
horizontal asymptote:  As $|x| \to \infty$, the term
$$-\frac{5}{x + 3} \to 0$$
so
$$y = -\frac{5}{x + 3} + 2 \to 2$$
the horizontal asymptote is the line $y = 2$.
vertical asymptote:  Since the denominator of
$$f(x) = -\frac{5}{x + 3} + 2 = -\frac{5}{x + 3} + \frac{2x + 6}{x + 3} = \frac{2x + 1}{x + 3}$$
vanishes at $x = 3$ and the numerator does not, $x = -3$ is the vertical asymptote of the function's graph.
line analysis:  The function can only change sign at an $x$-intercept or a vertical asymptote.  Therefore, its sign is constant in the intervals $(-\infty, -3)$, $(-3, 1/2)$, and $(1/2, \infty)$.  The function is equal to $0$ at the $x$-intercept $1/2$ and undefined at $x = 3$ since it has a vertical asymptote there.  Expressing the function in the form
$$f(x) = \frac{2x + 1}{x + 3}$$
we see that its sign is the product of the signs of the dividend $2x + 1$ and divisor $x + 3$.  The divisor is negative when $x < -3$, $0$ at $x = -3$, and positive when $x > 3$.  The dividend is negative when $x < -1/2$, $0$ at $x = -1/2$, and positive when $x > 1/2$.  Hence, the quotient is positive when $x < 3$, undefined at $x = -3$, negative when $-3 < x < -1/2$, zero at $x = -1/2$, and positive when $x > 1/2$.

Thus, when $x < -3$, we draw the curve in the region above the horizontal asymptote $y = 2$, and when $x > -3$, we draw the curve in the region below the horizontal asymptote so that it passes through the $x$- and $y$-intercepts, as shown above.
Comment: How do you stretch the graph by a factor of 5? Do you multiply every y-value by 5?
Comment: That is correct.
Comment: I have added an alternate approach that is more useful for more complicated rational functions.


The meaning of $N_{K/K(a)}$

Question: I am in the proof of the theorem of Artin-Schreier, where $K$ is a field with $\text{char}(K)=p$, and $p$ is a prime number. There I have discovered the following notation:
$$N_{K(a)/K}(\beta)$$
What does it mean?
Comment: By the way, currently the title says $N_{K/K(a)}$. I assume this should be $N_{K(a)/K}$...? If so, please edit your question so that it says so
Answer: I believe it's the field norm:
If $L\supseteq K$ is a finite field extension, then multiplication by some $x\in L$ can be given in matrix form. The determinant of this matrix is $N_{L/K}(x)$, the field norm.
See Wikipedia (etc.) for more information.

The meaning of $N_{K/K(a)}$


How to derive the likelihood ratio test for the Poisson distribution?

Question: I am stumped as to how to find the one-sided LRT for the Poisson distribution. The majority of the examples I am finding are for two-sided tests, which does not give all that much help. If you have links to any websites, those would be very useful.
Comment: The procedure remains same, i.e. forming the likelihood ratio statistic $\Lambda(x_1,\ldots,x_n)=\frac{\sup_{\theta\le \theta_0}L(\theta\mid x_1,\ldots,x_n)}{\sup_{\theta}L(\theta\mid x_1,\ldots,x_n)}$ where $L$ is the likelihood and rejecting $H_0$ for small values of $\Lambda$. So first find the restricted and unrestricted maximum likelihood estimators of $\theta$.
Answer: If anything, the one-sided case is simpler than the two-sided case, since the evidence in favour of the alternative hypothesis is only in one direction with respect to the sufficient statistic.  Let's work through the problem to have a look a the test in this case.
Since $X_1,...,X_n \sim \text{IID Pois}(\theta)$ you can easily establish that the log-likelihood function is:
$$\ell_\mathbf{x}(\theta) = T(\mathbf{x}) \log(\theta) -n \theta
\quad \quad\ \quad \text{for all } \theta>0,$$
where $T(\mathbf{x}) \equiv \sum x_i$ is the sample total, which is a sufficient statistic for the parameter $\theta$.  Moreover, using a well-known result for the Poisson distribution, it can be shown that $T(\mathbf{X}) \sim \text{Pois}(n\theta)$.

Now, suppose you have hypotheses $H_0: \theta \leqslant \theta_0$ and $H_1: \theta > \theta_0$.  Then from the Neyman-Pearson lemma we know that the UMP test is the likelihood-ratio test, which in this case is equivalent to a monotone test on the sample mean.  Since the alternative hypothesis is for a larger rate parameter, a higher sample mean constitutes evidence in favour of the alternative hypothesis.  Hence, the p-value function for the test is:
$$\begin{equation} \begin{aligned}
p(\mathbf{x})
\equiv \sup_{H_0} \mathbb{P}(T(\mathbf{X}) \geqslant T(\mathbf{x})|\theta)
&= \sup_{\theta \leqslant \theta_0} \mathbb{P}(T \geqslant T(\mathbf{x})|T \sim \text{Pois}(n\theta)) \\[6pt]
&= \mathbb{P}(T \geqslant T(\mathbf{x})|T \sim \text{Pois}(n\theta_0)) \\[12pt]
&= 1-\mathbb{P}(T < T(\mathbf{x})|T \sim \text{Pois}(n\theta_0)) \\[6pt]
&= 1-\sum_{t = 0}^{T(\mathbf{x})-1} \frac{\theta_0^x e^{-\theta_0}}{x!}. \\[6pt]
\end{aligned} \end{equation}$$
The p-value function fully determines the test, and so this constitutes a full specification of the test.  As can be seen, the p-value is just the upper-tail of the Poisson distribution with parameter $n \theta_0$.

Implementing the test: It is relatively simple to program this test in R using the standard method for programming a hypothesis test.  Here we will program a more general version of the test that allows you to stipulate the alternative to be greater or less than the null.  (For brevity, we will not include the two-sided test.)
Poisson.rate.test <- function(X, theta0, alternative = "greater") {

#Check validity of inputs
if(!is.numeric(X))      { stop("Error: Data should be numeric"); }
if(length(X) == 0)      { stop("Error: You require at least one observation"); }
if(all(X != as.integer(X)))  { stop("Error: Data should be non-negative integers"); }
if(min(X) < 0)          { stop("Error: Data should be non-negative integers"); }
if(!is.numeric(theta0)) { stop("Error: Parameter theta0 should be numeric"); }
if(length(theta0) != 1) { stop("Error: Parameter theta0 should be a scalar"); }
if(theta0 <= 0)         { stop("Error: Parameter theta0 should be positive"); }
if(!(alternative %in% c("greater", "less")))
                        { stop("Error: Alternative must be 'greater' or 'less'"); }

#Set description of test and data
method      <- "Poisson rate test (one-sided)";
data.name   <- paste0(deparse(substitute(X)));

#Set null hypothesis value
null.value  <- theta0;
attr(null.value, "names") <- "rate parameter";

#Calculate test statistics
n           <- length(X);
estimate    <- mean(X);
attr(estimate, "names") <- "estimated rate";
statistic   <- n*estimate;
attr(statistic, "names") <- "sample total";

#Calculate p-value
if (alternative == "less") {
  p.value   <- ppois(statistic, lambda = n*null.value,
                     lower.tail = TRUE,  log.p = FALSE); }
if (alternative == "greater") {
  p.value   <- ppois(statistic, lambda = n*null.value,
                     lower.tail = FALSE, log.p = FALSE); }
attr(p.value, "names") <- NULL;

#Create htest object
TEST        <- list(method = method, data.name = data.name,
                    null.value = null.value, alternative = alternative,
                    estimate = estimate, statistic = statistic, p.value = p.value);
class(TEST) <- "htest";
TEST; }

We can implement this with some data as an example.  I will create a data vector with $n=40$ values that I generated from a Poisson distribution (with a parameter value that I will keep secret).  We will test to see if the parameter I used is greater than $\theta_0=15$.
#Create a data vector
DATA <- c(21L, 25L, 13L, 21L,  8L,  9L, 14L, 12L, 14L, 14L,
          11L, 16L, 19L, 20L, 16L,  9L, 13L, 16L, 17L, 23L,
          14L, 16L, 16L, 14L, 17L, 14L, 12L,  9L,  8L, 16L,
          20L, 11L, 10L,  4L, 18L, 15L, 15L, 14L, 16L, 20L);

#Test the alternative hypothesis that theta > 15
TEST <- Poisson.rate.test(DATA, theta0 = 15, alternative = 'greater');
TEST;

        Poisson rate test (one-sided)

data:  DATA
sample total = 590, p-value = 0.6488
alternative hypothesis: true rate parameter is greater than 15
sample estimates:
estimated rate
         14.75

We can see in this case that there is no evidence that the rate parameter for this data was greater than the hypothesised value of $\theta_0=15$.


Apache Sqoop Where clause not working while using SQOOP IMPORT

Question: Can anyone tell me what will be the output of this command :
Here departments table was having the default 6 rows (from dept_id 2 to 7) then i added 2 new records to Mysql db 'retail_db.departments' table (department_id 8 & 9). What i am trying to do is selecting only the newly added records by using the –where argument & appending (–append) it to the existing HDFS directory for departments.
So when i ran the below command it created a new part-m-000006 file (earlier the default 6 records were splitted into part-m-00000 to part-m-00005 files) and all the records from department_id 2 to 9 (which includes 2 newly added recs) were added to it and as you can see the output below there is repetition of records.
Don't understand why it is not respecting the where clause:
sqoop import \
–connect "jdbc:mysql://quickstart.cloudera:3306/retail_db" \
–username retail_dba \
–password cloudera \
–query "Select * from departments where \$CONDITIONS" \
–where "department_id > 7" \
–append \
-m 1 \
–target-dir /user/cloudera/sqoop_import/departments

Output :
—————————————————————————————————————————–
[cloudera@quickstart ~]$ hdfs dfs -cat /user/cloudera/sqoop_import/departments/part*
2,Fitness
3,Footwear
4,Apparel
5,Golf
6,Outdoors
7,Fan Shop
2,Fitness
3,Footwear
4,Apparel
5,Golf
6,Outdoors
7,Fan Shop
8,Sports
9,Jewellery

—————————————————————————————————————————–
LOGS GENERATED :
—————————————————————————————————————————–
Warning: /usr/lib/sqoop/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
16/10/23 12:23:30 INFO sqoop.Sqoop: Running Sqoop version: 1.4.5-cdh5.4.0
16/10/23 12:23:30 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
16/10/23 12:23:31 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
16/10/23 12:23:31 INFO tool.CodeGenTool: Beginning code generation
16/10/23 12:23:31 INFO manager.SqlManager: Executing SQL statement: Select * from departments where (1 = 0)
16/10/23 12:23:31 INFO manager.SqlManager: Executing SQL statement: Select * from departments where (1 = 0)
16/10/23 12:23:31 INFO manager.SqlManager: Executing SQL statement: Select * from departments where (1 = 0)
16/10/23 12:23:31 INFO orm.CompilationManager: HADOOP_MAPRED_HOME is /usr/lib/hadoop-mapreduce
Note: /tmp/sqoop-cloudera/compile/b704a6e6d921fb544ba25c6343b18a36/QueryResult.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
16/10/23 12:23:33 INFO orm.CompilationManager: Writing jar file: /tmp/sqoop-cloudera/compile/b704a6e6d921fb544ba25c6343b18a36/QueryResult.jar
16/10/23 12:23:33 INFO mapreduce.ImportJobBase: Beginning query import.
16/10/23 12:23:34 INFO Configuration.deprecation: mapred.jar is deprecated. Instead, use mapreduce.job.jar
16/10/23 12:23:35 INFO Configuration.deprecation: mapred.map.tasks is deprecated. Instead, use mapreduce.job.maps
16/10/23 12:23:36 INFO client.RMProxy: Connecting to ResourceManager at quickstart.cloudera/127.0.0.1:8032
16/10/23 12:23:38 INFO db.DBInputFormat: Using read commited transaction isolation
16/10/23 12:23:38 INFO mapreduce.JobSubmitter: number of splits:1
16/10/23 12:23:39 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1477192024680_0012
16/10/23 12:23:40 INFO impl.YarnClientImpl: Submitted application application_1477192024680_0012
16/10/23 12:23:40 INFO mapreduce.Job: The url to track the job: http://quickstart.cloudera:8088/proxy/application_1477192024680_0012/
16/10/23 12:23:40 INFO mapreduce.Job: Running job: job_1477192024680_0012
16/10/23 12:23:56 INFO mapreduce.Job: Job job_1477192024680_0012 running in uber mode : false
16/10/23 12:23:56 INFO mapreduce.Job: map 0% reduce 0%
16/10/23 12:24:25 INFO mapreduce.Job: map 100% reduce 0%
16/10/23 12:24:26 INFO mapreduce.Job: Job job_1477192024680_0012 completed successfully
16/10/23 12:24:27 INFO mapreduce.Job: Counters: 30

Comment: you asked similar question: http://stackoverflow.com/questions/40189605/issue-in-using-where-clause-in-sqoop
Answer: You are using both --query and --where. That's why sqoop is not respecting --where tag.
--query is a superset of --where. It covers WHERE conditions.
That's why in your logs you see:
INFO manager.SqlManager: Executing SQL statement: Select * from departments where (1 = 0)

Use any one of these:

--query "select * from departments where department_id > 7 AND \$CONDITIONS"
--where "department_id > 7"


What key is this hash tag note?

Question:
In the treble clef line , what key is the hash tag note?
I know it's a black key but can't remember which .
Comment: Do you remember, which note you would press if there was no sharp ("_hash tag_")? The sharp raises the note by a semitone. Have a look: [en.wikipedia.org/wiki/Key_signature](https://en.wikipedia.org/wiki/Key_signature)
Answer: This hashtag is what we call a "sharp." It raises the pitch by one half step.
I'm assuming you mean the sharp in the bass clef. (Based on the music, it's hard for me to imagine these both being in treble clef.)
Since the written note is F, you'll move it up one half step to the nearest black key to make it F♯. If you're still having trouble finding this key, look for the group of three black keys; it will be the one on the far left.
If the left hand is in fact in treble clef, this pitch will be a D♯, which is the right-most black key in the grouping of two black keys.
Comment: Does it look weird to you - there's no note to be sung with the word 'peace'. I've heard of peace and quiet, maybe this takes it further?
Comment: @Tim: I think the tune goes mifa mi re do re so. The note of peace is in the bass clef. It seems to be an arrangement for "easy piano" (beginners)
Comment: Bach would surely write a fuge to the theme hashtag mi too ...
Comment: (I thought for certain this was a duplicate, but I can't find a clear question/answer for this. I apologize if there is a clear duplicate that I missed.)

What key is this hash tag note?


Como implementar um algorítimo de permutação em Python?

Question: Estou tentando implementar um algorítimo de permutação em Python.
Ele recebe como entrada uma frase e uma chave (valor numérico) que corresponde a quantidade de letras que cada grupo deve ter, e por fim, uma sequência numérica que vá de 1 até o valor da chave.
Segue um exemplo de entrada de dados:
Frase de entrada:

"Python é a melhor linguagem!!"

Chave de entrada:

5

Sequencia de entrada:

4 2 5 1 3

Saída esperada:

Hyopt
  méena
  rhllo
  unaig
  !e!gm

Segue a minha tentativa, porém sem resultado, porque eu não estou conseguindo implementar e fazer a divisão por grupos para obter o resultado ilustrado no exemplo.
Código:
contador = 0
frase = input('Digite uma frase: ').upper
chave = int(input('Digite a chave: '))
seq = []

while contador <= chave:
  seq.append(int(input('Digite o número da sequência: ')))

frase = frase.split()
frase = ''.join(frase)

Comment: Qual é exatamente a lógica para gerar a saída esperada?
Comment: 1º Juntar a frase em uma palavra só 2º Dividir em grupos de letras 3º Trocar a ordem de cada letra dentro de cada grupo, conforme a sequencia informada
Comment: E qual o critério para definir os grupos de letras no passo 2? Ter o número de caracteres definido pela chave?
Comment: O critério é o valor da chave informada, que corresponde a quantidade de letras em cada grupo
Comment: E se o comprimento do texto não for múltiplo da chave, o último grupo irá possuir menos caracteres? Se a chave for 5 e o texto possuir 12 caracteres, irá criar grupos de 5, 5 e 2 caracteres?
Comment: O último grupo deverá ser preenchido com caracteres asterisco *
Comment: Certo, depois de definido os grupos, qual a lógica para permutar os caracteres baseado na sequência de entrada? Apenas deslocar os caracteres dentro do próprio grupo?
Comment: Os números da sequência correspondem  a posição de cada caractere. Por exemplo: No grupo de caracteres "cafe",  com sequencia "3 1 4 2" o grupo passará a ter a sequência de caracteres na seguinte ordem: "fcea". Significa que o caractere da posição 3 passará a ocupar a posição 1, o caractere da posição 1 passará a ocupar a posição 2, e assim por diante
Comment: Agora sim ficou claro. Respondo assim que possível.
Answer: A separação do texto em grupos pode ser feito através de uma compreensão de lista, acessando as posições i:i+key do texto, onde i varia de 0 até o comprimento do texto, com passo igual a key. Quando o último grupo não possui a quantidade necessária de caracteres, é adicionado * utilizando o método ljust. Após, é percorrido os grupos e feita a permutação entre os caracteres.
# Frase de entrada:
text = input("Entre com uma frase: ")

# Chave de entrada:
key = int(input("Entre com uma chave: "))

# Sequência de entrada:
sequence = []
for i in range(key):
    sequence.append(int(input("Entre com um número da sequência: ")))

# Remove os espaços em branco do texto:
text = text.replace(" ", "")

# Divide o texto em grupos definidos pela chave:
groups = [text[i:i+key].ljust(key, "*") for i in range(0, len(text), key)]

# Percorre os grupos gerando os novos grupos:
result = []
for group in groups:
    output = ""
    for i in sequence:
        output += group[i-1]
    result.append(output)

print(result)

Com as entradas apresentadas na pergunta, a saída é:
['hyoPt', 'méena', 'rhllo', 'unaig', '!e!gm']

Veja funcionando no Ideone.


In R, Quantile based on flag/ factor value

Question: I am trying to undertake some simple benchmarking in R. I have a dataframe with several numeric and a number of factors.
What I am trying to do is find the top decile and top quartile of a variable called ALoS based on the associated factor value and then attach these values back to the original dataframe
In excel this would be the equivalent of an array formula similar to:
{=percentile(if(Factor_range = Factor, ALoS_range),k)}
Example
Answer: You seem to have two questions. As for the first, to compute the quantiles, since you haven't provided us with a dataset, I'll make up one. See if the following answers the question.
set.seed(954)
dat <- data.frame(A = sample(letters[1:3], 20, TRUE), X = rnorm(20))
dat
quantile(dat$X[dat$A == "a"], probs = c(0.75, 0.90))

As for the second question, to attach it back to the data frame, I really don't understand what you mean. Please give us an example of the wanted output.
Answer: This is a great time to use the ave function:
dat$top_q <- ave(dat$X, dat$A, FUN = function(x) quantile(x, .75))
dat$top_d <- ave(dat$X, dat$A, FUN = function(x) quantile(x, .9))

   A          X    top_q     top_d
1  a  1.7150650 1.346828 1.5677700
2  b  0.4609162 0.390532 0.4308438
3  a -1.2650612 1.346828 1.5677700
4  b -0.6868529 0.390532 0.4308438
5  b -0.4456620 0.390532 0.4308438
6  a  1.2240818 1.346828 1.5677700
7  b  0.3598138 0.390532 0.4308438
8  b  0.4007715 0.390532 0.4308438
9  b  0.1106827 0.390532 0.4308438
10 a -0.5558411 1.346828 1.5677700

data
set.seed(123)
dat <- data.frame(A = sample(letters[1:2], 10, TRUE), X = rnorm(10))

   A          X
1  a  1.7150650
2  b  0.4609162
3  a -1.2650612
4  b -0.6868529
5  b -0.4456620
6  a  1.2240818
7  b  0.3598138
8  b  0.4007715
9  b  0.1106827
10 a -0.5558411

Comment: Hero! You wouldn't believe how many other functions I tried. Thanks again - really appreciate the help!


How would I write this piece of pseudocode in mathematical notation?

Question: I am trying to figure out how to write the summation of a function, $f(t)$, on an interval as mathematical notation. I can only think of the answer in terms of pseudocode, can anyone help me convert the following into mathematical notation?
x = f(0)
for (int i = 1; i <= 7; i++) {
    x(i) = x + f(i);
}
Thanks!
edit: Sorry I asked this question wrong. I meant it to be written as each iteration denotes a new value. So, in the case of my problem f(t) is a function of time in days. I want the values to equal the following:
day0 = $f(0)$
day1 = $f(0) + f(1)$
day2 = $f(0) + f(1) + f(2)$
day3 = $f(0) + f(1) + f(2) + f(3)$
day4 = $f(0) + f(1) + f(2) + f(3) + f(4) $
day5 = $f(0) + f(1) + f(2) + f(3) + f(4) + f(5)$
day6 = $f(0) + f(1) + f(2) + f(3) + f(4) + f(5) + f(6)$
day7 = $f(0) + f(1) + f(2) + f(3) + f(4) + f(5) + f(6) + f(7)$
days 8 $\rightarrow \infty$ = $f(0) + f(1) + f(2) + f(3) + f(4) + f(5) + f(6) + f(7)$
Comment: $x=\sum_{i=0}^7f(i)$
Answer: Using a for-loop, you are summing up $f(0)$ up to $f(7)$.
The pseudo-code is describing $$x=\sum_{i=0}^7 f(i)$$
Edit:
For the edited question:
$$day_i = \sum_{j=0}^{\min(i,7)} f(j)$$
Comment: Thank you! Just what I wanted.


$\lim_{n\to \infty}\frac{1}{n}\sum_{k=0}^{n-1}\ln\left(\frac{m+k}{n}\right)=\int_{0}^{1}\ln x\, dx$

Question: I am trying to proof:
$$\lim_{n\to \infty}\sum_{k=0}^{n-1}\frac{1}{n}\left(\ln\left(\frac{m}{n}+\frac{k}{n}\right)\right)=\int_{0}^{1}\ln(x)dx \hskip50pt (1)$$
where $m\in\mathbb{R}$ and $m$ positive.
I got inspiration in this post: Prove that $\lim_{n\rightarrow\infty} \frac{1}{n}\sum_{k = 1}^{n}{f(\frac{k}{n}) }$ $=\int_0^1 f(x)dx.$ and the answer Prove that $\lim_{n\rightarrow\infty} \frac{1}{n}\sum_{k = 1}^{n}{f(\frac{k}{n}) }$ $=\int_0^1 f(x)dx.$ but I am not sure about how to deal with the $\frac{m}{n}$ term since my partition $\{0 +\frac{m}{n},\frac{1}{n}+\frac{m}{n},\frac{2}{n}+\frac{m}{n},\dots,\frac{(n-1)}{n},1+\frac{m}{n}\}$ isn`t from $0$ to $1$.
Maybe (1) is false? Am I missing something?
Any hint is appreciated.
Answer: Since $\ln x$ is strictly increasing, then
$$
\frac{1}{n}\ln\left(\frac{k}{n}\right)<\int_{k/n}^{(k+1)/n}\ln x\,dx
<\frac{1}{n}\ln\left(\frac{k+1}{n}\right)
$$
and hence
$$
\frac{1}{n}\ln\left(\frac{m+k}{n}\right)-\frac{1}{n}\ln\left(\frac{k+1}{n}\right)
<
\frac{1}{n}\ln\left(\frac{m+k}{n}\right)-\int_{k/n}^{(k+1)/n}\ln x\,dx
<
\frac{1}{n}\ln\left(\frac{m+k}{n}\right)-\frac{1}{n}\ln\left(\frac{k}{n}\right)
$$
But
$$
\frac{1}{n}\ln\left(\frac{m+k}{n}\right)-\frac{1}{n}\ln\left(\frac{k}{n}\right)
=\frac{1}{n}\ln\left(\frac{m+k}{k}\right)< \frac{1}{n}\ln\left(1+\frac{m}{k}\right)<\frac{m}{kn},
$$
while
$$
\frac{1}{n}\ln\left(\frac{m+k}{n}\right)-\frac{1}{n}\ln\left(\frac{k+1}{n}\right)=\frac{1}{n}\ln\left(\frac{m+k}{k+1}\right)=
\frac{1}{n}\ln\left(1+\frac{m-1}{k+1}\right)
$$
If $m\ge 1$, then $\ln\left(1+\frac{m-1}{k+1}\right)\ge 0$. If $m\in(0,1)$, then
$$
\ln\left(1+\frac{m-1}{k+1}\right)=\frac{1}{k+1}\ln\left(1+\frac{m-1}{k+1}\right)^{k+1}\ge \frac{1}{k+1}\ln\left(1+(k+1)\frac{m-1}{k+1}\right)=\frac{\ln m}{k+1}.
$$
Thus
$$
\frac{1}{(k+1)n}\min\{0,\ln m\}<\frac{1}{n}\ln\left(\frac{m+k}{n}\right)-\int_{k/n}^{(k+1)/n}\ln x\,dx<\frac{m}{kn}
$$
and therefore
$$
\frac{\min\{0,\ln m\}}{n}(\ln(n+1)-\ln 2) <
\frac{\min\{0,\ln m\}}{n}\sum_{k=1}^{n-1}\frac{1}{(k+1)}<\sum_{k=1}^{n-1}\frac{1}{n}\ln\left(\frac{m}{n}+\frac{k}{n}\right)
-\int_{1/n}^1\ln x\,dx<\sum_{k=1}^{n-1}\frac{m}{kn}
=\frac{m}{n}\sum_{k=1}^{n-1}\frac{1}{k}
<\frac{m}{n}(1+\ln n)
$$
since $1+\ln n>\sum_{k=1}^{n-1}\frac{1}{k}$.
Comment: Thank you very much for your answer. However, I don't see why is this inequality true:
$$0<\frac{1}{n}\ln\left(\frac{m}{n}+\frac{k}{n}\right)-\int_{k/n}^{(k+1)/n}\ln x\,dx$$.
Comment: @mathstudent007 See my edited answer.
Comment: thank you, it is very clarifying.


Accessing the first key in a nested Dictionary

Question: I have a dictionary that looks like the following:
{
"DICT_KEY1": {"nestKey1": "val", "nestKey2": "val", "nestKey3": "val"}
}

If I have a function that takes in a parameter like the dictionary above,
How would I access the key "DICT_KEY1" (not the values) without mentioning "DICT_KEY1" (since the nested dictionary passed into the parameter would be different each time)?
I can only think of accessing DICT_KEY1 by mentioning the key name, like:
dict1 = {(nested dictionary param)}
print(dict1['DICT_KEY1'])

Comment: You can do `next(dict1)` to get the first key according to insertion order.  Or `min(dict1)` to get the first one according to order.
Comment: `DICT_KEY1` is not in the nested dictionary, it's in the top-level dictionary.
Comment: `print(dict1['DICT_KEY1'])` prints the value of that key, not the key. You said you're not interested in the value.
Answer: The most efficient way to achieve that is using next() + iter() being the time complexity of this O(1).
print(next(iter(dict1)))

Transforming the keys of the dictionary into a list and accessing the first element will take O(n), what make that inneficient for bigger dictionaries.
Answer: You can use list(dict.keys()) to access the keys as a list.
For instance:
d = {"DICT_KEY1": {"nestKey1": "val", "nestKey2": "val", "nestKey3": "val"}}
print(list(d.keys()[0])

This is fine for small dictionaries, but can be inefficient for large ones. If you have a bigger dictionary, using a library might be more appropriate. See this post for more guidance with third party libraries.


SQL Convert varchar to int

Question: I was trying to display the number of days between two dates(column) in my database. The output display was in the varchar data type. How should I convert it into int data type? Following is the error message that pops up to me:

Msg 245, Level 16, State 1, Line 42
Conversion failed when converting the varchar value 'Overdue Day(s)'
  to data type int.

I have tried using both CAST and CONVERT syntax, but neither of them worked.
SELECT DVD_mem_id AS 'Member ID',
       DVD_mem_name AS 'Member Name',
       DVD_movie_id AS 'Movie ID',
       DVD_movie_title AS 'Movie Title',
       DVD_borrowing_date AS 'Date of Borrow',
       DVD_date_due AS 'Date Due',
       CAST('Overdue Day(s)' AS int),
       DATEDIFF(DAY, DVD_borrowing_date, DVD_date_due) -3 AS 'Overdue Day(s)',
       'Overdue Day(s)' * 2 AS 'Fine Incurred'
FROM DVD_T
WHERE (DVD_mem_id IS NOT NULL) AND
      (DVD_mem_name IS NOT NULL) AND
      (DVD_borrowing_date IS NOT NULL) AND
      (DVD_date_due) IS NOT NULL AND
      ('Overdue Day(s)' > 0)

Comment: `'Overdue Day(s)'` is a string literal, which can't be casted to integer.
Comment: You can't reference a column alias from the same select in the select list, or in the where clause.
Comment: Possible duplicate of [Conversion failed when converting the varchar value 'simple, ' to data type int](https://stackoverflow.com/questions/21984110/conversion-failed-when-converting-the-varchar-value-simple-to-data-type-int)
Answer: I think what you need is this, as @jarlh said 'Overdue Day(s)' is a string where you cannot do any math operations.
SELECT DVD_mem_id AS 'Member ID',
       DVD_mem_name AS 'Member Name',
       DVD_movie_id AS 'Movie ID',
       DVD_movie_title AS 'Movie Title',
       DVD_borrowing_date AS 'Date of Borrow',
       DVD_date_due AS 'Date Due',
       CAST((DATEDIFF(DAY, DVD_borrowing_date, DVD_date_due) -3) AS int),
       DATEDIFF(DAY, DVD_borrowing_date, DVD_date_due) -3 AS 'Overdue Day(s)',
       (DATEDIFF(DAY, DVD_borrowing_date, DVD_date_due) -3) * 2 AS 'Fine Incurred'
FROM DVD_T
WHERE (DVD_mem_id IS NOT NULL) AND
      (DVD_mem_name IS NOT NULL) AND
      (DVD_borrowing_date IS NOT NULL) AND
      (DVD_date_due) IS NOT NULL AND
      (DATEDIFF(DAY, DVD_borrowing_date, DVD_date_due) -3 > 0)

Comment: Thanks a lot, you solved my problem, really appreciated ^v^

SQL Convert varchar to int


How update programmatically node entity with empty field_image?

Question: i need to make an import from one mysql table in my base.
I create node with :
<code>$value= array(
                'type' => strtolower($typeProduit),
                'field_1'=>"test",
                'title'=>"test",
                'body' => array(
                    'value' => "test",
                    'format' => 'full_html',
                ),
                'field_2'=>"",
                'field_3'=>"",
                'field_4'=>"",
            );

 $nodeEntity=\Drupal::entityTypeManager()
        ->getStorage('node')
        ->create($value);

    $nodeEntity->save();
</code>
All node are create and if i have an image, i add it to my $value before save() :
<code>$value['field_image_video']=array(
                    'target_id' => $fileImageVideo->id(),
                    'alt' => $catalogue->titreVideo,
                    'title' => $catalogue->titreVideo,
                );
</code>
if i have no image, i do nothing for this field.
I need to update some node programmatically after this first step.
And when i just try to change the title like this :
<code>     $nodeEntityUpdate = \Drupal::entityTypeManager()
                    ->getStorage('node')
                    ->load(273);

     $nodeEntityUpdate->title="blabla";
     $nodeEntityUpdate->save();
</code>
if node don"t have image field set, i got this error :

PHP Fatal error:  Call to a member function getFileUri()

If node has image, update work.
How can i set my image_field to null ?
i try to set my image field like that on creation :
<code>$value['field_image_video']=array();
</code>
But that didn't work.
this image field is set to unlimited values
Answer: i got it in the update :
i set my image_field in the update:
<code>  $nodeEntityUpdate = \Drupal::entityTypeManager()
                    ->getStorage('node')
                    ->load(273);

     $nodeEntityUpdate->title="blabla";
     $nodeEntityUpdate->field_image_video =array();
     $nodeEntityUpdate->save();
</code>
I try to set this field in the create, but that change nothing.
As i can see, we need to set image field in the update if she is empty at the creation.
Comment: `$node->set($node->getEntityKey('label'), 'blabla')->set('field_image_video', NULL)->save();` or possibly `$node->get('field_image_video')->filter(TRUE)`.
Comment: yes but we need absolutly set the field_image_video ?


Lineageos bacon build failed

Question: I am trying to build LineageOS 17.1 bacon based on the steps here: https://wiki.lineageos.org/devices/bacon/build
All steps until the below failure have been successful. Everything is the latest leading to LINEAGE_VERSION=17.1-20210324-UNOFFICIAL-bacon
brunch bacon returns the following failure. This is my first android build, web search did not yield anything useful on how to fix this. Currently, I am clueless, any help/suggestions on how to fix this are very welcome.
[ 75% 372/496] including system/sepolicy/Android.mk ...
system/sepolicy/Android.mk:89: warning: Be careful when using the SELINUX_IGNORE_NEVERALLOWS flag. It does not work in user builds and using it will not stop you from failing CTS.
[100% 496/496] writing build rules ...
build/make/core/Makefile:28: warning: overriding commands for target `email@example.com'
build/make/core/base_rules.mk:510: warning: ignoring old commands for target `firstname.lastname@example.com'
FAILED: ninja: 'vendor/oppo/msm8974-common/proprietary/vendor/bin/hci_qcomm_init', needed by 'out/target/product/bacon/system/vendor/bin/hci_qcomm_init', missing and no known rule to make it
18:51:33 ninja failed with: exit status 1

Could the above error be due to the missing source?:
$ ./extract-files.sh

Cleaning output directory (./../../oppo/msm8974-common/../../../vendor/oppo/msm8974-common/proprietary)..

Extracting 115 files in ./../../oppo/msm8974-common/proprietary-files.txt from adb:

  - vendor/bin/adsprpcd

  - vendor/bin/hci_qcomm_init

    !! vendor/bin/hci_qcomm_init: file not found in source

Edit: Answering my own question, one has to run adb root on the terminal that guides you want needs to be done on the phone. This can be closed. #lineageos-dev is the place to ask such a question.
Answer: Answering my own question, one has to run adb root on the terminal that guides you to do what needs to be done on the phone. This can be closed. #lineageos-dev is the place to ask such a question.

Lineageos bacon build failed


Não estou a conseguir por o submenu na horizontal

Question: Tenho o  menu  principal  na horizontal  e depois queria por o meu  sub-menu  também  na horizontal  mas não consigo.
O meu código:
.menu ul li{
    background-color:;             /* muda a cor da barra */
    float: left;                   /* ficar horizontal */
    width: 140px;                  /* tamanho da barra */
    height: 50px;                  /* altura da barra */
    display: inline-block;
    text-align:center;             /* ficar a esqueda*/
    line-height:22px;              /* mover o submenu*/
    font-size: 24px;               /* tamanho da letra*/
    position: relative;
    z-index:9999;              /* para por o menu a frente do  texto*/

}

.menu ul li:hover{
    background-color:black;       /* muda a cor do submenu quando  metes la o rato */

}

.menu ul{
    padding: 0px;                   /* move a barra para a direita */
    margin:  0px;

}

.menu ul ul{
    display: none;                  /* para  o sub sub menu ficar invisivel*/
}

.menu ul li:hover > ul{             /* para quando por o rato no menu ementa, aparecer o sub menu*/
    display:block;

}

.menu ul ul ul{                     /* SOBRE AS CARNES E PEIXES*/
    margin-left:140px;              /* mover para a direita*/
    top: 0px;                       /* ir para baixo*/
    position: absolute;
}

.menu ul ul li:hover{               /* SUBMENU DA EMENTA*/
    background-color:#80bfff;       /* cor do  submenu*/

}

.menu ul ul ul li:hover{            /* SUBSUBMENU DA EMENTA*/
    background-color:#80bfff;       /* cor*/

}

.menu a{                            /* OS MENUS*/
    color:white;                    /* cor do texto*/
    text-decoration: none;          /* sem decoração*/
}
.menu li {
    -webkit-filter: blur(0);
    -webkit-transition: -webkit-filter 0.5s ease-in-out;
}
.menu:hover li {
    -webkit-filter: blur(1.5px);
}
.menu:hover li:hover, .menu:hover li:hover ul li{  /* Alinhamento horizontal do Menu no Centro da Página*/
    -webkit-filter: blur(0);
}

nav {                                               /* aumenta a barra do menu*/
    width: 580px;
    margin: 0 auto;
}

a{
    text-decoration:none;
    color:#fff;
    padding:10px;
    margin:10px;
    display:table-cell;
    text-align:left;
    vertical-align:left;
    width:200px;
    height:0px;
    font-size:18px;
}

body{
    background-image:url(bg.jpg);   /* para por como imagem de fundo */
    background-attachment: fixed;   /* faz com  que a imagem n rode */
    background-size:100%;           /* para ajustar ao tamanho da janela */
    background-repeat:no-repeat;    /* n repetir a imagem*/
    background-color:#000;

.123 {
    z-index:9999;
}

    </style>

Restaurante

Ementa

Entrada

Prato Principal

Carnes

Peixes

Vegetariano

Sobremesas

Reserva

Contacto

Comment: Lucas qual dos Sub-menus vc quer por na horizontal. O que desce da "Ementa" ou o que desce do "Prato Principal"?
Comment: o que desce da ementa.
Answer: Para mexer o mínimo possível no seu CSS eu usei a propriedade display:inline-flex; e ajustei as margins em duas classes, dessa forma:
/* Tirei o Display:Block */
.menu ul li:hover > ul{
    display: inline-flex;
}
/* Alterei os valores da Margin*/
.menu ul ul ul {
    margin-left: -30px;
    margin-top: 50px;
    top: 0px;
    position: absolute;
}

Execute o Snippet para ver o resultado (clique em "Página Toda" para exibir melhor o menu, pois seu CSS não tem tratamento para responsivo.)

.menu ul li{
    background-color:;             /* muda a cor da barra */
    float: left;                   /* ficar horizontal */
    width: 140px;                  /* tamanho da barra */
    height: 50px;                  /* altura da barra */
    display: inline-block;
    text-align:center;             /* ficar a esqueda*/
    line-height:22px;              /* mover o submenu*/
    font-size: 24px;               /* tamanho da letra*/
    position: relative;
    z-index:9999;              /* para por o menu a frente do  texto*/

}

.menu ul li:hover{
    background-color:black;       /* muda a cor do submenu quando  metes la o rato */

}

.menu ul{
    padding: 0px;                   /* move a barra para a direita */
    margin:  0px;

}

.menu ul ul{
    display: none;                  /* para  o sub sub menu ficar invisivel*/
}

.menu ul ul li:hover{               /* SUBMENU DA EMENTA*/
    background-color:#80bfff;       /* cor do  submenu*/

}

.menu ul ul ul li:hover{            /* SUBSUBMENU DA EMENTA*/
    background-color:#80bfff;       /* cor*/

}

.menu a{                            /* OS MENUS*/
    color:white;                    /* cor do texto*/
    text-decoration: none;          /* sem decoração*/
}
.menu li {
    -webkit-filter: blur(0);
    -webkit-transition: -webkit-filter 0.5s ease-in-out;
}
.menu:hover li {
    -webkit-filter: blur(1.5px);
}
.menu:hover li:hover, .menu:hover li:hover ul li{  /* Alinhamento horizontal do Menu no Centro da Página*/
    -webkit-filter: blur(0);
}

nav {                                               /* aumenta a barra do menu*/
    width: 580px;
    margin: 0 auto;
}

a{
    text-decoration:none;
    color:#fff;
    padding:10px;
    margin:10px;
    display:table-cell;
    text-align:left;
    vertical-align:left;
    width:200px;
    height:0px;
    font-size:18px;
}
body{
    background-image:url(bg.jpg);   /* para por como imagem de fundo */
    background-attachment: fixed;   /* faz com  que a imagem n rode */
    background-size:100%;           /* para ajustar ao tamanho da janela */
    background-repeat:no-repeat;    /* n repetir a imagem*/
    background-color:#000;
}
.123 {
    z-index:9999;
}

/* Tirei o Display:Block */
.menu ul li:hover > ul{
    display: inline-flex;
}
/* Alterei os valores da Margin*/
.menu ul ul ul {
    margin-left: -30px;
    margin-top: 50px;
    top: 0px;                       /* ir para baixo*/
    position: absolute;
}

Restaurante

Ementa

Entrada

Prato Principal

Carnes

Peixes

Vegetariano

Sobremesas

Reserva

Contacto

Comment: funcionou. agradeço pela sua ajuda


How can I send HTML newsletters?

Question: I have developed websites using Drupal since 1998. Getting Simplenews to send HTML formatted emails in D8 has been the most frustrating experience I've had in all those years. I am very upset. I find the current state of D8 documentation to be quite shoddy overall, not just Simplenews. Here's a glaring example of what I'm talking about: I'm building a D8 site using D8 modules. I go to the README file in the simplenews directory and I'm reading all about how.

You can customize the theming of newsletters. Copy any of the *.tpl.php
      files from the simplenews module directory to your theme directory. Both
      general and by-newsletter theming can be performed.
      Theme newsletter body:

simplenews-newsletter-body.tpl.php (for all newsletters)
simplenews-newsletter-body--[newsletter_id].tpl.php
simplenews-newsletter-body--[view mode].tpl.php
simplenews-newsletter-body--[newsletter_id]--[view mode].tpl.php

Here's some news for the module developers: None of that exists in the D8 module! WTF, really? These are D7 instructions. Not very helpful esp since that README file contains some of the most complete and detailed instructions on this aspect of simplenews-- if you're using the D7 version, that is..
I have spent an all-nighter and several full days on configuring this. I'm using sipmplenews Version: 8.x-1.0-alpha2, mailsystem Version: 8.x-4.1, mimemail Version: 8.x-1.x-dev and smtp Version: 8.x-1.0-beta2. No matter what recipe I follow from the myriad of posts on this subject, this is what my HTML email messages look like when they arrive in my inbox: HTML tags visible and absolutely no formatting.

Testing 1234
 Testing 1234

View this message in your browser HERE.

 MICHAEL "SKEETER" PILARSKI

 <img alt="Friends of the Trees Masthead" src="example.com/sites/default/files/images/top-fts.jpg" style="width: 100%` ...

If anyone has this working or if there is a sympathetic developer out there, hear my plea: Someone please create a step-by-step basic simplenews configuration that anyone can follow to get simplenews to successfully send HTML formatted emails from a D8 website. If it was a configuration that was just enough to get it to work (with a designated theme and any other variables set), user customization could follow once a successful email has been sent This whole thing has worn me out.
Answer: Outdated documentation is one of the reasons why Simplenews is only in Alpha. Sorry you had a frustrating experience, but a lot of work of porting modules and writing documentation is done in (my) free time. It is one of the many contrib modules that I help maintain.
You're more than welcome to help improving the module and documention so the next person will be able to figure this out faster. Patches or simply  by writing documentation on drupal.org.
The template extension is now .html.twig, which you should quickly see in the templates folder of the module.
Also, the very first paragraph on the project page contains this:

Simplenews publishes and sends newsletters to lists of subscribers.
  Both anonymous and authenticated users can opt-in to different mailing
  lists. HTML email can be sent by adding Mime Mail module for D7 and
  Swiftmailer for D8.

Swiftmailer requires a composer dependency and is a bit more complicated to install due to that, but it is what we've been using in our projects and should work well.
Also, make sure you enable HTML in the newsletter settings. And possibly try the latest dev versions if you have problems.
Answer: Yes. Need to improve the module & Documentation. For HTML, Actually Simplenews module depends Swiftmailer and swiftmailer requires mailsystem module.
Comment: The simplenews module does NOT require switfmailer and the swiftmailer module does NOT require mimemail.
Comment: @anonymous, If we send the mail with HTML format, they said in that document needs to install Swiftmailer module for Drupal 8. If we install Swiftmailer the module it requires Mimemail module. See the documentation and check with .info.yml file.
Comment: Nope. While you do need a helper module to send HTML email with Drupal, that helper module could be any one of a number of other modules, or could be your own custom code. If the Simplenews documentation suggests Swiftmailer as the helper module, that is only a suggestion, not a requirement. And Swiftmailer most certainly does NOT require Mime Mail - both Swiftmailer and Mime Mail do the same things, there is absolutely no need to use both at the same time. Perhaps you should take another look at swiftmailer.info.yml ...
Comment: @anonymous, Yes you are correct. I confused bit in between the Mailsystem & mime. Thanks for you info.

How can I send HTML newsletters?


Git: How to cherrypick commit from one branch and create pull request for another branch?

Question: I have two branches dev & master. I am using bitbucket.
I need to cherrypick some of the commit from dev branch.
Then need to create pull request for the master branch.
As my dev environment has so many things, some of them not able to directly merge to master.
So take commit <id 1>, <id 2> from dev branch. Take them together. Create pull request those to merge with master branch.
Comment: Using GIT allows you to cherry-pick specific commit(s), by commit id, regardless of the branch.
For instance: git cherry-pick
Comment: So after `git checkout dev`, `git cherry-pick `, `git cherry-pick `. How to create PR for those cherry-pick for master branch?
Comment: You can create a new branch on you master branch. Cherry pick the desired commits and then make a PR for this new branch. In your case it will contain your cherry-picked commits
Comment: So I will create new branch from dev, cherry-pick those commits and merge that branch or create pull request for master?
Comment: No merge is involved. Cherry-pick will take the desired commits and place them on top of your master. You then can push those commits to the new branch and make a PR
Comment: Are you able to provide full list of steps?
Comment: Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/217432/discussion-between-mighty-and-mad).
Answer: You can use
git cherry-pick <commit id>
to pick specific commits
To close the cycle and make a PR from master.
We can do the following steps:
Assume being on the master branch:
git checkout -b myNewBranch // this will create a new branch named myNewBranch
git cherry-pick <commitID 1> // this will take the commit with the commit ID 1 and
                             // attempt to place it on top of the master branch.
                             // Note however, there might be conflicts to resolve
git cherry-pick <commitID 2> // this will take the commit with the commit ID 2 and place on top of the master branch
git push origin/<some branch name> // will push the changes to remote. Usually origin/<local branch name>

Then you can make a pull request depending on your platform.
So it can be from the GUI. Be it on a GitHub platform or DevAzure, etc.
In your case via BitBucket GUI.
Side note: the steps above are made for simplicity. It is also possible to make the cherry-pick with one line. Like so:
git cherry-pick <commitID 1> <commitID 2>

Comment: We need to pick commit from dev branch. So will create new branch from `dev`. Then cherry-pick commit from them. Then merge this new branch via PR to master. Correct?
Comment: If you need to pick commits from dev to master. Then you make new branch on master. You cherry-pick the commits from dev. You then push the branch to remote and you use the Bitbucket GUI procedure to make the PR. As outlined in the answer. If further assistance is required (regarding merge). I believe you can find the answer here of StackOverflow or ask another question if no suitable answer is found.
Comment: If the answer solved your question. Please mark it as the correct answer
Answer: Fork original-repo as "your-repo"

git clone your-repo
cd your-repo
git checkout dev
git pull //to get all your commits to local
git checkout master
git pull //to make sure branch is upto date
git cherry-pick commit-id
git push //commits the cherry-picked commits to the master branch of forked repo

Raise PR from Forked repo "your-repo" master branch to "original-repo" master branch


enable the button to be clicked only to once exception?

Question: I use a dialog to get the user input, but I found the user may click double click the button and added the content twice, the cause is the dialog fadeout too slow or the user clicked twice on the mouse.. I don't want to adjust the fadeout speed, instead, how to enable the button only can be clicked once?
Comment: we need to see some of your code before we can give a definitive answer, but generally you will want to do that in the click event.  You might even unbind it with off (I think it was?)
Answer: jQuery provides the one() method to register a one-shot handler that will only run once.
You can write:
$("#yourButton").one("click", function() {
    // Add content...
});

Comment: oh snap! when was that added?  That's a nice feature!
Comment: @Joseph, the first form (similar to `bind()`) was introduced way back in jQuery 1.1. The other two forms (similar to `on()`) were introduced in version 1.7, like `on()` itself.
Comment: I had no idea that was in there all this time.  If only I could vote twice.  This is the most technically correct answer... and something I hadn't seen before.  Thank you for your answer
Answer: You can disable the button once it was clicked to prevent any further clicks:
$('button').on('click', function() {
    $(this).prop('disabled', true);
});

Answer: Here is my suggestion.  If you are destroying the dialog on exit, just unbind the click event
$('.my-button').on('click', function(){
    // process code
    $(this).off('click');
});

You can read about off here
And here is a demo.  First will not allow other clicks but the second will.
source
Answer: Here is a Plunker that shows how you can do this. Pretty much all you need to do is add the following line in your button:
onClick="this.disabled = true;"

So that your button HTML will look something like this:
<button type="submit" onClick="this.disabled = true;">Submit</button>

Comment: inline javascript is generally discouraged as a bad practice.
Comment: Joseph, I completely agree. While this question was tagged with jQuery there were no code examples and so I put forward an answer that solved the problem. If he had provided code that used `$(el).on(...)` then I would have suggested using `$(this).off(...)`.
Answer: try this:
    $('.myButton').click(function(){

        $(this).attr('disabled',true);

             ....
    })

Answer: try this with css
$("#yourButton").one("click", function() {
     $(this).css('pointer-events', 'none');
})