Solve $ \binom{a}{2} + \binom{b}{2} = \binom{c}{2} $ with $a,b,c \in \mathbb{Z}$

Question: I am trying to solve the Diophantine equation:
$$ \binom{a}{2} + \binom{b}{2} = \binom{c}{2} $$
Here's what it looks like if you expand, it's variant of the Pythagorean triples:
$$ a \times (a-1) + b \times (b-1) = c \times (c-1) $$
I was able to find solutions by computer search but this could have also been checked using the Hasse principle.
\begin{eqnarray*}
\binom{3}{2}+ \binom{3}{2}&=& \binom{4}{2} \\ \\
\binom{5}{2}+ \binom{10}{2}&=& \binom{11}{2} \\ \\
\binom{15}{2}+ \binom{15}{2}&=& \binom{21}{2}
\end{eqnarray*}
and many others.  Is there a general formula for the $(a,b,c) \in \mathbb{Z}^3$ that satisfy this integer constraint.

<code>>>> N = 25
>>> f = lambda a : a*(a-1)/2
>>> X = [(a,b,c,f(a) + f(b) - f(c)) for a in range(N) for b in range(N) for c in range(N)]

>>> [(x[0],x[1],x[2]) for x in X if x[3] == 0 and x[0] > 1  and x[1] > 1 and x[2] > 1]

[( 3,  3,  4),  ( 4, 6, 7) , ( 5, 10, 11), ( 6,  4,  7), ( 6,  7,  9),
 ( 6, 15, 16),  ( 7, 6, 9) , ( 7, 10, 12), ( 7, 21, 22), ( 9, 11, 14),
 (10,  5, 11),  (10, 7, 12), (10, 14, 17), (10, 22, 24), (11,  9, 14),
 (12, 15, 19), (12, 21, 24), (13, 18, 22), (14, 10, 17), (15,  6, 16),
 (15, 12, 19), (15, 15, 21), (15, 19, 24), (18, 13, 22), (19, 15, 24),
 (21,  7, 22), (21, 12, 24), (22, 10, 24)]
</code>
Comment: https://artofproblemsolving.com/community/c3046h1046687__
Comment: https://math.stackexchange.com/questions/794510/curves-triangular-numbers
Answer: After some algebra you can rewrite the equation as
$$
a(a-1)=(c-b)(c+b-1)
$$
Note that $c-b$ and $c+b-1$ have opposite parity. Conversely, if $p$ and $q$ are integers with opposite parity, then we can find integers $b,c$ such that $p=c-b$, $q=c+b-1$: namely, $b=\frac{q+1-p}{2}$ and $c=\frac{q+1+p}{2}$.
That is to say, all solutions to the equation can be obtained in the following way:

Choose some number $a$. Factor $a(a-1)$ into two numbers $p,q$ of opposite parity. Since $a(a-1)$ is always even, this just means $p$ and $q$ can't both be even.
Take $b=\frac{q+1-p}{2}$, $c=\frac{q+1+p}{2}$.

For example, we could take $a=16$. Then $a(a-1)=240$, which factors into two numbers with opposite parity in four different ways:
\begin{align}
1&\cdot 240\\
3 &\cdot 80\\
5 &\cdot 48\\
15 &\cdot 16
\end{align}
These give four essentially different solutions to the equation:
\begin{align}
\binom{16}{2}+\binom{120}{2}&=\binom{121}{2}\\
\binom{16}{2}+\binom{39}{2}&=\binom{42}{2}\\
\binom{16}{2}+\binom{22}{2}&=\binom{27}{2}\\
\binom{16}{2}+\binom{1}{2}&=\binom{16}{2}
\end{align}
A few notes:

Swapping $p,q$, or replacing them by $-p,-q$, gives a solution which is essentially the same if you remember that $\binom{n}{2}=\binom{1-n}{2}$.
The symmetry between $a$ and $b$ means that this method will produce each solution twice. For example, the third solution above ($\binom{16}{2}+\binom{22}{2}=\binom{27}{2}$) could also have been found by taking $a=22$, $p=11$, $q=42$.
Answer: $$ (2a-1)^2 + ( 2b-1)^2 = 1 + (2c-1)^2  $$
Taking any $c,$
if the right hand side is not twice a prime, there will be nontrivial $a,b,$ while factoring the right hand side gives a method for finding them other than raw search. So that is one approach.
Parameterizing all uses the modular group  $SL_2 \mathbb Z$: take integers
$$ \alpha \delta - \beta \gamma = 1.  $$ We also demand $\alpha \beta + \gamma \delta $ odd. This means that one of $\alpha, \beta, \gamma, \delta$ is even and the other three odd. Then
$$ 2a-1 =  \alpha \delta + \beta \gamma $$
$$ 2b-1 = \alpha \beta - \gamma \delta $$
 $$ 2c-1 = \alpha \beta + \gamma \delta $$
Yet another approach is the automorphism group of the quadratic form. However, see page 124 in Magnus, Noneuclidean Tesselations and Their Groups, where Lemma 3.7 shows that this group also depends on the modular group. Well, actually 3.33 and 3.34 on the next page, now that I look more carefully.
I ought to emphasize that $x^2 + y^2 - z^2 = 0$ possesses a parametrization in just two variables, while $x^2 + y^2 - z^2 = 1$ jumps immediately to four variables with a condition, namely the modular group.  Worth adding $x^2 + y^2 + z^2 - w^2 = 0$ is naturally four variables, it is parameterized by the integral quaternions.


How can you resolve mixed normal distributions into their component data sets?

Question: I am a bird ringer with 5000 data items recording the wing length of Willow Warblers caught in spring at a bird observatory in the UK. The data is bimodal and consists of 2 normally distributed components. One component is male birds the other is female birds. There is no other data that can identify the gender of individual birds. I would like to know the mean and standard deviation of each data set and the number of members in each. Is there a computer driven approach that will provide this analysis that I can access and use?
Comment: Thanks for such a quick response. I have a long way to go on this but your help gives me plenty to look at.
Comment: I included all that information in my answer, so I'll delete the above comments.
Answer: One approach would be to fit a two component Gaussian mixture model. This models the observed distribution as a mixture $w_1 f(\mu_1,\sigma_1)+(1-w_1)f(\mu_2,\sigma_2)$ where $f$ is the normal density.
There are a number of approaches to doing so; the E-M algorithm (by introducing latent variables - in your case indicating the relative weight to being from one of the two sexes) is one common approach. This should converge to the maximum likelihood estimate of the 5 unknown parameters above.
The book Elements of Statistical Learning, 2nd.Ed by Hastie, Tibshirani and Friedman gives an explicit algorithm (Algorithm 8.2 in the 10th printing, p277). This book is commonly available in university libraries and is also downloadable from the web-page for the book (in pdf form) here at one of the authors' academic webpages.
A number of questions on our site discuss this method.
There's a set of slides by some of the same authors here that also discuss this approach. One suitable search term on our site that turns up some of the previous posts on this topic is gaussian mixture EM.
This is a pretty standard method and lots of software is available to fit it.
For example, if you use R, the function normalmixEM2comp in package mixtools is specifically for 2-component Gaussian mixtures; this automates the process of fitting the mixture.
I created some data and fitted a mixture using it (I had never used this package before, but it's very simple and works like many other such programs):
The simulated data set of wing lengths (just under 5000 values) is in the variable "wing". Here's a histogram of the data:

After loading the package, here's how I fitted the mixture (the value 0.5 is the initial guess at the proportion in the first component, the 64,71 are initial guesses at wing length for the two components, and the 1.2,1.2 are initial guesses at standard deviation for the two components):
 mixres = normalmixEM2comp(wing, 0.5, c(64,71), c(1.2,1.2))
number of iterations= 38

So let's look at the results:
 summary(mixres)
summary of normalmixEM object:
          comp 1    comp 2
lambda  0.554041  0.445959
mu     64.477140 70.460471
sigma   1.301563  1.841486
loglik at estimate:  -12251.45

Pretty good actually, since those are really close to the values I used to generate the data to begin with.
Summarizing that information back onto the histogram:

In this case I obtained the estimated count form females by taking the proportion for component 1 times the overall count. This undercounted the females by 14, which is well within the uncertainty involved. On the other hand, the output of the function above also gives an estimated (posterior) probability of being in each component (which was returned in mixres$probability). If I allocate each of the individual birds to a sex based on which one has the higher relative probability for that winglength, the estimated count is 2800 female (an overcount of 17 ... again, within the uncertainty one might expect for the count with this fitted model).

[However, this approach will tend to lead to an overcount of the more prevalent group, as it did here.]
You should be able to do similar things with other software for fitting such mixtures.
Answer: You need to find $\theta^\ast = (\mu_1,\sigma_1,\mu_2,\sigma_2,n_1)$ fitting your data, so you could try guessing various $\theta$ and then picking the top-scoring one.  To score a particular $\theta$, you could try a Kolmogorov-Smirnov test.
I don't know how accurate you need it, but with a histogram like this ...

... my prototype code finds what it thinks is the optimal $\theta$ comfortably within 5% of all components of the true $\theta^\ast$.  The neater and more obviously bimodal your histogram, the better the results will be.
Would R code be helpful?  Are your observations in some convenient format like a CSV file?  Would you be willing to upload the data?
Comment: Rather than add all the 5000 data items here are the wing lengths and counts of each: 60 112:61 284:62 730:63 902:64 824:65 671:66 347:67 305:68 386:69 391:70 293:71 100:72 38. about 20 to 30% should be the long wing length(male)
Comment: Have just seen much better answer from Glen_b.  Following his instructions, I think you'll end up with 28.4% male (mean 68.6, sd 1.46),  the rest female (mean 63.4, sd 1.58).


Get value from dialog without closing it?

Question: I have an application that uses a JDialog to get input from the user, and then searching for files, not a browse dialog, but a more specialized one using metadata.
All this works fine. The only problem is I would like to be able to let the user input the search values, press Ok, and receive these values to do the search and some other operations (from the calling class that opened the dialog) without closing the dialog?
It's necessary to do these operations from the calling class, because that's part of a plugin in an editor.
Basically, in short it's sort of like the way a Find dialog works in any editor - the find dialog stays open while you skip from one found item to the next...
It seems like I'm missing something simple, but I cannot see how to do this.
EDIT:
I tried this in a simple test application according to the tutorial suggested by Nick Rippe, but I think I'm misunderstanding it somehow, because I cannot get it to work. I added a field with getters and setters, and then try to get it:
Main class:
public class TestJFrames {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        TestForm frame = new TestForm();
        frame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE);
        frame.addPropertyChangeListener("fileSelected", new FileSelectedListener());
        frame.setVisible(true);
    }
}

class FileSelectedListener implements PropertyChangeListener {

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        System.out.println("TEST");
    }
}

From the form class:
  private String fileSelected;
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        this.setFileSelected("Test");
    }

    public String getFileSelected() {
        return fileSelected;
    }

    public void setFileSelected(String fileSelected) {
        this.fileSelected = fileSelected;
    }

I ended up finding a different solution. Posting it here if it could help someone else with a similar difficulty:
It hit me that I could listen to the button event from the calling class, by registering it as a listener to the dialog class. I pretty much followed this example: Create a custom event in Java
Comment: @AndrewThompson: It was a problem because I could only return control to the calling class by closing the dialog. I've noticed that you often suggest using a "SSCCE". I'm sure that's a good idea in many cases, but in many cases one can be so stuck not understanding where to begin, so it's hard to do.
Comment: It all depends on the code in the ok JButton's Action or ActionListener. What code do you have there?
Comment: *"stuck not understanding where to begin .. I could only return control to the calling class by closing the dialog."*  If you post an SSCCE of that, it provides us with 1) A good idea of where you are at. 2) A template to (if we like) fill in the missing bits to answer the question.  Not all SSCCEs must make a serious attempt at achieving the problem they are trying to solve, though it is better if they do.
Answer: The Java Tutorials have a section specifically devoted to this.  I'd suggest checking that out.
Combine that with the Getting User Input section, and you have exactly what you wanted.
EDIT
Here's an example from messing with the tutorials a little:
import java.awt.event.*;
import javax.swing.*;

public class Temp extends Box{
    JFrame frame;
    JTextArea text;

    public Temp(JFrame frame){
        super(BoxLayout.Y_AXIS);
        this.frame = frame;
        text = new JTextArea("Clickity Clack, down't the track.\nspam");
        add(text);
        JButton button = new JButton("Click Me");
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                launchDialog();
            }
        });
        add(button);
    }

    public void launchDialog(){
        //What you want the find button to do
        JButton findButton = new JButton("Find");
        findButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int start = text.getText().indexOf("spam");
                int end = start + "spam".length();
                if(start != -1){
                    text.requestFocus();
                    text.select(start, end);
                }
            }
        });

        //Cancel button hides the dialog
        JButton cancelButton = new JButton("Cancel");

        // Create the options displayed in the dialog
        final JOptionPane optionPane = new JOptionPane(
                "Find \"spam\"?\n"
                + "Do you understand?",
                JOptionPane.QUESTION_MESSAGE,
                JOptionPane.YES_NO_OPTION, null, new Object[]{findButton, cancelButton});

        // Build the dialog window
        final JDialog dialog = new JDialog(frame,
                                     "Click a button",
                                     false);

        //Add action to close button
        cancelButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dialog.setVisible(false);
            }
        });

        //Finish up and make it visible
        dialog.setContentPane(optionPane);
        dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        dialog.setLocation(100, 100);
        dialog.pack();
        dialog.setVisible(true);

    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable(){

            @Override
            public void run() {
                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setContentPane(new Temp(frame));
                frame.pack();
                frame.setVisible(true);
            }});
    }

}

Comment: +1 for citing the tutorial. There's a related example [here](http://stackoverflow.com/a/12451673/230513).
Comment: Thanks for the tip, it looks promising, but I cannot make it work. Please see my update!
Comment: @NickRippe: Thanks, your code worked fine. However, it was too complex for what I was trying to do, especially since I already had an interface set up in the NetBeans GUI builder. So I found another way around it registering a listener. An upvote for the interesting suggestion though.


A smooth nonzero function $\mathbb R\to\mathbb R$ with uniformly bounded derivatives tending to zero at infinity?

Question: $\def\scrBp{\mathscr B\boldsymbol.}\def\rD{{\rm D}\kern.4mm}\def\ssp{\kern.4mm}\def\bbR{\mathbb R}
$For a certain purpose I invented the Banach space $\scrBp^\infty(\ssp\bbR\ssp)$ defined as follows. The vectors are all smooth functions $x:\bbR\to\bbR$ such that there is $M\in\bbR^+$ with $|\,\rD^kx(t)\,|\le M$ and $\lim_{\,s\to\pm\infty\,}|\,\rD^kx(s)\,|=0$ for all $k\in\mathbb N_0$ and $t\in\bbR$ . The norm of $x$ is the infimum of the set of all these $M$ . Now I am wondering whether this space has any nonzero vectors. Hence the question.
Comment: A smooth function with uniformly bounded derivatives is real-analytic, and its Taylor series converges on all of $\mathbb{C}$, so it would be the restriction of an entire function to the real axis. I'm almost sure that means your space is $\{0\}$, but I don't see a proof yet.
Comment: @Nishant An example is $t\mapsto t^{-1}\,\sin(t^2)$ .
Comment: I doubt so, since neither $e^{-x^2}$-like functions nor functions from $C_c^\infty$ will be in there (the uniform constant breaks these) as far as I can tell.
Comment: Can a continuous and differentiable function approach some finite limit as $x\to\infty$, without its derivative approaching $0$?
Comment: In view of Daniel Fischer's comment above, I added the "complex-analysis" tag.
Comment: Contrary to @DanielFischer 's conjecture, one can use Fourier methods to show that there are a lot of these functions (see my answer). It would be interesting to me what the original context of the invention of that Banach space was (had it something to do with Fourier analysis?)? Actually, Daniel's comment gave me the idea for the proof below, because I recalled that every function with compact support has an analytic Fourier transform, which gave me the idea to use Fourier methods.
Comment: @PhoemueX Thanks for the positive answer. The original context for which I invented the space was that I wanted to construct a contravariant *smooth* functor in the sense of Serge Lang's §III.4 in his book *Differential Manifolds*. I wanted the functor be such that via Lang's construction one can associate an infinite-rank Banach vector bundle with the tangent bundle of a finite-dimensional smooth manifold. It is easy to construct such *covariant* functors as well as contravariant functors in the category of Fréchet spaces which lead to vector bundles with non-Banach Fréchet fibres. (cont.)
Comment: Actually, for my purpose, I need the space over all finite-dimensional vector spaces, but the generalization from the one-dimensional case is straightforward.
Answer: It turns out that there are a lot of these functions. To see this,
one possibility is to use the theory of the Fourier transform:
Choose some $\varphi\in C_{c}^{\infty}\left(\left(-\frac{1}{2\pi},\frac{1}{2\pi}\right)\right)$
and let $f:=\mathcal{F}\varphi=\widehat{\varphi}$ be the Fourier
transform of $\varphi$, i.e.
$$
f\left(\xi\right)=\int_{\mathbb{R}}\varphi\left(x\right)\cdot e^{-2\pi ix\xi}\,{\rm d}x.
$$
By the usual properties of the Fourier transform, we conclude that
$f\in\mathcal{S}\left(\mathbb{R}\right)$ is a Schwartz-function,
which means
$$
C_{m,n}:=\sup_{x\in\mathbb{R}}\left|x^{m}\cdot\partial^{n}f\left(x\right)\right|<\infty
$$
 for all $m,n\in\mathbb{N}_{0}$. In particular, this implies (for
$\left|x\right|\geq1$):
$$
\left|\partial^{n}f\left(x\right)\right|=\left|\frac{x\cdot\partial^{n}f\left(x\right)}{x}\right|\leq\frac{C_{1,n}}{\left|x\right|}\xrightarrow[x\to\pm\infty]{}0
$$
so that $f$ fulfills the second one of your requirements.
By choosing (e.g.) $\varphi\geq0$ and $\varphi\not\equiv0$, we can
also ensure that $f\left(0\right)=\int_{\mathbb{R}}\varphi\left(x\right)\,{\rm d}x>0$,
i.e. $f\not\equiv0$ (alternatively, we have $\varphi=\mathcal{F}^{-1}f$,
so that $f\not\equiv0$ holds as soon as $\varphi\not\equiv0$ is
true).
Finally, we can differentiate "under the integral sign" to get
\begin{eqnarray*}
\left|\partial^{n}f\left(\xi\right)\right| & = & \left|\int_{\mathbb{R}}\varphi\left(x\right)\cdot\frac{{\rm d}^{n}}{{\rm d}\xi^{n}}e^{-2\pi ix\xi}\,{\rm d}x\right|\\
 & = & \left|\int_{\mathbb{R}}\varphi\left(x\right)\cdot\left(-2\pi ix\right)^{n}\cdot e^{-2\pi ix\xi}\,{\rm d}x\right|\\
 & \leq & \int_{\mathbb{R}}\left|\varphi\left(x\right)\right|\cdot\left|2\pi x\right|^{n}\,{\rm d}x\\
 & \overset{{\rm supp}\left(\varphi\right)\subset\left(-\frac{1}{2\pi},\frac{1}{2\pi}\right)}{\leq} & \int_{-\frac{1}{2\pi}}^{\frac{1}{2\pi}}\left|\varphi\left(x\right)\right|\cdot\left|2\pi x\right|^{n}\,{\rm d}x\\
 & \leq & \int_{-\frac{1}{2\pi}}^{\frac{1}{2\pi}}\left|\varphi\left(x\right)\right|\,{\rm d}x\leq\left\Vert \varphi\right\Vert _{L^{1}},
\end{eqnarray*}
so that the derivatives of $f$ are also uniformly bounded, which is the first of your desired properties.


A subgroup $Z$ of $p$-adic integer such that $Z/pZ\neq C_p$.

Question: This question may be weird in the sense that I am considering a subgroup of infinite index.
Let $p$ be a prime (let's say $p\neq 2$ although I'm not sure whether this assumption is needed) and we consider subgroup $\mathbb{Z}_p$, say $Z$, which contains $\mathbb{Z}$. Now I want to consider the group $Z/pZ$. For the obvious case, i.e $Z=\mathbb{Z}$ or $Z=\mathbb{Z}_p$, this group is isomorphic to cyclic group of order $p$, $C_p$. If $Z$ is smallest subgroup containing $\mathbb{Z}$ and a 'rational' number then $Z/pZ$ would be the same as before. However this doesn't seem to be true in general (for instance let $Z$ be a smallest subgroup containing $\mathbb{Z}$ and an irrational element). Would there be any classification of subgroup Z of $\mathbb{Z}_p$ such that $Z/pZ\cong C_p$? Or some broader property which $Z$ could have to make it true?
Motivation for this is an exercise of Neukirch in Algebraic number theory
Comment: It didn't help that the OP confused the issue by using $Z$ as the letter for a subgroup of $\mathbb Z_p$ containing $\mathbb Z$ :) @Arthur
Comment: @Arthur You sure about that? The equivalence class of $z \in Z$ would depend only on the $n+1$-th last digit.
Comment: @Arthur You don't seem to notice that we're looking at $Z/pZ$ and not at $\mathbb{Z}_p/Z$.
Comment: @McFry That's what I have been doing. I'm just being blind.
Comment: It appears I missed something. Notation I have used is from Neukirch so blame him for that. To be fair I really should have been clearer though.
Answer: $Z/pZ$ is always a vector space over $\mathbb Z/p\mathbb Z$. It is of dimension one if every two vectors are linearly dependent.
This means that if $z_1,z_2\in Z\setminus pZ$ then there are $1\leq a,b<p$ so that $az_1+bz_2\in pZ$, or, really, to simplify, you need $1\leq c<p$ so that $cz_1+z_2\in pZ$.
In particular, it is necessary that $Z\setminus pZ$ must have elements all of the same valuation in $\mathbb Z_p$, though that is far from sufficient.
If $Z$ contains $\mathbb Z$, then this condition means that given any element $z\in Z\setminus pZ$ of the form:
$$z=a_0p^0+a_{1}p^{1}+\dots\tag{1}$$
with $0\leq a_i<p$ and $a_0\neq 0$, then $a_{1}p^0+a_{2}p^{1}+\dots\in Z$.
Also, since all the elements of $Z\setminus pZ$ have the same valuation, then if $a_{0}=0$ in $(1)$ then $z\in pZ$ so $a_{1}p^0+a_{2}p^{1}+\dots\in Z$.
So, assuming $\mathbb Z\subset Z$, that ultimately means you need the one condition:

$Z\cap p\mathbb Z_p= pZ$

This should be necessary and sufficient.
The general subgroup $Z$ of $\mathbb Z_p$ such that $Z/pZ\cong C_p$ (without necessarily containing $\mathbb Z$) is some multiple of the above sort of group: $Z=wZ_0$ for $w$ any non-zero element of $\mathbb Z_p$ and $Z_0$ some group containing $1$ and satisfying $Z_0/pZ_0\cong C_p$. So the above really is the heart of all such groups.
Comment: This is great! I honestly didn't expect any real nice classification. Was mostly hoping! Not sure whether this will actually help me out solving the exercise but I will certainly have a better chance now!


Outlook permission on folder vba

Question: First, I want to apologize for my poor English and possibly, the question. I searched a whole day for a possibility to add permissions to a outlook folder via a vba-script, but without results.
We want to create a folder in the inbox and give a specific system user the right to read and write to this folder. This is necessary, because a web-based intranet application has to write into this personal folder in outlook.
All new users of our application must create this folder in outlook and give read/write permission to the system user. For some users its very difficult to manage it and therefore I want to develop an addin in outlook making all this steps automatically.
I read something about Redemption and ACE, but I was unable to use those two libraries, because they are not installed on the system or I don't know how to include them into my Outlook script.
I thought I could write a batch-file that will set up all necessary permissions. Is this possible ? Is there somebody else who have experience with this subject?
I'm looking forward to your responses.
Answer: You can either use Extended MAPI in C++ or Delphi to work with the folder's PR_ACL table or you can use Redemption (which exposes this functionality to any language).
Why exactly you couldn't use Redemption? All you need to install it is to register it using regsvr32.exe.
Comment: thank you for your response. i cant find the redemption.dll, i think this is the problem? I think i must execute  "regsvr32.exe redemption.dll"

Outlook permission on folder vba


Finding a third solution from two other solutions for linear ODE not equal to 0

Question: Edit: I am not asking how to solve the differential equation below. I know how to solve the equation as it is extremely easy. What I am asking is this:
For the equation $y' + y = 0$, if you already have the solutions $y_1, y_2$, then the solution $y_3 = c_1y_1 + c_2y_2$ where $c_1,c_2$ are any constants.
However, if that equation is modified to be $y' + y = 4$ for instance, then it doesn't look like you can find $y_3$ by taking any linear combination of $y_1,y_2$. It looks like you would need a specific linear combination, and I'd like to know how you would find that as I seem to be missing something.
In short, what constants $c_1, c_2$ would make $y_3 = c_1y_1 + c_2y_2$ a solution of that equation.
Also to whoever downvoted me: Seriously? Why are you people so obsessed with downvoting simple questions? I'm not asking for you to solve my homework or how to add 1+1. Why would you downvote me for trying to clarify something?
Comment: If $y'(x)+y(x)=4$ then what ODE does $ay(x)$ solve for constant, a?
Answer: The solution to a linear inhomogeneous ODE (inhomogeneous means zero is not a solution, or equivalently, there's a term with no $y$-dependence) is the sum of two parts, the complementary function $y_c$, which solves the homogeneous equation, and the particular integral $y_p$, which is one solution to the inhomogeneous equation. The complementary function is a sum $\sum_i A_i y_i$, and the constants $A_i$ are arbitrary unless determined by some set of boundary conditions, but the particular integral is fixed (at least up to adding bits of the complementary function to it).

This is exactly analogous to solving the inhomogeneous matrix equation
$$ Ax = b, $$
where the homogeneous equation $Ax=0$ has nonzero solutions: the general solution is the sum of a particular solution to $Ax=b$ and an arbitrary sum of solutions to the homogeneous equation.
Answer: When an equation is non-homogenous, then there is a particular solution $y_p(x)$ that ensures the left side always equals the right side. This particular solution is decided by the equation and doesn't have a constant multiplier.
In your case, $y' + y = 4$, the particular solution is pretty clear. Try $y = 4$, and the left side equals the right side. So, a solution to the DE is $y = 4$.
Of course, that's not the most general solution. Notice that $y = Ce^{-x} + 4$ is the most general solution. That extra term comes from $y' + y = 0$. Since the DE is of order 1, there is one constant.


Request Dispatcher to access pages in WEB-INF folder?

Question: according to netbeans e commerce tutorial. https://netbeans.org/kb/docs/javaee/ecommerce/page-views-controller.html#view there are 4 pages include header & footer placed in WEB-INF folder but they can access it via controllerservlet (RequestDispatcher).
i've googling and found a lot of questions about how to access/redirect to pages in WEB-INF folder but the result can't access pages(xhtml,jsp,etc) in WEB-INF folder.
my questions is
1. could i access pages in WEB-INF folder with RequestDispatcher (with JSF 2.X) ?
2. how to access pages in WEB-INF with JSF 2.X ?
Answer: A simple solution is to create a page that is outside WEB-INF. Let us call this page placeHolder.xhtml
If you know which page fragment you wish to show from within WEB-INF, then make it available via a bean. Let us say the following method returns the page that has to be included
<code>#{mybean.pageToInclude}
</code>
Now, in the placeHolder.xhtml file, use the ui:include tag to include page that is present under WEB-INF
<code>placeHolder.xhtml
...
  <ui:inlucde src="#{mybean.pageToInclude}"/>
</code>
This way you can get code within WEB-INF to be made available in a page that is outside of it.
There are other techniques like writing a ResourceHandler to locate view resources under different locations that you can use too.
Hope that helps.


Why is AWS RDS MYSQL INSERT taking READ IOPS?

Question: I have db.r3.2xlarge with 4000 PIOPS. I'm inserting like 1 billion rows from EC2 instances. There are like 40GB free RAM right now.
Currently, out of 4000 PIOPS, READ PIOPS is taking 3000 and I'm only getting 1000 WRITE PIOPS. So, it's been a low writing.
How do i check which is taking READ PIOPS? And how to speed thing up?
Thank you.
Edit:
insert ignore into dna (hash, time, song_id) values (b%s, b%s, %s)
I'm using self.cursor.executemany(query, rows) from python
hash + time + song_id is a composite primary key.
I'm using AWS RDS InnoDB.
I have 4000 PIOPS. However, it is now stuck at 2000 total. I have 60MB/s WRITE THROUGHPUT.
Comment: show us the insert statement, tell us which type of database you are using and confirm you are actually using RDS and not a database installed on EC2
Comment: @Vorsprung, I've made the edits. Please let me know.
Comment: probably won't make any difference but you haven't said if you are using mysql or Aurora
Comment: @Vorsprung, I'm using AWS RDS MySQL InnoDB.
Answer: If the hash is your primary key or is indexed, you're not inserting in primary my and/or index order.
Also, you're using INSERT IGNORE, which suggests you are trying to avoid the inevitable duplicate key error because there's duplicate data among what you're inserting.
For both of these reasons, InnoDB has to do a lot of readying to load the appropriate pages from the tablespaces on disk into memory to find the spot(s) in the primary and/or any secondary indexes where the next row needs to go, which may turn out to be wasted effort if the row is a duplicate, and may turn out to require a page split so that space is available to randomly insert the next hash into its proper place.
If hash is the primary key, it would probably be to your advantage to drop all other indexes while inserting, then add them at the end, where they can be built more efficiently.
Pre-sorting the inserts by hash should help, some, if the batches are large enough and hash is indeed the primary key.
Comment: my show create table looks like - CREATE TABLE `dna` (
  `hash` bit(26) NOT NULL,
  `time` bit(14) NOT NULL,
  `song_id` mediumint(9) NOT NULL,
  PRIMARY KEY (`hash`,`time`,`song_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=latin1
Comment: `bit(26)` is an interesting choice.  I assume you realize that (if my math is correct) this column can only support 67,108,864 (2^26) unique hashes.  Are you inserting the rows in sorted order by (hash,time,song_id)?
Comment: Hi, I'm not sure what you mean by sorted order. My primary key is (hash + time + song_id) so it's not just bit(26). It also considers time + song_id when deciding either it's unique or not. isn't it?


Windows Policies and "Look in Box" on Windows 7

Question: I am troubleshooting a computer that is running Windows 7 within a domain. The "look in" box on save and open dialogs is missing all but one entry. I'm guessing that someone flipped on a policy setting that disabled the other entries, because I am now noticing that entries such as "Computer" and "C:" are missing from all of the computers affected by the system policies.
Can anyone point me to where such a setting would appear within Windows group policy controls?
Answer: It sounds like you're referring to items displayed in the Places Bar. This setting, when configured via GPO, is configured at:
User Configuration|Administrative Templates|Windows Components|Windows Explorer|Common Open File Dialog|Items displayed in Places Bar
You can run RSOP from the local machine (if your user account has the appropriate rights) or you can run Group Policy Results in the Group Policy Management Console (again if your user account has the appropriate rights) to determine if this setting is being configured via GPO.
Answer: A lot of those are kept under Policies -> Administrative Templates -> Windows Components -> Windows Explorer. Check both the Computer and User policies for that, since they both can restrict.
If you have the ability, doing a Resultant Set of POlicies run from the Group Policy Management Console should let you figure out where they're coming from.


É possível adicionar um número diferente para cada  criada num for?

Question: Tenho um carossel em bootstrap e para chamar os posts do wordpress dentro dele, tenho um for dentro da
.
O for consegue criar os posts, porém não estou conseguindo incluir os indicadores de cada post (as bolinhas que ficam abaixo do carrossel ou
).
A estrutura dos indicadores é:

O que eu preciso é desse data-slide-to, pois ele está sendo definido como 0 para cada post que foi criado, ou seja, independente de qual eu clique, o carrossel volta pro primeiro post.
O que eu tenho:

   <?php for ($i = 1; $i <= NUMBER_OF_SLIDES; $i++) : ?>
      <li data-target="#carousel" data-slide-to="0" class="<?php echo ($i == 1) ? 'active' : ''; ?>">

   <?php endfor; ?>

As
 são criadas dentro do for, porém não estou conseguindo atribuir um número diferente do data-slide-to para cada
 criada.
O que estou tentando fazer, é com que o output desse for saia dessa maneira:

...

Answer: Seria isso?
<?php for ($i = 0; $i <= NUMBER_OF_SLIDES; $i++) : ?>
      <li data-target="#carousel" data-slide-to="<?php echo $i; ?>" class="<?php echo ($i == 1) ? 'active' : ''; ?>">

<?php endfor; ?>

Comment: Eu tentei esse método anteriormente, mas o problema é que ao clicar em qualquer bullet, ele pula um slide ou não vai, mesmo estando de 1 a 5 corretamente. Será pelo fato de não estar iniciando em 0?
Comment: Bem, era isso mesmo, a falta de iniciar em 0 hahahahaha quebrei a cabeça nisso atoa, mas obrigado pela resposta!
Comment: sim, provavelmente. Por isso iniciei o $i em 0. Acho que deve ser isso mesmo.
Comment: blz isso ae, show! =)


Sampling distribution

Question: A random variable takes the values 1, 2, and 3, each with equal probability. List all possible samples of size two that may be chosen, without replacement, from this population and hence construct the sampling distribution of the sample mean.
Comment: What have you tried so far?  What part or parts of the question are you having difficulty with?
Comment: So, for each of the possible samples of size two, find the mean of the sample.  Then find the probability of having observed that sample.  This becomes your sampling distribution.  For example, if you get a sample $\{1, 3\}$, the mean of that sample is $2$, and the probability of observing $\{1, 3\}$ is...?  Then $\Pr[\bar X = 2] = \ldots$.
Comment: @Jollie : Questions posted here should not be phrased in a manner in which it is appropriate for an instructor to assign homework problems.  You should be asking a question, not passing on to us a question written by someone other than you, with no indication that you've thought about it.
Comment: I listed down all the possibilities already. But I don't know how to 'construct the sampling distribution of sample mean'.
Comment: Easy start: Determine the probability of selecting a first number and then a second number.  For sure, you should get all equal probabilities.
Comment: So is the mean (1/3x1/2)/2 for all possible samples?What do u mean by the probability having observed that sample?
Comment: The sample mean is the mean of the sample.  So, if you draw a $1$ and then a $3$, you got the sample $\{1, 3\}$ and the mean of that sample is $(1+3)/2 = 2$.  The probability that you drew the sample $\{1, 3\}$ is $1/3$, because there are three possible samples of size two drawn without replacement:  $\{1, 2\}$, $\{1, 3\}$, $\{2, 3\}$, and each is equally likely because the individual probabilities of getting a $1$, $2$, or $3$ are equally likely.
Comment: Ok I understood already. Thank you very much for your help! :)
Answer: Without replacement:
\begin{align}
1+2 & = 3 \\
1+3 & = 4 \\  \\
2+1 & = 3 \\
2+3 & = 5 \\  \\
3+1 & = 4 \\
3+2 & = 5
\end{align}
Sorting the sums into increasing order, you have: $\quad 3,3, \quad 4,4, \quad 5,5$
With replacement:
\begin{align}
1+1 & = 2 \\
1+2 & = 3 \\
1+3 & = 4 \\  \\
2+1 & = 3 \\
2+2 & = 4 \\
2+3 & = 5 \\  \\
3+1 & = 4 \\
3+2 & = 5 \\
3+3 & = 6
\end{align}
Sorting the sums into increasing order, you have: $\quad 2, \quad 3,3, \quad 4,4,4 \quad 5,5, \quad 6$
The sample mean for a sample of size $2$ is just half the sum of the observations in a sample.
(Of course, you should write the solution that you turn in the way I wrote what you see above, but this should tell you how to solve the problem.)
Comment: The sampling occurs **without replacement.**
Comment: I missed that.  Now I've edited my answer to include both.

Sampling distribution


ggplot2: geom_vline to heatmap

Question: I created the below ggplot but I don't know how to highlight and to add 5 geom_vline() in my plot at: 04:00:00, 08:00:00,12:00:00,16:00:00 and 20:00:00? Is a way to do that? Also how to add the time to the x axis as I tried with x_continous but it does not work?

Sample code
ggplot(df, aes(x=time, y=variable, fill=value)) +
  geom_tile() +
  scale_fill_gradient(low="lightyellow", high="red") +
  labs(x="Time", y="Date", title="", fill="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(axis.text.x = element_text( hjust = 1),  face="bold", size=16, color="black") +
  theme(axis.text.y = element_text( hjust = 1),  face="bold", size=16, color="black") +
  theme_bw()+
  theme(plot.title = element_text(hjust = 0.5))

Sample data: Selected only the first 300
structure(list(time = structure(c(1800, 3600, 5400, 7200, 9000,
    10800, 12600, 14400, 16200, 18000, 19800, 21600, 23400, 25200,
    27000, 28800, 30600, 32400, 34200, 36000, 37800, 39600, 41400,
    43200, 45000, 46800, 48600, 50400, 52200, 54000, 55800, 57600,
    59400, 61200, 63000, 64800, 66600, 68400, 70200, 72000, 73800,
    75600, 77400, 79200, 81000, 82800, 84600, 86400, 1800, 3600,
    5400, 7200, 9000, 10800, 12600, 14400, 16200, 18000, 19800, 21600,
    23400, 25200, 27000, 28800, 30600, 32400, 34200, 36000, 37800,
    39600, 41400, 43200, 45000, 46800, 48600, 50400, 52200, 54000,
    55800, 57600, 59400, 61200, 63000, 64800, 66600, 68400, 70200,
    72000, 73800, 75600, 77400, 79200, 81000, 82800, 84600, 86400,
    1800, 3600, 5400, 7200, 9000, 10800, 12600, 14400, 16200, 18000,
    19800, 21600, 23400, 25200, 27000, 28800, 30600, 32400, 34200,
    36000, 37800, 39600, 41400, 43200, 45000, 46800, 48600, 50400,
    52200, 54000, 55800, 57600, 59400, 61200, 63000, 64800, 66600,
    68400, 70200, 72000, 73800, 75600, 77400, 79200, 81000, 82800,
    84600, 86400, 1800, 3600, 5400, 7200, 9000, 10800, 12600, 14400,
    16200, 18000, 19800, 21600, 23400, 25200, 27000, 28800, 30600,
    32400, 34200, 36000, 37800, 39600, 41400, 43200, 45000, 46800,
    48600, 50400, 52200, 54000, 55800, 57600, 59400, 61200, 63000,
    64800, 66600, 68400, 70200, 72000, 73800, 75600, 77400, 79200,
    81000, 82800, 84600, 86400, 1800, 3600, 5400, 7200, 9000, 10800,
    12600, 14400, 16200, 18000, 19800, 21600, 23400, 25200, 27000,
    28800, 30600, 32400, 34200, 36000, 37800, 39600, 41400, 43200,
    45000, 46800, 48600, 50400, 52200, 54000, 55800, 57600, 59400,
    61200, 63000, 64800, 66600, 68400, 70200, 72000, 73800, 75600,
    77400, 79200, 81000, 82800, 84600, 86400, 1800, 3600, 5400, 7200,
    9000, 10800, 12600, 14400, 16200, 18000, 19800, 21600, 23400,
    25200, 27000, 28800, 30600, 32400, 34200, 36000, 37800, 39600,
    41400, 43200, 45000, 46800, 48600, 50400, 52200, 54000, 55800,
    57600, 59400, 61200, 63000, 64800, 66600, 68400, 70200, 72000,
    73800, 75600, 77400, 79200, 81000, 82800, 84600, 86400, 1800,
    3600, 5400, 7200, 9000, 10800, 12600, 14400, 16200, 18000, 19800,
    21600), class = c("hms", "difftime"), units = "secs"), variable = c("02/01/2019",
    "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019",
    "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019",
    "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019",
    "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019",
    "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019",
    "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019",
    "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019",
    "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019",
    "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019", "02/01/2019",
    "02/01/2019", "02/01/2019", "03/01/2019", "03/01/2019", "03/01/2019",
    "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019",
    "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019",
    "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019",
    "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019",
    "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019",
    "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019",
    "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019",
    "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019",
    "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019", "03/01/2019",
    "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019",
    "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019",
    "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019",
    "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019",
    "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019",
    "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019",
    "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019",
    "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019",
    "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019", "04/01/2019",
    "04/01/2019", "04/01/2019", "04/01/2019", "05/01/2019", "05/01/2019",
    "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019",
    "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019",
    "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019",
    "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019",
    "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019",
    "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019",
    "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019",
    "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019",
    "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019", "05/01/2019",
    "05/01/2019", "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019",
    "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019",
    "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019",
    "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019",
    "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019",
    "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019",
    "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019",
    "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019",
    "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019",
    "06/01/2019", "06/01/2019", "06/01/2019", "06/01/2019", "07/01/2019",
    "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019",
    "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019",
    "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019",
    "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019",
    "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019",
    "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019",
    "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019",
    "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019",
    "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019", "07/01/2019",
    "07/01/2019", "07/01/2019", "08/01/2019", "08/01/2019", "08/01/2019",
    "08/01/2019", "08/01/2019", "08/01/2019", "08/01/2019", "08/01/2019",
    "08/01/2019", "08/01/2019", "08/01/2019", "08/01/2019"), value = c(0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0)), row.names = c(NA, -300L), class = c("tbl_df",
    "tbl", "data.frame"))

Answer: You could add your geom_vlines by converting the vector of times to hms format using lubridate::hms and passing the result to the xintercept argument of geom_vline:
library(ggplot2)
library(lubridate)

ggplot(df, aes(x=time, y=variable, fill=value)) +
  geom_tile() +
  geom_vline(xintercept = lubridate::hms(c("04:00:00", "08:00:00","12:00:00","16:00:00", "20:00:00"))) +
  scale_fill_gradient(low="lightyellow", high="red") +
  labs(x="Time", y="Date", title="", fill="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(axis.text.x = element_text( hjust = 1),  face="bold", size=16, color="black") +
  theme(axis.text.y = element_text( hjust = 1),  face="bold", size=16, color="black") +
  theme_bw()+
  theme(plot.title = element_text(hjust = 0.5))

Comment: Try with `scale_x_time(breaks = lubridate::hms(c("04:00:00", "08:00:00","12:00:00","16:00:00", "20:00:00")))`
Comment: As your dates are characters you could try with `fct_rev(variable)`. That will work for your example data. BTW: You could remove the white space by using `scale_x_time(..., expand=c(0,0))` and `scale_y_discrete(..., expand = ...)`. That will remove the default expansion of the scale added by ggplot2.
Comment: many thanks for your time. I don't know how to highlight on the x-axis "04:00:00", "08:00:00","12:00:00","16:00:00", "20:00:00", it does not work with x_continous. Alos why is the white gap between the x and y-axis?
Comment: I tried scale_x_continous() and it did not work
Comment: is there a way to have the date in increasing order and not in decreasing one?

ggplot2: geom_vline to heatmap


Random numbers in my array are filled by last one randomed

Question: I created program in which user can choose how many numbers have array and this array should have random values. Well, it doesn't. To check after each try to sign number to each array argument I make console.writeline to show which number was randomly assigned. And at the end entire array is filled by last one randomed this method:
static void Main(string[] args)
{

    Console.WriteLine("Set the number of arguments in mineArray:");
    string argumentsNumber = Console.ReadLine();
    int argumentsNumberInt = Convert.ToInt32(argumentsNumber);
    int[] mineArray = new int[argumentsNumberInt];
    Random rand = new Random();

    //set up values to each index of array
    foreach (int i in mineArray)
    {
        mineArray[] = rand.Next(1, 10);
        Console.WriteLine(i + " " + mineArray[i]);
    }
    string a = "asd";

    foreach (int k in mineArray)
    {
        if (mineArray[k] % 3 == 0 || mineArray[k] % 5 == 0)
        {
            if (mineArray[k] % 3 == 0 && mineArray[k] % 5 == 0)
            {
                a = "Able to divide by 3 and 5";
            }
            else
            {
                if (mineArray[k] % 3 == 0) { a = "Able to divide only by 3"; }
                if (mineArray[k] % 5 == 0) { a = "Able to divide only by 5"; }
            }

        }
        else
        {
            a = "Number unable to divide";
        }
        Console.WriteLine(mineArray[k] + " " + a);
    }

Comment: What `mineArray[] = rand.Next(1, 10);` supposed to mean?
Comment: @AlexeiLevenkov Believe he meant `mineArray[i]...`
Comment: you should use a normal `for` loop to set values, as `foreach` is just a readonly function
Comment: Yeah, sorry i've deleted it accidentially before posting this.
Answer: I assume you do mineArray[i] = rand.Next(1, 10);, otherwise this wouldn't compile (your code is missing the i).
The problem is in your foreach loop:
int[] mineArray = new int[argumentsNumberInt];
Random rand = new Random();

//set up values to each index of array
foreach (int i in mineArray)

This foreach will run through an array filled with zeroes, every time assigning the random variable to mineArray [0].
Use for:
for (int i = 0; i < argumentsNumberInt; i++)

Comment: You guys are incredible. Five minutes and I know hundred times more than by guessing what I've messed up. :)
Comment: Learning to use breakpoints and the [various debug windows](http://msdn.microsoft.com/en-us/library/esta7c62.aspx) could come in handy in cases like this. :)


Sorting `NSArray` based on C array values

Question: I have an NSArray with objects and a C array with doubles. I would like to sort the NSArray objects based on the C array values.
The only way I could think of is below (based on this SO question):
NSArray *sortedArray;
sortedArray = [origArray sortedArrayUsingComparator:^NSComparisonResult(id a, id b)
{
    // Getting c array values at the same indices as the objects being compared
    NSNumber *aValue = @(cArray[[origArray indexOfObject:a]]);
    NSNumber *bValue = @(cArray[[origArray indexOfObject:b]]);
    // Returning comparison result
    return [aValue compare:bValue];
}];

But I think that the indexOfObject: part is a bit costly. Is that so?
If so, is there any faster way of doing this?
Edit:
To provide a bit more context, this sorting is part of a fitness evaluation for an optimization algorithm. In my program, I have done a basic profiling and the fitness evaluation code turns out to be the bottleneck. As such, I am trying to optimize it.
Also, the number of elements in the arrays is expected to be from around 100 to 10k max.
Answer: Don't optimize the sort until you know it's a problem. First you need to answer some questions. How many values are going to be in your array? How long can the user be expected to wait?
After that, you should test the current solution. Does the user have to wait too long when sorting the expected number of values?
Next, answer other architectural questions. For example, can you sort the array in the background while the user is doing other work?
If you do all of this and you discover a problem, then you can start to think of how to optimize.
The first thing that comes to mind is mapping the arrays into a dictionary, sorting the dictionary, and mapping back the sorted array.
First things first, get a mapping category (here is one I found at NSArray Equivalent of Map).
@interface NSArray (Map)
- (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block;
@end

@implementation NSArray (Map)
- (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block {
    NSMutableArray *result = [NSMutableArray arrayWithCapacity:[self count]];
    [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        [result addObject:block(obj, idx)];
    }];
    return result;
}
@end

Once you have your mapping method of choice, then run the new sort.
// Step 1) Map into an array of a dictionaries
NSArray *dicts = [origArray mapObjectsUsingBlock:^(id obj, NSUInteger idx) {
    return @{ @"value": obj, @"sortValue": @(cArray[idx]) };
}];

// Step 2) Sort the dictionaries
NSArray *sortedDicts = [dicts sortedArrayUsingComparator:^NSComparisonResult(id a, id b)
{
    return [a[@"sortValue"] compare:b[@"sortValue"]];
}];

// Step 3) Map back to the sorted array
sortedArray = [sortedDicts mapObjectsUsingBlock:^(id obj, NSUInteger idx) {
    return obj[@"value"];
}];

After all of that, then you need to repeat your testing to answer the question, "Does the user have to wait too long when sorting the expected number of values?" If the answer is still yes, the user has to wait too long, then you once again need to look for a new solution.
Comment: Thanks for the answer and interesting approach.
Answer: There's no sense in speculating over a potential performance problem without having a real one.
If you can measure an actual problem with your code (e.g. by using Time Profiler in Instruments) you'll get an idea of where the bottle neck might be. In your code there are several spots that might slow the sorting down (boxing each number to calculate the NSComparisonResult, retain/release overhead from ARC just for accessing the objects from the array, ...).
There are a couple of ways to enhance performance but they depend upon the actual data (number of objects in origArray, source of the C array of doubles, ...).
If I'd take a guess at what might seem the candidate for performance enhancement, I'd say the general problem of having two arrays where the elements form a tuple instead of just one array of tuples should be eliminated. Here's a C function that sorts the array with a small overhead:
NSArray *sortedObjects(double valuesArray[], NSArray *objects)
{
    NSUInteger count = [objects count];
    struct tuple {
        double value;
        __unsafe_unretained id object;
    } tupleArray[count];

    for (NSUInteger i = 0; i < count; ++i)
        tupleArray[i] = (struct tuple){ valuesArray[i], objects[i] };

    qsort_b(tupleArray, count, sizeof tupleArray[0], ^int(const void *a, const void *b) {
        double v = ((const struct tuple *)a)->value - ((const struct tuple *)b)->value;
        return v == 0 ? 0 : v > 0 ? 1 : -1;
    });

    __unsafe_unretained id objectsArray[count];
    for (NSUInteger i = 0; i < count; ++i)
        objectsArray[i] = tupleArray[i].object;

    return [[NSArray alloc] initWithObjects:objectsArray count:count];
}

Comment: Thank you for the answer and the clear and elegant example. I have added some information in my question for clarification. If I understand correctly, the general approach here would be somehow creating a tuple (either through a struct, or through associated objects or regular objects, as @JeremyP suggested) of the object-sorting value pair.
Answer:
If so, is there any faster way of doing this?

Well the obvious question is why aren't the double values properties of your objects?
If you absolutely can't have a property that is the double value (and actually, you always can by using associated objects), you can create wrapper objects with one property that is the original object and one property that is the double value and sort an array of those.  This is, however, quite expensive (lots of allocations) and so you'll definitely want to do the profiling suggested by the other two answers first.
Comment: Thank you for the reference to associated objects, I was not aware it. With respect to the second part of your answer, I would like to avoid creating wrapper objects, because there is a need to sort different objects with different sorting values every time (therefore wrappers cannot be cached). As such I think (as you pointed out) that there will be a significant overhead in this approach.
Comment: On the other hand, I believe it would still be better than the approach I presented in my question.
Answer: If your single concern is the overhead of indexOfObject: you might want to use indexOfObjectIdenticalTo:. It's omitting the isEqual: message to every element and might be way faster if the array has many elements.


How to setup Apache virtual host based on name?

Question: I have a server with IP address 192.168.1.65
I want to setup virtual hosting such that:

if I access through http://192.168.1.65/, it will lead me to DocumentRoot A
else if I access through http://xyz.com/, it will lead me to DocumentRoot B

(xyz.com is already pointing to 192.168.1.65 in dns server)
Answer: The "default host" should be your doc-root A. Then add name based virtual hosts for B and any additional domains.
In your main config file default configurations including DocumentRoot should be setup for hosting site A. Also you should have a line such as NameVirtualHost *:80 to setup virtual hosting for everything on port 80. Then in your virtual host file you will have something like this for each domain:
<VirtualHost *:80>
    ServerName xyz.com
    DocumentRoot /path/to/B
</VirtualHost>

Anything without a virtual host and matching server name will use the default host, with your docroot set to A.
Comment: Yang it is possible to host different sites for the IP address when called directly and various domains that point to the same IP address. Your problem is your configs ... if you have the default setup correctly to catch unknown names, this will catch the IP address-as-name senario as well. It sounds like your virtualhost is not being recognized at all.
Comment: i have added a name based virtual host. the problem now seem that since the IP and the domain are pointing to the same machine using same port, when i type the domain, the browser lead me to DocRoot A which is the same as the ip address
Comment: what are the setting  i need to mod? i mean the 'default setup' catching unknown names.
Comment: i do have the NameVirtualHost *.80 specified in ports.conf file. and the virtual host file is very similar to yours (only diff are mine have ServerAlias option specified). I use the -S option to check the syntax of the vhost file, it says OK.
Comment: The most relevant settings are in my answer already, including haveing a DocumentRoot directive in the common config file outside of any VirtualHost container. If you are still having trouble it might be helpful to post your current configs to http://pastebin.com or some such place so we can look at them.
Comment: Hi Caleb, this is the default vhost file: http://pastebin.com/30zPbUsz and this is the one i created for name based vhost: http://pastebin.com/kzQVJL65
Comment: @Yang your "default vhost" is not at all what I was refering to. Everything there is inside a VirtualHost container. You need to get those to just be the default values for the server. Strip the VirtualHost wrapper tags from that and go through the main server config, setting the values from there as the server defaults. Then your name based virtual host should kick in and pick up the named requests.
Comment: Just to clarify, you want to setup a "default host" not a "default virtual host". The virtual host will be the name based ones that are sets of modified values from the server defaults. The IP address calls should reach just the server defaults, not any particular VirtualHost container.
Comment: do you mean i remove that vhost and add the options to apache2.conf files?
Comment: @Yang: Yes I do.


How much will the variance change in this scenario?

Question: Imagine that a firm decides to increase the salary of every single of its employees by 10% of their current salary. The average of the salaries will increase by 10% too. But, how will the variance of the salaries change?
Answer: The variance will increase by 21%.
We know that Var[aX] = a2 Var[X]. 10% increase in the salary of every employee equals when each salary is multiplied by 1.1; and the square of 1.1 is 1.21, which is 21% more than the previous variance.


How to do integral $\int_{0}^{\infty} \frac{x^4 e^{x}}{(e^x-1)^2}\,dx$

Question: $$\int_{0}^{\infty} \frac{x^4 e^{x}}{(e^x-1)^2}\,dx$$
This integral came from the Debye theory of the molecular heat capacity of crystal.
I heard that this integral form is related to Riemann Zeta function and Gamma function.
Also, i heard that it can be solved by using Feynmann's Trick.
How can i evaluate this integral?
Comment: Is there anything which could be improved that prevents you right now from accepting one of the given answers?
Answer: The Riemann/Gamma way:$$\int_0^\infty\frac{x^4e^{-x}dx}{(1-e^{-x})^2}=\sum_{n\ge 1}n\int_0^\infty x^4e^{-nx}dx=\sum_{n\ge 1}\frac{4!}{n^4}=24\zeta(4)=\frac{4\pi^4}{15}.$$
Answer: Recall the integral representation of the Polylogarithm given by

$$\operatorname{Li}_s(z)~=~\frac1{\Gamma(s)}\int_0^\infty \frac{t^{s-1}}{e^t/z-1}\mathrm dt$$

Moreover note that
$$\frac{\partial}{\partial z}\left[\frac{t^{s-1}}{e^t/z-1}\right]=\frac{t^{s-1}e^t}{(e^t-z)^2}$$
which is precisely the structure of your integrand. Thus, by applying a variation of Feynman's Trick we obtain
\begin{align*}
\frac{\mathrm d}{\mathrm dz}\Gamma(s)\operatorname{Li}_s(z)&=\frac{\mathrm d}{\mathrm dz}\int_0^\infty \frac{t^{s-1}}{e^t/z-1}\mathrm dt\\
\Gamma(s)\frac{\mathrm d}{\mathrm dz}\operatorname{Li}_s(z)&=\int_0^\infty \frac{\partial}{\partial z}\frac{t^{s-1}}{e^t/z-1}\mathrm dt\\
\Gamma(s)\frac{\operatorname{Li}_{s-1}(z)}z&=\int_0^\infty\frac{t^{s-1}e^t}{(e^t-z)^2}\mathrm dt
\end{align*}
Now plugging in $s=5$ and $z=1$ yields to
\begin{align*}
\Gamma(5)\frac{\operatorname{Li}_{5-1}(1)}1&=\int_0^\infty\frac{t^{5-1}e^t}{(e^t-1)^2}\mathrm dt\\
4!\operatorname{Li}_4(1)&=\int_0^\infty\frac{t^{4}e^t}{(e^t-1)^2}\mathrm dt
\end{align*}
Note that the RHS is the integral we are interested in whereas the LHS can be evaluated directly in terms of the Riemann Zeta Function. Overall this boils down to utilizing the value of $\zeta(4)$, as J.G.'s answer did aswell, since $\operatorname{Li}_s(1)=\zeta(s)$ as one can verify by using the series representation of the Polylogarithm.

$$\therefore~\int_0^\infty\frac{t^{4}e^t}{(e^t-1)^2}\mathrm dt~=~4!\operatorname{Li}_4(1)~=~\frac{4\pi^4}{15}$$
Answer: For a slight variation along a polylogarithmic theme, observe that for the polylogarithm of order $s = -1$ one has
$$\operatorname{Li}_{-1} (z) = \frac{z}{(1 - z)^2}.$$
Setting $z = e^{-x}$ leads to
$$\operatorname{Li}_{-1} (e^{-x}) = \frac{e^{-x}}{(1 - e^{-x})^2}.$$
Now for the integral
$$I = \int_0^\infty \frac{x^4 e^x}{(e^x - 1)^2} \, dx,$$
rewriting it as
$$I = \int_0^\infty \frac{x^4 e^{-x}}{(1 - e^{-x})^4} \, dx,$$
which in terms of polylogarithms becomes
$$I = \int_0^\infty x ^4 \operatorname{Li}_{-1} (e^{-x}) \, dx. \tag1$$
Now since
$$\int \operatorname{Li}_s (e^{-x}) \, dx = - \operatorname{Li}_{s + 1} (e^{-x}) + C,$$
integrating (1) four times by parts leads to
\begin{align}
I &= 4! \int_0^\infty \operatorname{Li}_3 (e^{-x}) \, dx = 4! \big{[} - \operatorname{Li}_4 (e^{-x}) \big{]}_0^\infty = 4! \operatorname{Li}_4 (1) = 4! \cdot \frac{\pi^4}{90},
\end{align}
or
$$\int_0^\infty \frac{x^4 e^x}{(e^x - 1)^2} \, dx = \frac{4 \pi^4}{15},$$
as required.

Comment
The real advantage of this approach lay in the fact it can be used to find the corresponding indefinite integral
$$\int \frac{x^4 e^x}{(e^x - 1)^2} \, dx.$$
Following exactly the method outlined above, one finds
$$\int \frac{x^4 e^{x}}{(e^x - 1)^2} \, dx = -x^4 \operatorname{Li}_0 (e^{-x}) - 4x^3 \operatorname{Li}_1 (e^{-x}) - 12 x^2 \operatorname{Li}_2 (e^{-x}) - 24x \operatorname{Li}_3 (e^{-x}) - 24 \operatorname{Li}_4 (e^{-x}) + C.$$
Note the polylogarithm expressions of order zero and one can be expressed as
$$\operatorname{Li}_0 (e^{-x}) = \frac{1}{e^x - 1} \qquad \text{and} \qquad \operatorname{Li}_1 (e^{-x}) = - \ln(1 - e^{-x}).$$


Pear: Includes are successful but cannot find functions

Question: EDIT: Solution...email is a function within Validate which is a class so you need to access it using:
Validate::email("email@example.com");
or
$val = new Validate();
$val->email("email@example.com");
Thanks red eyes
====================== original question ==============================
Hi,
I'm using Pear and have installed the package Validate to try it out.
Using the code:
<?php
require_once 'Validate.php';
email("firstname.lastname@example.com");
?>

I get the error.
PHP Fatal error:  Call to undefined function email() in /home/benb/temp/pear.php on line 4

If I alter the code to include a non existent extension like require_once 'Validate2.php'; it gives me the error to say it can't find it.
Also, if I view Validate.php I can see the email function within it.
So it seems as though it can find the extension but not the functions within it.
Can anyone help?
Thanks
Answer: It's possible to post Validate.php ?
I think Validate.php it's PHP5 ;)
So it's
$val = new validate();
$val->email();

Comment: Validate.php is over 1K lines but it's just the standard one downloaded from the Pear repository which can be viewed here:   http://pear.php.net/package/Validate/docs/latest/__filesource/fsource_Validate__Validate-0.8.4Validate.php.html#a515
Comment: Do you know what difference between PHP4 and PHP5 ?
PHP5 using class, it's a OOP language :)
Comment: Sorry, you've lost me there. The server is running PHP5.
Comment: Pear it's a library write on PHP5

If you want use a "function" from validate.php, it's necessary to create an interface.
So for call function email.
just use

$val = new validate();
$val->email();
Comment: I know, I've installed the Validate extension
Comment: test

email("email@example.com");
?>
Comment: I've got it, thanks Red that's fixed it. Thanks for your help.


Interfaces with different getter and setter for the same propertie

Question: I've made the following declaration for interfaces:
public interface IBasic
{
  int Data { get; }
}

public interface IChangeable : IBasic
{
  int Data { set; }
}

The compiler says that IChangeable.Data hides IBasic.Data. It's reasonable. The alternative I've found is:
public interface IBasic
{
  int Data { get; }
}

public interface IChangeable : IBasic
{
  void ChangeData(int value);
}

There is any way to define setter and getters for the same property on different hierarchy on interfaces?  Or there are any alternatives to this approach?
Comment: No need to declare the property in IChangeable since all objects that implements IChangeable also must implement IBasic (due to IChangeable : IBasic)
Comment: @Simon: I've showed a simplification of the problem. On my real problem, The IBasic declares more things.
Comment: @Simon -- I made this mistake initially, too.  He wants IChangeable to add a settor.
Answer: You can re-declare it (or rather, tell the compiler that you intend to hide it):
public interface IChangeable : IBasic
{
  new int Data { set; }
}
class Foo : IChangeable
{
    private int value;
    int IBasic.Data { get { return value; } }
    int IChangeable.Data { set {this.value = value;}  }
}

But this is confusing, and you'll need to use explicit implementations etc, and probably a bit of casting at the caller if you want to use the hidden version. If you went this route, I would recommend exposing both the get and set on IChangeable:
public interface IChangeable : IBasic
{
    new int Data { get;  set; }
}
class Foo : IChangeable
{
    private int value;
    int IBasic.Data { get { return value; } }
    int IChangeable.Data { set { this.value = value; } get {return value; } }
}

Re the comments; to expose on the implementing type:
public interface IChangeable : IBasic
{
    new int Data { set; }
}
public interface IBasic
{
    int Data { get; }
}
class Foo : IChangeable
{
    private int data;
    public int Data {
        get { return data; }
        set { data = value; }
    }
}

This would also work if you make it (which I prefer):
public interface IChangeable : IBasic
{
    new int Data { get; set; }
}

Comment: In this approach, which is the way to assign value to Foo.Data?
Comment: `IChangeable c = {some foo}; c.Data = {some value};` You could also put the property on the public API, but it isn't clear from the question whether that would be the `get`, the `set`, both, etc.
Comment: I want to allow the implementor of `IChangeable` to have the `get` and `set`.
Answer: Maybe I've misunderstood your question but wouldn't you just do
public interface IChangeable : IBasic
{
  int Data { get; set; }
}

i.e. Let IChangeable override the property but keep the "get" present.
As IChangeable inherits from IBasic I'm assuming you want an implementation of IChangeable to have an implementation of "get".
Answer: I think GetData and SetData methods is more clear for this situation:
public interface IBasic
{
    int GetData();
}

public interface IChangeable : IBasic
{
    void SetData(int data)
}

Comment: What about a read only `Data` property with a `SetData` method?


Is the addition and scalar multiplication continuous with respect to this particular topology?

Question: Suppose $X$ is a normed linear space.
If $\mathcal {B}$ consists of $\phi$, $X$, all open balls centered at origin, and all open annulus centered at origin, then it is clear that $\mathcal {B}$ is a base  for some topology $\mathcal {T}(\mathcal {B})$.
My Question is:
Is the addition and scalar multiplication continuous with respect to this topology $\mathcal {T}(\mathcal {B})$ ?
i.e. Does $X$ become a topological vector space with respect to the topology $\mathcal {T}(\mathcal {B})$ ?
Thanks in Advance.
Answer: So, we identify everything with the same norm, and apply the usual topology on $\mathbb{R}$ to those equivalence classes.
Scalar multiplication? That's continuous on $\mathbb{R}$, so it's continuous here.
Addition? That doesn't respect the identification, so it won't work. The preimage of $0$ under addition includes all pairs $(x,-x)$ but not the pairs $(x,x)$.
If $U$ is an open set containing $0$ but not $y$, then the preimage of $U$ under addition contains $(\frac y2,-\frac y2)$ but not $(\frac y2,\frac y2)$. On the other hand, every open set containing $-\frac y2$ also contains $\frac y2$, so a product of open sets that contains $(\frac y2,-\frac y2)$ also contains $(\frac y2,\frac y2)$. As such, the preimage of $U$ can't be open in the product topology, and addition is discontinuous.
Some versions of the definition of a topological vector space also include a separation axiom (such as $T_1$). This example, of course, would also fail that test.


Ask for a question about independence

Question: This is the question I met while reading Shannon's channel coding theorem. Assume a random variable $X$ is transmitted through a noisy channel with transition probability $p(y|x)$. At the receiver a random variable $Y$ is obtained. Assume we have an additional random variable $X'$ which is independent of $X$. How to show that $X'$ is independent of bivariate random variable $(X,Y)$ and $X'$ is independent of $Y$? It looks obvious because $Y$ is generated only from $X$, but I just can not prove it rigorously, i.e., that $p(x,y|x')=p(x,y)$ and $p(y|x')=p(y)$. Thanks a lot for your answer!
Answer: There does not seem to be enough information in your model to decide that. In order to do so, you need to have specified the joint distribution of $(X,Y,X')$.

You have specified the conditional distribution of $Y$ given $X$ (there seems to be a typo in your question), which together with marginal distribution of $X$ gives the joint distribution of $(X,Y)$.
You have also said that $X$ and $X'$ are independent which gives the joint distribution of $(X,X')$.

There is more that one joint distribution on $(X,Y,X')$ which agrees with these two pieces of information.
Here is the example: Consider $X$ to be a symmetric Bernoulli random variable (i.e. takes values 0 and 1 with equal probabilities). Let $X'$ be independent of $X$, with the following distribution
$$
X' \sim
\begin{cases}
 0 & \text{w.p.} \;0.9\\
 100 & \text{w.p.} \;0.1
\end{cases}
$$
Also, take $X'$ to be the channel noise and let $Y = X + X'$. Conditioned on $X' = 0$, $Y$ has the same distribution as $X$, while conditioned on $X' = 100$, $Y$ takes values $100$ and $101$ with equal probabilities. Hence $X'$ and $Y$ are not independent.
Comment: *Note that Y is generated solely from X*... Not in the sense you believe. In fact Y is generated by X and by some external randomness. Otherwise, the transition kernel $p(y\mid x)$ mentioned in your question would be degenerate, in the sense that for each given $x$, $p(y\mid x)$ would be zero except for one value of $y$.
Comment: but $X'$ and $Y$ are indeed independent in the proof to show subsequent results. Let's assume $X'$ and $X$ have the same distribution.
Comment: There are probably more assumptions implicitly made. It might have been easily assumed that $X'$ is independent of $(X,Y)$.
Comment: Yes, I must have omitted some assumptions, but I don't know what they are. Currently the assumptions can be summarized as: $X$ and $X'$ are iid with common probability $p(x)$. $Y$ is generated from $X$ according to the trasition probability $p(y|x)$ (sorry for the typo in the original post; I have corrected it). I really can not think of any other assumptions. Maybe someone who read the proof of Shannon's channel coding theorem before and familiar with random coding and joint typicality can answer this question.
Comment: The answer to that is pretty clear: one ASSUMES that $X'$ is independent of $(X,Y)$.
Comment: @Did: so the independence of $X'$ and $(X,Y)$ can not be derived from the independence of $X$ and $X'$? Note that $Y$ is generated solely from $X$, not like $Y=X+X'$ in the answer where $Y$ is also determined by $X'$.
Comment: I answered my question, but I would like to give the credit to you.
Comment: Zhou Heng, thanks.
Answer: Two given conditions are:
(1)$X'$ is independent of $X$,
(2)$Y$ is generated only from $X$, i.e., $p(y|x)=p(y|x,x')$. This acutually means $X'\to X\to Y$ forms a Markov chain.
Now let's prove $X'$ is independent of bivariate random variable $(X,Y)$, i.e., $p(x,y|x')=p(x,y)$:
$p(x,y|x')=p(x|x')p(y|x,x')=p(x)p(y|x,x')$(from (1))$=p(x)p(y|x)$(from (2))$=p(x,y)$.
It can easily shown that if $X'$ is independent of $(X,Y)$, then $X'$ is independent of each component. I have shown $X'$ is independent of $(X,Y)$, so $X'$ is also independent of $Y$.

Ask for a question about independence


How to reset a form element to its ordinary default value?

Question: I do a form alter on a node form and make some callbacks which restrict value lists in a < select > element, which is a entity reference. When the triggering element is changed, I want to load the node forms default value just like it is in the beginning of the form process.
I remember there was an api function to do that. Someone nows it?
Comment: Just a note, but you might want to write a ctools entity reference selection tool plugin instead. e.g: http://drupal.stackexchange.com/a/53177/7153
Answer: field_get_default_value - Helper function to get the default value for a field on an entity.
Usage:
<code><?php
  $field = field_info_field('YOURFIELDNAME');
  $instance = field_info_instance('node', 'YOURFIELDNAME', 'YOURNODETYPE');
  $defvalue = field_get_default_value('node', $node, $field, $instance, $node->language);
  print_r($defvalue); // Here structure, like $defvalue[0]['value']
?>
</code>


Binomial expansion with 2n power

Question: I'm trying to expand $$(z+z^{-1})^{2n}$$.
I've written the first 3 terms out but I can't figure out a way to work out the last 3 terms.
I'm trying to produce an expression for $$\cos^{2n}x$$ using the complex numbers.
Comment: $ z = x + iy = |z| (\cos \phi + i\sin \phi ) = r e^{i \phi} \ $
Answer: Just apply the binomial formula
$$
 (z+z^{-1})^{2n}=\sum_{k=0}^{2n}\binom{2n}kz^k(z^{-1})^{2n-k}
 =\sum_{k=0}^{2n}\binom{2n}kz^{2(k-n)}
 =\sum_{k=-n}^n\binom{2n}{n+k}z^{2k}.
$$
Now putting $\def\i{\mathbf i}z=\exp(\i x)$ and dividing by $2^{2n}$ you get
$$
  \cos(x)^{2n}= 2^{-2n}\sum_{k=-n}^n\binom{2n}{n+k}\exp(2\i kx)
 = 2^{-2n}\sum_{k=-n}^n\binom{2n}{n+k}\cos(2kx).
$$
Comment: I dont understand the 2nd part. What is this formula?
Comment: The second equation is just applying $z^a(z^{-1})^b=z^az^{-b}=z^{a-b}$. Is that what you were asking about?

Binomial expansion with 2n power


where quagga stores BGP Table in Linux file system

Question: I am using quagga with fedora 18. I successfully formed the neighbor relationship between the peers. I can also see the result of sh ip bgp command.
My question is in which file does the quagga saves the bgp table entries in the linux file system. Like the kernel routing table is located at the /proc/net/route.
Thanks in advance.
Answer: Quagga doesn't save the BGP routing table anywhere except in the memory of the bgpd daemon.  There is no way to access it other than going through the vtysh command or connecting to the bgpd daemon's control socket.
Answer: Well there are a couple of ways to access or assess what's in quagga BGP tables.
One way is vtyssh, another is to obtain the table through snmp (quite slow) and a third way is to dump the tables in an MRT file.
Here is an example on how to configure quagga so to be able to dump the tables.
http://www.nongnu.org/quagga/docs/docs-multi/Dump-BGP-packets-and-table.html#Dump-BGP-packets-and-table
Once they are dumped you will have to somehow analyze the file. My favorite one is https://github.com/iTransformers/javaMrt2Graphml which will generate you an internet BGP peering map from the captured dump.


User can change `Moderation State` on content without having permissions to do so - Workbench

Question: I am using Workbench, Workbench Moderation and Workbench access.
I have a content manager role, who should be able to only create unpublished content, edit content that is flagged as Needs review and change the moderation state from Needs review to Draft. But as i'm testing the role, the manager can go into the draft and change the moderation state to published, or even needs review, and I do not have the permissions set for the user to change the moderation state.
At least I think. I've followed a couple tutorials and my site is configured the same, but when they go to change the moderation state their drop down select list only has the options they specified, while mine has all states available regardless of permissions.
I've tested back and forth between the roles and there is differences in the permissions and what each user role can do, but I can't set the role to allow users to moderate specific state transitions.
I literally can turn off all workbench moderate state permissions and they still have access to change the moderation state to anything they want.

As you can see in the bottom right hand corner of the image, the permissions for Moderate all content from ___ to ____ is turned off for my content manager role, and I still have permissions to moderate all content from either state. If i sign is as the reviewer role, I can also turn off all permissions and still be able to moderate the content and change the states without permissions.
No I do not have another role enabled for this user, I have cleared every cache and used different machines, same issue.
My questions are:
if I have a setting on that allow the user to moderate the states of content, what is it?
If I do not have the correct permissions enabled, what should I do to correct it?
If the issue does not lie within the workbench permissions then what should I be looking for?
Thank you regardless.
Answer: in order to display the moderation states i wanted for a specific role I had to make sure
Administer Workbench Moderation and Bypass Moderation restrictions were turned off.


Why sample size is not a part of sufficient statistic?

Question: Following simple example from Wikipedia's definition of sufficient statistic with Bernoulli distribution with parameter $\theta$, where sufficient statistic is a sum of successes
$$T(X_n)=\sum_{i=1}^n x_i, x_i \in \{0,1\}$$
As MLE is $\frac{1}{n}\sum_{i=1}^n x_i$ we can't just use the sufficient $T(x)$, but we also need the sample size, which is a property of our sample, hence $T(x)$ doesn't contain all information about the sample. Is there an unspoken rule, that the sample size is not considered for the sufficient statistics?
Comment: Do you also need to know the stopping rules? Data from negative sampling (i.e. sampling until a pre-determined number of successes is observed) has a different frequentist interpretation from the same results from normal sampling (where the total number of tries is fixed in advance).
Comment: Following @MichaelLew $n$ is part of the sufficient statistic only when $n$ is the outcome of a random variable $N$, for which a distribution must be chosen/provided. Otherwise, if $n$ is fixed, it is irrelevant to include it in a statistic.
Comment: This is a good question (+1), probably because the sample size is considered a known constant, and not a random variable.
Comment: Yes, it is an unspoken rule that the sample size is known in the background.  That has the consequence that in many simple examples each of the sum and the mean of the observations is sufficient on its own, such as in your Bernoulli example
Comment: An intuition that is known comes even from the notation of the statistic where you sum from 1 to $n$
Answer: It is typical practice that the sample size is considered (implicitly) to be a known constant unless we specify the contrary in the analysis.  This practice saves time by alleviating the need to specify that the sample size is known, which is true in the vast majority of statistical applications.  You can of course proceed on the basis that $n$ is also an unknown parameter in the model.  In this latter case your log-likelihood function would be:
$$\ell_{\mathbf{x}_n}(n,\theta) = \log {n \choose T(\mathbf{x}_n)} + T(\mathbf{x}_n) \log(\theta) + (n-T(\mathbf{x}_n)) \log(1-\theta),$$
and the minimal sufficient statistic is indeed $(n,T(\mathbf{x}_n))$ (so the statistic $T(\mathbf{x}_n)$ is not sufficient in this case).
(Note: I do not agree with the comment by Xi'an asserting that $n$ must be the outcome of a random variable to be included as part of the sufficient statistic; the concept of sufficiency is a classical concept, and in that domain the notion of an "unknown constant" is perfectly valid.  There is no need to create a Bayesian model that specifies a distribution for $n$ in order for it to be part of the sufficient statistic.)
Comment: +1 for the parenthetical remark:  sufficiency pertains to data reduction.  Unless otherwise specified, $n$ is an observable quantity reflecting the amount of data that is observed.


Using Python see if Table exists

Question: I have to connect to an Oracle database and see if a table exists. While I can get a list of the tables, I'm having trouble seeing if the table I'm looking for is in the list. Some tables have associated table which I'll have to join on, some do not, thus I have to check.
What is in my list: ('NYSDOH_CI_EI_HOSPITAL',)
sql =   "SELECT table_name FROM all_tables"

cur.execute(sql)

searchstr = 'NYSDOH_CI_EI_HOSPITAL'
p = re.compile(searchstr)

#create data array to load in SQL results in.
ciDataSet = []

cxRows = cur.fetchall()
for i in cxRows:
    #print i  # list of tables
    if p.match(str(i)):
        print  i

It doesn't find it, even if I use a wildcard.
Comment: Is your string in the result from `print cur.fetchall()` ?
Comment: If not, what is being returned if you print cxRows?
Answer: fetchall() returns a list of tuples.
So when you do
for i in cxRows:

'i' is of type tuple. In your case, this tuple will have only single value. You can access it using i[0] and match it with p.
Currently you are converting a tuple to string so regular expression will not match.
Corrected code:
   sql =   "SELECT table_name FROM all_tables"

    cur.execute(sql)

    searchstr = 'NYSDOH_CI_EI_HOSPITAL'
    p = re.compile(searchstr)

    #create data array to load in SQL results in.
    ciDataSet = []

    cxRows = cur.fetchall()
    for i in cxRows:
        #print i  # list of tables
        if p.match(str(i[0])):
            print  i

Comment: It's better to do the reg exp matching in the query.
Answer: To improve on the syntax of @vaichidrewar, you could simplify the fetch loop to:
for tabname, in cur:
    if p.match(str(tabname)):
        print(tabname)

But it's going to be more efficient to do the reg exp matching in the query:
sql = "select table_name from all_tables where regexp_like(table_name, :tn, 'i')"
searchstr = 'EMP'

cur.execute(sql, (searchstr,))
for tabname, in cur:
    print(tabname)

The 'i' option does a case-insensitive match.  You can adjust the regexp as you like.
Comment: I first tried putting it into the query, but I couldn't get it working nor find a good example. You have a clear example that worked well.

Using Python see if Table exists


SVM for fMRI: unbalanced data - leave-one-triplet-out?

Question: I am using SVM (sklearn.svm) to classify fMRI data from two groups of people. One group has n = 25 and the other n = 26. Everyone except for one person has seen 96 trials, so in total I have 2,496 image files in one category and 2,398 in the other. Since the data is slightly unbalanced, I thought of two options:

Using a leave-one-triplet-out crossvalidation strategy, where the test data always includes data from two people from the larger group and one from the smaller one (going through all possible leave-outs) therefore using unbalanced test data.
Using a leave-one-out crossvalidation strategy with all possibilities meaning sometimes using unbalanced training data.

Does anyone have any experience with cases like this? Or general recommendations which option is better or why I should refrain from one (or both!) of these options?
I would be very thankful for any comments or recommendations!
Comment: Why do you expect this level of unbalance (almost none) will lead to problems? Have you considered using bootstrapping to validate your modeling approach instead of the (often unstable) leave-one-out CV methods?
Comment: To be honest, I haven't found any good information telling me when is an imbalance large enough to cause problems and just assumed that this is already too much of a difference. I haven't thought about using bootstrapping but that's a good pointer, thanks! Do you have any recommendations on how many iterations one would do in such a case?
Answer: Imbalance is often much less of a problem for classification than is feared. See this thread for some discussion. The important thing is to have enough cases in the minority class to be able to model its difference from the majority class adequately. Your limit is thus that you only have 25 cases in the minority class, so that you might be at risk of overfitting with such a large amount of data per case. As ISLR points out in Section 9.5, your SVM is closely related to logistic ridge regression, a method that penalizes individual predictors to avoid overfitting.
A key to avoiding overfitting is choosing the tuning parameter for the SVM, which is usually done by cross-validation. There's are problems with the types of leave-one-out CV approaches you have been considering. In particular, your number of training sets can't ever exceed the number of observations, and the models can't change very much from fold to fold. See this page for example. In practice, this can lead to high variance in estimates so that 5- or 10-fold CV is often preferred. And with those 5- or 10-fold CV approaches you aren't limited to 5 or 10 folds as you can, if desired, just repeat the CV on multiple different randomizations of the data to make sure that you have a stable and reliable choice of the tuning parameter.
With a small number of cases like this, you can't really estimate the quality of your model but you can estimate the quality of your modeling process. You build the model on the entire data set with a defined modeling process for deciding on things like the choice of kernel and the tuning parameter. Then repeat all steps of the modeling process on multiple bootstrapped samples of the data while testing the results on the full data set. By the bootstrap principle, that testing of the results from the bootstrapped samples on the full data set is analogous to testing the modeling process of your data set against the underlying population. The number of bootstraps will depend on the precision with which you want to estimate the quality of the modeling process and the variability of the process. See this page for more discussion.
Comment: Thanks for the helpful tips and links! It will take me a while to properly understand it all, but it seems like 5-fold CV (maybe with repetitions) and bootstrapping are definitely two things to try out on my data!


PHP stringtotime function first weekday

Question: echo date("d-M-Y", strtotime("first monday 2019-07"));

Shouldn't the output of this line be 01-Jul-2019? Thats the first monday in July but the output is: 08-Jul-2019.
What is the error im making?
Answer: Try
first monday of 2019-07

Instead of first monday 2019-07.
Comment: Isn't it obvious?
Comment: Nice thank you very much, this is what i wanted. Can you explain the difference?
Comment: for sure i noticed. My question was what "first monday 2019-07" is doing because its working when the first monday isn't the first day of the month.
Answer: Use,
echo date("d-M-Y", strtotime("first monday of 2019-07"));

You can find here php instructions to parsing date as natural languages.
http://php.net/manual/en/datetime.formats.relative.php
Answer: " first monday 2019-07 " returns the date of the first monday of july excluding the start date (in this case 1st july 2019). Where as "first monday of 2019-07" returns the date of the first monday of july including the start date.

PHP stringtotime function first weekday


How to handle a short ball which has dropped below the level of the net

Question: If I am a bit late to a short ball which has dropped below the level of the net I tend to hit up fairly crudely and the ball will land somewhere in no mans land which can be easily attacked by an opponent.
What is the best approach for handling this scenario, take it as a topspin forehand or backhand and really accelerate up the ball to give it some lift? Do a low volley? Or something else?
Answer: If you are late to the ball & it has dropped below the level of the net then drop shot would be a better & safer shot in the circumstance. Also if you could introduce sideways spin with backhand/forehand, then it would be difficult for opponent to reach it. I've seen Anastasia Sevastova do it a regularly.
Playing a top spin forehand or a normal slice bsckhand is risky. If the ball is below the net & your knees & you play top spin forehand, you'll most likely hit the shot in the net. If instead you play a backhand slice, you'll mostly have to upper cut it a bit to gain elevation. And with lack of speed & such high elevation, it will land in opponents half mid-court & easy for him to put it away


Draw surface graph

Question: Does any know how to draw a graph like this:

Which programs can do that? I'm a developer so I've no problem on formatting a complex files so that a software can handle it.
Comment: Look up for "response surface plot" on Google; e.g., if you're willing to use R, [Surface Plots in the `rsm` Package](http://cran.r-project.org/web/packages/rsm/vignettes/rsm-plots.pdf).
Comment: SAS is one that can.
Answer: Lots can do it. R (packages such as lattice, misc3d and others), Matlab, Python (see matplotlib), Wolfram Alpha / Mathematica... I'd use whatever your most comfortable in.
See these questions.
Comment: "these questions" link is wrong. Thanks for the info!
Comment: Fixed. Good luck!
Answer: Since it wasn't mentioned yet: You could have a look at gnuplot.

Draw surface graph


If I add a lagged dependent variable, do I need to add the lagged independent variables too?

Question: If I have a normal regression model
y_t = βx_t + ε_t

and want to add a y_(t-1), would this be proper?
y_t = ρΔy_(t-1) + βx_t + ε_t

or would I need to also add the lagged x, like this?
y_t = ρΔy_(t-1) + βx_t + θΔx_(t-1) + ε_t

Comment: what type of data you want to analyse ? time series , cross section , eperimental etc .,? why do you want to do something like this ?
Comment: I'm analyzing macro time series like interest rates, savings rates etc. I want
Comment: Sorry, accidentally pressed enter. I want to add the y-variable because I'm pretty sure it's significant.
Comment: The savings rate (y-variable) in the previous period should affect the savings rate in the current period
Comment: IA good point.. I am not aware of how  did you construct your independent variables.  Also you have not mentioned type of data and research design.
Comment: How I constructed the independent variables? They're basically just real interest rates over time in a single country. As for research design, I'm not quite sure what you mean.
Comment: Apparently,  your data is historical. For how many years or months. Is it monthly or annual  and without  missing year/month. How many observations.
Comment: Oh, I see. The data stretches from the 1960's to 2017 with quarterly frequency (about 220-230 observations), no missing quarters.
Comment: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/69963/discussion-between-subhash-c-davar-and-chisq).
Answer: The question ,  comments and the discussion taken together indicate that  you should use the multiple regression analysis that incorporates lagged dependent variable and other independent variable (variables)in your model. Whether it is proper to use lagged dependent as a n independent variable ? Yes, if there a valid reason. Generally, the past/antecedents affect the present outcome. A lag of x  - the independent variable, (along with) should not be used as one of independent variables. We may use lag of independent variable in place of  current values if the  stronger relation (with dependent variable) vis with  current values can be postulated.
Comment: So if I understand you correctly, it is not necessary to add a lagged x just because I add a lagged y?
Comment: You may ask another question if you want an answer to your imagination/fantasy.
Comment: Actually this was my original question if you see the title again.
Comment: Once you decide to introduce a lagged of dependent variable, there is no need to add lagged independent variable too.
Comment: many a thanks for your appreciation. was it for a doctoral thesis ?
Comment: It's for my bachelor thesis actually. Haha
Comment: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/69989/discussion-between-subhash-c-davar-and-chisq).


How to relate nodes by field, not title?

Question: I'm using Feeds to import content from XML. The content is films and their showtimes, like this:
<code><film id=av1>
  <title>Avatar</title>
  <showtimes total="2">
    <showtime show_id="1" id="av1" date="1/1/2012" price="10" />
    <showtime show_id="2" id="av1" date="2/1/2012" price="15" />
  <showtimes>
<film>
</code>
Right now, I've created two content types (Film and Showtime) and using Node Reference (References module) to relate Showtime to Film. Then I have various views that use the relationship to show listings, date listings etc.
This works ok, but Node Reference can only link on node title, so if someone updates the film title in the source feed we get problems. It would be better to link using the ID field, which never changes.
The problem is that I'm using Feeds to import to two content types, so running two Feeds importers, and they have to use title from the source to sync. So say the Film title is changed in Drupal, then more Showtimes get added to the XML. On import, the new Showtime nodes are created but can't find their Film node. Using the ID field from the source would keep things joined up. Maybe using Field Collection instead of referenced content types is better?
Possible solutions:

Use a taxonomy vocabulary and create a new term 'id' for each film. Then tag showtimes with the same term. I'm not sure this is a good use of taxonomy, creating single-connections in this way?
See if Relation module provides linking by field. Probably won't work with Feeds yet.
Create a single content type for films, and use Field Collection to store the showtimes. Then everything is connected in a single node. Not sure how feasible this is.

Any guidance or suggestions welcomed!
Answer: You are mistaken. Node reference uses the node id - the primary key for nodes to create the reference. The form element where you need to enter the node you want to reference, uses autocomplete to make it easier to find the node you want to reference, but the value stored is the node id. So there is actually no problem in using node reference and changing the title.
Code from the node reference module to illustrate this, can be found where the schema is defined for the field type it uses to create these reference:
<code>/**
 * Implements hook_field_schema().
 */
function node_reference_field_schema($field) {
  $columns = array(
    'nid' => array(
      'type'     => 'int',
      'unsigned' => TRUE,
      'not null' => FALSE,
    ),
  );
  return array(
    'columns' => $columns,
    'indexes' => array('nid' => array('nid')),
    'foreign keys' => array(
      'nid' => array(
        'table' => 'node',
        'columns' => array('nid' => 'nid'),
      ),
    ),
  );
}
</code>
Comment: Yes you're right; I should have made the question a bit clearer. If the title is changed in Drupal, the node reference continues to work fine. The problem is that I'm using Feeds to import to two content types, so running two Feeds importers, and they have to use title from the source to sync. So say the Film title is changed in Drupal, then more Showtimes get added to the XML. On import, the new Showtime nodes are created but can't find their Film node. Using the ID field from the source would keep things joined up. Maybe using Field Collection instead of referenced content types is better?