Certificate Authentication

Question: I am currently working on deploying a website for staff to use remotely and would like to make sure it is secure.
I was thinking would it be possible to set up some kind of certificate authentication where I would generate a certificate and install it on their laptop so they could access the website?
I don't really want them to generate the certificates themselves though as that could easily go wrong.
How easy / possible is this and how do I go about doing it?
Answer: What you are looking to do is called two way ssl authentication
How to implement it is going to vary based on your web server.
Apache Guide
Answer: This Article deals with creating certificates for Microsoft Exchange, but the process is similar for any IIS Website. Hope that helps!
Answer: Check out CAcert, "A community driven certificate authority that issues certificates to the public at large for free."
Answer: tinyca2 is a nice graphical front-end to generate certificates. It is packaged for both Debian and Ubuntu Linux distributions.  You will be able to generate the keys and certificates for the server and clients.  They can be exported in a number of formats.  I would recommend documentating proceedures for installing your ca-certificate as well as the client key and certificate.  Setting or changing the password on the client key by your users should also be covered.
I second using mod-rewrite to force access to https://.
Comment: URL: http://tinyca.sm-zone.net/
Comment: @Nathan: Thanks for the link.  It is packaged software for Debian based distributions including Ubuntu.  I've never had to go to the original site.  Although classified beta, I find it is more stable than some released software.
Answer: Wow, if you're using apache you can use mod_rewrite to force the use of SSL and in your httpd.conf you also need to use the 'SSLVerifyClient require' and 'SSLVerifyDepth 4' directives in your *:443 virtual host.
For the rewrite rule you can use something like this:
<code>RewriteCond %{HTTPS} !^on$ [NC]
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L]
</code>
Hope this helps.
Comment: I'm afraid I'm using IIS / Windows.

I'm looking for more of an overview really about the actual process of creating a certificate for a website and issuing it to users.
Answer: Security is a larger question than the authentication or authorization mechanisms in use.
Most security people leverage a few basic principles generally:

least privilege
deny by default
Fail open or Fail closed
minimization
privilege separation
role separation
defense in depth (to name a few)

Then apply that to assets, in your case, a webserver, an operating system, and potentially a web application and underlying database - really the business though!
For the above technology infrastructure, I would ask if you have applied proper security hardening to each, e.g. DISA STIGs, NSA SRGs, CIS guidance, or vendor security practices.  Afterwards, I'd look into the code of the web applications, and other things.
Getting to your specific question about certificates - what is a digital certificate?  It is a public key, embedded into a digital certificate, with some fields in it, typically x509v3.  A digital certificate is effectively an encryptor, that uses a decryptor (private key) in order to authenticate, sign, or perform some other type of transaction.
Certificates have no confidentiality generally, private keys have confidentiality and require protection.  However, using private keys on an operating system may mean they are exposed and compromised.  One piece of malware can be all it takes to get in.  Consequently, higher security environments such as companies and governments commonly use a hardware device to store private keys and enable a more secure authentication process.
If you are not doing this for a more secure environment, software certificates may be good enough for you.
Depending on the operating system you are using, you may have a very simple path ahead using certificate based auto-enrollment schemes like SCEP or microsoft's certificate services.
Microsoft's implementation is easy to follow at http://msdn.microsoft.com/en-us/library/bb643324.aspx and you can find other competing solutions for easier auto-enrollment PKIs.
You can share a few of your needs with above links with your network administrators and ask them to start testing it out.

Certificate Authentication


How to prevent load balancer from failing?

Question: sorry if the question is a bit ambiguous but it is the first time for me to set up a load balancer and I am a little worried.
I want to create a Glassfish Cluster, at the moment I am following this link: http://javadude.wordpress.com/2011/04/25/glassfish-3-1-clustering-tutorial/
In the above tutorial one of the nodes runs also as a load balancer (DAS - Domain Administration Server). In my scenario of course I intend to build 3 nodes, one acting as a load balancer for the other two.
Everything is pretty clear but can anyone give me an idea what to do if the node that acts as a load balancer fails?
Any information will be highly appreciated.
Answer: I can't speak specifically about glassfish, but it's normal to built failure-resilient LB systems with a pair of LBs, only one of which is active at any one time.
If the LBs are applicances, this is done in hardware - you'll have a pair, usually with some direct connection between the two, for monitoring/heartbeat and sometimes for state exchange.  If the LB is software-based and runs on one of the balanced nodes, it's fairly normal to run the second LB on another pool node.
Ensuring that one and only one LB runs at any given time is important, and can't easily be covered here.  Particularly for software-based solutions, a good STONITH implementation and appropriate hardware can really help with that.
Edit re your comment: I take your point, but no.  Generally the way this is done is to have an infrastructure which is aware that one and only one instance of something - in this case an LB - should be running, and using a floating IP address to handle failover between the two of them.  In software, under Linux, this is often done with something like LinuxHA and CRM, running on both primary and secondary LB nodes, which handles the business of ensuring that only one node runs the LB process, and making very sure that primary is dead if it decides to promote the secondary.
Comment: Typically the secondary node monitors the primary and will Shoot The Other Node In The Head (STONITH) before taking over the role of the primary when it detects malfunction. The STONITH implementation is to force the release of all resources held by the primary node, typically by forcing a hard reset. A third "supervisor" is typically not needed.
Comment: Thank you, if I have two LBs, for monitoring them, I will have to implement another LB...? I am a little confused, sorry.


Contradiction for Roots of a Complex Polynomial?

Question: In y complex analysis course we learned a theorem about the roots of a complex, nonconstant, holomorphic polynomial.
That if $p(z)$ is nonconstant and holomorphic then $p$ has a root, i.e. for some $\alpha \in \mathbb{C}$ we have that $p(\alpha) = 0$.
But wouldn't $p(z) = z^2 + 1$, not have a root but is also holomorphic and nonconstant?
Comment: Are you sure that $p(z)$ don't have a root, now that you know complex number.
Comment: $z=i$ is a root
Answer: $$p(z) = z^2 + 1$$ has two roots as promised by the theorem.
Both $ z=i$ and $z=-i$ satisfy $z^2+1=0$ so they are roots of $p(z) = z^2 + 1$
Probably you were expecting real roots.
Well, the theorem did not prove that the roots are necessarily real.


Using variation of parameters method to solve ODE $y'' + 4y' + 3y = 65\cos(2x)$

Question: I have the following ODE:
$$y'' + 4y' + 3y = 65\cos(2x)$$
I first used the method of undetermined coefficients to find the solution to this equation, which was relatively easy, and found that the solution was.
$$C_1e^{-3x}+C_2e^x+8\sin(2x)-\cos(2x)$$ where to the my $y_h =C_1e^{-3x}+C_2e^x$, I used this $y_h$ in the start of my problem of doing variation of parameters for the same ODE, using the Wronskian and the general formula for computing the particular solution, but ended up getting my $y_p = 0$, which can't be right since thats not what I got in my undetermined coefficients method. I have a feeling I'm going about this the wrong way. What is the correct way to compute this ODE using variation of parameters?
Comment: Yes, this seems like a straightforward application of the formulas. Begin with the trial form
$
y_p(t) = c_1(x)y_1(x) + c_2(x) y_2(x)
$
where $y_1(x)=e^{-3x}$ and $y_2(x)=e^x$. Then the formulas are:
$$
c_1(x) = -\int\frac{y_2(x)g(x)}{y_1(x)y_2'(x)-y_1'(x)y_2(x)}
$$
$$
c_1(x) = \int\frac{y_1(x)g(x)}{y_1(x)y_2'(x)-y_1'(x)y_2(x)}
$$
where $g(x)=65\cos(2x)$. You basically plug in for $y_1$, $y_2$, and $g$, then plug into the first formula, and should get the answer. Where is this going wrong?
Comment: I tried, whenever I ask a question and add tags, it doesn't let me do a lot of the tags related to the subject since my reputation points are not 1k yet.
Comment: $y_h$ should be in $x$, not $t$
Comment: Please show us what you've done (edit the post) so we can diagnose the problem
Answer: First of all, let me point out that you've made a mistake with your complementary solution $y_h$. It should be:
$$y_h(x)=c_1 e^{-3x}+c_2 e^{\color{red}{-x}}$$
I will show this in the first part of my answer.

Let's start by finding the complementary solution.
$$\frac{d^2 y}{dx^2}+4\frac{dy}{dx}+3y=0$$
We make the ansatz $y=e^{\lambda x}$ to obtain the characteristic equation:
$$\lambda^2+4\lambda+3=0$$
$$(\lambda+1)(\lambda+3)=0$$
$$\lambda=-1,-3$$
This implies that the complementary solution is:
$$y_h(x)=c_1 e^{-3x}+c_2 e^{-x}$$

The basis solutions are $e^{-3x}$ and $e^{-x}$. Thus, the Wronskian is:
$$W(x)=\begin{vmatrix} e^{-3x} & e^{-x} \\ -3e^{-3x} & -e^{-x} \end{vmatrix}=2e^{-4x}$$
Let $f(x)=65\cos(2x)$. The particular solution will thus be given by:
$$y_p(x)=v_1(x) e^{-3x}+v_2(x) e^{-x}$$
Where:
$$v_1(x)=-\int \frac{f(x)\cdot e^{-x}}{W(x)}~dx=-\int \frac{65\cos(2x)\cdot e^{-x}}{2e^{-4x}}~dx=-\frac{65}{2}\cdot \int e^{3x}\cos(2x)~dx$$
And:
$$v_2(x)=\int \frac{f(x)\cdot e^{-3x}}{W(x)}~dx=\int \frac{65\cos(2x)\cdot e^{-3x}}{2e^{-4x}}~dx=\frac{65}{2}\cdot \int e^x\cos(2x)~dx$$
Can you continue?


Power method for complex Hermitian matrices

Question: How should the power iteration be modified to handle complex yet Hermitian matrices? Because the matrix is Hermitian, the eigenvalues are real. I realize that the power method will fail if the eigenvalues are non-real, but I would think that it should work in my case.
It seems to me that the naive algorithm should be unchanged. There is a possible complication when doing the scaled power iteration, where one computes the norm of the current iterate.
There is also a potential issue with deflation for computing multiple eigenpairs. Does the simple Hotelling deflation method not work for complex Hermitians?
Answer: There are two simple changes that need to be made.
First, in the power iteration itself, the full complex version of the Rayleigh quotient $R(M, x) = x^H M x / (x^H x)$ must be used, instead of its simplified real version $x^T M x / (x^T x)$. Thus, the algorithm would be:
$$
\begin{align}
\textrm{while not converged}: & \\
w \leftarrow& A v \\
v \leftarrow& w / \|w\|_2 \\
\lambda \leftarrow& v^H A v
\end{align}
$$
(See this PR to TheAlgorithms  to see Python code for this change.)
In addition, deflation for computing multiple eigenvalues/eigenvectors must also account for the fact that the eigenvector may be complex. For example, Hotelling deflation would now be
$$
A \leftarrow A - \lambda v v^H / (v^H v).
$$


Express each power of the root $\alpha$ of $\frac{\mathbb Z_2[x]}{\langle x^3+x^2+1\rangle}$ as linear combinations of $1, \alpha$ and $\alpha^2$

Question: There are $8$ elements in $\frac{\mathbb Z_2[x]}{\langle x^3+x^2+1\rangle} = GF(8)$
and this generates the set $\{0,1,x,x+1,x^2,x^2+1,x^2+x,x^2+x+1\}$
We're required to express $\alpha^1$ all the way up to $\alpha^7$ as linear combinations of $1, \alpha$ and $\alpha^2$
$\alpha^1 = \alpha$
$\alpha^2 = \alpha^2$
$\alpha^3 = \alpha^2 + 1$
$\alpha^4 = \alpha^2+\alpha+1$
$\alpha^5 = \alpha+1$
$\alpha^6 = \alpha^2+\alpha$
$\alpha^7 = 1$
I'm really not seeing where these combinations are coming from. Why is $\alpha^3 = \alpha^2+1$?
Answer: If $\alpha$ is a root of $x^3+x^2+1$, then $\alpha^3+\alpha^2+1=0$, so $\alpha^3=\alpha^2+1$ (since $1=-1$ over $\mathbb{Z}_2$).
From here:
$$\begin{array}{l} \alpha^4=\alpha\alpha^3=\alpha(\alpha^2+1)=\alpha^3+\alpha=\alpha^2+\alpha+1\\
\alpha^5=\alpha\alpha^4=\alpha^3+\alpha^2+\alpha=\alpha^2+1+\alpha^2+\alpha=\alpha+1\\
\alpha^6=\alpha\alpha^5=\alpha^2+\alpha\\
\alpha^7=\alpha\alpha^6=\alpha^3+\alpha^2=\alpha^2+1+\alpha^2=1 \end{array}$$
(using $1+1=0$ over $\mathbb{Z}_2$)
Comment: ahh ok, it's actually just basic algebra now that I look at it that way. Thanks
Answer: Perhaps simplest: use the recursion $\rm\ \alpha^{n+3}\! = \alpha^{n+2} + \alpha^n\ $ arising from $\,\alpha^n\,$ times $\:\alpha^3 = \alpha^2 + 1$.
Alternatively, more generally, one easily calculates the effect of multiplying by $\rm\,\alpha\,$ as follows
$$\begin{eqnarray}\rm   \alpha^n &=\,&\rm a\,\ +\,\ b\, \alpha\  +\, c\, \alpha^2\\
\rm \Rightarrow\ \ \alpha^{n+1} &=\,&\rm  a\, \alpha + b\, \alpha^2  + c (\alpha^2\! +\! 1)\ \ \ by\ \ \ \alpha^3 = \alpha^2+1 \\
 &=\,&\rm  c + a\, \alpha + (b\!+\!c)\,\alpha^2 \end{eqnarray}$$
So $\rm\:(a,b,c)\to (c,a,b\!+\!c),\:$ i.e. rotate right $\rm\:(a,b,c)\to (c,a,b)\:$ then add the first into the last.
The same ideas generalize to arbitrary degree.


Why is the hazard rate (from an Aalen model) subject to the number of levels of a factor / parameter?

Question: As a follow up on How to understand Aalen additive regression model? I've conducted this method on my own data (which is, unfortunately, confidential). Hence, I cannot reveal what these data represent but I believe it doesn't matter, anyway.

You can see here the hazard rate(?) separated by country. I realized that the one country in the center in the lowest row (UK) has a quite high hazard rate. So I removed this country from the data just to check what happens. I figured out, that another country provided even larger rates then. So I removed this, too. And then two other countries had even higher values, than ever before.
What is going on? This doesn't seem robust to me?
I realized that
edit: Before I forget: For United Kingdom, there is only one subject. Other very "fragile" countries are Macedonia (with two subjects) or Czech Republic (with four subjects). In total, there are about 305 subjects.
The syntax of the fit is:
<code>fit<- survfit(Surv(time, event) ~ country,
               data = df[df$country != "?" & df$country != "", ])
</code>
Comment: The display for a particular level of a categorical predictor is the estimated _difference in hazard from that of its reference level_, evaluated at each event time. The intercept is the hazard when all predictors are at reference levels. What you describe could happen with any type of multiple-regression model when you change the data set. The image is impossible to read and you don't show the differences between models that you describe in words, so it's hard to say much else. Please edit the question so we can see better what's going on, perhaps with a simpler model/data subset.
Comment: I replaced the image with bigger ones. The data is confidential, sorry.
Answer: Aalen models are known to be unstable at the latest times, as there are few individuals left at risk for the regressions at each of the later event times. With a single UK individual whose event (if it happens at all) is at a very late time, this behavior isn't that surprising.
You also are probably overfitting your data. You evidently have 40 individual levels of a single categorical predictor (the reference level is what's shown in the Intercept). The usual rule of thumb in survival analysis is to have 10-20 events per coefficient that you are estimating. You should thus have 400-800 events for this model. If not all individuals experienced events, you presumably have fewer than 300 events. Such overfitting also can lead to the behavior that you describe, with high variability in predictions resulting from small changes in data. My sense is that this is even more of a problem in Aalen models with their repeated regressions at each event time, although I have almost no practical experience with them.
Comment: @Ben much depends on just what you're trying to accomplish. If these examples resemble your actual data, you need to reduce the number of predictors, e.g. by grouping based on subject-matter knowledge, or use a penalized method like ridge regression. I would avoid Aalen additive models. Look at Frank Harrell's [course notes](https://hbiostat.org/doc/rms.pdf) and [book](https://hbiostat.org/rms/) for guidance on how to deal with too many predictors and on survival modeling. I don't think that he covers Aalen additive models at all. Use other approaches (Cox models, fully parametric models).
Comment: thanks a lot for all your support! May I simply ask how you would proceed in my case? It seems like you know enough of the field itself to pick a reasonable track.


How does Michaud Resampling improve Mean-Variance Optimization?

Question: Michaud Resampling claims to reduce estimation error through the following process:
Step 1. Sample a mean vector and covariance matrix of returns from distribution of both
centered at the original (point estimate) values normally used in MV
optimization.
Step 2. Calculate an MV efficient frontier based on these sampled risk and return estimates.
Step 3. Repeat steps 1 and 2 (until enough observations are available for convergence in
step 4).
Step 4. Average the portfolio weights from step 2 to form the RE optimal portfolio.
Taken directly from the following paper - Michaud, R. O., & Michaud, R. (2007). Estimation error and portfolio optimization: A Resampling Solution. SSRN Electronic Journal.
I understand the process but have trouble understanding why this would lead to a different result than simply using the point estimates for mean and variance under regular Mean-Variance Optimization, let me elaborate as to why.
I would assume that the more observations that are taken using this method, the more accurate the result should be. I know that the convention is to take at least thousands of observations (steps 1 & 2) until proceeding to average all of these observations to form the optimal portfolio (step 4). What I cannot seem to understand is that if we are taking these observations from a probability distribution using our point estimates as the mean of those distributions, then wouldn't the average of all those observations simply be the point estimate itself?
As an example, traditional MVO would use a point estimate for Mean return. If we were to make a distribution around the Mean return using our point-estimate as the center and then take a large number of random observations from that distribution, wouldn't averaging them together simply yield the original point-estimate since it was the mean in the first place? The same logic would apply to the point-estimate of Variance.
I am sure that I am missing something here and my guess is that the answer lies somewhere in the mathematics of probability distributions and how the two separate distributions (for mean and variance) interact with each other. But my math skills aren't good enough to dig for the answer myself so I was hoping one of the fine members of this community could explain it to me.
Answer: You are not using the sampled values at each iteration to calculate the mean of the distribution, you are using them to calculate a sample of the optimal portfolio weights.  At the end of, say, $N$ iterations, you have $N$ samples of optimal portfolio weights, and you form your optimal portfolio by averaging them.  Each sample optimal portfolio weight vector is a nonlinear transformation of the sampled parameters, and as a consequence, the averaged sample optimal portfolio weights will (almost certainly) be different than the ones you would have calculated using the original estimated parameter values.


Unable to scrape data from https://www.gbgb.org.uk/meeting/?meetingId=355352&raceId=576255

Question: Hi for some reason I cannot seem to scrape any results data from https://www.gbgb.org.uk/ using BS, I can print the results page page I want using prettify but as soon as I ask for a "find_all" for example I get a 0 return, can anyone see if I'm doing anything wrong as the same code works fine on other sites, below is a quick example of what I mean, many thanks
import urllib.request
import urllib.parse
from requests import get
url = 'https://www.gbgb.org.uk/meeting/?meetingId=355490&raceId=577749'
response = get(url)
#print(response.text[:500])

headers = {}
headers['User-Agent'] ="Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17"
req = urllib.request.Request(url, headers = headers)

from bs4 import BeautifulSoup
html_soup = BeautifulSoup(response.text, 'html.parser')
type(html_soup)
#print(html_soup.prettify())

info_container = html_soup.find_all('div', class_ = 'MeetingRaceTrap')
print(type(info_container))
print(len(info_container))

Answer: If you go to NetWork Tab.You will get following API which returns result as json format.
https://api.gbgb.org.uk/api/results/meeting/355490?meeting=355490

You don't need BeautifulSoup here.
import requests
import json
headers = {'User-Agent':
       'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36'}
url = 'https://api.gbgb.org.uk/api/results/meeting/355490?meeting=355490'
response =requests.get(url,headers=headers)
data=json.loads(response.text)
print(data)

Now lets say you want get races
Just print
print(data[0]['races'])

Or you want to get prizes for races.
for price in data[0]['races']:
    print(price['racePrizes'])

Your output will be
1st £95 | Others £40 | Race Total £95
1st £95 | Others £40 | Race Total £295
1st £105 | Others £40 | Race Total £305
1st £100 | Others £40 | Race Total £300
1st £120 | Others £40 | Race Total £320
1st £110 | Others £40 | Race Total £310
1st £110 | Others £40 | Race Total £310
1st £115 | Others £40 | Race Total £315
1st £120 | Others £40 | Race Total £320
1st £105 | Others £40 | Race Total £305

To get all the dog name you need iterate the parent element.
import requests
import json
headers = {'User-Agent':
       'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36'}
url = 'https://api.gbgb.org.uk/api/results/meeting/355490?meeting=355490'
response =requests.get(url,headers=headers)
data=json.loads(response.text)
for d in data[0]['races']:
    for dog in d['traps']:
        print(dog['dogName'])

This will print all 60 names.
Talking Lulu
Demolition Dolly
Holycross Jo Jo
Fieldview Gramps
Fieldview Darcie
Blackrose Frog
Kilbreedy Gaga
Yorkstreet Milly
Blackrose Angus
Greencroft Snowy
Marcos Veggera
Ramors Flash
Dan The Tail
Killinan Fairy
Knockalton Bella
Howl At The Moon
Westmead Boss
Rockhill Romeo
Fieldview Gem
Only One Ding
Fieldview Jet
Leazes Samuel
Glassmoss Sally
Fieldview Franky
Talamh Dochais
Greencroft Spot
Greencroft Jed
Footfield Bee
Hather Pixie
Makeit My Dog
Makeit Mos Bro
Droopys Cristina
Puckane Panda
Hollywood Coco
Fieldview Dolly
Ballyphilip Bill
Bees Charm
Crossfield Hal
Savana Jody
Savana Hottie
Greencroft Briny
Savana Dan Dan
Savana Diamond
Savana Schnappes
Savana Pegasus
Millroad Captian
Savana Pimms
Ballyhoe Vouga
Fieldview Myles
Hollander
Savana Tequila
Ballygibba Chip
Rockburst Tess
All About Will
Clockwork Girl
Roma Lady
Fieldview Pancho
Harry Boy
Rahyvira Lady
Cobblers Girl

Comment: Great!!!Please accept the answer by clicking on hollow under down vote button.https://stackoverflow.com/help/someone-answers
Comment: thanks Kunduk, just one more thing, how do i print the dogName, as the process you explained kicks out an "KeyError: 'dogName'"
Comment: @Paul : Added the answer.


Using one or many training test - GLM Poisson

Question: I'm newbie to GLM. I'm modeling frequence of accident from driver age, vehicle age, vehicle power... using GLM Poisson
I create a training set and a test set. However, I notice for each time I run the model (so the training set changes), the coefficients change (and also the significance level). My question is that: should we change our training set several times or not? If yes, how to deal with the problem above.
I show there 2 examples (2 different training sets):
Call:
glm(formula = TPL ~ DrivAge + DrivGender + MaritalStatus + BonusMalus +
    LicenceNb + PayFreq + JobCode + VehAge + VehClass + VehPower +
    VehGas + VehUsage + Garage + Area + Region + Channel + Marketing,
    family = quasipoisson, data = train)

Deviance Residuals:
    Min       1Q   Median       3Q      Max
-0.7683  -0.4040  -0.3583  -0.3164   4.8324

Coefficients: (3 not defined because of singularities)
                                  Estimate Std. Error t value Pr(>|t|)
(Intercept)                      -3.433879   0.804993  -4.266 2.01e-05 ***
DrivAge                           0.008009   0.003139   2.552  0.01073 *
DrivGenderM                      -0.025324   0.073180  -0.346  0.72931
MaritalStatusDivorced             0.397871   0.269480   1.476  0.13985
MaritalStatusMarried             -0.017458   0.084927  -0.206  0.83713
MaritalStatusSingle               0.280122   0.099957   2.802  0.00508 **
MaritalStatusWidowed             -0.384041   0.235483  -1.631  0.10294
BonusMalus                        0.011595   0.002348   4.939 7.94e-07 ***
LicenceNb                        -0.011739   0.050265  -0.234  0.81535
PayFreqHalf-yearly                0.010197   0.078224   0.130  0.89629
PayFreqMonthly                    0.116260   0.162018   0.718  0.47303
PayFreqQuarterly                  0.025511   0.140871   0.181  0.85629
JobCodeFarmer                     0.282743   0.294779   0.959  0.33749
JobCodeOther                     -0.090008   0.233286  -0.386  0.69963
JobCodePrivate employee           0.050860   0.179362   0.284  0.77675
JobCodePublic employee            0.094397   0.183370   0.515  0.60671
JobCodeRetailer                 -12.532778 283.850222  -0.044  0.96478
JobCodeRetiree                    0.177935   0.217747   0.817  0.41385
VehAge                           -0.021195   0.007865  -2.695  0.00705 **
VehClassCheaper                  -0.033183   0.110429  -0.300  0.76381
VehClassCheapest                 -0.144738   0.148141  -0.977  0.32857
VehClassExpensive                 0.224670   0.375376   0.599  0.54950
VehClassMedium                    0.113419   0.197041   0.576  0.56489
VehClassMedium high              -0.029006   0.288382  -0.101  0.91988
VehClassMedium low                0.029851   0.135363   0.221  0.82546
VehClassMore expensive           -0.115352   0.544292  -0.212  0.83217
VehClassMost expensive            0.397490   0.632560   0.628  0.52976
VehPowerP11                       0.138692   0.129379   1.072  0.28375
VehPowerP12                       0.096941   0.139545   0.695  0.48726
VehPowerP13                       0.134677   0.166905   0.807  0.41974
VehPowerP14                       0.249407   0.199613   1.249  0.21152
VehPowerP15                      -0.030085   0.308138  -0.098  0.92222
VehPowerP16                       0.393038   0.398141   0.987  0.32357
VehPowerP17                       0.320942   0.809079   0.397  0.69161
VehPowerP2                      -11.743427 907.484450  -0.013  0.98968
VehPowerP4                      -12.058187 573.089763  -0.021  0.98321
VehPowerP5                       -0.995431   0.594664  -1.674  0.09417 .
VehPowerP7                        0.344036   0.268571   1.281  0.20022
VehPowerP8                        0.379639   0.142235   2.669  0.00761 **
VehPowerP9                        0.173538   0.133922   1.296  0.19506
VehGasRegular                    -0.127739   0.078080  -1.636  0.10186
VehUsageProfessional              0.299550   0.225092   1.331  0.18328
VehUsageProfessional run          0.576924   0.295204   1.954  0.05068 .
GarageClosed zbox                 0.213356   0.096891   2.202  0.02768 *
GarageOpened collective parking   0.047413   0.116148   0.408  0.68312
GarageStreet                      0.231024   0.122183   1.891  0.05867 .
AreaA12                          -0.161991   1.237855  -0.131  0.89588
AreaA2                           -0.500636   0.723129  -0.692  0.48875
AreaA3                           -0.546334   0.722099  -0.757  0.44931
AreaA4                           -0.223314   0.725155  -0.308  0.75812
AreaA5                           -0.352101   0.719116  -0.490  0.62440
AreaA6                           -0.568578   0.774222  -0.734  0.46273
AreaA7                           -0.414094   0.727111  -0.570  0.56902
AreaA8                           -0.375806   0.736787  -0.510  0.61002
AreaA9                           -0.230268   0.725615  -0.317  0.75099
RegionHeadquarters                0.155680   0.113223   1.375  0.16916
RegionParis area                  0.182765   0.122177   1.496  0.13470
RegionSouth West                 -0.472009   0.586351  -0.805  0.42084
ChannelB                          0.142026   0.248928   0.571  0.56831
ChannelL                         -0.139609   0.082359  -1.695  0.09007 .
MarketingM2                             NA         NA      NA       NA
MarketingM3                             NA         NA      NA       NA
MarketingM4                             NA         NA      NA       NA
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for quasipoisson family taken to be 1.012757)

    Null deviance: 5160.1  on 13503  degrees of freedom
Residual deviance: 5037.1  on 13444  degrees of freedom
  (28055 observations deleted due to missingness)
AIC: NA

Number of Fisher Scoring iterations: 13

And:
Call:
glm(formula = TPL ~ DrivAge + DrivGender + MaritalStatus + BonusMalus +
    LicenceNb + PayFreq + JobCode + VehAge + VehClass + VehPower +
    VehGas + VehUsage + Garage + Area + Region + Channel + Marketing,
    family = quasipoisson, data = train)

Deviance Residuals:
    Min       1Q   Median       3Q      Max
-0.6924  -0.3969  -0.3545  -0.3144   4.7259

Coefficients: (3 not defined because of singularities)
                                  Estimate Std. Error t value Pr(>|t|)
(Intercept)                      -3.758964   0.805871  -4.664 3.12e-06 ***
DrivAge                           0.008306   0.003166   2.623  0.00871 **
DrivGenderM                      -0.059227   0.072369  -0.818  0.41314
MaritalStatusDivorced             0.237533   0.286279   0.830  0.40671
MaritalStatusMarried              0.069704   0.083210   0.838  0.40222
MaritalStatusSingle               0.249467   0.101559   2.456  0.01405 *
MaritalStatusWidowed             -0.110189   0.204761  -0.538  0.59049
BonusMalus                        0.009858   0.002356   4.183 2.89e-05 ***
LicenceNb                        -0.006905   0.050557  -0.137  0.89137
PayFreqHalf-yearly                0.027229   0.078711   0.346  0.72940
PayFreqMonthly                    0.198096   0.157291   1.259  0.20790
PayFreqQuarterly                 -0.020713   0.145221  -0.143  0.88658
JobCodeFarmer                     0.565334   0.295674   1.912  0.05590 .
JobCodeOther                      0.213664   0.238004   0.898  0.36934
JobCodePrivate employee           0.210541   0.191649   1.099  0.27197
JobCodePublic employee            0.331952   0.194939   1.703  0.08862 .
JobCodeRetailer                   1.000891   0.612073   1.635  0.10202
JobCodeRetiree                    0.366832   0.227306   1.614  0.10659
VehAge                           -0.014329   0.007741  -1.851  0.06420 .
VehClassCheaper                  -0.013083   0.111105  -0.118  0.90627
VehClassCheapest                 -0.016907   0.149586  -0.113  0.91001
VehClassExpensive                 0.041037   0.390048   0.105  0.91621
VehClassMedium                    0.177040   0.186507   0.949  0.34252
VehClassMedium high              -0.436590   0.310360  -1.407  0.15953
VehClassMedium low               -0.068154   0.137396  -0.496  0.61987
VehClassMore expensive           -0.810244   0.688764  -1.176  0.23947
VehClassMost expensive            0.060609   0.704527   0.086  0.93145
VehPowerP11                       0.152053   0.130469   1.165  0.24387
VehPowerP12                       0.148002   0.140920   1.050  0.29362
VehPowerP13                       0.196015   0.168605   1.163  0.24502
VehPowerP14                       0.489279   0.198917   2.460  0.01392 *
VehPowerP15                       0.210457   0.297820   0.707  0.47979
VehPowerP16                       0.535802   0.422429   1.268  0.20468
VehPowerP17                      -0.089318   1.062724  -0.084  0.93302
VehPowerP2                      -10.935041 345.147440  -0.032  0.97473
VehPowerP4                      -11.316674 344.768434  -0.033  0.97382
VehPowerP5                       -0.888187   0.513750  -1.729  0.08386 .
VehPowerP7                        0.291672   0.260037   1.122  0.26203
VehPowerP8                        0.344021   0.139878   2.459  0.01393 *
VehPowerP9                        0.094111   0.133048   0.707  0.47937
VehGasRegular                    -0.094493   0.077936  -1.212  0.22537
VehUsageProfessional              0.380818   0.218267   1.745  0.08105 .
VehUsageProfessional run          0.565450   0.305062   1.854  0.06382 .
GarageClosed zbox                 0.181757   0.096416   1.885  0.05943 .
GarageOpened collective parking   0.095442   0.113857   0.838  0.40190
GarageStreet                      0.247142   0.119960   2.060  0.03940 *
AreaA12                          -0.032918   1.228840  -0.027  0.97863
AreaA2                           -0.458926   0.717346  -0.640  0.52234
AreaA3                           -0.451137   0.716336  -0.630  0.52885
AreaA4                           -0.243743   0.720159  -0.338  0.73502
AreaA5                           -0.277866   0.713694  -0.389  0.69703
AreaA6                           -0.517108   0.775208  -0.667  0.50475
AreaA7                           -0.302781   0.724004  -0.418  0.67581
AreaA8                           -0.048111   0.731303  -0.066  0.94755
AreaA9                           -0.102986   0.722589  -0.143  0.88667
RegionHeadquarters                0.082624   0.114706   0.720  0.47135
RegionParis area                  0.173735   0.122637   1.417  0.15660
RegionSouth West                 -0.838719   0.709602  -1.182  0.23724
ChannelB                          0.262125   0.244031   1.074  0.28278
ChannelL                         -0.109997   0.081158  -1.355  0.17533
MarketingM2                             NA         NA      NA       NA
MarketingM3                             NA         NA      NA       NA
MarketingM4                             NA         NA      NA       NA
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for quasipoisson family taken to be 0.9951371)

    Null deviance: 5123.8  on 13616  degrees of freedom
Residual deviance: 5008.5  on 13557  degrees of freedom
  (27942 observations deleted due to missingness)
AIC: NA

Number of Fisher Scoring iterations: 12

Answer: I'd suggest you to invest some more time in your models. Here are some issues that might be partly responsible for the unstable results:
1) Throwing away 2/3 of rows due to missing values is very bad practice. Try to retain these lines.
2) Why investing just one parameter in variables like DrivAge but many more for variables like area or power? The decision on how many parameters to use should not be based on the variable type of the data.
3) Why no interactions?
4) Three regressors are perfectly correlated with the others. That should not be happen.


How do I make the ImageView the same size as the image in pixels

Question: I have an image that is 242x314 pixels in size, but when I put it in an ImageView, the image becomes 726x942, which I see in the LayoutInspector, the layout_width and layout_height are set to wrap_content, why is that?How can I make the ImageView the same size as the image.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/eight_age" />

</android.support.constraint.ConstraintLayout>

Answer: You need to set ImageView from java code after getting the width and height of image. Here is the java code for it.
   public void setImage(String filePath){//If you have a bitmap use it directly
        Bitmap bitmap = BitmapFactory.decodeFile(filePath);
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        ImageView imageView = findViewById(R.id.image);//Change id according you name it in xml
        imageView.setLayoutParams(new ConstraintLayout.LayoutParams(width,height));
    }

And here is the xml code
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/eight_age"
        android:id="@+id/image"
        android:scaleType="fitCenter"/>

</android.support.constraint.ConstraintLayout>

Comment: But I'm still wondering why wrap_content can't make the image show its true size...
Comment: @AndLightLight I am not sure but mostly it happens because imageView automatically tries to expand and fill a area of screen or there is one more possibility that it works on other layout except for constraint


Sharing Source Control / Build Artifacts in Cruise Control .NET

Question: I've got one repository with multiple projects underneath it's directory structure, I'm looking to set up a unique CC.NET Project for each project in my repository.
There's two unique challenges I'm running into, and I want to make sure I can do this without shooting myself in the foot.
My main concern is source control, I can duplicate the source control block with the <cc:define> pre-processor block, that's fine. I'm concerned about source control conflicts however. If two projects are running at the same time, one might update the source control while the other is building. Is there a way to share this source control resource safely?
I had thought about having a special project that's responsible for all the CI triggering from source changes / periodic intervals / etc... and have the other projects trigger off of that project's completion. This seems a bit shady to me.
The other issue is dependencies, I know that CC.NET can use Solution files (and it's often reccomended), the problem here is that I'd really prefer to not build my library projects once for each project in CC.NET.
Comment: Did this answer your question? If so please mark the answer as so or provide more detail.
Answer: You could add a queue, that way when a project is building/updating source it blocks all other projects from doing so.
Otherwise you could create a new report on disk for each ccnet project - Which does undermine what you ideally want to do.
The advantages however are that one ccnet project doesn't block another - if it takes a while to build/update
Comment: The issue wasn't build sequence, it's run sequence, I wanted to share the source control checkout and compile results from previous builds so my core library doesn't get built for each child library. I've moved on from CC.NET so I'll let this comment sit here for a bit before I delete the question so you get an answer.


Determine for what values of x the sequence fn(x) = (nx+5)/(6n+7) converges pointwise

Question: May you tell me if this reasoning is correct? Thank you so much!
fn(x) = (nx+5)/(6n+7)
Determine for what values of x the sequence converges pointwise.
The limit function f(x) = x/6
D(x)= Absolute value of (fn(x) - f(x))
= Absolute value of ((nx+5)/(6n+7) - x/6)
= Absolute value of (30-7x)/(36n+42)
The limit of D(x) when n goes to infinite is 0, for all values of x.
D(x) is the distance function between fn(x) and f(x).
Thus fn(x) converges uniformly for all values of R, and for that reason it converges pointwise for all R.
Comment: You have to speak of uniformly convergent on some AREA but not for points. So e.g. uniformly convergent on $\mathbb{R}$. You above proof with the distance function shows pointwise convergent for every $x \in \mathbb{R}$
Answer: $(f_n)_{n \in \mathbb{N}}$ is pointwise convergence, your proof is correct. An easier way is the following: $$f_n(x) = \frac{n(x+5/n)}{n(6+7/n)} = \frac{x+5/n}{6+7/n} \to \frac{x}{6} \ \ (n \to \infty)$$
But the sequence is not uniformly convergent: Let $\epsilon > 0$ and $N \in \mathbb{N}$. Then for $x=-36N-42$ and $n \geq N$ we have
$$f_n(x)-f(x) = \frac{30-7(-36N-42)}{36n+42} = \frac{30}{36n+42}+7 > 7$$
Thus for e.g. $\epsilon=1$, the condition "$\forall \epsilon>0 \ \exists N \in \mathbb{N}$ s.t. $|f_n(x)-f(x)| < \epsilon \ \forall x \in \mathbb{R}$" is not true and $f_n$ is not uniformly convergent.
Comment: Your ideas are wonderful! May you explain me how to calculate the supremum of D(x)? I am sure that I am confused with that. Thank you for everything!
Comment: For $D(x)$ its better to write $D_n(x)$ because it's the distance between two functions and one depends on n. But $\sup_{x \in \mathbb{R}} D_n(x) = \infty$ since you can make the $x$ large and then $D_n(x)$ becomes large (because the $x$ is in the denominator of the above fraction)
Comment: Thank you for your amazing help! One new question: why did you write x is in the denominator? A typo? x is the numerator.
Comment: Oh yes, that was a typo. Numerator is right ;)


What are the equivalent statements of GRH using the Möbius or Liouville functions?

Question: We all know that Riemann Hypothesis can be stated as properties of $\mu$ or $\lambda$, particularly in terms of the random behaviour of those functions with "square root" bounds.
Are there similar equivalent statements for GRH (Generalized Riemann Hypothesis) in term of Möbius or Liouville function ?
I assume such statements exist, but I have not seen them in popular textbooks.
Can anyone share some links or pointers ?
Thanks in advance.
Answer: Well GRH is inherently about Dirichlet characters, so they should be present somehow. For example, we have that for $\Re(s) > 1$,
\[\sum_{n=1}^{\infty} \frac{\lambda(n) \chi(n)}{n^s} = \prod_p \sum_{k = 0}^{\infty} \frac{(-1)^k \chi(p)^k}{p^{ks}} = \prod_p \frac{1}{1 + \chi(p) p^{-s}} = \prod_p \frac{1 - \chi(p) p^{-s}}{1 - \chi^2(p) p^{-2s}} = \frac{L(2s,\chi^2)}{L(s,\chi)}.
\]
If GRH is true for $L(s,\chi)$, then the right-hand side is holomorphic for $\Re(s) > 1/2$, so by the usual methods, one can show that for all $\varepsilon > 0$,
\[\sum_{n \leq x} \lambda(n) \chi(n) \ll_{\varepsilon} x^{1/2 + \varepsilon}.
\]
Conversely, this upper bound holding for all $\varepsilon > 0$ implies that the left-hand side is holomorphic for all $\Re(s) > 1/2$, which implies GRH for $L(s,\chi)$.
Similarly,
\[\sum_{n = 1}^{\infty} \frac{\mu(n) \chi(n)}{n^s} = \prod_p \left(1 - \frac{\chi(p)}{p^s}\right) = \frac{1}{L(s,\chi)}
\]
for $\Re(s) > 1$, and if GRH is true for $L(s,\chi)$ then the right-hand side is holomorphic for $\Re(s) > 1/2$, which implies that
\[\sum_{n \leq x} \mu(n) \chi(n) \ll_{\varepsilon} x^{1/2 + \varepsilon}
\]
for all $\varepsilon > 0$. Again, the converse is also true.
One can also express this in terms of arithmetic progressions using the orthogonality relations for Dirichlet characters. If GRH is true for $L(s,\chi)$ for all Dirichlet characters $\chi$ modulo $q$, then for any $(a,q) = 1$,
\[\sum_{\substack{n \leq x \\ n \equiv a \pmod{q}}} \lambda(n) \ll_{\varepsilon} x^{1/2 + \varepsilon}, \qquad \sum_{\substack{n \leq x \\ n \equiv a \pmod{q}}} \mu(n) \ll_{\varepsilon} x^{1/2 + \varepsilon}
\]
for all $\varepsilon > 0$. Conversely, if
\[\sum_{\substack{n \leq x \\ n \equiv a \pmod{q}}} \lambda(n) \ll_{\varepsilon} x^{1/2 + \varepsilon}, \qquad \sum_{\substack{n \leq x \\ n \equiv a \pmod{q}}} \mu(n) \ll_{\varepsilon} x^{1/2 + \varepsilon}
\]
for all $\varepsilon > 0$ and all $(a,q) = 1$, then GRH holds for $L(s,\chi)$ for any Dirichlet characters modulo $q$.
Comment: Nice answer, but as the OP wished, some source for all this stuff would be welcome.
Comment: I haven't seen this written up anywhere, but it's sufficiently obvious to experts.


Is there a method to print long arrays, in the range of hundred to thousand indices, to a txt file in GDB? (Debugging Fortran Code)

Question: I am wondering whether it is possible to print the values of an array, specifying the format, to a .txt or other file while debugging a fortran program in gdb. This would be ideal if I could run this command when stopped at a breakpoint in the middle of my program. The reason I need this is because the arrays that I look at may have hundreds to several thousands of indices and analyzing them would be easier in a separate form after opening a text file. I don't have much C programming experience so I am having trouble outputting to a file using printf (I'm not exactly sure what the argument format is). I've tried searching through the internet to find this solution but the closest thing I have found is the dump command which isn't exactly what I'm looking for. I appreciate any help with this matter!
Comment: Why not write the necessary fortran code to write it all out to disk as needed?
Answer: The simplest solution is to write a debug dump routine in your program, and call it from GDB with the call command.
The next simplest solution is to write a python routine to do the same. Documentation.


How to make blob file downloadable?

Question: I have created a Module to make blob file available for Download in Drupal 7 .
Below my code for .module file
<?php

function blobfile_block_info() {
  $blocks = array();
  $blocks['blobfile_block'] = array(
    'info' => t('Blob Files Download'),
  );

  return $blocks;
}

function blobfile_block_view($delta) {

      $query = db_select('health_policy_document_upload_dtl', h)->fields('h');
      $result = $query->execute();

      $content ='';
      while($record = $result->fetchAssoc()) {

          $filename = $record['Document_Name'];
          $file     = $record['Document'];
          $type     = $record['Document_Type'];
          $size     = filesize($file);

          header("Content-length: $size");
          header("Content-type: $type");
          header("Content-Disposition: attachment; filename=$filename");

          $content .= "".$filename."";
          $content .= "
";
      }

    return array(
      'subject' => t('Bids'),
      'content' => $content
    );

}

Please guide me where I went wrong.
Comment: Can you expand a bit on what you want to have built and what's happening?  You've built a block display that sets the response headers for a download (several times potentially), but then returns content for the block. You will need at least a hook_menu() and a router to return the files but exactly how that would works depends on what you are trying to do.
Comment: Here am trying to create a Block using custom code to display list of documents, which can be downloaded by clicking on the same. I can able to get result from database and display the same. but how to make those blob files available for download?
Answer: I'm assuming you have already come up with a solution to upload the files and put them in the database, and that you have a good reason not to use Drupal's built-in file handling (I question that second assumption particularly given the reference to health policy but I'll grant it).
The block you created needs to just provide the list of links, but you should not set the headers there, just generate the links.  The link should probably be in the form of something like:  /custom_files/[filename]  (or something clearer based on your complete context.
First you need a hook_menu() to define the menu router to get your files. Something like:
function mymodule_menu() {
  $items['custom_files/%mymodule_filename'] = array(
    'page callback' => 'mymodule_filedownload',
    'page arguments' => array(1),
    'delivery callback' => 'mymodule_file_delivery',
  );
}

You should also add some permissions handling here, the documentation on hook_menu() explains how that works.  Also read the section on deliver callbacks because those also have security implications I'm glossing over.
Next you need the page callback function to actually send the file:
function mymodule_filedownload($mymodule_filename) {
   // Validate permissions
...
   // Validate filename
...
   // Load file object from database
   $query = db_select('health_policy_document_upload_dtl', h)->fields('h')->condition('filename', $mymodule_filename,'=');
  $result = $query->execute();

   // Prep an array to hand data off to the delivery callback. It might just be the results, but often you want to tweak details...
...
  return $file_data_array;

}

function mymodule_file_deliver($file_data) {
   // Check $file_data to see if this is a valid file or an error of some kind.
...
  // Process and errors found and send proper error response.
...

  // Send file
  drupal_add_http_header("Content-length: ".$file_data['size']);
  drupal_add_http_header("Content-type: " .$file_data['type']);
  drupal_add_http_header("Content-Disposition: attachment; filename=".$file_data['filename']);

   print($file_data['data']);

   drupal_page_footer();
}

Obviously lots of details are glossed over here. In addition to hook_menu()'s documentation you likely will also want to read drupal_deliver_html_page().  Note the use of drupal_add_http_header() instead of PHP's header(), for most basic tasks Drupal has internal functions that provide some clean up and standardization to avoid basic mistakes and conflicts with other module; you should use them whenever possible.

How to make blob file downloadable?


How to use Drush or Migrate module to create/edit/delete nodes hourly

Question: I need to

Create new nodes (W/12 fields) hourly from a new table/fields in the Drupal DB (x_table).
Update currently created nodes via current x_table rows.
Delete nodes once the row has been removed from x_table.

My skill sets do not include coding, and for years I have gotten by with the great Drupal modules, although I haven't had to import/update/delete rotating 10,000+ nodes.  I previously used Feeds w/out updating, and it was extremely slow.
I've been reading I should be using the Migrate module and/or Drush.  (I understand that Drush is part of Migrate)??  Anyhow I have installed the migrate module, but I have been completely baffled for an hour by their UI.  It seems I need to create some data/text files for it to work, which is why I was trying to use the UI.
I feel that it will likely be best to create these scripts using Drush and calling them hourly via cron.
My question is, how do I create the script??  I'm not quite sure how to map the fields either?  Could someone suggest a page showing this, or put together a quick example to work off of?  30 mn's of using the search engine hasn't shown me much, mostly only using csv files, etc. and not pulling from a database.
Thanks in advance for any help/suggestions.
Answer: In your module for the migration use this code:
<code>function YOURMODULENAME_cron() {
$machine_name = "MACHINE NAME OF YOUR MIGRATION";
$last_run = variable_get('YOURMODULENAME_last_cron', 0);
$interval = variable_get('YOURMODULENAME_cron_interval', 60);//60 seconds
if(time() - $last_run > $interval)
  {
   variable_set('YOURMODULENAME_last_cron', time());//track the last_run time
   $migration = Migration::getInstance($machine_name);
   $result = $migration->processImport();
  }
}
</code>


$A$, $B$ have eigenvalue $\pi$ implies $A - B$ has eigenvalue $0$?

Question: I like to know if this is true or false and why.

If $A$ and $B$ are $n \times n$ matrices with the same eigenvalue $\pi$, then an eigenvalue of $A-B$ is $0$.

Kind regards,
Dieter.
Answer: No, consider $A= \pmatrix{1 & 0 \\ 0 & -1}$ and $B= -A$. Then $A$ and $B$ have the same eigenvalues, but $A-B = \pmatrix{2&0 \\ 0 &-2}$ doesn't have  $0$  as an eigenvalue.
Answer: If I've interpreted the question correctly, the answer is no. Consider
$$A = \left[\begin{array}{cc}
2 & 0\\
0 & 1
\end{array}\right]\qquad\text{and}\qquad
B = \left[\begin{array}{cc}
1 & 0\\
0 & 2
\end{array}\right]$$
both of which have $2$ as an eigenvalue. Now consider $A - B$.
Answer: It will only work under the additional constraint, that they have a common eigenvector for that eigenvalue. Then you have $$Av = \lambda v = Bv \Rightarrow (A-B)v = Av-Bv = (\lambda - \lambda) v = 0$$
Answer: You got your counterexamples, but the "why" part might be more interesting. So, let us assume that we have matrices $A$ and $B$ with the common eigenvalue $\lambda$ (a bit more common than $\pi$). Then
$$Au = \lambda u, \quad Bv = \lambda v,$$
for some nonzero vectors $u$ and $v$. Now, if $u = v$, then
$$(A - B)u = Au - Bu = \lambda u - \lambda u = 0 = 0 u,$$
so zero is indeed an eigenvalue of $A-B$. However, if $u \ne v$, you cannot make such a conclusion. You can consider an eigenvector $w$ of $A - B$, but without any connection to $u$ and $v$, this is useless.
It probably seems obvious that the eigenvalues of $A - B$ are $\lambda_i - \mu_i$, where $\lambda_i$ are the eigenvalues of $A$, and $\mu_i$ are the eigenvalues of $B$, but this is far from correct, and works only if they have the same eigenvectors associated with them.
Also, note that the eigenvalues are never given in any specific order (i.e., there is no "first", "second",... eigenvalue), so you'd actually have $\lambda_i - \mu_j$ for all $i,j$, which is $n^2$ values if both $A$ and $B$ are diagonalizable, and $A - B$ can have at most $n$ eigenvalues, so $\lambda_i - \mu_j$ certainly cannot all be the eigenvalues of $A - B$.


How do I supposed to run Nginx + Django site connected together by UNIX socket?

Question: <code>runfcgi.py:18: RemovedInDjango19Warning: FastCGI support has been deprecated and will be removed in Django 1.9.
</code>
What to use instead? I don't want Nginx and Django site to share user account, chroot and other things and want a UNIX socket between them.
Is there any supported way to run Django disjointed from the web server?
Answer: You should move to uWSGI instead http://nginx.org/en/docs/http/ngx_http_uwsgi_module.html


Why the sample covariance estimator is unbiased, but the sample pearson correlation coeficient is not?

Question: Why the sample covariance estimator is unbiased, but the sample Pearson correlation coefficient is not?
I'm a bit confused because the sample Pearson coefficent was built using the sample covariance estimator and the sample variance estimator, that are both unbiased.
Thanks in advance!
Answer: Amazingly, transforming an unbiased estimator often results in a biased estimator. This is how the sample standard deviation is a biased estimator, despite the sample variance being unbiased. This fact comes from something called Jensen's inequality. For a concave function $f$, such as a square root:
$$
f(\mathbb{E}[X])\ge \mathbb{E}[f(X)]
$$
Equality holds if and only if $f$ is a straight line (or if $X$ is constant).
So why is $\hat{\rho}=\dfrac{\widehat{cov}(X,Y)}{s_X s_Y}$ biased? The standard deviation estimators are biased!
Comment: The Wikipedia article on Jensen's inequality has some pictures that might give some intuition.


How do I set my views to return a 404 using Global: Null under contextual filters?

Question: Standard Drupal behavior is to pass all arguments through, whether or not they requested. Sometimes this behavior is desired. However, I need to return a 404 for anything but a query string.
Example of the problem
http://drupal.org/project/modules
http://drupal.org/project/modules/google.com <- This should return a 404; 200 given. Duplicate content penalty!
The views 404 module assumes that by default you do not want arguments passed through. However there is no D7 version of the module.
But the project page says that 404s for views can also be accomplished by setting the Global: Null under Arguments.
Obviously in D7 "arguments" are now "contextual filters", but I am unsure as to what settings to add to the Global:null contextual filter to get my desired result.
Any help would be appreciated.
Answer: In Contextual filters select Add; in the dialog box that appears, select Global: Null.

Click on Add and configure contextual filters.
In the dialog box that appear next, in the fieldset When the filter value is available or a default is provided, check Specify validation criteria, select - Basic validation - for Validator, and select Show "Page not found" for Action to take if the filter value does not validate. In the fieldset More, check Fail basic validation if any argument is given.

I tested it with an "Articles" view I created, and it works.

The "Global: Null" argument must be the last one. If you need a user ID, for example, first you add it as argument, and then add the "Global: Null" argument.
I altered the "Article" view to accept a user ID as argument, which is used to filter the list of article nodes. The view still works, as it doesn't accept an extra argument.

Comment: This will return 403 not 404 code error. Select "Show "Page not found" option instead
Comment: @EugeneFidelin I was editing the "master" display, and I was not seeing the _Show "Page not found"_ as option. I corrected my answer.
Comment: In a thread on D.O. I see someone suggesting to use arg(1)==NULL; in the php validate code. Is this better or pretty much the same thing?
Comment: @NigelWaters Forget my previous answer. `:)` I was editing the wrong display, and the view was not working as it should. There is no need to use PHP code to validate the argument; see the updated answer.
Comment: I don't have enough points to comment yet - so posting here to say thanks to @kiamlaluno. Works great and something I was banging my head against for a while.
Comment: Thx Kiam, one issue I noticed that this solution does not work if there is a pager, otherwise it is good. For example /myinvalidargument?page=10 still shows content instead of 404.
Comment: There is an issue with Global:null. It is ignored when argument equal = all https://www.drupal.org/node/1951456
Answer: You can do this using views out of the box functionality. In every contextual filter setting you can see a check-box "Specify validation criteria" check that to see more settings.
Then, you can select "validator" based on your view conditions. If you would like to custom validate then select php code. Return True or False in php code based on your validation conditions.
Finally select "Action to take" as Display Access denied ! See below screenshot for nid contextual filter.
Comment: NEVER USE PHP CODE IN VIEWS OR ANY OTHER UI TOOL!!!
Comment: What is the php code that I add?
Comment: I am only using the Global:null contextual filter


Calculating probability of a normal distribution, not getting correct answer

Question: I'm doing a homework assignment and having some trouble matching the correct answers from my professor. As a reference, I'm calculating these answers using R.
The question is as follows:
Assuming $E(X_i) = \mu = 7$, $Var(X_i) = \sigma^2 = 0.12$, and $\bar{X_{50}} \sim N(7,0.12)$
What is $P(\mu - 2 \times \frac{\sigma}{\sqrt{50}} \leq \bar{X_{50}} \leq \mu + 2 \times \frac{\sigma}{\sqrt{50}})$?
The answer my professor gave is $0.9545$. He also stated that I don't need to know the values of $\mu$ and $\sigma$.
I don't know how he got this though? Doing the easy thing and plugging in 7 for $\mu$ and 0.12 for $\sigma^2$ I ended up getting:
$P(6.90202041 \leq \bar{X_{50}} \leq 7.09797959) = P(\bar{X_{50}} \leq 7.09797959) - P(\bar{X_{50}} \leq 6.90202041)$
Then in R I did pnorm(7.09797959,7,0.12) - pnorm(6.90202041,7,0.12) and got the result $0.5857838$
My question is what did I do wrong, and what should I be doing? This is the way he told us to do inequalities for probabilities like the one above. Also how could this be solved without having to use $\mu$ and $\sigma$?
Answer: Consider the more general probability $$\Pr\left[ \mu - z \frac{\sigma}{\sqrt{n}} < \bar X < \mu + z \frac{\sigma}{\sqrt{n}} \right],$$ for some $z > 0$, where $$\bar X = \frac{1}{n} \sum_{i=1}^n X_i$$ is the sample mean of $n$ independent and identically distributed observations from a normal distribution with mean $\mu$ and standard deviation $\sigma$.  Then the sampling distribution of the sample mean is also normally distributed, with the same mean $$\mu_{\bar X} = \mu$$ but with standard deviation $$\sigma_{\bar X} = \frac{\sigma}{\sqrt{n}}.$$  Therefore, if we standardize $\bar X$, we find that the above probability is equivalent to $$\Pr\left[ -z < \frac{\bar X - \mu}{\sigma/\sqrt{n}} < z \right],$$ and the random variable $$Z = \frac{\bar X - \mu}{\sigma/\sqrt{n}}$$ is a standard normal random variable with mean $\mu_Z = 0$ and standard deviation $\sigma_Z = 1$.  So the above probability is simply $$\Pr[|Z| < z] = 1 - 2 \Phi(-z) = 2\Phi(z) - 1.$$  Now you can see why your professor said that the values of $\mu$ and $\sigma$ do not matter:  what matters is the constant $z = 2$.  Looking up $\Phi(2) \approx 0.97725$ in a standard normal table, or using the R command pnorm(2,0,1), we then obtain the desired probability $$2(0.97725) - 1 = 0.9545,$$ as claimed.

Now, let's see why your calculation didn't work.  First, we have to be clear about the difference between the normal distribution from which individual observations are drawn, and the normal distribution that represents the mean of the set of observations, which we called "the sampling distribution of the sample mean."  Both distributions are normal, and both have the same mean, but the sampling distribution has a standard deviation that is a decreasing function of the sample size:  $\sigma_{\bar X} = \sigma/\sqrt{n}$.  Consequently, if individual observations follow a $\operatorname{Normal}(7,0.12)$ distribution, the sample mean of $n = 50$ such observations follows a $\operatorname{Normal}(7,0.0169706)$ distribution.  This, in addition to an apparent arithmetic error, is why your pnorm() command is incorrect, because you are using the wrong standard deviation.
The correct R command should be
pnorm(7+2*0.12/sqrt(50),7,0.12/sqrt(50))-pnorm(7-2*0.12/sqrt(50),7,0.12/sqrt(50))

which gives the same result as we calculated above.


What is the term in music recording for a mistake that is intentionally left in?

Question: The original fuzz bass effect, in "Don't Worry" by Robbins, for example, is one of these. Another example would be a click track being audible within the song; this I have also heard. "Lo-fi music" is music that lives on allowing such mistakes to persist, but more granularly, what do you call a mistake that is so allowed?
Comment: Half of Led Zeppelin's Whole Lot of Love would be a famous example. You can hear the original vocal take bleeding off the drum mics. Left in because… what the hell else were you going to do to clean that up in 1970? Or Bowie's "Get back on there" in Jean Genie - when the band almost went to the chorus 2 bars early.
Comment: I call it "live performance". :-)
Comment: I'd say "double mistake": the first is playing it, the second leaving it there ;-)
Comment: Improvisation, ornamentation, innovation.
Comment: I would call it owning your mistake
Comment: A fairly extreme example: when Tangerine Dream were recording a track from [Force Majeure](http://www.voices-in-the-net.de/force_majeure.htm), a transistor blew on their mixing desk — but they liked the resulting distortion and strange noises enough to keep it all in.
Comment: Related: https://www.youtube.com/watch?v=f19Z9Y0U92A
Comment: Permitted cock-up.
Comment: @Tetsujin I gotta admit, I started asking this question because I forgot the word "bleed."
Comment: I always called it "leaving a mistake in"
Comment: Another famous example was Its only rock n roll by the Rolling Stones, recorded it just to find out they recorded it in completely the wrong key
Comment: "lo fi" means low fidelity. That style tries to deliberately have lots on recording noise. To my ears it tries to recreate the sound of low quality, at home recording to tape, like old four track recording on cassette tapes, etc.
Answer: An excerpt from the wikipedia page on the Traveling Wilburys, a rock "supergroup" of sorts:

The term "Wilbury" also originated during the Cloud Nine sessions. Referring to recording errors created by faulty equipment, Harrison jokingly remarked to Lynne, "We'll bury 'em in the mix." Thereafter, they used the term for any small error in performance. Harrison first suggested "the Trembling Wilburys" as the group's name; at Lynne's suggestion, they amended it to "Traveling Wilburys"

Hardly well accepted terminology, but a word for it nonetheless.
Answer: Not limited specifically to music or recording, a happy accident might be called serendipity.
Several things that end up as effects in recording started out as epiphenomena, e.g., a lot of what we have come to expect in guitar tone came about because the process of sensing and amplifying the sound was imperfect.
But those are not "mistakes" exactly.
The Wikipedia article on "Don't Worry" says that guitarist Grady Martin didn't like the sound (so at least he considered it a mistake), but the producer liked the effect and kept it.
In your example of the audible click track, do you know that the artist or producer perceived it as a mistake?  It could have been done intentionally (or at least deliberately).
Some "lo fi" might arise from accepting mistakes, but some might just arise from experimentation by someone with an artistic ear and a willingness to eschew conventional recording or performance wisdom.
I've not yet come across a good concise musical term for a note played accidentally during improvisation that ends up working out.  We need one.
A related question was posed on the English Language & Usage stack: What is it called when something you previously took to be a mistake turned out to be the correct decision?
You might also look into what some call "Persian flaws", deliberate mistakes in handmade Persian rugs and carpets.  (Similar concepts occur elsewhere in the arts.)
Comment: "I've not yet come across a good concise musical term for a note played accidentally during improvisation that ends up working out. We need one." It's called Jazz :P
Answer: Perhaps 'happy accident' is the term you're looking for.  But sometimes just 'accident' that it wasn't feasible (or wasn't considered worth the effort) to fix.  I imagine most click-track leakage falls into this category.


Permission denied (publickey). (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255]. exited with return code [255]

Question: try to connect the virtual machine with gcloud but failed. Please advise
email@example.com: Permission denied (publickey).
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255]

Comment: if you find any answer useful, please consider upvoting/accepting it, thank you!
Answer: The permission denied (publickey) indicates your authentication is not correct.  Be sure you are using the proper public/private key pair.
See also:
https://cloud.google.com/sdk/gcloud/reference/compute/ssh#--ssh-key-file
Answer: There could be various reasons because of which the ssh is not connecting:

Firewall allow rule not added for ssh on the instance.
The ssh server is off or malfunctioned on the system after restart.
The keys are not added on .ssh folder in the user's directory.
If OS login is enabled may cause ssh to malfunction.

Try logging in as a different user with the gcloud tool by specifying another-username with the SSH request. The gcloud tool updates the project's metadata to add the new user and allow SSH access.
gcloud compute ssh another-username@$PROB_INSTANCE
I recommend you to review with the SSH troubleshooting steps as described in the documentation
Additionally, you can take a look at the following guide that explains how to control access to Linux instances by manually creating SSH keys and editing public SSH key metadata as alternative.
I hope this information would be useful to you
Answer: There may be several reasons why you can't connect. Firewall shouldn't be one of them since you're getting connected but authentication fails.
If you have OS login enabled you control access to your VM's by granting appropriate roles in the IAM. Most convinient & centralised way to grant SSH acces to your OS enabled VM's would be to create a dedicated service account and grant it SSH access.
It's good to try to update your SSH keys: gcloud compute os-login ssh-keys update
If you have OS login disabled (default setting, unless your organisation forces it enabled) then you can try update your SSH keys with gcloud compute config-ssh.
If you're still unable to connect you can have a look at the general SSH troubleshhoting documentation.
Still can't log in ?
Find out what's going on with your VM, check serial console output - this may give you a hint. Your OS may not boot up properly (full disk, corrupted files, many other reasons).  Have a look at one of my answers here how to troubleshoot this.
If you see that your system disk has ran out of space you can make it bigger with gcloud compute disks resize example-disk-1 --size=11GB
Another way to get into the VM is by manually addind a user/password (with no ssk-key) and logging in "the old way" - see my other answer how to add a user using startup script.
There may be some other reasons like routes on your VM (which may not sound very obvious) - I've found such an example here.


Nothing appears in Typo3 with powermail (Frontend)

Question: I need help with powermail.
I'm using Typo3 6.2.4 and powermail 2.0.16.
Something is wrong cause nothing appear in the frontend, but I don't what and I need some helps.
I created a new root page with the basic template "HELLO WORLD!" (ID = 15).
<code># Default PAGE object:
page = PAGE

page.10 = TEXT
page.10.value = HELLO WORLD!
</code>
In this template, I included two statics templates : "Main Template (powermail)" and "Add basic CSS (powermail)"
After that, in the root page, I created the folder "Powermail" to stock the data. (ID = 241)
And I created a second folder ("Form"; ID = 242).
In the folder "Form", I created a new Form ("registration") with the setting : Layout=Layout1; Language=Default; And the checkbox "Hide" is not checked
In this one, one Pages ("registration data") with the setting : Layout=Layout2; Language=Default; And the checkbox "Hide" is not checked
In "registration data", two fields, one for the name (Name of the sender) and one for the mail (Email of the sender) with setting : Mandatory Field=Checked; Layout=Layout3; Language=Default; And the checkbox "Hide" is not checked
And after that, in the root page, I created a new content element "powermail".
In the tab General, I set the header = Registration
In the tab Plugin, I selected Powermail. After, this is the setting : Selected Items=registration; Confirm page=checked;
Receivers Name=My Name; Receivers firstname.lastname@example.com; Subject=My test;
Sender Name=A Name; Sender email@example.com; Subject=test;
In the tab Behaviour, Recursive=0 levels;
Answer: It seems that you are missing the proper typoscript to actually show the form on the page.
The specified typoscript snippet is not enough to show the content elements on the page.
Inside your typoscript template include the css_styled_content static template and change the snippet to this:
<code># Default PAGE object:
page = PAGE

page.10 < styles.content.get
</code>
That should ensure proper showing on the frontend. This is basic as it is, if you want it to be better looking, or different templating you should take a look at templating with TYPO3 first.
Comment: I have one more question, is it possible to remplace styles.content.get by my own typoscript? How I do that?
Comment: A little late, but still an answer to the question. You can always provide your own typoscript (TS). In fact, the styles.content.get is one giant preset typoscript 'array'. You can complete override it or simply replace little things.

You might benefit from the information on the Typoscript in 45 minutes tutorial, [link](https://docs.typo3.org/typo3cms/TyposcriptIn45MinutesTutorial/)


How do I resolve "Use scipy.optimize.linear_sum_assignment instead"

Question: I am using python script for people detection.
I have the following line in my script:
import time
import cv2 as cv
import glob
import argparse
import sys
import numpy as np
import os.path
from imutils.video import FPS
from collections import deque
from sklearn.utils.linear_assignment_ import linear_assignment

When I run my script I have got the following lines:
/home/user/.local/lib/python3.6/site-packages/sklearn/utils/linear_assignment_.py:127:
     DeprecationWarning: The linear_assignment function is deprecated in 0.21 and will be removed from 0.23. Use scipy.optimize.linear_sum_assignment instead.
     DeprecationWarning)

Please, advice me how to solve it.
Answer: You need to replace the sklearn.utils.linear_assignment_.linear_assignment function by the scipy.optimize.linear_sum_assignment function.
The difference is in the return format: linear_assignment() is returning a numpy array and linear_sum_assignment() a tuple of numpy arrays. You obtain the same output by converting the output of linear_sum_assignment() in array and transpose it.
Your script should look like this:
import time
import cv2 as cv
import glob
import argparse
import sys
import numpy as np
import os.path
from imutils.video import FPS
from collections import deque
from scipy.optimize import linear_sum_assignment

#compute your cost matrix
indices = linear_sum_assignment(cost_matrix)
indices = np.asarray(indices)
indices = np.transpose(indices)

Answer: Replace the linear_assignment for linear_sum_assignment
# from sklearn.utils.linear_assignment_ import linear_assignment
from scipy.optimize import linear_sum_assignment
cost = np.array([[4, 1, 3], [2, 0, 5], [3, 2, 2]])
# result = linear_assignment(cost)
result = linear_sum_assignment(cost)
result = np.array(list(zip(*result)))

https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linear_sum_assignment.html


Contrary argument on $\inf h(x)$

Question: Suppose $h(x_n)$ is nonincreasing and we want to prove $\lim_{n\to\infty} h(x_n)=\inf h(x)$. $h$ is a function. Suppose we use a contrary argument, so we assume that $\lim_{n\to\infty} h(x_n) > h(x)$ for some $x$. Do we need any additional conditions? What if we want to prove $\lim_{n\to\infty} h(x_n)=\min h(x)$ using a contrary argument?
Answer: I assume that with $\inf h(x)$ you mean the infimum of the range of the function, let me call it $m$.
First a general fact:

Fact. if $h(x_n)$ is a convergent sequence (or diverges at $-\infty$), then $\lim_{n\to\infty}h(x_n)\ge m$.

The proof is easy. In particular, this holds if $h(x_n)$ is nonincreasing, because then it is convergent (or diverges to $-\infty$).
Let's now prove what you seem to be interested in:

$\lim_{n\to\infty}h(x_n)\ne m$ if and only if there exists $x$ such that $\lim_{n\to\infty}h(x_n)>h(x)$

Proof. Suppose that $\lim_{n\to\infty}h(x_n)>h(x)$; we have $\lim_{n\to\infty}h(x_n)> h(x)$ by assumption.
If $\lim_{n\to\infty}h(x_n)=m$, then we'd get $m>h(x)$, which is a contradiction.
Suppose instead that $\lim_{n\to\infty} h(x_n)\ne m$. Then $\lim_{n\to\infty}h(x_n)>m$ (because of the Fact above). Let $L>m$ be the limit. Then there exists $x$ so that $L>h(x)>m$, by definition of infimum.
QED
Here I assumed $m$ is finite; do the necessary changes for the case the function $h$ is unbounded below.
The case with the minimum has some additional complications (think to $h$ being a constant function).
Comment: My question is about function of sequence, not sequence. Your proof is not what the original post asked.
Comment: @JohnSmith Just set $a_n=h(x_n)$.
Comment: So you proved $\lim_{n\to \infty} a_n=\inf \{a_n\}$, but did you prove $\inf\{a_n\}=\inf h(x)$? Besides, the OP didn't ask a proof.
Comment: @JohnSmith The symbol $\inf h(x)$ is tremendously ambiguous; I assume it is $\inf h(x_n)$, otherwise the result would be plainly false. My first paragraph is about the issue in the OP's (that is, you) attempt.
Comment: The OP didn't ask whether the statement is true of false. By the way, it might be true under certain conditions. Please see the question carefully.
Comment: @JohnSmith It's your turn to make the question more precise. What do *you* mean by $\inf h(x)$? What is $h$? A generic function?
Comment: @JohnSmith I rewrote my answer with a different interpretation of your ambiguous $\inf h(x)$. But you're not helping.
Comment: I think your argument has some mistakes. You first assumed $\lim h(x_n)\neq m$, then you assumed $\lim h(x_n)=m$. Therefore, a contradiction was found.
Comment: @JohnSmith You asked me to read more carefully your question and I did it. Why don't you spend some time reading carefully my answer? In other words, the two paragraphs starting with "Suppose" are meant to prove the equivalence of "$\lim_{n\to\infty}h(x_n)\ne m$" with "there exists $x$ such that $\lim_{n\to\infty}h(x_n)>h(x)$". I reformulated the paragraph for better clarity.
Comment: To make the argument complete, I think the **FACT** needs a proof.
Comment: @JohnSmith You should be able to supply it. It's a simple application of the definitions.
Comment: When $h(x_n)$ diverges at $-\infty$, what does that mean $\lim_{n\to\infty}h(x_n)\ge m$?
Comment: @JohnSmith Just that $\lim_{n\to\infty}h(x_n)=-\infty$, of course. Since in this case also $m=-\infty$, this is just a method for not dividing the statement into too many cases.
Comment: Thanks! I greatly appreciate the answer and explanations.
Answer: The statement $\lim_{n\to\infty}h(x_n) = L$ means that
$$\forall \epsilon > 0,\,\exists n_0\in\mathbb N,\,\forall n\geq n_0,\,|h(x_n) - L|<\epsilon.$$
Its negation is hence
$$\exists \epsilon > 0,\,\forall n_0\in\mathbb N,\,\exists n\geq n_0,\,|h(x_n) - L|\geq\epsilon.$$
In other words, there is some $\epsilon >0$ and arbitrarily large indices $n$ such that $h(x_n)$ is at least $\epsilon$-away from $L$.
Comment: I don't think the argument is applicable to the above case. For instance, you assumed that $L$ is known, but that's not the case. Also $h(x_n)$ is nonincreasing.
Comment: It was my understanding that the question was about proof by contradiction (rather than about proving or disproving the claim per se). What I did was in fact provide the definiton of $\lim_{n\to\infty}h(x_n) = L$ and its negation.

Contrary argument on $\inf h(x)$


Monitorar serviço com Borland Socket Server

Question: Estou desenvolvendo uma aplicação em três camadas no delphi-7 , utilizando o componente TSockecConnection.
É possível fazer o monitoramento das conexões, identificar o IP dos usuários conectados, bem como derrubar algum usuário?
Comment: A resposta abaixo conseguiu resolver teu problema?
Answer: Segue abaixo um exemplo de como realizar o controle de conexões:
Para gravar quais usuários estão conectados, você precisa utilizar o evento ClientConnect do server socket e adicionar o cliente a algum objeto, lista ou dataset
procedure TForm1.ServerSocket1ClientConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
  AdicionaClienteConectado(Socket.RemoteAddress, Socket.RemotePort);
end;

Da mesma forma, você utiliza o evento onCLientDisconect para remover desta lista os usuários que se desconectarem
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  RemoveClienteConectado(Socket.RemoteAddress, Socket.RemotePort);
end;

E quando quiser derrubar um usuário é só forçar a desconexão do mesmo utilizando as informações que foram utilizadas para manter os dados dos usuarios conectados e dar um close na conexão
procedure TForm1.DerrubarCliente(const EndCliente: string;
  const PortaCliente: Integer);
var
  I: Integer;
begin
  for I := 0 to ServerSocket1.Socket.ActiveConnections - 1 do
  begin
    if (ServerSocket1.Socket.Connections[I].RemoteAddress = EndCliente) and
      (ServerSocket1.Socket.Connections[I].RemotePort = PortaCliente) then
      ServerSocket1.Socket.Connections[I].Close;
  end;
end;


Is there a way to let Python generate multiple if statements?

Question: I just need to add +30 to every number in every if statement. I need 36 of these, is there a way to let turtle make more if statements or something similar? I'm really stuck and the manual way would be crazy.
For example:
if 0 <= x <=30 and 0 <= y <= 30:
      turtle.drawsstuff

if 30 <= x <=60 and 0 <= y <= 60:

etc.

Comment: It depends on your if statements
Comment: What's in the if-statement bodies?
Comment: turtle fills a square
Comment: If you need this, you're doing something the hard way or doing the wrong thing altogether.
Answer: Use a for loop.
for n in range(0, 36 * 30, 30):
    if n <= x <= n + 30 and 0 <= y <= n + 30:
        pass #do something

Answer: for n in range(0, 36 * 30, 30):
    if n <= x <= (n+30) and n <= y <= (n+30):
        pass  # (do stuff)

range can take an optional third argument for the "step" value. For reference, see Python's documentation on range.


Bypass permissions in custom module

Question: I have written a custom module which generates a PDF when a Webform is submitted and mails it to the admin. I am using the Print module to generate the PDF. The problem is, it seems to use the user's permissions when generating the PDF, and not the admin's. This is generally ok for authenticated users, but for guests, it just fails completely.
I have enabled "Access the PDF version" and "Access own webform submissions" permissions for all users (anonymous and authenticated), but I guess "own" still checks for a user ID and fails for guests.
The Print module uses this code to get the content of the $node from the URL.
$node = new stdClass();
$node->body = menu_execute_active_handler($path, FALSE);

This is how I am using the Print module to generate the PDF content.
module_load_include('inc', 'print_pdf', 'print_pdf.pages');
$pdf_url = 'node/' . $nid . '/submission/' . $sid;
$file_content = module_invoke('print_pdf', 'generate_path', $pdf_url);

When the logged-in user has the permission, this works fine; it generates and mails the PDF successfully. The content of $node->body is fully populated.
However, when with anonymous users, the content of $node->body is just an integer. Is there any way for me to tell it to bypass the permissions when generating the PDF? Or is there a better, secure way around this?
Answer: Looking at webform_submission_access, prior to getting the PDF url, try:
// Where $sid is the webform submission id
$_SESSION['webform_submission'][$sid] = TRUE;

If that works for the anonymous user, it may grant access to view that submission.
Comment: Thanks, that seems to be working! There are some notices in the Webform module about an `$account` variable missing, but they are just notices.
Comment: And just a note for anybody else that I still had to have both permissions enabled for anonymous users.

Bypass permissions in custom module


Novice haskell - sequential monad binding

Question: I'm looking for the idiomatic way to do this. It works, but seems like I must be reinventing something in the standard library. What's the right way to do this?
I'm trying to pass a list of functions and bind them in sequence. Toy example:
bindSeq :: (Monad m) => m a ->  [(a -> m a)] -> m a
bindSeq m [] = m
bindSeq m (x:xs) = bindSeq ( m >>= x ) xs

bindSeq (Just 4) [ Just . (+1), Just . (+2)]
Just 7

Comment: What about `bindSeq = foldl' (>>=)`?
Comment: See [concatM](http://hackage.haskell.org/packages/archive/monad-loops/latest/doc/html/Control-Monad-Loops.html#v:concatM) in the **monad-loops** package.

Also, you could define a Monoid instance, like [this](https://gist.github.com/hiratara/4038651). Maybe there is a standard one already defined, but I can't find it.
Comment: Yes, that's kind of what I was looking for, thanks
Answer: As @Fixnum wrote in 2013, your bindSeq is foldl' (>>=)
But if you want to see this as an "effectful fold" over values, then you can just "put on m-colored glasses" and overlook the m, then look what's left. Absent the monadic effects, you want a signature: a -> [a -> a] -> a.
This is folding function application and can be written foldl (flip ($)).
So now, "promote" that to be effectful and we see the following:
Prelude Control.Monad> :t foldM (flip ($))
foldM (flip ($)) :: Monad m => a -> [a -> m a] -> m a

as desired!


Proving a system is linearly independent in a Hilbert Space

Question: http://i.stack.imgr.com/QfTyD.png
Okay, I've done part (i) but I'm stumped on part (ii) and how I can show that.
Any help would be appreciated please.
Answer: Suppose
$$\sum_{k=1}^n a_ke_k=0\implies\;\forall\,j=1,2,...,n\;,\;:$$
$$0=\left\langle \sum_{k=1}^na_ke_k\,,\,e_j\right\rangle=\sum_{k=1}^na_k\langle e_k\,,\,e_j\rangle=a_j$$
and we're done...
Comment: Thankyou for this, but can you tell me what the variable "a" represents? And also, how does this actually show that it is in fact linearly independent? So I know the workings behinds the answer to I understand it.
Comment: $\;a_i\;$ are not variables but *scalars*, and you should read again carefully the definition of "linear independent set" in a vector space
Comment: Just looked it up, makes sense now, thankyou!
Comment: Any time, @user109331...this is stuff you can't allow yourself to forget if you're going to mess up with Hilbert, Banach and stuff spaces...


Visual studio abre código já existente quando clico em NOVO projeto?

Question: Comecei a aprender C# e estou usando o Visual Studio.
criei meu programa básico "hello world", salvei o projeto. Até ai tudo bem, mas quando vou abrir um projeto NOVO, para poder criar um novo código, ele puxa o código desse meu primeiro programinha.
Claro que eu posso apagar esse código e digitar o novo, mas o projeto vem sem todas as using (o projeto vem só com a using.system).
Answer: Sim, ele tem gabaritos (templates) com um início bem básico de código que provavelmente você vai precisar de acordo com o tipo de projeto escolhido. Assim você não precisa digitar o que vai precisar de qualquer jeito. Alguns tipos de projetos chegam criar vários arquivos e até mesmo códigos que podemos classificar como "complexos" para um início. Não é seu primeiro programa, é o gabarito.
É possível inclusive criar seus próprios gabaritos ou modificar os existentes.
Comment: Entendi. Obrigado pela resposta, esclareceu minha dúvida. Como estou aprendendo sozinho, tenho estas dúvidas "idiotas". Abrçs!
Comment: @HenriqueScharfPisa Nenhuma dúvida é idiota se ela é legítima. Veja no [tour] a melhor forma de dizer obrigado aqui ;)


Encontre a primeira linha na matriz com todos os elementos positivos, e a soma desses elementos. Reduzir todos os elementos para essa soma

Question: Encontre a primeira linha na matriz com todos os elementos positivos, e a soma desses elementos. Reduzir todos os elementos para essa soma.
Aqui é a minha tentativa, mas desta forma somar os elementos positivos:
matrix = [[-5, -6, 2], [7, 2, 3], [8, 4, -9]]

summ = 0
for i in range(len(matrix)):
    pos = False
    for j in range(len(matrix[i])):
        if matrix[i][j] > 0:
            pos = True
            summ += matrix[i][j]

if pos:
    for i in range(len(matrix)):
        for j in range(len(matrix[i])):
            matrix[i][j] = summ
    print("Sum of the row with all positive elements: ", summ)
    for i in matrix:
        print(" ",i)

else:
    print("There is not a row with all positive elements.")

Comment: Não entendi bem qual a sua dúvida, poderia escrever com suas palavras? Qual erro está dando no seu código?
Comment: Downvote porque é dever de casa.
Answer: Isso resolve?
sum = 0;
pos = False;

for i in range(len(matrix)):
    for j in range(len(matrix[i])):
        if matrix[i][j] > 0:
           pos = True;
           sum+=matrix[i][j];
        else
           pos = False;
           sum = 0;
           break;
    if pos:
       break;

if pos:
    for i in range(len(matrix)):
        for j in range(len(matrix[i])):
            matrix[i][j] = sum;
    print('Sum of the row with all positive elements: ',sum);
    for i in matrix:
        print(' ',i);
else:
  print("There is not a row with all positive elements.");

Answer: >>> matrix = [[-5, -6, 2], [7, 2, 3], [8, 4, -9]]
>>> matrix
[[-5, -6, 2], [7, 2, 3], [8, 4, -9]]
>>> for line in matrix:
...  if not [i for i in line if i<0]:
...   soma = sum(line)
...   print 'Soma:',soma
...   print 'Linha:',line
...   matrix = [[soma for i in l] for l in matrix]
...   break
...
Soma: 12
Linha: [7, 2, 3]
>>> matrix
[[12, 12, 12], [12, 12, 12], [12, 12, 12]]


Why resample by centering vs. the sample estimate, not null parameter value?

Question: In a classic paper on conducting bootstrapped hypothesis tests, Hall & Wilson (1991) present the following guideline, which I am trying to understand:

On first read, this seemed obvious: $\widehat{\theta}^{*}$ are being resampled under $H_0$, so are consistent for $\theta_0$, whereas $\widehat{\theta}$ is consistent for $\theta$. Thus, $\widehat{\theta}^{*} - \widehat{\theta}$ is consistent for $\theta_0 - \theta$, which makes sense. In contrast, $\widehat{\theta}^{*} - \theta_0$ is consistent for $\theta_0 - \theta_0 = 0$, which is not useful.
But then I realized, on rereading the paragraph above the First Guideline and a subsequent example, that Hall & Wilson are computing $\widehat{\theta}^{*}$ by resampling directly from the sample, rather than under the null. In that case, I have no idea why they recommend resampling $\widehat{\theta}^{*} - \widehat{\theta}$, which is consistent for 0!
References
Hall, P., & Wilson, S. R. (1991). Two guidelines for bootstrap hypothesis testing. Biometrics, 757-762.
Answer: The idea is that irrespective of the choice of $\theta_0$, the bootstrap distribution of $\widehat\theta^*$ - $\widehat\theta$ resembles the sampling distribution of $\widehat\theta$ - $\theta$.  If you instead use $\theta_0$ you will be pulling the estimate closer to $\theta_0$ and thus lose power under the alternative. I think this is essentially what Hall and Wilson are saying but possibly a little simpler and hopefully clearer for you.
Comment: That sounds like a reasonable statement to me.
Comment: Interesting. (As an aside, your textbook on bootstrapping is wonderful -- thank you!)
Comment: Thanks -- I think I understand. Is it correct to say that this algorithm allows us to conduct a hypothesis test under $H_0$ while avoiding the difficulties of resampling under $H_0$ (because we're just resampling from the original)?
Comment: Thanks for the compliment.  I briefly discuss the Hall-Wilson paper in my book.  You may also like to look at Peter Hall's book which also covers this hypothesis testing issue.


how to check whether selected dates contains from calendar contains date less than todays date

Question: I need to check if selected dates(multiple) from calendar control contains any single date which is already passed or less than today.
How is it possible in c# wpf application.
Comment: mvvm environment or simple environment ?
Comment: Can you show your code for how you are storing the selected dates from the calendar control?
Comment: I am selecting multiple dates from calendar at time in UI using mouse. so i need get all that dates and compare every single date with todays date.
Comment: I am using simple environment
Answer: try below code
SelectedDatesCollection selectedDatesCollection = myCalendar.SelectedDates;

if (selectedDatesCollection.Count > 0)
{
    if (selectedDatesCollection.Any(x => x < new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)))
        MessageBox.Show("passed or less than today");
    else
        MessageBox.Show("today or future date");
}

Comment: Wow... Its awesome. short n simple.
Answer: private void CreateDynamicCalendar()  {
Calendar MonthlyCalendar = new Calendar();
MonthlyCalendar.Name = "MonthlyCalendar";
MonthlyCalendar.Width = 300;
MonthlyCalendar.Height = 400;
MonthlyCalendar.Background = Brushes.LightBlue;
MonthlyCalendar.DisplayMode = CalendarMode.Month;
MonthlyCalendar.SelectionMode = CalendarSelectionMode.MultipleRange;
MonthlyCalendar.DisplayDateStart = new DateTime(2010, 3, 1);
MonthlyCalendar.DisplayDateEnd = new DateTime(2010, 3, 31);
MonthlyCalendar.SelectedDates.Add(new DateTime(2010, 3, 5));
MonthlyCalendar.SelectedDates.Add(new DateTime(2010, 3, 15));
MonthlyCalendar.SelectedDates.Add(new DateTime(2010, 3, 25));  /*You Can Check all selected dates here with respect to current date*/

MonthlyCalendar.FirstDayOfWeek = DayOfWeek.Monday;
MonthlyCalendar.IsTodayHighlighted = true;

LayoutRoot.Children.Add(MonthlyCalendar);  }

You can follow this link for WPF Calender Tutorial
http://www.c-sharpcorner.com/UploadFile/mahesh/wpf-calendar-control/


P-values too low to plot

Question: In my GWAS analysis, I got some very low p-values (I have a very large dataset), below E-600. R Studio is not able to plot the values below E-300.
Do you have any suggestions on how to plot these, and if there is some software that could do it?
Comment: Hi @A29, welcome to CV. E-600 is effectively 0. So you might as well set them to zero to plot them.
Comment: I think it'd be a challenge to show that anyone's understanding of a topic will be furthered by knowing whether p is E-30 or E-300.
Comment: Better than p-values might be the use of so-called "S-values," which are the (binary) logarithms of the p-values.  It's unclear how R Studio might be used to plot anything (presumably you refer to `R` or an addon graphics package) and even less clear why it might fail to plot tiny values: please provide some details so we can understand what's going wrong and what you need to achieve.
Answer: Library gap has a function mhtplot.trunc that seems to be made for extremely low p values.

The rationale of this function is to extend mhtplot() to handle extremely small p values as often seen from a protein GWAS. Optionally, the function also draws an ordinary Manhattan plot.

P-values too low to plot


Como executar um loop até as linhas de um determinado arquivo.txt acabar

Question: Gostaria de fazer um sisteminha basico com loop por exemplo, abria o arquivo que o usuario digitou depois usava um if para enquanto tiver linhas no arquivo executar um loop com outros codigos
Comment: Na verdade, desde muitas versões atrás, qunado arquivos passaram a ser iteráveis diretametne, usar o `readlines` deixou de ser uma boa idéia:
http://stupidpythonideas.blogspot.com.br/2013/06/readlines-considered-silly.html.

Se quiser uma lista com todas as linhas do arquivo, é possivel passar o arquivo direto para o construtor da lista:   `linhas = list(open("meuarq.txt"))` - sem o readlines,
Comment: Pesquise pelo método `readlines` no Python.
Comment: certo vou da uma olhada.
Answer: Em Python, o próprio objeto que representa um arquivo aberto é feito para funcionar direto com um loop como você fala.
Por exemplo, um programa para imprimir cada linha de um arquivo é simplesmente:
nome = input("Digite o nome do arquivo: ")
with open(nome) as arq:
    for linha in arq:
        print(linha)

Em outras palavras: você usa o arquivo direto no comando for do Python - quando o arquivo acabar ele sai do for. (E nesse caso, como temos o with, ele saí do with também e já fecha o arquivo).
Isso acontece simplesmente por que o objeto arquivo implementa o "iterator protocol" - com os métodos __iter__ e  __next__. Qualquer objeto que tenha esses métodos (implementdos da forma correta) pode funcionar direto no comando for.
Answer: Eu não gosto de pedir interactivamente nomes de ficheiros;
prefiro a criação de scripts que recebem parâmetros via linha
de comando. Nesso sentido recomendo o módulo fileinput:
#!/usr/bin/python
# -*- coding=utf-8 -*-

import fileinput
for linha in fileinput.input():
   linha=linha.strip()
   #processa linha

Deste modo a script funciona como um comando normal Unix, e na linha de
comando podemos dar zero (stdin, pipes) ou mais ficheiros a processar.
Ver também as sempre úteis funções fileinput.filename() close() isfirstline() lineno() filelineno() nextfile()
Comment: Gostei!, e um bom módulo irei usar