Accent alignment in Japanese music with English lyrics

Question: When listening to Japanese (pop) songs containing English lyrics, I can't help but notice an interesting phenomenon. Usually for English songs, we tend to align the linguistic stress with the melodic/rhythmic/metric stress. But Japanese songs seem to follow different rules. This sentiment seems to be shared by some others. Redditors also made similar observations, although it's about K-Pop, and perhaps not phrased very politely.
Take S.A.T.E.L.L.I.T.E. by Camellia for example. At around 0:42 there is the word "satellite". The melody is bA-bB-bA, so the climax is at the syllable "tell"; it also lies on the metric stress, being at the third beat of a 4/4 measure; it is furthermore the rhythmic stress because the note bB is longer. But the English word "satellite" is most commonly pronounced with the stress at the beginning, not in the middle. In contrast, the word "scintillation" is aligned as expected, occuring earlier in the song.
I haven't been able to confirm whether this is simply because the songwriter himself pronounces "satellite" with an alternative stress, but I suppose not. Is there a difference between how Japanese and English songwriters align stress and accent? If so, how and why?
Comment: When you bring karaoke or karate to America, they become kara-Ohkee and kuh-Rah-dee. Arri Gaatoh!
Comment: @user94880 So are you suggesting this phenomenon is purely happening at the linguistic level? Could you provide some reference to back this up? Because as far as I know these songwriters seem to pronounce English stress in the English way in speech.
Comment: No reference, it's just an observation, that's how things seem to go. When people try to use foreign languages, there are many levels of fluency and skill, and placing stressed syllables like native speakers is one level. Maybe they don't feel that stress is important, or they never thought of it.
Comment: @user94880 or they're unaware of it, or they think they know but are wrong, as surely most English speakers are about Japanese.  There are many possibilities.  In any event, getting the stresses wrong -- and other subtleties of pronunciation -- in singing a foreign language or setting one to music is extremely common.  There are a few notorious instances in Handel's English-language output, for example.
Comment: I've seen all kinds of examples of English lyrics by native English speakers that mess this up, so....
Comment: All the English in that song is very katakanarised, to the point that it's hard to understand without simultaneously reading the lyrics. It just stands out the most at the word saTErite, since it's repeated so often. The melody in the Japanese parts seems to match with the saTErite part, so it seems pretty clear that it's simply English being put onto a melody, with zero considerations as to a native pronunciation.
Comment: But specifically WRT the Japanese perception of stress vis-a-vis the English word "satellite" - more precisely, the Japanese loanword サテライト, see also https://www.youtube.com/watch?v=JJYyeFoiYH4 which I think is much better known actually. The stress is clearly placed on RA, not TE.
Answer: Japanese doesn't have "stress" the way English does. The closest thing is "pitch accent," which is non-lexical and varies by region. Every mora in Japanese (represented by a single kana) lasts the same amount of time and receives about the same amount of emphasis.
Think about why the haiku, a syllable-based structure, doesn't really work in English. Stress is baked into English words and sentences, so different five-syllable phrases with different stresses don't flow similarly at all and may be awkward. Any five Japanese syllables will flow much more evenly, which makes syllable-based poetic structures a natural form in the language.
So the reason English lyrics written and sung by Japanese speakers can sound like they ignore stress rules is that they do. The writer simply isn't thinking in those terms.
Comment: Incidentally, the downstep of サテライト in 標準語 (standard Japanese) is on the third mora (sateRAito), so the pitch accent should be LHHLL.
Answer: The Japanese language does borrow words from other languages and changes them to fit with their standard rules of pronunciation.  So the word satellite becomes a word that is pronounced as Sa-Te-Ra-I-To.  And as such it's more natural for the stress to fall on the -Ra- in the middle.
So it's possible that the singer is singing the English word in a more comfortable Japanese stress style.


What are the basic affine transformations on a distribution for the various moments?

Question: To change a distribution's mean, we do the translation affine transformation. E.g. add a constant to every data point.
To change a distribution's variance, we do the scale affine transformation. E.g. multiple every datapoint by a constant.
Are there similarly canonical affine transformations for kurtosis, skew, and high order moments?
Comment: An affine transformation allows you to change only two moments (not necessarily the first two), basically because it gives you two coefficients to play with (I assume we're on the real line). If you want to change more than two moments you need a transformations with more than two coefficients, hence not affine.
Answer: Not affine, but polynomial transformations for example. Basically this is necessary because you want to change several numbers at the same time, and an affine transformation only gives you two coefficients to "play with" (I assume we're speaking about distributions on the real line).
If you consider a coordinate transformation $y=f(x)$, a density function $\mathrm{p}(x)$ changes in such a way that $\mathrm{p}(x)\,\mathrm{d}x = \mathrm{p}(y)\,\mathrm{d}y$, where $\mathrm{p}(y)$ is the density function in the new coordinates (related to the old one by a Jacobian determinant).
Denote the $n$th raw moment in $y$-coordinates as $m_n := \int y^n\,\mathrm{p}(y)\,\mathrm{d}y$, and in $x$-coordinates as $M_n := \int x^n\,\mathrm{p}(x)\,\mathrm{d}x$. Take an affine coordinate transformation $y=ax+b$.
Consider the third raw moment in $y$-coordinates and pass to $x$-coordinates:
\begin{align}
m_3&=\int(ax+b)^3\,\mathrm{p}(y)\,\mathrm{d}y\\
&= a^3\int x^3\,\mathrm{p}(x)\,\mathrm{d}x
+3a^2b\int x^2\,\mathrm{p}(x)\,\mathrm{d}x
+3ab^2\int x\,\mathrm{p}(x)\,\mathrm{d}x
+b^3\int\mathrm{p}(x)\,\mathrm{d}x
\\
&= a^3 M_3
+3a^2b M_2
+3ab^2 M_1
+b^3
\end{align}
Imagine to write similar equations for $m_2$ and $m_1$. You get a system of three equations giving you $\{m_1, m_2,m_3\}$ as polynomials of $\{M_1,M_2,M_3\}$, with the coefficients involving $a$ and $b$. If you fix all six moments, you may be able to choose the coefficients so that two equations are satisfied, but in general the remaining one won't be. This means that you need a transformation involving more than two coefficients. (You may still not be able to find a solution though; this is related to the moment problem.)

Otherwise, an everywhere-positive density function can be transformed into any other everywhere-positive density function by an appropriate coordinate change, so in principle you can change the moments in any way you please (within limits related to the moment problem).

Regarding the other part of your question, I don't know of any canonical transformations for skewness and kurtosis, but maybe there are.
This is a tricky and fascinating topic. The fact is this: from "the point of view of the distribution", which is a measure, the manifold upon which it's defined doesn't need to have any additional structure (just a measurable space). For us to speak about a mean, the space needs to have an additional convex structure (which locally implies an affine one). With such a convex structure we can't speak about a second moment or variance. To speak about a variance, the space needs to have a quadratic form defined on it (quadratic forms can be defined on a convex space, even if it isn't a vector space; they have just slightly different properties from forms on a vector space). And so on. So usually the space has some additional structure that makes sense in the specific problem. The transformations we consider have to somehow be compatible with that structure to make sense.
This is also why we standardize the first and second moments of a normal distribution, but don't standardize higher moments: we could, with an appropriate transformation, but the distribution would not be a normal distribution anymore (that is, one belonging to the normal family). And how can we say that a distribution is a "normal"? We need (1) an affine structure and (2) a quadratic form on that space. [I hope this makes sense to you, sorry maybe I'm being too concise.]
Comment: Thanks pglpm! This also explains why shifting mean/variance is so popular in ML operations like Batch Norm and Adaptive Instance Norm: mean and variance are only two moments, so it's changeable with a simple affine transform. Are there polynomial transformations that would be considered canonical for skew/kurtosis? For kurtosis, I could imagine a transformation t(x) = x**2. Dots close to zero get closer; dot far away get further. Dots exactly at 1.0 don't move. For skew... t(x) = x*log(x)?
Comment: You're welcome! I've added some info to my answer regarding that. I don't know of any, but they may well exist. You notice that if you use a 3rd order polynomial, it'll touch the *6th* moments. There's also a matter of which transformations "make sense" in your space. Your question touches a very fascinating topic.
Comment: @Yaoshiang Have a look at LambertW transformations . e.g. [What's the distribution of these data?](https://stats.stackexchange.com/questions/33115/whats-the-distribution-of-these-data/47917#47917)


componente devexpress para memorizar edit

Question: Alguém sabe qual componente do devexpress (delphi) que faz com que memorizar o texto editado nos edit(s) da aplicação ?
exemplo: tenho um TEdit, com nome de usuario, depois que digitar pela primeira vez, quando for digitar na segunda vez assim que colocar a primeira letra ele ja reconhece o que tinha digitado anteriormente (claro se tiver com a mesma letra do inicio.)
Answer: Na verdade é uma propriedade presente em diversos componentes que aceitam textos, como Edit e ComboBox, por exemplo. Na documentação procure por MRU (Most Recently Used / Mais Recentemente Utilizados).
Explorando a propriedade MRUList dos componentes você verá que é possível gravar e recuperar os valores automaticamente.
Exemplo em WinForms.
https://documentation.devexpress.com/WindowsForms/DevExpress.XtraEditors.MRUEdit.members
Comment: Embora este link possa responder à pergunta, é melhor incluir as partes essenciais da resposta aqui e fornecer o link para referência.  As respostas apenas por link podem ser invalidadas se a página com o link for alterada. - [Da Revisão](/review/low-quality-posts/178121)
Comment: Tranquilo, é que a documentação da DevExpress é um arquivo CHM (ou PDF) gigantesco (só a parte que trata de editores tem mais de 5 mil páginas) que fica instalado junto do componente (não há versão online para VCL), e não tenho a DevExpress instalada na minha IDE. De qualquer forma hoje a noite instalo e preparo um exemplo com imagens, aí atualizo minha resposta.
Comment: @RBZ, o link que postei não responde a pergunta, até porque trata-se de Visual Studio, enquanto a pergunta trata-se de Delphi, o que quis foi passar o conceito para facilitar a implementação. "MRUList" é a reposta para a pergunta, é apenas uma propriedade e não necessariamente precisa de códigos adicionais, mas isso abre um leque de outras possíveis perguntas que não poderiam ser respondidas aqui. ;-)
Comment: Marcio, vou te explicar o porque marquei isso na revisão. Eu não conheço delphi, então eu tenho que em parte deduzir que você está explicando certo, correto!? Então você diz "Na documentação procure por MRU"... Nisso, você já poderia ter passado essa documentação referente ao o que o usuário precisa, e melhor explicando, dar um exemplo, trazer mais informações, entende!? Novamente ficou no ar "Explorando a propriedade MRUList dos componentes..." incremente com exemplos, mesmo que sejam simples... poderá outro usuário vir até essa pergunta, sabendo menos ainda... entendeu?...
Comment: Não que sua resposta esteja incorreta só por link, mas eu poderia ter marcado como "Deveria ser um comentário" também... entendeu!? ;)


Getting started with bayesian structural models using MCMC

Question: I'm trying to learn bayesian structural time series analysis. For a variety of reasons I need to use Python (mostly pymc3) not R so please do not suggest the bsts R package. Moreover, I would like to gain a conceptual understanding not use a black box. I've posted a few questions on StackOverflow regarding prediction and seasonality. The SO questions are still open and I didn't want to violate any rules/etiquette by reposting here. However, I'm beginning to think I have a conceptual misunderstanding. Can anyone recommend online tutorials or lectures for exploring Bayesian structural models using MCMC preferably in Python?
Comment: Take a look at PyStruct
Comment: There is a nice set of notebooks using Python, including space state models, SARIMA, and other time series models in this GitHub [repo](https://github.com/ChadFulton/tsa-notebooks).
Comment: I could provide references if it was bayesian time series-mcmc but bayesian structural might be slightly different so I don't want to confuse the issue. If you don't mind, could you give a reference for bayesian structural ? thanks.
Comment: @mlofton I pretty much mean models of the form linked in the question (prediction and seasonality links).
Comment: @Paul: Thanks for clarification. You should definitely check out Andrew Harvey's blue book ( forget the name ) and Harrison and West's, "Dynamic Linear Models".
Comment: Check out this paper http://people.ischool.berkeley.edu/~hal/Papers/2013/pred-present-with-bsts.pdf
Answer: You might be interested in TensorFlow Probability. It has a Python API, and has been chosen to replace Theano as the PyMC3 backend at some point in the future. Tensorflow Probability can also be used for MCMC directly, and it has dedicated functionality for Bayesian structural time series modelling. There is a nice blog post which provides an introduction.


Passing graphical parameters across chunks in knitr

Question: Can anyone help me in relation to passing (or setting global) par graphical parameters across chunks in knitr.
I have a large piece of R code with a loop that generates a plot at each iteration of the loop and prints each plot on the same page of a PDF (via par(mfrow=c(5,4)).
If I break up my code into knitr chunks to make it more manageable, the graphical parameters are lost each time I leave the chunk and I lose the ability to output several plots on the same PDF page.
Is there a way to pass graphical parameters across chunks or to set the parameters as global so that all chunks can access them.
Comment: This question was answered in a comment [here](http://stackoverflow.com/q/23439274/937932).
Answer: You can set the global.par knitr-option to TRUE like this:
```{r setup, include=FALSE}
opts_knit$set(global.par = TRUE)
```

Then set par in the next chunk and plot something:
```{r}
par(mfrow=c(5,4))
plot(something)
```

The same par-options will now be passed to the following chunks (until changed again).
Comment: You may need to add `library(knitr)` to make it work.


scroll_to_index-2.1.1: Warning: Operand of null-aware operation '!' has type 'SchedulerBinding' which excludes null

Question: I'm trying to implement integration testing for my flutter app but I'm getting this error when writing something very straightforward.
ERROR: ../../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/scroll_to_index-2.1.1/lib/scroll_to_index.dart:358:57: Warning: Operand of null-aware operation '!' has type 'SchedulerBinding' which excludes null.
Please help me in resolving this error.
Answer: This might be because of Flutter SDK upgrade, it you are using Flutter SDK 3.0 then scroll_to_index is still not upgradable or if you are using Flutter 2.0 then you can simply run this command flutter pub upgrade
Comment: @Nike then this may be issue because of pub cache, did you try to delete pubspec.lock file and `flutter clean` and then `flutter pub get`
Comment: Flutter 3.1.0-0.0.pre.731 is what I'm using. How can I fix this?
Comment: Also I don even have scroll_to_index in my dependencies ;-;
Comment: If above issue still not fixing your problem then you can repair your cache but it will re download all the package are available inn cache, for more about cache clear you can look into this question  - https://stackoverflow.com/questions/55399209/update-flutter-dependencies-in-pub-cache


O Gunicorn não está funcionando, pois está dando o seguinte erro gunicorn.service: Failed with result 'exit-code'. error

Question: Boa noite,
Fiz uma tentativa de deploy do meu site em linguagem Django, mas sem sucesso. Os erros que me surgiram depois estão apresentados abaixo.
Agradeço toda a ajuda, pois já fiz muita pesquisa e várias correções, mas sem resultados positivos.
Após fazer a seguinte checagem:
sudo systemctl status gunicorn.socket
Surge-me o erro abaixo:
<code>Failed to dump process list, ignoring: No such file or directory
● gunicorn.socket - gunicorn socket
   Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset:
enabled)
   Active: active (listening) since Thu 2020-03-12 19:56:45 WET; 1min
 24s ago
   Listen: /run/gunicorn.sock (Stream)
   CGroup: /system.slice/gunicorn.socket

Mar 12 19:56:45 cursopython systemd[1]: Listening on gunicorn socket.
</code>
Após fazer a seguinte checagem
sudo systemctl status gunicorn
Surge o erro abaixo:
<code>● gunicorn.service - gunicorn daemon
   Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset
: enabled)
   Active: failed (Result: exit-code) since Thu 2020-03-12 19:54:59 W
ET; 5min ago
 Main PID: 19701 (code=exited, status=3)

Mar 12 19:54:59 cursopython gunicorn[19701]: django.core.exceptions.ImproperlyCo
nfigured: Error loading MySQLdb module.
Mar 12 19:54:59 cursopython gunicorn[19701]: Did you install mysqlclient?
Mar 12 19:54:59 cursopython gunicorn[19701]: [2020-03-12 19:54:59 +0000] [19727]
 [INFO] Worker exiting (pid: 19727)
Mar 12 19:54:59 cursopython gunicorn[19701]: [2020-03-12 19:54:59 +0000] [19701]
 [INFO] Shutting down: Master
Mar 12 19:54:59 cursopython gunicorn[19701]: [2020-03-12 19:54:59 +0000] [19701]
 [INFO] Reason: Worker failed to boot.
Mar 12 19:54:59 cursopython systemd[1]: gunicorn.service
: Main process exited, code=exited, status=3/NOTIMPLEMENTED
Mar 12 19:54:59 cursopython systemd[1]: gunicorn.service
: Failed with result 'exit-code'.
Mar 12 19:54:59 cursopython systemd[1]: gunicorn.service
: Start request repeated too quickly.
Mar 12 19:54:59 cursopython systemd[1]: gunicorn.service
</code>
Toda a ajuda é bem vinda.
Obrigado.
Answer: Pelo erro que está aparecendo, o sistema está tendo problemas para carregar a biblioteca de conexão com o MySQL. Verifique se você não esqueceu de instalar e se ela está funcionando direitinho.


Im currently trying to create a payment method in android studio ive tried stripe with no luck any ideas

Question:
I have no idea what this error means, I am new to android studio so would welcome some help.
Comment: Welcome to Stack Overflow. Please include the error as *text* inside the question, not as an image. It ensures that the question remains useful even if the URL stops working AND allows people to copy the error text to search for solutions. Also, please see these guidelines for creating helpful questions:
[How to Ask](https://stackoverflow.com/help/how-to-ask). Thanks!
Comment: The easier it is to read and understand your question, the best answers you will get.  That transparent window is terrible for readability.  And do not put images of text here, copy paste it directly.
Answer: You are passing parameters of wrong type to the constructur Card()
The expMonth and expYear are integers in your class Card, not strings


the miracle of 'this' keyword JavaScript

Question: var obj = {};
obj.fn = function() {
    return this;
    }

output: Window object
is the 'this' not pertaning to 'obj' which is the objectof property 'fn'?
but if I make declare like this below...
var obj = {
    fn: function() {
        console.log(this);
       }
    }

output is... Object object
are they not the same?
Comment: How are you executing your first example? Are you doing `obj.fn()` or something else?
Answer: Both your examples shall return the object itself with the console log of this, the window object is logged when reading this in the global scope:
    var obj = {};
    obj.fn = function() {
      console.log(this);
    }

    // logs window
    console.log(this);

    // logs object
    obj.fn();

    var obj1 = {
      fn: function() {
        console.log(this);
      }
    }

    // logs object
    obj1.fn();

this will always take the value of the containing scope


What can make windows fileshares slow without affecting ping latency, remote desktop, cpu usage or disk access?

Question: I've got a server named Babylon. It's running Windows Server 2003 SP2 and lives in the midwest.
I can ping Babylon from remote machines in the same building by hostname and IP. The latency is <20ms.
I can ping Babylon from machines in another state by hostname and IP. The latency is about 200ms.
I can remote into Babylon from machines in the building and other states and it works fine. Low latency, responsive, fast.
Once I've remoted into Babylon, I can copy files locally quickly.
Attempting to connect to a share via UNC (\babylon\projects) and browse the file system is deathly slow. Latency in the dozens of seconds.
Attempting to xcopy a file from one of those shares is deathly slow. Latency in the tens of seconds.
The shares reside on a RAID array. Two 2GB fiber channels for the RAID. I've tried it with other shares on the machine. The network utilization never spikes about 0.5%. The CPU usage never spikes above about 1%.
Any ideas what I should be looking at to understand why remote desktop, ping, and local copies are fast and copies across a file share are slow?
Comment: A ping of <20ms from within the same building isn't fast. It should be 1ms if both Babylon and the remote machines in the same building are on the same LAN.
Comment: Sorry - I'll clarify that. The 20ms ping was with a packet size of 65500 bytes. With the default packet size, it's 1ms.
Answer: What could cause this is the design of the SMB protocol.
SMB requires a lot of acknowledgemenst, in some case between every single operation.  This requirement for lots of acknowledgements means that your latency will kill your performance.  It is block based instead of stream based.
See:

http://blogs.technet.com/b/neilcar/archive/2004/10/26/247903.aspx
http://en.wikipedia.org/wiki/Server_Message_Block#WAN_performance_issues
Comment: Zoredache is correct. SMB/CIFS simply sucks over WAN links.
Comment: Would SMB requests saturate the network link with acknowledgments? Even when the server is totally unloaded, listing a directory takes multiple seconds; the network utilization never even hits 1%.
Answer: When you open the local area connection properties window, what's the value of Speed on the Babylon server?

Can you got to the Device Manager, find your network adapter, go to Properties and make sure that the network adapter's Link Speed & Duplex is set to Auto (or better yet if you know your max speed (eg. 1Gbps) set it to 1Gbps / Full Duplex)?
Have you tried changing to another port on the switch?
Just to be clear: the file copy operations you're trying to do, are between two machines (Babylon & another) on the same LAN, or between Babylon and a remote machine via Internet?
Comment: The copies are between babylon and another machine on the same LAN. (Copies to a machine on the WAN are even slower).
Comment: Too, the network adapter's speed is set at 1Gbps. We've tried changing to another port on the switch, no effect.
Comment: Is your nic's chipset from Broadcom?
Comment: If yes: read http://blog.serverfault.com/post/broadcom-die-mutha/ :-)
Comment: Sadly, we've got Intel NICs in the machine. Amusing story though!
Comment: Maybe Jumbo frames is enabled and your switch doesn't support it? Or the other way round: Jumbo frames is enabled on the switch but not on the NIC? Also try running [TCP Optimizer](http://www.speedguide.net/tcpoptimizer.php) and see if you need to change your MTU setting.
Comment: Try going into the network adapter driver properties and DISABLE "TCP Connection Offload (IPv4)".
Answer: Zoredache answer is correct; and it also means that the network link does not need to be saturated. For some operations (it seems badly buffered I/O) the effective transfer size can even be reduced by a tenfold, compared to normal copy operations.
Imagine a pizza delivery boy that has to drive 15 minutes (latency) to his customer. He has a box that can contain 10 pizza's (bandwidth). But his protocol (SMB) allows to carry only one pizza a time for a client. So if the client orders 5 pizza's, it takes 75 minutes to bring them all.


Gerar chave para acessar documento

Question: Preciso gerar uma chave que contenha letras e números Ex: "AJ67G8". estou gerando com o Random do java.io.Serializable:
public static String nomeAleatorio(int nCaracteres) {
    Random rand = new Random();
    char[] letras = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray();

    StringBuffer sb = new StringBuffer();

    for (int i = 0; i <= nCaracteres; i++) {
        int ch = rand.nextInt(letras.length);
        sb.append(letras[ch]);
    }
    return sb.toString();
}

Essa chave tem que ser única, o problema é que o Ramdom não garante isso e ficar indo ao banco cada vez pra verificar se a chave existe é muito trabalhoso. Qual estratégia usar para resolver esse problema?
Comment: https://pt.stackoverflow.com/search?q=+fisher-yates
Answer: O jeito mais fácil de resolver isso seria com o UUID (Identificador Único Universal) que é representado por valor de 128 bits.
Você pode gerar um com o seguinte trecho de código:
private String geraChaveUnica()
{
    final String idUnico = UUID.randomUUID().toString().replace("-", "");
    return idUnico;
}

Output:
feefa833f1184bd3bfa44272bea74a75

Gerar chave para acessar documento


How do I calculate PERT stddev if I use custom weight factors?

Question: According to (for example) http://tynerblain.com/blog/2006/04/13/foundation-series-basic-pert-estimate-tutorial/, the PERT mean estimate is
$$\text{meanA}=(\text{optimistic}\ +\ 4 \times \text{likely}\ +\ \text{pessimistic})/6$$
I understand I can use "custom" weight factors for the basic estimates. For example, I could say I weight the optimistic estimate by a factor of 2. Then, of course, the divisor would not be 6, but 7:
$$\text{meanB}= (2 \times \text{optimistic}\ +\ 4 \times \text{likely}\ +\ \text{pessimistic})/7$$
Now a PERT estimate includes an approximation of the standard deviation. With the widely used weights of 1:4:1, the stddev is approximately
$$\text{stdevA}=(\text{pessimistic}\ –\ \text{optimistic})/6$$
I am not sure where the 6 comes from, and I think this is my question.
I am wondering about this because if I use the weights from $\text{meanB}$, for example 2:4:1, which divisor would I use for approximating the stddev? Still 6? Or 7?
Comment: This seems to be the only SE site where newbies get downvotes, and don't get hints why, or what they can improve...you feel better now? :-(
Comment: Oh, it's not the only one. I think your last paragraph says that you haven't read the FAQ carefully and you're even aware of that. Also, I think people really prefer the MathJax over what appears to be some kind of psuedocode or something.
Answer: The mean and sd calculations you give are used in PERT three-point estimation.
They might be regarded as based on either assuming particular cases of a
four-parameter beta distribution
or a particular double triangular* distribution, such that the median
and mode coincide.
* The double triangular has a density consisting of two triangles back-to-back (with a discontinuity at the mode). The general case has probability $p$ in the left triangle and $(1-p)$ in the right, but in the particular one discussed above, $p=0.5$
The values given for calculating the mean and sd are based only on the three specified values.  In the case of the double triangular with equal probability in both halves, the given mean is right, but I haven't checked whether the sd estimate makes sense (I believe it's based on a rough approximation).
To derive a suitable sd estimate for your differently weighted average, you'd need some basis on which the weighted average
was a suitable way to approximate the distribution's mean and then obtain a suitable sd estimate from that same basis.
I think you might perhaps be able to choose a different beta or perhaps some other distribution so as to make your weighted mean work and then base an estimate of standard deviation off whichever distribution you ended up with. (No double triangular will produce relative weights of 2,4,1.)
Comment: What's enough to know is "No double triangular will produce relative weights of 2,4,1". Of course. Thanks!
Comment: You could get 2,6,1 though.


Show different forms depending of the user choice

Question: I'm trying to create an html page that contains 2 button one click on one of them it add a form to the page, and if I click on the other button it add another form

document.addEventListener('DOMContentLoaded', function showAppointementForm() {
  document.getElementById("button1").onclick = function() {
    document.getElementById("form").innerHTML = `
        <form action="{% url 'create_appointement_non_register_patient' %}" method="POST">
             {{ form.media }} {{ form.as_p }} {% csrf_token %}

            <button type="submit" value="create_appointement_non_register_patient">
                ok
            </button>
        </form>
    `
  }

  document.getElementById("button2").onclick = function() {
    document.getElementById("form").innerHTML = `
        <form action="{% url 'create_appointement_register_patient' %}" method="POST">

                select a patient
                <select name="patients" id="patients">
                <option value="">-- select a patient --</option>
                {% for patient in patients %}
                <option value="{{patient}}">{{patient}}</option>
                {%empty%}
                <option value="nothing">nothing</option>
                {% endfor %}
            </select>

 {{ form.media }} {{ form.as_p }} {% csrf_token %}

            <button type="submit" value="create_appointement_register_patient">
                ok
            </button>
        </form>

    `
  }
})

      <button name="type" class="button1" id="button1">register patient</button>
      <button name="type" class="button2" id="button2">non register patient</button>

is something wrong with my code in js file or is there another way to do it?
This the view that work with the 2 form in the 2 button in the views.py
@login_required
def create_appointement_register_patient(request):
    if request.user.is_doctor() or request.user.is_reception():
        form_app = AppointmentForm_2(request.POST or None)
        user2 = get_user_model()
        patients = user2.objects.filter(type_of_user=TypeOfUser.PATIENT)
        if request.method=='POST':
            form_app = AppointmentForm_2(request.POST or None)
            if form_app.is_valid():
                form_apps = form_app.save(commit=False)
                form_apps.user_ho_add = request.user

                start_time = form_apps.start_time
                future_time = dt.datetime(1970, 1, 1, start_time.hour, start_time.minute, start_time.second, start_time.microsecond) + timedelta(minutes=30)
                form_apps.end_time = dt.time(future_time.hour, future_time.minute, future_time.second, future_time.microsecond)
                form_apps.patient = request.POST['patients']
                if Appointment.objects.filter(patient=request.POST['patients']).exists():
                    form_apps.save()
                    messages.success(request, 'appointment added')
                else:
                    raise ValidationError('patient does not Exist')
            else:
                messages.error(request, 'Error')

            return render(request,'appointement/add_appointement2.html',{'form':form_app, 'patients':patients})
        else:
            return render(request,'appointement/add_appointement2.html',{'form':form_app, 'patients':patients})
    else:
        return HttpResponseRedirect(reverse("create_appointement"))

@login_required
def create_appointement_non_register_patient(request):
    if request.user.is_doctor() or request.user.is_reception():
        form_app = AppointmentForm_3(request.POST or None)
        user2 = get_user_model()
        patients = user2.objects.filter(type_of_user=TypeOfUser.PATIENT)
        if request.method=='POST':
            form_app = AppointmentForm_3(request.POST or None)
            if form_app.is_valid():
                form_apps = form_app.save(commit=False)
                form_apps.user_ho_add = request.user

                start_time = form_apps.start_time
                future_time = dt.datetime(1970, 1, 1, start_time.hour, start_time.minute, start_time.second, start_time.microsecond) + timedelta(minutes=30)
                form_apps.end_time = dt.time(future_time.hour, future_time.minute, future_time.second, future_time.microsecond)
                form_apps.save()
                messages.success(request, 'appointment added')
            else:
                messages.error(request, 'Error')

            return render(request,'appointement/add_appointement3.html',{'form':form_app, 'patients':patients})
        else:
            return render(request,'appointement/add_appointement3.html',{'form':form_app, 'patients':patients})
    else:
        return HttpResponseRedirect(reverse("create_appointement"))

Answer: it is possible to use render or render_to_string in django-side of the code.
as you showing the base for first time, but at this time you're using ajax so take an advantage of ajax, the success method. e.g:
    $.ajax({
            url: url,
            type: 'GET',

            success: function (res) {
                $('#gmodalContent').html(res);
            },

            error: function (er) {
                console.log(er);
            },
        });

I used html() but there are also append(), prepend() and other methods available out there in js.

the res is referring to the response from django side which is provided using render or render_to_string.
Comment: it seems the html code is not good. because you already put the buttons inside a form. take them out and drop that initial form. also the buttons are typed `submit` which by default tells the browser when each of them clicked submit the form and after that you're js code won't work at all.
Comment: my problem is in the javascripts code that did not work not in the django side of the code, is the js code good dose it work ???
Comment: I change that in my VS code, but it did not work, but when I edit the code in here (in the question) it works when I click on the button it show me the form, I added the function in Django if you can see where the error is that will be great
Answer: Unless you are passing the javascript source through the template processor, and I don't see any indication you do, you are just simply adding verbatim the code to the page. Instead put all the forms in the template hidden with display:none and make the button unhide them.
The best implementation is to create a route for each form, so that the user is presented with the form of their selection.
Comment: @houhou unless that's part of the assignment (in which case, I believe you are wasting your time), you are the one that decide how to achieve it. It's less painful to do it how I'm suggesting.
Comment: Yes, I'm aware of this method but I want to make the html page show nothing unless I click the button that way id did not interfere with the Django side, is there a way to make it possible by using the innerhtml method in js
Comment: @houhou you are already modifying served files, why not modify the application to do what you want. Modify the template and include both forms if you don't want a roundtrip when the user press the button. In fact, you have already two functions to handle each route. Create two routes on the urls, each one handled by each function and with their own template. Doing it any other way, is making it more complicated than in needs to.
Comment: this is a cs 50 final project i need to do it with javascripts and django, i want to make it work like this and after that i will add a popup small html that contait the form with javascripts, but know like this ( the simpleset way it did not work )


Análise de Expressão Gênica utilizando datasets do Gene Expression Omnibus (R)

Question: Eu sei que a proteína que procuro está nesse dataset, porém não estou conseguindo filtrar ela em meu código para fazer uma análise de expressão gênica nesse dataset em específico.
library(GEOquery)
gse <- getGEO("GSE8671")

if (length(gse) > 1) idx <- grep("GPL570", attr(gse, "names")) else idx <- 1
gse <- gse[[idx]]

ex <- exprs(gse)
pData(gse)
fData(gse)

summary(exprs(gse))
features <- fData(gse)
View(features)
library(dplyr)
features <- select(features, "Gene Symbol", "ID", "ENTREZ_GENE_ID")

"201482_at" %in% colnames(ex)
qsox1_index <- grep("^201482_at", colnames(exprs(gse)))
qsox1_exprs <- exprs(gse)[, qsox1_index]

Por enquanto estou fazendo somente para a proteína QSOX1 (ID 201482_at) mas gostaria de ampliar minha busca com outra proteína de controle para verificar sua expressão.
Answer: As expressões gênicas estão no objeto ex. Entretanto, ele é uma matriz, e o nome de cada gene está no nome da linha dessa matriz. Dessa forma, recomendo como boa prática, transformar essa matriz em uma tibble e criar uma nova coluna chamada ID:
library(dplyr)

ex <- ex |>
  as_tibble() |>
  mutate(ID = rownames(ex)) |>
  relocate(ID)

A função relocate é usada apenas para deixar a coluna ID no primeiro lugar do data frame. Seu uso é opcional.
Com isso feito, basta filtrar o nome ex pela ID da proteína desejada:
ex |>
  filter(ID == "201482_at")
#> # A tibble: 1 × 65
#>   ID       GSM215051 GSM215052 GSM215053 GSM215054 GSM215055 GSM215056 GSM215057
#>   <chr>        <dbl>     <dbl>     <dbl>     <dbl>     <dbl>     <dbl>     <dbl>
#> 1 201482_…     1370.     1998.     1661.     1939.     1387.     1588.     1972.
#> # ℹ 57 more variables: GSM215058 <dbl>, GSM215059 <dbl>, GSM215060 <dbl>,
#> #   GSM215061 <dbl>, GSM215062 <dbl>, GSM215063 <dbl>, GSM215064 <dbl>,
#> #   GSM215065 <dbl>, GSM215066 <dbl>, GSM215067 <dbl>, GSM215068 <dbl>,
#> #   GSM215069 <dbl>, GSM215070 <dbl>, GSM215071 <dbl>, GSM215072 <dbl>,
#> #   GSM215073 <dbl>, GSM215074 <dbl>, GSM215075 <dbl>, GSM215076 <dbl>,
#> #   GSM215077 <dbl>, GSM215078 <dbl>, GSM215079 <dbl>, GSM215080 <dbl>,
#> #   GSM215081 <dbl>, GSM215082 <dbl>, GSM215083 <dbl>, GSM215084 <dbl>, …

Created on 2023-04-04 with reprex v2.0.2
Comment: Muito obrigada pela ajuda! Mas nesse caso como conseguiria ver esses valores em forma de grafico?


How do I separately get label and field?

Question: For form fields, we have label and field (Text/Select/...).
How do I get the field title and its value separately in a template file?
<code>{{ form.title }}
</code>
I need both separately, so I can properly style.
Comment: label `form.title['#title']` value `form.title.0` **Note:** this will only get the first value, if it's a multi-value field you need to loop.
Comment: Thanks @NoSssweat In this way will get title. But how to get field separately as well
Comment: did you try `form.title.0` ?
Answer: To access separately labels and values for fields in twig template (example in node twig template: node.html.twig) I propose to loop all the node variable.
My example:
Instead of print all content with this line {{ content }} loop the content object
<code>    {% for item in node %}
        {# Print the label of the field #}
        {{ item.fieldDefinition.label }}

        {# Print the value of a field text/simple field #}
        {{ item.fieldDefinition.value }}

        {# Print the value of a field reference  #}
        {{ item.value[0]['target_id'] }}
    {% endfor %}
</code>
Other way is to use this module: https://www.drupal.org/project/twig_field_value


OS X NFS Automount: "locallocks" ignored?

Question: I'm having an issue with file-locking and auto mounting on OS X.
Here is my auto_master file:
#
# Automounter master map
#
+auto_master        # Use directory service
/net            -hosts      -nobrowse,hidefromfinder,nosuid
/home           auto_home   -nobrowse,hidefromfinder
/Network/Servers    -fstab
/-          -static
/- /etc/auto_nfs

And here is auto_nfs:
# Common Configuration

/Shared/Family          -fstype=nfs,rw,nodev,nosuid,nfc,locallocks nfs://10.0.0.11/Volumes/PDISK3/VDISKS/General1/Groups/Family\ Shared
/Shared/Users/christopher   -fstype=nfs,rw,nodev,nosuid,nfc,locallocks nfs://10.0.0.11/Volumes/PDISK3/VDISKS/General1/Users/christopher
/Shared/Scratch1        -fstype=nfs,rw,nodev,nosuid,nfc,locallocks nfs://10.0.0.11/Volumes/PDISK2/VDISKS/Scratch1

# END Common Configuration

It appears as though locallocks is ignored (the mount command doesn't show it and chflags fails and Finder's info window has a greyed-out Locked box). I've tried all combinations (e.g. nolocks, nolocks,locallocks, etc) to no avail.
While I'm OK with not having locks in general on the NFS side, having the lack of even a facade of locks is causing OS X to go insane if I try to have home directories on the NFS mount.
So: how do I get locks (or even a facade of locks) to work on an NFS share?
Misc details:
The server is an NFS4 server on Linux Mint with exports like this:
/Volumes/PDISK2 10.0.0.2(rw,async,no_subtree_check,insecure,no_root_squash) 10.0.0.3(rw,async,no_subtree_check,insecure,no_root_squash) 10.0.0.0/16(rw,async,no_subtree_check,insecure)
/Volumes/PDISK3 10.0.0.2(rw,async,no_subtree_check,insecure,no_root_squash) 10.0.0.3(rw,async,no_subtree_check,insecure,no_root_squash) 10.0.0.0/16(rw,async,no_subtree_check,insecure)
/Volumes/PDISK4 10.0.0.2(rw,async,no_subtree_check,insecure,no_root_squash) 10.0.0.3(rw,async,no_subtree_check,insecure,no_root_squash) 10.0.0.0/16(rw,async,no_subtree_check,insecure)

(Note: this computer is not one of the computers given root access and will remain that way).
If I set no_auth_rlm on the server, the Locked checkbox is no longer greyed out in the Finder but it won't let me check it (it unchecks itself). If I do this: touch a ; chflags uchg a on one of the mounts, I get:
chflags: a: Operation not supported

Interestingly, chflags nouchg a works, but still doesn't allow chflags uchg a afterwards. Note that it also doesn't work as root from one of the computer given root access.
The accounts are all from an OS X El Capitan Open Directory server. Yes, it is set up correctly (I can absolutely access/write/edit/etc everything, with the exception what what's apparently an OS X bug w.r.t deleting directories from the Finder).
This is cross-posted because there are two main groups who may have come across this: SysAdmins who have integrated OS X into directory groups (hence ServerFault) and OS-X enthusiasts who have tried to do the same thing personally or for a small business and had issues (hence Think Different).
More information, provided by "Heinrich":
This is not really an auto mount problem. Is seems that the mount(8), or mount_nfs(8) program simply ignores most options:
> mount_nfs -o lock,rsize=65535 newserver:/Volumes/Newdata/kits /mnt

> mount|grep /mnt

newserver:/Volumes/Newdata/kits on /mnt (nfs)

> umount /mnt

> mount_nfs -o lock,nodev newserver:/Volumes/Newdata/kits /mnt

> mount|grep /mnt

newserver:/Volumes/Newdata/kits on /mnt (nfs, nodev)

"nodev" is honored, but everything else seems to be ignored.
Answer: It seems that mount options aren't actually ignored, it's just that mount does not show them. nfsstat -m shows the NFS parameters given and the actual mount options currently in use for each mount.
locallocks in particular does have an effect: In my setup (macOS Sierra with NFS mounts from a Linux server), the Photos app initially didn't work with its library on the NFS mount (it just hung on start). Only after setting locallocks the Photos app could be used.
Answer: In my experience, locallocks is ignored (or at least not properly working) on OSX for NFSv4. Use nfsvers=3 as mount option.


Show that $\dfrac{\partial}{\partial x_i} f[x_0,x_1,\dots,x_n]=f[x_0,x_1,\dots,x_i,x_i,x_{i+1},\dots,x_n].$

Question: Let $x_0<x_1<\cdots<x_n$, and let $f$ be continuously differentiable. Show that $$\dfrac{\partial}{\partial x_i} f[x_0,x_1,\dots,x_n]=f[x_0,x_1,\dots,x_i,x_i,x_{i+1},\dots,x_n].$$
At first, I thought this question can be done by induction on $n$ but after attempting it, I got something weird.
Next, I tried using $$f[x_0,,x_1,\dots,x_n]=\sum_{i=0}^n f(x_i) \prod_{\substack{j=0 \\ j\neq i}}^n (x_i-x_j)^{-1}$$
 But when you take the derivative of this equation. I will obtain a double sum because of the product rule.
Can someone help me get started on this question?
Comment: How does your book define the notation $f[x_0,x_1,\dots,x_n]$?
Comment: https://en.wikipedia.org/wiki/Divided_differences
Answer: It is a matter of definitions. When arguments are distinct you have by the
very definition of the divided differences, and using permutation symmetry of the objects: $$ f[x_0,...,x_{i-1},u,v,x_{i+1},..,x_n] =
    \frac{ f[x_0,...x_{i-1},u,x_{i+1}...,x_n] - f[x_0,...,x_{i-1},v,x_{i+1}...,x_n]}
{u-v}$$
The case when arguments are equal are defined by taking limits (not described in the wiki page as far as I can see). Your function has to be differentiable in that case. As an example:
$$ f'(x_0) =  \lim_{x_1\rightarrow x_0} \frac{f(x_1)-f(x_0)}{x_1-x_0} =
 \lim_{x_1\rightarrow x_0} f[x_0,x_1]=:f[x_0,x_0]$$
In your case:
$$ f[x_0,...,x_i,x_i,...,x_n] = \lim_{\epsilon\rightarrow 0^+}
  { f[x_0,...,x_i,x_i+\epsilon,...,x_n]} $$
Using the first part we may rewrite as:
$$
\lim_{\epsilon\rightarrow 0^+}
  \frac{ f[x_0,...x_{i-1},x_i+\epsilon,x_{i+1}...,x_n] - f[x_0,...,x_{i-1},x_i,x_{i+1}...,x_n]}
{(x_i+\epsilon) -x_i}  $$
which equals the wanted partial derivative (assuming it exists).
Answer: There is something wrong. Some derivatives of $f$ should appear.
$$f[x_0,x_1]=\frac{f(x_0)}{x_0-x_1}+\frac{f(x_1)}{x_1-x_0}$$ and
so
$$\frac{\partial f[x_0,x_1]}{\partial x_1}=\frac{f(x_0)}{(x_0-x_1)^2}+\frac{f'(x_1)}{x_1-x_0}-\frac{f(x_1)}{(x_0-x_1)^2}.$$
The term $f'(x_1)$ cannot disappear.


How do you allow a role to assign other users roles - but only specific roles?

Question: I'm creating a "level'ing" role system on my page. At a certain role (Full Member) the user must be able to assign someone with the role level 5 the new role level 6 manually once a dialogue is complete.
How can you do this?
Answer: I think Role Delegation is what you're looking for.

For each role, Role Delegation provides a new assign ROLE role
  permission to allow the assignment of that role.


Facebook login in android app: what should I save in the database to know this user is logged in at the future?

Question: I used facebook login button that fetches the public profile and saves the email address in the database for the user, next time if the user logged out and logged in again, I search his email in the database. This method doesn't seem good because if the user was logged in and left the app, then opened it with no internet connection, the session is opened but without fetching the user public profile again, so he is logged in using facebook but I'm unable to know who he is! because I'm not being receiving any data of the user on this login!
So I thought maybe I should store the AccessTokens on session open, but I'm not sure if this is the right way to go, and I don't know if this tokens identify the user or the app or the session or what! and I read that it could be null, so when can I securely use them if I'm supposed to?
Answer: If you use the newest SDK 4.0.1. The Profile is also saved, so you can see who's logged in by looking at Profile.getCurrentProfile(). Also you can get the current user id on the current access token.
The access token is the secret that's used to make graph calls. It is unique, if you store it with the user e-mail, you can use it to associate back to the e-mail.


Criar uma nova variável em um dataframe a partir da condição de uma variável já existente

Question: Estou estudando python e pandas com um banco de dados no qual eu tenho as seguintes variáveis para a idade:
NU_IDADE_N = Correspondente ao número da idade
&
TP_IDADE = Correspondente ao tipo da idade, sendo:
1 - dias
2 - meses
3 - anos

NU_IDADE_N
TP_IDADE

19
3

21
2

56
1

12
3

Eu gostaria de criar uma terceira variável, 'IDADEANOS', na qual se TP_IDADE != de 3 então IDADEANOS = 0
A idéia que eu tive era da seguinte forma:
dados["IDADEANOS"] = dados["NU_IDADE_N"]

if dados["TP_IDADE"] != 3:
    dados["IDADEANOS"] ==0

Obviamente não funcionou e apesar de ser algo bem simples eu não encontrei nada na documentação que me auxilie com essa situação especificamente.
Então se alguém tiver uma solução serei muito grato.
Desde já agradeço pela atenção.
Comment: Na linha abaixo do `if dados["TP_IDADE"] != 3:` não deveria ser `dados["IDADEANOS"] = 0`? Da forma atual está fazendo uma comparação e não uma atribuição.
Answer: para este caso você pode utilizar o numpy para auxiliar na sua condicional

import pandas
import numpy as np

obj = [
{"NU_IDADE_N": 19,"TP_IDADE": 3},
{"NU_IDADE_N": 21,"TP_IDADE": 2},
{"NU_IDADE_N": 56,"TP_IDADE": 1},
{"NU_IDADE_N": 12,"TP_IDADE": 3}
]

df = pandas.DataFrame(obj)

df['IDADEANOS'] = np.where(df['TP_IDADE']!=3, 0, df['NU_IDADE_N'])
df.head()

#output
NU_IDADE_N  TP_IDADE    IDADEANOS
19             3           19
21             2            0
56             1            0
12             3           12

Answer: Crie um função que descreva a lógica que você quer aplicar para cada uma das linhas do seu dataframe:
def func(linha):
    if linha['TP_IDADE'] != 3:
        return 0
    else:
        return linha['NU_IDADE_N']

Depois, use df.apply para aplicar essa função a elementos do seu dataframe, passando também o argumento axis=1 para determinar que a função deve ser aplicada linha-a-linha:
import pandas as pd

df = pd.DataFrame({
    'NU_IDADE_N': [19, 21, 56, 12],
    'TP_IDADE': [3, 2, 1, 3],
})

df['IDADEANOS'] = df.apply(func, axis=1)
print(df)

output:
   NU_IDADE_N  TP_IDADE  IDADEANOS
0          19         3         19
1          21         2          0
2          56         1          0
3          12         3         12


Thumbnail generation with nginx reverse proxy

Question: I'm using nginx as a reverse proxy for a Drupal 7 site running on Apache2.
When I try to view a thumbnail I get the Drupal 404 page saying that the location is not found.
I have implemented the location rules to rewrite requests to the thumbnail to index.php and the error message includes this rewritten request.
These are my nginx location blocks:
location @rewrite {
    rewrite ^/(.*)$ /index.php?q=$1 last;
}

location ~ ^/sites/.*/files/styles/ {
    try_files $uri @rewrite;
}

# Try to serve files with Nginx if possible
location / {
     try_files $uri @proxy;
}

# Pass on php to Apache
location ~* \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    proxy_pass http://127.0.0.1:8000;
    include /etc/nginx/proxy_params;
}

location @proxy {
    proxy_pass              http://127.0.0.1:8000;
    include /etc/nginx/proxy_params;
}

The url of a thumbnail looks like this:
http://example.com/sites/default/files/styles/thumbnail/public/pictures/picture-1-1437996028.jpg?itok=19uLP_Ax

The error message displayed is:
The requested page "/index.php?q=sites/default/files/styles/thumbnail/public/pictures/picture-1-1437996028.jpg&itok=19uLP_Ax" could not be found.

I have tried setting the flag to allow insecure content generation (without a token) to test with.  Obviously I've removed that flag.
Answer: that is similar to me, i added this line in my nginx vhost config,
location ~* /sites/default/files/styles/ {
    if (!-e $request_filename) {
    rewrite  ^/(.*)$  /index.php?q=$1  last;
    break;
    }
}

you need to reload to make the image display, hope someone can improve my answer


Commucation Between C++ Client and Java Server

Question: I'm developing a Client application which talks to a Server using HTTP. The Client is in C++ and the Server component is in J2EE. I'm able to exchange data between Client and Server successfully. Now I want to encapsulate pices of information in a C++ object in client and send it in the HTTP request to server. My server after receiving the data should deserialize the C++ object to a java object.
My question is, I want to know whether we can exchange an object in the above mentioned way and if it can be achieved, could someone help me by providing references to online tutorials or code sample?
Comment: why not just use json or something easier?  I don't think what you are asking can be done. see http://stackoverflow.com/questions/4457615/how-to-convert-a-java-object-into-a-c-object
Comment: Actually on my Server side I want it as a Java object, can I convert the received JSON object on Server to Java Class Object?
Comment: you sure can, use a json library like http://jackson.codehaus.org/
Comment: Thank You @user2310289.. Will try it and post the comments...
Answer: You need to serialize the object into XML, JSON or something like that.
You can't use technology-specific serialization (e.g. RMI for java) because you are working cross stack (and it's bad practice anyway).
Don't know about c++ but in java binding objects to XML/JSON is trivial using JAXB. If you are exposing a webservice you can go the easy way: REST (using JAX-RS) or the slightly harder but technically better way (in that it has more features): SOAP (using JAX-WS).
Exposing such webservices is trivial in Java EE if you read up on the relevant webservice stacks.
Answer: It would be a nightmare if you send plain old C++ objects to the Server. You need to have a common protocol between client and server. A good option for this is JSON. The flow would be like this:
C++ object -> serialize to -> JSON -> deserialize to -> Java object
To serialize C++ objects into JSON using something like JSON Spirit. To deserialize the JSON into Java objects, Gson is a safe bet (it even does the conversion on-the-fly). You can find documentation for both projects on their respective homepages.


How do I define a pointer to a function in C and assign that pointer to a function?

Question: I am trying to define a pointer to a function in C then assign that pointer to a function.  All of the examples I have found are for functions with parameters and returns, but my function has neither.
Everything I have tried with the MPLAB XC8 compiler cause either 'main.c:39:9: error: initializing 'void (*)()' with an expression of incompatible type 'void'' or 'main.c:39:18: error: expression is not assignable' errors.
scan_KP() is a keypad scan function
This is my declaration for the pointer:
void (*KP_ScanPTR)(void);

Now I want the address of the function scan_KP assigned to the pointer; this is what I have tried:
(*KP_ScanPTR)() = scan_KP();

void (*KP_ScanPTR)() = scan_KP();

void (*KP_ScanPTR)(void) = scan_KP();

This one causes 'main.c:39:28: error: expected expression' but I didn't expect it to work anyway:
(*KP_ScanPTR)() = scan_KP(void);

I also tried this.  Interestingly I get: main.c:39:8: error: initializing 'int (*)()' with an expression of incompatible type 'void'.  So I think the declaration is correct since it knows there are no parameters and no return from scan_KP();:
int (*KP_ScanPTR)() = scan_KP();

This is the code example I was using as reference:
#include<stdio.h>
int subtraction (int a, int b) {
   return a-b;
}
int main() {
   int (*fp) (int, int)=subtraction;
   //Calling function using function pointer
   int result = fp(5, 4);
   printf(" Using function pointer we get the result: %d",result);
   return 0;
}

I have also reviewed this question A pointer to a function and this Returning a pointer to a function The second shows a similar syntax
int funcA(int a, int b) { ... }
int (*funcB)(int, int) = funcA;

so I removed the parameters and return, but it does not.
So what am I doing wrong here?
Comment: When you write `scan_KP()` you are calling that function, not getting its address.
Answer: The parentheses in scan_KP() cause your function to be called, rather than its address taken. The result is an expression whose type is void — I'm not sure that counts as an expression at all, and it's definitely not the right type for assigning to a function pointer.
Just omit the parentheses, consistently with the two examples you quoted:
void (*KP_ScanPTR)(void) = scan_KP;

You can also add the address-of operator &:
void (*KP_ScanPTR)(void) = &scan_KP;

For the compiler this makes no difference, but for the human reader it makes it clearer that the function's address is being taken.


MAC Layer Retransmissions during the same TXOP

Question: Back in the day I was messing around with MadWifi and, if I remember properly, after a packet was transmitted if the sender did not receive an ACK in SIFS time after the completion of the transmission, the sender would attempt a retransmission using the same or lower rate (multi rate retransmissions) without going into the backoff/contention phase.
I spent some time going through the 802.11-2012 protocol trying to find relevant information without any luck. Is anyone familiar with that concept? Does this happen in newer drivers like ath5k and ath9k? Is this what the protocol implies?
Any pointers/suggestions are greatly appreciated.
Thanks!
Answer: So, madwifi/freebsd had a TXOP burst mode where even best-effort traffic had a TXOP burst if it wasn't otherwise busy. So, it could do a retry without DIFS+CW, like any other 802.11 burst inside a TXOP.
ath9k doesn't do that by default, but freebsd still does. It's easy to do; mac80211 just needs to grow the "aggressive mode" burst things so the best effort queue gets a TXOP window if nothing else is active.
Here:
https://wiki.freebsd.org/WifiAggressiveMode
-adrian


To declare a inner struct consist of reference to the outer struct

Question:
Possible Duplicate:
Circular definition in C

typedef struct{
  node *next;
  node *last;
} doubleLink;

typedef struct{
 doubleLink doubleLink;
 int data;
} node;

The above is a doomed attempt to define an object with a double link.
Placing either typedef before the other would draw a compilation error of "unknown type"
One obvious recourse is to change the pointer type specifier in doubleLink to void *
But I wonder whether there are more "harmless" solutions, say, maybe
I can declare the node struct without defining it?
I'm cognizant that this must be a frequently asked question,  but I don't know by what keyword can I possibly find it.
Comment: search for "forward declaration"
Answer: Add forward declacation of node:
struct node;
typedef struct{
  struct node *next;
  struct node *last;
} doubleLink;

As you use pointers, you don't need to have this type completely defined before the definition of doubleLink.


Find combinations of two digits

Question: I am in a puzzle that which is generated by one of my friend .
She gave me last 4 numbers of her mobile phone & i want to find the first 6 numbers.
I guessed the first 4 letters.
Assume that AAAA is the first 4 letters and MMMM is the last 4 letters and XX is the 2 letters after the first 4 letters .
So her number is 10 digit soit would be AAAAXXMMMM
I know AAAA and MMMM and now i have to find XX .
I know getting the exact value is impossible but i think that i can get the combinations of XX [2 digits].
How can i get this ?
Thank you.
Answer: You should apply formula of permutations with repetition .
So , number of permutations in this particular case is given by :
$N=10^2$
Comment: @DileepDil,You can only calculate number of possible solutions which is $100$
Comment: @DileepDil,Then write them all..$00,01,02...$ , etc .
Comment: ok how can i calculate this ?
Comment: yeah,i am really poor in maths..i need the combinations...not 100.
Comment: Pardon me if i am making some troubles,but is there any calculator or something that which i can generate those numbers ?

Find combinations of two digits


Teclado bugando imagem no android [IONIC 2]

Question: estou com o seguinte problema:

Como podem ver na imagem acima, quando eu clico para escrever nos campos de login e senha, aparece esse fundo branco na imagem.
Imagino que o problema esteja relacionado com o teclado do android, já que no IOS funciona normalmente e não aparece nada de anormal.
Alguém já viu esse erro antes? Tem ideia do que pode ser?
Answer: Insira esse CSS na pagina em que isso esta acontecendo:

.scroll-content {
      padding-bottom: 0 !important;
   }


matlab neural network strange simulation performance

Question: I am not quite sure if this is the right place for a question like this, but asking anyway.
Having <14x10 double> input matrix (manually normalized) and <5x10 double> output matrix (manually normalized), after a long session of training and comparing performances (the less the better) for different functions, I have finally created five neural networks with the following sets of MATLAB functions:

1 newcf  trainlm initnw mse  learngd  satlin
2 newcf  trainlm initnw msne learngdm compet
3 newelm trainlm initwb mse  learnhd  purelin
4 newff  trainlm initnw mse  learngd  purelin
5 newff  trainlm initnw mse  learnwh  tansig

The best performance results (perf) for each one of them vary from xxxE-30 to xxxE-32.
But still, after running simulation of those networks for each single column of the input matrix, I got the expected output results in just 60% of the cases, while the other 40% are totally wrong.
I have exactly the same 60%/40% relationship between good and bad simulation results for all the above networks, with different bad columns per net.
Can something like this happen? What do you think could be wrong? Maybe the perf result when training is not enough to judge when a neural network is good enough? Maybe I didn't understand something well in the concepts?
Thank you in advance.
[edit 26/04/2013]
The approximate code I am using :
inp = {
0,1300  0,0300  0,0300  0,0300  -0,0100 0,0300  0,0900  0,0100  0,0600  0,0700;
0,0500  -0,0400 -0,0400 -0,0400 -0,0100 0,0100  0,1400  0,0900  0,0600  -0,1700;
0,2400  0,2200  0,2200  0,2200  0,3700  0,3000  0,5300  0,3400  0,1400  -0,6700;
.......
}

outp={
0,0427  -0,1071 0,0605  -0,0637 -0,0410 0,2566  -0,0551 -0,0902 -0,2483 0,1543;
-0,0249 0,0192  -0,1199 -0,3748 0,3212  0,5490  -0,1655 -0,1213 -1,0236 0,4678;
.......
}

[out_r, out_c] = size(cell2mat(outp));
[inp_r, inp_c] = size(cell2mat(inp));

%------------ for 2 layers:

biasConnect = [1;1];
inputConnect = [1; 0];
layerConnect = [0 0; 1 0];
outputConnect = [0 1];

%-------------or for 3 layers:

% biasConnect = [1;1;1];
% inputConnect = [1; 0; 0];
% layerConnect = [0 0 0; 1 0 0; 0 1 0];
% outputConnect = [0 0 1];

my_net = network(1, 2, biasConnect,inputConnect,layerConnect,outputConnect);    %create neural network

my_net.inputs{1}.size = inp_r;      % set the number of elements in an input vector
my_net.outputs{1}.size = out_r;     % set the number of elements in an output vector

my_net = newff(inp, outp, [inp_r out_r]);  % Create feed-forward backpropagation network

% or for 3 layers: my_net = newff(inp, outp, [inp_r round(inp_r/2) out_r]);

my_net.layers{1}.size = inp_r;                % 1st layer size
my_net.layers{1}.transferFcn = 'purelin';     % transfer function
my_net.layers{1}.initFcn = 'initnw';

% ---- Functions ----------------------------------%/
my_net.divideFcn = 'divideblock';
my_net.plotFcns = {'plotperform','plottrainstate'};
my_net.initFcn ='initlay';      % Layer init function
my_net.performFcn = 'mse';      % performing function
my_net.trainFcn = 'trainlm';    % training function
my_net.adaptFcn = 'learngd';    % should be from list: learngdm, learngd

% ---- set a few traininig params and train the net

my_net.trainParam.epochs = 100;
my_net.trainParam.goal = 1.0000e-030;
my_net.trainParam.max_fail = 3;
my_net.trainParam.mu = 1.0000e-03;

my_net.trainParam.mu_inc = 10;
my_net.trainParam.mu_dec = 0.1000;
my_net.trainParam.mu_max = 1e10;

my_net.trainParam.showWindow = false;
my_net.trainParam.showCommandLine = false;
my_net.trainParam.show = 0;

[my_net,tr] = train(my_net,inp,outp); % train the network

% ---- After all when the best my_net is found, I perform simulation for each column:

Y = sim(my_net, inp{:,i}); % for each i-column of the inp matrix and expect y=outp{:,i}

Answer: It is not very clear from the question exactly what has been done, but I suspect the problem is that there just is not enough data (10 patterns) to train a useful neural network to do anything meaningfully.  The errors are very low, which suggests that the neural network has essentially memorised the training data, which is likely to result in severe over-fitting.
Unless more data is available, I would advise using something like ridge regression, rather than neural networks.
What exactly is meant by "But still, after running simulation of those networks for each single column of the input matrix"?  If you could write a MATLAB script that shows what you are trying to do, that would make it much easier to find the problem.
Comment: Thank you very much for you answer! Indeed no more data is available but neural network as a statistical method is preferable in my case for other reasons … Therefore, I tested (automatically) all possible combinations of train/transfer/adapt functions trying to find an appropriate combination with the lowest possible performance value (perf). Should I include a few more criteria for the determination of the best result (except for perf value)? If yes, then what other criteria could be used? If no, then how can I avoid that over-fitting while still using neural networks? Thank you
Comment: Regarding the simulation, please refer to the code I attached in the edited question above - I try to compare the output of the simulation with the output data I trained my network with.
Shouldn't I expect to have the simulation output be approximately equal to my output data, for the same inputs as the input data? - even in case neural network just memorized these values. I am asking because I suspect that I do some other folly mistake in my thinking. Thank you again
Comment: can you explain the "other reasons" for which a neural net is preferable.  As you have more attributes than training patterns a linear model will be able to learn the data with zero error, so it is hard to see why a neural network should be expected to do better.
Comment: I've not really used the neural network toolbox (NETLAB, which is freely available from Aston University is a *much* better toolbox), but it looks to me as if you are using the newff incorrectly, the first parameter should be an n by 2 array of minimum and maximum values for each feature, and the second an array of the dimensions for each layer, whereas you have passed in the input and response variables.
Comment: They can also perturb the training images by slight elastic transforms, subsampling/resampling, etcetera.


read and filter a .DAT file with different column amount in R

Question: I have a .dat file with measurements. Some of these data are "broken". The rows where the broken data are should be skipped. The rows with the broken data have either a column amount over 6 or under 6. However I only need the rows with 6 columns.
So I tried to read the file Daten2.DAT in R with data.table. (see Image)
Does someone know how I can skip the rows not equal with a column amount of 6.
Comment: I've removed the Stata tag. I've nothing against Stata, quite the contrary, but tagging Stata and not even mentioning it, is just a distraction.
Answer: Instead of reading the data with data.table::fread, read it in with readLines, split the lines by comma and then parse the lines.
ncols <- 6
y <- readLines(con = "Daten2.DAT")
y <- strsplit(y, ",")
y <- lapply(y, function(line_read){
  if(length(line_read) != ncols) NULL else line_read
})
y <- y[!sapply(y, is.null)]
df1 <- do.call(rbind.data.frame, y)
names(df1) <- paste0("Col", seq_len(ncols))

This assumes that there is no first line with column headers in the file.


string to md5 hash in class using FILTER_SANITIZE_STRING

Question: Question: Why don't these match on output?
So I have been tracking down an issue that is causing me a lot of headache I can't figure out what is causing issues with passing a shortened version of MD5 hash that is sanatized with FILTER_SANITIZE_STRING
I know it seems strange that I sanitize a md5 hash but this class is not only used in this manner and I am trying to avoid making multiple methods to do the same thing.
<code>class test {
public function select($match,$debug) {
        $match1 = filter_var($match, FILTER_SANITIZE_STRING);
        if ($debug == '1') {
            var_dump($match,$match1);
        }

}
}

$title = "April 2013"; // Example Title
$currentHUID = substr(md5($title), 0, 12); // Convert string to UID not for encryption just comparison first 12 char of MD5 Hash

$test = new test();
$test->select("'$currentHUID'",'1');
</code>

RESULTS: string(14) "'8860d4398c9b'" string(22) "'8860d4398c9b'"
Comment: its the quotes - see my example here:http://codepad.viper-7.com/JvMkD5
Comment: So, what was the real question?
Comment: 14 character string reads 22 chars... That's not weird to you?
Comment: works for me: http://codepad.viper-7.com/fEuEzQ
Comment: try $test->select($currentHUID,'1');
Comment: @Dagon First of all that is not what I am doing exactly and you also do not shorten the md5 hash. All my tests doing basic things like what you did result it the correct response. Something in this configuration is causing weirdness and that's what I need to figure out. I need to leave the single quotes around it because it will be passed to MySQL
Comment: check again, i updated the example, and sure add the quotes in the query not in the function call
Comment: @cryptic ツ Seems even after using str_replace to remove the whitespace from the title it still gives a mismatch
Answer: You are sending single quotes with your value and these get encoded.
If you use:
<code>$match1 = filter_var($match, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
</code>
The result will be the same as the input.
Example.
Also see the manual.
Comment: I did read the manual as I normally do but I missed the Flag thanks for your help!


SpriteKit Buttons stay pressed

Question: I've made two buttons (leftBtn and rightBtn). They work fine when pressing and depressing.. However, when you press and hold, then move your finger away from the button and depress, the button stays down?
Here is the code for both touchDown and touchUp
<code>func touchDown(atPoint pos : CGPoint) {
    let rightBtn = childNode(withName: "rightBtn");
    let leftBtn = childNode(withName: "leftBtn");

    if(rightBtn?.frame.contains(pos) == true){
        right = true;
    }
    else if(leftBtn?.frame.contains(pos) == true){
        left = true;
    }
}

func touchMoved(toPoint pos : CGPoint) {

}

func touchUp(atPoint pos : CGPoint) {
    let rightBtn = childNode(withName: "rightBtn");
    let leftBtn = childNode(withName: "leftBtn");

    if(rightBtn?.frame.contains(pos) == true){
        right = false;
        carController.stopMove();
    }
    else if(leftBtn?.frame.contains(pos) == true){
        left = false;
        carController.stopMove();
    }
}
</code>
Answer: The button stays down because the touch up (i.e. finger moving up and away from the screen) doesn't occur on the button anymore. Instead, it occurs on some other part of your view. If you want the button to not remain pressed, consider adding code to the touchesMoved method too.

SpriteKit Buttons stay pressed


Como enviar todos os arquivo do diretório exceto um específico?

Question: Gostaria de enviar todos os arquivos do diretório, exceto o config.php. Basicamente uso o comando git add . para adicionar todos os arquivos, porém quando possui poucos arquivos editados, faço desta forma:
git add arquivo1.php
git add arquivo2.php
git add arquivo3.php

O arquivo config.php na minha maquina está de um jeito, porém no server possui outras variáveis específicas. Nem sempre preciso enviar o config.php. Gostaria de um comando para enviar todos os arquivos exceto este. Sei que existe o .gitignore e também essa pergunta sobre Ignorar todos arquivos exceto um especifico no GIT, porém as vezes preciso enviar o arquivo config.php, sem que ignore-o, quando há alguma configuração específica.
No "pseudocomando" seria algo como:
git add . exceto config.php

Como enviar todos os arquivo do diretório exceto um específico?
Comment: E porque não fazer uso do `.gitignore` para facilitar o processo?
Comment: @GuilhermeNascimento porque não é sempre que preciso ignora-lo. Se fosse fixo, já teria colocado lá. Seria algo mesmo como o pseudocomando, "Adiciona tudo e ignora esse"... `git add tudo exceto config.php`
Comment: Entendo, mas o `.gitignore` não precisa ser pra sempre, você pode edita-lo a qualquer momento na sua máquina local, ou seja ele é um arquivo de ajustável a sua necessidade para qualquer momento.
Comment: Ah, entendi, você não quer ignorar o arquivo, você quer ignorar as modificações, é isto?
Answer: Ignorar mudanças/modificações no GIT
Se quer ignorar modificações em um arquivo especifico "servidor git", o que você pode tentar é forçar assumir que não houve mudanças (creio que é necessário apenas uma vez):
git update-index --assume-unchanged foo/bar/baz/config.php

Assim o arquivo que já existe no repositório não será removido, mas não será mais atualizado, mas se fizer alguma modificação que necessite que atualize o config.php então use:
git update-index --no-assume-unchanged foo/bar/baz/config.php

E então no próximo update use novamente o --assume-unchanged no config.php
Ignorar enviar (remover o arquivo)
Se quer ignorar que um arquivo seja enviado pode usar o o .gitignore e ajusta-lo se desejar enviar posteriormente, o .gitignore é um arquivo editável a qualquer momento e você o usa como desejar.
Se adicionar:
 config.php

Além de não enviar, se existir algum config.php no repositório ele será removido de lá.
Answer: Faça a adição normal e peça um retrocesso do config.php.
git add -u
git reset -- config.php

Answer: Adicione somente o que vc alterou:
git add -u

Sumario
git add -A   Tudo que estiver em staging
git add .    Tudo em stage, e modificados
git add -u   stage modificados e deletados, novos ignorados.

Comment: Mas `config.php` eu alterei, mas não quero envia-lo. Nem sempre preciso envia-lo.


What are applications of Lie groups/algebras in mathematics?

Question: I studied Lie Groups and Lie Algebras as part of my Masters back in the 1970s. Although very elegant and beautiful, it seemed to its own little world, I never saw the connection with other branches of mathematics (or at least from my course).
Can anyone explain to me how Lie Groups fit in—in a nutshell—or provide me with some useful references I can chew over?
Comment: Did you read why Sophus Lie studied continuous transformation groups and their linearizations?
Comment: One of my students who went on to graduate school to study analytic number theory, or, maybe algebraic number theory. Or, well, I don't know, but, Lie algebra representation is important to him. Kind of surprising to me. On the other hand, another of my students is working towards some graduate work in differential geometry. He also needs Lie theory. Essentially, differentiation puts you in contact with derivations and derivations go hand in hand with Lie algebras. Besides that, and maybe in tune with that, Lie algebras approximate Lie groups and groups, well, they be everywhere.
Comment: Oh, but, more to your reference request, and a bit off topic, but you might enjoy the paper by Baez on Octonions. It perhaps will scratch your itch. I want all my students to read http://math.ucr.edu/home/baez/octonions/oct.pdf
Comment: Olver's book *Applications of Lie Groups to Differential Equations*, perhaps?
Answer: Lie theory connects to almost every other branch of mathematics! It's almost absurdly well connected! Just off the top of my head:

analysis (e.g. harmonic analysis and the Peter-Weyl theorem),
algebraic topology (e.g. principal bundles and characteristic classes),
algebraic geometry (e.g. algebraic groups and flag varieties),
combinatorics (e.g. root systems and Coxeter groups),
differential geometry (e.g. connections and Chern-Weil theory),
number theory (e.g. automorphic forms and the Langlands program),
low-dimensional topology (e.g. quantum groups and Chern-Simons theory),
Riemannian geometry (e.g. holonomy and symmetric spaces),
finite group theory (e.g. the finite simple groups of Lie type)...

And this is just mathematics. Lie theory is also hugely relevant to physics as well (which is related to some of the stuff above) since it's an important ingredient in the study of gauge theory; for example, the Standard Model is a gauge theory.
Comment: I wouldnt have much of a job without lie theory here in particle phenomonology. It is wonderfully beautiful stuff
Answer: There are many connections to other branches of mathematics. Many interesting answers have been given to the MO-question "Why study Lie algebras". It is also worth to have a look at the prerequisites for the Langlands program, where Lie groups and Lie algebras are on top of the list.


How to interpret coefficients in multi-way fixed effects model?

Question: My goal is to run a panel-regression in order to asses the impact of county-level average household income on test-scores across a wide array of undergraduate-level university courses.
Specifically, I have observations on test-scores in course $j$ for student $i$ in semester $t$ where $$j\in\{\text{calculus, linear-algebra, advanced-calculus, ... , comparative linguistics, linguistic typology, ...  }\}$$
and I can partition the set of courses by subject, i.e. define a mapping $s$ such that e.g.
$\,s(\text{calculus})=\text{math}$.
Currently, I'd go about this exercise by estimating
$$grade_{j,i,t}=\gamma_{s(j)}+\gamma_i+\gamma_t+\beta \cdot income_{c(i),t}+\delta x_{i,t}+\epsilon_{j,i,t}$$
where

$\gamma_{s(j)}$ is a subject fixed effect in order to take care of the fact that grading scales tend to vary by subject (but very little within subject)
$\gamma_i$ is a student fixed effect meant to capture unobserved (overall) intellectual ability, propensity to study, etc.
$\gamma_t$ is a time fixed effect.
I also control for parental income as well as $x_{i,t}$ - a set of demographics including parental income, employment status of parents, household size, race, etc.

As I am under the impression that the term fixed-effects has very different meanings in different disciplines, my usage of the term is meant to align with its usage in econometrics.
The coefficient of interest is $\beta$ where $c(i)$ denotes the county where student $i$ resides (my question is conceptual, so it does not really matter that in terms of a narrative the income of the county where a student grew up would presumably be more relevant).
It is my (perhaps erroneous) understanding that, in a simpler model $y_{it}=\alpha_i+\beta x_{it}+\epsilon_{it}$, by including a unit-fixed-effect I am effectively using the time-variation in $x_{it}$ to estimate $\beta$ so that $\beta$ is the impact of $x_{it}$ on $y_{it}$ within an $i$-cell (or rather the average of the impact within each $i$-unit taken over $i$-units?).
If I were to estimate $y_{it}=\alpha_t+\beta x_{it}+\epsilon_{it}$, I'd  on the other hand use the cross-sectional variation so that $\beta$ is the impact of $x_{it}$ on $y_{it}$ at a given time.
So in my setting, I am wondering how to interpret $\beta$ exactly. I would like $\beta$ to isolate the cross-sectional impact of county-income on test-scores.
Questions:
Does my inclusion of $\gamma_{s(j)}$ alter anything regarding the interpretation of $\beta$? I am not sure how to think about the variance reduction of the independent variable here, since it is not indexed at $j$.
I feel tempted to drop $\gamma_i$, because I want the variation that drives the estimation of $\beta$ to be chiefly cross-sectional variation in county income. Including $\gamma_i$ means that the variation in county-income to be exploited is in the time-dimension, right? But I also cannot be ignorant of the fact that there is something like (subject- and time-invariant) student-specific ability that drives grades. Is there a solution to this trade-off?
Finally, I include $\gamma_t$ in order to force the cross-sectional variation in county-income to be central to the estimate of $\beta$. But, now, since I have both $i$ and $t$ fixed effects, what is the exact variation in independent variable indexed at $(i,t)$ that I am using? What is the exact interpretation of $\beta$?
Thanks a lot!
Answer: There are a couple of things that need to be addressed before getting into the $\gamma_{s(j)}$ issue, just to clear up some features of FEs. You mention that this is conceptual, so I don't want to assume you thought through every detail, necessarily, but there is something more fundamental that should be considered before looking at $\gamma_{s(j)}$. A really important part of this model is $\gamma_i$ (student FE). Including this means all time-invariant factors are already "controlled for" that are related to the students. Whatever time-invariant differences (average level of grade over the panel) between students that do exist are eliminated (students are now on the same expected overall "level"). Variables like race can't be in a model with $\gamma_i$. Race might be expect to generate different overall "levels" of grade, but it doesn't change within-person over the panel. The time-invariant "level" that might be captured by race is already captured by $\gamma_i$, and race would drop from the model due to collinearity. Just like race, county is also "controlled for" by $\gamma_i$, unless individuals are moving between counties (another can of worms). This is important, because you say:

I want the variation that drives the estimation of $\beta$
to be chiefly cross-sectional variation in county income...

However, the cross-sectional effect of income "level" on grades among counties is already absorbed by $\gamma_i$. If we set aside class-subject for the moment, the interpretation of $\beta$ would be the expected change in a student's grade associated with a one-unit increase in county-level income (as a deviation from the mean county-level income for each student over the panel). $\gamma_i$ changes all interpretations to within-student effects. If between-student is absorbed and students stay in their counties, between-county is also absorbed in the student FE.
Each student has many subjects during the panel, though, so that is NOT already absorbed by $\gamma_i$. Since we know that subjects have systematic variation in average "levels" or grading scales among all students, we know that a change from one subject to another will generate an expected change in their grade that is not related to $income_{c(i),t}$. Like we did with students (and thus, race, county etc), we can make all subjects "equal" in their time-invariant attributes by absorbing the effect of each subject on the "level" of grades in $\gamma_{s(j)}$. Without this, we don't know if the change came from income or from moving between class-subjects. Thus, $\gamma_{s(j)}$ is important to include and doesn't interfere with the cross-sectional effect of income, because that was already absorbed by $\gamma_i$.
After including $\gamma_i$ and $\gamma_{s(j)}$ (and accounting changes that affect all students in a semester with $\gamma_t$), the interpretation of $\beta$ is the expected increase in grades caused by a one-unit increase in $income_{c(i),t}$ after accounting for time-invariant differences in students (including their counties) and class-subjects (and overall trends). This model won't tell you about cross-sectional effects of county income.
If you are interested in a mix of the within- and between(cross-sectional)-effect of county income, you can use a random effect for student, but you won't be able to say how much effect comes from variation within- versus between-students (and thus between counties). This is a fundamental issue in research with observational data. Another option is the "hybrid model" that isolates within and between effects. This R package gives a nice explanation of that setup.
Comment: Thanks so much for taking the time to answer my question in such detail! If I may confirm my takeaway: The inclusion of $\gamma_{s(j)}$ is necessary so that we do not conflate the effects of moving between class-subjects with the effects of county-income $income_{c(i),t}.$ Then, once I include $\gamma_i$, interpretations are to be thought of within-student. So $\beta$ is the expected change in a student's grade when I raise the average income level of student $i$s county by one unit — as a deviation from the time-average (?) of the time-series income levels for this particular county. (1/2)
Comment: So, $\beta$ is not the expected change in grade if the student would live in a different county with one unit more income, but the expected change in grade if the student's county's average income would increase by one unit above its time-average. Since I cannot just leave out $\gamma_i$ (which would mean that I wouldn't control for time-invariant attributes of the student e.g. intelligence), my best way forward is to look at mixed models. (2/2)
Comment: Glad it was helpful! It sounds like you get it, to me. Your point about increasing a county's income versus rich-poor counties is spot on. I think this model (with the three FEs) would be convincing for the within-effect we are describing. If you want to look at the between (rich/poor county) effect, you could consider the "hybrid model" ("mixed model" usually refers to models with one or more random effects i.e. lmer() in R, which is another can of worms).


Symbol for kernel and range of a linear transformation

Question: I'm wondering what symbol is used for the kernel and the range of a linear transformation. I've seen them being written as such:
$\ker(T)$
$\mathcal{R}(T)$
Are these the "correct" symbols for the kernel and range, or do they differ between different mathematicians? Are there any that are used more frequently? This is being a bit pedantic, but I'm just curious.
Comment: I've also seen $\text{im} (T) $ used for range.
Comment: For the former, I've also seen $\mathcal{N}(T)$; for the later, it's right.
Comment: Usually, $\ker T$ is paired with $\operatorname{im} T$, and $\mathcal{R}(T)$ is paired with $\mathcal{N}(T)$.
Comment: @SkeletonBow Feel free to answer your own question with what you have learned! It is highly encouraged on this site.
Comment: Thanks for the suggestion!
Answer: Daniel Fisher gave a good comment which I'm putting here:
Both of the notations are correct, but usually those two are not used together because of consistency. Here are the "pairs" that are usually used together for the kernel and the range:
$\ker T$ and $\operatorname{im} T$
$\mathcal{N}(T)$ and $\mathcal{R}(T)$


Backbone to use Underscore templates with helpers

Question: I want to use helper functions with Underscore templates and Backbone.
Now I'm doing it this way:
View:
var View = Backbone.View.extend({
    // ...
    template: getTpl('#b_ezlo', 1),
    // ...
    render: function(){
        this.$el.html( this.template(this.model.toJSON()) );
    }
});

Template getter:
Here I generally return the template, along with the helper functions.
The problem is when I do prepare I cannot return the helper functions, because it will require to return also other variables for the template, and it causes undefined getDisabledState:
function getTpl(tpl, options) {
    if (!tpl) return;
    if (!options) options = null;
    var prepare = false;
    if (options == 1) {
        // this is called on View initialization
        // with template: getTpl('#b_ezlo', 1),
        options = {};
        prepare = true;
    }

    var viewHelpers = {}

    if (tpl == "#b_view") {
        console.log("prepare", prepare);
        viewHelpers.getDisabledState = function() {
            if (typeof options.disabled != "undefined") {
                return options.disabled;
            } else {
                return '';
            }
        }
    }

    _.extend(options, viewHelpers);

    if (prepare) {
        return _.template($(tpl).html());
    } else {
        return _.template($(tpl).html())(options);
    }
}

And part of template (Jade) where I want to use the helper:
.icon-block(data-disabled!="<% if (typeof getDisabledState != 'undefined') {getDisabledState()} %>")

What I dislike here is if (typeof getDisabledState != 'undefined') part, which is not nice to have in the template.
So if there is any other way to prepare templates with helper functions?
Comment: I think u can checkout same task realization in MarionetteJS. There is templateHelpers feature quite close to your task.
Comment: What about Backbone+Marionette+Handlebars schema? Handlebars has a build in `registerHelper`, and your can declare your custom helpers.
Comment: Thanks for reply, @VahanVardanyan. I do like Handlebars, but the big part of project is already working with Underscore template, should stay within it for now.
Answer: Thanks to Evgeniy's comment, most probably will do it the MarionetteJS way - defining helpers in the View.
http://marionettejs.com/docs/marionette.view.html#viewtemplatehelpers


What is the scale played on this chord progression?

Question: I'm trying to figure out one jazz improvisation on this chord progression (Sunny - Bobby Hebb)
Am7 Gm7 C9 Fmaj7 Bm7b5 E7b9

So as the chords go Am7, Gm7 - C9 the improvisation starts in Am pentatonic when the chord is Am7 and Gm7 and then shifts on C9 to some scale which consists from C, Db, Eb, E, F, G, A, Bb, C. These are all of the notes which I caught up by ear. I would assume that the root of the scale should be C, but then these notes doesn't build any scale familiar for me (standard, mode or altered...?!). There could be a off-scale note as an ornament since it is an improvisation that confuses me so I can't recognize the scale?
Comment: This will probably end up closed, as analysis of a particular song is not in the site's remit. Can you move it round so it only includes a progression? And are you certain that the scale notes are exactly those? Showing us which version will put another nail in the coffin...
Comment: Tim - I have edited to try and help focus on the chord progression, not the actual song.
Comment: Thanks for editing. I apologize if the question wasn't clear enough. I tried to put focus on the scale, but mentioned the song just to give the idea where I'm trying to apply the scale we're talking about.
Answer: When improvising over standard changes it's important to understand the function of the chords in the progression. You need to see that Gm7-C7-Fmaj7 is a II-V-I progression in F major, and Bm7(b5)-E7-Am7 is a II-V-I in A minor. So if you know how to play over II-V-I progressions in major and minor you can improvise over this song.
Over Gm7-C7 you could simply play F major (which is G dorian / C mixolydian). However, over the V chord jazz musicians often add alterations to add tension that can nicely resolve to the I chord. If you heard the notes correctly (which I don't doubt), then what you heard was a C mixolydian scale with an altered 9, i.e., the note D was altered to add tension. Both possible alterations of the 9 are used: the b9 (Db) and the #9 (D#/Eb). This is very common, and I think it's more natural to view the notes just as a collection of possible notes over a dominant seventh chord that resolves down a perfect fifth. This collection of notes consists of the notes from the mixolydian scale, possibly plus some of the following alterations: b9, #9, #11, b13. You can freely mix notes from the mixolydian scale and altered notes. The altered tensions can also completely replace the standard tensions, which will give you the altered scale: C Db Eb E F#/Gb Ab Bb.
But anything in between is also possible.
If you want to give a scale name to the collection of notes you found, I would suggest "mixolydian b9/#9", because that's what it is.
Comment: Thanks a lot. I could accept this answer since this looks logical to me. (a self taught pianist). For the sake of correctness, if you could listen the following example at the begining (8th second) when goes to the C chord... do you think this is the case ? Leaving Amin pentatonic to C mixolydian but altering the 9th ?
https://youtu.be/LQ_CyyhCLJs
Comment: @Alexander: over C7 he plays F E G Bb Db Eb Db C Bb -> (G# ->)A (over Fmaj7), which is just C7 (mixolydian) with a b9 and a #9 instead of the unaltered 9. The G# before the A is just an approach note and shouldn't be analyzed as a tension. Note that the A is already over the F chord.
Answer: If you had a F# instead of the F, that would be the diminished scale, often played on 7b9 chords.
As Matt mentioned, playing such a scale on a chord that "shouldn't" match (here the C9 chord) adds tension, which releases nicely on the next chord.
It might be that the improviser built the tension this way but had an F there somehow.
Comment: Thanks for answering, I have considered the case if I'm wrong at some note but playing with F# doesn't sounds as the recording I'm analyzing (at least for my amateur ears)
Answer: The entire progression is A minor (or C Major is you prefer) so you could just play an A minor scale over the whole thing.  I think looking at the G-7 to C9 as a key change is not really correct and overly complicates what you are trying to do (it's actually serves more as a II-V of the IV in C major).
Point being that you might be better off improvising in the key center of the progression before exploring ways of making it more interesting by using altered scales to add color such as the suggestions I see above.
Nothing wrong with doing that of course, but step one is to become comfortable at hitting good notes and use that as a foundation for adding additional color for tension.