Arc length $y = \frac{1}{4} x^2 - \frac{1}{2} \ln x$

Question: $$y = \frac{1}{4} x^2 - \frac{1}{2} \ln x$$
$$\int_1^{2e} \sqrt{1 + (y')^2}$$
$$y' = \frac{x}{2} - \frac{1}{2x}$$
$$y' = \frac{2x^2-1}{2x}$$
$$\left(\frac{2x^2-1}{2x}\right)^2$$
$$\frac{4x^4-4x^2+1}{4x^2}$$
$$\int_1^{2e} \sqrt{1 + \frac{4x^4-4x^2+1}{4x^2} }$$
The 1 cancels out the negative term in the numerator
$$\int_1^{2e} \sqrt{ \frac{4x^4+1}{4x^2} }$$
So now if i have done this right I have now idea how to integrate this, subsitution doesn't seem to help. What is the trick here?
Comment: You have a mistake in the step from $y' = \frac{x}{2} - \frac{1}{2x}$. The next line should be $y' = \frac{x^2-1}{2x}$.
Comment: I think it might help you to square $y^{'}$ in its first form, instead of putting it over a common denominator.
Comment: @user84413 Is that valid?
Comment: Sure, it is valid, Paul the Pirate.
Comment: What is meant by "its first form"|
Answer: $$1+y'^2=1+\frac14\left(x^2-2+\frac1{x^2}\right)=\frac14\left(x+\frac1x\right)^2\implies$$
$$\int\limits_1^{2e}\sqrt{1+y'^2}dx=\frac12\int\limits_1^{2e}\left(x+\frac1x\right)dx=\ldots$$
Comment: Oh okay that was some tricky factoring that I didn't follow. Thank you.
Comment: I don't follow that first step.
Comment: Paul: $$y:=\frac14x^2-\frac12\log x\implies y'=\frac12\left(x-\frac1x\right)\implies y'^2=\frac14\left(x^2-2+\frac1{x^2}\right)\ldots$$
Answer: $$y' = \frac{x}{2} - \frac{1}{2x}$$
The only problem I can see in your work is the fact that you slipped when finding a common denominator for the fractions above. Doing so correctly gives us:
$$y' = \frac{x^2-1}{2x};\quad (y')^2 = \dfrac{x^4 - 2x^2 + 1}{4x^2}$$
Now, back to the integral:
$$\begin{align} \int_1^{2e} \sqrt{1 + (y')^2} \,dx & = \int_1^{2e} \sqrt{1 +  \frac{x^4 - 2x^2 + 1}{4x^2} }\,dx \\ \\
& = \int_1^{2e} \sqrt{\frac{x^4 + 2x^2 + 1}{4x^2} }\,dx \\ \\
& = \int_1^{2e} \sqrt{\frac{x^2 + 2 +\frac 1{x^2}}{4} }\,dx\\ \\
& =  \int_1^{2e} \sqrt{\dfrac{1}{4}\left(x^2 + 2 +\frac 1{x^2}\right) }\,dx\\ \\
& = \int_1^{2e} \frac 12\sqrt{(x + \dfrac 1x)^2}\,dx\tag{factored}\\ \\
& = \dfrac 12\int_1^{2e} \left(x + \dfrac 1x\right)\,dx \\ \\
& = \left.\dfrac 12\left(\frac{x^2}{2} + \ln x\right)\right|_1^{2e}\end{align}$$
Comment: Are there any differences when you put the limits in definite integral and the way Don wrote. I see, Don, is doing that a bit upper!? +)


How do Bayesians compare distributions?

Question: So, I think that I have a decent grasp of the basics of frequentist probability and statistical analysis (and how badly it can be used). In a frequentist world, it makes sense to ask such a question as "is this distribution different from that distribution", because distributions are assumed to be real, objective and unchanging (for a given situation, at least), and so we can figure out how likely it is that one sample is drawn from a distribution shaped like another sample.
In the Bayesian world view, we only care about what we expect to see, given our past experiences (I'm still a bit vague on this part, but I understand the concept of Bayesian updating). If that is so, how can a Bayesian say "this set of data is different from that set of data"?
For the purposes of this question, I don't care about statistical significance, or similar, just how to quantify difference. I'm equally interested in parametric and non-parametric distributions.
Comment: @JohnA.Ramey: What is the difference? Once it's all numbers, aren't "male" and "female" just labels for samples?
Comment: Could you clarify what you mean by "this set of data is different from that set of data?" As in, are you referring to the comparison of two or more groups, such as incomes of males vs. incomes of females? Or perhaps how does a Bayesian compare two samples of incomes without knowledge of gender?
Answer: Think your statement through as a Frequentist and make it more specific first. A Frequentist could not say that "data set A is different from data set B", without any further clarification.
First, you'd have to state what you mean by "different". Perhaps you mean "have different mean values". Then again, you might mean "have different variances". Or perhaps something else?
Then, you'd have to state what kind of test you would use, which depends on what you believe are valid assumptions about the data. Do you assume that the data sets are both normally-distributed about some means? Or do you believe that they are both Beta-distributed? Or something else?
Now can you see that the second decision is much like the priors in Bayesian statistics? It's not just "my past experience", but is rather what I believe, and what I believe my peers will believe, are reasonable assumptions about my data. (And Bayesians can use uniform priors, which pushes things towards Frequentist calculations.)
EDIT: In response to your comment: the next step is contained in the first decision I mentioned. If you want to decide whether the means of two groups are different, you would look at the distribution of the difference of the means of the two groups to see if this distribution does or does not contain zero, at some level of confidence. Exactly how close to zero you count as zero and exactly which portion of the (posterior) distribution you use are determined by you and the level of confidence you desire.
A discussion of these ideas can be found in a paper by Kruschke, who also wrote a very readable book Doing Bayesian Data Analysis, which covers an example on pages 307-309, "Are Different Groups Equal?". (Second edition: p. 468-472.) He also has a blog posting on the subject, with some Q&A.
FURTHER EDIT: Your description of the Bayesian process is also not quite correct. Bayesians only care about what the data tells us, in light of what we knew independent of the data. (As Kruschke points out, the prior does not necessarily occur before the data. That's what the phrase implies, but it's really just our knowledge excluding some of the data.) What we knew independently of a particular set of data may be vague or specific and may be based on consensus, a model of the underlying data generation process, or may just be the results of another (not necessarily prior) experiment.
Comment: Yes, ok, frequentists assume a distribution, and that is subjective. But then they can just measure the parameters of each sample, with error, and say "ok, these are the parameters of the true population of each sample, and now what is the probability that the difference is just due to sampling error". My question is about the step *after* your answer - how do Bayesian infer differences between samples (let's assume the samples are from the same *type* of distribution, parametric or not).
Comment: @naught101: Please see my edit.
Comment: @Wayne the paper you linked is excellent. Thanks for sharing
Comment: @naught101: I've updated the blog link. He's evidently kept older versions of the article and each links to a newer one, and the one I first linked to is three versions out of date.
Comment: This is quite a cool method, and it really makes clear how bayesian inference might work (by treating the distribution parameters as the source of uncertainty). Pity it's so computationally intensive. Also, the use of 95% CIs seems a bit too much like setting a significance level, but I can't see if there's a real way to get a reportable equivalent of a p-value (perhaps the sum of the probabilities of values more extreme than 0 from the mean, for the difference in means?).
Comment: @naught101: Obviously any range you pick is arbitrary: 95%, 99%, etc. These are credibile intervals, however, so they mean what casual frequentists think confidence intervals mean: we're 95% (or 99%, etc) certain that the valua lies within this range. Note that you also need a ROPE, as opposed to Sam's answer which assumes exact equality, which will never actually be true. (It's often assumed in frequentist calculations, but it's never actually true). Computationally intensive matters less with quad-core processors in even laptops. (Unless you're working with Big Data.)
Answer: this paper might be of interest:
http://arxiv.org/pdf/0906.4032v1.pdf
It gives a nice summary of some frequentist and Bayesian approaches to the two sample problem, and discusses both the parametric and nonparametric cases.
It might add something to the other answers to give a simple example.  Say you have two data sets $\mathbf{x}$ and $\mathbf{y}$ where each $x_i$ and each $y_j$ is either a $0$ or a $1$.  You assume an iid Bernoulli model in both cases, so each $x_i\sim Bern(p)$ and each  $y_i\sim Bern(q)$.  Your hypothesis testing scenario in both the frequentist and Bayesian settings can be:
$\mathcal{H}_0: \: \: p=q$
$\mathcal{H}_1: \: \: p,q$ not necessarily equal.
The likelihoods for the data in each case are:
Under $\mathcal{H}_0$ : $L_0(p) = f(\mathbf{x},\mathbf{y};p) = \prod_i p^i (1-p)^{1-i} \prod_j p^j(1-p)^{1-j}$
Under $\mathcal{H}_1$ : $L_1(p,q) = f(\mathbf{x},\mathbf{y};p,q) = \prod_i p^i (1-p)^{1-i} \prod_j q^j(1-q)^{1-j}$
(since under $\mathcal{H}_0 \:\: q=p$).  A frequentist approach to the problem might be to do a Likelihood ratio test, whereby you calculate the statistic:
$W = -2\log\left\{ \frac{L_0(p_{max})}{L_1(p_{max},q_{max})}\right\},$
where $p_{max},q_{max}$ denote the maximum likelihood estimates for $p$ and $q$ under the relevant hypothesis (so $p_{max}$ in the numerator may not be the same as $p_{max}$ in the denominator).  $W$ asymptotically follows a $\chi^2_1$ distribution (see e.g. Pawitan, 2001), so you would specify a significance level and reject/fail to reject $\mathcal{H}_0$ as appropriate.
Traditionally, in the Bayesian approach the test statistic would be the Bayes factor.  First you would assume some relevant priors $p\sim \pi_0$ under $\mathcal{H}_0$ and $p,q\sim \pi_1$ under $\mathcal{H}_1$.  The Bayes factor is the ratio of marginal likelihoods, given by:
$BF = \frac{ f(\mathbf{x},\mathbf{y}|\mathcal{H}_0) }{f(\mathbf{x},\mathbf{y}|\mathcal{H}_1)} = \frac{ \int_0^1 L_0(p)\pi_0(p)dp}{\int_0^1 \int_0^1 L_1(p,q)\pi_1(p,q)dpdq}$.
The Bayes factor can be combined with some prior beliefs on the probability of $\mathcal{H}_0$ or $\mathcal{H}_1$ being true, to give the probability of $\mathcal{H}_0$ versus $\mathcal{H}_1$ after seeing the data.  If we assume apriori that each hypothesis is equally likely, so $p(\mathcal{H}_0)=p(\mathcal{H}_1) = 1/2$, then this gives:
$\frac{p(\mathcal{H}_0|\mathbf{x},\mathbf{y})}{p(\mathcal{H}_1|\mathbf{x},\mathbf{y})} = BF \times \frac{p(\mathcal{H}_0)}{p(\mathcal{H}_1)} =  BF \times \frac{1/2}{1/2} = BF.$
Intuitively, if this ratio is $>1$, then the posterior probability of $\mathcal{H}_0$ is larger than $\mathcal{H}_1$, so you would say that $\mathcal{H}_0$ has a higher probability of being true under these assumptions for the prior and model.
One nice thing about the Bayes factor is how it automatically penalises more complex models (such as $\mathcal{H}_1$ here).  A nice paper offering some more intuition is here: http://quasar.as.utexas.edu/papers/ockham.pdf.
Hope that helps along with the other answers already posted.
Answer: Given data, how strongly do we believe that 2 groups do not come from the same population (H_1: they do not come from the same population vs H_0: they come from the same population). This can be done with a Bayesian t-test.
Complexity is used to figure out how much the prior is overlapping with one hypothesis. Fit is used to figure out how much the posterior is overlapping with one hypothesis. Combined you can compare the hypotheses and express your posterior belief in whether or not they come from the same population.

How do Bayesians compare distributions?


How to get granted and expires fields of commerce license updated?

Question: I have similar problem as described on Commerce License Billing: How do I charge or refund a prorated amount when the user's plan changes and the billing cycle is prepaid? by @wizonesolutions, but with different goal.
On a Drupal 7 website with the Commerce License Billing module used for subscriptions, the changing subscriptions plan by saving the new product_id on the license entity ($license->product_id) does in fact update the license and the due amount on the next recurring payment order, however, it does not update the granted and expires fields of the license.
So I tried to get those fields' values from the license, make my calculations and save them together with the whole license entity like so:
$bct=$form_state['storage']['target_product']->cl_billing_cycle_type[LANGUAGE_NONE][0]['target_id'];
    if ($bct == '1') { // hourly
      $target_date = strtotime('+1 hour', REQUEST_TIME);
      $license[arg(1)]->expires = $target_date;
    } elseif ($bct == '2') { // daily
      $target_date = strtotime('+1 day', REQUEST_TIME);
      $license[arg(1)]->expires = $target_date;
    } elseif ($bct == '3') { // monthly
      $target_date = strtotime('+1 month', REQUEST_TIME);
      $license[arg(1)]->expires = $target_date;
    } elseif ($bct == '4') { // quarterly
      $target_date = strtotime('+3 months', REQUEST_TIME);
      $license[arg(1)]->expires = $target_date;
    } elseif ($bct == '5') { // biannually
      $target_date = strtotime('+6 months', REQUEST_TIME);
      $license[arg(1)]->expires = $target_date;
    } else { // biannually
      $target_date = strtotime('+1 year', REQUEST_TIME);
      $license[arg(1)]->expires = $target_date;
    }
    $license[arg(1)]->granted = strtotime("now");
    $license[arg(1)]->product_id = $form_state['storage']['selected_plan'];
    entity_save('commerce_license', $license[arg(1)]);
    drupal_set_message('License has been updated.');

And the admin/commerce/licenses page after saving the license entity shows that all the relevant fields - new product_id, granted and expired fields have been in fact updated.
But the problem is that when expire time comes, the granted field reverts back to initial value and the expired field's value is calculated based on the initial granted field.
In other words, guess I have two billing cycles - hourly and daily - and if an initial order is placed with hourly billing cycle, then license with the following fields is created:
Cycle: Hourly
Granted: 15 January 2018 - 17:50
Expires: 15 January 2018 - 18:50

If I update the license with the new product id, granted and expires field then the admin/commerce/licenses shows:
Cycle: Daily
Granted: 15 January 2018 - 17:52
Expires: 16 January 2018 - 17:52

And when 16 January 2018 - 17:52 comes and all the relevant cron tasks are processed then the same page shows:
Cycle: Daily
Granted: 15 January 2018 - 17:52
Expires: 15 January 2018 - 20:48

Meanwhile bunch of extra orders are charged and the new recurring order with Recurring: Open status are created and then only the license admin page showing the granted and expires fields (with values behind from 16 January 2018 - 17:52) constantly changing with every cron execution:
Cycle: Daily
Granted: Active 15 January 2018 - 17:52
Expires: 16 January 2018 - 01:48

So my question is:
If changing the values for the granted and expires fields in license entity does not take effect, where else I should be looking for changing those values?
Answer: After monitoring how database tables change with recurring products, I've noticed that saving license with the new data was not sufficient and that the cl_billing_cycle should also be updated with the new granted and expire dates.
I am doing that with a direct database query for now. Let me know if there is a better way to update the cl_billing_cycle.


Jenkins pipeline - save to file build job properties

Question: Please help me how can I save to file build job properties
tried in below way, and I get following text in file: [slave:org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper@7fb29d4c]
def jobsResult      = [:]

pipeline {
    agent { label 'Apps' }

    stages {
        stage('Exec Job')
            steps {
                script {
                    echo "Stage name is : ${STAGE_NAME}"
                    try {
                        jobsResult.job_01 = build job: "job_01", propagate: true, wait: true
                        jobsResult.job_02 = build job: "job_02", propagate: true, wait: true
                    }
                    catch (e) {
                        echo "Slave job failed, marking build as UNSTABLE"
                        currentBuild.result = 'UNSTABLE'
                    }

                    writeFile file: "jobsResults.txt", text: "${jobsResult}"
                }
            }
        }
        stage('Sleep') {
            steps {
                script {
                    echo "Stage name is : ${STAGE_NAME}"
                    try {
                        sleep 10
                    } catch (Exception e) {
                        echo "Sleep stage failed, but continuing..."
                    }
                }
            }
        }
    }
}

Answer: When you use
writeFile file: "jobsResults.txt", text: "${jobsResult}"

The string represent of jobsResult is write to file, which is [slave:org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper@7fb29d4c]
You should use writeJSON instead, which will serialize the map object into JSON and write to file
writeJSON file: "jobsResults.json", json: jobsResult

Since writeJSON only works for map object, you may need to convert the object to map so that you can successfully save the data to file.
One potential solution is to define the following method ref
def extractProperties(obj) {
    obj.getClass()
       .declaredFields
       .findAll { !it.synthetic }
       .collectEntries { field ->
           [field.name, obj."$field.name"]
       }
}

And then change the following line from
jobsResult.job_01 = build job: "job_01", propagate: true, wait: true

to
def job_01 = build job: "job_01", propagate: true, wait: true
jobsResult.job_01 = extractProperties(job)

Comment: firstly write JSON should be in following format:
writeJSON file: 'jobsResults.txt', json: jobsResult

secondary still jobs properties failed to be write to file
Comment: @RomanZinger I see. I just update the answer, I think you may need to convert the object into map first.


Is there a module for repeated content?

Question: I recently faced a need of reusing some content, creating content templates (not in the usual meaning of the word).
I have content that is created periodically, a product for instance, which differs from another by one or two fields, all of the rest stays the same, so I thought of reusing content.
Have you ever seen a module that would accomplish that?
Comment: Are you looking for devel generate - https://drupal.org/project/devel
Comment: Maybe u can do this by SQL commands.
Comment: Actually not. Devel generates some random content which is not what I want, thanks tough
Answer: If you are talking about the actual content then check out the replicate and the replicate ui modules. They allow you to duplicate any entity. Much more powerful than the node clone module which only supports nodes.
If you are talking about cloning the content type or product type then look at the bundle copy module.
Comment: Although I imagined it a bit differently (a user would select one out of several "pre defined contents" and edit it afterwards), the replicate module accomplishes my goals pretty well, thank you!
Comment: Then just create a bunch of different content types (or entity types) with the default values for the fields filled out.

Is there a module for repeated content?


Carregar HTML em DIV recebido via requisição AJAX convertendo carácteres especiais

Question: Estou dando manutenção numa aplicação onde existe agora a necessidade de carregar numa div um HTML vindo do banco de dados. Com relação ao retorno desse HTML do banco d dados, está tranquilo, já recebo os valores num JSON e poderia (eventualmente) carregá-lo na view, mas simplesmente não carrega.
Vou mostrar o código:
$.ajax({
    url: '<minha url>',
    dataType: 'html',
    type: 'post',
    data: {<meus parametros>},
    success: function(data){
        $('#load-html-template').html(data[0].TemplateText);
    }

Quanto ao dataType, já mandei como HTML (não retorna nada), JSON (retorna o HTML como uma string), XML (não carrega nada), etc...
Resolvido uma parte do problema - entrando em outro
Obrigado pela ajuda galera até aqui, mas agora tive acesso direto ao banco de dados e percebi que, o código HTML está em formato de carácteres especiais, desta forma:
<html>
<head>

</head>

<body>
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
        <tr>
            <td width="2%">&#160;</td>
            <td width="920px">
                 <div style="line-height:120%;font-family:Arial;font-size:15pt;background-color:#e8eae8;"><form action=""><table border="0" cellspacing="1" cellpadding="0" width="99%">

......

Pois bem, como converter essas tags para as tags HTML em questão? Já fiz isso, mas mesmo assim o problema segue...
mystring.replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """);

Poderiam me dar uma força!!!
Desde já agradeço!!!
Comment: Podes colocar aqui o que aparece com `console.log(data);`?
Answer: Tentei o seguinte:
var html = String(data[0].TemplateText).replace(/&/g, '&')
        .replace(/"/g, '"')
        .replace(/'/g, "'")
        .replace(/</g, '<')
        .replace(/>/g, '>');

Comment: Não há necessidade de utilizar aspas duplas para atribuir aspas simples numa string. Basta atribuir com escape: `'\''`.
Comment: Funcionou... Thanks!!!


To what extent is music mentally internalized with respect to the original key it was learned in?

Question: This question was prompted by two phenomena I've encountered as a 24yo self-taught jazz musician of 2 years who is committed to playing entirely by ear.

A large fraction of people, myself included, when recalling songs do so within 1-2 semitones of the original key.  This shows that when internalizing music, the brain does so with some link to the actual key, despite not being able to identify the actual key or note when unfamiliar music is played (ie perfect/absolute pitch).

When learning complex melodies or chord progressions, I can play the first note or chord, and audiate the rest.  However, when transposing the concept (starting at a different note) I struggle to hear the rest in my head.  I don't have absolute pitch, so shouldn't my brain be totally agnostic to the specific key I play the concept in and thus able to hear it correctly no matter at which note/chord it started?

These patterns seem to imply that though I do not have perfect pitch, the licks and changes I learn are ultimately internalized with respect to the actual key I learned them in.  I hate this idea.  I want to fully digest all the licks and changes I learn by ear.  I want them to be deeply ingrained into my musical cognition and aurally summonable in any key when improvising.
This has implications for how I practice: should I make it a point to play and sing my favorite songs and progressions in every key?  Are they not fully digested/internalized if I don't?
NOTE:  With respect to reproducing/playing music back in different keys, I mean mainly in terms of singing/whistling/humming/hearing in your head.  The question presumes a skill level such that playing the concept on an instrument in different keys is a trivial task.  I am a guitar player, so almost often this is the case for me.  The question stresses the mental aspect of improvisation, as ideally I'd like to play whats heard in my head, not what the instrument suggests to the muscle memory in my fingers.
Comment: Reading through, I expected to see an instrument tag. No such luck. On guitar, there is a completely different mindset with respect to this question, compared to, say piano/keyboard. In other words, the *mechanics* of the instrument (barring vox) is of paramount importance. Also, playing in certain keys, again, instrument-wise will have some bearing. I'm happy on keys in most keys, but something like transposing to key B might have me doing a lot of thinking! On guitar - so what?
Comment: @Tim  Good point! I added a note stressing the mental focus of the question.  I'm a guitar player as well and given the nature of the instrument playing stuff in different keys is usually trivial.
Answer: For some, it's absolute: 'I learned that song in that key, and that's where it stays, for ever.' If it's a song that is sung (and played) by the person concerned, that's almost fair enough. They're in charge, with no (or little) reason to vary. I've worked with people like this, and it's almost written in stone. Which means when I want to harmonise, sometimes it's impossible.
Others, probably including myself, regard meody lines and harmony sequences in a very different way. Using interval and chord family patterns, it doesn't really matter where we are, key-wise. The geography of the piece works the same in any key (thanks to 12tet) so where we start will be where we finish - same key!
Answer: If you learned music from sheet music, it's pretty likely (at least IMO) that you internalized it as a series of note names and rhythms. This means that, regardless of whether you ever figured out the piece's key, you internalized it with respect to the original key it was learned in. This internalization is especially emphasized in every genre and situation where you are not expected to deviate from the sheet music (e.g. concert band, choir, children's typically classical piano lessons).
There are music types and situations where disconnecting learned music from keys is expected (e.g. national anthems, folk songs), but these pieces are often learned in a different context from the above (e.g. not from formal lessons), so disconnecting is easier to absorb.
Answer:
I can play the first note or chord, and audiate the rest.

But how can you or anyone else know that it's correct without actually playing it so that it will be heard?
This just seems to get down to ear training and whether you correctly hear relative pitch relationships. You can "hear" it in your head, or listen to some actual music, but the real test of whether the hearing is correct, for either case, is actually playing the music. You can't ear train with just mental audiation.
Transposing doesn't seem to be the way to exercise this skill. Transposing means you already have the material, you know the sequence of intervals. It's more a question of mechanics. Can you play it in another key with ease? Or, for large amounts, like a whole song, it a question of memory. Do you actually remember all the relative changes rather than the specific fingering of a specific key?
You need to do dictation or playback exercises with unfamiliar stuff. Or, you can do things like sing the "missing" note, ex. play root & fifth, sing the minor third, play a triad, sing the minor seventh. These things will actually test your hearing and mental audiation better than playing transpositions.

...playing the concept on an instrument in different keys is a trivial task.

On guitar it may be trivial to just slide up or down a few frets, but transposing a fourth by shifting up or down across strings (where patterns change shape over the G & B strings), or playing all fretted notes, like 3 notes per string scales, compared with playing open position, isn't so easy.
The mechanical part will be different for each instrument. Keyboard is sort of opposite of guitar. Transposing by fourths and fifth is fairly easy, but transposing by half step isn't. You should focus on whatever are the mechanical difficulties of the instrument until all positions, transpositions, etc. are equally accessible.

...ideally I'd like to play whats heard in my head, not what the instrument suggests to the muscle memory

It seems to me there are two things, which are on many levels separate, but eventually you want to train to become inextricably linked: mechanical mastery of an instrument, and good relative pitch. You want them to be one and the same.
For example, the sound of a borrowed, minor iv is a common and useful musical device. You want to be able to recognize it when you hear it played, silently audiate it mental, and play it in various position, in all twelve keys/roots, with a variety of figurations. Ideally, you want to recognize important scale degree relationships about it: half step above SOL, half step between LA & SOL. If given a tonic aloud, you can sing the minor sixth above it, then the other iv chord tones, then resolve the LI down to SOL? Instrumentally you can play iv I in various position, voicings, and all twelve keys.
The traditional way to build those skills is play lots of essential harmonic patterns in all keys combined with ear training that incorporates singing.
Answer: It is standard training for jazz musicians to learn everything (perhaps not literally) in every key. So, yes, you should make it a point to play/sing your favorite songs and progressions in every key. My experience is that this becomes easier over time, so that such transpositions happen more naturally and require less explicit practice.
Keep in mind that remembering and reproducing pitches/intervals/chords is not a function of auditory memory only. There's a physical component as well in associating the pitch/interval/chord to its production on an instrument. (See also @Tim's comment on the OP.)


For a triangle $ABC$, $a^2+b^2+c^2=8R^2$ then it is a right triangle?

Question: $ABC$ is a triangle, $a^2+b^2+c^2=8R^2$ then how do we prove it is a right triangle?
Comment: @BabakS. it is the circumradius
Comment: What does that `R`  stand for?
Answer: We use the well-known formula $R = \frac{abc}{4A}$, where $A$ is the area of the triangle.
Thus $8R^2 = \frac{8a^2b^2c^2}{16A^2}$, and by Heron's formula
$$16A^2 = (a+b+c)(-a+b+c)(a-b+c)(a+b-c).$$
Now assume that $a^2 + b^2 + c^2 = 8R^2$. Then we have
$$8a^2b^2c^2 - (a^2 + b^2 + c^2)(a+b+c)(-a+b+c)(a-b+c)(a+b-c) = 0.$$
Expanding this gives
$$a^6 + b^6 + c^6 - a^2b^4 - b^2c^4 - c^2a^4 - a^4b^2 - b^4c^2 - c^4a^2 + 2 a^2 b^2 c^2 = 0,$$
which can be factored as
$$(a^2 + b^2 - c^2)(b^2 + c^2 - a^2)(c^2 + a^2 - b^2) = 0.$$
Thus the claim follows from Pythagorean theorem.
Answer: Assuming that $R$ means circumradius we can use the formula
$$R=\sqrt{\frac{a^2+b^2+c^2}{8(1+\cos A\cos B\cos C)}},$$
where $a$, $b$, and $c$ are the sidelengths and $A$, $B$, and $C$ are the angles. Plugging in $a^2+b^2+c^2=8R^2$, we reduce the above to
$$1+\cos A\cos B\cos C=1,$$
whence one of $\cos A$, $\cos B$, or $\cos C$ must be $0$ - meaning that we have a right triangle.
Comment: How do you prove the formula?
Comment: I have a found a proof :)
Comment: @125a8owp Well, you can reduce it to the familiar form $R=\dfrac{abc}{4\triangle}$ by using the law of cosines and then some not-completely-awful,-but-still-not-particularly-fun algebraic manipulation. However, as is the nature of such formulae, it is nice just to know it and then be able to pull it out of one's hat when the appropriate problem (such as this one) arises. (I do not claim this is the simplest method of proof)
Answer: Let $S$ be the area of the triangle.
Since we have $4RS=abc$ and
$$\begin{align}16S^2&=(a+b+c)(-a+b+c)(a-b+c)(a+b-c)\\&=-(a^4+b^4+c^4)+2(a^2b^2+b^2c^2+c^2a^2)\end{align}$$
if $a^2+b^2+c^2=8R^2$, then we have
$$\begin{align} 0 &=\frac{a^2+b^2+c^2}{R^2}-8\\&=\frac{a^2+b^2+c^2}{a^2b^2c^2}(-a^4-b^4-c^4+2a^2b^2+2b^2c^2+2c^2a^2)-8\\&=\frac{(-a^2+b^2+c^2)(a^2-b^2+c^2)(a^2+b^2-c^2)}{a^2b^2c^2}.\end{align}$$
$$\Rightarrow (-a^2+b^2+c^2)(a^2-b^2+c^2)(a^2+b^2-c^2)=0$$
So, the triangle has to be a right triangle.
P.S. Actually, $a^2+b^2+c^2=8R^2\iff\text{The triangle $ABC$ is a right triangle}$.
Also, we can see the followings :
$$a^2+b^2+c^2\gt 8R^2\iff \text{The triangle $ABC$ is an acute‐angled triangle}.$$
$$a^2+b^2+c^2\lt 8R^2\iff \text{The triangle $ABC$ is an obtuse triangle}.$$


What type of data analysis should I make in case of (quasi-) experimental data?

Question: In my school, there is a trend of using computer software for teaching a first course in Chemistry for undergraduate students. I hypothesized that the use of this tool could make the students achieve better scores than without this help. So far what I have done is the following:

I chose two groups, both of them were going to follow the same topics. Only in one of them the use of the computer software was commendatory.
I make an entrance test about basic chemistry knowledge to both groups and approximately 100 percent of both classes failed that examination.
I had compiled the results of the mid-term exam and the final exam of both groups and I have seen an increase in the final marks of the group that was using the computerized tool.

I have read that this seems like a quasi experiment. I have gathered some information about this techniques, but apart from the basic stuff I am a little bit lost of what statistical techniques should I perform to gather a conclusion that this software tool should be encouraged to be used.
I have performed a hypothesis test, but I believe this is not enough. Any advice? My statistics knowledge is very basic.
Comment: Were the groups chosen by randomly assigning students?
Answer: The central question is whether you assigned students completely at random to the experimental groups.
If yes you can use a standard test for independent samples to assess the significance of the group difference. This is probably the hypothesis test that you have already done.
If no, it is indeed a quasi experiment also called a non-randomized experiment or broken experiment.
There are many statistical techniques available to correct for selective assignment including propensity score techniques, regression technqiues, and combinations of both.
The central question you need to answer to use these techniques is whether you know what caused the assignment to groups. Were certain students assigned to the computerized group (e.g. older/younger, better/worse, male/female, richer/poorer, smaller/taller....)? And do you have data on the variables determining the assignment? Then you need to adjust for the imbalance in these covariates using one of the above mentioned techniques.
The easiest, albeit not 'best', adjustment method is Analysis of Covariance, a regression technique which comes with the assumptions of linearity and normality in small samples. You can imagine it like a t-test where in addition you control for the confounding variables you identified as the responsible one for the treatment group assignment. Standard software packages like Excel, Stata, Spss, SAS or R have easy to use implementations of this technique.
Since you say that your statistics knowledge is very basic collaborating with a skilled analyst may be a good additional option in this situation, because the less basic techniques involving propensity scores can get a bit complicated.
Answer: please try propensity score matching ..here's a simple tutorial for you http://web.hku.hk/~bcowling/examples/propensity.htm
ideally you divvy up the groups (like you have already tried) and ID different attributes of the students in both the groups , perform a logistic regression on both groups. For e.g. if you ID attributes like "score in maths" A and "score in science" B and score in chem is C then your equation would be something like C = xA+yB, which after logistic regression on different samples should give you coeffecient values of x and y .. post that you apply these very coeffecients to both the data sets and compare the mean/median ..what this would tell us is that  due to A and B scores in C went up or down and that there's no bias in the test since all students are equally likely to be administered the computerized chem course .. if this is confusing, please read the tutorial above ..it does a better job


Deriving the central Euler method and intuition

Question: My professor (Dutch) asked us to determine, among other things, the truncation error of the central Euler method. First of all, this is probably not the correct term, since there are very few results for "Central Euler", so that made looking things up a hassle.
To determine the truncation error, I thought I had to first know how to derive this central Euler method, given by:
$$
u_{k+1}=u_{k-1} + 2h\cdot f(u_k)
$$
(It also states $u_0$ and $u_1$ are given/known)
In which $f(x)$ gives the slope at point $x$ (I think).
I tried to derive this using Taylor expansions, but I didn't get close.
I also thought I had to get an intuitive notion of what this means, and I figured out it's this: We add two times the slope (times the step size) at $x=u_k$ to the the y-coordinate at $u_{k-1}$ to get the y coordinate at $x=u_{k+1}$. The two times is because the length between $k-1$ and $k+1$ is equal to $2h$.
So my question is: How do I derive this method, what's it called, and is the derivation a good step in figuring out the truncation error?
Note: It was given that the truncation error is of order $h^3$.
Comment: If this is for a beginner's course in numerical methods then it would make much more sense in my opinion to consider the *explicit midpoint method* (aka *modified Euler method*) $u_{k+1} = u_k + h f\left( u_k + \frac{h}{2} f(u_k) \right)$, which is a one-step method. For this method you might use the techniques which you were taught for forward/backward Euler.
But the jump from one-step to two-step schemes is not so straightforward to understand simply in an exercise.
Answer: Local Truncation Error
You can also go the differentiation route, with $x=x_k$, $x\pm h=x_{k\pm 1}$ and $u_j= u(x_j)$ method step can be related to the the central difference quotient. With the Taylor expansion of $u$ we get
$$
u(x\pm h)=u(x)\pm hu'(x)+\frac{h^2}{2}u''(x)\pm\frac{h^3}6u'''(x)+...
\\~\\
\implies
\frac{u(x+h)-u(x-h)}{2h}=u'(x)+\frac{h^2}{6}u'''(x)+O(h^4)
$$
so that
$$
\frac{u(x+h)-u(x-h)}{2h}-f(x,u(x))=O(h^2)
$$
making this linear multi-step method a second order explicit method.

Global Error Approximation
The distance $d_k=u_k-u(x_k)$ of the numerical method solution $u_k$ to the exact solution $u(x_k)$ evolves as
\begin{align}
u_{k+1}&=u_{k-1}+2hf(u_k)\\
u(x_{k+1})&=u(x_{k-1})+2hf(u(x_k))+\frac{h^2}{6}u'''(x_k)+O(h^4)\\[1em]
\hline
d_{k+1}&=d_{k-1}+2h(f(u_k)-f(u(x_k))-\frac{h^3}3u'''(x_k)+...\\
&=d_{k-1}+2hf'(u(x_k))d_k-\frac{h^3}3u'''(x_k)+...
\end{align}
where the omitted terms are of higher order assuming that $hd_k^2$ is $O(h^4)$ or smaller.
Linear difference equation for the error terms: To get an easily solved problem, first assume that $h$ is small enough so that $u,f'(u),u'''$ are slowly changing over several steps. Then we can set them constant in the above recursion. The now linear recursion
$$
d_{k+1}=d_{k-1}+2hf'd_k-\frac{h^3}3u'''
$$
has for $f'\ne 0$ a solution $d_k=Aq^k+B(-q)^{-k}+C$ where $q>0$ solves
$$
q^2-2hf'q+(hf')^2=1+(hf')^2\implies q=hf'+\sqrt{1+(hf')^2}=e^{hf'+O(h^3)}
$$
The resulting form of the error terms is, up to higher order terms,
$$d_k=Ae^{khf'}+(-1)^kBe^{-khf'}+C.$$
Differential equations for the error components: Translating the terms back into general functions, $d_k=a(x_k)+(-1)^kb(x_k)+c(x_k)$, we identify functions and their differential equations as
\begin{align}
a(x)&\simeq Ae^{(x-x_k)f'(u(x_k))}&\implies a'(x)&=f'(u(x))a(x),\\
b(x)&\simeq Be^{-(x-x_k)f'(u(x_k))}&\implies b'(x)&=-f'(u(x))b(x),\\
c(x_{k-1})-c(x_{k-1})&=2hf'c(x_k)-\frac{h^3}3u'''&\implies c'(x)&=f'(u(x))c(x)-\frac{h^2}{6}u'''(x)
\end{align}
with $u'''(x)=f''(u(x))[f(u),f(u)]+f'(u)^2f(u)$. The initial values are zero for the trend $c$ and account for the error in the first step in the oscillating parts $a,b$.
\begin{align}
c(x_0)&=0, \\
a(x_0)+b(x_0)&=0, \\
a(x_1)-b(x_1)&=u_1-u(x_1)-c(x_1)\approx e(x_0)h^{p+1}+\frac{h^3}{6}u'''(x_0)
\end{align}
This has as consequence that the trend of the error has order $c(x)=O(h^2)$ while the oscillating parts are of order $a(x),b(x)=O(h^3)$ if $p\ge 2$ for the order of the method for the initial step. If the initial step has only order $p=1$, the oscillating parts will reflect this lower order, their contribution will be of the same scale as the error trend curve $c$.
Experimental Error Order Confirmation
That this method is really of order 2 but rather sensitive to the computation of $u_1$ show the following graph depicting the scaled error of a numerical against an exact solution. That the error graphs converge visibly, in the latter paths alternating between an upper and a lower error function, confirms the order, as else the scaled error graphs would be largely different in scale.

The equation used is of the form $F(u, u')=F(p,p')$ with here $F(u,u')=u'+10\sin(u)$ and $p(t)=\cos(t)$, so that $$u'(t)=f(t,u)=10(\sin(\cos(t))-\sin(u(t))-\sin(t).$$ The error for the method applied with step size $h$ is divided by $h^2e^{5t}$, as the equation is slightly stiff and the error rapidly growing.
The initialization is from top down by the exact value $u_1=p(t_1)$, order 3 Heun, by the explicit midpoint method and lastly by the order insufficient Euler method. To decrease the influence of the first error, the step was computed with 5 method steps of step size $h/5$.
See Hairer/Nørsett/Wanner: Solving ODE I: Non-stiff problems, chapter III.9, where Figure 9.2 about this same method has a similar construction.
Comment: Set $x=x_k=x_0+kh$, then $u_k\simeq y(x_k)$. The formula is the usual formula for the local discretization error of a method, you insert an exact solution in both sides of the method and use Taylor expansion to find the difference between them.
Comment: The odd part of the function $g(h)=f(x+h)$ is $\frac12(g(h)-g(-h))$. The even part is $\frac12(g(h)+g(-h))$. The odd part of a power series contains only the odd powered terms, the even part complementarily the even powers.
Comment: I unfortunately don't recognize my expression in this answer. You use y and x and a function f that takes two arguments instead of 1?
Comment: So that last line can be rewritten to $u_{k+1}=u_{k-1}+2h\cdot f(u_k) + O(h^2)$? And is what's on the right side exactly equal to the exact value of $u_{k+1}$? If so, to get the complete error, I calculate the difference between this expression and the approxmiation (i.e. $u_{k-1}+2h\cdot f(u_k)$)?
Comment: Also, where did you find the definition of the central difference? Especially the + third derivative and + O(h^4) part? I feel like I'm not searching the web correctly, since I'm having a hard time finding many aspects of numerical analysis.
Comment: You just take the odd part of the Taylor series, $\frac12(y(x+h)-y(x-h))=y'(x)+\frac{h^3}{3!}y'''(x)+\frac{h^5}{5!}y^{(5)}(x)+\frac{h^7}{7!}y^{(7)}(x)+...$.
Comment: I don't see where that comes from, dividing by 2 on the left side? And why only take every odd part?
Answer: It's a two-step Nyström method. Using the ODE $u' = f(u)$ and $x_k := x_0 + k h$ you write
\begin{equation}
u(x_{k+1}) - u(x_{k-1}) = \int \limits_{x_{k-1}}^{x_{k+1}} u'(x) \, \mathrm{d}x = \int \limits_{x_{k-1}}^{x_{k+1}} f(u(x)) \, \mathrm{d}x.
\end{equation}
Now you use a quadrature formula for the integral, in this case the midpoint rule: $\displaystyle \int \limits_{x_{k-1}}^{x_{k+1}} f(u(x)) \, \mathrm{d}x \simeq 2h f(u(x_k))$.

For the local truncation error at $x_2$ we assume that both previous values $u_0 = u(x_0)$ and $u_1 = u(x_1)$ are exact. The local truncation error is then given by
\begin{equation}
\tau_2 = u(x_2) - u(x_0) - 2 h f(u(x_1)) = u(x_2) - u(x_0) - 2 h u'(x_1)
\end{equation}
(using again the ODE in the last step). Now comes Taylor:
\begin{eqnarray}
  u(x_0) = u(x_1 - h) &=& u(x_1) - h u'(x_1) + \frac{1}{2} h^2 u''(x_1) - \frac{1}{6} h^3 u'''(x_1) + \frac{1}{24} h^4 u''''(x_1) + O(h^5),\\
  u(x_2) = u(x_1 + h) &=& u(x_1) + h u'(x_1) + \frac{1}{2} h^2 u''(x_1) + \frac{1}{6} h^3 u'''(x_1) + \frac{1}{24} h^4 u''''(x_1) + O(h^5),
\end{eqnarray}
for $h \rightarrow 0$, so that
\begin{equation}
\tau_2 = \frac{1}{3} h^3 u^{\prime\prime\prime}(x_1) + O(h^5), \quad h \rightarrow 0.
\end{equation}
Comment: That's right, I'll add something on the local truncation error.
Comment: Yes, I did it for $k=1$ only, you can do it for any $k$ of course. The two expressions above are just Taylor expansions of $u(x_0) = u(x_1 - h)$ (note the minus sign!) and of $u(x_2) = u(x_1 + h)$ around $x_1$.
Comment: Cool way of writing that difference as the definite integral of a derivative! So does this mean that the approximation error in the midpoint rule for this integral is the same as the truncation error of the "central euler method"?
Comment: So, my $u_{k+1}$ in the expression in my question is an approximation for the real value corresponding to $x_2$, right? And the $u(x_2)$ is the exact value at $x_2$? If that's the case, I understand why we then subract the approximation from the exact value.

I don't understand the taylor expansion of $u(x_0)$ tho, where do the minus signs come from, and how do you expand to a higher $x_i$?
Comment: One more thing: In your formula for $\tau$ you use $u(x_2)$ and $u(x_0)$ and $u(x_1)$, but here the first is an exact value for every iteration right? But the second and third are approximate results from previous iterations if I'm not mistaken? (So in this case $x_0$ and $x_1$ are exact in this example, because they were given, but I mean for the next and subsequent iterations).
Comment: You are right, but for the *local* truncation error we always *assume* that the previous values $u_{k-1}, u_k$ are exact and we check the error of the next value, $u_{k+1}$, which is no longer exact. See https://en.wikipedia.org/wiki/Truncation_error_(numerical_integration)#Extension_to_linear_multistep_methods for example.
Comment: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/88063/discussion-between-the-coding-wombat-and-christoph).


What is the technical difference between CreateJS, JQuery & GreenSock?

Question: As someone who is just now moving from ActionScript development into JavaScript development, I'm looking at various frameworks that can give me some of the animation power and flexibility that I'm used to.  I'm a bit confused by all the various options that are out there.
I'm currently using CreateJS because of the CreateJS Toolkit that is built into Flash, to help me port some of my work into JavaScript.
Are JQuery and GreenSock TweenMax competitors to CreateJS?  Are they complimentary? Are they entirely unrelated?
Thanks.  I feel embarrassed to be asking these n00b questions, but it is what it is.
Comment: First figure out exactly what each one is. jQuery for example is a library, not a framework. generally comparing a library to a framework is like comparing apples to oranges. comparing a javascript library to a flash library is madness.
Comment: @KevinB, could you please be constructive by explaining the technical difference between a library and a framework?  Thank you.
Comment: Yes, though rather than re-inventing the wheel i'll just link to one: http://stackoverflow.com/questions/3057526/framework-vs-toolkit-vs-library
Answer: CreateJS is a framework that uses several libraries for a more fully-featured, pre-packaged app building experience. This is probably a good thing if you come from an ActionScript/Flash environment as it will be somewhat familiar.
Greensock TweenMax specifically competes with a section of CreateJS's framework, namely TweenJS, and targets post-Flash developers in a similar. TweenMax does offer a useful amount of features and is actually quite fast, though I've only tooled around with it briefly.
Jquery is a library for DOM manipulation/event handling/ simple animation (think, ease in a box, animate on mouseover, etc)/ AJAX. Jquery is incredibly popular and exists on over 50% of websites. However, this solution isn't specifically focused on making animation-heavy applications like games, etc. For smoothing over cross-browser issues and adding some power and fluidity to common actions (DOM/AJAX/events), it's hard to beat.
Answer: I worked a lot with AS and I think the best solution for you is HTMl5+CSS3+JS/JQUERY.
Regards :)
Comment: @Vitor Venturin, thanks for sharing your subjective opinion.  I do find it helpful.  Could you tell me how you use this combination?  What kind of development work is it helpful for and why?  Thank you.
Comment: I'm sorry, Vitor, but we want facts, not opinions here. Why do you think that this particular combination is the best for the asker?
Comment: `HTMl5+CSS3+JS/JQUERY: All websites use that!`


Finding arbitrary value in joint pmf of discrete random variables.

Question: I am learning about probability and have a relatively good understanding of how random variables work. I am a little confused with this question as I have never seen an arbitrary (k value in this case) value in the pmf of two discrete random variables.

The joint pmf of two discrete random variables X and Y is given by Px,y (x,y) = k(x + 3y).
The support of X is X = {0,1,2}, whereas the support of Y is Y = {0,1,2,3).

The question then continues to ask to find the value of k, obtain the pmf's of both X and Y and determine whether they are independent or not.
I am finding it difficult to understand how to find the value of k in the beginning?
Comment: Hint: remember that the sum of a pmf over its support is 1. That is, $\sum_{x=0}^2\sum_{y=0}^3 P_{x,y}(x,y) = 1$.
Answer: As mentioned in the comments, the sum of a PMF over its support is $1$. Therefore,
$$1=\sum_{x=0}^2\sum_{y=0}^3 P_{X,Y}(x,y) =k \sum_{x=0}^2\sum_{y=0}^3 (x+3y)=66k,$$ from which we deduce $k=\displaystyle\frac{1}{66}$.
Moreover, notice that \begin{align}
P_X(x) &= P(X=x)\\
&=\sum_{y =0}^3 P(X=x, Y=y) &\textrm{(law of total probablity)}\\
&=\sum_{y =0}^3 P_{XY}(x,y).
\end{align}
Similarly, $P_Y(y)=\sum_{x=0}^2 P_{XY}(x,y)$. Hence,
$$P_Y(y)=\sum_{x=0}^2 P_{XY}(x,y)=\sum_{x=0}^2 \frac{1}{66}(x+3y)=\frac{3y}{22}+\frac{1}{22}$$ and
$$P_X(x)=\sum_{y=0}^3 P_{XY}(x,y)=\sum_{y=0}^3\frac{1}{66}(x+3y)=\frac{2x}{33}+\frac{3}{11}.$$
For independence, recall that $X$ and $Y$ are independent iff $P_{X,Y}(x,y)=P_X(x)P_Y(y)$, for all $x$ and $y$.
Comment: Can I ask how you deduced that the first equation is equal to 66k? how do you get 66?
Comment: @DeclanMorgan Sure, this is just double summation:
\begin{align} \sum_{x=0}^2\sum_{y=0}^3 (x+3y)&=\sum_{x=0}^2\left[(x+0)+(x+3)+(x+6)+(x+9)\right]\\ &= \left[(0+0)+(0+3)+(0+6)+(0+9)\right]+\left[(1+0)+(1+3)+(1+6)+(1+9)\right]+\left[(2+0)+(2+3)+(2+6)+(2+9)\right]\\ &= 18+22+26=66
\end{align}
See, for example, [this video](https://www.youtube.com/watch?v=vGQMmpTInPU) to see how to compute a double summation.


cakephp 3.1 mysql has gone away

Question: I have a Shell script that runs continuously on a loop.
It checks the database for records and alters them if needs be.
        set_time_limit(0);
        while(true){
            try{
                $this->out(mysql_ping());
                $companies = $this->findCompanies();
                $companies = $this->reduceCompanies($companies, $rules);
                $this->processCompanies($companies);

            }catch (\Exception $e){
                Log::write('debug', $e->getMessage());
            $this->out($e->getMessage());
            }
        sleep(3);
        }

Problem I'm having is this script seems to run ok, but then randomly will throw:
'2006 MySQL server has gone away'
I've tried to put some stuff in the exception catch to reconnect to the mysql server such as :
     }catch (\Exception $e){
                    if(!mysql_ping()){//tried
    $this->connection->reconnect();  //also tried
$this->Company->getDatasource()->reconnect();   neither seem to work.
                    }}

Any suggestions how to reconnect to the db?
Comment: I am facing a similar issue, we need to get to the root cause of this, this should ideally not happen :(
Answer: I had a similar Problem where the Shell is running in an infinite loop.
Add the use for the ConnectionManager:
use Cake\Datasource\ConnectionManager;

Get the connection before the loop:
$connection = ConnectionManager::get('default');

In the loop, shortly before you first need the connection, check if you are still connected and do a connect if you are disconnected:
if(!$connection->isConnected()) {
    $connection->connect();
}

If your Shell has a state where it is waiting for a longer time, you could try to manually disconnect and do a new connect when you need the connection again:
if($connection->isConnected()) {
    $connection->disconnect();
}

cakephp 3.1 mysql has gone away


On update triggering in oracle?

Question: I create 2 tables employees and customers.The employees table code is here:
create table employees(
employeeNumber     number not null,
lastName           varchar2(30) not null,
firstName          varchar2(30) not null,
email              varchar2(50) not null,
officeCode         varchar2(10) not null,
assignTo           number default null,
jobTitle           varchar2(100) not null,
primary key (employeeNumber),
foreign key (officeCode) references offices(officeCode),
foreign key (assignTo)  references  employees(employeeNumber)
);

here assignTo is a foreign key of his own table employees and employeeNumber is auto increment.Some insertion sample is here:
 insert into employees (lastName,firstName,email,officeCode,jobTitle)
 values ('hasan','rumy','email@example.com','123','manager');
 insert into employees (lastName,firstName,email,officeCode,assignTo,jobTitle)
 values ('hasan','rakib','email@example.com','123', 1 ,'assistant manager');

The customer table code is here:
create table customers (
customerNumber    number not null,
customerName      varchar2(50) not null,
phone             varchar2(20) not null,
address           varchar2(70) not null,
city              varchar2(50) not null,
postalCode        varchar2(15) not null,
country           varchar2(40) not null,
salesRepEmployeeNumber  number default null,
primary key(customerNumber),
foreign key (salesRepEmployeeNumber) references employees (employeeNumber)
);

customerNumber is auto increment.some sample insertion is here:
insert into customers
(customerName,phone,address,city,postalCode,country,salesRepEmployeeNumber)
values ('roxy','017456','holy park','kolia','Z143','something',1);

Now I create a trigger which execute before update employeeNumber column of employees table for on update cascade and the code is here:
create or replace trigger employees_update
before update of employeeNumber on employees
for each row
begin
update employees
set
assignTo = :new.employeeNumber
where assignTo = :old.employeeNumber;
update customers set
salesRepEmployeeNumber = :new.employeeNumber
where salesRepEmployeeNumber = :old.employeeNumber;
end;
/

above all is right in oracle but the problem is when I update employees table.The update code is here:
update employees set employeeNumber = 134 where employeeNumber = 1;

the problem is here:
    ORA-04091: table RUMY.EMPLOYEES is mutating, trigger/function may not see it
ORA-06512: at "RUMY.EMPLOYEES_UPDATE", line 2
ORA-04088: error during execution of trigger 'RUMY.EMPLOYEES_UPDATE'

1. update employees set employeeNumber = 134 where employeeNumber = 1;

As far I know it's a system problem so where I make mistake?Can not I make foreign key assignTo of employees table?Also notice that same thing work properly in mysql.Advance thanks for answering this long question.
Comment: Run this `SHOW ERRORS TRIGGER employees_update` for more details
Comment: the query 'show errors trigger employees_update' occurs an error which is :  "invalid SQL statement" .
Answer: As you have discovered, you cannot select from the same table that a row-level trigger is defined against; it causes a table mutating exception.
Then - assuming at least Oracle 11, this will need to be split into individual triggers in earlier versions
CREATE OR REPLACE TRIGGER employees_update
  FOR UPDATE ON employees
  COMPOUND TRIGGER

  TYPE employeeNumberRec IS RECORD
    (oldEmployeeNumber employees.employeeNumber%TYPE
    ,newEmployeeNumber employees.employeeNumber%TYPE);
  TYPE employeeNumbersTbl IS TABLE OF employeeNumberRec;
  g_employeeNumbers employeeNumbersTbl;

BEFORE STATEMENT
IS
BEGIN
  -- Reset the internal employees table
  g_employeeNumbers := employeeNumbersTbl();
END BEFORE STATEMENT;

AFTER EACH ROW
IS
BEGIN
  -- Store the updated employees
  IF :new.employeeNumber  <> :old.employeeNumber THEN
    g_employeeNumbers.EXTEND;
    g_employeeNumbers(g_employeeNumbers.LAST).oldEmployeeNumber := :old.employeeNumber;
    g_employeeNumbers(g_employeeNumbers.LAST).newEmployeeNumber := :new.employeeNumber;
  END IF;
END AFTER EACH ROW;

AFTER STATEMENT
IS
BEGIN
  -- Now update the child tables
  FORALL l_index IN 1..g_employeeNumbers.COUNT
    UPDATE employees
    SET assignTo = g_employeeNumbers(l_index).newEmployeeNumber
    WHERE assignTo = g_employeeNumbers(l_index).oldEmployeeNumber;
  FORALL l_index IN 1..g_employeeNumbers.COUNT
    UPDATE customers
    SET salesRepEmployeeNumber = g_employeeNumbers(l_index).newEmployeeNumber
    WHERE salesRepEmployeeNumber = g_employeeNumbers(l_index).oldEmployeeNumber;
END AFTER STATEMENT;

END;

EDIT
In addition you will need to make the foreign key constraints that reference this table deferred e.g.
CREATE TABLE employees
  (employeeNumber NUMBER       NOT NULL
  ,lastName       VARCHAR2(30) NOT NULL
  ,firstName      VARCHAR2(30) NOT NULL
  ,email          VARCHAR2(50) NOT NULL
  ,officeCode     VARCHAR2(10) NOT NULL
  ,assignTo       NUMBER DEFAULT NULL
  ,jobTitle       VARCHAR2(100) NOT NULL
  ,PRIMARY KEY (employeeNumber)
  ,FOREIGN KEY (officeCode)
     REFERENCES offices (officeCode)
  ,FOREIGN KEY (assignTo)
     REFERENCES employees (employeeNumber)
     DEFERRABLE
     INITIALLY DEFERRED
  )

and
CREATE TABLE customers
  (customerNumber         NUMBER       NOT NULL
  ,customerName           VARCHAR2(50) NOT NULL
  ,phone                  VARCHAR2(20) NOT NULL
  ,address                VARCHAR2(70) NOT NULL
  ,city                   VARCHAR2(50) NOT NULL
  ,postalCode             VARCHAR2(15) NOT NULL
  ,country                VARCHAR2(40) NOT NULL
  ,salesRepEmployeeNumber NUMBER DEFAULT NULL
  ,PRIMARY KEY (customerNumber)
  ,FOREIGN KEY (salesRepEmployeeNumber)
     REFERENCES employees (employeeNumber)
     DEFERRABLE
     INITIALLY DEFERRED
  )

Note: if the constraint is violated this will cause an error at COMMIT not after an individual DML statement.
Comment: still show this problem @DrabJay " integrity constraint (RUMY.SYS_C0027919825) violated - child record found " and also thanks for helping me to know some new feature.
Comment: @RumyHasan You will need to make the foreign key constraints referencing employees.employeeNumber `DEFERRABLE`; and `DEFFERED` for this transaction, either thorough the table statement or via an `ALTER SESSION` statement.
Comment: I don't understand.so can you give me some example or any link which can help me?Notice that the above commented problem is happen when I want to update.
Answer: You can re-write the above trigger in following ways to avoid the issues:
create or replace trigger employees_update
before update of employeeNumber on employees
for each row
begin
emp_upd_trg_proc(:new.employeeNumber,:old.employeeNumber);
update customers set
salesRepEmployeeNumber = :new.employeeNumber
where salesRepEmployeeNumber = :old.employeeNumber;
end;
/

create or replace procedure emp_upd_trg_proc
(new number, old number)
is
pragma autonomous_transaction;
begin
update employees
set
assignTo = new
where assignTo = old;
commit;
end;

/
Comment: It is never appropriate to use an autonomous transaction to work around a mutating trigger error.  First off, it breaks transactional integrity-- the original update may be rolled back but the autonomous transaction cannot be, so you may be left in an invalid state.  The autonomous transaction cannot see data changes made but not committed by the triggering transaction so your procedure may generate a foreign key exception if it is trying to point the `assignTo` to a row that was inserted as part of the parent transaction.

On update triggering in oracle?


Searching for appropriate binary classification metric

Question: Problem:
I am working on a a binary classification problem with the following qualities:

Highly imbalanced
False Negative errors much more costly than False Positive
False Positives are only False until investigated; may become True Positives
True Negatives are by far the largest class
Spatial in nature (raster based)

I am searching for a threshold dependent binary classification metric that utilizes the quandrant of a confusion matrix (TP,FP,TN,FN) to assess the magnitude of True Positives realtive to the area of False Positives.  Preferably, this metric would use only Sensitivity and Specificity as these are the more commonly reported quantities in previous studies.  Below are examples of metrics that fit some requirements, but not all.
Prime Example:
The use of classification metrics and confusion matrices is not overly common in my problem domain, so there is not much to go on.  However, one metric that was proposed in c. 1990's, has been used (in a few different ways), and has a good intuiative intepretation for this problem is the Kvamme Gain statistic. This is bounded by $(-\infty,<1]$ with zero as the bounadry of random selection. The intuition is that is quantifies the percent of correctly classified positive observations relative to the region of of the observation space classified as positive.
pros of this metric are that it is bounded between 0 and ~1 for a better than random prediction, that it is easy to calculate, and that the contours of the metric are not parallel. I don't know how to explain that technically, but see image below.
cons are that it is bounded by $-\infty$ on the low end, that the contours are compressed towards (1-Specificity) instead of Sensivity, and that there are wide regions of equality even when the Sensitivity (the more important quality) is quite different.  I know this is a problem with any aggregate metric, but perhaps it can be lessened
Desired Metric:  I would like to have a metric that places more importance on a high sensitvity over a low specificity.  Essentialy a metric that shifts the contour lines of the values so that they compress towards high sensitvity. Meaning, with an equivlant KG (i.e. KG = 0.62), it is preferable to know if this result is derived from [sens = 0.95, spec = 0.35] over the eqivalent KG derived from [sens = 0.40, spec = 0.15].
Kvamme Gain:
$KG = 1 - ((1 - Specificity) / Sensitivity)$
or
KG = 1 - (% area predicted positive / % correctly predictied positive cases)
Other Examples:
I have explored similar metrics that are commonly used (e.g. Precision, Recall, TPR, TNR, PPV, Cohen's Kappa, etc...) and have not found a good fit in terms of behavior or intuition.  I have posted grids of the Positive Likelihood Ratio (LR+) and Youden's J below for comparison
LR+ is similar to KG in that the contours are asymetrical; even more so thatn KG, but also compressed towards the wrong axis.  The lack of an upper bound make cross model comparison a little tougher, but log(LR+) helps.
On the contrary, Youden's J is nicely confined between -1 and 1, but the contours are parrallel giving no weight to sensitivity.
Positive Likelihood Ratio:
$LR+ = Sensitivity / (1 - Specificty)$
Youden's J (Informedness, True Skill Statistic):
$J = Senstivity + Specificity - 1$
Plots
KG

LR+

Youden's J, Informedness, TSS
Answer: Not exactly what you asked but MATLAB's perfcurve function uses a ratio of the costs assigned to the classes in the confusion matrix and assigns weights to them by the number of classified observations as positive and negative.
Quoting from 1:

perfcurve computes OPTROCPT for the standard ROC curve only, and sets
  to NaNs otherwise. To obtain the optimal operating point for the ROC
  curve, perfcurve first finds the slope, S, using
  $$S = \frac{Cost(P│N)-Cost(N│N)}{Cost(N│P)-Cost(P│P)} \cdot  \frac{N}{P}$$
  Cost(N|P) is the cost
  of misclassifying a positive class as a negative class. Cost(P|N) is
  the cost of misclassifying a negative class as a positive class. P =
  TP + FN and N = TN + FP. They are the total instance counts in the
  positive and negative class, respectively. perfcurve then finds the
  optimal operating point by moving the straight line with slope S from
  the upper left corner of the ROC plot (FPR = 0, TPR = 1) down and to
  the right, until it intersects the ROC curve.

MATLAB also gives you the possibility of assigning your own weights on every class (true positives, false positives, true negatives, false negatives).
Although this metric is intuitive, they cite no evaluation of the method.
See more here:
https://ch.mathworks.com/help/stats/perfcurve.html


How can I determine how often an event occurs based on collected data how long one has to wait for an occurence

Question: This is an experiment I can only observe, not design/change.
I make the following observations: A police officer frequently monitors the same traffic location in the same manner. I see the officer arrive and I note the time. It then takes x minutes until an incident occurs, the officer chases that car, and the observation is over. At a later point, perhaps even another day, the officer returns, and the game starts again.
I have now a series of observations, x1..xn [in minutes]. It is thus trivial to calculate the mean and say "on average, one has to wait ... minutes to witness an incident". However, the statement I would like to make is "on average, .. incidents occur per day". I seems that should be possible, but I don't know how, and I suspect that just the average of wait times does not equal how frequently an event occurs on average.
Note: Key here is that the officer does not observe continually 24hrs. They arrive from time to time, and then it takes x minutes for them to witness something.
(Also to keep it simple assume a "perfect" officer who is invisible, sees exactly each incident while present and chases every incident they see.)
I don't have the statistical vocabulary, but what is special about this experiment is that observation is not continuous (observe around the clock), but rather like a sample, and the duration of that sample is not independent (observe for say 15min every day), but ends with an observation.
Bonus question: The way I worded it, the officer always stays indefinitely until an incident occurs. Sometimes, however, the officer "gives up" and just leaves without having observed an incident, and I would have a separate list of values, wait-time and no occurence. I have a gut feeling including this would make it much harder, but should be included, since I have that information.
Comment: Would it be fair to assume that the probabilities that an officer will observe an incident are independent for each minute? If so, then if you take the total time observed and the number of incidents you could get a probability of an incident in a given minute and then multiply that by 60*24 to get the expected incidents in a day. Someone else will probably tell me what I'm overlooking.
Comment: @ChrisUmphlett, it could be that simple, but I'm just not sure. If the officer would come randomly, stay always for x minutes and simply count the occurrences during these x minutes, your method seems sound. I just don't know if it matters that observation always ends with an occurrence. This may skew things.
Comment: I thought you said the police officer gives up sometimes? It would not always end with an occurrence then.
Comment: Yes, but just as an side question. Reality is, they come, do a couple and never come back. And if nothing happens, they leave after a long time. But that would all be too hard to model, so I said assume they always leave at an occurrence.
Answer: Such problems are very well modeled by Poisson random process. The classical case is how many minutes do you have to wait for a train to come to a station, given the already collected data on train arrivals.
You may want to look here for more information.
Comment: Thank you, I'll look into Poisson. Your link is quite technical, and of course does not have my example where occurrence ends observation. But it does appear to to be the right approach. I'll post when I look it through.
Answer: I think your problem is probably well-described as a Poisson process. You can describe the Poisson process in two ways: based on the number of events that occur in a certain time interval, or alternatively using waiting times $\Delta t$ between events.
If car accidents are following Poissonian statistics, and they probably are, then it doesn't matter when you start your clock, i.e. when the police arrive. However, if the presence of the police officer has an effect on the occurrence of accidents, then what you estimate won't be just the accidents per day, but the accidents per day given that a police officer is present (and these two probably differ).
The distribution of waiting times between events for a Poisson process is
$P(\Delta t) = \nu \exp(-\nu\Delta t)$, where $\nu$ is the frequency of accidents, i.e. the average number of accidents per unit of time. If you want to give the average number in a day, just multiply by the corresponding factor. As I said, if the process is Poissonian it doesn't matter when you start your clock, the interval you measure will follow that distribution. Also, it doesn't matter if you observe just one accident and quit. If the value of $\nu$ is the same for every day (warning, it might not!) then you can pool $\Delta t$ from different days together. You could gather your waiting times and make a histogram, and check whether they follow an exponential distribution or not. If they do, you can get the frequency just as $\nu = 1/\langle \Delta t \rangle$.
The assumptions underlying the Poisson process are (just copied from Wikipedia):

The occurrence of one event does not affect the probability that a second event will occur. That is, events occur independently.
The average rate at which events occur is independent of any occurrences. For simplicity, this is usually assumed to be constant, but may in practice vary with time.
Two events cannot occur at exactly the same instant; instead, at each very small sub-interval exactly one event either occurs or does not occur.

It seems to me that your problem fulfills these conditions reasonably. Actually, the fact that you don't measure continuously in the same place helps fulfill these conditions, because if an accident occurred in a certain place in a certain time, then shortly after this accident it will be less likely that a new one occurs since some sort of signalization or whatever might be present. But if you stop the observation after the accident, you will probably get observations that better fulfill the conditions of independence between events.
Regarding your bonus question: this can be described by a zero-inflated Poisson process. In a Poisson process, it could occur that in a certain time interval you don't make any observation. A zero-inflated Poisson process includes another source of zero observations, which are due not just by chance but by another process that leads to no observations. You can see it here https://en.wikipedia.org/wiki/Zero-inflated_model#Zero-inflated_Poisson, and the reference therein. In this case, the expression for the frequency based on the observation of waiting times might not be easy to get analitically.


Can all points in the plane be represented like this?

Question: Solving a task regaring affine geometry, I've come across a problem:
Is it  true that, for every point $(x,y)\in \mathbb{R}^2$, there  exist $t\in \mathbb{R}, \alpha\in[0,2\pi]$, such that
$$x = t\cos\alpha + \sin \alpha \\ y = t\sin\alpha + \cos \alpha?$$
I don't have any idea how to prove this or find a counterexample. All hints appreciated!
Comment: what about just solving for $\alpha$ and $t$?
Comment: @Ilya It's a 2-nd degree equation with 2 variables, I don't know how to start it, I've tried to use $\sin \alpha = z - t\cos\alpha$ in second equation, but still I can't get equation for $\alpha$
Answer: This can be written as
\begin{align}
&\left(\begin{array}{cr}
\tilde{x} \\ \tilde{y}
\end{array}\right)=\frac{1}{\sqrt{2}}\left(\begin{array}{cr}
1 &-1 \\ 1 & 1
\end{array}\right)\left(\begin{array}{cr}
x \\ y
\end{array}\right)=
\left(\begin{array}{cr}
t-1 & 0 \\ 0 & t+1
\end{array}\right)\left(\begin{array}{c}
\cos\left(\alpha+{\pi}/{4}\right) \\ \sin\left(\alpha+{\pi}/{4}\right)
\end{array}\right).\tag{1}
\end{align}
Since $(\tilde{x},\tilde{y})$ are obtained by rotation of $(x,y)$ by $\pi/4$, it suffices to show that any point in $\mathbb{R}^2$ can be represented by the right side of (1). This is equivalent to showing that for any point $P=(x,y)$ with $x,y\neq 0$ one can always find $t\neq \pm1$ such that the ellipse
$$\left(\frac{x}{t-1}\right)^2+\left(\frac{y}{t+1}\right)^2=1 \tag{2}$$
passes through $P$ (which is true - think on what happens to this ellipse when $t$ continuously decreases from $\infty$ to $1$, and then from $1$ to $-1$).
Comment: +1. You beat me. I took too long TeX-ing up my arrays for the same argument. :)
Answer: Let's play around and see what happens.
I write $a$ for $\alpha$,
$c$ for $\cos \alpha$,
and $s$ for $\sin \alpha$
cause I'm lazy.
We have
$x = t c + s$
and
$y = t s + c$.
$x^2+y^2 = t^2 c^2+2tcs + s^2 + t^2 s^2 + 2tcs + c^2
= t^2+1+4tsc$.
$xy = t^2 cs + tc^2+t s^2 + sc
= cs(t^2+1)+t$.
We can solve for $cs$ in each of these.
$cs = (x^2+y^2-t^2-1)/(4t)$
and
$cs = (xy-t)/(t^2+1)$
so
$(x^2+y^2-t^2-1)/(4t) = (xy-t)/(t^2+1)$.
Now we can solve for $t$.
$4t(xy-t) = (t^2+1)(x^2+y^2-t^2-1)$
or
$4txy-4t^2 = (t^2+1)(x^2+y^2) - (t^2+1)^2
= t^2(x^2+y^2)+(x^2+y^2)-t^4-2t^2-1
$
so
$t^4-t^2(x^2+y^2+2)+4txy+1=0$.
This is a quartic, unfortunately,
and I don't see an obvious root.
We can also do this:
$xs-yc = (tcs + s^2)-(tsc+c^2)
= s^2-c^2
= 2s^2 - 1
$,
so
$yc = xs-2s^2+1$.
Squaring this,
and using $c^2 = 1-s^2$,
we get another quartic for $s$.
In other words,
we can get equations for
$t$
and $\sin \alpha$,
but they are quartics.
Answer: Here is an attempt at a visual interpretation.
The equation is equivalent to
$$ \frac{ x - \sin \alpha} { \cos \alpha} = t = \frac{ y - \cos \alpha} { \sin \alpha},$$
$$ \frac{ y - \cos \alpha } { x - \sin \alpha} = \frac{ \sin \alpha} { \cos \alpha}$$
What this means, is that the slope of the point $(x,y)$ to the point $A=(\sin \alpha, \cos \alpha)$ on the unit circle, is $\tan \alpha$.
Comment: Set $\alpha = \pi/4$ and $t=-1$ to get $(0,0)$
Comment: @MarkBennet that is true. I forgot the -1, which is needed to make it the tangent.
Comment: I did the same and was going to post the same answer!


Broadcast SparseTensor in tensorflow

Question: I want to elementwise multiply a dense tensor with shape [n, n, k] with a sparse tensor that has the shape [n, n, 1]. I want the values from the sparse tensor to repeat along the axis with the size s, like it would do if I used a dense tensor instead and relied on implicit broadcasting.
However the SparseTensor.__mul__ operation does not support broadcasting the sparse operand. I didn't find an operator to explicitly broadcast the sparse Tensor. How could I achieve this?
Comment: Do you need to have it as a sparse tensor? You can always make it dense and multiply (it would be smaller than the other dense tensor anyway).
Comment: The dense tensor is broadcasted from the shape [n, k], so it is actually smaller too.
Answer: If you do not want to just convert the sparse tensor to dense, you can extract select the right values from the dense tensor to build a sparse result directly, something like this:
import tensorflow as tf
import numpy as np

with tf.Graph().as_default(), tf.Session() as sess:
    # Input data
    x = tf.placeholder(tf.float32, shape=[None, None, None])
    y = tf.sparse.placeholder(tf.float32, shape=[None, None, 1])
    # Indices of sparse tensor without third index coordinate
    indices2 = y.indices[:, :-1]
    # Values of dense tensor corresponding to sparse tensor values
    x_sp = tf.gather_nd(x, indices2)
    # Values of the resulting sparse tensor
    res_vals = tf.reshape(x_sp * tf.expand_dims(y.values, 1), [-1])
    # Shape of the resulting sparse tensor
    res_shape = tf.shape(x, out_type=tf.int64)
    # Make sparse tensor indices
    k = res_shape[2]
    v = tf.size(y.values)
    # Add third coordinate to existing sparse tensor coordinates
    idx1 = tf.tile(tf.expand_dims(indices2, 1), [1, k, 1])
    idx2 = tf.tile(tf.range(k), [v])
    res_idx = tf.concat([tf.reshape(idx1, [-1, 2]), tf.expand_dims(idx2, 1)], axis=1)
    # Make sparse result
    res = tf.SparseTensor(res_idx, res_vals, res_shape)
    # Dense value for testing
    res_dense = tf.sparse.to_dense(res)
    # Dense operation for testing
    res_dense2 = x * tf.sparse.to_dense(y)
    # Test
    x_val = np.arange(48).reshape(4, 4, 3)
    y_val = tf.SparseTensorValue([[0, 0, 0], [2, 3, 0], [3, 1, 0]], [1, 2, 3], [4, 4, 1])
    res_dense_val, res_dense2_val = sess.run((res_dense, res_dense2),
                                             feed_dict={x: x_val, y: y_val})
    print(np.allclose(res_dense_val, res_dense2_val))
    # True

Broadcast SparseTensor in tensorflow


Melody with only notes C, G, D, A

Question: Is there any well-known melody that only contains the notes C, G, D and A? I'm learning to play the cello, so far practicing only playing on open strings and would love to be able to play a melody.
Comment: It's not just the note names, it's the octave in which they are, So your tune won't sound too good, as the notes are spread out.
Answer: Not really. The only thing similar to using only those open strings - that I can think of - is a tune based on only the interval of a fifth - any two adjacent strings on the cello, but try the G and D - which is the "Winkie Chant" of the flying monkeys from the Wizard of Oz. I couldn't find any music notation so this description must suffice...

...the tonic (first) could be the G and the dominant (fifth) would then be the D.
Title   Over the Rainbow: The Wizard of Oz as a Secular Myth of America
Author  Paul Nathanson
Publisher   SUNY Press, 1991
ISBN    0791407098, 9780791407097

Melody with only notes C, G, D, A


Tokenizer that splits up words with underscores in them but also retains a full version

Question: I'm implementing an Elasticsearch search for content that has filesnames in it, such as
"golf_master_2009.xls". I'd like a tokenizer that splits this up into at least the following tokens: "golf", "master", "golf_master_2009.xml". Now I have to use wildcards (for example "master") if I want to search for it without specifying the full filename.
Answer: You can apply differents analyzers using a multifield field.
See http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html
HTH
Comment: Can you explain a little bit please on this particular case. thx
Answer: You can use your own analyzer with keyword tokenizer and word delimiter token filter (with options generate_word_parts and preserve_original set to true)


How to make inference based on a box-plot?

Question: 1) Write a comment about age comparing the box-plots at two levels of treatment compliance levels.
2) What are the interquartile ranges of BMI for comparing these two levels of treatment compliance levels?
3) From Age and BMI which variable is more related to treatment compliance levels and why?
Comment: Welcome to Cross Validated. You might want to take a look at https://stats.stackexchange.com/tags/self-study/info. Following these guidelines is likely to lead to more useful answers to your question.
Comment: *"From Age and BMI which variable is more related to treatment compliance levels and why?"* This seems like a question for some kind of course, exam or study. I consider this a nasty/tricky question (ie. badly designed because the point that should come across, I guess something about boxplots, interferes with the background of this matter 'BMI vs age')........
Comment: ....... It would be very much overinterpreting the experiment to make any conclusion just on these two boxplots alone. What we would need (instead) is a scatter plot of BMI vs age (and it is very common for BMI to increase with age) and make the comparison between compliance level by using different colour or some other difference between the points.
Comment: @SextusEmpiricus , yes, correct. But, the question was formed like this. I have tried to solve it first but can't find any logical way to solve it. Could you help to figure it out from the current question?
Answer:
This sounds a lot like a question for a course, exam or study. If this is the case then you should mention this because in that case the answer can be tailored with respect to the educational/didactical goal of the question/problem.
Anyway, here is some (incomplete) guidance:
...
We can find that the boxplot from this particular problem relates to research on hypertension. More specifically: Hossain, A., Mithila, O. Sleep duration and treatment compliance: a population-based cross-sectional study of hypertensive patients in Bangladesh. BMC Res Notes 9, 271 (2016).
The boxplot is used to describe the data from a questionnaire filled in by 101 participants in the study (out of 512 initial participants, from which 123 had hypertension and, from those 101 participated to fill in the questionnaire).
It is very nice that the study comes along with the original data, so we can make the following scatter plot age and BMI, where we color the points differently based on the compliance (the compliance was based on answers in the questionnaire).

In the particular study the researchers performed a logistic regression and found out that the coefficient for BMI is significant, but not the coefficient for age.
To me it seems that this questions is meant to stimulate you to learn (by experience/exploration) how to observe patterns based on boxplots. Sidenote: It is a bit mixed however. On the one hand the question 2 is asking for a very plain/straightforward/direct question 'what is the interquartile range?' which means that you just look up the definition of the IQR and apply it to the graph/plot (it is a bit tricky because the drawing of the boxes, and especially the whiskers, in box-plots may be done according to different definitions). On the other hand the questions 1 and 3 are more asking about interpretation of the plot.
I would consider this question (the parts 1 and 3) a bit difficult to answer and it depends on the meaning of the tutor/questioner how you should answer this question. There are several (subtle) concepts mixed together.

In the regression the coefficient for bmi is significant, and the coefficient for age is not. But,

This doesn't mean that the compliance doesn't correlate with age. This is because age correlates with bmi. In the boxplots you see that for both cases age and bmi the non compliance correlates with higher bmi and also with higher age.
In a regression the age is not significant, but that doesn't mean there is not an effect of age. A positive effect of age was found, but it is only not considered significant (it is not surpassing a level such that we can say this effect is unlikely/remarkable and should be considered an anomaly)

It is a nuanced case. Maybe the professor/tutor wants you to see that the boxes are very close to each other (they overlap). This means that there is not much difference between the two groups. However, even though the two boxes are much the same this doesn't mean that there isn't a tiny difference. This difference can be very accurately measured if you have a sufficiently large sample size. That is what is happening here (This is also why it is difficult to conclude anything, about signficance, from the boxplot alone. The regression, based on computation, is providing an additional and more quantitative support to our initial qualitative assessment).

If you like to replicate all of this then download the data and follow:
<code>### data
data <- read.csv("~/datacompliance.csv", header=TRUE, sep=";")

#converting the category for duration
data$Durationofhypertension <- as.factor(c(1,3,1,2,2,3,3)[data$Durationofhypertension])

### plotting
par(mar = c(3,3,1,1), mgp = c(1.5,0.5,0))
layout(matrix(c(2,1,4,3),2), widths = c(2,1), heights= c(1,2))

plot(data$Age,data$BMI,
     col=c(1,1)[data$FinalCompliance],
      bg=c(2,0)[data$FinalCompliance],
     pch = 21,
     xlab = "age", ylab = "bmi")

legend(25,38,c("no compliance", "compliance"),
       col=1, pt.bg=c(2,0), pch=21, cex=0.7)

### curve for BMI vs age
mod <- lm(data$BMI ~ data$Age)
t <- c(1:100)
lines(t,t*mod$coefficients[2]+mod$coefficients[1], lty = 2)

### boxplots
boxplot(data$Age ~ data$FinalCompliance, col=c(2,0)[data$compliancewithmedicine], horizontal=TRUE )
boxplot(data$BMI ~ data$FinalCompliance, col=c(2,0)[data$compliancewithmedicine])

### replicating the model from the article
mod <- glm(FinalCompliance ~ Age + Sex + MaritalStatus + BMI + Otherproblem.1 + FamilyHistory +
             smoking +  Sleephour + Durationofhypertension + FamilyHistory,
           family=binomial(link = "logit"), data=data)
summary(mod)
</code>


Nginx - can't open php files from a different directory -ERR: failed (13: Permission denied)

Question: I have set a nginx, php-fpm, mysql and phpMyAdmin on my laptop (running Arch Linux). Everything was ok till I tried to move the root in my home directory.
Here is the nginx configuration file I'm using:
#user html;
#user root root;

worker_processes  2;

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    gzip  on;

    server {
        ############### General Settings ###################
        listen       80;
        server_name  localhost;
        root   /home/me/Development;
        charset utf-8;

        ############## Document Root #####################
        location  / {
            index  index.php index.html index.htm;
            autoindex on;
        }

        ############## PHPMyAdmin #######################
        location /phpmyadmin {
            rewrite ^/* /phpMyAdmin last;
        }

        ############# Error redirection pages ################
        error_page  404               NGINX/html/404.html;
        error_page  500 502 503 504   NGINX/html/50x.html;

        ############## Proxy Settings for FastCGI PHP Server #####
        location ~ \.php$ {

            try_files  $uri =404;
            #fastcgi_pass 127.0.0.1:9000; (depending on your php-fpm socket configuration)
            fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi.conf;
        }

        location ~ /\.ht {
            deny  all;
        }

    }
}

When i try to reach a php file (localhost/phpMyAdmin) I get the following error:
2016/05/20 16:33:12 [error] 8145#8145: *2 "/home/me/Development/phpMyAdmin/index.php" is forbidden (13: Permission denied), client: 127.0.0.1, server: localhost, request: "GET /phpMyAdmin/ HTTP/1.1", host: "localhost"

I've tried to change the rights(777 -not really a good idea) and the owner (username:username) of "Development" folder but with no success.
also I have added in the nginx.conf file the following line:
user root root;

But this caused an error with the connecting of the php-fpm.
I also has this line of code in my php.ini to make sure the the new directory is allowed path for php.
open_basedir= /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/:/usr/:/home/me/Development/

Any ideas what I'm doing wrong?
Comment: Check the permissions of the parent directories.
Answer: Your home directory is protected from reading by other users. And starting nginx as root is a REALY bad idea. If you realy need your project to be located in your home directory try to start nginx and php-fpm as your user you login as. don't forget to chown all nginx service directories (/var/run/nginx and so on)
Comment: Great! I never thought of this.


Intuitive meaning behind f' = 0 implies inseparability

Question: Let $K$ be a field of characteristic $p>0$, and let $f(x)$ be a polynomial in $K[x] - K$.  We know $f' = 0$ implies that $f$ is not separable. A proof that works is that if it were separable then we could write it in distinct linear factors over an algebraic closure, and substituting a root of $f$ in $f'$ gives a nonzero answer, hence $f'$ could not have been zero.
But I don't intuitively see why $f' = 0$ implies inseparability.
Comment: Inseparability as a whole is not the most intuitive thing. I think that proof is not too unintuitive - you already know the connection between multiple roots and derivatives from, say, an earlier calculus or real analysis class, so all you have to check here is that that still works over general fields.
Comment: Perhaps you're right.
Answer: An argument which makes it bit more intuitive for me is that if $f' = 0$ then $f = g(x^p)$ for some polynomial $g(x)$. So when we look in an algebraic closure, we find that if $g(x)$ has $(x-a)$ as a linear factor, then $f$ has $(x - a^{1/p})^p$ in its factorization, hence not separable.


Is this question on topic?

Question: I would like to ask this question:

Title: What are the defining features of Capitalism?
Body: What are the necessary and sufficient conditions for an economic system (or mode of production) to be classified as "Capitalism"?
Is it markets? Is it for-profit corporations? Is it limited liability companies? Is it workers selling their labour to capitalists/employees? Is it freedom to set up companies? Is it a subset of these?
I imagine the answer would depend on a particular schools of thought and/or the view of particular economists, so in principle I would expect different answers.
Disclaimer: I am not interested in your opinion about what capitalism is and it is not. I am looking for authoritative answers, with proper references

Do you think this would survive a "too broad" or "primarily opinion based" flagging? I want to stress the point in the disclaimer, as I'm afraid eager newer users will be easily tempted to respond with their opinions.
Let me know if you think there is a way to salvage the question to make it (relatively more) on-topic.
Comment: "I am not interested in your opinion" - you might make this more general, eg I am not interested in opinions (yours or others') ... Otherwise it could invite answers that refer to published opinions.
Answer: To me the question looks on-topic (and also like a good question)!
But anyway, if people vote it as off-topic then they should explain why in the comments. It is always possible to edit a closed question and then flag it for a moderator to reopen.

Is this question on topic?