Kind of counter intuitive sum of log gamma

Question: I came across an infinite series that appears to be rather counter intuitive.
Show that $\displaystyle \sum_{k=1}^{\infty}(-1)^{k+1}\ln(\Gamma(k+1))=\frac{-1}{4}\ln\left (\frac{\pi}{2}\right)$
At first glance, it obviously diverges.  I ran this through Mathematica for a check and that is what it said, "sum does not converge".
But, I ran it through Maple as $\displaystyle \sum_{k=1}^{\infty}(-1)^{k+1}\ln(k!)$ and it actually returned the above result.  Mathematica still would not.
If I entered it in using the Gamma function instead of its equivalent factorial, it would not return the result.
What is going on here?.  I presume this has something to do with analytic continuation of some sort?.
Since $k!=\Gamma(k+1)$,  why would Maple return the result for the factorial but would not for the Gamma even though they are essentially the same thing?.
It reminds me of $\zeta(0)=\frac{-1}{2}$.
If we just let $s=0$ in $\displaystyle\sum_{k=1}^{\infty}\frac{1}{k^{s}}$ we get an infinite string of 1's.  But, using the functional equation, it can be shown to converge to -1/2.
How can the above sum be shown to equal $\frac{-1}{4}\ln\left (\frac{\pi}{2}\right)$?.
I searched all around for something on this, but could find nothing.
Thanks all.  I hope you find this as interesting as I have.
Comment: Ignore this as off-topic: Your question reads like a poem :)
Comment: What version of Maple you use?
Comment: I have an old version. 9.5
Answer: This sum converges in Abel summation sense:
$$ \sum_{k=1}^{\infty} (-1)^{k-1} \log (k!) = \lim_{x \uparrow 1} \sum_{k=1}^{\infty} (-1)^{k-1} x^{k} \log (k!). $$
Let us evaluate the sum inside the limit.
\begin{align*}
\sum_{k=1}^{\infty} (-1)^{k-1} x^{k} \log (k!)
&= \sum_{k=1}^{\infty} (-1)^{k-1} x^{k} \sum_{n=1}^{k} \log n
 = \sum_{n=1}^{\infty} \sum_{k=n}^{\infty} (-1)^{k-1} x^{k} \log n \\
&= \sum_{n=1}^{\infty} \frac{(-1)^{n-1} x^{n}}{1 + x} \log n \\
&= \frac{1}{x+1} \sum_{n=1}^{\infty} (-1)^{n-1} x^{n} \int_{0}^{\infty} \frac{e^{-t} - e^{-kt}}{t} \, dt \\
&= \frac{x}{x+1} \int_{0}^{\infty} \left( \frac{e^{-t}}{1 + x} - \frac{e^{-t}}{1 + x e^{-t}} \right) \, \frac{dt}{t} \\
&= - \frac{x^{2}}{(x+1)^{2}} \int_{0}^{\infty} \frac{e^{-t} (1 - e^{-t})}{1 + x e^{-t}} \, \frac{dt}{t} \\
& \xrightarrow{x \to 1^{-}} -\frac{1}{4} \int_{0}^{\infty} \frac{e^{-t}(1 - e^{-t})}{t(1 + e^{-t})} \, dt.
\end{align*}
To evaluate the last integral, we introduce
$$ I(s) = \int_{0}^{\infty} \frac{e^{-t}(1 - e^{-t})}{t(1 + e^{-t})} e^{-st} \, dt. $$
Differentiating,
\begin{align*}
I'(s)
&= - \int_{0}^{\infty} \frac{e^{-t}(1 - e^{-t})}{1 + e^{-t}} e^{-st} \, dt \\
&= - \int_{0}^{1} \frac{u^{s} - u^{s+1}}{1 + u} \, du \qquad (u = e^{-t}) \\
&= - \int_{0}^{1} \frac{u^{s} - 2u^{s+1} + u^{s+2}}{1 - u^{2}} \, du \\
&= - \frac{1}{2} \int_{0}^{1} \frac{v^{\frac{s-1}{2}} - 2v^{\frac{s}{2}} + v^{\frac{s+1}{2}} }{1 - v} \, dv \qquad (v = u^2) \\
&= \frac{1}{2} \left[ \psi_{0}\left( \frac{s+1}{2} \right) - 2 \psi_{0} \left( \frac{s}{2} + 1 \right) + \psi_{0} \left( \frac{s+3}{2} \right) \right].
\end{align*}
So we have
$$ I(s) = \log \left( \frac{\Gamma\left(\frac{s+1}{2}\right) \Gamma\left(\frac{s+3}{2}\right)}{\Gamma\left(\frac{s}{2}+1\right)^{2}} \right) $$
and the sum is equal to
$$ \sum_{k=1}^{\infty} (-1)^{k-1} \log (k!) = -\frac{1}{4} I(0) = -\frac{1}{4} \log \left( \frac{\pi}{2} \right). $$
Comment: Wonderful, SOS.:)
Answer: An idea: put
$$C:=\sum_{k=1}^\infty(-1)^{k+1}\log(k!)\Longrightarrow e^C=e^{\sum_{k=1}^\infty(-1)^{k+1}\log(k!)}=\prod_{k=1}^\infty (-1)^{k+1}k!$$
Try now to google (or directly in Wolfram) "Barnes G-Function", "Hyperfactorial function", etc. It is an old, but by no means trivial or even easy, result
Comment: Continuing with this idea, [zeta regularization](http://mathworld.wolfram.com/Zeta-RegularizedProduct.html) would tell us that $C = -\hat{\zeta}'(0)$, where $\hat{\zeta}$ is the function defined by $$\hat{\zeta}(s) = \sum_{n=1}^{\infty} \left((k!)^{(-1)^{n+1}}\right)^{-s}.$$  No clue if this gets us anywhere.
Comment: Thanks for the comments.  I will look into it. If I find anything I will let you know.
Answer: I asked some others about this problem and they are adamant that the given closed form is wrong.  The series obviously diverges.
I do not know where this problem originally came from nor why Maple gives its numerical equivalent. Perhaps a bug in Maple?.
Anyway, thanks all.
Answer: If you use the Cesaro Sum or the Borel Formula this divergent series actually converges numerically to the value calculated in Maple, which is a little funny.
So far I failed to calculate a closed form for this sum.
Answer: Thanks a lot SOS. I always appreciate your input and clever solutions.
Anyway, sometime back, I combined consecutive terms to make it work.
The sum, as is, is certainly divergent. So, combine terms to try to make it convergent.
Let $\displaystyle S=\sum_{k=1}^{\infty}(-1)^{k+1}log(\Gamma(k+1))$
$=\displaystyle\frac{1}{2}\sum_{k=1}^{\infty}\left[(-1)^{k}log\Gamma(k)+(-1)^{k+1}log\Gamma(k+1)\right]$
$=\displaystyle\frac{1}{2}\sum_{k=1}^{\infty}(-1)^{k}log\frac{\Gamma(k)}{\Gamma(k+1)}$
$=\displaystyle\frac{1}{2}\sum_{k=1}^{\infty}(-1)^{k+1}log(k)$
This is still divergent, so combine terms again:
$S=\displaystyle\frac{1}{4}\sum_{k=1}^{\infty}\left[(-1)^{k+1}log(k)+(-1)^{k}log(k+1)\right]$
$=\displaystyle\frac{1}{4}\sum_{k=1}^{\infty}(-1)^{k}log\left(1+\frac{1}{k}\right)$
It now converges.
This is the log of the Wallis product formula $\displaystyle log(\frac{\pi}{2})=\sum_{k=1}^{\infty}(-1)^{k-1}log\left(1+\frac{1}{k}\right)$.
That comes from $\displaystyle\prod_{k=1}^{\infty}\frac{(2k)^{2}}{(2k-1)(2k+1)}=\frac{\pi}{2}$
This is a known sum that now equals $\displaystyle\frac{-1}{4}log(\frac{\pi}{2})$
Comment: I also considered that technique, but I decided not to try it because I wanted to show that the sum is indeed *summable* in some sense. But once we know that the sum is summable in some summation sense that possesses regularity, linearity and stability as listed in [this article](http://en.wikipedia.org/wiki/Divergent_series#Properties_of_summation_methods), then your solution is justified, which is of course the case.


How to create a module wide variable that refreshes every page load?

Question: What is the best way to create a variable that is accessed by the different views of my module (block, page etc), but that is destroyed at every new page request?
I've been using variable_set to store information that is used throughout my module, but this seems to persist across page requests.  Is there a hook I can implement to call variable_del for every outgoing page, or is there a better way of storing variables in my module that do not persist across page loads?
Answer: The variable_set() and variable_get() functions are made to set/get a persistent variable. So they should not be used to persist data within a single page request. The drupal_static() function is made for this task and is well documented. Off course, you could also go with a static variable without bothering about drupal_static(). But drupal_static() will make your code more maintainable and future proof.
/**
 * Set or get the shared foo variable.
 *
 * @param $new_value
 *  (optional) If set, the new value to assign to the foo variable.
 *
 * @return
 *  The value of the foo variable. If $new_value is set this would be
 *  the previous value.
 */
function MODULE_foo($new_value = NULL) {
  $value = drupal_static(__FUNCTION__, NULL);
  $previous_value = $value;
  if ($new_value !== NULL) {
    $value = $new_value;
  }
  return $previous_value;
}

Answer: Not only does variable_set persist across pages, it nukes the cache every time it is called.  It should only really be used for settings, and similar read-mostly uses.
If you read my answer to Where do I declare a global variable?, I outline a few methods that should work.  I typically use the method,
function foo_get_the_service ()
{
  static $service;

  if (! isset($service)) {
    $service = foo_init_the_service();
  }

  return $service;
}

which works well for me when I really do need a global.
Comment: In Drupal 7, the drupal_static() function should be used instead of static variable. This allow other modules to clear the value if needed (think of a batch or CLI script that want to re-use your code). In Drupal 6, the good practice is to provide a, optional $reset argument to let the caller clear the value.
Comment: @Pierre.Vriens (1) I left the comment. (2) The answer was flagged for moderator attention, and I handled it by leaving a mostly templated  response and downvoting.  I did not seek out that question or answer or go through your activity looking for a way to annoy you. Nearly everything moderator-related I do here is flag driven. (3) I will review the edit and potentially remove the downvote (and maybe even upvote it), but you really need to understand it may not happen immediately or even the same day.
Comment: @Pierre.Vriens (4) I don't know what you mean to accomplish by leaving a comment on a 5+ year old answer where I even told the OP to **accept the other answer**.  You could have downvoted it; you could have cast a delete vote; you could have flagged for moderator attention; you could have flagged it as a duplicate; you could have edited it and improved it.  But you left the comment above.  What do you think I should do to improve that answer?
Comment: @Pierre.Vriens This answer is perfectly tailored for the question being asked, which doesn't even shows code or give more details about the type of variable that needs to be accessed from different hooks. It's not the same as your answer.
Comment: @Pierre.Vriens A link in an answer is **never** a problem. The problem is with the answer being a link-only answer, or a _See this other answer, and replace any occurrence of "banana" in that answer with "mango"_ answer.  Links are allowed, as long as they aren't spam links.


¿A Dedekind-infinite set $X$ has a countable subset, and a proper subset equipotent to $X$, but both with intersection empty?

Question: In a more detailed way,
Definition: A set $X$ is said to be Dedekind-infinite if it has a proper subset $A$ equipotent (similar/in bijection) to $X$.
Let $X$ be a Dedekind-infinite set. Does it exists  $A, B$, subsets of $X$ such that,  $A\sim X$, $B\sim \mathbb{N}$ and $A\cap B=\emptyset$?
If not, what conditions are needed to ensure this?
In this case $U\sim V$ means "There is a bijective function $f:U\rightarrow V$".
The question comes to me and I think it's true; I can't find a counterexample.
Also, I think, the proposition is intuitive. The set of natural numbers is the "least" inductive set, and then, the first infinite set, and it has that property.

Thanks in advance
Answer: The answer is yes. The key observation is that any countably infinite set $A$ can be partitioned into two countably infinite subsets $A=A_1\sqcup A_2$ - this is just Hilbert's Hotel - and of course we then have $A\sim A_1\sim A_2$.
So suppose $X$ is Dedekind-infinite. I claim that $X$ has a countably infinite subset $A$. Before proving this, let's see why this is helpful: if $A\subset X$ is countably infinite, write $A=A_1\sqcup A_2$ as above. Then $A_2\cup (X\setminus A)\sim X$ (why? because $A_2\sim A$!), $A_1\sim\mathbb{N}$, and $[A_2\cup (X\setminus A)]\cap A_1=\emptyset$.
So now we just have to show that a Dedekind-infinite set has a countably infinite subset. Let $f: X\rightarrow X$ be injective but not surjective, and let $x\in X\setminus ran(f)$. Now think about the sequence $x, f(x), f(f(x)), f(f(f(x)))$, ... It's a good exercise to show that this sequence never repeats - that is, for $m\not=n$ we have $f^m(x)\not=f^n(x)$. So this defines a countably infinite subset of $X$, namely $\{f^n(x): n\in\mathbb{N}\}$.


no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits>::value_type {aka Sommet}' and 'int')

Question: I know I'm probably just stupid and that this error comes from not overloading something but I just can't seem to find a way out of this mess...
Especially since its a code I already used in the pasted that never gave me problems...
The code in itself is pretty simple (a basic BFS) and the error comes on line 524

    std::vector<Sommet> Graphe::BFS(int val_s0)
{
    std::queue<Sommet> maListe;
    std::vector<Sommet> predecesseurs;
    for(auto elem: m_sommet)
        elem.set_couleur(false);

    Sommet s;
    for(int i=0; i<m_ordre; i++)
    {
        predecesseurs.push_back(s);
    }
    Sommet s0 = m_sommet[val_s0];
    maListe.push(s0);
    m_sommet[val_s0].set_couleur(true);
    while(!maListe.empty())
    {
        Sommet top = maListe.front();
        maListe.pop();

        top = m_sommet[top.get_id()];

        for(auto elem : top.getAdj())
        {
            if(m_sommet[elem.get_id()].get_couleur() == false)
            {
                maListe.push(elem);
                m_sommet[elem.get_id()].set_couleur(true);

                 ///ERROR at following line
                predecesseurs[elem.get_id()] = top.get_id();
            }
        }
    }
    return predecesseurs;
}

Answer: You are trying to assign an ID to a vector element of type Sommet. You should either make your predecesseurs a vector of ints and store IDs there, or keep it a vector of Sommet objects, and set the actual objects into it.
Note that your current code pushes an empty predecessor in the loop, which may not be what you are looking for.


Validate JTextField

Question: How do I validate JTextField for a personal number? For example, I would like it to validate something formatted like 841017-4567.
Answer: Read up on JFormattedTextField and MaskFormatter.
JFormattedTextField phoneField = new JFormattedTextField(new MaskFormatter("######-####"));

Comment: @Hovercraft Full Of Eels I think he was confused because I edited the question to fix some grammar, so it probably looked like I answered my own question.

Validate JTextField


Inserting other column data into new row

Question: I have a database with columns id, begin, end, route.  Is there a way to select the max or previous rows end column value and insert it as the new row's begin value?
ID  Begin  End   Route
1     1    10     SW
2    10    21     NE
3    21    55     S

What I am trying to do is this...
INSERT INTO log ('id', 'begin', 'end', 'route')
VALUES (DEFAULT, MAX('End"), 'xxx', 'xxx')

Comment: Can you please provide sample data and desired results?
Comment: There is a way.  But without knowing the layout of your data, it is really hard to say more.
Answer: You'll need the MAX function to select the maximum value.
SELECT MAX(*column name*) AS *alias* FROM *table name*;

sgeddes and Slowcoder have provided answers for the INSERT statement.
Answer: Given your edits, something like this should work using max with insert into select:
INSERT INTO log (`begin`, `end`, `route`)
SELECT MAX(`End`), 'xxx', 'xxx'
FROM log

Condensed Fiddle Demo

Please also notice the use of backticks vs single quotes.  Use the backticks to delimit fields.
Comment: I get the following error.  "#1248 - Every derived table must have its own alias"
Comment: @the1Texan -- this query doesn't use any derived tables (subqueries).  That error generally means you to alias your subquery.  What's your query?
Comment: INSERT INTO `log`(`ID`, `begin`, `end`, `route`) VALUES (DEFAULT,(SELECT maxend FROM (SELECT MAX(`end`) FROM `log`),'5000.1','SW')
Answer: Try something like this.
INSERT INTO log (`id`, `begin`, `end`, `route`) VALUES (DEFAULT, (SELECT MAX(end) from log), 'xxx', "xxx');

Comment: @aphextwix -- well, that too won't work either without tricking mysql with a subquery.  Here's an example: http://sqlfiddle.com/#!2/d0b00b/1
Comment: This isn't valid sql syntax -- just because the OP writes it, doesn't mean we should copy it!
Comment: Why isn't it valid? Just curious.
Comment: @aphextwix -- before the edits, single quotes instead of backticks -- after the edits, double quote still needs to be removed --> `"xxx'` won't work either.  Getting closer though...
Comment: @sgeddes - Oh but the actual syntax of using a sub-query for the `SELECT` is fine though?
Comment: @sgeddes is right.  The select query won't work here without a different table alias.  http://stackoverflow.com/questions/8333376/you-cant-specify-target-table-table-name-for-update-in-from-clause


What does Hamming mean by "we live in $L_2$"?

Question: In 1980, Hamming wrote [0]:

We live in what the mathematicians call $L_2$ — the sum of the squares of the two sides of a right triangle gives the square of the hypotenuse.

What does $L_2$ means in this context? Note: 2 is written as a subscript for L.
Obviously, the part following the dash refers to the Pythagorean theorem.

[0] Richard W. Hamming, The Unreasonable Effectiveness of Mathematics, The American Mathematical Monthly, Volume 87, Number 2, February 1980.
Comment: More often than not [two is a superscript](https://en.wikipedia.org/wiki/Lp_space).
Answer: $L_2$ here means the so-called "$L_2$ norm". A norm is a way to give a length to a vector. If we have vector $v=(v_1, ..., v_n)$, its length in the $L_p$ norm is $||v||_p=(|v_1|^p + |v_2|^p + ... + |v_n|^p)^{1/p}$. For $p=2$ we get the length as given by the Pythagorean theorem. In particular, this is the way we see distance in our world.
Answer: $L_2$ is a norm on vector spaces. Very loosely speaking, given two orthogonal vectors $u$ and $v$ in a vector space, a norm on that space is a notion of length in that before space, and the the difference between the $L_a$ norms is the relationship between the lengths of $u, v$ and $u+v$.
$L_2$ is the norm where the relationship is given by the Pythagorean theorem. $L_1$ is the norm where the length of the sum is equal to the sum of the lengths. And $L_\infty$ is the norm where the length of the sum is the length of the longest of the two.
Comment: You'd call it the $L_2$-norm, but by just $L_2$ you usually refer to the space which is equipped with that norm.
Answer: It means that distance in our world is $L^{2}$ metric, i.e. Euclidean norm, which satisfies the Pythagorean theorem. For example, if a right triangle with base length 3 and height 4, then we know that its hypotenuse has length 5, by the Pythagorean theorem.
More generally, if we have two point $(x_{1}, y_{1}, z_{1})$ and $(x_{2}, y_{2}, z_{2})$ are given in our real world (you may have to set a coordinate for this), then the distance between two points is given by
$$
((x_{1}-x_{2})^{2} + (y_{1}-y_{2})^{2} + (z_{1}-z_{2})^{2})^{1/2}
$$
by the Pythagorean theorem.
In general, we can define $L^{p}$ metric for $1\leq p \leq \infty$, which is given by
$$
d_{p}(P_{1}, P_{2}) = ((x_{1}-x_{2})^{p} + (y_{1}-y_{2})^{p}+(z_{1}-z_{2})^{p})^{1/p}
$$
for $1\leq p<\infty$ and
$$
d_{\infty}(P_{1}, P_{2}) = \max\{|x_{1}-x_{2}|, |y_{1}-y_{2}|, |z_{1}-z_{2}|).
$$
In honest, the Hamming's claim is not true for some situations. For example, we can draw a triangle on the earth where all the length of the sides are equal but the angles are all 90 degrees. This situation occures because earth is not flat, which is a special case of non-euclidean geometry.


What are the pros/cons of the "tuning-in-slide" method of trombone design?

Question: Almost all American-made trombones are tuned using a tuning slide in the crook of the bell section. However, some European instrument makers sell trombones designed with a one-piece crook and a mechanism for tuning the instrument in the handslide.
What are the pros and cons of each style of trombone design?
Answer: Actually, American manufacturers (notably Conn and Olds) produced slide-tuning instruments well into the 1960s.  The design lasted longest in bass trombones (the Olds P24 and Conn 7xH).  S. E. Shires currently produces a slide-tuning alto and makes slide-tuning slides for tenors and basses on special order.  Kanstul makes a slide-tuning bass in its 1662 series and 1670 series, and a slide-tuning tenor in its 1688/1608 series.
Slide tuning has a substantial advantage for bass trombones because it allows a longer continuously tapered bell section.  Trombones are roughly 1/3 tapered and 2/3 cylindrical tubing.  A Bb/F bass trombone with slide tuning (and NO provision for bell tuning) can have a tapered tubing proportions that are approximately correct for the F side.  Of course, then it's too long for the Bb horn.  Slide tuning also allows for a longer slide section.  The Conn 62 has an in-tune low C without worrying about going off the inner slides.  Other instruments (notably the Bach 50) have the low C (on the F side alone) perilously near the end of the slide.  Shires went to slide tuning on his alto so that the instrument would have solid low A and E.  Other altos are notorious for having these notes almost off the slide.
Slide-tuning has two primary disadvantages.  First is weight: including the tuning mechanism in the slide necessarily increases the outer slide's weight.  More weight means more inertia means a slower slide.  Modern designs have much lower weight penalties than the designs of the 1960s.  The other problem is slide alignment.  A slide tuning instrument has more moving parts, which theoretically make it vulnerable to alignment problems.
As with all things musical, it is a matter of paying your money and taking your choice. Slide tuning and bell tuning trombones have different timbral and playing characteristics. Having a conical bell section generally gives a warmer sound than that of a bell tuning instrument. However, the conical bell section is very open and may require more air and effort from the player at louder dynamics.


Combining the results of two surveys

Question: Someone has surveyed a number of people and put the results in a database (Survey 1). Each observation has additional information that, for any subpopulation (men only, young only, etc.), gives a national-level estimate of the number of people in that subpopulation, as well as a confidence interval for that estimate. As expected, the sum of the estimates for mutually exclusive subgroups (number of men plus number of women) gives the estimate for the total number of people in the population.
I don't know how the survey was conducted, the sampling method, etc. All I have is the database. All estimated counts coming from the database are assumed to be log-normally distributed.
Someone else has done another survey (Survey 2). A lot more people were interviewed. This survey was not meant to estimate anything -- it was just meant to give information on those people who were interviewed.
For the population as a whole, and for any subpopulation, Survey 2 gives an undercount, since not everyone in the population was interviewed. Often, the estimate based on Survey 1 is greater than the count from Survey 2, but that's not always the case.
Question: What is the best way to combine the information from the two surveys? I am fine with an approximate solution.
If I only had Survey 1, my point estimate for the number of people in subpopulation A would be E(A). However, from Survey 2, I know that A > $min(A)$. So should I be computing E(A|A > $min(A)$)?
Doing so leads to a contradiction. Namely, the sum of estimated counts in mutually exclusive subpopulations comes out to be greater than the estimated count for the entire population.
Thank you for your help. I hope this is clear. If not, please ask, I will try to explain. :-)
Comment: You need to weight survey 2 to the whole population, but how to do this (and whether it is even possible) depends on the sampling method.
Comment: Hi, can you give an example of what you wish to do with the combined data. Depending on your objectives, something like a synthetic combined dataset might work.
Comment: I just want to give the best estimates of counts within whatever subpopulation someone asks about. This is particularly an issue when a count from Survey 2 is greater than the estimate from Survey 1. I cannot give Survey 1 estimate because it is clearly wrong. And I cannot just give a Survey 2 count because I know it to be an undercount.
Comment: As I explained in [your other question](http://stats.stackexchange.com/q/22172/7224), the use of conditioning is inappropriate in this case.
Answer: To be able to estimate to a population from a survey, the sampling method needs to be understood. The sampling method is used to create the sampling weights, which are then used to basically multiply up the survey estimates to be population estimates. There are all sorts of ways of creating weights, but they need to be based on the survey design.
If you don't have the survey design information and/or you don't know how the weights were constructed, the key pieces of information you need to create the population-level estimates are missing. In particular for the two surveys, you need to be confident that the sampling method was appropriate, e.g. no quotas were used to stop sampling people of a particular age/sex combination, a convenience sample wasn't used. If either survey had these particular characteristics in the design, any population estimates (and even subpopulation estimates) are going to be wrong.
There are some aspects of your question that I don't understand. For example, why do you wish to combine the two surveys - did they ask different questions? And surveys don't routinely sample the entire population - when that happens, we call it a census, so I don't understand your comment about the second survey.
Can you give any more information about the survey design, and also if there are weights in the datasets and what these weights look like?
Update for clarity: I am not sure that survey 2 will add anything other than bias to survey 1. In your question you state that survey 2 was not meant to estimate anything - that makes it sound like survey 2 has a convenience sample design. When dealing with convenience samples, it is not possible to weight up to the population because the sampling method used is biased rather than random. For example, a survey of supermarket shoppers at 10am on a weekday is biased (it will undercount full-time workers and overcount adult females, for example). With a biased sample it is not possible to weight the data to take account of the bias because the probability of being sampled is unknown for some groups, and may even be zero for others, but you don't know what these probabilities are. Therefore it is impossible to construct weights to account for the sampling when a biased sample has been used.
Because it sounds like survey 1 has the better design for population estimation, I recommend that you use survey 1 for your estimates.
Comment: Survey one must have been weighted to population and it sounds like there are at least instructions on creating confidence intervals from it so perhaps we can assume that was done correctly.  You need to do the same for survey two.  Then you have two estimates which are just independent random variables and you can take a weighted average of the two as your combined estimate.  But this will only work as Michelle says if the sampling method for two was random and in a known fashion that can be taken into account in weighting; and the weights for survey one are appropriately constructed.
Comment: * We can assume that the surveys were done correctly.
* I want to combine both surveys because I want to get the best estimator possible. As I mentioned, when the estimate from 1 is greater than the count from 2, you could just forget about 2 and go with 1. But when the count from 2 is greater than the estimate from 1, I don't think either can be used directly.
* Yes, Survey 1 has weights. Survey 2 does not. 2 is a "census" but not of the whole population of interest. That's why I said that it provides undercounts.
Comment: @Jessica: "Survey 2 is a 'census' but not of the whole population of interest." Does that mean that it was an attempt at a census that fell far short due to non-response, or that it was a census of a particular sub-population that you want to use to assist Survey 1 which was a sample of the entire population?
Comment: It was a census of a particular sub-population.
Answer: It looks like your survey 2 is a convenience sample. I don't know what it can be useful for. Without a clear sampling strategy, you cannot generalize to the population in any meaningful way. At best, you might be able to utilize Survey 2 to build a model of how variables are interrelated, and then try to improve your estimates from Survey 1 using some sort of generalized regression estimation but to get there, you need to make sure your sample is not biased.
For instance, suppose you want to predict how much income taxes can be collected in the economy. Suppose you use something like the US Current Population Survey as your survey 1. This is a very well designed survey, with weights, poststratification, bells and whistles, whatever have you. Then you also have a survey that you hand out in the local unemployment offices, and only hope that most people will write something in. This is your survey 2. You don't know how well it reaches to your population -- in all likelihood, you are more likely to reach those who are seeking jobs more actively, and show up in the local offices more often. You won't reach the frustrated workers who quit looking for a job, or those who are not eligible for the unemployment benefits but would be looking for a job otherwise, some seasonal workers, and a number of other people. You don't know any of that though: somebody just handed you Survey 2 and said, "This is our rich data base, make sense out of it". Well, this is a biased sample to begin with. If you fit a regression model of individual's earnings using this data set, you will likely get wrong estimates: the sample censors out those with higher earnings in full time, permanent jobs, and probably has way more people with low education than there are in general population. So what's the use of Survey 2 for you? As I said, I doubt it has much value in this purpose.
It is not helping at all that you give zero background information about what the survey is about, what sampling units are, etc. I understand that you are probably bound by your employer, or your client, or whatever form of supervisor you have. But without more detail, all we can give you is some sort of handwaving advice. I can point you to technical literature about combining information from several surveys (using Bayesian or empirical likelihood methods), but I am not sure it will help much at this point.
Comment: In the past, I have seen reports based on convenience samples say "x% of respondents", and then watched people interpret that to mean "x% of the population".

Combining the results of two surveys


Calculate the definite integral

Question: Calculate the following integral:
$$
  \int^3_{-3}\left(\frac{\arctan(\sqrt{|x|})}{1 + (1+x^2)^x} \right)dx
$$
I know that each function can be represented as a sum of even and odd function such that:
$$
f(x)=\frac{f(x) + f(-x)}{2} +\frac{f(x) - f(-x)}{2}
$$
I tried using this approach and separate the function but I'm mainly confused with the evenness and oddness of the numerator of the function.
If my approaches is correct, how can I properly separate the function?
Comment: Use https://math.stackexchange.com/questions/439851/evaluate-the-integral-int-frac-pi2-0-frac-sin3x-sin3x-cos3x/439856#439856
Answer: Let $u=-x\implies du=-dx$: $$I=-\int_3^{-3} \frac{\arctan\sqrt{|u|}}{1+(1+u^2)^{-u}} dx \\ = \int_{-3}^3 \frac{(1+u^2)^u \arctan\sqrt{|u|}}{1+(1+u^2)^u} du$$ And now comes the 'Add $I$ to itself' trick: $$I+I = \int_{-3}^3 \frac {\arctan\sqrt{|x|}}{1+(1+x^2)^x} dx + \int_{-3}^3 \frac{(1+x^2)^x\arctan\sqrt{|x|}}{1+(1+x^2)^x} dx \\ = \int_{-3}^3 \arctan\sqrt{|x|} dx \\ =2\int_0^3 \arctan \sqrt x dx\\ = 2x\arctan \sqrt x \big |_0^3 -\int_0^3 \frac{\sqrt x}{x+1} dx \\ \overset{x=u^2}=6\arctan\sqrt 3 -2\int_0^{\sqrt 3} \frac{u^2+1-1}{u^2 +1} du \\ =6\arctan\sqrt 3 -2 \big[ u-\arctan u \big]_0^{\sqrt 3}\\ = \frac{8\pi}{3}-2\sqrt 3 \\ \implies I =\frac{4\pi}{3} -\sqrt 3 $$
In general, this technique can be used for doing complicated integrals like $\int_a^b f(x) dx $ such that $f(x) +f(a+b-x)$ can be easily integrated.
Answer: The following is always true
$$\int_{-a}^a \frac{\operatorname{even}(x)}{1+\operatorname{even}(x)^{\operatorname{odd}(x)}}dx = \int_0^a\operatorname{even}(x)dx$$
Comment: @Dave just interchange $x\leftrightarrow-x$ and add the two integrals together
Comment: @Dave A more in depth explanation can be found in [this video](https://www.youtube.com/watch?v=xiIsPEqyTqU).
Comment: If you don't mind, I shall reuse this beautiful formula. Cheers :-)
Comment: Could you give hint how you come up with this?
Comment: @Claude not a problem! Cheers :)

Calculate the definite integral


arm trustzone monitor mode switch design

Question: the basic world switch flow is:
set FIQ to monitor mode

normal world -> FIQ triggered

-> enter monitor mode (do switch to Secure world, restore Secure world context)
-> in Secure world sys mode
-> FIQ is not clear, enter FIQ handler in Secure world

step3 and step 4, after we restore the target context,
arm will trigger the exception to enter the exception
is the behavior correct? (if we dont branch to FIQ handle in monitor mode vector table)
we need flow like below:
(no world context switch case, just enter monitor mode to check  if we need world switch, and enter irq exception from monitor mode directly. we need this because of our hw limitation, we only have IRQ in our chip)
set IRQ to monitor mode

normal world user mode -> IRQ triggered

-> enter monitor, do something we want to hook, check if we need context switch, prepare some spsr/lr for IRQ mode

-> enter normal world IRQ mode, irq handling
-> irq done, return back to user mode

for non-world switch case, we would like to let the normal world os does not know about the monitor mode, just though he enters the irq mode directly and return from irq mode.
for world switch case, just switch it in the monitor mode.
or it's just do the irq_handle in the monitor mode?
eq.
normal world OS usr mode ->   irq                                    -> usr mode
normal world OS usr mode -> monitor to irq handler -> usr mode
is the flow possible and well design?
Comment: It might help if you cited a specific SOC that you are using (and provided a link to a reference PDF)?
Comment: it's a non-popular SOC. In our develop environment, GIC only have IRQ connection to arm core, without FIQ . we would like to run two os in each world. Linux on normal world, rtos on secure world. Both OS have individual interrupts, basically we want them run separately. ARM has one recommend design, IRQ for normal world FIQ in normal world switch to secure world vice verse. But we have only IRQ, so we need to seek if any good solution for IRQ only case.
Comment: I believe that 'group 0' interrupts are FIQ and 'group 1' are IRQ.  Ie, you classify the interrupts with the DIST in the GIC to be either secure or normal (and therefore FIQ/IRQ).  The documents aren't clear on what 'group 0' and 'group 1' mean  (See **GICD_IGROUPR** and **GICC_CTLR** w. bit `FIQEnb`).  You may have to re-write some RTOS code, especially the system timer to be independant.  Also any 'pinctrl' in Linux needs to sync with the RTOS (for security and race reasons).
Comment: thank you very much, i understand. i will also check the FIQ of GIC status in the SoC.
Comment: The term 'FIQn' is a physical line.  Your hardware might not have this.  To be clear, the **regular** interrupt sources can be routed to either IRQ or FIQ.  As I remember, the GICC_CTRL.FIQEnb will cause group 0 to be all FIQ, but it maybe different for some versions of GIC.
Answer:
is the flow possible and well design?

It is possible.  'well designed' is subjective.  It has several fails or non-ideal issues.  I guess your system doesn't have a GIC; which is a trustzone aware interrupt controller.  The GIC has banked registers which allow the normal world OS to use it (almost) as if it was in the secure world.
It is not clear from you question whether you want the secure world to have interrupts?  I guess from the statement 'for non-world switch case...'.  If you only have interrupts handled by the normal world, things are simple.  Don't branch to monitor mode on an IRQ (or FIQ).  There is a register to set this behaviour (SCR/security configuration register).
For the dual world interrupt case, you have two issues.

You need to trust the normal world OS.
Interrupt latency will be increased.

You must always take the interrupt in monitor mode.  The monitor must check the interrupt controller source to see what world the interrupt belongs to.  It may need to do a world switch depending on the world.  This will increase interrupt latency.  As well, both the normal and secure world will be dealing with the same interrupt controller registers.  So you have malicious security concerns and non-malicious race conditions with multiple interrupt drivers trying to manipulate registers (RMW).  Generally, if your chip doesn't have a GIC, but the CPU supports TrustZone, the your system hasn't been well thought through for TrustZone use.  The L1/L2 cache controllers must also be TrustZone aware and you possible have issue there as well.
If you have Linux (or some other open source OS in the normal world), it would be better to replace the normal world interrupt driver with a 'virtual' interrupt driver.  The normal world virtual IRQ code would use the SMC instruction to set virtual registers and register IRQ routines for specific interrupts.  The secure world/monitor IRQ code would then branch directly to the decoded IRQ routine.

With a GIC, set the group 0 (secure world) interrupts as FIQ and group 1 (normal world) as IRQ using the GICC_CTLR bit FIQEnb.  Ie, you classify the interrupts with the DIST in the GIC to be either secure or normal (and therefore FIQ/IRQ).
You have to work through scheduling issues and how you want the different OS's to pre-empt.  Normally (easiest) is to always have the secure OS running, but this means that some Linux (normal world) interrupts may be very delayed by the secure world (RTOS) main line code.
Comment: it's a non-popular SOC. In our develop environment, GIC only have IRQ connection to arm core, without FIQ . we would like to run two os in each world. Linux on normal world, rtos on secure world. Both OS have individual interrupts, basically we want them run separately. ARM has one recommend design, IRQ for normal world FIQ in normal world switch to secure world vice verse. But we have only IRQ, so we need to seek if any good solution for IRQ only case
Comment: we may have different irq handle for two worlds. Like IRQ 1~100 is for normal world OS, IRQ 101~200 is for Secure world OS. It's slightly like visualization, but we dont have hypervisor, and user the monitor mode to achieve this.
Comment: So we are confused about the IRQ routing path. we are not sure if the monitor mode branch to two irq handle is fine, like the lr/spsr register. if irq is triggered in usr mode to monitor mode, the lr/spsr is from usr mode, but how to change mode to irq mode / run irq code and keep the return state(lr/spsr) to usr mode? maybe we can push the lr/spsr to irq_sp in monitor mode and change CPSR to irq mode then branch to os's exception vector's irq entry (with some modification in OS's interrupt entry function) ?
Comment: You can use `CPSID` to change modes.  If there is no way an exception can occur, you can alter the IRQ mode in the 'Secure world' by briefly changing to IRQ mode.  The registers are shared between worlds, so **IF** the secure world needs the lr_irq/sp_irq, you need some context block to save these.  However, if IRQ is exclusive to the normal world, there is no issue.  From secure world monitor, use `CPS` to IRQ and alter SP/LR (use unbanked registers r1-r12 to transfer) and then go back to monitor mode and return to the normal world IRQ.
Comment: This [question on banked registers](http://stackoverflow.com/questions/22080918/trustzone-monitor-mode-and-ifar-ifsr-dfar-dfsr) is also probably very useful to people looking at this question.  Ie, I am in monitor mode (secure world) and want to look at normal world CP15 registers that are banked (have a normal and secure world version).


$\sum_{n=1}^{\infty} \frac{n}{2^{np}}=?$

Question: By ratio test we can conclude that $\sum_{n=1}^{\infty} \frac{n}{2^{np}}$ is convergent for $0<p\leq 1.$
question: Can we compute the sum $\sum_{n=1}^{\infty} \frac{n}{2^{np}}$?
Comment: It's an [arithmetico-geometric series](https://en.wikipedia.org/wiki/Arithmetico-geometric_sequence#).
Answer: Hint
$$x=\frac 1{2^p}\qquad \implies \qquad\sum_{n=1}^{\infty} \frac{n}{2^{np}}=\sum_{n=1}^{\infty} n\,x^n=x\sum_{n=1}^{\infty} n\,x^{n-1}$$ Integrate the last term  with repect to $x$ which makes a very simple geometric series. Differentiate the result, muliply by $x$ and replace $x$ by its definition.


How to scale progressDrawable to fitxy

Question: Hi i need a customized seekbar
<code>        <SeekBar
            android:id="@+id/seekBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:progressDrawable="@drawable/volume_bar" />
</code>
it works works but it is clipped

the resource image looks like that

how can i scale the drawable into the seekbar?
Answer: my workaround was creating an xml drawable
<code><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="@color/seekBarColor" />
    <corners android:radius="@dimen/seekerLineCornerRadius" />
</shape>
</code>

How to scale progressDrawable to fitxy


(Pandas)I fail to assign value when I use loc and column name together

Question: The sample of my data is as follows.
  date         traffic_amount      factor
-----------------------------------------------
2012-01-01       613.586982        1.000000
2012-02-01       598.591841        1.107143
2012-03-01       653.042743        1.000000
2012-04-01       666.692536        1.033333

I tried to change value which has index 2012-02-01 using loc and column name. But I failed to do that. The value remained the same.
data_per_member.loc['2012-02-01']['factor'] = 31/29
print(data_per_member.loc['2012-02-01']['factor'])

1.1071428571428572

31/29 is 1.0689655172413792.
So I noticed that my code 'data_per_member.loc['2012-02-01']['factor'] = 31/29' did not work. Why did not my code work?
Answer: Do not chain the loc with []
data_per_member.loc['2012-02-01','factor'] = 31/29


Confirming if dependent t-test does not look into individual pair

Question: I would like to confirm about dependent T-test. As per my understanding, that t-test validates if the mean of 2 classes are significantly different. However, that does not take into account the individual pair, so:
score_first_test={1,2,3,4,5}
score_second_test={6,7,8,9,10}

and
score_first_test={1,2,3,4,5}
score_second_test={8,7,10,9,6}

will yield the same/similar result. Am I correct?
Comment: As a heads up, "validates of the mean of 2 classes is significantly different" is super sketchy phrasing. You get the gist of what a two-sample t-test does, but there are some details missing from this phrasing. I suggest JBStatistics on YouTube, who has a video on common hypothesis testing misconceptions.
Answer: It depends on which t-test you do. If you do a two-sample t-test (or Welch's t-test), the the pairing doesn't matter. In fact, there might not be any pairing; the sample sizes don't even have to be equal.
If you do a paired t-test, however, it first calculates pairwise differences and then performs a one-sample t-test on those differences. In this case, the pairing is crucial.
Comment: Hi Dave, I looked at the formula of student's (paired) t-test and it consists of mean, std, theoretical value, and n. How can it consider the individual pair? Thanks.
Comment: You calculate those values from the pairwise differences.
Comment: @DarrenChristopher, in the case of the paired-sample $t$-test, the $i$th subject has two values, say, before ($j=1$) and after ($j=2$) a treatment.  Then the analyst computes $y_{i,diff}=y_{i,2}-y_{i,1}$ for $i=1, 2, ...,, n$.  So if you have $n$ subjects, you'll have $n$ differences of the "after" value and the "before" value.  You then find the mean of these $n$ differences, $\bar{y}_{diff}$ and carry out a simple $t$-test on these differences.  By matching up each subject's before and after value and subtracting the difference, you've taken into account the pairing.
Comment: That being said, the *title* of your posts asked about the dependent $t$-test.  This implies you are using a paired comparisons test because two measurements taken on the same subject are dependent/correlated.


Restrição input "type date"

Question: Código:
<input type="date" name="data" value="">
<input type="submit" class="success round button" value=""/>

Preciso que quando eu clique no botão submit e o campo date estiver em branco ele não me deixe enviar. Tem algum modo no html mesmo sem ser JS para fazer essa restrição ?
Comment: Já testaste juntando o atributo `required`? Assim: https://jsfiddle.net/spz8txma/
Comment: É verdade rs, era só isso.
Answer: Podes usar o atributo required que é exatamente para evitar que o campo seja enviado vazio. Essa funcionalidade da API de HTML5 é suportada praticamente em todos os browsers.
Ficaria assim:
<input type="date" name="data" value="" required>

jsFiddle: https://jsfiddle.net/spz8txma/

Restrição input "type date"


Compare values from two arrays and generate a new one

Question: I have two arrays that may or may not have similar values
const arrayOne = [orange, red, black, blue, yellow]
const arrayTwo = [blue, purple, white, red]

I'm using react and in useEffect I want that when making a certain change through onClick it returns the values that are not the same
example:-
const = [orange, purple, black, white, yellow]

I have tried the following ...
const [newArray, setNewArray] = useState([])
const [reload, setReload] = useState(false)

  useEffect(() => {
    const results = arrayOne.filter((i) => {
      return (
        i.id != arrayTwo.id
      )
      setNewArray(results)
    })
  }, [reload])

  return (
    <button onClick={() => setReload(!reload) }>
      Trigger useEffect
    </button>
  )

Comment: You asking to return values that are not the same but in your example you return the same items `[blue,red]`, what is the logic behind this?
Comment: You can use lodash's `xor` like `_.xor(arrayOne, arrayTwo)`
Comment: How `useEffect` related to `onClick` event?
Comment: @DennisVash I didn't pass the dependency array that makes useEffect load
Comment: @DennisVash I made the adjustments
Answer: Try this
function diff (a1, a2) {

    var a = [], diff = [];

    for (var i = 0; i < a1.length; i++) {
        a[a1[i]] = true;
    }

    for (var i = 0; i < a2.length; i++) {
        if (a[a2[i]]) {
            delete a[a2[i]];
        } else {
            a[a2[i]] = true;
        }
    }

    for (var k in a) {
        diff.push(k);
    }

    return diff;
}

// call here
diff( ['a', 'b'], ['a', 'b', 'c', 'd'] );

Answer: Find the similar items, and then filter accordingly:

const arrayOne = ['orange', 'red', 'black', 'blue', 'yellow']
const arrayTwo = ['blue', 'purple', 'white', 'red']

// [red,blue]
const dupItems = arrayOne.filter(item => arrayTwo.includes(item));

const output = [...arrayOne.filter(item => !dupItems.includes(item)), ...arrayTwo.filter(item => !dupItems.includes(item))];
console.log(output);
Answer: One solution is to do it this way:

let arrayOne=['orange', 'red', 'black', 'blue', 'yellow'];

let arrayTwo=['blue', 'purple', 'white', 'red'];

let common=arrayOne.filter(value => arrayTwo.includes(value))

let result=[...new Set([...arrayOne,...arrayTwo])].filter(value=>common.indexOf(value)==-1)

console.log(result)
Answer: Maybe something like this could work
const diffArray = arrayOne.reduce((acc, value) => {
  if ((arrayTwo.inclues(value) { return acc; }
  return acc.concat([value]);
}, []);

Note: please check for typos on my code I'm answering from my phone


Why I'm getting MySQL error that server has gone away?

Question: I'm running:
Drupal 7.34,
PHP 5.4.16,
MySQL 15.1 Distrib 5.5.41-MariaDB, for Linux
I am getting a WSOD on just the module page after a move of server, everything else seems to be running ok.
I've added:
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

to index.php and see the below errors:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2006 MySQL server has gone away' in /public_html/includes/database/database.inc:2171 Stack trace:
#0 /public_html/includes/database/database.inc(2171): PDOStatement->execute(Array)
#1 /public_html/includes/database/database.inc(683): DatabaseStatementBase->execute(Array, Array)
#2 /public_html/includes/database/database.inc(2350): DatabaseConnection->query('SELECT expire, ...', Array, Array)
#3 /public_html/includes/lock.inc(167): db_query('SELECT expire, ...', Array)
#4 /public_html/includes/lock.inc(146): lock_may_be_available('theme_registry:...')
#5 /public_html/includes/theme.inc(449): lock_acquire('theme_registry:...')
#6 /public_html/includes/bootstrap.inc(455): ThemeRegistry->set(Array) #7 [internal function]:
DrupalCacheArray->__destruct()
    #8 {main} thrown in /public_html/includes/database/database.inc on line 2171
Fatal error: Access to undeclared static property: Database::$activeKey in /public_html/includes/database/database.inc on line 1466
Comment: Please include your Drupal and PHP version.
Answer: A couple of things to try:
First, it's potentially one of your contrib modules causing the problem, so option 1 would be to use Drush to disable all non core modules:
drush pml --no-core --type=module --status=enabled --pipe | xargs drush -y dis
After running this, there is a good chance that you can access your modules page again and be able to start enabling modules one by one to pinpoint the culprit.
Option 2 would be to check mysql's MAX_ALLOWED_PACKET.  You can check this by running SHOW VARIABLES LIKE 'max_allowed_packet' in your mysql console.  If it is set at 1MB, you can try raising it to 16M by running SET GLOBAL max_allowed_packet=16777216;. Try loading your page again to see if that was the issue.
Answer: It's problem with your database configuration.
You need to increase your max_allowed_packet value in your MySQL configuration file to at least 8MB or more depending on your site/database complexity.


Clearing cache after change the html code

Question: I've got some problem with clearing cache on web browsers. When I'm loading the changed website, even after deleting the cache, it does not load properly(on android browser - chrome, on pc it's all ok).
What can I do more except of deleting the cache, because I already did it? I need to add some code?
Edit: and what can I do for properly loading on iPhone(safari)?
Answer: Clear data of the chrome then it will work fine . Even i had the same problem


Multilayer perceptron: Hyperparameters vs Parameters and Cross validation (nested or not)

Question: I'm a bit confused about the k-fold cross validation (inner and external) done for the model performance evaluation.
I've read that when you are trying to validate your model, you need to do it without leaking info from the test set to the training set. Data leaking is common when you are doing feature selection on the whole dataset instead of the training set alone (the same goes for the feature standardization) for example.
But how do you prevent that when you are "learning" your best hyperparameters for your model? For example the number of layers of your neural net which performs better on your problem?
I need to "inner" cross validate them in my cross validation task? Or is it irrelevant to select them by the external cross validation? For example by iterating the parameters on 10-fold cross validation alone, and after that picking the best performing ones?
Essentially, need I to validate my process of hyperparameters selection to avoid some kind of bias?
I know pretty well that the parameters search (e.g. weights of your neural net) needs to be done in your training set alone, but is it the same for your hyperparameters?
Answer:
I know pretty well that the parameters search (e.g. weights of your
  neural net) needs to be done in your training set alone, but is it the
  same for your hyperparameters?

Yes. Models with many hyperparameters are more prone to overfit even if you select the hyperparameters inside the inner CV (that's using train data only). Given that you have chosen the CV design perfectly, you still have a chance of selecting the hyperparameter set that is overfit to your validation folds.  A good example is random forest or GBM, where you don't optimize weights but solely make a choice of the complexity of the model and its learning rate, which are hyperparameters.
You need outer crossvalidation in order to estimate how badly your inner-CV overfitted your model. A canonical k-fold CV is known to fail to meet the assumptions of error independence thus creating optimistically biased error (loss-function value).
However good the CV is, the more hyperparameters you search through the more chances that your model will behave as though you used the whole dataset for training. Then the outer-CV may come in handy.
Reading that may help get it: Is cross-validation enough to prevent overfitting?


Format Excel Workbook With EPPlus

Question: I am using EPPLUS with ASP.NET to extract a DataTable to Excel.  The actual extract portion works perfect, but I can't figure out how to format a column as a Percentage.  I tried using #0\\.00% but all that did was 0 and a percentage at the end.  So if my my original data was .34 using #0\\.00% would format it to 0.34%

My desired out put / formatting I want is for EPPLUS to format the number .34 to be 34.00%
Answer: Try and use this #0.00%
A quick run down ... in custom formats, % means "add % and multiply by 100", while \% means "just add %"
Comment: Worked perfectly.  And thank you for letting me know about the custom formats.
Answer: Use custom formats
you can try below code
worksheet.Cells[rowIndex, colIndex].Style.Numberformat.Format = "0.00%";
worksheet.Cells[rowIndex, colIndex].Style.Numberformat.Value = Decimal.Parse(.34)

Format Excel Workbook With EPPlus


How to avoid inadvertent string muting due to somewhat fast finger picking?

Question: Have come to realize that no matter how careful and sharp I try to finger-pick the guitar using my right hand (keeping the chord-shapes pressed with left hand to play Arpeggios or melody in general), at anything over say (roughly) 100bpm, the notes have hardly any sustain and almost instantaneous decay. This gives a very "muted" sound to the notes, instead of the distinctive acoustic guitar twang.

Is the above observation a shortcoming of my technique and
insufficiency of training (and of course experience) ?
Are there some techniques to improve the clarity and ring of the notes
in such cases ?

Please note that the style of finger-picking I've practised and learnt involves 50:50 combination of flesh and nail of the index, middle and ring fingers, instead of purely picked using nails.
Comment: Practice more and practice more slowly.
Comment: Looks like the answer to all of my miseries (with learning guitar) are "very very slow", while I'm in a great hurry to prove to myself that I can do it, and stay motivated. Thanks @ToddWilcox, for your insightful contributions.
Answer: Basically, the comment by Todd Wilcox sums it all up (although I'll put it the other way around): Practice more slowly, and practices more. So yes, it's a shortcoming in your technique and/or insufficient training.
The good news is that you will improve if you just keep practicing.
Pick up a copy of Mauro Giuliani's 120 right hand studies, and start studying.
Start at a pace at which you can make all notes sound clean, clear and evenly. Then start putting the accent in the arpeggios on a different notes to increase control of your fingers. Only then increase the pace slowly.
They're not the most entertaining exercises in the world, but they will help.
Comment: Well, technically, you don't need the book: The exercises basically feature every possible arpeggio combination (between p-i-m-a (thumb to ring finger)) to arpeggiate over an open C and open G7 chord, with twists added as you progress to the book. So it's not that hard to invent your own collection of exercises. The convenience of the book is more that (a) you don't have to invent them yourself, (b) you can easily keep track of combinations practiced, and (c) it's quite exhaustive: Giuliani was quite thorough in writing down variations that wouldn't quickly come to mind.
Comment: if you look at [this free pdf](http://www.classicalguitar.org/freemusic/exercises/Giuliani120.pdf), you only have to remember that for all exercises, the first bar is an open C, and the second bar is een open G7. The plucking finger indication is provided by p-i-m-a: The thumb, index, middle, and ringfinger respectively. That's all you need to get going :)
Comment: Thanks Willem, appreciate the answer. Yes -- agreeably, the answer to every question I ask seem to be "very very slow" :-) and I cannot but agree that I do seem to forget that, more often than not. As noted in my comment to ggcg's answer, I am learning on acoustic steel-string (although I do have a Nylon string Classical guitar) as per my teacher's instructions. Moreover, I choose to ignore what seemed to be much harder western classical notation using staff, clefs, bars. Without those, I suppose Mauro Guilliani's exercise can't be benefited from.
Comment: I would like to add that Pepe Romero reprinted much of Guilliani's exercises in one of his books.  There, he changed some of the exercises to E7 --> A to relieve stress on the index finger.
Answer: There is some missing information in your question.  You say 100bpm but you don't say if you are playing quarter, eighth, sixteenth, triplets, etc.  You can't leave it to us to guess.
I can say that people do play very fast using classical (and bluegrass, etc) finger style.  You need to train your right hand to attack perfectly every time.  It's a long process.  You will find that one day you can play 1/16 notes at 100bpm but it falls apart at 110bpm, months later you'll be fine at 120pbm and fall apart at 130bpm.  Practice not only more slowly, but very slowly, e.g. one note per beat at 60bpm.  Pay attention to what your fingers are doing when they have nothing to do!  That is part of the training.  I recommend using the planting technique, get the correct finger to the string it will pluck, long before it needs to pluck it.  Once this is in your muscle memory you'll get clean speed.  In addition to Giuliani's book I'd recommend
Guglielmo Papararo, La Technica Degli Arpeggi per chitarra classica.
This has just about every combination of right hand fingerings in triplets, quads, sextuplets, etc.  Giuliani has you holding chords (which you need to do) while these exercises are done on open strings allowing you to focus your mind on the right hand alone.
Comment: Yes, they should offer some help.  They are exercises designed to isolate right hand movement.  As for "reading", there isn't much to read as 80% of them are open string.  Classical notation also indicates string number in a circle for each string, so it's a little like tab.  The book I mention does NOT offer instruction on proper hand posture etc, or practice habits.  You may want to follow the advice of others on that front as well.  Take it slow, every movement should be intentional.  "Planting" is a techniques that works for speed picking as well.
Comment: Thanks @ggcg. Does these technique (in the books recommended) apply even if one is not following a Classical Guitar curriculum ? Add to it the fact that I cannot read music in the Classical Western notation -- only the neophyte tabs and chords-by-alphabets mechanism. So the pieces I am learning, have tabs along-side the Classical Western notation (staff, cleff, bar...). I suppose without being able read notation, those books wouldn't be usable. Any chance anyone has translated those books into instructions using tabs ?


error running a code of openMP on macOS catalina 2

Question: I just installed openMP just running

brew install gcc

Then I compiled my code using

gcc-10 -o task -fopenmp task.c

However I got the error message:
Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status
my code is:
<code>1. #include <omp.h>
2. #include <iostream>
3. using namespace std;
4.
5. #define TAMA_NTHREADS 4
6.
7.
8. int main (int argc, const char * argv[]){
9.
10.
11.   int nProcessors = omp_get_max_threads();
12.
13.   cout<<"Numero di core disponibili: " << nProcessors << endl;
14.
15.   omp_set_num_threads(nProcessors);
16.
17.   cout << "Numero thread fuori pragma: " << omp_get_num_threads() << endl;
18.
19.   #pragma omp parallel
20.      {
21.         cout << endl <<"Numero di thread in pragma: " << omp_get_num_threads() << endl;
22.         cout << "Sono il thread numero: " << omp_get_thread_num();
23.         cout << " E ti saluto! " << endl;
24.      }
25.
26.   exit(0);
27.}
</code>
May someone help me please?
Comment: That's C++ code that you are trying to compile as C. Rename the file to `task.cc` and use `g++-10` instead.
Comment: yes it does. :)
Answer: "That's C++ code that you are trying to compile as C. Rename the file to task.cc and use g++-10 instead".
Hirsto this solved the problem thank you. Anyway it works even if I do not rename the file.


How do I get the node URL in a Twig template?

Question: I am trying to get the node URL in a Twig template. {{ content.node_link }} returns the full link, but I only need the URL.
How do I retrieve the node URL?
Comment: If you look in the node template, you will see that `url` is an available variable. Thus simply printing `{{ url }}` for example will render the raw URL, `/node/[nid]` i.e. `/node/30` without any wrapping markup. Is that what you are looking to do?
Answer: According to Functions - In Twig Templates you can use is simple by
 {{ path('entity.node.canonical', {'node': node.id}) }}

Comment: This solution works, and is pretty groovy. But using {{ url }} in a `node--` based twig template will give you the same result.
Comment: I've used this in field template.
Answer: In a node.html.twig you can directly use {{ url }}
read more

For more information read comment in core template : /core/modules/node/templates/node.html.twig :
{#
/**
 * @file
 * Default theme implementation to display a node.
 *
 * Available variables:
 * - node: The node entity with limited access to object properties and methods.
 * ...
 * - url: Direct URL of the current node.
 * ...
#}
...

  {{ title_prefix }}
  {% if not page %}

      {{ label }}

  {% endif %}
  {{ title_suffix }}

Comment: You should explain your answer more rather than "simply put". An explanation, such as what @Danny Englander wrote in the question comment, helps the asker and others to learn more about *how* you came up with your answer and how they can help themselves in the future.
Comment: This is the easiest method, using a built-in variable in the node twig template.
Comment: That should be the accepted answer
Answer: I have found this solution that works, but is quite convoluted.
{{ path('entity.node.canonical', {'node': content['#node'].id()  }) }}

Comment: You can use `node.id` instead of `content['#node'].id()`
Comment: I am working in view with a display suite template and 'node' is not one of the available keys. {{ dump(_context|keys) }} gives these keys only: 'content','theme_hook_original','attributes','title_attributes','content_attributes','title_prefix','title_suffix','db_is_active','is_admin','logged_in','user','directory','settings','layout', '#cache','theme_hook_suggestions'
Comment: Great solution for display suite templates. @4k4 `content['#node'].id()` is correct for the DS context.
Answer: This worked for me:
<a href="{{ url('<current>') }}">{{ 'Reload'|t }}


load matching files in table

Question: I have a folder that contains multiple .csv files for each employee like empname_date.csv and I want to load files in one table.
Not all files but only files where file name matches the data with tbl_empmaster table that contains the master list of employees.
I do not want to check each file because it will take too much of time. I need to filter files as per master list and then load the matching employee files.
Please help what I can do in this case.
I am using SSIS to do the same.
Answer: Create an SSIS Package to with a For Each Loop Container to Read all the CSV files of the given Folder.
Read the File Name without extension to a variable and Before inserting perform a table lookup to see whether the given File Name exists in your table and insert only if the match is found
Comment: Then try reading all file names to an Array or Object then from that object match the file names and flag those need to be processed and read only the flagged files in the Data Flow
Comment: In this case, i have to check each file. I am trying to optimize the process and want to filter files that contain only matching names.
Comment: please comment.

load matching files in table


Finding 2-dimensional sufficient statistic via Fisher-Neyman factorization when marginal pdf functions for x don't contain x

Question: Let $X_1,...,X_n$ be mutually independent with pdfs given by $f_i(X_i\mid\theta) = 1/(2i\theta) $ where $ -i(\theta - 1)<x_i<i(\theta +1)  $ and $\theta>0.$ To find a two-dimensional sufficient statistic, I'm going to use Fisher-Neyman factorization.
The joint pdf of $X$ can be written as $$f(x|\theta)=1/((2\theta)^n\sum_i^n i) = (1- \bar x + \bar x)/((2\theta)^n\sum_i^n i)=(1- \bar x)/((2\theta)^n\sum_i^n i) + \bar x/((2\theta)^n\sum_i^n i) $$ over the domain of $X$. I need to factor $f(x|\theta)$ as $f(x|\theta)=h(x)g(T(x)|\theta)$, so letting $h(x)=1$, is $T=(T_1, T_2)=(\bar x,\sum_i^n i)  $  a sufficient statistic? My concern is  that $T_2$ doesn't involve $X$.
Comment: *Every* distribution function depends on its argument, period: for otherwise you would be describing a distribution comprising either zero or infinite probability.  Look more closely at your results and make sure to track the information about the set of values on which the distribution is nonzero (its *support*).
Comment: https://stats.stackexchange.com/q/510173/119261
Answer: The support of the distribution depends on the parameter $\theta$. So use indicator functions for writing down the pdf correctly and hence get a sufficient statistic for $\theta$ using Factorization theorem.
First note that
$$-i\theta+i<x_i<i\theta+i\implies \theta>\max\left(\frac{x_i-i}{i},\frac{i-x_i}{i}\right)=\frac{|{x_i-i}|}{i}$$
So for $\theta>0$, joint density of $ X=(X_1,X_2,\ldots,X_n)$ is
\begin{align}
f_{\theta}( x)&=\prod_{i=1}^n\frac{1}{2i\theta}\mathbf1_{-i(\theta-1)<x_i<i(\theta+1)}
\\&=\frac{1}{n!(2\theta)^n}\mathbf1_{|{x_1-1}|,|x_2-2|/2,\ldots,|x_n-n|/n<\theta}
\\&=\frac{1}{n!(2\theta)^n}\mathbf1_{\theta>\max\left(|x_1-1|,|x_2-2|/2,\ldots,|x_n-n|/n\right)}
\end{align}
By the Factorization theorem, you get a sufficient statistic $$T(X)=\max_{1\le i\le n}\{|X_i-i|/i\}$$ for $\theta$. If you take any other statistic $T'$, then $(T,T')$ would also be sufficient for $\theta$ as $T'$ plays no further role in the amount of data reduction or condensation without losing information about $\theta$.
Comment: It may be easier to note that $-\theta<\frac{x_i}{i}-1<\theta\implies |\frac{x_i}{i}-1|<\theta\implies \max\limits_{1\le i\le n}|\frac{x_i}{i}-1|<\theta$. The $T$ here is a minimal sufficient statistic.


Custom entities created time is always the same

Question: I have a custom content entity type. When I create an instance, the first one got the right created time stamp. But starting with the second one, they all have the same created time stamp: as the first one have!
Why is this happening?
Base field definition:
$fields['created'] = BaseFieldDefinition::create('created')
  ->setLabel(t('Created'))
  ->setDescription(t('The time that the entity was created.'))
  ->setReadOnly(TRUE)
  ->setDisplayConfigurable('view', TRUE);

Setter / getter methods:
  /**
   * {@inheritdoc}
   */
  public function getCreatedTime() {
    return $this->get('created')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function setCreatedTime($timestamp) {
    $this->set('created', $timestamp);
    return $this;
  }

Answer: I had my php code cached before adding the setCreatedTimemethod to my custom entity. After clearing the cache everything was fine!
So in general: add the setCreatedTime method to your custom entity to make your created timestamp work.


git: independent version control in sub directory?

Question: I have a project which is under git version control. Everything works smoothly.
I also have "buildtool" directory which have some script for testing,deployment and setup.
Sometime while changing branch I want that directory to be latest and also I want it to be under version control ?
How do I achieve that ?
Comment: Have you looked at `git submodule`s this allows you to combine various repositories
Comment: Why do it this way instead of using branches?
Comment: buildtools have script which are independent of actual project content and even if the actual project is at different branch, buildtools have script which needed for running the project so they should be at latest or some choosen version. ( question can be asked another way : How do I merge only single subdirectory ? )
Comment: You could commit changes in the directory on a separate branch and merge the branch.
Answer: +1 for submodules (cudos to Adrian Cornish for first suggesting it)  You've technically got two different projects that have loose coupling, but no real source code coupling.  Start off by putting them in separate repositories.  Then either leave them completely separate or use submodule to link the build content into the source content.


Existence of a strongly increasing sequence of compact subsets in a metric space

Question: Let $(X,d)$ be a metric space. When can we guarantee that there exists a sequence of compact subsets $(K_n)\subset X$ such that $K_{n}\subset\text{int}(K_{n+1}
)$ and $X
=\bigcup_n K_n$?
Answer: A necessary and sufficient condition (for topological spaces, not just metric spaces) is that $X$ is $\sigma$-compact and locally compact.
This is obviously necessary.  On the other hand,
 suppose $X$ is $\sigma$-compact and locally compact.  Since it is $\sigma$-compact, there is a sequence $J_n$ of compact sets with $\cup_n J_n = X$.  Construct the sequence $K_n$ as follows, starting with $K_1 = J_1$.  Given $K_n$, for each $x \in K_n \cup J_{n+1}$ take a compact neighbourhood $U(x)$.  The open cover $\{U(x): x \in K_n \cup J_{n+1}\}$ of the compact set $K_n \cup J_{n+1}$ has a finite subcover: let $K_{n+1}$ be its union.  Thus $K_{n+1}$ is a compact set whose interior contains $K_n \cup J_{n+1}$.
Answer: Just a partial answer for Banach spaces: If $X$ is a finite dimensional Banach Space, this is true, just take $K_n:=\overline{B_n(0)}$.
On the other hand if $X$ is an infinite dimensional Banach space this is wrong, because for $K_N\subset \operatorname{int}(K_{n+1})$ to be correct, the interior of $K_{n+1}$ would have to be nonempty. Hence there would be a closed Ball $\overline{B_r(x)}\subset K_{n+1}$ which would have to be compact as well. This is a contradiction to $X$ being infinite dimensional (see e.g. this question Is any closed ball non-compact in an infinite dimensional space?)


how to change int to Binary value

Question: I have a problem changing my data into binary. It's not so complicated just using basic math; like if a = 60, then the result is "good", and when a >= 60, then it is "very good", but this is implemented in the data below:

This is my data; I want to change new_cases data to be binary value when the data >=1; I want the result to be 1, but when I use
Dt[Dt['new_cases'] >= 1 ] = 1

It doesn't work.
Please, is anyone able to run it? Any ideas? What could be causing this issue?
Thanks!
Comment: Please post a fully running small example script, plus what you want to happen. For instance, don't bother with columns that aren't part of the problem.
Answer: You have to specify the column where you want to change the values:
Dt.loc[Dt['new_cases'] >= 1, 'new_cases'] = 1
Answer: Use
Dt["new_cases"] = Dt["new_cases"].apply(lambda x: 1 if x >= 1 else 0)

OR
Dt["new_cases"] = 1
Dt.loc[Dt["new_cases"] < 1, "new_cases"] = 0

how to change int to Binary value


Limit of correlation for random walks

Question: I want to show that
\begin{align}
\lim_{m\rightarrow\infty}\frac{1/\pi\sqrt{mk}-1/\pi\sqrt{m(m+k)}}{[1/\sqrt{\pi m}-1/\pi m]^{1/2}[1/\sqrt{\pi(m+k)}-1/\pi(m+k)]^{1/2}}=\frac{1}{\sqrt{\pi k}}
\end{align}
This is from p. 9 of the following probability lectures notes http://www.math.lsa.umich.edu/~conlon/math625/chapter1.pdf, and I'm stuck trying to do it.
Answer: Hint
Just multiply top and bottom by $\sqrt{m}$ (giving $\sqrt[4]{m}$ to each factor on the bottom.) From there the limit can be taken termwise and the answer drops right out.
Comment: @mlstudent The $1/\sqrt{m}$ decay of the first term on the top is slower than the second term, so if you multiply them by $\sqrt{m}$ you get a constant term plus something that goes away. Then it's just a matter of seeing if that $\sqrt{m}$ makes the bottom go to a constant as well (and it helps that the factors on the bottom are very similar in limit behavior in $m$ as the one on the top).
Comment: That was helpful.  Is there anything in particular that allowed you to notice that?

Limit of correlation for random walks


loop through a subfolder in bash

Question: I am super fresh in the bash language and I am missing several key concepts.
Please excuse my ignorance.
My structure is
folder A
   |--- folderB1q/output/output.csv
   |--- folderB2q/output/output.csv
   |--- ...
   |--- folderB100q/output/output.csv

I want to read in bash from folder A each output.csv file and apply a function on it. I have tested my function and it works when I go to the directory of the file.
I have thousands of directories though...
for each in *q/output/
do
my function .......
done

Thank you for your time and sorry for my bad coding
Answer:
each output.csv

Then loop over output.csv files.
for each in */output/output.csv
do
    my function "$each"
done

I have thousands of directories though...

With many directories, using a shell loop might be memory expensive, because shell. Use a find.
find . -type f -mindepth 3 -maxdepth 3 -path '.*/output/output.csv' |
xargs -d'\n' -n1 my_command

loop through a subfolder in bash


How handle large number of images in gallery node Drupal 7

Question: I have some gallery nodes with a large number of images (100+), the upload with Plupload integration module works fine, but after save the node and edit it again the node edit form loads 20+ seconds! How can I reduce the loading time of the form? Somebody have any suggestion for this problem? Lazy Loading of Fields possible? Pagination? Some Module?
Thanks
Comment: Have you tested what actually takes so long? SQL query? File download to user? Something else? Withuot knowing the reason, we can't guess solution.
Comment: Devel protocol showed me a huge number of sql queries so i tried entitycache module in combination with memcache! Tests: Deactivated Entity Cache Executed 2361 queries in 16415.45 ms.  Activated Entity Cache  Executed 412 queries in 627.84 ms. Source Devel! What do you think about this solution?
Comment: With Drupal you always get a huge number of queries. San you see if they actually take a lot of time? I would try memcached if I suspected query-related speed problem.
Answer: I do not know the intended site behaviour, or interface, for your galleries.  However, I would restructure the site.  Have you looked at each gallery "entry" being a node with 1 picture field and 1 taxonomy term reference?  The terms would then be your "galleries", you could use views to build the pages any way you want, even lazy load.  You could add sorting, and since you would not have 100+ field entries on any one entity, loading the entity into a variable for the various page build tasks would be far faster.  Gallery nodes work fine if they have less than 30 entries, but it sounds like your data management could use some revision.


Statistic that combines proportion and 'success' size

Question: I have proportion data where I am interested in the proportion of successes, but also in the number of successes.  Is there some statistic I can calculate to summarize this info into one number?
Sample data:
<code>X   N    P
2   4   .5
40 200  .2
3   10  .3
50 100  .5
</code>
Here the first and last data have the same proportion, but I would like the statistic to acknowledge the fact there is a lot more confidence in the last line (maybe incorporate the margin of error some how, but I would like it to take into account X not N).
Comment: Because the "confidence" (by almost any definition) depends on $N$, the last parenthetical remark may perhaps be asking for the impossible.  Note, too, that $X$ and $N$ are intimately linked via $X = N P$, so any MoE for $P$ depending on $X$ depends *a fortiori* on $N$.
Answer: I'd compute the proportion (X/N=P) along with a 95% confidence interval for that proportion. The width of that confidence interval shows you the margin of error you want. Use this free online calculator to do the math.
Comment: good solution but it again demonstrates that you can't describe this with a single number.
Answer: You might consider shrinkage estimation of $P$ given $X$. One straightforward way to do this is, for each row $i$,
$P_{i}^* = m\frac{c}{c+x_i} + \frac{x_i}{n_i}\frac{x_i}{x_i+c}$, where

$x/n = P$, the proportion of successes
$x =$ the number of successes
$m =$ the mean proportion across the whole data set (which, based on the data above, is 0.303)
$c =$ a scaling constant (the higher this is, the more shrinkage there is)

The intuition is that you are creating a weighted average $P^*$ which shrinks each proportion to the mean on the basis of how many successes it has. The left term establishes the base value, which will be more or less of a factor based on the degree to which $x_i$ differs from $c$. The right term pushes the value from $P_i^*$ away from that average, once again based on how $x_i$ differs from $c$.
The downside if that you have to choose an arbitrary scaling constant $c$. But you can justify this based on how many successes values $x_i$ it would take you to "trust" the proportion estimate $p_i$.
A canonical example of this in action is the imdb top 250, for which movie ratings are scaled to be higher (or lower, for the bottom 100) on the basis of how many votes they have.
(By the way, it's not clear to me why you trust entries with high $X$ more than high $N$, but you clearly have more domain-specific knowledge.)
Answer: You can't summarize this in one statistic,  But p and N the two binomial parameters tell the story.
Comment: You are correct--and refreshingly to the point--but doesn't the question at least implicitly ask for a way to express "confidence"? And, to take it seriously, we should be able to provide a *quantitative expression* of confidence. Which of the pair $(N, p)$ would you nominate as the confidence?
Comment: Both since the standard error of estimate is √[p(1-p)/N] But if I can take just one it will be N because regardless of pthe standard error is bounded above by 1/[2√N]


How can i run a python file as service python3

Question: I have a python script and that I have to run as a service/background process, I have tried python-daemon but it gives me errors is there any good way to run it as a service so that the script can be run in the background to accept messages and process files?
Comment: Can you provide the errors you are receiving?
Comment: os.umask(022) # Don't allow others to write
Comment: This is what i have tried "https://pypi.python.org/pypi/python-daemon/"
Comment: Again please provide a code example that you have tried and the errors you are receiving?
Answer: I have made a sytemctl service file in /lib/systemed/system
The file content is
<code>[Unit]
Description=RPC SERVER
After=network.target

[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/
Type=simple
ExecStart=/usr/bin/ python3 /home/ubuntu/rpc.py

[Install]
WantedBy=multi-user.target
</code>
/home/ubuntu/rpc.py is my python script path
and i saved the file as rpcservertest.service
so i can start the service using
sudo systemctl start rpcservertest.service
to stop
sudo systemctl stop rpcservertest.service
and to get status
sudo systemctl status rpcservertest.service


Em java, como fazer que só uma janela JFrame feche ao clicar no x, ao invés de todas?

Question: Estou fazendo um programa em Java com várias janelas JFrame, e queria que, quando apertasse o x de uma das janelas apenas esta fechasse, ao invés de todas elas.
Comment: Considere incluir o que você está tentando fazer. Além disto, talvez o melhor, no seu caso, não seja usar várias `JFrame`, mas usar `JInternalFrame`.
Answer: Basta utilizar a constante da classe JFrame, DISPOSE_ON_CLOSE, no método setDefaultCloseOperation(int), ao invés de EXIT_ON_CLOSE. Aqui está um pequeno exemplo que elaborei:
Window.java
import java.awt.BorderLayout;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class Window extends JFrame {

    private static final long serialVersionUID = 1L;
    private static final Random RND = new Random();
    private JPanel contentPane;

    public Window() {
        super("Close me!");
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setBounds(RND.nextInt(1024), RND.nextInt(768), 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);
        setVisible(true);
    }

}

Main.java
public class Main {

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            new Window();
        }
    }

}

Answer: Coloca na classe que extende JFrame
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);


Why would the SQL 2008 "Generate scripts..." utility generate an invalid SQL script?

Question: I have a SQL2008 database that needs to be restored to a SQL2005 instance.
I have gone through the "Generate scripts..." wizard, set it for SQL2005 compatibility, and generated a 62MB SQL script.
When I run it on the SQL2005 instance, it throws all kinds of errors, and some of them are really strange in that they describe an invalid database.

FK constraints are wrong.  It's trying to create FKs on columns that don't exist.
It's trying insert records with duplicate key errors.
It's trying to create the same objects twice.

Any idea how this could happen?  This SQL script was generated by SQL Server Management Studio just minutes before I tried to restore it, and was not modified.
Why would this generate an invalid SQL file?  Doesn't it just describe the SQL2008 database, which is presumably valid since we're using it?
In particular, the duplicate key insertion errors mystify me.  If there's a key constraint in the SQL script, then there must be the same thing in the SQL2008 table.  So how could we get rows in there that violate that key constraint?
Update:
It's something to do with the step-down to SQL2005.  I ran the script to be SQL2008 compatible, then turned around and ran the resulting script on the same SQL instance it just came from, and it ran without error.  So the problem comes when I try to make it SQL2005 compatible.
Another Update:
I re-genned the script to be SQL2005 compatible, then turned around and ran it on the SQL2008 instance.  It worked fine. So...

SQL2008 Script --> SQL2008 Instance WORKS
SQL2005 Script --> SQL2008 Instance WORKS
SQL2005 Script --> SQL2005 Instance DOES NOT WORK

Solution:
You can't create a script for SQL2005 and run it on Express.  I switched to Standard, and it worked fine.
Comment: Can you track it down to specific INSERTs that are generating the duplicate keys? And verify the constraint it is violating is supposed to be there? If you generate scripts without the data, do they run without error on SQL2005?
Comment: If after trying the script without the data (and if it doesn't work), you might try removing sections of the script and try to run that. I.e. just try run the script that generates the tables only, remove the SQL pertaining to Foreign Keys etc. If you are lucky it may just be a column type or something.
Answer: The problem was that I was trying to import to SQL 2005 Express.  I switched to SQL 2005 Standard, and I was able to run the script without error.
Comment: It won't let me accept my own answer yet ("...in two days"), but this is the valid answer.
Answer: I don't know if this is builtin these days to SQL Server 2008 Management Studio, but in 2005 you got more options when scripting if you used a separate download, the SQL Server Database Publishing Wizard Get it here: Microsoft Download Center
That be of some use to you.
Comment: I tried this, but it would not connect to SQL2008.  I think that this was a separate project with SQL2005, and they built it into SQL2008.


Prove that $(e^x-\ln y)^2+(x-y)^2\geq 2$

Question:
Prove that $(e^x-\ln y)^2+(x-y)^2\geq 2,\forall x\in\mathbb{R},\forall
y>0$. When does the equality hold?

I note that the equality holds only if $x=0,y=1$, but I don't know how to prove that without using functions with two variables. Any hint?
Comment: Why do you believe that you can solve it without calculus of several variables?
Comment: @Siminore I don't know. It should be solvable using only calculus of one variable (such as MVT, derivatives, integrals, etc.), since it is included on a Greek textbook.
Answer: Use the facts
$$\begin{align}e^x &\geq 1+x\\
\ln y &\leq y-1
\end{align}
$$
Then
$(e^x-\ln y) \geq (2+x-y)$.
Now you have 2 cases.

$(x-y+2)<0$. Then $(x-y)<-2$ and $$ (e^x-\ln y)^2+(x-y)^2 \geq (x-y)^2 \geq 4 \geq 2.$$
$(x-y+2)\geq 0$. Then
$$ (e^x-\ln y)^2+(x-y)^2 \geq (x-y+2)^2+(x-y)^2.$$
Here substitute $x-y=k$ and you obtain
$$(k+2)^2+k^2=2k^2+4k+4.$$
At this point you can easily prove that this quantity is always greater or equal than $2$.

For the equality, observe the proof. It can holds only if $2k^2+4k+4=2$. This holds if and only if $k=-1$, i.e. when $x-y=-1$. Now substitute it in your expression. You have
$$e^x-\ln(1+x)=1$$
It should be easy prove that the only solution is $x=0$, by observing that $e^x>1+x$ for every $x\neq 0$.
Answer: Use the following identity: for $\forall x,y\in(0,\infty)$,
$$(e^x-\ln y)^2+(x-y)^2=(e^x-x)^2+(\ln y-y)^2\color{red}{+}2(x-\ln y)(e^x-y).\tag{1}$$
Due to the monotonicity of $e^x$, we have
$$(x-\ln y)(e^x-y)=(x-\ln y)(e^x-e^{\ln y})\geq0.\tag{2}$$
By $(1),(2)$, we get (also use $e^x-x\geq1,y-\ln y\geq1$)
$$(e^x-\ln y)^2+(x-y)^2\geq(e^x-x)^2+(\ln y-y)^2\geq1+1=2.$$
When $x=1$ and $y=0$, the equality is ture!
Comment: @ River Li Thank you ! I fixed it.


What gives a left-handed pitcher an advantage over a left-handed batter?

Question: In baseball, a pitcher is often assumed to have an advantage over a batter based on his handedness (i.e. left-handed vs right-handed).  I think it is that right-handed pitchers have an advantage of left-handed batters, and vice-versa.
Why is this advantage?  If it is related to the break of the curve, is this advantage only relevant for pitchers that use a curveball, or does it also apply to pitchers that primarily use a fastball/change-up?
Comment: Quite a difference of opinion. The first answer says :"hitters can handle pitches on the inside portion of the plate better than the outside."
The third opinion says: Most batters have trouble hitting inside."
So really it is just a matter of opinion.
Answer: There are several things, including a major one that you mentioned before which is the break of the curveball/slider.
Generally speaking, hitters can handle pitches on the inside portion of the plate better than the outside.  Also, hitters can track and see a ball that is moving towards them better than away.  So for a lefty on lefty (or righty on righty) a 4 seam fastball tends to move slightly away (advantage pitcher) and both curveballs and sliders will break much further away (advantage pitcher).
You'll notice that many of today's best left handed pitchers have developed excellent Change Ups (Johan Santana, Cole Hamels, and popularized by Tom Glavine).  Since there are far more right handed batters than left, they needed a pitch that would break away instead of towards the right handed hitters.
For pitchers who use primarily a fastball change-up it still makes a difference but it is not as exaggerated.  The 4 seem fastball should still be a tougher pitch for the left on left matchup.
The last thing is: everyone, both left and right handed hitters, see far fewer left handed pitchers throughout their careers.  Just being unfamiliar and unique is an advantage to the lefty pitcher.
Answer: It makes a huge difference if the pitcher's delivery isn't completely overhand.
When a left-handed batter faces a left-handed pitcher throwing sidearm (or vice versa) it's downright intimidating.  It's much more difficult to track the ball out of the pitcher's hand, because the ball basically starts behind the hitter.  This also makes it feel like the ball is sneaking up on the batter (as if he has less time to respond) since he picks it up later with his eyes.
When a left-handed sidearm pitcher is throwing a sharp breaking ball to a left-handed batter... forget about it.  That's when you see lefties who hold opposing batters to batting averages under .200.
Answer: It helps to think about it from the hitters perspective. A right handed hitter would prefer the ball to be coming from an angle that is closer to first base (a lefty pitcher). This allows more room to "pull" the ball.
A right handed pitcher would be releasing the ball closer to third base. This forces the right handed hitter to "push" the ball - or hit it the other way which is more difficult.
Sidearm pitchers and pitches that move horizontally increase this angle advantage even more.
Answer: Most batters have trouble hitting "inside." (That is between themselves and the plate, meaning from the left side of the plate for a right-handed batter, and the right side for a left-hander.)
Most pitchers prefer to pitch "inside." In theory, right handed pitchers have trouble pitching to left handed batters (and vice-versa), because the right-handed pitcher's "inside" is the left-handed batter's "outside." Left handed pitchers get to pitch "inside" to left handed batters.
One exception to this rule is Jose Bautista, of the Toronto Blue Jays, whose forte is hitting inside (and is weaker outside). Left handed pitchers do better against him because their inside is his outside.


Endomorphism ring as a set of matrices

Question: Let $A=\mathbb Z[\sqrt{-5}]$, and let $I=(2,1+\sqrt{-5})$ (which is known to be a non-principal ideal of $A$ with $I^2=2A$). If we put $P=A \oplus I$, my question is:

Why the endomorphism ring of $P$ is the subring of matrices $\begin{pmatrix}A & I^{-1} \\I & A \\\end{pmatrix} \subseteq \mathbb M_2(K)$, where $K$ is the quotient field of $A$, and $I^{-1}=\{a\in K: aI \subseteq A\}$?

Thanks in advance!
Comment: $\{a\in A: aI\subseteq A\}=A$.
Comment: Sorry, I edited $a\in A$ into $a\in K$.
Answer: We have $\operatorname{Hom}_A(A,A)\simeq A$, $\operatorname{Hom}_A(A,I)\simeq I$, $\operatorname{Hom}_A(I,A)\simeq I^{-1}$, and $\operatorname{Hom}_A(I,I)\simeq A$. Is this enough for you to conclude?

Endomorphism ring as a set of matrices