Bag of Visual Words: the number of words is equal to the number of k-means centroids?

Question: I was reading these slides about Bag of Features (BoF), in particular at slide 23:

A visual vocabulary of 1M words is generated using an approximate
  K-means clustering method based on randomized trees.

By "words" they means the centroids obtained by k-means? Otherwise what they mean?
Comment: I think so. When you cluster in the centroids, you are creating your dictionary. Each one of the entries of the dictionary, are each one of the words. A word is nothing more than a feature vector, really.
Comment: But this looks weird...I mean, the histograms are going to be of  1M dimensions! This is INSANE! Right? :D
Comment: The histograms are one dimensionals because it is just a feature count. Imagine in a visual image, that you have a visual feature which is an eye. Eye is your visual word. Then, in your dictionary, you are going to have more than one, perhaps mouth,nose, whatever... all the words. The eye can have more than one feature (e.g. colours), however, in the histogram, you count how many eyes you have detected. In short, a histogram is a count, and the x axis is just the index of the visual word.
Comment: I'm sorry, i think that I'm not explaining myself. What I mean is that EVERY Image is going to be represnted as a 1 million dimensions vector! There is NO way that you can use such a vector, it's definitely too big! Do you know what I mean?
Answer: The "centroid" really refers to the coordinates.
The concept of "word" means it's simply a symbol, not something meaningful like coordinates.
Every SIFT vector is mapped to a word (e.g. "42"); the image is represented as a bag of such words ("42 13 17 42 17"), not as a string of centroid coordinates.
The "dictionary" translates coordinates to words.
Yes, there may be a million words (although most appear to only use a few thousand?). But most will be 0, and you don't need to store these zero values. Just as with text.
Comment: How many different words are there on the internet? Text usually has millions of dimensions, but most of them are 0 and don't need to be managed. Use *sparse* vectors.
Comment: Ok, but according to the quoted text this means that our vector is composed by MILLIONS of dimensions! This absolutely insane, no way that we can manage in any way such big vectors! And can you imagine running k-means for finding 1 million centroids? Something is wrong here I guess :D
Comment: I guess you're right for texts, but here we're talking about images. If this would be the case, then I think that PCA would a mandatory step in every application that involves BoF/BoW,  because we cannot deal with such big vectors. But this doesn't happens (there are several implemented applications which doesn't use PCA at all).
Comment: I mean, vectors of millions of dimension are too big even for LSH! The curse of dimensionality happens where we have vectors with some hundreds of dimensions. Millions of dimensions is unrealistic :D
Comment: No, PCA would be an infeasible route. But you are seeing a problem that doesn't exist. The point of this approach *is* to use text techniques; and usually images *do* produce sparse vectors, too.
Comment: Ok, interesting. So what could be a reasonable way? Using Latent Semantic Analysis through SVD decomposition, like we do in Texts?
Comment: You don't do dimensionality reduction. You do **full text search**. Imagine typing "42 13 17 42" into Google.
Answer: Once you created the vocabulary, you have a list of all possible words in the training set(dictionary). Let's do an easy example. The training set contains an 'eye', a 'mouth' and a 'nose'. When a new test image comes, then you are going to extract features and you are going to try to detect these three features. Then, what you do is you create a histogram, having as index these three. 1.eye 2. mouth. 3.nose. For every feature that is similar to an eye, you are going to add a +1. Say that now you test with an image where there are 100 eyes. Then your histogram for that image is going to be [100 0 0] (no mouth and no nose.) Therefore, in this case, this image is represented with 3 components.
100   |       0   |           0
e  | m | n
I hope it is clearer now. An image, will kind of have a 'signature' which will be a kind of summary of your features. In this case, the histogram would define perfectly the image as
100 eyes! And it is precisely what the image would be, right?
Let me know if something is not clear!
Comment: thanks for your explenation. I was not sure about the meaning of "word" in such a context.  But my observation still remain: according to text we have MILLIONS of words. This means that each image is represented through an histogram (vector) of MILLIONS of dimension. Can you imagine managing such a vector? It's simply IMPOSSIBLE! :D
Comment: Oh sure. You have a histogram which has as many dimensions as words in your dictionary. But note that most of them are going to be empty, so you can store only the ones that are not :)
Comment: I just saw that the sparsity thing has been comented below.


Calculating a limit. Is WolframAlpha wrong or am I wrong?

Question: What I'm trying to solve:
$$\lim _{x\to -\infty \:}\frac{\left(\sqrt{\left(x^2+14\right)}+x\right)}{\left(\sqrt{\left(x^2-2\right)}+x\right)}$$
What I put into WolframAlpha:
<code>(sqrt(x^2+14)+x)/(sqrt(x^2-2)+x)</code>
My result: $1$, which I get by simply dividing bot the numerator and the denominator by $x$, then letting it go towards $-\infty$
$$\frac{\frac{\left(\sqrt{x^2+14}+x\right)}{x}}{\frac{\left(\sqrt{x^2-2}+x\right)}{x}}=\frac{\left(\sqrt{\frac{x^2}{x^2}+\frac{14}{x^2}}+\frac{x}{x}\right)}{\left(\sqrt{\frac{x^2}{x^2}-\frac{2}{x^2}}+\frac{x}{x}\right)}=\frac{\left(\sqrt{1+\frac{14}{x^2}}+1\right)}{\left(\sqrt{1-\frac{2}{x^2}}+1\right)}\:=\:\frac{\left(\sqrt{1}+1\right)}{\left(\sqrt{1}+1\right)}\:=\:\frac22 \ = \ 1$$
WolframAlpha's result: $-7$. It has a long, complicated 25 step solution.
Is the solution $1$, $-7$ or neither?
Edit: of course, I set it $x$ to go towards $-\infty$ in WolframAlpha too
Comment: If you divide everything by $x$, then you should get $\frac{0}{0}$ which is no good.  (Keep in mind that $\sqrt{x^2} = |x|$, and as $x \to -\infty$, that means that $\sqrt{x^2} = -x$.)
Comment: For sufficiently negative $x$, the fraction that you want the limit of is negative (because the numerator is positive and the denominator negative). So the limit can't be a positive  number like $1$.
Comment: Could you elaborate on what you did when you "divided everything by $x$"?
Comment: Both the numerator and the denominator. Then I get $$\frac{\left(\sqrt{1}+1\right)}{\left(\sqrt{1}+1\right)}$$ after I let everything else tend towards negative infinity.
Comment: Edited my post, sorry. I thought it was more clear. After I divided by $x$, I canceled out the $x$'s as my post shows.
Answer: The limit is as $x$ goes to $-\infty,$ so you can't just divide by $x.$ Both the numerator and the denominator have the form $\infty -\infty.$ WolframAlpha is correct.
Comment: @DavidIlic $x=-\sqrt{x^2}$ when $x<0$.
Comment: Thank you. I asked about how to solve this limit a couple of days ago and one of the responses told me it's 1, and that it's fine to divide by x. He probably thought it tends towards positive infinity.
Comment: You actually can divide the numerator and denominator by $x$ as the expression $\frac{\sqrt{x^2+14}+x}{\sqrt{x^2-2}+x}$ is defined when $x< -\sqrt{2}$. Doing so gives $\frac{\frac{\sqrt{x^2+14}}{x}+1}{\frac{\sqrt{x^2-2}}{x}+1}$. Since $\frac{\sqrt{x^2+14}}{x}$ and $\frac{\sqrt{x^2-2}}{x}$ both approach $-1$ as $x$ approaches $-\infty$, the limit $$\lim_{x \rightarrow -\infty}\frac{\frac{\sqrt{x^2+14}}{x}+1}{\frac{\sqrt{x^2-2}}{x}+1}$$ yields your indeterminant form $\frac{0}{0}$, so it won't be that helpful
Comment: Edited my original post to show more clearly what I did. Why can't I go further dividing by $x$ under the root by turning it into $x^2$?
Comment: Yeah.. totally missed that. Thanks.
Answer: You can divide by $x$ but not in that way. Since $x\to-\infty$ it is eventually negative i.e. $-x>0$ so you should have $$\frac{\sqrt{x^2+c}}x = \frac{\sqrt{x^2+c}}{-\sqrt{x^2}}=  -\sqrt{1+\frac c{x^2}}=-1-\frac c{2x^2}+O(|x|^{-3})$$
This last inequality via the approximation $\sqrt{1+t}= 1 + \frac t2+O(t^2)$ which can be shown via Taylor's theorem. Thus
$$\frac{\sqrt{x^2+14}+x} {\sqrt{x^2-2}+x}=\frac{-14x^{-2}/2 +O(|x|^{-3})}{2x^{-2}/2 + O(|x|^{-3})} \to -7 \qquad (x\to-\infty)$$
quick Desmos graph to verify:
Comment: Lesson learned. When all else fails, use Taylor Series. +1
Comment: Makes sense. Thank you
Comment: @JackozeeHakkiuz whoops. Thanks for spotting that. Have fixed it
Comment: @MatthewPilling certainly beats a 25 step solution of Wolfram (do you still need to pay for those?)
Comment: Shouldn't you have $1+\frac{c}{x^2}$ inside the root in the second step?
Answer: If you let $t={1\over |x|}$ and divide top and bottom by $|x|,$
you get
$$\lim_{t\to 0^+}{\sqrt{1+14t^2}-1\over \sqrt{1-2t^2}-1},$$
to which you can apply l'Hôpital's rule.
Answer: Your statement is correct for the limit as $ \ x \ $ approaches "positive infinity",
$$\lim _{x \ \to \ +\infty \:}\frac{\left(\sqrt{\left(x^2+14\right)}+x\right)}{\left(\sqrt{\left(x^2-2\right)}+x\right)}  \ \ = \ \ 1 \ \ , $$
and the means by which you calculated it is valid in that direction.
A basic issue which arises in the expression for which we are taking limits is that the function $ \ \sqrt{x^2+a} \ $ (with any real $ \ a \ $) has even symmetry on its domain, while $ \ x \ $ has odd symmetry, so the numerator, denominator, and the rational function produced are not symmetric about the $ \ y-$ axis.  Rather than having a single horizontal asymptote, this function has two distinct asymptotes.
We can examine the general function $  \ x \ + \sqrt{x^2+a} \  . $  The asymptotes for $  \ \sqrt{x^2+a} \ $ are given by $ \ y \ = \ |x| \ , $ so as $ \ x  \rightarrow  +\infty \ , $ we expect that $  \ x \ + \ \sqrt{x^2+a}  \ \rightarrow \ 2x \ . $  So a ratio of two such functions has the limit
$$\lim _{x \ \to \ +\infty \:}\frac{\left( \ x \ + \ \sqrt{ x^2+a } \ \right)}{\left( \ x  \ + \ \sqrt{ x^2+b} \ \right)}  \ \ \rightarrow \ \ \frac{2x}{2x} \ \ =  \ \ 1 \ \ , $$
independently of the values of $ \ a \ $ and $ \ b \ , $ as you demonstrated.
For the limit as $ \ x  \rightarrow  -\infty \ , $ however, we can see that $  \ x \ + \ \sqrt{x^2+a}  \ \rightarrow \ x \ + \ |x| \ \rightarrow \ x \ - \ x \ \rightarrow \ 0 \ . $  But it does so in a way that does depend on the sign and value of $ \ a \ , $ since $ \sqrt{x^2+a}  \ $ approaches $ \ -x \ $ "from above" for $ \ a > 0 \ $ and "from below" for $ \ a < 0  \ \ . $  Applying the "conjugate-factor" method, we produce
$$ \lim _{x \ \to \ -\infty \:} \ \frac{( \ x \ + \ \sqrt{x^2+a} \ ) · ( \ x \ - \ \sqrt{x^2+a} \ ) }{ x \ - \ \sqrt{x^2+a} } \ \ = \ \ \lim _{x \ \to \ -\infty \:} \  \ \frac{ x^2 \ - \ (x^2+a)}{ x \ - \ \sqrt{x^2+a} } $$ $$ = \ \ \lim _{x \ \to \ -\infty \:} \  \ \frac{- \ a}{ x \ - \ \sqrt{x^2+a} } \ \ . $$
We can "extract" a factor of $ \ x \ $ in the denominator, but as mentioned more than once among the comments, because we have $ \ x < 0 \ , $ we must work "under the square-root" as $ \ x \ = \ - |x|  \ = \ - \sqrt{x^2} \ : $
$$   \lim _{x \ \to \ -\infty \:} \  \ \frac{- \ a}{ x \ - \ \sqrt{x^2+a} } \ \ = \ \ \lim _{x \ \to \ -\infty \:} \  \ \frac{- \ a}{ x · ( \ 1 \ - \ \left[ \frac{1}{-\sqrt{x^2}} \right] · \sqrt{x^2+a} \ ) } $$ $$ = \ \ \lim _{x \ \to \ -\infty \:} \  \ \frac{- \ a}{ x · ( \ 1 \ + \  \sqrt{\frac{x^2}{x^2}  +  \frac{a}{x^2}} \ ) } \ \ \rightarrow \ \ \frac{- \ a}{ x · ( \ 1 \ + \  \sqrt{1 \ + \ 0} \ ) } \  = \ -\frac{a}{2x} \ \ \rightarrow \ \ 0 \ \ . $$
The "negative-infinity" limit for $  \ x \ + \sqrt{x^2+a} \   $  leaves the value of $ \ a \ $ "exposed", so the corresponding limit for our ratio becomes
$$\lim _{x \ \to \ -\infty \:}\frac{\left( \ x \ + \ \sqrt{ x^2+a } \ \right)}{\left( \ x  \ + \ \sqrt{ x^2+b} \ \right)}  \ \ \rightarrow \ \ \frac{-a}{-b} \ · \ \frac{2x}{2x} \ \ = \ \ \frac{a}{b} \ \ . $$
For the particular function in question then,
$$\lim _{x \ \to \ -\infty \:}\frac{x \ + \  \sqrt{ x^2+14 } }{x \ + \ \sqrt{ x^2-2 } }  \ \ = \ \ \frac{14}{-2} \ \ =  \ -7 \ \ . $$


Apply on click javascript event to a header in JSP instead of using  tag

Question: I currently have a header with a toggle button which will expand on click.
Html :

    <spring:message code="TaxInformation.eSignature" />

JS:
$(document).on('click', '.icon_toggle_open', function (e) {
        stop(e);
        $(this).removeClass("icon_toggle_open")
            .addClass("icon_toggle_close")
            .attr("alt","Show")
            .attr("title","Show")
            .parent().next('.toggle_content').hide();
        $(window).blur();
      });

     $(document).on('click', '.icon_toggle_close', function (e) {
        stop(e);
        $(this).removeClass("icon_toggle_close")
            .addClass("icon_toggle_open")
            .attr("alt","Hide")
            .attr("title","Hide")
            .parent().next('.toggle_content').show();
        $(window).blur();
      });

It is currently working as expected. The user needs to click on the toggle icon to expand the div.
Instead of clicking on the expand button, I want the Expand/collapse to be triggered upon clicking anywhere in the accordion bar. I am new to JSP, can anyone help?
Comment: remove id or class on which the toggle is performing and add it to the anchor tag which is showing in your question or it will better to help you if you share full code
Answer: You want to set the event listener higher in the DOM. Try moving your event listener from .icon_toggle_open to .toggle_header.
$(document).on('click', '.toggle_header', function (e) {
  stop(e);
  var opened = $(this).children('.icon_toggle_open')
  if(opened.length > 0){
    opened
      .removeClass("icon_toggle_open")
      .addClass("icon_toggle_close")
      .attr("alt","Show")
      .attr("title","Show")
      .parent().next('.toggle_content').hide();
  } else {
    $(this)
      .children(".icon_toggle_close")
      .removeClass("icon_toggle_close")
      .addClass("icon_toggle_open")
      .attr("alt","Hide")
      .attr("title","Hide")
      .parent().next('.toggle_content').show();
  }
  $(window).blur();
});

Comment: Didn't work, Ill share a screenshot of what happened along with a part of the console that might help.
https://pasteboard.co/dcOv9x8Rz.png
Comment: Almost there. Expand is working, but not collapsing. Thank you
Comment: Thanks a lot for your help.
Answer: Apply and event listener to the entire h3 instead of the a tag:
document.querySelector('#Tax_information_eSignature').addEventListener('click', e => {
    // Expand your accordion bar by selecting it
});

I don't know how you have set up the 'expansion' feature but I would like to see how you've done your javascript to expand the accordion bar.


Let $G$ be a finite group, $H$ be a subgroup of $G$ with $[G:H]=2$ and for all $h \in H-{1}$, $C_G(h) \leq H$. Prove $G-H$ forms a conjugacy class.

Question: I'm studying for an exam and I am very much stuck on this problem. I wasn't able to find anything similar enough to this problem to help me yet, so I thought I would make a post.

Let $G$ be a finite group and $H$ a subgroup of $G$ with $[G:H]=2$. In addition, suppose that for all $h \in H-\{1\}$ that $C_G(h) \leq H$. Prove that the elements of $G-H$ form a conjugacy class of $G$.

So, I am starting to wonder if I am approaching this the wrong way. I've tried to prove this using double containment, starting both ways to see if one is easier, but I get stuck early on in both ways. I'll show what I have below.
Proof: Let $x \notin H$. We want to show $Cl(x) = G-H$.
$(\subseteq)$ Let $a \in Cl(x)$. Then there exists $g \in G$ such that $gxg^{-1}=a$. For the sake of contradiction, suppose $a \in H$. Then, $gx = ag$. If $g \in H$ then $gx \notin H$ as $[G:H]=2$ implies $G/H = \{H, Hx\}$. Yet, $ag \in H$ which would create a contradiction. Hence, $g \notin H$. [This is where I get stuck in this direction.]
$(\supseteq)$ Let $a \in G-H.$ Then, $a = hx$ for some $h \in H$. [This is where I get stuck here. I know we want to find some $g \in G$ such that $gxg^{-1} = hx$ but I am having trouble finding any such $g$.]
Comment: Have you seen that index 2 subgroups are always normal? That fact should make the proof of $\subseteq$ easy (and I think you are most of the way to reproducing the proof of this fact, anyway)
Comment: [Related.](https://math.stackexchange.com/q/2175828/104041)
Comment: For $\supseteq$, try looking at the set of all $h x h^{-1}$ as $h$ ranges over $H$. for distinct $h_1,h_2$, can these be equal?
Answer: Let $x\not\in H$.  Following @jacob, if $h_1\ne h_2\in H$, then $h_1xh_1^{-1}=h_2xh_2^{-1}\implies xh_2^{-1}h_1x^{-1}=h_2^{-1}h_1\implies x\in C_G(h_2^{-1}h_1)\subset H$.
Thus we have an injection from $H$ to the set of conjugates of $x$ by elements of $h$.
So $|\rm{cl}(x)|=|H|$.
Answer: Another way to look at it: consider the action of $H$ on $G$ by conjugation. For $x \in G-H$, $stab(x)$ is trivial by the given condition on centralizers. By orbit-stabilizer, $orbit(x)$ has size $|H|$. But $orbit(x)$ is just $cl(x)$.


Prove $T$ is a linear transformation and find $\ker T$ and $\mathrm{im} T$

Question: Let $P_n$ be the vector space of all real polynomials of degree less than or equal to n.
Let $T : P_3 \rightarrow P_3 $ be defined by $T(p(x)) = xp'(x) - 3p'(x)$, where $p'(x)$ represents the formal derivative of $p(x)$.
I am not sure if I am doing correctly please correct me if I did anything wrong.
Let $T(p_1(x)) = xp_1'(x)-3p_1'(x)$ and $T(p_2(x)) = xp_2'(x)-3p_2'(x)$
since $ xp_1'(x)-3p_1'(x) + xp_2'(x)-3p_2'(x) = (xp_1'(x) + xp_2'(x)) + (-3p_1'(x) -3p_2'(x)) = x(p_1'(x) +p_2'(x)) -3(p_1'(x) + p_2'(x))$
so that $T(p_1(x) +p_2(x)) = T(p_1(x)) + T(p_2(x)).$
and $T(λp(x)) =  λxp'(x) - λ3p'(x) =λ(xp'(x) - 3p'(x))$
Now I can say T is a linear transformaion.
Any hint on how to find kerT and imT?
Comment: What's $P_3$ again?
Comment: No, that's definitely wrong. $x_1$ doesn't mean anything in the vector space of polynomials. You want $T(p_1(x))$ and $T(q_1(x))$.
Comment: @SanathDevalapurkar Previous question was letting $P_n$ be the vector space of all real polynomials of degree less than or equal to n.
Comment: @user164945 Mention the context, please. Nobody will go checking through your question list in order to decipher your question in order to help you.
Comment: For the kernel, what polynomials of degree $\le 3$ have the property that $(x-3)p'(x)$ is the zero polynomial? For the image, certainly all the functions in the image are divisible by $x-3$. Is every polynomial of degree $\le 3$ which is divisible by $x-3$ in the image?
Comment: @ThomasAndrews I am right this time?
Comment: You haven't clearly show $T(p_1+p_2)=T(p_1)+T(p_2)$. You need that $(p_1+p_2)'=p_1'+p_2'$.
Comment: @ThomasAndrews How about this time?
Comment: @AndréNicolas so for the kernel, is it when x=3 i.e. sp(3,0,0). I am still not really certain about the image part.
Comment: No, we need $p'(x)=0$, so $p(x)$ a constant polynomial.
Comment: @AndréNicolas Why do we need to show that? If I remember correctly, You only need to prove addition and multiplication to show it is linear transformation
Comment: The comment is not about the linear transformation part, it is about identifying the kernel and image.
Comment: @AndréNicolas Sorry, That was my bad.
Answer: Actually, $T$ is composited by two linear transformation.
$T_1:P_2\rightarrow P_3$ which satisfies
$$T_1(p(x))=(x-3)p(x)$$
$T_2:P_3\rightarrow P_2$ which satisfies
$$T_2(p(x))=p'(x)$$
We have $T=T_1\circ T_2$.

Because $T_1$ is injection and $T_2$ is surjection, then we get
$$\text{Ker}(T)=\{p(x)\in P_3:p'(x)=0\}=\mathbb R$$
and
$$\text{Im}(T)=\{(x-3)p(x)\in P_3:p(x)\in P_2\}=\{p(x)\in P_3:x-3|p(x)\}$$
Comment: Are you saying that in order to prove T is linear transformation, I need to prove both $T_1$ and $T_2$ to be linear transformation so that T is linear transformation?
Comment: Not necessarily. Your direct proof is very efficient.
Comment: So the way you were doing is more about how to solve $Ker(T)$ and $Im(T)$ right?
Comment: Yes, I think the answer is more relative to the properties of two maps I mention.


Confidence intervals with penalized likelihood

Question: I am trying to perform parameter estimation using something like a maximum likelihood ratio method, however I need to add a penalty term to constrain nuisance parameters which describe certain systematic uncertainties in the measurement process. So I have been digging around in the literature to try and better understand what is know about penalized likelihood estimation, but I cannot find anything I can understand regarding the construction of confidence intervals for my parameters of interest.
I get that a penalty term in the likelihood is quite similar to a Bayesian prior, and indeed if I wanted to then I could easily analyse my situation in a Bayesian way and use credible intervals instead of confidence intervals, however for this instance I want my intervals to have correct frequentist coverage properties, at least asymptotically (as in the usual profile likelihood case where I could rely on Wilks' theorem).
So, are there theorems similar to Wilks' that work with penalized likelihoods? Or with particular kinds of penalty terms? In the literature it looks to me like people mostly do numerical studies of coverage rather than rely on theorems, does this mean that there are no known "general purpose" theorems for this?
Edit: Alternatively, I suppose that I would be happy to be able to treat the penalty term in a fully Bayesian way, but nevertheless, in the end, still construct frequentist confidence intervals based on whatever estimator resulted, say the maximum of the marginal likelihood (i.e. with the nuisance parameter marginalised out). Looking around I do find some literature discussing the frequency properties of Bayesian point estimates, so I guess that it is possible that somewhere in this literature exists the sort of construction that I want?
Answer: I don't think it's possible to provide meaningful confidence intervals in that case in a natural way.
Call $\theta$ the parameter and $\hat\theta$ the penalized likelihood estimator. Confidence intervals at 95% say that $P(|\theta-\hat\theta|\leq d|\theta)\geq0.95$ for all $\theta$. If you reframe the Bayesian idea in a back and white fashion: the reason why you need penalization is that not all $\theta$ are expected to really be "possible": you focus on the ones that you consider to be "possible".
Outside of the "possible" zone, $\hat\theta$ is a very poor estimate. If the real $\theta$ is far from the possible zone $\hat\theta$ can be far from the real $\theta$ with high probability. For such $\theta$, $P(|\theta-\hat\theta|\leq d|\theta)\geq0.95$ is only true if $d$ is big. Since $d$ is required to not depend on $\theta$, you would just use the worst case scenario $d$ yielding useless confidence intervals. Actually, I think $d=+\infty$ if you consider $\theta$ going to infinity.
A way to fall back on a frequentist analysis in this case is to define a "possible" region $\Theta$ inspired from the penalization. One possibility is a region containing 99% of the weight of the prior. With $L^2$ regularized MLE for example, if this region is a ball whose radius is exactly the norm of the penalized estimate, then the frequentist MLE raw estimate is the same as the penalized one and lies on the border (sphere). With this method, you can say: if $\theta\in \Theta$ then $P(|\theta-\hat\theta|\leq d|\theta)\geq0.95$ with a meaningful $d$. It is a confidence interval with condition $\theta\in \Theta$.
Comment: Hmm, I see what you are saying, but my scenario is slightly different. The parameter for which I want an interval (say x) is not the same as the one I wish to penalise (say y). Usually I'd just construct confidence intervals for x from the profile likelihood, i.e. maximised over y, however here I don't have any constraint on y except for a Bayesian type penalty (i.e. there is no explicit control measurement or such a thing). So, sure, some values of y are improbable and I don't want the maximisation to consider them. I did think of what you suggest, i.e. just limiting the support of y...
Comment: ...and then letting the maximisation just stop at the boundary, however since this is possible it makes me expect that it should also be possible with a less hard "boundary". I don't mind if the confidence interval coverage for x is ruined when the true y is far from where the prior says it is supposed to be, but if the true y is not too improbable under the prior I'd like to be able to get reasonable confidence intervals for x.
Comment: Ok I see. $y$ could be seen as a hidden variable rather than a parameter. Then $x$ would be the only parameter and a full frequentist approach seems possible.
Comment: Yeah. I could "fake" it and pretend that my prior represented an actual random process generating y, and indeed I have seen many people (particularly physicists) treat systematic uncertainties in this way, however I cannot shake the feeling that it is just not correct. Generally I'd say just do the Bayesian thing and then I can feel philosophically satisfied, however I can't help feeling that there must be some "correct" way to treat this situation in a fully frequentist way.
Comment: Humm... yeah. Formally the true frequentist way deals with $P(...|x,y)$ while the hidden variable does $P(...|x)$. Beyond this I feel that if you allow $y$ to be anything, even the confidence interval of $x$ could be affected badly...
Comment: Another thing I see physicists do is a kind of semi-Bayesian approach, i.e. they will compute a marginal likelihood where y has been integrated out, and then they will just compute confidence intervals "as if" this was a standard likelihood. Of course then it is unclear what exactly the obtained intervals mean; they are presented as confidence intervals but really this is just hoping for the best, though sometimes coverage is studied numerically. I have no problem with the general idea here, but I am unsatisfied with the lack of theoretical guarantees regarding the intervals obtained.
Comment: I never solved this, but did recently see this: https://cran.r-project.org/web/packages/penalized/vignettes/penalized.pdf, linked from https://www.reddit.com/r/statistics/comments/1vg8k0/standard_errors_in_glmnet/. They talk about not wanting to implement confidence interval calculations in their package due to it only being possibly to include contributions from variance, but not bias, and bias is probably the more important factor in penalised regression. Not sure if this is a general problem or just a restriction of their bootstrap estimation method.
Comment: I also have since come to appreciate better that Wilks' theorem and maximum-likelihood-based confidence intervals are kind of magical. Like it is actually kind of weird to me now that it is *ever* possible to construct intervals that are not sensitive to the true value of hidden/nuisance parameters. So it is less surprising to me now that it is not more generally possible to compute intervals with this property. You can simulate it, but the results will generally be different depending on what the true/assumed values of the hidden parameters were, which is rather a big problem.
Comment: The whole thing is kind of a big +1 in the column for Bayesian superiority tbh ;).


Keep failing to select radioButton on Currency SELENIUM JAVA

Question: My code seems something wrong as sometime it able to select the currency on radiobutton and sometime its not working. Any advise to improve the code by adding timer or something ? Thanks you
HTML :
id: enumTable_data

CODE :
private WebElement getRowForCurrency (String currency)  {
        AbstractPage page = new AbstractPage();
        String[] frame = {"i2ui_shell_content","rcp_content"};
        page.switchToFrame(frame);
        By cell = page.waitUntilPresent(By.xpath("//table[@id='enumTable_data']//nobr[text()[contains(.,'" + currency + "')]]"));
        WebElement currentElement = page.browser().findElement(cell);
        while(!currentElement.getAttribute("tagName").equals("TR")) {
            currentElement = currentElement.findElement(By.xpath(".."));
        }
        return currentElement;
    }

    public void selectCurrency (String currency)    {
        // find the text and get the parent, that is the row that contains the radiolist
        JLog.write("Select Currency: " + currency);
        WebElement row = getRowForCurrency(currency);
        if (row != null)    {
            WebElement radioButton = row.findElement(By.cssSelector("input[type='radio']"));
            if (null == radioButton)    {
                JLog.error("Found Document Row, but unable to find document radio button: " + currency, TakeScreenshot.True);
                return;
            }
            radioButton.click();
        } else  {
            JLog.error("Unable to find currency: " + currency, TakeScreenshot.True);
        }
    }

Comment: Can you post the html code for the element or link to the webpage
Comment: Which error/Exception you get when it does not select country?
Comment: the error was saying : Fail to find the element then it die there.
Answer: 1. you need to wait for the element to be present in the screen

 public static WebElement findElement(WebDriver driver, By selector, long timeOutInSeconds) {
    WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
    wait.until(ExpectedConditions.presenceOfElementLocated(selector));

    return findElement(driver, selector);
  }

  public static WebElement findElement(WebDriver driver, By selector, long timeOutInSeconds, String timeOutMessage) {
    try {
      WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
      wait.until(ExpectedConditions.presenceOfElementLocated(selector));

      return findElement(driver, selector);
    } catch (TimeoutException e) {
      throw new IllegalStateException(timeOutMessage);
    }
  }

  public static WebElement findElementSafe(WebDriver driver, By selector, long timeOutInSeconds) {
    try {
      return findElement(driver, selector, timeOutInSeconds);
    } catch (TimeoutException e) {
      return null;
    }
  }

  public static WebElement findElementSafe(SearchContext context, By selector) {
    try {
      return context.findElement(selector);
    } catch (Exception e) {
      return null;
    }
  }


Knockout binding for radio button not working initially

Question: I currently have the following HTML...
<input type="radio" style="height: 12px; width: 20px;" name="physTabPregRadio" value="true" data-bind="checked: pregnant.radioBool" />Y
<input type="radio" style="height: 12px; width: 20px;" name="physTabPregRadio" value="false" data-bind="checked: pregnant.radioBool" />N

...and the radioBool function is an extension of ko, as defined here...
ko.observable.radioBool = function () {
    var observable = ko.observable();
    observable.radioBool = ko.computed({
        read: function () {
            if (observable() === true) return 'true';
            else if (observable() === false) return 'false';
            else return 'unknown';
        },
        write: function (v) {
            if (v.toLowerCase() === 'true') observable(true);
            else if (v.toLowerCase() === 'false') observable(false);
            else observable(undefined);
        }
    });
    return observable;
};

...and is initialized in the model like this...
self.pregnant = ko.observable.radioBool();
self.pregnant(false);

Upon loading the page, neither radio button is checked, but the span's text is "false". Is there any potential reasons why the Radio Button would not be checked, even though its value is equal to one of the radio button's values?
Comment: What are you trying to accomplish with this approach?
Comment: Could you create a working example of this? [I failed to reproduce it.](https://jsfiddle.net/hp8jter2/)
Comment: @MikeC I think you'd need to use the radioBool. Updated Fiddle: https://jsfiddle.net/hp8jter2/1/
Comment: @MikeC: pregnant: ko.observable.radioBool()
Answer: You need to initialize var observable = ko.observable(false); (with false explicitly), or else it'll have undefined as its value at first and consequently the read funciton will fall through to the final else.
See this example:

var self = {};

ko.observable.radioBool = function () {
    var observable = ko.observable(false);
    observable.radioBool = ko.computed({
        read: function () {
            if (observable() === true) return 'true';
            else if (observable() === false) return 'false';
            else return 'unknown';
        },
        write: function (v) {
            if (v.toLowerCase() === 'true') observable(true);
            else if (v.toLowerCase() === 'false') observable(false);
            else observable(undefined);
        }
    });
    return observable;
};

self.pregnant = ko.observable.radioBool();

ko.applyBindings(self);

<input type="radio" name="physTabPregRadio" value="true" data-bind="checked: pregnant.radioBool" />Y
<input type="radio" name="physTabPregRadio" value="false" data-bind="checked: pregnant.radioBool" />N

Comment: I probably should have specified that I set self.pregnant(false) later on. Note, I did say that the span's text value WAS returning the correct string value.
Comment: *Then your question doesn't contain (enough information to create) a repro*, I'm afraid. Try using the Stack Snippet feature you can see in my answer (it's on the editor's toolbar) to add a runnable repro to your question.
Answer: I ran into a similar issue. Solved it by initializing the observable with a string value instead of a boolean or number.
self.pregnant('false');


Moving back to parent frame in Selenium

Question: For moving back to parent frame in Selenium,
driver.switchTo().parentFrame(); is used. In my example website, I achieved same functionality using driver.switchTo().defaultContent(); also.
Is there any functional difference between these two:
- driver.switchTo().parentFrame();
- driver.switchTo().defaultContent();

While referring to frames in a HTML document, are "Parent Frame" and "Default Content" different? Please explain.
Comment: Hello, I guess it does the same most of the time. But if you have 2 embedded frames or more, you may want to switch back to the first parent frame _or_ to the main frame (defaultContent).
Answer: It does have difference to an extent.
Suppose you have a page having frame 'three' inside a frame 'two' inside another frame 'one', considering that you are on the frame 'three' which is inner most...
driver.switchTo().parentFrame(); - This will shift focus back to frame 'two'.
driver.switchTo().defaultContent(); - This will shift focus back to main (default) content in which frame 'one' lies.
I hope this was helpful. Thanks !
Answer: If you only have two frames on a page, there is no functional difference. However, the app I'm working on has as many as 5 nested frames on a page.
For example, I need to work with two elements that are at the third frame, step inside another frame, then step back to work with another element in frame 3. I have two choices to accomplish this.
1: I can step all the way out and then back in
//click element 1
driver.SwitchTo().DefaultContent();
driver.SwitchTo().Frame(driver.FindElement(By.Id("Frame1")));
driver.SwitchTo().Frame(driver.FindElement(By.Id("Frame2")));
driver.FindElement(By.Id("element1")).Click();
//click element 2
driver.SwitchTo().DefaultContent();
driver.SwitchTo().Frame(driver.FindElement(By.Id("Frame1")));
driver.SwitchTo().Frame(driver.FindElement(By.Id("Frame3")));
driver.FindElement(By.Id("element2")).Click();

The other option is to switch to the parent frame.
//click element 1
driver.SwitchTo().DefaultContent();
driver.SwitchTo().Frame(driver.FindElement(By.Id("Frame1")));
driver.SwitchTo().Frame(driver.FindElement(By.Id("Frame2")));
driver.FindElement(By.Id("element1")).Click();
//click element 2
driver.SwitchTo().ParentFrame();
driver.SwitchTo().Frame(driver.FindElement(By.Id("Frame3")));
driver.FindElement(By.Id("element2")).Click();

Basically, it saves the effort of writing code to switch all the way back out then back into the frame if you only need to move back one level.

Moving back to parent frame in Selenium


Criar inputs para imagens dinâmicamente e passar para Servlet sem redirecionar a página?

Question: Gostaria de criar um botão que faça surgir um input para envio de imagens.
Esse botão pode ser usado várias vezes. Quando o(a) usuário(a) clicar no botão de submit, essas imagens devem ser enviadas ao servidor sem recarregar a página.
Eu quero que o usuário clique em adicionar campo, então apareceria um input HTML para imagens. Quando ele colocasse todas as imagens, e o botão de submit enviaria essas imagens para a servlet, atualizando as informaçoes na tela, sem redirecionar a página.
Tentei usar
<jsp:setProperty property="currentImages" name="message" value="${paramValues.campo}" />

e o action do submit voltando pra página, mas esse valor sempre fica salvo. Vi pela internet que dá pra fazer com AJAX, mas até agora não consegui pegar esse vetor e passar para servlet.
Como poderia fazer isso?
Answer: Implementação manual
Você pode adicionar vários botões de upload na página adicionando elementos em uma div container. Exemplo:
$('#container').append('<input type="file" />');

Depois na hora de enviar você coloca tudo num objeto do tipo FormData. Exemplo:
var formData = new FormData();
formData.append('imagem', file, file.name);

Finalmente envia tudo via AJAX usando XMLHttpRequest. Exemplo:
var xhr = new XMLHttpRequest();
...
xhr.send(formData);

Veja um exemplo completo:

$('#adicionar').on('click', function() {
  $('#container').append('<input type="file" />');
});

$('#enviar').on('click', function() {
  var formData = new FormData();
  $('#container input').each(function() {
    formData.append('imagens[]', this, this.name);
  });
  var xhr = new XMLHttpRequest();
  xhr.open('POST', '/uploadServlet', true);
  xhr.onload = function() {
    if (xhr.status === 200) {
      alert('Sucesso!');
    } else {
      alert('Erro!');
    }
  };
  xhr.send(formData);
});
input {
  display: block;
}

<button id="adicionar">+</button> <button id="enviar">enviar</button>

Usando um plugin
O código acima é bem simples e funciona nos navegadores mais modernos.
Porém, se você quer evitar de entrar em muitos detalhes de implementação que isso poderia acarretar num sistema de verdade que vão desde a formatação até o suporte a navegadores mais antigos, sugiro usar um plugin para isto.
Um plugin que já usei com sucesso no passado foi o Blueimp jQuery File Upload.
Você pode encontrar vários exemplos na documentação, embora na prática isso possa até atrapalhar um pouco porque tem tantas formas de usar que você acaba gastando um bom tempo aprendendo sobre o plugin.
No entanto, um uso bem simples pode ser algo como isto:
$('#fileupload').fileupload({
    dataType: 'json',
    add: function (e, data) {
        data.context = $('<button/>').text('Upload')
            .appendTo(document.body)
            .click(function () {
                data.context = $('
').text('Uploading...').replaceAll($(this));
                data.submit();
            });
    },
    done: function (e, data) {
        data.context.text('Upload finished.');
    }
});

Servlet
Para receber o upload no seu servlet, sugiro usar a biblioteca Apache Commmons FileUpload.
Entenda que, do ponto de vista do servidor, uploads são complexos de gerenciar. A documentação da biblioteca dá inúmeros exemplos de controle que você pode ter.
Um caso mais simples seria assim:
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(request);
for (FileItem item : itens) {
    if (!item.isFormField()) {
        String fileName = item.getName();
        String contentType = item.getContentType();
        File uploadedFile = new File(...);
        item.write(uploadedFile);
    } else {
        //campos normais
        String campo = item.getFieldName();
        String valor = item.getString();
    }
}

Note que você não pode acessar os demais campos usando request.getParameter() e métodos correlatos, pois o corpo de uma requisição onde ocorrem uploads é diferentes e o servidor não vai decodificar os campos da mesma forma que numa requisição normal.
Portanto, como no exemplo acima, você deve verificar os demais campos da requisição na mesma lista de itens onde ficam os arquivos. Quando for um campo normal, item.isFormField() vai ser verdadeiro.
Para uma descrição mais completa, veja esta resposta do SO (em Inglês).
Comment: Entendi. Funcionou passando os valores para a servlet via submit. Mas ainda nao conseguir passar os valores com o script que voce passou. Quando você diz: "O código que eu postei pega todos os inputs dentro do container", seria:     ? @utluiz
Comment: @ThiagoR. Sim, isso. O script que eu fiz pega qualquer tag `` (independente do conteúdo) que estiver dentro de um elemento com `id="conteiner"`, neste caso o `div`. O que não está funcionando? Se você olhar a Ferramenta do Desenvolvedor do seu navegador, você consegue ver a requisição AJAX sendo enviada na aba "Network"/"Rede"? Eu testei esse código no meu Chrome e a requisição é enviada. Se a requisição for feita mas o erro ocorre no servidor, pode ser que esteja faltando algum cabeçalho no AJAX. Você pode então comparar os dados da requisição com Submit da requisição com AJAX.
Comment: Se continuar enfrentando problemas, sugiro criar outra pergunta e postar o código que você tem e não funciona. Aqui nos comentários não é um lugar legal para entrar em discussões prolongadas.
Comment: O problema é que os valores sempre estão nulos


How would an "inside the park home run" affect BABIP?

Question: "Normal" home runs are those that leave the park, that fielders don't have a chance of catching. As a result, they are not counted in the "balls in play" part of BABIP.
On the other hand, an "inside the park home run" is a hit that remained in the field, was presumably "fieldable," and just happened to go for four bases. Would it be excluded from the "balls in play" part of the BABIP calculation like the other kind of home run?
Answer: In the park Home Runs are not tracked separately from HR and would not be included in BABIP.
Neither Fangraphs, Baseball-Reference nor MLB have in-the-park-homers tracked and thus do not include it in their BABIP calculations.
As there are only a few each year, and the number is very small in relation to the total number of hits, at-bats and home runs, these are not really a factor in making BABIP unreliable.


Understanding the definition of exterior derivative

Question: What shown below is a reference form Analysis on Manifolds by James Munkres

So I saw that some authors define the differential operetor $d$ as a function from $\bigcup_{k=0}^\infty\mathcal{L}^k\big(\mathcal T_x(\Bbb R^n)\big)$ to $\bigcup_{k=1}^\infty\mathcal{L}^k\big(\mathcal T_x(\Bbb R^n)\big)$ such that
$$
d\omega\in\Omega^{k+1}(A)
$$
for any $\omega\in\Omega^k(A)$ but anyway to give any definition I think that it is importat to prove  that if $h$ and $k$ are two different naturals then
$$
\Omega^k(A)\cap\Omega^h(A)=\emptyset
$$
because otherwise we do not how calculate the quantity $d\omega$ if $\omega$ is a $h$-form and $k$-form. Well it is not hard to prove that if $h,k\ge 1$ and $h\neq k$ then the above identity holds. Indeed if $x$ and $y$ are two point of $\Bbb R^n$ then
$$
\mathcal{L}^k\big(\mathcal T_x(\Bbb R^n)\big)\cap\mathcal{L}^h\big(\mathcal T_y(\Bbb R^n)\big)=\emptyset
$$
when they are different and when they are not. However unfortunately I did not be able to prove that
$$
\Omega^0(A)\cap\Omega^k(A)=\emptyset
$$
for any $k>0$ so I ask to prove it. In particualr I know that if there exist a scalar function $f$ in $\Omega^0(A)\cap\Omega^k(A)$ for some $k>0$ then
$$
f(x)\in\Bbb R\cap\mathcal{L}^k\big(\mathcal T_x(\Bbb R^n)\big)
$$
for any $x\in A$ and thus the statement follows proving that
$$
\Bbb R\cap\mathcal{L}^k\big(\mathcal T_x(\Bbb R^n)\big)=\emptyset
$$
but unfortunately I did not to prove it. Anyway if we define a $0$-tensor as an element of the set $\Bbb R^{\{0\}}$ where $0$ is the null vector of $\mathcal T_x(\Bbb R^n)$ then the above identity becames
$$
\Bbb R^{\{0\}}\cap\mathcal{L}^k\big(\mathcal T_x(\Bbb R^n)\big)=\emptyset
$$
and it trivially holds because $\mathcal{L}^k\big(\mathcal T_x(\Bbb R^n)\big)\subseteq\Bbb R^{\big(\mathcal T_x(\Bbb R^n)\big)^k}$ and
$$
\Bbb R^{\{0\}}\cap \Bbb R^{\big(\mathcal T_x(\Bbb R^n)\big)^k}=\emptyset
$$
so that the above identity follows. So could someone help me, please?
Comment: Okay, so I will accept the answer of @DanielSchleper. Thanks to much for for opinion!!! See you soon.
Comment: I cannot understand your pedantic confusion at all. How can a scalar be a $k$-multilinear map on a vector space (or vice-versa)? You're writing zillions of symbols, but just think about what things actually mean! Give me an injection of $\Bbb R$ into $\mathcal L^k(\Bbb R^n)$. You cannot. ... And what in the world is an elementary number theory tag doing here?
Comment: @TedShifrin Well, I understand your point of view: substantially (if I really well underastand) the identity $$\Bbb R\cap\mathcal L^k\big(\mathcal T_x(\Bbb R^n)\big)=\emptyset$$ is straightforward by the definition of tensors space and intially I thought this too but when for zeal I try to justify it formally I was strangerly not able and thus I take back what I studeid a just time ago in set theory to prove it.
Comment: So I know that the set $\mathcal L^k\big(\mathcal T_x(\Bbb R^n)\big)$ is coinainted in the set $\Bbb R^{\big(\mathcal T_x(\Bbb R^n)\big)^k}$ of all function from $\big(\mathcal T_x(\Bbb R^n)\big)^k\subseteq\big(\Bbb R^{2n}\big)^k$ to $\Bbb R$ and since $\Bbb R^{\big(\mathcal T_x(\Bbb R^n)\big)^k}\subseteq\big(\mathcal T_x(\Bbb R^n)\big)^k\times\Bbb R\subseteq\big(\Bbb R^{2n}\big)^k\times\Bbb R$ I tried to prove that $\Bbb R\cap\big(\Bbb R^{2n}\big)^k\times\Bbb R=\emptyset$ but I was not able to do it, that's all.
Comment: Anyway then I thought that this is not exetial because Mukres first define the exterior derivative for zero fomr and then for positive forms so since I proved that the postive forms are dsjoint it does not matter if (obviously impossible) a zero fomr is a positive form too. Forgive my confusion.
Comment: I think it's already been commented, but you want to think of $d$ as a collection of $d_k$, one for each natural number. That's the most constructive way to do it.
Answer: In practice, we do not actually care whether $\Omega^k(\mathbb{R}^n)$ and $\Omega^h(\mathbb{R}^n)$ are literally disjoint sets or not when $k \ne h$.  Instead, in a completely formal development, we would make it explicit that we are talking about a family of maps $d^{(k)} : \Omega^k(\mathbb{R}^n) \to \Omega^{k+1}(\mathbb{R}^n)$.  However, in most situations it will be clear from context which map $d^{(k)}$ we must be thinking of applying so that putting in the explicit index would be unnecessary noise.
For a somewhat more complex example of what I mean by that last sentence, we will also have a wedge product $\wedge$ which formally is actually a family of maps ${\wedge}^{(k,\ell)} : \Omega^k(\mathbb{R}^n) \times \Omega^\ell(\mathbb{R}^n) \to \Omega^{k+\ell}(\mathbb{R}^n)$.  Then one result you can state is: for $\omega \in \Omega^k(\mathbb{R}^n)$ and $\tau \in \Omega^\ell(\mathbb{R}^n)$, we have $$d(\omega \wedge \tau) = d\omega \wedge \tau + (-1)^k \omega \wedge d\tau.$$  Now, from this context, it is straightforward to go through and assign what indices would have to be filled in for a more formal system to be able to accept the statement:
$$d^{(k+\ell)}(\omega \wedge^{(k,\ell)} \tau) = (d^{(k)} \omega) \wedge^{(k+1,\ell)} \tau +^{(k+\ell+1)} [(-1)^k \cdot^{(k)} \omega] \wedge^{(k,\ell+1)} (d^{(\ell)} \tau).$$
(Note that here, I have also made it explicit that vector addition and scalar multiplication of differential forms are also formally indexed families, i.e. we will never try to add $\omega \in \Omega^k(\mathbb{R}^n)$ to $\tau \in \Omega^h(\mathbb{R}^n)$ unless $k = h$.)

As a side note, this point of view, that we don't really care in practice whether different sets might actually overlap or not, is part of the idea behind "type theory" as a language for mathematics.  In most type theories, the question of whether elements of unrelated types are equal becomes something that it is not even meaningful to ask, in the sense that the corresponding formulas would not qualify as "well-formed formulas".  And I'm personally convinced that outside of axiomatic set theory, a vast majority of mathematics is actually done and thought about in some version of type theory rather than in ZFC.  Certainly, ZFC is useful from a theoretical point of view because of its restricted language and few axioms, and type theory is usually not too difficult to build "on top of" ZFC.  A useful analogy to a computer science situation is to think of ZFC as a form of "machine code", and think of type theory as a higher-level language which can be translated to machine code.
Comment: Hmm, I suppose technically with $\mathcal{L}^k(\mathcal{T}_x(\mathbb{R}^n))$ being a function with real numbers embedded in the domain, if that function were also a real number then the real number would have to occur somewhere within one of the ordered pairs of that function, within the domain section of the pair; and then comparing ranks would give a contradiction.  But again, that's the sort of noise that we really shouldn't have to care about in the first place.
Comment: (And even in ZFC, the question of overlap is easy to make irrelevant if you move to using the disjoint union in defining $d : \bigsqcup_k \Omega^k(\mathbb{R}^n) \to \bigsqcup_k \Omega^k(\mathbb{R}^n)$ instead of using the literal union.)
Comment: I inted your point of view. Anyway if it would be $$\Bbb R\cap\mathcal L^k\big(\mathcal T_x(\Bbb R^n)\big)\neq\emptyset$$ in **ZFC** it seems to me it would be **very** stranger so coud it be the opposite? What can you say about?
Comment: So why the last identity holds? Could you say something  about?
Comment: Well, this could be a solution. Anyway your first comment have hinted what to follow.
Comment: So we observe that $$
\mathcal T_x(\Bbb R^n)\subseteq\Bbb R^{2n}\Rightarrow\big(\mathcal T_x(\Bbb R^n)\big)^k\subseteq\big(\Bbb R^{2n}\big)^k\Rightarrow\big(\mathcal T_x(\Bbb R^n)\big)^k\times\Bbb R\subseteq\big(\Bbb R^{2n}\big)^k\times\Bbb R
$$
so that $$
\mathcal L^k\big(\mathcal T_x(\Bbb R^n)\big)\subseteq\Bbb R^{\big(\mathcal T_x(\Bbb R^n)\big)^k}\subseteq(\mathcal T_x(\Bbb R^n)\big)^k\times\Bbb R\subseteq\big(\Bbb R^{2n}\big)^k\times\Bbb R
$$ and thus if we prove that $$
\Bbb R\cap\Big(\big(\Bbb R^{2n}\big)^k\times\Bbb R\Big)=\emptyset
$$ then the statement follows.
Comment: So why the last identity holds? Could you say something about?


Nonparametric changepoint detection for a point process

Question: I have a bunch of point processes that are generated by some unknown model. There is a marked pause that seems to begin and end at the same time in each process. I would like to measure this pause.
I have fruitlessly tried fitting the waiting times from the processes to standard distributions. The point processes represent the spiking activity of a neuron which is probably generated by a very complicated, currently unknown mechanism. Is there a largely nonparametric method for detecting changepoints for this data?
My original method was to use something like edge detection, though I'd like a more statistical method. Any help is appreciated and please let me know if this question is unclear or if anyone would like more detail.
Answer: Although the approach is parametric, try looking at Bayesian Changepoint Detection, especially papers by Adams, R. P. & MacKay (see https://arxiv.org/abs/0710.3742), and Fearnhead, P. & Liu (see http://onlinelibrary.wiley.com/doi/10.1111/j.1467-9868.2007.00601.x/abstract). For point processes in particular, have a look at: http://mlg.eng.cam.ac.uk/pub/pdf/SaaTurRas10.pdf.
The approach is that you partition your data into disjoint segments (that are ordered in time). According to the product partition model (See Barry and Hartigan,1992) each segment is independently modelled by a given probability distribution (i.e. model). As you are going to see in these papers you maintain a run-length distribution (distribution of possible segment lengths). Conditioning on that distribution you can try to model the data generating process by assigning a model/distribution to your data (say the multivariate normal) and a prior to the parameters of that model. As you get more and more data, you update your prior beliefs into posterior ones and predict whether a CP has occurred.
Hope that will get you going...


My first partial differential equation attempt

Question: have I solved this correctly? My textbook is asking for the relation between $ \alpha $ and $ \beta $:

$$ \frac{\partial{u}}{\partial{t}}=\frac{\partial^2{u}}{\partial{x^2}} $$ Textbook's proposed solution:
  $$ u\left(x,t\right)=\sin\left(\alpha{x}\right)\cdot{e}^{-\beta{t}} $$
  My work:
  $$ \frac{\partial}{\partial{t}}\left(\sin\left(\alpha{x}\right)\cdot{e}^{-\beta{t}}\right)=-\beta\cdot{\sin}\left(\alpha{x}\right)\cdot{e}^{-\beta{t}} $$
  $$ \frac{\partial^2{u}}{\partial{x^2}}=\frac{\partial^2}{\partial{x^2}}\left(\sin\left(\alpha{x}\right)\cdot{e}^{-\beta{t}}\right)=\frac{\partial}{\partial{x}}\left(\alpha\cdot{\cos}\left(\alpha{x}\right)\cdot{e}^{-\beta{t}}\right)=-\alpha^2\cdot{\sin}\left(\alpha{x}\right)\cdot{e}^{-\beta{t}} $$
  $$ \therefore-\beta\cdot{\sin}\left(\alpha{x}\right)\cdot{e}^{-\beta{t}}=-\alpha^2\cdot{\sin}\left(\alpha{x}\right)\cdot{e}^{-\beta{t}} $$
  $$ \implies\boxed{\beta=\alpha^2} $$

My textbook states that it's some kind of a heat equation relating the distribution of heat at a specific time t. I've looked at the Wikipedia page on heat equations and I find it fascinating. I've spent every spare moment this summer in-between semesters at RIT trying to get a better grasp on the calc. II content and I couldn't help but take a look at the chapters I'm bound to study in multivariable calc. this fall.
Thank you for your time,
Comment: Do you mean to say you want to solve $\frac{\partial f(x,t)}{\partial t} = \frac{\partial^2 f(x,t)}{\partial x^2}$? The notation for taking a derivative of $f = \sin(\alpha x) \cdot e^{- \beta t}$ with respect to $x$ would be $\frac{\partial f}{\partial x} = \frac{\partial}{\partial x} \left( \sin(\alpha x) \cdot e^{- \beta t} \right)$ as opposed to repeating the $f$ in the second statement as you do
Comment: I have edited your question to remove some of the confusion you have placed in the text. To answer your question you have found the relationship between $\alpha$ and $\beta$ correctly.
Comment: Yes, that's exactly right, I shouldn't have included the $ f $ in the second one, so it should read $ \frac{\partial{f}}{\partial{x}}=\frac{\partial}{\partial{x}}\left({sin}\left(\alpha{x}\right){e}^{-\beta{t}} \right) $
Comment: Is this solution unique? What happens if I tell you that $u(x,t)= A x + B$ is also a solution? ($A$ and $B$ are constants).
Answer: As you've correctly figured out,
$u\left(x,t\right)=\sin\left(\alpha{x}\right)\cdot{e}^{-\beta{t}}$
satisfies the heat equation,
$\partial u/\partial t = \partial^2 u / \partial x^2$,
provided that $\beta=\alpha^2$.  As pointed out in the comments, this solution is far from unique.  Let's try to provide a little more context.
Often, the heat equation is accompanied by one or more boundary conditions.  For example, we might specify that $u(0,t) = u(1,t) = 0$.  From a physical perspective, this means that $u$ describes the temperature along the line segment $0 \leq x \leq 1$ and that the temperature at the two endpoints is fixed to be zero.  If we want to ensure that your book's proposed solution
$u\left(x,t\right)=\sin\left(\alpha{x}\right)\cdot{e}^{-\beta{t}}$
satisfies the boundary conditions, as well as the heat equation, then from just the right hand endpoint we need
$$u(1,t) = \sin(\alpha)e^{-\alpha^2} = 0.$$
This only happens when $\alpha$ is an integer multiple of $\pi$.  Thus, one solution is
$$u\left(x,t\right)=\sin\left(\pi{x}\right)\cdot{e}^{-\pi^2{t}}.$$
Let's take a look at how the graph of this functions evolves over $7/10$ of a second.

I guess the point is that the object is warmest in the middle and, since the endpoints are immersed in an ice bath to hold their temperature at zero, the heat diffuses out of the bar.
At the next step, you start to consider other possible initial distributions of heat.  At that point, you take into account the fact that any function of the form
$$u_n\left(x,t\right)=\sin\left(n\pi{x}\right)\cdot{e}^{-n^2\pi^2{t}}$$
solves the equation and the boundary conditions.  At time $t=0$, we have
$$u_n\left(x,0\right)=\sin\left(n\pi{x}\right)$$
and, in fact, any sum of the $u_n$s satisfies the heat equation and the boundary conditions.  You're left to ask whether, given a more or less arbitrary initial temperature distribution, is there a sum of the $c_n\sin(n\pi x)$ terms that matches that initial distribution.  This is how the topic of Fourier series arises.
Comment: Nice explanation, @Mark. Could you please tell me what software you used for the graphics? It's pretty cool (never better said). Furthermore it's a nice exercise to show that this parabolic problem subjected to homogenous Dirichlet boundary conditions is given by: $$ u(x,t) = \sum_{n=0}^{\infty} G_n e^{- n^2 \pi^2 t} \sin{ n \pi x}, $$ where $G_n$ is a constant related to the initial condition.
Comment: @Dmoreno I'm glad you liked it. I generate the image with Mathematica. I generated a list of images and then exported that to an animated GIF. The command to generate the list of images was something like so: `Table[Plot[Exp[-Pi^2 t] Sin[Pi*x], {x, 0, 1}, PlotRange -> {0, 1}], {t, 0, 0.7, 0.01}]`.
Comment: Wow, I'm sorry I didn't see your answer earlier, this makes a lot of sense now!


Is the function 1/x differentiable?

Question: This question is about the usage of the word "differentiable". You can't talk about the function not being differentiable in $x =0$ simply because it is not defined there. Isn't it then correct to say, that the function is differentiable? Wouldn't it be the same for the function $g(x)=\frac{1}{x}-\frac{\cos(x)}{\sin(x)}$?
Comment: "because it is not defined there. Isn't it then correct to say, that the function is differentiable? "  Mmmm.  It's debatable.  Maybe semantical.  Every one agrees 1) it is differentiable on all points it is defined, ii) that is not defined and/or differentiable at x=0.  what is debatable is whether "it is not differentiable on all R" is a meaningful statement.  As dom(f) is not R it's arguable such a comment is meaningless and/or irrelevant.  I'm more or less in that camp.  On the other hand applicationwise R is so relevent that noting a function fails at x=0 is not... impertainent.
Comment: @fleablood, look at the definition of differentiability at $a$: That the limit  $\lim_{x\rightarrow a} \frac{f(x)-f(a)}{x-a}$ must exit. If $f(x)$ is not defined in $a$, then you can't calculate $f(a)$, hence it makes no sense to talk about differentiability at $a$.
Comment: The function $f(x)=\frac1x$ is not defined when $x=0$.  So what is its domain?
Comment: Oh, I agree and I made that exact argument.  But if f the lim doesn't exist then it is *not* true that f is differentiable at x=a.  And if it is not true that fi is differentiable at x=a, then f is *not* differentiable at x=a.  Likewise f(x) is not differentiable at x = "pink-honk-honk" either.  Most mathematians would say "1/x is differentiable" because to most mathematicians "differentiable" = "differentiable for all dom(f)".  But I think many scientists and practical mathematicians may take "differentiable" = "differentiable for all Reals".  They are wrong. But...
Comment: ... it is misleading to say "1/x is differentiable so STFU".  It is relevent to point out.  "1/x is undefined as x = 0 so x is not in dom(1/x), so it isn't relevant to talk of whether is differentiable there".
Comment: If you dont define the domain and codomain of a function then its not defined. From this point of view $f(x)=1/x$ is not a function, so it dont care to talk about it differentiability.
Answer: Excert from wikipedia (use a better source if you have one)

A differentiable function of one real variable is a function whose derivative exists at each point in its domain.

Let $f = (x\mapsto \frac{1}{x})$. For any $x \in \mathrm{dom} (f) = \mathbb R \setminus\{0\}$, $f$ is differentiable at $x$.  Does that make $f$ differentiable ?
For any $x \in \mathrm{dom}(g)$, is $g$ differentiable at $x$ ?
Comment: Yes, it will? Just as I said?
Comment: Yes, indeed.  You restrict your analysis to the domain of $f$; it's in the definition.
Comment: I just got confused, because some textbooks and internetsides talk about $\frac{1}{x}$ not being differentiable in $x=0$, which is indeed incorrect, since it makes no sense to talk about differentiability.
Comment: Those text book are right as you point out, but over all $f$ is differentiable "on every point of its domain".  The quoted part being implied when saying a *function* is differentiable.
Comment: I got that part. I think, that you still misunderstand me. I mean, that the sentence "$\frac{1}{x}$ is non-differentiable at $x=0$" is wrong.
Comment: @HamidMohammad As a side note, for the same reason, $f$ is continuous. It's a common mistake to think it's not.
Comment: Depends on how you understand "non-differentiable".  I take it to means "has not the property of being differentiable at $0$, which having not $0$ in the domain implies.  But your way is fine too.
Comment: Thanks. That was the question from the every start. The other things were trivial.
Answer: If a function
$f$
is not defined at a value
$a$,
then it is
not differentiable at
$a$
because the derivative
is defined by
$\lim_{x \to a}
\dfrac{f(x)-f(a)}{x-a}
$
and the fraction
$
\dfrac{f(x)-f(a)}{x-a}
$
is not defined.
If $f$ is defined
in a neighborhood or $a$,
you can
write
$\lim_{y \to a} f'(y)
=\lim_{y \to a}\lim_{x \to y}
\dfrac{f(x)-f(y)}{x-y}
$.
Whether this double limit exists
depends on  how
$f$ acts close to $a$.
If $f$ has a removable discontinuity,
such as
$f(x) = x$ for $x \ne 0$
and $f(0) = 1$,
then the limit exists.
If $f$ has an essential
discontinuity,
such as
$f(x) = \frac1{x}$,
the limit of the derivative
does not exist.

Is the function 1/x differentiable?


Name for a group of notes made up of a root, major third, and perfect 4th?

Question: I'm looking at the song One thing leads to another by the Fixx. Throughout the song, the guitarist plays the highest three strings at the 5th fret (giving C E A).
Correct me if I am wrong, but the C to E is a major third and the E to A makes a perfect 4th. The formula for a triad is a third and a 5th, 1 3 5, so this isn't considered a chord. What would this be called then?
Comment: A triad is simply three notes, and a chord is any combination of notes.  Major and minor triads are, of course, composed of a Maj/min third and a min/Maj third (or perfect fifth from the root).
Answer: This is an A minor chord in first inversion.
A is the root note, C is the minor 3rd, E is the perfect 5th. As the C, the 3rd, is at the bottom, this chord is in first inversion.
The musical excerpt below shows this with conventional notation. Each chord has the same three pitches of an A minor triad, A C E (R m3 5), but the change to the lowest pitch changes the inversion.
Comment: For completeness, it's worth noting that the term inversion refers specifically to the lowest note of the chord, regardless of the order of notes above that. So, while C E G is a root position C chord, so is C G E.
Comment: @CalebHines In that case, CEG would be referred to as a *closed chord*, because all of the notes are within an octave of each other, while CGE would be an *open chord*, since there are large intervals between each note.
Comment: (I'm sure you already know that. I think it's helpful information for some people reading the comment thread, though.)
Comment: Now I know what people mean when they go on about inversions!! Thank you! (Sometimes people use this term in their 'how to play' YouTube videos)
Comment: That is very useful information. Learning the key-words so they can be further researched is always one of the harder things in the beginning of learning some new realm of knowledge.
Comment: That makes perfect sense! I need to think outside of the box more - the root is not always the first note played. Thanks for the quick and concise answer.

p.s. I would vote up but I don't have enough rep.
Answer: I don't know the context of that particular song, but when it comes to naming chords, the octave in which the pitches reside is (usually) irrelevant -- a fact called octave equivalence. This allows you to re-order the notes into any order, to find the chord name. In this case, the perfect 4th (E to A) inverts to a perfect 5 if you drop the A below the E, which gives A C E -- an A minor chord. This is most likely what the chord is.
It's also possible that these notes belong to part of some more advanced chord, and the other notes of the chord are being played by other instruments -- for example, an FMaj7 has the notes F A C E, with the F being played in the bass. Another possibility would be a Cadd6, which is C E G A.
But without knowing about those missing parts, A minor is definitely the best choice.
Comment: Very interesting. I like how you point out the possibility of another instrument picking up part of the chord, showing the need for the context..


A real number times zero is zero

Question: Justify each step of the following direct proof, which shows that if $x$ is a real number, then $x\cdot0=0$. Assume that the following are previous theorems: If $a$, $b$, and $c$ are real numbers, then $b+0=b$, $a(b+c)= ab+ac$, and if $a+b=a+c$, then $b=c$.
Please show the steps as I'm confused here.
Comment: Please surround math with dollar signs, this makes the formulae stand out and makes them easier to read. For example `$(a+b)c$` gives you $(a+b)c$.
Answer: Note that
\begin{align*}
x \cdot 0 &= x\cdot (0 + 0) \\
&= x\cdot 0 + x\cdot 0
\end{align*}
Rearrange this to give
$$x \cdot 0 + 0 = x \cdot 0 + x \cdot 0$$
So what can you conclude from here? And can you justify each step?
Comment: I'm lost on the logic there, how did you translate the x*0=0 to x*0+)=x*0+x*0?
Answer: Since $a(b+c)=ab+ac$ for all real numbers $a$, $b$, and $c$, we know that $x\cdot0=x\cdot(0+0)=x\cdot0+x\cdot0$. This implies that $x\cdot0=x\cdot0+x\cdot0$. Since $b+0=b$ for all real numbers $b$, we know that $x\cdot0+0=x\cdot0+x\cdot0$. Since $a+b=a+c$ implies that $b=c$ for all real numbers $a$, $b$, and $c$, we can see that $x\cdot0+0=x\cdot0+x\cdot0$ implies that $x\cdot0=0$. Thus $x\cdot0=0$.

A real number times zero is zero


Form hypothesis and test it using given data

Question: In country A, during the ten-year period $2002 - 2012$ judges sentenced convicts to the death penalty 45 times. In contrast, the number of such penalties in 2013 was $19$ and in $2014$ it was $4$. An analyst claimed that the evident change in the rate of conviction is not statistically significant because of the sample.
I am trying to formulate a possible hypothesis that the analyst might have had in mind, given ONLY these data, and carry out a test to check whether or not the result is statistically significant. My idea for the hypothesis was the following:
\begin{align*}
H_0&: \mu_{x \le 2012} = \mu_{x  > 2012} \\
H_1&: \mu_{x \le 2012} < \mu_{x  > 2012}
\end{align*}
where $\mu_{x \le 2012}$ denotes the average annual number of convictions up to $2012$ and $\mu_{x  > 2012}$ denotes the average annual number of prosecutions from $2012$ onwards.
Assuming that this is a reasonable hypothesis, I am thinking of computing the likelihood ratio statistic and then proceeding from there. However, that statistic requires me to compute the likelihood function under the null and divide it by the maximum of the likelihood function under the full model. How is am I to approach this since I am not given anything about the distribution of the observations? Any suggestions will be greatly appreciated, especially ones regarding the correctness of the stated hypothesis.
Answer: The simplest approach that I can think of that is theoretically valid would be to assume that these convictions are generated by a Poisson process - meaning that each death sentence is a rare event, independent of other death sentences and that the probability distribution for the time between two such sentences is given by the exponential distribution.
With that, you can simply estimate the $\lambda$:s for the three different time periods and calculate the confidence intervals for the sample means.
2002-2012 (assuming it is a 10-year period as you said, and not 11):
$\widehat{\lambda} = \frac{45} {10} = 4.5$, with a 95% confidence interval of $\widehat{\lambda} ~ \pm ~ \sqrt{\widehat{\lambda}} \approx 4.5 \pm 0.67 $
2013:
$\widehat{\lambda} = \frac{19} {1} = 19$, with a 95% confidence interval of $\widehat{\lambda} ~ \pm ~ \sqrt{\widehat{\lambda}} \approx 19 \pm 4.36 $
2014:
$\widehat{\lambda} = \frac{4} {1} = 4$, with a 95% confidence interval of $\widehat{\lambda} ~ \pm ~ \sqrt{\widehat{\lambda}} = 4 \pm 2 $
(Note: the confidence intervals assume that the number of events is "great" and that the probability distribution for $\widehat{\lambda}$ can therefore be approximated with the normal distribution. This assumption does not hold very well for the 2014 time period)
You can then do pairwise comparisons. If you wish to check whether e.g. 2013 in particular stands out, then treat 2002-2012 and 2014 as a single 11-year period with 49 sentences. Clearly, the number of sentences in 2013 stand out as exceptional.
Answer: Let me suggest a different approach that is simpler and relies on fewer assumptions than Heitz Chi Square approach.
Going back to your data set, you essentially have a time series of annual death penalties running from 2002 to 2014.  And, except for 2013 in the other years the average is about 4 per year.  Now, 2013 is very different at 19 in that year.  Your hypothesis really should be is whether the 19 occurence in 2013 is statistically significant or not.  The easiest way to do this is by using linear regression.  For it to be interactive, I propose doing it with LINEST in Excel.  To investigate whether 2013 figure is statistically significant, we can structure our linear regression in two different ways.
Both regressions will have the same dependent variable structure.  We know the exact figures from 2012 to 2014.  And, for the earlier years we know they sum up to 45.  So, you can enter a bunch of annual figures with a bit of variation (let's say between 2 and 6) as long as they sum up to 45.
In the first regression, you will use three regressors: 1) Intercept; 2) a Trend variable (1, 2, 3,...); and 3) a dummy variable for 2013 (1 in 2013 and 0 in all other years).  Within this first regression, you will see that the 2013 dummy variable comes in with a very high value at around 15.  This makes perfect sense because at 19, it is 15 units higher than the average of the other years around 4.  And, the same 2013 dummy variable comes with a very high t stat of close to 12, meaning it is very statistically significant (any t stat > 3 is already very statistically significant).
In the second regression, you replicate the first regression except you do not use a 2013 dummy variable.  In this case, you will calculate the residuals of this regression and subsequently the standardized residuals of this regression.  Next, you observe how much of an outlier is 2013 by looking at its standardized residual or Z value.  In my case, the residual was - 11.8 and the standardized residuals was -38.3.  Any standardized residual whose absolute value is greater than 3 denotes a very statistically significant outlier.
Both regression methods fully confirm that the year 2013 is extraordinary and way above the norm or trend rate as depicted by all the other years.
By conducting your regression using LINEST you will see that the values you assign to 2002 to 2012 do not affect your outcome of the statistical significance of 2013.  You will get slightly different results than mine.  However, directionally your results will match mine.  2013 again is a very statistically significant extraordinary year compared to the other years in the data.
Given the number of data points you have, I think the above approach will be far more conclusive and robust than using a standard multiple group hypothesis testing approach like ANOVA or its nonparametrics equivalents.  That's because those approaches will not work well with one category that has only 2 data points or maybe even just one depending on how you segment your data (in 2 or 3 different groups).  The linear regression approach entirely circumvented this problem.
Comment: Nice approach Sympa.
Answer: I fit a robust Poisson model to the 3 data points that you have, adjusting for the number of years in each:
<code>. clear

. input t years y

             t      years          y
  1. 1 10 45
  2. 2 1 19
  3. 3 1  4
  4. end

. label define period 1 "2002-2012" 2 "2013" 3 "2014"

. lab val t period

. poisson y ib1.t, exp(years) robust nolog

Poisson regression                              Number of obs     =          3
                                                Wald chi2(0)      =          .
                                                Prob > chi2       =          .
Log pseudolikelihood = -6.8525416               Pseudo R2         =     0.6208

------------------------------------------------------------------------------
             |               Robust
           y |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           t |
       2013  |   1.440362   3.86e-11  3.7e+10   0.000     1.440362    1.440362
       2014  |   -.117783   2.27e-10 -5.2e+08   0.000     -.117783    -.117783
             |
       _cons |   1.504077   1.93e-16  7.8e+15   0.000     1.504077    1.504077
   ln(years) |          1  (exposure)
------------------------------------------------------------------------------
</code>
The coefficients on 2013 and 2014 are significant, suggesting 2013 is above the 2002-2012 average and 2014 is below it. You can exponentiate them to get the multiplicative effect on the baseline.
Answer: There are several layers to this onion.
First off, let me play devil's advocate and assume I am the analyst and took at quick look at these data.  You have 3 time spans, 2002-2012 (45), 2013 (19), and 2014 (4). Converting to a yearly rate, the 2002-2012 time span had 4.09/year (45/11), so comparing that to the 4 recorded death penalties in 2014, I might conclude off the bat that save for 2013, the yearly rate hasn't changed.
But let's move on.  There are a few ways to attack this problem, but in each you have some unknowns that need addressing.  You suggest going the likelihood ratio route, in which case you need to specify the nature of the distributions, but I think this problem can be addressed with chi-square.  In fact, your H0 and H1 as stated seems to anticipate this, as you are reducing everything to a contingency table (<=2012 vs > 2012). I will proceed with the assumption that the 2012 cut-off is adequate and call them the 'old' and 'new' time spans for convenience.
What you'd need to do next is figure out what you are comparing this death penalty to, and we'll have to make some assumptions.  You might want to compare the rates for new and old versus population in country A. For present purposes, I will instead assume that exactly 20 people per year are convicted of a crime potentially punishable by death penalty, but receive a lesser penalty (say, life in prison or something).
Lets create a contingency table.

Note that I've converted the 45 for the old period to 4.09/year, then rounded down to 4 for convenience.  For the new period, you actually have (19+4)/2 = 11.5, which I also round to 12 for convenience.  Despite the simplification, the point should be clear.
Next, I assume that 20 people/year have death-penalty eligible convictions, which I add to the contingency table.  You could use some other value too, but you'd have to correct the previous entries as well.  E.g., rate per capita, rate per 1000 people, etc.
With this toy example set, we can then compute the chi-square, which I won't do by hand, but here is some sloppy R code that computes it.
<code>x1 = data.frame(status=rep('Death',4),year='old')
x2 = data.frame(status=rep('Death',12),year='new')
x3 = data.frame(status=rep('No Death',20),year='old')
x4 = data.frame(status=rep('No Death',20),year='new')
x = rbind(x1,x2,x3,x4)
chisq.test(table(x),correct = FALSE)
</code>
The test does not attain conventional (p<.05) significance, suggesting that you retain the null hypothesis that there is no difference between the 'old' and 'new' periods. But, of course half the contingency table is fabricated.
Is your hypothesis reasonable?  It might be, provided that you really don't have access to the yearly data, and are limited only to 2002-2012, 2013, 2014. If you do have access to the yearly data, simplifying like this doesn't make sense.


Equivalence definition of creation of limits?

Question: The following is at Emily Riehl's Category theory in context, page 90.
Firstly the Definition of creation of limits:

Definition 3.3.1. : For any class of diagrams $K : J → C$ valued in $C$, a functor $F : C
→ D$  creates those limits if whenever $FK : J → D$ has a limit in
  $D$, there is some limit cone over $FK$ that can be lifted to a limit
  cone over $K$, and moreover $F$ reflects the limits in the class of
  diagrams.

But later the author writes the following at the same page, which I think is a weaker hypothesis than that in Definition 3.3.1, because it seems not to require the limit cone existing in $C$ to be a lift of a limit cone in $D$.

Remark 3.3.2. To ground intuition for these terms, the following metaphor may prove helpful: a functor $F : C → D $ maps from
  "upstairs" (the category $C$) to "downstairs" (the category $D$). An
  upstairs diagram (a functor $K : J → C$) sits above a downstairs
  diagram (by composing with $F$).
$F$ creates limits if the mere presence of a downstairs limit cone
   implies the existence of an upstairs limit cone, and if any cone
   sitting above a limit cone is a limit cone.

May I miss something? Thanks for any hint.
Answer: This is indeed a weaker hypothesis. The formal definition supposed that $F$ lifts and reflects limits, while the intuitive one suppose only that $F$ reflects limits and the existence of limits. As long as $\mathcal C$ has limits, the formal definition implies that $F$ preserves them, but the intuitive one does not, so is missing a piece of the concept.


How to call watchdog() outside Drupal

Question: I'm getting used to use the Drupal watchdog() function. It provides me a very simple and accessible way to log events in my code.
However, I would like to use the same (or very similar) function in some other PHP projects outside Drupal. Accessing the results via the Drupal reports interface would be nice.
Does anyone know any proper way to include the relevant files of a Drupal instance to provide this functionality in custom PHP code? I know that there are already other PHP logging solutions which may be better, but I'm looking for something similar to watchdog().
Comment: It's not very clear if you actually want to use drupal's watchdog() or looking for something similar. Please clarify.
Comment: I was not sure if the first was possible so I was looking for both
Answer: Requiring the existence of a Drupal installation for all of your other non-Drupal PHP projects isn't something I've come across before...but you can bootstrap Drupal to make the watchdog() function available like so:
define('DRUPAL_ROOT', '/path/to/drupal/installation');
include_once(DRUPAL_ROOT . '/includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

watchdog('my_module', 'A message');

Comment: Not all other non-Drupal PHP projects, only some. But many thanks, this was the answer I was looking for.
Answer: What you are requesting will considerably slow your external script. Perhaps there are better alternatives to using drupal's watchdog function.
To use watchdog function you will need to bootstrap drupal.
$drupal_path = '/drupal/home';

// Create a constant DRUPAL_ROOT that
// defines our path to the drupal install
define('DRUPAL_ROOT', $drupal_path);

// We need to load the bootstrap.inc file so we can
// have access to the drupal_bootsrap() function
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';

// Bootstrap Drupal at the phase that you need
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

Drupal bootraps in the index.php file in the drupal root.
Checkout the includes/bootstrap.inc file to see the bootstrap phases and what loads at each phase.
You can experiment with different phases, perhaps you do not need to perform a full drupal bootstrap.
Comment: Thanks I'm going to test how slow are going to be my scripts with this.

How to call watchdog() outside Drupal


"Operation could destabilize the runtime" when using ANTS profiler on a StructureMap application

Question: We are recently upgraded a web/mvc application to use StrucutreMap 3.0.4
Now, when attempting to profile the application using RedGate Ant's profiler at the "Line Level Timings, All Methods with Source" or greater level, we get the following error
Operation could destabilize the runtime.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Security.VerificationException: Operation could destabilize the runtime.

Source Error:

Line 174:
Line 175:                            Initialise(context);
Line 176:                            ObjectFactory.Initialize(x => {     x.AddRegistry<BWebsiteIoc>(); });
Line 177:                        }
Line 178:                    }

Source File: c:\_Development\NT\Platform\WebSite\Global.asax.cs    Line: 176

Stack Trace:

[VerificationException: Operation could destabilize the runtime.]
StructureMap.ObjectFactory.Initialize(Action`1 action) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\ObjectFactory.cs:42
   Nga.Platform.Website.FirstRequestInitialisation.Initialise(HttpContext context) in   c:\_Development\NT\Platform\WebSite\Global.asax.cs:176
   Nga.Platform.Website.MvcApplication.Application_BeginRequest(Object source, EventArgs e) in c:\_Development\NT\Platform\WebSite\Global.asax.cs:106
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +182
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165

I've tried adding  to system.web in web.config as per http://documentation.red-gate.com/display/APP8/Operation+could+destabilize+the+runtime+error+profiling+ASP.NET
Comment: Another solution to get rid of this exception, is to [add the assembly-in-concern to the "LineLevelBlacklist.xml" file](https://forums.red-gate.com/viewtopic.php?p=138072#p138072).
Answer: May be an old question, but it's still one of the first for me on google results, so here goes.
I was able to solve the issue by deleting structuremap's pdb files before profiling.
Comment: Can confirm. Had the same error, deleted all files in `bin` folder, re-built. Job done.
Answer: Added
<assemblyName>StructureMap</assemblyName> to %LOCALAPPDATA%\Red Gate\ANTS Performance Profiler 9\LineLevelBlacklist.xml which did the trick.
Answer: I was able to work around the problem by adding the following to the AssemblyInfo.cs of the class library causing the problem.
[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

I found this solution in a Redgate forum discussion.


Calculating limit for sequence that tends to infinity

Question: How am I supposed to calculate this? Please help, I don't know where to start.
cosine values are between -1 and 1 right? So how am I supposed to use that exactly?
$$
\lim_{n \to \infty} (\cos n - 1)n^2
$$
Do I just calculate brackets individually and multiply results?
$$
\lim_{n \to \infty} \left(\frac{3n+2}{5n+2}\right)^n \cdot \left(\frac{5n+3}{3n+1}\right)^n
$$
Answer: HINTS
for the first one, note that $n^2$ will grow to $\infty$ but $\cos n-1$ will keep changing the sign indefinitely.
for the second one, you can transform it to this:
$$
\lim_{n \to \infty}
\left(\frac{5n+3}{5n+2}\right)^n \cdot
\left(\frac{3n+2}{3n+1}\right)^n
$$
Comment: $(\cos n-1)$ is *not* changing signs, it always stays negative for $n > 0$. $\cos n$ will be below $0$ infinitely often, so $(\cos n-1)n^2$ is certainly not bounded below, so it does not converge in the strict sense that allows only real values as limits. If $\lim_{n\to \infty}(\cos n-1)n^2 = -\infty$ is actually a question I can't answer.
Comment: Can you please see if I did it correctly? I still don't know what I am supposed to do with the cos*n one, please elaborate.
[first one - please check if it's correct](https://ibb.co/iBr7Q0)
[cosinus one, what next?](https://ibb.co/bEa3Xf)
Comment: @B.Czostek first one is correct, the second limit does not exist because it is not bounded from either side