Tomcat is closing randomly

Question: We are using Tomcat 7.0.21 for production. Server is hanging randomly for last week.
It creates files like hs_err_pid4528.log under bin folder.
There are two parts in logs.
JRE version: 7.0_21-b11
Java VM: Java HotSpot(TM) 64-Bit Server VM (23.21-b01 mixed mode windows-amd64 compressed oops)
Problematic frame:
C  [zip.dll+0x5794]  ZIP_Open+0x1690

and
Stack: [0x0000000028830000,0x0000000028930000],  sp=0x000000002892d430,  free space=1013k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [zip.dll+0x5794]  ZIP_Open+0x1690

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J  java.util.zip.Deflater.deflateBytes(J[BIII)I
J  java.util.zip.GZIPOutputStream.finish()V
j  org.apache.coyote.http11.filters.FlushableGZIPOutputStream.finish()V+9
j  org.apache.coyote.http11.filters.GzipOutputFilter.end()J+26
J  org.apache.coyote.http11.AbstractHttp11Processor.action(Lorg/apache/coyote/ActionCode;Ljava/lang/Object;)V
J  org.apache.catalina.connector.OutputBuffer.close()V
j  org.apache.catalina.connector.CoyoteOutputStream.close()V+4
j  sun.nio.cs.StreamEncoder.implClose()V+110
j  sun.nio.cs.StreamEncoder.close()V+18
j  java.io.OutputStreamWriter.close()V+4
j  java.io.BufferedWriter.close()V+25
j  java.io.PrintWriter.close()V+21
j  com.vaadin.terminal.gwt.server.AbstractCommunicationManager.paintAfterVariableChanges(Lcom/vaadin/terminal/gwt/server/AbstractCommunicationManager$Request;Lcom/vaadin/terminal/gwt/server/AbstractCommunicationManager$Response;Lcom/vaadin/terminal/gwt/server/AbstractCommunicationManager$Callback;ZLjava/io/PrintWriter;Lcom/vaadin/ui/Window;Z)V+195
j  com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(Lcom/vaadin/terminal/gwt/server/AbstractCommunicationManager$Request;Lcom/vaadin/terminal/gwt/server/AbstractCommunicationManager$Response;Lcom/vaadin/terminal/gwt/server/AbstractCommunicationManager$Callback;Lcom/vaadin/ui/Window;)V+359
j  com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Lcom/vaadin/terminal/gwt/server/AbstractApplicationServlet;Lcom/vaadin/ui/Window;)V+37
j  com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+771
J  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
J  org.apache.catalina.core.ApplicationFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
J  org.springframework.web.filter.OncePerRequestFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V
J  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
J  org.springframework.web.filter.OncePerRequestFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V
J  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
J  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
j  org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(Lorg/springframework/security/web/FilterInvocation;)V+87
j  org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V+15
J  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
j  org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V+17
J  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
j  org.springframework.security.web.session.SessionManagementFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V+294
J  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
j  org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V+148
J  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
j  org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V+17
J  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
j  org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V+32
J  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
j  org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V+28
J  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
j  org.jasig.cas.client.session.SingleSignOutFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V+328
J  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
J  org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V
J  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
J  org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V
J  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
j  org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V+165
J  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
j  org.springframework.security.web.FilterChainProxy.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V+148
j  org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(Ljavax/servlet/Filter;Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V+5
j  org.springframework.web.filter.DelegatingFilterProxy.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V+71
J  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
J  org.apache.catalina.core.ApplicationFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
j  org.apache.catalina.core.StandardWrapperValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+780
j  org.apache.catalina.core.StandardContextValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+278
j  org.apache.catalina.authenticator.AuthenticatorBase.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+363
j  org.apache.catalina.core.StandardHostValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+142
j  org.apache.catalina.valves.ErrorReportValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+6
j  org.apache.catalina.valves.AccessLogValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+6
j  org.apache.catalina.core.StandardEngineValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+71
j  org.apache.catalina.connector.CoyoteAdapter.service(Lorg/apache/coyote/Request;Lorg/apache/coyote/Response;)V+196
J  org.apache.coyote.http11.AbstractHttp11Processor.process(Lorg/apache/tomcat/util/net/SocketWrapper;)Lorg/apache/tomcat/util/net/AbstractEndpoint$Handler$SocketState;
j  org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(Lorg/apache/tomcat/util/net/SocketWrapper;Lorg/apache/tomcat/util/net/SocketStatus;)Lorg/apache/tomcat/util/net/AbstractEndpoint$Handler$SocketState;+124
J  java.util.concurrent.ThreadPoolExecutor.runWorker(Ljava/util/concurrent/ThreadPoolExecutor$Worker;)V
j  java.util.concurrent.ThreadPoolExecutor$Worker.run()V+5
j  java.lang.Thread.run()V+11
v  ~StubRoutines::call_stub

Any Suggestions?
Thanks,
Beslan
Answer: It appears it's possible issue with some file handling, do you have this running on a filesystem using NFS?
It looks like JVM is crashing due to issue related to native O/S.
Comment: It's works when compression is off. So it's not OS.
Comment: Well it's a JVM bug which could depend on the O/S.  However, here is an answer to your related issue from a Tomcat guru: http://stackoverflow.com/questions/9742785/tomcat-7-0-25-apr-jre-crash
Comment: Indeed it could be a compression bug, I've seen a couple in the past for Java, I don't know if it would be possible to use another library file. I would just upgrade Tomcat at 1st.

Tomcat is closing randomly


Show $\int_{-\infty}^{\infty}\left[\left(-\frac{d}{dy}\right)^{k}\frac{\sin Ay}{y}\right]\frac{f(-y)}{\pi}dy=(-1)^{k}f_{A}^{(k)}(0)$

Question: I don't know how to prove the integral below.  Integral I have to use in another integral but to use this I need to prove.
$$\int_{-\infty}^{\infty}\bigg[\bigg(-\frac{d}{dy}\bigg)^{k}\frac{\sin Ay}{y}\bigg]\frac{f(-y)}{\pi}dy=(-1)^{k}f_{A}^{(k)}(0)$$
where $$f_{A}(x)=\frac{1}{\pi}\int_{-\infty}^{\infty}f(y)\frac{\sin A(x-y)}{x-y}dy$$
Can anyone help me?
Comment: Looks like integration by parts, repeated $k$ times. (I haven't checked that this works out correctly.)
Answer: Integrate by parts $k$ times to reexpress the integral as
\begin{align}
&\int_{-\infty}^{\infty}\bigg[\bigg(-\frac{d}{dy}\bigg)^{k}\frac{\sin Ay}{y}\bigg]\frac{f(-y)}{\pi}dy
=\frac{(-1)^k}\pi \int_{-\infty}^{\infty} f^{(k)}(-y)\frac{\sin Ay}{y}dy\tag1
\end{align}
and note that
$$f_{A}(x)=\frac{1}{\pi}\int_{-\infty}^{\infty}f(y)\frac{\sin A(x-y)}{x-y}dy\overset{x-y=u} =
\frac{1}{\pi}\int_{-\infty}^{\infty}f(x-u)\frac{\sin Au }{u}du\
$$
$$f^{(k)}_{A}(x)=
\frac{1}{\pi}\int_{-\infty}^{\infty}f^{(k)}(x-u)\frac{\sin Au}{u}du
\overset{x-u=-y} = \frac{1}{\pi}\int_{-\infty}^{\infty}f^{(k)}(-y)\frac{\sin A(x-y)}{x-y}dy
$$
Then, set $x=0$
$$f^{k}_{A}(0)
= \frac{1}{\pi}\int_{-\infty}^{\infty}f^{k}(-y)\frac{\sin Ay}{y}dy
$$
and plug into (1) to arrive at
$$\int_{-\infty}^{\infty}\bigg[\bigg(-\frac{d}{dy}\bigg)^{k}\frac{\sin Ay}{y}\bigg]\frac{f(-y)}{\pi}dy=(-1)^{k}f_{A}^{(k)}(0)$$


Determine whether $\sum _n \frac{{1+\sin (n^2) e^{\cos n}}}{n^\frac{3}{2}}$ is convergent or divergent

Question:
Determine whether the series convergent or divergent.
  $$\sum _n \frac{{1+\sin (n^2) e^{\cos n}}}{n^\frac{3}{2}}$$

How do we tell whether the series is convergent or divergent, and what test we are going to use (root test, ratio, etc.)
Or, we can compare to
$$\left|\frac{{1+\sin (n^2) e^{\cos n}}}{n^\frac{3}{2}}\right|\le \frac{1}{n^\frac{3}{2}}$$
So convergent?
Comment: There is no doubt that the comparison test kicks in, but the inequality you provided is not necessarily true. Perhaps you can provide a bound $$ \left| \frac{1+\sin(n^2)e^{\cos n}}{n^{3/2}} \right| \leq \frac{1 + e}{n^{3/2}} $$
Answer: $1\over {n^{3\over 2}}$ converges, $|\sin(n^2)e^{\cos(n)}|\leq e$, we deduce that $|\sin(n^2)e^{\cos(n)}|\over {n^{3\over 2}}$ $\leq$ $e\over {n^{3\over 2}}$ and the series converges.
Answer: It should be convergent.
Let's consider sequence $a_n=\sum_{k=1}^{n}\cfrac{3+\sin(k^2)e^{\cos k}}{k^{\frac{3}{2}}}$.
we know $\lim_{n\to\infty} a_n$ has a upper bound as it's less than $\sum_{n=1}^{\infty}\cfrac{3+e}{n^{\frac{3}{2}}}$;
we also know $\{a_n\}$ is increasing as each added term are positive.
$\therefore \{a_n\}$ is convergent.
$\sum_{n=1}^{\infty}\cfrac{1+\sin(n^2)e^{\cos n}}{n^{\frac{3}{2}}}=\lim_{n\to\infty}a_n-\sum_{n=1}^{\infty}\cfrac{2}{n^{\frac{3}{2}}}$, therefore it's convergent.
Comment: "$\lim_{n\to\infty} \sum_{n=1}^{\infty}$" makes no sense.
Comment: Thanks. Edited.


Can my LIkert data say anything about my intervention's effectiveness?

Question: I have Likert data from a survey that unfortunately I did not get to design, and I would like to see if there are any ways to assess if an intervention is having an effect (or rather, to assess participants' perceptions of whether the intervention is having an effect). I don't have baseline data, only post-intervention; I recognize the many major limitations of the data but I'm hoping something is salvageable!
Our "intervention:" we made medical specialists available via web chat to generalist clinicians that did not previously have access to specialists, so that they could ask for advice regarding complicated patients.
Evaluation data: we have no "before" data, and this was obviously not blinded or randomized. We just have survey data from clinicians who used this resource. Data is currently in Google Docs, hah, but could be exported somewhere else (Stata and Excel ideally). The questions we asked are as follows:

I changed elements of my patient's care based on what I learned from
  the specialist.
1 = Strongly disagree (my patient's care did not change)
5 = Strongly agree (my patient's care changed)
What I learned from the specialist allowed me to implement care which
  improved my patient's condition.
1 - Strongly disagree (there was no improvement)
5 - Strongly agree (there was improvement)
My knowledge about a particular medical condition improved as a result
  of the WhatsApp case discussion.
1 - Strongly disagree
5 - Strongly agree

The predicament: how should we present this data?!? We can calculate very simple summary stats (e.g. the mean), but it would be nice for a medical education paper we'd like to write to say something more statistically meaningful about whether our intervention was better than doing nothing. I thought about just comparing our mean to a null hypothesis of m=3 (or m=1 -- we debated about what the null should really be) but I've read that Likert data doesn't work that way. Here are the two options suggested to me so far:
Two proportion test: "bin" the data (either 1-2-3 vs 4-5, or 1-2 vs 3-4-5) and compare our proportion of "successful" responses to whatever portion we think would have occurred if our intervention had no impact or a negative impact. (If we did this, any recommendations on how to choose the null hypothesis proportion?)
Chi square test: if our null hypothesis is that the responses are random, and our intervention isn't causing any positive effect so people are just selecting their survey answers randomly, then we could use a Chi square test to compare the distribution of our answers to a hypothetical normal distribution centered around 3. I'm intrigued by this idea, but I'm not sure how to actually implement it mathematically.
Do those ideas sound reasonable? Are there other ideas to analyze our Likert data to show that what we're doing is better than nothing... without actually having a control group / counterfactual / baseline data?
In case it wasn't clear, I have decent classroom training in statistics thanks to my medical education but have not worked with them on real projects before. Will happily delve into any resources you all can provide, though! Thank you so much.
Comment: Do you just have pre and post intervention data or do you have it collected over time?
Comment: Are you interested in analyzing each question individually or combining the responses for several questions into a *scale*?
Comment: @costebk08 - I only have post-intervention data, unfortunately.
Comment: @SalMangiafico I'm probably going to analyze each question individually, because they measure pretty different things (impact on patient care vs. clinician learning).
Comment: 1. The general advice for Likert item data is to treat it as ordinal in nature.  That is, the responses are really categories, not numbers, but you know how to order them (Strongly agree is greater than Agree, and so on). So you don't want to use tests that assume the variable is numeric (like *t* test and actually the Wilcoxon signed rank test)... It sounds like you want a one-sample test (because you don't have two groups to compare).  One approach is the one-sample sign test, with which you might use 3 as the neutral response.  That is,
Comment: 2. you are asking if you had significantly more 4 and 5 responses than 1 and 2 responses.  Another approach like this is the two-proportion test you suggest.  There's nothing wrong with the chi-square test you propose, but I don't think the results will be very useful because you need invent the distribution you expected. Note also for this test that "at random" might imply a uniform distribution of answers, whereas you also propose a null of normally distributed about the neutral response.... For summary statistics, proportions or bar plots for each response in each question is very useful,
Comment: 3. if it's not overkill for the audience.  But note, it is also sensible to report medians for ordinal data.  The one-sample sign test I mentioned can also be interpreted as being about the median of the data.
Answer: I think you want to use the very simple one sample Z-test and its relative the one sample Z-test for proportion. Also, that link shows you how simple it is to do in R.
To be clear, the one sample portion of those names refers to the very fact that you only have one group (ie. no control group).
Suggested Method 1
If you want to consider each question individually, you may consider the one sample proportion test for each question. I think I'm describing what you called a two proportion test.
For a question that has a list of answers ranging from 1 to 5 like
$$[1,3,2,5,4,1,...]$$
If you consider a successful intervention as being a very effective one, you might say that the extreme answers of 4 and 5 are considered a "success" (coded by 1) while 1,2 and 3 are considered a "fail" (coded by 0). Then you would transform the list according to this rule and get
$$[0,0,0,1,1,0,...]$$
From here on out it is just a regular Z-test, since the mean of the transformed list equals the proportion of 1's in the transformed list.
A null hypothesis might be that the intervention is successful 30% of the time (equivalently, the proportion of successes is 0.3). You could then calculate a one-tailed p value from the Z-test to indicate whether the mean of your transformed survey answers is significantly greater than 0.3 (or, significantly less).
Suggested Method 2
You may also want to consider the questions together, in which case you could calculate a score for each survey taken and use a one sample Z-test.
So, each question has a list of answers in order of survey (ie. the first item in each list corresponds to the first survey taken),
$$\begin{align}\text{q1 answers} &=[1,4,2,5,3,...] \\
\text{q2 answers} &= [3,2,5,2,1,...] \\
\text{q3 answers} &= [4,5,2,3,1,...]
\end{align}$$
Then you score each survey taken by considering its mean across questions
$$\text{scores for each survey taken} = [2.66,3.66,3,3.33, 1.66,...]$$
A null hypothesis might be that the mean score is 4, and you test whether the mean of the survey scores is significantly different than 4 with a regular Z-test.
This is basically addressing your concern,

I thought about just comparing our mean to a null hypothesis of m=3 (or m=1 -- we debated about what the null should really be) but I've read that Likert data doesn't work that way.

When doing it like this, I think doing this with your data perfectly reasonable.
When choosing the null, consider the scale and meaning of your questions. Since answering 1 on the survey seems to be the same as answering "no change" (or similar), testing if the average survey answer is significantly greater than m = 1 is like testing if there was any significant change at all. Testing if the average is significantly greater than m = 3 is like testing if the intervention had a significantly extreme effect. The same goes for choosing your "rule" for success when doing a proportion test.
Comment: This is very very helpful, thank you! I had some instinct for this but your instructions are extremely helpful. We'll have to decide which null is more meaningful for us but your breakdown of what each null would mean helps confirm my instincts. Thank you!
Answer: A few comments...
What might be easiest is the chi-square approach.  If you do this, however, you won't be able to say in which direction the effect occurs.  You will only be able to say there appears to be a difference between intervention and control.  You would also have to verify that there are more than 5 people in each cell.
What might be best is to model the outcomes as a function of the intervention groups.  Since your data is essentially categorical, an ordinal logistic regression sounds appropriate.  Stata has this functionality if I remember correctly.
EDIT:  I have misread the question.
A proportions test wouldn't work because you have no null hypothesis.  Asking "what should my null be" is really only a question you can answer as the expert in the field, but I'm afraid whatever you'll choose will just be out of convenience rather than being a bonda fide hypothesis.
I can't think of much that can be done aside from perhaps using this as pilot data to do a future experiment.  You could reference it and say "from pilot data, we estimate the mean to be...".
Comment: What do you mean by "You will only be able to say there appears to be a difference between intervention and control" when the question specifically states that **there is no control group**? What do you mean by "model the outcomes as a function of the intervention groups" when there is only **one group**? How can you do any sort of regression in this case? What are the variables?
Comment: @AdamFrancey Whoops, must have misread the post.  I suppose you *could* still do a regression though.  Wouldn't be any different from just computing the sample proportions however.  In the case where there is no comparitor , then I can't think of much that can be done aside from just summarizing the data.


Wording for comparing two percentages

Question: I am trying to figure out how to make a correct statement with two values:
X = 59.8%
Y = 26.7%
Is this correct?
X has 44.6% more apples than Y
If I wanted to use the word "margin" what does that imply?
Can I say
X has more apples than Y by a margin of 44.6%
Also, is there a cheat sheet for a non-stats person that you can point to? I tried googling but I'm not getting the words right. Thanks!
Comment: Both statements are mathematically incorrect and evidently ambiguous.  Either one could be interpreted as meaning $X=(100 + 44.6)/100\times Y.$  Why don't you simply state the truth, such as "$X-Y$ is $33.1\%$"?
Comment: How did you calculate your X and Y in the first place ? Do they represent the proportion of apples in two baskets ?
Comment: There was one basket of apples shared between 5 people. I am supposed to compare the apples for person X and Y above. But it has to be in sentence format, not calculation. Like as though it was a feature story in the news. Apologies as I am not a stats person!
Answer: In your specific case, as mentioned by whuber, both statements are incorrect.
First let me explain how they are incorrect using your example with simple figures.

The basket contained 100 apples to be shared between 5 people
X took 60% of the basket (= 60 apples)
Y took 27% of the basket (= 27 apples)
The remainder (13 apples) was split between the remaining folks

In this case, the first sentence

X has Z% more apples than Y

Means that X has Z more apples than Y (33) relatively to the number of apples possessed by Y (27). What you are looking for is a representation of the exceeding number of apples in terms of percentage.
Hence, Z should be calculated this way.
$$ Z = 100*\frac{(X-Y)}{Y} = 100*\frac{33}{27} \sim 122\%
$$
Because $33 = 27*122\%$
Now for the second sentence

X has more apples than Y by a margin of Z%

Margin is inappropriate in this sentence. Leaving aside that it is quite a "business-oriented" term (e.g. gross margin), margin represents an idea of proportion, so once again, with a division operated somewhere. While it could represent the calculation in the first sentence, I would strongly recommend you to avoid using this term.
So what is the appropriate wording ?
I frankly don't know how did you get the 44.6%. $X - Y = 33.1\%$, so at most, you can say.

The difference between the share of X and Y represents 33.1% of the total share/basket.
Comment: Playing around with the numbers, I found 26.7/59.8 = .446488, so presumably this is where the OP got 44.6%
Answer: (1) X is 33.1 percentage points larger than Y.
(2) If you take this difference and divide it by X, you get 33.1/26.7 = 1.2397, so X is 124% more than Y.
(3) If you divide X by Y, you get 2.2397, so X is 224% of Y.
(4) Note that the number I got in (3) is 100% more than (2). This is because X is equal to Y plus the difference between X and Y. Since Y is equal to 100% of Y, we add 100% when going from "X is [percentage] larger than Y" to "X is [percentage] of Y.
(5) A lot of people in this sort of situation will say "X is 224% more than Y", but that is incorrect.
(6) If you divide Y by X, you get 44.6%. You seem to think that the correct statement of this is "X is 44.6% more than Y". But the actual correct statement is "Y is 44.6% of X".
(7) If X were 40%, then dividing Y by X would get 66.75%. It doesn't make sense that making X smaller increases the percentage by which X is larger than Y.
Answer: I have this problem all the time with clients/colleagues! The real answer is whatever works to make sure that it is understood. Possibly the easiest solution to that is to show your working.
I would go with "33.1 percentage points larger."
but I might say, for greater clarity:
"33.1 percentage points (that is 59.8%-26.7%) larger."
I do have one client who simply refuses to think that way. So for him, I would say
"124% larger - that is (59.8%/26.7%)."
or "larger by a factor of 124% - that is (59.8%/26.7%)." (this is close to the OP's idea of a margin)
This sounds clumsy, but is the equivalent of "twice as big" in the simple case of 40% vs 20%, say.

Wording for comparing two percentages


Can't .632+ rule be computed for any kind of outcome and prediction score?

Question: It seems that the R packages I found around for computing the .632+ estimation of prediction error work only with categorical outcomes.
Why is that? Looking at the formulas in Efron 1997 paper it seems the estimator could be used with every kind of error.
Answer: As Frank Harrell notes in this answer:

You need modifications to the bootstrap (.632, .632+) only because the original research used a discontinuous improper scoring rule (proportion classified correctly). For other accuracy scores the ordinary optimism bootstrap tends to work fine.

Also, as discussed on this page, use of .632-type rules doesn't strictly follow a fundamental property of bootstrapping.
So I suppose that you could compute a .632+ score for other purposes, but there might not be much point. I suspect that accounts for any paucity of functions in R with respect to .632+ estimates.
Comment: Thank you. I'm aware of Harrell answer, but I found this article which uses .632+ on AUC showing that it is better the normal OOB bootstrap https://www.researchgate.net/publication/220913453_Comparison_of_Non-Parametric_Methods_for_Assessing_Classifier_Performance_in_Terms_of_ROC_Parameters. Now, I'm not sure what Harrel means with "discontinuous improper scoring rule" and if AUC is improper or not. In his post there is a link to his page course, not directly to a paper justifying his statement.
Comment: @Bakaburg see [this page](https://en.wikipedia.org/wiki/Scoring_rule) about scoring rules, proper and improper. [This page](https://stats.stackexchange.com/q/339919/28500) discusses how AUC fits into that scheme (close, but not strictly proper). On an initial read of the paper linked in your comment, it doesn't seem to evaluate the ordinary optimism bootstrap (modeling on multiple bootstrapped samples, testing all models on full original data set) but rather a bootstrap-based evaluation that "test[s] on those cases that were not included in each bootstrap replicate" (page 5, bottom left).
Comment: thanks! I'll check them out!


Add job to scheduler to invoke that job automatically everyday

Question: I have a created a job which runs on everyday at 09:00:00.
Below is the snippet i have used to create a job :
BEGIN
            Dbms_Scheduler.create_job(
                job_name   => 'PROECSS_STATE_ARCH'
               ,job_type   => 'STORED_PROCEDURE'
               ,job_action   => 'TEST' -- Procedure Name
               ,start_date   => SYSDATE 9:00:00
               ,repeat_interval => 'freq=DAILY'
               ,enabled   => TRUE
               ,comments   => 'job schedule for archiving process_state');
END;

sole purpose of this is to run a stored procedure 'TEST' on everyday at 09:00:00
how to add this job to scheduler to invoke this job automatically on everyday?
Can anyone please tell me ??
Comment: Shouldn't that be PROCESS_STATE_ARCH ?
Comment: Ya, job name is process_state_arch.
Answer: You need to specify byhour too to run the job everyday at 9 pm.
BEGIN
            Dbms_Scheduler.create_job(
                job_name   => 'PROECSS_STATE_ARCH'
               ,job_type   => 'STORED_PROCEDURE'
               ,job_action   => 'TEST' -- Procedure Name
               ,start_date   => SYSDATE
               ,repeat_interval => 'freq=DAILY; byhour=9' --Added byhour
               ,enabled   => TRUE
               ,comments   => 'job schedule for archiving process_state');
END;
/

To run this on your scheme, you need CREATE JOB privilege. Otherwise you need to run this on any other privileged user. In that case specify job_action as,
job_action   => '<SCHEMA_NAME>.TEST'

To edit the job, you have the SET_ATTRIBUTE procedure in DBMS_SCHEDULER package.
Eg:-
BEGIN
     DBMS_SCHEDULER.SET_ATTRIBUTE (
          name => 'PROECSS_STATE_ARCH',
          attribute => 'repeat_interval',
          value => 'freq=DAILY; byhour=10' --Everyday by 10 AM.
          );
END;

Comment: Thank you. Will it run daily if i execute above code snippet? Where this job will be stored if i want to edit later. Any idea ?
Comment: Yes i don't have privilege to create a job. Thank you:)
Comment: @vkreddy, Yeah, this will run everyday at 9:00 AM. I've added an example for how to edit a created job in my answer.
Comment: Job has been created Successfully. But the procedure has not executed. Plz suggest @Dba


Adicionar ponto na numeração do título e adicionar numeração no sub título da lista ordenada

Question: Gostaria de saber onde estou errando no meu código css, pois estou tentando colocar um ponto no título da lista ordenada, exemplo:

Título

E também adicionar sub título para o mesmo:

Título
1.1 Sub Título

Porém quando vou ver o teste, ele não está adicionando o ponto na numeração do Título, ficando assim:
1 Título
Onde o sub título funciona normal.
Código Css:
 ol {
        counter-reset: section;
        list-style-type: none;
    }

    li::before {
        counter-increment: section;
        content: counters(section, ".") " ";
    }

    .custom-counter {
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .custom-counter li {
        counter-increment: step-counter;
    }

    .custom-counter li::before {
        content: counter(step-counter)'.';
        margin-right: 5px;
    }

Código HTML:

        <textarea required="" type="text" class="form-control" name="comentarios">

RESUMO DE ATIVIDADES

COMENTÁRIOS

        </textarea>

Lembrando que, não possui um subtitulo no código acima pois estou trabalhando com CKEditor, onde após eu dar uma quebra de linha no título dentro do editor de texto, ele adiciona automaticamente um sub titulo
Imagem de exemplo:
Answer: Tem que "iniciar" o Counter em todo o
, e remover o valor default da Lista Ordenada. Depois no
 vc faz o incremento do Counter no Content da lista
Basicamente só removi essas duas classes .custom-counter li e .custom-counter li::before  do seu CSS e já funcionou.

Deixei os comentário no código do CSS

Veja o exemplo. (apenas removi o textarea do seu código para ficar mais fácil de ver)

ol {
    counter-reset: section;  /* valor da inicial 1 */
    list-style-type: none;   /* remove o valor default da
 */
}

li::before {
    counter-increment: section; /* inicia uma nova contagem com o valor 1 */
    content: counters(section, ".") " ";  /* coloca antes do 1 o valor do pai */
}

.custom-counter {
    margin: 0;
    padding: 0;
    list-style: none;
}

RESUMO DE ATIVIDADES

SUB ATIVIDADES

SUB ATIVIDADES

COMENTÁRIOS

SUB COMENTÁRIOS

SUB COMENTÁRIOS

Aqui vc pode ler mais sobre o Counter https://developer.mozilla.org/pt-BR/docs/Web/CSS/CSS_Lists_and_Counters/Using_CSS_counters
Comment: Realmente funcionou, o problema é que ao mandar para o CKEditor, ele retira o ponto, exemplo (1. Teste para 1 Teste).
Comment: Nesse caso não tenho muito como ajudar. Vc pode tentar pegar o valor de um atributo *data* e colocar na frente.  Tipo assim `content: counters(section) attr(data-ponto);` e na tag li `` Testa e depois me fala se deu certo nunca tentei dessa forma rss mas pode dar certo...


VS says "Too few arguments...", but other compilers give me a correct output?

Question: I am doing edit-distance between two strings. It uses recursive function. Online compilers are compiling the code and giving me an output of 3, which is correct, but visual studio says "Too few argument in the function call" Can someone else please help out?
I have looked at other threads, and they genuinely missing arguments, but I do not, yet VS is flagging my recursive call
#include<iostream>
#include<string>
using namespace std;

int min(int x, int y, int z)
{
return min(min(x, y), z); // here VS flags error
}

int editDist(string str1, string str2, int m, int n)
{

if (m == 0) return n;

if (n == 0) return m;

if (str1[m - 1] == str2[n - 1])
    return editDist(str1, str2, m - 1, n - 1);

return 1 + min(editDist(str1, str2, m, n - 1),
    editDist(str1, str2, m - 1, n),
    editDist(str1, str2, m - 1, n - 1)
);
}

int main()
{
string str1 = "sunday";
string str2 = "saturday";

cout << editDist(str1, str2, str1.length(), str2.length());

return 0;
 }

Comment: Remove `using namespace std;` and use `std::min`. This is a perfect example for why you shouldn't use `using namespace std;`
Comment: @ThomasSablik Oh My God!! It worked. Never using `using namespace std` again. Thank you friend.
Answer: The problem is due to your function name matching with the standard minimum function std::min
int min(int x, int y, int z){
    return min(min(x, y), z); // the compiler is getting confused over whether to
    //call std::min which takes two parameters or user-defined min which
    //takes three parameters
    }

Change your function name and it should work fine.
Comment: Or better yet, remove `using namespace std;`
Comment: Hello! Thanks for answering. I just did it to X_Y_Z, still says, "Too Few Arguments for function call" And X_Y_Z does not take two arguments.
Comment: @Ayxan, just tried that too. `using std::cout` and `using std::string`. Same error as above.
Answer: Since you use std::min, you need to use #include <algorithm>.
If it works on some compilers, that's because got lucky and some of the headers you use include <algorithm> (maybe indirectly).


String para Array/List

Question: Tenho a seguinte String:
[{"Monstro":"Lobo","HP":100,"Level":2},{"Level":"1","HP":"100","Monstro":"Bruxa"}]

E preciso coloca-la dentro de uma Array ou List para pegar os valores de cada monstro.

Como eu faço isso?

Desculpe caso a dúvida pareça óbvia.
OBS: são dados de JSON que estão dentro dos […] normal do jeito que esta e tem a },{ vigula entre eles que seprar os 2 valores diferentes que estão dentro dos [...].
Comment: A melhor forma de fazer isso é criando uma classe e dando parse no json para um objeto da classe. Tem certeza que você deseja fazer assim?
Comment: sim eu usso a api org.json que não tem suporte ao parce e estou fazendo ums testes antes de montar eu mesmo essa parte da api. aproveitando como um desafio a min mesmo.
Comment: Precisa ser um array? Não pode utilizar `List`?
Comment: @Renan pode ser qualquer forma que de para eu escolher qual dos dois dados pegar.
Comment: OK, seu JSON está errado assim mesmo ou foi na hora de passar aqui para a pergunta? Existem chaves diferentes nos objetos `Monstro` e `Monstro:`.
Comment: @Renan nem percebi vou arrumar tive que digitar td ja que o ctrl+c/ctrl+v ta bugado no meu teclado
Answer: Eu seguiria a mesma ideia do comentário do @Francisco, criar um objeto que mapeasse os atributos do monstro: nome, hitpoints e level, ainda que não fosse utilizá-los por hora em minha aplicação. Mas, se o objetivo é somente obter todos os valores da chave Monstro, pode fazer assim:
public final List<String> getMonstros(String json){
    List<String> monsters = new ArrayList<>();
    try {
        new JSONArray(json).forEach(item -> {

            JSONObject object = (JSONObject) item;
            if(object.has("Monstro"))
                monsters.add(object.getString("Monstro"));

        });
    } catch(Exception ex){
        // Tratamento de exceção.
    }
    return monsters;
}

final String json = "[{\"Monstro\":\"Lobo\",\"HP\":100,\"Level\":2}, {\"Level\":\"1\",\"HP\":\"100\",\"Monstro\":\"Bruxu\"}]";
System.out.println(getMonstros(json)); // [Lobo, Bruxu]

Comment: sua resposta me deu uma ideia se usar esse mesmo codigo trocando `if(object.has("Monstro"))
                monsters.add(object.getString("Monstro"));` por `f(object.has("hp"))
                monsters.add(object.getString("hp"));` ele retorna na ordem?se ele retornar na ordem ja tenho uma ideia de como fazer o parcer do org.json
Comment: Ele nem funcionaria pois o atributo `HP` está em maiúsculo e é um tipo inteiro, teria que usar `object.getInt("HP")`. Mesmo assim, não retornaria em ordem (nem esse da minha resposta retorna ordenado), teria que utilizar o método [`Collections#sort()`](https://docs.oracle.com/javase/9/docs/api/java/util/Collections.html#sort-java.util.List-) para isto. E claro, ao invés de uma lista de strings, seria uma lista de inteiros.
Comment: então não retorna na ordem que esta na String do json?
Comment: to recebendo erro no `forEach`
Comment: Não, retornou em ordem porque a string está com os atributos `Lobo` e `Bruxu` em sequência. Qual erro está dando no `forEach`? Qual versão do Java está rodando?
Comment: java: `jdk1.8.0_151, jre1.8.0_151 forEach erro:cannot find symbol` e na hora de dar println da o erro:  `non-static method getMonstros(String) cannot be referenced from a static context`
Comment: vou ter que desligar o pc agora amanha vejo se resolvo, se tiver discord add#1011
Comment: Provavelmente você está chamando o método `getMonstros()` de um método estático. Basta mudar para `public static final Lista getMonstros()`.
Comment: agora so ta dando o erro do forEach
Comment: Qual erro.... ?
Comment: dx quieto arrumei uma outra forma para fazer isso vlw pela ajuda

String para Array/List


Can drupal be installed on a subdomain and used on the main domain?

Question: I was thinking about installing Drupal on admin.myexample.com for clients to access an add and edit news posts & products.
Then just using myexample.com as the main site. Calling the database and entries to their pages with PHP/SQL.
Is this practical?
I've been trying to learn my way around Drupal, I know this wouldn't be a way to learn. I'm much more comfortable writing the pages up myself than manipulating Drupal pages (at this point in time.)
Answer: Yes, you can have Drupal run in subdomain and have a completely different web site coded on the domain root.
Just make sure that the subdomain is directed at the Drupal root. To be clear, the Drupal root directory is the one that contains the following files:
authorize.php
CHANGELOG.txt
COPYRIGHT.txt
cron.php
.gitignore
.htaccess
includes
index.php
INSTALL.mysql.txt
INSTALL.pgsql.txt
install.php
INSTALL.sqlite.txt
INSTALL.txt
LICENSE.txt
MAINTAINERS.txt
misc
modules
profiles
README.txt
robots.txt
scripts
sites
themes
update.php
UPGRADE.txt
web.config
xmlrpc.php
Comment: Thanks. Appreciate it. I think it will be much easier for me to do this in the meanwhile while I learn the ropes in Drupal.
Answer: With Drupal (and many other CMSs) you don't need to have a separate domain for the admin area. Users simply login at domain.com/user/login.
If you especially want to use admin.domain.com as the login URL for users then a redirect would do fine, it is a kindof cool address.
But if you are thinking of writing your own code to get the content from the Drupal database for your main site then you are (just slightly) under-using Drupal. It is both the Content Management and Content Display platform and you would be creating your own version of the theme layer and hooks etc (might be fun though - definitely faster :).
The only advantages I could see in spreading out the admin (logged in) area of Drupal across to another domain would be in using a website caching service or some custom security for some reason.
So my advice is:
Yes, you can install Drupal on a sub domain, it is a domain in itself.
But no, don't bother having an admin domain and writing your own code to get the content from the database. Use Drupal for what its good at.


best windows based network monitoring software

Question: i want to know which is best windows based network monitoring tools mainly for monitoring network and control internet access.
i want to monitor the bandwidth of internet usage in each machine in network.
websites accessed by each machine.
is there any there is any opensource tools.
thanks in advance.
Answer: Once, I faced some problems with bandwidth. Which is that situation where too many users in a network causes lag and delay. Therefore I've search some solutions from my friends from abroad.
You can try this link to download the software which can control your network bandwidth as long as the pc is connected to the network.

http://www.netsoft2005.com/en/

It is called P2Pover, some kind of open-sourced software to monitor the network.
Dun worry, it's free =)
Comment: I checked this software.it is simple and good.thanks.
Answer: Well, a sniffer like WireShark or Network Monitor wouldn't help in that case, I guess.
Assuming you are in some kind of intranet with few uplinks to the internet, I'd suggest to configure the router that sits at this boundary to force traffic for certain ports (such as 80 for HTTP) through a transparent proxy (lighttpd, nginx and Apache with mod_rewrite can do that easily). That would satisfy the part about monitoring what gets accessed. However, for the amount traffic itself I have no immediate idea, except using the router to log that as well.


How is the "best loser" determined in football?

Question: We have played a 7-team competition, all seven teams met, we eliminated the team with the lowest points. After that the remaining six teams played knock out games and the three winning teams will go direct to semi-finals.
We decided that 4 teams should be picked to go for semi-final and that the best loser will join the other three to make it four teams to battle at the semi-final and final.
During the quarter final games, one team is beaten 2-0, another is beaten 3-0 and the third team is beaten in a penalty shoot-out by 4-0.
Now should you want a best loser to join the other three teams making four teams to play in the semi-final, who among these three teams would be in the best losers position.
Answer: It would have been better if there was predetermined criteria to select best loser. As there is no indication of that criteria, selecting best loser can be done in following ways:

Taking FKL Cup - Best loser rule : Since third team lost in penalties as opposed to other who were beaten in regulation time. So third team qualifies as best loser.
Looking at points or position after league matches : Among those three teams which performs best in league matches progresses to next round.
Comment: +1 for the first sentence. Making up the competition rules as you go along is pretty much a guaranteed way to end up with disgruntled teams when try lose out based on rules which didn't exist at the time.
Comment: This should have been discussed beforehand but as it is you take the team that lost in overtime.   In american football high-school down to pee-wee there are often playoff rules.   The most common is that you get a max of 13 points for a win and minus 13 in a blowout loss but in OT winner gets +1 even though they win by 6 most likely and loser -1.   In soccer if I ran a league I would probably put the max difference to 4-5 goals and OT win loss come down to half a goal.
Answer: Ideally, the rules of the tournament should be defined before it starts, but now that we're here:
In my opinion, the best loser out of 3 teams lost in the quarter-finals (or 1/6 finals in your case) is the one who performed better in the games involving only those 3 teams during round-robin phase or even who finished higher in the table.
Because this way the loser will be most probably the strongest one. Why? Here's a demonstrative example:
Answer: In my opinion you have to set quarterfinals with the best 6 teams as following:
Answer: I would say the third team, since they lost on a penalty shootout, thus implying that they were able to hold on to a draw throughout regulation and extra time. As for the other two teams, I infer from your post that they lost in regulation outright.
Answer: You're creating a problem that doesn't need to be solved, when better methods exist.
A quarterfinal round can be complete with only six teams. This naturally requires two byes, and it makes sense to have those be the two highest-ranked teams from pool play.
They are crossed in semifinals such that the first-ranked team plays the lowest-ranked quarterfinal winner, and the second-ranked team plays the highest-ranked quarterfinal winner, as done by a number of professional competitions.
Given that the games have already been played, the fourth place should go to the team with the best performance in the "quarterfinal" which is the team who achieved a draw, not either of the teams who were beaten.


convert image strings from an array into images in wordpress

Question: Im trying to set up a page on my site that has all the images from the media library on it shuffled up in a random order.
As of now I have the strings in a really long array and was wondering how I could turn them into images and "shuffle" them or maybe query them in a random order first and then convert them?
Have been stuck on this for awhile so any tips would be good.
Here is a link to the site http://ownc.co.nz/random/
Cheers
            <?php $query_images_args = array('post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'posts_per_page' => -1, );

            $query_images = new WP_Query($query_images_args);
            $images = array();
            foreach ($query_images->posts as $image) {
                $images[] = wp_get_attachment_url($image -> ID);
            }

            var_dump($images);
            ?>

Answer: To randomize your images you can add 'orderby' argument to WP_Query with the value of 'rand'
http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
alternatively you can shuffle the array
http://php.net/manual/en/function.shuffle.php
As far as converting I am not sure what you mean, if you have an array of urls than just do an image tag with the source of the url:
<?php foreach ($images as $img): ?>
<img src="<?php echo $img?>">
<?endforeach; ?>


How to understand the drawbacks of Hierarchical Clustering?

Question: Can someone explain the pros and cons of Hierarchical Clustering?

Does Hierarchical Clustering have the same drawbacks as K means?
What are the advantages of Hierarchical Clustering over K means?
When should we use K means over Hierarchical Clustering & vice versa?

Answers to this post explains the drawbacks of k means very well.
How to understand the drawbacks of K-means
Comment: In [this answer](http://stats.stackexchange.com/a/63549/3277) I touched some of potentially problematic facets of hierarchical agglomerative cluster analysis. The main "drawback" is that it is noniterative, single-pass greedy algorithm. With a greedy algorithm, you optimize the current step's task, which - for most HC methods - does not necessarily guarantee the best partition at a distant future step. The main advantage of HC is that it is flexible with respect to the choice of proximity measure to use. @Mic has already given a good answer below, so I'm just echoing.
Answer: Whereas $k$-means tries to optimize a global goal (variance of the clusters) and achieves a local optimum, agglomerative hierarchical clustering aims at finding the best step at each cluster fusion (greedy algorithm) which is done exactly but resulting in a potentially suboptimal solution.
One should use hierarchical clustering when underlying data has a hierarchical structure (like the correlations in financial markets) and you want to recover the hierarchy. You can still apply $k$-means to do that, but you may end up with partitions (from the coarsest one (all data points in a cluster) to the finest one (each data point is a cluster)) that are not nested and thus not a proper hierarchy.
If you want to dig into finer properties of clustering, you may not want to oppose flat clustering such as $k$-means to hierarchical clustering such as the Single, Average, Complete Linkages.
For instance, all these clustering are space-conserving, i.e. when you are building clusters you do not distort the space, whereas a hierarchical clustering such as Ward is not space-conserving, i.e. at each merging step it will distort the metric space.
To conclude, the drawbacks of the hierarchical clustering algorithms can be very different from one to another. Some may share similar properties to $k$-means: Ward aims at optimizing variance, but Single Linkage not. But they can also have different properties: Ward is space-dilating, whereas Single Linkage is space-conserving like $k$-means.
-- edit to precise the space-conserving and space-dilating properties
Space-conserving: $$D_{ij} \in \left[ \min_{x \in C_i, y \in C_j} d(x,y), \max_{x \in C_i, y \in C_j} d(x,y) \right]$$
where $D_{ij}$ is the distance between clusters $C_i$ and $C_j$ you want to merge, and $d$ is the distance between datapoints.
Space-dilating: $$D(C_i \cup C_j, C_k) \geq \max(D_{ik}, D_{jk}),$$
i.e. by merging $C_i$ and $C_j$ the algorithm will push further away the cluster $C_k$.
Comment: +1. However, `should use hierarchical clustering when underlying data has a hierarchical structure... and you want to recover the hierarchy` Not necessarily. In most cases rather on the contrary. The hierarhy of HC is rather [a story of the algo than a structure of the data](http://stats.stackexchange.com/a/63549/3277). Still, this question is ultimately philosophical/logical, not so statistical.
Comment: Can you give few more examples of data having hierarchical structure? Didn't follow the financial market example.
Comment: Sure. cf. http://arxiv.org/pdf/cond-mat/9802256.pdf or simply Figure 7 in http://arxiv.org/pdf/1506.00976.pdf which depicts a correlation matrix which has a (noisy) hierarchical correlation block structure: you can notice blocks on the main diagonal, which are divided into more blocks, each one divided into even more blocks. It corresponds roughly to a subdivision in regions (Europe, US, Asia ex-Japan, Japan), then each region divided by the asset quality (say high quality vs. junk), then divided by the big industrial sectors (retail, industry, media), further subdiv into (aerospace, auto...)
Comment: `Ward is not space-conserving, i.e. at each merging step it will distort the metric space`. Can you write more about it? This is not very much clear.
Comment: `Ward is space-dilating, whereas Single Linkage is space-conserving like k-means`. Did you want to say space-contracting for single linkage?
Comment: Agree with your first remark. Edit done for your second one. Hmm, I suppose it depends on the definitions. I remember of a paper studying how the Lance-Williams algorithms are partitioned according to such properties. Single Linkage was classified as a space-contracting (under their definition), but at the border of space-conserving (under their def). I usually define it in such a way that it is included in the "space-conserving" space.
Comment: @ttnphns "Still, this question is ultimately philosophical/logical, not so statistical" I'd just point out that a probability density has natural hierarchical structure when one considers the set of all connected components of superlevel sets -- an object commonly called the *cluster tree*. So it is natural to attempt to recover the hierarchical structure of data sampled from an arbitrary distribution, and we can talk about such notions as consistency w.r.t. hierarchical clustering algorithms (e.g., Hartigan consistency).
Comment: @jme, thank you. This is what I'm hardly familiar with. Will you want to issue a separate answer of yours, discussing it; it might be very interesting. (Perhaps you choose adding your answer not in this thread but in a more relevant one which I link to in the comment above?)
Comment: @ttnphns Sure, I can write up an answer with more details. I did a quick search through existing questions on the site, and it looks like this is the most relevant, so I'll just add an answer of my own below.
Answer: Scalability
$k$ means is the clear winner here. $O(n\cdot k\cdot d\cdot i)$ is much better than the $O(n^3 d)$ (in a few cases $O(n^2 d)$) scalability of hierarchical clustering because usually both $k$ and $i$ and $d$ are small (unfortunately, $i$ tends to grow with $n$, so $O(n)$ does not usually hold). Also, memory consumption is linear, as opposed to quadratic (usually, linear special cases exist).
Flexibility
$k$-means is extremely limited in applicability. It is essentially limited to Euclidean distances (including Euclidean in kernel spaces, and Bregman divergences, but these are quite exotic and nobody actually uses them with $k$-means). Even worse, $k$-means only works on numerical data (which should actually be continuous and dense to be a good fit for $k$-means).
Hierarchical clustering is the clear winner here. It does not even require a distance - any measure can be used, including similarity functions simply by preferring high values to low values. Categorial data? sure just use e.g. Jaccard. Strings? Try Levenshtein distance. Time series? sure. Mixed type data? Gower distance. There are millions of data sets where you can use hierarchical clustering, but where you cannot use $k$-means.
Model
No winner here. $k$-means scores high because it yields a great data reduction. Centroids are easy to understand and use.
Hierarchical clustering, on the other hand, produces a dendrogram. A dendrogram can also be very very useful in understanding your data set.
Comment: Both can work, and both can fail. That is why things like dendrograms are useful. Never trust a clustering result to be "correct", ever.
Comment: Does Hierarchical fail like k means when clusters are 1)non spherical 2) have different radius 3) have different density?
Comment: Hierarchical clustering may give locally optimise clusters as it is based on greedy approach but K means gives globally optimised clusters. I have also experienced that explanation of hierarchical clustering is relatively easy to business people compare to K means.
Answer: I just wanted to add to the other answers a bit about how, in some sense, there is a strong theoretical reason to prefer certain hierarchical clustering methods.
A common assumption in cluster analysis is that the data are sampled from some underlying probability density $f$ that we don't have access to. But suppose we had access to it. How would we define the clusters of $f$?
A very natural and intuitive approach is to say that the clusters of $f$ are the regions of high density. For example, consider the two-peaked density below:

By drawing a line across the graph we induce a set of clusters. For instance, if we draw a line at $\lambda_1$, we get the two clusters shown. But if we draw the line at $\lambda_3$, we get a single cluster.
To make this more precise, suppose we have an arbitrary $\lambda > 0$. What are the clusters of $f$ at level $\lambda$? They are the connected component of the superlevel set $\{x : f(x) \geq \lambda \}$.
Now instead of picking an arbitrary $\lambda$ we might consider all $\lambda$, such that the set of "true" clusters of $f$ are all connected components of any superlevel set of $f$. The key is that this collection of clusters has hierarchical structure.
Let me make that more precise. Suppose $f$ is supported on $\mathcal X$. Now let $C_1$ be a connected component of $\{ x : f(x) \geq \lambda_1 \}$, and $C_2$ be a connected component of $\{ x : f(x) \geq \lambda_2 \}$. In other words, $C_1$ is a cluster at level $\lambda_1$, and $C_2$ is a cluster at level $\lambda_2$. Then if $\lambda_2 < \lambda_1$, then either $C_1 \subset C_2$, or $C_1 \cap C_2 = \emptyset$. This nesting relationship holds for any pair of clusters in our collection, so what we have is in fact a hierarchy of clusters. We call this the cluster tree.
So now I have some data sampled from a density. Can I cluster this data in a way that recovers the cluster tree? In particular, we'd like a method to be consistent in the sense that as we gather more and more data, our empirical estimate of the cluster tree grows closer and closer to the true cluster tree.
Hartigan was the first to ask such questions, and in doing so he defined precisely what it would mean for a hierarchical clustering method to consistently estimate the cluster tree. His definition was as follows: Let $A$ and $B$ be true disjoint clusters of $f$ as defined above -- that is, they are connected components of some superlevel sets. Now draw a set of $n$ samples iid from $f$, and call this set $X_n$. We apply a hierarchical clustering method to the data $X_n$, and we get back a collection of empirical clusters. Let $A_n$ be the smallest empirical cluster containing all of $A \cap X_n$, and let $B_n$ be the smallest containing all of $B \cap X_n$. Then our clustering method is said to be Hartigan consistent if $\Pr(A_n \cap B_n) = \emptyset \to 1$ as $n \to \infty$ for any pair of disjoint clusters $A$ and $B$.
Essentially, Hartigan consistency says that our clustering method should adequately separate regions of high density. Hartigan investigated whether single linkage clustering might be consistent, and found that it is not consistent in dimensions > 1. The problem of finding a general, consistent method for estimating the cluster tree was open until just a few years ago, when Chaudhuri and Dasgupta introduced robust single linkage, which is provably consistent. I'd suggest reading about their method, as it is quite elegant, in my opinion.
So, to address your questions, there is a sense in which hierarchical cluster is the "right" thing to do when attempting to recover the structure of a density. However, note the scare-quotes around "right"... Ultimately density-based clustering methods tend to perform poorly in high dimensions due to the curse of dimensionality, and so even though a definition of clustering based on clusters being regions of high probability is quite clean and intuitive, it often is ignored in favor of methods which perform better in practice. That isn't to say robust single linkage isn't practical -- it actually works quite well on problems in lower dimensions.
Lastly, I'll say that Hartigan consistency is in some sense not in accordance with our intuition of convergence. The problem is that Hartigan consistency allows a clustering method to greatly over-segment clusters such that an algorithm may be Hartigan consistent, yet produce clusterings which are very different than the true cluster tree. We have produced work this year on an alternative notion of convergence which addresses these issues. The work appeared in "Beyond Hartigan Consistency: Merge distortion metric for hierarchical clustering" in COLT 2015.
Comment: This is an interesting way of thinking about hierarchical clustering. I find it strongly reminiscent of clustering by nonparametric density estimation ([pdf](http://link.springer.com/article/10.1007/s11222-006-9010-y)), which is implemented in `R` in the [pdfCluster](https://cran.r-project.org/web/packages/pdfCluster/index.html) package. (I discuss it [here](http://stats.stackexchange.com/a/172838/7290).)
Comment: HDBSCAN* uses a similar approach.
Answer: An additional practical advantage in hierarchical clustering is the possibility of visualising results using dendrogram. If you don't know in advance what number of clusters you're looking for (as is often the case...), you can the dendrogram plot can help you choose $k$ with no need to create separate clusterings. Dedrogram can also give a great insight into data structure, help identify outliers etc. Hierarchical clustering is also deterministic, whereas k-means with random initialization can give you different results when run several times on the same data. In k-means, you also can choose different methods for updating cluster means (although the Hartigan-Wong approach is by far the most common), which is no  issue with hierarchical method.
EDIT thanks to ttnphns: One feature that hierarchical clustering shares with many other algorithms is the need to choose a distance measure. This is often highly dependent on the particular application and goals. This might be seen as an additional complication (another parameter to select...), but also as an asset - more possibilities. On the contrary, classical K-means algorithm specifically uses Euclidean distance.
Comment: I suppose "problem" in your last paragraph would be seen positively as an asset. K-means, however, is _based implicitly_ on [euclidean distance only](http://stats.stackexchange.com/q/81481/3277).
Comment: Many possible choices can be a problem as well as an asset, indeed :) Thanks for the comment on k-means, I'll improve that paragraph.
Comment: @ttnphns Actually, " $k$-means " can be used with any Bregman divergences http://www.jmlr.org/papers/volume6/banerjee05b/banerjee05b.pdf ; I mean this is the case when considering that $k$-means is what results when considering the limiting case of Gaussian mixture models (from soft to hard), then by replacing Gaussian by another member of the exponential family, you replace the Euclidean distance by another Bregman divergence associated with the member of the family you picked. You end up with a similar algorithm scheme that aims to find a maximum likelihood with an expectation-maximization.
Comment: I believe the original question was made with regard to "classical' K-means and not a slightest intention to delve into Bregman divergences. Nice remark though, I'll check out this paper more thoroughly for sure.
Comment: @mic nobody uses Bregman divergences beyond variations of Euclidean distance... it is a tiny tiny class only. But people would like to use e.g. Manhattan distance, Gower etc. which are not Bregman divergences for all I know.


nullpointer LocationManager getLatitude

Question: I'm getting a null pointer exception on the line that calls get latitude in my GPSTracker class. Any ideas why? I'm using a mobile device as well, not DDMS. I've done a System.out.println(gps.getLatitude()) and it indeed does return null, but I can't figure out why. The GPS on my phone is turned on as well
Here is my class
public class GPSTracker extends Service implements LocationListener{

    private final Context mContext;
    boolean isGPSEnabled = false;
    boolean isNetworkEnabled = false;
    boolean canGetLocation = false;

    Location location;
    Double latitude;
    Double longitude;

    private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; //10 meters
    private static final long  MIN_TIME_BW_UPDATES = 1000 * 60 * 1; //1 minute
    protected LocationManager locationManager;

    public GPSTracker (Context context){
        this.mContext = context;
        getLocation();
    }

    public Location getLocation() {
        try {
            locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);

            //getting GPS status
            isGPSEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
            System.out.println(location.getLatitude());

            if(!isGPSEnabled && !isNetworkEnabled){
                //no network provider is enabled
            } else{
                this.canGetLocation = true;
                // First get location from Network provider
                if (isNetworkEnabled){
                    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                    Log.d("Network", "Network");
                    if(locationManager != null){
                        location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                        if(location != null){
                            latitude = location.getLatitude();
                            longitude = location.getLongitude();
                        }
                    }
                }
                if (isGPSEnabled){
                    if(location == null){
                        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                                MIN_TIME_BW_UPDATES,
                                MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                        Log.d("GPS Enabled", "GPS Enabled");
                        if(locationManager != null){
                            location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                            if(location != null){
                                latitude = location.getLatitude();
                                longitude = location.getLongitude();
                            }
                        }
                    }
                }
            }
        } catch (Exception e){
            e.printStackTrace();
        }
        return location;
    }
    /**
     * Function to get latitude
     * */
    public double getLatitude(){
        if(location != null){
            latitude = location.getLatitude();
            System.out.println(latitude);
            return 0.0;
        }
        System.out.println(latitude);
        return latitude;
    }
    public double getLongitude(){
        if(location != null){
            longitude = location.getLongitude();
            System.out.println(longitude);
            return 0.0;
        }
        return longitude;
    }

    /**
     * Function to show setting alert dialog
     */
    public void showSettingsAlert(){
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

        //Setting Dialog Title
        alertDialog.setTitle("GPS is settings");
        //Setting Dialog Message
        alertDialog.setMessage("GPS is not enabled. Do you want to go to settings and enable GPS?");
        //Setting Icon to Dialog
        //alertDialog.setIcon(R.drawable.delete);
        //On Pressing Settings button
        alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        mContext.startActivity(intent);

            }
        });
        //on pressing cancel button
        alertDialog.setNegativeButton("Cancel",  new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which){
                dialog.cancel();
            }
        });
        //Showing alert message
        alertDialog.show();
    }

    public void stopUsingGPS(){
        if(locationManager != null){
            locationManager.removeUpdates(GPSTracker.this);
        }
    }
    @Override
    public void onLocationChanged(Location location){
    }
    @Override
    public void onProviderDisabled(String provider){
    }
    @Override
    public void onProviderEnabled(String provider){
    }
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras){
    }
    @Override
    public IBinder onBind(Intent arg0){
        return null;
    }
}

Where I parse my the JSON
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class JSONParser {
      static InputStream is = null;
      static JSONObject jObj = null;
      static String json = "";
      // constructor
      public JSONParser() {
      }
      public JSONObject getJSONFromUrl(String myurl) {
        // Making HTTP request
        try {
          // defaultHttpClient
            URL url = new URL(myurl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setReadTimeout(10000 /* milliseconds */);
            conn.setConnectTimeout(15000 /* milliseconds */);
            conn.setRequestMethod("GET");
            conn.setDoInput(true);
            // Starts the query
            conn.connect();
            int response = conn.getResponseCode();
            Log.d("HttpConnection", "The response is: " + response);
            is = conn.getInputStream();
        } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        } catch (ClientProtocolException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }

        try {
          BufferedReader reader = new BufferedReader(new InputStreamReader(
              is, "iso-8859-1"), 8);
          StringBuilder sb = new StringBuilder();
          String line = null;
          while ((line = reader.readLine()) != null) {
            sb.append(line + "n");
          }
          is.close();
          json = sb.toString();
        } catch (Exception e) {
          Log.e("Buffer Error", "Error converting result " + e.toString());
        }
        // try parse the string to a JSON object
        try {
          jObj = new JSONObject(json);
        } catch (JSONException e) {
          Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
        // return JSON String
        return jObj;
      }
    }

My main activity
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;

    public class MainActivity extends Activity {

        public TextView weather = null;
        public TextView summary = null;
        public TextView icon = null;
        public JSONObject currentTemperature = null;
        public String temperature = "";
        public String weatherSummary = "";
        public String weatherIcon = "";
        public GPSTracker gps;
        public double latitude = 0;
        public double longitude = 0;
        public String myUrl;
        public TextView latitudeView = null;
        public TextView longitudeView = null;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            weather = (TextView) findViewById(R.id.weather);
            summary = (TextView) findViewById(R.id.weather_summary);
            icon = (TextView) findViewById(R.id.string_icon);
            // we will using AsyncTask during parsing
            new AsyncTaskParseJson().execute();

            gps = new GPSTracker(MainActivity.this);
            myUrl = "https://api.forecast.io/forecast/5530508d3568e57848d53bf10cfade1f/35.9033,-79.0440";
                //gps.getLatitude() + "," + gps.getLongitude();

             double lat = gps.getLatitude();
             double longitude = gps.getLatitude();
             latitudeView.setText(String.valueOf(lat));
             longitudeView.setText(String.valueOf(longitude));
        }

       /* public String convertLatitude(){
            latitude = gps.getLatitude();
            String latitude2 = Double.toString(latitude);

            return latitude2;
        }*/

       /* public String convertLongitude(){
            longitude = gps.getLongitude();
            String longitude2 = Double.toString(longitude);

            return longitude2;
        }*/

        //do in background method to call JSON Parser
        public class AsyncTaskParseJson extends AsyncTask<String, String, String> {
            final String TAG = "AsyncTaskParseJson.java";

            @Override
            protected String doInBackground(String... arg0){

               try {

                    // instantiate our json parser
                    JSONParser jParser = new JSONParser();
                    // get json string from url
                    JSONObject json = jParser.getJSONFromUrl(myUrl);

                    JSONObject current = json.getJSONObject("currently");
                    temperature = current.getString("temperature");

                    weatherSummary = current.getString("summary");
                    weatherIcon = current.getString("icon");

                } catch (JSONException e) {
                  e.printStackTrace();
                }
            return myUrl;

            }

            @Override
            protected void onPostExecute(String strFromDoInBg) {

                 weather.setText(temperature);
                 summary.setText(weatherSummary);
                 icon.setText(weatherIcon);

            }
        }
    }

And my LogCat
07-12 15:13:31.373: W/System.err(32167): java.lang.NullPointerException
07-12 15:13:31.378: W/System.err(32167):    at rafa.weatherapp.GPSTracker.getLocation(GPSTracker.java:42)
07-12 15:13:31.378: W/System.err(32167):    at rafa.weatherapp.GPSTracker.<init>(GPSTracker.java:33)
07-12 15:13:31.378: W/System.err(32167):    at rafa.weatherapp.MainActivity.onCreate(MainActivity.java:39)
07-12 15:13:31.378: W/System.err(32167):    at android.app.Activity.performCreate(Activity.java:5451)
07-12 15:13:31.378: W/System.err(32167):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
07-12 15:13:31.378: W/System.err(32167):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
07-12 15:13:31.378: W/System.err(32167):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
07-12 15:13:31.378: W/System.err(32167):    at android.app.ActivityThread.access$900(ActivityThread.java:175)
07-12 15:13:31.378: W/System.err(32167):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
07-12 15:13:31.378: W/System.err(32167):    at android.os.Handler.dispatchMessage(Handler.java:102)
07-12 15:13:31.378: W/System.err(32167):    at android.os.Looper.loop(Looper.java:146)
07-12 15:13:31.378: W/System.err(32167):    at android.app.ActivityThread.main(ActivityThread.java:5602)
07-12 15:13:31.378: W/System.err(32167):    at java.lang.reflect.Method.invokeNative(Native Method)
07-12 15:13:31.378: W/System.err(32167):    at java.lang.reflect.Method.invoke(Method.java:515)
07-12 15:13:31.378: W/System.err(32167):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
07-12 15:13:31.378: W/System.err(32167):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
07-12 15:13:31.378: W/System.err(32167):    at dalvik.system.NativeStart.main(Native Method)
07-12 15:13:31.378: I/System.out(32167): null
07-12 15:13:31.378: D/AndroidRuntime(32167): Shutting down VM
07-12 15:13:31.378: W/dalvikvm(32167): threadid=1: thread exiting with uncaught exception (group=0x41886c08)
07-12 15:13:31.378: W/System.err(32167): java.net.MalformedURLException
07-12 15:13:31.378: W/System.err(32167):    at java.net.URL.<init>(URL.java:152)
07-12 15:13:31.378: W/System.err(32167):    at java.net.URL.<init>(URL.java:125)
07-12 15:13:31.378: W/System.err(32167):    at rafa.weatherapp.JSONParser.getJSONFromUrl(JSONParser.java:29)
07-12 15:13:31.378: W/System.err(32167):    at rafa.weatherapp.MainActivity$AsyncTaskParseJson.doInBackground(MainActivity.java:76)
07-12 15:13:31.378: E/AndroidRuntime(32167): FATAL EXCEPTION: main
07-12 15:13:31.378: E/AndroidRuntime(32167): Process: rafa.weatherapp, PID: 32167
07-12 15:13:31.378: E/AndroidRuntime(32167): java.lang.RuntimeException: Unable to start activity ComponentInfo{rafa.weatherapp/rafa.weatherapp.MainActivity}: java.lang.NullPointerException
07-12 15:13:31.378: E/AndroidRuntime(32167):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at android.app.ActivityThread.access$900(ActivityThread.java:175)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at android.os.Handler.dispatchMessage(Handler.java:102)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at android.os.Looper.loop(Looper.java:146)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at android.app.ActivityThread.main(ActivityThread.java:5602)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at java.lang.reflect.Method.invokeNative(Native Method)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at java.lang.reflect.Method.invoke(Method.java:515)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at dalvik.system.NativeStart.main(Native Method)
07-12 15:13:31.378: E/AndroidRuntime(32167): Caused by: java.lang.NullPointerException
07-12 15:13:31.378: E/AndroidRuntime(32167):    at rafa.weatherapp.GPSTracker.getLatitude(GPSTracker.java:92)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at rafa.weatherapp.MainActivity.onCreate(MainActivity.java:43)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at android.app.Activity.performCreate(Activity.java:5451)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
07-12 15:13:31.378: E/AndroidRuntime(32167):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
07-12 15:13:31.378: E/AndroidRuntime(32167):    ... 11 more
07-12 15:13:31.383: W/ActivityManager(2431):   Force finishing activity rafa.weatherapp/.MainActivity
07-12 15:13:31.388: W/System.err(32167):    at rafa.weatherapp.MainActivity$AsyncTaskParseJson.doInBackground(MainActivity.java:1)
07-12 15:13:31.388: W/System.err(32167):    at android.os.AsyncTask$2.call(AsyncTask.java:288)
07-12 15:13:31.388: W/System.err(32167):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-12 15:13:31.388: W/System.err(32167):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
07-12 15:13:31.388: W/System.err(32167):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
07-12 15:13:31.388: W/System.err(32167):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
07-12 15:13:31.388: W/System.err(32167):    at java.lang.Thread.run(Thread.java:841)
07-12 15:13:31.388: E/Buffer Error(32167): Error converting result java.lang.NullPointerException: lock == null
07-12 15:13:31.393: E/JSON Parser(32167): Error parsing data org.json.JSONException: End of input at character 0 of

Comment: Did you set appropriate permissions in your manifest?   ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION
Comment: i've ACCESS_FINE_LOCATION
Comment: is getLongitude returning null as well? or jsut latitude?
Comment: both are returning null
Comment: And the location object is definitely not null?  It seems pretty weird if `getLastKnownLocation()` is returning a non null location but both longitude and latitude are null.  Can you log longitude and latitude in your `onLocationChanged()` for the location thats passed in to see if that is ever getting called with valid location?
Answer: Check that the location of the permissions are in the appropriate place within the manifest. It may help if you post the contents of your manifest.
Answer: replace all
System.out.println("")

with
Log.d("", "");

Answer: try replacing:
   gps = new GPSTracker(MainActivity.this);

with
 gps = new GPSTracker(getApplicationContext());

also
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                        MIN_TIME_BW_UPDATES,
                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                Log.d("GPS Enabled", "GPS Enabled");
                if(locationManager != null){
                    location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                    if(location != null){
                        latitude = location.getLatitude();
                        longitude = location.getLongitude();
                    }
                }

on getLastKnownLocation might be null if you've never actually gotten a location before. I would suggest putting the latitude = location.getLatitude() calls into the onLocationChanged method so you guarantee you are getting the correct location, asynchronously.

nullpointer LocationManager getLatitude


Identity Server 4 and auto redirect on sign out

Question: Playing around with a demo project from PluralSight, I am trying to have the IDP redirect back to the server app on sign out.
The PostLogOutRedirectUris is defined in the config for the Client at the IDP level, but it doesn't seem to have any effect.
public static IEnumerable<Client> Clients =>
    new Client[]
    {
        new Client
        {
            ClientId = "bethanyspieshophr",
            ClientName = "Bethany's Pie Shop HRM",
            AllowOfflineAccess = true,
            AccessTokenLifetime = 120,
            RequireConsent = false,
            RequirePkce = true,
            AllowedGrantTypes = GrantTypes.Code,
            ClientSecrets = {
                new Secret("108B7B4F-BEFC-4DD2-82E1-7F025F0F75D0".Sha256()) },
            RedirectUris = { "https://localhost:44301/signin-oidc" },
            PostLogoutRedirectUris = { "https://localhost:44301/signout-oidc" },
            AllowedScopes = { "openid", "profile", "email", "bethanyspieshophrapi" }
        }
    };

If I manually at runtime set the LoggedOutViewModel it works as expected.
Answer: How are you performing the logout request? Remember that the value in the client settings is just the registered value which is verified during logout request. The user is not redirected automatically to the postLogoutRedirectUri. You have to pass a post_logout_redirect_uri parameter to the end session endpoint and this parameter must match on of the values in the PostLogoutRedirectUris setting. To use this feature you should also post a valid ID token in the id_token_hint parameter, so that the server knows which client is requesting the logout.
You can have a look at the end session enpoint docs for details.
Comment: Thanks Michael, but the solution was simply that I used the wrong Uri. It should be ../signout-callback-oidc. The eyes sometimes reads what you want to see, not what it actually says :)
Answer: The issue was simply due to a typo, which sent me on a wild goose chase.
  PostLogoutRedirectUris = { "https://localhost:44301/signout-oidc" },

Should be
  PostLogoutRedirectUris = { "https://localhost:44301/signout-callback-oidc" },

And then, it worked.


Geometric proof for $|| u ||^2 + || v ||^2 = \frac{1}{2}||u-v||^2 + 2||\frac{u+v}{2}||^2$

Question: Is there an geometric proof for the following identity?

$|| u ||^2 + || v ||^2 = \frac{1}{2}||u-v||^2 + 2||\frac{u+v}{2}||^2$.

The norm here is normal Euclidean norm, and $u,v$ are vectors.
Answer: Not sure what you mean by a "geometric proof" so I'll reduce it to a statement in classical Euclidean geometry.
Consider the vectors $u-v$ and $u+v$ to be two edges of a triangle which meet at the origin (which is a vertex of said triangle). Call this triangle $ABC$ where $A$ is the origin and $AB$ is $u-v$ and $AC$ is $u+v$.
In this case the vector $u$ is simply the median of this triangle. Call $D$ the midpoint of $BC$. The distances $BD$ and $CD$ are both half of $BC$ and are equal to $|| v||$.
So your formula turns into $\displaystyle \frac{AB^2 + AC^2}{2} = AD^2 + BD^2$ which is the well-known theorem of Apollonius.


Importar decimal com vírgula

Question: No SQL Server, estou tentando executar um SELECT em um arquivo *.csv da seguinte forma:
SELECT *
FROM OPENROWSET(BULK 'C:\Minha_Pasta\meu_arquivo.csv',
                FORMATFILE = 'C:\Minha_Pasta\format.xml') AS Contents

meu_arquivo.csv está da seguinte forma:
1;Joãozinho;172,1
2;Mariazinha;163,5

format.xml está assim:
<?xml version="1.0"?>
<BCPFORMAT
    xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <RECORD>
        <FIELD ID="1"   xsi:type="CharTerm" TERMINATOR=";" />
        <FIELD ID="2"   xsi:type="CharTerm" TERMINATOR=";" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
        <FIELD ID="3"   xsi:type="CharTerm" TERMINATOR="\r\n" />
    </RECORD>
    <ROW>
        <COLUMN SOURCE="1"  NAME="ID"      xsi:type="SQLBIGINT"    NULLABLE="YES" />
        <COLUMN SOURCE="2"  NAME="Nome"    xsi:type="SQLNVARCHAR"  NULLABLE="YES" />
        <COLUMN SOURCE="3"  NAME="Altura"  xsi:type="SQLDECIMAL"   NULLABLE="YES" />
    </ROW>
</BCPFORMAT>

O problema é que a o valor decimal está sendo separado por vírgula ao invés de ponto. Existe alguma forma de resolver isso no format.xml com algo como COLLATION sem precisar alterar o arquivo manualmente? Infelizmente, pelo que vi COLLATION só se aplica para textos.
Comment: A resposta resolveu o que estava em dúvida? Acha que é possível aceitá-la agora?
Answer: É possível resolver com replace:
SELECT *, CAST(REPLACE(AlturaOrig, ',', '.') AS DECIMAL(5, 1)) AS Altura
FROM OPENROWSET(BULK 'C:\Minha_Pasta\meu_arquivo.csv',
                FORMATFILE = 'C:\Minha_Pasta\format.xml') AS Contents

Com este format.file:
<?xml version="1.0"?>
<BCPFORMAT
    xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <RECORD>
        <FIELD ID="1"   xsi:type="CharTerm" TERMINATOR=";" />
        <FIELD ID="2"   xsi:type="CharTerm" TERMINATOR=";" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
        <FIELD ID="3"   xsi:type="CharTerm" TERMINATOR="\r\n" />
    </RECORD>
    <ROW>
        <COLUMN SOURCE="1"  NAME="ID"      xsi:type="SQLBIGINT"    NULLABLE="YES" />
        <COLUMN SOURCE="2"  NAME="Nome"    xsi:type="SQLNVARCHAR"  NULLABLE="YES" />
        <COLUMN SOURCE="3"  NAME="AlturaOrig"  xsi:type="SQLCHAR"   NULLABLE="YES" />
    </ROW>
</BCPFORMAT>

Comment: Obrigado pela resposta @murillo-goulart , na verdade essa seria minha segunda alternativa, e funciona bem realmente! Mas eu não gostaria de fazer conversões no select, e sim algum tipo de "conversão" no XML. Estou achando que isso não é possível e a alternativa que vc apresentou é a única mesmo (salvo alterar manualmente as vírgulas por ponto).
Comment: @JedaiasRodrigues Ok, valeu!
Comment: Vou só esperar mais um pouco para ver se alguém mais oferece alguma outra alternativa. Muito obrigado mais uma vez.

Importar decimal com vírgula


Blur effect on SwiftUI NavigationBar stops working if I add content to the bottom of my view

Question: I have a very simple View with NavigationBar and a List in a VStack.  If I scroll up on the list, the list contents will appear behind the NavigationBar with a nice blur effect by default.  This behavior is correct.
The correct blur effect
I would also like to have some fixed text below my list that doesn't scroll.  However, if I add the following single line of code Text("bottom") below the list, the blur effect on the NavigationBar doesn't work anymore.
The blur effect is gone
struct ContentView: View {

    var body: some View {
        NavigationView {
            VStack {
                List {
                    Text("Hello, world!")
                        .foregroundColor(.red)
                        .font(.system(size: 70))
                }
                .listStyle(.plain)
                .border(.red)

                Text("bottom")  // remove this and the blur works
            }
            .background(.black)
            .navigationBarTitle("test", displayMode: .inline)
        }
    }
}

Why is this happening, and how can I get content below my list while retaining the blur effect?
Comment: You are adding black as the background. How did you get blur effect the first time. Could you check your code
Comment: Go ahead and try it yourself.  Paste the code above into XCode and remove the `Text("bottom")` line.  You will see that indeed the background is black, but when you scroll the list up, as the red text disappears behind the navigation bar, there is a blurred effect in the navigation bar which is common in many Apple apps. If you add the text line back in, the navigation bar becomes completely transparent when you scroll the list up.
Comment: is your question why this is happening or is your question how to achieve a bottom overlay?
Answer: This is mostly an educated guess, based on some interesting facts revealed in this article. Basically, UIKit has some internal logic for when it detects that the first view in a hierarchy is a UIScrollView, and it adapts the navigation bar behavior based on that. And either SwiftUI is still built on top of UIKit, or it has inherited that logic.
With the label in place, the list is not the first element in the UI tree, for some reason SwiftUI puts the label before the list, even if in the code is the other way around, and this causes the navigation bar logic to break.
If we capture the UI hierarchy of the app, this is what we see if the "bottom" label is part of the app:

, however, if we comment off the line with the label, we get this:

The above images confirm the theory that iOS gives different treatments when it detects a scroll view is the main view.
Answer: I had the same issue and found two possible solutions for this. Either use a section footer or use an overlay. Each will give you a different placement of the text: The footer places the text right below the section, the overlay at the very bottom of the screen hovering above the list.
Section footer
struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                Section {
                    Text("Hello, world!")
                        .foregroundColor(.red)
                        .font(.system(size: 70))
                } footer: {
                    Text("Bottom Text")
                }
            }
            .listStyle(.plain)
            .navigationBarTitle("Test", displayMode: .inline)
        }
    }
}

Overlay
struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                Text("Hello, world!")
                    .foregroundColor(.red)
                    .font(.system(size: 70))
            }
            .listStyle(.plain)
            .navigationBarTitle("Test", displayMode: .inline)
            .overlay(alignment: .bottom) {
                Text("Bottom Text")
            }
        }
    }
}


Jquery jtable in php not showing at front end table record

Question: Using jquery jtable but not showing record list...at front end this showing data is not available while there are 10 records in the database.

    <link href="themes/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
    <link href="Scripts/jtable/themes/lightcolor/blue/jtable.css" rel="stylesheet" type="text/css" />

Comment: Yo should show your PersonActions.php file here.
Answer: you must check the other page "PersonActions.php".
first you have to enter the table fields currectly in the position
if the fields are like (id,name,age,date)
you have to enter like this
fields: {
    id: {
        key: true,
        create: false,
        edit: false,
        list: false
    },
    name: {
        title: 'Author Name',
        width: '40%'
    },
    age: {
        title: 'Age',
        width: '20%'
    },
    date: {
        title: 'Record date',
        width: '30%',
        type: 'date',
        create: false,
        edit: false
    }
}

and in "PersonActions.php" you have to check the connection,query and every thing


How to find the derivative of $g(x)$ under this kind of situation

Question: Suppose we have $g(x) = \int_{-\infty}^{\infty} \frac{f(u)}{d(u,x)} du$ where $g,f,d$ are all functions.
How can we find the derivative of $g(x)$ under this situation
Comment: Welcome to MSE. Please use [MathJax](https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference).
Comment: If you do not tell, what kind of functions $f$ and $d$ are, no answer is possible !
Answer: Assuming that the conditions for derivation under the integral sign are fulfilled,
$$\frac d{dx}\int_{-\infty}^\infty\frac{f(u)}{d(u, x)}du=\int_{-\infty}^\infty\frac\partial{\partial x}\frac{f(u)}{d(u, x)}du=-\int_{-\infty}^\infty\frac{\partial d(u,x)}{\partial x}\frac{f(u)}{d^2(u, x)}du.$$


Countable base-Topology

Question: Can you please help me to prove that if a space has a countable base, then it has countable dense subset?
I know this happens in the real line, i.e.: it has a countable base as $\{(a,b):a,b \in\Bbb Q\}$ and $\Bbb Q$ is dense in $\Bbb R$.
But how can I generalize this result as mentioned in the problem?
Answer: We (commonly) say a topological space that has a countable base is  second countable. And we also (commonly) say a topological space that has a countable dense subset to be separable.
Here, we would like to show that a topological space $(X,\tau)$ that is second countable implies it is separable.
Let ${\scr B}=\{B_n\}_{n\in{\bf N}} $ be a countable base for $X$. We need a candidate set that could possibly be a countable dense subset of $X$. Since we only have information about ${\scr B}$ is countable, we use it to construct a set.
Suppose without loss that every base set in the collection $\scr B$ is not empty. Now, for each $B_n\in {\scr B}$, pick any element $x_n\in B_n$. This is possible since each $B_n$ is not empty. (And this infinitary choice is possible by Axiom of Choice.)
Write $D=\{x_n\}_{n\in{\bf N}}$, the collection of $x_n$ we just constructed. This set $D$ is our candidate set that is (i) countable, and (ii) dense in $X$.
We know $D$ is countable because we picked an $x_n$ for each $B_n$ from $\scr B$, that is, $D$ is bijective to our countable base $\scr B$. Hence $D$ is (i) countable.
Now we would like to show $D$ is dense in $X$. Recall the definition of a dense set $E$: We say $E$ is dense in $X$ if every nonempty open set $U$ of $X$ intersects $E$.
Now, also recall a property of a base $\scr B$: If $\scr B$ is a base then for every open set $U$ of $X$, and each point $x\in U$, there exists $B\in{\scr B}$ such that $x\in B\subset U$.
Try to show (ii) by using the definition of denseness and definition of a base.
Hint: To show (ii), take any nonempty open set $U$ of $X$. We need to show $U$ intersects our set $D$. Note for any $x\in U$, there exists a base $B_k$ such that $x\in B_k\subset U$. But $B_k$ contains $x_k\in D$. We have claimed.
Answer: Pick one point from every member of the countable base.

Countable base-Topology