Ukulele - tuning the C string

Question: I just bought an inexpensive Ukulele — the model is Aklot Concert Ukulele — I bought one for my niece as it sounded so good.
I am having a problem with tuning. When I try to tune the C string, the tuner goes from B to D and does not even show C. Why is this happening?
Is Aklot a good beginner brand?
Comment: It's probably the tuner causing an issue and not the instrument.  What tuner are you using?  You might be using a guitar tuner that only shows the notes for guitar standard tuning (EADGBe).
Comment: Try and find a manual for your tuner. like Edward said it is probably set to guitar but it may have other modes you can switch to. Either a chromatic mode or a ukelele mode in C will work.
Comment: We need to know exactly which tuner you are using, before proffering a sensible answer. It will be the tuner with the problem, not the uke.
Comment: Are you using the [Aklot clip-on tuner that comes with the ukulele](https://www.youtube.com/watch?v=b4ZqPiVDhEY&t=143s) if you bought [the starter kit](https://www.aklot.com/goods-47.html)?  See [how to tune another ukulele using a similar clip-on tuner](https://www.youtube.com/watch?v=8HxHroYse2o).
Comment: I'd like to add that if these comments have not given you a satisfactory answer to your question then you should edit it and post specific information on your tuner, the brand, model and perhaps a photo.
Comment: See some of the comments on https://music.stackexchange.com/q/132471/78419
Answer: The problem is with the tuner. As was mentioned in the comments, first see if your tuner will tune any notes other than EADGBE; if not, then it's a guitar tuner and won't tune a ukulele; get a chromatic tuner. You could also try to count 4 frets towards the bridge on the C string and tune to an E.
You can also try clipping the tuner to different places on the peghead; sometimes, overtones can overwhelm a tuner.

Ukulele - tuning the C string


Finding a common subsequence given two sequences on the same elements

Question:
Let $A = \{x_1, x_2, x_3,\dots\}$.
Claim: If a sequence $y_k$ in $A$ contains infinitely many distinct
  elements, then it has a subsequence $\{y_{k_m}\}$ that is a
  subsequence of the $x_n$ exhibited.
In short, two sequences constructed from the same set with infinitely many distinct elements
  must share some common subsequence.   (Is this rephrasing correct?)

Intuitively, this seems true, but how do I know for sure? Or is the claim false?
Answer: It is true, and here is a constructive proof that such a subsequence exists:
Begin with the element $y_{k_1}=y_1$ which is equal to $x_{n_1}$ for some index $n_1$. There are $n_1-1$ elements that precede $x_{n_1}$. So, by the pigeonhole principle, one of the next $n_1$ elements  in the sequence $\{y_k\}$ must have an index in $\{x_n\}$ which is greater than $n_1$.  Call this element $x_{n_2}=y_{k_2}$.
This process can be repeated indefinitely to produce a subsequence of $\{y_k\}$ that is also a subsequence of $\{x_n\}$.  In other words, for a given $y_{k_i}=x_{n_i}$, we find $y_{k_{i+1}}$ by selecting a member of the next $n_i$ members of $\{y_k\}$ that is further along in the sequence $\{x_n\}$.
Comment: Thanks for this constructive (instructive) proof.


Prove that $\overline{A} - A \subset A'$

Question: Prove that $\overline{A}-A \subset A'$
I did the following:
Let $x \in \overline{A}$ $\wedge x \not \in A' $
$\forall r_x>0$ $\{B(x,r_x) \cap \overline{A} \not = \emptyset\}$
$\implies \forall r_x>0$ $\{B(x,r_x) - \{x\}\cap \overline{A} \not = \emptyset\}$
$\implies \forall r_x>0$ $\{B(x,r_x) - \{x\}\cap A' \not = \emptyset\}$ Because $A' \subset \overline{A}$
$\implies x \in A'$
$\therefore \overline{A}-A \subset A'$
Comment: Is $A'$ the derived set of $A$?
Comment: Is the accumulation point set
Answer: $\overline A= A\cup A^{'}$.
Since $x\in \overline A$ but $x\notin A$, so $x\in A^{'}$.
Thus $\overline A\setminus A\subset A^{'}$.


How to format "cloud_auth" in logstash pipeline output

Question: I'm running logstash 7.12.1, and the pipeline I'm trying to run will not accept my cloud_auth syntax for some reason. It hits an error right after the " that contains the user:password pair. I've triple checked the documentation below and can't find the problem.
https://www.elastic.co/guide/en/logstash/7.12/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-cloud_auth
https://www.elastic.co/guide/en/logstash/7.12/connecting-to-cloud.html
[ERROR][Converge PipelineAction::Create] agent - Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Expected one of [ \t\r\n], "#", "{", "}" at line 15, column 20 after output {\n  elasticsearch { \n    cloud_id => "cluster:djMWUw\n    cloud_auth => "", :backtrace=>["/usr/share/logstash/logstash-core/lib/logstash/compiler.rb:32:in compile_imperative'", "org/logstash/execution/AbstractPipelineExt.java:184:in initialize'", "org/logstash/execution/JavaBasePipelineExt.java:69:in initialize'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:47:in initialize'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline_action/create.rb:52:in execute'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:389:in block in converge_state'"]}
output {
  elasticsearch {
    cloud_id => "cluster:dXM2VzdEu2NLNs3VkmVLlv5MMQMVOQ5NjiGyafdsg63DFH67M2JhNzlhOTZmOTNjJDM5ZWYyZWNiYzQ2NTliNWM4ZESTGARFHhsrtghsdfMWUw
    cloud_auth => "elastic:lpertgAFHJYTNzWFvR2aH"
 }
}

Answer: You are missing a double quote at the end of cloud_id.


Receber valores (popup) na página pai

Question: Em uma outra pergunta, conseguiram me ajudar sobre armazenar os valores de alguns input de um popup, para passar para a página pai.
Resumo.jsp (pág pai)
<input type="button" onclick="test();" value="Palavras" />

function test(){
  window.showModalDialog('saida.jsp',null,'status:off;center:yes;scroll:no;');
}

No popup, há uma função, addCampos(), para que o usuário crie vários campos input.
saida.jsp (popup)

<input type="text" id='ctxt' name="campo[]" class="form-control">
<input type="button" value="Adicionar campos" onclick="addCampos()">
<button class="btn btn-success" onclick="enviaDados();">Envia Dados</button>

No método abaixo, é a parte principal da outra pergunta, é onde é passado os valores (um array) para a página pai.

Atualização
O meu problema é que não sei como usar (pegar) esse valor na página pai.
O que preciso é: o usuário vai digitar várias palavras no popup, quando fechar o popup, as palavras digitadas serão comparadas com um array java, e assim somente as palavras digitadas que estiverem contidas nesse array serão mostradas na tela.
Comment: @Pacíficão Agora entendi o que você precisa. Porém terá que editar a pergunta, anexando tal problema para que possam te auxiliar.
Comment: Amiguinho, você pode pegar os valores a partir do `each` colocando o `$(this).val()` em um array no objeto `window` usando a função `Array.push()`.
Comment: @Pacíficão Opa, tu precisa pegar os valores dos inputs e jogar para o jsp pai ( aqui se entende como o proprio html já renderizado), ou para o java?
Comment: @Pacíficão Acho que está um pouco confuso, no jsp se entende como o html com suas funções JavaScript, se tu quer jogar para o java, pq não usa um Form normal?
Comment: @devgaspa Sim, partindo do principio que o programador pegou a lista do java e passou para um array no JS. Depois apenas se compara os valores do each com o array vindo do java.
Comment: @Matheus então, suponhamos que exista uma `array JS` com os valores a partir do java, apenas usando `if(arrayJsComValoresDoJava.indexOf($(this).val()) != -1)` eu consigo verificar a existência do valor.
Comment: @devgaspa A princípio sim, e isso resolveria o problema da pergunta.
Comment: vc pode dar um exemplo? Não tenho costume com programação HTML/JavaScript
Comment: @Matheus preciso jogar para o JSP pai. Lá vou usa-lo em uma função java.
Comment: @Matheus Em resumo, oq eu preciso é: Receber essas palavras digitadas no popup e comparar com um vetor que está em java. Só mostrarei na pág, as palavras que foram digitadas e estiverem no vetor em java. Ficou menos confuso agora?
Comment: @Matheus existe alguma forma de comprar em tempo-real os valores do `each` com os do `array java`?
Answer: Vamos lá, para pegar os dados você usa a mesma função($(this).val()), dentro do each, que esta atribuindo os valores na div#idPai do HTML.
Para armazenar esses valores em um array você declara uma variável antes da função enviaDados. Dentro do each, a cada execução, você adiciona no array o valor utilizando a função push().
Veja como fica no código:

Esta implementação é para guardar os valores que vieram do modal em um array no escopo global do JavaScript, sendo possível acessar da pagina pai.
@Edit
Pressupondo que você tenha criado um array no JS com os valores do JAVA, como nosso amigo @Matheus disse nos comentários, sendo este array de escopo global. Para verificar a existência dos valores você pode utilizar a função indexOf() para validar.
Obs: Vamos supor que você criou o array var ArrayJScomValoresDoJava = [x,p,t,o] com os valores do array do JAVA.
Veja como fica no código:

Esta implementação irá adicionar à div#idPai apenas quando o valor passado pelo modal existir no array, leia sobre indexOf se houver dúvidas.
Comment: @Pacíficão através da variável `arrayDados`. Porem pela discussão nos comentários, talvez, este exemplo não seja viável para seu problema.
Comment: Como eu acesso esse vetor na página pai?

Receber valores (popup) na página pai


pLSA using tempered EM

Question: In an article by Hofmann pdf, he proposes:

initialize $β$ to one, run until convergence, then rescale $β$ by a
  factor $η<1$, run again until convergence, and iterate this until
  changing $β$ no longer improves the result.

I used the TEM algorithm on a dataset for my project, but the problem is that the algorithm ends up traped in several local minima and doesn't give me full convergence. My question is: what is the optimal condition under which I can assume that the algorithm converged?
Answer: The first and still popular method for ensuring convergence relies on line searches, which optimize a function along one dimension. A second and increasingly popular method for ensuring convergence uses trust regions. Both line searches and trust regions are used in modern methods of non-differentiable optimization. Usually a global optimizer is much slower than advanced local optimizers, so often an efficient global optimizer can be constructed by starting the local optimizer from different starting points.
If you are converging to a local minima instead of the global minima, there may be a problem with the values used for $β$ or $η$. You may try initializing $β$ to a different value, or using a larger scaling factor $η$ (closer to one).

pLSA using tempered EM


Can this Arabic scale be described in Western terms?

Question: Does anyone know what scale this is? I know it may be a scale that's not used in Western countries and also uses quarter tones...but can it be described in Western music terms? It sounds similar to the Phrygian mode of the major scale except there is also a raised/major sixth at 00:12 and a #4 at 1:42.
These are the pitches I'm hearing: 1, m2, m3, p4, (#4, only used once) p5, m6, (M6, only used once) m7.
Also, I know this is a Maqam, which is one of the modes of Arabic music...but I'm wondering if there is anything specific about it that could help a student identify it as a Maqam/Arabic piece in a listening exam? I have heard similar music to this in Greece and I'm also wondering if other Eastern European countries or perhaps North African countries such as Egypt, might have very similar scales/music?
Comment: Since the tuning isn't 12tet, and there are half sharps and flats, it won't equate to any normal Western scale. It comes close to Phrygian mode, though.
Comment: Thanks Tim. Finding it difficult to hear quarter tones myself, it all sounds like Western semitones to me, even though I know this music is supposed to have a different tuning system.
Comment: Likewise. 1/4 tones are more recogisable audibly with bends on guitar!
Comment: I agree. It seems it would be difficult to find clear indications of where this piece is from in a blind listening exam.
Answer: There are two instruments in this recording.
In the left channel is a Greek bouzouki, which is a fretted instrument, tuned in typical Western fashion (12 tempered semitones).
In the right channel is an Arab Oud, which is a fretless instrument (imagine a medieval lute, but without the frets, played with a plastic pick that looks like a popsicle stick). I once had the chance of playing it for a few days, learning from a friend, a pro player from Syria.
Because one of the two instruments (the Bouzouki) has tempered tuning, the other guy (the Oud) is also by and large playing almost the same way (temperate) in this case. Conversely, the Bouzouki seems to try to imitate the quarter notes, occasionally, by bending the strings. (And it's not quarter notes, it's more like 30 cents off, but never mind that).
In other words, this is a very Westernized kind of Arab music. I wouldn't even call it Arab music, really. George Harrison plus a sitar does not Indian music make...
So this tune feels to me like a sort of a (pretty good, to be sure) crossover piece, with each instrument trying to accommodate for the other, creating some middle ground between the two traditions (Greek and Arab in this case).
A classic of this kind of thing is "A meeting by the River" with Ry Cooder (slide strat) and Vishva Mohan Bhatt (Indian classical musician who plays a slide guitar which is actually a sitar of sorts). Def check it out. I also once heard him (V.M. Bhatt) play Indian classical music live in Calcutta, and totally blew me away, but that's another story.
Anyway if you want to hear real Middle-Eastern, non-temperate scale based music, the above is not the right place to start, go for some real stand-alone Oud playing instead. And give yourself at least a few days of listening without trying to prematurely explain everything to yourself. Just listen and let it sink in by itself. As you are already a musician, it won't take long before your start to get it, and, quite possibly, enjoy it a lot too... :)
Comment: more than a greek bouzouki this should be a buzuq (https://en.wikipedia.org/wiki/Buzuq) and capable of a wide range of non-western scales, cf also: https://i2.wp.com/www.artsearth.org/wp-content/uploads/20151210-ali-jihad-racy.jpg?resize=930%2C340&ssl=1
Comment: the buzuq is the Turkish precursor of the bouzouki, so you could hardly call this westernised music
Comment: @clayRay If you allow me a metaphor, Turkish music is to Arabic music as, say, British Rock is to American plantation delta blues. Related? Definitely. Same thing? Not quite!
Answer: This is definitely Arabic playing by two well known Arab musicians. The title says it is Maqam Kurd, which is pretty much Phrygian mode. However a maqam is not exactly like a scale. It is made up of ajnas (jinns in the singular). These are generally 4 or 5 note sequences. Although a certain set of 7 notes is associated with a maqam, the performance of a maqam will involve modulation by playing ajnas that are NOT in the main maqam in order to change the mood and hint at other maqams.
Without analysing this piece closely I can't offhand say what ajnas are being introduced to do this, but I can hear moments when quarter tones and other sequences of notes not in the main 7 notes of maqam Kurd are being used. And definitely the buzuq is not using bent notes to get these. It is similar to Turkish saz, having extra frets so that some in between tones can be played.
Comment: Welcome and thanks for a good answer to an old question.  Any chance you could take a stab at my question here: https://music.stackexchange.com/questions/114753/what-just-intonation-intervals-are-appropriate-for-the-double-harmonic-scale ?  I believe the double harmonic scale corresponds roughly to maqam Hijaz Kar.
Answer: The arabic music has microtonal differences to western scales, and lots of pitch bending. You could work out something similar if you just improvise and try match the notes, but it won't be quite the same as these instruments are microtonally different to say a guitar.
Answer: I'm not familiar with arabic music, but in western terms he is playing something close to the dorian b2 scale (2nd mode of melodic minor). As well as phrygian, as you say. The #4 you refer to I hear more as a temporary b5, making it locrian instead of phrygian for a brief moment.
Answer: The basic scale here is known as maqam Kurd (or more precisely, Hijaz Kar Kurd) in Arabic music. In scale terms, as others have noted, it corresponds almost exactly to a Phrygian scale: 1 m2 m3 4 5 m6 m7 8. In practice, it has a number of other characterstics beyond the scale description.
As you noticed, there is a M6 used around 0:12.  For comparison, if you listen at 0:19 there is a neutral 6th (1/4 lower) followed by the usual m6 at 0:20.
In theory terms, the M6 is a temporary leading tone to the m7 degree. The neutral 6th is the third of a brief detour into jins Rast on the 4th degree (Rast is 1 2 n3 4 5, so in context this is 4 5 n6 b7 8).  The m6 brings us back to the parent maqam.
At 0:23, you hear a M2, similarly used as a temporary leading tone to the m3.  He does it again at 0:51, 1:34 and 1:41.
At 1:35 and 1:42 the d5 (not #4, as the 4 is part of the melody as well) is a common descending cadential figure. He explores this more fully around 5:10.
At 1:56 there is a subtle microtonal shift to a jins called Jiharkah. It is very close to the first 5 notes of a major scale, however, the 3rd and 4th degree are lowered slightly (between 1/5 and 1/8 tone).  So hear we hear a 6 that is slightly lower than a M6 and a 7 that is slightly lower than a m7. But not lowered a full quarter tone. He changes this back to n6 and m7 around 2:08 (leading up to the octave).  He then proceeds to play with this sound, going back and forth a bit between the different sounds.
At 5:18, there is a similar figure to what you heard with d5, but using the d4 degree (effectively M3, but the m3 is also included).  The 1 m2 m3 d4 jins is known as Saba Zamzama. ("True" Saba has a n2, the version with a m2 is what makes it "Zamzama"). At 5:32, there is a shift to Saba on 8. This has the structure 1 n2 m3 d4 (or 1 n2 m3 M3).  This continues until 5:47 where he uses the M6 again as a leading tone that sets us up to hear the b2 (actually b9 here).
From here he establishes Rast (1 2 n3 4 5) on 4 more fully, giving us 4 5 n6 b7 8.  He uses this to expand to a full maqam Suznak on 4: Suznak is Rast + Hijaz (1 m2 3 4) on 5.   So we end up with 4 5 n6 b7 8 m9 10 11, locally sounding like 1 2 n3 4 5 m6 7 8.
The m2 and M3 in hijaz are narrowed, with the m2 about 1/8 tone higher and the M3 about 1/8 tone lower than their equal tempered counterparts (JI aficianados may notice this is close to ideal JI ratios for these notes).
I could go on, but this should give you a good sense of what to listen for and how much is going on. In this piece, we have heard 4 different 6ths, 4 different 2nds/9ths, and 2 different 7ths, as well as chromatic alterations to the 3rd and 5th.


How to select a key-signature for a song

Question: There are so many songs in pretty odd key-signatures like 4,5,6 sharps or flats. At least this is my impression when I listen to songs on the radio/net while trying to follow them on my piano/guitar. I can understand that some instruments prefer certain ranges of the circle of fifths, nevertheless ...

are songs really "written" in the keys you hear on the radio/CD/...
why do composers make their lives so difficult, why don't they use "easier" keys?
what are the criteria for a composer (today - tempered tuning) to select a key for a song
Comment: Commercial songwriters, producers and performers aren't concerned with the niceties of tuning systems.  They place a song in the key that best suits the vocalist.
Once beyond intermediate student level there are no "hard" keys.
Comment: There are a lot of good answers already, so I'll just add one thing.  A song you hear on a recording may not even be _performed_ in the key you hear on the recording.  Post-production, especially in certain styles, will sometimes raise the pitch a little to increase energy both by raising the tempo and through the implication of a higher tessitura requiring more energy.  This does not happen so much in reputable classical recordings, but I understand it is very common in some pop styles.
Comment: If you understand key signatures well then Ab minor should be no harder to play than C major.
Comment: @NeilMeyer - merely understanding, and knowing key signatures is only a part of it. Different keys work differently on different instruments, and the fingering is harder in some keys. There's also the range to consider. A piece in a certain key won't be achievable on every instrument - hence different keys. Vocal tessitura has a bearing in a similar manner.
Answer: As I'm sure you're aware, you can transpose any tune to whatever key you like.
One reason to choose a certain key, is simply that it sounds good.
It might be that you feel that notes of a certain pitch inherently sound pleasant on your chosen instrument. I happen to like the tone of my guitar with a capo on the 7th fret, for example.
Or it might be that due to tempered tuning, the intervals work better for you (the difference between a C and a G is only approximately the difference between a D and an A). Most people can't consciously detect those differences, but there may be subconscious effects.
Another reason is ease of playing. You've asked why composers don't use "easier" keys. Bear in mind that what's easy on one instrument isn't so easy on another. Beginner guitarists don't like C major because they have to play a barre F chord.
Beginner pianists love C major because it's all on the white keys. More experienced pianists don't find black keys to be a problem, but they like certain keys because of the way the keys fall under their fingers (often keys with lots of black keys).
When composing for an orchestra or a band, you have to keep in mind preferred keys on all kinds of instruments -- violins, woodwind, harp, etc.
For songs, there's also vocal range to be considered. This is probably the main reason folk/pop/rock songs get transposed.
Finally there's the feel brought about by the mechanics of playing the piece in a given key on a given instrument. To go from an F to a G on a recorder, you have to lift three fingers. To go from a G to an A, you only lift one finger. You can imagine how the latter would sound cleaner -- and the effect may be more dramatic on other instruments.
Comment: many good thoughts in this thread ... I choose your answer because it summarizes most aspects - Thanks
Comment: Thanks, although you should probably wait quite a bit longer before selecting a right answer.
Comment: @MikeD that's correct in an ideal world, but due to pesky real-world physics issues, it's approximate. Google the Railsback Curve, for pianos. I gather that guitars have a similar issue.
Comment: +1 because capo on the seventh fret makes an open C Major sound like a choir of angels.
Comment: I only tend to disagree on "difference between C/G and D/A" in the case of tempered tunig as I asumed in my question; there is no difference, not even a subtile, it's a plain geometric sequence determined by the twelfth root of 2 and the relation between intervals is the same
Comment: I've been working with a mandolin plater lately, so we tend to end up using the keys of G and D fairly often. I'm told those are easy on mandolin.
Comment: Did you put the capo on the 7th string or the 7th fret?
Comment: @Tim good spot, even if it did take 5 years.
Comment: Be fair, slim, I have to eat and sleep as well...
Answer: Key signatures with sharps and flats aren't any easier or harder.  On a piano, for example, I find E Major (4 sharps) to be the easiest to play, whereas the composer Chopin taught his students B Major (5 sharps) first since he viewed it as the easiest.  C Major, which you might think is the easiest because it's all white notes, is actually quite unnatural.  Your fingers are different lengths so playing all the white keys forces your hand to take on awkward positions.
If a particular key seems easier to you, that mostly just means you've had more practice with it (either mentally or physically).  With more practice you'll be able to just look at a key signature and begin playing without needing to think about it; you'll play the right flats/sharps automatically.
With guitar in particular there are certain shapes that are harder to play than others, but you can use a capo or an alternate tuning to make that problem disappear.  Thinking that songs should be written to fit one's current tuning and experience would be silly, since there is so much variety out there and most music uses more than one instrument!
Comment: I think reading 6 sharps is pretty easy, think about it this way: only one note does not have a sharp. It's precisely the keys which have 3 or 4 sharps/flats I find most difficult. Especially minor keys which get extra alterations. Also agreed with Matthew about E Major being relatively easy to play on the keyboard as compared to C Major for instance. Though that would also depend on the intrinsic difficulty of the piece.
Comment: @BogdanAlexandru E# and F are different notes conceptually, and are actually different pitches on some instruments.  Plus, scales should have one of each letter note.  See my other answer here: http://music.stackexchange.com/a/88/28
Comment: I agree that for transposing instruments (esp. fretted) like g, mand, etc. the  performance is maybe not so much of an issue ... still reading 6 sharps seems more difficult to me than 0 or 1
Comment: @Raskolnikov What do you mean 6 sharps? Only A, C, D, F and G can have sharps...
Comment: @Bogdan Alexandru: Nothing better than counter examples. https://en.wikipedia.org/wiki/F-sharp_major
Comment: @Raskolnikov But why do they call it E# instead of F?
Answer: To answer your specific question:

are songs really "written" in the keys you hear on the radio/CD/?

the answer is, "usually not."
The way it's been done for centuries:
1) The song gets written. Key is irrelevant. It may be written down in one key, but nobody pays attention to that.
2) A singer decides to perform the song. The singer transposes the key of the song to the best one that fits the range of his or her particular voice. When other singers perform the song, they chose different keys at will.
3) If the song gets published, it may be written out in one key or another at the discretion of the publisher. The key it's published in is usually one that's been chosen by a popular singer who had a hit with the song.
This changed a bit in the 20th century with the advent of recording and radio broadcast. At that time the public got accustomed to hearing a certain song in a particular key because they listened over and over again to a certain popular recording by a certain pop star.
Any instrumental musician worth their salt can play any song in any key. Your idea that some keys are harder to play in than others is illusory. Proficient musicians learn to play anything in any key.
To this day, in jazz, any song can be played in any key at any time. Get a bunch of jazz musicians together to perform, give them a list of songs, and on the spot, usually with the guidance of a lead singer, they will select different keys for each song just for that one performance. If the sheet music is written out in a certain key, the jazz musicians and the singer will transpose to any different key they agree on while they are reading the sheet music written in one key.
The big exception to this is rock music based around guitars. Rock music played on guitars is almost always written in the keys of E, A, or D, because rock guitarists tend to write an entire song around the capabilities of the guitar, which favors certain open strings as pedal points. Rock musicians generally don't learn to play any song in any key like musicians in other genres do. But for the other 99.9999% of music in the history of the world, any song can be transposed to any key at any time.
Comment: Maybe you got downvoted for (perhaps not deliberately) singling out rock guitarists and being demeaning towards them. Classical guitar parts make use of open string pedal points (*Romanza* being a popular example). Jazz musicians would be foolish to eschew the opportunities offered by open strings. Folk and blues musicians built parts around open strings since before rock existed. Rock guitarists learn movable scales just like jazz guitarists do. Anyone can buy a capo ;)
Comment: One problem with this "question" is that the person asking really asked *several* questions in one. I answered *one* of his questions thoroughly and in-depth, and somebody voted me down! First, an editor should structure the question better or split it into multiple questions, and second, I don't see why my answer deserved a "down" vote.
Comment: Agree with Wheat's last main paragraph, except lots tune down one or two semitones (frets), which puts the finished work into keys strange for guitarists!
Comment: I'd argue that it hasn't been done for centuries, commonly. Even back in 1916, one hundred years ago, players would use the printed sheets, which inevitably were in the original key.
Answer: There's an important point especially when playing strings: chords voicings.
For example, Dm is usually referred to as the "most minor" or "saddest" key. I totally agree, mainly because playing a basic Dm on guitar gives you this figure:
<code>Dm
</code>
where the third is on the first string, so the last one you strum. That leaves your ear a strong feeling where the third (the "minorizer" note) is accentuated.
That does not occur with any other basic/elemental chord figure I can think of now and hence the different feeling compared to, say, Am.
For the opposite reason (expected major third), basic plain D major is usually the dullest of the chords to my ear.
If you play the guitar a lot you will notice after some time that playing in different keys (without using fret transposing) gives you different melodic ideas. That is because equal temperament is not exact but also because every way of playing chords has different accentuated sounds depending on fingering.
Comment: Ah, the 'Am' shape, barred at fret 3.
Comment: Using your theory of the min.3rd being the last note strummed, and the highest, it ought to work the same for the open D shape, again, but with the maj. 3rd on top this time.
Comment: To me, C minor is way darker, more tragic, scarier, angrier, stormier, sadder, more furious, and more raging than any other minor keys.
Comment: Are you sure you play the whole figure? Most people semimute the first string on complex fretted chords. But anyway, if you do a fret with the finger, it is probable that you are, at least, releasing a pure and stronger tone from your last dedicated finger, which in case of Cm is again the minor third
Comment: By semi-muting the first string, there's not even a minor third note in the chord. And where do you play a Cm chord with Eb on the top string? 11th fret?
Comment: What I mean is if you don't press a lot the fret a Cm tends to sound as x3554x, where that 4 is the minor third
Answer: Here's all the reasons I know of for composers to pick a certain key.
Physical limitations
Some instruments have/had physical limitations.  For example, certain harps cannot play all keys and antique horns and trumpets only had certain pipe fittings they could use that tended to be tuned toward the flat side of the circle of fifths (Bb, Eb, etc).  Triangles are only available tuned to certain notes, etc.
Considerations for stringed instruments
Guitarists who use traditional tuning will love a piece written in E because they will be able to use many open chords.
Hendrix and Cobain notedly tuned themselves one half step flat so they could play pieces in Eb.  Punk music commonly uses drop-D tuning which bottoms out at D natural.
The same sorts of constraints apply to other stringed instruments such as the violin, where the composer may have chosen A, E, D, or G to allow the use of open strings or certain double stops.
Form
Some works are part of a larger form, e.g. a movement in a sonata.  The first and last movements will typically be in the same key and inner movements will be in a prominent secondary key area, usually V in classical and V or VI in romantic music.
Tesatura for a vocalist
Some works are intended for a specific vocalist and either challenge their upper and lower ranges or linger around certain notes in the vocalists' "sweet spot."  The range and therefore the key was selected for optimum performance.
Symbolic meaning
In the old days before equal temperament, not all keys sounded the same, and took on a certain character and meaning by convention.  Some examples:

Mozart used the key of D major to represent magic and the divine supernatural
Wagner used the key of F# to represent disturbed emotional states
The key of F major is associated with hunting horns and the outdoors, and is frequently used in pastorales

Ease of play
A key with a lot of black notes is a lot easier for a pianist to play-- there is more tactile variety in the fingers which allows them to know where the keys are without looking.
Horn players generally prefer songs written to the flat side, e.g. Bb and Eb, as they are easier to play in tune.
Clarity of notation
Sometimes a key will be chosen because it is easier to notate.  F major is a lot easier to write in than F# major.
Some twentieth-century composers got in the habit of writing everything in the key of C and using only accidentals so that the performer would not have to remember the default sharps and flats at any given moment, which allows the composer to switch keys more frequently without confusing the performer too much.
Consonance with samples
EDM and other modern genres use a lot of sampling (borrowing waveforms from other songs) and choose the key so that the surrounding material is consonant relative to the key of the sample.
To accompany other sounds
Opposite of the above; music composed for sound tracks may be put into a certain key to accompany the rest of the sound going on at the moment in the scene.  For example, in The Hobbit, parts of the sound track accompany dwarven signing, or in in the 1979 film Tess, Sarde's sound track accompanies a wedding party.
Color and sound
Lower keys just sound, well, lower.  Sometimes the overall color and sound of the work is the most important.
As an exercise
Sort of an edge case but listed here for completeness.  Some works, most notably the 12 fugues and preludes of Bach's Well-Tempered Clavier, attempt to use certain keys to complete an exercise, i.e. the composer has an opportunity to try is hand at every key, the performer has an opportunity to play in them, and the listener has a chance to hear them (of particular interest when the instrument is not equally tempered).
Comment: How is F easier to notate than F#? Just write the appropriate key sig. in, (1b or 6#) and the notes fall on the same lines and spaces!
Comment: Sure, if your composition exists in one key (which is true only for very trivial compositions).  For a modulation to dominant you'd need a B-sharp, and modulation to relative minor would require C-double-sharp.
Answer: I have heard that some keys "sound" different because of slight variations in the frequency spacing between notes, but I cannot tell any difference. Two reasons to select a key for a song are

Voice range. The song should be in a range within the singer's ability and where the singer sounds best.
Up a half step. In a lot of songs, the key changes up a half step to get some inspiration going. This can result in a whole lot of sharps or flats.

Songs are usually written in the key you hear, but it is possible to electronically change the pitch. Most professional musicians can handle any key proficiently. This makes me jealous. Some music books you can buy have the songs transposed into keys that are easier to play.
Comment: +1 for voice range.  I think composers don't necessarily write in those hard keys; they write in something reasonable and then the singer needs it to be transposed.
Comment: The answers to [this question](http://music.stackexchange.com/questions/2/whats-the-difference-between-a-g-and-an-f) expand on your first paragraph; you normally don't notice any difference because most music is "wrong" :P
Comment: +1 for voice range and modulation ... better to modulate from D to E than from C to C#
Answer: I would compose in whichever key is easiest for you to work in and get your ideas across. Then you can transpose the song to another key if necessary depending on who you are playing with.
If you're working with professional musicians, they should be able to play in any key even in the "hard ones." If not, then you may need to put the song in an "easier" key, which most people generally feel are ones with fewer sharps and flats. However, the most important thing is that the key work for your vocalist--figure out the range of notes of your melody and put the song in a key that it is singable for your vocalist or the vocal type you plan to use whether it's soprano, alto, tenor or barritone voice. If you're not sure what's singable, ask someone to try it out and it'll become immediately obvious. Good luck!
Comment: Many guitarists don't care about sharps or flats -- or even know they're there -- they just care what's easy to finger. E major is a popular key for guitarists. Four sharps, but if you're just strumming chords, or following a tab, you might never realise.
Answer: Well if you have horns, there are Eb instruments and Bb instruments that are common and "easier" for beginners.  Piano beginners use C often, guitarists use E and A often since those are easy chords in an open position.  So, many times, a key is chosen by the instruments and levels of the players.
Answer:
why do composers make their lives so difficult, why don't they use "easier" keys?
  what are the criteria for a composer (today - tempered tuning) to select a key for a song

You should be familiar with all the key signature to such an extent that no one is harder or easier than the other.

are songs really "written" in the keys you hear on the radio/CD/...

It all depends on the instrument. Guitar are special in that they almost always want the tonic of the scale in the bass. That is why a whole lot of classical guitar music is played in E minor / Major or D minor / Major.
A major scale will almost always sound major regardless of with note you start on. So the practical considerations are usually what makes the difference.
Comment: The last para.: of the seven modes you hint at, only 3 will actually sound major - and not the major sound of the mother key, either! The other four all have a m3 between 'root' and 3


How to change a Prism module in runtime

Question: How to change modules in run time? I have ribbon menu with commands binded. On menu item click I want change modules on form.
Answer: AFAIK Prism module is simply an assembly loaded in the common Application Domain so unloading of a particular assembly is not possible (.NET Framework limitation).
PS:
Why Prism is not considered loading a module into the separate AppDomain as an option, in this way all modules would be pretty good isolated and Load/Unload will be available as well. I believe this would be a great benefit for Enterprise solutions with critical priority requirements for reliability since when multiple assemblies loaded into the same AppDomain - error in one assembly potentially could crash entire AppDomain, from my standpoint this is unacceptable for robust and reliable applications. Nice to have "Module per Assembly" by default, but additional option "Module per AppDomain" would be great. Perhaps I missed something important? Would be interesting know reasons why Module per assembly but not per AppDomain.

How to change a Prism module in runtime


Extract text after symbol and first non-word char in r

Question: How should I extract text between first @ and space? I have mentioned my code below. It extracts all the words after all @, but I just want the text first the @.
text
@pisa, what's up?
@italy @spain we're praying for you.

ideal result
pisa
italy

my code
regex <- "@([A-Za-z]+[A-Za-z0-9])"

words <- str_extract_all(text, regex)

print(words)

output
@pisa
@italy @spain

Comment: Use `str_extract(text, "(?<=@)\\w+")` (extract the first mention) or `str_extract(text, "(?<=^@)\\w+")` (the mention at the start of the string).
Comment: Your title is out of sync with the expected outut, you do not want to "Extract text after symbol and first space", you want "Extract text after symbol and first non-word char".
Answer: We can use a regex lookaround as regex i.e. to match the word followed by the symbol @
library(stringr)
str_extract(text, "(?<=@)\\w+")
#[1] "pisa"  "italy"

It can be also
str_extract(text, "(?<=@)[^, ]+")
#[1] "pisa"  "italy"

Or in base R, using sub, capture the word after the @ and in the replacement specify the backreference (\\1) of the captured group
sub("^@(\\w+).*", "\\1", text)
#[1] "pisa"  "italy"

Also, another option is regmatches/regexpr
regmatches(text, regexpr('(?<=@)\\w+', text, perl = TRUE))
#[1] "pisa"  "italy"

Or with trimws
trimws(text, whitespace = '@|,? .*')
#[1] "pisa"  "italy"

data
text <- c("@pisa, what's up?", "@italy @spain we're praying for you.")


Jquery Mobile links stopped working for pages

Question: I have a jquery mobile site in developement at http://www.ab-mobile-apps.com/app/fcs/index.html
The issuse is that the links from the main menu recently stopped working.  The browser recognizes them but upon a click of the link nothing happens exept for the service link.  I am using JQMobileRC 1.1 as I have with other sites with out any issues.
If anyone has any input It would be appreciated.  Thank you.
Comment: Does it help if you comment-out the PhoneGap include since you're testing in a web browser?
Comment: Nope, Didn't make a difference.
Answer: You could be running into this issue.  If so, you need to back up to version 1.0.1 or move forward to the latest bleeding edge.
Answer: I ran into the same issue (at  the time of this reply, latest jqm version is 1.4.2) and this solved it for me so far :
1) links pointing to a different page within you domain / app : data-ajax="false"
 ...

2) links pointing to a different domain : rel="external"
 ...


Check a discontinuity of a function

Question: Check discontinuity of a function
$$  f(x) =
\begin{cases}
x\left\lfloor \frac{1}{x}\right\rfloor,  & x\neq 0 \\
0, & x=0
\end{cases}$$
$$\lim\limits_{x\to 0}f(x)\neq f(0)\Rightarrow$$removable discontinuity at $x=0$.
Is this correct?
Comment: You should verify that $\displaystyle\lim_{x \to 0}f(x)$ actually exists, and is something other than $f(0) = 0$. Also, there are other discontinuities that you seemed to have missed.
Comment: Try computing the limit along the sequence $x_n = \frac{1}{n}$ as $n\to\infty$.
Answer: Note that for any positive integer $n,$ $f(1/n)=f(-1/n)=1.$ Note further that $f$ is increasing on $\left(\frac1{n+1},\frac1n\right]$ and decreasing (and continuous) on $\left(-\frac1n,-\frac1{n+1}\right].$
Determine $$\lim_{n\to\infty}\left(\sup_{-\frac1{n+1}<x\le-\frac1n}f(x)\right)$$ and $$\lim_{n\to\infty}\left(\inf_{\frac1n<x\le\frac1{n+1}}f(x)\right),$$ and use this to determine whether or not you are correct.

Check a discontinuity of a function


in C how can i store strings in a multidimensional table?

Question: I am trying to create a program for school where you can  register and login using your name, surname, age etc.
You can register up to 100 times using only different surnames each time.
I created the Register/login screen as follows
int main(int argc, char *argv[]) {
    int i = 0;
    MSCREEN: printf ("              =====   Main Screen    =====                \n");
    printf ("To Register type: Register\n");
    printf ("To Log-In type: Login\n");
    char rl[9]; //rl=RegisterLogin
    while ((strcmp (rl, "Register") != 0) || (strcmp (rl, "register") != 0) || (strcmp (rl, "Login") != 0) || (strcmp (rl, "login") != 0)) {
        scanf (" %s", &rl);
        if((strcmp(rl,"Register")==0) || (strcmp(rl,"register")==0)) {
            printf ("You will now Register\n");
            Register();
            i++;
            goto MSCREEN;
            break;
        }
        else if ((strcmp(rl,"Login")==0) || (strcmp(rl,"login")==0)) {
            printf ("You will now Login");
            Login();
            break;
        }
        else{
        printf("Please type 'Register' or 'Login'\n");
        }
    }
    printf ("Completed");
    return 0;
}

Now the problem is that I don't exactly know how I can store the different names and surnames using multidimensional arrays. I cant use separate files or data structures for this so I'm stuck.
I need to be able to display the information in a 2 dimensional array but in order to store information I probably need a 3 dimensional array for this.
I also need to be able to edit the names using a separate function now something like this:
void Register()
{
    //char name[50], surname[50], age[50], lamia[50], patra[50], volos[50], sum[50];
    printf ("               =====   Register    =====               \n");

    printf ("Please type your Name:\n");
    scanf (" &s", &name[50]);

    printf ("Please type your Surname:\n");
    scanf (" &s", &surname[50]);

    printf ("Please type your Age:\n");
    scanf (" &s", &age[50]);

    printf ("Please type your Trips  to Lamia:\n");
    scanf (" &s", &lamia[50]);

    printf ("Please type your Trips  to Patra:\n");
    scanf (" &s", &patra[50]);

    printf ("Please type your Trips  to Volos:\n");
    scanf (" &s", &volos[50]);

    return;

will save the necessary info only as global variables which will change after the next registration.
So how can I store all the info I need on a multi-dimensional array and then be able to access that info later down the line?
Comment: Welcome to SO! You might want to look into an array of structs. A single struct contains all information for a student, including a pointer to an array of names (if you haven't learned about memory allocation or pointers, there's no time like the present...). As an aside, it's very easy to smash the buffer in this code.
Comment: You can use a 3D array or an array of structs with the struct containing  one array for the name and one for the surname.
Comment: I am familiar with pointers and definitely confused by them so I am studying at the moment and clearing things up.. but using struct is pretty much frohibited for this one.. since its something the professor has not taught us yet in class, that would result on an F right away! (I used atoi and some other "untaught" knowledge and bamboozled myself last time..) thank you for answering. ill look into struct anyway (although I doubt Ill be able to solve this without using it) @ggorlen
Comment: @Davide Thats right .. a 3D Array was also my original thought and it fits with the knowledge im suppose to have but how can i store it in a 3D array to begin with? And after that how can I then edit those stings? When the user logs in, how can i authenticate the information... meaning...how can i access that info later? Im confused about the 3D array thing although i have no doubt that this is the way to go here
Comment: That's an unfortunate restriction because structs are the correct way to group different types of data together to represent an entity. It's too bad they're asking you to do a task that can be solved elegantly with a particular tool while prohibiting that tool. But in this case, since all your fields appear to be strings, you can use a `char[x][y][z];` where the first dimension is a list of students, the second dimension is essentially the flattened "struct" as an array and the third dimension are any lists that would be contained within this struct.
Comment: You could also use separate arrays, both 2d, one to store the flattened structs without the list field and the other to store the single field that has a list of values per student. This would be better for memory footprint, if that matters, but it's a bit harder to manage because you have to keep indices straight between two data structures. Both solutions make it much harder than this need to be.
Answer: So since you can't use structs, here's how you can use a 3D array
char students[STUD][DATA][LENGTH];

where STUD is the maximum number of students you want to store;
DATA is the number of entries for each student, in your case it's 2 (name and surname);
LENGTH is the maximum number of characters for each name/surname.
Every time you want to access the name of the n-th student you will refer to
students[n][0]

while for the surname you'd use
students[n][1]

students[x] represents a student and is a pointer to pointers to char (it points to the two pointers name and surname).
student[x][y] represents the name or surname of a student and is a pointer to char.
student[x][y][z] represents one of the characters composing the name or the surname.
If you want to print the data at some point in your program, I advise you to put a '\0' at the end of every name/surname while you fill them in the array.
And you should also keep track of the number of students you have initialized.
If you are not going to overwrite the students' data, you could even use memset to initialize every element with '\0' and then fill the data without caring about terminating your strings or keeping track of how many students you got.
Have fun.


How to interpret ROC with crossing curves?

Question: I have created a ROC curve for two classifiers on a two-class classification task:

The green curve is from a nearest neighbours classifiers. The red one from a tree boosting.
As we can see both curve cross each other. What can we say in this case? Which one is better? If a curve is completely above another, it is clear that it is better, but I don't know the case for crossings...
Comment: If you compute the area under the curve the blue seems bigger! See this http://stats.stackexchange.com/q/103884/77852 and the comments for more information on formal tests
Comment: note that ROC and AUROC are random variables; http://stats.stackexchange.com/questions/165033/how-to-interpret-95-confidence-interval-for-area-under-curve-of-roc/167154#167154
Comment: Side note, it would be easier for a reviewer to compare the superficial difference between the curves if the figure was symmetrically scaled. The blue curve does appear to have a greater AUC, but the scaling is not the same on both axes!
Comment: @hlsmith The aspect ratio is irrelevant, because a patch of any given size in this plot continues to correspond to the same area even when it is translated. That shows that any visually apparent difference in areas in the plot truly is a difference in the actual areas.
Answer: Those curves mean there's a specific rank where both the $\text{TPR}$ and the $\text{FPR}$ values are the same among curves. It's also clear the blue one has higher sensitivity at low specificity, while the red one has higher specificity at low sensitivity. Basically, it would mean one curve is better at predicting positives than the other, but there's of course a tradeoff.
Now, which one is better? Depends on what you define as "better", and also on the intended application. Without further details about the data it's hard to tell, but if you consider the $\text{AUC}$ as a good metric for your problem, then blue seems to be better (not sure, just eyeballing an area). Also, at the $\text{FPR} = \text{TPR}$ line, blue is also better.
Comment: note that ROC and AUROC are random variables, in other words the curves depend on the sample; http://stats.stackexchange.com/questions/165033/how-to-interpret-95-confidence-interval-for-area-under-curve-of-roc/167154#167154
Comment: Thank you for your answer. Which curve is better at predicting positives?
Comment: @machinery the blue one, it has higher $\text{TPR}$ at $\text{FPR} \geq 0.15$. But you always have to keep in mind the tradeoff, at $\text{FPR} < 0.15$ red has higher $\text{TPR}$, which is, of course, lower than in the first case.


roughly estimate the angle between two lines that are really close to each other

Question: Say, for example, what's the angle, theta, between y=10000x and y=10001x ?
In terms of calculator-independent estimation, I tried: calculate tan(theta), then use taylor expansion of arctan(theta). But that seems a bit of work. Is there any other approach with less work?
Comment: The most direct way to obtain such a result is using calculus. Are you comfortable with that?
Comment: @Semiclassical could you elaborate on that? do you mean find the cosine of angle between two vectors?
Comment: For small $\theta$ (in radians), $\tan\theta\approx\sin\theta\approx\theta$.
Answer: Using the Taylor expansion of $\arctan$ is the right idea, but you need to do that at, say, $10000$, not at zero.
You want $f(10001) - f(10000)$ where $f(x) = \arctan x$. For relatively small values of $h$, the first-order Taylor formula gives you
$$f(a + h) - f(a) \approx f'(a)h.$$
Here we have $f'(x) = \frac{1}{x^2 + 1}$
$$f(a + h) - f(a) \approx \frac{1}{a^2 + 1}h.$$
Moreover, the error in this approximation is bounded by $\frac{1}{2}Mh^2$ where $M$ is an upper bound in absolute value for $f''(x) = -2x/(x^2 + 1)^2$ between $a$ and $a + h$. The numerator is bounded above by $2(|a| + |h|)$ and the denominator below by $a^4$, so a bound for the error is $1/|a|^3 + |h|/a^4$.
But we can further approximate $1/(a^2 + 1)$ by $1/a^2$ with an error of at most $1/a^4$, so the approximation
$$f(a + h) - f(a) \approx \frac{h}{a^2}$$
is valid with error at most $1/|a|^3 + 2|h|/a^4$.
In our case, $a = 10000$ and $h = 1$, so the desired approximation is $10^{-8}$ radians with a maximum possible error just over $10^{-12}$.
The actual value is $0.0000000099990000000099987$ radians.
We could have obtained a more accurate estimate by using the second-order Taylor approximation, and then the bound on the error would be given in terms of the third derivative.
Comment: While it's equivalent, we can just as well take the lines to be $y=x/10000$ and $y=x/10001$ (since this just swaps the axes and doesn't change the angle). In that case we approximate $f(10000^{-1})-f(10001^{-1})$, in which case the use of Taylor's theorem is more direct.
Comment: Good point. That will be simpler. On the other hand, I imagine that bounding the error will be a bit worse if you have to add the errors based on the intervals $[0,1/10001]$ and $[0,1/10000]$ rather than just the error on $[1/10001,1/10000]$, which is a much shorter interval. So using the Taylor series at $0$ doesn't appear to be entirely equivalent at first glance.
Comment: Perhaps, I wasn't worrying too much about rigorous inequalities. But at the level of first-order approximations it's just: If $m=\tan \theta$, then for small $\theta$ we have $m\approx \theta$ and $\delta \theta \approx \delta m=\frac{1}{10000}-\frac{1}{10001}\approx 10^{-8}.$
Answer: Assume $1 < a < b$. We will further assume $b < 2a$. Your problem is to estimate $\arctan b - \arctan a$ with $a = 10000$ and $b = 10001$.
We have
$$
\begin{align*}
\arctan b - \arctan a &= \int_a^b \frac{dt}{t^2 + 1} \\
&= \int_a^b \left(\frac{1}{t^2} - \frac{1}{t^4} + \frac{1}{t^6} - \dots\right) \, dt \\
&= \int_a^b \frac{1}{t^2} \, dt - \int_a^b \frac{1}{t^4} \, dt + \int_a^b \frac{1}{t^6} \, dt -\dots \\
&= \left(\frac{1}{a} - \frac{1}{b}\right) - \frac{1}{3}\left(\frac{1}{a^3} - \frac{1}{b^3}\right) + \frac{1}{5}\left(\frac{1}{a^5} - \frac{1}{b^5}\right) - \dots
 \end{align*}
$$
The interchange of limit and integral is justified by uniform convergence. Since the series is alternating, as can be seen from the integral terms, if we cut it off at a particular term, then the error is bounded by the following term. If we let $h = b - a$ and cut off after one term, we obtain the approximation
$$\arctan (a+h) - \arctan a \approx \frac{h}{a(a+h)} = \frac{h}{a^2}\left[1 - \frac{h}{a} + \left(\frac{h}{a}\right)^2 - \dots \right],$$
where we've used the fact that $h < a$.
If we leave this as $\tfrac{h}{a^2}(1 - \tfrac{h}{a})$, then we commit a negative error no larger than $\frac{h^3}{a^4}$ and a positive one no larger than $\int_a^b \frac{dt}{t^4} \leq \frac{h}{a^4}$.
With $a=10000$ and $h = 1$, we get $\arctan 10001 - \arctan 10000 \approx 10^{-8} - 10^{-12}$ with an error not exceeding $10^{-16}$.


Assessing the fit of GLMM implementation of a Rasch model to binary data using lme4

Question: I'd like to assess the fit of the kinds of models described by de Boeck et al (2011) (http://www.jstatsoft.org/v39/i12). They are GLMM implementations of Rasch family models, e.g.:
all.1.NULL.Rasch <- glmer(score ~ -1
                          + item
                          + (-1 + X064.part.Part | person), data = IN11c, family=binomial)

As Gelman and Hill (2006) explain, a binned residual plot is a better approach than simply plotting the fitted values against the residuals (also discussed here: How to assess the fit of a binomial GLMM fitted with lme4 (> 1.0)?).
However, my plots (using the arm package) exhibit a striking pattern, which seems to me likely to be due to some aspect of the model which is different from those Gelman and Hill were talking about.

Can anyone explain this, and, preferably also a useful way to assess the fit of the type of model I have?
First, I'm assuming that this is correct:
binnedplot(fitted(all.1.NULL.Rasch),residuals(all.1.NULL.Rasch))

The data actually has 89 variables, so I'm supplying details for those in the quoted model:
> str(IN11c$score)
 Ord.factor w/ 2 levels "0"<"1": 2 2 2 2 2 2 2 2 2 2 ...

> str(IN11c$X064.part.Part)
 Factor w/ 4 levels "1","2","3","4": 1 1 1 1 1 1 1 1 1 1 ...

> str(IN11c$person)
 Factor w/ 9961 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...

> summary(IN11c$score)
     0      1   NA's
109222 238188   1225

> summary(IN11c$X064.part.Part)
     1      2      3      4
 69727  79688  69727 129493

> summary(IN11c$person)
      1       2       3       4       5       6       7       8       9      10      11      12      13      14      15
 35      35      35      35      35      35      35      35      35      35      35      35      35      35      35
 16      17      18      19      20      21      22      23      24      25      26      27      28      29      30
 35      35      35      35      35      35      35      35      35      35      35      35      35      35      35
 31      32      33      34      35      36      37      38      39      40      41      42      43      44      45
 35      35      35      35      35      35      35      35      35      35      35      35      35      35      35
 46      47      48      49      50      51      52      53      54      55      56      57      58      59      60
 35      35      35      35      35      35      35      35      35      35      35      35      35      35      35
 61      62      63      64      65      66      67      68      69      70      71      72      73      74      75
 35      35      35      35      35      35      35      35      35      35      35      35      35      35      35
 76      77      78      79      80      81      82      83      84      85      86      87      88      89      90
 35      35      35      35      35      35      35      35      35      35      35      35      35      35      35
 91      92      93      94      95      96      97      98      99 (Other)
 35      35      35      35      35      35      35      35      35  345170

and the output:
> summary(all.1.NULL.Rasch)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation)  ['glmerMod']

Family: binomial  ( logit )

Formula: score ~ -1 + item + (-1 + X064.part.Part | person)
Data: IN11c

  AIC       BIC    logLik  deviance  df.resid
369799.0  370283.1 -184854.5  369709.0    347365

Scaled residuals:
Min      1Q  Median      3Q     Max
-6.4212 -0.6800  0.3506  0.5897  6.6114

Random effects:
Groups Name            Variance Std.Dev. Corr
person X064.part.Part1 2.2550   1.5017
    X064.part.Part2 0.7472   0.8644   0.71
    X064.part.Part3 2.4486   1.5648   0.54 0.75
    X064.part.Part4 0.7124   0.8441   0.63 0.86 0.69
Number of obs: 347410, groups:  person, 9961

Fixed effects:
    Estimate Std. Error z value Pr(>|z|)
itemX1   3.01316    0.04289   70.25  < 2e-16 ***
itemX2  -0.60039    0.02900  -20.71  < 2e-16 ***
itemX3   2.06994    0.03466   59.72  < 2e-16 ***
itemX4   0.05922    0.02830    2.09  0.03635 *
itemX5   2.69565    0.03966   67.96  < 2e-16 ***
itemX6   1.67934    0.03239   51.85  < 2e-16 ***
itemX7   2.27617    0.03612   63.02  < 2e-16 ***
itemX8   1.61074    0.02833   56.86  < 2e-16 ***
itemX9   0.60380    0.02391   25.26  < 2e-16 ***
itemX10  0.46635    0.02362   19.74  < 2e-16 ***
itemX11  1.60557    0.02830   56.73  < 2e-16 ***
itemX12  0.63788    0.02398   26.60  < 2e-16 ***
itemX13  0.87095    0.02463   35.36  < 2e-16 ***
itemX14  1.20185    0.02602   46.18  < 2e-16 ***
itemX15  0.92694    0.02484   37.32  < 2e-16 ***
itemX16  0.30951    0.02872   10.78  < 2e-16 ***
itemX17 -0.08539    0.02869   -2.98  0.00292 **
itemX18  0.13537    0.02866    4.72 2.32e-06 ***
itemX19  1.34097    0.03091   43.39  < 2e-16 ***
itemX20  1.03142    0.03000   34.38  < 2e-16 ***
itemX21  0.91493    0.02967   30.84  < 2e-16 ***
itemX22 -0.14124    0.02874   -4.91 8.94e-07 ***
itemX23 -0.36678    0.02346  -15.63  < 2e-16 ***
itemX24  1.89063    0.03027   62.45  < 2e-16 ***
itemX25  2.38406    0.03510   67.93  < 2e-16 ***
itemX26  1.06347    0.02527   42.08  < 2e-16 ***
itemX27  0.59852    0.02378   25.17  < 2e-16 ***
itemX28  0.38406    0.02341   16.40  < 2e-16 ***
itemX29  1.43106    0.02709   52.83  < 2e-16 ***
itemX30  1.22191    0.02600   46.99  < 2e-16 ***
itemX31  0.97085    0.02489   39.00  < 2e-16 ***
itemX32  1.16746    0.02568   45.46  < 2e-16 ***
itemX33 -0.06049    0.02322   -2.60  0.00919 **
itemX34  0.44368    0.02351   18.87  < 2e-16 ***
itemX35  1.65890    0.02853   58.15  < 2e-16 ***

Comment: certainly interesting.  Any chance we could see `str(IN11c)` or `summary(IN11c)` and/or relevant bits of `summary(all.1.NULL.Rasch)` ?
Answer: OK, the only thing I can think of (in the absence of any continuous predictors) is link misspecification.  Tried this using the logit-power link code from the linked question, but I can't actually get it to look like your data (it's much noisier).
Logit-power (uses (fragile) internal C calls for speed; could use plogis(), qlogis() for readability and stability instead)
logitpower <- function(lambda) {
    L <- list(linkfun=function(mu)
              .Call(stats:::C_logit_link,mu^(1/lambda),PACKAGE="stats"),
              linkinv=function(eta)
              .Call(stats:::C_logit_linkinv,eta,PACKAGE="stats")^lambda,
              mu.eta=function(eta) {
                  mu <-  .Call(stats:::C_logit_linkinv,eta,PACKAGE="stats")
                  mu.eta <-  .Call(stats:::C_logit_mu_eta,eta,PACKAGE="stats")
                  lambda*mu^(lambda-1)*mu.eta
              },
              valideta = function(eta) TRUE ,
              name=paste0("logit-power(",lambda,")"))
    class(L) <- "link-glm"
    L
}

Comparing the shape of logit-power links, tweaked to have approximately
the same x-intercept:
par(las=1,bty="l")
curve(logitpower(1)$linkinv(x),from=-4,to=4)
curve(logitpower(0.5)$linkinv(x-1),add=TRUE,col=2)
curve(logitpower(2)$linkinv(x+0.8),add=TRUE,col=4)
legend("bottomright",bty="n",lty=1,col=c(1,2,4),
       paste0("lambda=",c(1,0.5,2)))
abline(v=0,lty=2)

This suggests that the pattern observed above (underpredict for values < 0.5, overpredict for values > 0.5) could come from a logit-power link with $\lambda>1$
However, when we try simulating and fitting with regular logit and logit-power links, it doesn't reproduce your pattern (and doesn't seem to make much difference):
ff <- binomial(link=logitpower(4))
dd <- expand.grid(f1=factor(1:10),f2=factor(1:20),rep=1:20)
library("lme4")
betavec <- seq(-2,2,length=10)
dd$y <- simulate(~-1+f1+(1|f2),family=ff,
         newdata=dd,
         newparams=list(theta=1,beta=betavec),
         seed=101)[[1]]
fit1 <- glmer(y~-1+f1+(1|f2),family=ff,
              data=dd)
fit2 <- update(fit1,family=binomial)

Binned residual plots:
library("arm")
par(mfrow=c(1,2))
binnedplot(predict(fit1,type="response"),resid(fit1),nclass=100)
binnedplot(predict(fit2,type="response"),resid(fit2),nclass=100)


lasso - how to evaluate results

Question: I'm working on lasso as an alternative to step-wise forward/backward regression using the lars package in R. I normalized my variables, calculated the lars and did a CV for figuring out the most suitable fraction s. After that I used that s-value for predicting my model using predict.lars and identify those variables to use and to neglect in my regression equation.
No I got stucked in the further evaluation of my work. What needs to be done next to evaluate the fitting of my model. Is there a kind of p-value and R-square to use as parameter for valuation?
I would like to use the regression equation for interpolation my Y using the variables to a map and need to evaluate the regression.
I know that there are many topics covering my question at a certain point but after browsing the website and literature (Elements of Statistical Learning, An introduction to statistical learning, regression shrinkage and selection via lasso, a significance test for the lasso) I came not up with a specific result.
Answer: You can compare the predicted values from lars and from stepwise on the test data and see how close each comes to the actual values.
However, a lot of this sort of thing has been done already so, unless this project is for your own education, you should review the literature on how well lars works.  One source is Regression Modelling Strategies by Frank Harrell (get the 2nd edition, published this year) that has a lot of material and an extensive bibliography.
Also take a look at the Lasso Page which has a lot of material.
Comment: Comparing of predicted values is a good idea. Thanks you for that unknown resources. But is there a way to obtain R²?
Comment: You can re-run the model that lars suggests in lm and get whatever you like
Comment: Thank you. How should I consider "intercept"? In lasso, the intercept = T and therefore  0 but it's not the case in lm and therefore the coefficients are different.
Comment: If you re-run the model in lm then the intercept will not be 0.

lasso - how to evaluate results


How to calculate players score with php

Question: I have a json string with players statistics and I want to get total player score with that player name here is an example of the json
{
"Players": [
    {
        "playerId": 1,
        "player_name": "Player 1",
        "player_score": 10
        "game_type": "action"

    },
    {
        "playerId": 2,
        "player_name": "Player 1",
        "player_score": 120
        "game_type": "action"
    },
    {
        "playerId": 1,
        "player_name": "Player 1",
        "player_score": 233
        "game_type": "action"
    },
    {
        "playerId": "n",
        "player_name": "Player n",
        "player_score": "n"
    }
   ]
  }

In this example I need to find player 1 for example and calculate all points
so this is what it should be right player 1 has 233 points + 10 points = 243 points, $player_name => $totalpoints;
I've trying with loops to do that but with no success.
Comment: What have you tried so far? Also, IMHO it might be better to leave this to the backend. And to be a bit helpful, use an `each` over that array
Comment: Use `json_decode` then run a loop..most likely
Answer: this should work for you! UPDATED
Cheers Mario
$json  = '[{"playerId": 1,"player_name": "Player 1","player_score": 10},   {"playerId": 2,"player_name": "Player 1","player_score": 20},{"playerId":  1,"player_name": "Player 1","player_score": 233},{"playerId": "3","player_name": "Player 3","player_score": "3"}]';
$array = json_decode( $json, true );
$totalcount = array();
foreach ($array as $key => $value){
   if (!empty($totalcount[$value['playerId']])) {
      $totalcount[$value['playerId']] += $value['player_score'];
   }
   else
   {
    array_push($totalcount, $value['playerId'],$value['player_score'] );
   }
}
foreach ($totalcount as $key => $value) {
echo "Player ".$key." total=".$value."
";
}

Comment: Thanks Mario, how is possible to use without hard coding playerId ?
Comment: Do you want to get back an array with all of them done? and each player with a summed total?
Comment: Updated the code with a summed array output of the players values
Answer: Try this. By using this you can get the result as you want.
$player_array = json_decode($json_string); // put your json string variable

$palyer_array_total = array();
foreach($player_array as $player){
        $palyer_array_total[$player['playerId']]['name'] = $player['player_name'];
        if(isset($palyer_array_total[$player['playerId']]['total_score'])){
            $palyer_array_total[$player['playerId']]['total_score'] = $palyer_array_total[$player['playerId']]['total_score']+$player['player_score'];
        }else{
            $palyer_array_total[$player['playerId']]['total_score'] = $player['player_score'];
        }
}
echo "
"; print_r($palyer_array_total);

Comment: Hey Amit, thanks, its saying that total_score is not defined
Comment: Thanks a lot @Amit, I've added a parameter called "Game type" how can I group users based on game type   {
        "playerId": 1, "game_type": "action",
        "player_name": "Player 1",
        "player_score": 10
    },
Answer: Loop through the array and then add them.. let me suppose the array name is $players, then..
$total_score = 0;
foreach($players as $key=>$value)
{
  if($value['player_name']=='player1')
  {
    $total_score +=$value['player_score'];
  }
}
echo "PLAYER's TOTAL SCORE = ".$total_score;

EDIT:
This looks like JSON code.. so first decode it using json_decode
Comment: Hey phpfresher is that possible not to harcode 'player1' ?
Answer: Here is a way to do it :
//Convert json to php array
$listPlayers = json_decode({
"Players": [
    {
        "playerId": 1,
        "player_name": "Player 1",
        "player_score": 10
    },
    {
        "playerId": 2,
        "player_name": "Player 1",
        "player_score": 120
    },
    {
        "playerId": 1,
        "player_name": "Player 1",
        "player_score": 233
    },
    {
        "playerId": "n",
        "player_name": "Player n",
        "player_score": "n"
    }
   ]
  });

//Sum score for each player id
$totalByPlayers = array();
foreach($listPlayers as $player)
{
    //If player doesnt exists yet, we create it
    if(false === isset($totalByPlayers[$player['playerId']]))
    {
        $totalByPlayers[$player['playerId']] = 0;
    }

    $totalByPlayers[$player['playerId']] += $player['player_score'];
}

//Then for score of player one :
echo $totalByPlayers[1];

How to calculate players score with php


Let M be an Artinian module over a commutative Artinian unital ring R. Is M necessarily finitely generated?

Question: I was trying to prove this statement as true. Actually I found an identical question here:
"Is every Artinian module over an Artinian ring finitely generated?"
However, in the proof of the link above, a key step is
Claim:"If $M$ is not finitely generated one can assume that every proper submodule of $M$ is finitely generated. (In order to see this take the partial ordered set of submodules of $M$ which are not finitely generated and choose a minimal element.) "
I suppose that the statement above assumes we can have a minimal generating set for each submodule. However, I cannot prove that.
Or in another way, the claim above is used to prove that $Ann(M)$ is a prime ideal in $R$, so, is their any way to prove $Ann(M)$ is a prime ideal in $R$?
For some information which might be useful, we have: a commutative Artinian ring is Noetherian.(http://math.stanford.edu/~conrad/210BPage/handouts/Artinian)
and
Modules whose proper submodules are finitely generated is called almost finitely generated
http://www.sciencedirect.com/science/article/pii/0021869383900753
In this article it seems that the claim is not true for a general ring, however, I don't know how to use $R$ being Artinian in the proof.
I do not have enough reputation to comment on the original question so have to open a new one.
Comment: @Matt Samuel did you mean a chain indexed by elements in ℚ? but ℚ is countable, which means there is an injection from ℕ to ℚ. .. but suppose there is a chain indexed by uncountable set, such as real number, it seems that we could still use the descending chain condition
Comment: The intention was to use the Artinian condition and Zorn's lemma but there's actually a subtelty here. We can only apply the Artinian condition on a decreasing sequence of submodules *indexed by the natural numbers*, so the fact that Zorn's lemma applies (that is, every chain has a lower bound) is not obvious.
Comment: @Matt Samuel it is enough to show that every chain (which is indexed by natural numbers) has a minimal element, and that is true because $M$ is an Artinian module. Then Zorn's Lemma applies so we have a minimal element. I suppose we then should do the trick of showing that we can further construct a "more minimal" element which is still not finitely generated, and thus a contradiction, but that requires a minimal generating set.
Comment: Not every chain can be indexed by natural numbers in such a way that preserves the order type, because not every linear order is isomorphic to $\mathbb{N}$. We could have a chain isomorphic to $\mathbb{Q}$, for example.
Comment: @honoka if you're willing to learn the Hopkins Levitzki theorem, you get the result almost immediately, and for noncommutative rings to boot. I've put that solution on the question you linked.
Comment: @honoka *I suppose that the statement above assumes we can have a minimal generating set for each submodule. However, I cannot prove that.* Why would it need that? There is a minimal element regardless, owing to the minimum condition. So, wlog you can begin with a module whose proper submodules are finitely generated.
Comment: @Matt Samuel well, I just searched wiki and it says "a sequence can be defined as a function whose domain is a countable totally ordered set"; and  a "descending chain condition (DCC)" is "if every strictly descending sequence of elements eventually terminates". So it seems that we cannot use D.C.C. when the chain is uncountable..
Comment: @rschwieb that's right, I just figured it out with your helps, thanks  a lot !!
Comment: @honoka cool: good luck!
Comment: @Matt Samuel  If we have a uncountable chain, is it possible to pick a countable subchain, such that any element in the original chain is between two elements from the countable chain, and then apply D.C.C.?
Comment: @honoka that's not true. Every countable subset of $\omega_1$ is bounded. In any case Eric's proof is fine.
Comment: @MattSamuel Question: But using Zorn's Lemma requires that "every chain", especially uncountable chain, has a minimal element, so how did Eric's proof solve that problem?
Comment: @honoka rather than directly apply the descending chain condition to the entire chain, assume there's no minimal element and construct a countably infinite descending chain, to which the condition can be used to obtain a contradiction.
Comment: @MattSamuel So that removes the possibility of existence of an uncountable chain at the outset right? thanks a lot!!
Comment: @honoka yes. You're welcome.
Answer: If $M$ is Artinian, then any nonempty collection $S$ of submodules of $M$ has a minimal element.  For suppose $S$ has no minimal element; let $N_0\in S$ be any element.  Since $N_0$ is not minimal, there is some $N_1\subset N_0$ in $S$.  Since $N_1$ is not minimal, there is some $N_2\subset N_1$ in $S$.  Continuing by induction, you get an infinite strictly descending sequence of submodules, contradicting the fact that $M$ is Artinian.
So now let $S$ be the collection of non-finitely generated submodules of $M$, and let $N\in S$ be a minimal element.  Then $N$ is a non-finitely generated module with the property that every proper submodule is finitely generated.  Also, $N$ is Artinian because $M$ is.  We now replace $M$ by $N$: that is, apply the rest of the argument to the module $N$, instead of $M$.
Comment: I guess you would let S be the set of submodules of M which are not finitely generated. And let N be a minimal element in S, but we need to show N is precisely M, which can be shown if there is a minimal generating set for M. However we don't have that.
Comment: If $N$ isn't $M$, you just replace $M$ with $N$ in the rest of the argument.
Comment: Oh I see, so we can show that $N$ is finitely generated, contradicts the defining property of element in $S$, and that leads to S is a empty set, is it?  |||   Thanks a lot!!!!


Prolog Tree Traversal

Question: Good Day,
I am trying to write a Prolog program that given a tree with a functor of a:
start(a(f,2,9), X).

I want it to square any values inside so that it yields:
X = a(f,4,81).

I have code that squares numbers in a list already that works.
Here's what I have so far:
start([],[]).
start(Tree, []) :- Tree =.. [P|C], write(P), nl, write(C), nl, squareMe([P|C], []).
squareMe([X|T], [Y|Result]) :-   % I think the problem is here
    atom(X),
    Y=X,
    squareMe(T, Result).
squareMe([X|T], [Y|Result]) :-
    number(X),
    Y is X * X,
    squareMe(T, Result).
squareMe([], []).

when the code writes P and C, I do get the correct values via the UNIV operator, but it seems to be failing inside squareMe.
When I invoke squareMe([P|C], []), my understanding is the P = a and C = [f, 2, 9].  So shouldn't atom(a) be true?  It doesn't appear to be the case and I'm not sure why?
I've tried using trace/notrace to track my path, but it would sure be nice to see the values that were passed into squareMe.  Is that possible?  I'm using SWI-Prolog.
TIA,
coson
Answer: This is an answer instead of a comment only because it is too long; I don't fully understand your question though.
To get the solution to the query you show at the top, it would be enough to write:
start(a(f, X, Y), a(f, XX, YY)) :-
    XX is X*X,
    YY is Y*Y.

That's it:
?- start(a(f, 2, 9), X).
X = a(f, 4, 81).

This is way too easy, and more importantly, I don't see any tree structure here, which is why I am certain I am misunderstanding the question. I definitely have trouble following the code you have shown. You should edit your question to explain:

where is the tree structure you are traversing?
are you using lists, flat terms, nested terms (a tree?)
does your predicate have to work both ways, so, should you be able to ask: ?- start(X, Y). for example.

Prolog Tree Traversal


Which NFL teams have natural grass stadiums?

Question: What percentage of NFL teams play on natural grass at their home stadium?
How many are indoor versus outdoor fields?  Please further breakdown the percentages for indoors and outdoors fields. When listing these teams, and mention whether they play indoors, or outdoors.
If a team has already committed moving to a new stadium in the near future (e.g. the LA Rams and Chargers), indicate the future stadium's grass type as a side note.
Answer: An article on lawnstarter.com has compiled a list of NFL stadiums, and what type of turf they play on.
Of the 32 professional teams, 56% (or 18 teams) play on natural grass.
Of those 18 professional teams, 6% (or 1 team) plays indoors.
The 18-team stadium breakdown on natural grass is as follows:

Kansas City Chiefs (outdoors)
    Carolina Panthers (outdoors)
    Washington
  Redskins (outdoors)
    Cleveland Browns (outdoors)
    Miami Dolphins (outdoors)
  Pittsburgh Steelers (outdoors)
    Green Bay Packers (outdoors)
    San
  Francisco 49ers (outdoors)
    Philadelphia Eagles (outdoors)
    Los Angeles
  Rams (outdoors) - LA Rams will move to an artifical turf in 2019.
    Baltimore Ravens (outdoors)
    Tennessee Titans (outdoors)
                                                    Los Angeles Chargers (outdoors) - LA Chargers will move to artifical turf in 2020.
    Tampa Bay
  Buccaneers (outdoors)
    Chicago Bears (outdoors)
    Denver Broncos (outdoors)
  Arizona Cardinals (indoors)
    Oakland Raiders (outdoors) - The Oakland raiders will move to Las Vegas sometime around 2020 and will have Sprinturf (a brand of artificial turf).
Comment: Also Arizona Cardinals don't play indoors
Comment: For the purpose of this question, consider all stadiums with retractable roofs as indoors. So the cowboys and the Texans also play indoors
Comment: Yeah, the idea is that if you play under a roof when it's cold, raining, and snowing, then you play indoors.
Comment: Totally agree with everything, just trying to point out that your comment above says the arizona cardinals don't play indoors when they have a retractable roof at University of Pheonix Stadium. Also, I will edit my answer to fit the specifications later today!
Comment: BTW Miami Dolphins play outdoors!


How to revert git add?

Question: I wanted to branch off my master into a new branch, say new-branch. However, I accidentally ran git checkout -b add new-branch.
Now I cannot view any of my other branches or checkout to my origin master. The command seems to have created a new repo locally.
I've tried using git revert to fix this, to no avail.
I would like to know how to get to my origin repo and delete the submodule.
Comment: The command you stated in your first paragraph will only create a new branch called `add` from an existing ref called `new-branch`. If `new-branch` is an unknown ref, the command should fail ("fatal: 'new-branch' is not a commit and a branch 'add' cannot be created from it").
Comment: That is what I expected but it created a submodule.
Comment: @BeulahAkindele (just a sidenote) You actually wanted to name a branch *add*? If so, this is a really bad idea. There are billions of words or word combinations. Only a few dozens are used for git commands themselves. Don't shoot yourself in the foot by choosing one of them as a branch name.
Comment: @RomainValeri No, I don't mean I want to name a branch "add", but I see where the misunderstanding stems from. I meant I did not expect the command to execute successfully as knittl said in her comment.
Answer: I'm thinking I should just delete the question but I was just in the wrong directory.
So to get my old branches, I just cd into the appropriate directory and to delete the submodule git rm --cached unintended-branch-name.
Comment: But thanks for the feedback :-) Useful to finally understand what was going on, but not everyone does it.

How to revert git add?


rsnapshot : will the initial backup be retained forever?

Question: When making a backup with rsnapshot, "[...] we first replicate the previous backup into a parallel directory structure, creating all the directories and making hard links to all the files.". This is all good.
I assume this implies that the initial backup will be retained forever? The "newer" backups will only point (through hardlinks) to the older backup, so I'm assuming that the actual file which any given hardlink points to needs to be retained forever to not break things?
Is this assumption right?
Answer: No, this is not correct. If you have multiple hardlinks to a file, it doesn't matter which one originally created the file, the file will only be deleted if the last link to the file is deleted (see the difference between a hard link as used by rsnapshot and a symbolic link)    In the case of rsnapshot this means that every backup directory is self-contained and you can delete all other backup directories (including the initial one) and still have a full set of data.
Depending on how you configure rsnapshot, it will eventually delete the orginal backup set.
Comment: @SvW: Is there any way I could tell rsnapshot to keep the initial(very first) backup forever ?
Answer: TL;DR: no.
It depends on what you define an "initial backup".
You first create a backup (hourly.0), which has all the files from today.
On the next iteration, it "copies" the files (cp -L, just copies the links to the data), to hourly.1 folder.
If all the files are the same as before, rsync won't write anything, so you have one block of data for a file (let's use myfile.jpg), and two links (hourly.0/myfile.jpg and hourly.1/myfile.jpg) pointing to the same file on the drive.
On the next iteration with no changes, you still have the same data, just another pointer (hourly.2/myfile.jpg) pointing to that data.  If you have set it up to keep 3 backups, it will then delete hourly.2, movde hourly.1 to hourly.2, move hourly.0 to hourly.1, "copy" (create hardlinks) from hourly.1 to create hourly.0, and then run rsync again.
If the file changes, rsync will "remove" the file (just the link actually) hourly.0/myfile.jpg (the data stays on the drive, since there are still two links pointing to it). Rsync will then create a new file (link+data) with the new myfile.jpg.
So now you have one block of data with one link for the new file, one block with two links to it for the old version of the file.
On the next iteration, it deletes the hourly.2 (one link less for the data of the old file), "copies" (hard links) the new file (new link for the new file. There are two pointers for the new file data, and one for the old versions data.
On the next iteration, it deletes the last link for the old version (data with no links pointing to it, is considered free by the filesystem, and will get overwriten when needed), and three links towards the new file data.
If there is a link pointing to data (no matter from which directory), this data stays on the drive. Only once you delete all the links, then the data can get overwriten.


Why am I getting blank pdf when downloading using request in python

Question: I am trying to download a pdf from its URL using the requests.get method and then saving it with a variable name in the local desktop.
However, it takes around 2 minutes to run and the pdf is saved, but the acrobat reader can't read it.
from datetime import date

market_type = "ECenter"

market_name = ["Minden", "Porta-Westfalica", "Osnabruck", "Melle", "Bad Nenndorf", "Herford"]

weekNumber = date.today().isocalendar()[1]

city_codes = ["3315", "3317", "3309", "3323", "3325", "3328"]

for city in city_codes:
 url = "https://static.edeka.de/media/handzettel/MINDEN/"+city+"/blaetterkatalog/pdf/complete.pdf"
 myfile = requests.get(url)
 for name in market_name:
  with open('C:\Users\user\Desktop\LeafletFiles\{0}_{1}_{2}.pdf'.format(market_type,name,str(weekNumber)), 'w') as pdf:
    pdf.write(myfile.content)

Answer: I would use the pathlib module for that. The following code may help you:
from datetime import date
from pathlib import Path  # import pathlib module
import requests

market_type = "ECenter"

market_name = ["Minden", "Porta-Westfalica", "Osnabruck", "Melle",
               "Bad Nenndorf", "Herford"]

weekNumber = date.today().isocalendar()[1]

city_codes = ["3315", "3317", "3309", "3323", "3325", "3328"]

for city in city_codes:
    url = "https://static.edeka.de/media/handzettel/MINDEN/" + city + "/blaetterkatalog/pdf/complete.pdf"
    myfile = requests.get(url)
    for name in market_name:
        # making our pdf
        pdf = Path('C:\\Users\\user\\Desktop\\LeafletFiles\\{0}_{1}_{2}.pdf'.format(
                market_type, name, str(weekNumber)))
        pdf.write_bytes(myfile.content) # writing the content


Is there a way to create a taxonomy path redirect?

Question: I am trying to create a taxonomy redirect for specific taxonomy URL. Basically what Taxonomy Redirect did for Drupal 6 but for Drupal 7. I have searched the Drupal 7 API for hook_term_path but don't see it.
Finally, I need these links to be associated with particular profile2 profiles.
Is this possible?
Comment: updated my answer for doing it the custom module way and a way to use the contrib module
Comment: for drupal 6 there's a [taxonomy redirect](http://drupal.org/project/taxonomy_redirect) module.
Comment: not for Drupal 6 .... Drupal 7... I think the closest is TVI... but I haven't used it.
Comment: thnx for the information
Answer: Instead of hook_term_path you can use hook_entity_info_alter.
A small example
function MYMODULE_entity_info_alter(&$entity_info) {
  $entity_info['taxonomy_term']['uri callback'] = 'MYMODULE_term_uri';
}

and then you can implement you version of MYMODULE_term_uri function.
Hope it helps.
Also if you want the D7 version of the module you mentioned you should try
http://drupal.org/project/entity_path
Comment: Do you know how to create an argument for profile 2 fields for a block with this in mind so that any particular user can see information via a taxonomy term for any other particular user.  I'm always interested in going the custom module route but worried that there is some incompatibility with something already previously installed.
Comment: I am actually clueless as to what you want to achieve. Can you give some more information. If you want to go the custom module way I just mentioned above the hook and MYMODULE_term_uri will be the custom function where you can do all the necessary changes you want to do.
Comment: I'm just trying to create a dynamic view for profiles2. I need to have a view showing fields of one user at a time. I wanted to create the view and redirect my taxomy term to it. I assumed to take a taxonomy redirect approach since all users of a specific type will have a unique tag so it becomes a basic identifier. Some may share the tag, some may not, which gives me the option of grouping. That's basically it in a nutshell - I'm stuck at trying to find a solution to show a user profile via views. I only need to show one profile because only one user roll will have that profile control.
Comment: Back to the drawing board
Answer: drupal.org/projects/tvi seems the closest for drupal 7. It actually does what I need. I am just concerned that its not needed since what it does could be done with managing the fields of taxonomy and this doesn't point directly to specific nodes created by views for profile 2.


Carregar o conteúdo de uma  em outra  ADVPL ASP

Question: Estou com uma dúvida em um código que utiliza de advpl(Microsiga Protheus) mais HTML.
Estou precisando na parte html,  que o conteúdo de uma TD seja capturado no momento da escrita, e seja atribuído em outra TD.
Segue abaixo a captura de tela mais o trecho do código:

Nesse caso preciso que ao fazer a coleta da chave da Nota, autocomplete o Numero da NF e série  pegando o SUBSTRING 26,9 número da nf  e 23,3  Série da NF.
Código html
REGISTRO DE NF DE SAIDA

             Chave Da NF:
            <input type="text" name="T2" size="44" MAXLENGTH="44" onblur="jscript:valida(this.value);">

             Numero NF:
            <input type="text" name="T3" VALUE=" " size="6">

             Serie NF:
            <input type="text" name="T4" VALUE=" " size="3">

             Status:

                <select size="1" name="STATUS">
                    <option value="S">1= Saída na Portaria</option>
                    <option value="D">2= Devolvido para Estoque</option>
                    <option value="C">3= Cancelamento Cliente</option>
                </select>

        <button name="B1" type="none" onclick='jscript:validaall()'>> Confirma <</button>

        Voltar ao Menu

Já deixo meus agradecimentos pela ajuda.
Answer: Obrigado siga0984..
Consegui resolver, seguindo sua dica tive uma ideia, ao invés de criar o formulário, na função valida, onde já temos os dados carregados, passei uma substring do conteúdo do campo da chave da nota fiscal para o (value) do outro campo.
Como no html além da validação do JavaScript como você mencionou,também é passado a função onblur ao clicar fora do campo automaticamente é carregado o campo Numero NF e Série NF.
Segue o trecho do código para melhor entendimento:

Answer: No seu código Html, já está sendo usado JavaScript para fazer a validação da chave da nota fiscal ( função javacript:valida() , disparada após a perda do foco no campo "Chave da NF" ), e a validação "total" através da função validaall(), disparada através do botão "Confirma".
O que você vai atualizar não é exatamente as "TDs" das tabelas, mas os valores dos INPUTs dispostos na tabela. Para fazer estes eventos, eu criaria um formulário HTML para agrupar os inputs, passando este formulário como parâmetro para a função valida() em Javascript, e dentro dela faria a quebra do valor do campo e alimentação dos valores dos demais inputs do formulário.
Existe um tópico (em inglês) no próprio StackOverflow -- https://stackoverflow.com/questions/7609130/set-the-value-of-an-input-field -- mostrando alternativas de como fazer o preenchimento de um campo de formulário ou INPUT Html usando JavaScript.


CSS3 support for ie6,7,8

Question: I need to add support to some css3 selectors to ie6,7,8:

nth-child
first-child
last-child

I cannot use ajax to get the content of the css and parse the css3 specific selectors because the css file is very huge and it would imply having to download the same css file 2 times for each request.
I've been investigating the already parsed CSS rules available in document.styleSheets[<index>].selectorText, but when IE parses a selector that doesn't understand such as nth-child, the whole selector string is replaced by UNKNOWN. For example:
css:
ul li:nth-child(2){
  color: red;
}

javascript
console.log (document.styleSheets[0].selectorText);
/*
UNKNOWN {
  COLOR: red;
}
*/

Therefore, I cannot put css3 specific syntax inside the css file and I cannot redownload the whole css via ajax. What I've thought is to download the css file only one time via ajax and without using a <link> tag. Then parse and apply the css rules using javascript.
I don't want to do css hacks, my initial idea is to use a polyfill in javascript.
Any better ideas?
Comment: Just use [selectivzr](http://selectivizr.com/) and let it do everything for you.
Comment: Gabriel, use [jquery](http://jquery.com/browser-support/) in conditional comments.
Comment: @vutran I've already seen selectivzr but it doesn't apply some selectors correctly, but more important, it gets the file via ajax and I don't have CORS support in the server side.
Answer: This is already in a comment here, but it is the best answer. Use selectivizr

selectivizr is a JavaScript utility that emulates CSS3 pseudo-classes and attribute selectors in Internet Explorer 6-8. Simply include the script in your pages and selectivizr will do the rest.

Here it is on Github
If this is not a workable solution, make sure that IE6-8 degrade gracefully and render a functional page. Old browsers are allowed to render sites differently :)
Answer: nth-child:
ul > li + li + li ... + li {}
     ^    ^    ^        ^
     1st  2nd  3rd ...  n-th

first-child:
ul > li {}

last-child:
not possible except you know how many childs are there and you use n-th child

Comment: With this approach I can't simulate `nth-child(even)` and similar :(
Comment: that is a real problem, but there is no way, except with an javascript workaround to fix this.
Comment: The best solution may be to let ie6 - 9  degrade as gracefully as possible and forget about replicating these effects.

CSS3 support for ie6,7,8


How to generate a GARCH series contaminated with outliers

Question: How can I simulate a GARCH series that is contaminated with both additive and innovative outliers?  My goal is compare different robust estimators. I am using R.
Answer: A simple example for GARCH(1,1) (the R code should be self-explanatory):
<code>T=500
y=sigma.sq=rep(NA,T+1)
set.seed(1); innov=rnorm(T+1)
omega=0.05; alpha=0.1; beta=0.85
sigma.sq[1]=1/(alpha+beta)

# Below you specify the additive and multiplicative outliers
add.out=rep(0,T+1); add.out[100]=10; add.out[300]=20
mul.out=rep(1,T+1); mul.out[200]=10; add.out[400]=20

# Generate a GARCH(1,1) process with both additive and multiplicative outliers
for(t in 2:(T+1)){
 sigma.sq[t]=(omega+alpha*(sigma.sq[t-1]*innov[t-1]^2)+beta*sigma.sq[t-1]+add.out[t])*mul.out[t]
 y[t]=innov[t]*sqrt(sigma.sq[t])
}
sigma.sq=sigma.sq[-1]
y=y[-1]

# Plot the process and its conditional standard deviations
ylim=range( c( y,sqrt(sigma.sq) ) )
plot(y,type="l",ylim=ylim)
lines(sqrt(sigma.sq),col="red")
</code>

Here the outliers affect the conditional variance equation. You can easily change the code so that the outliers affect the realized values directly: replace
<code> sigma.sq[t]=(omega+(sigma.sq[t-1]*alpha*innov[t-1]^2)+beta*sigma.sq[t-1]+add.out[t])*mul.out[t]
 y[t]=innov[t]*sqrt(sigma.sq[t])
</code>
with
<code> sigma.sq[t]=omega+(sigma.sq[t-1]*alpha*innov[t-1]^2)+beta*sigma.sq[t-1]
 y[t]=(innov[t]*sqrt(sigma.sq[t])+add.out[t])*mul.out[t]
</code>
Comment: thanks a lot , but i am wondering is the multiplicative outliers the same as innovative outliers in garch model
Comment: @mona I suppose it depends on how you define things, but I do not see why they should be the same. My example code shows both types of outliers. You can play with the code, e.g. change the size or the locations of the outliers, add more of them or remove the existing ones. That way you might get a better feel for what effects the outliers have.
Comment: @RichardHardy Hi Richard, I wonder if the code you used to generate the conditional variances are correct; more specifically: `sigma.sq[t] = omega + alpha * innov[t-1] ^ 2 + beta * sigma.sq[t-1]` (I omitted the terms for the outliers). Shouldn't the white noise `innov[t-1]` be replaced by the actual residual at `t-1` (which is dependent on `sigma.sq[t-1]`)?
Comment: @XiuboZhang, you are right, I will have to fix it.
Comment: @RichardHardy I was going through [this](http://www.econ.nthu.edu.tw/bin/downloadfile.php?file=WVhSMFlXTm9MemMyTDNCMFlWOHlNamczTVY4eU5UQTNPRGhmTWpJd05qVXVjR1Jt&fname=HDJHWTCHJDSTDGRP1501RL04IHVTCD51GHRPEHDD35JHTWCHSXFD15CHEDIHWX50A5VTCDPKJDA5DD40STSTKOVX) slide deck; on page 11, the author showed an alternative specification for GARCH involving a white noise series, which suggests a easy correction to the original code: `sigma.sq[t] = omega + alpha * sigma.sq[t-1] * innov[t-1] ^ 2 + beta * sigma.sq[t-1]`
Comment: @XiuboZhang, thank you very much. I edited fast, I hope I got it right this time. The mistake was a stupid one.