Is it appropriate to run correlations first and then a regression?

Question: In my study I have several predictor variables as well as dependent variables/outcomes. I don't have much theoretical pressure to choose any variable over another, making decisions about regressions frustrating. So I ran the correlations between all variables, IVs and DVs to see which had relationships. Is this frowned upon? Can I use this information to inform where to look further?
Are correlations susceptible to familywise error?
Comment: Are correlations susceptible to the usual multiple testing issues?  Yup.
Answer: In my opinion, it is OK to inspect correlations first. In fact such exploratory data analysis is important, for one thing so that you know about any possible problems in advance with multicollinearity.
The best way to choose covariates in the first instance is by recourse to a priori understanding of the causal relations between the covariates and the outcome(s). A good way to do this is by drawing a causal path diagram or directed acyclic graph. This has the advantage of allowing the identification of potential confounding variables that should also be controlled for, but also the identification of a minimally sufficient set of covariates, to avoid over-adjustment (which can result in the reversal paradox). An excellent description of these pitfalls can be found here.
If you really have no a priori knowledge to help choose candidate covariates, then you are running the risk of choosing covariates on the basis of spurious correlations. In this case you can employ stepwise procedures to choose covariates, but this can result in inflated Type 1 errors (ie familywise error), and you also need to be very careful about multicollinearity.


F1 is higher than accuracy using sklearn in keras callback. Something wrong?

Question: I tried to make a custom callback to compute f1 and roc_auc in keras. I used sklearn to compute the f1 measure and roc_auc. Here's the code :
from keras.callbacks import Callback
from keras import backend as K
import numpy as np
import tensorflow as tf
from sklearn.metrics import accuracy_score, f1_score, roc_auc_score

class Measurement(Callback):
    def on_train_begin(self, logs={}):
        self.acc = 0
        self.f1s = 0
        self.roc_auc = 0

def on_train_end(self, logs={}):
    y_true = []
    for y in self.validation_data[1]:
        for idx in range(2):
            if y[idx] == 1:
                y_true.append(idx)
    y_pred_temp = self.model.predict(self.validation_data[0])
    y_pred = []
    for y in y_pred_temp:
        for idx in range(2):
            if y[idx] > 0.49999 + K.epsilon():
                y_pred.append(idx)
    self.acc = accuracy_score(y_true, y_pred)
    self.f1s = f1_score(y_true, y_pred)
    self.roc_auc = roc_auc_score(y_true, y_pred)
    return

def on_epoch_begin(self, epoch, logs={}):
    return

def on_epoch_end(self, epoch, logs={}):
    return

def on_batch_begin(self, batch, logs={}):
    return

def on_batch_end(self, batch, logs={}):
    return

My dataset amount is so imbalanced, i have 2 classes, the 1st class data is only 33% of the entire data. So i used, StratifiedKFold to mitigate the problem of that imbalanced data itself. But, the final result yields a lower accuracy in comparison with the F1 value. I never saw something like that. My professor also said there might be something wrong, but i chose to believe that it is normal, since the negative class(1st class) amount is a lot lesser than the positive class, which will result to a lower true negative value, and make the accuracy lower. Any thought? Thanks in advance.
Comment: Its very hard to say unless you post the actual values and data.
Comment: The data is actually a confidential asset, all i can tell you is that it comes in form of texts, and it has 2 classes, with a distribution 33% for the first class and 67% for the second class, which means the data is imbalanced in terms of amount. And the result is as follow :
`ACCURACY: 84.28%`
`F1: 87.79%`
Comment: Any idea @VivekKumar ?
Answer: I've finally tried to switch the classes label, and it gives a smaller F1. So the phenomenon i described in the question is possibly because of the low amount of the negative class which result to a lower true negative value, which is not considered in F1 but considered in accuracy.


Standard 12 bar blues shuffle

Question: In a standard 12 bar blues shuffle, "A" Major, on a six string guitar, in standard tuning.  When you get to the IV, I know... I can play the pentatonic major/minor, I know I can do some mode positions or b minor scales, Some people say you have to stick to the major and minor blue scales, but that's OK too...All of this is fine.
Is there a way I can comfortably/Musically stay on the IV for the duration of the song?
I don't know if this would be a practical musical thing to do or if I just want to see if I can do it properly.  I just have real problems with the IV and coming back to the 1...
Thank you both...
In the A Major blues shuffle we're talking about I can solo with E major licks for the duration of the song, so I assumed I could stay in D (IV) because it's perfect also.  Obviously this is not correct. When I hear other great blues guitar it seems they hang around the four longer than I do/can or somehow transpose back to the one after a long day at IV.
From what I am now understanding ( IV & V ) perfect relates to the scale and not cord song structure.
So I can solo ANYTIME with "A" major and minor scales and "E" Major and minor scales but not on the IV, except for the duration of the four?
Comment: There's a myriad of things that can be done, notes that can be played. The question is unclear as it stands.Why would you want to 'stay on the IV' for the rest of the song, which doesn't 'stay on the IV'?
Comment: @Tim - I think he's saying he gets stuck on IV and doesn't know how to transition away from it.
Answer: In Blues in A, the IV chord is D. Over that, as you state, , maj. pent., min. pent., maj. blues, min. blues are the main notes most use (ignoring modes for now!).
Let's consider all the notes those entail. D, E, F, F♯, G, A♭, A, B, C. In fact, it's probably more simple to quote 'avoid' notes! They're B♭, D♭ and E♭.
A lot of those notes - which I'll call pivot notes - also belong to A, pents and blues.
In order, they are A, B, C, C♯, D, E♭, E, F♯, G.
So, those 'pivot notes', common to both D and A chords, will be : A, B, C, D, E, F♯, and G.
A choice of 9 notes which could be common to both chords, and could be the last note played over D, and the first over A. The best and most convincing to start the next A bar would of course be the note A, but with such a choice, the options are almost endless. That's even before B♭ gets re-instated as the last note played over the D chord, leading like a tritone sub. back to note A on chord A. The list goes on...
Comment: I think you mean Bb, Db and Eb as the 3 avoid notes?
Comment: @mkorman - did indeed! Well spotted!
Comment: I really enjoy your (in the moment) inspirational direction with your instruction to the individual student question. I will definitely get on with studying pivot points....
Answer: Ideally your soloing needs to reflect the underlying harmony.
I'm assuming your basic 12-bar shuffle, the harmony of which is:
I7  - I7  - I7 - I7
IV7 - IV7 - I7 - I7
V7  - IV7 - I7 - V7
which in the key of A would be:
A7 - A7 - A7 - A7
D7 - D7 - A7 - A7
E7 - D7 - A7 - E7
Whatever you play at any given point in time needs to reflect the chord that you're on. This is sometimes called "playing the changes".
This means that in the first four bars you need to play licks/phrases that go well with A7, then in the next 2 phrases that go well with D7 and so on.
There are some tricks/shortcuts for beginners, which are "just play A blues licks all the time". This sounds OK ish, but not great (and you may hit wrong notes every so often). In order to sound great, you need to play the right notes at any given time.
What are the right notes? @Tim explains it quite well in his answer. If that's too complicated to begin with (I'm still absorbing some of that info into my playing myself), then you can simplify it as:

Play A licks and the A major/minor blues scales over the A7 chord
Play D licks and the D major/minor blues scales over the D7 chord
Play E licks and the E major/minor blues scales over the E7 chord

If you decide to stay in IV (so, D) for the whole song, your soloing will sound somewhat monotonous and not reflect the chord changes.
Comment: Someone's going to take the last part literally, and actually play blues scales over the chords! Blues scale *notes* may be a better option... +1.

Standard 12 bar blues shuffle


Estou tendo um erro em meu exercício em c++. O que eu posso fazer para consertar?

Question: #include <math.h>

#include <iomanip>
#include <iostream>

using namespace std;

int main() {
    float R;
    float pi = 3.14159;
    float volume = (4.0 / 3) * pi * pow(R, 3);
    cin >> R;
    cout << fixed << setprecision(3);
    cout << "VOLUME = " << volume << endl;
}

E Essa é a minha saída.
Comment: Talvez você devesse fazer a leitura da variável `R` **antes** de utiliza-la nos cálculos.
Answer: A entrada R é requisitada depois de ser usada no cálculo. É preciso alterar o código para algo como
#include <math.h>
#include <iomanip>
#include <iostream>

using namespace std;

int main() {
    float R;
    float pi = 3.14159;
    float volume;

    cin >> R;
    volume = (4.0 / 3) * pi * pow(R, 3);

    cout << fixed << setprecision(3);
    cout << "VOLUME = " << volume << endl;
}


Update multiple items

Question: I want to update a few items in real time without having to change the page.
I already use something like this for another item which updates every 5 seconds.
I tried doing it for each item but it made my website VERY slow.
I was told it could be done with jQuery but I didnt know how exactly.
What I want to do:
Using PHP I will be getting information from my database which will either say "1" or "0"
This I need updated will be these: (if they are 1)

If they are "0" the icon "id" will be something like "first_icon_2"
How can I get a request for all of them at once??
Thanks in advanced, I have tried to do this for about a month.
Comment: If you tried to do this for a month, you have to show us _"What have you tried?"_
Comment: It won't benefit anything because it didn't work and won't work.
Answer: What you want to use is an ajax call.  jQuery has an .ajax() function: http://api.jquery.com/jQuery.ajax/ which is extremely straight forward.
Essentially, what you need to do is set up a PHP script which does any processing that you need done.  Anything that is echoed out onto the page will be returned via the ajax call.  If you're looking to process multiple items, you should look into JSON.
Since it seems like you need to return multiple values (1 for each of the icons) you will want to create an array in PHP.  The array will look something like this:
$icons = array("first_icon => 1, "second_icon => 0, "third_icon" => 0, "fourth_icon => 1);

You can then use json_encode to encode the array into a string which will be readable on your javascript side:
$iconsJSON = json_encode($icons);
echo $iconsJSON;

If you set up your AJAX function on your main page (the one with the javascript) like the following, you will be able to reference any of the icon keys.
$.ajax({
dataType: 'JSON',
type: 'POST',
url: api_url+'client/'+client.id+'.json',
data: {
    variable1: 'value',
    variable2: 'value',
    variable3: 'value'
},
success: function(data) {
    // On success perform this function
    var icons = data;
},
error: function(data) {
    // On failure perform this function
}
});

I would recommend reading through this resource if you need more guidance: http://www.jquery4u.com/json/ajaxjquery-getjson-simple/

Update multiple items


ASP.NET MVC Render View to a string for emailing

Question: I want to use MVC views to create the body for an email and I have come across this (http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/) but it doesn't seem to work with strongly typed views (ViewContext is null). But I was after something the would render a full view including a masterpage.
I thought that if there was a way of just invoking a view with out redirecting and just writing to a different stream and sending the email within the controller that might do it, but I can't work out how to invoke a view.
Any suggestions would be great!
Thanks in advance.
Gifster
Comment: possible duplicate of [Render a view as a string](http://stackoverflow.com/questions/483091/render-a-view-as-a-string)
Answer: The question has been asked (and answered) already:
Render View as a String
This is the bit that I use:
protected string RenderViewToString<T>(string viewPath, T model, System.Web.Mvc.ControllerContext controllerContext) {
        using (var writer = new StringWriter()) {
            var view = new WebFormView(viewPath);
            var vdd = new ViewDataDictionary<T>(model);
            var viewCxt = new ViewContext(controllerContext, view, vdd, new TempDataDictionary(), writer);
            viewCxt.View.Render(viewCxt, writer);
            return writer.ToString();
        }
    }

Best place for this method is in a class library project that your mvc project has a reference to.  Mainly because that way you can easily reuse it in all your apps.  But also because it is neither Application logic (so doesn't belong in the controller) nor does it belong in the model.  Some things are just utilities.
Note that to get this to work, the viewPath parameter HAS to be the PHYSICAL PATH to the file, complete with the .aspx extension.  You can't use a route as WebFormView class requires a physical path in its constructor.
This will render the full view and take account of the master page.

HEALTH WARNING FOR HTML EMAILS:
HTML emails and the devices where you read them are even more difficult and restrictive to design for than websites and browsers.  What works in one, will not work in another.  So with html emails, you really have to Keep It Simple!  Your lovely page with menus and relative images and whatever else, JUST WON'T WORK in all email devices.  Just as an example, the images src attribute needs to be absolute and include the domain:
This won't work:

Bit this will:

With those caveats, it works fine and I use it.  Just don't try to send them the full gimmickry of your website, cos that won't work!
Even more important:
All CSS must be INLINE and just for basic styling:  colours, borders, padding.  But no floating and positioning.  CSS layouts won't work consistently across devices!
Comment: At least if you're using Razor, you can do:   var view = new RazorViewEngine().FindView(controllerContext, viewName, masterPageName)  and then when creating your ViewContext pass view.View in as your second argument, to avoid the physical path issue in finding the view and master page.
Comment: Yeh Cheers, Pretty well up on email html, just new to MVC... I have an EmailController that has a Welcome action, would this method sit in that controller? or elsewhere??
Comment: @Andy:  the health warning is also there for anyone coming later to this.  Strictly speaking, this is not application logic so shouldn't be in the Controller.  Its not part of the model either.  As it is reusable functionality, I would make the method static and put it in a static class in a library project.  That way it is reusable across all your applications, just by dropping the dll into the bin folder.
Comment: So here I will need to pass through the ControllerContext??

new ViewContext(ControllerContext, view, vdd, new TempDataDictionary(), writer);
Comment: so where do you get the controllerContext from if you are using this in a dos application and not an mvc application?
Answer: You can use MvcView NuGet package to do this! Its simple, just install using install-package MvcMailer and you are done! Use full power of view engine to template, master page, view model and send html emails neatly!


Can I make Electronic Drums even more quiet?

Question: I live in an apartment and recently bought a Yamaha dtxtreme III.  Luckily I live on the bottom floor and have no one under me, however the drums are facing a wall that I share with my neighbors.  The pads sound like I'm hitting a phone book and the kick drum has a bit more bass to it, what I would love to do is hang up some of these curtains (http://www.moverssupplies.com/catalog/product/view/id/141/s/vb-73g/category/92/) and block out as much of the sound as possible for them.
I realize I am being paranoid about this, and even went as far as to talk to them about it and they are really cool about the drums, however I have been in their shoes and want to maintain as good of a relationship as possible with them!
Is this a reasonable way of doing this?  The blankets say they have a NRC rating of .8, and they weigh about 11lbs each, I would love to get 6 of them and hang them in a square around my drums so I could play late into the evening.
Comment: Sounds like a good plan from here.  One possible option (and I'm not a percussionist, so take it w/ a grain of salt): put some rubber padding between the drumhead and the mallet ( for the bass drum) or sticks to reduce the immediate sound impact.
Comment: The best thing you can do really is talk to your neighbors and designate practice times (like when they aren't around.) If after you've talked and they've let you know it's bothersome still, *then* I would go ahead with the curtains. I wouldn't add a rubber layer as that will change the feel and response of both the instrument and your beaters.
Comment: http://music.stackexchange.com/questions/9542/electronic-drums-in-apartment
Answer: This is quite a lot like this thread, which was quite comprehensive :
Electronic Drums in apartment
A few points :

The problem isn't so much sound travelling through the air and through the wall so much as making its way to hard surfaces and travelling through that. If you have a wooden flor, the wood will resonate nicely as you hit the kit (especially bass drum) and travel through to next door. A home made drum riser (tennis balls for 'legs') is suggested to mute it.

If you have a concrete floor then that helps hugely to mute this effect anyway.

Mesh drums are much quiter than pads, although the rubber cymbals and the bass drum are still noisy.

If some sound travels through the air anyway (and that's what the neighbours can hear) then the curtains sound like a good idea

How excellently considerate of you to check with your neighbours. That's half the battle, I think : consideration goes a long way, as opposed to just playing and assuming they can handle it.
Answer: Percussion sound also travels well through the hard surfaces - drum stand, then floor and walls - much better than through the air. In some badly design buildings you may hear that way a tennis ball dropped on the floor two flats above.
Put something like a carpet or towel under the drum stand.
Answer: You're never going to completely kill the sounds without spending enough money to just buy another place.
Before spending money on kit, see if you have move things around and stick the drums against another wall, or in another room. As was mentioned in the comments, talking it over with neighbours always helps, but it is very human to say 'that's fine' then complain later, so I wouldn't have too much faith in it.
The curtains will of course work, but I doubt you'll get the psychological satisfaction of feeling perfectly quiet, so I'd just stick to evening hours and reserve the later night for snoozing.
Answer: Many of the tips above are good, I would add "white noise" to dampen the sound of the tapping. They are online, apps for phones and on Itunes. Download them and play them trough a speaker. Most are free and they are used to reduce outside noise from bothering you. Cover the other rooms by turning on a fan, a bathroom fan, an air filter, turn your TV on to the fireplace channel. It all helps. Personally I would replace your pads with mesh pads. I started with an inexpensive kits and one by one moved to used mesh pads as they came up on ebay.
Answer: I found that a "mattress sandwich" does the job very well.
High-density rubber helps to block sound and low-density fibre helps to absorb sound.
Without this the drum pads and pedals would sound like somebody doing DIY through the floorboards to the room below.
But with this it just sounds like pitter-patter of rain drops. :)
My "mattress sandwich" is made from:
1 x Cot Mattress (Eco Fibre, 100x70x7cm); £20 at amazon.
2 x Protective Anti-Vibration Rubber Mat (100x60x2cm); £30 at floormats.
Total cost: £80. :)
In contrast, Roland's set of noise eaters and mats would cost over £300.


Replacing with single quote using sed

Question: I want to replace a set of characters with ' using sed.
This post suggest:

With single quotes around the argument (sed 's/…/…/'), use '\'' to put a single quote in the replacement text.

So, I tried following:
echo 'abcd' | sed 's/[abcd]/\'/g'

But it simply ends up expecting more input:
anir@DESKTOP-4856511:~$ echo 'abcd' | sed 's/[abcd]/\'/g'
>
>
>
> ^C

When I copy pasted echo 'abcd' | sed 's/[abcd]/\'/g' in .sh file and ran, it gave me following error:
anir@DESKTOP-4856511:~/Mahesha999/delete$ ./trysed.sh
./trysed.sh: line 1: unexpected EOF while looking for matching `''
./trysed.sh: line 2: syntax error: unexpected end of file

What the right way to do this? Is it impossible to escape single quote inside single quoted string (and I have to use double quotes only as explained here)?
Comment: the post you linked at the end also mentions `'s/ones/one\x27s/'` and `sed 's/ones/two'\''s/'`
Comment: Use `sed "s/[abcd]/'/g"` or `sed 's/[abcd]/'"'"'/g'`
Comment: @Sundeep whats that `\x27s` there?
Comment: @anir : Wouldn't be a `tr abcd "'"` easier than using _sed_?
Comment: @anir `\xNN` allows you to specify a character with two digit hexadecimal value, `27` is for single quote, see https://ascii.cl for mapping.. and [my tutorial](https://learnbyexample.github.io/learn_gnused/breere-regular-expressions.html#escape-sequences) for more details about such escape sequences and how the meaning can differ in replacement section
Comment: @Sundeep got it `\x27` is ascii code for `'`
Comment: @Sundeep is this issue only limited for replacement text?  The first link in my question says so.
Comment: strictly speaking, this isn't a `sed` issue, but shell issue... bash doesn't allow escaping single quote within single quotes, but it is possible in double quotes.. if you use `-f` option and [provide a file as source of sed commands](https://learnbyexample.github.io/learn_gnused/z-s-and-f-command-line-options.html#file-as-source-of-sed-commands), you won't run into this issue
Answer: As the post says:

With single quotes around the argument (sed 's/…/…/'), use '\'' to put a single quote in the replacement text.

So, using your example, you would do:
echo 'abcd' | sed 's/[abcd]/'\''/g'

If you want to replace with just one single quote:
echo 'abcd' | sed 's/[abcd][abcd]*/'\''/g'

The shell does not allow single quotes inside a single quoted string. What the code above does is create three strings (which are not separated by anything):

single-quoted string: 's/[abcd]/'
unquoted string containing just an escaped single-quote: \'
single-quoted string: '/g'

The shell then expands them and because they are not separated, they effectively become joined into a single string.
sed sees: s/[abcd]/'/g

Replacing with single quote using sed


Number of ways of dividing a set into a set of sets

Question: This is really two related questions.  First, it seems to me that given a set of $n$ objects you can divide it into a set of subsets of $a_1$ sets containing $n_1$ objects, $a_2$ sets containing $n_2$ objects and so on such that $a_1\cdot n_1 + a_2\cdot n_2 + \cdots + a_m\cdot n_m = n$ in the following way:
$$\frac{\binom{n}{n_1}\cdot\binom{n-n_1}{n_1}\cdots\binom{n-(a_1-1)n_1}{n_1}\cdot\binom{n-a_1n_1}{n_2}\cdots\binom{n-a_1n_1-(a_2-1)n_2}{n_2}\cdots\binom{n-a_1n_1-a_2n_2\cdots}{n_m}}{a_1!a_2!\cdots a_m!}$$
An example of this would be to divide a set of 13 distinct objects into 2 sets
of 2 object and 3 sets of 3:
$$\frac{\binom{13}{2}\binom{11}{2}\binom{9}{3}\binom{6}{3}\binom{3}{3}}{2!3!}$$
However, deriving from another question in my book there seems to be another general formula for calculating this whose combinatoric explanation I don't really understand:
$$\frac{n!}{a_1!a_2!\cdots a_m!(n_1 !)^{a_1} \cdot (n_2 !)^{a_2} \cdots (n_m !)^{a_m}}$$
Based on my above example I would get:
$$\frac{13!}{2!(2!)^2 3!(3!)^3}$$
First is this general formula right and if so how do you explain it?
I hope the explanation to the first part is clear.
Comment: In the second term of you first formula is it $\binom{n-n_1}{n_1}$ or $\binom{n-a_1n_1}{n_1}$??
Comment: I mean the first.
Comment: @Robert S. Barnes : in $\binom{n}{n_1}\cdot\binom{n-n_1}{n_1}\cdot\dots\cdot\binom{n-a_1n_1-a_2n_2\dots}{n_m}$ the sequence is not clear, would you please add more terms to clarify the sequence?
Comment: @palio Hope it's clearer now.
Comment: I added a concrete example to try and make the question more clear.
Answer: Your first formula, though not quite given in full detail, is correct if one makes a reasonable interpretation of what you mean by $\dots$. No explanation is given for the first formula: the reasoning that led to it is not mentioned. Although the actual reasoning is easy to guess from the structure of the formula, some explanation ought to be given.  We give a justification of the second formula.
Assume that all of the $n_i$ are distinct.  This was not mentioned explicitly, but is a necessary assumption. The result is false otherwise.
Imagine arranging our $n$ objects in a row.  Now group the first $n_1$ together, then the next $n_1$, and so on until we have $a_1$ groups of $n_1$ members each. Then do the same with $n_2$, and so on.
Do this for every one of the $n!$ permutations of our $n$ objects. We will get every division of the type you are looking for. The only problem is that we get every division in more than one way. But luckily every division is obtained in the same number of ways.
Each division into groups of $n_1$ occurs in $a_1!(n_1!)^{a_1}$ ways.  This is because each of the $a_1$ little groups can be internally permuted in $n_1!$ ways, for a total of $(n_1!)^{a_1}$ ways.  Then each of the $a_1$ groups themselves can be permuted as blocks in $a_1!$ ways. The same consideration applies to all $i \le m$. Thus we need to divide $n!$ by
$$\left[a_1!a_2!\cdots a_m!\right]\left[(n_1!)^{a_1}(n_2!)^{a_2}\cdots (n_m!)^{a_m}\right].$$
Comment: Oops, I forgot to type in the division by $a_1!a_2!\dots a_m!$, but I meant to include that.
Comment: I added that into the question.
Comment: @Robert S. Barnes: Edited answer to omit correction of formula. Comment at the end became irrelevant.
Comment: +1 Thanks! Much clearer than the explanation in my book.  Just a little nitpick, I think you should use the term sets instead of groups as it's more specific and matches the term in the original question.
Comment: I guess that the same logic can be extended to any arbitrarily deep nesting of sets of sets?
Comment: @Robert S. Barnes: Hard to know about arbitrarily deep nesting until an explicit question is formulated.


Does there exist a homomorphism of commutative rings with unit from $\mathbb{Z}[x]/(x^2+3)$ to $\mathbb{Z}[x]/(x^2-x+1)$

Question: Does there exist a homomorphism of commutative rings with unit from $\mathbb{Z}[x]/(x^2+3)$ to $\mathbb{Z}[x]/(x^2-x+1)$? Either exhibit such a homomorphism, or prove that none exists.
The solution claims "The question amounts to whether $−3$ has a square root in the ring $\mathbb{Z}[x]/(x^2-x+1)$". Why?
Comment: If $\alpha\in \mathbb Z[x]/(x^2-x+1)$ satisfies $\alpha^2+3=0$ then you can define the homomorphism by sending $x\in \mathbb Z[x]/(x^2+3)$ to $\alpha$.
Answer: The idea is that $\mathbb{Z}[x]/(x^2-3) \simeq \mathbb{Z}[\sqrt{3}]$ with $\bar x$ mapping to $\sqrt{3}$, and similarly $\mathbb{Z}[x]/(x^2 - x + 1)\simeq \mathbb{Z}[\frac{1+ \sqrt{3}}{2}]$, with $x \mapsto ...$ . Now, there is a natural map ( inclusion ) that maps $\mathbb{Z}[\sqrt{3}] $ to $\mathbb{Z}[ \frac{1+ \sqrt{3}}{2}]$. Now one sorts out that $\bar x$ of the first ring has to go to $\overline{2x -1}$ of the second ring.


Jersey: com.sun.jersey.server.impl.template.ViewableMessageBodyWriter

Question: I'm totally alien to Jersey. I'm trying to run a jar which throws javax.ws.rs.WebApplicationException when I hit the endpoint. The error thrown by the program is as follows:
09-Apr-2011 08:32:20 com.sun.jersey.spi.container.ContainerResponse write
SEVERE: A message body writer for Java class java.lang.String, and Java type class java.lang.String, and MIME media type application/json was not found
09-Apr-2011 08:32:20 com.sun.jersey.spi.container.ContainerResponse write
SEVERE: The registered message body writers compatible with the MIME media type are:
/ ->
  com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
09-Apr-2011 08:32:20 com.sun.jersey.spi.container.ContainerResponse logException
Any ideas for where to start looking at for debugging?
Update: I've got javax.ws.rs.ext.MessageBodyWriter in the META-INF/services of the jar with the following content: com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
And at the beginning of the program I see: com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
Answer: You need to include jersey-json module on your class path - see the Jersey dependencies page, which has a list of dependencies you need to include based on the type of functionality you need: http://jersey.java.net/nonav/documentation/latest/chapter_deps.html


if $q \mid (2^p -1)$ then $q \equiv 1 \pmod{p}$

Question: Let $p,q$ be two primes, if $q \mid (2^p -1)$ then $q \equiv 1 \pmod{p}$.
My work: So far what i have done is noticed that since $q \mid (2^p - 1)$ we have that $2^p \equiv 1 \pmod{q}$ Therefore, $ord_{q}(2)\mid p$ and since $p$ is prime we must have that $ord_{q}(2)=p$. Similarly $ord_{q}(2) \mid \phi(q)=q-1$ and so $p\mid(q-1)$ in other words $q \equiv 1 \pmod{p}.$
The previous question on my homework asked me to prove,
If $m=a^n-1$, where $a,n$ are positive integers. Show that $ord_{m}(a)=n$
The question I proved above tells me to use this result which makes me think there is an error in my proof since I didn't seem to use it. Could someone take a look at my proof and let me know if it holds or not, thanks!
Comment: The only mistake in your argument is you didn't explain why $ord_q(2) \neq 1$ ($p$ has two divisors !). Otherwise your proof is correct
Comment: Using [Euler's theorem](https://en.wikipedia.org/wiki/Euler%27s_theorem) is allowed?
Comment: Yeah Euler's Theorem is allowed.
Comment: See  https://proofwiki.org/wiki/Factor_of_Mersenne_Number_Mp_is_of_form_2kp_%2B_1
Answer: Your proof is correct, assuming ...

You know how to prove "Therefore, $ord_q(2)\mid p$" part. With more details if $\gcd(a,q)=1$
$$a^n \equiv 1 \pmod{q} \Rightarrow ord_q(a)\mid n$$
Let's assume this is not true and apply Euclidean division, i.e. $n =ord_q(a)\cdot t + r$ where $0< r < ord_q(a)$. Then
$$1 \equiv a^n \equiv a^{ord_q(a)\cdot t + r}=a^r \pmod{q}$$
and because $0< r < ord_q(a)$, this contradicts the definition of $ord_q(a)$. So $r=0$.

You show that (as per the comment @Max left), given $a=2$ and $q$ is prime, $ord_q(2)>1$. Otherwise $2\equiv 1 \pmod{q} \Rightarrow q \mid 1$.


Does the 2-2-1-1-1 format get used in 7-game series anymore?

Question: I can't remember the last time I saw a playoff series in the NBA, NHL or MLB use the 2-2-1-1-1 format (as opposed to the 2-3-2).
I understand the motivation. Usually the travel distances are so great, even with LA currently playing the Houston Astros. But what if the Mets played the Yankees? Would they use 2-2-1-1-1? I miss it. It also feels like that is a more fair approach.
Comment: It may be more fair but the travel will be much harder on the players if they are traveling up to 4 times during the series rather then twice.
Comment: I have been following MLB for over 40 years, and my recollection is that they've always used 2-3-2 for 7 game series. They have switched from 2-3 to 2-2-1 for 5 game series. I'm not a huge hockey fan, but I don't recall anything but a 2-2-1-1-1 format. As noted below, the NBA has switched back and forth.
Answer: I believe the NHL still uses the 2-2-1-1-1 format. Three of the series in the most recent playoffs went to seven games and followed that format (PIT vs WAS in Eastern Semi Finals, ANA vs EDM in Western Semi Finals and OTT vs PIT in the Eastern Finals)
Answer: NBA used to be 2-3-2, but has moved back to 2-2-1-1-1 since 2014.
Note that the leagues using it (NHL/NBA) don't normally schedule back-to-back games during the playoffs.  So the impact of the travel day is reduced.
Baseball tends to prefer several games in a row.  4 travel days between 7 games would be an unusual pace.


How to get the arguments of a function pointer from a CallExpr in Clang?

Question: I am trying to analyse C++ source code with function calls within them. I am able to analyse normal function calls to get their arguments without problem using the source code below where ce is a CallExpr object:
1.  if(ce != NULL) {
2.      QualType q = ce->getType();
3.      const Type *t = q.getTypePtrOrNull();
4.
5.      if (t != NULL) {
6.          llvm::errs() << "TYPE: " << t->isFunctionPointerType() << " " << q.getAsString() << " " << t->isPointerType() << "\n";
7.      } else {
8.          llvm::errs() << "FUNCTION CE HAS NO TYPE?\n";
9.      }
10.
11.
12.     const Decl* D = ce ->getCalleeDecl();
13.     while(D->getPreviousDecl() != NULL)
14.         D = D->getPreviousDecl();
15.
16.     llvm::errs() << "Kind:  " << D->getDeclKindName() << "\n";
17.
18.     FunctionDecl* fd = (FunctionDecl*) llvm::dyn_cast<FunctionDecl>(D);
19.     for(int x = 0; x< fd ->getNumParams(); x++) {
20.         if(fd ->getParamDecl(x)->getType()->isAnyPointerType()) {
21.             // Do Stuff Here
22.         }
23.     }
24. }

The problem with the above source code comes on line 18, when I try to typecast the Decl from the CallExpr to a FunctionDecl, this results in fd becoming NULL if the CallExpr is from a function pointer call.
I tried to debug by trying to print the kind on line 16. For function pointers, it specifies the Decl on 12 is a VarDecl, not a FunctionDecl like normal function calls.
I also tried using the isFunctionPointerType(), but this is returning false.
Here is a piece of source code that results in a segfault:
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
    void* (*mp)(size_t size);
    void *mpp;

    mp = &malloc;
    mpp = mp(30);

    free(mpp);
    return (0);
}

Is there a way using clang to detect whether a CallExpr is a function pointer call? and if so, how to get a list of the arguments?
I am using clang 3.1
Thanks
Comment: If you already have an answer, please post it below and self-accept.
Comment: this is C++ not C
Answer: Use getDirectCallee() function (I am not sure if it is available in clang 3.1 or not)

    FunctionDecl *func = ce->getDirectCallee();
if (func != NULL){
    for(int i = 0; i < func->getNumParams(); i++){
        if(func->getParamDecl(i)->getType()->isFunctionPointerType()){
            // Do stuff here
        }
    }
}

Answer: You should get function prototype from pointer declaration, after that you will be able to get information about return type and parameters types:
clang::CallExpr* expr;
...
auto decl = expr->getCalleeDecl();
if (decl != nullptr) {
    if (decl->getKind() == clang::Decl::Var) {
        clang::VarDecl *varDecl = clang::dyn_cast<clang::VarDecl>(decl);
        if(varDecl->getType()->isFunctionPointerType() == true) {
            const clang::PointerType *pt = varDecl->getType()->getAs<clang::PointerType>();
            const clang::FunctionProtoType *ft = pt->getPointeeType()->getAs<clang::FunctionProtoType>();
            if (ft != nullptr) {
                std::string retTypeName = ft->getReturnType().getAsString();
                ...
                auto paramsCount = funcType->getNumParams();
                for (size_t i = 0; i < paramsCount; ++i) {
                    clang::QualType paramType = funcType->getParamType(i);
                    std::string paramTypeName = paramType.getAsString();
                    ...
                }
            }
        }
    }
}

Answer: May be you can also use getArg(position) to get particular argument and before that you should use getNumArgs to get details about number of argument that function contains.


KDB generating ERROR:file/path/location/sym os reports: No such file or directory

Question: I am trying to save table as partition using .Q.dpt[hdbroot;.z.d;`tablename].
But it's generating No such file or directory error, but the directory is present.
can you please help me on this.
I have created blank folder to store the data but it's checking for sym file while storing data.
I have created one blank folder and gave that folder path to hdbroot variable, but it's not working.
Comment: Could you provide the exact error output for us? There is not much information to go on here. .Q.dpt calls .Q.en which will create the sym file it it's not present, so it's not correct to say that kdb is checking and failing to find the sym file. Does the output in the error and the hdbroot variable exactly match what you expect? You can use `key` to determine whether a directory exists or not from kdb. What does `key hdbroot` return? An empty folder returns an empty symbol vector; a non-existent folder returns an empty general list. https://code.kx.com/q/ref/key/#whether-a-folder-exists
Answer: I could replicate your error by trying to save to a location that doesn't exist on the machine.
q).Q.dpt[`:/does/not/exist;.z.d;`t]
'/does/not/exist/sym. OS reports: No such file or directory
  [0]  .Q.dpt[`:/does/not/exist;.z.d;`t]

Like I mentioned in my comment, make sure that the hdbroot variable is exactly the location you're expecting. key can help you determine this, here is a quick helper function for you.
q)exists:{"Folder/file ",$[11=abs type key x;"exists";"does not exist"]}
q)exists`:/does/not/exist
"Folder/file does not exist"
q)exists`:/tmp
"Folder/file exists"


Postfix won't accept SASL logins

Question: I've followed this guide to setup an email server with IMAP and SMTP. IMAP is working great, but SMTP doesn't work.
If I try to send a message using telnet:
MAIL FROM: <email@example.com>
250 2.1.0 Ok
RCPT TO: <firstname.lastname@example.com>
554 5.7.1 <firstname.lastname@example.com>: Relay access denied
Attempting to login with my mail client (Mail.app on OS X Lion) gives this error in the system log:
postfix/smtpd[13322]: warning: my.computer.hostname[188.8.131.52]: SASL PLAIN authentication failed: no mechanism available
The client says "The server rejected the password given."
What can I do to get email relaying working?
Answer: The issue was related to this bug. Following the temporary solution steps (downgrading temporarily) provided a fix. Hopefully the bug will be fixed soon and I'll be able to upgrade.

Postfix won't accept SASL logins


Site name is not changing in

Question: When I change the site name in admin/config/system/site-information it has no effect on the site name between the title tags. It always shows "Drupal" as the site name.
I'm using the Basic theme with the same implementation as in the core themes:
<code><title>{{ head_title|safe_join(' | ') }}</title>
</code>
I already checked the translations and the site name is also not hard coded in settings.php
Comment: It goes without saying, but have you cleared your Drupal caches?
Comment: 1 million times .D
Comment: nobody an idea?
Answer: I had same problem, and I solved it after reading this article:
Source : https://www.drupal.org/node/2844755
you can do it step by step :

Change the default language to English.
Delete the other language.
Clear the cache.
Change the site name.
Add the other language and set it back to default.

It works after adding new language again
Comment: Yes, I discovered this thread too in the meantime and solved the problem. Just forgot to mention in here.
Answer: I was not able to change the front page title of my drupal 8 site
I have done it by Jquery, and used the following code in the front page twig file.

    document.title="new title";

It worked for me

Site name is not changing in


MySQL: Too many open files (24) BUT open_files has not reached open_files_limit?

Question: I have an issue with the following error:
Too many open files (24)
And after lots of hours researching, we noticed that Open_files status do show a count of files opened, but the error occured when this number was below the open_files_limit setting? How is this possible?
We are using table_open_cache setting as well and after reading how MySQL documentation about table_open_cache and how MySQL opens and closes tables, we start to think it's because that the status count open_files does not calculate the tables opened that goes into table_open_cache, but not sure.
Any clear answer on how this can be possible?
Comment: What were the hard and soft ulimit values? How many files were open? Code 24 is EMFILE, which means you hit the system/process limit for open file descriptors.
Comment: What Linux distribution? How did you install the MySQL server? How did you start it?
Comment: From https://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html "It does not include other types of files such as sockets or pipes. Also, the count does not include files that storage engines open using their own internal functions rather than asking the server level to do so." And that has nothing to do with the os ulimit.
Comment: @MichaelHampton Amazon Linux AMI, installed the MySQL like normal? Also started it like normal? sudo service mysqld start. Not really sure if these answers help.
Comment: @symcbean I have taken notes to that line, but what does that even mean? Is table_open_cache then not being calculated to the count of open files?
Answer: The current version of Amazon Linux AMI utilises systemd.  If that's what you are using whatever you set in /etc/security/limits.conf will be ignored by systemd.
Find the .service file for your version of MySQL and update it.  For example:
/usr/lib/systemd/system/mysqld.service

Under the Service section add the following:
[Service]
LimitNOFILE=4096

Change 4096 to the limit you need.
Afer you update that file reload the systemd configuration:
systemctl daemon-reload

Then restart the mysql server.
Comment: But i have already changed the limit in limits.conf which is confirmed when i check with query: SHOW VARIABLES LIKE 'open_files_limit'; ? and can see that the open_files status count is using more files than the previous limitation there was. So this is not the cause to my case?
Comment: Maybe check to see how many threads are being opened by the mysql process?
Answer: Run following commands to see open-files limit:
mysql> select @@max_open_files ;

And from system side:
#sudo -u mysql bash
$ulimit -Sn
$ulimit -Hn

Add following line into your my.cnf:
open-files-limit = 4096

Eximine /etc/security/limits.conf for strings with mysql, and add it if needed:
# echo "mysql           soft    nofile          4096" >> /etc/security/limits.conf
# echo "mysql           hard    nofile          4096" >> /etc/security/limits.conf

Then restart mysql-server
Сhange the value to the one you need
Comment: Thanks for instructions on how to raise the limit, although this does not answer my question at all. ulimit are already set to another number and the open files limit is also set to it.
Comment: As I know, **open_files_limit** should be increased after increasing parametrs like `table_cache, max_connections, max_tmp_tables`.

Which OS mysql-server is running on? If you are using CentOS 7, you should check `cat /proc/$(pidof mysqld)/limits`. And check init-file in systemd directory for limits. Add `LimitNOFILE=4096` in `[Service]` block if needed. Then run `systemctl daemon-reload && systemctl restart mysqld`


Proof that $\mathbb{Q}(x) \not \subseteq \mathbb{Q}(x+i)$

Question:
Let $x\in \mathbb{R}$ be transcendental over $\mathbb{Q}$. I want to show that $\mathbb{Q}(x) \not \subseteq \mathbb{Q}(x+i)$.

So I assume that $\mathbb{Q}(x) \subseteq \mathbb{Q}(x+i)$ $\Rightarrow $ $i\in \mathbb{Q}(x+i)$
I know that shouldn't be possible but I can't find the right words to express that. Maybe that $i$ could then be expressed as a linear combination of $x+i$ but that isn't possible because $x+i$ is transcendental?
Comment: Wouldn't this mean there exist coprime $f,g\in\mathbb{Q}[X]$ with $i=\frac{f(x+i)}{g(x+i)}$? So then $i\cdot g(x+i)-f(x+i)=0$ as a 'polynomial' in $x$ with coefficients in $\mathbb{Q}$? Using that they are coprime, $f,g\in\mathbb{Q}$, but $i\not\in\mathbb{Q}$.
Comment: @HennoBrandsma Because by field axioms $i = (x+i) - x$ must be in $\mathbb{Q}(x+i)$
Comment: Duplicate of https://math.stackexchange.com/questions/4296633/prove-that-x-is-transcendental-base-of-mathbbqx-i
Answer: Suppose that $i \in \mathbb{Q}(x + i)$. Then there are polynomials $f(t), g(t) \in \mathbb{Q}[t]$ with
$$
i = \frac{f(x+i)}{g(x+i)}
$$
in $\mathbb{Q}(x, i)$.
Write $f(t) = \sum_{k=0}^m a_kt^k$ and $g(t) = \sum_{k=0}^n b_kt^k$, for $a_k, b_k \in \mathbb{Q}$ with $a_m, b_n$ nonzero. Then $ig(x+i) = f(x+i)$ in $\mathbb{C}[x]$, so
$$
i\sum_{k=0}^nb_k(x+i)^n = \sum_{k=0}^ma_k(x+i)^k
$$
as polynomials in $\mathbb{C}[x]$. Comparing leading coefficients, we must have $m=n$ and $ib_n = a_n$. But since $b_n$ is nonzero, we have $i = \frac{a_n}{b_n} \in \mathbb{Q}$, which is a contradiction.


Confusion with lottery probabilities.

Question: Problem
I tried to compute some probabilities for a lottery (6/49 to be specific) and found a discrepancy between two ways to compute the same probability, so I must have done something wrong. But I do not see at which point my thoughts diverge from reality.
The lottery works as follows. There are $N$($=49$) numbers to choose from ($1,\dots,N$) and a correct solution consisting of $n$($=6$) of those numbers all different from one another. The player tries to guess the correct solution by also choosing $n$ distinct numbers. The order of the numbers does not matter.
Mathematically, the solution space $\mathcal L$ consists of all subsets of $\{1,\dots,N\}$ with cardinality $n$, and has $|\mathcal L|=\binom Nn$ elements. If $\ell_0\in\mathcal L$ is the correct solution, then $C(\ell)=|\ell\cap\ell_0|$ is the number of correctly guessed numbers.
I tried to find formulas for $P(C=k)$ and $P(C\geq k)$, but the formulas I found do not satisfy $P(C\geq k)=\sum_{j=k,\dots,n}P(C=j)$ even though $\{C\geq k\}=\bigcup_{j=k,\dots,n}\{C=j\}$ is a disjoint union.
My approach
To find $P(C=k)=|\{C=k\}|\big/|\mathcal L|$ I need to count all sets $\ell\in\mathcal L$ where $k$ numbers are correct (i.e. belong to $\ell_0$) and where the other $n-k$ numbers of $\ell$ are not correct (i.e. belong to $\{1,\dots,N\}\setminus\ell_0$). I count $\binom nk$ possibilities for the former condition and $\binom{N-n}{n-k}$ possibilities for the latter condition, giving me $$P(C=k)=\frac{\displaystyle\binom nk\binom{N-n}{n-k}}{\displaystyle\binom Nn}.$$
Similarly, to find $P(C\geq k)=|\{C\geq k\}|\big/|\mathcal L|$ I need to count all sets $\ell\in\mathcal L$ where $k$ numbers are correct (i.e. belong to $\ell_0$) and where the other $n-k$ numbers of $\ell$ are arbitrary (i.e. can be any of the remaining $N-k$ numbers, regardless of whether they are correct or not). I count $\binom nk$ possibilities for the former condition and $\binom{N-k}{n-k}$ possibilities for the latter condition, giving me $$P(C\geq k)=\frac{\displaystyle\binom nk\binom{N-k}{n-k}}{\displaystyle\binom Nn}$$
Error
If I compute $P(C\geq k)$ using the formulas above for $(N,n,k)=(49,6,3)$ I get
$$
P(C\geq k)
=\frac{50}{2,303}
\color{red}\neq
\frac{4,654}{249,711}
=\frac{8,815}{499,422}+\frac{645}{665,896}+\frac{43}{2,330,636}+\frac{1}{13,983,816}
=\sum_{j=k,\dots,n}P(C=j),
$$
which means I miscounted $\{C\geq k\}$ and $\bigcup_{j=k,\dots,n}\{C=j\}$ by about 43,000 elements. I strongly suspect that my formula for $P(C\geq k)$ is wrong. Any insight is appreciated.
Comment: Your $P(C\ge k)$ is overcounting. For example $(N, n, k) = (49, 6, 3)$ and if the winning solution is $\ell_0 = \{1,\ldots, 6\}$, then $\ell$ like $\{1,2,3,4,48,49\}$ are counted multiple times, because the $1,...,4$ are counted both among the $k$ numbers $\in \ell_0$ and among the $n-k$ arbitrary numbers.
Comment: Maybe the summation formula is the easiest, though I have not tried simplifying it.
Answer: For solutions $\ell$ that has $j$ matching numbers, your $P(C\ge k)$ formula is overcounting $\binom jk$ times as many as it should be.
For example $(N, n, k) = (49, 6, 3)$ and if the winning solution is $\ell_0 = \{1,\ldots, 6\}$, then $\ell$ like $\{1,2,3,4,48,49\}$ are counted multiple times, because the $1,...,4$ are counted both among the $k$ numbers $\in \ell_0$ and among the $n-k$ arbitrary numbers.
$$\begin{align*}
\sum_{j=k}^n P(C=j)&\ne\sum_{j=k}^n \binom{j}{k}P(C=j)\\
&= \sum_{j=k}^n \binom{j}{k}\cdot\frac{\dbinom nj\dbinom{N-n}{n-j}}{\dbinom Nn}\\
&= \frac{1}{\dbinom Nn}\sum_{j=k}^n\dbinom nj\dbinom jk\dbinom{N-n}{n-j}\\
&= \frac{1}{\dbinom Nn}\sum_{j=k}^n\dbinom nk\dbinom {n-k}{j-k}\dbinom{N-n}{n-j}&\dbinom nj\dbinom jk = \dbinom nk\dbinom {n-k}{j-k}\\
&= \frac{\dbinom nk}{\dbinom Nn}\sum_{j=k}^n\dbinom {n-k}{j-k}\dbinom{N-n}{n-j}\\
&= \frac{\dbinom nk}{\dbinom Nn}\sum_{j'=0}^{n-k}\dbinom {n-k}{j'}\dbinom{N-n}{n-k-j'}&j' = j-k\\
&= \frac{\dbinom nk}{\dbinom Nn}\dbinom{N-k}{n-k} &\text{by Vandermonde's identity}
\end{align*}$$
Comment: Thank you very much! This problem has driven me crazy for the last couple of hours. P.S. Very nice proof :)

Confusion with lottery probabilities.


How to prove SSE and SSR are independent

Question: Consider $Y=X\beta+\varepsilon$, where $X$ is n by p, $\beta$ is p by 1 and $\varepsilon$ is n by 1 with covariance matrix = var($\varepsilon$)=$\sigma^2 I$.
Give expression for the regression and error sums of squares, find their expected values, and show that they are independent.
My work:
One has $SSE=Y^{T}Y-\hat{\beta}^{T}X^{T}Y=Y^{T}(I-X(X^{T}X)^{-1}X^{T})Y$, and $SSR=Y^{T}(X(X^{T}X)^{-1}X^{T}-\frac{1}{n}J)Y$. For $SSE$, it is easy to get its distribution. But I have difficulty to get the distribution of $SSR$, I was trying to prove $X(X^{T}X)^{-1}X^{T}-\frac{1}{n}J$ is idempotent. But it seems not easy for me.
Also I have difficulty to prove $(I-X(X^{T}X)^{-1}X^{T})(X(X^{T}X)^{-1}X^{T}-\frac{1}{n}J)=0$. Can someone help me here?
Comment: Your question has a flaw. You did not say what distribution $\epsilon$ follows yet you are trying to find the law!!
Answer: Anyway here is a series of results that'll help you understand what's going on (I am assuming Euclidean norm i.e. $\langle u,v\rangle=u'v$)
Definition: Let $V\subset \mathbb{R}^n$ be a sub-space. $P_{n\times n}$ is a projection onto $V$ if
1) $\forall x\in V$ we have $P.x=x$ and
2) $\forall x\in V^{\perp}$ we have $P.x=0$
Theorem 1: If $P_{n\times n}$ is the projection onto $V\subset \mathbb{R}^n$ $\iff$ $P$ is idempotent symmetric and $\mathscr{C}(P)=V$.
Theorem 2: Let $o_1,...,o_r$ be any orthonormal basis of $V$(of course with rank $r\leq n$). Then the projection matrix onto $V$ is $P=OO'$ where $O=[o_1,...,o_r]_{n\times r}$
Theorem 3: Suppose you are given a $n\times p$ matrix $X$ with rank $p$. Then $X(X'X)^{-1}X'$( say $P_X$) is the projection onto $\mathscr{C}(P)=\mathscr{C}(X)$. Also by the prior theorem if you can find $p$-many orthonormal basis (since columns of $X$ are independent you can always do Gram-Schmidt) then $P_X$ will also be equal to $OO'$ (since Projection onto a given space is unique).
Theorem 4: $Y\sim N_p(\mu,I)$ and $P$ be any projection matrix then $Y'PY \sim \chi^2_{\operatorname{rank}(P)}(\frac{1}{2}\mu'P\mu)$ i.e. with $d.f.=\operatorname{rank}(P)$ and non-centrality parameter $\frac{1}{2}\mu'P\mu$
Proof: It's not hard at all. Since $P$ is symmetric it can be written in Spectral Decomposition form i.e. $P=\Gamma D \Gamma'\implies Y'DY=Y\Gamma D \Gamma'Y=Z'DZ=\sum d_i.Z_i^2$
Fact: Under normality un-correlation $\iff$ independence.
Assume $\epsilon \sim N_n(0,\sigma^2I)$. Then $Y \sim N_n(X\beta,\sigma^2I)$. In this set-up $\mu=X\beta\in\mathscr{C}(X)$. Hence $SSE=Y'(I-P_X)Y \sim \chi^2_{n-p}(0)$
[Important: $I-P_X$ is the Orthogonal Projection of $\mathscr{C}(X)$ i.e. if you take a vector $v$ from $\mathscr{C}(X)$ (which is indeed of the form $X.u$) then $(I-P_X)v=0$. So the non-centrality parameter $\frac{1}{2}\mu'(I-P_X)\mu=\frac{1}{2}X\beta'(I-P_X) X\beta=0$.]
For SSR the matrix involved $P_X-\frac{J}{n}$ is not necessarily a projection matrix! But if you have an intercept term in your regression then it will be i.e. the model looks like $y_i=\beta_1+\sum x_{ij}.\beta_j$ or in other words $X$ has $1$ as one of it column i.e. $1\in \mathscr{C}(X)$. If we have so, $$P_X.\mathbb{1}=1\implies \left(P_X-\frac{J}{n}\right)\left(P_X-\frac{J}{n}\right)=\cdots=P_X-\frac{J}{n}$$ i.e. idempotent! Thus we can apply Theorem 4.
For independence of SSE and SSR use the fact that $(I-P_X)(P_X-\frac{J}{n})=0$
Answer: To prove $(I-X(X^{T}X)^{-1}X^{T})(X(X^{T}X)^{-1}X^{T}-\frac{1}{n}J)=0$ , we only need to prove:
\begin{split}
\mathbf{1_n(1_n)^T} = X(X^{T}X)^{-1}X^{T}\mathbf{1_n(1_n)^T}
\end{split}
And $\mathbf{1_n}$ is the $n\times1$ matrix with all elements are $1$
Notice that $X = \begin{bmatrix}
  \mathbf{1}& X_1
\end{bmatrix}$ that is the elements of first column are all $1$.
Consider the generalized-inverse matrix $X^-$ satisfies that:
\begin{split}
XX^-X=X
\end{split}
And because the first column of $X$ is $\mathbf{1_n}$, so we have:
\begin{split}
XX^-\mathbf{1_n}=\mathbf{1_n}
\end{split}
which is very important!!!
Then replace $\mathbf{1_n}$ in $X(X^{T}X)^{-1}X^{T}\mathbf{1_n(1_n)^T}$ with $XX^-\mathbf{1_n}$ , then we have:
\begin{split}
X(X^{T}X)^{-1}X^{T}\mathbf{1_n(1_n)^T}&=X(X^{T}X)^{-1}X^{T}XX^-\mathbf{1_n}\mathbf{(1_n)^T}\\ &= XX^{-}\mathbf{1_n(1_n)^T}\\
&=\mathbf{1_n(1_n)^T}
\end{split}
So we complete our proof.
Actually we can find the inverse of $(X^{T}X)^{-1}$ by using $X = \begin{bmatrix}
  \mathbf{1}& X_1
\end{bmatrix}$ and we can get the same answer.


About CNN, kernels and scale/rotation invariance

Question: I have a couple of questions that are confusing me regarding the CNN.
1) The features extracted using CNN are scale and rotation invariant?
2) The Kernels we use to convolution with our data are already defined in the literature? what kind of these kernels are? is it different for every application?
Answer:
1) The features extracted using CNN are scale and rotation invariant?

A feature in itself in a CNN is not scale or rotation invariant. For more details, see: Deep Learning. Ian Goodfellow and Yoshua Bengio and Aaron Courville. 2016: http://egrcc.github.io/docs/dl/deeplearningbook-convnets.pdf ; http://www.deeplearningbook.org/contents/convnets.html:

Convolution is not naturally equivariant to some other transformations, such
  as changes in the scale or rotation of an image. Other mechanisms are necessary
  for handling these kinds of transformations.

It is the max pooling layer that introduces such invariants:

2) The Kernels we use to convolution with our data are already defined in the literature? what kind of these kernels are? is it different for every application?

The kernels are learnt during the training phase of the ANN.
Comment: Note that the pooling you're talking about is refered to as cross-channel pooling and is *not* the type of pooling which is usually refered to when talking about "max-pooling", which only pools over spatial dimensions (not over different input channels).
Comment: Does this imply a model which does not have any max-pool layers (most of the current SOTA architectures do not use pooling) is completely scale dependent?
Comment: @Franck 1) That means, we don't take any special steps to make over system rotation invariant? and how about the scale invariant, is it possible to get the scale invariant from the max pooling?
Comment: So does pooling make the network only *slightly* invariant to scaling and rotation?
Comment: I cannot speak to the details in terms of the current state of the art, but on the topic of point 1, I found [this](http://techtv.mit.edu/collections/bcs/videos/30698-what-s-wrong-with-convolutional-nets) interesting.
Comment: 2)  The kernels are the features. I didn't get that. [Here]
(http://www.wildml.com/2015/11/understanding-convolutional-neural-networks-for-nlp/)
They have mentioned that " For example, in Image Classification a CNN may learn to detect edges from raw pixels in the first layer, then use the edges to detect simple shapes in the second layer, and then use these shapes to deter higher-level features, such as facial shapes in higher layers. The last layer is then a classifier that uses these high-level features."
Comment: (Cont (2))
Therefore, what i want to is the Kernel/Filter we use in our First, second and third layer are defined by the user or these kernels are fixed 3x3, 5x5 ....etc matrix to extract the edges?
Comment: @AadnanFarooqA sorry, I should've said that kernels are learnt during the training phase. "Features" loosely refer to the input of a layer. I corrected the answer.
Comment: @FranckDernoncourt Thanks for correction. But it confuse me more.
we usually do convolution between kernel and the input image at first layer.. is it right?
Comment: @AadnanFarooqA the ANN may have several convolution layers.
Comment: @FranckDernoncourt Yes it may have.. but let's talk about the first only.. we convolve out input image with the kernel.. that's correct i think.
I want to know how we define that kernel??
Answer: I think there are a couple of things confusing you, so first things first.
Given a signal $x[n]$, and a kernel (also called a filter) $h[n]$, then the convolution of $x[n]$ with $h[n]$ is written as $y[n] = (x \star h)[n]$, and is computed via a sliding dot-product, mathematically given by:
$$
y[n] = \sum_{m=-\infty}^{\infty}x[m] \ h[n-m]
$$
The above if for one-dimensional signals, but the same can be said for images, which are just two-dimensional signals. In that case, the equation becomes:
$$
I_{new}[r,c] = \sum_{u=-\infty}^{\infty}\sum_{v=-\infty}^{\infty} I_{old}[u,v]  \ k[r-u, c-v]
$$
Pictorially, this is what is happening:

At any rate, the thing to keep in mind, is that the kernel, in actually learned during training a Deep Neural Network (DNN). A kernel is just going to be what you convolve your input with. The DNN will learn the kernel, such that it brings out certain facets of the image (or previous image), that are going to be good for lowering the loss of your target objective.
This is the first crucial point to understand: Traditionally people have designed kernels, but in Deep Learning, we let the network decide what the best kernel should be. The one thing we do specify however, is the kernel dimensions. (This is called a hyperparameter, for example, 5x5, or 3x3, etc).
Comment: Nice explanation. Can you please answer the First part of the question. About the CNN is scale/rotation Invariant?
Comment: @AadnanFarooqA I will do so tonight.
Answer: Many authors including Geoffrey Hinton (who proposes Capsule net) try to solve the issue, but qualitatively. We try to address this issue quantitatively. By having all convolution kernels be symmetric (dihedral symmetry of order 8 [Dih4] or 90-degree increment rotation symmetric, et al) in the CNN, we would provide a platform for the input vector and resultant vector on each convolution hidden layer be rotated synchronously with the same symmetric property (i.e., Dih4 or 90-increment rotation symmetric, et al). Additionally, by having the same symmetric property for each filter (i.e., fully connected but weighs sharing with the same symmetric pattern) on the first flatten layer, the resultant value on each node would be quantitatively identical and lead to the CNN output vector the same as well. I called it transformation-identical CNN (or TI-CNN-1). There are other methods that can also construct transformation-identical CNN using symmetric input or operations inside the CNN (TI-CNN-2). Based on the TI-CNN, a geared rotation-identical CNNs (GRI-CNN) can be constructed by multiple TI-CNNs with the input vector rotated by a small step angle. Furthermore, a composed quantitatively identical CNN can also be constructed by combining multiple GRI-CNNs with various transformed input vectors.

"Transformationally Identical and Invariant Convolutional Neural Networks through Symmetric Element Operators"
https://arxiv.org/abs/1806.03636  (June 2018)
"Transformationally Identical and Invariant Convolutional Neural Networks by Combining Symmetric Operations or Input Vectors"
https://arxiv.org/abs/1807.11156  (July 2018)
"Geared Rotationally Identical and Invariant Convolutional Neural Network Systems"
https://arxiv.org/abs/1808.01280  (August 2018)
Answer: I think max pooling can reserve translational and rotational invariances only for translations and rotations smaller than the stride size. If greater, no invariance
Comment: could you expand a little bit? We encourage answers on this site to be a little bit more detailed than this (right now, this looks more to a comment). Thank you!


O que significa os três pontinhos ... antes de document.querySelectorAll

Question: No código a seguir o que significa os três pontinhos que antecedem document.querySelectorAll
const [marcas, valor] = [...document.querySelectorAll('input.classNew')];

marcas.addEventListener('keyup', function() {
    //codigo
}

Fiz inúmeras buscas no site e no Google sem obter exito.

Obs: sei que se retirar um ou mais pontinho dá erro no script
Comment: @AndersonCarlosWoss, valeu!!!!
Comment: Relacionada: [Quais são as melhorias que a implementação do Spread Operator trará para o javascript?](https://pt.stackoverflow.com/q/111497/5878)
Comment: Eu positivei a pergunta e negativei as duas respostas, acredito que votar como duplicata é a melhor ação nessa "boa" pergunta
Comment: A principal vantagem e poder copiar o array invés de passar a referencia.
Comment: @MarceloBoni, após o @ AndersonCarlosWoss ter me indicado os links eu ia remover a pergunta mas as respostas dadas não me deixam remover.
Comment: @MarceloBoni é legal você ler "quando negativar uma resposta" que diz claramente que você deve negativar apenas quando a resposta está perigosamente errada. Atitudes como  a que foi tomada nesse caso desmotivam a responder. [Aqui](https://pt.stackoverflow.com/help/privileges/vote-down) você confere uma explicação de quando você deve votar contra.
Comment: @Sorack a resposta não está errada, mas acabam tirando o mérito das outras respostas (posso estar enganado e pode até ser exagero), acredito que vincular as outras respostas a está pergunta e fecha-la como duplicata, talvez possa vir a ser o melhor nesse caso (mais uma vez, pode ser um exagero da minha parte)
Comment: @MarceloBoni sim, é exagero e o modo errado de usar o downvote, como você pode ler no que eu linkei. Vou ressaltar aqui "Use os votos contra quando encontrar uma publicação destacadamente negligente e malfeita ou uma resposta que esteja claramente, e talvez perigosamente, incorreta.". E também "Os votos contra devem ser reservados para casos extremos".
Comment: Downvote é coisa de super gênio preguiçoso. Sabe pra caramba, acha sua pergunta/resposta incorreta mas NÂO apresenta argumentos. No meu caso, dessa pergunta, ele deve ter achado que eu tinha obrigação de saber a respeito desse operador ou talvez não tenha visto minha dificuldade `Fiz inúmeras buscas no site e no Google sem obter exito.`
Answer: É o operador Spread do Javascript.
Você expande uma expressão em que há múltiplos argumentos, por exemplo:
function sum(a,b) {
    return a+b;
}

let myArray = [1, 2];
console.log(sum(...myArray)); //3

let spreadInArray = [3, 4, ... myArray];
console.log(spreadInArray); //[ 3, 4, 1, 2 ]

Answer: Essa é uma sintaxe do ES6 chamada operador spread.

Operador Spread
O operador spread permite uma expressão ser expandida em locais onde múltiplos argumentos (por chamadas de função) ou múltiplos elementos (por array literais) são esperados.

Basicamente no seu caso serve para definir que os elementos contidos no array serão utilizados 1 a 1 dentro de outro array, atribuindo o primeiro valor à variável marcas e o seguindo a variável valor.
Comment: `O basicamente no seu caso .... utilizados 1 a 1 dentro de outro array` foi decisivo para que eu entendesse claramente o significado do `Operador Spread`


Integration with complex infinity

Question: I'm struggling to solve this problem.
$$
\int_{-\infty}^{\infty} e^{-a(x+di)^2} dx
$$
I tried
$$
t = \sqrt{a}(x+di)
$$
$$
=> dt = \sqrt{a}dx
$$
$$
=> \int_{-\infty}^{\infty} \frac{e^{-t^2}}{\sqrt{a}} dt
$$
since $\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}$,
$$
=> \int_{-\infty}^{\infty} \frac{e^{-t^2}}{\sqrt{a}} dt = \sqrt{\frac{\pi}{a}}
$$
$$
=> \int_{-\infty}^{\infty} e^{-a(x+di)^2} dx  = \sqrt{\frac{\pi}{a}}
$$
However, I have found that complex infinity has only magnitude without arguments.
It means I can't regard domain of t as (-$\infty$,$\infty$) when $t = \sqrt{a}(x+di)$ and $x(-\infty, \infty)$.
And I found the correct answer is $\sqrt{\frac{\pi}{a}}e^{ad^2}$.
How can I reach to this answer? I lost my way.
Answer: Here is the way I like to do it, avoiding contour integration.  Fix a real number $a>0$.  Define a function of a complex variable $k$ by
$$
F(k) := \int_{-\infty}^\infty \exp\left(-a(x+k)^2\right)\;dx
$$
When $k$ is real, do the change of variables suggested (the real line maps to the real line for that change of variables) to get
$$
F(k) = \sqrt\frac{\pi}{a} \qquad \text{if } k \in \mathbb R.
$$
Next, from Morera's theorem, $F$ is an entire function of the complex variable $k$.  Therefore
$$
F(k) = \sqrt\frac{\pi}{a} \qquad \text{if } k \in \mathbb C.
$$

Your assertion about "the correct answer" is wrong.  Your answer is actually for
$$
\int_{-\infty}^\infty \exp\left(-a(x^2+(id)^2)\right)\;dx = \sqrt\frac{\pi}{a}\;e^{ad^2}
$$

Integration with complex infinity


Generate testcategory based on vsmdi file

Question: I'm upgrading a couple of big solutions from Visual Studio 2010 to Visual Studio 2012. Now I want to delete the .vsmdi files for the unit tests. I want to use the new TestCategory attribute.
Is it possible to generate the test categories above the test methods bases on a list in the vsmdi file? So in example I have the lists "Shoppingcart" and "Nightly" and if the test is in that vsmdi list, the category is set above the method.
A simple find replace (multiple times per list?) is also a good solution. The problem is that we have a couple of thousand tests where one or multiple categories should be placed.
thanks
Answer: I just went through this.  Our VSMDI defined several lists and covered around 2500 tests.  Unfortunately I couldn't find a one-stop utility, but I did manage to get it done with a quick and dirty console app in combination with an existing test list migration tool: http://testlistmigration.codeplex.com/
This extension will produce Test Play Lists from the vsmdi, a smiple XML structure with full test names.  My utility reads the play list XML into a HeapSet, then iterates each test file in a directory, parses each method that begins with [TestMethod], checks whether it's referenced in the play list and if so adds the test category attribute.  It's ugly, but it works and I wrote it in about an hour.
Here is the C# code...and remember it was written hastily with no regard to aesthetic or best practice. It solved my problem and would otherwise be thrown away if not for this post :)
<code>using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using TestListMigration.Properties;

namespace TestListMigration
{
    class Program
    {
        static void Main(string[] args)
        {
            HashSet<string> tests = new HashSet<string>();
            XmlDocument doc = new XmlDocument();
            doc.Load(Settings.Default.Playlist);
            XmlElement root = doc.DocumentElement;
            XmlNodeList nodes = root.SelectNodes("Add");
            foreach (XmlNode node in nodes)
            {
                tests.Add(node.Attributes["Test"].Value);
            }
            DirectoryInfo di = new DirectoryInfo(Settings.Default.TestPath);
            foreach (FileInfo file in di.GetFiles("*.cs",SearchOption.AllDirectories))
            {
                var testFileReader =file.OpenText();
                string fileContent = testFileReader.ReadToEnd();
                testFileReader.Close();
                bool dirty = false;
                var namespaceMatch = Regex.Match(fileContent, @"namespace ([a-zA-Z\.]*)");
                if (namespaceMatch.Success){
                    string namespaceName = namespaceMatch.Groups[1].Value;
                    var classNameMatch = Regex.Match(fileContent, @"[\n\r\t ]*(public|internal|public sealed) class ([a-zA-Z0-9\.]*)");
                    if (classNameMatch.Success)
                    {
                        string className = classNameMatch.Groups[2].Value;
                        StringBuilder newFile = new StringBuilder();
                        StringReader reader = new StringReader(fileContent);
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            newFile.AppendLine(line);
                            if (line.Contains("[TestMethod]") || line.Contains("[TestMethod()]"))
                            {
                                bool methodLineRead = false;
                                StringBuilder buffer = new StringBuilder();
                                while (!methodLineRead)
                                {
                                    line = reader.ReadLine();
                                    buffer.AppendLine(line);
                                    if (line.Contains("void")){
                                        methodLineRead=true;
                                        var testNameMatch = Regex.Match(line, @"[\n\r\t ]*public void ([a-zA-Z\._0-9]*)\(\)");
                                        if (testNameMatch.Success)
                                        {
                                            string fullName = namespaceName + "." + className + "." + testNameMatch.Groups[1].Value;
                                            if (tests.Contains(fullName) && !buffer.ToString().Contains("\t\t[TestCategory(Category." + Settings.Default.Category + ")]"))
                                            {
                                                newFile.AppendLine("\t\t[TestCategory(Category." + Settings.Default.Category + ")]");
                                                dirty = true;
                                            }
                                        }
                                    }
                                }
                                newFile.Append(buffer.ToString());
                            }
                        }
                        if (dirty)
                        {
                            File.WriteAllText(file.FullName, newFile.ToString());
                        }
                    }
                }
            }
        }
    }
}
</code>
Comment: Maybe someone could use your code one day. For now I used Search and Replace. Also powerfull trick ;-). Thanks for sharing


Create dataframe with timestamp field

Question: On Databricks, the following code snippet
%python

from pyspark.sql.types import StructType, StructField, TimestampType
from pyspark.sql import functions as F

data = [F.current_timestamp()]
schema = StructType([StructField("current_timestamp", TimestampType(), True)])
df = spark.createDataFrame(data, schema)
display(df)

displays a table with value "null". I would expect to see the current timestamp there. Why is this not the case?
Answer: createDataFrame does not accept PySpark expressions.

You could pass python's datetime.datetime.now():
import datetime

df = spark.createDataFrame([(datetime.datetime.now(),)], ['ts'])

Defining schema beforehand:
from pyspark.sql.types import *
import datetime

data = [(datetime.datetime.now(),)]
schema = StructType([StructField("current_timestamp", TimestampType(), True)])
df = spark.createDataFrame(data, schema)

OR add timestamp column afterwards:
from pyspark.sql import functions as F

df = spark.range(3)

df1 = df.select(
    F.current_timestamp().alias('ts')
)

df2 = df.withColumn('ts', F.current_timestamp())

Create dataframe with timestamp field


Exchange Email Server on Multiple DSL Connections (SonicWall TZ-210)

Question: I work for a company that is located in an area where the fastest Internet connection available is 3M/512K DSL. Due to growth of Internet use we now have configured (4) DSL connections in our SonicWall TZ-210 router using "Ratio" load balancing.
In order to make this setup work I had to configure a route so that all outbound email goes out on port X1, our original DSL connection. Without this routing we frequently get return failures. Our X1 DSL connection is the one that has SPF and PTR records configured. It's also the IP address to which our MX record is forwarded.
Looking at the reports in the SonicWall I can see that this X1 connection is by far the busiest, not to mention that our server (SBS 2008, our only server) is sending and receiving some 90% of all Internet traffic. Is there some way that I can allow our server to send out emails on any of our DSL connections/IP Addresses? Do I just need to setup PTR records (reverse DNS) for each of our DSL connections/IP Addresses?
Answer: You can look into moving sending/receiving capabilities to some relay system, e.g Linux, appliance-type server. You probably should configure one DSL internet connection for WEB traffic and the others for SMTP, you should inspect the traffic generated to/from your system and decide appropriately. In the DNS zone just create 3 A/PTR records, say mail1.domain.com, mail2.domain.com, mail3.domain.com and utilize all 3 others DSL connections.
Comment: 1) Your suggestion to configure 1 DSL for Internet and 3 for Email is spot on, except that it appears you missed the critical point of the post: How do you configure the DSL connections to so that we don't get return failures when using them to send out email? The A records your suggesting won't help.
Comment: A and PTR records, Can you please explain why?
Comment: PTR is reverse DNS. Many email systems will reject an email that comes from an IP address that has a Reverse DNS name that does not match the email domain for the sent email. Does that make sense? A records deal more with receiving email into our email system which is, well, somewhat relevant. I'm more concerned about sending email I guess, which I did not say in the original post.
Comment: If the email domain is domain.com as indicated in my post, why would mail1.domain.com, mail2.domain.com, mail3.domain.com will be treated differently? ISP will be required to add those PTR records to it's DNS zone. And the client will be required to add the external IPs of the DSL lines to it's own DNS zone as A records.
Comment: How do the receiving email systems use the PTR record? Do they strip off the subdomain and simply verify that mydomain.com in the PTR record matches the sender's stated email domain in the senders email address?
Comment: They validate that the connection initiated by the server through the IP that has an A record of mail1.domain.com actually has a PTR record in the reverse lookup zone.
Comment: For outgoing email, is the A record necessary?
Comment: Well, it might seem as not required, however I would do such a testing only with test domains. I would assume that various anti-spam solutions do such a check.
Answer: It sounds more like your load balancer isn't working right if 90% of all bandwidth is on one connection.
That said, sure, you can create RDNS entries for all of your IP addresses and that will work fine. In DNS, a single IP address can have many hostnames, and a single hostname can have many IP addresses. You can also specify more than one IP address in your SPF record. We do that, in no small part because we're an ISP with several mail servers for outgoing mail.
Comment: The 90% on one connection is because, apparently, 90% of all our traffic is email. Remember, I'm forcing all email to go through X1 which is the one showing the high usage.
Comment: Well even so, you should be able to do exactly what you propose: add each IP address to your SPF and RDNS records for mail.yourdomain.com. Or you can just as easily move your mail server to a colocation space on a 100 Mbps internet connection. I can think of a dozen other reasons to do so as well.
Comment: "I can think of a dozen other reasons to do so as well." - If I understand you correctly you're saying it would be advisable for a large variety of reasons to run the email server elsewhere? How would this help since the outlook clients still have to push/pull the same emails from the server?
Comment: Easy. You can load balance the traffic over your 4 ADSL connections. Unless I'm missing something and Exchange does SPF and reverse dns lookups on Outlook clients? I thought the point was to provide one point of contact between Exchange and other SMTP servers on the internet to prevent bouncebacks from those other SMTP servers. Other benefits usually include a better operating environment, backup power, and redundant internet connections. You can also look into hosted Exchange solutions.


How to ignore dependencies with msbuild

Question: I have a Visual Studio solution (ab.sln) which references two (VC) project files a.proj and b.proj. The projects depend on each other (A is a postProject ProjectDependency of B). This dependency is needed when compiling under Visual Studio.
Now I want to compile only project B from the command line and I thought msbuild would be a good choice. But I want to compile the two projects separately in different folders (for CI). After compiling A, I want to copy the required files over to the working directory for the B compile.
How can I compile one project in the solution from the command line without building the dependencies (and without having an extra file)? My current command that builds the dependency is:
<code>msbuild /t:b ab.sln
</code>
I could of course use a separate solution file b.sln that just contains project B, but I was trying to do without the extra file.
The answer given by jlew in How to get MSBuild to ignore project references? does not work for me, probably because I do not use ProjectReferences.
Answer: If both projects used the same $(OutDir) and project B made a binary reference rather than a project reference to A in the shared $(OutDir), then it should work.
Comment: I can't find how to create binary references (are those possible for C++ as opposed to C# projects?). But I replaced my ProjectDependencies-references in the solution file with ProjectReference-references in the project files and tried the solution by jlew again. Still does not work: the referenced projects are all being build.
Answer: https://stackoverflow.com/a/8127377/1578962

MSBuild myproj.csproj /p:Configuration=Debug /p:BuildProjectReferences=false /t:Build

How to ignore dependencies with msbuild


Totally disconnected is a topological invariant, but not a continuous invariant

Question: I am self-learning topology and would like help with the following exercise.
Prove: The property of being totally disconnected is a topological invariant but not a continuous invariant.
I can prove that being totally disconnected is a topological invariant because any homeomorphism induces a one-to-one correspondence between components. Thus let $f: X \to Y$ be a homeomorphism and let $X$ be totally disconnected. Each component of $X$ maps to a distinct component of $Y$. Since the components of $X$ are singletons, so are the components of $Y$. Hence $Y$ is totally disconnected.
To complete the proof, I believe that I must furnish an example of a continuous surjection $f : X \to Y$ that does not preserve the property of being totally disconnected. Moreover, $f$ should not be a homeomorphism. Thus either $f$ is not bijective or $f^{-1}$ is not continuous.
Can anyone provide me with an appropriate example or a hint please?
Comment: Hint. A good one is the "binary" map from $\{0,1\}^\mathbb N$ to $[0,1]$
Comment: Hint: any space is the continuous image of a discrete space.
Comment: @GEdgar thank your for the hint! What is the "binary map"? When I search Google for binary map of sequences to the unit interval I found material on the dyadic transformation (bit shift map), but it was not totally clear how I could use it. If it is easy to expand on what you mean, I would appreciate it.
Comment: @HennoBrandsma thanks! I believe that I used your hint to produce an example that is sufficient for completing the exercise.
Comment: Binary map:  sequence of 0s and 1s maps to the real number whose binary expansion (right of the point) is those 0s and 1s .  In this example, both spaces are compact separable metric.
Answer: Let $(\mathbb{R}, \mathcal{T})$ be the real line with the discrete topology and let $(\mathbb{R}, \mathcal{T}')$ be the real line with the usual topology. Let $f$ be any surjective function from $\mathbb{R}$ to $\mathbb{R}$.
Since any discrete topological space is totally disconnected, so is $(\mathbb{R}, \mathcal{T})$. However the real line with the usual topology is not totally disconnected. Moreover since any function on a discrete topological space is continuous, $f$ is an example of a continuous surjection from a space that is totally disconnected to a space that is not totally disconnected, which shows that the property of being totally disconnected is not a continuous invariant.
Comment: Indeed. An example should (IMO) always be as concrete as possible..
Comment: Simplify: just use $f(x)=x$ which clearly fits the bill.
Comment: @HennoBrandsma yes I had chosen $f(x) = x$, however I then realized that any surjective function $f$ would work. In general, I have a preference for being concrete when it comes to examples, so I guess there really was no reason not to go with $f(x) = x$.


Change Hamburger/backarrow toolbar color Android

Question: I want to change the color of my hamburger/backarrow in the toolbar from colorPrimaryDark to white.
In my style.xml file I have 2 themes:

and this is my toolbar:
<android.support.v7.widget.Toolbar
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/toolbar"
  android:fitsSystemWindows="true"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@color/colorPrimary"
  android:elevation="4dp"
  android:theme="@style/toolbar">
</android.support.v7.widget.Toolbar>

I tried with several methods and the only one that works is move <item name="android:textColorSecondary">@android:color/white</item> from toolbar theme to base application theme.
That's not ok for me because setting textColorSecondary to white in base theme change other components color too.
I want to set it only for my toolbar. But it does not work even though I have<item name="android:textColorSecondary">@android:color/white</item> and set my toolbar style into the toolbar.xml using "android:theme="@style/toolbar"

the strange thing is that the other theme colors are applied properly.
where am I wrong?
Comment: Have you tried [this](http://stackoverflow.com/questions/31870132/how-to-change-color-of-hamburger-icon-in-material-design-navigation-drawer)?
Comment: yes, but it change only the color of the hamburger icon not both, why?
Answer: Work around:
(but i think it isn't an elegant solution)
i set the default arrow icon with this:
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);

and change hamburger color with this:


How to pass randomly-generated data to include_tikz in R/exams?

Question: When I add static data to a chart created with TikZ and include_tikz() from R/exams, they are rendered correctly. For example I have created the following graphic

using exams::include_tikz(graf01, library = "arrows") with the TikZ code below. And then I can include it in exams2html(), exams2moodle(), etc.
 graf01<-c("\\definecolor{uuuuuu}{rgb}{0.26,0.26,0.26}",
      "\\definecolor{zzttqq}{rgb}{0.6,0.2,0}",
      "\\definecolor{ududff}{rgb}{0.30,0.30,1}",
      "\\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]",
      "\\clip(-0.1,-0.1) rectangle (5,5);",
      "\\fill[line width=2pt,color=zzttqq,fill=zzttqq,fill opacity=0.10] (0,0) -- (4.68,-0.02) -- (4.7,4.66) -- (0.02,4.68) -- cycle;",
      "\\draw (3.44,3.80) node[anchor=north west] {\\textbf{12}};",
      "\\draw (0.35,4.57) node[anchor=north west] {\\textbf{DH}};",
      "\\draw (3.97,4.57) node[anchor=north west] {\\textbf{CA}};",
      "\\draw (2.31,0.72) node[anchor=north west] {\\textbf{R}};",
      "\\draw [line width=2pt] (1.76,3.08) circle (1.3cm);",
      "\\draw [line width=2pt] (3.05,3.13) circle (1.3cm);",
      "\\draw [line width=2pt] (2.45,1.98) circle (1.3cm);",
      "\\draw [line width=2pt,color=zzttqq] (0,0)-- (4.68,-0.02);",
      "\\draw [line width=2pt,color=zzttqq] (4.68,-0.02)-- (4.7,4.66);",
      "\\draw [line width=2pt,color=zzttqq] (4.7,4.66)-- (0.02,4.68);",
      "\\draw [line width=2pt,color=zzttqq] (0.02,4.68)-- (0,0);",
      "\\begin{scriptsize}",
      "\\draw [fill=ududff] (0,0) circle (2.5pt);",
      "\\draw [fill=ududff] (4.68,-0.02) circle (2.5pt);",
      "\\draw [fill=uuuuuu] (4.7,4.66) circle (2.5pt);",
      "\\draw [fill=uuuuuu] (0.02,4.68) circle (2.5pt);",
      "\\end{scriptsize}",
      "\\end{tikzpicture}")

Now instead of hard-coding the number 12 in graf01[7]
"\\draw (3.44,3.80) node[anchor=north west] {\\textbf{12}};"

I want to use a randomly-generated number, say:
 vald <- sample(1:20, 1)

I tried using
"\\draw (3.44,3.80) node[anchor=north west] {\\textbf{vald}};"

but then the string vald instead of its value is included:

How can I include the value of vald instead?
Comment: I assume that you are the same user as https://stackoverflow.com/users/15344973/%c3%81lvaro-%c3%81ngel-molina Why are you posting under different names/pseudonyms? It makes it more difficult to understand connections between questions... Also, do you happen to be the same user as https://stackoverflow.com/users/15677793/alvaretto-ancelotti ? If so, please follow up on the only question you asked under that pseudonym.
Comment: Forgiveness. It's true. One of those pseudonyms I used once. I made many mistakes due to ignorance of the rules and decided to abandon it. The other pseudonym I used today because I had trouble asking the question. It will not happen again. Thanks.
Comment: If you still have the Ancelotti account please accept the answer to the num_to_schoice question so that it is flagged correspondingly on StackOverflow. Thanks.
Comment: The email I used for that pseudonym, no longer exists ...
Answer: To include the value of a variable in a string you can use the function paste() or paste0():
vald <- 7
line7 <- paste0("\\draw (3.44,3.80) node[anchor=north west] {\\textbf{", vald, "}};")
line7
## [1] "\\draw (3.44,3.80) node[anchor=north west] {\\textbf{7}};"

Or for equivalent output sprintf():
line7 <- sprintf("\\draw (3.44,3.80) node[anchor=north west] {\\textbf{%s}};", vald)

The latter is typically more convenient if you have several placeholders like %s in a string or when you have different types of placeholds etc.
In either case you can subsequently do:
graf01[7] <- line7
include_tikz(graf01, library = "arrows")

Comment: It's surely easiser to do on the R side because you need the solution etc. in R as well. As for the proposed strategy. Say you have a general LaTeX template with `%s` placeholders such as `venn <- '\\textbf{%s} and \\textbf{%s}'`. And then you sample different frequencies like `freq1 <- sample(1:20, 2)` and `freq2 <- sample(1:20, 2)`. Then these can be combined as `graf1 <- sprintf(venn, freq1[1], freq1[2])` and `graf2 <- sprintf(venn, freq2[1], freq2[2])`. Of course, in your case the LaTeX code and the random sampling will be more complex but the basic strategy will remain the same.
Comment: It worked perfectly. We keep moving forward. Thank you very much for your guidance.
Comment: For combining this with https://stackoverflow.com/questions/67630203/how-to-include-tikz-images-in-r-exams-exercises I would recommend the following: Set up one long character string `venn` with the **template** for the Venn diagram including `%s` placeholders in all positions that contain frequencies. Then generate the different frequency vectors and do `graf1 <- sprintf(venn, freq1[1], freq1[2], ...)` and `graf2 <- sprintf(venn, freq2[1], freq2[2], ...)` and so on. And then you can use `include_tikz(...)` for all of the different graphics and include them in the answerlist. Good luck!
Comment: Thanks Achim for the good wishes. I do not fully understand this strategy that you have just proposed to me. One last question: Is there no way to randomize variables outside the chunks of `R`, that is, with the `TikZ` code, in the `Latex` environment? A million thanks.
Comment: When I need `exams2pdf` I find it easier on the `Latex` side (not so much on the `R` side), because it is only "copy and paste" the code directly from `TikZ`, even requiring a random solution. Is it possible to generate the image (`TikZ`) for `exams2moodle` in this way? Thanks.
Comment: No, unfortunately not. For inclusion in HTML you need to create a separate graphics file in one of the formats that can be directly embedded, e.g., PNG, JPG, or SVG. So you need a separate program to create/convert that figure. In exams2pdf this is not necessary because everything is compiled into a single PDF file controlled by LaTeX.
Comment: I can't replicate your "long character string" strategy for `Venn`. I got lost. I do not know what I'm doing wrong.
Comment: Can I elaborate a new question? I cannot convert other `TikZ` codes downloaded from the internet to a character string.
Comment: Strategy 1: Copy the `{tikzpicture}` in your code editor and put it in single quotes `tikz <- '...'`. Then use find-&-replace for all `\ ` by `\\ `. Then use find-&-replace for all `'` by `\'` (without the closing `'` from the string). If the TikZ code contains many single quotes, you can apply the same strategy with double quotes. ~ Strategy 2: Use `tikz <- readLines("file.tex")` and then copy the output of `dput(tikz)` into the exercise. Typically, Strategy 1 should yield more readable code then Strategy 2, I would say. And as usual: Try to start simple and then get more complex gradually.
Comment: Thanks!!! Thanks!!! Thanks!!! Thanks!!! Thanks!!! Thanks!!! Thanks!!! And finally, Thank you !!!


Como chamar uma função logo após um efeito de slide?

Question: Preciso pegar a altura de uma div e remidensionar um ifram de acordo com a altura atual, até ai tudo bem.
Só que eu estou pegando a altura logo após um clique que dá um slideToggle nessa div. E me parece que como ainda o efeito de slide não terminou eu não consigo obter a altura correta.
Então como consigo chamar essa função somente após o slide estiver completo?
$(document).on("click", "#toggleDiv" function(){
    $("#questao").slideToggle(300);
    // chamar função para pegar altura somente após o fim do slide. como?
});

Answer: O .slideToggle() aceita uma callback, ou seja uma funcão que deve correr quando a animação terminar.
Podes usar assim:
$(document).on("click", "#toggleDiv" function(){
    $("#questao").slideToggle(300, function(){
        // aqui o slide já acabou
    });

});

Dentro dessa função podes usar o this para acessar  elemento animado. Se quiseres a altura podes usar $(this).height();


Understanding sound in a lamellophone (kalimba, karimba, or mbira)

Question: I am familiar with the construction of a lamellophone and of a metallophone. I played anklung gamelan for several years and of course I've played around with a thumb piano.
As I understand it with a metallophone, the bars are tuned and mounted at the 1/4 and 3/4 nodes of the tuned bars.
With a lamellophone (such as a kalimba, karimba, or mbira) the tines are tuned by the length that emerges out from under the straining bar.
With the lamellophone, is the straining bar positioned at a node? Is the length of the tine that is above the straining bar important in producing the sound? How does the percussive wave interact with the tine and the straining bar?
Bonus question: Are there concussion lamellophones that are struck with a mallet? If so, what are they called?
Answer: Well, by definition,  a clamped (or even unclamped - see the "nut" at the top of a guitar or violin fingerboard) point is a node, as no vibration can take place there.  So the length of the tine is the primary physical feature which sets the tone.  That is, assuming all tines are made of the same material, same thickness, etc.,  the fundamental vibration is a wavelength that depends only on the length of the tine. (the elasticity values are same for all tines, that is).
Because you pluck the tine at its end, the fundamental frequency should dominate.  If instead you were to hammer at, say,the 1/4 point from the clamp point, you'd excite higher overtones because you've exacerbated the energy at a higher-overtone maximum location.   <-- I'm not saying that any instrument in this class is ever played with a mallet/hammer, just commenting on what could happen.  It's vaguely similar to the difference in frequencies generated when hitting a cymbal at the edge or near the center.