Why is the conditional mean of the reduced form error zero?

Question: For example, we have a simultaneous equation model of supply and demand:
Supply: $$s(p)=\alpha_{s}+\beta_{s}p+\epsilon_{s}$$
Demand: $$d(p)=\alpha_{d}-\beta_{d}p+\epsilon_{d}$$
Market clearing condition: $$q = d(p) = s(p)$$
It is obvious that $E(\epsilon_{s}|p) \neq 0$ and $E(\epsilon_{s}|p) \neq 0$, as price $p$ is endogenous.
The reduced form of this model is:
$$p = \frac{\alpha_{d}-\alpha_{s}}{\beta_{d}+\beta_{s}}+\frac{\epsilon_{d}-\epsilon_{s}}{\beta_{d}+\beta_{s}}$$
$$q = \frac{\alpha_{d}\beta_{s}+\alpha_{s}\beta_{d}}{\beta_{d}+\beta_{s}}+\frac{\beta_{d}\epsilon_{s}+\beta_{s}\epsilon_{d}}{\beta_{d}+\beta_{s}}$$
It follows that the reduced form errors are linear combinations of the structural errors. My question is, how can one derive that the conditional means of the reduced form errors, given the constants, are zero?
Answer: Of course they are not. You write
$$p = c + h(\epsilon_{d},\epsilon_{s})$$
where $h(\epsilon_{d},\epsilon_{s})$ is (supposed) to be the "reduced form error".
How could it be that $E[ h(\epsilon_{d},\epsilon_{s})\mid p] = E[ h(\epsilon_{d},\epsilon_{s})\mid c + h(\epsilon_{d},\epsilon_{s})] =0?$
Moreover, what you name "reduced form of the model" is the theoretical solution of a reduced form after incorporating the market clearing condition (this reduced form being your first two equations where we replace $s(p)$ and $d(p)$ by $q$). So what you call "reduced form errors", really are not. Note that this solution is not estimable, since the RHS contains only unobservables. Assume now that you specify a regression
$$q=\gamma_0+\gamma_1p+u$$
which is an attempt to formulate a reduced-form model. But if you insert the solution for $p$ into the solution for $q$, you obtain
$$q = \frac{\alpha_{d}\beta_{s}+\alpha_{s}\beta_{d}}{\beta_{d}+\beta_{s}}+\frac{\beta_{d}\epsilon_{s}+\beta_{s}\epsilon_{d}}{\alpha_{d}-\alpha_{s}+\epsilon_{d}-\epsilon_{s}}p$$
$$\Rightarrow q = \gamma_0 + \gamma_1(\epsilon_{d},\epsilon_{s})\cdot p$$
This last equation, which is the "final" reduced form of the model, has no additive "error term" and this makes the inclusion of the reduced-form error $u$ shaky on theoretical grounds-what kind of error/disturbance does it represent, given the theoretical model? All such distrubances are captured by the two structural errors. So postulating the existence of some reduced form error $u$ is a misspecification.
The last equation tells us that the coefficient of price that reflects its effect on quantity is a non-linear function of the structural disturbances (without even containing a constant term around which it fluctuates due to the structural errors) : the reduced form model is one of stochastic and time-varying coefficients, and not of the variety for which some estimation approaches have been developed (that usually assume that the coefficient is the sum of a constant term and a time-varying stochastic term).
And this is why we approach the problem through the Instrumental Variables (IV) method (of which this example is the standard econometrics textbook one to introduce IV estimation), in which essentially we will eventually run a regression without using $p$ as a regressor.
Comment: There is nothing wrong with your comment - but you don't need all this elaboration to calculate the sample mean of a variable and treat this as a regression where the regressor matrix contains only one regressor which is a series of $1$'s (your $X$ variable). In this way we learn nothing about the relation between $p$ and $q$ -and this is what I meant by "not estimable" (i.e. that the relation between $q$ and $p$ is not estimable by this pair of equations). In any case, this does not change the fact that $E[ h(\epsilon_{d},\epsilon_{s})\mid p] \neq 0$.


Two fields on the same line in a vertical form with bootstrap

Question: I would like the fields "Name" and "Last Name" to be on the same row.
I've found some solutions such as this one here in stackoverflow, but the problem is that I want the labels positioned above the fields to be side by side too.
How is that possible?

Here's the form code:

<form>

    Name:
    <input type="text" class="form-control" id="inputName" placeholder="Enter your name here" value="Leandro">

    Last Name:
    <input type="text" class="form-control" id="inputLastName" placeholder="Enter your last name here" value="Faria">

    Title:
    <input type="text" class="form-control" id="inputTitle" placeholder="Enter your title here" value="CEO">

    Email:
    <input type="email" class="form-control" id="inputEmail" placeholder="Enter your email here" value="firstname.lastname@example.com">

    Notifications:
    <select class="form-control" id="selectEmailNotifications">
      <option>None</option>
      <option>Daily</option>
      <option>Weekly</option>
      <option selected>Monthly</option>
    </select>

    Status:
    <select class="form-control" id="selectEmailNotifications">
      <option selected>Active</option>
      <option>Inactive</option>
    </select>

    Profile:
    <select class="form-control" id="selectEmailNotifications">
      <option selected>Administrator</option>
      <option>User</option>
    </select>

</form>
Answer: Something like this should get you started.

      Name:
      <input type="text" class="form-control" id="inputName" placeholder="Enter your name here" value="Leandro">

      Last Name:
      <input type="text" class="form-control" id="inputLastName" placeholder="Enter your last name here" value="Faria">

Comment: @FábioZangirolami it may appear as if you don't need it, but you do. If you omit the row, the left and right margin will be messed up and your floating col-sm-6's will no longer be contained in a block level row.
Comment: the class 'row' not is need for me...!
Comment: I treated it with `@media screen and (min-width: 768px) ... padding-left ... padding-right ... `
tks
Answer: Yes, the top answer is true, but this is another solution.You can use inline bootstrap forms like this:

        Name
        <input type="text" class="form-control" id="input1" placeholder="David">

        Last Name
        <input type="text" class="form-control" id="input2" placeholder="Tanner">

Read the bootstrap document


Session state controller in Umbraco

Question: I have a custom controller in ~/Controllers/Api/Test.cs inherited from SurfaceController.
What will be routed URL for it ?
Answer: All is documented here: https://our.umbraco.org/documentation/reference/routing/surface-controllers. If it supposed to be an API controller, you should probably inherit from UmbracoApiController to be able to use standard WebAPI features with addition of Umbraco Context and Helper injected inside.
More info about it: https://our.umbraco.org/documentation/Reference/Routing/WebApi/
Comment: Marcin, and how exactly can I access Session via Umbraco Context ?
Comment: What exactly you want from session? This is a standard ASP.NET sessionstate which you're able to use everywhere (https://msdn.microsoft.com/en-us/library/ms178581.aspx). UmbracoContext is a different object which contains many other useful informations about current umbraco state: https://our.umbraco.org/apidocs/csharp/api/Umbraco.Web.UmbracoContext.html.

Session state controller in Umbraco


How to get integer with regular expression in kotlin?

Question: ViewModel
fun changeQty(textField: TextFieldValue) {
    val temp1 = textField.text
    Timber.d("textField: $temp1")
    val temp2 = temp1.replace("[^\\d]".toRegex(), "")
    Timber.d("temp2: $temp2")
    _qty.value = textField.copy(temp2)
}

TextField
                OutlinedTextField(
                    modifier = Modifier
                        .focusRequester(focusRequester = focusRequester)
                        .onFocusChanged {
                            if (it.isFocused) {
                                keyboardController?.show()
                            }
                        },
                    value = qty.copy(
                        text = qty.text.trim()
                    ),
                    onValueChange = changeQty,
                    label = { Text(text = qtyHint) },
                    singleLine = true,
                    keyboardOptions = KeyboardOptions(
                        keyboardType = KeyboardType.Number,
                        imeAction = ImeAction.Done
                    ),
                    keyboardActions = KeyboardActions(
                        onDone = {
                            save()
                            onDismiss()
                        }
                    )
                )

Set KeyboardType.Number, it display 1,2,3,4,5,6,7,8,9 and , . - space.
I just want to get integer like -10 or 10 or 0.
But I type the , or . or -(not the front sign), it show as it is.
ex)
typing = -10---------
hope = -10
display = -10---------
I put regular expression in
val temp2 = temp1.replace("[^\\d]".toRegex(), "")

But, it doesn't seem to work.
How I can get only integer(also negative integer)?
Answer: Use this regex (?<=(\d|-))(\D+) to replace all non digit characters, except first -.
fun getIntegersFromString(input: String): String {
    val pattern = Regex("(?<=(\\d|-))(\\D+)")
    val formatted = pattern.replace(input, "")
    return formatted
 }

Check it here


Structural equation models without circular definition of latent variables

Question: I'm trying to perform Bayesian structural equation modeling in Python and PyMC3, but I think the problem is similar for most probabilistic progamming languages, include JAGS, Stan, etc.
SEMs are often defined using equations like these:
$\begin{equation}
\boldsymbol{y}=\boldsymbol{\nu}+\boldsymbol{\Lambda}\boldsymbol{\eta}+\boldsymbol{\epsilon}\\
\boldsymbol{\eta}=\boldsymbol{\alpha}+\boldsymbol{B}\boldsymbol{\eta}+\boldsymbol{\zeta}\\
\boldsymbol{\epsilon}\sim\mathrm{MvNormal}\left(0, \boldsymbol{\Theta}\right)\\
\boldsymbol{\zeta}\sim\mathrm{MvNormal}\left(0, \boldsymbol{\Psi}\right)
\end{equation}$
As you can see, the latent variables in $\boldsymbol{\eta}$ are defined in terms of themselves. The model makes sense because $\boldsymbol{B}$ is a sparse, invertible, non-symmetric matrix that defines paths between latent variables, but I'm not sure how to code this in practice. Can the second equation be re-written/expanded to so that the definition is no longer "circular" and therefore more amenable to coding?
I realize that under SEM one usually marginalizes out $\boldsymbol{\eta}$ and so the problem is moot. However, I think it should be possible to code it up with $\boldsymbol{\eta}$ explicitly sampled.
Comment: Defining a variable as a function of itself, which hasn't been defined yet. `x = x` won't work in most programming languages.
Comment: What makes the original form difficult for coding? I fail to see
Comment: I wouldn't define it like that. For instance, in c++ you could do f(**f()), in Python you could pass a list of functions references. It's also more generic than naming concrete functions, this way you can pass any functions
Comment: Exactly, I don't want to define it that way. This is more of a question of the mathematical notation anyhow. The accepted answer perfectly understood the issue and provided the correct answer.
Answer: Assuming $(\mathbf{I} - \mathbf{B})$ is invertible, we can rewrite the $\boldsymbol{\eta}$ equation as follows:
$$
\begin{align}
\boldsymbol{\eta} &= \boldsymbol{\alpha}+\mathbf{B}\boldsymbol{\eta}+\boldsymbol{\zeta} \\
&\Updownarrow \\
\boldsymbol{\eta} - \mathbf{B}\boldsymbol{\eta} &= \boldsymbol{\alpha}+\boldsymbol{\zeta} \\
&\Updownarrow \\
(\mathbf{I} - \mathbf{B})\boldsymbol{\eta} &= \boldsymbol{\alpha}+\boldsymbol{\zeta} \\
&\Updownarrow \\
\boldsymbol{\eta} &= (\mathbf{I} - \mathbf{B})^{-1} (\boldsymbol{\alpha}+\boldsymbol{\zeta}) \\
\end{align}
$$
Where $\mathbf{I}$ is an identity matrix with the appropriate shape.


populating List from an Enumerable.Range or a List

Question: Currently, I use the following C# code to populate a List<dynamic> object with a range of integers:
var x = new List<dynamic>();
foreach (int i in Enumerable.Range(0, 100)) x.Add(i);

Is there a more lucid way of doing this? I tried
x = Enumerable.Range(0, 50).ToList();

and also
x = Enumerable.Range(0, 50).ToList<dynamic>();

but both result in type checking errors, presumably because C# has no automatic cast to List<dynamic> from List<T>.
Note that I am interfacing with an external library, so simply using List<int> instead of List<dynamic> is not an option.
Answer: You can use LINQ like this:
var x = Enumerable.Range(0, 100).Select(i => (dynamic) i).ToList();

Comment: or `Cast()`, which is (arguably) neater.
Answer: If your input really is a List<int> (or a List<T>, even), the following saves on allocation:
List<int> li;
var x = new List<dynamic>(li.Count);
x.AddRange(li.Cast<dynamic>());

If you find yourself doing this a lot, this is a prime candidate for an extension method:
static class CollectionExtensions {
    public static List<dynamic> ToDynamicList<T>(this ICollection<T> collection) {
        var result = new List<dynamic>(collection.Count);
        result.AddRange(collection.Cast<dynamic>());
        return result;
    }
}

Using ICollection rather than IList doesn't add a lot, but hey, ICollection is the one introducing Count, so why not.
Otherwise, using .ToList() after a .Cast<dynamic>() works fine.
Comment: Thanks, I've settled for `Enumerable.Range(0, 100).Cast().ToList()` which seems to be the cleanest looking solution.


Expository texts on advanced subjects

Question: I'm reading The Princeton companion to Mathematics and Basic Notions of Algebra by Shafarevich. Both of them are really pleasant reading, the first one treats the topics from a more elementary point of view and the second one use advanced examples from other areas and from algebra itself. From this I got to know the Encyclopaedia of Mathematical Sciences of Springer, I'm wondering if you know more texts like this, they don't have to be books, they could be papers/blogs/etc. I'm looking for well explained and motivated introductions to advanced fields/ideas in contemporary Mathematics.
Comment: I think you might find the Unapologetic Mathematician interesting and relevant: http://unapologetic.wordpress.com
Answer:
A book that comes to mind is Abhyankar's Lectures in Algebra. It is a fascinating book.
Miles Reid's Undergraduate Commutative Algebra should also fit your description. I am not sure about his other undergraduate book on Algebraic Geometry. I have not read this book.
I also like notes by Dr. David R. Wilkins. He has notes on a wide variety of subjects.
Notes by James Milne cannot be overlooked.
I don't know if Richard Courant's "What is Mathematics?" qualifies as an introduction to advanced areas in contemporary mathemtics. I certainly learned a lot from it at some point.
May be, Mumford's Red Book qualifies your criteria?
A nice introduction to Algebraic Geometry is Fulton's book "Algebraic Curves".
Ravi Vakil's notes on Foundations of Algebraic Geometry are also becoming very popular (though they are not elementary).
I also like Cox, Little and O'Shea's "Ideals, Varieties and Algorithms".
Rosen and Ireland's "A Classical Introduction to Modern Number Theory"
The Catsters on youtube explaining Category Theory.
Comment: Also, the books and notes mentioned above are a bit biased toward Algebra and Algebraic Geometry. I am sure there are great texts for other fields, and would like to know of some.
Answer: There are a lot of mathematical blogs. For example, I can mention Qiaochu's and also shamelessly plug my own. I can also direct you to look at the "Other Maths Blogs" section of the links on my blog.
Just in case you weren't aware of this: John Baez's This Week's Finds is the granddaddy of mathematical blogging, and contains a lot of gems along what you are looking for.

Expository texts on advanced subjects


How to set tty-clock output as background

Question: I would like to set tty-clock output as background for my i3 setup.
I want to know how to display a command output as background.
Things I tried so far:

Running a script that supposedly would run tty-clock and take its screenshot with scrot once a minute and feh would set it as background.Problem: tty-clock would stay on without ever letting next command to run and scrot is a screenshot utility and it would capture whatever I am looking at. Or I would need to switch to that workspace every minute to run, shot, kill, set as background.

tty-clock && killall tty-clock
scrot ~/Pictures/Wallpaper/background.png
feh ~/Pictures/Wallpaper/background.png

save tty-clock output to a file which supposedly would be converted into image by convert (by imagemagick) and feh would set it as background.Problem: tty-clock output is more than just clock which I guess give information about characters' colors or place.

tty-clock | cat > ~/TEMP/tty-clock-output

tty-clock-output
[?1049h[22;0;0t[1;39r(B[m[4l[?7h[?1h=[39;49m[?25l[39;49m(B[m[H[2J[17;59H[H[2J[7;12H[17;59H
[64G[45m
[Z
[Z
[Z
[Z  [49m(B[m[18d [45m  [49m(B[m  [45m
[67G  [49m(B[m  [45m
[67G

  [49m(B[m[18;79H[45m      [19;75H  [49m(B[m  [45m  [49m(B[m  [45m
[79G  [49m(B[m  [45m  [21;75H  [49m(B[m  [45m  [49m(B[m  [45m
[79G      [49m(B[m[18d [45m  [49m(B[m  [45m
[86G  [49m(B[m  [45m
[86G

  [49m(B[m[22;66H [22;85H[92G[22;66H   [22;85H[92G[22;66H   [22;85H[92G[22;66H   [22;85H[92G[22;66H   [22;85H[92G[22;66H   [22;85H[92G[22;66H   [22;85H[92G[39;1H[?12l[?25h[?1049l[23;0;0t
[?1l>[?1049h[22;0;0t[1;39r(B[m[4l[?7h[?1h=[39;49m[?25l[39;49m(B[m[H[2J[17;59H[H[2J[7;12H[17;59H
[64G[45m
[Z
[Z
[Z
[Z  [49m(B[m[18d [45m  [49m(B[m  [45m
[67G  [49m(B[m  [45m
[67G

  [49m(B[m[18;79H[45m      [19;75H  [49m(B[m  [45m  [49m(B[m  [45m
[79G  [49m(B[m  [45m  [21;75H  [49m(B[m  [45m  [49m(B[m  [45m
[79G      [49m(B[m[18d [45m
[86G

[86G      [49m(B[m[22;66H  [22;85H[92G[22;66H   [22;85H[92G[39;1H[?12l[?25h[?1049l[23;0;0t
[?1l>

Answer: You don't need to invoke tty-clock at all: a script which sends the output of date (formatted to suit) to a text file, and then runs convert on that should do the trick. You'll need to spend some time playing with the convert parameters to get the desired look of course.
Comment: Expected & achieved results are [here](https://imgur.com/a/OL5f0Kx)
i really wanted to have blocky tty-clock font but it was not available in figlet fontDB.
I will update my question if I get the solution I wanted.
Comment: Any particular reason you're using figlet? You can use any installed font with convert.
Comment: I know I can enlarge any font as much as I want (I learned that yesterday :) but I really like the tty-clock style and I don't know any monospace font with same style. I even looked at [tty-clock source code](https://github.com/xorg62/tty-clock) to find the font tty-clock uses but it uses [drawnumber function](https://github.com/xorg62/tty-clock/blob/0cec6b099385d0db33fe81ae3d0d34e15ed40430/ttyclock.c#L221) instead.
Comment: Incorporating that in your own code would seem to be the answer then!


Applying Rubin's rule for combining multiply imputed datasets

Question: I am hoping to pool the results of a pretty basic set of analysis performed on a multiply imputed data (e.g. multiple regression, ANOVA). Multiple imputation and the analyses have been completed in SPSS but SPSS does not provide pooled results for a few statistics including the F-value, covariance matrix, R-Squared etc.
I have made a few attempts to address this issue by venturing into R or trying macros that are available and have not successfully resolved the problem (e.g. with running into issues with pooling the stats for more than 5 imputations in Mice, for example).
At this point, I would like to try computing these by hand, applying Rubin's rule, using the output that SPSS generates. However, I am not sure how I can derive the within-imputation variance ($\bar U = \frac 1 m\sum_{j=1}^mU_j$) based on the output SPSS generates.
I would really appreciate a detailed instruction on this.
Comment: Are you just wondering what the symbols in that formula mean? Do you know what $U$ stands for in the SPSS output?
Comment: For the ANOVA output in particular (as part of the linear regression), F-statistic is reported along with sums of squares, df, and mean squared. I am specifically trying to figure out how to compute the within imputation variance component for the F-statistic.
Answer: Rubin's rules can only be applied to parameters following a normal distribution. For parameters with a F or Chi Square distribution a different set of formulas is needed:

Allison, P. D. (2002). Missing data. Newbury Park, CA: Sage.

For performing an ANOVA on multiple imputed datasets you could use the R package miceadds (pdf; miceadds::mi.anova).
Update 1
Here is a complete example:

Export your data from SPSS to R. In Spss save your dataset as .csv
Read in your dataset:
library(miceadds)
dat <– read.csv(file='your-dataset.csv')

Lets assume, that $reading$ is your dependent variable and that you have two factors

gender, with male = 0 and female = 1
treatment, with control = 0 and 'received treatment' = 1

Now lets convert them to factors:
dat$gender    <- factor(dat$gender)
dat$treatment <- factor(dat$treatment)

Convert your dataset to a mids object, wehere we assume, that the first variable holds the imputation number (Imputation_ in SPSS):
dat.mids <- as.mids(dat)

Now you can perform an ANOVA:
fit <- mi.anova(mi.res=dat.mids, formula="reading~gender*treatment", type=3)
summary(fit)

Update 2 This is a reply to your second comment:
What you describe here is a data import/export related problem between SPSS and R. You could try to import the .sav file directly into R and there are a bunch of dedicated packages for that: foreign, rio, gdata, Hmisc, etc. I prefer the csv-way, but that's a matter of taste and/or depends on the nature of your problem. Maybe you should also check some tutorials on youtube or other sources on the internet.
library(foreign)
dat <- read.spss(file='path-to-sav', use.value.labels=F, to.data.frame=T)

Update 3 This is a reply to your first comment:
Yes, you can do your analysis in SPSS and pool the F values in miceadds (please note this example is taken from the miceadds::micombine.F help page):
library(miceadds)
Fvalues <- c(6.76 , 4.54 , 4.23 , 5.45 , 4.78, 6.76 , 4.54 , 4.23 , 5.45 , 4.78,
             6.76 , 4.54 , 4.23 , 5.45 , 4.78, 6.76 , 4.54 , 4.23 , 5.45 , 4.78 )
micombine(Fvalues, df1=4)

Comment: Thank you for your suggestion. I have in fact tried miceadds but one issue I ran into was pooling the F value for all 20 imputed datasets and not just the 5 that mice is programmed to read by default (I believe). I have tried entering all 20 f-values I obtained from the SPSS output and used mice to pool these estimates. Would this method be acceptable (i.e. do imputation in SPSS, pool these estimates in mice adds)? If there is a way in which I could have all 20 imputations read in MICE, I'd appreciate it. Thanks again!
Comment: I have updated my answer with an complete example from spss to miceadds.
Comment: Thank you again. I will try running this and hope to follow-up with the results!
Comment: By the way: mice is not restricted to any number of imputations. I often use mice with m > 20 imputations. Getting the estimates out of SPSS and pooling them in mice is difficult and tedious, because mice assumes by default that all steps are performed inside the package scope.

If my answer has helped you, please tag it as correct or upvote!
Comment: > dat$IV1=factor(dat$IV1)
Error in `$<-.data.frame`(`*tmp*`, "IV1", value = integer(0)) :
  replacement has 0 rows, data has 10> dat.mids=as.mids(dat)
Error in mice(data[data[, .imp] == 0, -c(.imp, .id)], m = max(as.numeric(data[,  :
  Data should contain at least two columns
> fit=mi.anova(mi.res=dat.mids,formula="DV~IV1*IV2*INT",type=3)summary(fit)
Error: unexpected symbol in "fit=mi.anova(mi.res=dat.mids,formula="DV~IV1*IV2*INT",type=3)summary"
>
Comment: You can more easily run the R code directly in SPSS Statistics in a BEGIN PROGRAM R block.  The active data can be read by calling  spssdata.GetDataFromSPSS(), which can also automatically convert categorical variables to factors.
Answer: You correctly wrote down the pooled estimator:
$$ \bar{U} = \frac{1}{m} \sum_{i=1}^m U_i$$
Where $U_i$ represents the analytic results from the $i$-th imputed dataset. Normally, analytic results have some normal approximating distribution from which we draw inference or create confidence bounds. This is mainly done using the mean value ($U_i$) and its standard error. T-tests, linear regressions, logistic regressions, and basically most analyses can be adequately summarized in terms of that value $U_i$ and its standard error $\text{se}(U_i)$.
Rubin's Rules uses the law of total variance to write down the variance as the sum of a between and within imputation variance:
$$\text{var}(\bar{U}) = E[\text{var}(\bar{U}|U_i)] + \mbox{var}\left(E[\bar{U}|U_i]\right)$$
The first term is the within-variance such that $E[\text{var}(\bar{U}|U_i) = \frac{1}{m}\sum_{i=1}^m V_i$ where $V_i$ is the variance of the analysis result from the $i$-th complete or imputed dataset. The latter term is the between-imputation variance: $ \mbox{var}\left(E[\bar{U}|U_i]\right) = \frac{M+1}{M-1} \sum_{i=1}^m\left(U_i - \bar{U}\right)^2$. I've never quite grasped the DF correction here, but this is basically the accepted approach.
Anyway, since the recommended number of imputations is small (Rubin suggests as few as 5), it is typically possible to compute this number by hand fitting each analysis. A by-hand example is listed below:
require(mice)
set.seed(123)
nhimp <- mice(nhanes)
sapply(1:5, function(i) {
  fit <- lm(chl ~ bmi, data=complete(nhimp, i))
  print(c('coef'=coef(fit)[2], 'var'=vcov(fit)[2, 2]))
})

Gives the following output:
coef.bmi      var
2.123417 4.542842
3.295818 3.801829
2.866338 3.034773
1.994418 4.124130
3.153911 3.531536

So the within variance is the average of the imputation specific point estimate variances: 3.8 (average of second column). The between variance is 0.35 variance of the first column). Using the DF correction we get variance 4.23. This agrees with the pool command given in the mice package.
> fit <- with(data=nhimp,exp=lm(chl~bmi))
> summary(pool(fit))
                  est        se        t       df   Pr(>|t|)     lo 95      hi 95 nmis       fmi     lambda
(Intercept) 119.03466 54.716451 2.175482 19.12944 0.04233303  4.564233 233.505080   NA 0.1580941 0.07444487
bmi           2.68678  2.057294 1.305978 18.21792 0.20781073 -1.631731   7.005291    9 0.1853028 0.10051760

which shows the SE = 2.057 for the model coefficient, (Variance = SE**2 = 4.23).
I fail to see how increasing the number of imputed datasets creates any particular issue. If you cannot supply an example of the error, I don't know how to be more helpful. But by-hand combination is certain to accommodate a variety of modeling strategies.
This paper discusses other ways that the law of total variance can derive other estimates of the variance of the pooled estimate. In particular, the authors point out (correctly) that the necessary assumption for Rubin's Rules is not normality of the point estimates but something called congeniality. WRT normality, most point estimates that come from regression models have rapid convergence under the central limit theorem, and the bootstrap can show you this.
Comment: @llewmills hmm the DF correction must have been $(1+1/m)$ and not $(m-1)/(m+1)$.
Comment: @llewmills why would you calculate 5 p-values? You have a grand mean and a grand SE, now combine them and calculate one p-value for the multiply imputed analysis.
Comment: can you explain how you got to 4.23 from 3.8 (mean of variance estimates for each imputed dataset) and 0.35 (variance of the coefficient estimates for each of the five datasets)? I am missing a step.
Comment: thank you @AdamO. I assume you meant $\frac{m+1}{m}$, (rather than $\frac{1+1}{m}$) because that delivered the exact result as the `pool(fit)`.
Comment: I don't suppose you know the formula for pooling the *p*-value @AdamO?
Comment: I have already :) Thanks for your help @Adam0. https://stats.stackexchange.com/questions/327237/calculating-pooled-p-values-manually?noredirect=1#comment620159_327237


Would this note from Consolation No. 3 be considered a nonchord tone?

Question: I was playing through Consolation No. 3 by Liszt yesterday, and I had a theory question about something.
In the second measure of this picture, the harmony is an E major triad. This section is in A minor, so that would be the V chord. In the top melody line, there is a G natural being played. This makes the descending line sound smoother rather than having a G# go to an F natural.
Would you consider the G natural a nonchord tone in this case? I'm wondering if there are arguments for and against classifying it as a nonchord tone. I'd love to hear some thoughts.
Thanks in advance!

 (2:14 in the piece is where the nonchord tone is)
Answer: There is certainly no G natural in the chord of E major, so yes, you would regard it as a nonchord tone.  When there is a clash like in the above example, it is called a 'false relation'.  It is simply a chromatic contradiction between two voices.
Comment: To hear a lot of false relations in a small space, try the works of Thomas Tallis (if you like 16th century music) or Ralph Vaughan Williams (if you like 20th century music).
Comment: After reading the German translation of the wiki article I can say I knew this term as **Querstand**. Now I have to admit I've never seen this case in a situation of simultaneity.
Comment: Thanks for the answer. I never encountered the "false relation" concept in my theory books before. It's a cool concept!
Answer: Mind that G (and F) belong to the melodic scale downward of Am and G# is the lead tone of E7 - the V7 of Am. We also have DF in the next chord. This explains the clash of G and G#.
Edit: I didn't know the term false relation (Jomiddnz) I've looked up this site and now I see ex.2 is the case I mentioned:
https://en.wikipedia.org/wiki/False_relation
" Here the false relation occurs because the top voice is descending in a minor key, and therefore takes the notes of the melodic minor scale descending (the diatonic sixth degree). The bass voice ascends and therefore makes use of the ascending melodic minor scale (the raised sixth degree)."
Answer: It's also worthwhile to point out that G# is part of the harmonic A minor scale, and G natural is part of the natural A minor scale. (In effect, minor keys borrow the dominant 7th chord from their enharmonic major key so as to have a leading tone on the seventh scale degree. Hence the term "harmonic" minor; the notes that are used in harmony.) So, Liszt is using both the natural and harmonic scale notes at the same time.
There's a further ambiguity here that's interesting. If you just took the top notes of the two measures and played them by themselves, you'd probably swear that they were in C major, the relative major of A minor. I'm quite sure that that is intentional, and one of the reasons that he uses G natural in the melody instead of G# in the passage. It's sort of like the melody is in C, and the harmony is in A minor.
One gets the feeling that he doesn't want to wander too far into a minor mode context, which is rather borne out by the fact that the similar later passage (around 2:46) is harmonized with a (very) standard I64-V7-I progression in the home key of Db.


Como executo um código com o aplicativo fechado ou minimizado?

Question: Estou querendo executar código que mantem a tela sempre acesa, ele já funciona perfeitamente quando estou dentro do APP, porem, se minimizo ou fecho ele, para de funcionar.
OBS: Estou usando UIKit.framework
código que mantem a tela acesa:
<code>[[UIApplication sharedApplication] setIdleTimerDisabled: YES];
</code>
De qual forma eu poderia seguir com ele ativo mesmo fechando ou minimizando o app?
Achei este projeto na internet:
https://github.com/muhku/FreeStreamer/tree/master/FreeStreamerMobile
Ele é um APP de rádio, quando toco a rádio e minimizo o APP, ela segue tocando. Quero algo assim, só que ao invés de um Streaming de rádio, quero executar o código mostrado acima.
Comment: Já tentou colocar esse código no método _applicationDidBecomeActive:(UIApplication *)application_ do seu AppDelegate? Isso irá forçar sempre que o aplicativo voltar, colocar o tempo de espera como desativado.
Comment: Obrigado Lucas, vou tentar desta forma e até amanha dou retorno se consegui ou não :)
Comment: @LucasEduardo , como desativo o tempo de espera?
Comment: Publiquei um exemplo na pergunta. Neste exemplo quando minimizo a aplicação, ela continua funcionando.
Answer: Não existe app rodando em background em iOS além de algumas exceções (música, gps, bluetooth, etc).
Consulte a documentação oficial para mais informações: iOS - Background Execution


How do I find the 3rd angle or a vector with only the two other angles?

Question: A vector has direction angles α = 65° and β = 45°
Find the value of angle γ
Find a vector that has those direction angles
Answer: Hint
$cos^2 \alpha + cos^2 \beta + cos^2 \gamma =1$


How do I approach a multi-class classification problem involving a 2-part taxonomy?

Question: I am trying to solve a classification problem and am unsure of the strategy to use. I am using scikit learn and am more interested in whether I have the correct approach rather than the implementation.
I have

set T, where each item in the set is a string
two sets L1 and L2, that are non-overlapping controlled lists of labels
each item in T can map to one and only one item on L1 and one and only one item in L2
L1 and L2 are related as part of a 2 part taxonomy with which I am tagging items in T

e.g.

T = {'queen elizabeth's barnet', 'queen elizabeth's london', 'odeon leicester sq', 'odeon london', 'pizza express 189', 'piz expss 2', 'honda civic 25-jul'}
L1 = {building, car, boat}
L2 = {school, cinema, restaurant, honda, ford, cruise-boat}
I have trained my classifier on previous data to tag ''queen elizabeth's barnet' with L1/building, L2/school and 'odeon london' with L1/building and L2/cinema

At the moment I am approaching the problem as a multi-class classification, where I am assigning one and only one label from L1 and one label from L2 to each item in T and treating the 2 classification tasks independently i.e. I have trained a classifier to predict L1 given T and separately predict L2 given T.
I am thinking whether this method is the best approach as it doesnt make use of the dependency/constraint between L1 and L2 - and am considering predicting L1 for a given T and then using the predicted L1 in the feature vector to predict L2 (or vice versa). Unsure as to whether this is the best approach given there is error in the prediction.
Any ideas/experience on how best to approach this problem?
Thanks in advance for any help!
Answer: I solved a similar problem a few months ago. What you are describing actually is a clear example of a hierarchical classification problem.
In these kind of problems, what you usually want to do is to focus on building a single classifier for L1 (call it your first-level classifier); and then N classifiers for L2 (where N is the number of possible classes in L1) - these are your second-level classifiers.
You already know how to train the first-level classifier. For the second-level ones, the only gotcha is to remember that your training sets must be composed of only the examples of the particular subclass each classifier is modelling (e.g for the second-level model for car, you'll only use examples tagged as honda or ford, but examples tagged as cinema would not be part of the training set of this model).
Finally, when using your models, you just classify each test example with the first-level classifier. This gives you your L1 output, but also determines which second-level model to use for L2.
There are other ways of representing these kind of problems, of course. But in those where you have such a clear taxonomy:

each item in T can map to one and only one item on L1 and one and only one item in L2*)

Splitting the problem into 2 or more levels is the best way to go.
Comment: This is a very clear answer and strategy thanks for this! Very helpful.
Comment: Is there any paper addressing the problem of how to train classifiers for the smallest branches of the taxonomy (with very few instances)? Thank you.


React setState if Axios.get response data is good

Question: Currently I am making axios request and setting the response data to my state.
I have discovered some data have 'poster_path' of null (No image).
I want to remove those data before setState in componentDidMount.
I have tried the following but causes error.
    componentDidMount() {
        let url = "".concat(baseURL, '?api_key=', APIKEY, configData, `&with_genres=${genreID}`)
        axios.get(url)

        .then(res =>
            if (res.data.results.poster_path != null){
            this.setState({movies: res.data.results},()=>{
                console.log(this.state.movies);
            })
        }
        )}

Any help is greatly appreciated.
export class Documentary extends Component {
    constructor (props) {
        super (props)
            this.state = {
                movies:[]
            };
    }

    componentDidMount() {
        let url = "".concat(baseURL, '?api_key=', APIKEY, configData, `&with_genres=${genreID}`)
        axios.get(url)

        .then(res =>
            this.setState({movies: res.data.results},()=>{
                console.log(this.state.movies);
            })
        )}

.....render...

The API data looks like the following
{
  "page": 1,
  "total_results": 10000,
  "total_pages": 500,
  "results": [
    {
      "popularity": 27.169,
      "vote_count": 0,
      "video": false,
      "poster_path": "/4RtCBnCnsEqcTQejPQ1lIiCE75r.jpg",
      "id": 680438,
      "adult": false,
      "backdrop_path": "/aejCGlzSRY3nVmB23IpBiXuoXzW.jpg",
      "original_language": "en",
      "original_title": "After Truth: Disinformation and the Cost of Fake News",
      "genre_ids": [
        99
      ],
      "title": "After Truth: Disinformation and the Cost of Fake News",
      "vote_average": 0,
      "overview": "An investigation into the ongoing threat caused by the phenomenon of "fake news" in the U.S., focusing on the real-life consequences that disinformation, conspiracy theories and false news stories have on the average citizen.",
      "release_date": "2020-03-19"
    },
    {
      "popularity": 25.04,
      "vote_count": 0,
      "video": false,
      "poster_path": "/rODi66xlhEIaHs2krHlj4A8da5f.jpg",
      "id": 674334,
      "adult": false,
      "backdrop_path": "/rjtXLRO0ixmbjoQM27Rj7rFRWe9.jpg",
      "original_language": "en",
      "original_title": "Climbing Blind",
      "genre_ids": [
        99
      ],
      "title": "Climbing Blind",
      "vote_average": 0,
      "overview": "Blind climber Jesse Dufton's ascent of the Old Man of Hoy.",
      "release_date": "2020-03-20"
    },
    {
      "popularity": 24.492,
      "vote_count": 0,
      "video": false,
      "poster_path": null,
      "id": 674338,
      "adult": false,
      "backdrop_path": null,
      "original_language": "en",
      "original_title": "Amber and Me",
      "genre_ids": [
        99
      ],

Answer: You can try this out. Just filter your movie data before setting the state.
axios.get(url)
    .then(res => {
        if (res.data) {
            const movieData = res.data.results.filter(movie => movie.poster_path != null);
            this.setState({movies: movieData}, () => {
                console.log(this.state.movies);
            });
        }
    }

Comment: Perfect! Works great!
Answer: You can create a new array with the filter method to remove the movie with a poster_path of null, if that is what you want to do.


Gradient of Gaussian entropy w.r.t. $W$

Question: I have been struggling with deriving a gradient in matrix form for the following function. (w.r.t. $w$)
$$ H(w) = \sum_{i = 1}^{n} p(y_i - x_i^T*w) \log (p(y_i - x_i^T w)) $$
where $$p(x)$$ is the Gaussian,
$$ p(x) = \frac{1}{\sqrt{2 \pi \sigma^2}} \exp(-\frac{x}{2 \sigma^2}) $$
$X$ is $n \times m$, $y$ is $n \times 1$ and $w$ is $m \times 1$
So far I have used the chain rule to figure out the derivative but the dimensions do not add up if I want the gradient for $w$. How can I obtain this gradient w.r.t. $w$?
Answer: Let $z = y - X w $ (where $y,z,w$ are column vectors)
Then $z_i = y_i - \sum_j w_j X_{i,j} = y_i-x_i^T w $ (where $x_i$ is the $i-$ row of $X$) and $$\frac{\partial z_i }{\partial w_j}=-X_{i,j}$$
Recall that $ (p \log p) ' = (\log p +1) p'$
Then $$\frac{\partial H(w)}{\partial w_j}= - \sum_i (\log(p(z_i)+1) \frac{\partial p(z_i)}{\partial z_i} X_{i,j} $$
$$\frac{\partial H(w)}{\partial w} = - X^T s$$
where $s_i = (\log(p(z_i)+1) \frac{\partial p(z_i)}{\partial z_i}$
Can you go on from here?

Gradient of Gaussian entropy w.r.t. $W$


Overloading operators in C++ with template classes

Question: I have the following template class:
    template <class T>
class Matrix {

    public:
        Matrix(size_t rows, size_t columns, const T elements = 0);

        // scalar multiplication
        Matrix<T> operator*(const T& rhs){

            Matrix<T> result(rows, columns);

            for(size_t index = 0; index < rows * columns; ++index){
                result.elements[index] = elements[index] * rhs;
            }

            return result;
        }

        Matrix <T> operator*(const T& lhs, const Matrix<T>& rhs);

        const size_t rows;
        const size_t columns;

        private:

            std::vector<T> elements;
};

and the following implementation of the operator* :
// scalar multiplication
template <class T>
Matrix<T> Matrix<T>::operator*(const T& lhs, const Matrix<T>& rhs){

    Matrix<T> result(rhs.rows, rhs.columns);

    for(size_t index = 0; index < rhs.rows * rhs.columns; ++index){
        result.elements[index] = elements[index] * lhs;
    }
    return result;
}

when I try to compile clang says: error: overloaded 'operator*' must be a unary or binary operator (has 3 parameters)|
And I don't quite understand, what I am missing in this. In general template classes give me a hard time when it comes to overloading operators and I don't know why. There have been some posts on here on SO on this topic and I tried a few variations of the code but none of them worked.
Comment: as a member function it has `this` implicitly as first parameter but you want to add 2 more. Lets say you have `Matrix a,b,c;` your operator would be called like `a.operator*(b,c)` does this make sense? no ;)
Comment: Related: http://stackoverflow.com/questions/35853204/c-overloading-operator-in-a-template-class
Answer: The simple and reasonably efficient way to solve this problem is as follows:

Implement Matrix& operator *=(SomeType const&) and similar operations first.  These are mutating operations that change an instance of the class, then return a reference to *this.
Implement other operations as inline friends in terms of *=, where the lhs (usually) argument is taken by-value, modified and returned.

This tends to be really simple and quite often more efficient than starting with operator* instead of operator*=.
So you'll have:
 template<class T, etc>
 struct Matrix{
   Matrix& operator*=(T const&);
   Matrix& operator*=(Matrix const&);
   Matrix& operator+=(Matrix const&);

which you implement traditionally.  Then:
   friend Matrix operator*(T const& t, Matrix m){ m*=t; return m; }
   friend Matrix operator*(Matrix m, T const& t){ m*=t; return m; }

   friend Matrix operator*(Matrix lhs, Matrix const& rhs){ lhs*=rhs; return lhs; }
   friend Matrix operator+(Matrix lhs, Matrix const& rhs){ lhs+=rhs; return lhs; }

and now you only need to implement a few, traditional, methods.
These friend operators are non-template inline non-method functions that are auto-generated for each template instance of Matrix.
Your immediate problem was your non-static operator actually took an implicit this in addition to its two explicit parameters, and binary operators cannot take 3 arguments.

The complex and even more efficient solution involves a technique often called "expression templates".  The disadvantage is that expression templates are more complex to write, and have a few points of fragility around the auto keyword and similar situations.
As an example:
Matrix m = m1 * m2 + m3 * m4 + m5 + m6;

An expression template will do the above with only one allocation of the internal data of a matrix.
My above code will copy m1, multiply the result by m2.  Then it will copy m3, then multiply that by m4.  Then it will add up everything without making any additional copies.  Finally, this result will be moved into m.
So two matrices will be created instead of 1 in the expression template case.
A more-naive solution (like the OP's design) would create 5 Matrices instead of 2.
Comment: @kimsay If it is short and you are ok with `inline` and its perils, do it in the class definition.  If it isn't, put it elsewhere?  In the case of the above Koenig friend operators, you *must* do it in the class definition (as there is no way to refer to the operator outside of the class): this also means (to me) that they should always be short.
Comment: @kimsay nope: it does a bunch of things.  It makes ADL work smoothly, makes the operators themselves non-template (which has some nice properties: template operators can be fragile), it makes them non-member binary operators, etc.
Comment: thank you! Very often I'm not sure if I should implement a function within the class definition or outside of it. Is there a general rule?
Comment: also the friend is only there to access private fields?
Comment: sorry, got it! Thank you! @ Yakk
Answer: You're declaring Matrix <T> operator*(const T& lhs, const Matrix<T>& rhs); as member function, which has an implicit parameter this, that why compiler complains it "has 3 parameters".
You can make it a free template function,
template <class T>
class Matrix {
    ...
    template <class Z>
    friend Matrix<Z> operator*(const Z& lhs, const Matrix<Z>& rhs);
    ...
};

and
// scalar multiplication
template <class Z>
Matrix<Z> operator*(const Z& lhs, const Matrix<Z>& rhs){

    Matrix<Z> result(rhs.rows, rhs.columns);

    for(size_t index = 0; index < rhs.rows * rhs.columns; ++index){
        result.elements[index] = elements[index] * lhs;
    }
    return result;
}

Comment: @kimsay Only for accessing private fields, nothing more.
Comment: I tried friend earlier, but it doesn't work either, @songyuanyao
Comment: @kimsay My bad. Fixed.
Comment: thanks @songyuanyao . Do I only need friend for accessing private fields, or is there more to it?
Answer: Your function is a member function. Member functions have a hidden parameter, the this pointer.
You either need to make your operator* a non-member function or you need to get rid of one of the arguments to your operator* function (which will then multiply the data in "this" with the data in the incoming Matrix<T>.)


How to set up a cron job to send reminder e-mails in official Redmine Docker image?

Question: In a Redmine container based on an official image on Docker Hub, I am trying to set up a cron job to send reminder e-mails periodically.
As instructed here, typing bundle exec rake redmine:send_reminders RAILS_ENV=production as root inside the container works fine. However, setting the same command using crontab -e does not work and outputs various error messages. I suspect that they have something to do with setting correct PATH for Bundler or rake, but not being familiar with Ruby apps I am totally lost right now. I even tried adding (seemingly) relevant environment variables to crontab such that:
PATH=/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUBY_MAJOR=2.6
RUBY_VERSION=2.6.5
RUBY_DOWNLOAD_SHA256=d5d6da717fd48524596f9b78ac5a2eeb9691753da5c06923a6c31190abe01a62
GEM_HOME=/usr/local/bundle
BUNDLE_SILENCE_ROOT_WARNING=1
BUNDLE_APP_CONFIG=/usr/local/bundle
RAILS_ENV=production
HOME=/home/redmine
REDMINE_VERSION=4.1.0

but so far to no avail.
The followings are what I've tried adding on crontab -e so far. Each commands are (of course) preceded by cron's date time string format, and trailed by > /var/log/myjob.log 2>&1 to log whatever it outputs.

root cd /usr/src/redmine; bundle exec rake redmine:send_reminders RAILS_ENV=production
root cd /usr/src/redmine; /usr/local/bin/bundle exec /usr/local/bundle/bin/rake redmine:send_reminders RAILS_ENV=production

 Could not locate Gemfile or .bundle/ directory

cd /usr/src/redmine; /usr/local/bin/bundle exec /usr/local/bundle/bin/rake redmine:send_reminders RAILS_ENV=production
/usr/src/redmine/remind.sh (The following script)

remind.sh
#!/bin/bash
cd /usr/src/redmine
bundle exec /usr/local/bundle/bin/rake redmine:send_reminders days=7 RAILS_ENV="production"

bundler: failed to load command: /usr/local/bundle/bin/rake
(/usr/local/bundle/bin/rake) Bundler::GemNotFound: Could not find
rake-13.0.1 in any of the sources
/usr/local/lib/ruby/2.6.0/bundler/spec_set.rb:91:in `block in
materialize'   /usr/local/lib/ruby/2.6.0/bundler/spec_set.rb:85:in
`map!'   /usr/local/lib/ruby/2.6.0/bundler/spec_set.rb:85:in
`materialize'   /usr/local/lib/ruby/2.6.0/bundler/definition.rb:170:in
`specs'   /usr/local/lib/ruby/2.6.0/bundler/definition.rb:237:in
`specs_for'   /usr/local/lib/ruby/2.6.0/bundler/definition.rb:226:in
`requested_specs'
/usr/local/lib/ruby/2.6.0/bundler/runtime.rb:108:in `block in
definition_method'
/usr/local/lib/ruby/2.6.0/bundler/runtime.rb:20:in `setup'
/usr/local/lib/ruby/2.6.0/bundler.rb:107:in `setup'
/usr/local/lib/ruby/2.6.0/bundler/setup.rb:20:in `<top (required)>'
/usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in
`require'
/usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in
`require'

root cd /usr/local/bundle/bin/rake; rake --trace redmine:send_reminders RAILS_ENV=production

rake aborted! No Rakefile found (looking for: rakefile, Rakefile,
rakefile.rb, Rakefile.rb)
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:698:in
`raw_load_rakefile'
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:104:in
`block in load_rakefile'
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:186:in
`standard_exception_handling'
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:103:in
`load_rakefile'
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:82:in
`block in run'
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:186:in
`standard_exception_handling'
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:80:in
`run' /usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/exe/rake:27:in
`<top (required)>' /usr/local/bundle/bin/rake:23:in `load'
/usr/local/bundle/bin/rake:23:in `'

Here is what is inside /usr/src/redmine. A file named Gemfile exists.
root@975094a2b06b:/usr/src/redmine# ls -l
total 140
-rw-rw-r--  1 redmine redmine  538 Dec 20  2019 CONTRIBUTING.md
-rw-rw-r--  1 redmine redmine 2937 Dec 20  2019 Gemfile
-rw-rw-rw-  1 redmine redmine 5665 Apr 21  2020 Gemfile.lock
-rw-r--r--  1 root    root    5491 Feb 27  2020 Gemfile.lock.mysql2
-rw-r--r--  1 root    root    5483 Feb 27  2020 Gemfile.lock.postgresql
-rw-r--r--  1 root    root    5493 Feb 27  2020 Gemfile.lock.sqlite3
-rw-r--r--  1 root    root    5645 Feb 27  2020 Gemfile.lock.sqlserver
-rw-rw-r--  1 redmine redmine  205 Dec 20  2019 README.rdoc
-rwxrwxr-x  1 redmine redmine  275 Dec 20  2019 Rakefile
drwxrwxr-x  6 redmine redmine 4096 Dec 20  2019 app
-rw-rw-r--  1 redmine redmine  863 Dec 20  2019 appveyor.yml
drwxrwxr-x  2 redmine redmine 4096 Dec 20  2019 bin
drwxr-xr-x  1 redmine redmine 4096 Mar 26  2020 config
-rw-r--r--  1 root    root     136 Mar 10  2020 config.ru
drwxrwxrwx  1 redmine redmine 4096 Mar 26  2020 db
drwxrwxr-x  2 redmine redmine 4096 Dec 20  2019 doc
drwxrwxr-x  5 redmine redmine 4096 Dec 20  2019 extra
drwxr-xr-x  3 redmine redmine 4096 Oct 19 10:16 files
drwxrwxr-x  6 redmine redmine 4096 Dec 20  2019 lib
drwxr-xr-x  2 redmine redmine 4096 Mar 18  2020 log
drwxr-xr-x  5 redmine redmine 4096 Mar 26  2020 plugins
drwxrwxr-x  1 redmine redmine 4096 Dec 20  2019 public
-rwxr-xr-x  1 root    root     125 Dec 17 16:24 remind.sh
drwxrwxrwx  2 redmine redmine 4096 Feb 27  2020 sqlite
drwxrwxr-x 14 redmine redmine 4096 Dec 20  2019 test
drwxr-xr-x  1 redmine redmine 4096 Feb 27  2020 tmp
drwxrwxr-x  2 redmine redmine 4096 Dec 20  2019 vendor

What is the correct command ?
Answer: It turned out that crond included in BusyBox could run bundle exec rake... command without a problem. Perhaps it handles environment variables differently from standard crond?
All I had to do was
apt-get install busybox-static
busybox crontab -e

and then adding following job to crontab's list.
0 7 * * 1-5 cd /usr/src/redmine; bundle exec rake redmine:send_reminders RAILS_ENV=production

Please note that, for the time being, those steps were done manually inside the running Redmine container. I will add these to Dockerfile later.


How to create synthetic speech with a musical synth?

Question: I want to create 100% synthetic voice speech with no human voice to make my instrument say and sing lyrics.
I looked at the formants of different vowels like "A" or "E" or "O"

For example, "u" sounds with F1 at 300 Hz and F2 at 800 Hz, so I created a wave and I increased the volume in the 2 formants like this with Audacity:

But we cannot recognise any vowels,  Why not?
https://voca.ro/1kE9qIH5Yyfk
Comment: Google "talking piano" for several attempts that came before you.
Comment: Speech synthesis *has* been accomplished (and become quite advanced—thus Siri and Alexa). It might be educational to try to re-invent this wheel, but maybe research how the pioneers of synthesis handled the problem in the 20th century?
Comment: Yamaha did this starting the late 90s with Vocaloid (and it's now on version 5).
 https://www.vocaloid.com/en/  Be aware, it's very hard, and it's unlikely you are going to be able to do anything just in Audacity.  You will end up creating a very complex VST plugin.  Better start reading up about digital signal processing too.
Comment: Start by studying how [vocoders](https://en.wikipedia.org/wiki/Vocoder) work.  Once you grok that, the path should be obvious.  This will require significant signal processing skills.
Answer: The problem with your Audacity experiment is probably that the EQ filters just aren't steep and selective enough. (and using a single sine wave as input, which leaves the filters with nothing to filter) Try something like Pure Data and use three or more band-pass filters in parallel (not in series), creating a really steep contour. Try searching for formant filters, they are done as parallel band pass filters. Your source article gives you frequencies F1 and F2, but you need something that gives you F3 etc. And use band-pass filters in parallel, not Audacity's EQ curves.
I once tried this and I was able to do a semi-intelligible vocal synth with one oscillator (actually, more than one because there was noise as well) and a formant filter consisting of a bank of three filters set to the right frequencies. To switch between vowels, morph/slide the three filters to the next vowel's frequencies. IIRC, two filters was too few, there needs to be at least three filters to create recognizeable vowels. Some letters like W that are classified as consonants can be done by morphing the formant filters between vowels very quickly. Plosives like t, p, k are more difficult and I couldn't do those with the simple synth building blocks I tried, namely oscillators and filters.
Here's a Sound on Sound article on formant synthesis https://www.soundonsound.com/techniques/formant-synthesis
Edit. I didn't look at your audio example. Seeing user1079505's answer, I recalled what the oscillator was in my vocal synth. It was not a simple sine wave, but something more complex like a square wave that has many partial frequencies besides the fundamental - and I mixed in some noise to simulate breathiness. More noise = more breathiness. If you have only noise, then it sounds like whispering. Wind noise of air flowing through a pipe, filtered by a formant filter. But filters need there to be something to filter. If there's no frequency content at, say, 400 Hz, then what does a band-pass filter at 400 Hz let through? Nothing.
Answer:
For example, the "u" sounds with a F1 at 300 Hz and a F2 at 800 Hz, so I created a wave and I up the volume in the 2 formants like this with audacity

This is the wave that you created:

And this is its spectrum:

It appears to me that your wave is a pure sine wave at 100 Hz. It does not contain any other frequencies (apart from distortions, see the next point), so boosting 300 Hz and 800 Hz won't do anything. EQ won't create sound at frequencies missing in the input signal. In order to imitate human voice you need a wave more resembling broad spectrum of human voice, e.g. containing multiple harmonics.

The wave is distorted (close to the left edge of the waveform image), and also saturated (right part of the image). I don't know what part of your process makes this, but it results in audible artifact, that may impede speech sound.
Answer: There is little use to eq certain frequencies when your base signal is a sine wave. You should start with a signal with wide harmonic spectrum. ZynAddSubFx has a special formant filter for such stuff, if you are interested.
Answer: The model seems far too simple; even if you would manage the vowels, the consonants will become insurmountable (due to lack of periodicity).
Either the synthesizer supplies something (see General Midi, programs 53 and 54 out of the box, or you will run out of oscillators. Compared to speech (song) the sound curves of real instruments are simple, and they use recorded samples for any decent approximation.


Is the notion of "expression" formal/rigorous enough?

Question: For any set $S$ and field $k$, one can form the vector space over $k$ with basis $S$. As a set, this is the set of all linear combinations ("expressions") of the form $\sum_i\alpha_is_i$ where $\alpha_i\in k$, $s_i\in S$, and all but finitely many $\alpha_i$ are zero. I thought this was a perfectly rigorous definition until I read Example 1.2.4(c) which, in particular, says:

To be completely precise and avoid talking about "expressions", we can define $F(S)$ [the vector space in question] to be the set of all functions $\lambda: S\to k$ such that $s\in S:\lambda(s)\ne 0\}$ is finite.

Why would one want to "rigorize" further the notion of expression and avoid talking about it? Isn't it a perfectly well- and rigorously defined notion already?
Comment: If "expression" were formal, what would be its definition? Would "$u \div$" be one? Or if $u$ and $v$ were known elements of an arbitrary vector space, would "$u^v$" be one? I have no doubt that an "expression" can be formalised on a context-by-context basis (which is what's happening here), but I doubt there's a sensible, useful definition for mathematics in general.
Comment: @user634426: Theo's point is that "$u\div$" or "$u^v$" **are not** among the "expressions" you want to deal with, and in order to have a rigorous definition you need to have an actual definition about which strings of symbols you're talking about _and which strings of symbols you are not_.
Comment: @user634426: Yes, there is a standard definition of linear combination. It's the one you have quoted following the words "To be completely precise". You seem to be dissatisfied with it.
Comment: @TheoBendit Isn't the notion of linear combiation formal? Namely, it is a sum of the form $\sum \alpha_i s_i$. And an expression is defined to be a linear combination. As for the 2nd and 3rd sentences in your comment, I don't know what that notation stands for.
Comment: @HenningMakholm But the definition of a linear combination contains the information about which strings of symbols are "allowed" and which are not, as far as I understand. And if an expression is defined as a linear combination, then those two "things" from Theo's comment are not expressions.
Comment: @user634426: Does it? There may be such a description in the book you're working from, but you have certainly not quoted any such description in your quotestion.
Comment: @user634426 Linear combinations are another context-sensitive definition of expression. They're well-defined enough for the given context, but someone had to specifically define them for certain operations and variables (again, a bit like the quote from the textbook). They're not a definition for the general term "expression".
Comment: @HenningMakholm I assumed there is a "universal"/standard definition of a $k$-linear combination of elements of any set $S$ (from any book in linear algebra).
Answer: For example, if your $S$ consists of the letters $a$, $b$, and $c$, are the strings "$1a$" and "$1a+0b$" and "$0c+1a$" all expressions? If they are all expressions, then are they all elements of your vector space? Are they different elements? If you say they are all elements of your vector space, but are the same element, then how to you get that from any concept of "expression"? They are certainly not the same strings of symbols.
If "$1a+0b$" is not an expression, then which expression is the zero element of your vector space?
How about "$1a+1a$" versus "$2a$"?
How about "$1a+2b$" versus "$2b+1a$"? There is nothing in your informal description that says $S$ comes with a preferred ordering, but expressions are always finite strings of symbols that appear in a particular order.

These problems are not insurmountable showstoppers. It is absolutely possible to give a rigorous definition of "expression", and then define your vector space as the quotient of a set of expressions by all identities that are provable in a certain formal theory -- but doing all that turns out to be more work and in the end less convenient and less rewarding than speaking about functions $S\to k$ with finite support.

A more rewarding thing to do with expressions would be to start by looking at the set of all expressions that can be built with the vector space operations, such as $3\cdot(5\cdot((-b)+7\cdot a+13\cdot(\vec0+c)))$. That is, don't a priori restrict to expressions of a particular form. The quotient out all identities that can be proved from the axioms for $k$-vector spaces (and arithmetic on $k$).
This still gives you a vector space of formal linear combinations of $S$, but this time around the entire construction is openly an example of a general concept of free models for equational theories. This is arguably worthwhile because it shows conceptual parallels to things that might not immediately look similar.
On the other hand, one of the first things one would do with this construction is probably to prove that it is isomorphic to the space of finitely supported functions $S\to k$, and then use the latter for actual computations.
Comment: Right, if I define an expression as a sum $\sum \alpha_i s_i $, then nothing tells me that $1a$ and $1a+0b$ are the same element. But why should they be the same element? Does it follow from vector space axioms or only from common sence? And if I define an expression as a function (as quoted), then $1a$ corresponds to (according to the remark in the cited text) $\lambda(a)a$ and $1a+0b$ corresponds to $\lambda(a)a+\lambda(b)b$. Why are these expressions (according to this formal definition) the same expression?
Comment: @user634426: With the common definition (which you quoted), there is one element of the vector space represented by the function $\{a\mapsto 1,b\mapsto 0,c\mapsto 0\}$. This single element is what we mean when we write the informal expressions $1a$ or $1a+0b$, or even $a$.
Comment: @user634426: It is possible that you can find a useful vector space structure on a set that contains the strings $1a$ and $1a+0b$ as different elements. It just won't be what people generally mean when they speak of the space of formal linear combinations. And the point of having a definition is to make such things explicit!
Comment: Apparently I didn't know until today about the formal definition of linear combination. Even relatively serious text like Artin or Axler only define linear combinations as sums of the form $\sum \alpha_i s_i$, but not as functions.
Comment: So if we use the rigorous definition, we also don't need to worry about what exactly the multiplication $\alpha_i s_i$ is, right? (That's the problem littleO pointed out in his answer.)
Comment: @user634426: The Artin I have a copy of ("Algebra", Prentice-Hall 1991) mostly only defines formal linear combinations (at the end of section 3.3) when $S$ is explicitly assumed to be a _"finite ordered set whose elements are distinct"_. In that case it makes sense to specify that an expression must contain all of the $s$ in the given order, which eliminates the ambiguities here. There's a single sentence that alludes to formal linear combinations of an _infinite_ set; that sentence does seem to sweep all of the subtleties under the carpet.
Comment: @user634426: Correct, you don't need to worry about $\alpha_i s_i \cdot \alpha_j s_j$. Even in the intuitive view where you ignore the subtleties, such an expression would never arise out of use of the allowed vector space operations.
Comment: I meant the multiplication of an element of $k$ by an element of $S$, not the product $\alpha_is_i\cdot \alpha_j s_j$.
Comment: @user634426: Ah. In both cases you would need an actual definition of how scalar multiplication works in your new vector space. This definition can be short and simple when your vectors are functions $S\to k$ with finite support, but it does need to be there. In the simple "expression" view you can sort of get away with claiming the right definition follows from the distributive law. But then there's really a lot of heavy lifting being done by a notion of "expression" that doesn't yet have a rigorous definition.
Comment: Yes, I would defenitely need a definition of scalar multiplication and addition in the vector space (and it's given in the book cited), but what I meant is that I don't have to worry about what kind of product is used in the "expression" $\alpha s$ because such "expression" is formally just a function, and the question pointed out in littleO's answer doesn't even arise, as far as I understand. (Unlike in the case of the informal definition.)
Comment: @user634426: Yes, that is right.
Answer: $S$ is just a set with no structure, so it is not clear what is meant by multiplying an element of $S$ by a scalar, or adding together two elements of $S$. If $S$ were assumed to be a vector space over a field $F$ this would be no problem. But $S$ is just a set, so we must carefully define what we mean by taking linear combinations of elements of $S$.
For example, suppose that $S$ is, say, the set of all lines in a given plane. Without further explanation, it's not clear what it would mean to take a linear combination of elements of $S$.
Comment: "If $S$ were assumed to be a vector space over a field $F$ this would be no problem." Ironically, if one is not careful about distinguishing distinct operations, pre-existing additive structures could pose a big problem when trying to form a free additive structure.
Comment: @TheoBendit An example is the group ring $\Bbb Z[G]$, which is formally the set of maps $G\to \Bbb Z$ that are $\ne0$ only for finitely many $x\in G$, or les formally linear combinations of elements of $G$ with coefficients in $\Bbb Z$. The poblems you mention occur for example when we consider $\Bbb Z[\Bbb Z]$ and the various meanings of $+$ and $\cdot$ therin


on('click') executando mais de uma vez

Question: Quando clico em uma area e depois no botão .mais1 pela primeira vez executa corretamente a função mas se eu clicar em uma area depois em outra e clicar no botão .mais1 ele executa a função duas vezes, a função é executada o número de vezes que eu clico no elemento.
Não consegui identificar o erro, alguem já teve esse problema? Alguem sabe a solução?
 $("area").click(function(){

    var escrever = '';
    var a = $(this).attr('class');
    var x = $.inArray(a,paises1);
    var clicado = x;

    t = ataques_possiveis[x].length;
    meus_territorios_tamanho = meus_territorios.length;

    if(opcao==2){

        for(w=0; w<meus_territorios_tamanho; w++){
            if(meus_territorios[w]==x){
                $(".selecione").html(paises2[x]);
            }
        }

        $('body').on('click','.distribuir .mais1',function(){

            if($('.selecione').text()!='Selecione'){
                var local = $(this).parent().parent().children('h2').text().replace(':','');
                var ter = $.inArray($(".selecione").text(),paises2);
                var pos_local = $.inArray(local,nomes_locais);

                for(var z=0; z<meus_territorios_tamanho; z++){
                    if(local==nomes_locais[0]){//verifica o tipo de exercito
                        if((meus_territorios[z]==x)&&(distribuir_locais[pos_local]>0)){
                            distribuir_locais[pos_local] = distribuir_locais[pos_local] -1;
                            exercitos[ter] = exercitos[ter]+1;
                            $('.'+ter).text(exercitos[ter]);
                            $(this).parent().parent().children('.dist_local').text(distribuir_locais[pos_local]);
                        }
                    }
                }
            }
        });
    }
});

Comment: precisamos do html, obrigado
Answer: Na verdade ele vai ocorrer toda vez que o evento click elemento area for clicado. Pode ser que o .mais1 esteja dentro dele, então possa parecer que é o clique nele que está fazendo, mas não necessariamente.
O que você pode fazer é tirar a criação do evento click do .mais1 de dentro do clique de area, já que você está atribuindo o evento no body mesmo. Se o funcionamento do .mais1 depende do clique em area e que a variável opcao(que me parece ser global) seja igual a dois, você pode replicar a condição no if dentro do evento:
$('body').on('click','.distribuir .mais1',function()
{
    if(opcao == 2 && $('.selecione').text()!='Selecione')

Outra solução é usar o .off(), mas não recomendo porque seria uma gambiarra, mas seria útil caso a regra fosse "o clique em .mais1 só deveria funcionar após um clique no area. Funcionaria assim:
$('body').off('click','.distribuir .mais1').on('click','.distribuir .mais1')

Comment: Muito obrigado! Deu certo já tinha ficado hrs tentando resolver!
Comment: @Thadeu se quiser já pode aceitar a resposta
Comment: @Math vocês unificaram o usuário dele?
Comment: @DontVoteMeDown sim, fizemos um merge de usuários

on('click') executando mais de uma vez


SearchView needs to be clicked twice to open

Question: I'm following this Android tutorial to implement the Search View. After fixing some issues, I got it to work. However, the search view needs to be clicked twice to open the editText. Any idea of what's going on?
Filter class:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    getMenuInflater().inflate(R.menu.toolbar_menu_filter, menu);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager =
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView =
            (SearchView) menu.findItem(R.id.menu_item_search).getActionView();
    searchView.setSearchableInfo(
            searchManager.getSearchableInfo(getComponentName()));

    searchView.setQueryHint(getResources().getString(R.string.search_hint));

    return super.onCreateOptionsMenu(menu);
}

menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".FilterUI">

<item android:id="@+id/menu_item_search"
    android:title="Search"
    android:icon="@drawable/ic_search_white"
    app:actionViewClass="android.widget.SearchView"
    app:showAsAction="ifRoom|collapseActionView"/>

<item android:id="@+id/menu_item_options"
    android:icon="@drawable/ic_clear_all_white"
    app:showAsAction="ifRoom"
    android:title="@string/filter_default"/>

Manifest file
<activity android:name=".Activities.FilterUI"
        android:screenOrientation="portrait"
        android:configChanges="orientation"
        android:windowSoftInputMode="adjustNothing">

        <meta-data android:name="android.app.searchable"
            android:resource="@xml/searchable" />

    </activity>

    <activity android:name=".Activities.SearchActivity">

        <intent-filter>
            <action android:name="android.intent.action.SEARCH"/>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>

Comment: Why you don't use `SearchView` **v7**, more compatibility and easy to use: http://developer.android.com/intl/es/reference/android/support/v7/widget/SearchView.html
Comment: Note to self, ignore this completely: "Note: This class is included in the support library for compatibility with API level 7 and higher. If you're developing your app for API level 11 and higher only, you should instead use the framework SearchView class." Support V7 is the way to go regardless
Comment: Oh, it works fine now, thanks!
Comment: Probably wasn't using v7 because developer docs https://developer.android.com/training/search/setup don't use it.
You should use v7 as @Mohsen said
Answer: Might be too late to answer but, let's get this done. Like I said, it's better to use:
app:actionViewClass="android.support.v7.widget.SearchView"

For more compatibility and etc. But the point is, in new AndroidX, we can't use android.support since we migrate to AndroidX and there will be only:
app:actionViewClass="android.widget.SearchView"

Available. But, let's see what documentation says for the newest APIs (AndroidX) and etc:

Note: This class is included in the support library for compatibility with API level 7 and higher. If you're developing your
  app for API level 11 and higher only, you should instead use the
  framework android.widget.SearchView class.

So in AndroidX, I have found:
app:actionViewClass="androidx.appcompat.widget.SearchView"

To use but you still can use: android.widget.SearchView.
Comment: Thanks a lot, replacing from app:actionViewClass="android.widget.SearchView"  to app:actionViewClass="androidx.appcompat.widget.SearchView" works for me.


How would I compute the Standard Error (SE) from a "response" type predicted value in r

Question: I am using the predict function in r to obtain a "response" type output (probability of event occurring), but using se.fit=TRUE doesn't work in that case.
As stated in the comment in this thread,

When using type="response", the prediction is back-transformed with the anti-link function (e.g. plogis for the logit-link). Using type="response"and se.fit=T yields non-sensical values

It follows that I should predict both the raw and response scores if I am interested in obtaining the SE. How would I go about applying the correct transformation to the SE values so that they are on the same scale as my "response" type probabilities?
Thank you
Comment: You can back-transform the limits of the prediction intervals if the software gives that but you cannot obtain the standard error.
Comment: Thanks. I've actually been thinking of moving to a Kaplan Meier, or Cox survival analysis since the data mostly lends itself to the type of analysis which makes it very simple to obtain a probability and Confidence Interval (CI) (except that interactions are more troublesome).
Answer: As stated by medewy in the comments,

You can back-transform the limits of the prediction intervals if the software gives that but you cannot obtain the standard error

Co create a function to use the predict function:
Using a Kaplam Meier model gives an easy confidence interval, but is more descriptive than anything.
For simpler models, COX survival analyses also provides the confidence interval when using the prediction feature, and works well if you have data that fits the distribution assumptions very well.
For more complex models, you can play with different distributions using survreg to fit fully parametric models. However, you are limited in the number of clustering variables (can't have interactions with multiple clusters), and still need to have a intrinsically linear relationship.
If you need even more control over certain moderators, then structural equations or decision trees with survival analyses are pretty much necessary. Predicted scores are still available, but you need to look into the specific prediction functions used for the different SEM packages.


How can I check whether the network connection between two servers is occasionally dropping?

Question: I have deployed a multi-tier java application and from time to time am seeing jobs in the application fail with broken pipe and closed channel errors similar to:
Caused by: java.nio.channels.ClosedChannelException
    at sun.nio.ch.SocketChannelImpl.ensureWriteOpen(SocketChannelImpl.java:125)
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:294)
    at com.common.connectionmanager.AsyncSocket$AsyncSocketOutputStream.write(AsyncSocket.java:466)
    at java.io.DataOutputStream.writeInt(DataOutputStream.java:180)

and
2009-06-15 14:02:53,492 ERROR [com.ClientConnectionManager] [Socket (ClientConnectionManager.java:368) - Client connection error
com.ConnectionException: Error encoding message to stream
Caused by: java.io.IOException: Broken pipe
    at sun.nio.ch.FileDispatcher.write0(Native Method)
    at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:29)
    at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
    at sun.nio.ch.IOUtil.write(IOUtil.java:75)
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:302)
    at com.common.connectionmanager.AsyncSocket$AsyncSocketOutputStream.write(AsyncSocket.java:466)
    at java.io.DataOutputStream.writeInt(DataOutputStream.java:180)

I think this means that the network connection between two of my servers is dropping momentarily and that these errors are telling me that the servers can't talk to each other.
All the servers are connected on a 1GBPS LAN.
The servers concerned are running Solaris - can anybody recommend any tools which I could use to monitor the network connection between them and spot whether it is indeed dropping out from time to time?
Answer: Run a ping test for a reasonable period of time.

ping 10.1.1.10 > connection.txt

The result will be at the end of the file connection.txt.

Ping statistics for 10.1.1.10:
      Packets: Sent = 53, Received = 53, Lost = 0 (0% loss),
  Approximate round trip times in milli-seconds:
      Minimum = 0ms, Maximum = 0ms, Average = 0ms
Comment: What should I learn from the result?
Comment: If you lose some packets it means your connection isn't stable. You should get 100% received packets (or close to 99.9%) if your servers are on the same network.
Comment: Thanks - I will try to check for missing packets as you suggest
Answer: You didn't mention if how these servers are connected ... LAN / WAN etc, which will make a huge difference in where you should start troubleshooting. If it's a LAN, start monitoring the switch interfaces these servers are plugged into, look for errors (maybe your duplex/speed settings are wrong), maybe one of the servers keeps requesting auto negotiation, or there's just a bad cable somewhere in the mix. You could also be seeing timeouts due to plain old congestion - there's a malware infected PC on the switch / you're running on 10BaseT.
If you're going across a WAN, start with a tool like smokeping, which will monitor a connection and tell you when, and for how long, you lose connectivity. If you are seeing  drops, this could be congestion / crappy connectivity / someone is stepping on the cable at your ISP ... could be anything.
Bonne chance.
Comment: Thanks - all servers are connected on a gigabit LAN.  Would smokeping still help?
Answer: I can't offer any Solaris-specific advice, but rather than testing the connection by pinging or something similar, you're probably better off monitoring the interfaces; if the connection is being dropped, I'd imagine you'd see something about it in the logs.


Does "=" have to be interpreted as equality?

Question: To put it briefly: In model theory, we are allowed to interpret any relation symbol in any way we like. So why do people seem to require that "$=$" is interpreted as the actual equality?
Let me elaborate a little more. In model theory, as I imperfectly understand it, one starts with an alphabet $\Sigma$ consisting of the allowable function and relation symbols; for instance for ordered fields we could take $\Sigma = \{\cdot,+,<,0,1\}$. To these, we add symbols for variables $x_1,x_2,\dots$ and logical symbols $\vee, \wedge, \forall, \exists, \dots$. Using these, we can form terms (well formed expressions that will describe elements of the set) and sentences (expressions that will either be true or false). If we assume some set $A$ of sentences to be true (axioms), then the set of all their logical consequences, say $T$, is a theory. A theory can be interpreted by first choosing a set $X$ to work on, and then assigning to the function and relation symbols actual functions ($X^k \to X$) and relations ($X^k \to \{\top,\bot\}$). This is to be done in such a way that the axioms are satisfied.
My problem is that the equality seems to be treated in a different way than other relations, and I don't quite see why. As far as I understand, it is normally required to be the "real" identity: $x = y$ means that $x$ and $y$ are the same element of $X$. Is there some reason not to treat "$=$" just as an ordinary relation (with axioms of being an equivalence relation + for each relation symbol axiom "if $x_1 = y_1,\dots,x_k=y_k$, then $R(x_1,\dots,x_k)$ iff $R(y_1,\dots,y_k)$" )? What would go wrong if we did?
(The reason I am asking is mostly that it seems to me that this would make some constructions more elegant (such as the ultraproducts) by eliminating a quotient.)
Comment: I think it's okay if we treat equality as just another relation. Some logic textbooks in fact define equality exactly as you did.
Comment: You might find this wikipedia section satisfactory: http://en.wikipedia.org/wiki/First-order_logic#First-order_logic_without_equality
Comment: @Adriano: Thank you! May I ask you for a reference to some of these textbooks?
Comment: In probability theory, $=$ is often not treated as equality. In particular, if $X$ and $Y$ are random variables on a common outcome space $\Omega$, then $X=Y$ is usually taken as shorthand for $\{\omega \in \Omega : X(\omega) = Y(\omega)\}.$
Answer: It is not wrong. We can interpret '$=$' as an arbitrary binary relation symbol, then if we insert the statements to $A$ that it is equivalence relation and that it preserves all other relation and function symbols, then it will be interpreted as a congruence relation $\sim$ on a model $X$, and we can calmly form the quotient model $X/\sim$, which behaves exactly the same way as $X$, and '$=$' will be interpreted as real equality therein.
Answer: To add a historical twist to the fine answers given earlier, note that Fermat, Leibniz, and Euler precisely considered a generalized notion of equality in their work.  Fermat is discussed here: http://www.mitpressjournals.org/doi/abs/10.1162/POSC_a_00101, Leibniz here: http://www.ams.org/notices/201211/rtx121101550p.pdf, and Euler here: http://u.cs.biu.ac.il/~katzmik/bairetal.html
Answer: When I learned logic in college, the equality relation was treated specially: rather than taking = as a possibly optional symbol in a particular language, it was a built-in feature that had the same syntactic role as any other relation symbol, but was required to have the interpretation of actual equality in a model.  That is, it had the same status as $\neg$, which one could interpret as a unary relation (i.e. a predicate) but is in fact fixed in meaning by the rules of logic.
There is no disadvantage to having a symbol with a certain requisite meaning in every model, so long as that meaning is available regardless of the language.  For one could otherwise just simulate it with a relation symbol, as you say, except that we'd get other (presumably spurious) models with = not meaning equality.  Of course, since almost any set with any structures can be a model for some theory, there isn't much room for this kind of thing; however, equality is one relation you can guarantee exists, so we do.
Answer: No, there is nothing wrong with treating "$=$" as just another relation, although that approach seems to be out of fashion. See Abraham Robinson's 1965 book Introduction to Model Theory and to the Metamathematics of Algebra. If memory serves (I don't have a copy) it treats equality the way you are asking for.
Answer: I think that Leibnitz' identity is a part of the answer.
As I see it $'\!\!='$ is not just any equivalence relation, but the ultimate. Given any equivalence relation $'\!\!\sim '$, then it must be true that $x=y \Rightarrow x\sim y$.
Not all phenomena are identical to others or even to themselves: it is virtually impossible to define an identity for statements (here equivalence is the best, but obvious different statements can be equivalent) or even for some physical phenomena as photons and waves.
I think this is a question about how (for example) mathematical objects differs from other mathematical features. The question of the existence of mathematical objects, should rely on explicitly stated postulates or paradigms.
Also, the question of the identity is closely related to the principle of substitution in mathematics.


Urn draws with replacement problem: number of drawn white balls till we draw black ball for the k-th time

Question: In the urn we have a white, b red and c black balls. We draw with replacement. Calculate the expected number of white balls, which are drawn until we drew black ball for the k-th time.
My solution:
The expected number of draws till be draw black ball for the k-th time is:
$$\left(\frac{a+b+c}{c} \right)^k$$ That should be correct? I don't really know how to continue.
The below is obviously wrong due to comments.
In the sequence of turns there are
$$\left( \frac{a+b+c}{c} \right)^k-k$$
possibilities to draw white or red. Therefore
$$\frac{b}{a+b+c}\left(\left(\frac{a+b+c}{c} \right)^k-k \right)$$
of them are white.
Is my solution correct?
Comment: As a side note:  it's at least an informal convention to use variable names that match the colors.  I assumed that $b$ was the number of black balls, for instance.  Here, the red balls are irrelevant and can be ignored, I'd just use $w,b$ for the white and black balls.  makes it easier to read.
Comment: I suggest:  start with $k=1$.  Work recursively  from there.
Comment: My first comment had an error, so I deleted it.  Half of it was correct, though:  if $a=0$ the answer here is clearly $0$, as you'll never draw white.  Yet your formula does not yield $0$ in that case.
Comment: For another illustration that the formula can't be right, suppose $b=0$, so there are no red balls.  That clearly has no effect on the number of white balls chosen before you see however many blacks, yet the formula yields $0$ in this case.
Comment: Please show all of your work, directly in the posted question, (not the comments) in very clear detail.  That is, please clarify how you reached each conclusion in your posted question.
Comment: For what it's worth, virtually no MathSE posted question that I have seen (from me or anyone else) that followed
[this article on MathSE protocol](https://math.meta.stackexchange.com/questions/33190/how-to-avoid-downvotes-for-beginners-questions/33236#33236)
has been downvoted. Instead, such questions are almost always upvoted, with
MathSE reviewers going out of their way to try to answer the question.
Comment: Note:  while I don't think this is the best method, you can do it along these lines.  Your big mistake is in the first line.  The expected number of draws until you get the first black ball is indeed, $\frac {a+b+c}c$.  But, after that, the expected number is *linear* in $k$, hence additive, not multiplicative as you have suggested.
Comment: You can get properly sized parentheses (and other paired delimiters) that adjust to the size of their content by preceding them with `\left` and `\right`.
Answer: $\textbf{Hint}$
Following lulu's advice to use friendly nomenclature for symbols, and realising that the red balls are irrelevant,
Let $w$ = # of white balls, $b$ = # of black balls, $n = w+b$, then
P(black) $=p = \dfrac{b}{n},\;\;$ P(white) $=1-p = q$
The earliest the $k_{th}$ black could come would be at position # $k$ in the queue with no white preceding it, then at  # $(k+1)$ with one white preceding it, and so on upto all $w$ whites preceding it
Thus P(expected # of whites preceding # $k_{th}$ ball)
$= \dfrac{(k-1)!}{(k-1)!0!}q^0p^k*0 + \dfrac{k!}{(k-1)!1!}q^1p^k*1 +...$
(If you prefer, you could use binomial coefficirnts rather than permutations)
You should be able to continue from here, and also condense the formula ?

 Letting $j$ be the counter for the number of whites before the $k_{th}$ black, the expected # of whites before the $k_{th}$ black
$$ =\sum_{j=0}^w \binom{k+j-1}{j}q^jp^k*j$$
Answer: To summarize the discussion in the comments:
The red balls are irrelevant, so let's ignore them.  And let's use $W,B$ for the number of white and black balls respectively.
Let $E_k$ denote the answer we seek, for a given $k$.
We first solve the case $k=1$. Considering the result of the first draw, we have $$E_1=\frac B{W+B}\times 0+\frac W{W+B}\times (1+E_1)\implies E_1=\frac WB$$
But it is clear that $E_k=E_{k-1}+E_1$ so we have $$\boxed {E_k=\frac {kW}B}$$
Sanity Checks:  if $W=0$ this vanishes, as it must.  If $B=0$ this is infinite, as again it must be.  Also, it's easy to see that replacing $(W,B)$ by $(nW, nB)$ has no effect on the expectation, and the formula reflects that.
As mentioned in the comments, the idea behind your approach is fine, though you get the initial expectation wrong.  Specifically, the expectation is additive in $k$, not multiplicative as you have written.  Once you correct this, you should be able to make your computation go through.  Specifically:  We expect it to take $\frac {B+W}B=1+\frac WB$ draws to see the first black ball, hence $$k\times \left( 1+\frac WB\right)=k+\frac {kW}B$$ draws to see the $k^{th}$, and all but $k$ of those are White.


From convergence in $L^2$ to convergence of the squares in $L^1$

Question: Given a function $f\in L^2(X,\mu)$ for some measure space $(X,\mu)$, we of course have that $|f|^2$ is a positive function in $L^1(X,\mu)$. I now came across the following. Suppose $\int_X |f_n(x)-g_n(x)|^2 d\mu(x)\rightarrow 0$ for sequences $f_n,g_n\in L^2$, then we also have $\int_X \big| \,|f_n(x)|^2-|g_n(x)|^2\big| d\mu(x)\rightarrow 0$. Can anybody give an idea on how to prove this?
Edit: We also assume the sequences are bounded.
Answer: $$\int \left| |f_n|^2 - |g_n|^2 \right| = \int \left| |f_n| - |g_n| \right| \left| |f_n| + |g_n| \right| \le \int |f_n - g_n| (|f_n| + |g_n|) \le \sqrt{\int |f_n- g_n|^2} \sqrt{\int (|f_n| + |g_n|)^2} \le  \sqrt{\int |f_n- g_n|^2} \left(\sqrt{\int |f_n|^2} + \sqrt{\int |g_n|^2}\right)$$
Where I used Cauchy-Schwarz and Minkowski's inequalities.
Comment: I see this working only if the $L^{2}$ norms of $f_n$ and $g_n$ are uniformly bounded. Or is there an additional argument that you could provide to show that the last term goes to $0$ as $n\to\infty$?
Comment: @T.Eskin I think that the statement isn't even true. I think I came up with a counterexample. I'll post when I get done polishing it.
Comment: @T.Eskin if we take $f_n = (n+1) \chi_{(0,1/n)}$ and $g_n = n \chi_{(0,1/n)}$, then all the assumptions hold but $\int ||f_n|^2 - |g_n|^2| = 2 + 1/n \to 2$.
Comment: You're right. That counterexample seems to do the job. And your current answer proves the statement e.g. for uniformly bounded sequences in $L^{2}$.
Comment: True, it only works if the sequences are bounded. Sorry not to have mentioned that.


Counting argument proof or inductive proof of $F_1 {n \choose1}+...+F_n {n \choose n} = F_{2n}$ where $F_i$ are Fibonacci

Question: Prove that $$F_1 {n\choose1} +...+F_n {n\choose n} = F_{2n}$$
where $F_i$ is the $i$th Fibonacci number.
This question is mentioned on Putnam and Beyond book number 861. I looked at the proof of the question, and the book's proof uses Binet's formula (i.e. the explicit formula for $n$th Fibonacci number), binomial formula, and the fact that $\frac{3+\sqrt{5}}{2} = (\frac{1+\sqrt{5}}{2})^2$. I am wondering whether there is a counting argument for this proof (or an inductive proof), and if so, it would be great if anyone posts them here.
Comment: You can also write $n$ *choose* $k$ as follows: $$\binom nk$$ which is *\binom nk* with dollar signs at the beginning and end, or *n\choose k* with dollar signs etc.
Answer: (The following answer is essentially Example 3.1.5 in this pdf.)
First, $F_{2n}$ counts the number of ways of tiling a strip of length $2n-1$ with tiles of length either $1$ (squares) or $2$ (dominos).
Now, let's look at the number of tilings of that strip in which $k$ of the first $n$ tiles are squares. There are $\binom{n}{k}$ ways of arranging the first $n$ tiles. A collection of $k$ squares and $n-k$ dominos will have length $2n-k$. So the strip remaining after the first $n$ tiles has length $k-1$, which means that it can be tiled in $F_k$ ways. In summary, the number of tilings of this sort is $F_k \binom{n}{k}$.
Moreover any tiling of the strip uses at least $n$ tiles (or it would have length at most $2n-2$), and the first $n$ tiles cannot all be dominos (or they would have length $2n$). So we have
$$
F_{2n}=\sum_{k=1}^n F_n \binom{n}{k}
$$
as desired.
Comment: Note that this proof also can be easily adapted to give the more general identity in @achille hui's answer.
Answer: Although this not my answer, I would like to rewrite it here. In fact, every time I read the @Robert Israel answer I understand that I  know a bit about Fibonacci numbers and not more!
Consider $A=\pmatrix{0 & 1\cr 1 & 1\cr}$ then the $n$th power of $A$, denoted by $A^n$, is obtained as follows
$$
A^n = \pmatrix{F_{n-1} & F_{n}\cr F_n & F_{n+1}} .
$$
where $F_n$ is the $n$th term of Fibonacci numbers.
The matrix $A$ is satisfaied on the equation $x^2-x-1=0$, since we have
$$
 \pmatrix{1 & 1\cr 1 & 2\cr}=\pmatrix{0 & 1\cr 1 & 1\cr}+\pmatrix{1 & 0\cr 0 & 1\cr} \Leftrightarrow  A^2=A+I
$$
Therefore,  we get
$$
A^{2n}=(A^2)^n=(A+I)^n=\sum_{j=0}^n C_j^n\, A^j \tag{1}
$$
Now consider the entry of the first row and second column of the matrix equation $(1)$ which impliying that
$$
F_{2n}=\sum_{j=0}^n C_j^n\, F_j\, .
$$
Comment: That's the clearest proof!
Answer: This is one way to attack the problem by induction. We need to generalize
the statement a little bit before we can carry out the induction step.
Extend definition of $F_n$ to $F_0 = 0$.
For any $n > 0$, let $\mathcal{S}_n$ be the statement:
$$\mathcal{S}_n :\quad F_{2n+k} = \sum_{\ell=0}^n \binom{n}{\ell} F_{\ell+k},\;\text{ for all k} \ge 0$$
When $n = 1$, $S_n$ reduces to $F_{k+2} = F_{k+1} + F_k$ for all $k \ge 0$. This is trivially true.
Assume $\mathcal{S}_{n}$ is true. For any $k \ge 0$, we have
$$\begin{align}F_{2(n+1)+k} = F_{2n+(k+2)}
&\stackrel{\mathcal{S}_n}{=}
\sum_{\ell=0}^n \binom{n}{\ell} F_{\ell+(k+2)}
= \sum_{\ell=0}^n \binom{n}{\ell} \left( F_{\ell+k+1} + F_{\ell+k}\right)\\
&= \sum_{\ell=1}^{n+1}\binom{n}{\ell-1}F_{\ell+k}
+ \sum_{\ell=0}^n \binom{n}{\ell} F_{\ell+k}\\
&= F_{n+1+k} + F_k + \sum_{\ell=1}^n \left(\binom{n}{\ell-1}+\binom{n}{\ell}\right)F_{\ell+k}
\end{align}
$$
Notice $\binom{n+1}{\ell} = \binom{n}{\ell}+\binom{n}{\ell-1}$ for $1 \le \ell \le n$, this leads to
$$F_{2(n+1)+k} = F_{n+1+k} + F_{k} + \sum_{\ell=1}^n \binom{n+1}{\ell}F_{\ell+k} = \sum_{\ell=0}^{n+1} \binom{n+1}{\ell}F_{\ell+k}$$
Since this is valid for all $k$, $\mathcal{S}_{n+1}$ is true.
By principle of induction $\mathcal{S}_n$ is true for all $n$.
In particular, if we fix $k$ to $0$, the desired identity follows:
$$F_{2n} = \sum_{\ell=0}^n \binom{n}{\ell}F_{\ell} = \sum_{\ell=1}^n \binom{n}{\ell}F_{\ell}$$


Example of a sequence of functions where the limit cannot be interchanged

Question:
Give an example of a sequence of continuous functions $f_n$ on $[0,1]$ with $f_n$  converges pointwise to a continuous function $f$ such that the following relation does't hold:
$$\lim_{n \rightarrow \infty} \lim_{x \rightarrow 0} f_n(x)=\lim_{x \rightarrow 0}\lim_{n \rightarrow \infty} f_n(x)$$

I know such a convergence is not uniform. I already tried with this one: $f_n(x)= 2nx e^{-nx^2}$. Actually this one satisfies the given limit condition even though the convergence is not uniform! Any hint?
Answer: Since all $f_n$ are continuous we have $\lim_{x\to0} f_n(x) = f_n(0)$ and since $f = \lim_{n\to\infty} f_n$ is also continuous we have $\lim_{x\to 0} f(x) = f(0)$.
So your relation boils down to $\lim_{n\to\infty} f_n(0) = f(0)$, which is true because $f_n \to f$ pointwise.
Comment: @LearningMathematics Yes, because $f$ is also assumed to be continuous. This doesn't follow from $f_n \to f$ pointwise.
Comment: so your conclusion is: the limit can be interchanged even the convergence is pointwise.