Poisson adaptation of IRT model: how to interpret parameters?

Question: For my work I made an assessment in which users have to stack blocks in a certain configuration in as few steps as possible. If the user does this in the minimally required number of steps, they get the perfect score of 0. With every extra step they need, their score increases by 1.
To measure the skill of the participants, we use an IRT (item response theory) model. Since the test isn't dichotomous, scores are discrete, scores on every item can range from 0 to $\infty$, and scores seem roughly normally distributed, we adapted the IRT model to use a poisson distribution.
That is, we use the normal MaxLogLikelihood estimation, but instead of using the 2-parameter IRT fomula(1)
$$
   P(X|a,b,\theta) = {e^{a(\theta - b)} \over 1+ e^{a(\theta - b)}}
$$
we calculate P according to the regular poisson formula (2)
$$
   P(X=n) = {\lambda^n e^{-\lambda} \over n!}
$$
where $\lambda$ is ... well, that's the question. Based on a textbook I have been using (3)
$$
\lambda = e^{(b - a\theta)}
$$
My questions are about the relationship between $b$, $\lambda$ and $\theta$:
- does the formula at (3) make sense, or should it be something else?
- in the 2plm IRT model (1) the roles of the parameters are very clear to me: $\theta$ is assumed/defined to be N(0,1) so ranges roughly from -3 to 3. $b$ is defined such that if $b = \theta$, the chance of getting a correct answer is exactly 50%. And $a$ defines the slope. Makes perfect sense. In the poisson model however, I lack these definitions. If $b$ still represents the difficulty of an item, and suppose $b = \theta$, what $\lambda$ should I expect? What does $a$ represent? I'm finding it hard to wrap my head around the conceptual meaning.
In short: keeping $\theta$ defined as N(0,1), what would be the best/most sensible way to define the other parameters of a poisson-based IRT model?
p.s. first post here, feel free to give other feedback.
Comment: I would have to work on this a bit, but my first inclination is that the formula $\lambda = e^{b-a \theta}$ would not be interpreted in the same way.  The reasoning is that formula (1) should actually be X=1 where you have just X.  This is important, because this gives the probability of a correct response given the item difficulty and the person ability.  So, if we ask the same question in the Poisson setting, we have X=0 which gives $e^{-\lambda}$.  Plugging your (3) into this doesn't seem correct.
Comment: A minor point of clarification: this seems like an application of generalized structural equation modeling to me. I view IRT as a special case of generalized SEM (fun fact: all the IRT models in Stata are fit using the generalized SEM command behind the scenes).
Answer: I recently came across a paper by Daniel Bauer and Andrea Hussong (2010, available for free on PubMed Central) that appears to tackle this topic. As mentioned in comments, I think that what you want to do can be described as a non-linear confirmatory factor analysis. The paper treated 5 variables as indicators of alcohol involvement, and the variables are all of different types (one is binary, one is Poisson, two are unordered categorical).
Their equation 3 shows how you'd model item responses in general terms (altered notation to be consistent with original question):
$g_i(\lambda_{ij}) = v_i + d_i\theta_j$
Where i indexes items/questions and j indexes persons
$\lambda{_ij}$ is the mean of item i for the j-th person
$g_i$ is a link function like you might find in a GLM (e.g. log link for Poisson, logit for binary items)
$v_i$ is the intercept for the i-th item, which I believe is a parallel concept to difficulty or severity (note @Heteroskedastic_Jim's comment that in the OP's context, because higher count = lower ability, this should probably be interpreted as easiness rather than difficulty)
$d_i$ is the factor loading for the i-th item, which I believe is parallel to discrimination (note: the paper used $\lambda_i$ for this term, but I'm reserving this for the Poisson parameter; also note Jim's comment that this would be on the log scale given the context)
And $\theta_j$ is the j-th person's trait level, whatever trait it is you're interested in.

For Poisson items, I would suggest the equation doesn't really need to be rearranged other than specifying the log link. In regular Poisson regression, our model is:
$ln(E(Y|X)) = ln(\lambda|X) = \alpha + X\beta$
In the original poster's context, our model is now:
$ln(\lambda_{ij}) = v_i + d_i\theta_j$
So, if I am correct, the original question gave the wrong formula for $\lambda_i$, but the correct probability mass function.

For Bernoulli items, like you'd find in a basic 1- or 2-parameter logistic (1- and 2-PL) IRT model, the link is the logit link, i.e.
$ln(\frac{\lambda_{ij}}{1 - \lambda_{ij}}) = v_i + d_i\theta_j$
Rearrange terms and you should get the IRT parameterization that many people are familiar with. For Gaussian items, then $g_i$ is most likely the identity link, and the equation becomes something you'd see in linear SEM. In principle, any family and link function supported by your software could be used to model the items, e.g. you could model count items as negative binomial, or you could model Gaussian item + log link.
I don't know any specific R packages, but they have to exist. The authors used SAS PROC NLMIXED to fit their model. Stata's gsem command will also fit this model, as demonstrated at the link.
Comment: You are right and it does not matter. More $v_i$, higher count, so it is an item _easiness_. And $d_i$ is the relation between the random slope $\theta_j$ and the outcome on the log scale.
Comment: @HeteroskedasticJim excellent observations; noted above.


One index weirdly missing in pandas dataframe

Question: I'm importing an excel file into pandas. It contains mixed text and numerical data; what I need to do is iterate over a column containing text with a view to processing that text. However, when I do, I get a key error:
KeyError: 145831

The thing is, there is no reason this value should be missing. The values before and after it are present:
hashtags['tweet'].loc[145829:145834]

145829    Internet Marketing Made Easy. Stop By:   https...
145830               @sbxr Lol. How's the fishing up there?
145832    @HelloMD_com @TreatWellHealth Tinctures are or...
145833    @MikeBloomberg We would like to suggest that y...
145834    @mannydr Yeah the whole re-labeling thing is w...

For some reason, 145831 just isn't there. I tried reindexing the dataframe, but the KeyError remains.
Can anyone suggest a workaround, or why this might might be happening? Note that the excel served an error notice when I opened the sheet, saying it repaired some of the data––this is likely relevant.
Comment: Yes, this is the answer! I'd confused reindex with reset_index. Thanks!
Comment: have you tried reset_index(drop=True) and try the same?
Answer: In my opinion there should be 2 reasons - index values are already in excel file and some rows are missing or some rows was removed after reading excel file.
Solution is generate default index:
hashtags = hashtags.reset_index(drop=True)

Comment: Thanks––this is the answer I was looking for!


Is there a name for a 3-3-2-2-2 rhythm?

Question: I have a 12/8 rhythm that has beats on the x's below:
<code>1 + + 2 + + 3 + + 4 + +
x     x     x   x   x
</code>
I vaguely remember hearing a name for this years ago. Is it some kind of clave? Is there a name for it?
Comment: This article by Brad Mehldau might be of interest: [Rock Hemiolas](https://www.bradmehldau.com/rock-hemiolas).
Answer: There are several rhythms that use the 3-3-2-2-2 pulse in flamenco music from Spain. One of the most well known is Bulerías, a seemingly simple but very complex sounding rhythm made even more complex by the fact that they count starting on 12 instead of 1 So the basic accents fall on:
12..3..6.8.10.
An often used variation is:
12..3....78.10.
This gives the 3-3-2-2-2 pulse you are asking about.
In other styles that emulate a Spanish flavor, some of the most well known occurrences of this is "America" from "West Side Story" and the main theme from "Man of La Mancha". I have played the latter show and this rhythm is used in a few songs in the score of that show. In La Mancha they wrote it as alternating bars of 6/8 and 3/4 but in America I believe they just wrote it in 6/8 with every other bar having the accents on beats 1, 3 and 5.
Someone with a more detailed knowledge of Flamenco music and dance can likely give you names of other rhythms that use this basic count such as Soleares, Alegrias and Peteneras (kudos @jsantander) but hopefully this will at least point you in the right direction.
Comment: What does "they count starting on 12" actually mean? Does it mean that "12 - - 3 - - 6 - 8 - 10 -" is the same rhythm as "1 - - 4 - - 7 - 9 - 11 -" and they simply use different numbers when talking about it? Or does it mean that in the rhythm "12 - - 3 - - 6 - 8 - 10 -," the second beat is logically the first beat in some sense, and so the rhythm is effectively actually "- - 3 - - 6 - 8 - 10 - 12"?
Comment: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/116506/discussion-on-answer-by-john-belzaguy-is-there-a-name-for-a-3-3-2-2-2-rhythm).
Comment: @TannerSwett I don't have the experience with that style to explain it but this video does around the 2 minute mark https://youtu.be/9ophgWK8dMs To me it sounds like 1-4-7-9-11  but they think of it and play it differently.
Answer: This is an example of hemiola
From the Oxford Companion to Music (2nd ed., Alison Latham, 2002)

Hemiola: In modern notation, a hemiola occurs when two bars in triple meter (e.g., 3/2) are performed as if they were notated as three bars in duple meter (6/4) and vice versa.

The Wikipedia entry linked above goes on to say that when the 3:2 ratio occurs simultaneously -- that is, one part is in three while another is in two -- the term is sesquialtera. However, the term does not appear in the OCM.
Comment: @LaurencePayne If by "We're not discussing hemiola" you mean "this is the dictionary definition of hemiola", then I totally agree with you.
Comment: No answer to the original question would be complete unless hemiola was mentioned.
Comment: @LaurencePayne The section in the linked article explicitly calls out this rhythm pattern in the section on horizontal hemiola: "It is "a cliché of various Spanish and Latin American musics ... well established in Spain since the sixteenth century", a twelve-beat scheme with internal accents, consisting of a 6/8 bar followed by one in 3/4, for a 3 + 3 + 2 + 2 + 2 pattern." That's exactly what is described in the question.
Comment: "sesquialtera" is [discussed here](https://en.wikipedia.org/wiki/Sesquialtera) I see it as a synonym of hemiola.  Simultaneous 3 against 2 is often described as a hemiola  cross-rhythm or simply a 3 against 2 cross-rhythm.
Comment: I think this is the term i heard years ago
Comment: But as what we're discussing is neither a hemiola or two simultaneous rhythms, neither term is appropriate here.
Comment: +1 it's obvious the pattern is hemiola. It strange to read the comments that it isn't. However, hemiola isn't a rhythm "name" in the sense of tresillo, clave, habanera, etc. It's more like a category of rhythm.
Comment: @chasly-supportsMonica - sesquialtera *was* organ related. Hemiola is 3 against 2, and also 2 against 3.
Comment: The rhythm described is not 3 against 2 or vice versa, it is an even pulsed rhythm with two groups of 3 and three groups of 2. There's no "against".
Comment: @JohnBelzaguy Hemiola only requires that "two bars in triple meter are performed as ... three bars in duple meter."
Comment: @Aaron I'm not saying it isn't a hemiola, just that the implication in other comments in your answer seem like they're referencing 3 against 2 as if they were say, triplets to eighth notes. Maybe I'm misreading.
Comment: @JohnBelzaguy My mis-read. Thanks for clarifying.
Comment: @Tim sesquialtera has two completely distinct senses, of which one has to do with pitch, and therefore organ stops, and the other has to do with meter.  The common element is a factor of one and a half (think _sesquicentennial),_ or indeed 3/2.
Comment: @JohnBelzaguy - point taken. There is no 3 *against*  2, or vice versa, it's simply a rhythmic metrication within a bar. So is, or isn't it a hemiola..?
Comment: Related to defining "hemiola": [Is that a hemiola or what?](https://music.stackexchange.com/questions/7572/is-that-a-hemiola-or-what); [How can I explain a hemiola to someone who knows nothing about music?](https://music.stackexchange.com/questions/49785/how-can-i-explain-a-hemiola-to-someone-who-knows-nothing-about-music).
Comment: @Tim In the wiki article in Aaron's answer there is a description of a "horizontal hemiola", which has this exact rhythm although the written rhythm has the 2's before the 3's. As for whether it technically is or isn't, I'll leave that one to the music scholars!
Answer: Colloquially it's often described as 'that rhythm from 'America' (West Side Story).
Comment: 'Is there a name for it?' I reckon ten times more folk would call it 'America' compared with 'hemiola'...
Comment: Why isn't it hemiola?  What does hemiola have that this rhythm doesn't?
Comment: OK, it's hemiola.
Comment: @LaurencePayne my question wasn't rhetorical.  I agree that this isn't what I would associate with the term, but I am at a loss to define the difference.
Answer: Your rhythm is reminiscent of Arabic rhythms, which of course are an influence on Flamenco music. Check this out: https://www.maqamworld.com/en/iqaa/warshan_arabi.php
Comment: Thanks for your answer, and welcome. Problem for the future with links is they can suffer from linkrot, leaving answers like this pretty empty.

Is there a name for a 3-3-2-2-2 rhythm?


Interpreting percent variance explained in Random Forest output

Question: I've run a Random Forest in R using randomForest package.
The fitted forest I've called: fit.rf.
All I want to know is: When I type fit.rf the output shows '% var explained' Is the % Var explained the out-of-bag variance explained?
Answer: Yes %explained variance is a measure of how well out-of-bag predictions explain the target variance of the training set. Unexplained variance would be to due true random behaviour or lack of fit.
%explained variance is retrieved by randomForest:::print.randomForest as last element in rf.fit$rsq and multiplied with 100.
Documentation on rsq:

rsq (regression only) "pseudo R-squared": 1 - mse / Var(y).

Where mse is mean square error of OOB-predictions versus targets, and var(y) is variance of targets.
See this answer also.
Comment: [note] above comment was a small answer as some body asked: "What if explained variance is more than 100%" and the person later deleted the comment again
Comment: Would not have thought that was possible, as then either model variance('mse') or total variance('Var(y)') would have to be negative. I'd like to see a code that can produce a >100% performance. It can be negative though when model variance is larger than total variance. The implications thereof is then you likely would be better of with off with a simple average than a random forest model.
Answer: To add some details to the content of the other answer, the formula to get the explained variance displayed in the summary is:
#fit.rf <- randomForest(...)
round(100 * fit.rf$rsq[length(fit.rf$rsq)], digits = 2)

You can check this by looking at what randomForest is printing with the command   getAnywhere(print.randomForest).
Furthermore, this is equivalent to the following commands:
# recalculate using model output
round(100* (1 - var(fit.rf$y - fit.rf$predicted) / var(fit.rf$y)), digits = 2)

# recalculate using the formula for rsq used internally
# see getAnywhere(randomForest.default).
n <- length(fit.rft$y)
rsq = 1 - fit.rf$mse/(var(fit.rf$y) * (n - 1)/n)
round(100 * rsq[length(rsq)], digits = 2)

Answer: This seems to be a misinterpretation of extending $R^2$ to more complicated situations than the usual in-sample OLS linear regression. In particular, the "propotion of variance explained" interpretation of $R^2$ is the exception, not the rule. As is derived in the link, that definition only applies when $\overset{N}{\underset{i=1}{\sum}}\left[
\left(
y_i - \hat y_i
\right)\left(
\hat y_i - \bar y
\right)
\right]
= 0$, which is not the case in a random forest regression.
library(randomForest)
set.seed(2023)
N <- 1000
x1 <- rnorm(N)
x2 <- rnorm(N)
x3 <- rnorm(N)
y <- x1*x2 + x3^2 + rnorm(N)
# d <- data.frame(x1, x2, x3, y)
forest <- randomForest(y ~ x1 + x2 + x3, mtry=3)
y_hat <- forest$predicted
y_bar <- mean(y)
sum(
  (
    y - y_hat
  )
  *
  (
    y - y_bar
  )
)
# I get 1778.79

Indeed, the documentation gives this quantity as:
$$
1-\left(
\dfrac{
\text{MSE}
}{
\text{var}\left(y\right)
}
\right)
=
1-\left(
\dfrac{
\dfrac{1}{N}\overset{N}{\underset{i=1}{\sum}}\left(
y_i - \hat y_i
\right)^2
}{
\dfrac{1}{N}\overset{N}{\underset{i=1}{\sum}}\left(
y_i - \bar y
\right)^2
}
\right)
=
1-\left(
\dfrac{
\overset{N}{\underset{i=1}{\sum}}\left(
y_i - \hat y_i
\right)^2
}{
\overset{N}{\underset{i=1}{\sum}}\left(
y_i - \bar y
\right)^2
}
\right)
$$
The third of the three expressions is a common definition of $R^2$, so the linked information about $R^2$ applies.
This does not mean that such a value is worthless, however. Indeed, I have lots of thoughts on an $R^2$-style performance metric in complicated settings.


Music Notation (in Musescore) - Ties or Separate Voices?

Question: I'm new to using Musescore and writing notation, so excuse any ignorance on my part.
For the sake of example, let's say we want to play a C-Major triad in the root position, but we want to express that C and E are held for two beats and the G is held for one. Initially, I would think to do something like this:

But I've come across notation where people would use different voices to express the same thing. Here the blue represents voice 1 and the green represents voice 2:

When I first saw this, I actually thought it looked a little cleaner. But when I looked up the definition of voices, it said:

A voice is a musical line or part which can have its own rhythm independently of other voices on the same staff.

Then I thought this might be some sort of notation abuse because in some of the sheets I was looking at, it was clear that there was one voice being expressed with two voices.
My question revolves around correct notation and readability. Is it technically correct or incorrect to express one voice using two? Is one more readable than another? Can one be more misleading than another? Does this even matter or should I just stop overthinking things and get back to playing music?
Answer: Is it technically correct or incorrect to express one voice using two?

No it does not really matter technically, either works.

Is one more readable than another?

They both are readable, and in my opinion, option 1 is better but probably even better would be a combination, which would be just like option 1, but has a quarter rest on beat two in voice 1.

Can one be more misleading than another?

They are both fine but my personal preference is choice 1.

Does this even matter or should I just stop overthinking things and get back to playing music?

As a percussionist who rarely gets music in a standardized/normal format, I think formatting always matters. It's good that you are trying to view the music from the perspective of the performer, not the composer. That being said, don't be too concerned, as long as it makes sense and is consistant, it's fine.
Answer: Ankit got it right, I would only like to add another possibility.
For me (as a classical guitarist), putting it into two voices would be the way to go. I would also typeset the G with stem up and the C and E with stems down, like this:

(I like the second bar more. Also sorry for the huge image, sadly all images get stretched to the width of the post.)
By the way, by writing it in two voices, you aren't "cheating the system" somehow. You correctly said that notes with different rhythms should go to different voices. The G has a rhythm "quarter note, quarter rest", the C and E have a rhythm of "half note". Clearly the rhythms are different.
However, even your example with stems the same way is OK and can be encountered in "real music", e. g. in this bit of Torroba's Sonatina (a famous work for the guitar):


How can I display no results text in a template?

Question: I have added no results behaviour text to a view called Events which is a page. This template I am using has a twig called views-view--events--page_1.twig. I want to add the no results text to this twig template, but I can't find any way to do it. How can this be done?
Comment: Look for `views-view.html.twig` in core and compare it with your template. You may be missing a lot more than just the empty case. Also, twig overrides end in `.html.twig`. See [Views template files](https://api.drupal.org/api/drupal/core%21modules%21views%21views.theme.inc/group/views_templates/10.0.x) for the correct way to name your views templates.
Answer: It's always useful to look at the original template (views-view.html.twig). The documentation list the available variables, which in this case are the following.

attributes: Remaining HTML attributes for the element
css_name: A css-safe version of the view name
css_class: The user-specified classes names, if any
header: The optional header
footer: The optional footer
rows: The results of the view query, if any
empty: The content to display if there are no rows
pager: The optional pager next/prev links to display
exposed: Exposed widget form/info to display
feed_icons: Optional feed icons to display
more: An optional link to the next page of results
title: Title of the view, only used when displaying in the admin preview
title_prefix: Additional output populated by modules, intended to be displayed in front of the view title
title_suffix: Additional output populated by modules, intended to be displayed after the view title
attachment_before: An optional attachment view to be displayed before the view content
attachment_after: An optional attachment view to be displayed after the view content
dom_id: Unique id for every view being printed to give unique class for Javascript

<code>{{ empty }}</code> appears to be what you're after.


Get variable out of anonymous javascript function

Question: I'm using an anonymous function to perform some work on the html I get back using Restler's get function:
var some_function() {
    var outer_var;
    rest.get(url).on('complete', function(result, response) {
        if (result instanceof Error) {
            sys.puts('Error: ' + result.message);
        } else {
            var inner_var;
            // do stuff on **result** to build **inner_var**
            outer_var = inner_var;
        }
    });
    return outer_var;
}

How can I get the value of inner_var out to the some_function scope and return it? What I have written here doesn't work.
Answer: The get call is asynchronous, it will take some time and call your callback later. However, after calling get, your script keeps executing and goes to the next instruction.
So here is what happens:

you call get
you return outer_var (which is still undefined)
... sometimes later ...
get result has arrived and the callback is called.
outer_var is set

You can't have your some_function return a value for something that is asynchronous, so you will have to use a callback instead and let your code call it once data is processed.
var some_function(callback) {
    rest.get(url).on('complete', function(result, response) {
        if (result instanceof Error) {
            sys.puts('Error: ' + result.message);
        } else {
            var inner_var;
            // do stuff on **result** to build **inner_var**
            callback(inner_var);
        }
    });
}

Comment: Thanks, the callback was the way to do it. I do have a question though. The .on('complete', function(... was supposed to take care of the asynchronous nature of the call, right? The code in that function should not have executed until the get call finished. Would I somehow still have been able to pass data out of the function handler back out to the outer context?
Comment: When you declare the callback for on "complete", you create a closure: the function is created and its scope contains everything declared above. So yes, the callback can pass data to the outside this way. You should definitely try to execute the code step by step in the debugger in order to understand the order in which functions are called, and what is the scope accessible for each function. It will make things much clearer than this explanation :)
Answer: Like most of the modules of node, Restler is also a event based library having async calls. So at the time you do return outer_var; the complete callback was not necessarily called (With some libraries it could be if it the result was cached, but you should always expect that it is called asynchronous).
You can see this behavior if you add some logging:
var some_function() {
    var outer_var;
    console.log("before registration of callback"); //<----------
    rest.get(url).on('complete', function(result, response) {
        console.log("callback is called");  //<----------
        if (result instanceof Error) {
            sys.puts('Error: ' + result.message);
        } else {
            var inner_var;
            // do stuff on **result** to build **inner_var**
            outer_var = inner_var;
        }
    });
    console.log("after registration of callback");  //<----------
    return outer_var;
}

So if you would like to do something with this value you would need to call the function that should do something with this value out of your complete callback.
Answer:
Remove the var outer_var; from your function some_function;
Declare the var outer_var; upper then your function

It should be work after you did step 1, not really need step 2.
Comment: The problem is because the call of `complete` callback of `get` is asynchronous.


Como aumentar a fonte no Semantic UI

Question: Estou começando a utilizar Semantic UI e queria saber se é possível modificar o tamanho da font, pois achei muito pequena e tive procurando no Settings do próprio site do Semantic e acabei não encontrando nada.
Quero aumentar a fonte das opções no dropdown.
Answer: Semantic UI não requer nada fora do comum, da pra aumentar o tamanho da fonte simplesmente usando uma classe CSS:
.cabecalho{
   font-size: 250%;
}

Caso você queira dar uma conferida em alguns tamanhos pré-definidos pelo próprio Semantic UI, da uma olhada aqui.
Segue um exemplo de um dropdown que encontrei no próprio site:

  <input type="hidden" name="gender">

Gender

Male

Female

Para alterar o tamanho da fonte dos itens dentro do drop, simplesmente altero a classe css, só toma cuidado que esse código pode alterar em outros locais que utilizam a classe .item também, qualquer dúvida deixa um comentário aqui na minha resposta.
.item{
  font-size:22px;
}

Como aumentar a fonte no Semantic UI


Proof verification: Atiyah-Macdonald Exercise 3.7(i)

Question: A multiplicatively closed subset $S$ of a ring $A$ is said to be saturated if:
$$ xy\in S \Leftrightarrow x\in S \text{ and } y\in S $$

Exercise 3.7(i): $S$ is saturated if and only if $A-S$ is a union of prime ideals.

$(\Leftarrow)$: Let $A-S$ be a union of prime ideals $\{ \mathfrak{p}_i \}_{i\in I}$.
$$ S = A-(A-S) = A-\bigcup_{i\in I} \mathfrak{p}_i = \bigcap_{i\in I} A\setminus \mathfrak{p}_i $$
Let $xy\in S$ then $xy\in A\setminus \mathfrak{p}_i$ for all $i\in I$. Let $\mathfrak{m}_i$ be the maximal ideal in the local ring $A_{\mathfrak{p}_i}$ and consider the maps:
$$ A \overset{\mu}{\to} A_{\mathfrak{p}_i} \overset{\pi}{\to} A_{\mathfrak{p}_i} / \mathfrak{m}_i $$
Thus, $\pi(\mu(xy)) \neq 0$ since $\mu(xy)$ is a unit. Therefore, $\pi(\mu(x)), \pi(\mu(y)) \neq 0$. Suppose that $x\in \mathfrak{p}_i$ (any $i$) for a contradiction, then $(x)\subset \mathfrak{p}_i$ and hence $(x)_{\mathfrak{p}_i} \subset \mathfrak{p}_i^e = \mathfrak{m}_i$; therefore, $\pi(\mu(x)) = 0$. Contradiction. Therefore, $x\in S$; similarly for $y$.
($\Rightarrow$):  Let $x \in A$ be a unit, then $x\cdot 1/x = 1\in S$. Therefore, $x\in S$. Therefore, $A\setminus S$ contains only non-units. Consider:
$$ U := \bigcup_{\mathfrak{p} \text{ prime} \\ \mathfrak{p} \subset A\setminus S} \mathfrak{p} $$
I claim that $A\setminus S \subset U$. Let $x\in A\setminus S$, then $x\in \mathfrak{m}$ for some maximal ideal $\mathfrak{m}$ (since $x$ is a non-unit). Therefore, $(x)\subset \mathfrak{m}$ and $S^{-1}(x) \subset S^{-1}\mathfrak{m}$ where $S^{-1}\mathfrak{m}$ is a prime ideal in $S^{-1}A$ by the correspondence theorem. The contraction of $S^{-1}\mathfrak{m}$ back into $A$ is a prime ideal which contains $x$ and is contained in $A\setminus S$. Therefore, $x\in U$.
I hope I used the correspondence theorem correctly. Please let me know if my reasoning is sound. Thank you.
EDIT: I think I have not guaranteed that $\mathfrak{m}$ does not meet $S$, so this proof might not work as stated. I will try to fix it tomorrow morning. Please let me know your thoughts anyway.
Answer: Let $A-S$ be a union of prime ideals. Suppose $xy\in S$, but $x\notin S$. Then $x\in A-S$, which is a union of prime ideals, and hence $x\in\mathfrak{p}\subseteq A-S$. So $xy\in\mathfrak{p}$ too. So $xy\in A-S$. Contradiction.
Let $S$ be saturated. Let $x\in A-S$. You showed $x$ is not a unit. So $x$ remains a non-unit in $S^{-1}A$. Then $x$ is in a maximal (hence prime) ideal in $S^{-1}A$. So $x$ is in a prime ideal in $A-S$ by the correspondence.


Would the source and destination address in ethernet frame change?

Question: Say there are 2 computers are connected this way in a wireless network:
Computer A -> Access Point 1 -> Access Point 2 -> Computer B
When a frame is sent from Computer A to Computer B, the frame needs to be first sent to Access Point 1 then Access Point 2 then eventually Computer B.
3 frames are generated along the way.
In its 802.11 frame, the 3 frames would have different source and destination addresses along the way.
But in its 802.3 ethernet frame, would the destination and source address in the 3 generated frames remain the same throughout with Computer B as the Destination Address and Computer A as the Source Address OR would the frame changes the Destination Address along to way to the Access Points ethernet address?
Answer: The destination address is the destination system, Computer B's MAC address.
The traffic's going to go through the access point because the client is associated to it (which is a different field in the 802.11 header, the recipient); the destination isn't the access point unless the access point is actually the final destination for the traffic on the layer two network - for instance, accessing its management interface or, if it's a router, sending traffic outside of the subnet.
802.11 was designed to work on many of the same principles of 802.11, which is why these access points can work just fine on the same layer 2 network as ethernet; just think of them like a switch with invisible cables to each associated client.
Yes, the frames need to be format-munged at each hop when changing media, but the headers always contain Computer B's MAC as the destination.  Access Point 1 keeps track of the fact that Computer A's MAC address belongs to an associated client, while Computer B's MAC address is out whichever ethernet interface that Access Point 2 is plugged into.
Every switch or access point in the layer 2 network keeps track of what MAC addresses are accessible via a given interface, which is what allows each device handling a frame to independently make a decision about which interface to send it out of, be it wired or wireless.
Comment: The destination MAC address will never change (to my knowledge). It's going to be either the MAC address of the destination host if the destination host is on the same layer 3 network or it's going to be the MAC address of the default gateway (router) if the destination host is on a different layer 3 network. The source MAC address will change if the destination host is on a different layer 3 network as the default gateway (router) will replace the original source MAC address with it's own MAC address.
Comment: The frame format of the 802.11 has 4 address fields and so it could keep track of all the MAC addresses. But in the Ethernet frame, it has only the destination and source address fields. So while travelling, the MAC addresses swap between the 4 fields in the 802.11 frame. But in the Ethernet frame, since there are only 2 address fields, do the source and destination addresses remain throughout with destination as Computer B's MAC address and source as Computer A's MAC address?
Comment: @Taro There are address fields for the transmitter and receiver, which are often not the same as the source and destination, which is why the frame has 4 fields.  The destination of the frame is not changed in transit or translation between wired and wireless media.  The transmitter and receiver for the wireless connection are obviously inconsequential on the wire; the source and destination fields are maintained.


Central limit theorem approximation of distribution

Question: I am doing a question which asks for an approximation of the distribution of X, which is the number of successes out of 50 independent trials with probability 0.4, using the central limit theorem. Then the question asks the probability that the number of successes is less than 10 using this approximate distribution.
So the average of the sum $S_{50}=\sum_{i=1}^{50} X_i$ can be standardized, and then follows a standard normal distribution:
$$\frac{S_{50}-50E(X)}{\sqrt{50Var(X)}} \simeq N(0,1)$$
From this point, I think the probability that the number of successes is less than 10 is:
$$P(S_{50})=P(\frac{S_{50}-50E(X)}{\sqrt{50Var(X)}}\leq\frac{10-50\cdot20}{\sqrt{50\cdot 12}})$$
Where, on the right side, 10 is the number of successes, $E(X)$ is $np=50\cdot 0.4=20$, and the variance is $npq=12$. These values are from the binomial distribution. Am I correct in calculating $E(X)$ and $Var(X)$ in this way? It seems that these values must be calculated from a binomial distribution. Any help is really appreciated.
Answer: You double counted $50E(X)$ and $50V(X)$. This because $S_{50}$ is a binomial, sum of 50 iid bernulli, thus in this version of CLT mean and variance are referred to the bernulli.
One way (not absolutely accurate is this)
$$\mathbb{P}(S<10)=\mathbb{P}\left[Z<\frac{10-50\cdot0.4}{\sqrt{50\cdot0.4\cdot0.6}}\right]=\Phi(-2.88)\approx0.0019$$
This result is not quite accurate. To realize that, the exact value using the binomial is
$$\mathbb{P}(S<10)\approx 0.0008$$
To improve our CLT approx, just use the Continuity Correction Factor obtaining
$$\mathbb{P}(S<10)=\mathbb{P}\left[Z<\frac{9.5-50\cdot0.4}{\sqrt{50\cdot0.4\cdot0.6}}\right]=\Phi(-3.031)\approx0.0012$$

To understand this reasoning I suggest you to calculate, for example, $P(S<20)$ so you will appreciate the best approximation I showed you. In fact, with the first approximation you get
$$\mathbb{P}(S<20)=\mathbb{P}(Z<0)=0.5$$
while the exact result with the binomial is $0.4465$
Now using the continuity correction factor you get
$$\mathbb{P}(S<20)=\mathbb{P}\left(Z<\frac{19.5-20}{3.464}\right)=\Phi(-0.14434)\approx0.4426$$
which is very close to the exact result
Comment: Thanks for the answer, I needed to realize that each random variable is Bernoulli distributed, not binomial. Something just occurred to me, which is the formula for standardizing $\bar{X}$ : $(\frac{\bar{X}-E(X_1)}{\sqrt{Var(X_1)/n}})$ with the denominator divided by $n$? Normally to standardize you just subtract the mean and divide by the standard deviation, right?
Comment: @fmtcs ; that's correct! this one is another version of the same CLT. I prefer the former because it is more suitable to me when applying the continuity correction factor but anyway...use the version you are more familiar with
Comment: but I don't understand why that $/n$ is there in the first place, because it seems to me that $\bar{X}$ is not standardized if you multiply the numerator by $\sqrt{n}$ ?
Comment: @fmtcs :A version of CLT is

$$\frac{\Sigma_i x_i -n\mu}{\sigma\sqrt{n}}\xrightarrow{\mathcal{L}}N(0;1)$$

if you divide numerator and denominator by $n$ you obtain
$$\frac{\overline{X}_n -\mu}{\sigma}\sqrt{n}\xrightarrow{\mathcal{L}}N(0;1)$$

which is your latter version.


Is this a constrained optimization?

Question: Consider a minimization with regard to $\theta$:
$Q(\theta) = [y-f(\theta)]'[y-f(\theta)]$ $\quad$  (1)
where $y,(m \times 1)$ is a data vector, $\theta=(\theta_1, \theta_2)'$ is a $p×1$ vector with $\theta_1$ and $\theta_2$ being $p_1 \times 1$ and $p_2 \times 1$, respectively.
In my case, from the first-order condition associated with (1), i.e., $\partial Q(\theta)/\partial \theta = 0$, I have the following (not closed form) solution for $\theta_2$:
$\theta_2 = h(\theta)$ $\quad$ (2)
where $h(\theta)$ is a known function.
If I rewrite the minimization problem as follows
$\min Q(\theta)$ with subject to $\theta_2 = h(\theta)$ $\quad$,
I'm wondering if this becomes a constrained optimization problem since the restriction (2) is derived from the optimization problem (1) itself.
In terms of computation, minimizing (1) with or without a restriction (2) yield very different results.
Answer: The original problem is unconstrained.  When you include the optimality condition (2) as an explicit constraint, the new problem is constrained.  If (2) holds "without loss of optimality," you should get the same optimal objective value.
Comment: Many thanks! Then, the values of $\theta$ that minimize $Q(\theta)$ should be identical regardless of whether the constraint (2) is imposed or not. So, if two are different, that should be a numerical issue, right?
Comment: There might be multiple optimal $\theta$, but you should get the same minimum value for $Q(\theta)$.

Is this a constrained optimization?


how to get the content between the first html tag and the second html tag in ruby

Question: Hi friend~
I want get the content between the first html tag and the second html tag.
for example

Hello <bold>world</bold>!

will return
Hello
What should I do in Ruby?
Thank you~
Comment: Have you tried Nokogiri? it's a lot easier than using regexes to parse HTML
Answer: Regex will be: <[^>]*>([^<]*)

<[^>]*> - math thiw first tag "<...>"
([^<]*) - capture text to open next tag "<...> some text <...>"

how apply him on Rubby - i dont know
look http://www.regular-expressions.info/ruby.html
Answer: A regular expression catching everthing between the first and the second pair of angle brackets lools like
/<.*?>(.*?)</m

The result will be in the first capturing group of the first match.
Note that this will probably fail on HTML comments and JavaScript.


Como inserir elementos em um vetor R com append?

Question:
Estou tentando adicionar elementos a um vetor em R; porém ele dá o
erro dizendo que o objeto não foi encontrado. Realmente é necessário
criar um objeto vazio?

for (i in 1:length(hosts)) {
  n <- nrow(logs_slap[which(logs_slap$host == hosts[i]) ,])
  num_acessos <- append(num_acessos, n)
}

Console:
Error in append(num_acessos, n) : object 'num_acessos' not found
Comment: Bem-vindo ao StackOverflow em Português! Infelizmente, esta pergunta não pode ser reproduzida por quem for tentar respondê-la. Por favor, dê uma olhada [neste link](https://pt.meta.stackoverflow.com/questions/6700/como-fazer-uma-pergunta-reproduz%C3%ADvel-em-r/6701#6701) (principalmente no uso da função `dput`) e veja como fazer uma pergunta reproduzível em R. Assim, as pessoas que desejarem te ajudar conseguirão fazer isto da melhor maneira possível.
Answer: A resposta à pergunta é sim, é preciso criar um objeto vazio. Mas a melhor forma de fazer o que o código tenta fazer e que conseguiria se o objeto fosse criado fora do ciclo for é criar um vetor do mesmo comprimento do host e atribuir valores no ciclo.
num_acessos <- integer(length(hosts))
for (i in seq_along(hosts)) {
  n <- nrow(logs_slap[which(logs_slap$host == hosts[i]) ,])
  num_acessos[i] <- n
}

Desta maneira não se está a tornar o objeto maior de cada vez que lhe é atribuído mais um elemento. Isso obriga o R a chamar as rotinas de gestão de memória e torna o código mais lento.

Ainda melhor é criar o vetor num_acessos de forma vetorizada. Em uma linha:
num_acessos <- as.vector(table(match(logs_slap$host, host)))


GWT getting an inherited module on the compiler's classpath

Question: I have a project with multiple gwt modules, one of which is a library module without an entry point from which the other modules inherit.  All the modules are contained in a single project built using maven and the gwt-maven-plugin.  Unfortunately, building the project fails because gwt:compile is looking for the inherited module on the classpath when it compiles the main modules that inherit it.  How do I get the library module on the classpath for the compilation of the main modules?
Answer: You're going to need to do some creative "Maven-ing," as I just made up the term to describe it. (In reality it probably isn't creative at all, but I'm a bit of a Maven newbie myself, so it stumped me for a while too).
You're right in a sense, the GWT comipler is looking for the inherited module's source on the classpath when it tries to compile your "main" module. To achieve this, you will need to add a dependency, to the main module's pom, on the library module's sources (strictly for the compile phase).
Something like this:
...
<artifactId>main-module</artifactId>
...
<dependency>
  <groupId>library-group</groupId>
  <artifactId>library-artifact</artifactId>
  <type>jar</type>
  <version>0.1-SNAPSHOT</version>
  <classifier>sources</classifier>
  <scope>compile</scope>
</dependency>
...

Now, where you get those sources from can differ. If you're just trying to do this from an IDE, like Eclipse, this is probably enough because the m2eclipse plugin is smart enough to know where to get those sources (if the library-module is also in your workspace). If this is your actual build process, then you will need to modify the library-module's pom to produce the -sources artifact along with the standard "library-artifact." So you'll end up with both:
library-artifact-0.1-SNAPSHOT.jar

and
library-artifact-0.1-SNAPSHOT-sources.jar

Hopefully it's more clear how the gwt-maven-plugin proceeds from that point.
Almost forgot, the one other question I've answered here might be of some use as well: GWT Project Structure.
Comment: Ah, I missed the "single project" part, initially. Indeed, I'm describing a separate project/artifact. However, you should be able to do it just like you have inheritance set up between your other GWT modules. GWT module A's gwt.xml, you'd have "", where Module B is your shared GWT module (with a gwt.xml file, but entry-point-less, if you want). Now, it _should_ be easy for the GWT compiler to find the source for B, since they are all in the same Eclipse project. Have you tried turning Maven debug stack traces on (-X)?
Comment: Thanks for the response.  Some additional clarification on our situation:  We are indeed using Eclipse and currently have our application set up as a single Eclipse project.  Within this project we have several gwt modules that make up different areas of our application.  It made sense to have another, entry-point-less module to house shared resources for the other modules to inherit.  We figured it would require us to set up a new project for our application to depend on, which I think is what you are describing.  But, is there a way to locate the resource module within the primary project?
Comment: For me the missing piece in this answer was how to create this sources artifact. It is as simple as adding the maven-source-plugin to your project as described here https://maven.apache.org/plugins/maven-source-plugin/usage.html
Answer: Ok, I was able to solve this by explicitly listing my GWT modules in the project's pom file's gwt-maven-plugin configuration.  By doing this, I was able to enforce the order of GWT compilation, ensuring that the shared module was compiled first and available to the other modules that inherit from it during their compilations.
Here is an example of the config:
<configuration>
  <modules>
    <module>com.foo.gwt.shared.Shared</module>
    <module>com.foo.feature.one.gwt.One</module>
    <module>com.foo.feature.two.gwt.Two</module>
  </modules>
</configuration>

Thanks to Jason482 for all the help.
Answer: I would have preferred to comment on the answer above but I do not have enough rep to do it. So I am posting my findings here.
Jason482's answer worked for me. Adding:
<classifier>sources</classifier>
  <scope>compile</scope>
to each of my sub-modules dependencies, inside the reactor pom, solved my issue.
The solution that mreynolds went with, adding GWT module references to the main pom file's gwt-maven-plugin configuration, seems to be necessary ONLY if you have other entry points in your GWT submodules. I did not, so that step was not necessary for me.


Magento add email to billing and shipping address

Question: I would like to add email adress of my clients to billing and shipping address.
To do that, I have tried to add var order.getCustomerEmail(), var email into html address template. But it doesn't fill it in.
Code example:
{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}

{{depend company}}{{var company}}
{{/depend}}
{{if street1}}{{var street1}}
{{/if}}
{{depend street2}}{{var street2}}
{{/depend}}
{{depend street3}}{{var street3}}
{{/depend}}
{{depend street4}}{{var street4}}
{{/depend}}
{{if city}}{{var city}},  {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}

{{var country}}

{{depend telephone}}T: {{var telephone}}{{/depend}}
{{depend fax}}
F: {{var fax}}{{/depend}}
**
Email: {{var order.getCustomerEmail()}}**
{{depend vat_id}}
VAT: {{var vat_id}}{{/depend}}

Can it be because of not registered users? But they are also required to enter an email address.
Comment: do you want it on sales order email?
Comment: Yes I would like to add customers email to 'sales order email'
Answer: If you want the customer's email in sales order email, change the below file
\app\code\core\Mage\Sales\Model\Order.php
 locate the function sendNewOrderEmail()
$email =$order->getCustomerEmail();
$mailer->setTemplateParams(array(
       'order'        => $this,
       'billing'      => $this->getBillingAddress(),
       'payment_html' => $paymentBlockHtml,
       'email'       => $email
     )
);

Now you can access this variable like
{{var email}}

NOTE I will advice not to make changes in the core file


lissajous curve ellipse derivation

Question: It is known that if $x$ and $y$ are oscillating with the same frequency and a difference in phase, then the curve they trace is generally an ellipse.
I tried to show this but failed. Can you help me with this? Or please tell me where I can find the derivations.
General Formula:[
\begin{cases}
x=A\cos(\theta+\theta_0)\\
y=\sin(\theta)
\end{cases}
]
Comment: Square $\,x + A \sin \theta \sin \theta_0 = A \cos \theta \cos \theta_0\,$ and substitute $\,\sin \theta = y\,$.
Comment: Please also refer to my post [*here*](https://math.stackexchange.com/questions/2838356/eliminating-theta-from-a-cos-theta-alpha-x-and-b-cos-theta-beta-y/2838863#2838863).
Answer: You can write $\cos(\theta+\theta_0)=\cos(\theta_0)\cos(\theta)-\sin(\theta_0)\sin(\theta)$ so the parametric equations are of the form
$$
\begin{cases}
x=a\cos(\theta)+b\sin(\theta)\\
y=c\sin(\theta)+d\sin(\theta)
\end{cases}
$$
which can be written as a matrix equation:
$$
\begin{bmatrix}
x \\ y
\end{bmatrix}
=
\begin{bmatrix}
a & b\\ c & d
\end{bmatrix}
\begin{bmatrix}
\cos(\theta) \\ \sin(\theta)
\end{bmatrix}
$$
or $X=MY$ with $X=\begin{bmatrix}
x \\ y
\end{bmatrix}
$, $M=\begin{bmatrix}
a & b \\ c & d
\end{bmatrix}
$ and $Y=\begin{bmatrix}
\cos(\theta) \\ \sin(\theta)
\end{bmatrix}$.
If $M$ is invertible (this is the case in the OP, as shown by a quick computation), we can write $Y=M^{-1}X$. We can then transform the identity $\cos^2(\theta)+\sin^2(\theta)=1$ into a quadratic equation in $x$ and $y$. Using the discriminant (for example), you can show this is the equation of an ellipse.

Detail of computations:
More specifically, $M^{-1}=\frac{1}{\delta}\begin{bmatrix}
d & -b \\ -c & a
\end{bmatrix}$ with $\delta=ad-bc$. Therefore,
$$
\cos(\theta)=\frac{1}{\delta}(dx-by),\hskip 5mm \sin(\theta)=\frac{1}{\delta}(-cx+ay)
$$
so
$$
(dx-by)^2+(ay-cx)^2=\delta^2
\iff
(a^2+d^2)x^2-2(bd+ac)xy+(b^2+c^2)y^2-\delta^2 = 0
$$
Therefore, the graph is indeed a conic section. It is not degenerate since it is the image of a circle by an invertible linear function (hence cannot be empty, or a point, or one or two lines).
The discriminant is $\Delta=4(bd+ac)^2-4(a^2+d^2)(b^2+c^2)=-4(ab-cd)^2$ is clearly negative, so it is an ellipse.
Remark: it cannot be a hyperbola or a parabola for topological reasons too.

lissajous curve ellipse derivation


How can we upgrade the Cloud Composer version of our composer environment?

Question: We have a Cloud Composer environment running a no longer current version of Cloud Composer that we would like to upgrade. I found no documentation on how to do that. Does anyone have recommendations on how to upgrade without creating a new environment and losing the run history?
Answer: The only current way to update a Composer Environment is to create a new one and migrate all of the data.
This script should useful for recreating the Environments and maintain your DAG run history and settings:

Script to create a copy of an existing Cloud Composer Environment.
  Creates a clone of a Composer Environment, copying Environment
  Configurations, DAGs/data/plugins/logs, and DAG run history. This
  script can be useful when migrating to new Cloud Composer releases.
Comment: Thanks. We tried that, but it seems that the copies created by the script are the same version as the old environment. So the script does not help to update the environment.
Comment: That's odd, Are you sure about that? I have just tried and the new_copy environment
 is in the latest composer version. The thing is that you cannot set the Composer version when creating an environment, so it will get the latest version possible. That would be weird if you are getting a new composer environment created with an oldest Composer version.
What is your old environment version?
Comment: After your comment, we tried again with the most recent version of the script. It worked this time.


iPhone - What is the best way to display error message below UITextfield

Question: I have a form with many UITextfields like Name, password, email, etc.., and during validation, i want to display the error message for the fields below the respective textfield.
What is the best way to do this. Any examples would really help.
Comment: put a label under the textfield and display error there. Wrap label and textfield into a single custom control for cleaner code
Comment: No wonder your name is "Flash Thunder"....
Answer: Create a new object model containing a textfield, a label and a validation block.
When the textfield resigns first responder, call the block to check if it is valid and if not, display the label
Something like this
<code>@protocol ValidationTextFieldDelegate

-(void) validationTextField:(ValidationTextField*)textField didResignWithResult:(BOOL)result;

@end

@interface ValidationTextField : NSObject <UITextFieldDelegate>

@property (nonatomic, strong) UITextField *textField;
@property (nonatomic, strong) UILabel *errorLabel;
@property (copy) void(^validationBlock)(BOOL);
@property (nonatomic, assign) id<ValidationTextFieldDelegate> delegate;

@end

@implementation ValidationTextField

-(void)textFieldDidEndEditing:(UITextField*)textField {
    BOOL result = self.validationBlock();

    self.errorLabel.hidden = result;

    if (self.delegate) {
        [self.delegate validationTextField:self didResignWithResult:result];
    }
}
</code>
And in your controller
<code>-(void) validationTextField:(ValidationTextField*)textField didResignWithResult:(BOOL)result {
    if (!result) {
        int yOffset = textField.errorLabel.bounds.size.height;

        // Update here the frames of your other textfields, adding the yOffset to their frames
    }
}
</code>
Comment: Thanks. My doubt is how will the remaining below text fields align based on the new label added. I want the errorLabel to be initally hidden and show up once the form is submitted.
Comment: You've got two solutions : either always leave an empty space below each textfield or update your view after a textfield has resigned
Comment: Is there any implementation that I could refer.
Comment: Just updated my code to show you the logic
Comment: Thanks a lot. Have one more doubt. Is it possible to design the Textfields using xib if i use the above ValidationTextField class. If so,how can i do it.
Comment: You should be able to do so but I have a doubt as how to link them with your properties... As you only have one textfield and one label you could do easily do it programmatically. And if you make your ValidationTxtField class inherit from UIView you will be able to create the xib for your controller and lay them out for your form


Selenium element.text() is not considered as a string

Question: Im trying to get an element name with python selenium and print it later but it throws following error:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'using' must be a string

Code line looks like this:
title = driver.find_element((By.CLASS_NAME, 'mt-3')).text()

HTML element looks like this:

ElementTitle

I tried searcing for element by XPath but it seems not to be a reason for error...
Answer: To get a web element text you should apply .text on it, not .text()
Also, there are unnecessary parenthesis here that should be removed.
So, instead of
title = driver.find_element((By.CLASS_NAME, 'mt-3')).text()

it should be
title = driver.find_element(By.CLASS_NAME, 'mt-3').text

Comment: Maybe also consider to remove the double paranthesis. As mentionend in: https://stackoverflow.com/questions/60395570/invalidargumentexception-message-invalid-argument-using-must-be-a-string
Comment: @DevStarter101 you are right, thanks
Comment: Thanks! I needed to do both for it to work
Comment: I know, I just didn't pay attention to the redundant parenthesis at the first look.


How to pass jvm options / Procfile in Elastic Beanstalk Java SE Platform

Question: I am deploying a Spring Boot application (a "war" file) on Elastic Beanstalk Java SE (Java 8) but would like to pass jvm options such as heap size. I created a Procfile with the following content:
web: java -jar application.jar -Xms1024M -Xmx2048M

Unfortunately Beanstalk does not consider this setting and still starts application without the mentioned jvm options.
Please suggest a way to pass jvm options where a war file needs to be deployed on Java SE Platform.
Comment: Is the `Procfile` in the root folder of your deployment bundle?
Comment: Procfile is in the root folder, exactly at the same level where .ebextensions are present. In the directory `/opt/elasticbeanstalk/deploy/appsource` I can see the content extracted from the war file I upload and deploy. The content contains .ebextenions folder, Procfile both
Answer: I faced this problem in the past, and solved by deploying a zip file containing both the application jar and the Procfile, instead of putting the Procfile inside the jar.
Something like this:
zip -r application.zip application.jar Procfile
eb deploy

In the file .elasticbeanstalk/config.yml specify the file to upload:
deploy:
  artifact: application.zip


Skip specific id while getting record from database with Entity Framework asp.net MVC

Question: i want to skip specific record for example i want to skip id umber 10 how i can skip this id using entity framework Skip method.
Code
int id=10;
DB.Brands.Skip(id).ToList();

as we know that it will skip 10 records but i want to skip id number 10 means skip only single id number 10. So any possible way to do that?
Answer: could you do this with a where statement instead?
Skip is (as you pointed out) used to skip N records in a result set.
DB.Brands.Where(n=>n.id != id).ToList();
Comment: that,s also way to do that. so that,s not possible with Skip ?
Comment: Maybe with a bit of jumping through hoops but why would you? The where clause is there and ready to do the job.


Is there anything like g_form.showFieldMsg for GlideDialogWindow popup? (ServiceNow)

Question: Is there anything like  g_form.showFieldMsg which shows an error message under the field for GlideDialogWindow popup (ui page) in ServiceNow?
Answer: This is a little complicated, but here's what I've learned:
What you need to do is add a parameter to the UI page which you can then use in the client script as it renders.
So you'd do something in the client script for the UI page, like:
if (sysparm_fieldMessage) {
    element.showFieldMessage(sysparm_fieldMessage + '');
}

then in your calling code, you'd need to do something like:
gdw.setPreference('sysparm_fieldMessage', 'this is my message');

Answer: You could use for Error : g_form.showFieldMsg('field_name_here', "your_message",'error');
or just for information : g_form.showFieldMsg('field_name_here', "your_message",'info');


On app pool recycle user sessions are lost if application pool identity is set to 'custom account' but not when it is set to ApplicationPoolIdentity

Question: On IIS 8.5 we have an web application running with application pool's identity set to ApplicationPoolIdentity.
When we switch to Custom account instead of the ApplicationPoolIdentity then web application's user session is lost at random and also on app pool recycle.
But everything is ok with the ApplicationPoolIdentity.
Any idea what is the issue with Custom account which is using a windows user account that has IIS_IUSRS permission.
All we need is to have the Custom account identity to behave the same way as the ApplicationPoolIdentity for the session state. Everything else is ok.
Update 1:

We are using InProc Session State Mode as we have not defined the value for the mode property in the web.config file and InProc is the default value
Same IIS web application retains sessions after a manual/auto app pool recycle for all users in case of ApplicationPoolIdentity. Good/bad is not the question here but here is the reason how that my happen: https://stackoverflow.com/a/4089977/218408
Permanently stopping the app pool recycling is not an option for us
Comment: Found a solution. Posted the answer here: [https://stackoverflow.com/a/57688457/218408](https://stackoverflow.com/a/57688457/218408)
Answer: First, to correct a misconception, you're meant to lose state on an App Pool Recycle, unless you've moved state information out of process (for example, by using ASP.Net Session State Server, or a database, or a scheme involving persistent cookes). So unless the app has been designed to cope gracefully with recycling - and they're not by default - you might find that your initial assumption isn't right. See also this answer.
That said - I think the key clue here might be that it sounds like you randomly lose state while the app is running as a custom user without recycling (or apparently without recycling).
Possible things going on here:

The app's crashing for some reason (causing a full App Pool recycle - this'd show up in the Event Logs)
The AppDomain is recycling for some reason (this won't show up in the event logs, but you can attach logging which'll tell you when this happens)
The user's somehow causing one of the above to occur

It's possible the presence of the user causes - for example - antivirus software or another organizational security control to start doing things to the machine (or scan the website files), if it's not simply the app behaving differently and crashing due to something it can't do when not run as a NetworkService-derived user.
So, I'd check:

For evidence of App Pool recycling
For evidence of AppDomain recycling
The Application and System logs for evidence of the app having a problem around the time of the session state loss
Whether it's the particular user, or any user
Whether it can be reproduced with a debugger (or set ShutdownActionExe to dump the process on shutdown, and take a look at what happened in the memory dump).
Comment: Thanks for the detail information. This will help to trace the problem. However as per the answer here: https://stackoverflow.com/a/4089977/218408 my case seems to be valid and not a misconception. I will update my question with more info as I dig more.


Generate pdf from appended html content

Question: I'm having problem with creating a pdf of html content
I want to convert all the content inside a certain div to a pdf. I've tried a couple of converters now but they only convert html-files. I don't want to convert the html-file because the user changes the content on the page with javascript.

I lack experience in this matter but shouldn't there be som simple way to run this on the client without installing something on the server?
I've tried: http://jspdf.com/ and https://pdfcrowd.com/.
jsPdf was in its early stages with html-converting and pdfCrowd just converted html-files(as I understand it)
I welcome all help and oppinions.
Thanks for your time!
Answer: Since you want to convert the page that's edited by the user, you probably need something that uses Javascript. So - enter PhantomJS!
Link to website
Answer: I've used  http://www.tcpdf.org/
its really easy to generate a PDF with that.
See their Examples: http://www.tcpdf.org/examples.php
Comment: I have a problem where I cant install plugins on my host. Otherwise this would be a nice solution.
Answer: You can use
1.HTML2PDF http://html2pdf.fr/en/example
2.tcpdf   http://www.tcpdf.org
3.MPDF   http://www.mpdf1.com/mpdf/index.php
Comment: I will try html2pdf. I't looks like it runs on the client. The reason why I don't want to install plugins on my host is because I can't.
Comment: @Oscar,You want to create pdf without using php?
Comment: @Oscar,Then how to create pdf without installing a plugin like TCPDF in your server?Did you get a solution?
Comment: Im workin on it :). Found a tutorial on nettuts (https://tutsplus.com/tutorial/generating-pdfs-with-php/) where they are using http://www.fpdf.org/

Generate pdf from appended html content


Choosing features to identify Twitter questions as "useful"

Question: I collect a bunch of questions from Twitter's stream by using a regular expression to pick out any tweet that contains a text that starts with a question type: who, what, when, where etc and ends with a question mark.
As such, I end up getting several non-useful questions in my database like: 'who cares?', 'what's this?' etc and some useful ones like: 'How often is there a basketball fight?', 'How much does a polar bear weigh?' etc
However, I am only interested in useful questions.
I have got about 3000 questions, ~2000 of them are not useful, ~1000 of them are useful that I have manually label them. I am attempting to use a naive Bayesian classifier (that comes with NLTK) to try to classify questions automatically so that I don't have to manually pick out the useful questions.
As a start, I tried choosing the first three words of a question as a feature but this doesn't help very much. Out of 100 questions the classifier predicted only around 10%-15% as being correct for useful questions. It also failed to pick out the useful questions from the ones that it predicted not useful.
I have tried other features such as: including all the words, including the length of the questions but the results did not change significantly.
Any suggestions on how I should choose the features or carry on?
Thanks.
Comment: What is your definition of a useful question? I am not sure if I can extrapolate your definition by the examples you gave.
Answer: Interesting problem!
Have you tried using other classifiers? I bet you'd get better performance using a support vector machine (SVM) classifier. There's a wealth of literature demonstrating that SVM's can excel in high-dimensional classification problems (such as yours...and many text-classification problems, for that matter). In my experience, Naive Bayes can get mislead by uninformative features, when the problem space gets large.
In terms of other features you could try, it might be interesting to have a feature denoting the co-occurrence of a question-type word (e.g., what, when, how), and a noun (e.g., polar bear or basketball). Have you taken a look at the ones that you've labeled as interesting and considered what the characteristics were that lead you to that conclusion?
Comment: Thanks for the suggestions. I have never worked with SVM before but I wil get started on that. I have tried to look at both sets useful and not_useful questions to see if there is any pattern but it looks very random to me. Im still playing around with different features to see if it can improve the classifier.
Answer: With only 3000 examples, your data set is fairly small (tweets are short) for a naive word frequency approach. If you use good priors on word frequencies, you might have better luck. Intuitively, I would expect words with lower frequency in the english language to have a higher rank of "interestingness".  There are lots of datasets out there to get these word frequencies from.

Choosing features to identify Twitter questions as “useful”


Tips on playing quietly/gently?

Question: I am amateur self taught musician and I am new to reed instruments. I decided to try out saxophone, but the problem is, it is way too loud. Each time I try to practice I need to blow very hard to obtain sound.
I know it is possible to play gently and quietly and I am aware it's question of practice the embouchure and handling the reed with a mouth. I know the whole "color", all characteristics of saxophone sound come from how we handle the reed with our mouth. The problem is I cannot find any tips on how to start.
Nearly every single tutorial I found on the internet doesn't say a word about volume control, and for me it is essential, because I live in an apartment and need to be able to practice without bothering my neighbors, so I prefer to learn first controlling volume.
I'd like to add, please don't say anything like "go find a teacher" et cetera, I will not mark this kind of answer as solution, because this is not useful for me neither for many others self taught musicians who will read this post hoping to find some tips.
Answer: Playing quietly through a sax is all about having a sufficient embouchure (mouth position/tension), to create a sound when pushing less air through.
It's very normal to initially be playing loud when first learning the sax, and your embouchure is less developed - unfortunately this develops mainly through sustained (loud) practice. I wouldn't say there's a particular secret to playing quietly - only exactly what you'd expect - blowing less.
Let's knock out the basics, to ensure you're not making a simple mistake which is making things harder. As a beginner, you should be using a low strength reed (1.5), and a 'basic, no-frills' mouthpiece. (You probably have one of these, just be aware there are mouthpieces specifically designed to make a big sound, which won't be suitable for learning on - if you've brought second hand.) At the moment, I imagine when you blow less, you make no sound, and if you start to blow harder, you get a bit of a honk.
That unfortunately, is somewhat the nature of learning sax, your mouth adjusts almost 'subconciously' to make things easier for you. Your best way to practice playing quieter I would say is to simple attempt to make a respectable sound be blowing less, and adjusting your mouth to do the hard work, rather than blowing more to get a sound out, as I image you currently would do.
Sax Mutes
If your problem is practising indoors, "Saxophone mutes" are available. There are simple £25 ones, which involve shoving a few things inside your sax, and more extravagant £400 ones, which essentially are a container for the entire sax. I personally have never tried one, and they have mixed reviews, but you may be interested in taking a look. Don't expect the same results are brass instrument mutes of course, as the sound is formed in an entirely different way!
Disclaimer
I would completely recommend getting a couple of lessons to start off with, to make sure you are approaching things in the right way. Embouchure technique is something most definitely best taught by someone who can see what you're doing with the sax, and advise. I respect however, that you've noted this is not an option you're interested in - however I wouldn't want to post my answer without reference to it!
Comment: Thank you, this is a very good answer. So to make sure I understand it correctly, it is all question of correct mouth position, right? And my reed is "2 - medium soft" and my mouthpiece is "Rico Royal Weril W5". I suppose it is not "basic, no frills" one..
Comment: I'm sorry, I can't find anything about the W5 mouthpiece online! Perhaps take it into a music store, they may know more, and be able to advise on something suitable. A softer reed will help when you are just starting out - again, if you have a local shop, it may be worth dropping in to pick up a couple and ask for their recommendations at the same time - I generally find prices aren't much more online. (At least in the UK!)
Comment: Thanks Chris. Actually after reading your answer I tryed yesterday to play more gently, more precicesly, by arriving at the moment when reed starts to vibrate and trying to maintain it and actually after about one hour of practice I was able to create a gentle soft sound and maintain it for few seconds (but for now only for about three or four notes), it is a progress. I'm very greatfull for your tips. Thank you.
Comment: Great, that sounds exactly the right way to go about it! Good luck!
Answer: Normally people that are new to a saxophone would go for a 1.5 reed but I was also having the same problems. My band instructor then gave me a 2.5 reed, when I still couldn't  control my volume, he gave me a 3 to 3.5 reed. I then started playing bari sax and that helped control my air more. Im down to I think a 2.5 reed since then and I can control my air so much better, but Im still known as the loudest but worst sax player in the band.
Answer: The best way to learn to play softly is to play each note from the very softest you can to the loudest and back to the softest. If you're worried about your neighbors perhaps don't go to the loudest, go to medium instead. You can also do this by playing quarter notes going from soft to loud and back again. You will find over time you will get more control and you will be able to play softer as you get better. I also recommend getting musician earplugs to protect your ears when practicing for long sessions as Sax is loud in general and you want to protect your hearing.
Answer: A very common issue is only being able to play loud because your mouthpiece is way too far in your mouth.
You can find a position which is good for playing loud as well as soft and at the same time producing the most pleasant sound by first trying the extremes and their effect:
Mouthpiece too far in. sound is quacky, only loud playing possible.
Too less mouthpiece in the mouth: stuffy, very soft sound to no sound at all because the reed completely closes the opening.
By moving from one extreme to the other you will be able to find an intermediate position where the sound is the most pleasant, with a good balance of harmonics and being able to play loud and soft.
The bottom lip, which rests between reed and teeth should be also in an intermediate position, neither too far in nor too far out. This is usually the position of your bottom lip when you pronounce the letter V.
As important as the embouchure is a good breathing control (through the diaphragm).
Learning an instrument is a continuous challenge where self-observation (sound, feel, movement, optic) as important is as absorbing (listening to good players, reading, getting advice).
There are surely many good players around who never had a lesson and I know you don't want to hear this but finding a good teacher would be a good way to avoid a lot of trouble and learn much faster eliminating a whole deal of guesswork and leaving more time for making music!
Answer: okay, so I am a student learning how to play the sax for a year now or so I think.  What Id try to do now is, put the mouthpiece less in my mouth and blow less just like the writer said . I think It would also help if you sat up straight so the air flows more easily and also so you can breathe properly, Make sure you can see just a sliver of the mouthpiece when you put your reed. And, when you put the mouthpiece onto the sax, try seeing that it is in the middle a bit almost reaching the end of the cork but not quite.
Answer: I am also a self-taught alto sax player and agree with the above. I had to hold my saxophone further away from my chest. By loosening the neck strap a bit, I could hold less of the mouthpiece between my lips and play more quietly. In my case, it wasn't about the strength of the reed, but only about the neck strap
Answer: Im self taught on alto sax (having played the piano, oboe briefly and bagpipes). I went for one lesson after I reached a point where I wanted more out of my sax (feeling to the music). The teacher, rightly so, politely informed me I nearly gave him ear bleed when it was supposed to be mf (medium loud). I then realised I had a similar problem of just playing too loud and hense the lack of feeling to the music. I totally agree it is how far you have your mouthpiece in your mouth. It does take a while to get it so it becomes second nature but try to enjoy all of the trials. I found it quite amazing how to bend notes and also enhancing the sound you can produce just by altering your mouth whilst playing. Good luck and enjoy

Tips on playing quietly/gently?


Correct process for feature selection with cross validation with R Caret and Boruta

Question: I have a specific question relating to the use of the two R packages in building a prediction model; namely caret (training) and boruta (feature selection).
Firstly; I have a small data set ~ circa 2000 records. I have chosen to split this immediately in to 1600 ish records for training and 400 records for a holdout set.
Within the 1600 records, I have used caret to train and optimise the mtry parameter on a random forest model using 5-fold cross validation.
I've then applied this model against my holdout set to measure its AUC.
So far so good. However, having come across Boruta I want to try reducing the number of features in the data to hopefully improve this AUC fit. I realise random forest does this to some extent, but the Boruta model uses randomised significance testing to avoid overfitting, and this "feels" like a worthy improvement.
My question therefore is: where in this process is it correct to run Boruta? I'm wary from other posts here that it is incorrect to apply feature selection prior to CV, but does this still apply to my case where I've held out a clean, unseen 400 records?
Am I duplicating effort in applying Boruta? Is it worth doing CV when I have a holdout set?
Any advice would be gratefully received! Thanks.
Comment: I'm surprised that nobody answers the question!
Comment: Note that feature selection may make generalisation performance worse rather than better, especially if you have a lot of features and not very  many samples.  The reason is that the more features you have, the greater the degrees of freedom available to minimise the feature selection criterion, and so the greater the likelihood of over-fitting the feature selection criterion.  The smaller the dataset, the greater the variance of the feature selection criterion and the easier it is to overfit.  So if improving performance is the only aim, regularisation is likely to work better.
Comment: What are your constraints? If you have enough computational time, I'd

1) use nested CV, as a single hold-out will be spoiled after a series of (indirect) attempts of improving metrics

2) run boruta inside CV and on the whole data, and compare results.

Do you have time to sort out potential collisions? Eg if you get different importance with boosting/lasso and boruta, which one you'd be ready to rationalize? Will you have time for further experiments? If no, I'd go with nested CV + model's native feature selection.
Answer: Since you created a separate test set prior to feature selection / model training, any error estimates for that test set would still be valid.
That said, the biggest positive change that you could make that comes to mind would be to use some variant of K-fold CV (10-fold, LOO, Repeated K-fold CV, or Stratified Repeated K-fold CV) to repeat your entire process on different splits of the data, to ensure that your results aren't overly specific for the particular test set you generated.
Caret and scikit-learn both provide functionality to help you generate indices for all of the splits, so it just takes a little bit of time to use these to generate the various splits and repeat your entire process for each partitioning.
Regarding the use of Boruta followed by RF, it's less obvious how necessary the feature selection step is, and most likely it will depend on the nature and scale (# features) of your data. Random forest seems to perform well even when the number of features is much larger than the number of samples you have, but at some point it will start to be affected by the disproportionate number of features. As such, I personally tend to combine the two approaches, using feature selection as a first-pass method to eliminate the least informative variables, and then training/optimizing a final model on the remaining subset.
Ultimately though, the best way to find out is to try both approaches, using proper CV, and compare the impact of each on downstream model performance.


How to link block and view to basic page

Question: Please tell me how to link a block and view with to a basic page.
for example I want to add a block for featured service and assign with view, my problem is how to assign with a basic page.
Comment: Your question is a bit unclear, do you mean you have built a block with views and now you want to create a link inside it to a basic page? or you want the block to shown in specific page?
Answer: You can assign a view and/or block to a basic page in structure > blocks. You can add both view and block to the page.


Como alterar o EF6 para criar campos DateTime como datetime2

Question: Estou trabalhando com **EF6 Code-first", banco de dados SQL-Server.
Me deparei com o seguinte erro, ao salvar um objeto com propriedade DateTime.

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
  ↵The statement has been terminated.

Pesquisando, verifiquei que o EF6 por default, cria as propriedades do Tipo DateTime do C#, como o tipo datetime do Sql-Server.
Fiz algumas pesquisas para entender a diferença, até mesmo criei uma pergunta sobre isso aqui no stack datetime vs datetime2. qual é a melhor?, na resposta do colega, ele destacou a sugestão na própria documentação da microsoft, indicando o uso do datetime2. Conforme menciono abaixo..

Use os tipos de dados time, date, datetime2 e datetimeoffset para o novo trabalho. Esses tipos estão de acordo com o SQL padrão. Eles são mais portáteis. time, datetime2 e datetimeoffset fornecem mais precisão de segundos. datetimeoffset é compatível com fuso horário para aplicativos implantados globalmente. Fonte: https://docs.microsoft.com/pt-br/sql/t-sql/data-types/datetime-transact-sql

Baseado nisso, eu quero saber como fazer com que o EF6, passe a usar o datetime2, sem ter que configurar propriedade a propriedade. Que seria da seguinte forma:
Property(m => m.Created)
        .HasColumnName("Created")
        .HasColumnType("datetime2")
        .IsRequired();

Eu quero uma configuração global.
Comment: @VirgilioNovic é o V12 do azure
Comment: Qual a versão do seu banco?
Answer: No meu caso, eu defini isso no método OnModelCreating, acrescentando essa linha:
modelBuilder.Properties<DateTime>().Configure(c => c.HasColumnType("datetime2"));

Foi uma resposta dessa pergunta no SO (não a aceita, mas a que me ajudou): https://stackoverflow.com/questions/15687408/how-to-switch-to-datetime2-in-enitity-framework-sql-server-2008-project
Answer: No seu Context você pode configurar para que todas propriedades do tipo DateTime sejam datetime2. Para isso é necessário dar um override o método OnModelCreating o código seria assim:
public class MyContext : DbContext
{
    public MyContext()
    {}

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Properties<DateTime>()
            .Configure(p => p.HasColumnType("datetime2"));
    }
}


Prepare name and address for use with drupal_mail()

Question: I'm having problems with certain characters when using the drupal_mail() function.
Here is the apache error.log entry for the issue:

Ignoring invalid 'To:' recipient address '=?UTF-8?B?IsWgxZLFvcWhxZPFvsW4wqXCtcOAw4HDgsODw4TDhcOGw4fDiMOJw4rDi8OMw40=?=  =?UTF-8?B?w47Dj8OQw5HDksOTw5TDlcOWw5jDmcOaw5vDnMOdw5/DoMOhw6LDo8Okw6XDpg==?=  =?UTF-8?B?w6fDqMOpw6rDq8Osw63DrsOvw7DDscOyw7PDtMO1w7bDuMO5w7rDu8O8w73DvyI=?=  =?UTF-8?B?IDxjaXRyaWNndXlAZ21haWwuY29tPg==?='
  Transaction aborted: no recipients specified

For sake of example, what would be the simplest way to successfully send an email (In the RFC2822 format of "User <firstname.lastname@example.com>") to:
ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÍÎÏÐÑÒÓÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñóôõöøùúûýÿ <email@example.com>

Currently drupal_mail() fails with:

"Unable to send e-mail. Contact the site administrator if the problem
  persists."

Preferably, I would like to be able to keep these special characters intact.
Otherwise, could I use a project like Transliteration or Pathauto to convert or prepare the string? If so, which project and function should I use to prepare the "To" name?
Drupal Log Message:
Comment: The watchdog log (dblog.module) should contain more information, including the actual error message.
Comment: Attached a graphic of the error from watchdog. :)
Answer: All credit to @deceze
Original Solution
In short:
mb_internal_encoding('UTF-8');

$name  = '山本';
$email = 'firstname.lastname@example.com';
$addr  = mb_encode_mimeheader($name, 'UTF-8', 'Q') . " <$email>";


Is using the same person as data observation in different time stamps a way to produce data leakage in a Machine Learning model?

Question: Let's assume we are going to train a regression model (could be any ML tabular solution for regression. Ex.: LGBM, XGBoost, Perceptron, ...) to predict a customer profit in the next month. While setting up the training dataset, we observe that the same customer appears in the dataset 3 times like the following table:

ID
REFERENCE_MONTH
PROFIT ON MONTH M-3
PROFIT ON MONTH M-2
PROFIT ON MONTH M-1
PROFIT ON MONTH M+1 (TARGET)

123
2022/04
2,00 (2022/01)
4,56 (2022/02)
3,12 (2022/03)
7,87 (2022/05)

123
2022/05
4,56 (2022/02)
3,12 (2022/03)
1,02 (2022/04)
9,85 (2022/06)

123
2022/06
3,12 (2022/03)
1,02 (2022/04)
7,87 (2022/05)
2,64 (2022/07)

The columns ID and REFERENCE_MONTH are just to determine the customer.
The true training variables would be PROFIT ON MONTH M-3, PROFIT ON MONTH M-2 and PROFIT ON MONTH M-1.
Therefore, the target variable is PROFIT ON MONTH M+1.
My doubt is about the fact that the target variable in row number 1 is 7,87 because it refers to 2022/05, but this same value is also an independent variable for row number 3. Does this characterize a data leakage? I mean, the target variable for customer 123 in REFERENCE_MONTH = 2022/04 is inside the training dataset.
Answer: This shouldn't be a problem if all these records are in the training set.
There could be a problem if some records for the customer are in your training set and others in your test set if you want to use the model to predict profit for customers for which you have no training data. If this is the case then have a separate set of customers for training and testing to avoid any data data leakage.
I'd also suggest randomly shuffling the training data before training your model (if the package you're using doesn't do this for you), as the model may not train as well if related rows are clustered together.


How to Find Current Month and Year From Custom Date range?

Question: I have a problem about custom date range. let me explain it, for our company month count from current month day 21 to next month day 20. if i want to know which employee join current month then normally i can find using sql
SELECT *
  FROM tblEmployeeMaster
  --CURRENT MONTH
  WHERE MONTH(DateOfJoining)=MONTH(GETDATE())  AND YEAR(DateOfJoining)=YEAR(GETDATE())

but for this custom date range i can not find employee who are join in this month. For example in this system if i want to find list of employee joined in this month then result will be show that employee who join in previous month  after day 21 to current month day 20. Could someone please help me?
Comment: which custom date range?
Answer: In this example, this month's period is considered to be from 21 of the previous month to 20 of current month, employees in that period are considered to be this month's employees (all who came to company after 2012-05-21 until 2012-06-20 (including 2012-06-20)). Try it:
SELECT  DateOfJoining,
        DATEADD(DAY, 20, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 1, 0)) PeriodStart,
        DATEADD(DAY, 19, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)) PeriodEnd
FROM    tblEmployeeMaster
WHERE   DateOfJoining > DATEADD(DAY, 20, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 1, 0))
        AND
        DateOfJoining < DATEADD(DAY, 20, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0))

Comment: There is one more thing, if DateOfJoining contains dates together with time, for instance '2012-06-20 13:00:00' and you want employees who came that day, WHERE condition should be changed to:  WHERE   DateOfJoining > DATEADD(DAY, 20, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 1, 0))
   AND
   DateOfJoining < DATEADD(DAY, 20, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0))
Answer: SELECT *
FROM tblEmployeeMaster
WHERE DateOfJoining BETWEEN CAST(CAST(YEAR(GETDATE()) AS VARCHAR) +'-'+ CAST(MONTH(GETDATE()) AS VARCHAR) +'-21' AS DATETIME)
AND CAST(CAST(YEAR(DATEADD(month,1,GETDATE())) AS VARCHAR) +'-'+ CAST(MONTH(DATEADD(month,1,GETDATE())) AS VARCHAR) +'-20' AS DATETIME)


Reduced models after finding significant interactions

Question: If you run an ANOVA and find that there are significant interactions, do you then pull the variables out individually and re-run the ANOVA?
I am using Type III.  I want to see if there is a difference in survival between 3 groups, but I have to include 3 variables other than group in my model to make sure they didn't influence survival as well.  When I do that A affects survival, and so do A*D and A*E, but when I run A, D, and E by themselves, nothing affects survival.
I wish had a better grasp on stats, because I am still so confused.  In essence, I am looking at how survival differed between 3 groups of animals while taking into account that length, weight, and age may have played a role.  When I look at these factors individually, none had a significant effect on survival...but, when I include interaction terms (i.e. length*weight, group*weight, etc.) the variables are significant.  What does this mean? Am I wrong to put in my results that x,y, and z do not affect my results?
Comment: You could conceivably leave B and C out but that should only affect things in specific instances.  What kinds of sums of squares are are you using for your ANOVA?  Do you know if there is any correlation among your predictors?  What, specifically do you really want to find out.  (It's better if you edit your question, not just add a comment.)
Comment: Why do you mean by "pull the variables out individually"? Run an ANOVA with an interaction but no main effects? Run separate ANOVA with each factor in turn?
Comment: Example: I ran a full model.  A was sig, A*D was sig, A*E was sig, but B was not and C was not nor were any of the interaction terms that included B and C.  Do I rerun the ANOVA with A, D, and E individually to see which variable actually influenced my results?
Comment: I wish had a better grasp on stats, because I am still so confused. In essence, I am looking at how survival differed between 3 groups of animals while taking into account that length, weight, and age may have played a role. When I look at these factors individually, none had a significant effect on survival...but, when I include interaction terms (i.e. length*weight, group*weight, etc.) the variables are significant. What does this mean? Am I wrong to put in my results that x,y, and z do not affect my results?
Answer: This is akin to a stepwise procedure and generally not recommended. Adjusting a model is good for prediction or for explorative purposes but it biases p-values if those are computed afterwards on the same dataset. Ideally, if the main objective is testing then you should specify the model in advance and stick to that.
You also need to take into account the fact that the difference between significant and not-significant is not itself significant, there is really nothing special about conventional thresholds. This means that if the p-value is .04 for one factor and .06 for another, you have very little evidence that the first is somehow more important than the second one. Formally, you cannot reject the null hypothesis in the second case but that is not evidence than it is true either. Removing one but not the other based only on this seems arbitrary.
Furthermore, what purpose would it serve? If you don't have too many potential variables or particular issues with your model, there is no reason not to include all your covariates/predictors.
See also Frank Harrell's work and previous questions on this site:

Is a variable significant in a linear regression model?
Classic linear model - model selection
When to drop a term from a regression model?
Comment: I wish had a better grasp on stats, because I am still so confused. In essence, I am looking at how survival differed between 3 groups of animals while taking into account that length, weight, and age may have played a role. When I look at these factors individually, none had a significant effect on survival...but, when I include interaction terms (i.e. length*weight, group*weight, etc.) the variables are significant. What does this mean? Am I wrong to put in my results that x,y, and z do not affect my results?
Comment: +1, lots of good advice here. However, I wonder if the OP's main issue is how to understand the nature of interactions. @user26934, I wrote an answer here: [interaction-in-generalized-linear-model](http://stats.stackexchange.com/questions/49002//49701#49701), that tries to explain interactions; you may find it helpful.
Comment: I understand the definition of interactions, but not the usage of it in SAS.  You do things one way and you get significance.  You turn around and do it the other way, and there is no significance.  This dilemma has lead me into a world of confusion and, despite all that I have read thus far, I am utterly confused.


How to create the "wubs" in dubstep?

Question: One of the signature sounds of dubstep is the "wub-wub-wub" sound.
How do I create this sound?  I'm using Reaper as my DAW but if there's a way to create the sound with subtractive synthesis on a 3 oscillator synth, I'd be interested in that, too.
Comment: [That's how](https://www.youtube.com/watch?v=W0dguxWkiik) :D
Answer:
How do I create this sound?

This kind of sound is usually created with modulation on synthesizers. Like @foreyez already mentioned in the comments, you can use an LFO (Low Frequency Oscillator) to modulate your sound.
For example you can set up a low pass filter on some basic sound which will filter out the top end of your sound. So only the low end part will come through. Then you can link an LFO to control the frequency where the low pass filter filters. The LFO will now raise and lower the frequenzy where the low pass filter runs over time. The faster the LFO runs, the faster will the "wobble" get.
You can experiment with different kind of sounds, filters, lfo's, envelopes and all these settings which your synth provides. You can combine them and try new things out.
The link from @foreyez seems a good starting point.
You should familiarize yourself with what all these different knobs and filters are really doing with the input signal and play around with them.
You can also experiment by using samples instead of basic synth sounds which you want to modulate. Play with the sample-rate and the time-stretching.
Like the sound of a tie fighter from starwars (which at least to me has a similar timbre like a lot of dubstep sounds) is just the sound of a car which runs on a wet road combined with the sound of an elephant crying for its newborn.
Try to be creative.

if there's a way to create the sound with subtractive synthesis on a 3
  oscillator synth

I am by far no synth-expert, but if i get the word subtractive synthesis right, it is basically what i have written above.
From wikipedia

Subtractive synthesis is a method of sound synthesis in which partials
  of an audio signal (often one rich in harmonics) are attenuated by a
  filter to alter the timbre of the sound

If you can do this with the synth you are using depends on capabilities of the synth. I have often seen massiv beeing used. But basically any synth with some basic lfo and filter can work out.
Comment: I think that it is not uncommon to add a compressor (or similar) as an envelope follower that ducks the audio of *other tracks* when the beat hits.
Comment: Yes, thats side chain compression. It could be added, but is not necessarily part of the "wub-wub" bass itself.
Answer: In general, to generate a "wub" you just have to change the timbre over (a relative short amount of) time. If the amplitude (volume) is changing it's called a tremolo. If the frequency (pitch) is changing it's called a vibrato. If the timbre is changing it's a "wub" in a dubstep context, or a "wah" in an electric guitar context.
So you use the same tools that you use for tremolos and vibratos:

LFOs
Envelopes
Velocity
Aftertouch
Track automation
Envelope followers
Triggers
Sidechain

But instead of targeting them to amplitude or frequency, you target them to timbre, or more specifically:

Filter frequency
Filter resonance
FM amount
Overdrive
Equalizer
Distortion
Overtone amplitude
Compressor

The actual "how to" heavily depends on the tool you are using, but in general it is achieved by routing a modulator to a component that is affecting the timbre of the sound.

subtractive synthesis on a 3 oscillator synth

The most common way is to route an LFO or envelope to the filter's cutoff frequency. The "wubs" will become more accentuated if you increase the filter's resonance.
A lot of the "wubs" you hear in dubstep are made through FM or additive synthesis though, so you might want to look into those.

 (Pitch - frequency, and amplitude - volume are not actually the same thing, but I'm using the oversimplification to make the answer more clear for a layman.)

How to create the "wubs" in dubstep?


Differentiation: $y = 9x + \frac{3}{x}$

Question: Differentiate $y = 9x + \frac{3}{x}$
I think the first step is to turn $\frac{3}{x}$ into a more "friendly" format, so $x$ to the power of something maybe? How do I get $x$ with an index from $\frac{3}{x}$?
Comment: 9+(-3/x^2) ,,,,
Answer: $\frac{3}{x} = 3x^{-1}$
Then the derivative is $3*(-1)* x^{-2} = - \frac{3}{x^2} $.
Comment: That makes sense, thanks
Comment: Yes I understand
Comment: Remember the definition of negative and rational powers of x, it will make it much more simple to calculate derivatives e. g. x^(1/2) is the square root, and 1/x^a is x^(-a)
Answer: Since you referenced implicit differentiation ...
$xy = 9x^2+3\\
x dy + y dx = 18x dx\\
x dy = dx(18x - y)\\
dy/dx = (18x-y)/x = 18-y/x
= 18-(9+3/x^2)
= 9-3/x^2
$.
A simpler example...
$y = 1/x\\
xy = 1\\
x dy + y dx = 0\\
dy/dx = -y/x
= -1/x^2
$.
And in case you confuse f abd g ...
$y = f/g\\
gy = f\\
g dy + y dg = df\\
\\
dy = (df - y dg)/g
= (df-f dg/g)/g
=(g df - f dg)/g^2
$.
Answer: You can also apply the definition (whenever $x\neq 0$):
\begin{align*}
f(x) = 9x + \frac{3}{x} \Rightarrow f'(x) & = \lim_{h\to 0}\frac{1}{h}\left(9(x + h) - 9x + \frac{3}{x + h} - \frac{3}{x}\right)\\\\
& = \lim_{h\to 0}\frac{1}{h}\left(9h - \frac{3h}{x(x + h)}\right)\\\\
& = \lim_{h\to 0}\left(9 - \frac{3}{x(x+h)}\right)\\\\
& = 9 - \frac{3}{x^{2}}
\end{align*}
Hopefully this helps !

Differentiation: $y = 9x + \frac{3}{x}$


Adding custom layer to openlayers map

Question: I'm working with Openlayers and I would like to add a custom layer to a map with markers from a webservice.
It should works in this way:

I create a map with Openlayers UI and display it in a page;
I call an external webservice that returns me X elements with lat/long informations;
I show these elements in the map as a normal layer, with markers etc.

The questions are:

Have I to create with Openlayers UI a custom layer and then I've to populate it with js/ajax?
Or I should create a map without a layer and add this layers js/ajax, and popoulate it with js/ajax?
Answer: One way to do this is with a views geojson layer. This seems to be the only way that works right now...at least for me.
With static data, you create a views display of type feed (create a view with no page or block and set it to type feed). Then, set the format to geojson. You'll have to set the settings to your geofield, and add your geofield as a field to the view. Then finally, create a layer through the OL UI and set your feed as a source. Hope this helps.

Adding custom layer to openlayers map