Better understanding Maximum Likelihood parameter estimation

Question:
Suppose I am trying to model the dependence of a variable $B$ on another variable $A$ by a function $B=f(A;k)$, where $k$ is a parameter, whose value I would like to estimate. Given $n$ observations $\{A_i,B_i\}$, how can use MLE to estimate the value of $k$?

For example (and just as an example), I assume the value of glucose ($=G$) depends on hemoglobin ($=H$) by the following model:
$$
G=\frac{1}{1+H\cdot k},
$$
where $k$ is a parameter unique to each individual, that is known to be normally distributed in the population. I am given a set of $n$ measurements of glucose and hemoglobin of one person, and would like to estimate the value of $k$. How can I do it?
I will be happy to receive recommendations (or, even better, explicit explanations) on resources covering the solution to this problem. I keep finding explanations on estimating a parameter from a distribution, and can't figure out how to relate such explanations to this kind of a problem.
I thought of first isolating $k$ to obtain that (EDIT: I failed to correctly isolate $k$ in my first thread, and fixed it in an edit)
$$
k=\frac{1-G_i}{H_i G_i},
$$
but wasn't sure how to continue from here...I know that $k$ is normally distributed in the population, but how can this help? What if the distribution of $k$ in the population wasn't given?
Thank you!
Comment: The core concept of MLE is that it is a probability model that seeks the parameters which maximize the joint probability of observing the data. How would you write down the joint probability of your data according to your model? In what you've written, there doesn't seem to be anything probabilistic, or anything to estimate, because $k$ is a deterministic function of $H$ and  $G$, which are known and fixed.
Comment: @jhin The question asks what the MLE would be for some unstated probability model; it is not possible to answer it. If the measurements are, indeed, measured with some amount of error as you have suggested, then that will need to be stated explicitly by OP in an [edit], with a description of what the errors are.
Comment: @Jorimu In case it's not clear from our discussion until now, your question only makes sense if measurements (of Glucose and Hemoglobin) are *noisy*, i.e., subject to measurement errors. Otherwise, you could just compute the exact value of $k$ from a single pair of measurements. For an exact answer, you would need to clarify what kind of distribution you're assuming for the measurement noise.
Comment: Unfortunately, I need to reclose the question because it is ambiguous: is your model $G=1/(1+Hk)$ or is it $G = 1-Hk$ as implied later in the post??
Comment: @Sycorax OP did not write explicitly that $H$ and $G$ are "known and fixed," only that they are "measurements". Of course, one would need to assume some kind of measurement noise, but that could be part of an answer, right? I'm a bit confused this question was closed; it seems perfectly answerable to me.
Comment: @Sycorax Obviously, the OP is not an expert on probabilistic inference in general and ML estimation in particular, which is why he/she is asking for advice. I personally find it a bit weird and TBH not very welcoming to close such a question as "you did not formulate it correctly using the framework you're asking about". I also do not read the question as concerned with the correct ML estimator for a very particular problem, but rather concerning a general understanding for how ML estimation for this *type* of problems would work, with an example given.
Comment: @jhin The best place to raise questions about question closure is on https://stats.meta.stackexchange.com/ If OP is interested in general questions and answers about MLE, there are a number of examples available via Search. But it seems that OP has a specific questions about the MLE for this problem, so bridging the gap between an example of MLE in another setting and applying it to this setting seems like the crux of the issue; this Question requires more information to be answerable. OP can provide this information via [edit], whence the question will be eligible for re-opening.
Comment: I think the previous interlocutors might have overlooked the description of $k$ as being normally distributed.  That makes this a clear, answerable question.
Comment: Thanks everyone for suggesting really good points. I am indeed not an expert in probabilistic inference, and was looking for a good reference, or a good explanation. I also apologize for not isolating $k$ correctly, fixed it in an edit.

As for the "noise" part - this is a good point, that I wasn't aware of. I guess that an implicit assumption is that $G_i=\frac{1}{1+H_i \cdot k} + \varepsilon$ where $\varepsilon$ is random noise? (normally distributed maybe) Will this addition make the problem well-posed? Thank you!
Comment: It might be that what I was missing is that we have to assume that $G_i=\frac{1}{1+H_i \cdot k} + \varepsilon$. In such a case, the likelihood function is just obtained from inserting $G_i-\frac{1}{1+H_i \cdot k}$ into the normal distribution, and taking the log of what we obtain right? Even if this is correct, I would still appreciate a recommendation on a relevant book with examples, or explanation. Thank you all again!
Answer: In ML estimation, one maximizes the likelihood of the data given the parameters. In your case:
$$
\hat{k}_{\mathrm{ML}} = \arg\max_k p(G_1, G_2, \ldots, G_N, H_1, H_2, \ldots, H_N \mid k).
$$
If we assume that
$$
G_i = \frac{1}{1+H_i k} + \varepsilon , \quad \varepsilon \sim \mathcal{N}(0, \sigma_\varepsilon ),
$$
i.e., we assume Gaussian measurement noise on the $G_i$ and independent measurements, we obtain
$$
\begin{align}
\hat{k}_{\mathrm{ML}} &= \arg\max_k p(G_1, G_2, \ldots, G_N, H_1, H_2, \ldots, H_N \mid k) \\
&= \arg\max_k p(G_1, G_2, \ldots, G_N \mid k) \\
&= \arg\max_k \prod_{i=1}^N p(G_i \mid k) \\
&= \arg\max_k \log \prod_{i=1}^N p(G_i \mid k) \\
&= \arg\max_k \sum_{i=1}^N\log p(G_i \mid k)
\end{align}
$$
Furthermore, we have that
$$ p(G_i \mid k) = \mathcal{N}(G_i; \mu_i(k)=\frac{1}{1+H_i k}, \sigma_{\varepsilon })=\frac{1}{\sigma_\varepsilon\sqrt{2\pi}} \mathrm{e}^{-\frac{1}{2}(\frac{G_i-\mu_i}{\sigma_\varepsilon})^2}.$$
Plugging that into the above optimization problem, we get
$$
\begin{align}
\hat{k}_{\mathrm{ML}} &= \arg\max_k \sum_{i=1}^N -\frac{1}{2}\left(\frac{G_i-\mu_i(k)}{\sigma_\varepsilon}\right)^2 -N\log (\sigma_\varepsilon \sqrt{2\pi}) \\
&= \arg\max_k \sum_{i=1}^N -\frac{1}{2}\left(\frac{G_i-\mu_i(k)}{\sigma_\varepsilon}\right)^2 \\
&= \arg\min_k \sum_{i=1}^N (G_i-\mu_i(k))^2
\end{align}
$$
A few remarks:

This particular example is an ordinary least squares problem a nonlinear least-squares estimation problem (as can be seen in the last equation).
If the measurements $H_i$ are also assumed to be noisy, things get more complex. In that case, we're dealing with a nonlinear errors-in-variables regression problem. The optimization problem can still be solved numerically, of course.
What happened to the information that $k$ is normally distributed in the general population? That was not used at all in the above derivation, because ML estimation does not consider such priors. If you want to take that into account, you can do maximum a posteriori (MAP) estimation, which is essentially ML estimation + a prior on the parameters. MAP estimation maximizes $p(k \mid G_1, \ldots, G_N, H_1, \ldots, H_N).$ Using Bayes theorem, we have that
$$
\begin{align}
\hat{k}_{\mathrm{MAP}} &= \arg\max_k p(k \mid G_1, \ldots, G_N, H_1, \ldots, H_N) \\
&= \arg\max_k \frac{p(G_{1:N}, H_{1:N} \mid k) \, p(k)}{p(G_{1:N}, H_{1:N})} \\
&= \arg\max_k p(G_{1:N}, H_{1:N} \mid k) \, p(k) \\
&= \arg\max_k \log p(G_{1:N}, H_{1:N} \mid k) + \log p(k) \\
&= \arg\max_k \log p(k) + \sum_{i=1}^N\log p(G_i \mid k),
\end{align}
$$
where $p(k)$ denotes prior knowledge about the distribution of $k$. In your example, that could be the population average. We see that this is exactly what we had above for the ML estimate, except for the additional term $\log p(k)$.
Comment: I am surprised at the complexity and incompleteness of this answer.  It looks like that's because you adopt a model not implied by the question.  According to the question, each $(G_i,H_i)$ observation independently determines a $k_i$ assumed to have a Normal$(\mu,\sigma^2)$ distribution. Therefore the MLE of $\mu$ is the arithmetic mean of the $k_i$ and the MLE of $\sigma^2$ is the (non-bias-corrected) variance of the $k_i.$ Although it is indeed more realistic to also model measurement errors, why do you model errors for $G$ but not for $H$??
Comment: @whuber Sure, but then it's a MAP estimate, not an ML estimate, isn't it? That's what I was trying to convey in my last remark. (I just spelled out the derivation of the MAP formulation a bit more.)
Comment: Thanks everyone for you suggestions. I think everything is much clearer now. By the way - indeed, for each individual we have a different value of $k$, and I am given a set of several measurements from the same person, from which I would like to estimate $k$. I was missing two key insights - 1) the assumption about the noise. 2) verification that the calculation turns out to be equivalent to OLS.
Thanks for accepting my question and answering it... I hope I will manage to better understand everything from here.
Comment: @whuber The blockquote at the top of OP says that $k$ has a single value and is a parameter of some function $f$. But your comment supposes a different $k_i$ for each individual, whence we have a distribution over $k_i$. This is why I asked for clarification about the probability model -- it wasn't clear to me what was data and what was a parameter.
Comment: @whuber You're completely right that the assumption to model errors for $G$ but not for $H$ was arbitrary. My understanding of the question was that the OP is interested in how to generally derive an ML estimator for a single parameter given a set of i.i.d measurements and a functional model. I showed how to do so using the simpler case of errors in only one variable (but mentioned the EIV case below). The complexity arises because I wanted to show step by step how to get to the final estimator from the ML formulation.
Comment: I understood from the question that a) each individual has its own value of $k$, b) there is a Gaussian distribution of these $k$ in the whole population, and c) we're now taking $N$ measurements of Glucose and Hemoglobin in a single individual and want to estimate that individual's value of $k$.
Comment: I share that understanding--but that's why I was surprised at your asymmetric treatment of $G$ and $H.$  This looks like a perfect setting for applying Bayes' theorem: we suppose a Normal prior for $k$ and, upon adopting some kind of probability assumption for the distribution of $(G,H)$ conditional on $k,$ can then obtain a posterior distribution for $k.$


Steepest descent with slow variation

Question: Suppose that one has an integral of the form
$$
\int_{\mathbb{R}} g(x) e^{\lambda f(x;\lambda)}
$$
where
$f(x;\lambda) = f_0(x) + f_1(x;\log(\lambda))/\lambda $ and $f_1$ depends slowly on $\lambda$ in the sense that it can grow at most polynomially in its argument.
Is it true that, as $\lambda\to \infty$,
$$
\int_{\mathbb{R}} g(x) e^{\lambda f(x;\lambda)}dx \sim \sqrt{\frac{2\pi}{\lambda |f_0''(x_0)|}}g(x_0)e^{\lambda f_0(x_0)},
$$
where $x_0$ is a unique stationary point of $f_0(x)$, i.e. the asymptotics agree with those replacing $f(x;\lambda)$ with $f_0(x)$?
Answer: You may appeal to the following theorem by Olver (Asymptotics and Special Functions, Chapter 9, Section 2, Theorem 2.1). You have to shift the stationary point $x_0$ to the origin, split the integral at $x=0$ into two separate integrals, and finally cut off the integrals at finite points and show (in the usual way) that the contributions from the tails are negligible.
Theorem. Let $k$ and $\Lambda$ be fixed positive numbers, and
$$
I(\lambda ) = \int_0^k {g(x,\lambda) e^{\lambda f_0 (x) + f_1 (x,\lambda )} dx} .
$$
Assume that
(i) $f'_0 (x)$ is continuous and negative in $(0,k]$, and as $x\to 0+$
$$
f_0 (x) = f_0(0) + F_0 x^\alpha   + \mathcal{O}(x^{\alpha _1 } ),\quad f'_0 (x) = \alpha F_0x^{\alpha  - 1}  + \mathcal{O}(x^{\alpha _1  - 1} ),
$$
where $F_0<0$ and $\alpha _1  > \alpha  > 0$.
(ii) For each $\lambda \in [\Lambda,\infty)$, the real or complex functions $f_1(x,\lambda)$ and $g(x,\lambda)$ are continuous in $0 < x \leq k$. Moreover
$$
\left| {f_1 (x,\lambda )} \right| \le F_1 x^\beta  \lambda ^\varepsilon  ,\quad \left| {g(x,\lambda ) - G_0 x^{\gamma  - 1} } \right| \le G_1 x^{\gamma _1  - 1} \lambda ^\delta  ,
$$
where $F_1,\beta,\varepsilon,G_0,\gamma,G_1,\gamma_1$ and $\delta$ are independent of $x$ and $\lambda$, and
$$ \beta \geq 0,\quad \gamma>0, \quad \gamma_1>0,\quad \varepsilon <\min(1,\beta/\alpha),\quad \delta < (\gamma_1-\gamma)/\alpha.
$$
Then
$$
I(\lambda ) = \frac{{G_0 }}{\alpha }\Gamma\! \left( {\frac{\gamma }{\alpha }} \right)\frac{{e^{\lambda f_0 (0)} }}{{(|F_0| \lambda )^{\gamma /\alpha } }}\left( {1 + \mathcal{O}\!\left( {\frac{1}{{\lambda ^{\varpi /\alpha } }}} \right)} \right)
$$
as $\lambda \to +\infty$, where
$$ \varpi = \min(\alpha_1-\alpha,\beta-\alpha \varepsilon,\gamma_1-\gamma-\alpha\delta).$$

Steepest descent with slow variation


Can one find a $g(x)$ , which is differentiable in $[a,\infty)$ and $\lim_{x\to\infty}g(x)=\infty$,but $\lim_{x\to\infty}x^2g'(x)\neq\infty$

Question: Can one find a $g(x)$ , which is differentiable in $[a,\infty)$ and $$\lim_{x\to\infty}|g(x)|=\infty$$
but $$\lim_{x\to\infty}x^2|g'(x)|\neq\infty$$
(Or doesn't exist that limit)
Comment: I don't think there exists such a g, but I don't how to prove.
Answer: Let $$g(x)=x+\sin x$$
Then clearly, $$\lim_{x\rightarrow +\infty}|g(x)|=+\infty$$
but $$\lim_{x\rightarrow +\infty}x^2|g^\prime(x)| =\lim_{x\rightarrow +\infty}x^2|1+\cos(x)|$$ does not exist.
Comment: (+1) All too easy
Comment: Yes, really easy
Answer: Since, if $g$ is at least absolutely continuous and $g'$ integrable,
$$|g(x)| \leqslant |g(a)| + \int_a^x |g'(t)| \, dt$$
and $|g(x)| \to \infty$, we have
$$\int_a^\infty |g'(t)| \, dt  = \infty$$
Hence, we can rule out "nice" functions where $\lim_{x \to \infty}x^2 |g'(x)| = L < \infty$ which would imply that the integral converges with $|g'(x)| = \mathcal{O}(x^{-2})$ as $x \to \infty$.
The limit may not exist though, for example,
$$g(x) = \int_1^x \sin^2(t) \, dt$$
where $|g(x)| \to \infty$ but $x^2|g'(x)|= x^2 \sin^2 (x) $ does not converge as $x \to \infty$.
Note that $\liminf_{x \to \infty} x^2 \sin^2 (x) = 0$ and $\limsup_{x \to \infty} x^2 \sin^2 (x) = \infty$.
At this point your question is answered and we don't need to explore more pathological cases.
Answer: Let
$g(x)=x\sin x+2x$,
then
$x^2g'(x)=x^2(\sin x+2)+x^3\cos x$ .
Comment: 原来是你


Question on Graph Connectivity

Question: Now this question is on graph connectivity and I still can't get my head around these graph theory questions. Now we've been given an n-node graph which is represented by $G=(V,E)$ and two nodes $s$ and $t$ are in $V$, where all the paths between $s$ and $t$ are strictly greater than $n/2$. Show that a node $v$, not equal to $s$ or $t$, exists, removing which from $G$ would eliminate all $s-t$ paths.
And next we have to devise an algorithm with runtime $O(n + m)$, where $m$ is the number of edges, which can find such a node v.
Solution: Now I tired making diagrams to figure out what the Graph may look like. One observation I made was that the nodes $s$ and $t$ can't be in a cycle because then one of the paths from $s$ to $t$ won't be strictly greater than $n/2$. It's fairly obvious. Lets have a graph which is just a cycle. There would be $n$ nodes and $n$ edges. Hence one of the two paths would be shorter than $n/2$.
Hence there are two options:

There is only one path from $s$ to $t$ in which case we can just remove any node between those two.
In the other case there is one path from $s$ to $t$ and one path from either $s$ and $t$ to any vertex in the path from $s$ to $t$. Hence we get a cycle from $s$  or $t$ to that specific vertex $v$ back to $s$ or $t$. Hence we can remove that specific node between $s$ and $t$ to disconnect all the paths.

In that algorithm I though one can just walk from $s$ to $t$ and figure out the vertex with maximum degree and remove it.
Is my solution correct? Thanks in advance.
Comment: Yup, the theoretical part follows simply from Menger's, and since checking connectedness can be done by linear time (say DFS), we can for each vertex not equal $s,t$, delete it and check whether it is still connected.
Comment: I could say that the theoretical part and algorithm with quadratic running time are just easy, but a algorithm with linear time would be very challenging. Your argument seems not convincing, since in the second option, it can surely happen that those two paths don't form a cycle.
Comment: ^So can you help me out with the second part.
Comment: As I said, I still cannot figure out a linear time algorithm.
Comment: How would we do this in quadratic time? I may be able to figure it out from that.
Comment: The first part follows easily from Menger's Theorem. Do you have that available to use? If not, then the idea is that if there is no such cut vertex, then in fact there must be two internally disjoint paths from $s$ to $t$, which is impossible if both paths have length greater than $n/2$.
Comment: I don't have Menger's Theorem available to use here. Can one of you write the answer here?
Comment: Actually, the proof of Menger's is not so long, say just begin from max-min flow and then some transformations. And I really think Menger's perfectly fits this exercise.
Answer: We show by strong recurrence on $n$ the number of nodes that for every graph $G=(V,E)$ and two nodes $s$ and $t$ in $V$, where all the paths between $s$ and $t$ are strictly greater than $n/2$ there is a node $p$ that is on all paths from $s$ to $t$.
Base case $n=3$: Let $G=(\{s,t,p\},E)$ be such that all the paths between $s$ and $t$ are strictly greater than $3/2=1$ the only possibility for $E$ is that $E=\{(s,p),(p,t)\}$ and thus $p$ is on all paths from $s$ to $t$.
Similarly for $n=4$ we obtain that the only possible graph is the line hence the property is satisfied.
Assume that the property holds for every $k\leq n$.
Let $G=(V,E)$ be a graph with $n+1$ nodes and $s$ and $t$ two nodes in $V$, such all the paths between $s$ and $t$ are strictly greater than $(n+1)/2$.
We distinguish two cases:

either there is an unique node $p$ such that $(s,p)\in E$. We have thus that $p$ belongs to all the paths from $s$ to $t$
There exists two node $s_1$ and $s_2$ such that $(s,s_1)\in E$ and $(s,s_2)\in E$. Consider the graph $G'=(V',E')$ obtained from $G$ by contracting the two edges i.e. $V'=V\setminus\{v_1,v_2\}$ and $E'= E\cap (V'\times V')\cup \{ (s,v)\mid (s_1,v)\in E,v\in V'\}\cup \{ (s,v)\mid (s_2,v)\in E,v\in V'\} $. Assume, by contradiction, that there is a path in $G'$ from $s$ to $t$ on length $l\leq (n-1)/2$ this path gives you a path in $G$ ( by expending the contracted edges) of length $l'\leq l+1 \leq (n-1)/2+1 = (n+1)/2$. Contradiction.

hence $G'$ have $n-1$ nodes and all the paths from $s$ to $t$ are strictly greater than $(n-1)/2$. Hence by hypothesis there exist a node $p\in V'$ that is on all path from $s$ to $t$. And by construction this node is also on all paths from $s$ to $t$ in $G$.
This proof also gives you for free an algorithm to find such node. Either there is an unique edge leaving $s$ and you have your node, or there are at least two edges leaving $s$: you contract two of them and start again.
I hope it helps.
Answer: @wece
Small fix needed in your proof:
In your "case two" you are deleting two vertices from $V$ (I am assuming that you meant $s_1$ and $s_2$, not $v_1$, $v_2$) and then you are saying that $G'$ has $n-1$ nodes. If you are contracting one edge, say $AB$ to vertex $A$, then you are eliminating one node (namely, $B$) and transforming all the edges $BV$ to $AV$.
So: $n$ changes to $n-2$, and all the paths from $s$ to $t$ are now obviously longer than $(n-2)/2$ = $n/2$-1. Also -- edge $s_1s_2$, if it existed, needs to be eliminated upon contraction. Thankfully, it could not have been present in any shortest path from $s$ to $t$.

Question on Graph Connectivity


how to add link to null path in menu in drupal 7

Question: I have added superfish menu in menu bar in that one of the link have sub-link. How to add a sub-link with null path.
Please help me.
Thanks
Answer: You can use the Special menu items module.

Features:

User can create a new menu item and place either "<nolink>" or "<separator>" to the Path field, without quotes.
"<nolink>" item will be rendered similar to a normal menu link item but there will be no link just the title.
You can change HTML tag used for menu item
"<separator>" item will be rendered to an item which is no link and by default title will be "-------".
Breadcrumb of "<nolink>" will be rendered same as "<nolink>" menu item.
CSS class "nolink" is added to "nolink" menu item.
CSS class "separator" is added to "separator" menu item.


Stange cache issue IIS

Question: We have a website at a hosting provider. The strange thing is that pages seem to be cached somehow by the server.Even asp.net pages...
So when i update the application , or i delete everything aspx pages still work like they were there,even i clean browser cache.I get outdated pages randomly.Only workaround is to use a proxy server .If you make a request from another ip then most of the time it gets refreshed..Something this is boring as i keep getting error when there isnt one.Any idea of any workaround and how can it be by ip ?
Answer: Are you using Output Caching?  You may want to test disabling that.  Some people get burned by this if they don't know the nuances of how it works.  Or you can disable it for only aspx pages.
Comment: server isnt mine,it is share hosted.So i am trying to guess what is happening

Stange cache issue IIS


Help with an integral equation: $\int_0^h \sinh\left(\sqrt{p^2z^2 + ptz + t^2}\right)\ \text{d}z = D$

Question: I need some help with this integral:
$$\int_0^h \sinh\left(\sqrt{p^2z^2 + ptz + t^2}\right)\ \text{d}z = D$$
$t$ is unknown constant. $h$, $p$ and $D$ are known constants
I tried Taylor series expansion dropping higher order terms. But I was wondering if it is possible to solve this using some analytical treatment. After solving this integration I should be able to get a polynomial interms of $t$. Thereafter I have to solve for $t$.
Thanks
Fir simplicity the integrand may be written as
$$\int_0^h\sinh\sqrt{Ax^2 + Bx + C}\ \text{d}x$$
Comment: 'Help' means that you've tried something yourself. Can you please share it?
Comment: Hello, The function is highly non linear. I tries talor series expansion dropping higher order terms. But was wondering if there is any analytical treatment
Comment: Welcome to Math.SE! I think you misunderstood a key aspect of this site. This is more about *helping* you find the right answer then giving you answers to arbitrary problems. For example, if you were to give us what you've tried, where you've looked, what you've read to answer the problem, and describe why you aren't satisfied/doubt what you've come across, I'm sure others would help. Also, choosing a descriptive title that described the content would help. For more, I recommend reading [How to ask a good question?](http://meta.math.stackexchange.com/q/9959/9754)
Comment: What is $E$? I don't see any $E$ in the problem...
Comment: I apologize, it should be h instraed of E. Sorry for the glitches from my side.
Comment: (If $h$ is a constant too, then there is no equation to solve) Is $B^2-4AC<0$ ?
Comment: Actually, B, A and C constants are used for normalization and consists of some unknown constants. So it's hard to figure out if B^2-4AC<0
Comment: What happens if you differentiate both sides?
Comment: Thanks for the instructions. I am new to this forum and getting used to writing the equation using scripts. Please bear with my mistakes. Thanks
Comment: This equation itself was obtained after taking integral of a differential equation. so not sure if it is going to help. thanks
Comment: When you write "*equation*", you want to find at least one *unknown* in terms of at least one *constant* (or *parameter*). Which ones, among $A,B,C, D$ and $E:=h$ are the parameters and which ones are the unknowns?
Comment: A=p^2, B=p*TAU, C=TAU^2. After solving the integral equation I should be getting a polynomial in terms of TAU. Thereafter I have to come up with an equation TAU=(...)
Answer: We shall analyse case by case. The simplest one is surely when you have
$$\Delta = B^2 - 4AC = 0 ~~~ \to ~~~ x = -\frac{B}{2A}$$
In that case:
$$\int_0^h\sinh\sqrt{\left(x + \frac{B}{2A}\right)^2}\ \text{d}x = \int_0^h\sinh\left(x + \frac{B}{2A}\right)\ \text{d}x = D$$
The integral is then trivial:
$$\int_0^h\sinh\left(x + \frac{B}{2A}\right)\ \text{d}x = \cosh\left(\frac{B}{2A} + h\right)-\cosh\left(\frac{B}{2A}\right)$$
Hence
$$D = \cosh\left(\frac{B}{2A} + h\right)-\cosh\left(\frac{B}{2A}\right)$$
Second Case
Things get really complicated when you have
$$\Delta = B^2 - 4AC > 0$$
Obtaining two solutions:
$$x_{1,\ 2} = \frac{-B \pm \sqrt{B^2 - 4AC}}{2A} = (x_1, x_2)$$
In this case the integration becomes
$$\int_0^h \sinh\sqrt{(x + x_1)(x + x_2)}\ \text{d}x = D = $$
$$ = \frac{1}{4} \sqrt{\pi } e^{-\frac{1}{4} (x_1-x_2)^2} \left(e^{\frac{1}{2} (x_1-x_2)^2} \left(\text{erf}\left(\frac{x_1+x_2}{2}\right)-\text{erf}\left(\frac{x_1+x_2}{2}+h\right)\right)+\text{erfi}\left(\frac{x_1+x_2}{2}+h\right)-\text{erfi}\left(\frac{x_1+x_2}{2}\right)\right)$$
Which you can see is really not easy. You deal with special functions, and it all depends on $h$.
Last Case
In this case we have
$$\Delta = B^2 - 4AC < 0$$
I don't feel like I can write anything explicit or sure about. So I pass.
Other possibilities
Use Taylor Series for the square root:
$$\sqrt{Ax^2 + Bx + C} = \sqrt{C\left(\frac{A}{C}x^2 + \frac{B}{C}x + 1\right)} = \sqrt{C}\sqrt{1 + Y}$$
Where
$$Y = \frac{A}{C}x^2 + \frac{B}{C}x$$
Now the square root expansions gives
$$\sqrt{1 + Y} = 1 + \frac{Y}{2} - \frac{Y^2}{8} + \frac{Y^3}{16} + \ldots$$
And you would integrate
$$\int_0^h\sinh\left(\sqrt{C}\cdot\left(1 + \frac{Y}{2} - \frac{Y^2}{8} + \frac{Y^3}{16} + \ldots\right)\right)\ \text{d}x = D$$
Then you may try at first order, second order, third order and so on.
FIRST ORDER
$$\int_0^h\sinh\left(\sqrt{c}\cdot\left(1\right)\right)\ \text{d}x = D = h\cdot \sinh\sqrt{C}$$
And so on..
Comment: Special function recall: **Error Function** (Google it).
Comment: Thanks a lot for the your detailed solution. I tried the Tylor series expansion. But as it turned out, for higher orders, it gets difficult to solve the polynomial equation for $t$. I am ckecking purturbation methods to see if i can apply that up here. Any suggestions regarding that will be appreciated. Thanks!


Partial view having switches called multiple times

Question: I have a main view where I am calling a partial view

                    @Html.Partial("_CompanyEmployeeNotifChildPartial", Model.EmployeeSMSNotifs)

                @Html.Partial("_CompanyEmployeeNotifChildPartial", Model.AdminSMSNotifs)

Following is my child view

            <input type="checkbox" name="AB_EmployeeSMS" id="@Model.AppointmentBooked" value="true" class="switch-input" checked="">
            @BookIt.Portal.Localization.Resource.cmpEmp_AppointmentBooked_Title
            <input type="hidden" name="AB_EmployeeSMS" value="false">

                @Html.SwitchFor(x => x.NewAppointmentRequest, Model.NewAppointmentRequest, "", new { name = "NAR_" + (Model.DisplayText.Contains("Employee") ? "Employee" : "Admin") + Model.NotificationType })
                @BookIt.Portal.Localization.Resource.cmpEmp_NewAppointmentRequest_Title

                @Html.SwitchFor(x => x.NewFormSubmitted, Model.NewFormSubmitted, "", new { name = "NFS_" + (Model.DisplayText.Contains("Employee") ? "Employee" : "Admin") + Model.NotificationType })

                    @BookIt.Portal.Localization.Resource.cmp_Appointment_Cancelled_Title

                @Html.SwitchFor(x => x.ClientArrived, Model.ClientArrived, "", new { name = "CA_" + (Model.DisplayText.Contains("Employee") ? "Employee" : "Admin") + Model.NotificationType })

                    @BookIt.Portal.Localization.Resource.cmpEmp_ClientArrived

                @if (Model.NotificationType == BookIt.Portal.Enums.NotificationTypes.Email)
                {

                }
                else
                {

                }

Following is how I have view Models built
  public class CompanyEmployeeNotificationsViewModel
    {
        public CompanyEmployeeNotificationsViewModel()
        {

            // Initialize lists to avoid null reference exceptions
            EmployeeSMSNotifs = new EmployeeNotificationSettingsViewModel();
            AdminSMSNotifs = new EmployeeNotificationSettingsViewModel();

        }
        public long? UserId { get; set; }
        public long CompanyId { get; set; }

        public EmployeeNotificationSettingsViewModel EmployeeSMSNotifs { get; set; }

        public EmployeeNotificationSettingsViewModel AdminSMSNotifs { get; set; }

    }

and the EmployeeNotificationSettingsViewModel as follows:
 public class EmployeeNotificationSettingsViewModel
    {
        public string DisplayText { get; set; }

        public string DisplayDescription { get; set; }
        public Enums.NotificationTypes NotificationType { get; set; }

        [Display(ResourceType = typeof(Localization.Resource), Name = "cmpEmp_AppointmentBooked_Title")]
        public bool AppointmentBooked { get; set; }

        [Display(ResourceType = typeof(Localization.Resource), Name = "cmpEmp_AppointmentRescheduled_Title")]
        public bool AppointmentRescheduled { get; set; }

        public string AppointmentRescheduledType { get; set; }

        [Display(ResourceType = typeof(Localization.Resource), Name = "cmpEmp_NewAppointmentRequest_Title")]
        public bool NewAppointmentRequest { get; set; }

        [Display(ResourceType = typeof(Localization.Resource), Name = "cmpEmp_NewFormSubmitted")]
        public bool NewFormSubmitted { get; set; }

        [Display(ResourceType = typeof(Localization.Resource), Name = "cmpEmp_ApptCancelled")]
        public bool AppointmentCancelled { get; set; }

        public string AppointmentCancelledType { get; set; }

        [Display(ResourceType = typeof(Localization.Resource), Name = "cmpEmp_ClientArrived")]
        public bool ClientArrived { get; set; }

    }

When I am saving, its not showing the correct toggle (true/false). Can you guys suggest a better way to do it and help me fix toggle.
Answer: Fixed it using the following approach with the help of chatgpt. Posting for others to benefit.
Created a Helper Method in the Main View:
@model CompanyEmployeeNotificationsViewModel

@functions {
    MvcHtmlString RenderPartialForProperty<TModel, TProperty>(
        TModel model,
        Expression<Func<TModel, TProperty>> propertyExpression,
        string propertyName)
    {
        var partialModel = propertyExpression.Compile()(model);
        return Html.Partial("_YourPartial", partialModel, new ViewDataDictionary { { "PropertyName", propertyName } });
    }
}

Used the Helper Method to Render Partial Views:
@model CompanyEmployeeNotificationsViewModel

@{
    var propertyNameEmployeeEmail = nameof(Model.EmployeeEmailNotifs);
    var propertyNameEmployeeSMS = nameof(Model.EmployeeSMSNotifs);
    var propertyNameAdminEmail = nameof(Model.AdminEmailNotifs);
    var propertyNameAdminSMS = nameof(Model.AdminSMSNotifs);
}

@RenderPartialForProperty(Model, m => m.EmployeeEmailNotifs, propertyNameEmployeeEmail)
@RenderPartialForProperty(Model, m => m.EmployeeSMSNotifs, propertyNameEmployeeSMS)
@RenderPartialForProperty(Model, m => m.AdminEmailNotifs, propertyNameAdminEmail)
@RenderPartialForProperty(Model, m => m.AdminSMSNotifs, propertyNameAdminSMS)

Retrieved Property Name in Partial Viewdirectly from the ViewData:
@model EmployeeNotificationSettingsViewModel

@{
    // Get the property name dynamically
    string propertyName = ViewData["PropertyName"] as string;
}

    Model Property Name: @propertyName


Methods for fitting a "simple" measurement error model

Question: I am looking for methods which can be used to estimate the "OLS" measurement error model.
$$y_{i}=Y_{i}+e_{y,i}$$
$$x_{i}=X_{i}+e_{x,i}$$
$$Y_{i}=\alpha + \beta X_{i}$$
Where the errors are independent normal with unknown variances $\sigma_{y}^{2}$ and $\sigma_{x}^{2}$.  "Standard" OLS won't work in this case.
Wikipedia has some unappealing solutions - the two given force you to assume that either the "variance ratio" $\delta=\frac{\sigma_{y}^{2}}{\sigma_{x}^{2}}$ or the "reliability ratio" $\lambda=\frac{\sigma_{X}^{2}}{\sigma_{x}^{2}+\sigma_{X}^{2}}$ is known, where $\sigma_{X}^2$ is the variance of the true regressor $X_i$.  I am not satisfied by this, because how can someone who doesn't know the variances know their ratio?
Anyways, are there any other solutions besides these two which don't require me to "know" anything about the parameters?
Solutions for just the intercept and slope are fine.
Comment: the Wikipedia article itself provides you the answer to this question. If you assume normality of the "true" regressor, then you need further conditions on the distributions of the errors. If the true regressor is not Gaussian, then you have some hope. See [Reiersol (1950)](http://www.jstor.org/pss/1907835).
Comment: also, what do you mean by "Solutions for just the intercept and slope are fine". Those are your only two parameters! Or were you hoping to try to back out the "true" regressor as well?
Comment: @cardinal - I meant that I didn't particularly care about the two scale parameters, and as you say, the "true" regressor $X_{i}$.
Comment: I see. That makes sense.
Answer: There are a range of possibilities described by J.W. Gillard in An Historical Overview
of Linear Regression with Errors in both Variables
If you are not interested in details or reasons for choosing one method over another, just go with the simplest, which is to draw the line through the centroid $(\bar{x},\bar{y})$ with slope $\hat{\beta}=s_y/s_x$, i.e. the ratio of the observed standard deviations (making the sign of the slope the same as the sign of the covariance of $x$ and $y$); as you can probably work out, this gives an intercept on the $y$-axis of $\hat{\alpha}=\bar{y}-\hat{\beta}\bar{x}.$
The merits of this particular approach are

it gives the same line comparing $x$ against $y$ as $y$ against $x$,
it is scale-invariant so you do not need to worry about units,
it lies between the two ordinary linear regression lines
it crosses them where they cross each other at the centroid of the observations, and
it is very easy to calculate.

The slope is the geometric mean of the slopes of the two ordinary linear regression slopes. It is also what you would get if you standardised the $x$ and $y$ observations, drew a line at 45° (or 135° if there is negative correlation) and then de-standardised the line.  It could also be seen as equivalent to making an implicit assumption that the variances of the two sets of errors are proportional to the variances of the two sets of observations; as far as I can tell, you claim not to know which way this is wrong.
Here is some R code to illustrate: the red line in the chart is OLS regression of $Y$ on $X$, the blue line is OLS regression of $X$ on $Y$, and the green line is this simple method. Note that the slope should be about 5.
<code>X0 <- 1600:3600
Y0 <- 5*X0 + 700
X1 <- X0 + 400*rnorm(2001)
Y1 <- Y0 + 2000*rnorm(2001)
slopeOLSXY  <- lm(Y1 ~ X1)$coefficients[2]     #OLS slope of Y on X
slopeOLSYX  <- 1/lm(X1 ~ Y1)$coefficients[2]   #Inverse of OLS slope of X on Y
slopesimple <- sd(Y1)/sd(X1) *sign(cov(X1,Y1)) #Simple slope
c(slopeOLSXY, slopeOLSYX, slopesimple)         #Show the three slopes
plot(Y1~X1)
abline(mean(Y1) - slopeOLSXY  * mean(X1), slopeOLSXY,  col="red")
abline(mean(Y1) - slopeOLSYX  * mean(X1), slopeOLSYX,  col="blue")
abline(mean(Y1) - slopesimple * mean(X1), slopesimple, col="green")
</code>
Comment: @Henry - I have accepted your answer. One point I would make in addition to the ones you have already made is that your simple slope is the same as the first Principal Component, based on the correlation matrix of the data.  This will certainly help with calculating standard errors
Comment: @Henry, your definition of $\hat{\beta}$ doesn't make any sense to me. Are some "hats" missing?
Comment: It is mean to be the observed standard deviation of $\{y_i\}$ divided by the observed standard deviation of $\{x_i\}$. I'll change $\sigma$ to $s$
Comment: @Henry, can you clarify some of your comments? Something strikes me as being off based on your current description. Let $\hat{\beta}_{xy}$ be the slope assuming $y$ is the response and $x$ is the predictor. Let $\hat{\beta}_{yx}$ be the slope assuming $x$ is the response and $y$ the predictor. Then $\hat{\beta}_{xy} = \hat{\rho}s_y / s_x$ and $\hat{\beta}_{yx} = \hat{\rho} s_x / s_y$, where $\hat{\rho}$ is the sample *correlation* between $x$ and $y$. Hence the geometric mean of these two slope estimates is just $\hat{\rho}$.
Comment: @cardinal: No - when I see $x = by+c$ I mean the slope is $1/b$ since it can be rewritten as $y=x/b-c/b$. When you try to draw the two OLS lines on the same graph together with the observed points (e.g. with $y$ on the vertical axis and $x$ on the horizontal axis) you have to invert one of the slopes.  So I meant that you take the geometric mean of $\hat{\rho}s_y/s_x$ and $s_y/\hat{\rho}s_x$, which is simply $s_y/s_x$. Or, if you are unconventional enough to plot $y$ and $x$ the other way round for both lines and the observed points, then you get the inverse of that as the slope.
Comment: @Henry - that's quite an interesting answer.  I don't necessarily doubt its validity, but one thing which does surprise me is that the correlation/covariance between $Y$ and $X$ is completely absent from the answer.  Surely this *should* be relevant to the answer?
Comment: @probabilityislogic: Not *completely* as I do use the sign of the correlation/covariance ;)  But the magnitude may just be noise.  In standard OLS, the noise is all assumed to be on the "dependent variable" so the predicted change in the dependent variable due to the change in the independent variable is reduced by the magnitude of the correlation.  But if you don't know where the noise is, or indeed which is dependent and which independent, then how can you decide whether to increase or decrease?
Comment: @Henry, thanks, that clarifies things a bit. Still, the methodology seems a little odd. I may think about this some more and ask another question or two.
Comment: @cardinal: To stress my original point, this is not the best way to approach the problem if you have any idea what might actually be going on.  It does dreadful things to residuals if the correlation is low.  But it is simple if you think you have absolutely no information. Plato is supposed to have said something like *ignorance is the root of all evil*.
Comment: @Henry, it seems to me that in the setting of this problem, the solution given is equivalent to assuming that $e_{y,i} = \beta e_{x,i}$ for each $i$. In an OLS setting, this method completely ignores the uncertainty in the data. It *pretends* that $y_i$ and $x_i$ are perfectly correlated and so assumes the data lie ***perfectly*** on a line, despite the fact that the data themselves contradict that. In either case, this strikes me as a very ***strong*** (and false) assumption.
Comment: @cardinal: No - the simple solution cannot make any requirement that the $e_{y,i}$ and $e_{x,i}$ are correlated.  It is discussed in section 2.4 of Gillard's historical overview linked in my original answer, and has the names "Geometric mean regression", "Reduced major axis regression", "Standardized principal component regression" or "Ordinary least products regression" in the literature, having been invented several times. I think the strongest criticism is that it can appear to provide a result where vagueness would be better, particularly when the observed correlation is weak.
Comment: @Henry, perhaps I'm having a slow last couple of days and you can find the flaw in my argument. If we fix $\hat{\beta} = s_y / s_x$, then we implicitly assume that the sample correlation between $x$ and $y$ is one. Now, this can **only** happen if $x$ and $y$ are (perfectly) linearly related. If we consider the model of this question, a simple substitution yields $y_i = \alpha + \beta x_i - \beta e_{x,i} + e_{y,i}$. The only way to get a perfect linear relationship between $x$ and $y$ is to take $e_{y,i} = \beta e_{x,i}$ for all $i$. Perhaps I'm being dense. Do you see a flaw?
Comment: @cardinal: You are thinking in OLS terms and seem to have $\hat{\beta}_{xy} = \hat{\rho}s_y / s_x$ fixed in your mind;  in OLS this minimises the sum of squares of vertical residuals, which is not appropriate here as the $x_i$ have errors.   I will put some R code in my answer to illustrate the impact.
Comment: @Henry, my argument is that they are equivalent. Independently of how one arrives at it, by making the choice $\hat{\beta} = s_y / s_x$, this is ***equivalent*** to assuming that your two observable variables $x$ and $y$ are perfectly correlated in an OLS framework. I'm, of course, basing this on the (somewhat limited) information in your post. I'll try to have a glance at the link and await your $R$ code.
Comment: @Henry, I took a quick look at your link. Notice that their (2.1) is a weak form of the relation that I noted above. That is, for unbiasedness (though I think they really meant consistency), $\sigma_y^2 = \beta^2 \sigma_x^2$ is required, which is equivalent to a second-moment version of my (stronger) requirement.
Comment: @cardinal: Gillard does mean *unbiased*. This is why I said in my original answer "It could also be seen as equivalent to making an implicit assumption that the variances of the two sets of errors are proportional to the variances of the two sets of observations"
Comment: @Henry, I'm not so sure about that. First, no model is specified for the latent variable in the surrounding text. Is it fixed (i.e., *functional* form) or random (i.e., *structural* form)? If the former, some hope remains (though I actually doubt this---but haven't done the calculation). If it's the latter, there is **no** way that I can see that $\tilde{\beta}_{\mathrm{GM}}$ would be *unbiased* for all possible distributions of the latent variable. Furthermore, the surrounding text and following math expression strongly hint that they intended to say "consistent" instead of "unbiased".
Comment: @Henry, your example is interesting. The constants are chosen "perfectly" to satisfy the only case in which the estimate could be consistent.
Comment: @cardinal: If you mean $2000/400=5$, then it was indeed deliberate.  Apart from that ratio, the constants were arbitrary. At the start of this overlong thread, all I was offering was a simple method with some basic properties.
Comment: @Henry - is there a measure of error for the slope parameter?  from my intuition it would seem to have something to do with "how far" apart the two lines are in the geometric average.  For instance, how should I test the hypothesis that the slope is zero?
Comment: @probabilityislogic: I would have thought that looking at the   [correlation_coefficient](http://en.wikipedia.org/wiki/Pearson_correlation_coefficient#Inference), taking account of the sample size, ought to tell you this.  It is a measure of how far apart the $y$-on-$x$ and $x$-on-$y$ slopes are.
Comment: @henry - so I take it that there is no standard variance formula for this slope - only my intuition to guide me?  presumably I could use the delta method, and get $var(\hat{\beta})\approx\frac{var(s_y^2)}{E(s_x)^2}$
Comment: @probabilityislogic: You are correct when saying there is no standard method for $\hat{\beta}$.  I am not sure what your formula for $var(\hat{\beta})$ is, but it may be better at this stage to ask a new question.
Comment: @Henry, how does this extend to $x$ vector, $y$ scalar --
can I just centre x¯ y¯ to 0 0, then take the hyperplane with slope $s_y, s_{xi}$
in each coordinate ?
(Shall I ask a new question ?)


Are you down if your head touches a defender who is laying on the ground?

Question: It's my understanding that if you touch the ground with your head (while in contact with a defender) you are down. Are you down if your head touches the defender who is sitting/laying on the ground (knees, elbows and rest of body have yet to contact ground)? What are the rules surrounding falling on other players?
Was watching the Bears play the Eagles when a Bear caught a pass, then touched an Eagle (who was sitting on ground) with his head, only to have the ball ripped from his possession before any other part of his body touched anything else.
Comment: No body part is touching the ground, so you are not down by rule
Answer: The player is not down because he did not touch the ground with his head. You will sometimes see runners roll over the top of other players who are on the ground and keep going if the referees have not whistled the play dead.
Answer: A player is not down until they touch the ground with something other than a hand or foot,  either after a tackle or while touched by an opposing player.
Since an opposing player is not the ground, the player is not down. Otherwise any time a defensive player touched the ball carrier, they would be at risk of being downed, since the defender is almost surely standing on the ground at the time.
In your example, this is entirely legitimate play.


Is there any way in VSCode to suggest a header file by just writing its starting letters?

Question: VSCode is not suggesting the header file after I write its starting letters. I mean that by writing "<iost" it should suggest the complete header file.
I reset my laptop earlier because of a corrupt Windows update. Before resetting, it was working completely fine. After resetting, I am now facing some problems. I code in C++.
I expect that it will work after configuring setting.json. It is continuously asking me to configure IntelliSense.
Answer: If you have the C/C++ extension installed, press Ctrl + Shift + P(or F1) to bring up the VSCode command palette, and then type "C/C++: Select IntelliSense Configuration". Afterward, press Enter and choose one of the configurations.


showing an inequality not using stirling formula

Question: I don't know how to show that
$$
\frac{k^k}{k!}\leq e^{k}
$$
without using Stirling's approximation. I want to show it directly. I guess I need some inequality to achieve this but I don't know.
Comment: Can you use $$e^x = 1 + x  + \frac{x^2}{2!} + \cdots + \frac{x^k}{k!} + \cdots$$?
Answer: The Taylor series for $e^x$ is $$e^x = \sum\limits_{n=0}^\infty \frac{x^n}{n!}$$
so for an integer $k$ we have
$$e^k = \sum\limits_{n=0}^\infty \frac{k^n}{n!} = 1+\frac{k}{1!}+\frac{k^2}{2!}+\cdots+\frac{k^k}{k!}+\cdots$$
If you don't want to use Taylor series, you could prove it with induction. All we'll need is the Binomial Theorem, some algebra skills, and a small (easy to verify) fact at the end.
Step one (starting with $k=1$):
$$e \geq 1$$
Great, let's proceed to the induction step, where we suppose that $e^k \geq \frac{k^k}{k!}$ for some (fixed) $k$ no less than $2$:
\begin{align}\frac{(k+1)^{k+1}}{(k+1)!} &= \frac{(k+1)^k}{k!} \\ &= \frac{\sum_{i=0}^k \binom{k}{i}k^{k-i}}{k!} \\ &= \sum_{i=0}^k \frac{1}{k!}\binom{k}{i}k^{k-i} \\ &= \sum_{i=0}^k \frac{k^{k-i}}{i!(k-i)!} \\
&= \frac{k^k}{k!}+\frac{k^{k-1}}{1!(k-1)!}+\frac{k^{k-2}}{2!(k-2)!}+\cdots+\frac{1}{k!} \\ &\leq e^k+\frac{e^{k-1}}{1!}+\frac{e^{k-2}}{2!}+\cdots+\frac{1}{k!} \\ &< e^k + e^{k-1} + \cdots + 1\end{align}
The last sum can be shown to be less than $e^{k+1}$ provided you can show that, for all real numbers $a \geq 2$, the inequality $a^{n+1} > a^n+a^{n-1}+\cdots+a+1$ holds for all $n \in \mathbb{N}$.
A short proof of that last claim, for those interested:

 One can easily show that $a^n+a^{n-1}+\cdots+a+1 = \frac{a^{n+1}-1}{a-1}$. Let $\alpha = \frac{1}{a-1}$. Then $a \geq 2 \Rightarrow 0 < \alpha \leq 1 \Rightarrow \alpha a^{n+1} \leq a^{n+1} \Rightarrow \frac{a^{n+1}-1}{a-1} = \alpha(a^{n+1}-1) < a^{n+1}$ since $\alpha(a^{n+1}-1) < \alpha a^{n+1}$.
Answer: If you want a somewhat elementary argument not using Taylor series, I have one that only relies on the fact that for any $x>0$ we have $\left(1 + \frac{1}{x}\right)^x < e$ (which is proved by showing $\ln(x+1)-\ln(x) < \frac{1}{x}$ using integration).
Then we have
$$\begin{align*}
\frac{k^k}{k!}
& = \left(\frac{k}{k-1}\right)^{k-1}
\left(\frac{k-1}{k-2}\right)^{k-2}
\left(\frac{k-2}{k-3}\right)^{k-3}\cdots
\left(\frac{4}{3}\right)^3
\left(\frac{3}{2}\right)^2
\left(\frac{2}{1}\right)\\
& < e \cdot e \cdot e \cdots \cdots e \cdot e \cdot e
= e^{k-1} < e^k \end{align*}
$$
Comment: I guess this is the shortest one. Thanks!
Comment: This is the weak form of Stirling inequality used to prove [Carleman's inequality](https://en.wikipedia.org/wiki/Carleman%27s_inequality#Proof) , so that is more elementary than I thought.
Answer: Both sides of the inequality are positive. So log both sides, and prove $k\ln k-\ln(k!)\le k$ :
$$\ln(k!)=\sum_{i=2}^k\ln i\ge\sum_{i=2}^k\int_{i-1}^i\ln x\,dx=\int_1^k\ln x\,dx=\left[x\ln x - x\right]_1^k =(k\ln k-k)-(-1)\ge k\ln k-k
$$
Answer: And yet another approach. First note that for $n>k$
$$ \prod_{j=0}^{k-1}\left(1-\frac{j}{n}\right)=\frac{n}{n}\frac{n-1}{n}\ldots\frac{n-k+1}{n}=\frac{n!}{(n-k)!n^k}\rightarrow 1\tag{1}$$
when $n\rightarrow\infty$ because $k$ is fixed and each term of the product converges to 1.
Therefore, since you know that (by the binomial expansion)
\begin{align} \left(1+\frac{k}{n}\right)^n&=1+\binom{n}{1}\frac{k}{n}+\ldots+\binom{n}{k}\left(\frac{k}{n}\right)^k+\ldots+\binom{n}{n}\left(\frac{k}{n}\right)^n\\
&\ge \binom{n}{k}\left(\frac{k}{n}\right)^k \\
&=\frac{n!}{(n-k)!n^k} \left(\frac{k^k}{k!}\right)\end{align}
Taking limits on both sides you have (depends on what definition you have of $e^k$ but usually this is the most elementary)
$$ e^k=\lim_{n\rightarrow\infty} \left(1+\frac{k}{n}\right)^n\ge\left(\frac{k^k}{k!}\right)\lim_{n\rightarrow\infty}\frac{n!}{(n-k)!n^k}=\left(\frac{k^k}{k!}\right)~~,$$
because of (1).
Comment: Thanks! This is also a good approach.
Comment: you are welcome
Answer: Suppose
$\frac{k^k}{k!}\leq e^{k}
$
and
$\frac{(k+1)^{k+1}}{(k+1)!}> e^{k+1}
$.
Then
$e
=\frac{e^{k+1}}{e^{k}}
<\frac{\frac{(k+1)^{k+1}}{(k+1)!}}{\frac{k^k}{k!}}
=(1+\frac1{k})^k
$.
But
$(1+\frac1{k})^k
< e
$,
as shown in many places
(including this question of mine:
What is the most elementary proof that $\lim_{n \to \infty} (1+1/n)^n$ exists?).
Therefore,
$\frac{k^k}{k!}\leq e^{k}
\implies
\frac{(k+1)^{k+1}}{(k+1)!}> e^{k+1}
$.
Since
$\frac{1^1}{1!}
< e^1
$,
$\frac{k^k}{k!}\leq e^{k}
$ for all $k$.
Comment: Thank you! Another smart way to show it.
Answer: A somewhat different approach:
In the pmf for a Poisson$(k)$ $P(X=k) = \frac{e^{-k} k^k}{k!}$ but $P(X=k)<1$ (since it's a probability).
The result follows by multiplying by $e^k$.
Comment: COOL. Thanks! Probability method. But I guess to show it is a probability we need to show this inequality.
Comment: Proofs designed for humans necessarily take some things as "given" (assumed knowledge). This relies on already having the Poisson as a distribution as "given"; whether that's acceptable depends on who you're talking to. If I'm talking to another statistician, this is a good short proof, of the form I generally call "spot the density". [To show $\frac{e^{-k}k^k}{k!}\leq 1$, however, you only need $\exp(-k)x^k/x!\geq 0$ (for all non-negative integer $x$) and that $\sum_{x=0}^\infty x^k/x!=e^k$  $\implies\sum_{x=0}^\infty e^{-k}x^k/x!=1$; whence they're *all* probabilities]
Comment: Okay. I see. Thanks.
Answer: Since
$e^x
=\sum_{n=0}^{\infty} \frac{x^n}{n!}
$,
for $x > 0$
and any integer $n$,
$e^x
> \frac{x^n}{n!}
$.
Setting $x = n$,
$e^n
> \frac{n^n}{n!}
$.


Joint density of transformed independent uniform random variables

Question: I'm taking a course in probability and struggling with transformations of random variables.  An example in the text is:
Let U1 and U2 be independent uniform random variables, both on (0,1).  Let Y1 = U1U2 and let Y2=U2.
(a) Find the joint density of Y1 and Y2.
If I calculate the inverse functions for U1 and U2, I get:
U1 = Y1/Y2
U2 = Y2
But I feel like I'm already on shaky ground because Y1 and Y2 defined over (0,1),  which makes U1 undefined at Y2=0.  Regardless, calculating the Jacobian gives my 1/Y2 - again, feels like shaky ground.
From this, the joint density should be 1/Y2 since this is defined as the product of the densities of U1 and U2 (uniform over (0,1), so densities equal 1) and the Jacobian is 1/Y2.
(b)  What is the marginal density for Y1?
If I take the integral from 0 to 1 of the density above, I get -infinity.  The integral of 1/Y2 is log(Y2), and I have to find that at 0 for the lower limit of the integral.
This seems like it should be an easy problem, but I can't wrap my head around where I've gone wrong.
Answer: Here is a rough outline to compute the joint:
$$P(Y_1 \le y_1, Y_2 \le y_2)=P(U_1U_2\le y_1, U_2\le y_2)$$
The right hand side can be re-written as:
$$P(U_1U_2\le y_1 | U_2\le y_2)\: P( U_2\le y_2)=P(U_1U_2\le y_1 | U_2\le y_2) \:y_2$$
Now, $P(U_1U_2\le y_1 | U_2\le y_2)$ can be written as:
$$P(U_1U_2\le y_1 | U_2\le y_2) = \int_0^{y_2}P(U_1 \le \frac{y_1}{y}) \: dy$$
If $y_2 \ge y_1$ then the integral simplifies to:
$$\int_0^{y_1} dy + \int_{y_1}^{y_2}\frac{y_1}{y} \: dy = y_1 +  y_1[\log(y_2)-\log(y_1)]$$
If $y_2 < y_1$ then the integral simplifies to:
$$\int_0^{y_1} dy = y_1 $$
Thus, the joint can be written as:
$$y_1 \cdot y_2 I(y_2<y_1) + y_2(y_1+y_1[\log(y_2)-\log(y_1)]) \: I(y_2\ge y_1)$$
The above can be simplified to:
$$y_1 \cdot y_2 \left\{ 1 + (\log(y_2)-\log(y_1))\: I(y_2\ge y_1) \right\} $$
I hope the above helps you start on the right track.
Comment: I think I see what you did - converted the probability to a conditional probability and recognized that Y1 <= Y2.  Can you recommend an online tutorial for these types of problems or a good probability text?  The text I have is written by the instructor and lacks explanation plus had many errors.
Comment: Starting with the joint CDF, using the conditional probability formula to simplify and then proceed further down that path is a standard approach. Recognizing how the integral depends on whether $y_2 > y_1$ or not requires some careful thinking. In general, in problems such as this it helps to be a bit careful about limits of integration as they are often a bit subtle.
Comment: I see that now.  Thanks for the post and explanation.  My text skips the explanation through the conditional and none of the worked examples require a change to the limits of integration.  A better text or resource would help.
Comment: Working through your answer, I see in the first integral the appearance of y with no subscript, sp. Y1/Y.  Was that done just to have a placeholder for Y2 which is effectively provided by the integration limits?
Comment: In that integral, $y$ is just a dummy integration variable. You can replace that with some other letter, say $x$, with the limits still going from $0$ to $y_2$. So, it would be incorrect to say that it is a placeholder for $y_2$. In fact, if anything it is a placeholder for $U_2$ as we are integrating over the possible values for $U_2$ as it ranges from $0$ to $y_2$.


Boundedness for "optional stopping"-like equation

Question: Assume $(M_n)_{n\in\mathbb{N}}$ is a martingale and $\tau \leq \rho$ bounded stopping times. I want to prove that $\mathbb{E}[M_{\rho}]=\mathbb{E}[M_{\tau}]$.
This result looks very similar to the optional stopping theorem and indeed the proof is done in the same manner. However, I was thinking why the following does not hold:
We know that for almost all $\omega \in \Omega$, $\tau(\omega) \leq \rho(\omega)$ holds and therefore
$$
\mathbb{E}[M_{\rho(\omega)}| \mathcal{F}_{\tau(\omega)}](\omega)=M_{\tau(\omega)}(\omega)
$$
by the martingale property (which again holds for almost all $\omega$). Now taking the expectation on both sides, i.e. integrating w.r.t. the given probability measure, this yields
$\mathbb{E}[M_{\rho}]=\mathbb{E}[M_{\tau}]$.
This is cannot be true, since one could prove the optional stopping theorem in the same way, without using boundedness of the stopping time. So what is my mistake in the proof above? Thanks.
Answer: Your proof is correct.
The boundness of the stopping times is needed in optional stopping theorem because the martingale $M=(M_n)$ may not converge as $n\to\infty$. In other words, if the martingale $M_n$ does not converge as $n\to\infty$ and also the stopping time $\tau$ is unbounded, then the random variable $M_{\tau(\omega)}(\omega)$ cannot be well-defined at those $\omega$ satisfying $\tau(\omega)=\infty$.
Comment: This cannot be sufficient, just take $\tau =0$ and $\rho < \infty$ a.s., then this is exactly OST, but we can find $\rho$ (satisfying the condition above) s.t. OST does not hold.
Comment: @Gabriel Sorry I'm not very good at this.  In your post you get $\mathbb E[M_\rho|\mathcal F_\tau]=M_\tau$ just by "martingale property"?  I think it is a version of optional stopping theorem.  If $\rho$ is not bounded, I think we need the uniform integrability of $M$ to make sure this identity valid.


How to check whether a vector field is Morse-Smale?

Question: Setup and notation:
Let $f:M\to \mathbb{R}$ be a Morse-function on the compact $m$-dimensional manifold $M$ and let $X$ be a gradient-like vector field for the function $f$.
Denote the unstable respectively stable manifold by $W^u_f(p)=\{x\in M\, |\, \lim_{t\to -\infty}\varphi^t(x)=p\}$ resp.  $W^s_f(p)=\{x\in M\, |\, \lim_{t\to \infty}\varphi^t(x)=p\}$ where $\varphi^t$ is the flow of the vector field $X$ and $p\in Crit(f)$ is some critical point of $f$.
We have a free $\mathbb{R}$-action (at least if $p\neq q$) on the intersection $\mathcal{M}(p,q):=W^u_f(p)\cap W^s_f(q)$ by $s\cdot x = \varphi^s(x)$.
I would like to check whether the vector field $X$ is Morse-Smale, i.e. whether $W^u_f(p)\pitchfork W^s_f(q)$ for all $p,q\in Crit(f)$.

Question: Suppose $p\neq q$ and $\mathcal{M}(p,q)\neq \emptyset$ and that the intersection is transverse at $r\in \mathcal{M}(p,q)$ (i.e. if $T_rM=T_rW^u_f(p)+T_rW^s_f(q)$).
  Does this imply that the intersection is transverse at $\varphi^s(r)$ for every $s\in \mathbb{R}$?

In other words, to check whether $X$ is Morse-Smale, is it enough to check that the intersection is transverse for any single point on each flow line connecting $p$ and $q$?
Relevant references are also much appreciated.
Answer: I'd say that the answer to your question is yes. Note that $\varphi^s$ preserves stable (resp. unstable) manifolds: $$x\in W_f^s(p)\Leftrightarrow\lim_{t\rightarrow\infty} \varphi^t(x)=p\Rightarrow\lim_{t\rightarrow\infty} \varphi^t(\varphi^s(x))=p\Leftrightarrow\varphi^s(x)\in W_f^s(p).$$ Now, since $\varphi^s$ is a diffeomorphism we have the first equality of the following line: $$T_{\varphi^s(r)}M=D_r\varphi^s(T_rM)=D_r\varphi^s(T_rW_f^u(p)+T_rW_f^s(q))=D_r\varphi^s(T_rW_f^u(p))+D_r\varphi^s(T_rW_f^s(q)).$$ Finally, since $\varphi^s$ preserves (un)stable manifolds the last sum is contained in $T_{\varphi^s(r)}W_f^u(p)+T_{\varphi^s(r)}W_f^s(q)$. The other inclusion being obvious one gets the equality we were looking for.
Comment: That's a nice argument, thanks a lot!
Comment: @Dave: You're welcome!


Deriving $\Delta z=\frac{\partial y}{\partial x}\Delta x+\frac{\partial f}{\partial y}\Delta y+\alpha\sqrt{\Delta x^2+\Delta y^2}$

Question: I was reading a math book, which contained.
"Let us consider a function $$z=f(x,y)$$
of two variables. If it has continuous partial derivatives, we can prove that its increment
$$\Delta z=f(x+\Delta x, y+\Delta y)-f(x,y)$$
corresponding to the increments $\Delta x$ and $\Delta y$ of its arguments, may be put in the form
$$\Delta z=\frac{\partial f}{\partial x}\Delta x+\frac{\partial f}{\partial y}\Delta y+\alpha\sqrt{\Delta x^2+\Delta y^2}$$
And the differential will be the first 2 summands."
Now how did they get the last expression?
Comment: That's better - I down-voted but didn't leave a comment as I was in a hurry. I needed the context you've added. Many thanks, it's helped me understand the problem. Preparing an answer now, suffice to say it's a Taylor's theorem answer...
Comment: @Bacon? Are you preparing an answer?
Comment: Is it still unclear?
Comment: What's $\alpha$?  As the question is written now, the second equation for $\Delta z$ is simply wrong.  The first order terms are correct (assuming $\partial y/\partial x$ is really $\partial f/\partial x$), but the "higher order terms" should depend on $f$.
Answer: should $\frac{\partial y}{\partial x}$ be $\frac{\partial f}{\partial x}$ I would say this is a linear approximation, i.e. like $$f(x+h)=f(x)+hf'(x)+O(h^2)$$ but in two dimensions.
The $\sqrt{\Delta x^2+\Delta y^2}$ is a radius of point $(\Delta x, \Delta y)$, i.e. the distance from original point $(x,y)$
which plays the role of $h$ in this case. The $\alpha$ comes from the definition of $f=O(h)$ which means there is exists an $\alpha$ such that $f\le \alpha h$ and as you can see the equality in your expression should be changed by $\approx$.
Comment: This looks like a Taylor expansion.
Comment: exactly! i.e. Taylor expansion is infinite series, but when you truncate it you get a linear, quadratic, cubic etc approximation.
Comment: But then there is no need for $\approx$, equality sign is sufficient.
Comment: with $O$ notation you should use the equality, but not in your form, unless you have very special $f$
Answer: As the question is written now, the second equation for $\Delta z$ is simply wrong.  The first order terms are correct (assuming $\partial y/\partial x$ is really $\partial f/\partial x$), but the "higher order terms" should depend on $f$.
Perhaps the equation was supposed to say:
\begin{equation}
\Delta z = \frac{\partial f}{\partial x} \Delta x + \frac{\partial f}{\partial y} \Delta y + o\left(\sqrt{\Delta x^2 + \Delta y^2}\right).
\end{equation}
(In this corrected equation we're using little-o notation.)
Comment: Yea, but proof? Also, why that little-o notation? Is there a pun intended?
Comment: @AdityaAgarwal No pun intended, it really is called [little-o notation](http://mathworld.wolfram.com/Little-ONotation.html).  I suspect that in the book you're looking at, the $\alpha$ was a typo.
Comment: No in single variable differential also, $\alpha$ was used.


Fitting model AR(1) with R

Question: I've sampled 100 variables from a Gauss distribution with mean 0 and standard deviation 1.
> set.seed(1)
> wn=rnorm(100)

Then I've fitted an AR(1) model with the arima command and sent the results to the wnF variable
> wnF=arima(wn, order=c(1,0,0))

Finally I've requested the estimated coefficients
> wnF$coef
         ar1    intercept
-0.003655755  0.108935363

Now I want to replicate the computation R. I exported the data to an Excel file (https://www.dropbox.com/s/6c8ukcbtxe9gqp1/DataTester.xlsx?dl=0) and computed the following model:
$$
x{_t}-\mu = \psi_1x_{t-1}+\omega_t
$$
I've replaced $\mu$ and $\psi_1$ with the intercept and ar1 coefficients reported by the wnF$coef command. I've also replaced $\omega_t$ with zero, since I've sampled the data from a zero-mean population.
Finally I've compared the residuals from the R computed model (wnF$residuals) with the residuals I've computed in the Excel file and I've noticed that they differ about $\delta<0.0005$ in absolute value.
I know that 0.0005 is not much, but when dealing with such small values it may not be negligible.
I also find strange that there is no difference up the fourth decimal place.
Can you please help me finding the origin of the difference?
Comment: @Repmat the estimates of AR coefficients produced by `lm` (what I assume you mean by "LM") are not maximum likelihood estimates and will not be the same as those produced by `arima`.
Comment: You should have $x_t-\mu=\psi_1(x_{t-1}-\mu)+w_t$, that is, you should include the mean not only on the left hand side but also on the right hand side. Also, $w_t$ need not be zero, or actually, it should not be zero.
Comment: Subtracting the mean on the right side greatly improved the model. The difference between R computed residuals and Excel computed residuals is now less than 0.000001. Regarding $\omega_t$, I really don't know how to estimate it.
Comment: @Eduardo if you wish to estimate an AR(q) model in R, why not just use the LM command? It is much more (IMO) intuitive than the arima-command.
Answer: After some research I found out that the difference between R computed residuals given by wnF$residuals and the residuals I've computed externaly in Excel file, was originated from the lack of precision of the data passed to Excel.
At first, I had passed data to Excel with only 7 decimal places. After repeating the procedure with 15 decimal places, the difference almost disapeared.
Also, as Richard Hardy commented, the model I was fitting was not correct. The correct model is:
$$
x_t-\mu=\psi_1(x_{t-1}-\mu)+\omega_t
$$

Fitting model AR(1) with R


How to set mongod.conf bind_ip with multiple ip address

Question: I am a newbie for setting up the server environment and mongoDB. This may sounds something really simple, however, I really need your help on it.
I am trying to connect to my virtual machine which runs the mongodb instance from the local machine, which I believe should be similar to the production environment when I run it on a separate remote server.
The environment is as following:

Private IP for virtual machine: 192.168.184.155
Public IP for both local machine and virtual machine: 126.96.36.199

I changed the bind_ip in /etc/mongod.conf file from
bind_ip = 127.0.0.1

to
bind_ip = 127.0.0.1,192.168.184.155,188.8.131.52

After I restarted the mongod service, neither the virtual machine nor the local machine can access mongodb through mongodb command and giving me the following error.
MongoDB shell version: 3.0.1
connecting to: test
2015-03-17T16:02:22.705-0400 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-03-17T16:02:22.707-0400 E QUERY    Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
    at connect (src/mongo/shell/mongo.js:179:14)
    at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed

However, if I change the
bind_ip = 192.168.184.155

and restart the service, it works and I can access using mongo from my local machine. It seems just not work with multiple ip addresses. I tried to do look up in the mongodb document, however, they does mention that bind_ip takes a comma separated list, which really confused me.
Thanks for your help in advance.
Comment: What if you use bind_ip = 127.0.0.1,192.168.184.155? To me 22.214.171.124 is not a valid IP on your VM
Comment: @anhlc It's the same result. Once I have added more than one ip address, none of them works. Any ideas?
Comment: Can you get the parsed command line options from the log when you boot mongod? It really should work, so I wonder if there's some weird VM networking obstacle here?
Comment: Hi @wdberkeley, thank you so much for bring it up! I checked the log file and find out the problem! It seems I happened to add a space before the next ip address, which crash the whole thing.
Comment: I agree with wdberkeley, it's _always_ worth checking the log file, to see if there are any clues there about what is going wrong.
Comment: I would recommend to set `bindIpAll: true` Using `bindIp` with an IP address is useful when you have a machine with several network interfaces, otherwise it does not make much sense in my opinion. Exception is `bindIp: localhost` when you like to prevent any external connection, typically used while maintenance work.
Comment: A public IP is typically achieved by your router using [NAT](https://en.wikipedia.org/wiki/Network_address_translation), i.e. your local computer does not know this address and thus it does not make any sense to bind such an IP.
Answer: Wrap the comma-separated-Ips with brackets works in mongo 3.2.7 for me:
bindIp = [127.0.0.1, 192.168.184.155, 126.96.36.199]

Comment: Don't know why this was downvoted but this seems to be norm now
Comment: there shouldn't be the brackets or spaces after the commas anymore. it's also bind_ip instead of bindIp. this is for ubuntu might be different for other systems...
Comment: Both joe-cheng's and @puneet-goyal's solutions work. With spaces brackets are needed, without spaces just a comma-separated list works.
Comment: In my case it didn't work 3.6 here. It added bracked as part of the IP.
Comment: bindIp: 127.0.0.1, 10.8.0.1   # works for centos 7.4, mongo 3.6
Comment: I get: Jun 02 19:04:31 mongod[23698]: Scalar option 'net.bindIp' must be a single value
Jun 02 19:04:31 mongod[23698]: try '/usr/bin/mongod --help' for more information
Comment: I am using latest version. The above solution did not work for me
Comment: none of these work on mongodb 6
Answer: With the following version of MongoDB:
MongoDB shell version v3.6.10
Reproducing Problem:
When [127.0.0.1,xxx.xxx.xxx.xxx] is used we get the following error.
    Scalar option 'net.bindIp' must be a single value
    try 'mongod --help' for more information
Analysis
This is because, according to MongoDB Documentation: https://docs.mongodb.com/manual/reference/configuration-options/#net.bindIP
net.bindIP is of type "string".
Solution for binding multiple IP Addresses
bindIp: "127.0.0.1,xxx.xxx.xxx.xxx"

Note: No spaces after commas
Comment: doesnt work for mongo 6.0
Comment: it worked for mongo 4.4.8 version
Comment: still work for mongo 6.0
Comment: Not works for MongoDB 7.0 (demands ; - semicolon divider)
Answer: You can do that by:
bindIp: [172.31.60.184,127.0.0.1]

Remember to not put a space after the comma.
Comment: What version of MongoDb are you using? I'm trying with 2.6 and this does not seem to work (list with comma, no space) nor the version with brackets.
Comment: This does not work on `db version v3.2.12
git version: ef3e1bc78e997f0d9f22f45aeb1d8e3b6ac14a14 Ubuntu 16.04`.  Using the brackets in answer below works
Comment: for some reason this '[172.31.60.184,127.0.0.1]' does not work in version 3.6.8. what worked for me was modifying /etc/mongodb.conf and inserting:
binding_ip = 172.31.60.184,localhost
that will bind to the first ip sepecified and to the localhost.
Answer: The default /etc/mongod.conf file has this entry for network interfaces:
# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1

This corresponds to the --bind-ip arg parameter on the command line. Notice the dash notation converted to camel case. To expose the database running in a VM to the host, it's simplest to bind the database to all interfaces for testing purposes. This will cover situations where the VM is using a NAT interface or bridged interface. The command line parameter is --bind_ip_all which does not have a parameter, it's existence corresponds to the bindIPAll: true parameter in the configuration file. Therefore, the configuration file should be changed to:
# network interfaces
net:
  port: 27017
  bindIpAll: true

Notice the bindIp parameter is removed.
It should also be noted that it is possible to add parameters to the command line that override parameters in the config file. Normally, mongod is run with the --config /etc/mongod.conf parameter. It's easier to change the config file instead of hunting down the script what runs it as a daemon and getting systemd to reload and use it.
For details on the YAML-ness of the config file vs. parameters on the command line, see the documentation currently at https://docs.mongodb.com/manual/reference/configuration-options/
If you are running mongod on a VM using NAT, the default port 27017 will not be exposed to the host. It will be necessary to map a port on the host to this port in the guest VM. That's beyond the scope of this answer, but a little research will provide a method used for the VM software you are using (VirtualBox, VMware, etc.)
Answer: In my case, with mongoDB 4.4.6 following solution worked -
net:
  port: 27017
  bindIp: 127.0.0.1;<private_host_ip>

After making changes, restart mongoDB with following command -
sudo systemctl restart mongod

To Check mongoDB status, run -
sudo systemctl status mongod

Comment: This works with the config. but I am not able to run the mongo shell it is throwing error `connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:372:17`
Comment: @KartikGarasia - Please send detailed error log, or may be screenshot of your mongo conf file.
Comment: This works for MongoDB shell version v4.0.28
Comment: Doesn't appear to work with MongoDB shell version v4.4.9
Answer: MongoDB 6.0.1
bindIp: 127.0.0.1;192.168.1.0

After change just restart mongodb server:
sudo systemctl restart mongod

Comment: Didn't work for me using 6.0.0
Comment: as per documentation: "enter a list of comma-separated values". so replace semi-colon. (@Dylee try this way)
Answer: In my case the solution was to put the comma separated IP and without any spaces.
bind_ip=192.168.2.29,127.0.0.1
#port = 27017

That way worked:
2018-10-02T07:49:27.952+0000 I CONTROL  [initandlisten] options: { config: "/etc/mongodb.conf", net: { bindIp: "192.168.2.29,127.0.0.1", unixDomainSocket: { pathPrefix: "/run/mongodb" } }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongodb.log" } } 2018-10-02T07:49:27.954+0000 I -    [initandlisten] Detected data files in /var/lib/mongodb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.

Mongo 3.6.3 here.
mongod --version
db version v3.6.3
git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
OpenSSL version: OpenSSL 1.1.0g  2 Nov 2017
allocator: tcmalloc
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64
Answer: Thanks for @wdberkeley and @anhlc brought up the clue.
I looked at the log file under /var/log/mongodb/mongod.log. It shows the failing reason for the problem.
2015-03-17T16:08:17.274-0400 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1, 192.168.184.155" }, storage: { dbPath: "/var/lib/mongodb" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2015-03-17T16:08:17.332-0400 I NETWORK  [initandlisten] getaddrinfo(" 192.168.184.155") failed: Name or service not known

So the mongo.conf file is sensitive to space, which I happened to add and should have noticed. Also just as @anhlc pointed out, 126.96.36.199 is not a valid IP address for VM. So that one also contribute to the error.
Great thanks for both of your help! Hope this may help if someone happened to run into the same problem.
Comment: You mean we should write something like this: `bind_ip=127.0.0.1 192.168.184.155 220.127.116.11` i.e. space separated instead of comma separated?
Answer: I successfully added a second ip on my version 3.2 service using a comma, no spaces and an FQDN
net:
  port: 27017
  bindIp: localhost,dev-2.office.sampleorg.com

Answer: I am running 3.6 on SUSE 12.x and had an issues using comma separated IP lists. I fixed the issue by
        bindIp: 0.0.0.0
Comment: 0.0.0.0 will work because you aren't binding to any server which essentially binds it to your Public IP and can potentially expose your database to the public. Will work, but bad idea.
Comment: I still think it is a bit hacky. It is basically allowing any IP address that gains access to the local server. For 3.6, the safest way would be to `bindIp: 127.0.0.1, xxx.xxx.xxx.xxx` and under that `bindIpAll: true` <-- default value is false.
Comment: Thanks i was having same problem none of the above and below solution worked but yours +1
Comment: Don't think so. 0.0.0.0  is a non-routable meta-address. In the context of servers, 0.0.0.0 means "all IPv4 addresses on the local machine".
Comment: Not a great idea, it will expose your database.
Comment: Not sure, how? can you give me an example?
Comment: Wow... don't do this ! It will let any IP address to access your DB.
Answer: In Mongo 3.*,
use a bracket such as
net:
    port: 27017
    bindIp : [127.0.0.1,10.0.0.2,10.0.0.3]

Answer: The case in mongodb version 3.6 on my Ubuntu16.04 LTS is that you do not need to put the IP addresses in the square brackets "[]". Delete the space after the comma solve the failed connection problem in the mongod log (/var/log/mongodb/mongod.log)
NETWORK  [initandlisten] getaddrinfo(" xxx.xxx.xxx.xxx") failed: Name or service not known

After modify the bindIp: 127.0.0.1 to bindIp: 127.0.0.1,xxx.xxx.xxx.xxx (notice no comma between IPs), the host IP is listening as below:
xxx@xxxx:/var/log/mongodb$ sudo netstat -plnt |egrep mongod
tcp        0      0 xxx.xxx.xxx.xxx:27017   0.0.0.0:*               LISTEN      30747/mongod
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      30747/mongod

Answer: Ubuntu 16.04 -> MongoDB shell version: 2.6.10
For me the following works:
bind_ip = [127.0.0.1;X.X.X.X]
Notice I have a ; not ,
Comment: Ubuntu 14 with mongo 2.6 also works like this. Thanks finezza
Answer: The bindIp rule with comma separated IP addresses is only meant for known ethernet interfaces, or for the 0.0.0.0 and 127.0.0.1 rules. You can only use the ip addresses of your system's Network Interface Cards. If this list contains an unknown IP address, i.e. an IP of another system, your MongoDb instance will not restart and hence you're not able to connect. To check if your MongoDb instance is running, run the following:
$ sudo systemctl status mongod

If you would like to make your MongoDb instance available to other systems on your network, you'll want to bind the local IP associated with the private network. To determine network interface configuration easily, just run an ifconfig from the command line:
$ ifconfig

This will list all available IP addresses that you can use in the bindIp rule. Most certainly, the IP address 184.108.40.206 that you use is not a valid IP address or unknown by your system.
Answer: Amazon-linux2 | Cent OS | MongoDB shell version: 3.0.15
This is how it needs to be done in the latest config
#network interfaces
net:
  port: 27017
  bindIp: [xxx.xxx.xxx.xxx,127.0.0.1]  # Listen to local interface only, comment to listen on all interfaces.

Cheers!!
Comment: Error: Scalar option 'net.bindIp' must be a single value
Answer: For 4.4.6, so - lets assume for series 4.x (perhaps for some of series 3.x)
The correct syntax is:

bindIp: 127.0.0.1,<private_host_ip>,<public_host_ip>

For each new IP just use , and without any spaces
For LAN access must be used the private_host_ip, you can use ipconfig or ip a for Windows and Linux respectively to know the ip value.
Of course for public WAN access must be used <public_host_ip>, it about your ISP
Warning both ips - private_host_ip and <public_host_ip> - are the locations where your MongoDB server is running, not the remote clients. Therefore exists the wrong assumption to add each new ip where each one represents the remote client IP address (other different than the server IP address - LAN and/or WAN), it is not correct.
Note To avoid problems is better for both use static ips, the private through your router and the second through your ISP.
Answer: Here I resolve this issue using bellow code. my mongod version 4.4.21.
# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1, <your_server_ip>
  bindIpAll: true

After Changes restart the mongod service
sudo service mongod restart

To verify the connection write bellow code in your local system terminal
nc -zv <your_server_ip> 27017

Output :
Connection to <your_server_ip> port 27017 [tcp/*] succeeded!

Answer: With MongoDB server version: 3.6.8 plain comma separated list worked for me. With or without spaces after comma.
bind_ip = 127.0.0.1, 192.168.0.104
bind_ip = 127.0.0.1,192.168.0.104

However, adding enclosing in [] fails with following error in MongoDB log
bind_ip = [127.0.0.1,192.168.0.104]
getaddrinfo("[127.0.0.1") failed: Name or service not known

bind_ip = [127.0.0.1, 192.168.0.104]
getaddrinfo("[127.0.0.1") failed: Name or service not known

Answer: This worked for my mongo v4.2.15:
vi /etc/mongod.conf
net:
  port: 27017
  bindIp: 127.0.0.1;X.X.X.X;Y.Y.Y.Y

sudo systemctl restart mongod
Answer: net:
  port: 27017
  bindIp: 127.0.0.1;188.8.131.52

This for MongoDB 4.4, CentOS 7
Answer: If all you want to do is connect to this machine over the network you do NOT need to modify the bind_ip value.
In your case you need to follow the following steps.

Setup the remote machine to block all connections to port 27017
Enable remote machine to only accept connections from your local machine
Setup credentials with MongoDB
Connect with client using credentials.

If you are not sure how to do any of this steps. Check out a blog post that I wrote that goes more in details how to do this.
Blog Post
Hope this helps.
Comment: that doesn't make any sense at all.
Comment: i downvoted this answer because its wrong. An example why, consider a private network. Network security prevents unauthorized access to the mongo cluster. But the clients need to be bound to the private interface for it work. but, you in circumstance you may need to bind localhost as well for statistics, maintenance etc. bind all would be dangerous, even with credentials. my webservers connect to my mongo cluster over private network interface (local subnet) much safer than public internet.
Comment: Your answer and blog post are not relevant to the OP's question - which was about issues with configuring bind_ip on a virtual machine.
Comment: What part? He wants to access a machine from a public location simple networking.
Comment: Make sure that if you downvote this answer you post why?
 https://youtu.be/Jsb-9iM_tiw


Lost access to permissions checkboxes at admin/config/group/permissions/node/

Question: Not sure what happened. I'm using Drupal 7.15 and the latest OG dev version (2.x) and for some reason, I lost access to all permissions checkboxes at admin/config/group/permissions/node/ - It's not even showing them in read-only mode, they are just not there.
I do have OG access control and field access modules enabled and I haven't done much but trying to create a new group and new content.
Rebuilding permissions or uninstalling the modules completely didn't help.
Any idea?
Answer: I think I found a corresponding bug: http://drupal.org/node/1649186


Como fazer para que o tamanho da fonte se ajuste automaticamente ao tamanho de uma div

Question: Olá, tenho uma div de 300px por 300px, nela eu deixo um texto que vem de um banco de dados, o problema é que tem vezes em que o texto dentro da div ultrapassa o tamanho da mesma, deixando invavel para impressão. Eu preciso saber se tem como redimentcionar automaticamente o tamanho da fonte para que o texto da div nunca ultrapasse 300px de altura e nem de largura.
veja como o problema em
http://jsfiddle.net/xVB3t/1747/
Answer:

$(document).ready(function() {
    $('#conteudo').textfill({
        maxFontPixels: 12
    });
});
#conteudo {
    width: 300px;
    height: 300px;
    border: 1px solid red;
}

        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum consequat at tortor sit amet euismod. Pellentesque dapibus bibendum felis, sit amet consectetur eros condimentum in. Cras efficitur tellus id lectus sagittis tincidunt. Aliquam imperdiet sem at laoreet elementum. Curabitur aliquam gravida varius. Praesent id pulvinar nulla. Mauris ultricies iaculis augue bibendum consequat.

        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum consequat at tortor sit amet euismod. Pellentesque dapibus bibendum felis, sit amet consectetur eros condimentum in. Cras efficitur tellus id lectus sagittis tincidunt. Aliquam imperdiet sem at laoreet elementum. Curabitur aliquam gravida varius. Praesent id pulvinar nulla. Mauris ultricies iaculis augue bibendum consequat.

Utilizei o plugin jQuery textfill. Ele redimensiona a fonte de acordo com a div. Realizei alguns testes com o preview de impressão do Chrome e no IE 11 e manteve o tamanho da fonte.
Comment: Aqui ta tudo fora da div no seu snippet.
Answer: Para resolver esse problema das palavras ultrapassarem a div, você pode usar a propriedade overflow: auto;
No seu exemplo ficaria assim:
div {
    font-size: 100%;
    border: 1px solid red;
    height: 200px;
    width: 200px;
    overflow: auto;
}

Veja no JSFiddle.
Comment: De fato, até hoje só vi com JS mesmo. E nenhum muito simples não.
Comment: Oi Tais. Ele pede uma div fixa 300x300. O texto é que precisa diminuir automaticamente.
Comment: @Bacco, acho que não tem como fazer isso só com CSS.
Comment: @Bacco, pois é, com JS tem como, mas eu não sei qual o objetivo dele. Na minha opinião, pensando na usabilidade, é melhor o usuário dar um scroll, do que a letra diminuir o tamanho.
Answer: Também da para fazer ajustando o scaleY do conteúdo dentro do container:

$(function() {
  $('.container').each(function() {
    var scaleY = $(this).height() / $('.conteudo', this).height(),
      translateY = (($('.conteudo', this).height() - $(this).height()) / 2) * -1;
    $('.conteudo', this).css({
      '-webkit-transform': 'matrix(1,0,0,' + scaleY + ',0,' + translateY + ')',
      '-moz-transform': 'scaleY(1,0,0,' + scaleY + ',0,' + translateY + ')',
      '-ms-transform': 'scaleY(1,0,0,' + scaleY + ',0,' + translateY + ')',
      '-o-transform': 'scaleY(1,0,0,' + scaleY + ',0,' + translateY + ')',
      'transform': 'scaleY(1,0,0,' + scaleY + ',0,' + translateY + ')'
    });
  });
});
.container {
  float: left;
  font-size: 100%;
  border: 1px solid red;
  height: 200px;
  width: 200px;
  margin-right: 10px
}

    Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe

    Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola
    Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe Hola Pepe

Answer: tenta isso aqui a função se chama "Viewport Sized Typography" ou em termos chulos texto escalonável tela visualização da tela.
p {font-size: 16px; font-size: 4vw;}

consulte mais informações e outras funções em
https://css-tricks.com/viewport-sized-typography/
olha um exemplo
http://jsfiddle.net/8TrTU/2037/
Comment: Eu preciso de acordo com o tamanho da div, eu até achei uma forma parecida que funcionava mais ou menos usando `font-size: 2.6vmin;` mas só ajuda a fonte de acordo com a janela e não de acordo com a div
Comment: usa % em vez de um valor https://css-tricks.com/almanac/properties/f/font-size/
Comment: Colocando porcentagem até que vai, mas quando o texto e muito pequeno a fonte continua pequena não se ajusta.
Comment: agora é questão de ajuste, da uma lida nisto aqui https://web-design-weekly.com/2014/11/18/viewport-units-vw-vh-vmin-vmax/
Comment: postei um ex q eu fiz no fiddle
Comment: Bom cara, abri seu exemplo coloquei um texto com 100 palavras e a fonte não diminuiu de tamanho permaneceu igual e a div não manteve o tamanho inicial ela estouro de tamanho.
Comment: entendi vou ver se acho alguma solução
Answer: Nesses casos o bom é usar em ao invés de px para o tamanho da fonte, você pode ver mais sobre isso aqui: http://www.w3schools.com/cssref/css_units.asp.
Também, o texto não deveria estourar o container dele, a menos que não existam espaços nesse teu texto, então no container use a propriedade word-wrap (http://www.w3schools.com/cssref/css3_pr_word-wrap.asp).
Caso não resolva teu problema, poste aqui teu código para podermos ajudar mais...
Comment: Já tentei assim mudando as unidades de medidas, não funcionou :(
Comment: posta como está o teu código então, tanto o html como o css
Comment: editei coloquei um link para o jsfiddle com o meu problema
Comment: eu havia compreendido o seu problema de forma errada @joaopaulosantosalmeida, a princípio não sei se existe uma solução para fazer isso de forma efetiva, mas vou dar uma olhada...


What is the best Web Application Firewall for IIS?

Question: What is the best Web Application Firewall(WAF) for IIS? What makes it better than the others? How useful is it at blocking attacks against poorly written code, otherwise known as an Intrusion Prevention System (IPS)?
WAFs are required by the PCI-DSS, so if I have to get one, then it should the best one.
Comment: If you think a firewall will protect you from attacks against poorly written code you have some interesting days ahead of you. :)
Comment: Please note that in new regulations provided to ASVs from the PCI security council this month, detection of an IPS/IDS that affects the results of the scan is an instant PCI fail. So ensure that you choose one that allows you to whitelist your ASV's source addresses.
Comment: Can you indicate where in the PCI documentation it indicates that a WAF is required? I'm not convinced this is true, without a reference.
Comment: @Cheekysoft,  your right, it does however require an IPS or IDS and HTTP/HTTPS is the only thing open on the server.
Comment: Product and service recommendations, including 'best' research, are off topic per the updated [FAQ](http://serverfault.com/faq).
Answer: That is an extremely open ended question.  A firewall can be software or hardware, free or tens of thousands of dollars.  It really depends on your needs and budget as far as "best".
Of course, in the end, when you say "best", I say: Cisco.
Note that the term "web application firewall" also means different things to different people.  To Cisco, it seems to mean an xml-targeted system.  You may actually need a more general purpose firewall like something from the ASA series.  These issues of security are multifaceted, and I'm not a PCI-DSS expert, so I'm not completely sure of the nuances with your request.  However, I can tell you that whatever you need, Cisco has it, and it probably rocks, if you'll forgive the superlative.
Comment: A web application firewall is a stateful inspection service that looks for popular attack patterns and stops them.
Answer: I have tested a number of different Web Application Firewalls from many the major hardware and software vendors. None of them have really had any noteable affect on my ability to manually expose the problems in vulnerable web applications.
They are getting pretty good at stopping the kind of attacks that worms, or unseasoned attackers may try, but a determined human attacker can always easily tweak his attack vector such that it no longer trips the IDS. They all essentially match requests against regular expressions, looking for common attack patterns. But they are so easy to get around.
Only consider a device like this as an additional layer to your security. Do not consider one to save your developers from writing vulnerability-free code, or save your admins from keeping systems and software regularly updated and patched. I can tell you for free that they won't stop people getting at your SQL injection or cross-site scripting vulnerabilities.
Comment: Agreed with anonymous; Non-vulnerable code doesn't really exist and a layered approach to security is a great idea. It is also always important to understand what each layer achieves.
Comment: Writing vulnerability free code is impossible.  So then would it also be true that you should put up as many obstacles as possible.
Comment: @Cheekysoft, your right, the pci-dss does however require an IPS or IDS and HTTP/HTTPS is the only thing open on the server.
Answer: First of all, I'm not sure where you doubters have been for the last few years, but the requirement for a WAF in PCI is one part of requirement 6.6, and it's been the most talked about requirement of the last few years. (I would post a link, but since I'm new I can only post one link per message, and I'm saving it. Just google "6.6 PCI WAF" and you'll have a thousand results).
As for which is "best", best is a very relative term. Try to find the one that best fits your needs and budget. If you want a starting point, there's a brief writeup of the major players here:
http://www.docstoc.com/docs/9687629/WAF
Answer: I'm with Cheekysoft, but I'd also regularly scan my Web applications for vulnerabilities with Nessus, Nikto, and (haven't tried yet but heard good things) with Google's recently released SkipFish.  You may also be able to make your own informed decision from The Open Web Application Security Project (OWASP) guide to Web Application Firewalls:
http://www.owasp.org/index.php/Category:OWASP_Best_Practices:_Use_of_Web_Application_Firewalls
Answer: I have tried several top of the line WAFs.  Some come built-in with load balancers (think F5, Zeus).  Others are dedicated, stand-alone WAFs.  Tested numerous ones by actually running AppScan against known vulnerable web code.  The top performer for me was Imperva's SecureSphere WAF.  You're going to pay through the nose for it, but in terms of raw security, logging, and customizability, it's currently the best.  You can get it virtual or physical appliance, each with their advantages.  They have very strict licensing, and are pricey, but their logging capabilities and their signature updates are hard to beat.
We also code test the applications themselves using AppScan and WebInspect both.  As has been mentioned, doing WAF + code review is best because you can't get 100% with either method alone.  This is very different than IDS/IPS systems which is looking mostly at layer3 traffic, not at layer7 where most attacks are successful nowadays.  There are also cloud-based WAF protections (security as a service) which offer the same protection but for much less investment.
Answer: Larry Suto recently did an analysis of WAFs which you might find interesting. I have no connection to him, but Imperva did well. http://www.manvswebapp.com/wp-content/uploads/Analyzing_Effectiveness_of_Web_Application_Firewalls.pdf
For some balance, Ofer Shezaf, who was at Breach Security for several years and has been a contributor to the open source ModSecurity has some concerns about Larry's methodology, i.e. lack of testing WAF's ability to detect evasion techniques
http://www.xiom.com/2011/11/17/larry_suto_strikes_again
I have no connection to Ofer Shezaf either.
Full disclosure - My company is an information security solution provider and we selected Imperva's SecureSphere. Imperva also offers a cloud-based WAF that's not as functionally rich as SecureSphere, but faster to deploy and easier to administer.
Answer: For IIS consider Microsoft Threat Management Gateway (was ISA server).  It is geared towards IIS and it is one of only three firewalls that have EAL4 + rated (the other two being ASA/PIX and Checkpoint).  You can either install it on your own commodity hardware, or buy it as an appliance such as made by Celestix.
Answer: At the end of the day I am shakey on if webknight is legit for the long haul or not.  But in all honesty their app kicks most of the paid apps I have worked with in the butt.
I am not paying 13 trizzilion dollars for an isapi extension, many people seem glad to pay this.
We need to rally on the webknight dude and help update his software if he needs it.  Too bad he doesn't publish on codeplex or somewhere where we can help easily.


Simple exponential smoothing

Question: I simulated a time series using expressions (3.10a), (3.10b) from (Hyndman et al., 2008). Next, I'd like to use a simple exponential smoothing method to forecast for the next period.
For a given initial point $\hat{y}_1$ I obtained the smoothing parameter $0<\alpha<2$, etc.
My question is as follows: am I going to predict the next value of the local level $l_t$ or the next value of the observed time series $y_t$? Regretfully, I still do not understand how one can predict a quantity which includes a random component, and if I got it right, time series without trend consists of level and such a component.
Answer: For simple exponential smoothing,
\begin{align*}
y_t &= \ell_{t-1} + e_t \\
\ell_t &= \ell_{t-1} + \alpha e_t,
\end{align*}
where $e_t$ is a white noise error. So the forecast of $y_{t+1|t}$ is also a forecast of $\ell_{t+1|t}$. That is, both conditional distributions have the same mean, and the forecast is an estimate of that mean.
Everything you want to predict has a random component, otherwise you would know its value and there would be no need to predict it. Forecasts are just estimates of the means of conditional distributions.

Simple exponential smoothing