I want to show that $\frac{i}{2\pi}\int^{2\pi}_0e^{(a+b)\cos\theta}\sin((a-b)\sin\theta-n\theta)d\theta = 0$

Question: So we have that $\theta\in\mathbb{R}$ and $a,b\in\mathbb{C}$, and $n\in\mathbb{N}$ and I have to show that
$$ \frac{i}{2\pi}\int^{2\pi}_0e^{(a+b)\cos\theta}\sin((a-b)\sin\theta-n\theta)d\theta = 0.$$
I have the tools of complex analysis.
So far I have tried using Euler's formula and gotten to the point where the above integral is equal to
$$ \frac{1}{4\pi}\int^{2\pi}_0 e^{ae^{i\theta}+be^{-i\theta}}e^{-in\theta}-e^{ae^{-i\theta}+be^{i\theta}}e^{in \theta}.$$
But I can't really get much further. Some help would really be appreciated.
Thanks.
Comment: Maybe we could use the Residue theorem.
Answer: Note that the integrand $$
f(\theta) = e^{(a+b)\cos \theta} \sin\left((a-b)\sin\theta - n\theta\right)
$$
is an odd function, and it is also periodic with period $2\pi$. In general, this always implies the integral over the whole period is $0$. Observe: $$
\int_0^{2\pi} f(\theta) d\theta =\int_0^\pi f(\theta)d\theta+\int_{\pi}^{2\pi}f(\theta)d\theta =\int_0^\pi f(\theta)d\theta + \int_{-\pi}^0 f(\theta+2\pi)d\theta = \int_0^\pi f(\theta)d\theta+\int_{-\pi}^0f(\theta)d\theta=\int_{-\pi}^\pi f(\theta)d\theta=0
$$
The integral of an odd function over a symmetric interval is always 0.
Comment: Ah yes, of course! Thank you so much!
Comment: Ah yes, of course! Thank you so much!
Answer: Use the property of definite integrals that:
$$I=\int_{0}^{2a} f(x) dx=\int_{0}^{a} [f(2a-x)+f(x)] dx=2\int_{0}^{a} f(x) dx,~ if ~~ f(2a-x)=f(x);$$ $$\implies I= 0, ~if~~(2a-x)=-f(x).$$
So for $$J=\int_{0}^{2\pi} e^{p\cos x} \sin[q\sin x-nx]~dx$$
Here $$f(x)=e^{p\cos x} \sin[q\sin x-nx], f(2\pi-x)=e^{p \cos x}\sin [q \sin(2\pi-x)-n(2\pi-x)]$$ $$=e^{p\cos x}\sin [-q ~\sin x+nx-2n \pi]=-e^{p\cos x}\sin [q ~\sin x-nx] =-f(2\pi-x).$$ Hence the required $J$-integral vanishes.
Answer: Let $ n\in\mathbb{N} $, $ a,b\in\mathbb{C} \cdot $
Condider the function : $ f_{n}:\mathbb{C}^{*}\rightarrow\mathbb{C},\ z\mapsto\frac{1}{z^{n+1}}\,\mathrm{e}^{az+\frac{b}{z}} \cdot $
Denoting $ a_{p}=\left\lbrace\begin{aligned}\frac{a^{p}}{p!},\ \ \ &\textrm{If }p\geq0\\ 0,\ \ \ &\textrm{If }p<0\end{aligned}\right. $, and $ b_{p}=\left\lbrace\begin{aligned} 0,\ \ \ &\textrm{If }p>0\\\frac{b^{-p}}{\left(-p\right)!},\ \ \ &\textrm{If }p\leq0\end{aligned}\right. $, we have that :
$ \ \ \ \ \ \ \ \ f_{n}\left(z\right)=\frac{1}{z^{n+1}}\left(\sum\limits_{p=-\infty}^{+\infty}{a_{p}z^{p}}\right)\left(\sum\limits_{p=-\infty}^{+\infty}{b_{p}z^{p}}\right)=\sum\limits_{p=-\infty}^{+\infty}{c_{p}z^{p-n-1}} $, where $ c_{p}=\sum\limits_{k=-\infty}^{+\infty}{a_{k}b_{p-k}}=\sum\limits_{k=0}^{+\infty}{\frac{b^{k}a^{p+k}}{k!\left(p+k\right)!}} $
Considering the coefficient of $ z^{-1} $ in the previous expansion, we get that $ \mathrm{Res}\left(f_{n},0\right)=\sum\limits_{p=0}^{+\infty}{\frac{b^{p}a^{n+p}}{p!\left(n+p\right)!}} \cdot $
The Residue theorem allows us to write that $$ \oint_{\left|z\right|=1}{f_{n}\left(z\right)\mathrm{d}z}=2\pi\,\mathrm{i}\,\mathrm{Res}\left(f_{n},0\right) $$
Taking $ z=\mathrm{e}^{\mathrm{i}\,\theta} $, gives the following $$ \int_{0}^{2\pi}{f_{n}\left(\mathrm{e}^{\mathrm{i}\,\theta}\right)\mathrm{e}^{\mathrm{i}\,\theta}\,\mathrm{d}\theta}=2\pi\,\mathrm{Res}\left(f_{n},0\right) $$
Since \begin{aligned}\Large f_{n}\left(\mathrm{e}^{\mathrm{i}\,\theta}\right)\mathrm{e}^{\mathrm{i}\,\theta} =\mathrm{e}^{a\,\mathrm{e}^{\mathrm{i}\,\theta}+b\,\mathrm{e}^{-\mathrm{i}\,\theta}-\mathrm{i}\,n\theta}&\Large=\mathrm{e}^{\left(a+b\right)\left(\frac{\mathrm{e}^{\mathrm{i}\,\theta}+\mathrm{e}^{-\mathrm{i}\,\theta}}{2}\right)+\mathrm{i}\left(a-b\right)\left(\frac{\mathrm{e}^{\mathrm{i}\,\theta}-\mathrm{e}^{-\mathrm{i}\,\theta}}{2\,\mathrm{i}}\right)-\mathrm{i}\,n\theta}\\&\Large=\mathrm{e}^{\left(a+b\right)\cos{\theta}+\mathrm{i}\left(a-b\right)\sin{\theta}-\mathrm{i}\,n\theta} \end{aligned}
Taking the imaginary part, we get that $$ \int_{0}^{2\pi}{\mathrm{e}^{\left(a+b\right)\cos{\theta}}\sin{\left(\left(a-b\right)\sin{\theta}-n\theta\right)}\,\mathrm{d}\theta}=0 $$


Can scp setup file mode of copied files?

Question: The man page of scp does not mention any mode option. Is there a way (or other program) that could setup the mode for transferred files?
Comment: What do you mean by setup the file modes ?
Answer: rsync has a --chmod argument, which sounds like what you are looking for.


Proper superset of intersection of nested collection of sets have proper subset in the collection?

Question: I am trying to prove (or disprove) the following statement

For arbitrary countable collection of sets $\{A_i\}_{i \in \mathbb{N}}$ that is non-increasing, i.e. $A_i \supseteq A_{i+1}$ for all $i \in \mathbb{N}$, and have a non-empty intersection, i.e. $\bigcap\limits_{i \in \mathbb{N}} A_i \neq \emptyset$, it holds that:
  If $B \subsetneq A_j$ for some $j \in \mathbb{N}$ and $\bigcap\limits_{i \in \mathbb{N}} A_i \subsetneq B$, then there exists some $k \in \mathbb{N}$ such that $A_k \subsetneq B$

However, all my efforts so far have failed. Intuitively it seems that the statement must be true, given that the intersection is (sort of) a limit for the sequence $A_i \supseteq A_{i+1} \supseteq \ldots$ and therefore one should be able to find $A_i$'s arbitrarily 'close' to the intersection, but I can't seem to find the right argument that it must be true (making we wonder if the statement is actually false), but I can't find any counterexamples either.
Any help would me much appreciated.
Answer: The result is false. Take $A_i=\{0\}\cup\{n \in \mathbb{N}~:~n \geq i\}$. These sets are non-increasing with nonempty intersection $\{0\}$. Let $B=\{0,1\}$. Then $B\subsetneq A_1$, $\bigcap_{i\in\mathbb{N}}A_i\subsetneq B$, yet there does not exist $k$ such that $A_k \subsetneq B$.


upright piano and apartment: how to prevent neighborhood problems?

Question: I am dealing a K-200 because I liked this piano very much. But I am concerned about possible problems with my neighborhood. Here's my detailed setup: I live in a concrete apartment, my floor is in porcelanate (original was ceramic, I just put porcelanate over the old ceramic floor), highest floor (10th, nobody lives above me, there's a playground/party hall above me specifically), the apartment right below me (9th) is vacant as is the one below it (8th)(the owners only come in specific holidays, since my town is good for tourism), the bedroom in which the piano will stay have no direct sharing walls with neighborhood (my apartment is in the corner and this bedroom is exactly the corner of the building. So the 4 walls are: behind the piano (front of the player): outside; left of the player: outside with a window; back of the player: my main bedroom wall, and right: my social toilet. Can you visualize?). There are no near buildings near my building - I can see the clean horizon from all my windows. However, there are 6 apartments per floor and I am worried about possible problems with collateral neighbors. There is a window in this bedroom that will be only 2 meters away from the piano (I will triple-glass soundproof it). The bedroom is small, 3x3 meters. The main door of the apartment is in the opposite extreme of the piano and there are 2 doors before it, so I'm not worried about corridor noise (I will further wind seal these doors anyway). What are my chances of problem here? Will the sound propagate to many floors below me, or to other units? What do you suggest?
My plan was making a decoupling that is just described as the following, from piano to ground order: rubber washing machine feet, decorative thin rug, MDF, thick rug, rubber mattress (a rug for kids playing over it), thick rug again and ground, so MDF spreads the pressure evenly through the sandwich. Moving away the piano from the back wall 25cm, dense eggcrate foam with points towards the soundboard, between the foam and the wall, a layer of dense rock wool glued or fixed in the wall somehow.
What are approximately my chances of success? Im losing my hopes and giving up an upright piano =( but I am simply not buying another digital piano...
Thank you very much.
EDIT:
I recently used a pvc foam adhesive tape to seal all my doors, and a set of 2 rolls of hard foam that is sold with this purpose, to seal the gap below the doors. My TV has 60" and is only 20cm away laterally from my main door of my apartment, i just set the volume of the TV to maximum (about 90 dB I think) and then I went to the corridor and shut the door, the sound was audible but like a soft whisper, almost hard to recognize the words. Airborne sound is easy to control and for me this part is done already (there is another door between this door and my piano, and this second door is sealed as well, so...). The piano dealer will let me test it for a week, the piano arrives tomorrow, if problems occur he will let me return the piano at no cost. I said rubber mattress up there, but it's actually an EVA mattress with about 1,5cm of width. Unfortunately some people marked this as duplicate, but I think every case is unique, as is the relationship of walls of my neighborhood with my apartment. Thank you very much for the answer.
Answer: The main problem with sound transmission from acoustic pianos is through the floor into the building structure. Since the piano is heavy, this is hard to eliminate.
I would start by getting some proper polyurethane sound-absorbing caster cups. Don't try to improvise - a set of 4 for an upright will probably cost about $100, which is cheap compared with the cost of the piano.
If that isn't sufficient, you can either soundproof the walls, or put sound absorbing material onto or inside the piano itself. But normally two sets of closed windows (in your apartment and the other one) will block out all the airborne sound transmission.
For doors and corridor noise, the important thing is to avoid any gaps around the door - fill them with draught excluder tape or something similar.
If none of that works, the only real solution is a false floor that doesn't transmit sound to the building floor - but that will be expensive!


CGAffineTransformMakeRotation() is resizing image on iPad?

Question: I'm my application I have a UIImage view that is set up with an image in my view's nib file. In the view did load method of my view controller I rotate the image using the following line,
<code>self.myImage.transform = CGAffineTransformMakeRotation(-126 * M_PI / 180);
</code>
Now on the iPhone version of my app my image is getting rotated by -126° just fine. However I've just recently started working on an iPad version of my app and when I use the above line of code to rotate the image it also gets resized?
As far as my eyes can tell it seems as though the width and height are being swapped?
Is there something I missed?
NOTE: If it helps i'm also setting the anchor point using,
<code>[myImage.layer setAnchorPoint:CGPointMake( 0.5, 0.857142857 )];
</code>
And i'm running the code in he iPad 4.2 simulator
Answer: "To fix the problem I had to adjust the Autosizing property of my UIImage in interface Builder, I enabled all the outer ones "bars" and disabled all the inner "bars" and that seemed to fix the problem."
Thanks Man , You are the life savior.. and Time too. :)
Answer: Well I've figured out my problem. First of all the only orientation that I'm supporting on the iPad is landscape mode, versus portrait mode on the iPhone version. By changing the orientation of the device the position of my image is also changing.
To fix the problem I had to adjust the Autosizing property of my UIImage in interface Builder, I enabled all the outer "bars" and disabled all the inner "bars" and that seemed to fix the problem.


SWT usando DATETIME com problema em salvar formato SQL compatível

Question: O problema é o seguinte: Tenho um programa de finanças pessoais que vai cadastrar alguns dados importantes, dentre eles a data do cadastro e data do vencimento. As interfaces do programa são feitas no Eclipse em SWT, e estou usando o widget DateTime, que utiliza uma instância do calendário nativo do windows e mostra na tela do programa.
Acontece que não consigo armazenar no banco de dados esse formato, pois ele não é compatível com nenhum tipo SQL, como Date ou TimeStamp. Eu já tentei converter esse valor pra String e pra Date, mas ele não aceita. Alguém tem uma idéia?
Espero ter deixado claro o problema sem a necessidade de postar código, pois é um problema de compatibilidade de formatos SWT com SQL. Se alguém usa SWT ou tem uma ideia de como mostrar um calendário resumido (dd/MM/yyyy) na tela, pro usuário acompanhar a data do cadastro e escolher a data do vencimento pra depois salvar no banco, eu agradeço o auxílio.
Comment: Pelo seu comentário na [resposta do Anthony](http://pt.stackoverflow.com/a/66696/4816), a solução que ele deu, funcionou - sugiro que você *aceite* a resposta dele, clicando no sinal de *certo*, no canto superior esquerdo da resposta. É desta maneira que retribuímos a ajuda que a comunidade nos presta.
Answer: Eu converteria para um tipo intermediário como Calendar (Java <= 7) ou LocalDate (no Java 8):
Calendar:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, dateTime.getDay());
calendar.set(Calendar.MONTH, dateTime.getMonth());
calendar.set(Calendar.YEAR, dateTime.getYear());
// Em alguns bancos como o Oracle tipo `DATE` pode incluir tempo
// Em bancos sem resolução de tempo não é necessário zerar os campos
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);

LocalDate
LocalDate instance = LocalDate.of(dateTime.getYear(),
        dateTime.getMonth() + 1, // SWT Retorna mes no padrão 0 - 11
        dateTime.getDay());

Daí para frente é questão de converter para um tipo sqlDate como você faria normalmente.
java.sql.Date sqlDateFromCalendar = new java.sql.Date(calendar.getTimeInMillis());
java.sql.Date sqlDateFromLocalDate = new java.sql.Date(Date.from(localDate
        .atStartOfDay(ZoneId.systemDefault()).toInstant()).getMillis());

Comment: Obrigado pela ajuda, usei o Local Date e funcionou perfeitamente.


Problemas com arrays em Javascript

Question: Bom, estou tendo alguns problemas com o seguinte trecho de código:
alert(lineOut[i].trim() + " - - " + lineOut[i + 1].trim());

Uncaught TypeError: Cannot read property 'trim' of undefined(…)

O array lineOut é um array preenchido dinamicamente, que no momento da execução do trecho acima conta com os seguintes valores:
lineOut = ["6", "Comentario"];

Alguém pode me dar uma luz do porquê deste problema estar acontecendo?
Comment: Quanto vale `i` no momento da execução?
Comment: Esse código está a correr dentro de um ciclo `for`? vejo um risco de `i + 1` ser maior que o index do ultimo elemento da array e dar `undefined` por causa disso. Como o @Emoon perguntou, qual é o valor de `i` e qual é o valor de `lineOut.length` quando esse erro ocorre?
Comment: @Emoon `for(var i = 0; i<lineOut.length; i++)` esse é o cabeçalho do meu loop.
Comment: @Sergio `i = 0` e `lineOut.length = 2`. Mas provavelmente eu estou estourando o índice do array mesmo. Vou desenvolver uma outra lógica pra resolver esse problema. Muito obrigado pelo comentário.
Answer: Seu código deve ser parecido com isso:
var total = lineOut.length;
for (var i = 0; i < total; i++) {
    alert(lineOut[i].trim() + " - - " + lineOut[i + 1].trim());
}

O problema é que na última iteração, o i vale (total - 1) e o array lineOut vai de lineOut[0], lineOut[1], ..., lineOut[total - 1]. Você está tentando pegar lineOut[i + 1], que é igual a lineOut[(total - 1) + 1], ou seja, lineOut[total], que está fora dos limites (só vai até lineOut[total - 1]).
Quando você tenta acessar algo fora dos limites de um array, o JS retorna undefined.
Comment: @Michele Akemi realmente é isso mesmo, vou adicionar uma condição pro `undefined`. Obrigado.

Problemas com arrays em Javascript


Iteration through OCaml lists with conditional statements

Question: New to OCaml, so all I can come here with is some pseudo.
I'd like to write a function which takes in a list, then returns a new list with only odd integers.
So, simply iterate through the list, possibly use %2 to find the odd integers, and append those into the new list.
Being new to OCaml, I've looked through what could be useful, such as map, rev_map, or iter, or possibly even filter?.
What would be the best to use, and how would you set it up?
Answer: The most suitable function is filter in List module. Look at its signature and description:
val filter : ('a -> bool) -> 'a list -> 'a list

filter p l returns all the elements of the list l that satisfy the
  predicate p. The order of the elements in the input list is preserved.

you should know how to supply the predicate for checking odd integers as clearly described in your question.
Another less elegant solution is:

Simply iterate through the list, and use an accumulator list to gather results.
If an element is an odd integer, prepend it to the accumulator.
Reverse the accumulator to get the correct order.

This solution involves in List.fold_left for accumulating results and List.rev for reversing a list.
Since you only ask which functions are appropriate, hopefully you're able to use them by yourself.
EDIT:
Because you shared your attempt on List.filter, here is one way to use it:
let odds xs = List.filter (fun x -> x mod 2 <> 0) xs

To be able to get further with OCaml, please take some time to read an OCaml tutorial. OCaml tag wiki has quite a number of good resources for getting started.
Comment: Thanks. Of course I'm able to browse around and probably take a good guess at what functions will work best, but I'm just having trouble understanding the syntax.

If I were to use filter, what I'm thinking would look something like:
let oddfunc mylist =
List.filter (mylist x -> [if{x%2!=0} then, append to list

As you can see, I have a very poor understanding of the ocaml syntax, and am mostly just jotting down my pseudo ideas..
Comment: The type that pad quoted tells you what you need to know.  `List.filter` takes a function and a list and returns another list.  The function tells whether you want the element to appear in the result or not.  So the next thing you need is a function that returns `true` if a number is odd.  It should work for any `int`, it doesn't have to (and shouldn't) know anything about `mylist`.
Comment: of course, instead of `List.fold_left` and reversing you could also use `List.fold_right`, but it's not tail recursive


Can you filter views user list result based on the current users role

Question: Is it possible to have the result of a views user list only contain users with a specific role that the current user also has?
I'm not familiar with Views, but it seems to fit the bill for making a better looking and more usable user list than the one that comes standard with Drupal. However, I need to have the user list filtered.
I setup multiple user groups that are identified by a specific role (like groupmember - group A). Admin users of that group have an additional admin role (like group manager), but they should only see users in their own group when using the view.
Can something like this be done? I'm writing modules so I could use the api if that is the way to go. I'm using Drupal 7.
Answer: As I understand, you want to create a view which list users which lists only those users who has a specific role or roles that the current user also has. The below approach can be a solution :

Add a field 'User: Uid' in your view (Let the view is of type 'Users').
Make the field as 'Exclude from display'.
Add a 'global php' field and add some code as below under 'VALUE CODE' :

$user_load = user_load($data->uid);
$data->user_role = $user_load->roles;
return ($data->user_role);

Here, we are getting the roles of each user being rendered.
Here used '$data->uid' instead of '$row->uid' to avoide issue of returning NID with $row in D7. Although in this case '$row->uid' returns correct information.
Make the field as 'Exclude from display' as well.
Under Filter Criteria add a 'global php' field and add the below codes :
i) Under 'Setup Code' :

 global $user;
 $roles = array();
 $view->roles = $user->roles;

Here we are getting all the roles of the current user.
ii) User 'Filter Code' :

 // Suppose you have five roles in the instance with the 'rid's as saved in
 // 'role' table as : 1 (anonymous user), 2(authenticated user), 3(administrator), 4(hr), 5(web admin)
 // Suppose ROLE you want be matched has RID = 4
 if (isset($view->roles[4])) {// Checking if the current user has the role that you want to be matched with
   if (!isset($data->user_role[4])) {// If the user getting rendered doesn't have that role
     return TRUE;// If TRUE is returned, then that row is NOT shown
   }
 }

Note : Considering, 'views_php' module is installed.
Note : If the current user doesn't have the role that you want be filtered for, then the view will list the default list of users based on other conditions.
Note : Instead of writing the 'rid' in the filter code directly, we can provide an admin menu which will render a custom form with a text field and, admin or user with required access permission, can set any role(s) through that form and save it in a drupal variable, and we can render the role information we want be matched from the variable inside our filter code.
Hope it helps
Comment: Awesome, that exactly pointed out how to manipulate the filters. I needed something a bit different, but you showed me the way! Thanks.
Two remarks: could you update your post and mention you need the [Views PHP module](https://drupal.org/project/views_php) for this?
And could you also mention at 5ii that if TRUE is returned, then that row is NOT shown? Maybe saves someone else an hour of feeling stupid ;-)
Answer: In Views, you can add a block showing those users which have the same roles as current user has:
An example of view block configuration:
The current user has to be autencitaded, so we'll be able to get his roles:
BLOCK SETTINGS -> Access: Role | authenticated user
Now, add contextual filters:
User: Roles
When the filter value is NOT available ->
Provide default value -> PHP code:
global $user;
if ($user->uid) {
  $roles = $user->roles;

  // unset 'authenticated user' ( related users doesn't have to be logged in )
  $roles = array_diff($roles, array('authenticated user'));

  // get roles keys
  $roles = array_keys($roles);

  // compose the arguments
  // in order to displaying only users with exactly the same roles as current user has
  // the arguments will be separated by commas.
  $arguments = implode(",", $roles);
  return $arguments;
}
else {
  return false;
}

Users might have multiple roles, so multiple values have to be allowed:
More -> check: Allow multiple values
That's all for this contextual filter. Save it.
Probably, you would need to remove the current user from the view, because he don't need his name on the list. To do that, add next contextual filter:
User: Uid
When the filter value is NOT available -> Provide default value -> User ID from logged in user
MORE -> check: exclude


output for the following c# snippet

Question: class Program
{

    static void Main(string[] args)
    {
        Program p = new Program();
        string s = p.ToString();
        Console.WriteLine(s.Length);
        Console.Read();
    }
}

The output I am receiving is 27
Why?
Answer: Because the string representation of Program class, basically it's full name (namespace and class name) as string has this number of characters.
Answer: The default implementation of the ToString method is to return the name of the type, so your string s contains the full type name of the Program class, i.e. something like "MySecondTestProgram.Program", and that is what you are getting the length of.

output for the following c# snippet


Outlook Express emails disappeared - can I get them back?

Question: A user opens his Outlook Express 6 (all windows updates up to date) this morning and finds that his inbox is empty.  200-odd messages that were there yesterday have disappeared.  I have checked that the View is set to All Messages, and it is.  No rules in existence.  New emails arriving are adding to the inbox.  Other folders (sent, deleted) have the same content as yesterday.
It seems to be the files related to the inbox had a problem, or physically got deleted, and OE6 just self-recovered by giving the user an inbox with nothing in it.
Is there anything I can do, other than scanning hard disk sectors for text, that may retrieve these lost emails?
Thanks.
Comment: If Outlook Express is configured to access a remote mailbox using IMAP then a likely cause of this is someone connecting to the same mailbox using POP and downloading (and deleting) all messages in INBOX (since that's all POP can access). This is likely to be through an action on the user's part (since it needs their password). Looking at mail server logs may shed light (and lead you to the POP client that has the downloaded messages).
Answer: Yes there is, restore from backup.
Then upgrade to something developed more recently than a decade and a half ago and is still supported with the likes of ongoing security patches from the vendor.


Elementary interpolation inequality between Lebesgue and Sobolev-Slobodeckij spaces

Question: Let $W^{s, 2}$ for $0 < s < 1$ denote the Sobolev-Slobodeckij spaces on the interval $(0, 1)$ and $L^2$ the Lebesgue space on the same interval.  I'm interested in an elementary proof that there exists $C > 0$ such that for any $f \in W^{s, 2}$ there holds
$$ \| f \|_{W^{s/2, 2}} \leq C \| f \|_{L^2}^{1/2} \| f \|^{1/2}_{W^{s, 2}}. $$
I'm not super comfortable with interpolation theory, but as far as I know one has $(L^2, W^{s, 2})_{1/2,2} = W^{s/2, 2}$ by the real interpolation method (and reiteration theorem), such that this estimate should be true. I wish to apply a very similar estimate in another context where I cannot use this abstract result directly, which is why I'm interested in an elementary proof of the inequality above.
Let for $0 < s < 1$ the Gagliardo semi-norm of $f \in W^{s, 2}$ be denoted by
$$| f |_{W^{s, 2}} = \left( \int_0^1 \int_0^1 \frac{|f(x) - f(y)|^2}{|x-y|^{2s+1}}\,\mathrm d x \mathrm dy \right)^{1/2}.$$
Then it is sufficient to prove that there is $C > 0$ such that for any $f \in W^{s,2}$ there holds
$$ | f |_{W^{s/2, 2}} \leq C \| f \|_{L^2}^{1/2} | f |^{1/2}_{W^{s, 2}}. $$
I tried to prove this estimate directly, but I can ultimately only prove
$$ | f |_{W^{(s+\mu)/2, 2}} \leq C_\mu \| f \|_{L^2}^{1/2} \| f |^{1/2}_{W^{s, 2}} $$
for $0 < \mu \ll 1$ with $C_\mu \to \infty$ as $\mu \to 0$. Using Hölder's inequality I estimate (omitting the bounds in the integrals for simplicity)
$$\begin{align}
| f |_{W^{(s+\mu)/2, 2}}^2
&\leq \int \int \frac{| f(x) - f(y) |}{|x - y|^{s+\mu+1}} \left( |f(x)| + |f(y)| \right)\,\mathrm dx \mathrm dy\\
&\leq 2 \int |f(y)| \int \frac{| f(x) - f(y) |}{|x - y|^{s+\mu+1}}\,\mathrm dx \mathrm dy\\
&\leq 2 \left( \int |f(y)|^2 \,\mathrm dy \right)^{1/2} \left( \int \left( \int \frac{| f(x) - f(y) |}{|x - y|^{s+1/2}} \frac{1}{|x-y|^{1/2+\mu}} \,\mathrm dx \right)^2 \mathrm dy \right)^{1/2}\\
&\leq 2 \left( \int |f(y)|^2 \,\mathrm dy \right)^{1/2} \left( \int \int \frac{| f(x) - f(y) |^2}{|x - y|^{2s+1}} \,\mathrm dx \mathrm dy \right)^{1/2} \left( \int \int \frac{1}{|x-y|^{1+2\mu}} \,\mathrm dx\mathrm dy \right)^{1/2}
\end{align}$$
such that
$$ |f|_{W^{(s+\mu)/2,2}} \leq C_\mu \|f \|_{L^2}^{1/2} |f|_{W^{s,2}}^{1/2} \quad\text{with} \quad C_\mu = \sqrt 2 \left( \int \int \frac{1}{|x-y|^{1+2\mu}} \,\mathrm dx\mathrm dy \right)^{1/4}. $$
But there holds $C_0 = \infty$ as the integral in the constant is unbounded for $\mu = 0$.
As an alternative approach I again used only Hölder's inequality to show that for any $0 < \mu \ll 1$ there holds
$$ |f|_{W^{s/2,2}} \leq \operatorname{ess\,sup}_{(x, y) \in (0, 1)^2} | x - y|^{\mu/2} |f |_{W^{\mu, 2}}^{1/2} |f|_{W^{s,2}}^{1/2} $$
but I read in the Hitchhikers Guide to Fractional Sobolev Spaces that only $\lim_{\mu \to 0} \mu |f|^2_{W^{\mu, 2}} = C \| f \|_{L^2}^2$ holds and the essential supremum in the last inequality is actually $1$, so the constant again blows up as $\mu \to 0$.
Comment: For the interval maybe it is easy to use Fourier series? Haven't checked your calc so maybe it runs into the same issue?
Comment: With the Fourier approach the estimate follows easily, which is interesting, thanks for the hint. Looking through the derivation in the Hitchhiker's Guide this seems to stem from the ability to estimate $f(x) - f(y)$ sharply. I would like to see a technique which works using the Gagliardo representation though.
Comment: huh, I wish it was a 'hint', which would imply I knew that it would help! Glad to have helped :):) perhaps you could write a sketch as an answer
Comment: might be too early to say but it looks like the bounty didn't help. Sorry!
Answer: Using a Fourier approach the interpolation inequality follows easily. In contrast to the original question I consider the function spaces with domain $\mathbb R^n$ for any $n \in \mathbb N$, the estimate for the interval $(0, 1)$ follows for $n = 1$ since $(0, 1)$ is an extension domain.
According to the Hitchhicker's Guide to Fractional Sobolev Spaces (Prop 3.4), there holds
$$ | u |_{W^{s, 2}(\mathbb R^n)}^2 = C(s, n) \int_{\mathbb R^n} |\xi|^{2s} |\mathcal Fu(\xi)|^2 \,\mathrm d\xi $$
with some factor $C(s, n)$, where $\mathcal F$ denotes the Fourier transform. Then
$$ \begin{align}
| u |_{W^{s/2, 2}(\mathbb R^n)}^2
&= C(s/2, n) \int_{\mathbb R^n} |\xi|^{s} |\mathcal Fu(\xi)|^2 \,\mathrm d\xi \\
& \leq C(s/2, n) \left( \int_{\mathbb R^n} |\xi|^{2s} |\mathcal Fu(\xi)|^2 \,\mathrm d\xi \right)^{1/2} \left( \int_{\mathbb R^n} |\mathcal Fu(\xi)|^2 \,\mathrm d\xi \right)^{1/2}\\
& \leq C(s/2, n) C(s, n)^{-1/2} |u|_{W^{s, 2}(\mathbb R^n)} \| u \|_{L^2(\mathbb R^n)}
\end{align}$$
using Hölder's inequality and Plancherel's theorem.
While this answers the original question I'm still very interested in how one can directly argue using the Gagliardo semi-norm.


Rolling dice possible outcome

Question: Can you help me to find the solution to the following question?

Fifty identical dice are rolled. How many distinct outcomes with positive even number of 1's, 2's, ..., of 6's are possible? For example, 8 of them 1, 14 of them are 2, 10 of them are 3, 10 of them are 4, 2 of them are 5, 6 of them are 6.

I am trying to write 50 as sum of even numbers such that $50 = 50 + 0$, $50 = 48 + 2$, $50 = 46 + 4$, $50 = 46 + 2 + 2$, etc.
By using this method, I can solve this question. I am curious to know about any other methods.
Comment: [the same question](https://math.stackexchange.com/questions/3683548/fifty-identical-dice-are-rolled-how-many-distinct-out-comes-with-positive-even) was asked a little while ago.
Comment: @lulu Which was then deleted by the OP shortly after receiving an answer. :sigh:
Answer: I assume that you do not care about the order in which the numbers are rolled... Any way of rolling twenty $2$'s and thirty $3$'s will be considered the same, whether the $2$'s appeared first or the $3$'s appeared first or they appeared mixed.
Letting $x_i$ represent the number of times that the number $i$ was rolled for each $i\in\{1,2,3,4,5,6\}$ respectively, you are trying to count the number of non-negative integer solutions to $\begin{cases}x_1+x_2+x_3+x_4+x_5+x_6 = 50\\0\leq x_i\\x_i~\text{even}\end{cases}$
As for a hint... recall that if $x_i$ is even then it can be written as $x_i=2y_i$ for some $y_i$.
Further, Stars-and-bars is a common technique/explanation for how to proceed.

Rolling dice possible outcome


Shell : "touch" command

Question: I have the following shell command, allowing to create blank files with randoms Last Modification Times.
for i in {1..10}; do touch -d "$(((RANDOM % 36) + 1980))-$(((RANDOM % 11)+1))
-$(((RANDOM % 28)+1)) 12:12:12.000000000 +0530" file$i;done

I'd like to make those files occupy a certain amount of bytes (which I would randomly generate). Is it possible somehow with touch, or do I need something completely different ? Thanks in advance.
Comment: You could use `dd` or `truncate` to create files of a certain size, and then use `touch` to set the file modification date.
Answer: Just add the following in the loop after touch command:
dd if=/dev/zero of=file$i bs=1 count=10

where 10 is the number of bytes.

Shell : "touch" command


$\mathbb{X}$ be a normal space, then $f^{-1}\left(U\right)$ is a normal subspace of $\mathbb{X}$

Question: Let $\mathbb{X}$ be a normal topological space, and $f:\mathbb{X}\rightarrow\mathbb{R}$ continuous function.
Claim: if $U\subseteq\mathbb{R}$ an open set, then $f^{-1}\left(U\right)$ is a normal subspace of $\mathbb{X}$.
Found this claim in some old lecture notes, and couldn't find a proof for it. Any ideas?
Answer: Yes, this is true: since $U$ is open in $\mathbb{R}$, $U$ in an $F_\sigma$ set in $\mathbb{R}$ (i.e., countable union of closed subsets). This holds in every metric space.
Hence $f^{-1}(U)$ is $F_\sigma$ in $X$, and $F_\sigma$ sets in normal spaces are normal (see, for instance, Engelking, General topology, 2.1.E).


Is Lebesgue integral over interior equal to the integral over the whole set?

Question: I have a measurable set $S\subset\mathbb{R}$ and a measurable function $f\colon\mathbb{R}\rightarrow \mathbb{R}$.
Is it true that $$\int\limits_Sf(x)\, dx=\int\limits_{\operatorname{int}(S)}f(x)\,d x?$$
Answer: No, the interior can even be empty. Consider $S = \Bbb{R} \setminus \Bbb{Q}$.
Answer: Another example: $S$ is a fat Cantor set, so $S$ is closed and bounded, but $\int_S 1\,dx \ne 0$, but $\mathrm{int}(S) = \varnothing$.


Can I hook a firewall inside a network and VPN connect to another network?

Question: I'm wondering what I'd have to do to make the following scenario possible:
<code> _____________           __________________
|             |         |                  |
|  Network A  |         |  Network B       |
|             |         |     ___________  |
|             ----------====== Network C | |
|             |         |    |___________| |
|_____________|         |__________________|
</code>
I.e. I want to tunnel the trafic from Network C to network A through the network and firewall of Network B.
I have
- a Cisco ASA-5510 on Network A
- an unknown setup on Network B
- Requirements of an as small as possible unit on Network C
My current idea is to prime an ASA-5505 and use it as a hardware VPN-client using EZVPN, but I'd like to have a product that's more rugged and industrial, as the unit may work in +40°C areas.
BTW: Never mind my mad ASCII-art skills ;)
Answer: What you're talking about is certainly possible, but the "Network B" edge firewall is going to determine how easy that is for you.
If the "Network B" firewall won't pass IPSEC then you're going to have to use some other type of VPN protocol or encapsulate the IPSEC into another protocol. (Off the top of my head I can't recall if the ASA's can do site-to-site IPSEC over UDP tunnels or not...)
You're probably going to have a tunnel that can only be initiated in "one direction", too. I'm assuming that the operators of "Network B" aren't going to forward unsolicited inbound traffic from the public Internet to your "Network C" firewall / VPN termination device. If that's the case then the "Network C" firewall will have to be the one that initiates the tunnel with your ASA on "Network A", because unsolicited traffic from "Network A" (i.e. requests to bring up the tunnel) won't ever get to the "Network C" device. As long as you've got something inside "Network C" that can generate traffic and keep the tunnel running this shouldn't be problematic.
Comment: Hi, thanks for your answer. No that's my thought too, that the tunnel will have to come from Network C, but as you too said, it shouldn't be a problem. Because if the tunnel goes down for some reason the trafic from inside Network C would start the tunnel back up again, right?

Also, assuming they allow IPSEC-trafic, my Network C-trafic wouldn't differ from an ordinary IPSEC software client, right?
Comment: Do you know of any industrial VPN hardware client?
Comment: ASAs can do IPSEC over UDP, and apparently over TCP as well according to http://www.cisco.com/en/US/docs/security/asa/asa70/configuration/guide/ike.html#wp1052899
Comment: @Adam: I figured they could but I'd never actually researched it (having never needed it, personally).
Answer: Depending on what kind of traffic you're sending and how many clients you have on Network C, one of the ASA's SSL VPN options might work. Network B would only need to allow outbound HTTPS, and you wouldn't require any VPN hardware at all.
They're aimed at a single client PC using them for remote access though, and the most that you'll be able to do will be to forward particular ports for that client PC.
Comment: Yeah, the thing is we're using special hardware inside Network C, and no PCs will be there. The idea is to talk directly to a computer in Network A from the units in Network C. And as we already have a IPSec setup going, I'd like to stick to that for our case, but it seems a valid point for a more general purpose.


Rank of Logistic Regression Model

Question: I've built a logistic regression model in R using below lines of code. I tried extracting an element of model object called rank. How is this rank calculated internally?
fit = glm(vs ~ hp + mpg, mtcars, family = "binomial")
fit$rank # returns 3

Is it simply 1 more than number of independent variables?
Answer: From the documentation of glm

rank  the numeric rank of the fitted linear model.

This is likely the rank of the design matrix.  Since you have 3 parameters to estimate (hp, mpg, and the intercept), and the two covariates are not perfectly collinear, the design matrix has rank 3.
It is not the number of independent variables.  For a single categorical variable with $c$ categories, the rank would be $c$.  In general, and assuming there is no perfect collinearity, the rank would be 1 + the number of continuous covariates + $\sum_{i=1}(c_i -1)$.  Here $c_i$ is the number of categories in the $i^{th}$ categorical variable included in the model.  We subtract one because one category is absorbed as the reference group.

Rank of Logistic Regression Model


SQLite, ORDER BY name if group doesnt exist

Question: I'm trying to order a list by alphabetical name, unless that row has a group, then I want the group to be used. grouped can also be NULL or an empty string.
For example:
name      grouped
a         NULL
b
c         a
d

Would be ordered as:
a,c,b,d

Here's what I have
SELECT name FROM table ORDER BY COALESCE(grouped, name)

I've also tried:
SELECT name FROM table ORDER BY CASE WHEN LENGTH(grouped) = 0
THEN name ELSE grouped END

But neither of these solutions work properly, they end up having all the grouped items show up first, not inter-mingled with the names as I would expect.
Comment: @Holt: CONCAT is, AFAIK, a MySQLism, the official operator for string concatenation is `||`. Also, `null || anything` is `null` so that won't help as is.
Comment: What do you get with your `COALESCE` order?  It should work.  Is `grouped` possibly empty string instead of actually null?
Comment: @SamuelNeff, hm, i guess there are some instances where it is an empty string. So it can be null or empty
Comment: Please update your question with a description of the ways in which "neither of these solutions work properly". Also, what is the value of `grouped` in the case of `b` and `d` above? There _must_ be a value, even if it is `NULL`…
Comment: @DonalFellows, there is an empty string value.
Answer: Since you have a mix of null and empty string, do this:
SELECT name
FROM table
ORDER BY COALESCE(grouped, '') || name;

This will change nulls to empty string, leave empty string as empty string, and concatenate name.
Comment: Hm, that seems to order all the groups AHEAD of all the names.
Answer: SELECT *
FROM MyTable
ORDER BY CASE COALESCE(grouped, '')
         WHEN '' THEN name
                 ELSE grouped
         END,
         COALESCE(grouped, '') <> ''

Comment: That still orders all grouped items ahead of non grouped items.
Comment: Ah, I figured it out, there was an issue with case. grouped was all capitalized, and name was not. Capital letters get sorted first.


When is $\sum_{n \ge 0} g_n(z)$ analytic?

Question: Let $D$ be an open subset of $\mathbb{C}$ where $g_n(z)$, $n \in\mathbb{N}$ are analytic. Then $$f(z)=\sum_{n \ge 0}g_n(z)$$
is analytic on $D$ iff $\sum_{n\ge 0}g_n(z)$ is locally uniformly convergent.
Firstly, what is the proof of this, and is there a way of intuiting why pointwise convergence is not strong enough to imply $f$'s analyticity, and why (non-local) uniform convergence is not required?
Comment: Uniform convergence is needed in order to get a continuous function, at least. And we can expect a local criterion since analyticity is a local property by definition.
Comment: Edit: I do remember one such theorem that says that if $f'_n$ converges uniformly and there exist a $x_0$ such that $f_n(x_0)$ converges then $f_n$ converges uniformly.
Comment: @BenA. What you say also applies for real functions, but for real functions this theorem isn't true.
Comment: Dear @Winther, am I missing a theorem for real functions? Like, is global uniform convergence enough to ensure that the limit is analytic? I roughly meant, if there is a criterion, it should be replacable by its local version (if such a thing exists), but I may have been a bit rash, apparently.
Comment: @BenA. I don't remember any theorem about this. The answer is no. The uniform limit of analytic functions on a real interval need not even be differentiable. Let $f_n = \sin(nx)/\sqrt{n}$. This function converges uniformly to $0$ on $R$, but the derivative does not exist anywhere.
Comment: @Winther, *what* derivative does not exist anywhere? $0=\lim f_n$ is differentiable everywhere. Are you thinking in $\sum f_n$? (BTW, the convergence is this case is doubtful, but $\sum\sin(nx)/n^2$ works, I think)
Comment: The missing ingredient is the theorem of Morera. In the real case, the uniform convergence of derivatives is required, as pointed by @Winther.
Comment: Please don't delete these comments, they have been useful to me.
Comment: @Martín-BlasPérezPinilla Its maybe not the best example, but at least it shows $\lim f_n \to f$ does not imply $\lim f_n' \to f'$. My main point was that real functions don't always behave so nicely, while complex analytic ones always do (as this theorem is an example of).
Comment: @Winther, OK. The correct phrase is "the derivatives don't converge."
Answer: I'm sorry for the discussions in the comments. They are not helpful, so let me try to make my point clear. You asked for intuition on
a) why uniform convergence is needed,
b) why it is sufficient, and
c) why it is only needed locally.
The hardest point here is b), and I'm not sure if I can explain this entirely intuitionally, so let's do the easy stuff first.
Ad a), pointwise convergence only is never good enough to preserve continuity; there are always series of arbitrarily nice (non constant) functions converging pointwise to a discontinuous function. On the other hand, uniform convergence will always results in a continuous function.
Ad c), as I tried to point out in my comment, analyticity is a local property by definition. A function is analytic if it is analytic in any point, i.e. if any point has an open neighbourhood on which the function is a convergent power series.
Therefore, any condition that is good enough to make sure a series converges to an analytic function will work locally too.
For a), finally, we can observe the wonderful miracle of function theory: holomorphic functions are analytic, roughly because their derivatives are again holomorphic, which is pretty strong, but the conditions imposed on their differentiability are not to strong. We only need a continuous function that fulfills a certain condition, where the occurring terms are compatible with uniform convergence.
I'm thinking of Morera's theorem, of course, that is, a continuous function, defined on some open domain in $\mathbb{C}$, is holomorphic on this domain if its contour integral over any closed curve in this domain vanishes.
Now, one is encouraged to gain an intuitive understanding of what it means for a contour integral to vanish. If you know some physics, you could first convince yourself of the relationship between the (converse of the) above statement and Green's theorem and try to combine it with the physical idea behind the latter.
Unfortunately, I don't know this stuff good enough to give good further explanation of this.
(Anyone more familiar with this kind of interpretation may very well add extra information or references where this is explained. Therefore, I made this post community wiki.)
Answer: Can't help you much on the intuition, but I know one proof that $f$ is analytic using Cauchy's theorem.
Let $f_n = \sum_n g_n$ and pick a point $\alpha \in {\rm Int}(\Gamma)$ where $\Gamma$ is a compact region where $f_n$ converges uniformly. Since $f_n$ is analytic
$$f_n(\alpha) = \frac{1}{2\pi i}\int_\gamma \frac{f_n(z) dz}{z-\alpha}$$
where $\gamma$ is the boundary of $\Gamma$. To show that $f$ is analytic in $\alpha$ we only need to show that $f(\alpha) = I$ where
$$I =  \frac{1}{2\pi i}\int_\gamma \frac{f(z) dz}{z-\alpha}$$
But this is easy as
$$|I - f(\alpha)| \leq |I - f_n(\alpha)| + |f_n(\alpha) - f(\alpha)|\\=\frac{1}{2\pi i}\int_\gamma \frac{|f_n(z)-f(\alpha)| dz}{z-\alpha} + |f_n(\alpha) - f(\alpha)| \leq  2|f_n - f|_\infty \to 0 {\rm ~~for~~} n\to \infty$$
by the uniform convergence of $f_n$.


Proof regarding arithmetic sequence

Question: I'm given the first term $a$ and the common term $d$. I need to find an index $n$, so that the sum of first terms is $S(n)=v$.
Basically, I need to solve the following quadratic system in terms of $n$: $$\frac{2a+d(n-1)}{2}n=v$$
How to prove or give a counterexample to the following proposition: there is at most one positive integer root of the equation $\frac{2a+d(n-1)}{2}n=v$.
Comment: I think it must be $$S_n=na+d\cdot \frac{(n-1)n}{2}$$
Answer: A counterexample to the statement given would be where $d\lt 0$. For example, if $a=1$ and $d=-1$, then the values of $S(n)$ would be
$$1,1,0,-2,...$$
where the initial two values are the same. So, $S(n)=1$ would have $2$ positive solutions - $n=1,2$.

Proof regarding arithmetic sequence


merge 3 files with awk in linux

Question: following problem: (similar to one last question)
I tried `
 awk 'FNR==NR {a[NR]=$0;next} {print a[1]","c[1]", "$0}' file1 file2 file3

but does not work
FILE1:
line1
line2
line3

and FILE2:
date1

and FILE3:
TITEL1

Result should be date1 merged to each line of file1.
So result:
line1, date1, TITEL1
line2, date1, TITEL1
line3, date1, TITEL1

Thanks
Answer: Input
[akshay@localhost tmp]$ cat f1
line1
line2
line3

[akshay@localhost tmp]$ cat f2
date1

[akshay@localhost tmp]$ cat f3
TITEL1

Output
[akshay@localhost tmp]$ awk 'FNR==1{i++}i<3{A[i,1]=$0;next}{print $0,A[1,1],A[2,1]}' OFS=', ' f2 f3 f1
line1, date1, TITEL1
line2, date1, TITEL1
line3, date1, TITEL1

Comment: No need for the 1s `awk 'FNR==1{i++}i<3{A[i]=$0;next}{print $0,A[1],A[2]}' OFS=', '`

merge 3 files with awk in linux


Pandas - read data (two-row header, index column)

Question: I have a data file that looks like this (miRNA-seq data from TCGA):
A X X X Y Y Y Z Z Z
B a b c a b c a b c
0
1   regular 5x9
2   data matrix
3
4

A describes the first header row, B describes the first column.
I want to use pandas.read_csv to return a DataFrame such that I can access rows by something like df[0] and columns by something like df['X']['a'], eventually delete selected rows and/or columns.
On my search I have found that MultiIndex could help my, however df = pandas.read_csv("datafile", header=[0, 1]); print(df.index) does return an Index.
Thank you for any suggestions.
EDIT: Some sample data (tab-separated)
Hybridization REF   TCGA-2V-A95S-01A-11R-A37G-13    TCGA-2V-A95S-01A-11R-A37G-13    TCGA-2V-A95S-01A-11R-A37G-13    TCGA-2Y-A9GS-01A-12R-A38M-13    TCGA-2Y-A9GS-01A-12R-A38M-13    TCGA-2Y-A9GS-01A-12R-A38M-13    TCGA-2Y-A9GT-01A-11R-A38M-13    TCGA-2Y-A9GT-01A-11R-A38M-13    TCGA-2Y-A9GT-01A-11R-A38M-13
miRNA_ID    read_count  reads_per_million_miRNA_mapped  cross-mapped    read_count  reads_per_million_miRNA_mapped  cross-mapped    read_count  reads_per_million_miRNA_mapped  cross-mapped
hsa-let-7a-1    17377   4045.749542 N   47187   7077.368096 N   31765   8956.551210 N
hsa-let-7a-2    34913   8128.517796 N   94766   14213.530526    Y   64148   18087.355487    N
hsa-let-7a-3    17496   4073.455371 N   47683   7151.760928 N   31782   8961.344580 N
hsa-let-7b  33546   7810.249993 N   46089   6912.683963 N   64948   18312.925799    N
hsa-let-7c  1349    314.077006  N   12185   1827.573913 Y   14075   3968.627681 N
hsa-let-7d  1735    403.946335  N   1763    264.424523  N   1176    331.588359  N

Comment: please post a sample dataset, othewise you're asking the helper to construct a 5 x 9 matrix for you in order to help you
Comment: And can you post a sample/desired output?
Comment: I think part of your confusion is `df.index` vs. `df.columns`. `df.columns` is a MultiIndex with the levels you want.
Answer: Try this out:
df=pd.read_csv('zhoop.csv', header=[0,1], index_col=0)

Note: in order to index rows you would use df.loc[rownum], not just df[rownum].
Comment: Glad I could help! Also, if you aren't aware already, there are two main ways of indexing in pandas, by position (using .iloc or .iat) or by label (using .loc or .at). You will want to know the difference, especially if you'll be deleting rows. https://pandas.pydata.org/pandas-docs/stable/indexing.html
Comment: Thanks for clearing my confusion. I had the very same command, however I was not addressing `df.columns` nor `df.loc`.


SwiftUI List Rows Different Heights for Different System Images

Question: In my SwiftUI app, I have a List inside of a sidebar NavigationView with 2 rows, like this:
List {
    NavigationLink(destination: MyView1()) {
        Label("Test Row 1", systemImage: "list.bullet")
    }

    NavigationLink(destination: MyView2()) {
        Label("Test Row 2", systemImage: "shippingbox")
            .frame(maxWidth: .infinity, alignment: .leading)
    }
}

However the second row is taller that the first row, I believe due to the image. If I change the image to this:
NavigationLink(destination: MyView2()) {
    Label("Test Row 2", systemImage: "list.number")
        .frame(maxWidth: .infinity, alignment: .leading)
}

the rows are now the same height. I don't want to fix the height of the rows, but I was wondering if there was a solution where the rows could be the same height.
Comment: Looks fine here with provided code, Xcode 13.3 / iOS 15.4, but yes SF symbols (aka system images) can have different sizes for same font, actually for the same reason as 'a' and 'A'.
Answer: If you want to ensure that the rows are even, you can use PreferenceKeys to set the row heights to the height of the tallest row like this:
struct EvenHeightListRow: View {

    @State var rowHeight = CGFloat.zero

    var body: some View {
        List {
            NavigationLink(destination: Text("MyView1")) {
                Label("Test Row 1)", systemImage: "list.bullet")
                    // This reads the height of the row
                    .background(GeometryReader { geometry in
                        Color.clear.preference(
                            key: HeightPreferenceKey.self,
                            value: geometry.size.height
                        )
                    })
                    .frame(height: rowHeight)
            }

            NavigationLink(destination: Text("MyView2")) {
                Label("Test Row 2)", systemImage: "shippingbox")
                    .background(GeometryReader { geometry in
                        Color.clear.preference(
                            key: HeightPreferenceKey.self,
                            value: geometry.size.height
                        )
                    })
                    .frame(height: rowHeight)
                    .frame(maxWidth: .infinity, alignment: .leading)
            }
        }
        // this sets backgroundSize to be the max value of the tallest row
        .onPreferenceChange(HeightPreferenceKey.self) {
            rowHeight = max($0, rowHeight)
        }
    }
}

// This is the actual preferenceKey that makes it work.
fileprivate struct HeightPreferenceKey: PreferenceKey {
    static var defaultValue: CGFloat = .zero
    static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {}
}


How to build a conda package but exclude/omit/not include a specific folder/directory?

Question: I'm trying to build a conda package but I just realized that it keeps adding all of my previous releases in tar ball.  I tried adding this line: recursive-exclude releases/ *.tar.gz to my MANIFEST.in but it isn't working.
Here is my build command:
(µ_env) jespinozlt-osx:Packages jespinoz$ cd soothsayer/
(µ_env) jespinozlt-osx:soothsayer jespinoz$ ls
Icon?           dist            releases
MANIFEST.in     docs            setup.py
README.md       install         soothsayer
bin         license.txt     soothsayer.egg-info
build           logo.png        standalone
devel.txt       meta.yaml       tutorials
(µ_env) jespinozlt-osx:soothsayer jespinoz$ conda build .
No numpy version specified in conda_build_config.yaml.  Falling back to default numpy value of 1.11
WARNING:conda_build.metadata:No numpy version specified in conda_build_config.yaml.  Falling back to default numpy value of 1.11
Adding in variants from internal_defaults
INFO:conda_build.variants:Adding in variants from internal_defaults
Attempting to finalize metadata for soothsayer
INFO:conda_build.metadata:Attempting to finalize metadata for soothsayer
BUILD START: ['soothsayer-py36_2019.12-0.tar.bz2']
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... done
Source cache directory is: /Users/jespinoz/anaconda3/conda-bld/src_cache
INFO:conda_build.source:Source cache directory is: /Users/jespinoz/anaconda3/conda-bld/src_cache
INFO conda_build.source:download_to_cache(43): Source cache directory is: /Users/jespinoz/anaconda3/conda-bld/src_cache
No hash (md5, sha1, sha256) provided for soothsayer_v2019.12.tar.gz.  Source download forced.  Add hash to recipe to use source cache.
WARNING:conda_build.source:No hash (md5, sha1, sha256) provided for soothsayer_v2019.12.tar.gz.  Source download forced.  Add hash to recipe to use source cache.
WARNING conda_build.source:download_to_cache(59): No hash (md5, sha1, sha256) provided for soothsayer_v2019.12.tar.gz.  Source download forced.  Add hash to recipe to use source cache.
Found source in cache: soothsayer_v2019.12.tar.gz
INFO:conda_build.source:Found source in cache: soothsayer_v2019.12.tar.gz
INFO conda_build.source:download_to_cache(63): Found source in cache: soothsayer_v2019.12.tar.gz
Extracting download
source tree in: /Users/jespinoz/anaconda3/conda-bld/soothsayer_1578343428831/work
export PREFIX=/Users/jespinoz/anaconda3/conda-bld/soothsayer_1578343428831/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho
export SRC_DIR=/Users/jespinoz/anaconda3/conda-bld/soothsayer_1578343428831/work
Processing $SRC_DIR
Building wheels for collected packages: soothsayer
  Building wheel for soothsayer (setup.py): started
  Building wheel for soothsayer (setup.py): finished with status 'done'
  Stored in directory: /private/tmp/pip-ephem-wheel-cache-z5uej2un/wheels/93/2c/ae/23c5322c97f4ea4b77b566ff85638a1b92198cf0836e7fab90
Successfully built soothsayer
Installing collected packages: soothsayer
Successfully installed soothsayer-2019.12

Resource usage statistics from building soothsayer:
   Process count: 3
   CPU time: Sys=0:00:00.4, User=0:00:00.7
   Memory: 57.2M
   Disk usage: 4.2K
   Time elapsed: 0:00:04.1

Packaging soothsayer
INFO:conda_build.build:Packaging soothsayer
INFO conda_build.build:build(1551): Packaging soothsayer
Packaging soothsayer-py36_2019.12-0
INFO:conda_build.build:Packaging soothsayer-py36_2019.12-0
INFO conda_build.build:bundle_conda(890): Packaging soothsayer-py36_2019.12-0
No files or script found for output soothsayer
WARNING:conda_build.build:No files or script found for output soothsayer
WARNING conda_build.build:bundle_conda(970): No files or script found for output soothsayer
number of files: 0
Fixing permissions
Packaged license file/s.
TEST START: /Users/jespinoz/anaconda3/conda-bld/noarch/soothsayer-py36_2019.12-0.tar.bz2
Adding in variants from /var/folders/6z/5vbtz_gmkr76ftgc3149dvtr0003c0/T/tmp6matkfoy/info/recipe/conda_build_config.yaml
INFO:conda_build.variants:Adding in variants from /var/folders/6z/5vbtz_gmkr76ftgc3149dvtr0003c0/T/tmp6matkfoy/info/recipe/conda_build_config.yaml
INFO conda_build.variants:_combine_spec_dictionaries(189): Adding in variants from /var/folders/6z/5vbtz_gmkr76ftgc3149dvtr0003c0/T/tmp6matkfoy/info/recipe/conda_build_config.yaml
Nothing to test for: /Users/jespinoz/anaconda3/conda-bld/noarch/soothsayer-py36_2019.12-0.tar.bz2
Renaming work directory,  /Users/jespinoz/anaconda3/conda-bld/soothsayer_1578343428831/work  to  /Users/jespinoz/anaconda3/conda-bld/soothsayer_1578343428831/work_moved_soothsayer-py36_2019.12-0_osx-64_main_build_loop
# Automatic uploading is disabled
# If you want to upload package(s) to anaconda.org later, type:

anaconda upload /Users/jespinoz/anaconda3/conda-bld/noarch/soothsayer-py36_2019.12-0.tar.bz2

# To have conda build upload to anaconda.org automatically, use
# $ conda config --set anaconda_upload yes

anaconda_upload is not set.  Not uploading wheels: []
####################################################################################
Resource usage summary:

Total time: 0:01:52.0
CPU usage: sys=0:00:00.4, user=0:00:00.7
Maximum memory usage observed: 57.2M
Total disk usage observed (not including envs): 4.2K

####################################################################################
Source and build intermediates have been left in /Users/jespinoz/anaconda3/conda-bld.
There are currently 1 accumulated.
To remove them, you can run the ```conda build purge``` command

Here is my MANIFEST.in file:
(µ_env) jespinozlt-osx:soothsayer jespinoz$ cat MANIFEST.in
recursive-include soothsayer/io/data_type/ *.py
recursive-include soothsayer/feature_extraction/algorithms/ *.py
recursive-include soothsayer/r_wrappers/packages/ *.py
recursive-include soothsayer/tests/data/ *.py
recursive-include soothsayer/db/ *.pbz2
recursive-exclude releases/ *.tar.gz
global-exclude *.py[cod] __pycache__

I want to exclude the tar balls in this folder:
(µ_env) jespinozlt-osx:soothsayer jespinoz$ ls -lhS releases/
total 189456
-rwxrwxrwx@ 1 jespinoz  tigr    18M Jan  2 11:41 soothsayer_v2019.12.tar.gz
-rwxrwxrwx@ 1 jespinoz  tigr    18M Dec  2 10:57 soothsayer_v2019.11.tar.gz
-rwxrwxrwx@ 1 jespinoz  tigr    18M Nov  5 14:13 soothsayer_v2019.10.tar.gz
-rwxrwxrwx  1 jespinoz  tigr    10M Oct  2 11:26 soothsayer_v2019.09.tar.gz
-rwxrwxrwx@ 1 jespinoz  tigr    10M Sep  3 11:08 soothsayer_v2019.08.tar.gz
-rwxrwxrwx@ 1 jespinoz  tigr    10M Aug  8 16:33 soothsayer_v2019.07.tar.gz
-rwxrwxrwx@ 1 jespinoz  tigr   9.1M Jun 20  2019 soothsayer_v2019.06.tar.gz
-rw-r--r--@ 1 jespinoz  tigr   659B Jun 20  2019 create_release.sh

It's including all of my previous releases:
(µ_env) jespinozlt-osx:noarch jespinoz$ tar -xzf soothsayer-py36_2019.12-0.tar.bz2
(µ_env) jespinozlt-osx:noarch jespinoz$ ls -lh info/recipe/releases/
total 192776
-rw-r--r--  1 jespinoz  tigr   659B Jun 20  2019 create_release.sh
-rwxr-xr-x  1 jespinoz  tigr   9.1M Jun 20  2019 soothsayer_v2019.06.tar.gz
-rwxr-xr-x  1 jespinoz  tigr    10M Aug  8 16:33 soothsayer_v2019.07.tar.gz
-rwxr-xr-x  1 jespinoz  tigr    10M Sep  3 11:08 soothsayer_v2019.08.tar.gz
-rwxr-xr-x  1 jespinoz  tigr    10M Oct  2 11:26 soothsayer_v2019.09.tar.gz
-rwxr-xr-x  1 jespinoz  tigr    18M Nov  5 14:13 soothsayer_v2019.10.tar.gz
-rwxr-xr-x  1 jespinoz  tigr    18M Dec  2 10:57 soothsayer_v2019.11.tar.gz
-rwxr-xr-x  1 jespinoz  tigr    18M Jan  2 11:41 soothsayer_v2019.12.tar.gz

Here's my meta.yml
{% set name = "soothsayer" %}
{% set version = "2019.12" %}

package:
  name: {{ name|lower }}
  version: py36_{{ version }}

source:
  url: https://github.com/jolespin/{{ name }}/releases/download/v{{ version }}/soothsayer_v{{ version }}.tar.gz

build:
  noarch: python
  number: 0
  script: python -m pip install --no-deps --ignore-installed .

requirements:
  run:
    - python >=3.6,<3.7

about:
  home: https://github.com/jolespin/soothsayer
  license: BSD-3
  license_family: BSD
  license_file: license.txt
  summary: 'High-level package for (bio-)informatics'
  description: 'This module contains analytical tools and sophisticated plotting methods for informatics datasets.'

Comment: What is your `meta.yaml`?
Comment: I've added it in there.
Answer: This is a workaround for whatever is going wrong here. You could always split out your build script into a file called build.sh and manually rm -rf releases at the end of it.
rm -rf $PREFIX/info/recipe/releases

Conda-build is simply making a tar archive of everything your script command is doing.  Although this is under info/recipe, so that might be the contents of your recipe directory.  I'd move your recipe into a subdir (conda.recipe) and run it out of there or you can tell conda-build (in the meta.yaml) to not include the recipe using a switch: --no-include-recipe


Problems with modeling a cumulative dependant variable

Question: I am building a .NET program. One of its functions is to provide a predictive model for a vehicles life-to-date maintenance costs, basically what is the cumulative cost(Y) for a vehicle at specific year(X). I decided to use a 2nd degree polynomial least squares fit and for the most part it does a good job. Sometimes though the curve will peak and start trending downward which doesn't make sense for life-date-cost since its a cumulative value...(X,Y) > (X-1,Y).
This negative trend happens when the difference in cost for say, year 2 to year 3 is less than year 1 to year 2. Some sample data that gives me a negative trend:
(1,328.76)
(2,1133.12)
(3,1366.07)
My solution for now is to check for a negative trend and if its found use a linear best fit instead but I feel like that's a messy fix. I've thought about implementing some sort of minimum value for the change from year to year...essentially turning the curve into a linear line at a certain X value but that seems complicated to implement. Does anyone see a better way of doing this or a better model to use? I'm not very knowledgeable with statistics so go easy on me :-p
Edit
Each vehicle has a varying amount of data depending on how long its been in service, with a soft max at 15 years. So the last data point for each vehicle is for the most recent year(2011 in this case) and we are really only interested in extrapolating 5 years beyond that point. As we use the model year to year, we will get more data for the vehicles which require the model to be altered. Thats why I choose the polynomial least squares fit because its easy to just run the new data back through that function and get a new equation.
Comment: What software are you using to fit the predictive model? Is it .NET, or are you just implementing the model in .NET that you fit elsewhere? There are strategies pre-programmed in statistical software such as R, SAS, SPSS, etc. that would be hard to do from scratch w/o a good deal of expertise. Also, are you going to need to do extrapolation, or will all future predictions be w/i the interval spanned by your training data? NB extrapolation raises difficult issues; see here: [using-a-regression-model-to-make-prediction-when-to-stop](http://stats.stackexchange.com/questions/26914//26923#26923).
Comment: Hi @gung. Can you give some detail on the strategies you have in mind? That would, I think, be an answer.
Comment: I'm not using any software to find the model...I suppose I should start there. I initially used Excel's trendline function. I'm using .NET to implement whatever model I find. Your link makes a good point. I edited my question with some more details regarding extrapolation.
Answer: Using a squared term to capture a curvilinear relationship in your data is fine, but it's worth noting that this can only capture one exact shape of curvature.  This can be very limiting in practice.  What you want typically is to use smoothing splines.  I wrote about this here: What are the advantages / disadvantages of using splines, smoothed splines, and Gaussian process emulators?, which may be helpful to read.  However, these techniques are somewhat advanced, and I doubt they can be done in Excel.  Moreover, extrapolation is very hard to do well (here's a humorous example), and extrapolation is especially likely to go awry when using splines.  Most likely, you will need to work with a statistical consultant.


passar valor de select com array por ajax

Question: Preciso de passar a informação de um select array por ajax mas não estou a conseguir.
O meu form:
<form method="post" id="form1">

<select name="sel1[]" id="sel1" onblur="run_sel(this)">
<option value="1">Valor 1</option>
<option value="2">Valor 2</option>
<option value="3">Valor 3</option>
</select>

+
-

</form>

O jQuery:

Comment: Tem uns erros aqui: `value="1'`... abre com aspas duplas e fecha com simples
Comment: Qual o problema que está acontecendo?
Comment: @dvd, corrigido. obrigado.
Comment: Aqui tb: `$("#form1")[0].form.reset();`.. seria `$("#form1")[0].reset();`
Comment: @dvd, na página ajax.php recebe apenas o primeiro valor selecionado se não usar implode, com implode não aparece nada.
Comment: Pelo que entendi vai receber o valor da option selecionada.
Comment: Pelo `name="sel1[]"` entende-se que vc quer enviar um array... mas só tem 1 select... como iria enviar um array se só tem 1 select?
Comment: @dvd, inclui o codigo na pergunta que monta o array, erro meu não ter colocado logo de inicio.
Answer: Serialize o formulário e envie pelo data::
data: $("#form1").serialize(),

O valor de $_POST['sel1'] no PHP será uma array com o valor de cada select. Você pode usar implode() para converter em string com os valores separados por vírgula:
implode(",", $_POST['sel1']);

Agora, há um erro nesta linha:
$("#form1")[0].form.reset();

O correto seria:
$("#form1")[0].reset();


Customer Attrition Modeling

Question: I am building a customer attrition model for a commercial banking client. I am having difficulty defining target variable - customer attrition. In the data set, i can have multiple records for a single customer. Suppose a customer holds multiple accounts (or products) so there would be multiple records for a customer. The question arises - Should i calculate attrition at customer level or multiple models for each products? I know it all depends on the objective of the study. Is it possible to calculate customer attrition at customer level (aggregating information of multiple products)?
Answer: Yes, it is possible. If your end objective is if a customer has attrited or not, then you have to see if he has stopped using all the products and (if you have the information), will not be using the products anymore.
So, the type of product becomes irrelevant in such a case. However, if you want to map attrition on a product level basis, you have to check whether he has stopped using that specific product.

Customer Attrition Modeling


Proportion as Dependent Variable or Control for the Denominator in Regression Model

Question: I am a little confused as to which model specifications to use for my question.
I have number of technological failures (positive count variable) as dependent variable but I am supposed to control for total number of technologies patented (another positive count variable but higher than failures variable always). I have a panel of 100 firms for 10 years.
Either I can take proportion of failures by dividing technological failures with total number of technologies patented and use this as dependent variable. I can use glm for this specifications, I guess. Or I can use negative binomial model with technological failures as dependent variable and control for  total number of technologies patented in the model. Is one of these methods preferred over other? Please feel free to refer to any article or journal which throws some light on this.
Thanks
Answer: This sounds to me like something best suited to a Poisson or negative binomial model. You have count data - that right there should tell you that linear regression is not appropriate, and because each observation isn't a functioning vs failing widgets, but number of failed widgets per firm. There are panel Poisson models that you can use.
The difference between Poisson and negative binomial is basically whether you have overdispersion or not, i.e. the mean=variance of the counts. There are numerous ways to test for this, that a simple Web search will show you.
The question you ask about proportion vs raw counts is one of offset or exposure. A count model without an exposure variable is interpreted as the predicted number of failures at any given firm, based on the covariates. When you have an exposure variable, say total widgets produced, you enter that as a constrained independent variable, with coefficient of 1, just as you seem to understand in your description of how you would do it in a negative binomial model. The difference in arithmetic is:
no exposure:
$log(failed widgets)=\beta_0+\beta_1IV +\beta_2year$
exposure:
$log(failed widgets)=1*widgets+\beta_0+\beta_1IV +\beta_2year$
The interpretation is no longer the predicted total number of failures in the model with the exposure variable, but the rate of failures.
Which do you choose? Here are the criteria I usually use:
 - What makes most intuitive sense to myself and other stakeholders?
 - Does the number of failures make any sense without considering the number of widgets produced in total? Sometimes it is useless to compare failure between large and small factories without considering their size.
 - Does a rate make sense? Sometimes a rate is not what you want. If it is for compliance purposes, and producing more than say 10 widgets is unsafe for the cosmic consciousness, then it doesn't matter if its a large or small firm producing. In fact, maybe small firms are more likely to have no failures because they do everything by hand and are more meticulous.
Here is another link that may provide more insight.
Answer: I think this would depend on what you really want to know. Could you say that you are really interested in how much of the patented technologies patented eventually failed? Or is the number of failures not really a part of the number of technologies patented, and is the latter really just a control variable?
If your dependent variable is in reality a proportion: the proportion of technologies that failed, you could use logistic regression on these 'real proportions'. In that case, you could say that your imaginairy binary data are aggregated but therefore still binomially distributed.
Comment: hmm...I understand your point but is there any statistical difference in these two methodologies or is it just the matter of the question at hand?
Comment: Maybe I'm not really sure of how your data is structured. Could you give an example?
Comment: So I have 100 firms with data for 10 years on number of failures, productivity (total technologies patented), and some measures of social embeddedness and my questions is whether social contentedness of technologies (through inventors) matter as well along with economic factors related to technologies when it comes to make decisions about their fate (continue or discontinue).
Comment: Are the failures a subset of those patented?


User role can't view/edit their own unpublished content

Question: I have a Drupal 7 site where users have a listing they can edit.
This all works fine when the listing is published but as soon as it's set to unpublished they can't view the page or the edit page.
They've got all the relevant permissions:
View own unpublished content Edit own content
I've even got the Override Node and View Unpublished modules installed but still I get the page trying and trying to load but never actually loading.
As soon as I set it to published it's all fine.
Open to any ideas.
Thanks
Comment: I've used the http://drupal.org/project/publishcontent module in Drupal 6, there is a version of it available in Drupal 7, but I've not used it.
Comment: Sounded promising but it won't let the role view unpublished content...
Comment: I actually just have the 'authenticated' user role have the 'View own unpublished content' permission and have had no issues like yours.  None of my editors have 'administer content' or 'bypass content access controls', but can see their unpublished content. I'm assuming you've done this a thousand times, but just want to check that you've tried clearing cache, rebuilding permissions, etc?  And do you have any special modules installed that may be hijacking the regular Drupal permissions?
Answer: For me, the solution was to enable the "Bypass content access control" permission setting.  In my case it was for an internal role, so I was comfortable with that but some roles I would not give that to.
I am running Drupal 7, BTW.
Comment: @monymirza, I don't understand your comment.
Comment: "Bypass content access control"
Comment: It's a permission under node category for user roles.
Answer: That is how the permission system is setup for Drupal nodes. Users need some super user permission to be able to edit unpublished nodes (administer content I believe it's called), not very practical. You could instead make a custom form that allows users to publish their own content or create a custom node access function for editing nodes.
Comment: Really? Even though I can set the role to be able to edit their own content etc, they won't be able to view their own unpublished content? Do you know any modules (other than the mentioned) that would help?
Comment: @SpaceBeers Most node access modules would add a lot of unnecessary complexity. I haven't heard of a module that just changes this behavior.
Comment: I know this question is a bit old, but check the code @ http://drupal.stackexchange.com/questions/30750/view-unpublished-content-permission-for-non-author
Answer: "Bypass content access control" only comes into play in a view. You can give someone permission to view their own unpublished nodes, but they will still not see those nodes in a View unless, in that specific view, you select
"Bypass content access control".
Answer: I had to create a view "Unpublish" in View module  and Module: publishcontent and view_unpublish works perfectly. Solves the problem.


Orthogonal projection to graph of Hilbert space

Question: Let H be a Hilbert space and A be a bounded linear operator on H.
Let G be the graph of A , i.e a subset of the direct sum of H with itself of the form (h,Ah).
Then we know G is a closed linear subspace (This is one direction of closed graph theorem), so we can define the orthogonal projection P from the direct sum of H with itself onto G.
My question is that do we have an explicit form of P? I have no idea how to express it explicitly.
Any help would be appreciated.
Answer: The orthogonal projection of $(y,z)\in\mathcal{H}\times\mathcal{H}$ onto the graph $\mathcal{G}(A)=\{ (x,Ax)\in\mathcal{H}\times\mathcal{H} : x\in\mathcal{H} \}$ is the unique $(x,Ax)\in\mathcal{H}\times\mathcal{H}$ such that the following orthogonality conditions hold in $\mathcal{H}\times\mathcal{H}$:
$$
           ((y,z)-(x,Ax)) \perp (x',Ax'), \;\;\; x'\in\mathcal{H}.
$$
That is, the following hold for all $x'\in\mathcal{H}$:
$$
           (y-x,z-Ax)\perp(x',Ax'),\;\;\; x'\in\mathcal{H}, \\
                \langle y-x,x'\rangle=\langle Ax-z,Ax'\rangle,\;\;\;  x'\in\mathcal{H}, \\
            \langle y-x,x'\rangle=\langle A^*(Ax-z),x'\rangle,\;\;\; x'\in\mathcal{H}, \\
            y-x=A^{*}(Ax-z) \\
            y+A^*z =(A^*A+I)x \\
           x=(A^*A+I)^{-1}(y+A^*z).
$$
Therefore, if $P$ denotes the orthogonal projection of $(y,z)$ onto the graph $\mathcal{G}(A)$, then
$$
        P(y,z) = (x,Ax) \\
   = ((A^*A+I)^{-1}(y+A^*z),A(A^*A+I)^{-1}(y+A^*z)) \in\mathcal{G}(A)\subset\mathcal{H}\times\mathcal{H}.
$$
It's ugly and pretty all at the same time.
Comment: this is a side question: can you tell me the kernel of this projection map?
Comment: @biden : That would be the set of all $(y,z)\in\mathcal{H}\times\mathcal{H}$ such that $y+A^*z=0$ or $y=-A^*z$. In other words, it s a transpose of the graph of $-A^*$.


How to sort a dictionary by two elements, reversing only one

Question: Consider the following dictionary:
data = {'A':{'total':3},
        'B':{'total':5},
        'C':{'total':0},
        'D':{'total':0},
       }

The desired order for above is B, A, C, D. Order by descending total, then by ascending key.
When I call sorted(data, key=lambda x: (data[x]['total'], x), reverse=True)
I get B,A,D,C because reverse is called on both keys.
Is there an efficient way to solve this?
Comment: You'll have to do a two-pass sort.
Answer: Sort on negative total, that'll reverse put the totals in reverse order without having to use reverse=True. Ties are then broken on the key in forward order:
sorted(data, key=lambda x: (-data[x]['total'], x))

Demo:
>>> data = {'A':{'total':3},
...         'B':{'total':5},
...         'C':{'total':0},
...         'D':{'total':0},
...        }
>>> sorted(data, key=lambda x: (-data[x]['total'], x))
['B', 'A', 'C', 'D']

This trick only works for numeric components in a sort key; if you have multiple keys that require a sort direction change that are not numeric, you'd have to do a multi-pass sort (sort multiple times, from last key to first):
# when you can't take advantage of numerical values to reverse on
# you need to sort repeatedly from last key to first.
# Here, sort forward by dict key, then in reverse by total
bykey = sorted(data)
final = sorted(bykey, key=lambda x: data[x]['total'], reverse=True)

This works because the Python sort algorithm is stable; two elements keep their relative positions if the current sort key result is equal for those two elements.
Comment: @Murphy4: there is no way to do this without 2 passes in that case.
Comment: This is clever, but if the requirements used strings for both sorts, is there any way to do this without 2 passes?
Comment: Thank you for specifying last key to first. Excellent answer.


Relation of Mahalanobis Distance to Log Likelihood

Question: The Wikipedia entry on Mahalanobis Distance contains this note:

Another intuitive description of Mahalanobis distance is that it is square root of the negative log likelihood. That is, the exponential of the negative square of the Mahalanobis distance will give you the likelihood of your data point belonging to (a presumed normal) distribution of the sample points you already have.

How/where is this shown? What does it mean (I guess it's not so intuitive...)?
Comment: The quotation is only partly correct: the log likelihood is given by *negative one-half* the square root of the Mahalanobis distance *plus* one-half the log of the determinant of the inverse covariance matrix, $\det(S^{-1})$, *minus* $(n/2)\log(2\pi)$ (in $n$ dimensions). For the purpose of comparing likelihoods with the same covariance matrix the additive factors can be dropped, but the initial factor of $1/2$ is crucial for implementing and interpreting certain tests.
Comment: How do the two differ?  It looks the same to me. :-)  It might help to know that $\Sigma=S^{-1}$, which flips the sign of the logarithm of the determinant in the formula.
Comment: This is the topic from Bayes classification. You can find a number of good answers here covering it. But let me mention this time just [one of mine](http://stats.stackexchange.com/a/31384/3277). The "likelihood" of a class given the data point, `k|x`, there is expressed pdf function, where the exponent of the squared Mahalanobis d you may notice in the numerator.
Comment: @whuber: I just found this equation on Wikipedia: http://en.wikipedia.org/wiki/Multivariate_normal_distribution#Likelihood_function. It is a bit different from your comment. Which is correct?
Comment: @whuber, ttnphns:  Can you write out the exact equations as an answer? What does it mean?
Comment: If the Mahalanobis distance can be defined in terms of the log likelihood of the normal distribution, can we derive other distances for other distributions by just plugging in their respective log-likelihood functions? Would there be a name for this possible class of distances? I guess I will post a new question for this.
Answer: For completeness, I'll answer myself.
I eventually found the equation here, and as @whuber writes in his comment:
Define:

$k$: the multivariate dimension
$\mu$: the multivariate mean (a $k$-dimensional vector);
$\Sigma$: the $k\times k$ covariance matrix;

Then:

The squared Mahalanobis Distance is: $D^2=(x-\mu)^T\Sigma^{-1}(x-\mu)$
The log-likelihood is: $ln(L)=-\frac12ln(|\Sigma|)-\frac12(x-\mu)^T\Sigma^{-1}(x-\mu)-\frac k2 ln(2\pi)$
or: $ln(L)=-\frac12ln(|\Sigma|)-\frac12D^2-\frac k2 ln(2\pi)$

Thus, define $c\equiv\frac12(ln(|\Sigma|) + k\cdot ln(2\pi))$ then:

$ln(L)=-\frac12D^2-c$ and;
$D=\sqrt{-2(ln(L)+c)} $


Equivalence of certain geometry axioms.

Question: I'm studying axiomatic Euclidean Geometry, and I'm using two books which have slightly different set of axioms. Here's the set of Incidence Axioms and Betweenness Axioms of the first one:
I1) For any line, there are at least two points in the line and two points outside of it.
I2) For any given two distinct points, there is a unique line that contains both of them.
B1) For any given three distinct points in a line, one and only one is between the other two.
B2) For any two distinct points, there are points $C$ and $D$ such that $C$ is between $A$ and $B$, and $B$ is between $A$ and $D$.
B3) A line determines exactly two semiplanes.
Where, by definition, given a line $l$ and a point $A$, the semiplane determined by $l$ and $A$ is the set of points $B$ such that $AB$ (the set of points between $A$ and $B$) does not intersect the line l.
Using that, I'd like to prove Pasch's Axiom:
"Let $A$, $B$, $C$ be three points that do not lie on a line and let $l$ be a line which does not meet any of the points $A$, $B$, $C$. If the line $l$ passes through a point of the segment $AB$, it also passes through a point of the segment $AC$, or through a point of segment $BC$."
Is it possible? I'm not sure if it's provable without using the later axioms of the book.
Answer: Consider the two half-planes determined by line $l$. Points $A$ and $B$ belong to different half-planes, because $AB$ intersects $l$. It follows that either $C$ belongs to $l$, or it belongs to the same half plane as $A$ (and then $BC$ intersects $l$), or it belongs to the same half plane as $B$ (and then $AC$ intersects $l$).

Equivalence of certain geometry axioms.


Show that $dX_t=\frac{X_t}{1-t}dt+dW_t$ can be written as $X_t=(1-t)\int_{0}^{t}\frac{1}{1-s}dW_s$

Question: I have been reading the following link on Brownian Bridge definition, and came across the following statement (bullet point 9 in the link above):
Suppose $W_t$ is a standard Brownian motion, define $X_1=1$, then, for $h \in [0,1]$, the process $X_t$ is a Brownian Bridge:
$$X_t=(1-t)\int_{h=0}^{h=t}\frac{1}{1-h}dW_h \tag{1}$$
I can actually understand the proof of this statement presented in the link above and do not have an issue with the claim that $X_t$ above is a Brownian Bridge. However, the author then goes on to state that:
"In differential form, the above can be written as:"
$$dX_t=\frac{X_t}{1-t}dt+dW_t \tag{2}$$
I actually am unable to connect the differential form with the equation (1) given for $X_t$.
When I rewrite the differential form in the "long-hand" notation, I get ($X_0:=0$):
$$X_t=\int_{h=0}^{h=t}\frac{X_h}{1-h}dh+\int_{h=0}^{h=t}dW_h=\int_{h=0}^{h=t}\frac{X_h}{1-h}dh+W_t$$
The above is clearly not the same as the former definition of $X_t$ given in equation (1). I am thinking there might be some Ito's lemma application to a smartly defined function $F(X_t,t)$, that I haven't been able to figure out (I've tried playing around with variants of $F(X_t,t):=X_te^t$, but to no avail).
Is there a way to "solve" the differential equation (2) into (1), or has the author made a typo?
Edit: having read the answer linked in the comment below, and in the spirit of my own answer on notation to another question here, I have attempted to rewrite the linked answer using the long hand notation (because I struggle with interpreting some of the steps of the short-hand notation answer):
I am still getting a wrong answer. Could you please help me spot where I am going wrong?.
The "trick" in the linked aswer seems to be applying Ito's lemma to a function $F(W_t,t):=\frac{W_t}{1-t}$. The derivatives are:
$$\frac{\partial F}{\partial t}=\frac{-W_t}{(1-t)^2}, \frac{\partial F}{\partial W_t}=\frac{1}{1-t}, \frac{\partial^2 F}{\partial t^2}=0$$
We also have that:
$$W_t=W_0+\int_{h=0}^{h=t}a(W_h,h)_{=0}dh+\int_{h=0}^{h=t}b(W_h,h)_{=1}dW_h$$ so that:
$$\frac{W_t}{1-t}=\int_{h=0}^{h=t}\left(\frac{\partial F}{\partial t}+\frac{\partial F}{\partial W}*a(W_h,h)_{=0}+\frac{\partial^2 F}{\partial W^2}_{=0}*b(W_h,h)\right)dh+\int_{h=0}^{h=t}\frac{\partial F}{\partial W}b(W_h,h)_{=1}dW_h=\\=\int_{h=0}^{h=t}\left(\frac{-W_h}{(1-h)^2}\right)dh+\int_{h=0}^{h=t}\left(\frac{1}{1-h}\right)dW_h$$
Multiplying through by $1-t$ then gives:
$$W_t=(1-t)\int_{h=0}^{h=t}\left(\frac{-W_h}{(1-h)^2}\right)dh+X_t$$
Therefore we have:
$$X_t=(1-t)\int_{h=0}^{h=t}\left(\frac{W_h}{(1-h)^2}\right)dh+W_t$$
Focusing on the term $(1-t)\int_{h=0}^{h=t}\left(\frac{W_h}{(1-h)^2}\right)dh$, we can write:
$$\int_{h=0}^{h=t}\left((1-t)\int_{s=0}^{s=h}\frac{1}{1-h}dW_s\right)\frac{1}{1-h}dh$$
Note that the term in the bracket above, i.e. $\left((1-t)\int_{s=0}^{s=h}\frac{1}{1-h}dW_s\right)$ in fact does not equal to $X_h$ (as defined in equation (1)), so in fact we do not have that:
$$X_t=\int_{h=0}^{h=t}\frac{X_h}{1-h}dh+W_t$$
Comment: https://math.stackexchange.com/questions/231426/applying-ito-formula-to-the-brownian-bridge?rq=1
Comment: The trick is to apply Ito's lemma to the function $F(Y_{t},t):=(1-t)Y_{t}$, where $Y_{t}=\int_{0}^{t}\frac{1}{1-s}dW_{s}$, so $dY_{t}=\frac{1}{1-t}dW_{t}$.
Comment: @B_B: thank you for the link. It has allowed me to make a lot of progress, but I am still struggling to fully replicate the result. I have edited my question above to show where I am still diverging.
Answer: Let $Y_{t} = \int_{0}^{t} \frac{1}{1-s}\, dW_{s}$. Next take a look at
$$X_{t} = (1-t) \int_{0}^{t} \frac{1}{1-s}\, dW_{s} = (1-t)Y_{t}$$
and differentiate using It^o's lemma
\begin{align*}
dX_{t} &= -Y_{t}\, dt + (1-t)\, dY_{t} + d[ 1-t, Y_{t} ] \\
&= - Y_{t}\, dt + (1-t)\cdot \frac{1}{1-t}\, dW_{t} \\
&= -\frac{X_{t}}{1-t}\, dt + dW_{t}
\end{align*}
and so there is indeed a typo.

If you want to solve
$$dX_{t} =  \frac{X_{t}}{1-t}\, dt + dW_{t},$$
then (as in ODEs) use integrating factor
$$\mu(t) = e^{-\int_{0}^{t} \frac{1}{1-s}\, ds } = 1-t$$
to solve SDE
\begin{align*}
d \left (X_{t}(1-t) \right) = (1-t)\, dX_{t} - X_{t}\, dt =: (1-t)\, dW_{t}
\end{align*}
for solution
\begin{align*}
X_{t} = \frac{1}{1-t}X_{0} + \frac{1}{1-t} \int_{0}^{t} (1-s)\, dW_{s}.
\end{align*}

Note of caution: you should not apply It^o's lemma to solve the SDE. This only works in the case that it admits a strong solution (cf. Oksendal, Chapter 5).


Can I get the probability of a value being 0.5 larger or smaller?

Question: So I have some clothing data, with some body measurements and the sizing. The sizing is a discrete variable ranging from 7 to 14 with steps of 0.5.
I know that a specific consumer with specific measurements has a probability of 65% picking size 10. How can I know the probability of him picking a size that's 0.5 larger (10.5) or 0.5 smaller (9.5)?
EDIT: for clarification, let's say Y is the size, and X the variable of the body measurements. Y is approximated to a normal distribution $N(11, 1.02)$. In this case, just to make sure I interpreted the question right, isn't the question about the conditional probability $P(|Y-10|=0.5  / X = X\_spec )$  with $X\_spec$ being the given measurement values of the customer ?
Comment: This cannot be answered without more information on the distribution of the RV.
Comment: I updated the question.
Answer: If $X$ is the size picked by the consumer, you are trying to find $P(|X-10| = 0.5)$. If you have data, a raw estimate would be to create a new variable $y = |x-10|$ and count how many of your observations have $y = 0.5$.
However, if you don't have data and the only thing you know about $X$ is that $P(X = 10) = 0.65$, there is no direct way to find $P(|X-10| = 0.5)$.
Comment: Thanks for your answer but then, the customer has a specific given set of measurements, isn't it more a conditional probability?
Comment: @JamesGot How so? $P(\vert X - 10\vert = 0.5 \bigg{\vert} X = 10)$?
Comment: No. never mind though. I was thinking of something too complicated, I ended up solving this with prediction intervals from a regression. Thanks :)


Running different versions of the same binary, same file

Question: I have a single binary that can run in server or client mode.  It can be used like this:
$ ./a.out --server &
$ ./a.out --client &

They talk to each other, and this is working well.  My question is what is the expected behavior when I launch the server:
$ ./a.out --server &

But then I forget to kill it, and go about my development work, editing and building, and running the client:
$ edit client.c
$ make
$ ./a.out --client
^C
<repeat>

Now without the sticky bit set, is my OS (Ubuntu) running two different versions of my binary?  Or is it taking a shortcut and using the in-memory instance and therefore ignoring my latest build?  Are there any other side effects to this mistake?
Answer: make replaces the executable by deleting the original file. However, since it is executing in the background, there is a reference to it. The file isn't completely deleted until the reference is cleared (though directory entries are cleared to make way for the new executable file).
So, in your example there are two versions of the program running. One side-effect is if you make changes which cause major incompatibility b/w your server & client code - such as changes in packet structures. You'll probably see weird, unexplainable behavior, crashes, etc. Its always a good idea to kill the background server and re-run your entire test.
Comment: Thank you, that's exactly what I feared, and did in fact see.
Answer: If you do not change server code, the just copy your a.out into 'my_server' e.g. Then run it as my_server --server. make will replace a.out, but not my_server.
Another way - tell make to kill all running a.out-s just before recompile: add target 'all' (it must be first in makefile), which depends on a.out and executes 'killall a.out'.


Javascript closures in modules

Question: I am trying to adapt some code I have written in javascript outside Drupal to a Drupal module:
<code>(function($) {
  Drupal.behaviors.myModule = {
    $(config.targetElement).html(config.template).promise().done(function(){
      initialize($(config.targetElement).attr('data-region'));
    });

    var initialize = function (region) {
      if (region in config.regions) {
        //Calls the API
        $.ajax({
          url: config.apiUrl + config.regions[region]
        }).then(function(data) {
          //Build a regional weather object and render it to the UI
          renderUI(buildRegionalWeather(data));
        });
      }
    };
  }
})(jQuery);
</code>
This code was working before I wrapped it in the Drupal behavior, but now it is broken. initialize() can't be referenced from within the promise callback.
I assume it has something to do with the intricacies of closures which to be honest I'm not that familiar with.
I had a similar problem with some other code where I ended up Doing like this:
<code>(function($) {
  Drupal.behavior.myModule = {
    //Document ready code here...
  }
  Drupal.myModule = {
    doStuff: function() {
      //Some public function here...
    },
    doMoreStuff: function() {
      //Yet another public function...
    }
  }
})(jQuery);
</code>
Which works, but exposes every single function I write. In the above case it is not so much of a problem, but there are many other functions in the javascript-file I am trying to adapt which should not be exposed like that.
How should I be implementing this?
Comment: Are you sure the code at the top of the question is definitely what you're using? I only ask because it's invalid syntax
Comment: The first example is a snippet from a larger file, so there are obviously some variables that are not defined, but aside from that it should be good, but let me just check it again...
Comment: What @Clive is saying is that, inside an object literal, you cannot use `$(config.targetElement).html(config.template).promise().done(function(){})` directly.
Comment: Also, how to avoid to expose every JavaScript method is a plain JavaScript question. Drupal doesn't change how that is done.
Comment: @kiamlaluno How is this off topic? The question is about implementing Javascript in Drupal Behaviors. It is a very Drupal specific issue as he had the script working before trying to use it with Drupal behaviors.
Comment: @sareed The code is not even correct; we don't teach JavaScript syntax.
Comment: Ok, I guess I get that. I saw it as more of a Drupal behaviors syntax issue as the solution is definitely not the same as it would be in standard JavaScript.
Answer: Try this for Drupal 7 documentation:
<code>(function ($) {
  Drupal.behaviors.myModule = {
    attach: function (context, settings) {
      // code here
      // example function call
      Drupal.behaviors.myModule.exampleFunction();
    },
    exampleFunction: function () {
      // code
    }
   }
 })(jQuery);
</code>

Javascript closures in modules


Practicing modes on the piano

Question: This has probably been asked a lot here but I can't seem to find the question, sorry if I'm repeating it.
I know the definitions of the different modes I just want to incorporate them, being able to play all of them and, perhaps develop some ear while listening to others.
An example, the only difference between F lydian and F lonian is that the first uses B natural and the other uses B flat. That means that if I'm playing a series of chords that don't involve nor B natural nor B flat I really can't tell if I'm playing F lydian or F lonian. I think to make a difference between those modes I have to emphasize which B I'm playing.
I've heard that a common mistake is trying to compose a melody in lydian mode and after listening to it, it turns out it was actually in another mode, say dorian. How to about doing that?
Any tips, exercises, suggestions that I can do to practice each mode?
Thanks in advance!
Comment: What exactly are you asking? How to work out what the notes are in each mode? What fingers to use? What do you mean by 'degrees'? Please edit your question to bring some clarity.
Comment: I just realized how much I don't know about the subject but I'm only talking about modern western modes (Lonian, Dorian, Phrygian, Lydian, Mixolydian, Aeolian and Locrian).
Comment: I had a similar problem on guitar, as all the modes kind of begin to sound the same unless you really emphasize the root note. On guitar I would use a drone (open string) and play the scale over that. On piano I would assume if you pedal the root note with one hand, then play the mode with the other hand, you begin to get a better idea of the mode's qualities.
Answer: The main note to  emphasise on each mode has to be the 'key note'.As in, for example, D Dorian, the D; in G# Mixolydian, the G#. Those are the 'key centres' for the modes, and everything will gravitate towards that note. The V will not necessarily be a V,as we normally see it. In Locrian, it's going to actually be a flat five, although all the other 6 modes will have a 'perfect fifth'. You probably realise that each mode , when played in a scalar way, starts on a particular note from its parent scale, as in the Lydian of C, starting on F, known as F Lydian, uses only the C scale notes. Thus, if you mean "how can I practise running up and down modes", then it's just the C scale notes, going from F to F.
The question is vague, but maybe what you need to do is find modal pieces - of which there are many - Celtic songs are often Dorian or Mixolydian - and play through those.
Comment: "Those notes are the 'key centers'." Be careful when playing some modes - they have very weak tonal centers, so to speak, and if you're not deliberately emphasizing the root of the mode, it's easy to accidentally modulate to an entirely different, more stable mode.
Comment: @Kevin - yes, generally the parent key.

Practicing modes on the piano