"Averaging" variances

Question: I need to obtain some sort of "average" among a list of variances, but have trouble coming up with a reasonable solution. There is an interesting discussion about the differences among the three Pythagorean means (arithmetic, geometric, and harmonic) in this thread; however, I still don't feel any of them would be a good candidate. Any suggestions?
P.S. Some context - These variances are sample variances from $n$ subjects, each of whom went through the same experiment design with roughly the same sample size $k$. In other words, there are $n$ sampling variances $\sigma_1^2$, $\sigma_2^2$, ..., $\sigma_n^2$, corresponding to those $n$ subjects. A meta analysis has been already performed at the population level. The reason I need to obtain some kind of "average" or "summarized" sample variance is that I want to use it to calculate an index such as ICC after the meta analysis.
P.P.S. To keep the discussion more concrete, let me explain the issue with the following example in R:
library(metafor)
dat <- get(data(dat.konstantopoulos2011))
dat$district <- as.factor(dat$district)
dat$school <- as.factor(dat$school)

In the dataset there is a variance associated with each school's performance score:
str(dat)
Classes 'escalc' and 'data.frame':  56 obs. of  6 variables:
 $ district: Factor w/ 11 levels "11","12","18",..: 1 1 1 1 2 2 2 2 3 3 ...
 $ school  : Factor w/ 11 levels "1","2","3","4",..: 1 2 3 4 1 2 3 4 1 2 ...
 $ year    : int  1976 1976 1976 1976 1989 1989 1989 1989 1994 1994 ...
 $ yi      : atomic  -0.18 -0.22 0.23 -0.3 0.13 -0.26 0.19 0.32 0.45 0.38 ...
 $ vi      : num  0.118 0.118 0.144 0.144 0.014 0.014 0.015 0.024 0.023 0.043 ...

Suppose that we perform a meta analysis with a hierarchical or mixed-effects model:
$y_{ij} = a + \alpha_i + \beta_j + \epsilon_{ij}$
where $\alpha_i$ and $\beta_j$ are the random effects for the $i$th school and $j$th district, respectively, and $\epsilon_{ij}$ is the measurement error with a known Gaussian distribution $N(0,v_{ij})$. This model can be analyzed as below:
(fm <- rma.mv(yi, vi, random = list(~1 | district, ~1 | school), data=dat))

rendering the following variance estimates for the two variance components:
Multivariate Meta-Analysis Model (k = 56; method: REML)
Variance Components:

            estim    sqrt  nlvls  fixed    factor
sigma^2.1  0.0814  0.2853     11     no  district
sigma^2.2  0.0010  0.0308     11     no    school

The two variances in the result, sigma^2.1 and sigma^2.2, correspond to the two random-effects variables (district and school).
I would like to compute the ICC for district, and that is why I wanted to obtain a summarized variance in the first place for those individual variances, $v_{ij}$, of the measurement term $\epsilon_{ij}$. Since the total variance is
$Var(y_{ij})= Var(\alpha_i + \beta_j + \epsilon_{ij}) = \sigma_1^2 + \sigma_2^2+v_{ij}$
my original (and simple) approach was to use just the arithmetic mean:
$\frac{\sigma_1^2}{\sigma_1^2 + \sigma_2^2+mean(v_{ij})}$
but I am not sure if the arithmetic mean, $mean(v_{ij})$, is appropriate in this context.
Comment: Context is everything here. Are these theoretical variances (moments of distributions), or sample variances? If they are sample variances, what is the relation between the samples? Do they come from the same population? If yes, do you have available the size of each sample? If the samples do not come from the same population, how do you justify averaging over the variances?
Comment: Hierarchical modeling is a very flexible answer. This blog post on the eight schools is a good start. http://andrewgelman.com/2014/01/21/everything-need-know-bayesian-statistics-learned-eight-schools/ Gelman et al., *Bayesian Data Analysis* is a great place to get more information.
Comment: Possible duplicate of [How to 'sum' a standard deviation?](https://stats.stackexchange.com/questions/25848/how-to-sum-a-standard-deviation)
Comment: In that case does this https://stats.stackexchange.com/questions/187197/computing-heterogeneity-assigned-to-random-factors-in-meta-analysis post help?
Comment: Is this an XY problem? Do you want to know how to average variances... Or do you want to know how to calculate an ICC for a meta-analysis?
Comment: Does the documentation on the package author's website http://www.metafor-project.org/doku.php/analyses:konstantopoulos2011 not answer your question? Search the page for ICC. It even uses the same example as you are using.
Comment: @mdewey Thanks for the information! I knew that website before, but the ICC formula there does not seem to take the total variance into consideration: $Var(y_{ij}) = Var(\alpha_i + \beta_j + \epsilon_{ij}) = \sigma_1^2 + \sigma_2^2+v_{ij}$
Comment: @mdewey Yes, that's something I should look into further. Thanks a lot for the pointer!
Comment: Can you provide some context? Where did the variances come from, and why do you want to average them?
Comment: @`Alecos Papadopoulos` @GeoMatt22 Per your comments, I just added some information to my original question. Thanks!
Comment: Can you pool all the values then calculate the variance from this big pool?
Comment: @SmallChess Unfortunately direct pooling is not an option in this case since it's a meta analysis.
Comment: When you say it is a meta-analysis what exactly are you trying to meta-analyse? Do you have $n$ primary studies each of which gives rise to a variance based on $k$ observations within that study?
Comment: @mdeway I just added a little bit more detail about the meta analysis in the original post.
Comment: @Sycorax I'm familiar with that blog post. However, my specific goal here is to define an index such as ICC based on the "average" sampling variance among the subjects.
Comment: It's not clear to me how the blog post is *not* exactly the answer you need -- sample some variances from the posterior and compute the ICC for each. Then you have a distribution over ICC statistics.
Comment: @MarkWhite The latter: I would like to calculate an ICC after the meta analysis. Since each subject has a variance, the question is: how to "average" those $n$ variances so that I could plug it into the ICC formula?
Answer: Expanding the comments that you got, answer for the question in your title is already given in How to 'sum' a standard deviation? thread, and reads as follows: to get average standard deviation, first take average of variances and then take square root of it.
At face value this approach is valid, but it ignores the hierarchical nature of your data. Similar example is discussed in chapter 5 of Bayesian Data Analysis by Andrew Gelman et al (see also here), who show that it is actually wiser to use hierarchical models that rely on pooled estimates. In your case you have $n \times k$ observations, for $n$ subjects in $k$ treatments and I guess it can be assumed that there is some kind of similarity between results obtained by each subject and between each treatment. This already suggests a hierarchical model with crossed upper-level effects for treatments and for subjects. By using such model you would account for both sources of variation.
Notice that modern formulations of ICC in fact define it in terms of mixed-effects models of the kind as described above, so employing such model solves multiple problems for you and it is often the recommended approach to meta-analysis (but notice that ICC can be misleading).

Regarding your edit, if your model is
$$ y_{ij} = a + \alpha_i + \beta_j + \epsilon_{ij} $$
then $\alpha_i \sim \mathcal{N}(\mu_\alpha, \sigma^2_\alpha)$, $\beta_j \sim \mathcal{N}(\mu_\beta, \sigma^2_\beta)$ and $\epsilon_{ij} \sim \mathcal{N}(0, \sigma^2_\epsilon)$, so your ICC is
$$
\mathrm{ICC}_\alpha = \frac{\sigma_\alpha^2}{\sigma_\alpha^2 + \sigma_\beta^2 + \sigma_\epsilon^2}
$$
The mean of errors does not come into the equation at any point. What comes to the equation is variance of each of the random effects $\alpha,\beta$ and global "noise" $\epsilon$. The idea is to estimate the share of variance taken by $\alpha$, i.e. how much of the total variance does it account for. This is how ICC was defined by its creator Ronald A. Fisher (1966) in Statistical Methods for Research Workers:

(...) the intraclass correlation will be merely the fraction of the total
  variance due to that cause which observations in the same class have
  in common.

So the numerator in the ICC formula is the variance of the effect of interest and the denominator is the total variance. Notice that mean of variances has nothing to do with total variance (sum of variances), so unless I misunderstand something, I can't see why the mean is of your interest in here.
Comment: I really appreciate the answer and all the comments above! I just added another postscript in the original post to further clarify the issue. I have to admit that I'm not so familiar with the Bayesian approach. If the issue can be better characterized under the Bayesian paradigm, please elaborate a little bit more with the example dataset I just presented in the postscript. Thanks!
Comment: @bluepole You do not need a Bayesian model. Traditional mixed-effects model would work just fine. Bayesian models are generally more flexible for such problems.
Comment: So, for the added example dataset in my original post, do you think that the arithmetic mean is reasonable in the context?
Comment: One thing that is misstated in your addendum is that $\epsilon_{ij}$ follows $N(0, \sigma_{ij}^2)$, not $N(0, \sigma_\epsilon^2)$, where $\sigma_{ij}^2$ is known. So, I don't see how your $\sigma_\epsilon^2$ is estimated. And my original question remains.
Comment: In my description I've only mentioned one model with the assumption $\epsilon_{ij} \sim N(0,\sigma_{ij}^2)$, where $\sigma_{ij}^2$ is known. Could you elaborate a little bit more as to how $\sum_i\sigma_{ij}^2/\sum_{ij} \sigma_{ij}^2$ is related to the ICC formula? Thanks!
Comment: What do you mean by "overdisposed"? I've already included some R code in my description to solve the system.
Comment: @bluepole I am afraid I don't fully understand your questions (you actually asked few different ones after the edits). I answered your initial question and the PS. However your PS was not totally clear since, after re-reading it, I don't understand what kind of ICC do you want to estimate. Your PPS makes it even more unclear and needs from your reader to be familiar with metafor package (I am not). Nonetheless, the model you suggest in metafor code seems to be the one that I described. The model specification you describe in your formulas seem to be mixing fixed effects model with distinct ...
Comment: ...variances, with mixed-effects model. The default that you use (struct="CS") estimates model with single variance component (see the docs), i.e. the model that I described. It is not clear however how and why do you want to mix the output from the model with calculated by hand variance component and if/why this should be valid. Nonetheless, the answer still applies to the general questions you asked. As about the edits, it is unclear what (and why) do you mean.
Comment: Thanks for the follow-up! I just added a little bit clarification in the PPS regarding the total variance, and hope that explains a little better about my question.
Comment: @bluepole as I said, I do not fully understand what do you mean by your edit. The model that you describe returns all the variance components that are part of it, so if you include in your calculation some arbitrary, calculated by hard variance component, then you are counting something twice. I can't see why do you want to do your manual calculations. Either you use mixed-effects model and use it's estimates for calculating ICC, or not.

"Averaging" variances


Rails push into array saves object

Question: I have an interesting problem. I'm using Ruby 1.9.2 and Rails 3.1.3.
I have 2 models, for simplification let's say customers and stores.
Stores have many customers, and a customer belongs to a store.
I'm trying to collect all customers for a store, and create a place for a few more that I can populate with values later. Instead, customer.save is called when I don't expect it.
store = Store.find(1)
customers_array = store.customers
random_array = Array.new
customers_count = customers_array.count + 1

(customers_count..2).each do |i|
  customer = Customer.new
  c.id = "#{i}000000000000"
  random_array << customer # this line doesn't call customer.save
  customers_array << customer # this line calls customer.save when store has customers
end

For some reason when the customer is pushed into the array, customer.save is called.
It doesn't happen if you push to an array is a plain array and not a relation.
I found a workaround, but I'm still wondering why that happens.
The workaround:
store = Store.find(1)
initial_customers_array = store.customers
additional_customers_array = Array.new
customers_count = initial_customers_array.count + 1

(customers_count..2).each do |i|
  customer = Customer.new
  c.id = "#{i}000000000000"
  additional_customers_array << customer
end
customers_array = initial_customers_array + additional_customers_array

Comment: For those looking for a solution and not the why: use ```build``` on the collection to create a model without saving it: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Collections
Comment: I had the opposite problem. Using `build` in model specs, then adding items to a collection using << did not work. The answers to this question explain why not.
Answer: << is an alias for push

http://apidock.com/rails/ActiveRecord/Associations/CollectionProxy/%3C%3C
http://apidock.com/rails/ActiveRecord/Associations/CollectionProxy/push

which in the ActiveRecord::Associations::CollectionProxy calls concat

http://apidock.com/rails/ActiveRecord/Associations/CollectionAssociation/concat (view the source of the method)
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/collection_proxy.rb#L283

which calls concat_records

http://apidock.com/rails/v3.2.3/ActiveRecord/Associations/CollectionAssociation/concat_records

where you can see the insert taking place.
So, with an existing record (persisted into the database), running << or .push will insert records into the collection, persisting them to the database if necessary. Calling << on an Array, not the record collection, as you're doing in
random_array << customer

calls Ruby's << Array method, not the AR equivalent (as you found, no save takes place in this case).
Edit: To be clear, the workaround you found is more or less how I typically handle the situation you're dealing with; my answer focuses more on why << has this behavior.
Answer: Another way around this would be to change your second line (of your original code) to:
customers_array = store.customers.to_a

That casts the active record association to a real array object, so the << method will be the normal Array#push method.

Rails push into array saves object


How prove this diophantine equation $(x^2-y)(y^2-x)=(x+y)^2$ have only three integer solution?

Question: HAPPY NEW YEAR To Everyone! (Now Beijing time  00:00 (2015))

Let $x,y$ are integer numbers,and such $xy\neq 0$,
Find this diophantine equation all solution
$$(x^2-y)(y^2-x)=(x+y)^2$$

I use Wolf found this equation only have two  nonzero integer solution $(x,y)=(-1,1),(-1,-1)$,see wolf
$$\Longleftrightarrow x^3+y^3+x^2+y^2=xy(xy-1)$$
But How prove it?
and I found sometimes,and my problem almost similar with 2012 IMO shortlist:2012 IMO shortlist
Comment: What about $(x,y)=(3,3)$?
Comment: The equation in the title is different from the one in the post. Which one do you mean?
Comment: Oh,Sorry,I havd edit it
Comment: Let $P=xy,S=x+y$, then your equation is $P^2+P(1+3S)-S^2-S^3=0$, a quadratic whose discriminant is $1+6S+13S^2+4S^3$
Comment: if we say $1+6S+13S^2+4S^3$ is square numbers,But then maybe is ugly?
Comment: Yes, I think so.
Comment: At least, $S>-3$.
Comment: Yes.Nilan give it.Thank you Jack,Happy New year
Comment: @chinamath Happy New Year
Comment: Some more factorisations, not sure if useful: $(x+y)(x^2-xy+y^2+x+y)=xy(xy+1)$ and $(x+y+1)(x^2+y^2+1-x-y-xy)=(xy-1)^2-(x+y)^2$. Also, $(x+y+1)(x^2+y^2)=xy(xy+x+y-1)$.
Answer: (Apologies for the rather long solution.)

Write $x = ka$, $y = kb$, with $a, b$ relatively prime.
The equation $(x^2 - y)(y^2 - x) = (x + y)^2$ becomes
$$
\newcommand{\divs}{\; \mid \;}
(ka^2 - b)(kb^2 - a) = (a + b)^2 \tag{1}
$$
Or, rearranged,
$$
(ka + 1)(k b + 1) ab = (a + b)(kb^2 + b + ka^2 + a) \tag{2}
$$
Taking (2) modulo $a$, we get $kb^3 + b^2 \equiv 0$, and
dividing by $b^2$ (which is a unit mod $a$) we get $kb + 1 \equiv 0$.
So $a \divs kb + 1$ and likewise $b \divs ka + 1$.
Let $c = \text{gcd}(ka + 1, kb + 1)$,
$ka + 1 = bcA$, $kb + 1 = acB$ for relatively prime integers $A, B$.
Rewrite (2) as
$$
(bcA)(acB) ab = (a + b)(abcB + abcA)
$$
i.e.
$$
abc A B = (a + b)(A + B). \tag{3}
$$
Since $a$ and $b$ are relatively prime to $a + b$,
$$
ab \divs A + B \tag{4}
$$
Since $A$ and $B$ are relatively prime to $A + B$,
$$
AB \divs a + b \tag{5}
$$
Recall the following integer properties:

If $m \divs n$, then $|m| \le |n|$ OR $n = 0$.
$|m + n| \le |mn| + 1$ for all $m,n \ne 0$.
(Follows from triangle inequality and $(|m| - 1)(|n| - 1) \ge 0$.)

From these and (4), (5) we get that
$$
|a + b| \le |ab| + 1 \le |A + B| + 1 \le |AB| + 2 \le |a + b| + 2
$$
unless $A + B = 0$ or $a + b = 0$ or one of $A, B, a, b$ is $0$.
Case 1: $\boldsymbol{A + B = 0}$
Since $A$ and $B$ are relatively prime, we conclude WLOG $A = 1$, $B = -1$.
From (3), $abc = 0$.
But $a, b \ne 0$, so $c = 0$.
So $ka + 1 = kb + 1 = 0$.
So $x = ka = -1$ and $y = kb = -1$,
and in this case we get the solution $(x,y) = \boxed{(-1, -1)}$.
Case 2: $\boldsymbol{a + b = 0}$
Since $a$ and $b$ are relatively prime, we conclude WLOG $a = 1$, $b = -1$.
From (1),
$(k - 1)(k + 1) = 0$,
so either $k = 1$ or $k = -1$,
giving the solutions $(x,y) = (ka, kb) = (k, -k) = \boxed{(1, -1), (-1, 1)}$.
Case 3: $\boldsymbol{abAB = 0}$
From (3) this case implies $0 = (a + b)(A + B)$,
so this case is encompassed in the first two.
Case 4: $\boldsymbol{|a + b| \le |ab| + 1 \le |A + B| + 1 \le |AB| + 2 \le |a + b| + 2}$
From the inequality, we conclude that
$$
|a + b| \le |a| + |b| \le |ab| + 1 \le |a + b| + 2 \le |a| + |b| + 2
$$
Therefore,
$$
|ab| + 1 = |a| + |b| + r
$$
where $r \in \{0, 1, 2\}$.
In particular,
$$
(|a| - 1)(|b| - 1) \in \{0, 1, 2\}
$$
We know $a, b \ne 0$.
The first subcase is if $|a| = 1$ or $|b| = 1$ (WLOG $|a| = 1$).
Otherwise, $(|a|, |b|) = (2, 2), (2, 3), \text{ or } (3, 2)$,
Since $a$ and $b$ are relatively prime,
the first of these is impossible.
Otherwise we may assume $|a| = 2$.
By flipping the sign of $k$, we may assume $a$ is positive.
So we are left with three subcases: $a = 2$ and $b = 3$,
or $a = 2$ and $b = -3$, or $a = 1$.

(Case 4a) $a = 2$, $b = 3$

(1) gives
$(4k - 3)(9k - 2) = 25$,
which has no rational solutions.

(Case 4b) $a = 2$, $b = -3$

(1) gives
$(4k + 4)(9k - 2) = 1$,
which has no rational solutions.

(Case 4c) $a = 1$

From (4), $b \divs A + B$.
By the inequality we are still assuming,
$|A + B| + 1 =$ $|a + b|$, $|a + b| + 1$, or $|a + b| + 2$.
This implies $A + B = \pm(a + b)$
or $A + B \in \pm(a + b) \pm 1$.
With $a = 1$, we have
$A + B = b + 1, -b - 1, b + 2, b, - b, -b - 2$.
(Case 4c-i)
If $A + B = b + 1$ or $-b - 1$, then from (4) $b \divs A + B$ so $b = \pm 1$.
$a = 1$ and $b = -1$ implies $a + b = 0$, which we have already covered.
So $a = b = 1$.
Then (2) gives $(k + 1)^2 = 2(2k + 2)$,
so $k = -1$ or $k = 3$.
If $k = -1$ then $(x,y) = (-1, -1)$ which we already found.
If $k = 3$ then we have the solution $(x,y) = \boxed{(3,3)}$.
(Case 4c-ii)
If $A + B = b + 2$ or $-b - 2$, then from (4) $b \divs A + B$ so $b \divs 2$.
$b = \pm 1$ is covered in case 4c-i.
So assume $b = \pm 2$.
Then $A + B = 0$ or $\pm 4$.
If $A + B = 0$ this is covered by Case 1.
So assume $|A + B| = 4$.
Rewriting the inequality assumed in Case 4,
$$
|b + 1| \le |b| + 1 \le |A + B| + 1 \le |AB| + 2 \le |b + 1| + 2
$$
The middle term is $|A + B| + 1 = 5$, so $5 \le |b + 1| + 2$,
so $b = 2$.
Returning to (1), we get
$$
(k - 2)(4k - 1) = 9
$$
so $4k^2 - 9k - 7 = 0$,
which has no integer solutions.
(Case 4c-iii)
If $A + B = b$ or $-b$,
then write
$A + B = \frac{ka+1}{bc} + \frac{kb+1}{ac}$
so that $ka^2 + a + kb^2 + b = abc(A + B) = \pm b^2 c$.
Then from (2) we get
$$
(k + 1)(bk + 1) = \pm (b + 1) b^2 c
$$
Since no factors of $b$ are shared by $bk + 1$, $b^2 \divs k+1$.
But we also have $k + 1 + kb^2 + b = \pm b^2 c$,
implying $b^2 \divs  b$.
Since $b \ne 0$, $b \in \{-1, 1\}$.
So $(a,b)$ is one of $(1, -1)$ or $(1, 1)$.
But $(a,b) = (1, -1)$ satisfies $a + b = 0$, so was covered by Case 2.
And $(a,b) = (1,1)$ was covered in Case 4c-i.
Answer: Please don't vote. Just a pictural comment to show what
the curve $(x^2-y)(y^2-x)-(x+y)^2=0$ does look like ( : it's an "elbow" ) .

$\color{red}{Red}$ is positive, $\color{green}{green}$ is negative.
The integer coordinates are yellow lines.
Picture on the right is $\color{blue}{blue}$ rectangle in picture on the left zoomed in $20 \times$ .
Comment: I wouldn't call it "an elbow".
Comment: @VividD: How would you call it then?
Comment: It depends what is around that area! BTW, why don't you zoom out the picture lets say 100 or even 1000 times? I think it will be informative.
Comment: My impression is that the key is not in the small area where all solutions are, but why there is no solution othewise - so I would like really to see how the green area extends for larger x and y. Is there a red island maybe (its "tip" would be point (3,3)?
Comment: I think it would rather be a green lake than red island!
Comment: No, I was wrong, there is neither lake nor island.
Comment: @VividD: Update upon request: picture on the left zoomed out $20 \times$ .
Comment: Miraculous how such a curve can go through infinite outer space
$(|x|,|y|) > (5,5)$ without ever hitting an integer coordinate pair ..
Answer: This is a partial solution. But this shows, we can obtain more solutions than which are given. Suppose $x=y,$ then $$(x^2-x)^2=4x^2$$ has three solutions namely,$$x=y=0, -1, 3.$$ Now suppose $x>y>0,$ if $y=1$ then $$(x^2-1)(1-x^2)=(x+1)^2$$ which has only solution $x=-1.$
Comment: Hello,But other case? $y>1?$
Answer: On the LHS the sum of the two factors is nonnegative, so $x^2-y$ and $y^2-x$ cannot be negative at the same time. Hence, if $x+y\ne0$ then both $x^2-y$ and $y^2-x$ must be positive.
If $y^2-x\ge8$ and $x^2-y\ge8$ then
$$
(x+y)^2 = (x^2-y)(y^2-x) = \\
= \frac{x^2-y}2(y^2-x) +\frac{y^2-x}2(x^2-y) +0 \ge \\
\ge
4(y^2-x) +4(x^2-y) -2(x-y)^2 = \\
= 2(x+y)^2 - 4(x+y); \\
0\le x+y \le 4.
$$
Therefore, all solutions satisfy $0\le x+y\le4$, $1\le x^2-y\le 7$ or $1\le y^2-x\le 7$.
It is a few simple cases and they all lead to finding the integer roots of certain polynomials with integer coefficients.
Comment: The integer part starts when you solve the cases $x+y=0$, $x+y=1$, ..., $x^2-y=1$, ... $x^2-y=7$ for integers.
Comment: The form of this argument is applicable to any _real_ valued $(x,y)$ ; if so then it cannot be true. Where is the specific integer part ?
Comment: @HandeBruijn No, I think the idea of this is valid.  You will see in my solution as well that a lot of cases amount to seeing if quadratic polynomials have integer coefficients.
Answer: Note that your equation is basically
$$-(x^2-y)^2 = (x+y)^2$$
Comment: This is for the equation in the title, but not the equation in the post. Hopefully the OP will clarify which one they intended to ask about.
Comment: Hello,I have edit it,then My problem not this.
Answer: $$
\begin{array}{l}
 \left( {x^2  - y} \right)\left( {y^2  - x} \right) = \left( {x + y} \right)^2  \\
  \Leftrightarrow xy\left( {xy - 1} \right) = x^3  + y^3  + x^2  + y^2  \\
  \Leftrightarrow xy\left( {xy - 1} \right) = x^2 \left( {1 + x} \right) + y^2 \left( {1 + y} \right) \cdots \left(  *  \right) \\
 \left\{ \begin{array}{l}
 x = y \\
 \left(  *  \right) \Leftrightarrow x^2  - 1 = 2x\left( {1 + x} \right) \\
 \left(  *  \right) \Leftrightarrow \left( {1 + x} \right)^2  = 0 \\
 \left(  *  \right) \Leftrightarrow \left( {x;y} \right) \in \left\{ {\left( { - 1; - 1} \right)} \right\} \\
 \end{array} \right.;\left\{ \begin{array}{l}
 x =  - y \\
 \left(  *  \right) \Leftrightarrow x^2  + 1 = 2x^2  \\
 \left(  *  \right) \Leftrightarrow \left( {x;y} \right) \in \left\{ {\left( {1; - 1} \right);\left( { - 1;1} \right)} \right\} \\
 \end{array} \right. \\
 \end{array}$$
Comment: In the left bracket, 2nd line, RHS there is a factor $x$ too much: it should be $2(1+x)$.
Comment: I think have other many case except $x=y$ or$-y$


Why is this binary relation symmetric but not reflexive or transitive

Question:
Let $\def\Rthree{\,{\mathrm{R}_3}\,} \Rthree$ be the relation on sets $C$, $D$ of natural numbers such that $C \Rthree D$ iff $C \cap D$ is finite. Then $\Rthree$ is symmetric, but not reflexive or transitive.

I don't understand any of the 3. The example for why it was not reflexive was

$\Bbb{N} \Rthree \Bbb{N}$ is not true

If that's the case can't I say that because $\Bbb{C} \Rthree \Bbb{N}$ isn't true, it isn't symmetric either? Why is it symmetric?
I would appreciate insight onto why it's not transitive as well. Thank you.
Answer: First of all, the relation only applies to natural numbers, so $\mathbb C R_3\mathbb N$ doesn't mean any thing. Even so, the symmetric property states:

If $A\, R\, B$, then $B\, R\, A$.

If $A\,\not R\, B$, then the property doesn't apply (we might say it is vacuously satisfied). Symmetry is true for this realtion because if $A\cap B$ is finite, then $B\cap A$ is finite. Again, if $A\cap B$ is not finite, then symmetry doesn't apply, so we don't even worry about $B\cap A$.
Comment: It doesn't have to apply to only natural numbers, but you said that we are limited to sets of natural numbers for this particular case in the first sentence of your question. It's important to know the domain you are working with because a relation may have some properties in one domain, but lose those properties in a larger domain. For example, this relation is an equivalence relation if we limit ourselves to finite sets.
Comment: Hmm, could you elaborate on why this relation only applies to natural numbers? Sorry, I'm new to this type of math.
Comment: Wow! Thank you. I read it (and copied it) but never really _read_ it.
Answer: Remember the definition of a relation on $\Bbb N$:
$R$ is a relation on the power set of $\Bbb N$ $\mathscr{P}(\Bbb N)$ (the set of all subsets of $\Bbb N$) if it is a subset of $\mathscr{P}(\Bbb N) \times \mathscr{P}(\Bbb N)$.
This means that for every pair $(A,B) \in R$ we have $A \subseteq \Bbb N$ and $B \subseteq \Bbb N$. We are really only talking about subsets of $\Bbb N$.
Alex S addressed the symmetry, so I will talk about the reflexivity and the transitivity.
$R$ is not reflexive because there exists $A \subseteq \Bbb N$ such that $A \not R_3 A$, or such that $A \cap A$ is infinite. For a counterexample you can take any infinite subset of $\Bbb N$ (even $\Bbb N$ itself, as you wrote).
$R$ is not transitive, because we can find subsets of $\Bbb N$ $A,B$ and $C$ such that $A \ R_3 \ B$ and $B \ R_3 \ C$, but $A \not R_3 C$. For a counterexample, try to find two infinite sets $A,C$ whose intersection is infinite, and let $B$ be any finite set.
Comment: Thank you for the super clear answer. For transitive, would the following be valid:
A={ a is odd}, B = { b < 50}, C = {c is even}?
Comment: Another question, Alex S stated for his answer that when $A \not R A$, the property doesn't apply so it's vacuously true. When $ \mathbb N \not R \mathbb N$, why isn't that also vacuously true?
Comment: We say that the implication $P \implies Q$ is true vacuously if the hypothesis, $P$, is always false; the implication that needs to be satisfied for symmetry is $A \ R_3 \  B \implies B \  R_3 \ A$ for any $A,B \subseteq \Bbb N$. The hypothesis here is $A  \ R_3 \ B$, and if two sets $A,B$ fail to satisfy it, the whole *implication* is vacuously true. Reflexivity isn't really given in terms of an implication, but rather in terms of a statement with a universal quantifier: "for *all* $A \subseteq \Bbb N$ we have $A \ R_3 \ A$". (cont.)
Comment: And the negation of this reflexivity statement is "*there exists* some $A \subseteq \Bbb N$ such that $A \not R_3 A$. So showing that $\Bbb N \not R_3 \Bbb N$ shows that the negation of the statement is true, meaning the statement is false. Does this make sense?
Comment: Yes, it does. Thank you.
Comment: @wcarvalho I missed the edit on your first comment; the example almost works but doesn't because $A \cap C = \varnothing$. Try this: take $A,B$ as you wrote them, and take $C = \Bbb N$.
Comment: Ahh thank you. I misread it as a union not an intersection.
Answer: As an intuition, the relation is similar to saying "not equal" or "disjoint", so it is almost the opposite of an equivalence relation.  It is the relation of disjointness on sets of integers modulo finite sets (where we regard two sets as equivalent if they differ on only a finite number of elements).


Reordenar AUTO_INCREMENT de forma correta

Question: Oi,
Preciso reordenar o campo AUTO_INCREMENT no MySql para que fique na sequencia correta. Pesquisando, eu consegui faze-lo mas quando insiro um novo registro, ele fica com o Id continuado da ordem anterior. Exemplos:
ANTES
Id's: 1, 2, 4, 5, 7...
REORDENADO
Id's: 1, 2, 3, 4, 5...
APÓS NOVO REGISTRO
Id's: 1, 2, 3, 4, 5, 8.
Como faço para reordenar e continuar corretamente?
Comment: por que não cria uma coluna `codigo` pra controlar isso?
Comment: Como seria a correção no caso de desordem?
Comment: se você não tem um campo que consegue ordenar, tipo data de cadastro ou código, acredito que terá que fazer manual mesmo..
Answer: Fala amigo, tente editar o código do registro de 8 para 6 e depois rode este comando:
ALTER TABLE  AUTO_INCREMENT = 1


Connectedness of factors of connected product space

Question: If $A\times B$ is connected, why does it immediately follow that $A$ and $B$ are connected as well?
I know that all functions $A\times B\rightarrow \{0,1\}$ are constant, but how would I prove that all $A\rightarrow \{0,1\}$ and $ B\rightarrow \{0,1\}$ are also constant?
Comment: Why the downvot please?
Answer: You mean that all continuous functions on $A \times B$ are constant.
The projection map $\pi : A \times B \to A$ given by $\pi(a,b) = a$ is continouous. So if $f : A \to \{0,1\}$ is continuous, so is $f \circ \pi : A \times B \to \{0,1\}$. So it's constant, and then $f$ is constant as well because $\pi$ is surjective.


Different characterizations of Liouville numbers

Question: Usually, Liouville numbers are defined as follows:
$x$ is Liouville if for ever $i\in\mathbb N$ there exist $n,m\in\mathbb Z$ such that
\begin{equation}
\left|x-\frac nm\right|<\frac1{m^i}.
\end{equation}
In their 1982 paper on almost-periodic Schrödinger operators, however, Avron and Simon use the following definition:
$x$ is Liouville if for ever $i\in\mathbb N$ there exist $n,m\in\mathbb Z$ such that
\begin{equation}
\left|x-\frac nm\right|<\frac1{i^m}.
\end{equation}
Do these sets of numbers agree? If yes, how can one show that?
Answer: This seems to be a long-time misuse of terminology. The second definition is not of a Liouville number, it is much stronger. Liouville number is a number which can be approximated by rationals at any power rate. The second definition assumes that a number can be approximated at any exponential rate.
Comment: Thanks for your answer...yet both sets are of measure 0 and dense $G_\delta$...
Why do Avron and Simon coin them Liouville numbers, then?
Comment: As I said, seems to be some old misuse of terminology. I was not able to  trace it to the origin, which may well be Avron and Simon's paper.
Comment: Ok thanks! I also couldnt find any other source for that (and obviously the monograph by Cycon, Froese, Kirsch and Simon). They need the second bound, though, to apply Gordon's theorem...


Não consigo diminuir o tamanho de componentes .form-control

Question: Olá,
Eu estou tentando diminuir o tamanho de componentes que usam a classe .form-control do bootstrap 3 mas quando tento setar o width dos componentes para o valor "auto" ele gera uns espaçamentos entre os componentes que eu não consigo identificar analisando o código HTML.
Esse é o problema que eu quero resolver, diminuir o tamanho dos últimos 3 select's para "auto"

Código HTML da interface acima:

  <input id="search" name="searchValue.$" type="text" class="form-control"/>

  <select class="form-control">
   <option>2019</option>
   <option>2018</option>
   <option>2017</option>
   <option>2016</option>
   <option>2015</option>
  </select>

  <select class="form-control">
   <option>2019</option>
   <option>2018</option>
   <option>2017</option>
   <option>2016</option>
   <option>2015</option>
  </select>

  <select class="form-control">
   <option>Tudo</option>
   <option>Função</option>
   <option>Tipo de Sistema</option>
   <option>Sistema</option>
   <option>Veículo</option>
  </select>

Mas quando tento setar o width para "auto" me acontece isso:
Os select's ficam separados por espaçamento que eu não consigo identificar analisando o código HTML.

Código da interface acima:

  <input id="search" name="searchValue.$" type="text" class="form-control"/>

  <select class="form-control" style="width: auto;">
   <option>2019</option>
   <option>2018</option>
   <option>2017</option>
   <option>2016</option>
   <option>2015</option>
  </select>

  <select class="form-control" style="width: auto;">
   <option>2019</option>
   <option>2018</option>
   <option>2017</option>
   <option>2016</option>
   <option>2015</option>
  </select>

  <select class="form-control" style="width: auto;">
   <option>Tudo</option>
   <option>Função</option>
   <option>Tipo de Sistema</option>
   <option>Sistema</option>
   <option>Veículo</option>
  </select>

O que está gerando esse espaçamento entre os componentes?
PS: Estou usando Bootstrap 3 e AngularJS.
Answer: Como vc está usando Bootstrap 3 uma das opções para corrigir isso é colocando float:left nos elementos do form. Mas depois disso vc vai precisar fazer o tratamento responsivo para ajusta-los quando a tela for pequena, se é que vc vai usar esse form em telas mobile por exemplo...
Segue o exemplo

<link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />

               <input id="search" name="searchValue.$" type="text" class="form-control" style="width: auto; float: left;"/>

               <select class="form-control" style="width: auto; float: left;">
                  <option>2019</option>
                  <option>2018</option>
                  <option>2017</option>
                  <option>2016</option>
                  <option>2015</option>
               </select>

               <select class="form-control" style="width: auto; float: left;">
                  <option>2019</option>
                  <option>2018</option>
                  <option>2017</option>
                  <option>2016</option>
                  <option>2015</option>
               </select>

               <select class="form-control" style="width: auto; float: left;">
                  <option>Tudo</option>
                  <option>Função</option>
                  <option>Tipo de Sistema</option>
                  <option>Sistema</option>
                  <option>Veículo</option>
               </select>


Event "After cloning a node" by node clone module is not working

Question: I am trying to use the event "After cloning a node" provided by Node clone module for Rules integration but its not working.Do any one came across this issue before?
I have created the issue as a bug in issue queue of node clone module.
Any pointers on this?
Comment: two years later and the bug is still there :-) Did you find a combination of action/conditions for a replacment of this event?
Answer: Your issue seems to be confirmed by some other users also now.
Comment #9 of that issue contains a patch that might possibly solve it.
Another possible solution (patch) is included in comment #8 of that issue, proposed by the module maintainer. With a comment like "Not sure about the use case ..."
The issue is currently in status "Needs review", so maybe you might (still) have an appropriate use case to get that issue in RTBC status?
Comment: Thanks Pierre for the update, I stopped following the thread, will give a try sometime!


How to Reference Bootstrap-Colorpicker in ASP Net 5 View

Question: I'm working through the ASP.NET MVC 6 tutorials and getting used to the framework. I have a requirement to add a color picker to one of my views. Since the HTML5 type 'color' isn't supported on IE I can't use that.
Instead I thought I'd use the bootstrap-colorpicker plugin here: http://mjolnic.com/bootstrap-colorpicker/.
I've installed the package via NPM but can't work out how to reference it in the View. Should the package be installing files in the wwwroot\libs folder? Or do I need to copy these in manually and reference in the @section Scripts?
I've also installed it using NuGet PM and it appears under References but I'm in the same boat wondering how to reference it in the actual View.
Comment: drag the `js` and `css` file to your view.
Comment: Where from? I can't see the file anywhere in the `wwwroot`. My source files have a 'node_modules' folder (which contains the colorpicker) but I can't see how this is accessed in Visual Studio.
Comment: Check [this blog post](http://www.mikesdotnetting.com/article/283/asp-net-5-managing-client-side-dependencies-with-npm-bower-and-gulp), hopefully it will help you to find your installed package.
Comment: is there any folder created inside `www\lib` after you have added those libraries.
Comment: No there isn't - But following the blog @Michael suggested I can view all files and see the node_modules in the solution explorer. I can then drag a link onto the View resulting in: ``.
Comment: that's what you need to do . Now It should work.
Answer: The installation with NuGet PM creates following folder structure:
/Content
    /bootstrap-colorpicker
        /css
            /bootstrap-colorpicker.css
        /img
            /*.png
/Scripts
    /bootstrap-colorpicker.js

So you have to add following lines to BundleConfig:
bundles.Add(New ScriptBundle("~/bundles/colorscripts").Include(
    "~/Scripts/bootstrap-colorpicker.js")
bundles.Add(New StyleBundle("~/Content/bootstrap-colorpicker/bootstrap-colorpicker/colorstyle").Include(
    "~/Content/bootstrap-colorpicker/css/bootstrap-colorpicker.css"))

Then reference the bundles in the Razor view:
@section SiteCSS
    @Styles.Render("~/Content/bootstrap-colorpicker/bootstrap-colorpicker/colorstyle")
End Section

@section Scripts
    @Scripts.Render("~/bundles/colorscripts")
End Section

BTW: The additional "bootstrap-colorpicker" folder for the style bundle is necessary for the optimizer. Otherwise you get a 404 (see here, here and here).


Multisite, shared users, own databases, own files, how to deal with profile picture?

Question: I'm in the middle of implementing a multisite setup. Each site will have it's own database, and files directory, but they will share the user table from the default database.
Because the profile picture field in the user table is set to a fid, am I right in thinking this will break a user picture if they look at their profile on a different site?
fid 26 might be their picture on the main site, but fid 26 in another site might be for a completely different image, or not even an image at all.
How do you normally address this issue?
Cheers
Answer: You need a single sign on approach.
You could implement your own approach just like this one https://drupal.org/node/1043724 or try to find some contribute module to handle it.
Hope this help.
Regards
Comment: Hi Enxebre. I have this part of it setup, so getting sso working and sharing users isn't the issue. What I'm struggling to understand is how the profile picture, or avatar will work across each of the sites. the single user table shared amongst each site is set with a fid, but because each site manages it's own files folder, and has it's own file_managed table, a fid from site 1 would point to a different file on site 2 etc.


Views: group by content type in an arbitrary order

Question: Note: I spend a lot of time in this question explaining, what I've been trying to do, but the end goal is to be able to sort by content type in an arbitrary order.  I'm then grouping on content type, and getting headings in my results as desired.  If you can show me how to do it without hook_views_query_alter() I'd be just as happy, though why my solution isn't working is giving me an ulcer.  I'd prefer to avoid creating a whole bunch of attachments since I'm dealing with about 20 types here, but I think that is the next thing I'll have to try if nobody can help me.

A few other answers here, have gotten me to where I feel I'm close, but I'm getting not results, hopefully someone here can see what I'm doing wrong.
My actual setup is more complex than this.  Basically I have a variable in settings that gives me some details about the different content types I'm dealing with, including a weight value for each.  I'm building my order by clause using those weight values, but that doesn't seem to be the problem, so here is the query taken to it's simplest form:
Given a view that loads a set of nodes of at least two different types, one of which (for the purposes of this function has a machine name of 'brief' and a human readable name of Briefs):
<code>/**
 * Implements hook_views_query_alter().
 */
function MYMODULE_views_query_alter(&$view, &$query) {

    if ($view->name == "view_name" && $view->current_display == "display_block_name") {

        $caseclause = 'CASE node_type WHEN "brief" THEN 1 ELSE 2 END';
        array_unshift($view->query->orderby, array(
            'field' => $caseclause,
            'direction' => 'ASC'));
    }
}
</code>
I would expect this to give me the node listing with Briefs listed first, and other types listed afterward.  Instead I get no results.  If I remove the alteration to $view->query->orderby I get results.  I've tried checking for "Briefs" instead of "brief".  I got the column name, by adding it as a sort in the view and seeing what the view itself used, but just in case I've also tried node.type and type as the column name to put in the case statement.  I tried doing all of this with the $query object too, just in case.
I tried adding the CASE clause as $query->addExpression, setting an alias of order_col for the expression, intending to then order by that column, but the whole page stopped showing up.  It is possible I did something wrong on that attempt, if you can make that work, please let  me know.
So here's what I need:  How can I make a CASE statement work in hook_views_query_alter(), or failing that, how can I sort content type by an arbitrary order?
Here's a really brief section of the configuration variable that I have in settings.php that I'm trying to get the weight value from to do my sort.
<code>$conf['pubtype_bundles'] = array(
    'brief' => array(
        'name' => 'Briefs',
        'weight' => 5,
        'description' => 'Issue Briefs, Policy Briefs, and Briefing Notes',
        'help' => '',
        'types' => array(
            'issue' => 'Issue Brief',
            'policy' => 'Policy Brief',
            'briefing' => 'Briefing Note',
        ),
        'typehelp' => '',
    ),
    'book' => array(
        'name' => 'Books',
        'weight' => 10,
        'description' => '',
        'help' => '',
        'types' => array(
            'book' => 'Book',
        ),
        'typehelp' => '',
    ),
);
</code>
Answer: When you want to do arbitrary sort, U must be having your own sorting routine/algo/criteria?
When you have that then you can add a "global php" field in sort criteria and then u can use a setup code(if required) and then you can write your sorting logic in "sort code".
Comment: I'll add a brief sample of what I'm working with in the question.  I really just need a simple numerical sort, the issue is that there is no where to provide those numbers.  It looks like your solution must be using php views or something?
Comment: Yup my solution is using [php views](https://www.drupal.org/project/views_php) and u can get the numerical sort done in the global php
Comment: This is the best answer so far.  I've ended up just making a bunch of attachments and adding them to views in the right order, which will be a giant PITA if the order needs to change.  I'd really like to know why my CASE solution doesn't work, I've seen others, including someone on the documentation page for the hook claiming that it should.
Answer: Though I am not very clear with this

Basically I have a variable in settings that gives me some details
  about the different content types

What I understood is, you have a settings defined somewhere which has weight and content type relation. Based on this one solution can be:

Create a weight field / setting (assuming there is no configuration for it) in content types, and populate the weight from your settings.
Use this weight field to sort nodes in views.
Comment: Thank you. The problem with this approach is that the only way I can see to do that is to create an admin only weight field in each content type's fields with a default value. In the larger scheme it is minimal, but that is a lot of unnecessary duplication. Additionally: when I decide I want one type to move up, I need to somehow go update every single node of all content types whose weight has changed.
Comment: Yes, duplication will be a problem. You may also try using this module - https://www.drupal.org/project/vvf, It allows you to use variables in views. Or  If it doesn't work, I think you will have to create views handler relations.
Comment: I'm trying to figure out how this would help me, but I'm not quite seeing it.  Does it integrate with tokens?  If I could have variables set for type_book_weight and type_brief_weight, etc and then load the appropriate variable based on the type, then I could see where that would be workable, assuming it is available to the filters and not just to the fields.
By the way, I updated my question to clarify the part that was unclear.


Finding coordinates for 3rd point in isosceles right triangle, knowing 2 other points and lengths of sides

Question: I have the following triangle

The length of AB, AC, AC', BC and BC' are known and AB = AC = AC', BC = BC'.
Coordinates of A and B are known.
What is a fast way of finding coordinates for C and C'?
I've tried using the distance formula for AB and AC and tried to get the coordinates from the resulting equation system, but I think I messed up somewhere because the C coordinates were off. Tested with A(1, 0) and B(5, 1) and I got C' y coordinate at 3.05 and that didn't add up.
I'm looking for a general formula if there is one, not one just for the set of points I mentioned above. Haven't tried any trigonometry formulas for this because I didn't know which one to use.
Comment: If A is $z_1$, B is $z_2$, C is $z_3$ and C' is $z_4$ then it immediately follows that $z_3=z_1+i(z_2-z_1)$ and $z_4=2z_1-z_3$. ($z$ represents a complex number). You can use these results to directly get a cartesian equivalent.
Answer: From $A$ and $B$ coordinates you can compute vector $B-A=(x,y)$. Then:
$$
C-A=(-y,x),\quad C'-A=(y,-x),
$$
because they are rotated 90° with respect to $B-A$.
Add these to $A$ and you're done.
Answer: You have the points $a, b$ and thus the vectors to these points that are just their coordinates
$$\overrightarrow{a}=(a_x ~a_y)^T, \overrightarrow{b}=(b_x ~b_y)^T$$
You can establish a vector going from $a$ to $b$, by subtracting them:
$$\overrightarrow{ab}= \overrightarrow{b} -  \overrightarrow{a}$$
To rotate a vector $(x~y)^T$ by some angle $\alpha$, multiply it with a matrix like so:
$$
\left(
\begin{matrix}
x_{new}\\
y_{new}
\end{matrix}
\right)
=
\left(
\begin{matrix}
\cos \alpha & -\sin \alpha\\
\sin \alpha &\cos \alpha
\end{matrix}
\right)
\left(
\begin{matrix}
x\\
y
\end{matrix}
\right)
$$
Let $\overrightarrow{ab}$ start from $a$ and go to $b$, now rotate the vector counterclockwise 90° and it will go from $a$ to $c$. Counterclockwise rotation is usually defined as positive. The matrix is very easy, because of the 90°:
$$
\overrightarrow{ac}
=
\left(
\begin{matrix}
0 & -1\\
1 & 0
\end{matrix}
\right)
\overrightarrow{ab}
$$
Then you can find $c$ via $a$
$$\overrightarrow{c} = \overrightarrow{a} + \overrightarrow{ac}$$
You could rotate the other way around to find $c'$, but because it is exactly the opposite direction, you can as easily negate the direction vector
$$\overrightarrow{c'} = \overrightarrow{a} - \overrightarrow{ac}$$


configure: error: xml2-config not found. Please check your libxml2 installation

Question: I am trying to install php5 to my fedora 14. But when I ./configure the error shows configure: error: xml2-config not found. Please check your libxml2 installation.. I installed libxml2 and when I run yum install libxml2 it says Package libxml2-2.7.7-3.fc14.i686 already installed and latest version
Nothing to do
. What is happening
Answer: You should install devel package.
Comment: It's `libxml2-devel`. Also if you are unsure about a name again search for it: `yum search libxml2`
Comment: I also run `yum install libxml2-dev` and it says `No package libxml2-dev available.
Error: Nothing to do
`!!
Comment: Can you post the output of yum search libxml2 ? Does yum install libxml2-devel works better?
Comment: Thanks faker. It was `libxml2-devel`.


Need help configuring NAT

Question: First of all, the router I am using is a Cisco WRVS4400N.
My company runs a software which handles the MySQL database of all of their products.
The software now has an e-commerce module, so I have to set up a secure tunnel from our
network to the server that will be hosting our e-commerce site so that when the database is updated, the site will also be updated.
The technician completeing the job said there is an IP conflict, and has asked me to NAT 192.168.0.0/24 to 192.168.115.0/24.
I am not really sure how to do this, and they want to charge $150 an hour to do it for me.  Can anyone help?
Comment: I would suggest to [have a look at the doc](http://www.cisco.com/c/dam/en/us/td/docs/routers/csbr/wrvs4400n/administration/guide/WRVS4400N_AG_OL-20048.pdf)
Comment: I read the docs but I'm not really sure what I am looking for, what should I be searching for?
Comment: You should search for NAT
Answer: QuinnFTW,
The technician with the NAT request needs to be more clear on what exactly needs to be done. From what I read in your question that does not sound like a proper NAT. Are these networks completely separate from each other? When you mentioned "secure tunnel" the first thing that came to mind was a site-to-site vpn tunnel which is completely different.
From a firewall perspective (assuming this is a static NAT rule we are talking about) there is a source (inside private address) and an public IP that is configured to use the "outside" interface. I have about 20 or so statics on my Cisco ASA so your mileage may vary.
In reference to the guide krisFR linked to I believe page 100 is what you might be looking for.
Good luck
Comment: The networks are completely separate.  I think the idea is that my server will trigger the event which causes the sync, so my firewall can remain closed while the other end is open.  I will look at what you suggested, thanks.

Need help configuring NAT


How to pass a string as a parameter of query

Question: I have a variable Name, that is going to receive a value from cmd/terminal, and I'm trying to pass this variable as a parameter to a query command.
I've already tried these:
'"+Name+"', :Name, @Name, +Name, DESCRIBE, #define @Name, Values(%s),Name),...
C code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <my_global.h>
#include <mysql.h>

void finish_with_error(MYSQL *con)
{
  fprintf(stderr, "%s\n", mysql_error(con));
  mysql_close(con);
  exit(1);
}
int main()
{
    printf("Enter a name ");

    int n = 0;
    char c;

    char *Name = NULL;

    do
    {
        Name = (char*)realloc(Name, (++n) * sizeof(char));
        Name[n-1] = (c = getchar()) == '\n' ? '\0' : c;

    }while(c != '\n');

    MYSQL *con = mysql_init(NULL);

    if (con == NULL)
    {
        fprintf(stderr, "%s\n", mysql_error(con));
        exit(1);
    }

    if (mysql_real_connect(con, "localhost", "root", "YES", "Users", 0, NULL, 0) == NULL)
    {
        finish_with_error(con);
    }

    /*I WANNA PASS THE VARIABLE Name TO THIS QUERY -> VALUES(NAME)*/
    if (mysql_query(con, "INSERT INTO Personal_info (First_name) VALUES()"));
    {
        finish_with_error(con);
    }

    return 0;

I want to put in the query command the value of that variable.
To all code that I've tried, I receive the same error message:
syntax error

Comment: I don't know well, but this may help https://stackoverflow.com/questions/36266635/mysql-c-api-parameterized-query-fetch-result
Comment: Can you post a complete example that produces the error? Also, which language? `C` or `C++`?
Comment: I've updated the code
Answer: How about this:
snprintf(buf,sizeof(buf),"INSERT INTO Personal_info (First_name) VALUES(%s)",Name);
if(mysql_query(con, buf))

Warning: Just off the top of my head, not actually compiled and tested!
Comment: Thank you, but I've already tried this one and didn't work.
its point to the beginning  of Name and says, error: expected expression before '}'


docker registry: Pushing behind traefik is failing

Question: I've deployed an registry:2 behind an traefik.
I'm facing with traying to push an image to it:
$ docker push registry.dind.localhost:32785/feedly:v1
The push refers to repository [registry.dind.localhost:32785/feedly]
aa0f3a996547: Preparing
43c5bd749b73: Preparing
d7fc70cd5810: Preparing
27cd2023d60a: Preparing
4b52dfd1f9d9: Preparing
error parsing HTTP 404 response body: invalid character 'p' after top-level value: "404 page not found\n"

I've took a look on dockerd logs:
level=debug msg="Calling POST /v1.40/images/registry.dind.localhost:32785/feedly/push?tag=v1"
level=debug msg="Trying to push registry.dind.localhost:32785/feedly to https://registry.dind.localhost:32785 v2"
level=debug msg="Pushing repository: registry.dind.localhost:32785/feedly:v1"
level=debug msg="Checking for presence of layer sha256:aa0f3a9965479ba5f42cdbdddb14d00fa321d56c267bc0b944c6af8ffbfa7beb (sha256:c602ede608540175f12957c5b9fb7ebeb0e17a9625e0f8e8711306556cb251a8) in registry.dind.localhost:32785/feedly"
level=debug msg="Checking for presence of layer sha256:d7fc70cd581085df5bc3d2ed1249e507b290f9e9873024736a4861870fd00baf (sha256:cf2f38b98af20b81ce03efaa616cda3ff098f68275c55342eceee05f204a326c) in registry.dind.localhost:32785/feedly"
level=debug msg="Checking for presence of layer sha256:4b52dfd1f9d986c4319979f31a32f5ff7acef454f207d2b7ac72bb9f336c6ce8 (sha256:7fe5fcc0340ea9baed3fa3a50c78e997ed51112a739a64f093dd8938656f53c4) in registry.dind.localhost:32785/feedly"
level=debug msg="Checking for presence of layer sha256:43c5bd749b737695c814bb528d170b117e415440a2bd54a27e58d66cb2ecba28 (sha256:0df3b2d147c7a5fefc06f031771af3c9e0905a3e2459f475a3166796b56d1021) in registry.dind.localhost:32785/feedly"
level=debug msg="Checking for presence of layer sha256:27cd2023d60ab891655435a9102be0ce246410f5a54db39edf070a97819b5d38 (sha256:086296bbdfc786dec2bd9f9637f937fcdfaa4ac89de84b99cea50228059aed2c) in registry.dind.localhost:32785/feedly"
level=debug msg="Pushing layer: sha256:aa0f3a9965479ba5f42cdbdddb14d00fa321d56c267bc0b944c6af8ffbfa7beb"
level=debug msg="Pushing layer: sha256:4b52dfd1f9d986c4319979f31a32f5ff7acef454f207d2b7ac72bb9f336c6ce8"
level=debug msg="Pushing layer: sha256:27cd2023d60ab891655435a9102be0ce246410f5a54db39edf070a97819b5d38"
level=debug msg="Pushing layer: sha256:d7fc70cd581085df5bc3d2ed1249e507b290f9e9873024736a4861870fd00baf"
level=debug msg="Pushing layer: sha256:43c5bd749b737695c814bb528d170b117e415440a2bd54a27e58d66cb2ecba28"
level=error msg="Upload failed: error parsing HTTP 404 response body: invalid character 'p' after top-level value: \"404 page not found\\n\""
level=error msg="Upload failed: error parsing HTTP 404 response body: invalid character 'p' after top-level value: \"404 page not found\\n\""
level=info msg="Attempting next endpoint for push after error: error parsing HTTP 404 response body: invalid character 'p' after top-level value: \"404 page not found\\n\""
level=debug msg="Skipping non-TLS endpoint http://registry.dind.localhost:32785 for host/port that appears to use TLS"

I've also took a look on traefik logs:
"GET /v2/ HTTP/1.1" - - "-" "-" 32 "-" "-" 0ms
"HEAD /v2/feedly/blobs/sha256:c602ede608540175f12957c5b9fb7ebeb0e17a9625e0f8e8711306556cb251a8 HTTP/1.1" - - "-" "-" 33 "-" "-" 0ms
"HEAD /v2/feedly/blobs/sha256:7fe5fcc0340ea9baed3fa3a50c78e997ed51112a739a64f093dd8938656f53c4 HTTP/1.1" - - "-" "-" 34 "-" "-" 0ms
"HEAD /v2/feedly/blobs/sha256:086296bbdfc786dec2bd9f9637f937fcdfaa4ac89de84b99cea50228059aed2c HTTP/1.1" - - "-" "-" 35 "-" "-" 0ms
"HEAD /v2/feedly/blobs/sha256:cf2f38b98af20b81ce03efaa616cda3ff098f68275c55342eceee05f204a326c HTTP/1.1" - - "-" "-" 36 "-" "-" 0ms
"HEAD /v2/feedly/blobs/sha256:0df3b2d147c7a5fefc06f031771af3c9e0905a3e2459f475a3166796b56d1021 HTTP/1.1" - - "-" "-" 37 "-" "-" 0ms
"POST /v2/feedly/blobs/uploads/ HTTP/1.1" - - "-" "-" 38 "-" "-" 0ms
"POST /v2/feedly/blobs/uploads/ HTTP/1.1" - - "-" "-" 39 "-" "-" 0ms
"POST /v2/feedly/blobs/uploads/ HTTP/1.1" - - "-" "-" 40 "-" "-" 0ms
"POST /v2/feedly/blobs/uploads/ HTTP/1.1" - - "-" "-" 41 "-" "-" 0ms
"POST /v2/feedly/blobs/uploads/ HTTP/1.1" - - "-" "-" 42 "-" "-" 0ms

I've also took a look on registry logs and it doesn't generate logs!
Next step: I've tried to reach at registry using curl. I've realized it's reached:
$ curl -s registry.dind.localhost:32785/v2/_catalog | jq
{
  "repositories": []
}

I've also tried to perform previously tried requests by docker push like HEAD _/v2/feedly/blobs/sha256:c602ede608540175f12957c5b9fb7ebeb0e17a9625e0f8e8711306556cb251a8:
$ curl -s -X HEAD -I registry.dind.localhost:32785/v2/feedly/blobs/sha256:0df3b2d147c7a5fefc06f031771af3c9e0905a3e2459f475a3166796b56d1021
HTTP/1.1 404 Not Found

It's also reached and it's telling me layer doesn't exist.
This time, requests has reached to registry. Here registry logs:
level=info msg="response completed" go.version=go1.11.2 http.request.host="registry.dind.localhost:32785" http.request.id=f9698ee1-0ee3-4021-82ab-8b659ffc0549 http.request.method=GET http.request.remoteaddr=10.0.0.2 http.request.uri="/v2/_catalog" http.request.useragent="curl/7.58.0" http.response.contenttype="application/json; charset=utf-8" http.response.duration=1.094913ms http.response.status=200 http.response.written=20
"GET /v2/_catalog HTTP/1.1" 200 20 "" "curl/7.58.0"
"HEAD /v2/feedly/blobs/sha256:0df3b2d147c7a5fefc06f031771af3c9e0905a3e2459f475a3166796b56d1021 HTTP/1.1" 404 157 "" "curl/7.58.0"
level=error msg="response completed with error" err.code="blob unknown" err.detail=sha256:0df3b2d147c7a5fefc06f031771af3c9e0905a3e2459f475a3166796b56d1021 err.message="blob unknown to registry" go.version=go1.11.2 http.request.host="registry.dind.localhost:32785" http.request.id=e42c4aa6-ee13-4eda-ab08-ee15ba3d00a4 http.request.method=HEAD http.request.remoteaddr=10.0.0.2 http.request.uri="/v2/feedly/blobs/sha256:0df3b2d147c7a5fefc06f031771af3c9e0905a3e2459f475a3166796b56d1021" http.request.useragent="curl/7.58.0" http.response.contenttype="application/json; charset=utf-8" http.response.duration=1.692543ms http.response.status=404 http.response.written=157 vars.digest="sha256:0df3b2d147c7a5fefc06f031771af3c9e0905a3e2459f475a3166796b56d1021" vars.name=feedly

Here, you have docker stack with traefik and registry:
version: "3.7"
services:
  traefik:
    image: traefik
    command:
      --api=true
      --api.debug=true
      --api.dashboard=true
      --providers.docker.endpoint=tcp://172.18.0.4:2376
      --providers.docker.tls.ca=/certs/ca.pem
      --providers.docker.tls.cert=/certs/cert.pem
      --providers.docker.tls.key=/certs/key.pem
      --providers.docker.swarmMode=true
      --providers.docker.exposedByDefault=false
      --accesslog=true
    networks:
      - traefik-net
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /certs/client:/certs
    deploy:
      placement:
        constraints: [node.role==manager]
      labels:
        - traefik.enable=true
        - traefik.http.routers.api.rule=Host(`traefik.dind.localhost`)
        - traefik.http.routers.api.service=api@internal
        - traefik.http.routers.api.middlewares=auth
        - traefik.http.middlewares.auth.basicauth.users=admin:$$apr1$$7h4Zhn7O$$aTpZnWbkA44AWTMgHCwrw1
        # Dummy service for Swarm port detection. The port can be any valid integer value.
        - traefik.http.services.dummy-svc.loadbalancer.server.port=9999
  registry:
    image: registry:2
    deploy:
      labels:
        - traefik.enable=true
        - traefik.http.routers.registry.rule=Host(`registry.dind.localhost`) && PathPrefix(`/v2`)
        - traefik.http.services.registry.loadbalancer.server.port=5000
    networks:
      - traefik-net

Any ideas?
Comment: Have you resolved it?
Answer: try setting the REGISTRY_HTTP_RELATIVEURLS environment variable to true. as per describe here
environment:

REGISTRY_HTTP_RELATIVEURLS=true


Removing "Home" from the title

Question: How do I remove Home from the page title?
I added in page.twig.html this part of code.
{% if not is_front %}

      {{ page.content }}

      {% endif %}

The title appears as follows.

I just want it to be Nekretnina.ba, without Home |.
Answer: Override html.twig.php in your template, not page.twig.html. May I also suggest metatag for better control over page titles?

Removing "Home" from the title


How to fix this regex problem to match optional columns and spaces?

Question: This is my data format with up to 3 columns:
WORD, FREQ and TAG
WORD, FREQ
WORD, TAG
WORD

The following are some examples:
WORD FREQ TAG
dog 100 n
kill 200 v
cat n
united states
united kingdom 100
new york 2 n

Where only the first column WORD is required. The second column could be a number or a tag (a-z). I use the re_pattern to parse each line to get each column.
words = ['dog 100 n', 'kill 200 v', 'cat n', 'united states', 'united kingdom 100', 'new york 2 n']
re_pattern = re.compile('^(.+?)(\s[0-9]+)?(\s[a-z]+)?$', re.U)

for w in words:
    word, freq, tag = re_pattern.match(w).groups()

    print(word, freq, tag)

The output is below:
dog  100  n
kill  200  v
cat None  n
united None  states
united kingdom  100 None
new york  2  n

As you can see, all others are right, but 'united states' are wrong. It parse 'states' and the tag and None as freq. In this case, there is only one column, WORD, no freq and tag.  How to fix this pattern to get all the patterns right?
Comment: Thanks @IainShelvington for pointing that out. I updated my answer to include support for tags that has more than 1 letter.
Comment: According to your format a single line with two words is interpreted as a word and a tag. Can the definition of a tag be more specific, they seem to be limited to a few select characters?
Comment: 'united states' is a normal word, and 'united' itself is a normal word, if it exists on a line alone.
Comment: What makes "cat n" a word and a tag but "united states" a single word? If the definition of a tag can be made more specific maybe that would help?
Comment: Yes, you are right. What about TAG is a list defined: TAG = ['n', 'nz', 'v', 'vz'] for example.
Comment: Change the part of the regex that picks up tags to only match those strings and you should be good: `(n|nz|v|vz)`
Comment: My my tag count is about 50. It's hard to list in the regex.
Comment: Do the tags follow a pattern? A brute force approach would be to create a large "or" group/match and use it in your regex: `'|'.join(all_tags)`
Comment: How to use an external list in a regex? I can predefine it before applying the regex.
Comment: A regex is just a string, you can use normal string formatting to insert whatever you want into it: `'^(.+?)(\s[0-9]+)?(\s(?:{})+)?$'.format('|'.join(all_tags))`
Comment: @IainShelvington That's a good thing to know and thanks a lot for the technique.
Comment: You should be aware the answer you accepted only works for single letter tags. "cat nz" for example would come out as a single word
Answer: With the assumption that the TAG part is a single letter (see also the comments section), try this pattern:
^(.+?)\s*(\b\d+)?\s*(\b[a-z])?$

But if the TAG might contain more than 1 letter e.g. nz, what we can do to remove the ambiguity between treating cat aw as a WORD while cat nz as a WORD and a TAG is to list all possible tags in an OR | operation:
^(.+?)\s*(\b\d+)?\s*(\b(?:n|nz|v|vz))?$

Code:
import re

TAG = ['n', 'nz', 'v', 'vz']

words = ['dog 100 n', 'dog 100 nz', 'kill 200 v', 'cat n', 'cat vz', 'united states', 'united states nz', 'united kingdom 100', 'new york 2 n', 'new york 2 vz']

# Option 1: If using single-letter tags
re_single_letter_tag = re.compile(r'^(.+?)\s*(\b\d+)?\s*(\b[a-z])?$', re.U)
# Option 2: If using a specific set of tags with more than 1 letter
re_multi_tag = re.compile(
    r'^(.+?)\s*(\b\d+)?\s*(\b(?:' + r"|".join(TAG) + r'))?$',
    re.U,
)

for w in words:
    word1, freq1, tag1 = re_single_letter_tag.match(w).groups()  # Option 1
    word2, freq2, tag2 = re_multi_tag .match(w).groups()  # Option 2
    print(w)
    print(f"\t{word1=} {freq1=} {tag1=}")
    print(f"\t{word2=} {freq2=} {tag2=}")

Output
dog 100 n
    word1='dog' freq1='100' tag1='n'
    word2='dog' freq2='100' tag2='n'
dog 100 nz
    word1='dog 100 nz' freq1=None tag1=None
    word2='dog' freq2='100' tag2='nz'
kill 200 v
    word1='kill' freq1='200' tag1='v'
    word2='kill' freq2='200' tag2='v'
cat n
    word1='cat' freq1=None tag1='n'
    word2='cat' freq2=None tag2='n'
cat vz
    word1='cat vz' freq1=None tag1=None
    word2='cat' freq2=None tag2='vz'
united states
    word1='united states' freq1=None tag1=None
    word2='united states' freq2=None tag2=None
united states nz
    word1='united states nz' freq1=None tag1=None
    word2='united states' freq2=None tag2='nz'
united kingdom 100
    word1='united kingdom' freq1='100' tag1=None
    word2='united kingdom' freq2='100' tag2=None
new york 2 n
    word1='new york' freq1='2' tag1='n'
    word2='new york' freq2='2' tag2='n'
new york 2 vz
    word1='new york 2 vz' freq1=None tag1=None
    word2='new york' freq2='2' tag2='vz'

Where:

^ - Start of string
(.+?) - Non-greedy matching of the "WORD" part. This will capture the least possible characters that would still satisfy the next parts capturing their own parts. Treat this as if the next parts would be prioritized to capture their parts first before this pattern will get its share.
\s* - Any number of spaces
(\b\d+)? - Optionally match the "FREQ" part
\s* - Any number of spaces
(\b[a-z])? - Optionally match the "TAG" part. It is mandatory to put the boundary \b so that this wouldn't get the last letter supposedly for the "WORD" e.g. "s" in "united states".
(\b(?:n|nz|v|vz))?- Optionally match the "TAG" part from a specific list of possible tags
$ - End of string
Comment: It seem working! It's a good learning the use of \b and \d
Comment: Glad it helped. Note that as being discussed in the other comment section, the format of the tag must be consistent. In my answer, it assumes that the tag is a single lowercase letter separated by a space/word-boundary. If you have tags with 2-letters such as "nm", then we have to identify all of them so that we will treat "cat aw" as a WORD and "cat nm" as a WORD and TAG (see the ambiguity?). In that case, I'm afraid the only way of doing it is listing all possible tags in an or `|` operation in the regex.
Comment: I understand that now and thanks.
Comment: @marlon I updated my answer to include another option when the tags contain multi-letters. I believe it might help you better with your use case :)


Trainable weights in attention mechanism

Question: I am wondering what are the trainable weights inside an attention-powered transformer. I figure the feed-forward layer contain trainable weights and the token embeddings, but what other parts contain trainable weights? i.e. when you store a trained model, what parts are you actually storing
I also wonder what weights inside the attention-mechanism must be temporary stored, or being held in memory, during a training iteration until the backpropagated gradient descent comes back?
Answer: Computation of one a single head of the scaled dot-product attention for values $V$, keys $K$ and queries $Q$ does not need any parameters. The output of the attention is simply (Eq. 1 of the Attention is all you need paper).
$$
\mathrm{Attention}(Q, K, V) = \mathrm{softmax}\left(\frac{QK}{\sqrt{d}} \right) V
$$
However, in the multi-head setup, the keys, values, and queries are a result of a head-specific projection (unnumbered equation on the top of page 5)
$$
\mathrm{MultiHead}(Q, K, V) = \mathrm{Concat}(\mathrm{head}_1,\ldots,\mathrm{head}_h)W^O
$$
where
$$
\mathrm{head}_i = \mathrm{Attention}(QW_i^Q, KW_i^K, VW_i^V).
$$
Here, all the projection matrices $W$ are trainable parameters. The Transformer Base architecture has dimensions 512, 8 heads and each head has a dimension 64. This means that the matrices $W_i^Q$, $W_i^K$, and $W_i^V$ have 512×64 parameters and there are eight of them (in practice, they are grouped into large matrices and the output of the large matrix multiplication is then reshaped accordingly), this is 262k parameters. Matrix $W^O$ projects a concatenation of 8 64-dimensional heads into 512 model, dimensions, i.e., further 262k parameters. In some implementations, there are also biases to the projections, but this is negligible in terms of parameter count.
The Transformer Base architecture thus has over 0.5M parameters in each self-attention sublayer. Compared to the feed-forward layers (2×512×2048≈2M), it is approx 4 times less.
During the forward and backward pass, there must a node for each of the computation (each dot product, each softmax) and all the intermediate results needs to be stored in order compute the gradient.


How can i drop or ignore "syn" packets for opening connection in perl socket programing over linux that use listen() function?

Question: I need a way to ignore connection requests (e.g syn req) for my server that listens via "listen()" funcion using perl socket programing.
I realized that "listen()" listens to the socket and response imidiately to syn request with syn-ack.
delay the syn-ack response to the request is also countable.
Thanks !
Comment: If you want to ignore connection requests, why not just not `listen()`?  Or you could use a firewall to block requests to that port
Comment: Maybe explain what the *real* problem is that you are trying to solve. A server accepting connections cannot be the problem ,right?
Answer: I don't think this is as easy as you think, because the listen() function works at a higher level than the TCP/IP packet stream. It opens a socket, tells the OS to accept incoming connections.
It's therefore the OS that's handling the SYN packets first, and is why firewalls are often used to deal with this problem. You might be able to do something involving generating your own packets (I haven't tried, so I'm not going to recommend anything) and manually 'handling' the connection. (You'd almost certainly need to be operating as a privileged user to do this too).
But I would have to ask - why do you want to do this?
I mean SYN is an essential part of the 3-way handshake of setting up a TCP/IP session. If you don't want a TCP/IP session to be established, then why open a port in the first place?
I would suggest that if it's for filtering of incoming traffic, then the tool for the job is a firewall like iptables.
Comment: I need this option in order to simulate situation where a "connect timeout" is happening in the client. Connect timeout in the client  is where the client sent a connection request (syn) and the connection is not established immediately , e.g the server do not response with a syn-ack . I addition,  i must simulate this when the server is up and i prefer using "internal" software solution for this rather using external tools that preventing the packet from entering the machine (e.g iptables).

Thanks !
Comment: That is exactly my scenario. I currently connect to an address from a reserved IPv4 block and the connection is dropped by the network firewall currently but opening a dropping network service on localhost would be more stable. @idan, what solution did you use eventually?


How to assess whether experimental measurements obtained from different technicians are biased?

Question: Suppose I have a list of measurements from an experiment; for example,

34 31 55 18 19 22 44 48 23 . . .

But I then learn that these experiments were conducted by two different technicians, so I embolden those conducted by tech #1, and I leave untouched the measurements of tech #2:

34 31 55 18 19 22 44 48 23 . . .

I want to know if the bold numbers are somehow biased relative to the unbolded numbers.  How should I measure this?
My intent is to compare the mean and variance of the overall sequence to the means and variances of each of the subsequences.  But I'm a novice at statistics, so perhaps this naive approach is too shallow?
Comment: Actually, this is related to one of the deepest (and, in some sense, most troubling) problems in classical statistics. See the [Behrens-Fisher problem](http://en.wikipedia.org/wiki/Behrens%E2%80%93Fisher_problem).
Comment: @Arun, Sorry if my comments confused matters. It was meant more as a side note. If the two samples are independent, and each comes from a normal distribution with the same variance, but possibly different means, then, yes, a two-sample $t$-test is the natural choice. There are strong theoretical reasons for its use. The interesting thing from a statistical perspective is that these theoretical properties break down in a big way as soon as we let the variances be unequal. In applications, this is often seen. :)
Comment: @Cardinal, I read the wiki page (and I am by no means a statistician). Actually I am even more confused. Under the assumption of normal distribution, wouldn't the problem boil down to a t-test? And if they don't come from a normal distribution, still they come from the same distribution. In that case, isn't there an equivalent to z-score possible?
Comment: @Cardinal, thank you, that clears things a bit. Can we mathematically be certain of the population variances being equal? I mean, how does one go about validating the assumptions of a t-test before using one. Or this is normally a determinant of experiment?
Answer: This answer is probably a bit late for you, but I think this falls under the category of repeatability. If anyone disagrees, feel free to comment!
Repeatability is the extent to which the identity of the observer can be used to predict the result, or in simple terms, the consistency with which one observer differs from another.
Repeatability can also be used to quantify how closely repeated measurements of an individual resemble each other, relative to measurements from another individual. (e.g. when measuring the weight of a bird at several occasions over a year, high repeatability means that the individuals consistently differ across the course of a year).
Repeatability is quantified by the intra-class correlation coefficient (ICC). In your case, the class is the observer. R can be calculated by ANOVA, or the best-practice method, linear mixed effects modelling (LMM).
If you have a low repeatability within observers (small R, nonsignificant p-value), you can say that the observers are not biasing the result.
If you have high repeatability, you have a problem, although it is not so bad if the observer error is balanced across treatment groups (but still should be avoided if possible). This would perhaps be a good time to use a model in which the observer is specified as a random factor, so that adjustments can be made for the inter-observer differences.
Here is a very good review on the topic by Nakagawa and Schielzeth (2010): http://onlinelibrary.wiley.com/doi/10.1111/j.1469-185X.2010.00141.x/abstract
And the related R package, with support for general and generalized linear mixed modelling:
http://rptr.r-forge.r-project.org/
Answer: The first thing I would do would be to plot the data.
But then, as you say, compare the means and SDs for each technician, to each other.  A t-test would be the first thing to try, for comparing the means.
Comment: Could the two technicians have the same mean and variance yet be measuring differently?


Google Maps Geolocation API limited at 100 requests even with billing enabled?

Question: Did Google changed recently "his terms" about the Google Maps APIs ??
My APIs were working fine and I had billing enabled even if I never was billed cause I never reached the free 2 500 requests / day allowed.
Now it seems that we are limited to 100 requests / day + 1 request/second/user... and I believe my app is not working fine anymore because of this (unless the API keys could have changed with Google's changes?!?).
Is there anyone who also has billing enabled and still is limited to 100 requests per day?
Or anyone knows how to get rid of this limits?
Thanks in advance for your help!!
Answer: I don't think so.

This is exactly what the Google Developer Console told me three minutes ago.


Is L' context free language?

Question: Given context free grammar :   G=(V,T,P,S).
and  L'={a $\in$ (V $\cup$T)* | S$\Rightarrow$*a}   when $\Sigma$=V $\cup$ T
Is L' context free language ?
I think no because for the grammer:
G=(S,{a,b},P,S)   ,P={ S$\rightarrow$aSb|ab}
we will get that L' is:
L'={$a^nS^nb^n$}$\cup${$a^nb^n$} and L'  is not context free language.
Comment: Why $a^nS^nb^n$ instead of $a^nSb^n$?
Answer: Given context-free grammar $G = (V, T, P, S)$, define $G' = (V, T \cup V', P \cup P', S)$, such that $V'$ has one element for each element of $V$,
$$ V' = \{ v' \mid v \in V \} \enspace, $$
and, for each element $v \in V$, $P'$ contains the production $v \rightarrow v'$.  The language of $G'$ is context-free, and is isomorphic to $L'$.
Answer: Your initial definition:
$$
L'= \{a \in (V \cup T)^* \mid S \Rightarrow^* a \}   \quad \text{when } \Sigma =V \cup T \quad (*)
$$
seems to use $V$ as set of non-terminals and $T$ as set of terminals.
$L'$ consists of all words $a \in \Sigma^*$ which can be produced via $P$ from the start symbol $S\in V$ in finite many steps.
The language generated from $G=(V, T, P, S)$ is
$$
L(G) = \{ a \in T^* \mid S \Rightarrow^* a \} \quad (**)
$$
To have $L'$ be context-free, one has to provide a context-free grammar $G'=(V', T', P', S')$ which generates it similar to $(**)$.
Solution:
We have $T' = V \cup T$ from the definition of $L'$ and comparison to $(**)$.
The requirement $\emptyset = V' \cap T'$ needs us to come up with a $V'$ disjoint with $V$. As $S \in V$, $S' \in V'$ this means $S' \ne S$.
$P$ contains the production rules $\alpha_i \to \beta_i$ with $\alpha_i \in V$ and $\beta_i \in (V \cup T)^*$.
If $a \in L'$ then $a \in (V\cup T)^*$ and we have $S = u_1 \Rightarrow \dotsb \Rightarrow u_k = a$ for $k \ge 1, k\in \mathbb{N}$, $u_i \in (V\cup T)^*$ because the productions from $P$ are used:
$u \Rightarrow v$ means there is a production rule $\alpha \to \beta$ and prefix $p$, suffix $s$ such that $u = p \alpha s$ and $v = p \beta s$.
We now choose some set $V'$ disjoint with $V$ but with the same number of elements, as $V$ is finite, this should always be possible.
We choose some bijection $f$ between $V$ and $V'$:
$$
v' = f(v) \quad (v \in V)
$$
Then $V' = f(V)$, $S' = f(S)$.
For each production $\alpha \to \beta$ from $P$,
we define a production $\alpha' \to \beta'$ for $P'$, where $\alpha' = f(\alpha)$ and $\beta'$ such that each symbol $s$ from $\beta$ with $s\in V$ is replaced by $s'=f(s)\in V'$, while the symbols $s\in T$ will be kept. A little bit sloppy, we write this as $\beta'=f(\beta)$.
This $G'$ so far will generate (in the sense of $(*)$) all words $a' = f(a)$ where $a\in L'$. These $a'$ might contain non-terminal symbols from $V'$, $a' \ne a$ might occur, so we add production rules $v' \to v = f^{-1}(v')$ for each $v' \in V$ to $P'$.
This should give
$$
L' = L(G')
$$
according to $(*)$.
Example:
$$
G = (V=\{S\}, T=\{a,b\}, P, S)
$$
with production rules $P$:
$$
S\to aSa \mid bSb \mid \varepsilon
$$
Then
$$
L' = \{ wSw^R \mid w \in T^* \} \cup \{ ww^R \mid w \in T^* \}
$$
Then
$$
G' = (V'=\{ S' \}, T'=\{ S, a, b \}, P', S)
$$
with $P'$:
$$
S' \to aS'a \mid bS'b \mid \varepsilon \mid S
$$
The first three productions will generate (in the sense of $(*)$)
$$
f(L') = \{ wS'w^R \mid w \in T^* \} \cup \{ ww^R \mid w \in T^* \}
$$
the last one extends to
$$
\{ wS'w^R \mid w \in T^* \} \cup \{ wSw^R \mid w \in T^* \} \cup \{ ww^R \mid w \in T^* \}
$$
however generated in the sense of $(**)$, thus restricted to $T'=\{ S, a, b \}$ we get $L'$.

Is L' context free language?


Let images work properly online and offline (MAMP)

Question: I just started using MAMP to work offline on my drupal-projects.
Because MAMP and working offline is new to me I started today with a test-website.
I installed MAMP, no problems.
I installed a new drupal 7.30 offline in MAMP, no problems.
I imported the CKEDITOR and IMCE for uploading images, no problems.
I created two test-pages and imported in each page a image using CKEDITOR & IMCE, no problems.
After that i tried to upload my offline website online: backup DB, create a new DB online, imported the offline DB, FTP my files online, change the settings-file for connecting instructions DB.
After all those steps my website was showing up online and i could login. Everything seems to work fine.
But then when i clicked one of the testpages, i saw that my images where not showing up...
When i checked the sourcecode i saw something like this:

When i removed /sweetmorning, and saved that code, the image was showing up again.
What is the best practice to still work with CKEDITOR IMCE and let the images showup offline and also after i put the website online.
Any tips, links, info are welcome :-)
Thanks in advance,
Kristof
Answer: Part of your code did not go through; however I believe it's pretty clear that the issue is in image paths.
Check out Pathologic module, as it deals with exactly such issues:

Pathologic is an input filter which can correct paths in links and images in your Drupal content in situations which would otherwise cause them to "break;" for example, if the URL of the site changes, or the content was moved to a different server. Pathologic can also solve the problem of missing images and broken links in your site's RSS feeds. See more example use cases on the documentation page.
Comment: I tried this module "Pathologic" but this didn't fix my problem. I will try to look further with this module. But not even sure if the solution is in there... the part in the url ( sweetmorning/... ) refers to the map in htdocs wher my project is in offline. that part should disapear when transferrring my website online...
Comment: Exactly that is the problem Pathologic solves. Maybe you did not configure it properly - give it another try and read the instructions [here](https://www.drupal.org/node/257026).
Comment: Thanks for the tips. I tried a little bit more with Pathologic. I did read the instructions and saw a instruction movie... But the only thing that happend was that http:localhost8888 was changed by my domainname online. I did not reach to the point where i could let the part sweetmorning/ dissapear. I geuss its also possible with Pathologic. But i did find a good solution without to have to install an extra module... I made a virtual host for my mamp, so the start of the url didn't used the name of the map in HTDOCS. Did fixed my problem and the pictures do show up online:-)
Answer: Here you can information how i fixed the problem:
http://sawmac.com/mamp/virtual/
This solution ensures that the name of the folder (project name - htdocs) in htdocs no longer used in the URL to the location of the photo. This creates NO problems when I place the website online.
With this i could move my offline project online and al the pictures showed up.
Probably a solution is also possible with Pathologic (and this looks like a good module, that can fix a lot of problems). So thank you again TOPSITEMAKERS.


how to get the width of textView in android

Question: This is the code what i am using...
<TextView
    android:id="@+id/textView"
    android:layout_width="100dp"
    android:layout_height="40dp"
    android:text="AMIT KUMAR" />

and here is a java code.
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView textView = (TextView) findViewById(R.id.textView);
    Log.d("left", textView.getLeft() + " " + textView.getRight() + " "
            + textView.getWidth()+" "+textView.getHeight());
}

for all above i am getting the output 0.
so how can i get the width and height of textView.
Comment: what's parent view of this textview?
Comment: see http://stackoverflow.com/questions/3591784/android-get-width-returns-0
Answer: Try like this:
textView.setText("GetHeight");
textView.measure(0, 0);       //must call measure!
textView.getMeasuredHeight(); //get height
textView.getMeasuredWidth();  //get width

Answer: On your onCreate do this then you will get actual width and height of the textView
textView.postDelayed(new Runnable() {

            @Override
            public void run() {
                textView.invalidate();
                float dw = textView.getWidth();
                float dh = textView.getHeight();
                Log.v("",dw + " - " + dh);
            }
        }, 1);

If you need to get width, height before view drawn then you can do this
ViewTreeObserver viewTreeObserver = textView.getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @SuppressLint("NewApi")
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            float dw = textView.getWidth();
            float dh = textView.getHeight();

            System.out.print(dw +" - "+dh);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                textView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                textView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        }

    });

Comment: ya i got the answer, but will you pls explain why you are using this code. means runnable thread
Comment: The runnable doesn't get run until the layout has occurred. So it will wait until the view is displayed in screen and for this reason it will always gives correct width, height. But it will fail if you need to calculate width height before view drawn.


AddThis buttons wont update to include fragment (#Hash Tag)

Question: I have these AddThis buttons on my website, and my site uses JS to take a user though an image gallery, when changing an image the URL is updated with the image title in the fragment element, the problem I have is this is not being reflected in the AddThis links. I've tried to get some answers from the AddThis forums, but was pointed at the api documentation and the addthis.toolbox() function, but it doesn't seem to be working out for me, so I thought I'd run it past the experts here.
This is my AddThis code on the basic page.

In my JS script when a user changes the image, I have added this to the function.
addthis.toolbox(".addthis_toolbox");

I've also tried this
addthis.toolbox();

When running the code, I get no JS errors, but I dont see any updates to the AddThis buttons.
you can see the problem here.
http://www.martynazoltaszek.com/artpages?nid=30#Rendezvouz
This link will open up the site on a particular image called "Rendezvouz" but the nid=30 is actually a differnet image called  "Walking by".The problem is shown by AddThis (Facebook) will always link to the Walking by" image. AddThis Gmail appears to be ok, but I dont think this is a factor of the API, as it works with or without the above function call.
Thanks in advance.
p.s. The reason for using a ?nid GET variable and a Fragment are due to php page load and JS viewing(without page refersh), but this also leaves support for a non JS browser.
Answer: I had a similar issue whilst using hashbangs for a javascript driven site. This code was used because the share buttons wouldn't re-render when content is loaded async.  You should be able to take parts of this to fit to your situation. Maybe just the addthis.update() code
First I changed the script for addThis to async
http://s7.addthis.com/js/250/addthis_widget.js#async=1

Once the DOM has loaded, listen for hashchanges, this is where we will update the addthis share details.
You may require additional plugins for this bit to work with older browsers, consider jQuery hashchange event - v1.3 - 7/21/2010 - http://benalman.com/projects/jquery-hashchange-plugin/
Now its all wired up for a hashchange, the next step is to alter addThis.
    $(function(){
        $(window).hashchange(function(){
            if($('body').hasClass('addThis')){
                addthis.ost = 0;
                addthis.update('share', 'url', window.location.href); // new url
                addthis.update('share', 'title', window.document.title); // new title.
                addthis.ready(); // this will re-render the buttons.
            }
            else {
                addthis.init();
                $('body').addClass('addThis');
            }
        });
        addthis.init() //As we've changed the addthis to async, you will have to call addthis.init() once the DOM has loaded.
    });

Hope this helps.
Comment: Thanks, I have downgraded my sites now to basic page changes, and unfortunatly quite busy. As soon as I get a chance I will check this out I like the sound of your solution.
Comment: Just a note, something I encountered the other day whilst working on this site, the addthis.update isn't required if you are doing addthis.ost = 0 and then addthis.ready.
Comment: @DamonSkelhorn where are you placing the functions above? Within the jQuery which triggers the hashchange or some other place? Thanks


Help in understanding a proof about infinite double summations

Question:

This is a problem from the book Understanding Analysis. I am struggling understanding to things. First I do not see how the order limit theorem is used, and second how they go from strictly less to less or equal. Can anybody give me a explanation for these two things?
Comment: You never told us what $r_1, r_2,\ldots,r_m$ are. Is $r_i=\sum_{j=1}^{\infty}a_{ij}$ (with the assumption that all those series converge)?
Comment: Try using summations or elementary addition principles
Answer: For a given $m$, $s_{mn}-S$ is a sequence indexed by $n$. If $$-\epsilon< s_{mn}-S<\epsilon$$
then, as  $n\to \infty$, $s_{mn}\to (r_1+r_2+\dots +r_m)$, where $r_i=\sum_{j=1}^{\infty}a_{ij}$, and, by the Order Limit Theorem, the inequalities hold but they are no more strict:
$$-\epsilon\leq  (r_1+r_2+\dots +r_m)-S\leq\epsilon.$$
P.S. Order Limit Theorem: if $\exists N$ such that $a \leq b_n\, \forall n\geq N$, and $\lim_{n\to \infty} a_n=A$, $\lim_{n\to \infty} b_n=B$ then $A\leq B$.
Of course we can replace $a \leq b_n$ with the stronger assumption $a< b_n$ and we may conclude again that $A\leq B$.
Comment: @xxtensionxx Is it clear now?
Comment: Aah now I am with you! Thanks for a great answer!


$\sum_{j=1}^n (B_{t_j}-B_{t_j^{\ast}})^2\xrightarrow{L^2}\frac{T}{2}$?

Question: I was reading this post that at some point explains why  $\sum_{j=1}^n (B_{t_j}-B_{t_j^{\ast}})^2\xrightarrow{L^2}\frac{T}{2}$. Since the post is old, I thought it may be easier to ask the question here.
First, if we define $S_n:= \sum_{j=1}^n (B_{t_j}-B_{t_j^*})^2$, I am struggling to understand the equality $$\text{Var} \, (S_n)  = \sum_{j=1}^n \text{Var} \, \left[ (B_{t_j}-B_{t_j^{\ast}})^2 - (t_j-t_j^{\ast})\right]$$
Indeed, if $X$ and $Y$ are independent we have $Var(X+Y)=Var(X)+Var(Y)$, so wouldn't we get $\text{Var} \, (S_n)  = \sum_{j=1}^n \text{Var} \, \left[ (B_{t_j}-B_{t_j^{\ast}})^2\right]$?
Also I am struggling to understand ($|\Pi|$ is the size of the mesh) the bound $$E \left[ \left( \sum_{j=1}^n (B_{t_j}-B_{t_j^{\ast}})^2 - \frac{T}{2} \right)^2 \right] =Var(S_n)\leq C|\Pi| T$$
Is it because $B_{t_j}-B_{t_j^*}\overset{d}{=}\sqrt{t_j-t_j^*}Z$ where $Z\sim\mathcal{N}(0,1)$ and so
\begin{align}
Var(S_n)&=\sum_{j=1}^n Var[(B_{t_j}-B_{t_j^*})^2]\\&=\sum_{j=1}^n Var[(t_j-t_j^*)Z^2]\\&=\sum_{j=1}^n (t_j-t_j^*)^2\underbrace{Var(Z^2)}_{=2}\le\sum_{j=1}^n |\Pi|(t_j-t_j^*)\cdot2 =2|\Pi|\underbrace{\sum_{j=1}^n t_j-t_j^*}_{\le T}
\end{align}
Comment: For the first question: $var (X+c)=var (X)$ if $c$ is a constant.
Comment: @KaviRamaMurthy, thank you. But what is the point of adding this constant term?
Answer: Let be $ (\Omega, \mathcal{F}, \mathbb{P})$ a probability space on which we define a Brownian motion $ B $. Let $\{t_i\}_{i\in \{0,..,n\}}$ be a partition of $[0,T]$ and we note the middle point $t^*_i = \frac{t_i + t_{i-1}}{2}$.
We want to show that $\sum_i (B_{t_i} - B_{t^*_i})^2 \to \frac{T}{2}$ in $L^2(\Omega, \mathcal{F}, \mathbb{P})$ when the mesh size $\Pi \to 0$.
The idea is to first "center" the r.v. $\sum_i (B_{t_i} - B_{t^*_i})^2$: $E[\sum_i(B_{t_i} - B_{t^*_i})^2] = \sum_i E[(B_{t_i} - B_{t^*_i})^2]=\sum_i(t_i-t^*_i)=\frac{T}{2}$.
As such, we have:
\begin{align}
Var\left(\sum_i(B_{t_i} - B_{t^*_i})^2 - \frac{T}{2}\right) &= E\left[\left(\sum_i(B_{t_i} - B_{t^*_i})^2 - \frac{T}{2}\right)^2\right] - \underbrace{E\left[\left(\sum_i(B_{t_i} - B_{t^*_i})^2 - \frac{T}{2}\right)\right]^2}_{=0}\\
&=||\sum_i(B_{t_i} - B_{t^*_i})^2 - \frac{T}{2}||^2_{L^2}
\end{align}
We know that the Brownian increments are independent and stationnary. Thus,
\begin{align}
Var\left(\sum_i(B_{t_i} - B_{t^*_i})^2 - \frac{T}{2}\right) &= \sum_i Var((B_{t_i} - B_{t^*_i})^2) \\
&= \sum_i 2(t_i - t^*_i)^2 \\
&\leq 2 \sup_i |t_i - t_{i-1}| \sum_i (t_i - t^*_i)= \Pi T \xrightarrow[\Pi\to0]{}0
\end{align}
In second equality we used that if $X\sim \mathcal{N} (0,\sigma^2)$, then $E[X^2] = \sigma^2$ and $E[X^4] = 3\sigma^4$.
To conclude, $||\sum_i(B_{t_i} - B_{t^*_i})^2 - \frac{T}{2}||^2_{L^2}  \to 0$ when $\Pi \to 0$.