Any books similar to Mikrokosmos written by a famous composer?

Question: I just discovered this gold nugget in piano teaching called Mikrokosmos by Bela Bartok.
Are there any other books that have progressively difficult sight-reading exercises written by a famous composer? Also, are there any such exercises specifically to train rhythm?
Answer: Schumann's Album for the Young (Album für die Jugend), is a famous example.  Not exercises as such, but simple through to hard self-contained pieces.
You couldn't get much better than the Mikrokosmos to train rhythm.


For Loops while using selenium for webscraping Python

Question: I am attempting to web-scrape info off of the following website: https://www.axial.net/forum/companies/united-states-family-offices/
I am trying to scrape the description for each family office, so "https://www.axial.net/forum/companies/united-states-family-offices/"+insert_company_name" are the pages I need to scrape.
So I wrote the following code to test the program for just one page:
from bs4 import BeautifulSoup as soup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome('insert_path_here/chromedriver')
driver.get("https://network.axial.net/company/ansaco-llp")
page_source = driver.page_source
soup2 = soup(page_source,"html.parser")
soup2.findAll('axl-teaser-description')[0].text

This works for the single page, as long as the description doesn't have a "show full description" drop down button. I will save that for another question.
I wrote the following loop:
#Note: Lst2 has all the names for the companies. I made sure they match the webpage
lst3=[]
for key in lst2[1:]:
    driver.get("https://network.axial.net/company/"+key.lower())
    page_source = driver.page_source

    for handle in driver.window_handles:
         driver.switch_to.window(handle)
    word_soup = soup(page_source,"html.parser")

    if word_soup.findAll('axl-teaser-description') == []:
        lst3.append('null')
    else:
        c = word_soup.findAll('axl-teaser-description')[0].text
        lst3.append(c)
print(lst3)

When I run the loop, all of the values come out as "null", even the ones without "click for full description" buttons.
I edited the loop to instead print out "word_soup", and the page is different then if I had run it without a loop and does not have the description text.
I don't understand why a loop would cause that but apparently it does. Does anyone know how to fix this problem?
Comment: Your first example for ansaco-llp does not work for me. It does not find the axl-teaser-description element. Page_source does not reflect that element if you print it and check it.
Comment: @Sri Not sure why it doesn't work for you, but I found the solution, which I will post in the next comment.
Answer: Found solution. pause the program for 3 seconds after driver.get:
import time
lst3=[]
for key in lst2[1:]:
    driver.get("https://network.axial.net/company/"+key.lower())
    time.sleep(3)
    page_source = driver.page_source

    word_soup = soup(page_source,"html.parser")

    if word_soup.findAll('axl-teaser-description') == []:
        lst3.append('null')
    else:
        c = word_soup.findAll('axl-teaser-description')[0].text
        lst3.append(c)
print(lst3)

Answer: I see that the page uses javascript to generate the text meaning it doesn't show up in the page source, which is weird but ok. I don't quite understand why you're only iterating through and switching to all the instances of Selenium you have open, but you definitely won't find the description in the page source / beautifulsoup.
Honestly, I'd personally look for a better website if you can, otherwise, you'll have to try it with selenium which is inefficient and horrible.
Comment: Right, I forgot browsers need to time to load a page while requests have that built-in and are virtually instant anyway.
Comment: The window_handles loop was unnecessary, I changed it in the solution.


Let $I$ be an ideal of a ring $R$, and let $S$ be a subring of $R$. Prove that $I\cap S$ is an ideal of $S$

Question: Let $I$ be an ideal of a ring $R$, and let $S$ be a subring of $R$. Prove that $I\cap S$ is an ideal of $S$
I've tried listing the properties of an ideal, but I don't know where to go from there.
Comment: Multiply an element of $I\cap S$ with an element of $S$.  The product is clearly in $S$. (Why?)  Now to show the product is also in $I$ use the fact that $I$ is an ideal in $R$ and the element you chose from $S$ is clearly also in $R$.
Comment: It would have been awesome if you could have written down all the properties of ideal which property of ideal is bothering you...
Answer: Let $J = I \cap S$.  Let $s_1, s_2 \in J$.  Then since $J = I \cap S \subset I$, $s_1, s_2 \in I$.  Thus, since $I$ is an ideal, $s_1 - s_2 \in I$; we also have $s_1, s_2 \in S$, whence
$s_1 - s_2 \in S$.  Thus $s_1 - s_2 \in I \cap S = J$.  Next, if $s \in J$ and $r \in S$, we have $s \in I$ whence $rs, sr \in I$, and the fact that $S$ is a subring means $rs, sr \in S$.
So $rs, sr \in I \cap S = J$, showing $J$ is a two-sided ideal of $S$ if $I$ is a two-sided ideal of $R$.  Scrutiny of these assertions reveals that similar conclusions hold if $I$ is a left or right ideal; $J$ inherits the "ideality" of $I$ in all cases.  QED
Hope this helps.  Cheerio,
and as always,
Fiat Lux!!!


Data Preparation in R: normalization, log - order

Question: I have a little problem with my data (GDP per capita, some control variables with negative minimums (e.g. FDI) and explanatory variables without negative values but also different ranges.
Originally, I derived growth rates for GDP per capita = (GDPpc_t=0 - GDPpc_t=1)/ GDPpc_t=1) *100. Then I normalized all variables/ the complete dataset and used log10(DF[,]+1) (+ 1 due to normalization, and log10() to make it easier to interpret).
But then a friend looked over it and said I should use log growth to calculate the growth rates. So, I started doing so and now I am completely confused.
The overall goal is to do a rolling fixed effects regression whereby I want to observe how coefficients/ elasticities change over time.
I am wondering:
Is the log now already applied to log growth? When I now normalize all data (also growth rate), and log() (not log10) the data, I get completely different estimates. So, this cannot be correct.
Leaving normalization completely away also brings different estimates.
Should I normalize before calculating the growth rates?
Can you please help me? In the following you can see a litte part of my data:
Log Growth rates:
Min. = -11.9384; Mean=1.6815; Max = 21.5104
One of the controls variables:
Min. = -57.5323; Median= 1.6087; Mean = 4.5322; Max = 86.4792
Two of the explanatory variables:
Min. = 0.01146; Mean=0.32895 ; Max=3.83870
Min. =10.47; Mean= 4506.50; Max. =15009.01
(Further, the data is not normally distributed)
Edit: I now tried the following:

No adaption at all (best findings regarding R-squ. and significance)
Normalization (similar sig. and R^2 to 1.)
Log just the relevant variables for which I would     use elasticities --> here no problem of negativity (similar solutions to 1.)
Create growth rates out of all variables (good R-squared but the variables of interest are insignificant)
Cube root transformation (applied to all variables or GDP growth left out --> to all variables brings worse estimates)
Square root transformation (similar to 5.)

Generally, I am copying a combination of 2 papers. The first paper (which has also the negative values) only normalizes and the second one logs all variables but has no negative values as control variables included. So, after looking at all alternatives I would only log the important variables. Its ok to do so, right ?
Comment: What is DF? That isn't clear.
Comment: Thanks for the clarification. So, you are mapping the range [0, 1] to [log 1. log 2]???  I can't see that that would be either standard or helpful.
Comment: This sorely and surely needs context. It sounds as if you are applying some kind of regression, for which some transformations are probably are a good idea given some variables you've mentioned. It's not obvious why any kind of normalization or other scaling is needed at all. So, what is your overall goal?
Comment: Data frame (just as an info that I applied the calculation to all variables)
Comment: I want to do a fixed effects regression. I applied normalization because of the different ranges and log10 to directly interprete the data (elasticities)
Answer: GDP per capita is often better considered on a logarithmic scale, for at least two reasons:

Over a range of countries, its distribution can be awkwardly skewed with outliers

It tends to change multiplicatively, so changes in log GDP per capita might be more natural and/or more convenient than changes in GDP per capita.

That said, "growth" can be occasionally be negative and in principle could be zero, so log growth sounds at best a poor choice of measure and at worst quite wrong as you could not helpfully take logarithms of zero or negative values. (The mathematical fact that logarithms are defined for negative values does not help here.)
Discussing whether normalization is a good idea depends on knowing what you mean by it. Normalization in the sense of standardization (value $-$ mean) / SD can only be carried after logarithmic transformation. To see this, consider that if carried out before then some values will be negative and zero isn't impossible either, so the problem in the previous paragraph would bite hard.
log(something $+1$) sounds like a fudge here. Sometimes there is a good reason for it, but often it is a poor work-around to apply logarithms whenever that is not helpful.
Comment: Thank you for your comment :-) By normalization I do not mean standardization but Min-max normalization.
Comment: That is not really consistent with anything but taking logarithms beforehand.
Comment: Ok, so I can also just log I guess. Still, I have the problem that some variables containing negative values. As I found my options are:
- Add arbitrary number (which was been criticized and has to be adapted anyways
- Add NAs to the negative values (too much!)
- square the data, log it (and eventually divide it by 2)

What's your opinion on that ? Thank you very much :-)
Comment: Occasionally there are good grounds -- given some negative values -- for cube roots, neglog = sign(x) * log(1 + abs(x)). or asinh, but the question with transforming any predictor is why do you want to transform it?   The best reasons for transforming a predictor are that the functional form is then a better match to the data OR that it dampens major skewness or outliers (second reason in my view). Leave a variable as it comes unless there is a strong reason for a simple transform. Being interested in elasticity is what it is, but only makes sense sometimes.


Is this a I IV V ii progression?

Question: I'm currently learning a piece that has the following chords in the chorus (one chord per bar):

     Em7
     A
     Bm7
     F#m7

Am I correct in assuming this is a I-IV-V-ii progression in the key of E minor?
Answer: For starters, major chords are written in RN capitals, minors in lower case. But, in Em, F#m is not a diatonic chord. I'd say it's more likely in D major, which uses all four chords diatonically. If so, them the RN will be ii, V, vi, iii.

Is this a I IV V ii progression?


Theoretical reason for multiple linear regression predictions being the same when adding and subtracting predictors

Question: Say I have two variables $x_1$ and $x_2$, now I build a linear regression model as below
$$\hat{Y} = n_1 x_1 + n_2 x_2.$$
Then I build another model as below
$$\hat{Z} = m_1 (x_1 + x_2) + m_2 (x_1 - x_2).$$
Intuitively, $\hat{Y}$ should be equal to $\hat{Z}$.  Below is my R code to demonstrate the equivalence
set.seed(1)
num = 10
X1 = runif(num)
X2 = runif(num)
Y = runif(num)

mydata <- data.frame(X1, X2, Y)
fit1 = lm(Y ~ X1 + X2, data = mydata)
summary(fit1)

mydata <- data.frame(X1 + X2, X1 - X2, Y)
names(mydata)[1] <- 'new_X1'
names(mydata)[2] <- 'new_X2'

fit2 = lm(Y ~ new_X1 + new_X2, data = mydata)
summary(fit2)

My questions is, how can I conceptually prove the equivalence?
Comment: https://stats.stackexchange.com/questions/540938 is a textbook exercise designed to explore this.  For additional approaches see https://stats.stackexchange.com/questions/31858 (a very quick demonstration using matrices) and the remarks at the end of https://stats.stackexchange.com/a/66295/919 (for a geometrical explanation).
Answer: Hi: You can prove the equivalence by re-writing your second regression model  as
$Z = (m_1 + m_2) \times x_1 + (m_1 - m_2) \times x_2 + \omega$
#==================================================================
EDITED ON 11/01/2021 IN ORDER TO  PROVIDE CLARIFICATION BASED ON COMMENT FROM OP THAT AN EXTRA ASSUMPTION IS BEING MADE.
#==================================================================
This way, it looks a lot more like the first regression model
$Y = n_1 \times x_1 + n_2 \times x_2 + \epsilon $
Now, when the estimation of both models is done, $Z$ and $Y$, the respective responses in the two regression models are identical. Also, $n_1$ corresponds to $m_1 + m_2$ and $n_2$ corresponds to $m_1 - m_2$.
So, when the regression using $Z$ is carried out, the coefficient $(\hat{m_1 + m_2})$ is estimated and the coefficient $(\hat{m_1 - m_2})$ is estimated such that the squared deviations of $Z$ from $\hat{Z}$ are minimized.
Similarly, from a least squares standpoint, in the first regression model,  one is minimizing the sum of squared deviations of $Y$ from $\hat{Y}$ by finding the coefficient estimates, $\hat{n_1}$ and $\hat{n_2}$.
Therefore, from a system of equations perspective ( taking the derivatives and setting them to zero and all of that ), one has two equations and two unknowns in both cases. Therefore, the result of the minimization procedures have to be identical in that $\hat{n_1}$ has to correspond to $(\hat{m_1 + m_2})$ and $\hat{n_2}$ has to corrrespond to $(\hat{m_1 - m_2})$.
Does that clarify why the two models are identical ?  If not, then maybe someone else can give a clearer explanation. In practical terms, the fact that, in the second regression model, the first coefficient is $(m_1 + m_2)$ and the second coefficient is $({m_1 - m_2})$ makes no difference to the minimization algorithm. It views them as variables to be estimated. Since the second regression model faces the same minimization problem that the first regression model faces, the coefficient estimates have to correspond in that the sum of the coefficients in the second model corresponds to $n_1$ and the difference of the coefficients in the second model corresponds to $n_2$.
#=================================================================
EDIT ON 11-02-2021 IN ORDER TO COMMENT ON NICO'S QUESTION REGARDING HOW $m1$ and $m2$ ARE ACTUALLY OBTAINED.
#====================================================================
Nico: Notice that when the R code is run ( output shown below ), the coefficients for the second regression  are $m_1$ and $m_2$. So, a system of equations for dealing with the dependence is not necessary because the relation I used to show equivalence of the regression models, is not used in the R code itself. So, my explanation of using a 2 by 2 system of equations to solve for $m_1$ and $m_2$ AFTERWARDS, is only conceptual. The lm call in the second regression model does not need to do anything fancy because there is no dependence between the two coefficients $m_1$ and $m_2$. I just introduced the dependence to show equivalence  of the two models. I hope that helps.
Note that if you take the 2 coefficients in the second output and add them and subtract the second from the first, then you will obtain the same coefficients that are obtained in the first regression model.
#====================================================================

Call:
lm(formula = Y ~ X1 + X2, data = mydata)

Residuals:
    Min      1Q  Median      3Q     Max
-0.3904 -0.2223 -0.0482  0.2495  0.4115

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   0.7706     0.3004   2.566   0.0373 *
X1           -0.2867     0.3326  -0.862   0.4172
X2           -0.3475     0.3881  -0.895   0.4004
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.3149 on 7 degrees of freedom
Multiple R-squared:  0.1815,    Adjusted R-squared:  -0.05238
F-statistic: 0.776 on 2 and 7 DF,  p-value: 0.4961

>
+ mydata <- data.frame(X1 + X2, X1 - X2, Y)
+ names(mydata)[1] <- 'new_X1'
+ names(mydata)[2] <- 'new_X2'
+
>
+ fit2 = lm(Y ~ new_X1 + new_X2, data = mydata)
+ summary(fit2)
+
Call:
lm(formula = Y ~ new_X1 + new_X2, data = mydata)

Residuals:
    Min      1Q  Median      3Q     Max
-0.3904 -0.2223 -0.0482  0.2495  0.4115

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   0.7706     0.3004   2.566   0.0373 *
new_X1       -0.3171     0.2550  -1.244   0.2536
new_X2        0.0304     0.2562   0.119   0.9089
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.3149 on 7 degrees of freedom
Multiple R-squared:  0.1815,    Adjusted R-squared:  -0.05238
F-statistic: 0.776 on 2 and 7 DF,  p-value: 0.4961

Comment: This is not what I expected. You are making the assumption that Z_hat is equal to Y_hat before you actually prove they are equivalent, which is not true
Comment: Maybe the notation is what is bothersome. See edit.
Comment: @mlofton nice explanation. There's still something I can't understand to close the loop though. In the second model both coefficients (m1 +m2) and (m1 -m2) are dependent. And this isn't true on the first model where n1 isn't dependent on n2.  Why is the optimization result the same in both cases?
Comment: Thanks Nico. The coefficients are dependent but when the actual minimization is done, it ends up being an equality ( $\hat\beta = (X^\prime X)^{-1} X^\prime Y $) where $X$ is the matrix of dependent variables ( $n \times 2$ forgetting the intercept ) So, its best to think of it as just solving for 2 coefficients, $\beta_1$ and $\beta_2$. Then, AFTER THAT,  the relation  $\beta_1 = m_1 + m_2$ and $\beta_2 = m_1 - m_2$  can be used to solve for $m_1$ and $m_2$. Essentially, the dependence of the actual coefficients can be handled by solving a 2 by 2 system of equations afterwards.
Comment: Nico: Note that I'm just explaining it in the way above in order to explain the handling of the dependence. I'm not sure how it's actually done inside the lm call. But atleast the way I explained it is one way to think about it. The people who wrote lm are all R-core members whose brains operate on a whole different level so they may do something totally different from the way I explained it. Either way, the dependence is handled in some manner.
Comment: Nico: I added another edit in my answer because I realized something after I wrote the comments above. I hope it helps.
Comment: Thanks @mlofton ! I think I get it! In my head it all boils down to the feasibility of solving the system of equations at the end with n1 and n2 provided. Provided this is solvable (2 unknowns with 2 equations: OK) then the optimization can find any value of the coefficients in the second regression making both regressions equivalent.
Comment: Hi Nico: yes. but the thing is, I just wrote it that way (using m_1 + m_2 and m_1 - m_2)  in order to show the model equivalence of the first and second formulations.  The actual call to lm in the R code uses the original version of the second formulation that Bratt had. So, in that case, there is nothing to back out afterwards because $m_1$ and $m_2$ are "independent"  algebraicall ( but the model is equivalent to the one I wrote where there is dependence ).
Answer: This occurs because of the properties of the hat matrix
The theoretical reason that this occurs is due to the properties of a projection matrix in linear regression called the "hat matrix".  In linear regression, the predicted response vector under OLS estimation is:
$$\hat{\mathbf{y}} = \mathbf{h} \mathbf{y}
\quad \quad \quad \quad \quad
\mathbf{h} \equiv \mathbf{h}(\mathbf{x}) \equiv \mathbf{x} (\mathbf{x}^\text{T} \mathbf{x})^{-1} \mathbf{x}^\text{T}.$$
The matrix $\mathbf{h}$ (called the "hat matrix") is a projection matrix that projects onto the column-space of the design matrix $\mathbf{x} =[\mathbf{x}_1,...,\mathbf{x}_k]$.  This column-space is the set of values:
$$\mathscr{C}(\mathbf{x}) = \bigg\{ \sum_{i=1}^k \omega_i \mathbf{x}_i \bigg| \omega_1,...,\omega_k \in \mathbb{R} \bigg\}.$$
It can easily be shown that if you make an adjustment to the design matrix by a linear transformation (with no zero weights) then the column-space is unchanged.  In your particular example, the two formulations of the explanatory variables in your two models lead to design matrices that are linear transformations of one another, and most importantly, they have the same column-space.  Because the hat matrix is a projection matrix that projects onto the column-space of the design matrix, you have the implication:
$$\mathscr{C}(\mathbf{x}) = \mathscr{C}(\mathbf{x}_*)
\quad \quad \implies \quad \quad
\mathbf{h}(\mathbf{x}) = \mathbf{h}(\mathbf{x}_*).$$
In particular, if we create a new design matrix $\mathbf{x}_* = \mathbf{x} \mathbf{A}$ using some invertable linear transformation $\mathbf{A}$ (which is a $k \times k$ matrix in the present context) then we will have $\mathscr{C}(\mathbf{x}) = \mathscr{C}(\mathbf{x}_*)$ and $\mathbf{h}(\mathbf{x}) = \mathbf{h}(\mathbf{x}_*)$ (see direct proof of the latter in the section below).
Now, in your question you use linear regression models for two different sets of explanatory variables, where the resulting design matrices are related by an invertible linear transformation.  This means that while your design matrices are different, they have the same column-space and they have the same hat matrix.  Consequently, the predicted response vector in each case is the same.

Invariance of hat matrix to invertible linear transformation of design: Suppose we create a new design matrix $\mathbf{x}_* = \mathbf{x} \mathbf{A}$ using some invertable linear transformation $\mathbf{A}$.  The hat matrix for the new design matrix is:
$$\begin{align}
\mathbf{h}(\mathbf{x}_*)
&= \mathbf{h}(\mathbf{x} \mathbf{A}) \\[6pt]
&= (\mathbf{x} \mathbf{A}) ((\mathbf{x} \mathbf{A})^\text{T} (\mathbf{x} \mathbf{A}))^{-1} (\mathbf{x} \mathbf{A})^\text{T} \\[6pt]
&= \mathbf{x} \mathbf{A} (\mathbf{A}^\text{T} (\mathbf{x} ^\text{T} \mathbf{x}) \mathbf{A})^{-1} \mathbf{A}^\text{T} \mathbf{x}^\text{T} \\[6pt]
&= \mathbf{x} \mathbf{A} \mathbf{A}^{-1} (\mathbf{x} ^\text{T} \mathbf{x})^{-1} (\mathbf{A}^\text{T})^{-1} \mathbf{A}^\text{T} \mathbf{x}^\text{T} \\[6pt]
&= \mathbf{x} (\mathbf{x} ^\text{T} \mathbf{x})^{-1} \mathbf{x}^\text{T} \\[6pt]
&= \mathbf{h}(\mathbf{x}). \\[6pt]
\end{align}$$


Is the ring $\frac{\Bbb{C}[X,Y,Z]}{(XY-Z)}$ a UFD?

Question: I think the ring $\frac{\Bbb{C}[X,Y,Z]}{(XY-Z)}$ is a UFD.
If we consider the evaluation map $f: \Bbb{C}[X,Y,Z] \rightarrow \Bbb{C}[t^2,t]$ such $f(X)=f(Y)=t$ and $f(Z)=t^2$. Then clearly $(Z-XY)$ is in $\ker f$. Now suppose $p \in \ker f$. Then considering $p$ as a polynomial is $\Bbb{C}[X,Y][Z]$, we have by division algorithm $p=q(Z-XY)+r$, where $q,r \in \Bbb{C}[X,Y][Z] $. If $r \neq 0$, then $\deg r < 1$ in $\Bbb{C}[X,Y][Z]$. So $r \in \Bbb{C}[X,Y]$. Also $f(r)=0$. Now if $r= \displaystyle{\sum_{m,n}c_{(m,n)}X^mY^n}$, then $f(r)=0 \Rightarrow r(t,t)=0 \Rightarrow \displaystyle{\sum_{m,n}c_{(m,n)}t^{m+n}}=0 \Rightarrow c_{(m,n)}=0 \,\forall \, m,n$. So $r=0$. Hence we have $\frac{\Bbb{C}[X,Y,Z]}{(XY-Z)}\approx \Bbb{C}[t^2,t]$.
Now is $\Bbb{C}[t^2,t]$ a UFD?
If so then we are done !
Comment: Your $f$ is not an isomorphism, because $Y$ and $X$ are not in the same coset of $(XY-Z)$. Instead, can you produce an isomorphism between $\Bbb{C}[X,Y,Z]/(XY-Z)$ and $\Bbb{C}[X,Y]$?
Comment: Your conclusion that all $c_{m,n}=0$ is false since different $m$ and $n$ lead to the same $t^{m+n}$. For example $X-Y$ is in the kernel of your map (in fact, the kernel is $(X-Y,Z-XY)$). Also note that $\mathbb C[t^2,t]$ is just a strange notation for $\mathbb C[t]$.
Answer: The kernel of your proposed map $\mathbb C[X,Y,Z]\to\mathbb C[t]$ with $X, Y\mapsto t$ and $Z\mapsto t^2$ is not $(Z-XY)$ but $(Z-XY,X-Y)$. However, note that dividing by $(Z-XY)$ just imposes the relation $\overline Z=\overline X\,\overline Y$ in the quotient, which effectively let's us get rid of $Z$:
Consider the ring homomorphism $g\colon \mathbb C[X,Y,Z]\to\mathbb C[X,Y]$ given by $X\mapsto X$, $Y\mapsto Y$ and $Z\mapsto XY$. This is a surjective ring homomorphism with kernel $(Z-XY)$ and hence
$$
\mathbb C[X,Y,Z]/(Z-XY) \cong \mathbb C[X,Y].
$$
For any UFD $R$, the polynomial ring $R[X]$ is a UFD as well. Since $\mathbb C$ is a UFD, so is $\mathbb C[X]$ and hence $\mathbb C[X,Y]\cong \mathbb C[X][Y]$ is a UFD as well.
Comment: Okay I get it. Thank you so much.


Inter-VLAN routing: multiple VLANs, only one should be accessible to all. Makes sense?

Question: I am trying to segment our company's network. My main goal is to have many small broadcast domains instead of a gigantic one, so I thought of assigning one VLAN per department.
However, we have many printers and a centralized file server that should be accessible to any device within the company. So, I imagine these services should belong in a separate VLAN which, in turn, would communicate with department VLANs through L3 addressing.
As we own an L3 Cisco switch, inter-VLAN routing seems to be a valid way to go. But as I am experimenting it, I am noticing that I have to assign an IP address to each VLAN interface (thus allocating each department into its own subnet) and, as soon as I allow ip routing on the L3 switch, the devices can ping not only printers or the file server, but also any other device on any other department.
I know the broadcast domain is not the same between one subnet and another, but I thought it would be more secure somehow if those VLANs could not communicate with each other.
That being said, here are my doubts on the subject:
1) For the sake of security, is it better to isolate those department VLANs in a way that they can only see the printers/files VLAN (not seeing each other)?
2) If so, what is the best way of doing it? The only feasible approach I can think of is to use ACLs, but they do not seem that practical as I would have lots of entries to handle.
Comment: Maybe you need a firewall?
Comment: Here's a phrase I like to use for questions like this: **Tilting at windmills.** You're implementing VLAN's based on vague ideas about "security" and "broadcast domains". Do you have a real problem that can be solved with VLAN's or are you simply doing this because you think you should or because someone told you that you should or because you read somewhere that you should?
Comment: I think broadcast domains hardly to be considered a vague idea. Disallowing clients to reach each other is quite hard these days that users can simply decide to use cloud services to solve their problem, it takes quite a bit of thought beyond vlans. Worst case one creates s security problem where there was none.
Comment: @Marki - to block traffic between department can be done easily with the L3 switch he already has - no need for a firewall here.
Comment: @joeqwerty I didn't go into much detail because I was afraid my question would be too extensive; maybe I oversimplified it, I don't know. Basically, I want to divide the network because of three things: 1) Limiting scope - as far as possible, issues from one department should not propagate to other departments. 2) Better tracking - just by looking at the address of a host, I could locate it. 3) Performance - right now, broadcast storms may compromise our entire network. I'm not tied to VLANs or subnetting, they were just the possible solution I could think of. Feel free to give any ideas.
Comment: @Renato - if you have 20-50 hosts, then it's probably not worth too much trouble, but if you have 200+ hosts, then by all means, break your broadcast domain with VLAN for each area.
Answer: 1) Depends on your security requirements. If your requirements are that the user PC should only be able to communicate with servers/printers, and not between PCs, then yes, you should have ACLs on the Interface VLAN to block traffic as desired. What is the most secure - well blocking everything but what is really needed is the most secure.
2) To do this you simply implement ACLs and apply the ACLs to the Interface VLAN. Since you're trying to allow PCs to Servers/Printers, your ACLs should be simple... something along the lines of:
assuming your subnets are all 10.0.0.0 and your Servers/Printers are in 10.1.1.0/24:
permit ip 10.0.0.0 0.255.255.255 10.1.1.0 0.0.0.255
deny ip any any log

That is obviously a simple version, you'll need to tweak from there to obtain the exact result desired. With this example, you can apply that to all your PC VLAN Interfaces as it is written in a generic way that will work for all your VLANs.
You can find another example of this in another question which I answered last week: Keep router interfaces isolated
Comment: Is your proposal to solve all internet access through proxies?
Comment: @ErikE - Not particularly as there were no mention of Internet in the OP question. He is trying to block traffic between departments. But having all Internet traffic through proxy is something I would recommend yes to better control what is allowed out for security reasons - if just to get some logs.
Comment: Thank you for the answer. The ACL syntax did clarify things a bit. As for the first point, I haven't elaborated security requirements - mostly due to lack of knowledge. What would you say are possible threats of letting all the devices communicate with each other through the network layer? In your opinion, is it worth it to block communication between sections of an organization?
Comment: @Renato - it's hard to say without knowing more the type of business, size of network, other security measures on your machines. But take this example, Virus Infected Machine A starts hitting all your machines through an open RPC connection and spreads... well if you block traffic between your department, you'll at least mitigate this. What if you have security requirements on documents and you find that Joe in Dept A is a wiseass and set himself up to be able to VNC to all other departments... you could block that, etc.
Answer: This is a very common situation and unfortunately the initial response should not be technical. Inter-Vlan routing is fine if it works for your company. Yes there are possible security and performance issues but do you have the staff to manage the requirements if you lock your systems down?
As long as you have designed your network properly you should be able to secure inter vlan routing and limit the changes necessary after the fact. And just like you said, by securing your vlan you are reducing your security risk, improving performance, and enabling you to put controls in place to track IP's and devices.


Need help understanding Hilbert's Nullstellensatz (weak version)

Question: The theorem is stated in my lecture notes as follows:
Every proper ideal $\mathcal{a}$ of $k[x_1 , \dots , x_n]$ admits a point in $V(\mathcal{a};l)$ over some algebraic field extension l/k. In particular, if $k$ is algebraically closed, then $l=k$.
I am having a hard time understanding this last part.
For example, let $k = \mathbb{C}$, let $S = \{ x^2 + 1 , x^2 - 1 \} \subset \mathbb{C}[x]$, and let $a_S$ be the ideal generated by $S$. In this case, $\mathbb{C}$ is algebraically closed, so the theorem says there should be a point in $\mathbb{C}$ satisfying both $x^2 + 1$ and $x^2 - 1$. However, these polynomials have no common roots.
Where am I going wrong here?
Comment: $a_S=(1)$ is not a proper ideal.
Comment: The ideal generated by $x^2+1$ and $x^2-1$ is not proper unless $\operatorname{char}k=2$, in which case $1$ is a common root.
Answer: The ideal $a_S$ contains $x^2+1$ and $x^2-1$, so it contains $1=\frac{1}{2}((x^2+1)-(x^2-1))$ and hence $a_S = \mathbb{C}[x]$ is not a proper ideal, so the theorem (as stated) doesn't apply.
In this case (where the ideal is the whole ring), points in $V(\mathbb{C}[x],\mathbb{C})$ are also solutions to the equation $1=0$ (by the above expression for $1$), so there are no points: $V(\mathbb{C}[x],\mathbb{C}) = \varnothing$.


Is it possible to programatically create a xaml page?

Question: I might write no sense on the next lines:
I tried to derive a struct named mainpage from winrt::Windows::UI::Xaml::Controls::Page and pass it to winrt::xaml_typename<>(), in "<>" is mainpage.
It will be understandable when you look at the code:
Point number 1 "(1)" is the mainpage.h file, is very short.
Point number 2 "(2)" is the App.cpp file, it only has the necessary.
//(1) mainpage.h

#pragma once

#include "pch.h"

struct mainpage : winrt::Windows::UI::Xaml::Controls::Page
{
    mainpage() {

        winrt::Windows::UI::Xaml::Controls::Button thebutton = winrt::Windows::UI::Xaml::Controls::Button();
        thebutton.Click([&](const IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& event_arg)
        {
            thebutton.Content(winrt::box_value(L"Clicked"));
        });
    }
};

//(2) App.cpp

#include "pch.h"
#include "mainpage.h"

struct App : winrt::Windows::UI::Xaml::ApplicationT<App>
{
    void OnLaunched(const winrt::Windows::ApplicationModel::Activation::LaunchActivatedEventArgs& event_arg)
    {
        winrt::Windows::UI::Xaml::Controls::Frame root_frame{ nullptr };
        winrt::Windows::UI::Xaml::UIElement content = winrt::Windows::UI::Xaml::Window::Current().Content();
        if (content)
        {
            root_frame = content.try_as<winrt::Windows::UI::Xaml::Controls::Frame>();
        }

        // Do not repeat app initialization when the Window already has content,
        // just ensure that the window is active
        if (root_frame == nullptr)
        {
            // Create a Frame to act as the navigation context and associate it with
            // a SuspensionManager key
            root_frame = winrt::Windows::UI::Xaml::Controls::Frame();

            root_frame.NavigationFailed({ this, &App::OnNavigationFailed });

            if (event_arg.PreviousExecutionState() == winrt::Windows::ApplicationModel::Activation::ApplicationExecutionState::Terminated)
            {
                // Restore the saved session state only when appropriate, scheduling the
                // final launch steps after the restore is complete
            }

            if (event_arg.PrelaunchActivated() == false)
            {
                if (root_frame.Content() == nullptr)
                {
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    root_frame.Navigate(winrt::xaml_typename<mainpage>(), box_value(event_arg.Arguments()));
                }
                // Place the frame in the current Window
                winrt::Windows::UI::Xaml::Window::Current().Content(root_frame);
                // Ensure the current window is active
                winrt::Windows::UI::Xaml::Window::Current().Activate();
            }
        }
        else
        {
            if (event_arg.PrelaunchActivated() == false)
            {
                if (root_frame.Content() == nullptr)
                {
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    root_frame.Navigate(winrt::xaml_typename<mainpage>(), box_value(event_arg.Arguments()));
                }
                // Ensure the current window is active
                winrt::Windows::UI::Xaml::Window::Current().Activate();
            }
        }
    }
    void App::OnNavigationFailed(const IInspectable&, const winrt::Windows::UI::Xaml::Navigation::NavigationFailedEventArgs& event_arg)
    {
        throw winrt::hresult_error(E_FAIL, winrt::hstring(L"Failed to load Page ") + event_arg.SourcePageType().Name);
    }
};

int __stdcall wWinMain(HINSTANCE, HINSTANCE, PWSTR, int) {
    winrt::Windows::UI::Xaml::Application::Start([](auto &&) { winrt::make<App>(); });
}

If it is not possible, how can I properly create a page?
Answer: It is simple if you have installed the CppWinRT VSIX. Then create a "View model" and edit the files. You shouldn't derive the struct from the winrt::Windows::UI::Xaml::Controls::Page class because winrt::xaml_typename<> needs a WinRT class in <>.


How can I get the most recent file from a directory?

Question: cached_folder = os.path.expandvars(r'%APPDATA%\Microsoft\Windows\Themes\CachedFiles\*')
list_of_files = glob.glob(cached_folder)
latest_file = max(list_of_files, key=os.path.getctime)

I just want the path of the most recent file in CachedFiles although this doesn't work and list_of_files is an empty list.
What am I doing wrong here?
Comment: Did you verify that `%APPDATA%\Microsoft\Windows\Themes\CachedFiles` is not actually empty? The code you posted worked for me
Answer: The code below (essentially wrapping your code) worked for me.
You may have an empty
%APPDATA%\Microsoft\Windows\Themes\CachedFiles.
#!/usr/bin/env python

def main():
    import os, glob
    cached_folder = os.path.expandvars(r'%APPDATA%\Microsoft\Windows\Themes\CachedFiles\*')
    list_of_files = glob.glob(cached_folder)
    print( list_of_files )
    latest_file = max(list_of_files, key=os.path.getctime)
    print( latest_file )
    return

if (__name__ == '__main__' ) :
    main()


Can't save file on webserver: System.UnauthorizedAccessException

Question: I can't save a file on my webserver with FileUpload.SaveAs() or with File.WriteAllText(). The folder I save in is CHMOD 666.
My code is this:
File.WriteAllText(MapPath(".") + "\\Ads\\test.jpg", "test");
This code works perfectly in Dev. server.
Best regards,
Lasse Espeholt
System.UnauthorizedAccessException: Access to the path *' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at System.Web.HttpPostedFile.SaveAs(String filename)
at System.Web.UI.WebControls.FileUpload.SaveAs(String filename)
at *(Object sender, ListViewInsertEventArgs e)
Comment: Access to the path *' is denied - is this an actual error or you removed the path from exception?
Answer: You will need to give read write permissions to machine's ASPNET account for desired folder.
You can do it by opening folder properties -> security tab.
Comment: I have used your comment and displayed it to the webadmin. Now it works thanks :)
Answer: Your error message states:
System.UnauthorizedAccessException: Access to the path *' is denied.

This looks a little odd. Have you edited the path or is that exactly how it's displayed? If the latter then something is going wrong with your call to MapPath.
I know the following may seem obvious, but I've been bitten by assumptions too many times in the past.
Have you verified that the folder you think you're writing to is the one that MapPath(".") + "\\Ads\\test.jpg" actually resolves to?
Do you have full rights to the "Ads" sub folder as well?
Comment: I hided the path for security reasons :)


Coherence for symmetric monoidal categories

Question: Let $\mathcal{C}$ be a monoidal category. By Mac Lane's coherence theorem for monoidal categories, there are strong monoidal functors $F : \mathcal{C} \to \mathcal{C}_s$ and $G : \mathcal{C}_s \to \mathcal{C}$ such that $\mathcal{C}_s$ is a strict monoidal category and $(F, G)$ form an equivalence of categories. [CWM, Ch. XI, §2] Informally, this tells us that we may pretend that the associators $\alpha$ and unitors $\lambda, \rho$ are identity arrows rather than mere isomorphisms.
My question concerns the analogue for symmetric monoidal categories: suppose $\mathcal{C}$ has a braiding
$$\gamma_{a, b} : a \otimes b \to b \otimes a$$
such that $\gamma_{b, a} \circ \gamma_{a, b} = \textrm{id}$, and suppose it is compatible with the monoidal structure making $\mathcal{C}$ into a symmetric  monoidal category.

Does $F \gamma$ make $\mathcal{C}_s$ into a symmetric monoidal category?
Assuming that (1) is true, do "all" diagrams involving $\gamma$ with atomic subscripts commute in $\mathcal{C}_s$? More precisely, let $\sigma$ be a permutation on $k$ letters, and suppose that $\sigma = \tau_1 \cdots \tau_m = \tilde{\tau}_1 \cdots \tilde{\tau}_n$ for some transpositions $\tau_i$, $\tilde{\tau}_j$ of adjacent pairs; does the equation $\tau_1 \cdots \tau_m = \tilde{\tau}_1 \cdots \tilde{\tau}_n$ still hold true when I interpret $\tau_i$ and $\tilde{\tau}_j$ as the corresponding braiding operation?
For example,
$$(1 \, 2 \, 3) = (1 \, 2) (2 \, 3) = (2 \, 3) (1 \, 2) (2 \, 3) (1 \, 2)$$
so I expect that
$$(\gamma_{a, c} \otimes \textrm{id}_b) \circ (\textrm{id}_a \otimes \gamma_{b, c}) = (\textrm{id}_a \otimes \gamma_{b, c}) \circ (\gamma_{a, b} \otimes \textrm{id}_c) \circ (\textrm{id}_a \otimes \gamma_{b, c}) \circ (\gamma_{a, b} \otimes \textrm{id}_c)$$
which is indeed correct.
Let $a = a_1 \otimes \cdots \otimes a_n$, $b = b_1 \otimes \cdots \otimes b_m$. Let $\sigma$ be the permutation
$$(a_1, \ldots, a_n, b_1, \ldots, b_m) \mapsto (b_1, \ldots, b_m, a_1, \ldots, a_n)$$
Assuming (2) holds, let $\gamma_\sigma : a \otimes b \to b \otimes a$ be the morphism corresponding to the permutation $\sigma$. Then, is it true that $\gamma_{b, a} = \gamma_\sigma$?
For example, take $n = 2$, $m = 1$. I expect it to be true that
$$\gamma_{a \otimes b, c} = (\gamma_{a, c} \otimes \textrm{id}_b) \circ (\textrm{id}_a \otimes \gamma_{b, c})$$
and this turns out to be an instance of the hexagon axiom, in the special case of a strict monoidal category. But what if $n > 2$ or $m > 1$?
Does this imply that "all" diagrams involving $\alpha, \lambda, \rho, \gamma$ commute in $\mathcal{C}$?

I suspect that the answers to all the questions are yes, at least if I understood Mac Lane [CWM, Ch. XI, §3] correctly, but I haven't found an explicit statement of the implied coherence theorem for symmetric monoidal categories. (There is an obvious way of defining a "free symmetric strict monoidal category" generated by another category, and I imagine there is some way of defining a "free symmetric monoidal category"; the coherence theorem ought to state that the two are equivalent via strong braided monoidal functors.)
Answer:
Yes. By functoriality and strong monoidality, $F\gamma$ must satisfy the symmetry axioms.
This is precisely the statement of coherence for SMC's. Mac Lane gives the braided version at the end of XI.5. Note, however, that this does not imply that "all" diagrams of the correct type commute. Only those corresponding to the same element of the symmetric group.
The fact that you say "the" symmetry map corresponding the given permutation is already a consequence of coherence for SMC's. All symmetry maps corresponding to the given permutation (including $\gamma_{a,b}$) are equal.
Nope, c.f. #2. In fact, the "all diagrams commute"-type coherence theorem is quite atypical. Most monoidal categories with extra structure have a coherence theorem more along the lines of "this is how to (efficiently) decide which diagrams commute: (...)".


Retrieve links from XMLNodeList

Question: how to get the links from these nodes:
script <- getURL("www.r-bloggers.com")
doc <- htmlParse(script)
li <- getNodeSet(doc, "//ul[@class='xoxo blogroll']")

thanks in advance for any hints.
Answer: You can extract the a elements and call xmlGetAttr on them.
library(RCurl)
library(XML)
script <- getURL("www.r-bloggers.com")
doc <- htmlParse(script)
li <- getNodeSet(doc, "//ul[@class='xoxo blogroll']//a")
sapply(li, xmlGetAttr, "href")

You can also use xpathApply directly:
xpathSApply(doc,
  "//ul[@class='xoxo blogroll']//a",
  xmlGetAttr, "href"
)

Retrieve links from XMLNodeList


redirect to a page if response.redirect fails

Question: I have a response.redirect(url) which goes to another site.
In the event this fails, how should I redirect again to a redirect fail page?

The request is being sent from the code behind an aspx page.
I have an httpmodule in place. Can it be used?
Comment: The initial redirect goes to a completely different site, or just another page on your application?
Answer: response.redirect(url) tells browser to request the "url" so you can not control if this url call is failed in browser.
What you can do is do a HTTP GET HEAD to that url first to see if you get http 200 response and then do a response.redirect(url).
Comment: Nitpick: rather than performing an HTTP GET, consider performing an HTTP HEAD instead and save yourself some bandwidth - http://stackoverflow.com/questions/830435/how-to-check-if-a-file-exists-on-a-server-using-c-and-the-webclient-class
Comment: agreed.  If the new page is on a different server outside of the OP's control then the only way to do this is first test if that server is available then decide whether to redirect or not
Comment: @Chris - So, regardless of the client and server (normally) having completely different networks and see the web differently, a check on the server side would mean something on the client side?
Comment: @Oded: As you're attempting to point out, it is entirely possible that the server does indeed see things differently.  This could be the case if the server is locked down from making external requests or if the network it is on is configured in such a way that certain sites are blocked.  Both of which are possible and even likely.  If this is the case then this answer would utterly fail.  However, if it is sufficiently important to be able to perform this action then I'd hope the OP (and perhaps his/her boss) could cajole the net admins into allowing those outbound requests.
Comment: @Nitpick yes http head makes more sense for bandwidth usage.
Answer: This doesn't make much sense - if a redirect fails, how will the server ever find out?
A redirect tells the browser to go to a different page - if this fails, it fails on the browser and the server has no way to know about it.
Comment: Not true completely. You can catch it and redirect in the catch. I think the problem is how to tell it to redirect without "Response" because the object is null.


Automatizar a criação de números em um loop no R

Question: Os algarismos após ^ (1, 2 e 3) são os valores que desejo automatizar (de forma crescente: do 1 ao i-ésimo valor):
var1<-rnorm(3,5000,1300)/1.15^1
var2<-rnorm(3,5000,1300)/1.15^2
var3<-rnorm(3,5000,1300)/1.15^3

Mas, automatizar dentro de um loop for:
for(i in 1:10){
name<-paste0('var',i)
assign(name,rnorm(3,5000,1300)/1.15^1)
}

Como inserir esta automatização no loop for e evitar escrever uma função por vez?
Comment: Não é simplesmente substituir `1.15^1` por `1.15^i`?
Answer: Uma resposta foi dada pelo @Marcus Nunes no campo de comentários. A expressão fica, então:
for(i in 1:10){
    name <- paste0('var', i)
    assign(name, rnorm(3, 5000, 1300)/1.15^i)
}

Answer: Quando se têm vários objetos semelhantes, a regra geral é tê-los numa list. Em vez de ter n (neste caso 10) objetos no .GlobalEnv tem-se só um.
Para criar essa list não é necessário um ciclo for, pode ser feito com lapply.
var_list <- lapply(1:10, function(i) rnorm(10, 5000, 1300)/1.15^i)
names(var_list) <- paste0("var", 1:10)
var_list

Isto tem a vantagem de, como têm todos o mesmo comprimento, os podermos transformar em vetores coluna de uma matriz,
mat_var <- do.call(cbind, var_list)
mat_var

ou de uma data.frame.
df_var <- do.call(cbind.data.frame, var_list)
df_var

Depois podem-se usar as funções R que operam sobre tabelas.


Meu index está dando um retorno de Undefined variable: imagem

Question: Criei meu index assim só que está me retornando um erro na view para eu conseguir obter a imagem : Undefined variable: imagem (View: /var/www/html/fernandosite/resources/views/admin/marcadaguas/index.blade.php)

      @foreach($imagem as $image)

              {{ $image->id }}

              imagem}}" class="rounded img-fluid" style="height: 50px;">

        @endforeach

e no meu controller está assim o index:

public function index()
    {
        return view('admin.marcadaguas.index')->with('imagem', Marcadagua::all());
    }

No meu store está assim:

public function store(Request $request)
    {

        $this->validate($request,[
            'imagem' => 'required|image',
            'perfil' => 'required|image',
            'logomarca' => 'required|image',
            'nome' => 'required',
        ]);

        $imagem = $request->file('imagem');
        $filename = time() . '.' . $imagem->getClientOriginalExtension();

        $perfil = $request->file('perfil');
        $filename = time() . '.' . $perfil->getClientOriginalExtension();

        $logomarca = $request->file('logomarca');
        $filename = time() . '.' . $logomarca->getClientOriginalExtension();

        $nome = $request->nome;

        $imagem = Image::make($imagem)->fit(1080,720);
        $perfil = Image::make($perfil)->fit(140,140);
        $logomarca = Image::make($logomarca)->fit(140,140);

        Image::make($imagem)->insert($perfil, 'top-left', 0,15)->insert($logomarca, 'bottom-left', 0,5)->insert(public_path('marcadagua/principal.png'), 'bottom-left', 0, 0)
        ->text($nome, 70, 170, function($font) {
            $font->file('marcadagua/RobotoCondensed-Bold.ttf');
            $font->size(15);
            $font->color('#2BB7C4');
            $font->align('center');
            $font->valign('top');
        })->save('uploads/posts/' . $filename );

       $imagem = Marcadagua::create([
        'imagem' => 'uploads/posts/' . $filename,

        ]);

        Session::flash('success', 'Post criado com sucesso.');

        return view('admin.marcadaguas.index');
    }
Answer: Sua função store não está enviando nenhuma variável chamada imagem para sua view.
Tente retornar a rota para seu controller acessando a função index no final da sua função store, algo parecido com:
    public function store(Request $request){
       ...
       return route(rota.para.index.controller);
    }


Showing that $U + V \mod 1$ is also a $U(0,1)$

Question:
Let $U$ and $V$ be independently distributed random variables from the uniform distribution $U(0,1)$.
a.) Show that $U + V \mod 1$ is also $U(0,1)$.
b.) A random number generator is defined by $$R_n = \left(\frac{X_n}{8} + \frac{Y_n}{7}\right)\mod 1$$ where $X_0 = 0$, $Y_0 = 1$, $X_{n+1} = (9X_n + 3)\mod 8$, and $Y_{n+1} = 3Y_n \mod 7$ for $n = 0,1,\ldots$ Calculate $R_0, R_1,\ldots, R_5$. What is the period of the generator $\{R_n\}$.

Thoughts for a.) I have proved that if $U,V\sim U(0,1)$ then $U + V\sim U(0,1)$ in a probability theory and Statistical Inference course but I am not sure if that proof would apply when we the $\mod 1 $ operator.
Attempted solution b.) We have $$R_0 = \left(\frac{X_0}{8} + \frac{Y_n}{7}\right)\mod 1 = \frac{1}{7}\mod 1 = \frac{1}{7}$$ and $$R_1 = \frac{45}{56}$$ etc... What I do not understand in this question is what the question means by asking what is the period of the generator $\{R_n\}$?
Any suggestions in the latter above are greatly appreciated.
For the convolution:
Let $U\sim U(0,1)$ and $V\sim(0,1)$. Now, set $Z = U + V$. So we have $$f_{U}(t) = f_{V}(t) = \begin{cases}
1 \ &\text{if} \ t\in (0,1)\\
0 \ &\text{otherwise}
\end{cases}$$
Thus $$f_{Z}(t) = \int_{0}^{1}f_{U}(t-v)f_{V}(v)dv$$
so the convolution of $Z$ is $$f_{Z}(t) = \begin{cases}
t \ &\text{if} \ t\in [0,1]\\
2-t \ &\text{if} \ t\in (1,2)
\end{cases}$$
Comment: It's not true that if $U,V\sim U(0,1)$ then $U+V \sim U(0,1)$
Answer: For a) you calculate convolution $Z=X+Y$ like here.
Then for $t\in (0,1)$:
$$P(X+Y\pmod{1}\le t)=P(Z\le t)+P(1\le Z\le 1+t)=\int_0^t zdz+\int_1^{1+t}(2-z)dz\\=\frac{t^2}{2}+t-\frac{t^2}{2}=t$$
which is the CDF of a random variable distributed Uniform$(0,1)$
What you said [that $X+Y\sim\text{Uniform}(0,1)$], is not correct.
For b)
To find the period of $R_n$ means to find smallest positive integer $k$ such that $R_{n+k}=R_n$
You might note that: $R_n=\frac{(7X_n+8Y_n)\pmod{56}}{56}$
so you might see that
$$R_n=R_{n+k}\\
\iff (7X_n+8Y_n)\pmod{56}=(7X_{n+k}+8Y_{n+k})\pmod{56}\\
\iff 7(X_n-X_{n+k})+8(Y_n-Y_{n+k})\equiv 0\pmod{56}$$
So $8|X_n-X_{n+k}$ and $7|Y_n-Y_{n+k}$ which happens when $X_n=X_{n+k}$ and $Y_n=Y_{n+k}$
Now the first terms of $X_n$ are $0,3,6,1,4,7,2,5,0,\ldots$ (period $8$)
The first terms of $Y_n$ are $1,3,2,6,4,5,1,\ldots$ (period $6$)
So the period of $R_n$ is $\text{lcm}(6,8)=24$
Comment: I see, so we have that $X\sim U(0,1)$ and $Y\sim (0,1)$ then we let $Z = X+Y$ and prove that $Z\sim U(0,1)$ and in doing so we have for $t\in (0,1)$ we calculate the integral you have there and since it equals $t$ we have proved that $Z\sim (0,1)$ since $t\in (0,1)$?
Comment: Yes, that is correct.
Comment: I still don't really understand what we need to do for part a.). Could you provide more detail. The link you provided does not make much sense to me
Comment: Also, I am not familiar with what $8|X_n - X_{n+k}$ and $7|Y_n - Y_{n+k}$ means, can you clarify?
Comment: means that "$8$ divides $X_n-X_{n+k}$"
Comment: For the convolution you may take a look [here](https://www.youtube.com/watch?v=NMjL5F2qfvc). If your background is engineering, you might look [here](https://www.youtube.com/watch?v=3iIPvdmUegM) as well.
Comment: Thanks Ill see if that helps
Comment: Last question what does $R_n$ is $1cm(6,8) = 24$ mean?
Comment: "least common multiplier". And it is about the period $k$ of $R_n$, not about $R_n$ itself.
Comment: I am going to post what I think the solution for the convolution is. Could you check if I am getting it right or if it is thorough enough?
Comment: Yes, that is correct. The crux is to get the integration limits right.
Comment: Could you take a look at this: http://math.stackexchange.com/questions/2128248/goodness-of-fit-tests-for-uniform-distribution-computing-d-n


Obtain dimension of multivariate polynomial quotient ring?

Question: Let $\mathbb{C}[z_1,z_2,...,z_n]$ be the ring of multivariate polynomials in the variables $z_1,z_2,...,z_n$ with complex coefficients. This ring is spanned by the countably infinite basis of monomials
$$e_{i_1,i_2,...,i_n}=z_1^{i_1}z_2^{i_2}\cdots z_n^{i_n}$$
for $i_j=0,1,2,...$ where $j\in\{1,2,...,n\}$.
Next, consider taking the quotient ring of $\mathbb{C}[z_1,z_2,...,z_n]$ by an ideal of $n$ known multivariate polynomials $\langle p_1,p_2,...,p_n\rangle$ in variables $z_1,z_2,...,z_n$ with complex coefficients:
$$Q=\frac{\mathbb{C}[z_1,z_2,...,z_n]}{\langle p_1,p_2,...,p_n\rangle}.$$
If $Q$ turns out to have finite dimension, in the sense that it is spanned by a finite subset of monomials $e_{i_1,i_2,...,i_n}$ (not known explicitly), how does one then compute the dimension of $Q$ in general? In other words, how does one compute the overall number of linearly independent $e_{i_1,i_2,...,i_n}$ that are a basis of $Q$?
Comment: In general of course this is difficult. But, if in addition you had the $p_i$s to be homogeneous, then Bezout's theorem will tell you that the dimension is just the product of the degrees of the $p_i$.
Comment: So basically, what you are saying is that one should first reduce the ideal to a Groebner basis, eliminate all but one variable, and then treat the remaining univariate quotient ring as shown in this link? http://www.maths.manchester.ac.uk/~pas/code/notes/part13.pdf
Comment: Which would mean that the number of linearly independent monomials would be equal to the degree of the single variable (highest degree) polynomial in the Groebner basis?
Comment: Well, this is an interesting question, firstly, We need to note that The Provided ideals are of $\mathbb{C}[z_1,...,z_n]$ Next you can proceed by induction. In case $ n=1$ it's deg $p_i$ in case $n=2$ the given set $Q_2$ is you will and element is of the form $f(z_1,z_2)+a(z_1,z_2)p_1(z_1,z_2)+b(z_1,z_2)p_2(z_1,z_2)$ you can guess that it's $A_2=\max (\deg{p_i})_{i=1}^{2}$  Now induct. In case I am not forgetting the definition of ideal generated by $$ the answer should be $A_n$ where $A$ indexed defines corollary as before as $A_2$
Comment: I am answering this question wait a bit,  Let me think it more properly.
Answer: The ideal $\langle p_1,p_2,...,p_n\rangle$ can be equivalently expressed in terms of the corresponding Groebner basis $G$. In the following we consider the special case where the polynomials $\langle g_1,g_2,...,g_n\rangle$ of the Groebner basis have the following structure:
$$g_1=z_1-P_1(z_n)\\g_2=z_2-P_2(z_n)\\\vdots\\g_{n-1}=z_{n-1}-P_{n-1}(z_n)\\g_n=P_n(z_n)$$
where $P_i(z_n)$ for $i\in\{1,2,...,n\}$ are certain polynomials in the single variable $z_n$, while we assume that $z_n$ is the highest weight variable in the employed monomial ordering.
On the support of the ideal $\langle g_1,g_2,...,g_n\rangle$ we have the simultaneous condition $g_i=0$ for all $i\in\{1,2,...,n\}$. Therefore, $g_1$ through $g_{n-1}$ can be used to eliminate the variables $z_1$ through $z_{n-1}$ in the quotient ring $Q$, producing a new, equivalent, but effectively univariate quotient ring
$$Q\rightarrow Q'=\frac{\mathbb{C}'[z_n]}{\langle g_{n}\rangle}$$
In the univariate case, it is well known that for a quotient ring with an ideal containing a single polynomial of degree $m$, a minimal basis is spanned by the set of univariate monomials $e_i=z_n^{i-1}$ for $i\in\{1,2,...,m\}$ (see i.e. proposition 28 here). Therefore, $Q'$ has dimension $\dim_{\mathbb{C}}(Q')=m$, and by equivalence the same is true for $Q$:
$$\dim_{\mathbb{C}}(Q)=\dim_{\mathbb{C}}(Q')=\deg(P_n(z_n))=m$$
Due to the above, it seems that in order to obtain the dimension of a multivariate quotient polynomial ring over a zero dimensional ideal, one has to determine the degree of the univariate equation in the Groebner basis for the polynomial ideal (if the Groebner basis satisfies the structure above). Which can be rather difficult to compute. But conceptually, this should be a possible way to go about. Any objections anyone?
Comment: A groebner basis of the form you describe can only exist if the function mapping a point of the zero set of the ideal to its last coordinate is injective, and it is easy to find examples of ideas for which this does not work for any ordering of the components.
Comment: Why would a Groebner  basis have that form?
Comment: @MarianoSuárez-Alvarez because per definition a Groebner basis always exists that linearizes the relation between all but one variable to the highest weight variable. That is the whole purpose of computing a Groebner basis in the first place, as far as I know.
Comment: @MarianoSuárez-Alvarez admittedly, this point is not always made completely clear. Take the example on page 2 in http://people.math.umass.edu/~norman/462_11/notes/m462notes13.pdf for instance. What they claim to be the minimal Groebner basis can actually still be reduced to just $g_1=y^3$ and $g_2=x-2y^2$, which displays the structure claimed above (in a different variable weight order). I know its just an example, but I don't seem to be able to track down a general reference right now.
Comment: Oh, I did not know this! Sorry about that. I will edit the answer to emphasize this point.


How to control red noise generator by another one (Rocket engine effect - Subtractive synthesis of sound)

Question: I am programming some sound effects in Java and exporting them into .wav files. Currently, I am trying to program a rocket engine sound effect. I want to do it in the following way:
The sound of a rocket engine may be synthesized with a red noise generator controlled by a second red noise generator. The parameter of the first generator modified by the second one is the number of interpolated samples, influencing the spectral content of the generated noise. In order to simulate changes of sound intensity (e.g. during launch) the envelope generator should be used.
I am wondering how can it be done, e.g. what does it mean that one signal controls another one. Probably this part is explaining it, but I am not sure what to do now:

The parameter of the first generator modified by the second one is the
  number of interpolated samples, influencing the spectral content of
  the generated noise.

Is it about this parameter describing how many values from white noise are taken and linearly interpolated while creating the red noise? (see my simple drawing explaining this process below)

I have a red noise generator, which returns an array of doubles with values between -1 and 1 (it is generated from the white noise as described). What am I supposed to do now? How can I control the second red noise? I guess that it does not mean that I should control the amplitude of the second signal. Does it?  Schema of steps required to obtain the rocket engine sound effect is attached below.
Comment: I understood that you are supposed to read an integer N from the controller noise generator, read the next output O_2 from the second noise generator and interpolate N output samples from O_1 to O_2, where O_1 is the previous output from the second noise generator.
Comment: The [tag:processing] tag should only be used for questions about the Processing language.
Comment: Correction: I refer to the first generator in the original text misleadingly as the second noise generator in my comment.
Comment: You can visualize the method as generating a waveform by connecting straight lines one after the other. The next endpoint's time and amplitude are both chosen at random, as long as time > previous time. Every line can span any number of sample frames.
Answer: I have already solved this problem:
I have a white noise generated as an array of doubles:
public static double[] whiteNoise(int length) {
    double[] out = new double[length];
    for (int i = 0; i < length; i++) {
        out[i] = (Math.random() * 2 - 1.0)/2.0;
    }
    return out;
}

I obtain the red noise from the white noise in the following way:
public static double[] redNoise(int length, int m) {
    double out[] = whiteNoise(length);

    for (int i=0; i<length/m-1; i++) {
        int k = i*m;
        int l = ((i+1)*m <= length-1) ? (i+1)*m : length-1;
        double d = (out[l] - out[k])/((double)(m));
        for (int j=0; j<m; j++) {
            out[k+j] = out[k] + d*j;
        }
    }
    return out;
}

Where the m parameter is the number of interpolated samples (we take the first sample, and the m+1 sample, and interpolate values of all samples between these two).
And now the SHOW BEGINS
I generate the red noise with the interpolation number equals to let's say 10000. According to the value of consecutive samples, I alter this red noise with different values obtained from these samples taken as the interpolation number parameter. In this way a rocket sound effect is obtained.
int interpolatedframes = 10000;
    double[] rednoise1 = SigGen.redNoise(duration, interpolatedframes);
    while(i<rednoise1.length-1)
    {
        selectedNumber = (int)Math.floor(Math.abs((100*(rednoise1[i]+0.5)+100)));
        if(i+selectedNumber < rednoise1.length-1) {
            rednoise1 = SigGen.alterRedNoise(rednoise1, i, selectedNumber);
        }
        else
        {
            break;
        }
        i+=selectedNumber;
    }

With the following code the array with the noise is altered in a way, that it interpolates "interpolationNumber" of samples beginning from the startingIndex.
public static double[] alterRedNoise(double[] input, int startIndex, int interpolationNumber)
{
        int k = startIndex;
        int l = ((startIndex + interpolationNumber)<input.length-1?(startIndex+interpolationNumber):input.length-1);
        double d = (input[l] - input[k])/((double)(interpolationNumber));
        for (int j=0; j<interpolationNumber; j++) {
            input[k+j] = input[k] + d*j;
        }
    return input;
}

Sorry for a bit messy code, but I just wanted to publish it ASAP.
#EDIT 1
The sound which is supposed to be generated is the sound of a rocket being launched. Take a look at this movie (maybe from 1:45): https://www.youtube.com/watch?v=OnoNITE-CLc
To have the effect of the rocket flying over, an envelope generator might be used. It can be implemented as a simple multiplication of the samples obtained from the described method in such way, that it will be gradually suppressed.


Probability of drawing no red balls from 20 draws without replacement given finite sample

Question: I understand this to be a binomial distribution: There are 100 balls in a bucket. 10 are red, 90 are blue. I select a ball at random and then replace it in the bucket, and I do this 20 times. I then calculate the probability that none of the selected balls were red.
But what if I don't put the ball back in the bucket? The probability then changes with each trial. Can anyone point me in the right direction of how to calculate the probability in this case?
Answer: Let $B$ denotes blue balls, $R$ denotes red balls, then you may apply the formula for hypergeometric distribution:
$$P(B = 20, R = 0) = \frac{\binom{10}{0}\binom{90}{20}}{\binom{100}{20}} = \frac{\binom{90}{20}}{\binom{100}{20}}$$
The last term exactly matches the @Macro's answer, but hypergeometric formula is more general. The idea beyond the formula is simple: get the number of ways to draw $20$ $B$ of $90$, number of ways to draw $0$ $R$ from $10$ (there is only one possibility) and divide their product by the number or ways to draw any $20$ balls from $100$. Hope this was not your homework ;)
Comment: perfect! not homework ;-) I just came up with the ball question to remove the distractions from the problem I'm actually working on
Answer: Well, on the first try, you have a $90/100$ probability of not drawing a red ball; if the first was not a red ball, then on the second try there are still 10 red balls left, but only 99 to choose from, so you have a $89/99$ chance of not drawing a red ball. Similarly, on the third draw, if the second draw was also not a red ball, then you have a $88/98$ chance of picking a red ball, and so on. In general, if you attempt $k$ times independently without replacement, the probability you seek is
$$ \prod_{i=1}^{k} \frac{ 90-i+1 }{100-i+1} $$
One important thing to note is that this probability actually doesn't arise from a binomial distribution. You are not conducting independent trials with equal probability and counting the number of "successes". The trials are not independent because the success probability of a future trial depends on whether a past trial was a success, making it fundamentally different from the binomial distribution. If there was replacement, then you'd be correct in saying the number of success follows a binomial distribution.
Comment: ahh the fundamental difference had escaped me, thanks!


Conclusion of my logistic regression with interaction terms

Question: I ran a logistic regression, all assumptions checked and so on, and I have two models with four predictory variables predicting one dependent. In my first model I just check the variables themselves, and only variable 2 is significant. In my second model I include all possible interaction terms between my four predictors and now one of these interactions becomes significant.
For my conclusion, do I just show the odds ratios of the models separately? And how do I explain the significant interactions in words? I understand that for variables I can say: This variable has a significant effect and its odds ratio is Exp(B) so we can see that category 1 occurs 3 times as probable as category 2 for instance. But how do I say this for interaction terms that are significant with their odds ratios?
Thanks if anyone could help me and happy holidays guys!
Answer: Follow up question: If your interactive term is significant, how did you assess this? If you are just using the P-value, you may wish to use a likelihood ratio test to determine which model is a better fit.
If the likelihood ratio test reveals that your interactive model is a better fit, you would report the odds ratios for each level of the interactive term in question. You may wish to report the odds ratio for the non-interaction model, but this will depend on your research question. Generally, you should only be concerned with the interaction, not the crude value without interaction, as by definition the crude value would be misleading.
So to summarize, report the odds ratios at each level of the interaction. Additionally, the odds ratio will still be compared to your reference group, not to other positively coded values in the interaction, so be careful in saying this category occurs x times more than this category. Hope this helps.


How to trigger email, account/user and order creation actions when payment is made in paypal, not when user is redirected back

Question: I have read many discussions of this sort, but just couldn't get my head around this issue.
I am testing my site locally and using paypal WPS as my module to process payments. As default, when my users are directed to paypal and makes the payment, they are not re-directed back to my site unless they click one of the paypal links to be redirected back and as a result no user account is created, no order is recorded and no order/welcome emails are fired, unless the user goes back to my site, which I do not want.
So I went to rules and replaced all the 'Completing the checkout process' events with 'When an order is first paid in full' events, so that I can have all the above actions triggered as soon as the payment is first made on paypal, but unluckily none of these rules are now working and I assume it's because I am not receiving IPNs on localhost. I did look into the logs.
Here's a quick list of questions I would need your advice on.
Q1. Am I really having these issues because of not receiving the IPNs in localhost. The way I looked for IPN was by looking into the admin>reports>Recent log messages. Please let me know if it's the correct way?
Q2. If that is the reason, do I have to put my site live to test the IPNs. It might be a silly question but what if my users attempt to make payments while I my site is live and still in a test phase. Is there a way I can test this all locally first.
I hope it has nothing to do with rules and replacing all the 'Completing the checkout process' events with 'When an order is first paid in full' events is the right move to create accounts, orders and send emails when the payment is made, rather than when the user comes back to the site.
I am using xampp stack and paypal sandbox account to test my site.
Comment: _do I have to put my site live to test the IPNs_ Definitely not, that's what the Sandbox system is for (assuming, of course, PayPal can reach you server through the network). PayPal have tools within their own developer centers that can help you debug the IPN, that would be the best place to look first. If you see anything other than 200 for the response codes, there's something wrong with the IPN delivery
Comment: Clive I read it at few places that paypal cannot send IPN to localhost. You have to make you site available to public somehow in order to receive the IPN, but if you say so, i will look into it.
Comment: Yes that's true, I mentioned the same thing in my comment...
Comment: I misunderstood it, but got your point now. Thanks :)
Answer: Q1
To test Paypal unfortunattely you need to test on a website which Paypal also can connect to. This is not necessaraly your live site. Maybe you should setup a test/demo environment somewhere else. If you don't want people to access that site you can setup an extra login with htpasswd, but it needs to be disabled during testing of the IPN.
An easy way to do this is using the shield module.
Q2
You can always test using another payment method. For other tests I always use the Payment Example module which is provided with the Payment module in Drupal Commerce.
This way you can test payments without having to deal with receiving IPNs.
Comment: I am happy to create my test/demo environment somewhere else, but how can i make sure whether paypal is able to connect to that environment/website. What if it doesnt connect to that envioronment too just like it doesnt connect to localhost. Are there some protocols or creteria to make sure.
Comment: If __anyone__ can access the site from __anywhere__, Paypal can also connect to it.
Comment: My payment workflow works perfectly fine as long as the user gets back to my site and I have similar settings in rules. As soon as I change the event to 'when the payment is first made in full' in rules, the payment workflow breaks .. Example module works fine because it has nothin to do with IPNs and it doesnt directs users off site ..
Comment: The Paypal WPS module does exactly the same, with the exception of the redirect and the IPN. The payment example module can be used to test the complete steps, the redirect back to your site can be made anywhere, even your local computer, but the IPN can only be posted in an environment which Paypal can send data to.
So testing on a test/demo environment should work for your final tests.
Comment: As long as my local site doesnt rely on IPN, all the orders, users and emails fire up in perfect order . It's only when I add a specific event 'When an order is first paid in full', all my orders, accounts and emails rely on receiving the IPN and so nothin fires up. So I guess I have to test my site in an evnioronment which is open to public as that is where my site can receive the IPNs. Thank you absoludo for giving me the direction :D


How to Install nuget package in visual studio with 32 bit or 64 bit specific

Question: How to Install nuget package in visual studio with 32 bit or 64 bit specific
I have solution where two projects and every project configuration manager in both directing to x64 only , and we removed x86 from options totally from each project configuration manager
while trying to
install - package of DB2.dll ,
its downloading both x64 and x86 folders in packages folder but in
 Refernce -> properties - > Path  its taking x86 dll ,
 where it should direct to the x64 folder/dll
any command to specify to only install the 64 bit
Comment: Can't you just change the reference to point at the x64 dll?
Comment: @shaswatatripathy, what about this issue? Would you please let me know the latest information about this issue?
Answer:
any command to specify to only install the 64 bit

Apparently specific target for 32 or 64 bit architectures is still unsupported. You can vote it at: http://nuget.codeplex.com/workitem/679
This question has two answers, you can check them. One is address this with a single package by following System.Data.SQLite.org to implement Native Library Pre-loading.
The other is to use multi-package. Create two DB2 packages, One for x86 and the other for x64, add DB2`s x64 package to your project.
How to deal with x86 vs x64 packages


Query for this situation

Question: I have a table like this:
EMP_ID   emp_name Designation  DOB        Address
--------------------------------------------------
101         X         Null     Null       NULL
101       NULL      Engineer   Null       null
101       NULL       NULL      31/07/1992 Null
101       NULL       NULL       NULL      XYLEM

This is basically a single row scattered information across. How to query it so we can get the single result row?
Comment: You probably have an error in the SQL that generates this result set.
Answer: We can try taking the max of each column:
SELECT
    EMP_ID,
    MAX(emp_name) AS emp_name,
    MAX(Designation) AS Designation,
    MAX(DOB) AS DOB,
    MAX(Address) AS Address
FROM yourTable
GROUP BY
    EMP_ID;

However, given the unnormalized layout of your current table, I might wager that you made a data design decision incorrectly somewhere along the way.  Normally, you would not want to store your information this way.
Comment: Thanks Tim Correct its just an Scenario Not an actual Situation. Kind Regard
Answer: SELECT
    EMP_ID,
    MAX(emp_name) AS emp_name,
    MAX(Designation) AS Designation,
    MAX(DOB) AS DOB,
    MAX(Address) AS Address
FROM yourTable
GROUP BY
    EMP_ID;

OR
SELECT
    EMP_ID,
    MIN(emp_name) AS emp_name,
    MIN(Designation) AS Designation,
    MIN(DOB) AS DOB,
    MIN(Address) AS Address
FROM yourTable
GROUP BY
    EMP_ID;

Query for this situation


Steps to perform time series analysis

Question: I'm trying estimate an autoregressive model with an exogenous variable. It's about the impact of changes in oil prices on the economy. I'm planning on regressing gdp growth rate on its own lagged values and lagged values of oil price.
I don't know from where to start.  Here's what I think so far:

I should check if the gdp and oil price are stationary, right? (dickey-fuller test??)
Find the  number of lags for gdp and oil price.( AIC criterion?.)
Estimate the model.
Test the signification of the estimators, heteroscadesticity and then serial correlation.

Should I test for the presence of cointegration? later I'm planning on using the same variables in a Markov switching model. I have the same question for Grangers causality test.
I've been reading a few books and watching more than one video about times series, but I still can't find my way through it. Can you please guide me and see if there is something missing in those steps?
Answer: It sounds like you want to fit an ARIMAX model to your time series. I would try to fit an ADL (auto-regressive distributed lag) model, an ECM (error correction model) or apply the Engle-Granger 2-step analysis to the series to see if your series cointegrate and to estimate the long-run relationship between them in case they do. If they do not cointegrate then continue with the ARIMAX model or estimate stationary ADL or ECM models. Note that an ADL model and the ARIMAX model are very similar. Although cointegration analysis with several variables is quite an endeavour and fills up entire text books (see e.g. Katarina Juselius' "The Cointegrated VAR Model: Methodology and Application) cointegration analysis with only two variables is quite fast and easy depending on what approach you want to use. Note that a part of my answer is the same as I answered in another question on a similar question. I will outline the steps you should follow in order to model the time series appropriately.Remember firstly that there are different kinds of non-stationarity and different ways on how to deal with them. Four common ones are:
1) Deterministic trends or trend stationarity. If your series is of this kind de-trend it or include a time trend in the regression/model. You might want to check out the Frisch–Waugh–Lovell theorem on this one.
2) Level shifts and structural breaks. If this is the case you should include a dummy variable for each break or if your sample is long enough model each regimé separately.
3) Changing variance. Either model the samples separately or model the changing variance using the ARCH or GARCH modelling class.
4) If your series contain a unit root. In general you should then check for cointegrating relationships between the variables but since you are concerned with univariate forecasting you shoud difference it once or twice depending on the order of integration.The steps to model the series:
1) Look at the ACF and PACF together with a time series plot to get an indication on wheter or not the series is stationary or non-stationary. If the ACF decays very slowly and the TS plot looks like it exhibiting a unit root (not mean reverting) then this is a good indication that the series do not include a unit root.
2) Test the series for a unit root. This can be done with a wide range of tests, some of the most common being the ADF test, the Phillips-Perron (PP) test, the KPSS test which has the null of stationarity or the DF-GLS test which is the most efficient of the aforementioned tests. NOTE! That in case your series contain a structural break these tests are biased towards not rejecting the null of a unit root. In case you want to test the robustness of these tests and if you suspect one or more structural breaks you should use endogenous structural break tests. Two common ones are the Zivot-Andrews test which allows for one endogenous structural break and the Clemente-Montañés-Reyes which allows for two structural breaks. The latter allows for two different models. An additive outlier model which accounts for sudden changes in the slope of the series and an innovative outlier model which takes gradual changes into account and allows a break in the intercept and slope. Look these tests up on Wikipedia or in some econometrics text book. Some statistical packages have these tests built in which makes conducting a battery of unit root test on your series very easy.
In case your series contain a unit root then test the first differences of your series in orer to see if they contain a second unit root.
3) In case your series are non-stationary then you should:
<code>        A) Apply the Engle-Granger 2-step procedure

        B) Apply an ADL model

        C) Apply an ECM model
</code>
Note that you could use the Johansen cointegration test or some other tests but for simplicity these are left out and in your case where you only have two time series either one of A), B) and C) will suffice. Note that although the Engle-Granger procedure is easier to apply (at least I think so) the ADL/ECM estimators are prefferable as can be seen by conducting a Monte Carlo simulation.
I will not explain all these approaches and how to derive the long-run solution as that would take a considerately amount of time and space but here is an excellent link in order to introduce these methods:
http://www.econ.ku.dk/metrics/Econometrics2_07_I/LectureNotes/Cointegration.pdf
4) The amount of lags you include should be picked so that you eliminate all residual autocorrelation when picking lags for your ADL model.
5) After your cointegration analysis you are more or less done. Please note that in case you want to expand your model to several variables you should use the CVAR model and the analysis gets a lot more complicated as mentioned above.
6) In case your variables do not cointegrate but contain a unit root then continue with your ARIMAX modelling
<code>        A) Difference the series

        B) Choose lag length according to the ACF and PACF. Pick the best model according to the AIC, BIC or HQ criterions and test for residual autocorrelation using the Ljung-Box Q test. Test the significance of your variables.

        C) Estimate and ADL/ECM model to your data. Include lags so to remove serial correlation and do tests on variable significance.
</code>
7) In case of stationary variables estimate a stationary ADL/ECM model for your data or proceed with your ARIMAX. Same steps as in 6). An excellent introductionary note on the stationary models can be found here: http://www.econ.ku.dk/metrics/Econometrics2_07_I/LectureNotes/dynamicmodels.pdfIn case your series contain a unit root with a drift or no unit root but a deterministic trend you can add a time trend to your specification. Further, check the first differences of the series and the time series plots to see if your series contain a structural break and/or outliers and include dummy variables for these. Note that you should test for structural breaks, see point 2) above. Another alternative is the Chow test. Thirdly it could be an idea to take natural logs of your variables as this will stabilize the variance of the series. The log transformation will not change anything as its a monotonic transformation.
Hopefully this made some sense. Please note that this was a very short introduction and that this could easily fill several chapters in a textbook. I will strongly recommend to read those two lectur notes I posted links to or that you get hold of a textbook on time series analysis/econometrics. If you need help to understand some of the concepts better then please feel free to ask! Model specifications and examples are all included in the lecture notes I linked to.
Comment: Please note that you do not need to perform the Johansen test as indicated in an answer given as you only have two time series. It was designed to test multiple cointegrating relationships and can be sensitive to misspecifications of your model. Also, the Johansen test is more complicated than the above mentioned. models.
Comment: the two variables are stationary at level 0, I suppose I don't have to check for co-integration. I was wondering, which model should I opt for, if I mainly want to get an idea on the relation between oil and gdp. Should I go for ARIMAX or ARDL models? It's quite hard for me to chose between the two, I suppose the main difference will lie in the interpretation of the results?
Answer: Problem with starting straight with variables with first differences is that if variables are co-integrated then you are leaving one important variable out, this leads into omitted variable bias.
You should test for unit-roots of course, but it is important to test for co-integration as well.
You could form an VAR-system where you can test presence for co-integration relations via methods of Johansen.
http://www.amazon.com/Likelihood-Based-Inference-Cointegrated-Autoregressive-Econometrics/dp/0198774508
You can test for the size of model in VAR system since there are tests for lag orders and such.
And of course residuals must be white-noise, otherwise many tests are invalid and results might be suspect.

Steps to perform time series analysis


How to define a menu with and without url arguments in hook_menu?

Question:  $items['jobs/%'] = array(
    'page callback' => 'custom_changes_jobs_interface_create_update',
    'access callback' => TRUE,
    'page arguments' => array(1),
  );

I need to use jobs for POST request and jobs/% for put and delete request where the argument would be string but if its not passed I want to make sure it works.
Answer: You have two options:
1) Define both paths, jobs and jobs/%.
2) Define only the first path
$menu['jobs'] = array(
  'page callback' => 'my_page_callback',
  ...

Then make the argument optional:
function my_page_callback($job_id = FALSE) {
  ...

This callback will be called for both paths.


Windows 7/8 Strongswan IKEv2 Wrong Gateway

Question: I have setup Strongswan on Ubuntu 14.04 from the official package. I use IKEv2 with PKI authentication and a custom authorization plugin. This works great for Android and Ubuntu clients using strongswan but not when using the Native Windows 7/8 IKEv2 client.(Machine certificates authentication). I connect to the VPN server just fine, but on the Status tab for the vpn interface it shows this:

and as you can guess I can't access anything as I have broken routing.
I have censored the IP details, Client IPv4 is correctly an IP assigned from the strongswan pool at the VPN subnet. (it's no-NAT, all addresses are public routable except the origin address which is behind my home NAT router)
Comment: Are you worrying about the "Server IPv4 address 0.0.0.0" line? Or those red marked IP addresses?
Comment: the 0.0.0.0 address :P
Comment: That 0.0.0.0 address is always like that for IKEv2 connections. But the red marked IP addresses actually look like they are from the same subnet, which might be an issue.
Comment: Android clients with strongswan app and linux clients using strongswan can connect and have correct routing behavior.
Comment: As far as I could determine the censored addresses, they are from the same subnet. It might throw the Windows client off that the VPN gateway's public address and the client's **internal** tunnel IP are in the same subnet. Do you use [split tunneling](http://wiki.strongswan.org/projects/strongswan/wiki/ForwardingAndSplitTunneling)? Have you disabled the _"Use default gateway on remote network"_ option in the _"Advanced TCP/IP"_ settings of the VPN connection?
Comment: Just to clarify, I use fake-arp so the client gets a public routable IPv4, no NAT takes place.
Answer: SOLVED:
You should specify 0.0.0.0/0 for rightsubnet for windows config, the Windows IPsec client isn't "smart enough" to handle split tunneling.
Comment: Really? What I have always resolved to do for all our remote windows workers is not "use gateway on remote network" and just insert the needed routes via the "route" command from a command prompt.
Comment: Yes. That's split tunneling. The Windows IKEv2 client doesn't take route pushdown (something the mac client does handle), but it'll split tunnel. Adding routing works better with the powershell command `Add-VpnConnectionRoute` and `Add-VpnConnectionTriggerTrustedNetwork` for on-demand DNS dialing.
Comment: That's incorrect. You can split tunnel with the windows client. In fact, I'm doing it right now.


Is there a name for this type ascending inversions of a repeated chord?

Question: I was messing around on one of my guitars one day and stumbled upon this interesting ascending progression.  I ended up writing a song using the progression even though I wasn't even sure what the names of the ascending chords were.
Here is what it sounds like:
Ascending Progression in G

I looked up the chord names on a reverse chord name finder and learned that the names of the chords I play in the progression are G - Gsus2 - G - G - C.  Apparently each of the ascending chords is a derivation or inversion of the G-major chord.  But they all sound different.  The bass note in the G chord variants are G - A - B - D respectively,  and the chords are played by moving up the fret-board from the open G position all the way to the tenth fret inversion of G major (with a D in the bass).
Here is the way the G chords look (note open or muted strings at far left of each chart):

Is there a name for this type ascending inversions of a repeating chord with a different bass note in each inversion?  Or a term that commonly describes this device?  It's not very common in the music I listen to but it sounds really cool.
Comment: I'll write a full answer later, but at least to me the inversions don't really affect the overall progression and seems more like an accompanying technique like Alberit bass or walking bass.
Comment: @Dom But there could be, or perhaps there is a name for this *style* of playing which I myself do with other voicings, and is distinctive. Perhaps we can make one up. Maybe it will catch on.
Comment: @Dom thanks for embedding the soundcloud link.  I was not sure how to do that or if it would work on this site.
Answer: I don't think that there's a specific name for such a progression. You basically repeat a chord in different inversions. However, the way I hear the second chord (with A in the bass) is not as a version of G. Of course you can call it Gsus2, but the question is if you hear it as a Gsus2. I don't because the 2 in the bass (A) is quite uncommon and suggests something else. What I hear is a D chord with the 5th in the bass, which is a much more common bass note than the 2. As a D chord it would be called Dsus4/A. So the way I hear it, it is a I-V-I progression eventually going to the IV chord (C).
Comment: It could be a Dsus4.  So it sounds as if perhaps I should name it a Dsus4/A if I was writing a lead sheet?
Answer: This is called comping. You play the same chord in different positions. It creates movement and exhibits the whole range of the instruments while in some cases it generates interesting voicings like your Gsus. It sounds cool and its the dirty job of a guitarist.
Comment: [Comping](http://en.wikipedia.org/wiki/Comping) is just short for accompanying. It doesn't describe the progression.
Comment: Yet, this is the closest thing to describe the playing. As far as the progression goes, one could say that it is a G going to a C and that would be enough to describe it.
Comment: This sounds like the right usage to me. Melody in octaves and with G chord comping underneath. As a side note, the melody is a Gadd2 arpeggio.
Answer: Slash chords could be what you mean. It's a way of describing a chord with a note other than the root at the bottom. Common are G/B and G/D, which are G chords with B and D as the lowest note respectively. Otherwise called 1st and 2nd inversions. When A is underneath the chord is G add 2 or sometimes G sus 2, if B is absent, and here is written G/A. If there is a bassist playing, expect him to play the note after the slash, otherwise on guitar or piano, make that note the lowest played.
With the G/A chord, it sometimes gets named as an 11th. Listen to Midnight at the Oasis intro. First chord (in Eb) F#11, or maybe Gb11. It's an  E major with F# bass - E/F#.


Drop-down-menu works great with Firefox, but not with WebKit

Question: I am working on a Drop-Down-Menu only using CSS & HTML5 (no JavaScript) in my personal website. Here it is: http://davidvalles.cu.cc
If you enter with Firefox, the menu works great (it is the one called "Secciones"): when you put the mouse over the "Secciones" div, the menu appears with a transition.
But if you try it with Safari or Chrome, it will work normally, unless you put the mouse UNDER the "Secciones" div. In that case, menu will appear normally. And I don't want the menu to open in that case. I only want it to open when you put the mouse over the "Secciones" link (all the box that contains the Secciones text).
What am I doing wrong? Why does the menu work perfectly in Firefox but not in Safari?
Could you take a look at it? Thank you, and sorry for my poor English, I'm learning. Please, correct me :)
Answer: Your easing? Is "ease" a easing value?
<code>-moz-transition: opacity .25s ease;
-webkit-transition: opacity .25s ease;
-o-transition: opacity .25s ease;
-ms-transition: opacity .25s ease;
transition: opacity .25s ease;
</code>
Comment: I solved it. It was a problem with the code which was previous to the menu. A div was higher than that he had to be.

By the way, according to w3schools.com ( http://www.w3schools.com/cssref/css3_pr_transition-timing-function.asp ), ease is a valid value to easing property.

Thanks!


CSS3 Buttons with icon

Question: I am following this tutorial to create CSS 3 button with Icon. But the problem in this tutorial Icon height depends on font-size. If I increase font-size of text, icon fits well but if I try to reduce the font-size, it doesn't fit well.Image I am using is 40x30
a.button {
  background-image: -moz-linear-gradient(top, #ffffff, #dbdbdb);
  background-image: -webkit-gradient(linear,left top,left bottom,
      color-stop(0, #ffffff),color-stop(1, #dbdbdb));
  filter: progid:DXImageTransform.Microsoft.gradient
      (startColorStr='#ffffff', EndColorStr='#dbdbdb');
  -ms-filter: "progid:DXImageTransform.Microsoft.gradient
      (startColorStr='#ffffff', EndColorStr='#dbdbdb')";
  border: 1px solid #fff;
  -moz-box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.4);
  -webkit-box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.4);
  box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.4);
  border-radius: 2px;
  -webkit-border-radius: 2px;
  -moz-border-radius: 2px;
  padding: 5px 5px;
  text-decoration: none;
  text-shadow: #fff 0 1px 0;
  float: left;
  margin-right: 15px;
  margin-bottom: 15px;
  display: block;
  color: #597390;
  line-height: 38px;
  font-size: 15px;
  font-weight: bold;
}
a.button:hover {
  background-image: -moz-linear-gradient(top, #ffffff, #eeeeee);
  background-image: -webkit-gradient(linear,left top,left bottom,
      color-stop(0, #ffffff),color-stop(1, #eeeeee));
  filter: progid:DXImageTransform.Microsoft.gradient
      (startColorStr='#ffffff', EndColorStr='#eeeeee');
  -ms-filter: "progid:DXImageTransform.Microsoft.gradient
      (startColorStr='#ffffff', EndColorStr='#eeeeee')";
  color: #000;
  display: block;
}
a.button:active {
  background-image: -moz-linear-gradient(top, #dbdbdb, #ffffff);
  background-image: -webkit-gradient(linear,left top,left bottom,
      color-stop(0, #dbdbdb),color-stop(1, #ffffff));
  filter: progid:DXImageTransform.Microsoft.gradient
      (startColorStr='#dbdbdb', EndColorStr='#ffffff');
  -ms-filter: "progid:DXImageTransform.Microsoft.gradient
      (startColorStr='#dbdbdb', EndColorStr='#ffffff')";
  text-shadow: 0px -1px 0 rgba(255, 255, 255, 0.5);
  margin-top: 1px;
}
a.button {
  border: 1px solid #979797;
}
a.button.icon {
  padding-left: 11px;

}

a.button.icon span{
  padding-left: 48px;
  display: block;
  background: url(../img/gmail2.png) no-repeat;
}

Answer: Your statement is a little ambiguous and lacks a question, but I'll take a stab.
In this scenario, font-size will always play a small factor, as it will determine the height of the icon. At some point you are going to need to know some details about the button size, but it doesn't have to be affected by font. If you set the button height and the img{ height:100%; } the image will scale to fit the area.

Button

combined with
#container{
    border: 2px solid black;
    width: 200px;
    height: 20px;
}
#container img{
    height:100%;
}

Should get you something you close to what you're looking for. I've whipped up a small jsfiddle to demonstrate one way to accomplish this.
Answer: It would be helpful if you could share your code.
In the css3 buttons examples of the link you provided, if I decrease font-size and set the following CSS style, works.
span { display: block; }

span is the tag that wraps the text inside the buttons.
Comment: If I add to a.button.icon span {display: block; }, image is not center.Try to add image with bigger size.
Comment: It works fine if I do it on the examples of the link you shared. So post your code so far to help you further.

CSS3 Buttons with icon