Can a 24-year-old learn to play violin/viola proficiently?

Question: I've seen a few of these questions asked, but it seems like most of the students to be where just starting out in music. They didn't have limber fingers, couldn't read notes. That's not a bad thing considering we've all had to start somewhere.

Question!
I'm wondering how long it would take an experienced musician going on 11 years of theory / guitar experience to make a half way decent player. Or if anyone else has been through a similar situation. Any information or tips to speed up the process would be appreciated.
I've been playing for a few weeks.
I've already studied the instrument in depth, including its construction.
I'm gaining proficiency in vibrato rather quickly, from what I understand, taking steps to avoid reinforce bad muscle memory whilst teaching myself.
I used to teach guitar.
I'm capable of reading the Alto and Treble clefs (minus the more difficult task of pairing the notes with the fretboard. That's still a work in progress).
I can make a clear sound and am starting work on pieces like Tchaikovsky's Possession (for vibrato practice) and Cello Suite No. 1 (for general practice).
I practice roughly 6+ hours per day. (Not continuous play, but rather attacking the instrument from every perceivable angle.)
Answer: There is a shortcut, yes. The secret is to practice smart.
I used to tell my students there is a difference between practicing and playing; between cleaning up all the difficulties and going into the small details, and playing just for fun or for others.
The more time you spend in cleaning grey zones, being careful with sound quality, with fast exercises (but only as fast as you can play without missing tones); the better.
When you clean a passage, scale, or arpeggio and play it many extra times, you are building a stronger platform for the rest of your playing.
I think about a pyramid: if you spend time building a large base, then you can go high; it's mathematics.
So, be tolerant and patient. If something sounds not good, spend an hour with it, then rest or play something else and return to the same point. Playing things in slow motion is both hard and extremely beneficial. Playing fast is also good, but not so fast that you lose control.
Exercise in a dark room--for hours. The lack of light will develop your ears and your muscle memory. It will make you play by ear. You will develop. If you play the same passage in a comfortable tempo (and not too long a passage, maybe like 4-10 bars) 10 times in a row, the human brain will find new details in it and you will develop, get an enhanced level of detail that will be there for the next passage, and everything will be faster afterwards as a result.
The answer to how many years is based on the individual, and also depends on the musical genre.
But start by being smart in the way you spend time with the instrument and record your self at least once every two weeks.
If you do this, you are on the right track.
Answer: If you've got 11 years of guitar and theory, with time and devotion you can most certainly become a proficient violinist.
I've got 6 years of music experience, and I picked up the cello a few months ago, and it's going well. The hardest thing about bowed string instruments is the bowing! If you buy your violin at a good respectable violin shop they will most likely be able to put learning tape on your instrument. Some people might look down on learning tape, but I feel that learning tape is very good for picking up bowed string instruments.
The tape serves a similar purpose to the frets on a guitar. Eventually you'll have to get rid of the tape, but for starting out, it'll be remarkly similar to playing guitar, except for the tuning which is the same as a mandolin for the violin. So if you've tinkered with a mandolin, you're off to an even better start.
Practice smart, practice for at least 30 minutes a day as often as possible, 4-5 times a week if you can. Also, focus on the bowing. The bowing is crucial. The fretting is different due to the lack of frets, but if you start with tape, you can side step that issue, but you need to bow correctly!
So go for it and have fun!
Answer: Just know that proficiency is strongly reliant on not only knowing where the notes are but having proper form because proper form makes it easier to play well.  If you do not have someone physically present who can instruct you on proper wrist, elbow and shoulder positions then I would make a careful study of professional violinists on video.  Watch how their wrists bend at the neck, the way they hold their bowing arm, how the bow arm elbow and wrist move at different tempos.
The above takes more words to describe what to look for than it takes effort to do this -- I do not mean to make it sound over complicated.
Answer: As a guitarist, you already know a lot of technique and theory, all which carries over to violin/viola. There are some things you will need to pick up on, though. If you choose to play viola, you will need to learn the alto clef.

Holding the instrument: it will take time to get used to the feeling of an instrument on your neck.
Moving the bow: you need to develop a straight bowing motion and learn all the techniques for good playing.
Left hand finger accuracy: It takes a lot of accuracy on violin/viola to play a note in tune. However, your guitar experience should help.
Taking care of instrument: There are a few things you need to do to make sure your instrument will be in good shape (rosin, tuning, bow, etc.)

As a good guitarist, it shouldn't be too too hard to learn! Since you know theory already and treble clef, you've got a head start. Violas play in alto clef, so that's something you might need to learn should you choose that. I am a violist, and I feel learning viola will have benefits you can't find with being a violinist. Good luck picking up a new instrument!
Answer: The fastest way to progress with a string instrument is with a good teacher.  If you develop bad habits with your position and technique, that will slow you down tremendously.
Adults can also benefit from the Suzuki method -- not just children.  This is a pedagogical approach which progresses very step by step, in an extremely efficient way.
Some teachers who have not been Suzuki trained use the Suzuki books but not the pedagogy -- avoid these.  True Suzuki trained teachers will be certified.
When you are farther along, you may be able to space your lessons farther apart, or work completely on your own.  But I would not recommend this for you at this time.
Usually people wait with vibrato until they have a good basic technique.


Manipulating primitive form of a VAR model

Question: Given a primitive form of a bivariate VAR(1) below,

and correspondingly in a matrix form below.

What were the steps involved in manipulating the matrices such that it resulted in this form below as the idea is to obtain a normal form VAR representation following these manipulations.
Answer: Just represent the vector as
$\left(\matrix{\gamma_{1,t}\\ \gamma_{2,t}\\}\right) = \left(\matrix{1&0\\0&1\\}\right) \left(\matrix{\gamma_{1,t}\\ \gamma_{2,t}\\}\right) $
then you just have to subtract the matrix with $\alpha_{i,j}$ effects from both sides and you get the matrix from the 2nd picture. Look that I manipulated the matrix and vector, because for some reason, the terms in the picture's vector are displaced.
$\left(\matrix{1&-\alpha_{1,1}\\-\alpha_{2,2}&1\\}\right)\left(\matrix{\gamma_{1,t}\\ \gamma_{2,t}\\}\right) = \left(\matrix{1&0\\0&1\\}\right) \left(\matrix{\gamma_{1,t}\\ \gamma_{2,t}\\}\right) - \left(\matrix{0&\alpha_{1,2}\\\alpha_{2,2}&0\\}\right)\left(\matrix{\gamma_{1,t}\\ \gamma_{2,t}\\}\right)$


String.Replace not working correctly

Question: This is very odd as I have used the Replace function for thousands of times. This is my code:
while (d.IndexOf("--") != -1) d=d.Replace("--", "-");

and this is the variable d's value when I trace:
"آدنیس,اسم دختر,girl name,آدونیس---گلی-به-رنگ-زرد-و-قرمز-که-فقط-هنگام-تابش-خورشید-باز-می-شود"

but it stuck when the value of d is:
"آدنیس,اسم دختر,girl name,آدونیس--گلی-به-رنگ-زرد-و-قرمز-که-فقط-هنگام-تابش-خورشید-باز-می-شود"

can anybody tell me why?
Its funny that even dashes are added programatically.
Comment: you realise how hard it is for non arabic readers to see the difference right?
Comment: @Stuart the loop doesn't stop. the indexOf returns a value different than -1 that is correct but the last "--" doesn't get replaced with "-" so the loop continues
Comment: My intention was to point out that it would have been cut down the ammount of text showing in your question so its easier to scan over, also there were a lot of characters included that look partially similar to the '-' character, If you had done this you would have received more of a response to your question
Comment: sorry - I don't understand why you think this is not working correctly - can you explain more? what does 'it stuck' mean?
Comment: @Stuart The replace is in a loop but the result contains two minuses that do not get replaced.
Comment: @Sayse as I have written, "I have used Replace thousands of times". this was the only string that it had problem. so I had to copy the exact text. By the way its not arabic, its Persian, and Im Turkish ;)
Comment: @Sayse by the way I got the answer in 2 minutes and the answerer has used my text and described well. It looks that they all have understood it. so there is no problem.
Answer: That is because this:
var d1 = "آدنیس,اسم دختر,girl name,آدونیس---گلی-به-رنگ-زرد-و-قرمز-که-فقط-هنگام-تابش-خورشید-باز-می-شود";

is not the same as this:
var d2 = "آدنیس,اسم دختر,girl name,آدونیس---گلی-به-رنگ-زرد-و-قرمز-که-فقط-هنگام-تابش-خورشید-باز-می-شود";

The last three characters in your string are not actually the unicode - Try it yourself:
var d1 = "آدنیس,اسم دختر,girl name,آدونیس---گلی-به-رنگ-زرد-و-قرمز-که-فقط-هنگام-تابش-خورشید-باز-می-شود";
var d2 = "آدنیس,اسم دختر,girl name,آدونیس---گلی-به-رنگ-زرد-و-قرمز-که-فقط-هنگام-تابش-خورشید-باز-می-شود";
while (d.IndexOf("--", StringComparison.Ordinal) != -1) d1 = d1.Replace("--", "-");
Console.WriteLine(d1); // the last characters are left
while (d2.IndexOf("--", StringComparison.Ordinal) != -1) d2 = d2.Replace("--", "-");
Console.WriteLine(d2); // All clear

Just FYI:
String comparison method indexof is culture specific. I would use:
var d = "آدنیس,اسم دختر,girl name,آدونیس---گلی-به-رنگ-زرد-و-قرمز-که-فقط-هنگام-تابش-خورشید-باز-می-شود";
while (d.IndexOf("--", System.StringComparison.Ordinal) != -1)
      d = d.Replace("--", "-");

Since it uses ordinal rules i.e. culture independent unicode values, and it runs faster.
Comment: greattttttt, I have used indexOf alot but never had this problem. Thanks alot
Comment: i have tried this code but it seems it's not working in my compiler, what am I missing? http://i.stack.imgur.com/jxswx.jpg
Answer: You can use Regex.Replace()
string _txt = "----------";
_txt = Regex.Replace(_txt, @"\-{2,}", "-");

this will output: -
Comment: the `replace` or `regex.replace`?
Comment: thanks a lot this solves my problem but i'm really confused could you tell me what is the problem with the replace?
Comment: oh i tried to debug the code, i am not expert with this but i did an infinite loop using the string on the question. maybe it has something to do with the encoding.
Answer: I've tested this with LinqPad - interesting.
// d0 succeeds:
var d0 = "world--life";

while (d0.IndexOf("--") != -1)
{
    d0=d0.Replace("--", "-");
    d0.Dump();
}

// d1 loops forever
var d1 = "world--life";

while (d1.IndexOf("--") != -1)
{
    d1=d1.Replace("--", "-");
    d1.Dump();
}

The difference between the two loops is that while they may appear identical, the second loop actually uses different Unicode characters for the hyphens in IndexOf to the ones in Replace
Looking at the MSDN docs:

IndexOf - http://msdn.microsoft.com/en-us/library/k8b1470s.aspx - This method performs a word (case-sensitive and culture-sensitive) search using the current culture. The search begins at the first character position of this instance and continues until the last character position.
Replace - http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx - This method performs an ordinal (case-sensitive and culture-insensitive) search to find oldValue.

So the difference is culture-insensitive versus culture-sensitive
Comment: I got the answer, it was interesting. have a look at it.
Comment: i didn't spot the difference between two loops

String.Replace not working correctly


Comparing means of two simple time series

Question: I'm trying to look for difference in timing (ie. earlier/later) in a variable measured at regular intervals between two groups.
This seems like a simple experimental design, and working in R, I'm able to visualize the data in a way that makes sense to me, but somehow I'm getting confused when it comes to testing for  significance.
The data consist of weekly measurements of number of flowers for each individual, within and outside of the greenhouse. To take a small example:
expand.grid(week=(1:6),treatment=c("greenhouse","outside"),individual=1:2)->df
c(0,3,10,2,0,0,0,0,0,2,18,0,0,1,19,0,0,0,0,0,1,2,15,1)->flowers
data.frame(cbind(df,flowers))->df

Visually,
qplot(week,flowers,data=df,facets=treatment~.)

If my interest is simply to determine whether there's a significant difference in the time of flowering between the treatments; should I be doing a repeated measures ANOVA and looking at the interaction?
Simplifying (?) the problem even further, what if I remove the quantity of flowers, and just consider how many individuals are flowering? So the summarized data would be
ddply(df, .(treatment,week), function(d) length(d[d$flowers>0,"flowers"]))->indiv

Which looks like this:
 qplot(week,V1,data=indiv,facets=treatment~.)

Here, my first thought was that I can just think of these as two distributions, and compare with a t-test; however, only individuals and not individualsxweek are independent, so perhaps this should also be a repeated measures ANOVA? Or do I need to venture into the world of more complex time-series math?
Thanks for your help!
Edit
As an update, I'm now also considering failure-time / survival analysis as a possible appropriate method.
Answer: My answer to   Tools to detect jumps in a linear time series could be of interest as it lays out strategies for testing the hypothesis of a constant mean when faced with two time series.What you are proposing is called Intervention Modelling where you know a priori when the series may have shifted and you want to test the hypothesis.Piggyback series2 behind series1: identify the ARIMA model within each series;Estimate a combined causal (0,0,.0,1,1.1) & the ARIMA structure.The test for the hypothesis isthe test for the 0/1 causal series. –


Quotient spaces of homeomorphic spaces

Question: Let's take $X$ be a regular connected space, and take $Y$ to be a connected regular subspace such that $X \cong Y$.
Is it true that $X/Y$ (we identify the elements of $Y$ as a point) homehomorphic to $X$ or to a point?
If my proposition is false, what can we say about such quotient spaces? If there exists a reference it also would be nice.
BTW: We can take general (or even more concrete spaces). I'm looking for interesting results (a classification of such spaces, for example).
For example, if we take $ X = \mathbb{R}$, and $ Y = (a,b) $ than we get: $ X/X \cong \{e\} $ and $ X/Y \cong X $.
Update: According to the comments the $ \mathbb{R} / (a,b) \not \cong \mathbb{R}$ so my example actually disproves the conjenture.
Comment: $\mathbb R/(a,b)$ isn't homeomorphic to $\mathbb R$.  It isn't even Hausdorff.
Comment: @user281392 OK, then take the cone of my space and there's still a lot of different results to get. -- More genreally: Let $Z$ be any connected space, $z_0\in Z$ a closed point. Let $X$ consist of countably many copies of $Z$, glued together at their $z_0$'s. If $Y$ is obtained by leaving out one of the copies of $Z$, then $X\cong Y$, and $X/Y\cong Z$.
Comment: We can get many different results. For example, if $X$ is countably many disjoint copies of $Z$, then $X/Y$ can be 42 disjoint copies of $Z$ plus a point
Comment: @HagenvonEitzen Noticed the hypothesis "connected"
Comment: @Aweygan thanks for your currection, I'll fix it.
Comment: @Aweygan just to clarify, is $\mathbb{R} /(a,b)$ not Hausdorff because $a$ and $b$ are distinct but there are no open sets separating them?
Comment: @OsamaGhani Yes, any open set containing either $a$ or $b$ also contains the point that $(a,b)$ was collapsed to.
Answer: Let $X$ be the annulus $S^1\times [0,1]$ and $Y$ the homeomorphic subspace $S^1\times[0,1/2]$. The quotient $X/Y$ is homeomorphic to a disk.

Quotient spaces of homeomorphic spaces


ssh connect view options

Question: When connecting via ssh like this:
ssh example.com

I'm assuming at some point all the command line and config options are all combined to form a full command with all the -o options passed to it, something like this:
ssh example.com -oForwardX11 no -oPubkeyAuthentication yes ...etc.

Is there any way to see what the exact command was?
I used the -vvv flags and they output a lot of info, just not exactly what I need.
Edit: Using OpenSSH 6.2, before the -G flag was introduced.
Answer: No, it does not. There is concept of configuration files, where you can set this values and if you don't set up them, the default ones are used. If you are interested in special value, it is quite easy to search for it in manual page man ssh) to find the default value and through you configuration files if you redefine it somewhere.
But if you are using recent openssh version (> 6.7 at least), you can use -G switch (from manual page):

-G
Causes ssh to print its configuration after evaluating Host and Match blocks and exit.

So trying:
ssh -G example.com

should give all information you want.
Comment: Thanks for the offer! I just ended up downloading Fedora 23, setting up a virtual machine to do this testing.
Comment: Thanks that a great tip, but I'm not using OpenSSH > 6.7. I know about all the options and config files, just want to get an output of the finally selected options. There are multiple config files and I want to see how they are all parsed, so I can write a python script to generate a valid ssh connection string with different parameters. Basically just want to test exactly how the command line options and config options are parsed and combined in different scenarios.
Comment: It is described in manual pages. This config option was added just recently (in last ~year) so if upgrading is not an option for you, I would recommend you to build latest version where you can do this "for free".
Comment: Thanks, but I really don't want to build from source, I'm using CentOS 7 and there doesn't seem to be any rpms available, even in the third party repos, epel etc.
Comment: I can build you one we are using in Fedora :) By the way, on current updated CentOS is version 6.6.1p1. It will not make a change in this case, but there are others.

ssh connect view options


*ngFor lado do cliente

Question: Estou implementando um crud onde estou a utilizar o ngFor para iterar uma lista. Porém não sei como faze-lo no lado cliente. Creio que isso só será possível criando um componente no meu main.js . Porém não tenho certeza.

var app = angular.module("crudlist", []);
app.controller("MyCrud", function($scope) {
    $scope.title = 'Músicas';
    $scope.musicas =[];
    $scope.id = 0;
    $scope.nome = '';
    $scope.album = '';
    $scope.ano = '';
    $scope.object = {};
    $scope.add = function(){
    $scope.object = {id: $scope.id ,nome:$scope.nome , album:$scope.album , ano:$scope.ano };
    $scope.musicas.push($scope.object);
    $scope.id += 1;
  };
   $scope.delete = function(){
    $scope.musicas.pop();
  };
   $scope.clone =  function(id){
   $scope.object = {id: $scope.id ,nome:$scope.musicas[id].nome , album:$scope.musicas[id].album , ano:$scope.musicas[id].ano };
   $scope.musicas.push($scope.object);
   $scope.id += 1;
  }
});

{{title}}

<input type="text" ngModel="nome">
<input type="text" ngModel="album">
<input type="text" ngModel="ano">
<button ng-click="add()" >Adicionar música</button>

      id
      Nome
      Albúm
      Ano

      {{item.id}}
      {{item.nome}}
      {{item.album}}
      {{item.ano}}
      <button ngModel="delete()" >Delete</button>
      <button ngModel="clone(item.id)" >Clone</button>

Comment: Altere `*ngFor="let item of musicas"` para `ng-repeat="item in musicas"` ... Veja a [**documentação**](https://docs.angularjs.org/api/ng/directive/ngRepeat).
Answer: Esta havendo uma confusão, ngFor e ngModel estãopresente na versão 2+ do Angular. Já no Angular 1 o correto é ng-repeat e ng-model:

var app = angular.module("crudlist", []);
app.controller("MyCrud", function($scope) {
  $scope.title = 'Músicas';
  $scope.musicas =[];
  $scope.id = 0;
  $scope.nome = '';
  $scope.album = '';
  $scope.ano = '';
  $scope.object = {};
  $scope.add = function(){
    $scope.object = {id: $scope.id ,nome:$scope.nome , album:$scope.album , ano:$scope.ano };
    $scope.musicas.push($scope.object);
    $scope.id += 1;
  };
  $scope.delete = function(){
    $scope.musicas.pop();
  };
  $scope.clone =  function(id){
    $scope.object = {id: $scope.id ,nome:$scope.musicas[id].nome , album:$scope.musicas[id].album , ano:$scope.musicas[id].ano };
    $scope.musicas.push($scope.object);
    $scope.id += 1;
  }
});

{{title}}

<input type="text" ng-model="nome">
<input type="text" ng-model="album">
<input type="text" ng-model="ano">
<button ng-click="add()" >Adicionar música</button>

      id
      Nome
      Albúm
      Ano

      {{item.id}}
      {{item.nome}}
      {{item.album}}
      {{item.ano}}
      <button ngModel="delete()" >Delete</button>
      <button ngModel="clone(item.id)" >Clone</button>

Referências

AngularJS API Docs
Angular Docs

*ngFor lado do cliente


OLS Regression with Endogenous Variables

Question: I know that endogenous variables will result in inconsistent OLS estimates, but what do these estimates actually turn out to be if we try to use an OLS linear regression? Anywhere I look is just simply telling me not to do it, but I'd be interested in seeing the relationship which does arise.
Say, for example, we have:

Where
 is not exogenous, though  is.
If we attempted to estimate the parameters by OLS, what estimates would we get, and how would these relate to the inconsistency arising from the endogeneity?
Comment: There is a derivation of the bias term that persists in large samples (hence, inconsistency) on slides 10-13 here: https://www.uio.no/studier/emner/sv/oekonomi/ECON4150/v17/lecture6_ols_multiple_regressors.pdf.  It addresses the case when there are no other predictors in the model besides the endogenous variable.  Are you specifically interested in the case when there is another variable included ($X_1$ in your case)?  That will require a more complicated answer, as it will depend on possible correlation between included predictors.
Answer: This is very general question, so I will try to make general sketch. Endogeneity in narrow sense is violation of condition $cov(X,u)=0$, in other words, in your example one of regressors $X_2$ is correlated with error term $u$.
All other things being fine (true model is linear, not other omitted variables etc.), we expect that OLS in your example will return us biased estimation $b_2$ of coefficient $\beta_2$. Biased in simple terms means that we systematically get wrong (shifted) value of the coefficient in question.
Notice that books warn us not to use such models if we are interested in relationship between $Y$ and $X_2$.
But if we are interested, say, in $\beta_1$ only, it might be fine, and $X_2$ is regarded as control variable in such cases (though, it doesn't mean that control variables must be endogenous).
Another class of cases where your model can be acceptable is if we what to simply predict some values of $Y$ without need to explain (or understand) causal relationships in the model. It it works for such a purpose, why not.
It is boring statement, but always choice of a model depends on real needs of the modeler.

Small numerical example
I will use Mathematica code and try to comment it.
Cook variables (for 20 observations).
SeedRandom[100]; u = RandomReal[{-1, 1}, 20];
x1 = Range[20];
x2 = Range[20, 1, -1] (u);

y = 5 - 1 x1 + 3 x2 + 6 u

Let us take a look at correlations between regressors and errors numerically and visually.
{Correlation[x1, x2], Correlation[x1, u], Correlation[x2, u]}

{0.295826, 0.182349, 0.866208}

It is fine to have some covariance between $X_1$ and $X_2$ in multiple regression models; the main thing here to avoid perfect colinearity.
Our OLS is as follows:
lm = LinearModelFit[Thread[{x1, x2, y}], {X1, X2}, {X1, X2}];
lm["BestFit"]

5.79933 - 1.05241 X1 + 3.45583 X2

You may see that we've got $b_2 = 3.45$ instead of expected $3$. How fine is that?
If we fit a model without endogeneity 1000 times we may build such histograms of coefficients (for $b_1$ to the left and $b_2$ to the right).

You may see that it is highly unlikely to get the point estimate that we have obtained from our model. We have got inconsistent estimate in the sense that $b_2$ does not approach to $\beta_2$ even if we had more data.
Nonetheless, we cannot get rid of $X_2$ to evaluate $b_1$ (because of some covariance between regressors). Notice that $b_1$ looks just fine.

You may also want to see geometry of endogeneity in simple OLS here.


Prove equality in discrete maths

Question: So I want to prove why those two are equal but I'don't know how.
$\exists x(A(x) \implies B(x))$ and $\exists x A(x) \implies \exists x B(x)$
I have a theory but I am not sure if that's the right way. First find their negatives:
1st: $\lnot(\exists x(A(x) \implies B(x)))  \iff \forall x(A(x) \wedge \lnot B(x))$
2nd: $\lnot(\exists x A(x) \implies \exists x B(x)) \iff \forall x A(x) \wedge ∀x \lnot B(x)$
then set $\lnot B(x)$ as $C(x)$ and then the proof is rather easy. I think though even if what I have written above is correct its kinda a roundabout way and there's got to be a better, any ideas?
Answer: They are not equal. Think about what each implication says when $A(x)$ is "$x=1$" and $B(x)$ is "$x=0$" .
Comment: What is there to prove? A counterexample is a proof that an assertion is false.
Comment: Shoot, you are right but yet again how to I prove that?

Prove equality in discrete maths


Fourier transform of $\frac{1}{\sinh(x \pm i\epsilon)\cosh(x \pm i\epsilon)}$

Question: I would like to calculate the Fourier transform of the following functions where epsilon is considered as a small positive number:
$$
\mathcal{F}_k\left(\frac{1}{\sinh(x \pm i\epsilon)\cosh(x \pm i\epsilon)}\right) := \frac{1}{2\pi} \int dx \ \frac{1}{\sinh(x \pm i\epsilon)\cosh(x \pm i\epsilon)} e^{-ikx} \,, \qquad \epsilon>0  \,.
$$
I tried to used the properties of the FT and some well known FTs then I get :
$$ \mathcal{F}_k\left(\frac{1}{\sinh(x + i\epsilon)\cosh(x + i\epsilon)}\right) = -\frac{i}{1+exp(-\frac{\pi k}{2})} $$
Comment: It seems that we have $$\lim_{\epsilon\to0^+}\mathcal{F}_k\left(\frac{1}{\sinh(x + i\epsilon)\cosh(x + i\epsilon)}\right) = -\frac{i}{1+\exp(-\frac{\pi k}{2})},$$ whereas $$\lim_{\epsilon\to0^+}\mathcal{F}_k\left(\frac{1}{\sinh(x - i\epsilon)\cosh(x - i\epsilon)}\right) = \frac{i}{1+\exp(\frac{\pi k}{2})}.$$
Comment: Yes I found the same results but using, as I said, the properties of the FT and some well known FTs. I would like to know your direct calculations if you do not mind of course.
Answer: To obtain the results presented by @HJames and @Sangchul Lee we can use contour integration.
First of all, $i\epsilon$ is needed only for setting the path of bypassing the poles.
($x+i\epsilon$) means that we go above $x=0$, and ($x-i\epsilon$) - below $x=0$.
Let's define
$$I_{+}= \frac{1}{2\pi} \int  \ \frac{e^{-ikx}}{\sinh(x + i\epsilon)\cosh(x + i\epsilon)} dx=\frac{1}{\pi} \int  \ \frac{e^{-ikx}}{\sinh(2x + i\epsilon)}dx=\frac{1}{2\pi} \int dx \ \frac{e^{-ikx/2}}{\sinh(x + i\epsilon)}$$ and $$I_{-}=\frac{1}{2\pi} \int  \ \frac{e^{-ikx/2}}{\sinh(x - i\epsilon)}dx$$
We can write $I_{+}=\frac{1}{2\pi}P.V.\int_{-\infty}^\infty  \ \frac{e^{-ikx/2}}{\sinh x}dx+\frac{1}{2\pi}\int_{C_{1+}}=J+\frac{1}{2\pi}\int_{C_{1+}}$, where $J$ - integral in the principal value sense, and $\frac{1}{2\pi}\int_{C_{1+}}$ - integral along small half-circle above $x=0$.
Let's first consider $J$ and the following rectangular closed contour ($R\to\infty$):

It can be shown that integrals along path $[1]$ and $[2]$ $\to0$ as $R\to\infty$.
We also have $\frac{e^{-ik(x+\pi i)/2}}{\sinh (x+\pi i)}=-\frac{e^{-ik\pi i/2}}{\sinh x}e^{-ikx/2}$. Our contour "catches" one pole at $x=\pi i$, and we get
$$J+\frac{1}{2\pi}\int_{C_{1+}}+Je^{-ik\pi i/2}+\frac{1}{2\pi}\int_{C_{2+}}=2\pi iRes_{x=\pi i}\frac{1}{2\pi}\frac{e^{-ikx/2}}{\sinh x}$$
Integrals along half-circles above $x=0$ and $x=\pi i$ can be easily evaluated:
$\int_{C_{1+}}=-\pi i$ and $\int_{C_{2+}}=-\pi i e^{-ik\pi i/2}=\int_{C_{1+}}e^{-ik\pi i/2}$
Finally we get:
$$\Big(J+\frac{1}{2\pi}\int_{C_{1+}}\Big)\Big(1+e^{\pi k/2}\Big)=I_{+}\Big(1+e^{\pi k/2}\Big)=-i\,e^{\pi k/2}$$
$$I_{+}=\frac{-i}{1+e^{-\pi k/2}}$$
In the same way $I_{-}$ can be evaluated - we have to integrate along the following contour:

In this case the pole is at $x=0$, and residual is simply $i$.
$$I_{-}\Big(1+e^{\pi k/2}\Big)=i\,\,\, \Rightarrow \,\,\, I_{-}=\frac{i}{1+e^{\pi k/2}}$$
Comment: Excellent! Thank you @Svyatoslav for your answer. For the second integral I_-, I used a rectangular closed contour around the real axis along x+i\epsilon and x-i\epsilon in order to relate I_+ and I_-.
Comment: Thank you, @HJames. It was also interesting to myself to clarify the issue. It seems to me that we should not drop unanswered questions and vaguely understood subjects ;)
Answer: Couple of identities that might be useful for things like this:
$$\sinh(2x)=2\sinh(x)\cosh(x)$$
$$\cosh(2x)=\cosh^2(x)+\sinh^2(x)$$
$$\tanh(2x)=\frac{2\tanh(x)}{1+\tanh^2(x)}$$
obviously in this case the top one is the important one. Another thing to take into account is the definition of the hyperbolic functions:
$$\sinh(x)=\frac{e^x-e^{-x}}{2}$$
and so when we have the $\sinh$ of a complex number the imaginary part will be an imaginary exponential, which can be represented in terms of trig functions.


Removing HTML entities in strings

Question: I have text that is retrieved on a linkbutton press:

When I press the button I am getting the following returned:
Test UAT's for release 2.2.0

It looks like HMTL entities are being retrieved. How do I turn these back into normal strings?
Answer: You don't need to remove the Html entities, actually the string that you are showing here is HTML Encoded so you just need to do Html Decoding to get it in normal form.
For that you have HttpUtility.HtmlDecode method.
string normalString = HttpUtility.HtmlDecode(myEncodedString);

If you are using .NET 4.0 or higher then you can also use WebUtility.HtmlDecode
Comment: must reference `System.Web.dll`
Comment: Please, take mention about WebUtility.HtmlDecode as primary way. It is better, because does not require System.Web.dll
Answer: Use HttpUtility.HtmlDecode to decode the string.

Removing HTML entities in strings


Sort a list of dates by month in python

Question: I have a list like this:
['25/May/2015', '27/May/2015', '27/Apr/2015', '27/Jan/2015', '07/May/2015' '22/May/2015', '16/Jan/2015', '29/Jan/2015', '28/Feb/2015', '18/Feb/2015', '08/May/2015', '20/Jan/2015', '24/Jan/2015', '31/Mar/2015', '30/Apr/2015', '17/Feb/2015', '19/Mar/2015', '05/May/2015', '22/Jan/2015', '14/Aug/2015', '26/Feb/2015', '14/Mar/2015', '28/May/2015']']

I want to order the dates by month: jan, feb, march, etc...
but also i want to order them by day, this means the first day must be: 1/jan/2015 then 2/jan/2015
i tried to sort the list:
days.sort()

BUT it´s ordering the list by days and not by months.
Any will be really appreciated
Comment: view [how-do-i-sort-this-list-in-python-if-my-date-is-in-a-string](http://stackoverflow.com/questions/2589479/how-do-i-sort-this-list-in-python-if-my-date-is-in-a-string)
Comment: you've got to try a little harder than *that*.
Answer: Try sorted with key.
from datetime import datetime
days_sorted = sorted(days, key=lambda day: datetime.strptime(day, "%d/%b/%Y"))

Comment: perfect, thanks. Can i ask u to explain to me how exactly this works?. I will mark it as correct in 5 minutes.
Comment: The key is to turn your strings into something sortable and that's `datetime` objects (`datetime.strptime`) here. `"%d/%b/%Y"` is just [format of your dates](https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior).
Answer: You are going to want to sort the dates by using your own comparison function. sort allows this, you just need to say list.sort(key=comparison_function). To make a function to compare the months in your list, one simple idea I came up with was
months = {"Jan":0, "Feb":1, "Mar":2, "Apr":3, "May":4, "Jun":5, "Jul":6, "Aug":7, "Sep":8, "Oct":9, "Nov":10, "Dec":11 }

Make a dict that turns each month into a corresponding number
def month_value(date):
    return months[date.split('/')[1]]

Write a function that takes one of your strings and returns the value of the second component of it.
dates.sort(key=month_value)

This will sort the dates in place, according to their month.

Sort a list of dates by month in python


How to easily extract 2x int16 from a int32?

Question: I have a variable that have 2x int16 values as:
int32_t value = 0x1234ABCD; // a=0x00001234, b=0xFFFFABCD

The naive solution is to do a mask:
int32_t a = (value & 0xFFFF0000) >> 16;
int32_t b = (value & 0x0000FFFF);

But with this, I don't have any sign expansion and b becomes 0x0000ABCD instead of 0xFFFFABCD.
My next attempt was to use an intermediate structure
struct dual_int16 {
   long hi:16;
   long lo:16;
}

int32_t a = (struct dual_int16)value).lo;
int32_t a = (struct dual_int16)value).hi;

Unfortunately my compiler doesn't allow me to do this "struct dual_int16 is not allowed" or "type of cast must be arithmetic or pointer".
Is there any correct way to extract my 2x int16 with sign expansion in C99?
EDIT
Because I am using a specific compiler (ADSP-21xxx) . I don't have all the standard types defined in stdint.h such as int16_t. My compiler does not recognize int8_t and int16_t.
The arch has an hybrid 32-48bits dual ALU, big endian.
Comment: You might want to try to store the 16-bit values in a 16-bit type.
Comment: Did you try casting to `int16_t` before converting to 32 bits?
Comment: What makes you think `0x1234ABCD & 0x0000FFFF` should become `0xFFFFABCD`?
Comment: You want int16 but define result as int32. The result is normal.
Comment: @BennoZeeman Because I store 2x int16. `0xABCD`= -21555. If you do the sign expansion the final value become `0xFFFFABCD` = -21555
Comment: @coin What compiler has `int32_t`, but no `int16_t`?
Comment: ok. so maybe you need to write arch specific code. maybe you could offer us the endianness info, length of `short`, `int` and `long`, and what standard library you have.
Comment: maybe we can investigate more. is right shift in your compiler arithmetic or logic?
Comment: It can be both depending on a configuration bit. I can of course use an assembly macro that do the trick. But I am looking for a more portable solution
Answer: If you want signed 16-bit values, use the proper type:
#include <stdint.h>

const int32_t value = 0x1234ABCD; // a=0x00001234, b=0xFFFFABCD

const int16_t a = (value >> 16) & 0xffff;
const int16_t b = value & 0xffff;

printf("a=%hd\nb=%hd\n", (short) a, (short) b);

This prints:
a=4660
b=-21555

Also note that I shift before I mask, to reduce the literal size of the masks. This is probably pointless with modern smart optimizing compilers, but that's the reason I changed it.
I used int16_t since you used uint32_t and mentioned C99, that really made me believe you should have it. Make sure you #include <stdint.h>.
Comment: If OP needs to store them into `int32_t`, I guess you could implicitly cast `int16_t` to `int32_t` by `int32_t a = (uint16_t)((value >> 16) & 0xffff);`.
Comment: I really don't get the `(uint16_t)` cast there, that's not what you said you wanted to do ... I'm quite skeptical to this suggestion.
Comment: I'm terribly sorry. I meant `int16_t`. I think you confused me by mentioning `uint32_t` in your answer. Oh dear.
Comment: Regarding reducing the literal size, you wouldn't want to do `(value & 0xFFFFFFFF) >> 16` anyhow, because right-shifting a negative integer is implementation defined behavior: you don't know whether it will fill up with zeroes (logical shift) or with the sign bit (arithmetic shift). The code you have written avoids this issue since you mask away the unwanted bits _after_ the shift.
Comment: @Lundin That's true, and perhaps another reason I switched to this pattern a long time ago. :) Thanks.
Comment: Oh and btw... nobody expects implicit integer promotion! A hex literal larger than 0x7fff is actually of unsigned type on a 16 bit system. This means that `value & 0xffff` will get promoted to an unsigned type, since 0xffff is then actually of type unsigned int. This could potentially cause a bug, but as far as I can see this particular code will be okay. Mixing signed integers with bitwise operators is always dangerous.
Answer: union will do the trick.
union {
    int32_t value;
    struct {
        int16_t v1, v2;
    } decomp;
} extract;

/* ... */
extract.value = value;
int32_t a = extract.decomp.v1, b = extract.decomp.v2;

notice that, a and b have desired signs.
Comment: Might work, but more work and more error-prone than the manual masking and shifting. Not all the world is little-endian.
Comment: @Deduplicator yeah. actually in big endian, it will do the trick too. but `v1` and `v2` are in reversed order. not necessary to be more error-prone than manual shift, since they are actually the same.
Comment: C99, 184.108.40.206: "When a value is stored in a member of an object of union type, the bytes of the object representation that do not correspond to that member but do correspond to other members take unspecified values.". I'm a bit lost now, but I'm pretty sure people should avoid it if they can. Low layer programming is different, because usually you're targeting a specific architecture etc.
Comment: Never read a member that has been written to by another member.
Comment: You're only supposed to read the field which was most recently written.
Comment: Sorry, I can't find it in the standard at the moment. But I have [an answer that backs me up](http://stackoverflow.com/a/252568/2703418).
Comment: @BennoZeeman not in c99 anymore, because value touch the whole union you are allowed to read from v1 and v2. Reading value after writing to v1 is not allowed.
Comment: @BennoZeeman decomposing bit/byte sequence using `union` is a regular trick in C, heavily used in low layer programming.
Comment: @BennoZeeman yeah. sometimes people will avoid that, if you are defining a `union` to represent a selection. that is something like `struct { enum myenum choice; union { /* some structs */ } value; }`. but in my case, it has to work in this way. not necessary to target a specific arch, if you are decomposing a stream in TCP/IP, you will be happy to use `union` too.
Answer: short a = (short)( (value >> 16) & 0xFFFF );
short b = (short)( value & 0xFFFF );

int32_t is not a standard type, as well (comment to @coin). short/short int is equivalent of int16_t.
Comment: What do you mean by int32_t is not a standard type? sizeof( short ) could be > 2.
Comment: Might be, or might not be equivalent. And it's a *standard*-typedef, if the implementation has a fitting type, in C99 (and probably back-ported).
Comment: It is comment from above: "Unfortunately int16_t doesn't exists with my compiler". For that reason I say that int32_t is also not a normal type.


Understanding simple LRT test asymptotic using Taylor expansion?

Question: I am trying to understand the proof that the LRT test for
$$H_0: \theta = \theta_0 \quad vs \quad H_1: \theta \neq \theta_0$$
is asymptotically $\chi_1^2$. I am reading the proof presented in Casella Berger (2002, Ch. 10).
They first use a taylor expansion to write the log-likelihood under the null as
$$\ell(\theta_0) = \ell(\hat{\theta}) + (\theta_0-\hat{\theta})\ell'(\hat{\theta}) + \frac{1}{2} (\theta_0-\hat{\theta})^2 \ell''(\hat{\theta})^2 +R_n$$
and then substitute this into the test statistic:
$$-2 \log \lambda (X) = -2 \log \frac{\mathcal{L}(\theta_0)}{\mathcal{L}(\hat{\theta})}=-2\left(\ell(\theta_0) - \ell(\hat{\theta})\right).$$
After doing this, I end up with
$$-2\log \lambda (X) = -2\ell(\hat{\theta})-2\left(\theta_0 - \hat{\theta}\right)\ell'(\hat{\theta}) - (\theta_0 - \hat{\theta})^2\ell''(\hat{\theta})-(-2\ell(\hat{\theta}))$$
$$=- (\theta_0 - \hat{\theta})^2\ell''(\hat{\theta})$$
since $\ell'(\hat{\theta})=0$ as it is the MLE.
However Casella & Berger arrive at
$$-2\log \lambda(X) = \frac{(\theta_0-\theta)^2}{-\ell''(\theta)}$$
I don't understand how the observed fisher information is in the denominator, when it is multiplied by $(\theta_0 - \hat{\theta})$ in the Taylor expansion.
Also, wouldn't we require it to be in the numerator anyway as $\sqrt{n}(\theta-\theta_0) \to \mathcal{N}(0, I^{-1}(\theta))$?
The proof in question can be found on page 489 here.
Comment: How to get $ln(\hat \theta)=0$?
Comment: For what is worth, I had a quick look and obtained the same result, it seems it would be in the numerator. I am curious to see if somebody have an explanation.
Comment: @user158565 $\hat{\theta}$ is the MLE. I meant $ln'(\hat{\theta})$ not $ln(\hat{\theta})$ sorry, typo
Comment: I am reading this book recently. I got the same derivation as yours. I believe there is a typo in the book here.
How is the $\chi^2_1$ then arrived at? We can go back to Theorem 10.1.12 of the same book, where it indicates that $\sqrt{n}(\hat\theta-\theta)\to n(0,1/I(\theta_0))$. So your guess on this distribution is correct.
Answer: it can be seen by using the properties of logarithms to bring an exponent in front:
$$ ln''(\hat{\theta}) = ln''(\hat{\theta})^{(-1)(-1)} = -\ln''(\hat{\theta})^{-1}$$
Comment: This does not provide an answer to the question. Once you have sufficient [reputation](https://stats.stackexchange.com/help/whats-reputation) you will be able to [comment on any post](https://stats.stackexchange.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/309382)
Comment: The Inverse of the ln, not that of value.


Definitions of relative compactness

Question: Per definition, a subset $A$ of a metric space $(X,d)$ is relatively compact if and only if its closure $\overline{A}$ is compact.
That means that any sequence in $\overline{A}$ contains a subsequence that converges in $\overline{A}$. Does that imply that $\partial A$ is compact?
According to an alternative definition, $A$ is relatively compact if any sequence in $A$ contains a subsequence convergent in $X$. How do you derive from this that $\partial A$ is compact?
In other words, how can you show that both definitions are equivalent?
Answer: Yes.
The boundary of $A$ is defined as
$$
\partial A=\overline{A}\cap\overline{A^c}.
$$
So $\partial A$ is a closed subset of a compact set, and hence compact.
Let $\{x_n\}\subset\partial A$. Since $\partial A\subset\overline{A}$ and $\overline{A}$ is compact, then there exists a subsequence $x_{n_k}\to x\in\overline{A}$. However,
$\{x_{n_k}\}\subset\partial A$, and since $\partial A$ is closed and $\{x_{n_k}\}$ convergent to $x$, then $x\in \partial A$. Thus every sequence in $\partial A$ possesses a convergent subsequence with limit in $\partial A$. Hence, $\partial A$ is compact.
Comment: @user1975053 I only use the fact that $\overline{A}$ is compact and $\overline{A^c}$ is closed.
Comment: @user1975053 See my further explanation.
Comment: But how do you get there from the alternative definition of relative compactness?
Comment: Ignore the first definition. How can you get from the second definition to the compactness of $\partial A$?
Comment: if any sequence in A contains a subsequence convergent in $\overline A$, can there be no sequences in  $\partial A$ without an in $\partial A$ convergent subsequence?
Comment: My problem is, the compactness of $\overline A$ is not part of the second definition of relative compactness of $A$. How do you get there from this second definition? (I have edited my question accordingly).

Definitions of relative compactness


Android Auto Scrolling EditText Hint

Question: problem with making edittext scrollable
there is mentioned that it is not scrollable with singleLine=true.
So i have 2 options:

I check if the user inputs "\n" and delete that, then i have to worry about things in the second line, too.
I use a custom textviews which scrolls through in a loop, could this be used here too only for the hint ?
 <com.test.ScrollingTextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginTop="1dp"
        android:layout_weight="0.17"
        android:background="@color/black"
        android:ellipsize="marquee"
        android:gravity="center_vertical"
        android:marqueeRepeatLimit="marquee_forever"
        android:paddingLeft="10dp"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text="@string/editLength"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/white" />

public class ScrollingTextView extends TextView {
public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public ScrollingTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public ScrollingTextView(Context context) {
    super(context);
}

@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
    if (focused)
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
}

@Override
public void onWindowFocusChanged(boolean focused) {
    if (focused)
        super.onWindowFocusChanged(focused);
}

@Override
public boolean isFocused() {
    return true;
}

}
I just cant get this formated right. Sorry for that.
Answer: Make your EditText Scrollable like this:
EditText yourEditText = new EditText(context);
yourEditText.setScroller(new Scroller(context));
yourEditText.setMaxLines(1);
yourEditText.setVerticalScrollBarEnabled(true);
yourEditText.setMovementMethod(new ScrollingMovementMethod());

Comment: yourEditText.setMaxLines(1); doesnt seem to work, gets split into 2 lines
Comment: are you looking to scroll horizontally ?
Comment: I actually dont want to scroll it, id rather let it scroll automatically, like with the TextView i posted above.
Comment: The answer does not help for auto scrolling the hint

Android Auto Scrolling EditText Hint


Como organizar conteúdo JSON

Question: noite!
Preciso da ajuda de vocẽs na seguinte questão:
Tenho 2 arquivos .json, porém ao abrir no notepad++ percebo que o conteúdo esta desorganizado.
Exemplo:
Arquivo1.json
{
"xxx.yyy.E-mail": "E-mail",
"xxx.yyy.Senha": "Senha",
"xxx.yyy.Voltar": "Volver",
"xxx.yyy.Enviar": "Enviar",
"xxx.yyy.Sair"  : "Sair",
}

Arquivo2.json
{
"xxx.yyy.E-mail": "E-mail",
"xxx.yyy.Voltar": "Volver",
"xxx.yyy.Senha": "Senha",
"xxx.yyy.Sair"  : "Sair",
"xxx.yyy.Enviar": "Enviar",
}

Se observarem a ordem está diferente!
Eu preciso ordenar o arquivo2.json pra que fique na mesma ordem do Arquivo1.json, isso tendo em consideração que os arquivos contém mais de 3000 linhas ao abrir no notepadd++.
Existe alguma forma de ordenar o conteúdo do json ?
Eu preciso organizar pra depois comparar os conteúdos linha por linha.
Obrigado desde já!!!
Comment: Se sua aplicação depende da ordem dos dados do JSON ela provavelmente tem um problema de arquitetura (ou nem deveria usar JSON, e sim algum formato "fixo", como texto puro). Sugiro repensar no problema real, que é primeiro interpretar o JSON na sua aplicação, e depois comparar os elementos individualmente.
Comment: Se quiser apenas comparar no editor de texto, selecione os 2 arquivos e ordene alfabeticamente. Depois aplique um diff nos arquivos (mas aí a questão talvez já esteja "quase fora" :P do escopo do site).
Answer: Primeiro gostaria de sugerir uma edição do seu Json para que o retorno fique legível, alguém pode mexer no código que um dia não seja você! Então faria algo no sentido:
   Escreva seu arquivo usando Javascript, se não souber como disponibilizo o link
   https://www.w3schools.com/js/js_json.asp
 var Json =
{
"xxx.yyy.E-mail": "E-mail",
"xxx.yyy.Senha": "Senha",
"xxx.yyy.Voltar": "Volver",
"xxx.yyy.Enviar": "Enviar",
"xxx.yyy.Sair"  : "Sair",
 }

Após isso Faria uma função de ordenação muito simples:
function OrdenarPorNome()
{
   Json.sort(function (a, b) { return a.Json > b.Json ? 1 : -1; });
}

Espero ter ajudado forte abc
Comment: Gabriel Lucchese, muito obrigado por responder e sua preocupação!!! Desculpa minha ignorância mais onde executo isso?
Eu não sou programador javascript, somente recebi os arquivos.
Pode me orientar mais por favor?
Comment: você deve escrever isto dentro de tags
Answer: acho que eu não deveria está fazendo isto, mas está ai.

var arquivo_json = document.getElementById("arquivo_json");
var ordenar = document.getElementById("ordenar");
var form = document.getElementById("form");

ordenar.addEventListener("click", function (evt) {
  if (form.checkValidity())
  {
    evt.preventDefault();
    var reader = new FileReader();
    reader.addEventListener("load", function (evt) {
      var json = JSON.parse(evt.target.result);
      var novo = {};
      Object.keys(json).sort().forEach(function (key) {
        novo[key] = json[key];
      })
      var blob = new Blob(
        [JSON.stringify(novo, null, 2)],
        { type: "application/json" }
      );
      var link = document.createElement("a");
      link.href = URL.createObjectURL(blob);
      link.download = arquivo_json.files[0].name;
      link.textContent = "download " + link.download + " ordenado";
      document.body.appendChild(link);
    });
    reader.readAsText(arquivo_json.files[0]);
  }
})
label {
line-height: 30px;
}
<form id="form" action="#">

    Arquivo JSON:
    <input id="arquivo_json" name="arquivo_json" required type="file" />

  <input id="ordenar" name="ordenar" type="submit" value="Ordenar" />
</form>
Comment: {
  "message": "Script error.",
  "filename": "",
  "lineno": 0,
  "colno": 0
}

Tobias Mesquita..... selecionei e apareceu isso
Comment: O seu json está mal formado, se estiver utilizando o exemplo que postou, terá de remover a última vírgula.

Como organizar conteúdo JSON


Some tokens show as "missing name or description" in status report

Question: Looking at a Drupal 7.43 maintenance project, my status report lists the following issue for Token 7.x-1.6:
<code>The following tokens or token types are missing required name and/or description information:

$info['types']['date']
$info['tokens']['node']['url']
$info['tokens']['file']['size']
$info['tokens']['user']['url']
$info['tokens']['date']['custom']
The following token types are not defined but have tokens:

$info['types']['node']
$info['types']['term']
$info['types']['vocabulary']
$info['types']['file']
$info['types']['user']
$info['types']['current-user']
</code>
I have cleared cache a few times, hit update.php, and ran cron a handful of times. This message never goes away.
It is causing RealName to no longer work, path aliases are not being made, and page title / meta tags are not appearing (all are driven by Token).
What is causing this and how can I fix it? I am unable to replicate the issue locally with the same database and same code.
Comment: Increased opcache memory from 64 to 128 M
Comment: Did you check you aren't missing some Drupal core files? As far as I can see, [`node_token_info()`](https://api.drupal.org/api/drupal/modules%21node%21node.tokens.inc/function/node_token_info/7.x) does define _node_ as token type (`'types' => array('node' => $type)`). Otherwise, there is a module implementing `hook_token_info_alter()` that is messing up things.
Comment: Yeah, it's all there. I don't see any shenanigans with hook_token_info_alter in contrib or custom modules.
Comment: A suggestion. Run the Hacked module and check if some file has been modified.
Comment: According to https://www.drupal.org/node/2256315, entity_tokens or the workflow module can cause problem.
Comment: @Kevin Did you find the solution for this ?
Tokens or token types missing name property
$info['types']['date']
$info['tokens']['node']['url']
$info['tokens']['file']['size']
$info['tokens']['user']['url']
$info['tokens']['date']['custom']

Please share your solution.

Thank you
Answer: In my case, the answer is related to the autoslave module: https://www.drupal.org/node/2898888
Also discussed here (not resolved), https://www.drupal.org/node/1265848#comment-12191146
Other mentions online about the PHP memory settings had no effect for me.
Hopefully this helps someone as the issue has been quite elusive.


$\int_{\mathbb{R}^3}|f(x)|^{3/2}dx\leq (\int_{\mathbb{R}^3}|\nabla f(x)|dx)^{3/2}$

Question: This is an old prelim problem that I'm doing for practice.
So suppose that we have $f,\nabla f\in L^1(\mathbb{R}^3)$.  Show that
$$\int_{\mathbb{R}^3}|f(x)|^{3/2}dx\leq (\int_{\mathbb{R}^3}|\nabla f(x)|dx)^{3/2}$$
I have absolutely no idea how to start this problem. I thought of using integration by parts or something akin to that, but didn't get anywhere.
EDIT: Note sure if it helps or not, but the inequality can be rephrased as.
$$ ||f||_{L^{3/2}}\leq ||\nabla f||_{L^1}$$
This seems like an inequality involving Sobolev spaces or the like.
Comment: Maybe this will be useful https://en.wikipedia.org/wiki/Poincar%C3%A9_inequality
Answer: This is the Gagliardo–Nirenberg–Sobolev inequality for $p=1$ and $n=3$.
Comment: Thanks! Also the wiki says it says for functions of compact support, but I'm guessing we just use a density argument for the general case.
Comment: Yes, you can use density for the general case.


How to avoid block IO operation when responding a user's request in asp.net

Question: I am working on WCF project hosted by asp.net/IIS. This WCF service has a Method called SearchImage, which looks like this:
string SearchImage(string query)
{
  //call bing service to get the images
  //it is very time-consuming
  return result.
}

The call to bing service is very time consuming. This can impact the service very much. Async call doesn't help here:
string SearchImage(string query)
{
  //async call bing service to get the images
  WaitForComplete();
  return result.
}

You can see, I still need to wait until bing returns result.
My question is, is there any technology to avoid this kind of block IO issue? Ideally, I want to tell asp.net to response when bing result is back.
Comment: Can you look at it from the other way around? Initiate AJAX on the webpage, and the AJAX handler then calls the WCF? That way the user get an immediate response from the website, and the WCF can take all the time it needs
Answer: No. What you have to do is return a complete web page, with javascript embedded (jquery is popular, though atlas can integrate with asp.net better) that will perform the async call after the page is already rendered, and then replace the relevant DOM section (usually tagged with a CSS id) with the contents that you loaded. That way, the user sees everything loaded but a throbber, which will be replaced by the final text, image, or whatever you're loading once it's ready.
You can make the async call go to your server, so that you can do the extra massaging server-side, but that's rarely worth the effort. Javascript can handle almost any massaging you need.
Comment: But it is a pure data service, no javascript/web page involved here. So there is no way to avoid block IO?
Comment: I'm not sure exactly what you mean, but if it's anything like web services, no, there's usually no way you can return partial results and then turn around and return more once the IO completes. Depends on the API, of course, but it looks like you're out of luck.
Comment: I see. Thanks, It seems I need to live with it. :-)
Answer: I once worked on a project where I needed to parse the website structure by recursively navigating to all internal links. I used a plain ASP.NET application as a frontend and a WCF service (don't remember if it was hosted in IIS or as a Windows service) which does the actual job.
Since the process of traversing all links can take a long time to complete (plus I needed to inform the user with the progress periodically) I implemented an asynchronous service operation (MSDN reference) for performing an actual parsing (was called server-side) and a synchronous one for pooling the status of the task (was periodically called client-side using AJAX).
This SO question contains some useful links regarding the subject: How to make a call to my WCF service asynchronous?
Hope this will help you a bit.
Comment: Sorry, it's still not relevant. My problem is not about async call for client.


Proof of convergence

Question: I have the following problem I want to solve with induction method. Would be great if someone helped me with it.
I have $a_0=0$, $a_1=$$1\over 2$ and $|a_{n+1}-a_n|\le|a_n-a_{n-1}|^2$
I need to show $a_n$ is convergent.
I need to show that the sequence is increasing and bounded. I use induction method:
$a_1\lt 1,$ I assume $a_n\lt 1$ and prove that $a_{n+1}\lt1$
$|a_{n+1}-a_n|=|a_n-a_{n-1}|^2\lt1\to|a_{n+1}-a_n|\lt1$ and since $a_n\lt1,a_{n+1}\lt1$
Is this true? How do I use induction to prove increasingness?
Help would be appreciated!
Thanks in advance!
Comment: The way the problem is currently worded, the sequence need not be increasing. At $n+1$ we can freely choose to go above or below $a_n$.
Comment: @AndréNicolas Can you elaborate a bit? I do not understand
Comment: @AndréNicolas Sorry I made a crucial mistake typing the question
Comment: If I may, why do you want to solve it by induction in particular? (and again, it does  not need to be increasing. Take $a_{n+1} = a_n + \frac{(-1)^n}{2^{2^n}}$ or something like that, for instance.)
Comment: What if $a_n =.9$ and $a_{n+1} = 1.8$ then $a_{n+1} - a_n < 1$
Answer: The sequence $(a_n)$ need not be increasing. For example, $a_2$ could be as high as $\frac{3}{4}$, but it also could as low as $\frac{1}{4}$. There is a similar available choice at every $n+1$.
I would suggest that you try to prove that our sequence is a Cauchy sequence.
Comment: I had a typo mistake in the question I corrected.
Comment: The correction does not change anything (whether it's $=$ or $\leq$, the issue is the same).
Comment: I made a minor modification of the answer, to deal with the change to $\le$. But in essence nothing changes. The sequence need not be increasing, and the suggestion to show the sequence is Cauchy still applies.
Comment: An alternative way would be to show that $\sum_{n=1}^\infty ( a_{n+1}-a_n )$ is an (absolutely) convergent sequence, which by telescoping will give that the sequence $(a_n)_n$ converges.
Answer: Define $b_n =|a_{n+1} -a_n | $ then $b_0 =\frac{1}{2} ,$  $b_{n+1} \leq b_n^2 $ thus $b_n \leq\left(\frac{1}{2}\right)^{2^n}$ and this implies convergence of $(a_n )$ because $$|a_{m} -a_n|\leq\sum_{j=0}^{m-n-1} |a_{m-j} -a_{m-j-1}|= \sum_{j=0}^{m-n-1} b_{m-j-1}\leq \sum_{j=0}^{m-n-1}\left(\frac{1}{2}\right)^{2^{m-j-1}}\to 0$$ as $m,n\to \infty.$
Comment: How can I take $b_{n+1}=b^2_{n}$? There is inequality

Proof of convergence


What hook can access every field label at once and change the label of one?

Question: I am trying to change the display label of one field on a node (not the form), depending on the value set in another field in Drupal 7. I don't want to change the label in the database, just on the final node page when you view it, if another field is set to a certain value.
I tried a few different hooks with no luck. Some can access every field, but only the value and not the label. Some can access the label on a per field basis which I can get half working (Set a flag in another function if the field is set correctly) but that only worked if the fields are checked in the right order.
So which painfully obvious hook will allow me to check a field setting and then edit the display of a label on another only on the node page? My perusing of the hook documentation and Google have not helped.
Thanks!
Answer: A guaranteed solution for all fields is hard. It depends on:

The field formatters you have chosen
the template files used

For a general approach try:
<code>/**
 * Implements hook_preprocess_HOOK().
 */
function YOUR_MODULE_preprocess_field(&$variables) {
  if ($variables['element']['#field_name'] == 'YOUR_DEPENDENT_FIELD' && !empty($variables['element']['#object']->YOUR_DEPENDENCY_FIELD)) {
    // YOUR LOGIC IN RELATION TO YOUR_DEPENDENCY_FIELD
    $new_value = 'something';
    $variables['label'] = $new_value;
  }
}
</code>
Notes:

This will change the label display everywhere, not only on a
node display. Since you don't mention anything about view modes, I
guess the given solution is good enough.
Make sure you sanitize $new_value if you are showing user input.
Comment: So, I can make this work but it has some issues (I think). Each call of hook_preprocess_field only has access to that field. I can't check the dependee field and then set the label for the dependent field in the same call. I would have to check the dependee field, set a variable in a custom function and then check that custom function for each call to hook_preprocess_field. This will only work if the 2 fields are called in the correct order. That is the case right now, but will likely change down the road.
Comment: You can manage all in once, no need for variable_set().
In that hook you have access to the complete object (node) the field is attached to. I take, that both the field you want to change, as the field you need to check are on the same node? You can access the field value you need to check: $variables['element']['#object']->YOUR_DEPENDENCY_FIELD.
Answer: Seems I forgot to log in last time and it's not letting me mark that as the answer. dmsmidt was exactly correct. I just had to dig a little deeper in DPM to find the info I needed. Thanks!


How do I query the DB when the dbPath is not default? MongoDB

Question: Previously I had been connecting to my db like this:
const db = 'mongodb://localhost/dbname';

mongoose.connect(db, {
  useMongoClient: true
});

After following along with a tutorial, I decided to change where my logs and db is stored. I changed my connection to:
const db = 'mongodb://localhost:5000';

mongoose.connect(db, {
  useMongoClient: true
});

And I created a mongod.conf:
# where to write logging data
systemLog:
  destination: file
  logAppend: true
  path: /Users/matt/mongodb/sampledb/logs/mongod.log

# Where and how to store data
storage:
  dbPath: /Users/matt/mongodb/sampledb/data/db
  journal:
    enabled: true

# network interfaces
net:
  port: 5000
  bindIp: 127.0.0.1

Now when I "show dbs" from the mongo shell, I am not sure "use" the db to query it. I figure I am missing a step somewhere.
Comment: `dbPath` has nothing to to with client interfaces or "database namespacing" in general at all. It's just a setting of the server process that determines the "physical location" of where the server files are stored. This has "zero" impact on your end application.
Comment: Looks like it. The format of the URI is basically `"mongodb://:@:/"` And the full description is [in the manual](https://docs.mongodb.com/manual/reference/connection-string/). If you don't specify a database namespace then `"test"` is used by default. Just as `localhost:27017` is presumed the default if not URI is provided at all.
Comment: Dude. `mongo 'mongodb://localhost:5000/dbname'` has been valid for a very long time. The shell is build on a driver afterall.
Comment: @NeilLunn That makes sense. I edited my question to include my new connection. Is my issue related to not having dbname after localhost:5000?
Comment: @NeilLunn Since I am able to save and retrieve documents using this setup, where are they saving to?
Comment: I already told you what the default namespace is.
Comment: @NeilLunn Turns out my problem was 2 fold. I needed to use a db name in the connection string (or use the default like you said) as well as use the --port command line option when starting the shell.
Comment: Clearly this was a very beginner question. I didn't realize I could access it like that.
Answer: My issue was my that I was using a non-default port. So instead of starting the mongo shell with:
mongo

I needed to start it with:
mongo --port 5000

I also added a name to my db in the connection:
mongoose.connect('mongodb://localhost:5000:/dbname', {
  useMongoClient: true
});


Question about Differential Geometry (Surfaces and Differentiability

Question: I have a doubt about differentiability.
Why if I have two regular surface, $S_1$ and $S_2$ $\in \mathbb{R^3}$ and a function $f: \mathbb{R^3} \to \mathbb{R^3}$ such that $f(S_1) \subset S_2$ differentiable, then we can define another function $g=f|_{S_1}$ it's also differentiable? This it's from a proposition of Do Carmo but I can't understand it. And even less can I understand why if it is differentiable we can say that $dg_p(v)=Df(v)$ $\forall p \in S_1$ and $v \in T_p (S_1)$
Answer: If you take $i_1:S_1\rightarrow \mathbb{R}^3$ the usual inclusion, then it's differentiable, so $g=f\circ i_1$ is the composition of two smooth maps, then is smooth.
rmk: The inclusion $i_1$ induces a injection $d(i_1)_p:T_p(S_1)\rightarrow \mathbb{R}^3$, so you can talk about $T_p(S_1)\subset \mathbb{R}^3$, and if you look at $g:S_1\rightarrow S_2$, you know that if $\gamma$ is a curve on $S_1$ with $\gamma(0)=p$ and $\gamma'(0)=v\in T_{p}(S_1)$ then $f\circ i_1(\gamma)$ is a curve in $\mathbb{R}^3$ but in fact is a curve in $S_2$ and you can derivative, in this case $dg_{p}(v)=df_{i_1(p)}\circ d(i_1)_p(v)\in \mathbb{R}^3$ but under the identification $T_{f(p)}S_2\subset \mathbb{R}^3$ as we say before with $i_2:S_2\rightarrow \mathbb{R}^3$ we see that $df_{i_1(p)}\circ d(i_1)_p(v)\in T_{f(p)}S_2$.
Comment: Sometimes when I am about to take an exam I feel like I am forgetting all but all the essential concepts. So, I'm very grateful for your help


Probability on cards involving two conditions .

Question: $\text{Problem (i) :}$

When $4$ cards are drawn out of $52$ cards, what is the probability of only $2$ cards  being  same value and the rest being different  ?

MY WORK:
The probability I found is :
$$\frac{\binom{13}{1}\times \binom{4}{2}\times \binom{12}{2}\times \binom{4}{1}\times \binom{4}{1}}{\binom{52}{4}}$$
$\text{Problem (ii) :}$

When $4$ cards are drawn out of $52$ cards,  what is the probability of $2$ cards to be of same value of same colour and the other two cards to be of same value ( different from the previous one ) of different colours?

MY WORK:
The probability I found is :
$$\frac{\binom{2}{1}\times \binom{13}{1}\times \binom{2}{2}\times \binom{12}{1}\times \binom{2}{1}\times \binom{2}{1}}{\binom{52}{4}}$$
Here,  I at first select a particular colour $\binom{2}{1}$ and then a particular value $\binom{13}{1}$  .  Then,  there is only single way of first condition. After,  I select a different value $\binom{12}{2}$ . For different colour,  I take $\binom{2}{1}\times \binom{2}{1}$ .
AM I CORRECT  ?
N. B.  Value means ace,  king,  jack,  queen and the numbers from $2$-$10$  .
Comment: By the way, Jack is the "full name" of the card just above $10$. It's not a nickname. ;)
Answer:
$$\frac{\binom{13}{1}\times \binom{4}{2}\times \binom{12}{2}\times \binom{4}{1}\times \binom{4}{1}}{\binom{52}{4}}$$

$\checkmark$ Select a rank and two suits for it, and select two other ranks, and a suit for each.

$$\frac{\binom{2}{1}\times \binom{13}{1}\times \binom{2}{2}\times \binom{12}{1}\times \binom{2}{1}\times \binom{2}{1}}{\binom{52}{4}}$$

$\checkmark$ Select a colour, a rank, and two suits of that colour for that rank, and select another rank, and a suit of each colour.
Answer: Your answers look good.
Another way to state the second one: Choose the color and rank of the color-matched pair, then from the $12$ ranks that remain, choose which of the $4$ color-mismatched pairs you want.


Mean and covariance of a mixture of two distributions

Question: This is a homework problem. If I could have some hints on how to solve it that would be great.
Mean and Covariance of a Mixture of Two Distributions:
$$ I = \left\{
  \begin{array}{l l}
    1 & \quad \text{if subject in group 1}\\
    0 & \quad \text{if subject in group 2}
  \end{array} \right.$$
Suppose $\mathbf{Z}=(Z_1,\ldots,Z_p)^T$ is a vector of measurements on a subject with mean and covariances: $$ E[\mathbf{Z}|I=1]=\mathbf{\mu}_1, \quad E[\mathbf{Z}|I=0]=\mathbf{\mu}_2\\Cov[\mathbf{Z}|I=1]=\mathbf{\Sigma}_1, \quad Cov[\mathbf{Z}|I=0]=\mathbf{\Sigma}_2$$
Let $p=P(I=1)$. Find $E[\mathbf{Z}]$ and $Cov[\mathbf{Z}]$.
My Attempt:
(This makes sense to me) $E[\mathbf{Z}] = E[E[\mathbf{Z}|I]] = E[p\mathbf{\mu}_1+(1-p)\mathbf{\mu}_2] = p\mathbf{\mu}_1+(1-p)\mathbf{\mu}_2$.
(Not sure about this one) $$ \begin{align*}Cov[\mathbf{Z}] &= Cov[E[\mathbf{Z}|I]] + E[Cov[\mathbf{Z}|I]]\\&= Cov[p\mathbf{\mu}_1+(1-p)\mathbf{\mu}_2] + E[Cov[\mathbf{Z}|I]]\\&= ???\end{align*}$$
Comment: The start of a solution is outlined at http://stats.stackexchange.com/questions/32699, where the question (implicitly) suggests computing the *raw* moments of the mixture and combining them (according to the definitions) to obtain the variances and covariances.
Comment: Thanks, I've gotten it figured out using $Cov[Z]=E[ZZ^t]-EZ(EZ)^T$ and some hints from this http://math.stackexchange.com/questions/147497/covariance-matrix-of-mixture-distribution
Answer: Here is my solution if anyone is curious (sorry it is so ugly):
We begin by finding the expected value using iterated expectation
$\begin{align*} E[\mathbf{Z}]&=E[E[\mathbf{Z}|I]]  \\ &= E[p\mu_1+(1-p)\mu_2]\\ &= p\mu_1+(1-p)\mu_2  \end{align*}$
Next we note that the group specific covariances can be written as
$\begin{align*} Cov[\mathbf{Z}|I=1] &= E[\mathbf{Z}\mathbf{Z}^T|I=1]-\mu_1\mu_1^T = \mathbf{\Sigma}_1\\   Cov[\mathbf{Z}|I=0] &= E[\mathbf{Z}\mathbf{Z}^T|I=0]-\mu_2\mu_2^T = \mathbf{\Sigma}_2\\   E[\mathbf{Z}\mathbf{Z}^T|I=1] &= \mathbf{\Sigma}_1 + \mu_1\mu_1^T\\   E[\mathbf{Z}\mathbf{Z}^T|I=0] &= \mathbf{\Sigma}_2 + \mu_2\mu_2^T  \end{align*} $
Using this same equation for covariance we get
$\begin{align*}  Cov[\mathbf{Z}] &= E[\mathbf{Z}\mathbf{Z}^T] - E[\mathbf{Z}]E[\mathbf{Z}]^T\\  &=E[E[\mathbf{Z}\mathbf{Z}^T|I]] - (p\mu_1+(1-p)\mu_2)(p\mu_1+(1-p)\mu_2)^T\\  &= E[p(\mathbf{\Sigma}_1 + \mu_1\mu_1^T)+(1-p)(\mathbf{\Sigma}_2 + \mu_2\mu_2^T)] - (p\mu_1+(1-p)\mu_2)(p\mu_1^T+(1-p)\mu_2^T)\\  &= p\mathbf{\Sigma}_1 + p\mu_1\mu_1^T+(1-p)\mathbf{\Sigma}_2 + (1-p)\mu_2\mu_2^T - (p\mu_1+(1-p)\mu_2)(p\mu_1^T+(1-p)\mu_2^T)\\  &=p\mathbf{\Sigma}_1 + p\mu_1\mu_1^T+(1-p)\mathbf{\Sigma}_2 + (1-p)\mu_2\mu_2^T - (p^2\mu_1\mu_1^T+p(1-p)\mu_1^T\mu_2+p(1-p)\mu_1\mu_2^T+(1-p)^2\mu_2\mu_2^T)\\  &=p\mathbf{\Sigma}_1+(1-p)\mathbf{\Sigma}_2+(p-p^2)(\mu_1\mu_1^T)-p(1-p)\mu_1^T\mu_2-p(1-p)\mu_1\mu_2^T+(p-p^2)(\mu_2\mu_2^T)\\  &=p\mathbf{\Sigma}_1+(1-p)\mathbf{\Sigma}_2+p(1-p)\left[(\mu_1\mu_1^T)-\mu_1^T\mu_2-\mu_1\mu_2^T+(\mu_2\mu_2^T)\right]\\  &= p\mathbf{\Sigma}_1+(1-p)\mathbf{\Sigma}_2+p(1-p)(\mu_1-\mu_2)(\mu_1^T-\mu_2^T)\\  &= p\mathbf{\Sigma}_1+(1-p)\mathbf{\Sigma}_2+p(1-p)(\mu_1-\mu_2)(\mu_1-\mu_2)^T\\  \end{align*}$


Calculate Harrell's C-index from random survival forest

Question: I'm fitting a random survival forest in R using the ranger package, and I'm curious about how the OOB error rate is calculated. According to the documentation it is calculated as one minus Harrell's C-index. However, calculating the C-index requires two components: the actual survival times, and the predicted survival times (or at the very least a rank-ordering of my observations by expected survival time).
I have the actual survival times. But how do I get the predicted survival times, or a rank-ordering of my observations by expected survival time? The random forest itself returns estimated hazard and survival functions. My first thought was to turn each estimated survival function into a pmf of survival time, and calculate the expected survival time from that. However in practice this seems intractable, at least without making non-trivial assumptions, because the survival functions are usually truncated (e.g. cumulative probability of survival never hits 0 but instead is cut off around 0.2 or some other non-trivial probability).
Is there some other way of comparing (truncated) survival or hazard functions to create a ranking of estimated survival times?
Admittedly my question is essentially the same as this one but I don't think there is an adequate response there either.
Comment: See subsection 5.2 of the original RSF paper: Ishwaran, Hemant; Kogalur, Udaya B.; Blackstone, Eugene H.; Lauer, Michael S. Random survival forests. Ann. Appl. Stat. 2 (2008), no. 3, 841--860. doi:10.1214/08-AOAS169. https://projecteuclid.org/euclid.aoas/1223908043
Answer: I believe I found the answer I'm looking for here (equation 5, under Prediction Error).
The statistic used to compare outcomes is $\mathcal{M}_i=\sum_{k=1}^{M}\hat{H_e}(t_k|X_i)$ where $t_1,...,t_M$ are the unique times in the data, $\hat{H_e}$ is the cumulative hazard estimate, and $X_i$ is the vector of covariates for observation $i$.
Answer: You need observed survival time, observed event status and the predictor from the model. See https://arxiv.org/pdf/1507.03092.pdf.
Calculating Harrell's C is not model specific. Using R code:
library(Hmisc)

#generate observed survival
  set.seed(42)
  censor <- rbinom(100, 1, 0.33)
  time <- rpois(100, 100)

#place in survival object
  obs_surv <- Surv(time, censor)

#generate a predictor from model of any kind
  predictor <- rnorm(100, 100,25)

#assess value of predictor on observed data
  rcorr.cens(predictor, obs_surv)

C Index  = 0.6004452
Comment: Yes, but how do I obtain the predictor from the model? The random forest returns estimated survival and hazard functions, not any particular statistic $\eta$ that can be plugged into the formula for Harrell's C (as far as I'm aware). Thanks.


Losing superfish menu item after logging out from administration panel

Question: I have a superfish menu as my nav menu bar. I customised it and added some pages for each menu item.
When I log out of the administration panel, as a general user I can only see the first menu item, all other menu items are gone.
[edit below]
Right, found out that the problem was because my other three menu items are all link to '.../add/node'. Superfish will not show empty links on the menu bar. However, I actually don't want some of the items link to anywhere as they all have submenu items. I want the link to remain empty so that the user can click on the submenu item. How can I achieve this?
Comment: checkout out your permissions. Admin user can access/view everything.
Comment: Hi, I have assigned permission to all for Menu(Administer menus and menu items) in 'People -> Permission', I also have cleared cache, but nothing has changed. Is there anything else I should assign?
Comment: can you see the menu items without superfish? try to create a custom menu from `admin/structure/menu` then assign the menu with superfish block `admin/structure/block` and see if you'll get the same result.
Answer: When an item in a menu tree is unavailable because of a lack of permissions, the entire tree below that item will disappear.
You should probably restructure your menu to use placeholders. Have a look at the Special menu items module.


Ajuda com JQuery $ is not a function

Question: Meu arquivo .js
$(document).ready(function () {

$("#uf").on("change", function () {
    atualizaProfissional();
});

$("#botao").on("click", function(){
    s = $("#municipio").val();
    if (s == 1){
        $("#imagem").attr("src","https://drglass.com.br/uf/popup1.png");
        $("#mensagem").html('Uhul! Nós atendemos sua região. Temos uma unidade de atendimento pertinho de você. Ligue agora mesmo e faça um orçamento.');
    }else{
        $("#imagem").attr("src","https://drglass.com.br/uf/popup0.png");
        $("#mensagem").html('Ops! Ainda não estamos na sua cidade. Mas muito em breve levaremos a melhor empresa de Vidros para sua região, consulte nosso plano de expansão.');
    }
});

function atualizaProfissional() {
    var options = {};
    options.url = "https://drglass.com.br/uf/listaCidades.php";
    options.type = "POST";
    options.data = { "uf": $("#uf").val() };
    options.dataType = "json";
    options.success = function (data) {
        $('#municipio').empty();
        for (var i = 0; i < data.length; i++) {
            $("#municipio").append("<option value='" + data[i].atende + "'>" + data[i].Nome + "</option>");
        }
    };
    $.ajax(options);
}
});

Como estou chamando:

Link do erro:
https://drglass.com.br/regioes/

Não tenho mais ideia de como resolver. Na minha máquina local, funciona de boa, quando faço o upload dá esse erro.
Comment: Veja esse artigo: https://stackoverflow.com/questions/12343714/typeerror-is-not-a-function-when-calling-jquery-function. O Wordpress já injeta um JQuery. Você está tentando reinserir a biblioteca. Veja como fazer aqui: https://pt.blogpascher.com/wordpress-tutorial/como-add-corretamente-the-code-jquery-on-wordpress
Comment: Uma pessoa postou a solução aqui e depois apagou. Muito estranho, mas consegui copiar o código a tempo rsrsr. Basta trocar a primeira linha por `jQuery(document).ready(function($){`
Answer: Caro Italo, eu não sei se tem haver, mas o próprio Wordpress adiciona isto:
Linha 103:

e na linha 381 você adicionou isto:

Pode ser a causa do conflito, realmente recomendo que remova o segundo jQuery, mesmo que não tenha relação com o problema, isso não esta certo.
Eu não consegui testar ou analisar mais coisas, eram muitos .js para olhar, mas já lhe adianto, se não for o primeiro problema citado, algo deve estar impedindo ou sobrescrevendo a variável global $, note que se usar jQuery funciona normalmente, provavelmente é alguma lib ou add-on, ou é proprio do wordpress que esteja usando jQuery.noConflict
O que você pode fazer é isolar o escopo fazendo isto:
(function ($) {

    $(document).ready(function () {

    $("#uf").on("change", function () {
        atualizaProfissional();
    });

    $("#botao").on("click", function(){
        s = $("#municipio").val();
        if (s == 1){
            $("#imagem").attr("src","https://drglass.com.br/uf/popup1.png");
            $("#mensagem").html('Uhul! Nós atendemos sua região. Temos uma unidade de atendimento pertinho de você. Ligue agora mesmo e faça um orçamento.');
        }else{
            $("#imagem").attr("src","https://drglass.com.br/uf/popup0.png");
            $("#mensagem").html('Ops! Ainda não estamos na sua cidade. Mas muito em breve levaremos a melhor empresa de Vidros para sua região, consulte nosso plano de expansão.');
        }
    });

    function atualizaProfissional() {
        var options = {};
        options.url = "https://drglass.com.br/uf/listaCidades.php";
        options.type = "POST";
        options.data = { "uf": $("#uf").val() };
        options.dataType = "json";
        options.success = function (data) {
            $('#municipio').empty();
            for (var i = 0; i < data.length; i++) {
                $("#municipio").append("<option value='" + data[i].atende + "'>" + data[i].Nome + "</option>");
            }
        };
        $.ajax(options);
    }
    });

})(jQuery);

Ou simplesmente adaptar tudo para jQuery()...

Ajuda com JQuery $ is not a function


Customizing Yarn container

Question: I'm testing spring-yarn integration API and I'm little confused about what is the best practice of Yarn container customization in terms of:
1) If I want to use spring-boot-yarn combo, what is the correct way of telling the spring boot to pick up my implementation of yarn container instead of DefaultYarnContainer...The only way I figured out was via ImportResource annotation at container project class containing main method, which was pointing to spring application xml with declaration:
<yarn:container container class="myhadoop.yarn.container.custom.MyContainerImplementation"/>

Component scan doesn't work at all...Spring boot was still using DefaultYarnContainer...
2) If I understand Yarn architecture correctly then application master is responsible for launching the container. But If I change DefaultYarnContainer for my implementation then I need to start container manually via run method, nothing was starting it, please what is the correct way?
Thanks a lot in advance for help
Comment: Anyone? Or do I need to add additional information?
Comment: You could also write something about why you want to have a custom container impl. Is there something what existing build-in features doesn't support?
Comment: Think I need to make docs better on this and provide a sample.
Answer: If boot is doing auto-configuration for yarn container, there are few ways to define the actual container which defaults to DefaultYarnContainer.
Logic of this can be found from here https://github.com/spring-projects/spring-hadoop/blob/master/spring-yarn/spring-yarn-boot/src/main/java/org/springframework/yarn/boot/YarnContainerAutoConfiguration.java#L107

Use spring.yarn.container.containerClass=foo.jee.MyContainer in yml
Create class as bean with name yarnContainerClass
Create your container impl as bean with name yarnContainerRef
Create bean as name customContainerClass which would be a class as string
Answer:
You don't need to implement all beans for container, just one is
  enough.

You're right. I didn't notice of the following method in SpringYarnConfig:
@Override
    public void configure(YarnContainerConfigurer container) throws Exception {
        if (StringUtils.hasText(sycp.getContainerClass())) {
            container
                .containerClass(sycp.getContainerClass());
        } else if (yarnContainerClass != null){
            container
                .containerClass(yarnContainerClass);
        } else if (yarnContainerRef != null) {
            if (yarnContainerRef instanceof YarnContainer) {
                container
                    .containerRef((YarnContainer) yarnContainerRef);
            }
        } else if (StringUtils.hasText(containerClass)) {
            container.containerClass(containerClass);
        }
    }

where it's clear that one is really enough...:)

Use of event publisher and state listener are really meant as building
  blocks what you'd need to call yourself.

Yes, I see that DefaultYarnContainer is handling notifyXXXX methods(fires up container state changes) calling by himself...Alright, I will definitelly play with it more.
Janne, thanks a lot for help. You provided perfect closer insight into Spring-Yarn.
Answer: Janne, thanks a lot! This way is far more elegant and it works...Here is what I did:
@EnableAutoConfiguration
@Configuration
@ComponentScan
public class ContainerApplication {

@Autowired
private MyContainerImplementation myContainerImplementation;

@Bean(name="yarnContainerClass")
public Class<? extends YarnContainer> getYarnContainerClass() {
    return MyContainerImplementation.class;
}

@Bean(name="yarnContainerRef")
public MyContainerImplementation getYarnContainerRef() {
    return myContainerImplementation;
}

@Bean(name="customContainerClass")
public String getCustomContainerClass() {
    return "myhadoop.yarn.container.custom.MyContainerImplementation";
}

public static void main(String[] args) {
    SpringApplication.run(ContainerApplication.class, args);
}

}
I added MyContainerImplementation into yml as you pointed and my container implementation was started by application master without me running the run method manually, because I see the following lines in the hadoop logs:
LifecycleObjectSupport:started
myhadoop.yarn.container.custom.MyContainerImplementation@5e2cd950
.
.
LifecycleObjectSupport: stopped
myhadoop.yarn.container.custom.MyContainerImplementation@5e2cd950

Anyway, I have additional question. I wanted to test low-level yarn things like ContainerStateListener and YarnPublisher, but they're not called at all..:-( Here is my test customized container:
@Component
public class MyContainerImplementation extends AbstractYarnContainer {
private static final Log log =    LogFactory.getLog(MyContainerImplementation.class);

public MyContainerImplementation() {
    super();

    log.info("...Initializing yarn MyContainerImplementation....");

    this.setYarnEventPublisher(new DefaultYarnEventPublisher() {
        @Override
        public void publishContainerAllocated(Object source, Container container) {
            super.publishContainerAllocated(source, container);
            log.info("Yarn container allocated: "+container.getResource().getMemory());
        }
    });

    this.addContainerStateListener(new ContainerStateListener() {

        @Override
        public void state(ContainerState state, Object exit) {
            switch(state) {
                case COMPLETED: {
                    log.info("...Container started successfully!...");
                    break;
                }
                case FAILED: {
                    log.info("...Starting of container failed!...");
                    break;
                }
                default: {
                    log.info("Unexpected container state...exiting!...");
                }
            }
        }
    });
}

public void runInternal() {
    log.info("...Running internal method...");
}

}
Do I need to add additional configuration to make ContainerStateListener and YarnPublisher to work?
Comment: You don't need to implement all beans for container, just one is enough. Use of event publisher and state listener are really meant as building blocks what you'd need to call yourself. With boot container execution logic starts from here https://github.com/spring-projects/spring-hadoop/blob/master/spring-yarn/spring-yarn-boot/src/main/java/org/springframework/yarn/boot/YarnContainerAutoConfiguration.java#L67 which is a boot `CommandLineRunner` and executes `YarnContainer`. Then it's really up to you to implement higher level features.
Comment: You know, if using boot based container, you don't event need to use any support libraries because from YARN's point of view its yarn container is just a process with exit value.

Customizing Yarn container


Can I ignore under-dispersion in my count data?

Question: I have under-dispersed count data. I do not want to transform them, and using a negative binomial error distribution (via glmer.nb) does not help.
My results are the same regardless of the distribution I use, and agree very well with the conclusion that you would draw by eyeballing the data (it is pretty obvious that there is no effect, see below). I can not seem to find any real way to deal with this problem, and I am left wondering if the most appropriate thing to do is acknowledge the under-dispersion, point to the result that is robust to every method I've thrown at it, and move on.
If you've been in this situation- could you share any tools/advice/philosophy that you found helpful?

Here is the output from my Poisson model:
mc_p <- glmer(tubes ~ status + (1|site/plant), family="poisson",
         data=mc)
summary(mc_p)

Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
 Family: poisson  ( log )
Formula: tubes ~ status + (1 | site/plant)
   Data: mc

     AIC      BIC   logLik deviance df.resid
    713.7    725.7   -352.8    705.7      143

    Scaled residuals:
          Min       1Q   Median       3Q      Max
     -2.08950 -0.38627 -0.04237  0.33830  2.87921

    Random effects:
     Groups     Name        Variance Std.Dev.
     plant:site (Intercept) 0.01958  0.1399
     site       (Intercept) 0.01790  0.1338
    Number of obs: 147, groups:  plant:site, 20; site, 4

    Fixed effects:
                Estimate Std. Error z value Pr(>|z|)
    (Intercept)  2.25665    0.08417  26.809   <2e-16 ***
    statusy      0.01356    0.05301   0.256    0.798
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

    Correlation of Fixed Effects:
            (Intr)
    statusy -0.308

I am trying determine whether pollen tube counts differ between nectar-robbed and un-robbed flowers. Pollen tube counts are nested within plant (multiple flowers of each type sampled from each plant) and plants are nested within site.
I've tried using a negative binomial error distribution (as I described in the first iteration of this post), but that still gave me a very high deviance relative to my residual df.
It seems that there isn't a straight-forward way to apply a useful error distribution to my nested data. At the same time, the result (that there is no difference between groups) is the same regardless of how I arrange my model, and can be seen very clearly in the bar-graph above.
Comment: I have a possibly silly question: why do you think your data are under-dispersed?
Answer: If the data are overdispersed, you can estimate the same relative rates and calculate prediction intervals as in a poisson model using a quasipoisson model. Even if the data are not overdispersed, a quasipoisson model is valid and fairly efficient. A quasipoisson model just extends the poisson by estimating a dispersion parameter.
It is, of course, important to think about the originating nature of the data, the question you're trying to answer, and to ask about why this dispersion comes about, and how it might affect your interpretation of the results.
Comment: @BioUser Over and under dispersion are basically the same thing: they show that the mean-variance relationship is not entirely correct. *Allowing* for dispersion means assuming that the mean-variance relationship is *at least* proportional to the one assumed under the usual fully parametric GLM model. In Poisson models: var=mean. Negative binomial models are more complicated. Note well: what you are calling underdispersion *may not necessarily be addressed by using a model that allows for dispersion*. It could be evidence of several things.
Comment: @BioUser Think of it this way: not all eggs contain salmonella, but you rarely worry about testing raw eggs for salmonella, you just use them in recipes where they are cooked. If the data are not over/under dispersed then, quasipoisson is a recipe which cooks the eggs. It tastes the same either way.
Comment: @BioUser that was a pretty substantial modification. You ought to post more about your data and what you're trying to actually find.
Comment: Thanks @AdamO. My data are actually under-dispersed, does this advice still apply? I've tried fitting them using glmer.nb, but it always hits the iteration limit, and I'm not sure what (if anything) I can do about that. IN regard to the nature of the data- I feel that it makes perfect sense that the data are distributed in the way that they are, and that there is no difference between the groups.
Comment: @BioUser Do you have any rationale for choosing a negative binomial probability model for these data? There are a lot of assumptions behind such a model, many idiosyncrasies compared to exponential family GLMs, and few tests of those assumptions. Have you tried fitting a poisson model?
Comment: AdamO, thanks again! Yes- I've tried fitting a Poisson model (which looks the most appropriate to me). How would I sort out whether I truly have underdispersion, and whether or not I should allow for dispersion? I've edited my question to include the output for my Poisson model.
Comment: I like the analogy. However- I can't use quasipoisson with mixed effects (eg, in glmer), correct?
Answer: A descriptively adequate treatment of under-dispersion can apparently be gotten from regression using a Conway Maxwell Poisson (COM) distribution or Consul's Generalized Poisson (GP) regression.  It seems that just modeling with a Normality assumption is inefficient.
A review paper and responses for the COM model are here and an R package to implement it is here.  A Stata package with references to the GP regression model is described here.
Full disclosure: I've never used these things in anger.
Comment: The COMPoisson is just being used as a conditional distribution, so it'd be the regression part of the package that failed to deal with nesting. It's possible there's another implementation that does that. The alternatives would be to be a) write out the likelihood function with nesting and maximize it with an optimizer (rather you than me), or b) write out the same model, add some sensible priors and run a multilevel model in JAGS (possibly more me than you), or c) Block bootstrap the standard errors to deal with the nesting (perhaps the more straightforward option).
Comment: Thanks @conjugateprior. However, I'm under the impression that COM-Poisson can't handle nested data. Is this incorrect?


How to establish and prove causality between two variables?

Question: I want to establish causality between two variables/attributes of some time series data.
Is there any method to prove and establish the causality mathematically?
Answer: I believe that "proving and establishing causality" is probably somewhat context-dependent. I am familiar with the high bar of academic economics, from when I was in grad school. In other settings, the bar may be lower because "proof" is really a matter of what is acceptable in the eye of the audience to whom you're offering that proof.
Here's my taxonomy of relationships:

Two things are not related
Correlation: simple mathematical relationship (though the thresholds of un-,weakly, and strongly correlated may be context dependent)
Association: Beyond correlation (and in fact, regardless of the strength of correlation), some sort of statistical model has found that indeed A and B move together after controlling for some other variables. But the relationship cannot yet be called causal, and/or the direction of causality cannot be proven.
Causality: This takes association further. There is theoretical support for the causal relationship of A causes B (and not B causes A); and there is also some kind of experimental support: a trial (ideally randomized), simulation or natural experiment, eg two states pass a law in different years and you compare the results of the law's effect on behavior during the time when only one state passed the law.
Comment: Thanks for the answer. So I will assume from the above comment that there is no standard and generic method or measure in mathematics which can do the job. We can at best have a correlation measure. Thanks for the help once again.
Comment: Yes I agree with you. But the thing is I just wanted to know if there is some method or measure with which I could at least tell the audience that this-this thing shows there could be a potential causal relationship between two variables
Comment: You've told us nothing about your data so how can I be more specific than that? My suggestion is that you give your audience theory that supports causality, and the strongest empirical/quantitative evidence you have (if not of your own then perhaps some other study that you can reference).
Comment: I am not having my data as such. I just wanted to know how this can be done. For example you can take the data as **percentage GDP invested in sports vs the number of medal that country wins in Olympics**. So for these kind of data sets, I wanted to know is there any generic method with which I can tell my audience or give them some idea that why I think there might be a causal relationship.
Comment: In that example the theory is clear: a country that spends more on sports will be better at sports. There should be ample empirical data: countries that have varies their expense, and then the outcomes are known. First, is there a correlation? Easy to discover. For causality if I was in the audience I'd want to make sure you had investigated, and with good reason disregarded, the possibility that countries that do well in the Olympics then decide to raise how much they spend which could make the causality go in the opposite direction.