Start spring scheduling based on some Event

Question: I need to start spring scheduling based on the constraint that my scheduler job will run every 5 seconds after a receive a jms message from other component.
What can be the possible way to implement /handle this scenario ,googled for the same but the solutions ask me to have a property in properties file for enabling scheduling which again is static approach.
Kindly suggest some solutions.
Answer: You can use:-

Thread.sleep(long delay)  after receiving a message from JMS queue i.e. Thread.sleep(300000);

Basically your problem is not related to a scheduler. The message received from the queue is a trigger to invoke the job in your case.
Whereas the scheduled tasks are the ones which keeps repeating them periodically either based on fixed delay or fixed interval or at specific time.

Your job is event based and not on time based so its not a scheduled
  job.
Comment: after I get the message I have execute that method every 5 seconds .Is some thing not possible by aid of spring
Comment: http://stackoverflow.com/questions/14630539/scheduling-a-job-with-spring-programmitically-with-a-fixedrate-set-from-a-databa/14632758#14632758 check this link if it helps.


Crystal Reports XI- blank last page

Question: I have a report with 2 subreports. When the 1st subreport is pretty long (but still leaving a good few cm on the page) and the 2nd empty, I often get an extra page printed with only page header and footer.
The subreports and sections are set to be suppressed when blank and it seems to work: I tested this by setting different colours to them and they don't appear. The strange thing is that when I set the section with 2nd subreport to be suppressed for good, the blank page is not printed.
I already switched the New Page After for all the sections, added Not OnLastRecord formula to it and suppressed or deleted all the empty sections in the subreports and around them and still no luck.
I would appreciate any suggestions.
Answer: Here are a couple things you could check that aren't addressed in your question:

right click on your subreport and select "Format Subreport"
on the common tab, uncheck the box that says "Keep Object Together"
on the Subreport tab, in case you are suppressing it another way, check the
    box that says "Suppress Blank Subreport".

I hope this helps.

Crystal Reports XI- blank last page


How to predict how the time series behaves in the future?

Question: I was wondering how a statistician estimates how a time series continues. Namely, which is more accurate way to estimate the series?

Draw a line between start and end points of the time series data and use the value that the line shows from the future estimate.
Use more sophisticated methods like ARIMA models.

What are pros and cons between those two methods?
Answer: If you simply connect the first and the last data point and extract this line out, then your forecast will heavily depend on the vagaries of your data. After all, you are using just two out of all your data points. If the last observation just randomly happened to be high, all your forecasts will be high, and over time, your forecast could diverge more and more from the actuals.
ARIMA is one alternative. There are simpler ones, like Exponential Smoothing. You can include or exclude trend and seasonality. If you have causal factors driving your series, it is important to model these. The main aspect is that all statistical methods try to use all the available data. (Or, if they ignore some data points, they do so only for very good reasons.)
There are many textbooks on forecasting. I recommend this one.
Answer: Conceptually all forecasting boils down to extracting the constant. Once you reduce your observations to a set of constant, you're done, because constant don't change, no need to forecast them.
For instance, suppose, you think that your data is a perfect sine wave. In this case you need to know three constants: amplitude, phase and a frequency.
Another example is "stationarity." Time series people like to talk about. Why? Because stationary time series have useful constants such as mean and variance. Once you determined them, you don't need to forecast them, they'll stay the same, right?
What about trend stationary? The same thing: you find the trend, which is a constant rate of growth over time such as $\alpha t$, where $\alpha$ is a constant! The you add the stationary part, maybe: $y=c+\alpha t+\varepsilon_t$, where $\varepsilon\sim\mathcal N(0,\sigma^2)$ You got three constants $c,\alpha,\sigma$ - you keep them... constant and it's your forecast, just plug different $t$ to get $\hat y$
Answer: To follow up on the other excellent responses: The only way you are going to predict the future of a time series is to assume that it has some non-random structure or pattern that will continue into the future. There are two ways to do this:

You use a statistical method like ARIMA (or ETS, BSTS, GAM's, etc...). In this case you explicitly have to specify what you think the structure of your time series is: Is it seasonal? Does it have a trend? Do you need to make it stationary?
You use a machine learning method, like Neural Networks, Random Forests, etc...In this case you typically don't have to specify explicitly what the structure is, but there still has to be an implicit structure in the signal that your chosen ML method should learn in order to be able to predict the future.
Answer: What are really asking is "What is the taxonomy of a time series model ?" and probably should be the first point of order when teaching/learning time series analysis. Kudos to you !
Time series forecasts can include
1) User specified predictor series which might have a contemporaneous and/or lag effects. These predictors can be either stochastic or deterministic .
2) Latent deterministic structure such as level shifts , trend changes , seasonal pulses and/or pulses . Note the plural suggesting generality of approach and not presumption.
3) Memory effects of which ARIMA is the most general form being a generalization of simple weighted averages like exponential smoothing (the Brown model ) and other simple procedures like a K period moving average where K is assumed and the k weights are specified either implicitly or explicitly.
Your two particular examples can be characterized as follows :
Example 1 is a particular deterministic effect (type 1) with 1 trend based upon two data points
Example 2 is a type 3 model where it is assumed that the adjusting for previous values is all that is needed AND there are no latent deterministic structures/features in the data.
Modern approaches ( read general approaches ) consider a hybrid model integrating/optimizing one or more of the three types that I have detailed here.
I suggest that you follow this very broad BUT good question with a more detailed one and actually present data be it textbook data , real data or simulated data and let some of the responders actually illustrate how to build a model in an educational step-by-step approach. Alternative solutions can be rendered with commentary regarding pro's and con's.
All three of these possible components to the time series model must be tested for constancy of the model error variance over time AND constancy of the model parameters over time ...fulfilling the stationarity/reproducability requirements for the model errors .
A visual of the three components ("X" being user-specified ; "I" being latent and waiting to be discovered and the error process ("e") reflecting the ARIMA/memory component or the currently unknown components is here http://www.autobox.com/pdfs/SARMAX.pdf.
Useful models are not necessarily simple models just complicated enough  to characterize the data in a minimally sufficient form where all estimated coefficients are necessary .
Each time series has it's own distinct features that require identification in order to separate signal and noise.


How to insert breakpoints for knockout using chrome

Question: I would like determine what value my my knockout script are returning because I have a strong feeling some of my knockout variables are returning null. I clicked on the line number then chrome is supposed to step through the code somehow please clarify the process??
thanks
Comment: insert this piece of code `debugger;`  before your problem piece and press F12 on browser and F5 alternatively you can log the data using `console.log(//your observable value)` and check console for logged value.
Answer: If you are talking about how to do debuggin in chrome then go through this link
https://developer.chrome.com/devtools/docs/javascript-debugging
Otherwise you can retrieve the Knockout Viewmodel object in Console tab of chrome.
To use this you will have to expose the Knockout viewModel object so that you can access it from Console tab.
Otherwise just try debugging your javascript through Chrome developer tool where you are binding Knockout with your DOM
Answer: There is Chrome Extention called "Knockoutjs context debugger",
I guess that's what you need.


Any denumerable set is infinite

Question: Currently, I'm learning 'An Introduction to Classical Real Analysis' (Stromberg, 1981) by myself and find that the proof of Theorem (1.55) in pages 29-30 is far beyond my comprehension. Can anybody explain the statement below that g is onto N?
I am looking forward your valuable help.
Comment: There has always been some ambiguity with the term countable or denumerable. The [Wikipedia page](http://en.wikipedia.org/wiki/Countable_set) tries to separate the notions clearly. For your question, can we know how $\mathbb{N}$ was defined in this book?
Comment: In this book, N is defined as the set of natural numbers [or the positive integers].
Answer: Take $m\in\Bbb N$.
Suppose that $m<f(n)$. Since $f$ is onto, there is some $r$ such that $1\leq r\leq n$ and $f(r)=m$. And since $f$ is one to one, $r<n$. Then $g(r)$ is defined and $g(r)=m$.
If $m\geq f(n)$ then $m+1>f(n)$. Again, since $f$ is onto there exists some $r$ such that $f(r)=m+1$. And since $f$ is one to one, $r<n$. Then $g(r)$ is defined and $g(r)=f(r)-1=m$.
Comment: @MauroALLEGRANZA No. Note that the domain of $f$ is $\{1,\ldots,n\}$, so $r>n$ does not make sense.
Comment: Since the domain of g is {1,…,n-1}, I wonder why the range of g is the same as that of f.

Any denumerable set is infinite


What is the best way to test a group of interaction effects in a GLM?

Question: I have a binary outcome Y and predictors a, b, c, and d. I have a logistic regression model which includes all the predictors, plus all the interactions between all the predictors. What is the right approach to determining whether all the interactions can be removed from the model? My thought was that a partial F-test would be suitable:
partial_f_test <- anova(reduced,full)

However, calling "partial_f_test" returns Resid. Df, Resid. Dev, Df, Deviance. I'm not sure how to interpret the results I got, namely Df = 9 and deviance = 2. Is a partial F-test even the right approach here, and if so, how do I interpret the results?
Comment: Logistic models do not have a residual variance term, so $t$ an $F$ distributions do not apply.  Use either a Wald "chunk" $\chi^2$ test or the better statistically behaving likelihood ratio $\chi^2$ test.   The latter is obtained by fitting the model without any of the interaction terms and comparing the -2 log likelihood of that model with that from the full model.
Answer: Conceptually, you are on the right path, but the details are wrong because you have a logistic regression model.  With linear (ordinary least squares) models, you can conduct a nested model test using the multiple partial $F$ test.  With logistic regression, you can do the analogous thing by using a likelihood ratio test of the nested model.  A logistic regression model is typically fit by using a version of the Newton-Raphson search algorithm to find the model that minimizes the deviance, whereas an OLS model uses a formula that minimizes the sum of squared errors.  The anova() output lists deviances because you have logistic regression models.  But the basic ideas are all the same.  You needn't worry too much about the underlying math—you use the function in largely the same way and interpret the output the same way.  You'll just need to use anova(, test="LRT") in the function call.  Lastly, when discussing it, you wouldn't call it a partial F test, you call it a likelihood ratio test.


How to explain memory usage on Windows Server outside the list of running processes

Question: I have a Windows 2003 Server running a bit slow where the commit charge and page file usage tick up and up until I eventually reboot. To fix this I need to find out what's consuming all the memory, and this is where the big mystery is.
Current stats from the Task Manager:
Physical Memory (K): 2096400
Commit Charge (K):   5364848
Page file usage:     5.11 GB

Fine, so let's pull up SysInternals Process Explorer and check the working set size of everything running. Biggest culprit is a Tomcat instance using 121,980K WS, 481,284K VM Size. Nothing in there comes close
to explaining the 5 GB commit charge.
Next step: SysInternals pslist: pslist -m, split up the output by column and calculate column sums for the 61 processes that are reported.
SUM (Working Set)  : 681,484 K
SUM (Private Bytes): 593,424 K

Am I fundamentally misunderstanding what the tools are reporting? I've always been under the impression that an OS would actually commit much less memory than the full amount of virtual memory mapped by a process, on the assumption that it won't actually ever use that much, and that looking at VM here is a red herring.
Comment: Update: Yes, this system is paging, and I'm frequently getting the "Running out of virtual memory" warning. Whenever I get the warning I check the memory stats and there's no process that seems to be particularly misbehaving, but the Memory, Committed Bytes stat is always over 5 GB.
Answer: Sorry to just paste some links - but we've been using some techniques to find memory leaks, using logparser and powershell, so I'll share.
http://blogs.msdn.com/debuggingtoolbox/archive/2008/08/22/powershell-script-chart-and-statistics-from-top-20-objects-leaking.aspx
(The Never Doubt Thy Debugger site is excellent):
http://blogs.msdn.com/carloc/archive/2007/09/14/something-you-need-to-know-before-start-debugging.aspx
I'll also provide a link to Mark Russinovich's excellent insight to Memory Usage on Windows:
http://blogs.technet.com/markrussinovich/search.aspx?q=memory&p=1
Short of opening actual Microsoft cases, the Performance Team site has a lot of good info, too:
http://blogs.technet.com/askperf/Default.aspx?p=2
Answer: The priciple tool for helping to diagnose this is perfmon.  The counters I'd look at (to begin with) are:
Memory, Committed Bytes this is a measure of the demand for virtual memory
Process, Working Set, _Total virtual memory in "active" use
Paging File, %pagefile in use
Memory, Pages/Sec (this is not an necessarily an indicator of low memory, although everyone seems to assume it does)
Memory, Pages Output/Sec how many virtual memory pages were written to the pagefile to free RAM page frames for other purposes each second
Memory, Cache Bytes
Memory, Pool Nonpaged Bytes
Memory, Pool Paged Bytes
Memory, System Code Total Bytes
Memory, System Driver Total Bytes
when this sum gets close to 2GB you'll have performance issues usually due to 32 bit architecture
Memory, Available MBytes- this measures how much RAM is available to satisfy demands for virtual memory (either new allocations, or for restoring a page from the pagefile).
See also http://members.shaw.ca/bsanders/WindowsGeneralWeb/RAMVirtualMemoryPageFileEtc.htm
Comment: Interesting link. On this server, I'm seeing total Process Working Set at 640MB, but "Memory, Committed Bytes" is 5.4GB. None of the other counters you mention is very high. I frequently get the "Running out of virtual memory" warning, which is why I'm investigating. Adding comment to the OP.
Answer: How long has that server been running since the last reboot? It's an unfortunate fact of life that Windows has memory leaks. i.e. Memory that is allocated does not always get released back to the system. The symptoms are exactly what you are seeing. If you don't already do it I would suggest rebooting at least once a week. Many data centers reboot Windows every day, as doing so greatly cuts down on support calls. Of course that's a lot easier to do when you use clusters because there's no down time.
Answer: JP, I believe your comment that this is an automated build / unit test server that is running less than stable code says it all. My guess is that this server needs to be rebooted frequently because of the unstable code running on it probably has memory leaks that are giving you the symptoms you are seeing. Memory leaks are not going to get listed on any of the process trees of running processes as they are memory that is grabbed by processes that no longer exist, and are still allocated, even though the process associated with them are long gone.
Get a frequent maintenance window to allow you to automagically reboot this machine, perhaps nightly, a couple times a week, or weekly depending upon the speed at which this behavior starts to exhibit performance issues.
We have Oracle Application Servers servers on Windoze a while back that needed to be rebooted twice daily. We kicked out the users at lunch time, and in the middle of the night every day. That was a few years back, with supposedly stable productions code from Oracle.
Answer: It's said that there is a sysadmin somewhere that really understands Windows memory stats, but I've never met them.
However it's not usually too hard to find a misbehaving process. Try using Perfmon to look at the various process counters like handles or Page faults/sec.
JR
Further thoughts: are you sure you're actually low on memory. The key thing is whether your'e getting paging. If there's no paging you're not short on memory. Using PerfMon have a look at the Memory - Pages/sec counter.
Comment: I don't see anything obvious in the running processes.

Is there any possible way for memory to not be reclaimed by the OS after a process exits? This is an automated build/unit test server so _of course_ processes crash all the time, as it's always running bleeding-edge builds automatically built from SVN.
Comment: See my edit for some further thoughts
Answer: Remember that working set is the bit of memory that is actually represented by REAL physical memory.  you also have your virtual memory charge, and Windows does code page sharing, some chunks of MFC are going to be shared among lots and lots of processes without duplicating memory usage.  Plus you have Windows incessant desire to keep the filesystem cache as large as possible (i've seen it balloon to 800MB on a 2.5GB laptop before).
Windows memory management is very robust.  However once Windows starts paging, things get ugly, and you ALWAYS have to leave room for the filesystem cache - always always always.  I routinely have to shutdown and restart Firefox when my 80+ tabs drives it's memory consumption up to 1.2gb/1.2+gb.
Windows also blurs the line a bit, between pages that are in the cache, and pages that are listed as memory/working set.


Isomorphism between centralizer and semi direct product

Question: I have just encountered the concept of a semi-direct product in group theory and the following exercise is being quite troublesome. If you could give me some help, I will be very grateful. Here we are:
Show that the centralizer of a product of $m$- disjoint $b$-cycles in $S_{mb}$ is isomorphic to a semi-direct product $(\mathbb{Z}/b\mathbb{Z})^m \rtimes S_m$.
Comment: Hint: Let $\sigma\in S_{mb}$ be your product of $m$ disjoint $b$-cycles. As a first step you should be able to show that elements centralizing $\sigma$ permute the orbits of $\langle\sigma\rangle$.
Answer: We denote by $T$ the "shift" map  in $(\mathbb{Z}/b\mathbb{Z})$, defined by $T(x)=x+1$. As a permutation it is a cycle of length $b$. Iterating the action of $T$, we see that the $j$-th iterate $T^j(x)$ is defined for $x$ and $j$ in $\mathbb{Z}/b\mathbb{Z}$ (and in fact, $T^j(x)$ is simply $j+x$ in $(\mathbb{Z}/b\mathbb{Z})$).
Take $m$ copies of $(\mathbb{Z}/b\mathbb{Z})$ : $H_k=(\mathbb{Z}/b\mathbb{Z})$ for $1 \leq k \leq m$, and form the product $H=H_1 \times H_2 \times \ldots \times H_m $. Each $H_k$ has its own private shift $T_k$.
Let us call $\gamma$ the main permutation here. Renaming things, we may assume without loss of generality that $\gamma$ is a permutation of $H_1 \cup H_2 \cup \ldots \cup H_m$, acting on each $H_k$ by "shifting" : $\gamma(x)=T_k(x)=x+1$ for $x\in H_k$.
Denote by $C$ the centralizer of $\gamma$. If $c\in C$, then $c$ commutes with $\gamma$ so $c$ permutes the orbits of $\gamma$ : so we have a permutation $\bar{c}$ of $\lbrace 1,2, \ldots,m \rbrace$ such that
$c(H_k)=H_{\bar{c}(k)}$ for every $k$. In particular, if we denote by $0_{H_k}$ the zero element in $H_k$,
we have $c(0_{H_k}) \in H_{\bar{c}(k)}$, so that there is an integer $j_k$ such that $c(0_{H_k})=T_{\bar{c}(k)}^{j_k}(0_{\bar{c}(k)})$. The equality $c\gamma=\gamma c$ becomes $cT_k=T_{\bar{c}(k)}c$ on $H_k$, so we deduce
$$
(1) \ \ \ c(x)=T_{\bar{c}(k)}^{j_k+x}(0_{H_{\bar{c}(k)}}) \ (1 \leq k \leq m, x \in H_k)
$$
Conversely, the formula (1) uniquely defines a permutation of $H_1 \cup H_2 \cup \ldots \cup H_m$
commuting with $\gamma$. So the map
$$
(2) \ \ \ \phi : C \to (\mathbb{Z}/b\mathbb{Z})^m \rtimes S_m, c \mapsto ((j_1,j_2, \ldots ,j_m),\bar{c})
$$
is a bijection. By construction, it will also be a group homomorphism, qed.


Engineering Mathematics problem with proving an equation

Question: This is problem 20, further problems in Engineering Mathematics book by K.A.Stroud. It states:

Show that the equation
  \begin{equation}
4\frac{d^2x}{dt^2} + 4\mu\frac{dx}{dt} + \mu^2x = 0
\end{equation}
  is satisfied by
  \begin{equation}
x = (At + B)e^{-\frac{\mu t}{2}}
\end{equation}
  where A and B are arbitrary constants.

So i calculated
\begin{equation}
\frac{dx}{dt} = Ae^{-\frac{\mu t}{2}} + \frac{At^2\mu^2}{4}e^{-\frac{\mu t}{2}} + \frac{Bt\mu^2}{4} e^{-\frac{\mu t}{2}}
\end{equation}
and
\begin{equation}
\frac{d^2x}{dt^2} = \frac{At\mu^2}{4}e^{-\frac{\mu t}{2}} + \frac{At\mu^2}{2}e^{-\frac{\mu t}{2}} + \frac{At^3\mu^4}{16}e^{-\frac{\mu t}{2}} + \frac{B\mu^2}{4}e^{-\frac{\mu t}{2}} + \frac{B\mu^4 t^2}{16}e^{-\frac{\mu t}{2}}
\end{equation}
and then i put everything into the original equation i want to prove and this is what i come up with:
\begin{equation}
(At+B)e^{-\frac{\mu t}{2}} [\mu^3t^2 +4\mu^2t + 8\mu) + 8A(t\mu + 2)
\end{equation}
which isn't equal to 0.
Well, i've completely lost it with this problem, if anyone could help me a bit i would be very, very grateful.
Comment: There seems to be a typo: In the original differential equation, $m$ ought to be $\mu$.
Answer: You did something wrong in calculating the derivatives, we have
\begin{align*} \frac{dx}{dt} &= A\exp\left(-\frac{\mu t}2\right) + (At + B)\cdot \left(-\frac\mu 2\right) \exp\left(-\frac{\mu t}2\right) \\ &=
   A \exp\left(-\frac{\mu t}2\right) - A \frac{\mu t}2  \exp\left(-\frac{\mu t}2\right) - B\frac{\mu}2 \exp\left(-\frac{\mu t}2\right) \end{align*}
and
\begin{align*}
  \frac{d^2x}{dt^2} &= -\frac\mu 2 A \exp\left(-\frac{\mu t}2\right)
   - \frac \mu 2 A \exp\left(-\frac{\mu t}2\right) + (At + B)\left(-\frac \mu 2\right)^2 \exp\left(-\frac{\mu t}2\right)
\end{align*}


Two different remainders for same expression

Question: $$\frac{n! + 1}{n} = (n-1)! + \frac{1}{n}$$
The remainder is $\frac{1}{n}$
$$n! + 1 \equiv 1 \cdot 2 \cdot 3 \cdot \dotsc (n-1) \cdot 0 + 1 \equiv 1 \mod n$$
The remainder is $1$
What is going on? Why am I getting two different remainders for the same operation?
Comment: Well in the first equation the remainder is $1$ too. You don't divide the remainder by $n$.
Answer: You've just said the same thing in two different ways. The reason that they seem to say something different is that you're conflating remainder with fractional part of quotient.
Your first equation says that $n!+1=n\cdot(n-1)!+1$; to see this, just multiply it by $n$. This says that the remainder when you divide $n!+1$ by $n$ is $1$, just as your second result does.
Alternatively, recall that the statement that $n!+1\equiv 1\pmod{n}$ means that there is some integer $q$ such that $(n!+1)-1=qn$; if you now divide this through by $n$ and rearrange it a little, you get
$$\frac{n!+1}n=q+\frac1n\;.$$
Of course the $q$ here is $(n-1)!$.
More generally, when you divide $n$ by $d$ to get a quotient $q$ and a remainder $r$, it's always true that $n=dq+r$, so
$$\frac{n}d=q+\frac{r}d\;:$$
the fractional part of the quotient is the remainder $r$ divided by the divisor $d$.


Can I exceed the estimated sample size?

Question: I'm doing a cross-sectional descriptive study with an estimated sample size being 140. Will it be statistically justifiable if I managed to collect a sample of 200? Could there be any side effect that may not be scientifically acceptable?
Comment: No, what would be the scientific unacceptable side effect of more data? The only real down side is that its gonna cost money
Comment: (This doesn't seem to me that it is so unclear that it needs to be closed.)
Comment: It is invalid if you notice your results aren't quite significant, so you keep gathering data to get significance. If that isn't what you're doing, I don't see the problem here.
Answer: I can think of at least three possible issues with exceeding a planned sample size, but you will have to judge for yourself, which of these apply in your case.

Perhaps most importantly, there might be ethical issues. E.g. if more samples means more animals or humans being involved in an experiment, then this might be problematic, if an ethics committee approved a much smaller sample size.
A key concern from a statistical perspective is that if this is done based on what the collected data looks like, then there is a problem with keeping type I error rate etc. and approaches like group-sequential methods or adaptive designs might be needed. That should ideally be decided up-front. However, that is not a concern, if your approach is "Without looking at the data we are getting we will collect at least 140 samples and more if we can, then we will go and analyse what we have." I would be tempted to clearly say that in my research protocol though.
It might not be entirely necessary and be a waste of money/resources/effort to collect more samples than planned. If there were a very large discrepancy, the result might mean that you demonstrate very clearly that there is some effect/difference (whatever you are looking for) that is so small that it is irrelevant. However, 200 instead of 140 does not sound like a massive difference in terms of power for the effect size you may have powered for (this would not turn 80% power into 99.9%) and is not going to get you an enormous power for a much smaller effect size.

Can I exceed the estimated sample size?


Prove this function is locally unbounded, $\sum_n e^{-n^2(x-q_n)^2}$

Question: Let $\{q_n\}$ be an enumeration of $\mathbb{Q}$, then put $f(x) = \sum_{n=1}^{\infty} e^{-n^2(x-q_n)^2}$, this is well defined as a function of   $\mathbb{R} \to \mathbb{R} \cup \{\infty\}$. The idea is to prove that this is finite a.e and however is unbounded for every interval. I am stuck on this last part.
What I do: To prove that $f$ is finite a.e I integrate the function on $\mathbb{R}$, using monotone convergence theorem. Is easy to see that this yields a finite result and hence the integrating has to be finite a.e.
Now I am stuck on proving that this is locally unbounded, what I've tried is, given an interval, take a rational number on it, $p/q$, and then try to find a term in the series of $f(p/q)$ that is as bigger as I want.
Answer: Hint: given any interval $I_0$, find a nested sequence of intervals $I_0 \supset I_1 \supset I_2$ such that, for every $j\ge0$, there exists $n(j)$ such that
$$
I_j \subset \bigg[ q_{n(j)}-\frac1{{n(j)}^2},q_{n(j)}+\frac1{{n(j)}^2} \bigg].
$$
The density of the rational numbers in $\Bbb R$ should help you construct such intervals. Do you see why we have $f(x) \ge je^{-1}$ for $x\in I_j$?
Comment: Okey, I think I get it. That is because you have at least $j$ rationals, $\{q_{n(1)}, q_{n(2)},... , q_{n(j)}\}$ whose terms in the series meets that the distance between $x$ and $q_{n(j)}$ is in the worst case equal to $\frac{1}{n(j)^2}$ . Am I ok?
Comment: Now the question is how did you come up with that?
Comment: Mmm i was thinking that the squares in the intervals are innecesary
Comment: Of course experience helps with coming up with proof strategies ... I was motivated by thinking, if I want the series to be unbounded, I'll need to make several of the summands pretty big at the same time.


Weird Fluttering sound

Question: I have a brand new Jackson JS30, and I am already having issues with a weird fluttering sound when I pull of from 15 to 14, 9 to 8, 8 to 7, etc. I can't seem to find anyone else with this problem, yet I have had this same problem on three guitars. I have tried it on multiple amps, and with different cords, as well as taking it to the shop multiple times. Here is a link to the sound. "https://soundcloud.com/porter-larson/fret-fluttering/s-p9y5f"
Comment: If you don't have the problem with the cloth wrapped then there are two possibilities, 1) you're hitting another string when you pull off and it's making a second note and 2) the string is resonating between the fretted note and the nut. The second is rare but can happen. The first is very common. Either way, I would take it back to the store and **play it in front of them with an amp** and let them tell you if it's 1) or 2). Or you could post extensive videos here and we could *try* to tell you but that probably won't work.
Comment: I've had similar things like that happen to me and it ended up being caused by low voltage out of the wall socket, it might be worth checking it out with a VOM meter.
Comment: There are two different notes playing after you pull off. Are you definitely muting all of the other strings? What if you wrap a cloth or towel around the neck at frets 1-3 and then try the pull offs, do you still have the problem?
Comment: I don't still have the problem when I wrap the cloth, but even when I palm mute the other strings (w/out the cloth) it still happens. Also I have a floyd rose w/ a locking nut
Comment: It's really difficult to tell w/o seeing and touching the guitar but here are a couple things.  It actually sounds similar to a fast beat frequency for 2 notes out of tune.  Are you sure you are playing a single note clean?  Try the following, 1. Play with the amp clean (no effects), 2. try acoustically and see if the sound persists.  That may sound strange for an electric but it would help identify any mechanical issues, is this Jackson solid body or semi hollow?
Comment: It doesnt happen when it is on clean or acoustic, and it is a solid body. It seems to only be an issue on the b string and yes i recorded it fast so I didn't do a great job but it happens with only one "clean" note as well
Comment: Also you should be muting with your fretting hand as well as your picking hand. Are you doing that?
Comment: @Tetsujin - I suppose a Camper-van might have low voltage problems, but I ran into this problem when playing in a bar in the mountains above Boulder, and again a couple of years later at an old theatre in Milwaukee. Low voltage can happen because of old wiring and it can create the strangest problematic effects.
Comment: I think you may very well be right - I have had some problems with other mistakes being amplified only on the distorted channel.
Comment: You say you've had the same problem with 3 different guitars. I'd say that proves there's nothing wrong with the guitar. There's a simple fault finding technique. You replace each component in turn until you find the faulty one. You could do this in a friendly music store. If it isn't the equipment then it's you!
Answer: I highly suspect that the issue here is inadequate muting technique.
You said that you are muting the strings, but we also know that:

This problem happens on three different guitars,
The audio you shared sounds exactly like extra unmuted strings ringing out,
The extra notes that ring out are G, A, and D, which are easily excitable natural harmonics on the EADGBE-tuned guitar, and
The fluttering can be stopped with additional muting help from a cloth.

This is strong evidence toward a problem with your muting technique.
Next time you hear a flutter, touch each string with your right hand.  Hopefully you will find that touching one of the strings stops the flutter.  That's the string that you failed to mute.
Answer: This may be a nothing burger, but distortions and beat frequencies can be caused by pick-ups too close to the strings. I had a similar distortion on my Peavey Raptor cured by increasing the distance. I don't know if this applies to Humbuckers, but for single coil pick-ups, a starting spacing of 2mm (at the e string) and 2.4mm (at the E string) between the pick-up's magnet and the bottom of the string (this from a video I watched on a Strat setup). Oh, if you have an electronic caliper for measuring, a cool trick to get that elusive distance between string and fret or string and pick-up is to measure the diameter of the string in question and zero the caliper. This now allows you to measure from top of the string to the fret or pick-up while reading the distance from bottom of string to the fret/pick-up. BTW, these calipers are really cheap these days! I just looked and Amazon shows them for as little as $9.99 (although I'd pay closer to $25 to get some quality) Neiko makes a decent one for $20 (Mine's a $150 Mitutoyo). Good Luck & Great Playing!

Weird Fluttering sound


onSizeChanged() calls onCreate() and onStart()? - Android

Question: My app currently calls a method within the onCreate() method so that the game will start and animations will run once the view is created. However when i flip the screen to switch between portrait and landscape, this method is called again.
I've moved the calling line both to the onStart() method and even the methods class constructor.
this is the method that is being called:
public void startGame() {
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        public void run() {
            runGame();
        }
    }, 500);
}

There is a delay to allow everything to be constructed before it is run, otherwise it won't work.
Is there i way to stop onSizeChanged() affecting this method being called? Or is there a way i can call this method so that it starts when the activity is started (again so that onSizeChanged() cant affect it and that everything is initialized before its call).
Thanks for looking.
Answer: The easiest way is to add:
android:configChanges="orientation|screenSize"

which tells the system you'll take care of them yourself. However, it's not recommended.

Note: Using this attribute should be avoided and used only as a last-resort. Please read Handling Runtime Changes for more information about how to properly handle a restart due to a configuration change.

Or you can check savedInstanceState. If it is not null, that means a user changes the orientation (or the app are coming back from a configuration change). Maybe something likes this:
if(savedInstanceState == null)
    startGame();
else
    //handle a configuration change if necessary

Please see Don't reload application when orientation changes
Edit :
if(savedInstanceState == null) {
    startGame();
} else {
    //handle a configuration change if necessary
    int yourVar = savedInstanceState.getInt("something");
}

Comment: That works thank you :) is there a way i can save the state of another class (used by the View class, it creates a sequence and in the constructor it adds 3 integers to the sequence. so when i change the orientation it adds 3 again which i dont want).
Comment: @Waddas i'm not sure what you try to do but you can use onSaveInstanceState. please see http://stackoverflow.com/questions/4096169/onsaveinstancestate-and-onrestoreinstancestate
Comment: Sorry im not being clear. i have a class that does not implement View, is there a way i can save and restore its state so that chnging the orientation does not affect it?
Comment: From my understand, the state should be saved automatically. Anyway, you can override onSaveInstanceState() and add something likes this savedInstanceState.putInt("something", value); Then in onCreate retieve it using savedInstanceState.getInt("something");
Comment: please see my updated answer and also see http://stackoverflow.com/questions/4096169/onsaveinstancestate-and-onrestoreinstancestate
Comment: If you are still not sure, could you ask another question with details (Your code) ? it looks like u'r having another problem
Comment: Ok, thanks for all your help, you've solved my main problem which is a massive help :)
Comment: welcome. i'd be happy to help more but without your code, it's hard to show how to do things.
Answer: add this to your manifest:
android:configChanges="screenSize"

Answer: Could you use a static thread variable instead of handler?
e.g.
  private static Thread gameThread = new Thread(new Runnable(){
        public void run()
        {
              //if necessary: Thread.sleep(500);
              runGame();
        }
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
        //rest of oncreate code here
        if(gameThread.isAlive() == false)
        {
              gameThread.start();
        }
  }

Comment: Not a good idea. When you initialize the `Runnable` object anonyomously, it will implicitly hold a reference to the parent class(In this case, an `Activity`), and that `Activity` will be leaked as long as the thread keeps running.


C++ references vs return values

Question: I understand the principle point of references is to avoid making copies of large structures, but what if a function you're writing itself creates a large structure? Is it less efficient (or are you more likely to run out of memory) to create the variable locally, then return it, than you are to pass the destination object as a reference, and fill it from within the function?
I can't seem to phrase that well, so a concrete example: Suppose a function takes a string, and returns a vector of each line in the string. Is there a material advantage to the function:
void getLines(std::string in, std::vector<std::string>& out);

over:
std::vector<std::string> getLines(std::string in);

Thanks for any help,
Wyatt
Comment: I think you're missing a `&` in the first code snippet. (`out` should be a reference...)
Comment: out is a reference... I'm sorry, it was missing, someone else edited it.
Answer: That depends on if your compiler supports return value optimization (most do) and if the code qualifies for that optimization.
Comment: VC2005 performs *named* RVO, which saves you headaches when returning vector (so that you don't have to construct "lazy" iterators all over the place). See http://msdn.microsoft.com/en-us/library/ms364057(v=vs.80).aspx
Comment: Also note that at least one compiler (VC++) will perform plain old RVO *even when all optimizations are turned off*.
Answer: The first example should presumably be more like one of these two:
void getLines(std::string in, std::vector<std::string> &out);
void getLines(std::string in, std::vector<std::string> *out);

The second style is often more convenient, and can in theory be made mostly as efficient as the first one:
http://en.wikipedia.org/wiki/Return_value_optimization
Whether this is seen in practice depends on the compiler, optimization levels, and whether the compiler can spot the opportunity in the first place.
Whilst I don't speak for everybody, I've never actually managed to get compilers to take advantage of RVO, even with simple objects that don't do anything fancy. So I therefore personally recommend the first approach, because you are guaranteed to get the desired behaviour, on every compiler, and (which seems relevant for me...) for every programmer's code -- i.e., that the object created to hold the return value is filled in directly by the called function, without any extra copies.
(The cost of default-constructing the result object, which is something that could potentially be avoided were RVO to be taken advantage of, is usually not significant compared to the copy the compiler might be unable to avoid.)
Another point to note would be that if attempting to avoid unnecessary copies, passing objects by const reference instead of by value is often a good idea, e.g.:
void getLines(const std::string &in, std::vector<std::string> &out);
void getLines(const std::string &in, std::vector<std::string> *out);

Comment: Every by-reference function argument should be const if its referent isn't modified by the function. This should be second nature. It helps the compiler to optimise, and it helps the programmer to understand and use the function.
Comment: You can pass a temporary object in if the function accepts a value or a const reference, but not if the function accepts a non-const reference. This is just one of the rules of the language. So the behaviour is then pretty much like passing by value, in that you can pass a temporary object if you like. (There's also some marginal protection against having the object modified by the callee -- but not much, thanks to `mutable` and `const_cast`. But cases where that's a problem are actually rare in practice.)
Comment: I understand the utility in passing the input by reference, that was just an oversight, but why a const reference?
Answer: Well, in your specific case (filling a container with values) I would go for an input iterator approach. But in all other cases (like a complicated string generation or some calculations) I wouldn't care about possible performance hits and trust RVO (see Jim's answer) and the compiler to optimize it like it should. If it becomes a bottleneck (profile!), change it of course!
Comment: yes, iterators are the way to go usually. Except if you use virtual functions.
Answer: My advice is to write the code so that the client usage is as intuitive as possible.
If - as is usually the case - you judge that to be returning by value, then if your system is performance critical and you find a particular return value is not being optimised nicely by your compiler - even at the highest reasonable optimisation level you can use and after checking for any relevant command line options or compiler tips on achieving RVO, and considering alternative compilers if practical - ideally a C++11 compiler that benefits from always-efficient move semantics, only then change the specific problematic spot to accept the return value by reference.

C++ references vs return values


Pandas group-by, filter, and aggregate

Question: I have a dataframe like
import pandas as pd
import numpy as np
d = {'id':[1,2,3,4,3,3,1,6], 'type':['t2','t1','t2','t2','t3','t3','t4','t3']}
df = pd.DataFrame(data=d)

The goal is to get a dataframe that is grouped by id and has the nunique of each type per group.
I thought this would resolve it but it does not seem to work:
df.groupby('id').agg({'type':pd.Series.nunique()})

Comment: Remove the `()` from `nunique`, as you want to pass a reference to the function, not to call it. `df.groupby(by='id').agg(pd.Series.nunique)` will do the trick.
Comment: Thanks @dnswlt - i new it was an easy one.
Answer: You can do this a bit more simply by just accessing the type SeriesGroupBy first.
>>> df.groupby('id').type.nunique()
id
1    2
2    1
3    2
4    1
6    1

As mentioned in the comments, your current approach does not work as agg expects a function object which it can call (nunique), not an actual function call attempt as you have with nunique() .

Pandas group-by, filter, and aggregate


JSF SelectOneMenu Browser Back Button

Question: I have a problem where I am using a SelectOneMenu for navigation:
<code><p:selectOneMenu value="#{navigator.outcome}">
    <f:selectItem itemLabel="Select item.." />
    <f:selectItems value="#{navigator.menuItems}" />
    <p:ajax event="change" listener="#{navigator.navigate}" />
</p:selectOneMenu>
</code>
This works fine except when I navigate back it doesnt display "Select Item.."
The navigator bean is request scoped (I've tried view scoped as well).
I've disabled caching using a WebFilter.
Comment: Since you haven't cached the page, when you go back in your browser, your `navigator` managed bean must be recreated, have you tried to debug this behavior as well?
Comment: Yup the bean is recreated...I'm not sure why the browser isnt updating. Not sure how to debug that.
Comment: When the bean is recreated, is `navigator.menuItems` filled?
Comment: I think this is a problem with browser caching select options. Apparently adding autocomplete=off fixes this but not sure if I can do this.
Answer: You need to turn autocomplete off at the form level.
With JSF 2.1 you cannot do this.
Either wait until JSF 2.2 or uses omnifaces:
See link:
how to do autocomplete="off" at form level in JSF

JSF SelectOneMenu Browser Back Button


Inverse complex matrix

Question: I calculated the inverse of an complex matrix $C=A+iB$, where $A,B$ are real matrices and $i^2=-1$:
$C^{-1}=(A+BA^{-1}B)^{-1}-iA^{-1}B(A+BA^{-1}B)^{-1}$
my question is: what assumptions must be met $A$ and $B$ to have this inverse?
Obviously, must be $A^{-1}$ and $(A+BA^{-1}B)^{-1}$, but there exist a way to characterize this?
Thanks!
Comment: So, it seems your question is as follows: "given an invertible matrix $A$, for which matrices $B$ is $A + BA^{-1}B$ invertible?"  What kind of conditions on $B$ are you looking for?  Something about the rank of $B$, perhaps?  Maybe a condition on the eigenvalues/eigenvectors? Do you have anything in mind that would be particularly helpful?
Comment: find some as "$C^{-1}$ is invertible if and only if $A$ and $B$ are invertible also", would be ideal.
Answer: I suppose you are asking for a reformulation of the condition that both $A$ and $A+BA^{-1}B$ are invertible. Note that this is different from asking when will $C$ be invertible, because $C$ can be invertible when $A$ is singular (e.g. consider $C=iI$).
Since $A+BA^{-1}B=A\left(I+(A^{-1}B)^2\right)$, you may rewrite the condition that both $A$ and $A+BA^{-1}B$ are invertible as

$A$ is invertible and $\pm i$ is not an eigenvalue of $A^{-1}B$,

but I am not sure if this is really useful. Alternatively, viewing $A+BA^{-1}B$ as a Schur complement, one can obtain another equivalent condition:

both $A$ and $\pmatrix{A&-B\\ B&A}$ are invertible.

Inverse complex matrix


Multiple comparisons correction with independent groups

Question: A question: I have a study with 3 experiments, each involving a between-subjects comparison of a treatment vs. control group. The groups in each experiment are independent samples and no groups are repeated across experiments.  A t-test is run for each experiment.
A reviewer is asking for correction for multiple comparisons. It seems odd to perform such a correction across experiments, especially since we only ran one t-test per experiment.  However, in all 3 experiments we are interested in whether there is an effect of the treatment (albeit under different conditions in each case).  Is Bonferroni the appropriate method here?  What other methods might be preferable?  Are there citeable works on whether it is appropriate to do such corrections?
Note: a somewhat similar question was asked here: correcting for multiple comparisons with independent groups
Thanks for any advice!
Comment: Have a look at this answer [here](https://stats.stackexchange.com/questions/225937/linear-mixed-effects-model-and-multiplicity-issue-and-adjusting-for-p-values/226215#226215) It also provides some references that may help you in your specific situation. In general, the appropriate method will depend on your experiment and what you want to control for.
Answer: A Bonferroni correction is conservative, but always an option, because the Bonferroni inequality requires no assumptions about the relationships among the events. It exerts the strongest control over the simultaneous error probability, $\Pr(\text{at least one type I error})$, unconditionally, and may be used also for constructing (conservatively) a set of confidence intervals whose simultaneous confidence level exceeds the specified one. For just 3 tests, it usually isn't all that conservative, and so it has much to recommend it when this strong type of control over the error rate is desired.
You could also use a slightly less conservative adjustment and run each test at an individual significance level of $1-(1-\alpha)^{1/3}$ (which is about 0.017 with $\alpha=0.05$). This is based on setting the joint probability of 3 independent events to the desired value, and it is justified because you have independence here. Again, this would control the overall error probability at the simultaneous CI level.
Some other simultaneous-testing procedures gain power by avoiding testing certain comparisons at all when other comparisons are already deemed non-significant. There are various levels of control over the error rate with such procedures. Methods that control the false-discovery rate are at the weakest level of control (other than no correction at all). It is unclear how one might apply such methods to the situation described in the OP. But I suppose one possibility is to fit a model with a block effect for the three experiments, and a treatment factor that has 4 (or 6?) levels: control, treat1--treat3 (or perhaps 3 levels of control?). A Dunnett-style test could be used to test the comparisons of interest. The Dunnett method has the same strong control over error rate as the Bonferroni, and be slightly more powerful than Bonferroni -- I suspect not that much. An FDR method could be applied using something like the R function p.adjust() with the unadjusted $P$ values.
A good reference for all the issues under discussion is Chapter 5 of Oehlert's experimental design text, which is openly available by the Creative Commons license: http://users.stat.umn.edu/~gary/book/fcdae.pdf
Comment: @Alexis seems to be arguing that the FDR is always the rate one should control. But I don't think many statisticians agree with that. For one thing, sometimes people want simultaneous confidence intervals and the FDR doesn't work for that. By the way, most popular FDR methods actually use the Bonferroni inequality, but this is done stepwise with families of different sizes.
Comment: @Alexis you are obviously missing the point. You made a pretty strong claim in your **first** comment. I asked for references to support this. You provide references that explain the FDR method but none of these references actually suggesting to never use Bonferroni. It seems your claim is opinion-based, which is fine, but then it should be labeled as such. You don't seem to be reading the comments because nowhere I am advocating for anything. If you think you can help the OP with his/her problem, I'd suggest you post an answer since answers on CV can also be cited!
Comment: The Bonferroni adjustment is always wrong in that it (a) always assumes all null hypotheses are true, even after some have been rejected and hemorrhages statistical power thereby, and (b) rejection probabilities under it are conditional on an undefined and loosey-goosey concept of "family of tests," and change when the number of tests change. The method is 55 years old, and has been supplanted by control of the [false discovery rate](https://en.wikipedia.org/wiki/False_discovery_rate) (FDR) which suffers neither of these problems.
Comment: There are different types of control over the simultaneous error rate. See for example Chapter 5 of Gary Oehlert's book, http://users.stat.umn.edu/~gary/book/fcdae.pdf. FDR methods establish only weak control.
Comment: @Alexis Can you explain how you conclude that the Bonferroni adjustment is always wrong (maybe you want to elaborate in a separate answer?) It's a very strong statement. Is it your personal opinion or a claim that has been established in the literature? I am just curious. I was always under the impression that there is no perfect test that can be applied across all problems you may encounter. It all depends on your data, your hypotheses, and other assumptions specific to your experiment.
Comment: @Stefan the Bonferroni adjustment is not a test: it's a method of **either** adjusting *p*-values, **or** adjusting the rejection threshold under multiple testing. The two claims I specifically articulated are backed up in the literature (some of which is cited in the link I provided), but here's a solid history of the FDR: Benjamini, Y. (2010). [Discovering the false discovery rate](https://pdfs.semanticscholar.org/2d8b/c065924c4729e15b565eca0e7b06a8077b2c.pdf). *Journal of the Royal Statistical Society Series B (Statistical Methodology)*, 72(4):405–416.
Comment: @Stefan As a method of adjustment it (1) unnecessarily hemorrhages statistical power (even for a [FWER](https://en.wikipedia.org/wiki/Family-wise_error_rate) method see [Holm's methods](https://pdfs.semanticscholar.org/7f0a/29a89655d7998efc7bb53e695b3b950bf7fd.pdf)), and (2) "family of tests" has no formal meaning, but the results on rejection probabilities depend on the choice of family.
Comment: @Alexis I understand what you are saying. That was not my problem. I certainly agree that FDA methods are perfectly fine to address the issues surrounding multiple comparisons. However it still doesn't support your claim that the Bonferroni adjustment is **always** wrong.
Comment: @Stefan Can you falsify my claim? (Other than in some "A broken clock is right twice a day" fashion?)
Comment: @Alexis Why should I? I asked you for references to support you claim that the Bonferroni adjustment is **always** wrong. So it's up to you to either do it or leave it. And so far, you provided a link with references and a single paper to support that claim. In my opinion this isn't sufficient and if this claim was made in a manuscript, it would almost certainly not pass the peer-review process.
Comment: Note: just wanted to link to the following which details typical standards in the field for appropriate FDR values: https://stats.stackexchange.com/questions/252937/benjamini-hochberg-choosing-the-false-discovery-rate-q-value
Comment: I edited my answer, adding more details and changing "always correct" to "always an option".
Comment: @Altair555 The answer in the link your provided ignores the fact that FDR methods are step-down. The adjusted *p*-values are uninterpretable with respect to rejection decisions without also knowing the ordering of the unadjusted *p*-values.
Comment: @Stefan I believe I have answered you. You are dissatisfied with my answers, which is fine. But perhaps you can help me understand what your standard of evidence you are looking for to evaluate my claim "The Bonferroni adjustment should **never** be preferred to control of the FDR"?
Comment: I believe my revised answer gives an example of such a scenario.
Comment: rvl, "because the Bonferroni inequality requires no assumptions about the relationships among the events." is missing the dependent clause "even when evidence to the contrary accumulates." (I.e. suffers from my point #1) You also conflate stepping procedures with FDR: the Holm-Bonferroni and Holm-Šidak are both step-up, and both FWER).
Comment: rvl, The Bonferroni adjustment also provides different rejection probabilities if, for example, a three more independent experiments were conducted, for a fourth groups to be compared to the first three: is the family 3 or 6 tests? Bonferroni's rejection probabilities *change* depending on the size of the "family" which is effectively arbitrary. This gets at my point #2. FDR does not have these issues, ergo: Bonferroni is never preferred over it.
Comment: He only wanted to compare each treatment with control. That's 3 comparisons. The rest of this is a retread of what you've said before. We don't and won't agree.
Comment: @Alexis (1) It's interesting to see how your claim that the "Bonferroni adjustment is always wrong" changed to "The Bonferroni adjustment should never be preferred to control of the FDR". This makes a meaningful discussion quite difficult. (2) I read the link and the paper and **nowhere** the authors concluded what you are claiming here (whether you first or now second claim). Instead the authors developed a methodology to help with the problem of multiple comparisons. So providing those links is certainly useful to learn about FDR but not useful as evidence to support your claim.
Comment: To me rvl, provided a thoughtful answer and also suggest solutions to the problems @Altair555 is facing.
Comment: @Stefan I do not see the claim as having changed, but having been clarified. Given that methods exist that share neither of the Bonferroni adjustment's two major shortcomings, it is never correct to use it. But if you do not wish to articulate or clarify your desired standard of evidence, by all means go ahead and keep advocating for outdated methods that have been surpassed.
Comment: @Stefan I have been justifying my **first** comment the entire thread of this conversation. You have not articulated your standard of evidence by which you would like my first point justified. I think we're done here.
Comment: @Alexis thanks for taking out the part from your last comment that I'm not being able to comprehend your argumentation. Much appreciated!
Answer: Dunnetts multicomparrison test is used for multiple comparisons when there is a control
For reference:
http://www.statisticshowto.com/dunnetts-test/
Comment: I disagree. Dunnett's method applies when you have one control and several other treatments in ONE experiment.
Comment: Thanks for the thoughts.  An ANOVA across all experiments might be worth considering.  We initially already sidestepped the issue in our first invited revision, but this is the second round, and the reviewer is more insistent this time (yet rather vague, only stating correcting for multiple comparisons).
Comment: It sounds like they should have done an anova based on reveiwer comment . Almost as if each experiment is really a different factor or factor level. So I treated it like posthoc tests. If they strongly disagree with the reveiwer and they truly are independent experiments  they should write a rebuttal.
Comment: I can't  comment on the other answers, but here is a discussion of bonferoni from another question: https://stats.stackexchange.com/questions/120362/whats-wrong-with-bonferroni-adjustments


What intuitively is "bias"?

Question: I'm struggling to grasp the concept of bias in the context of linear regression analysis.

What is the mathematical definition of bias?
What exactly is biased and why/how?
Illustrative example?
Answer: Bias is the difference between the expected value of an estimator and the true value being estimated.  For example the sample mean for a simple random sample (SRS) is an unbiased estimator of the population mean because if you take all the possible SRS's find their means, and take the mean of those means then you will get the population mean (for finite populations this is just algebra to show this).  But if we use a sampling mechanism that is somehow related to the value then the mean can become biased, think of a random digit dialing sample asking a question about income.  If there is positive correlation between number of phone numbers someone has and their income (poor people only have a few phone numbers that they can be reached at while richer people have more) then the sample will be more likely to include more people with higher incomes and therefore the mean income in the sample will tend to be higher than the population income.
The are also some estimators that are naturally biased.  The trimmed mean will be biased for a skewed population/distribution.  The standard variance is unbiased for SRS's if either the population mean is used with denominator $n$ or the sample mean is used with denominator $n-1$.
Here is a simple example using R, we generate a bunch of samples from a normal with mean 0 and standard deviation 1, then compute the average mean, variance, and standard deviation from the samples.  Notice how close the mean and variance averages are to the true values (sampling error means they won't be exact), now compare the mean sd, it is a biased estimator (though not hugely biased).
<code>> tmp.data <- matrix( rnorm(10*1000000), ncol=10 )
> mean( apply(tmp.data, 1, mean) )
[1] 0.0001561002
> mean( apply(tmp.data, 1, var) )
[1] 1.000109
> mean( apply(tmp.data, 1, sd) )
[1] 0.9727121
</code>
In regression we can get biased estimators of slopes by doing stepwise regression.  A variable is more likely to be kept in a stepwise regression if the estimated slope is further from 0 and more likely to be dropped if it is closer to 0, so this is biased sampling and the slopes in the final model will tend to be further from 0 than the true slope.  Techniques like the lasso and ridge regression bias slopes towards 0 to counter the selection bias away from 0.
Comment: @whuber: Wow. While the abbreviation makes sense, I don't recall having come across it in any more formal settings. Are there particular subfields or applied areas where that is a "standard" initialism?
Comment: @cardinal See http://en.wikipedia.org/wiki/Simple_random_sample
Comment: (+1) @whuber's edit was helpful in clarifying this answer.
Comment: SRS?    $\text{  }$
Comment: @cardinal Simple Random Sample.
Comment: @whuber: I know what a simple random sample is. :) It was the initialism that struck me as odd, combined with the assumption that it was ubiquitous enough to use without defining.
Comment: @cardinal I'm sorry; I had no intention of even suggesting you didn't know.  I apologize for giving you that impression.  The point of the Wikipedia reference is that it uses "SRS" (see the fifth paragraph), indicating that it's not confined to some subfield but actually is quite common.
Comment: @whuber: No apology necessary at all. I was not "offended". In my quick perusal of the page, I missed the reference in the fifth paragraph; thanks for the pointer. (From the perspective of proper composition, I'd argue that SRS still needs to be defined, even in that Wiki article.)
Comment: Can you include and put 'positive bias' and 'negative bias' into context?
Comment: @RomanLuštrik, positive and negative bias could just refer to the sign of the difference between the estimator and the true parameter.  Or it could be positive if the bias is minor but greatly reduces the variance and negative if is has a large impact on estimates.  Do you have more context for your question?
Comment: @GregSnow I was thinking in the context of the sign.
Answer: Bias means that the expected value of the estimator is not equal to the population parameter.
Intuitively in a regression analysis, this would mean that the estimate of one of the parameters is too high or too low. However, ordinary least squares regression estimates are BLUE, which stands for best linear unbiased estimators. In other forms of regression, the parameter estimates may be biased. This can be a good idea, because there is often a tradeoff between bias and variance. For example, ridge regression is sometimes used to reduce the variance of estimates when there is collinearity.
A simple example may illustrate this better, although not in the regression context. Suppose you weigh 150 pounds (verified on a balance scale that has you in one basket and a pile of weights in the other basket). Now, you have two bathroom scales. You weigh yourself 5 times on each.
Scale 1 gives weights of 152, 151, 151.5, 150.5 and 152.
Scale 2 gives weights of 145, 155, 154, 146 and 150.
Scale 1 is biased, but has lower variance; the average of the weights is not your true weight. Scale 2 is unbiased (the average is 150), but has much higher variance.
Which scale is "better"? It depends on what you want the scale to do.
Comment: I agree with @whuber here. In the (proper) sense of bias that the OP is asking about, it is *not* the scale that is biased or unbiased, but rather whatever estimate of your weight that you derive from its measurements!
Comment: Although the definition of bias is correct, I fear that the examples confuse it with inaccuracy, which is something altogether different!  Bias is a property of a *statistical procedure* (an estimator) whereas accuracy is a property of a *measurement process*.  (-1).
Comment: @whuber: Yes, I agree with that. And, I still think that, even so, it is necessary to make clear the difference between mathematical expectation and a sample average, as they relate to bias.
Comment: No, I was not trying to say anything about "inaccuracy" (which is awfully hard to define) but about "variance". One scale is unbiased, the other scale has low variance. I did not use the word "accurate" or "accuracy". A scale which tends to estimate your weight too high (or too low) is biased.
Comment: But this sense of "bias" is just a synonym for inaccurate; it is not the same as the definition you gave in the first line. Moreover, as @cardinal points out, the example also confounds an expectation with the mean of a particular sample.
Comment: OK, so, I should say "the measurements that you get from stepping on the scale are biased"? That seems needlessly wordy. And my use of "bias" even if technically wrong, is not the same as inaccurate; BOTH scales (or the measurements gotten from them) are inaccurate, just in different ways.
Comment: @Peter, no you shouldn't say that, either, as it is also incorrect. For an appropriate discussion of bias, you need (a) a statistical model for how the data are collected---and the associated measurement process---which identifies at least one parameter of interest and (b) a procedure (a function of the data!) to take the measurements and produce an estimate of the parameter of interest. The former is neglected entirely in your post and, with due respect, you sound a bit confused about the latter.
Comment: @whuber: I think the main problem that your point addresses is the lack of explicit mention of assumptions and a modeling setup. I suppose, in my own mind, I filled these in as I was reading the answer. It seems to me it would not take much to clean that up.
Comment: @cardinal It might not take much work, but the work is essential for the reply to be fully correct.
Answer: In Linear regression analysis, bias refer to the error that is introduced by approximating a real-life problem, which may be complicated, by a much simpler model. In simple terms, you assume a simple linear model such as y*=(a*)x+b* where as in real life the business problem could be y = ax^3 + bx^2+c.
It can be said that the expected test MSE(Mean squared error) from a regression problem can be decomposed as below.
E(y0 - f*(x0))^2 = Var(f*(x0)) + [Bias(f*(x0))]^2 + Var(e)
f* -> functional form assumed for linear regression model
y0 -> original response value recorded in test data
x0 -> orginal predictor value recorded in test data
e -> irreducible error
So, the goal is selecting a best method in arriving a model that achieves low variance and low bias.
Note: An Introduction to Statistical Learning by Trevor Hastie & Robert Tibshirani has a good insights on this topic
Comment: This is often referred to by something like "model mis-specification error" in order not to confuse it with the standard definition of bias given in the accepted answer.  Otherwise it would be impossible to make sense of the (correct) assertion that OLS is an *unbiased* estimator of the coefficients of the regressors.

What intuitively is "bias"?


Converting IPv6 to integer in BigQuery standard SQL

Question: I tired converting IP address to integer. It worked for IPv4 but while doing IPv6 i got error saying

NET.IPV4_TO_INT64() encountered a non-IPv4 address. Expected 4 bytes but got 16

How to convert IP address both IPv4 & IPv6?
Comment: An IPv6 address is 128 bits long, and all of the bits are relevant. You cannot expect to fit one into a 32 bit integer, and I don't think BigQuery has a 128-bit integer type.
Comment: Hi Damien_The_Unbeliever, Please let me know if there is any way that i could actually convert IPv6 to integer ?
Comment: You would need to have 128-bit integers. IPv4 addresses are 32-bit unsigned integers, regardless of the dotted-decimal notation, which is just to make it easier for humans to read, but an actual IPv4 address (the way network devices see and use it) is a 32-bit unsigned integer. An IPv6 address is a 128-bit unsigned integer, and that is how network devices see and use it. You simply cannot fit a 128-bit data structure into a 32-bit data structure.
Comment: @Sunil if the workaround helped somehow, consider accepting/upvoting
Answer: If you need to convert a IPV6 to a decimal value, you can use a JavaScript UDF just like below. Please have in mind that the numeric value resulting from this operation needs to be represented as a STRING because its too big to fit into a BigQuery number type
CREATE TEMP FUNCTION ipv6_to_number(ip STRING)
RETURNS STRING
LANGUAGE js AS """
var parts = [];
    ip.split(":").forEach(function(it) {
        var bin = parseInt(it, 16).toString(2);
        while (bin.length < 16) {
            bin = "0" + bin;
        }
        parts.push(bin);
    })
    var bin = parts.join("");
    var dec = BigInt("0b"+ bin)
    return dec;

""";

Select "2001:0db8:0:0:8d3:0:0:0" ip, ipv6_to_number("2001:0db8:0:0:8d3:0:0:0") number

Result:
Row ip                         number
1   2001:0db8:0:0:8d3:0:0:0    42540766411282592857539836924043198464


How do I prove that |A| - |A\B| = |A∩B|

Question: I tried to prove that |A| - |A\B| = |A∩B| by the following identities:

|A| + |B| - |A⋃B| = |A∩B|
A\B = A(A∩B)
A∩B = A(A\B)
(A⋃B)\B = A\B
A⋃B = A⋃(B\A)

I can't figure out what to do, I would be glad to get some help here. Thanks in advance!
Comment: You could use that for $A,B \subset \Omega$ we have $A \setminus B = A \cap B^{\complement}$.
Comment: Also, A∩B = A(A\B) doesn't really make sense, I suspect you are missing an operator there. The same goes for the second statement.
Comment: The notation $|A|$ likely means the size or *cardinality* of set $A$.  While that may be known to you, it is worth pointing out that since your conclusion involves that notation, and since only "identity" 1. uses that notation among the ones listed, that first identify will need to be used in your proof.  So that's a place to start.  I suspect that the setup for this exercise specified that the sets $A,B$ are finite, and you should look for steps in which their finiteness is important to the argument.
Comment: In identity 3 I meant to A∩B = A \ (A\B)
Comment: @hardmath You're right, I misread
Answer: Note that $$ A=(A\cap B) \cup (A-B)$$
The sets on the RHS are disjoint so $$|A|=|A\cap B)|+|A-B|$$
Answer: By using the fact that $|A\setminus B|=|A\cap \overline{B}|$ this becomes
$$|A\cap \overline{B}|+|A\cap B|=|A|$$
then, applying identity $1$ on the LHS,
$$|(A\cap \overline{B})\cup(A\cap B)|+|(A\cap \overline{B})\cap(A\cap B)|=|A|$$
$$|A|+|\varnothing|=|A|$$
which is true.
Comment: Thank you! It took me a while to figure it out, thanks again.

How do I prove that |A| - |A\B| = |A∩B|


$x^y < y^x$ for $y\ll x$?

Question: Sorry if this is a naive question; I am not very good at mathematics.
It seems obvious that for many $x$ and $y$, $x^y < y^x$ if $y \ll x$, e.g. $2^{10} > 10^2$. If $x$ and $y$ are very close to each other, this does not hold (simple case: $2^3 < 3^2$).
So - is there really such a regularity? Does it have a name? Is there an exact rule for which $x$ and $y$ it holds (let us, for simplicity, assume both are natural numbers)?
Comment: Well note that $1 << 100$ but $100^1 > 1^{100}$
Comment: Assuming everything is positive $x^y<y^x\iff x^{1/x}<y^{1/y}$ so simply investigate $x^{1/x}$
Comment: Try graphing $f(x)=x^{1/x}$ and compare $f(a)$ with $f(b)$ for different values of $a$ and $b.$ This is the same as comparing $a^b$ with $b^a$, if you think about it (exponentiate both sides by something.) It's a decreasing function after some point, so you can say that is the "regularity" in this case.
Comment: @DanZimm Right, that should have been obvious, even to me. But is it a counterexample or an exception?..
Comment: I'd probably say an exception, since $1$ is a multiplicative identity. This is indeed an interesting question to me nonetheless.
Answer: This is an interesting problem. Since you say you're "not very good at mathematics", I'll give the result first and then explain how I came up with it.

If $x$ and $y$ are greater than $2.71828\dots$, then $x^y < y^x$ if and only if $x > y$.
If $x$ and $y$ are less than $2.71828\ldots$, then $x^y < y^x$ if and only if $x < y$.
If $x$ is less than $2.71828\ldots$ and $y$ is greater than $2.71828\ldots$ (or vice versa), you should compute $x^y$ and $y^x$ to see which is bigger.

The number $2.71828\ldots$ is Euler's constant $e$. This result explains why strange things happen around $2$: as you noticed, $2^4 = 4^2$ and the two number $2^3$ and $3^2$ are very close. But in general, if $x$ and $y$ are close to each other but "far away" from about $2.71828\ldots$ then you can just compare them directly to see if $x^y < y^x$.
In more detail, the inequality $x^y < y^x$ is equivalent to $y\ln x < x\ln y$, by taking logarithms. And that inequality is equivalent to $(\ln x)/x < (\ln y)/y$, by dividing by $xy$. So we can reformulate your original problem to the problem of determining whether the function $f(t) = (\ln t)/t$ is increasing or decreasing. You can show, using calculus, (I'll supply the details if you would like them), that the function $f(t)$ is increasing when $t < e$ and decreasing when $t > e$.
Comment: Very good answer!
Comment: Thank you, I think you pretty much hit my level of calculus with that explanation :)
Answer: Take $\ln(\cdot)$ on both sides of the inequality $x^y < y^x$ and then separate the variables, you get the inequality $\ln(x) / x < \ln(y) / y$. So it comes down to investigating where the function $f(x)=\ln(x)/x$ is decreasing, which has a very simple and satisfying answer using calculus.
Answer: The function $f(x) = \frac{\log x}x$ has one local maximum which is also a global maximum at $x = e$ (considering $(0, \infty)$ as the domain). For the purpose of integer calculcation, we need to consider $2$ and $3$ as they are the integers surrounding $e$. From $f(2) = f(4)$, we know $f(3)$ is the maximum when the domain is restricted to positive integers. From this knowledge, we know that there are only two cases where the strict inequality does not hold: $2^3 < 3^2$ and $2^4 = 4^2$.

$x^y < y^x$ for $y\ll x$?


cssSelector("select[title=\"Sort By\"]")

Question: In a selenium script Sorting a dropdown using
new Select(driver.findElement(By.cssSelector("select[title=\"Sort By\"]"))).selectByVisibleText("Name");
Can anybody please explain me this part cssSelector("select[title=\"Sort By\"]" of above statement.
Thanks!
Answer: cssSelector("select[title=\"Sort By\"]")

this is one of the technique to locate web element/elements.
You must have heard about xpath, which is one of the way to locate element/elements in a web page.
Further more , select is tag in HTML. title is attribute and Sort By is value of attribute.
Just like this :
HTML :
<select id="sel" class="drop-down" title="Sort By">
  <options>..</options>
  <options>..</options>
  <options>..</options>
</select>

Now If you have to write cssSelector , you can write like this :
tagname[attribute="attribute value"]

select[id="sel"]

or
select[class="drop-dwon"]

or
select[title="Sort By"]

Hope this will be helpful !
Comment: That escapes the quote mark. (because you are already in between two double quotes). So it passes on "Sort By" instead of Sort By
Comment: Or to make it simple, you can use single quote, `select[title='Sort By'] `.  Using Single/Double quote to wrap HTML Tag Attribute value is acceptable in XPath and CSS Selector.
Comment: Thankyou! yes it helps. one more thing why \ is used with Sort By.
Answer: new Select(driver.findElement(By.cssSelector("select[title=\"Sort By\"]"))).selectByVisibleText("Name");
You are selecting by CSS selector https://www.w3schools.com/cssref/css_selectors.asp. The alternative is XPath which is more powerful but harder to learn.
What this part By.cssSelector("select[title=\"Sort By\"]") does is select all select elements that have title attributes set equal to "Sort By". Although by prefixing driver.findElement( you are requesting just one element, the first. At least you would be if it was python, Java might differ but was not in your question nor tags.


Run a boolean test function on form submit

Question: Is there a way to run a function when a user submits a form in Drupal that returns a true or false. If it is true, run the submission handler. If false, return an error.
Application:
I am using Drupal to run a product booking system. If a product is reserved during a certain period of time, it is not available to others. The client wants the customer to be able to change the dates of the their order. This is fine. The order creates a reservation node and with permissions and hook_form_alter, I set it up so that they can edit the reservation dates.
However, I don't want them to be able to change the dates to whatever they want without first checking to see if it is already reserved. I have already written the code to run a query and return a boolean based on whether or not there is a booking conflict. Now I just need to be able to use that on the form submission handler.
Answer: You should do this in validation handler. In hook_form_alter (or in your form definition function), add $form['#validation'][] = 'mymodule_form_validate';. Then, add this code:
function mymodule_form_validate($form, &$form_state) {
  if (!mymodule_dates_valid($form_state)) { // Return boolean here.
    form_set_error('date_field', t('Invalid dates'));
  }
}


Derivatives interpreted as fractions

Question: So I was wondering if manipulating differential as fraction is fine.In Physics problems ,usually, what I see is if we have equations of magnetic field ,we consider a magnetic field caused by a small length dl and the magnetic field is dB and integrating over the whole length.it seems we are treating dB as a infintesimal quantity.However ,after browsing for a while,the answer is that the notation dy/dx is not a infintesimal quantity but rather an operation on the function y.I am confused as to how it is valid in physics to treat it as infintesimal quantities.(After learning it,my notion for physics just got crushed and am now confused).I have not learned multivariable calculus yet,but from the arguments I've read ,I found that interpreting them as fractions does not work anymore.But it seems it works fine when in 2 dimensions.In mechanics when we derive equation for rocket motion (ejecting mass) we interpret differential as small quantities (dm) and divide by small time dt.Sorry for the long story... I am confused right now
TL:DR : In physics ,dy/dx can be operated as if it was a small quantity divided by small quantity,though from what I've read it is not supposed to be a ratio.
When does interpreting them work and when does it not. Any help would be very much appreciated ...
Answer: I think you meant "derivatives" rather than "differentials" and are asking if it is valid to "treat derivatives as fractions with differentials as numerator and denominator".
Yes, it is.  To show that any given property of a fraction still holds for a derivative, go back before the limit in the definition of the derivative to the "difference quotient", use the fraction property, then take the limit.

Derivatives interpreted as fractions


Copy paste to different position using macro

Question: i need the code to copy paste in the row below the last row with data in it. Ive wriiten the code to do this but instead of only picking data from E2:J9 its picking data from B2:J9 from the pivot.
How do i fix this.
Thanks
Sub aaaaaa()
Dim ws As Worksheet
Set ws = Worksheets("Pivot_WH calculations") 'change name as needed

With ws
   'assumes data is in a "table" format with all data rows in column A and data columns in row 1
   Dim lRow As Long, lCol As Long
   lRow = .Range("A" & .Rows.Count).End(xlUp).Row
   lCol = .Cells(1, .Columns.Count).End(xlToLeft).Column

   .Range(.Range("E2:J9"), .Cells(lRow, lCol)).Copy _
    Worksheets("WH Calc_new").Range("L" & .Rows.Count).End(xlUp).Offset(2)

   .Range(.Range("A2:A9"), .Cells(lRow, lCol)).Copy _
    Worksheets("WH Calc_new").Range("K" & .Rows.Count).End(xlUp).Offset(2)
End With

End Sub

Comment: If you want data from only E2:J9, why are using lRow and lCol?
Comment: This `.Range(.Range("E2:J9"), .Cells(lRow, lCol)).Copy` should  be `.Range("E2:J9").Copy`
Comment: Similarly for other Column
Comment: Thanks, i used a different code as the base for this.
Answer: Try
Sub aaaaaa()
Dim ws As Worksheet
Set ws = Worksheets("Pivot_WH calculations") 'change name as needed

With ws
   'assumes data is in a "table" format with all data rows in column A and data columns in row 1
   Dim lRow As Long, lCol As Long
   lRow = .Range("A" & .Rows.Count).End(xlUp).Row
   lCol = .Cells(1, .Columns.Count).End(xlToLeft).Column

   .Range("E2:J9").Copy _
    Worksheets("WH Calc_new").Range("L" & .Rows.Count).End(xlUp).Offset(2)

   .Range("A2:A9").Copy _
    Worksheets("WH Calc_new").Range("K" & .Rows.Count).End(xlUp).Offset(2)
End With

End Sub

When the Range is Specific, you don't need lrow & lcol as said by AAA
Comment: what can i do to add the date in a sequential order, i cant use a for loop as it will populate additional cells, how can i add code so that every next cell 7 days are added to the date. Thanks
Comment: You should ask a New question, clearly explaining the problem that you are facing.


Saving multiple field values in a users entity

Question: I am trying to reference other nodes on the user entity on field_clinic but everything else is saving except that multiple value field. What could i be doing wrong. The field_clinic accepts multiple values. Below is my code:
$clinics = [

        array('value' => 132),
        array('value' => 133),
        array('value' => 134),
    ];

    // if the user exsists update basestation
    $UserEntity = User::create([
        'name' => 'Final',
        'roles' => array('subscriber'),
        'field_age' => '2',
        'field_city' => 12,
        'field_clinic' => $clinics,
        'field_base_statition' =>  $bs_nid

    ]);

    $UserEntity->save();

The clinics array contains the node ids that I am trying to reference. Please help
Answer: The way you're setting the values may be failing to work if you've got the wrong keys in your array - setting any field from code requires you to know how that specific field type stores its data in the entity.
If you're not sure about that key, using the devel module you can simply save one of those users filling the field_clinic field with appropriate values then switch to the devel tab for that user and inspect what keys are actually being used to store the values in that field (probably one named target_id).
According to what you find there, fixing your code may be just matter of changing this:
$clinics = [
    array('value' => 132),
    array('value' => 133),
    array('value' => 134),
];

to this:
$clinics = [
    ['target_id' => 132],
    ['target_id' => 133],
    ['target_id' => 134],
];

(disregard the difference between declaring an array using the [] or the array(), I used the former in my edited code just for coherency)


Excluir registros separados por vírgula

Question: Estou fazendo o upload de várias imagens e ao guarda-las no banco, até aí está perfeito. Os registros são gravados, separados por vírgula no campo materialDocumento na tabela tb_material.
O problema é que não estou conseguindo excluir uma imagem em específico que seja selecionada, quando necessário.
Poderiam me ajudar?
Os arquivos são registrados no banco da seguinte forma:
498818_03c4414ce0324292a51e63009f513a82_mv2.jpg, 64223640_2226772990741441_1192728863528976384_o.jpg, 64254162_1912126265586260_4480819099357675520_o.jpg, 25044125149117.jpg

material-edita.php
<a href="material-edita.php?edita_material_ID=<?php echo $_GET['edita_material_ID']; ?>&imagem_material=<?php echo $img; ?>"><button type="submit" class="btn btn-large btn-danger" name="btn-deletar-imagem">   Excluir Imagem Material</button>

<?php
  if (isset($_GET['edita_material_ID'])) {
      $materialID = $_GET['edita_material_ID'];
      extract($classeMaterial->getID($materialID));

      $mDocumento = $_GET['imagem_material'];

  if ($classeMaterial->deletarArqImg($materialID, $mDocumento)) {
    var_dump($mDocumento);
  }
}
?>

class.classe_material.php
<?php
    public function deletarArqImg($materialID, $mDocumento)
    {
        try {
            $stmt = $this->db->prepare("DELETE FROM tbl_material WHERE materialID = :materialID AND materialDocumento = :mDocumento");
            $stmt->bindparam(":mDocumento", $mDocumento);
            $stmt->bindparam(":materialID", $materialID);
            $stmt->execute();
            return true;

            } catch (PDOException $e) {
            echo $e->getMessage();
            return false;
        }
    }
?>

Comment: Se quer apenas excluir uma imagem específico, não faz muito sentido dar `DELETE` no registro inteiro. Não seria melhor fazer um `UPDATE` removendo a imagem da lista?
Comment: O mais simples seria gravar cada imagem com um id, agora estando elas juntas você terá que recuperar o registro, e separar com um explode, o que vai gerar um array e depois encontrar o índice respectivo... Ou seja, repense a forma de salvar as imagens...
Comment: Fabio, a solução com explode irá lhe dar muito mais dor de cabeça do que remodelar essa seção em sua base de dados. Se esta mexendo nisso, refaça, perca um pouco mais de tempo. Crie uma tabela só para as imagens, cada imagem com um id e associe com o id do material.
Comment: Sim Anderson, concordo. Mas quando dou UPDATE, ele deleta todos os registros e acrescenta o registro que eu queria deletar. Acredito que o explode poderia resolver como comentou o MagicHat. Poderia me dar uma orientação de como faze-lo?
Comment: Justamente, já que está usando um banco relacional, não tem porque se beneficiar dele para resolver o problema.
Answer: Como você estava armazenando uma "coleção" de valores em string você precisa entender o que está fazendo.
Todos os seus documentos relacionados a um determinado material estão salvos como um único valor (string). Então o seu banco de dados não entende que existem vários documentos relacionados pois não foi realizado essa estrutura. Mas como você sabe que existem várias relações o ideal é seguir a sugestão do @AndersonCarlosWoss e realizar um update na string.

Primeiro, é necessário obter o registro a ser atualizado (Caso não tenha um método para isso):
public function find($id)
{
    $stmt = $this->db->prepare("SELECT * FROM tbl_materia WHERE materialID = ?");
    $stmt->execute(array($id));
    $material = $stmt->fetchAll();
    return $material[0];
}

Após obter o registro pelo id, é necessário verificar se o documento a ser excluído existe para então realizar o update no lugar do delete.
public function deletarArqImg($materialID, $mDocumento)
{
    $material = $this->find($materialID);

    //Utilizar o array_map para aplicar a função trim (remover os espaços vazios do lado direito e esquerdo) em cada valor do array
    $documentos = array_map('trim', explode(',', $material['materialDocumento']));

    $key = array_search($mDocumento, $documentos); //Verificar se existe o documento a ser "excluído"
    if ($key !== false) {
        unset($documentos[$key]); //Removendo o documento do array de documentos
        $newDocumentos = implode(',', $documentos);

        try {
            $update = $this->db->prepare("UPDATE tbl_material SET materialDocumento = :newDocumentos WHERE materialID = :materialID");
            $update->bindParam(":newDocumentos", $newDocumentos);
            $update->bindParam(":materialID", $materialID);
            return $update->execute(); //Retorna TRUE para sucesso ou FALSE para falha
        } catch (PDOException $e) {
            echo $e->getMessage();
            return false;
        }
    }
}

Comment: Perfeito Victor. Entendi, funcionou corretamente, muito obrigado. Agradeço imensamente pela ajuda. E eu concordo com os colegas, o melhor e mais fácil procedimento seria criar uma tabela a parte. Mas o problema e alterar toda a estrutura do projeto e acrescentar mais um JOIN nas minhas QUERY´S, o qual já estão  bem grandes pela quantidade de tabelas relacionadas que tenho. Mas a ajuda de vocês foi fantástica e agradeço a todos pela ajuda.
Comment: Não é seguro fazer `if ($key)` para validar o retorno de `array_search`, pois o valor procurado pode ser o primeiro do *array* e ser retornado o índice 0, não entrando no `if`. O ideal é fazer `if ($key !== false)` dado que o retorno é `false` quando o valor não é encontrado. Ou usando as condições Yoda: `if (false !== $key)`.
Comment: Obrigado @AndersonCarlosWoss pelo observação, agora nunca mais esqueço isso xD
Comment: O grande problema é como informar a posição correta a ser substituída, como a aplicação vai identificar o registro a ser excluído? Pode ser o índice 0, hora o índice 2 e assim por diante... Cada imagem tem de ter o próprio identificador.
Comment: O correto seria desta forma mesmo, obdecendo a estrutura *one to many* mas para o caso que ele informou não tem muito o que fazer. Ele pode fazer a solução que postei ou reestruturar essa parte na base de dados como você havia sugerido.
Comment: Esta me aparecendo o seguinte erro: Parse error: syntax error, unexpected '$material' (T_VARIABLE), expecting ',' or ')' in classes\classe_material\class.classe_material.php on line 158
Comment: @Fabio, atualizei a resposta com a correção. A instrução `explode` precisa de dois parâmetros separados por vírgula, estava sendo passado os dois parâmetros mas sem a separação.

Excluir registros separados por vírgula


"Monitorando" uso de aplicativos

Question:
Há alguma maneira de de monitorar quanto tempo o usuário usa cada aplicativo?

O Google Analytics tem a capacidade de fazer isso?
Answer: Sim, existe essa possibilidade. O Google Analytics te dá o tempo médio das sessões de uso. Há ainda a feature de "ao vivo", onde você consegue ver quem está utilizando o aplicativo no momento.
Comment: existe alguma documentação alem dessa? https://developer.android.com/reference/com/google/android/gms/analytics/Tracker.html
Comment: Sim: https://developers.google.com/analytics/devguides/collection/android/v4/

"Monitorando" uso de aplicativos


TypeError in Jython?

Question: I'm trying to make two lines across a circle, like an X. Since it's an X, to find the (x,y) I just multiplied sqrt(2)/2 by the radius and then added or subtracted it from the (x,y) origin depending on what corner of the circle it was in. However I keep getting a TypeError 'The error was: 2nd arg can't be coerced to int' This is what I have:
#starting/ending points of the line
a1 = z - ((sqrt(2) / 2)*(r1))
b1 = w - ((sqrt(2) / 2)*(r1))
a2 = z + ((sqrt(2) / 2)*(r1))
b2 = w + ((sqrt(2) / 2)*(r1))
c1 = z - ((sqrt(2) / 2)*(r1))
d1 = w + ((sqrt(2) / 2)*(r1))
c2 = z + ((sqrt(2) / 2)*(r1))
d2 = w - ((sqrt(2) / 2)*(r1))
pic.addLine(black, a1, b1, a2, b2)
pic.addLine(black, c1, d1, c2, d2)

...where z is the x origin, w is the y origin, and r1 is the radius.
What am I doing wrong here? This what I'm getting :
Comment: Have you tried turning the `a1`, `b1`, `a2`, `b2`, etc. arguments to integer yet? `int(a1), int(b1), int(a2), int(b2)`?
Comment: What gets displayed if you do `print type(a1)` right before you call `pic.addLine`?
Answer: By using sqrt() you end up with floating point values, but the method you are calling wants integers only. Call int() on the values before passing them to pic.addLine():
pic.addLine(black, int(a1), int(b1), int(a2), int(b2))
pic.addLine(black, int(c1), int(d1), int(c2), int(d2))

TypeError in Jython?


Clustering documents based on pairwise similarity and without access to features

Question: I have a set of documents and distances among them. I want to cluster the documents based on pairwise distances/similarities among them.
I have only a single parameter as distance. What are the available clustering algorithms to work on these kind of problems?
Comment: Please clarify what you mean by "correlation distance".
Comment: correlation distances means distance between every two nodes.
Answer: Assuming that you only have access to pairwise distances among your documents but no access to the documents themselves, there are still some clustering techniques you can apply.
Algorithms like k-Means, which require access to the feature space (e.g., to place the centroids) cannot be applied. However, scikit-learn has some other clustering algorithms which can work by simply analyzing a matrix of pairwise distances among samples:

AffinityPropagation, with the option affinity="precomputed"
SpectralClustering, again with affinity="precomputed"
AgglomerativeClustering, passing affinity="precomputed"
DBSCAN, with metric="precomputed"

edit: Take a look at the concerns of @Anony-Mousse in the comments to this answer.
Comment: Note that affinity requires different input than distance metrics.
Comment: Some methods require a *similarity*, some a *distance*. That is not the same.
Comment: @Anony-Mousse, can you be more specific? I can edit the answer if I am missing something.
Comment: Well, I checked and all the cited clustering methods from sklearn accept euclidean distances. I will remove the "or some other similarity measure" from the answer, as maybe some weird custom similarities might cause problems with some of the algorithms. Thanks for the correction.
Comment: Try passing a precomputed Euclidean distance matrix to these functions vs. passing the data matrix and setting the parameter to run euclidean. You'll see that for the first two you get fundamentally different results, only the bottom two expect a distance matrix k (to make it more confusing, the "affinity" parameter of AC does *not* expect an affinity but a distance matrix).
Comment: Well, If that is the case, maybe it would be good to open an issue about this in the sklearn repo. I will look into that more carefully if I have the time.