Chi-Square Difference Test for Nested Models with a Continuous Outcome

Question: Apologies if this is a very basic question - I'm still definitely a beginner when it comes to statistical tests. I understand that chi-square tests are conducted to determine the relationship between two categorical variables or to determine how well a categorical outcome fits a discrete probability distribution.
However, I often come across articles using a chi-square difference test to compare the fit of nested models, even when the outcome is continuous. I'm struggling to understand this a little - how can we calculate a chi-square value for two models to then test if the difference between them is significant if the DV/outcome is continuous?
Answer: Chi-square is a distribution, not a test. Chi-square tests are used for things that are chi-square distributed. There are two different things they are used for:

The chi-square test of a contingency table (which is what you're thinking of, when you say they are to determine the relationship between two categorical variables).
Likelihood ratio tests are often also called chi-square tests, because the difference in (-2 *) loglikelihood of two models is chi-square distributed. If I fit a model, and then I add a parameter, I might ask if that parameter significantly improved the models. I can compare the likelihood ratios of the two models because this difference is chi-square distributed.

(Although the first is actually a type of the second.)
Answer: The term 'chi-squared test' tends to be applied to almost any test that has a test statistic whose distribution under $H_0$ is (at least approximately) distributed as chi-squared. Something similar happens with the term 'z-test'.
There are perhaps dozens of different tests with this property.
The chi-squared distribution occurs when you sum squares of independent standard normal random variables.
More generally (to get mildly technical - while dodging still further technicalities), the chi-squared distribution arises from the quadratic term in the exponent of a multivariate normal. That is, if $\underline{X}\sim N_p(\underline{\mu},\Sigma)$ then $(\underline{x}-\underline{\mu})^\top \Sigma^{-1}(\underline{x}-\underline{\mu})$ has a $\chi^2_p$ distribution, and if there are linear restrictions on the $\underline{X}$ the chi-squared distribution will lose 1 degree of freedom for each such restriction.
The chi-squared tests you mention (goodness of fit and test of independence) are based on a (degenerate) multivariate normal approximation to a multinomial distribution of counts, given marginal total(s), in just this sense.
There are a variety of other tests that use chi-squared distributions for the test statistic under $H_0$, many involving continuous models. Here's a few examples of ways that chi-squared tests may arise:

the distribution of sample variance under simple random sampling of a normal population is a (scaled) chi-squared. So a one-sample variance test may be a chi-squared test.

the distribution of sums of squares of residuals from a (correct) Gaussian model with known $\sigma$ is a multiple of a chi-squared.

the distribution of minus twice the log of the likelihood ratio in a likelihood ratio test is asymptotically chi-squared (Wilks' theorem) -- indeed there are a number of tests of nested models that result in chi-squared distributions (for some models these will be exact, for others asymptotic); this includes Wald tests and Lagrange multiplier (/score) tests.

The case you mention doesn't specify whether we're dealing with an assumption of normality or not. It might be an 'exact' small sample test or it might be an asymptotic test.


VMWare Server 2.0 Physical disks

Question: I have a machine setup with VMWare Server 2.0.   There are several VMs running on the VMWare server and I have several physical drives.  I would like to give one of the VMs exclusive access to one entire physical drive.  Is it possible to essential give a physical drive to one of the VMs and let it access it as if it were actual hardware?
Answer: There's a similar question asked here.
I couldn't get it to work in my configuration, and I ended up deploying on Hyper-V for that very reason. Hyper-V does support physical disk access. VMWare workstation supports physical disk access AFAIK however.
Comment: The linked answers are correct.  VMware Server 2.0 does not support RDM (raw disk mappings).  I have kept my server that uses RDM on VMware Server 1.x for this reason.  People seem to be having similar difficulties with ESXi.  As I move forward with my own workings, I'm more and more inclined to configure a storage server using OpenFiler and then passing whatever disks I want to VMware Server/ESXi over iSCSI giving me the most flexibility in dealing with disks and how I want to manage them.
Comment: The closest that you can get with VMWare Server 2.0 is to format the drive as a single partition, mount it, add it as a storage volume, and create the VM using fixed (pre-allocated) disk(s) nearly filling the volume (leave some room for temporary files maintained by VMWare including RAM imaged for suspending and any snapshot you might want to create now or later). This will not perform quite as fast as raw disk access would, however.
Answer: I suppose creating a virtual machine without a hard disk and than using VMX Builder to create a vmdk linked to the physical disk will work. Haven't tested it yet though

VMWare Server 2.0 Physical disks


How should I approach or shouldn't unit test?

Question: I have a huge codebase written by someone else its not unit tested at all. I want to add unit testing to a spring application.but the code is very much of decoupled and some times the code is not testable. how should I approach this should I start with the low level objects or the high level once and can you give me a step by step example of how to write unit tests for a spring application.
Comment: Decoupled code is easier to test, not harder. Too broad and unclear what you're asking.
Comment: I want to test a spring class which has some autowired dependencies and those also have some autowired in them some dependencies uses database while others uses config files how should I test and mock these classes.
Answer: You can easily transform @Autowired attributes into @Autowired constructors. Check this example:
@Component
public class SomeClass {
    @Autowired
    private SomeDependency someDependency;

    public ... doSomething(...) {
        ...
    }
}

can be transformed to
@Component
public class SomeClass {

    private SomeDependency someDependency;

    @Autowired
    public SomeClass(SomeDependency someDependency) {
        this.someDependency = someDependency;
    }

    public ... doSomething(...) {
        ...
    }
}

In fact, this injection method is preferred since your object has all the dependencies it needs when the constructor finishes. In the first approach you would need to do something like:
SomeClass someClass = new SomeClass();
someClass.setSomeDependency(someDependency); // <- you would need to add this

Also this could happen!
SomeClass someClass = new SomeClass();
someClass.methodThatUsesSomeDependency(); // <- NullPointerException since someDependency is not initialized!

So, by using constructor injection you are safe! You could also add a bit of extra safety by setting your dependencies as final so they must be initialized when the constructor ends:
@Component
public class SomeClass {

    private final SomeDependency someDependency;

    @Autowired
    public SomeClass(SomeDependency someDependency) {
        // Removing this line will cause a compile time error
        this.someDependency = someDependency;
    }

    public ... doSomething(...) {
        ...
    }
}

So, summing up: move your @Autowired annotation to a constructor and everything will go fine.
Once you have a constructor with its dependencies as arguments unit testing it should be trivial
Answer: You may refer to the Integration Testing provided by Spring
Here below is an example JUnit test class that provides test cases on beans in Spring Context.
@ContextConfiguration(locations = { "/your-spring-cfg.xml" })
public class YourTest extends AbstractJUnit4SpringContextTests
{
    @Autowired
    private YourBean beanToTest;

    @Test
    public void testYourBean()
    {
        beanToTest.method();
        ....
    }
}

EDIT
For configuration classes, you may refer to the following code.
@ContextConfiguration(classes=YourConfigClass.class, loader=AnnotationConfigContextLoader.class)
public class YourTest extends AbstractJUnit4SpringContextTests
{
    @Autowired
    private YourBean beanToTest;

    @Test
    public void testYourBean()
    {
        beanToTest.method();
        ....
    }
}

Comment: Yes, the project I'm working with is still using xml configuration and compose unit test classes like what I answered. BTW, you may refer to [link](http://spring.io/blog/2011/06/21/spring-3-1-m2-testing-with-configuration-classes-and-profiles/) if you are using configuration classes.
Comment: One question here do you use xml configuration in real world project.?


A Notation in Matsumura's Commutative Algebra

Question:
Let $A$ is a ring and $P$ is a prime ideal in $A$. What is the meaning of writing $PA_P$?

This object appears in the proof of Item (7.D) of Chapter 3 in Matsumura's Commutative Algebra.
I understand that $A_P$ denotes the localization of $A$ using the multiplicative set $A\setminus P$.
By writing $PA_P$ do we mean
$$\{(pa)/s:\ p\in P, a\in A, s\in R\setminus P\}$$
which is same as the ideal generated by the extension of $P$ in $A_P$?
Is this correct?
Comment: You don't need $pa$ above, since $pa\in P$. The last sentence is correct.
Answer: Your interpretation is correct: $PA_P$ denotes the unique maximal ideal of $A_P$, i.e. the extension of $P$ to $A_P$ via the canonical morphism $A \to A_P$.
Do note that you can slightly simplify the definition as a set, though, because $pa \in P$ for every $p \in P$ and $a \in A$:
$$
PA_P = \left\{\frac{p}{s} \in A_P : p \in P \,\text{ and }\, s \in A \setminus P\right\}
$$


iOS - Handle Internet Disconnection, Firebase

Question: I am developing an iPhone app that uses Firebase to retrieve data into a table, I have two questions:
1)I tested my app with no internet and it doesn't crash, but I want to display a message to the user saying that there's no internet and they have to connect to the internet to see the table content.
2)I plan to submit this app to the AppStore, what advice do you have for managing Firebase data query in order for Apple to approve it?
Best,
Anas
Comment: you want to check internet connection then it is already answered . check this http://stackoverflow.com/a/34128493/3400991
Comment: hopefully you are still in SO and see this, your questions make me wonder what limits apple has set for firebase query that you were worried about being rejected?
Answer: This question was answered here.
If you want to learn more about Detecting Connection State, have a look at the Firebase docs, also to get the code for the lastest version of swift.


How can you make a public folder in Exchange system manager

Question: I have exchange 2003 and wondering how do i create a public folder in the exchange system manager?
Answer: In ESM expand the Administrative Group, expand Folders, right click Public Folders and select New... Public Folder.
You can also create new PF's from Outlook if you have the proper permissions.


What is the derived algebra of $\mathfrak{sl}(n,\mathbb C)$?

Question: I believe that the derived algebra of gl(n,C) =[gln(C),gln(C)]=[sln(C),Sln(C)]=Sln(C) but what is the derived algebra of Sln(C)? Is it just [sln(c),Sln(C)].
Answer: Since $\mathfrak{sl}(n,\mathbb C)$ is a simple Lie algebra and its derived algebra is an ideal which is not $\{0\}$, $\bigl[\mathfrak{sl}(n,\mathbb C),\mathfrak{sl}(n,\mathbb C)\bigr]=\mathfrak{sl}(n,\mathbb C)$.
Comment: Thank you very much for the help.
Answer: Another response not using the fact of simlicity of $\mathfrak{sl}(n,\mathbb{C})$.
I will prove it for $\mathfrak{sl}(2,\mathbb{C})$ and the same thing for $\mathfrak{sl}(n,\mathbb{C})$ .
If we considere $(e,f,h)$ is the basis of $\mathfrak{sl}(2,\mathbb{C})$ as $[e,f]=h,[h,e]=2e,[h,f]=-2f$.
In one hand: $\forall x,y\in \mathfrak{sl}(2,\mathbb{C}), [x,y]\in   \mathfrak{sl}(2,\mathbb{C})$ by the definition of the brakets, i.e. $[\mathfrak{sl}(2,\mathbb{C}),\mathfrak{sl}(2,\mathbb{C})]\subseteq \mathfrak{sl}(2,\mathbb{C})$.
In the other hand, $e=[h,\frac{1}{2}e]\in [\mathfrak{sl}(2,\mathbb{C}),\mathfrak{sl}(2,\mathbb{C})], f=[h,\frac{-1}{2}f]\in [\mathfrak{sl}(2,\mathbb{C}),\mathfrak{sl}(2,\mathbb{C})]$ and $h=[e,f]\in [\mathfrak{sl}(2,\mathbb{C}),\mathfrak{sl}(2,\mathbb{C})]$.
Recall that $(h,e,f)$ is the basis, hence  $\mathfrak{sl}(2,\mathbb{C})\subseteq[\mathfrak{sl}(2,\mathbb{C}),\mathfrak{sl}(2,\mathbb{C})]$.
As conculsion: $\mathfrak{sl}(2,\mathbb{C}) = [\mathfrak{sl}(2,\mathbb{C}),\mathfrak{sl}(2,\mathbb{C})]$.
Comment: For the first inclusion you did not need to choose any basis, it always holds by definition. --- You claim you also show it for general $n$, I do not see that proof?


keytool how to use the keyUsage with -ext

Question: I am trying to create a certificate with the keytool utility.
i need some information on keyUsage, i have seen the javadoc.
however i am not able to understand the the difference between various key usage like :

what is digitalSignature and when it should be used.
what is the difference between keyCertSign and cRLSign and which one to use when?
Answer:
Ad 1. The key will be used to create digital signatures of data.
Ad 2. Key will be used to Sign Certificates and Certificate Revocation List

If you just want to create a simple certificate you do not need to define its usage.


tuneRF and stepFactor problems

Question: I feel uncomfortable with the meaning of stepFactor parameter of tuneRF function which is used for tuning the mtry parameter used futher in randomforest function (R program).
The documentation of the tuneRf function says that stepFactor is a magnitude by which the chosen mtry gets deflated or inflated. Obviously, sisnce mtry is a number of variables chosen randomly, it has to be intetger, however I saw many examples on the net using stepFactor=1.5. At first I thought that R uses by deflault next mtry equal to floor(mtry_current-stepFactor), but it turned out that not at all was I right. Moreover I do not understand the R commands displaying search left... search right... while tuneRF function is working. I thought it was the information on either inflating or deflating the mtry parameter, but my suppositions did not turn out to be correct.
To sum up this long and not too graceful description of my doubts, my questions are:

Why is stepFactor NOT an integer number?
How are subsequent mtry values chosen?
What does searching left/right actually mean?
Comment: not clear: mtry is not chosen randomly, it is mtry=if (!is.null(y) && !is.factor(y))
max(floor(ncol(x)/3), 1) else floor(sqrt(ncol(x))
Answer: Awful argument! It seems that at each iteration mtryStart gets multiplied by stepFactor. Greater help from a simple cycle where mtryis increased by 1.
set.seed(1)
tuning<-vector(length =(ncol(iris)-1))
for (i in 1:(ncol(iris)-1)) {
    irisRF<-randomForest(x=iris[,-5],mtry = i,iris$Species, ntree = 100);
    tuning[i]<-irisRF$err.rate[100,1];
}

plot(x=1:(ncol(iris)-1), y=tuning, ylab="OOBError", xlab="mtry value", type='b')

tuneRF and stepFactor problems


why can't I copy and paste

Question: I have written this code in js to validate my text in an html input field.  It works great except that I can't copy/paste anything into the textbox.  How can I modify this to allow copy/pasting while not losing the validation functionality?  Or is there a better way to validate a textbox?
function checkText(e)
{
    var ok = /[a-z A-Z]/.test(String.fromCharCode(e.charCode));
    if (!ok)
        e.preventDefault();
}

Comment: How is this function linked to the input element?  `onchange`?  or one of the key events?
Comment: When you paste, there's no `e.charCode`. That only exists in keyboard events.
Comment: Does this answer help? https://stackoverflow.com/a/44558661
Comment: I am calling this with "onkeypress"
Answer: As it's been mentioned in the comments, the paste event does not have the charcode property. You can try the following to handle both events:
function checkText(e)
{
   var str = String.fromCharCode(e.charCode) || (event.clipboardData || window.clipboardData).getData('text')
   var ok = /[a-z A-Z]/.test(str);
   if (!ok)
     e.preventDefault();
}

So you handle both the keyboard and the paste events. The paste event will have to be only one char though.
Answer: try it:

function checkInput(elem){
  let newValue = elem.value.split("").filter(chr => /[a-z A-Z]/.test(chr)).join("")
  elem.value = newValue;
}
<input onInput="checkInput(this);">
Comment: @user2236794 so please mark it as the correct answer.
Answer: it turns out my problem was that somewhere in my code, there was code like this:
document.body.onpaste = (e) => {
   e.preventDefault();
}

preventDefault() prevents normal paste operations.
i rewrote this line to only prevent default on a specific element that needed it (instead of the entire body), and then i was able to paste into my textboxes again

why can't I copy and paste


Hard pain for recover crease

Question: I am have much of the time on the RECOVERY crease/s in game of friendly CRICKET
How is best line for pick up of new PITCH ?
I am have much problem in back where speed has very low possible
I am strained, therefore I have no hand for low recovery
thanks,
PRASHANT :)
Comment: I realise English isn't your first language, but is there any chance you can clarify what you mean - what are you trying to do?
Comment: @PRASHANTP it is still very hard to understand what you are trying to say. Hop on Chat and we can see if we can work it out.
Answer: I have read over TalkCricket's description of cricket. And from what I can interpret from your question, you are spending most of your time in recovery. You want to know what the best line for the pickup of a new pitch, and you have pain in your back that prevents you from throwing the ball quickly, and you have no hand to use for low recovery.
From this description, it is very hard to tell what is being asked. Since we cannot read your mind and do now know what you are asking, it is difficult to answer the question.
I suggest you visit some of the cricket strategy websites, such as PitchVision, MyCricketGame, and Dangermouse. Once you have figured out what you are looking for, Google is your friend. Sports Stack Exchange can also help you, but the members need to know what is being asked first. Look at the links provided and try to determine what the question is, and then edit your question to make it more specific.

Hard pain for recover crease


What to do AFTER nested cross-validation?

Question: I've searched exhaustively on this forum and elsewhere, and have come across a lot of great material. However, I'm ultimately still confused. Here's a basic, concrete example of what I'd like to accomplish, my approach for doing so, and my questions.
I have a dataset sized 1000 x 51; 1000 observations, each with 50 numeric features and 1 binary response variable marked with either "0" or "1". "0" indicates a response of "not-early," and "1" indicates a response of "early." I'd like to build a single LASSO logistic regression model to predict, on a testing set that does not include response variables, whether each testing observations result in a classification of 0 or 1.
My approach uses the following steps:

Partition the training data into k = 5 folds, each containing 200 observations. Let's label each fold data_1, data_2, data_3, data_4, data_5.
For k = 1, our train_set_k is comprised of data_1, data_2, data_3, and data_4, and will contain 800 observations. Our test_set_k is comprised of data_5, and will contain 200 observations.
For k = 2, our train_set_k is comprised of data_1, data_2, data_3, and data_5. Our test_set_k is comprised of data_4.
Etc.
For k = 1 to 5, partition train_set_k into k_i = 5 folds, each containing 800/5 = 160 observations. Cross-validate on these k_i = 5 folds to find the optimal setting for the hyper-parameter lambda for our LASSO logistic regression model. Lambda should be a floating point number between 0 and 1.
Question #1: I'm unclear as to what "cross-validate to find the optimal setting for the hyper-parameter lambda" actually entails. In R, I'm using the following code:
model.one.early <- cv.glmnet(x.early, y.early, family = "binomial", nfolds=5,
                             type.measure="auc")

..where nfolds = 5 pertains to the k_i = 5 above. In other words, each of the nfolds = 5 folds will contain 160 observations.
From this code, I'm able to output values for: "lambda.min" - the value of lambda that gives the minimum mean cross-validated error, which I assume to mean "gives the maximum mean cross-validated AUC," as I specified type.measure = "auc" above; "lambda.1se" - the largest value of lambda such that error is within 1 standard error of the minimum."
Question #2: What is the above line of code actually doing? How does it compute values of lambda.min and lambda.1se?
Question #3: Which value of lambda (lambda.min or lambda.1se) do I want to keep? Why?
Fit a LASSO logistic regression model to the 800 observations in this fold using hyper-parameter lambda.min (or lambda.1se) as obtained above. Use this model to predict on the remaining 200 observations, using a piece of code like this:
early.preds <- data.frame(predict(model.one.early, newx=as.matrix(test.early.df),
                          type="response", s="lambda.min"))

Compute an AUC for these predictions.
Once the above loop finishes, I should have a list of k = 5 lambda.min (or lambda.1se) values, and a list of 5 corresponding AUC values. To my understanding, by taking an average of these k = 5 AUC values, we can obtain an "estimation of the generalisation performance for our method of generating our model." (-Dikran Marsupial, linked here)
This is where I'm confused. What do I do next? Again, I'd like to make predictions on a separate, un-labeled testing set. From what I've read, I must ultimately fit my LASSO logistic regression model with all available training data, using some code like this:
final_model <- glmnet(x=train_data_ALL, y=data_responses, family="binomial")

Question #4: Is this correct? Do I indeed fit one single model on ALL of my training data?
Then, I'd simply using this model to predict on my testing set, using some code like this:
finals_preds <- predict(final_model, newx=test_data_ALL, type="response",
                        lambda=?)

In my nested cross-validation employed in steps 1 through 5, I've obtained a list of 5 values of lambda and 5 corresponding AUC values.
Question #5: Which value of lambda do I choose? Do I select the value of lambda that gave the highest AUC? Do I average the k = 5 values of lambda, and then plug this average into the above line of code for lambda = ?.
Question #6: In the end, I just want one LASSO logistic regression model, with one unique value for each hyper-parameter ... correct?
Question #7: If the answer to Question #5 is yes, how do we obtain an estimate for the AUC value that this model will produce? Is this estimate equivalent to the average of the k = 5 AUC values obtain in Step 5?
Answer: To answer your initial question (What to do AFTER Nested Cross-Validation?):
Nested cross-validation gives you several scores based on test data that the algorithm has not yet seen. Ordinary CV ("non-nested") gives you just one such score based on one held-out test set. So you can better evaluate the true performance of your model.
After nested CV you fit the chosen model on the whole dataset. And then you use the model to make predictions on new, unlabeled data (that are not part of your 1000 obs.).
I'm not 100% sure that you perform proper nested CV with an outer and an inner loop. To understand nested CV, I found this description helpful:

(Petersohn, Temporal Video Segmentation, Vogt Verlag, 2010, p. 34)
Thoughts on bootstrapping as a better alternative than (nested) CV can be found here.
P.S.: I presume that you will more likely get answers if you only ask 1 or 2 questions instead of 7 in one post. Maybe you want to split them up so that others can find them more easily.
Comment: Thanks a lot for a great answer tobip. The above question was definitely posed during my "brain-scramble to understand basic model validation topics." Fortunately, it's all straightened out at this point. Will do my best to stick to fewer questions next time.
Comment: This is a great answer, but I still have one related question. What if the parameter set p giving the minimum test error (i.e. etilda_cv in step 10 in algorithm) is not the same in each iteration of the outer cross-validation? In this case, the outer CV test error e_cv doesn't seem very meaningful as a performance statistic because it would average the error for different hyper-parameter settings. It seems to me that it would be better to choose the parameter set that most often gives the minimum etilda_cv [i.e. the mode of the set P := {arg min (etilda_cv_i)} where i indexes the iterations...
Comment: ...of outer cross-validation as in the algorithm above]. The outer CV test error could then be calculated as e_cv = (1/m) sum(e_m) from the set of test error values resulting from the same parameter set but different test sets.
Comment: It's unclear what this answer means by "chosen model". If it means something like "model with hyperparameters that gave the best outer performance", I don't think that is correct.
Answer:
Question #5: Which value of lambda [of all the λs returned for the different surrogate models] do I choose?

Obviously, if the λs are practically the same, there is no difficulty as there is essentially no choice involved.
If the λs you find for the different surrogate models bounce all over the place, you are in trouble: that is a symptom that either your sample size is too small to auto-tune λ based on your data set, or that the models are (still) very unstable. In both cases, IMHO you'd need to step back and think again about your modeling approach.
I encounter nearly only situations with extremely small sample sizes in my work. Therefore, I'd always decide for the hyperparameter that yields the least complex model (of any kind of regularization).
While your situation may be different, the fact that you use the LASSO indicates that there is a problem with model complexity, so I guess that would be a sensible approach for you as well.

Question #3: Which value of lambda (lambda.min or lambda.1se) do I want to keep?

The same reasoning about model complexity applies. I'd go for lambda.1se.

Question #6 [and #4]: In the end, I just want one LASSO logistic regression model, with one unique value for each hyper-parameter ... correct?

yes

Question #7: If the answer to Question #5 is yes, how do we obtain an estimate for the AUC value that this model will produce? Is this estimate equivalent to the average of the k = 5 AUC values obtain in Step 5?

No it is not the AUC from step 5. This is measured by the outer loop of the nested validation.
I think it is easiest to think of your model training as including the autotuning of λ. I.e. write a training function that does all that is necessary to auto-tune λ using e.g. [iterated] cross validation and then return a model trained on all data that is handed to the training function. Perform the usual resampling validation for these models.

Questions #1 and #2

... are best answered by reading the code: you work in R, so you can read the code and even work though it step by step. In addition, read up what the Elements of Statistical Learning say about hyperparameter tuning. AFAIK, that book is the origin of the 1SE idea for hyperparameter tuning.

Long anwer:
The key idea behind the lambda.1se is that the observed error is subject not only to bias but also to random error (variance). Just picking the lowest observed error risks "skimming" variance: the more models you test, the more likely is observing an accidentally good looking model. lambda.1se tries to guard against this.
There are (at least) 3 different sources of variance here:

finite test set variance: the actual composition of the finite test set for the surrogate model in question ("finite test set error")
model instability: the variance of the true performance of the surrogate models around the average performance of models of that training sample size for the given problem
variance of the given data set with respect to all possible data sets of size $n$ for the given problem.
This last type of variance is important if you want to compare e.g. algorithms, but less so if you want to estimate the performance you can achieve for the data set at hand.

The finite test set variance can be overwhelmingly large for small sample size problems. You can get an idea of the order of magnitude by modeling the testing procedure as a Bernoulli trial: you can know the size of this variance as it is tied to the observed performance. You could in principle construct confidence intervals around your observed performance using this, and decide to use the least complex model that cannot reliably be distinguished from the best performace observation you got. This is basically the idea behind lambda.1se.
Model instability causes additional variance (which by the way increases with increasing model complexity). But usually, one characteristic of a good model is that it is actually stable. Regarding the λ, stable models (and a data set that is large enough to do the estimation of λ reliably)
imply that always the same λ would be returned. The other way round, λs that vary a lot indicate that the optimization of λ was not successful.


Close Opened Hibernation sessions if exist

Question: When a Hibernate session is opened (sessionFactory.openSession()) it might be closed. It is ok. In case it is missed to close an opened session which is used to retrieve data (not to save or update or delete) any where in the application, how to close opened sessions if exists?
(Let's say when a JFrame is closed, if there are opened sessions available, they must be closed. Closing sessions can be done by going through the codes one by one, but I mean here, without checking codes, is there any way to close sessions which are missed to close with some piece of code).
Answer: Why dont you close the session when your database operation finished?
I mean, In DAO classes you get opened session perform database operation. And in finally block, Close your session.
You can close session like :
finally {
   if(session!=null){
      session.close();
   }
}

OR
You can get the current session using
Session sess = sessionFactory.getCurrentSession();

And close session on closing event of JFrame.
I get following lines from this link

The main contract here is the creation of Session instances. Usually
  an application has a single SessionFactory instance and threads
  servicing client requests obtain Session instances from this factory.
  The internal state of a SessionFactory is immutable. Once it is
  created this internal state is set. This internal state includes all
  of the metadata about Object/Relational Mapping.
  Implementors must be threadsafe.

And it is our duty to close session when finished the operation or transaction. When we close sessionfactory all resources(connection pools etc) are released properly.
Comment: Thank you very much for your answer.I mean, in case closing the session is forgotten as a mistake and when the application runs then more opened sessions exist and then memory wastage may occur. In such a case, how to close or see that there any session is opened?
Comment: `Session s=sessionFactory.openSession(); List list=s.createCritaria... .list();`  if this session 's' is forgotten to close.(there is no code: s.close(); )  lets say, this getting list is executed more times and then a new session is opened.Then every time above code is executed,a new session begins,but not closed.then more and more open sessions may exists.Finally it may a cause to be jvm memory overloaded.isn't it? I want to close opened sesseions if exist. Thank you for your attention
Comment: Thanks.I tried to close the session which is taken from `sessionFactory.getCurrentSession();`.then there was an exception saying no session open.But there was already opened a session which was not closed. I suppose we d better to go through our codes twice checking opened sessions.
Comment: can you give example of such scenario (I cant visualize)?
Comment: So Aash, I have edited above answer accordingly. As we have single Sessionfactory for application, we'll have all sessions associated with application and we can close them. I am not sure but I read and made conclusion.


How can i delete user profile picture in drupal 7?

Question: Is there a way that I can remove/delete user profile picture through programing? or How can i override existing image with my new one?
Comment: Is there a reason you can't use the UI? If you could explain more about what you're trying to accomplish that would be helpful
Comment: Yes because i have custom Layout for user profile page. for that I user my custom tpl file other than user--profile.tpl.php
Comment: have you investigated https://api.drupal.org/api/drupal/modules!user!user-picture.tpl.php/7 ?
Answer: use code below in hook_user_delete($account)
<code>// Load user by using user id
$user = user_load($uid);
// Get file id of profile photo
$fid = $user->picture->fid;
// Load the file object
$file = file_load($fid);
// delete profile photo from.
file_delete($file);
// Unset the image object (my case it's 'picture')
unset($user->picture);
// Save the user
user_save($user);
</code>


What is the maximum length that $.parseJSON() can handle?

Question: I have a long json array that needs to be sent to an html5 mobile app and parsed. The whole array has around 700kb (gziped to 150kb) and it's 554976 characters long at the moment. But it  will increase on time.
Using jquery to parse the json, my app crashes while trying to parse it. And so does jsonlint, json parser.fr and any other online json validator I try, so I'm guessing eval() is not an option either.
Might be a broad question but what is the maximum "acceptable" length for a json array?
I have already removed as much data as I can from the array, the only option I can think of is to split the array in 3-4 server calls and parse it separately in the app. Is there any other option?
EDIT
Thanks to @fabien for pointing that if jsonlint crashes there is a problem on the json. There was a hidden "space" character in one of the nodes. It was parsed correctly on the server but not on the client.
Comment: Do you really mean "crash" or more like "freeze" ?
Comment: `eval` would no doubt be faster and more memory efficient than `$.parseJSON`. Also have a look at `JSON.parse` (not fully cross browser)
Comment: http://stackoverflow.com/questions/9912642/max-recommended-size-of-external-json-object-in-javascript has a 20mb JSON string being parsed. Are you sure your JSON object is properly formed?
Comment: @Petah From jQuery 2 source `parseJSON: JSON.parse,`. jQuery 1.x uses it for all browsers which support it.
Comment: The json is properly formed as I can parse it on the server side. It just freezes on the client side. I get no errors, it just stops on the  parsing!
Comment: A [related](http://stackoverflow.com/questions/4605586/is-there-a-limit-on-size-of-json-object-that-can-be-processed-by-browsers) query on stack overflow. The accepted answer also contains the analysis and approach followed by the developer to parse large JSON strings. Hope this points you towards a solution
Answer: I've parsed way bigger arrays with jquery.
My first guess is that there's an error in your json.
You have many ways to find it (sublime text could highlight the error but some time, it's a bit long). Try to paste it in a web tool like http://www.jsoneditoronline.org/. and use any of the buttons (to format or to send to the right view). It'll tell you where the error is.
Comment: That's a good tool, it actually parsed the json correctly! If i try directly on jsonlint it freezes. Which seems a little bit weird to me.
Comment: can you show us the json ? If lint freeze, there's a problem with it :)
Comment: Unfortunately I can't. NDAs. Love them! But I found out the problem. There was a strange "empty space" character in one of the nodes. For some reason it was parsed correctly on c# but not on javascript. .net flagged it when i used a different parser! Great online tool btw! Thanks for sharing that!
Comment: This is because of the way jquery will parse it ; it won't escape the special characters, the spaces, the line breaks... If you are web based, you can proxy the datas by parsing it first with php / ruby (it will correct most of the errors) and then send it to your app.


add last user IP in view

Question: How to add last IP address for online user ( only last IP address ) and link to ban user IP address ?
i tried display all ip address but that showed to me all ip addresses from any time
i want show last ip address
Answer: Because it needs lots of coding and building a new module I only give you the tips and the algorithm, you need to know how to build a module.

build a module and create a variable (called IP) using drupal_get_variable, in this way a variable will be created in the `variable`` table.
for any user who visits your website, replace its IP address with the existing one (drupal_set_variable) in the IP variable (so far it is easy to implement).
you need output this variable in your view, so use the hook_views_prebuild ($view) hook function, get the IP and embed it in the view.

add last user IP in view


I dont get temp name of image upload using php,ajax

Question: I want to get the temp name of image upload using php and ajax.I got the file name of upolad image. But dont get the temp name of image upload.My code is given below
main.php
<form action=" " method="POST" enctype="multipart/form-data">

        File Upload
        <input type="file" name="file" id="file" size="150">

Only Excel/CSV File Import.

    <button type="button" class="btn btn-default"
            name="Import" value="Import" onclick="file_up()">
        Upload</button>
</form>

first_ajax.php
<?php
   echo $file1 = $_POST['file'];   // for get file name
   echo $file1 = $_POST['file']['tmp_name']; //for get temp name
?>

Comment: the fle will not be included since you only passed the string value of the input file.  use ajaxForm instead.  you can search it on google
Comment: maybe this can help -> http://stackoverflow.com/questions/17651073/get-files-temp-name-of-the-binary-file
Comment: Dont get temp name......
Answer: Use FormData to get $_FILES and $_POST array in AJAX file...
function file_up() {
 var formData = new FormData($('#form')[0]);
                    $.ajax({
                        url: 'first_ajax.php',
                        type: 'POST',
                        data: formData,
                        async: false,
                        success: function(data) {
                            $("#upload_show").html(msg);
                        },
                        cache: false,
                        contentType: false,
                        processData: false
                    });
                }

Answer: Instead of,
var file = $('#file').val();
try,
var file = $("#file").prop("files")[0];


Inverse hyperbolic sine transformation: estimation of theta

Question: I'm trying to use an inverse hyperbolic sine transformation to reduce the effect of outliers in my target variable. Unfortunately, I don't appear to have access to the basic papers on it. I've found the formulation but am not sure how to estimate the theta parameter for it. Does anyone know?
Thanks
Comment: A useful followup thread (which includes a more accurate description of the IHS that is valid for negative $z$ as well as positive $z$) is at http://stats.stackexchange.com/questions/157532.
Comment: Please clarify the question: what is theta? The inverse hyperbolic sine function is $asinh(z)=\log(z+\sqrt{z^2+1})$ - no theta in sight.
Answer: The basic idea is as follows,
You have the IHS transformation
$$z_j = g_j(y_j;\theta)= \operatorname{sinh}^{-1}(\theta y_j)/\theta,\,\,j=1,...,n.$$
Then you have to find the value of $\theta$ that maximises the concentrated log-likelihood
$$L(\theta) = -\dfrac{n}{2}\log[g(\theta)^TMg(\theta)] - \dfrac{1}{2}\sum_j\log(1+\theta^2 y_j^2),$$
where $g(\theta)=(g_1(y_1;\theta),...,g_n(y_n;\theta))$, $M = I - X(X^TX)^{-1}X^T,$ and $X$ is the matrix of explanatory variables.
I hope this helps.
Ref: Alternative Transformations to Handle Extreme Values of the Dependent Variable
Author(s): John B. Burbidge, Lonnie Magee, A. Leslie Robb
Source: Journal of the American Statistical Association, Vol. 83, No. 401 (Mar., 1988), pp. 123-127x
Comment: yeah this is what i was looking for thanks. i unfortunately don't have access to jstor. just to double check, that first term, its log absolute value correct?
Comment: No, it is a square bracket [], but the term inside the log is a quadratic form then it is always positive.
Comment: I have corrected the $sinh^{-1}$ instead of $sinh$.


Tricks for questions involving finding integer solutions for a fraction which contains variables

Question: I've come across several problems which involve finding a certain number of integers that the expression could be. For example, here is a question:
"There are exactly four integer values of a for which 2a+b/a-2 is itself an integer" - This is only  true for certain values of b only. For how many values of b in the range 1 ≤ b ≤ 20 is the statement true?
My thought process so far - I'm trying to work out when there will only be four values which a, and so far I cannot think of anything. I've also tried splitting the fraction but that hasn't worked either.
How would you:
a) tackle this problem
b) tackle similar problems in the future i.e. what can I take away from this problem that I could apply to another one down the line?
Comment: These types of problems involves divisibility. To start, rewrite $\dfrac{2a+b}{a-2} = m+\dfrac n{a-2}$, where $m,n$ are integers.
Comment: So, for m, I could have 2a-4/a-2 = 2. But what about for n?
Comment: $n=b+4$. Now think what must $b+4$ be for there only being $4$ values of $a - 2$ that can generate an integer.
Comment: That's where I'm stuck, unfortunately, @player3236
Comment: What numbers only have $4$ divisors, including positive and negative ones?
Comment: Positive numbers with two unique prime factors have four factor (but only positive). The cube of a prime has 4 (positive) factors. But the hint about positive and negative is the key! Prime numbers have 4 factors if positive and negative are counted. But how did you know to look for positive AND negative?
Comment: $a-2$ could be positive or negative.
Comment: @player3236 - so the answer is all primes from 1-20...right?
Comment: Not exactly; it is $b+4$ that must be prime.
Comment: I'm so sorry @player3236 - I'm now slightly confused again! - Would it be possible for you to write up a full solution please to explain? I can then tick that to thank you for your kind help!
Answer: We want to know when $\dfrac{2a+b}{a-2} = 2 + \dfrac{b+4}{a-2}$ is an integer.
This is equivalent to finding when $\dfrac{b+4}{a-2}$ is an integer.
Hence we need to know when $a-2$ is a factor of $b+4$.
Since the question ask for values of $b$ where there are exactly $4$ values of $a$ satisfying the condition, we need to find when $b+4$ has exactly $4$ factors.
Since both positive and negative factors are included, only primes can satisfy this condition (as you have observed). That is, we need to find values of $b$ such that $b+4$ is prime (but not $b$ itself).
Comment: Ahhh - I see now! Thanks @player3236!


Snapshot has data even if it not exist in Firestore

Question: I have this StreamBuilder:
<code> SizedBox(
                  height: 200,
                  child: StreamBuilder<QuerySnapshot>(
                    stream: FirebaseFirestore.instance
                        .collection('users')
                        .doc(uid)
                        .collection('favoritePets')
                        .snapshots(),
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        print(snapshot);
                        return ListView.builder(
                            itemCount: snapshot.data!.docs.length,
                            itemBuilder: (context, index) {
                              DocumentSnapshot doc = snapshot.data!.docs[index];
                              return Text(
                                doc['title'],
                              );
                            });
                      } else {
                        return Text(
                          "No data",
                        );
                      }
                    },
                  ),
                ),
</code>
If the collection does not exist in the Firestore because no items were added or all of the items are removed I got a blank page, instead of showing the "No data" text.
This gets printed no matter whether the collection exists or not:

AsyncSnapshot<QuerySnapshot<Object?>>(ConnectionState.active, Instance
of '_JsonQuerySnapshot', null, null)

How is it possible to get the "No data" text?
Comment: What about `snapshot.data!.docs.length`, is it not 0 in case the collection is empty or not existing?
Answer: You have to distinguish snapshot from non existance of the doc. If the doc doesn't exist the snapshot still has data! Non existance is also a data. To acomplish what you want you have to check !snapshot.exists and snapshot.hasData condition. Also you should check the hasError flag.
Hope I helped.


How to handle a day light saving issue properly in ASP.net?

Question: I have gone through many answers and articles but I havent got the better solution.
I have to set a reminder for daily, weekly or monthly from different regions.
Even if I convert the time into UTC also there will be issues when the region is prone to Daylight saving.
Comment: UTC doesn't have daylight saving time, store all your times in UTC and you won't have to do any conversions.
Comment: @DavidG: Except that doesn't work for repeated events. If you have a repeated event that occurs every Monday at 4pm in Los Angeles, then converting 4pm to UTC once doesn't help.
Comment: *"Even if I convert the time into UTC also there will be issues when the region is prone to Daylight saving"* That's not how UTC works...
Comment: Can you be more specific if you don't mind?
Comment: Well the *question* isn't specific. In particular "there will be issues" is far too vague. Your answer contains a `dateTimeStamp` with no explanation, and no obvious expectation of whether that's a daily, weekly, monthly value etc.
Comment: Basically, "do everything in UTC" is advice which is often given and only appropriate for certain situations.
Comment: @JonSkeet That's a fair point. Does Noda Time have a feature to help in this situation? :)
Comment: @DavidG: Well it makes *everything* easier, of course :) This is feasible with `DateTime`, but the code won't be as clear.
Answer: I have solved this problem by using this code.
We will get the TimeZoneInfo from TimezoneId
<code>var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(TimezoneId);
</code>
convert the DateTime into a timestamp
<code>   private DateTime ComputeNextUtcTimeToRun(long dateTimeStamp, TimeZoneInfo timeZoneInfo)
        {
            try
            {
                // Get the current time in the target time zone
                DateTime now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, timeZoneInfo);

                // Compute the next local time
                DateTime scheduledLocalTime = (new DateTime(1970, 1, 1, 0, 0, 0)).AddMilliseconds(dateTimeStamp).ToLocalTime();

                if (scheduledLocalTime < now)
                {
                    scheduledLocalTime = scheduledLocalTime.AddDays(1);
                }
                // If it's invalid, advance.  The clocks shifted forward!
                if (timeZoneInfo.IsInvalidTime(scheduledLocalTime))
                {
                    return TimeZoneInfo.ConvertTimeToUtc(scheduledLocalTime.AddHours(1), timeZoneInfo);
                }
                // If it's ambiguous, pick the first instance
                if (timeZoneInfo.IsAmbiguousTime(scheduledLocalTime))
                {
                    TimeSpan offset = timeZoneInfo.GetAmbiguousTimeOffsets(scheduledLocalTime).Max();
                    DateTimeOffset dto = new DateTimeOffset(scheduledLocalTime, offset);
                    return dto.UtcDateTime;
                }
                return TimeZoneInfo.ConvertTimeToUtc(DateTime.SpecifyKind(scheduledLocalTime, DateTimeKind.Unspecified), timeZoneInfo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
</code>
Please refer this link for more information
please correct me if it can be made better.
Comment: @CalC No it shouldn't, it's a self answer, not a problem here. The quality of the answer... a different question.
Comment: @CalC see [Can I answer my own question?](https://stackoverflow.com/help/self-answer) in the help section.
Comment: Thanks @DavidG. SO seems nuts sometimes. Is there a guide/meta on this?


Google Maps Android bad perfomance and screen map lagging when draw polyline

Question: I'm developing an application that fulfills the function of doing a route search, the user enters the point of origin and destination, after this through switch widget the user can draw the routes of the result.
The interface and the map are fluid, the problem occurs when 1 polyline is drawn.
I'm using asynctask to load the data of the coordinates of the routes and to draw them.
To get the coordinates I use Android Maps Utils to decode and simplify the polyline. Each polyline contains about 300 points and in total there are 40 polylines.
I also use a service to process the results of the search, it works well.
What else can I do to optimize this polyline load? I have researched but the results are similar to what I am already doing.
I look forward to your help!
Code:
MapDemoActivity.class
<code>public class MapDemoActivity extends AppCompatActivity
    implements
    GoogleMap.OnMyLocationButtonClickListener,
    GoogleMap.OnMyLocationClickListener {

private SupportMapFragment mapFragment;
public static GoogleMap map;
Location mCurrentLocation;
private final static String KEY_LOCATION = "location";
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;
protected static final String TAG = "LocationOnOff";
private GoogleApiClient googleApiClient;
final static int REQUEST_LOCATION = 199;
public static final String EXTRA_CIRCULAR_REVEAL_X = "EXTRA_CIRCULAR_REVEAL_X";
public static final String EXTRA_CIRCULAR_REVEAL_Y = "EXTRA_CIRCULAR_REVEAL_Y";
View rootLayout;
private int revealX;
private int revealY;
FloatingActionButton searchButton, checkButton, checkButtonDestino, reset;
ImageView markerOrigen;
private RoundedView mRoundedIndicatorOrigin;
private RoundedView mRoundedIndicatorDestination;
TextView source_location, destination_location;
String type = "";
Intent intentAnim = null;
private GoogleMap.OnCameraIdleListener onCameraIdleListener;
Marker source_location_marker, destination_location_marker;
double LatOrigen;
double LonOrigen;
double LatDestino;
double LonDestino;
private SlidingUpPanelLayout mLayout;
SlidingUpPanelLayout dragView;
ArrayList<Integer> validadorFinal = new ArrayList<Integer>();
ArrayList<Switch> listSwitch = new ArrayList<Switch>();
private static final PatternItem DOT = new Dot();
private static final int PATTERN_DASH_LENGTH_PX = 50;
private static final PatternItem DASH = new Dash(PATTERN_DASH_LENGTH_PX);
private static final int PATTERN_GAP_LENGTH_PX = 10;
private static final PatternItem GAP = new Gap(PATTERN_GAP_LENGTH_PX);
private static final List<PatternItem> PATTERN_POLYLINE_DOTTED = Arrays.asList(DASH, DOT, GAP);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_demo_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.arrow_left);

    LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(mMessageFilterResult, new IntentFilter("validador"));

    intentAnim = getIntent();

    rootLayout = findViewById(R.id.root_layout);
    if (savedInstanceState == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
            intentAnim.hasExtra(EXTRA_CIRCULAR_REVEAL_X) &&
            intentAnim.hasExtra(EXTRA_CIRCULAR_REVEAL_Y)) {
        startAnim();
    }

    if (TextUtils.isEmpty(getResources().getString(R.string.google_maps_api_key))) {
        throw new IllegalStateException("You forgot to supply a Google Maps API key");
    }

    mapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
    if (mapFragment != null) {
        mapFragment.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap map) {
                loadMap(map);
            }
        });
    } else {
        Toast.makeText(this, "Error - Map Fragment was null!!", Toast.LENGTH_SHORT).show();
    }

    initView();

}

protected void startAnim(){
    rootLayout.setVisibility(View.INVISIBLE);

    revealX = intentAnim.getIntExtra(EXTRA_CIRCULAR_REVEAL_X, 0);
    revealY = intentAnim.getIntExtra(EXTRA_CIRCULAR_REVEAL_Y, 0);

    ViewTreeObserver viewTreeObserver = rootLayout.getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                revealActivity(revealX, revealY);
                rootLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });

    } else {
        rootLayout.setVisibility(View.VISIBLE);
    }
}

public void initView(){
    searchButton = (FloatingActionButton)findViewById(R.id.fab);
    //dataResultView.setVisibility(View.VISIBLE);
    markerOrigen = (ImageView)findViewById(R.id.markerTarget);
    dragView = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
    checkButton = (FloatingActionButton)findViewById(R.id.fab2);
    checkButtonDestino = (FloatingActionButton)findViewById(R.id.fab3);

    reset = (FloatingActionButton) findViewById(R.id.reset);
    resetMap();

    mRoundedIndicatorOrigin = (RoundedView)findViewById(R.id.rounded_indicator_source);
    mRoundedIndicatorDestination = (RoundedView)findViewById(R.id.rounded_indicator_destination);

    source_location=(TextView) findViewById(R.id.source_location);
    source_location.setTag(0);
    destination_location=(TextView)findViewById(R.id.destination_location);
    destination_location.setTag(0);

    searchButton.setTag("1");
    searchOptions();

    mLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
    mLayout.setAnchorPoint(0.7f);
    //mLayout.setPanelState(SlidingUpPanelLayout.PanelState.ANCHORED);
    mLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {
        @Override
        public void onPanelSlide(View panel, float slideOffset) {
            Log.i(TAG, "onPanelSlide, offset " + slideOffset);
        }

        @Override
        public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
            Log.i(TAG, "onPanelStateChanged " + newState);
        }
    });
    mLayout.setFadeOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //mLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
            mLayout.setAnchorPoint(0.7f);
            mLayout.setPanelState(SlidingUpPanelLayout.PanelState.ANCHORED);
        }
    });
}

private void resetMap(){
    reset.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            map.clear();
            map.setOnCameraIdleListener(null);
            source_location.setText(null);
            destination_location.setText(null);
            mRoundedIndicatorOrigin.setChecked(false);
            mRoundedIndicatorDestination.setChecked(false);
            searchButton.setTag("1");
            type="";

            if (listSwitch.isEmpty()) {
                //Nothing
            }else {
                for (int i=0; i <= 79; i++) {
                    if (listSwitch.get(i).isChecked()) {
                        listSwitch.get(i).setChecked(false);
                    }
                }
            }

            searchButton.hide();
            checkButtonDestino.hide();
            checkButton.hide();
            reset.hide();
            dragView.setPanelHeight(0);
        }
    });
}

private void searchOptions() {
    source_location.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            configureCameraIdle();
            mRoundedIndicatorOrigin.setChecked(true);
            mRoundedIndicatorDestination.setChecked(false);
            map.setOnCameraIdleListener(onCameraIdleListener);

            checkButton.show();

            markerOrigen.setVisibility(View.VISIBLE);
        }
    });

    destination_location.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            configureCameraIdle2();
            mRoundedIndicatorOrigin.setChecked(false);
            mRoundedIndicatorDestination.setChecked(true);
            map.setOnCameraIdleListener(onCameraIdleListener);
            checkButtonDestino.show();

            markerOrigen.setVisibility(View.VISIBLE);
        }
    });

}

private void configureCameraIdle() {
    getDataCameraIdle();
    onCameraIdleListener = new GoogleMap.OnCameraIdleListener() {
        @Override
        public void onCameraIdle() {
          getDataCameraIdle();
        }
    };
}

private void getDataCameraIdle(){
    LatLng latLng = map.getCameraPosition().target;
    Location mLocation = new Location("");
    mLocation.setLatitude(latLng.latitude);
    mLocation.setLongitude(latLng.longitude);

    new AsyncGeocoder().execute(new AsyncGeocoderObject(
            new Geocoder(this),
            mLocation,
            source_location
    ));

    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title("Origen");

    checkButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            checkButton.setTag("1");
            map.setOnCameraIdleListener(null);
            //Log.d("TAG", "click checkbutton");
            if (source_location_marker!=null)
            {
                source_location_marker.remove();
            }
            LatOrigen = latLng.latitude;
            LonOrigen = latLng.longitude;
            source_location_marker=map.addMarker(markerOptions);
            markerOrigen.setVisibility(View.GONE);
            checkButton.hide();
            source_location.setTag(1);

            checkSearchButtonStatus();

        }
    });
}

private void configureCameraIdle2() {
    getDataCameraIdle2();
    onCameraIdleListener = new GoogleMap.OnCameraIdleListener() {
        @Override
        public void onCameraIdle() {
            getDataCameraIdle2();
        }
    };
}

private void getDataCameraIdle2(){
    LatLng latLng = map.getCameraPosition().target;
    Location mLocation = new Location("");
    mLocation.setLatitude(latLng.latitude);
    mLocation.setLongitude(latLng.longitude);

    new AsyncGeocoder().execute(new AsyncGeocoderObject(
            new Geocoder(this),
            mLocation,
            destination_location
    ));

    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title("Destino");

    checkButtonDestino.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            checkButtonDestino.setTag("1");
            map.setOnCameraIdleListener(null);
            Log.d("TAG", "click checkbutton destino");
            if (destination_location_marker!=null)
            {
                destination_location_marker.remove();
            }
            LatDestino = latLng.latitude;
            LonDestino= latLng.longitude;
            destination_location_marker=map.addMarker(markerOptions);
            markerOrigen.setVisibility(View.GONE);
            checkButtonDestino.hide();
            destination_location.setTag("1");

            checkSearchButtonStatus();

        }
    });
}

private void checkSearchButtonStatus() {
    if(source_location.getTag()!=null && destination_location.getTag()!=null){
        type = source_location.getTag().toString() + destination_location.getTag().toString();
    }
    switch (type) {
        case "10":
            //Show toast polyline 1 ("A")
            Toast.makeText(getApplicationContext(), "Selecciona un destino", Toast.LENGTH_LONG).show();
            break;
        case "01":
            Toast.makeText(this, "Selecciona un origen", Toast.LENGTH_SHORT).show();
            break;
        case "11":
            initSearchService();
            searchButton.show();
            break;
    }
}

public void initSearchService(){
    searchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(searchButton.getTag().toString()=="1"){
                Intent intent = new Intent(MapDemoActivity.this, searchService.class);
                intent.putExtra("LatOrigen",LatOrigen);
                intent.putExtra("LonOrigen",LonOrigen);
                intent.putExtra("LatDestino",LatDestino);
                intent.putExtra("LonDestino",LonDestino);
                startService(intent);

                int sizeInPixel = getApplicationContext().getResources().getDimensionPixelSize(R.dimen.dragView);
                dragView.setPanelHeight(sizeInPixel);

                source_location.setTag("0");
                destination_location.setTag("0");

                searchButton.setTag("0");
                searchButton.hide();
                reset.show();
            }else {

            }
        }
    });
}

protected void revealActivity(int x, int y) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            float finalRadius = (float) (Math.max(rootLayout.getWidth(), rootLayout.getHeight()) * 1.1);

            // create the animator for this view (the start radius is zero)
            Animator circularReveal = ViewAnimationUtils.createCircularReveal(rootLayout, x, y, 0, finalRadius);
            circularReveal.setDuration(1190);
            circularReveal.setInterpolator(new AccelerateInterpolator());

            // make the view visible and start the animation
            rootLayout.setVisibility(View.VISIBLE);
            circularReveal.start();
        } else {
            finish();
        }
    }

@SuppressLint("MissingPermission")
protected void loadMap(GoogleMap googleMap) {
    map = googleMap;
    if (map != null) {
        // Map is ready
        map.setMyLocationEnabled(true);
        map.setOnMyLocationButtonClickListener(this);
        map.setOnMyLocationClickListener(this);
        changeGPSIcon();

        try {
            // Customise the styling of the base map using a JSON object defined
            // in a raw resource file.
            boolean success = map.setMapStyle(
                    MapStyleOptions.loadRawResourceStyle(
                            this, R.raw.style_json));

            if (!success) {
            }
        } catch (Resources.NotFoundException e) {

        }

        LatLng marker = new LatLng(19.407021,  -102.046595);
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(marker, 13));
        //Zoom Preferences
        map.setMinZoomPreference(12);
        map.setMaxZoomPreference(19);
    } else {
        Toast.makeText(this, "Error - Map was null!!", Toast.LENGTH_SHORT).show();
    }
}

public void changeGPSIcon() {
    ImageView locationButton = (ImageView) mapFragment.getView().findViewById(Integer.parseInt("2"));
    locationButton.setVisibility(View.GONE);
    FloatingActionButton gpsButton = findViewById(R.id.gpsbutton);
    gpsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            locationButton.callOnClick();
        }
    });
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    MapDemoActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);

    switch (requestCode) {
        case 0x1:
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                Toast.makeText(this, "Permission is granted", Toast.LENGTH_SHORT).show();
                if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
                    enableMyLocation();
            }

    }
}

private void enableMyLocation() {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                != PackageManager.PERMISSION_GRANTED) {
            // Permission to access the location is missing.
            PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE,
                    Manifest.permission.ACCESS_FINE_LOCATION, true);
        } else if (map != null) {
            // Access to the location has been granted to the app.
            map.setMyLocationEnabled(true);
        }
    }

    @Override
    public boolean onMyLocationButtonClick() {
        enableLoc();
        return false;
    }

    @Override
    public void onMyLocationClick(@NonNull Location location) {
        Toast.makeText(this, "Ubicación actual", Toast.LENGTH_LONG).show();
    }

public void onSaveInstanceState(Bundle savedInstanceState) {
    savedInstanceState.putParcelable(KEY_LOCATION, mCurrentLocation);
    super.onSaveInstanceState(savedInstanceState);
}

private void enableLoc() {

    if (googleApiClient == null) {
        googleApiClient = new GoogleApiClient.Builder(MapDemoActivity.this)
                .addApi(LocationServices.API)
                .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                    @Override
                    public void onConnected(Bundle bundle) {

                    }

                    @Override
                    public void onConnectionSuspended(int i) {
                        googleApiClient.connect();
                    }
                })
                .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
                    @Override
                    public void onConnectionFailed(ConnectionResult connectionResult) {

                        Log.d("Location error", "Location error " + connectionResult.getErrorCode());
                    }
                }).build();
        googleApiClient.connect();

        LocationRequest locationRequest = LocationRequest.create();
        locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        locationRequest.setInterval(30 * 1000);
        locationRequest.setFastestInterval(5 * 1000);
        LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
                .addLocationRequest(locationRequest);

        builder.setAlwaysShow(true);

        PendingResult<LocationSettingsResult> result =
                LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
        result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
            @Override
            public void onResult(LocationSettingsResult result) {
                final Status status = result.getStatus();
                switch (status.getStatusCode()) {
                    case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                        try {
                            // Show the dialog by calling startResolutionForResult(),
                            // and check the result in onActivityResult().
                            status.startResolutionForResult(MapDemoActivity.this, REQUEST_LOCATION);

                            //finish();
                        } catch (IntentSender.SendIntentException e) {
                            // Ignore the error.
                        }
                        break;
                }
            }
        });
    }
}

@Override
public void onBackPressed() {
    if (mLayout != null &&
            (mLayout.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED || mLayout.getPanelState() == SlidingUpPanelLayout.PanelState.ANCHORED)) {
        mLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
    } else {
        super.onBackPressed();
    }
}

private BroadcastReceiver mMessageFilterResult = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getBundleExtra("extra");
        if (bundle != null) {
            validadorFinal = (ArrayList<Integer>) bundle.getIntegerArrayList("validadorFinal_");
        } else {
        }
        new polylinePrinter().execute();
    }
};

protected class polylinePrinter extends AsyncTask {

    PolylineOptions pUnidad1PalitoVerdeIda;
    PolylineOptions pUnidad1PalitoVerdeVuelta;

    PolylineOptions pUnidad1ManantialesIda;
    PolylineOptions pUnidad1ManantialesVuelta;

    PolylineOptions pUnidad1SanJoseIda;
    PolylineOptions pUnidad1SanJoseVuelta;

    PolylineOptions pConstiZumpi2AIda;
    PolylineOptions pConstiZumpi2AVuelta;

    PolylineOptions pConstiJica2Ida;
    PolylineOptions pConstiJica2Vuelta;

    List<LatLng> simplifydecodedRuta1Ida;
    List<LatLng> simplifydecodedRuta1Vuelta;

    List<LatLng> simplifydecodedRuta1MIda;
    List<LatLng> simplifydecodedRuta1MVuelta;

    List<LatLng> simplifydecodedRuta1SIda;
    List<LatLng> simplifydecodedRuta1SVuelta;

    List<LatLng> simplifydecodedRuta3Ida;
    List<LatLng> simplifydecodedRuta3Vuelta;

    List<LatLng> simplifydecodedRuta5Ida;
    List<LatLng> simplifydecodedRuta5Vuelta;

    @Override
    protected Object doInBackground(Object[] objects) {
        double tolerance = 20;

        if (validadorFinal.get(0)==1){
            simplifydecodedRuta1Ida = PolyUtil.simplify(ConstantsRoutes.decodedRuta1Ida, tolerance);
            simplifydecodedRuta1Vuelta = PolyUtil.simplify(ConstantsRoutes.decodedRuta1Vuelta, tolerance);
            Loader1Ida();
            Loader1Vuelta();
        }

        if (validadorFinal.get(1)==1){
            simplifydecodedRuta1MIda = PolyUtil.simplify(ConstantsRoutes.decodedRuta1MIda, tolerance);
            simplifydecodedRuta1MVuelta = PolyUtil.simplify(ConstantsRoutes.decodedRuta1MVuelta, tolerance);
            Loader1MIda();
            Loader1MVuelta();
        }

        if (validadorFinal.get(2)==1){
            simplifydecodedRuta1SIda = PolyUtil.simplify(ConstantsRoutes.decodedRuta1SIda, tolerance);
            simplifydecodedRuta1SVuelta = PolyUtil.simplify(ConstantsRoutes.decodedRuta1SVuelta, tolerance);
            Loader1SIda();
            Loader1SVuelta();
        }

        if (validadorFinal.get(3)==1){
            simplifydecodedRuta2Ida = PolyUtil.simplify(ConstantsRoutes.decodedRuta2Ida, tolerance);
            simplifydecodedRuta2Vuelta = PolyUtil.simplify(ConstantsRoutes.decodedRuta2Vuelta, tolerance);
            Loader2Ida();
            Loader2Vuelta();
        }

        if (validadorFinal.get(4)==1){
            Loader2AIda();
            Loader2AVuelta();
        }

        if (validadorFinal.get(5)==1){
            simplifydecodedRuta3Ida = PolyUtil.simplify(ConstantsRoutes.decodedRuta3Ida, tolerance);
            simplifydecodedRuta3Vuelta = PolyUtil.simplify(ConstantsRoutes.decodedRuta3Vuelta, tolerance);
            Loader3Ida();
            Loader3Vuelta();
        }

        return null;
    }

    protected void onPostExecute(Object result) {
        loadSwitches();
        if(validadorFinal.get(0)==1){
           shower1Vuelta();
            Shower1Ida();
        }

        if (validadorFinal.get(1)==1){
            shower1MIda();
            shower1MVuelta();
        }

        if (validadorFinal.get(2)==1){
            shower1SIda();
            shower1SVuelta();
        }

        if (validadorFinal.get(3)==1){
            shower2Ida();
            shower2Vuelta();
        }

        if (validadorFinal.get(4)==1){
            shower2AIda();
            shower2AVuelta();
        }

        if (validadorFinal.get(5)==1){
            shower3Ida();
            shower3Vuelta();
        }
    }

    private void loadSwitches(){
        Switch switch_ida1 = (Switch) findViewById(R.id.switchIdaRuta1);
        Switch switch_vuelta1 = (Switch) findViewById(R.id.switchVueltaRuta1);

        Switch switch_ida1M = (Switch) findViewById(R.id.switchIdaRuta1M);
        Switch switch_vuelta1M = (Switch) findViewById(R.id.switchVueltaRuta1M);

        Switch switch_ida1S = (Switch) findViewById(R.id.switchIdaRuta1S);
        Switch switch_vuelta1S = (Switch) findViewById(R.id.switchVueltaRuta1S);

        Switch switch_ida2A = (Switch) findViewById(R.id.switchIdaRuta2A);
        Switch switch_vuelta2A = (Switch) findViewById(R.id.switchVueltaRuta2A);

        Switch switch_ida2 = (Switch) findViewById(R.id.switchIdaRuta2);
        Switch switch_vuelta2 = (Switch) findViewById(R.id.switchVueltaRuta2);

        Switch switch_ida3 = (Switch) findViewById(R.id.switchIdaRuta3);
        Switch switch_vuelta3 = (Switch) findViewById(R.id.switchVueltaRuta3);

        Switch switch_ida4 = (Switch) findViewById(R.id.switchIdaRuta4);
        Switch switch_vuelta4 = (Switch) findViewById(R.id.switchVueltaRuta4);

        Switch switch_ida5 = (Switch) findViewById(R.id.switchIdaRuta5);
        Switch switch_vuelta5 = (Switch) findViewById(R.id.switchVueltaRuta5);

        listSwitch.add(0,switch_ida1);
        listSwitch.add(1, switch_vuelta1);

        listSwitch.add(2,switch_ida1M);
        listSwitch.add(3,switch_vuelta1M);

        listSwitch.add(4,switch_ida1S);
        listSwitch.add(5,switch_vuelta1S);
    }

    private void Loader1Ida(){
        pUnidad1PalitoVerdeIda = new PolylineOptions();
        pUnidad1PalitoVerdeIda.addAll(simplifydecodedRuta1Ida)
                .color(Color.parseColor("#2196F3")); //Color blue
    }
    private void Shower1Ida(){
        LinearLayout linearLayout1 = (LinearLayout) findViewById(R.id.layoutRuta1);
        linearLayout1.setVisibility(View.VISIBLE);

        final Polyline[] Unidad1PalitoVerdeIda = new Polyline[1];
        listSwitch.get(0).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {

                    Unidad1PalitoVerdeIda[0] = map.addPolyline(pUnidad1PalitoVerdeIda);
                    Unidad1PalitoVerdeIda[0].setClickable(true);
                    Unidad1PalitoVerdeIda[0].setTag("Unidad1PalitoVerdeIda");
                    Unidad1PalitoVerdeIda[0].setWidth(8);
                    Unidad1PalitoVerdeIda[0].setPattern(PATTERN_POLYLINE_DOTTED);
                } else {
                    Unidad1PalitoVerdeIda[0].remove();
                }
            }
        });
   //39 Routes more
</code>
}
Answer: You can reduce screen map lagging when draw polyline if you draw not all, but only generalized for each zoom level "special" (point where path changes) point of your polylines. For determine "special" points of your path you can use, for example, Ramer-Douglas-Peucker algorithm:

You can use Google Maps Android API Utility Library especially
<code>PolyUtil.simplify()</code> method as its implementation.
Also, here you can find it's implementation in Java (with comments):
<code>private static class Point extends Pair<Double, Double> {
    Point(Double key, Double value) {
        super(key, value);
    }

    @Override
    public String toString() {
        return String.format("(%f, %f)", getKey(), getValue());
    }
}

private static double perpendicularDistance(Point pt, Point lineStart, Point lineEnd) {
    double dx = lineEnd.getKey() - lineStart.getKey();
    double dy = lineEnd.getValue() - lineStart.getValue();

    // Normalize
    double mag = Math.hypot(dx, dy);
    if (mag > 0.0) {
        dx /= mag;
        dy /= mag;
    }
    double pvx = pt.getKey() - lineStart.getKey();
    double pvy = pt.getValue() - lineStart.getValue();

    // Get dot product (project pv onto normalized direction)
    double pvdot = dx * pvx + dy * pvy;

    // Scale line direction vector and subtract it from pv
    double ax = pvx - pvdot * dx;
    double ay = pvy - pvdot * dy;

    return Math.hypot(ax, ay);
}

private static void ramerDouglasPeucker(List<Point> pointList, double epsilon, List<Point> out) {
    if (pointList.size() < 2) throw new IllegalArgumentException("Not enough points to simplify");

    // Find the point with the maximum distance from line between the start and end
    double dmax = 0.0;
    int index = 0;
    int end = pointList.size() - 1;
    for (int i = 1; i < end; ++i) {
        double d = perpendicularDistance(pointList.get(i), pointList.get(0), pointList.get(end));
        if (d > dmax) {
            index = i;
            dmax = d;
        }
    }

    // If max distance is greater than epsilon, recursively simplify
    if (dmax > epsilon) {
        List<Point> recResults1 = new ArrayList<>();
        List<Point> recResults2 = new ArrayList<>();
        List<Point> firstLine = pointList.subList(0, index + 1);
        List<Point> lastLine = pointList.subList(index, pointList.size());
        ramerDouglasPeucker(firstLine, epsilon, recResults1);
        ramerDouglasPeucker(lastLine, epsilon, recResults2);

        // build the result list
        out.addAll(recResults1.subList(0, recResults1.size() - 1));
        out.addAll(recResults2);
        if (out.size() < 2) throw new RuntimeException("Problem assembling output");
    } else {
        // Just return start and end points
        out.clear();
        out.add(pointList.get(0));
        out.add(pointList.get(pointList.size() - 1));
    }
}
</code>
Changing of <code>double epsilon</code> value you can create reduced lists of "generalized" path points for each zoom level and reduce map lagging.
Comment: I used PolyUtil.siplify() but in documentation says:
"The time complexity of Douglas-Peucker is O(n^2), so take care that you do not call this algorithm too frequently in your code."
I called it maybe 20 times and the map still lagging
Comment: @EmmanuelMolina you need to use `PolyUtil.siplify()` only once just after your polylines data downloaded. Then store simplified polyline data and use it. Actually, not once, but once for each zoom level: e.g. for zoom level 20 use not simplified polyline,  for zoom level 19 - use `PolyUtil.siplify()` with `tolearnce1`, for  zoom level 19 - use `PolyUtil.siplify()` with `tolearnce2`, `tolearnce2 > tolearnce1` etc. I mean - precalculate polylines for each zoom level (or one simplified polyline for several zoom levels) and use once precalculated data. `O(n^2)` is appropriate for that case.


IIS6 subdomain not resolving

Question: I have a subdomain something like dev.something.root.com where I get a connection timeout.
If I ping dev.something.root.com , it returns the ip address of the server. If I enter the IP address in the hosts file, then I can access the site. If I take it out - I can no longer access the site.
So it doesn't seem like there's a problem with the site, and the domain seems to be resolving the correct IP.
The request doesn't get all the way to IIS I think, as it's not logging anything.
What could I do to find out the problem ?
Edit
Why would it work when I add the ip to the hosts file ?
Answer: Well since DNS is resolving to the correct IP address, DNS is good.  Now you'll simply have to make use of host headers in IIS.
More information can be found here.
<code>To add a Web site using a host header identifier using the Web Site Creation Wizard
1. In IIS Manager, expand the local computer, right-click the Web Sites directory, point to New, and then click Web Site.
2. Click Next.
3. In the Description box, type the name you have selected for the Web site, and then click Next.
4. In the Enter the IP address to use for this Web site box, click the IP address used by all sites on the server.
5. In the TCP port this Web site should use box, type the port number used by all sites on the server.
6. In the Host Header for this Web site (Default:None) box, type the host header name to identify the Web site. The host header name must contain the full name of the site, for example, dev.something.root.com.
7. If SSL encryption is not enabled on the server, the SSL port box does not appear. If SSL encryption is enabled on the server, type the SSL port number, and then click Next. Note that you cannot use host headers with SSL encryption.
8. In the Path box, type or browse to the path of your Web site home directory.
9. To create a secured or private Web site, clear the Allow anonymous access to this Web site check box, and click Next. (Web sites are configured for anonymous access by default.)
10. In the Web Site Access Permissions box, set the permissions for the home directory.
11. Click Next, and then click Finish.
</code>
Comment: I added more details to my post ... this subdomains has a php site behind it. could that be a cause for the problem ?

IIS6 subdomain not resolving


Check box against dropdownlist item

Question: Is there anyway to create a dropdownlist or combobox with a check box on it. So the user can select multiple items at once.
The similar thing I found is the checkedListBox, but it grows when there are more items.
In my case I don't have enough space to use checkedListBox.
Is there any way to achieve this?
Answer: To have a combo/dropdown with checks is absolutely crazy idea because combo meant for selection of single item out of list.
If real estate is your problem you can create a hidden user control with listbox and OK button, make it popup when you click some button. For example, you can have a read-only text box with selected items listed semicolon-delimited with small ... button next to it. When you click, list box pops up and you select stuff, close it, and it appears in your textbox.
This is just one of things you can do.
Answer: You'll have to create your own control - http://www.codeproject.com/Articles/18929/An-OwnerDraw-ComboBox-with-CheckBoxes-in-the-Drop might be a good starting point.

Check box against dropdownlist item


Check if a string of chars is all comprised in another string

Question: Can anyone tell me why this piece of code doesn't return any values when there are matches from my table?
CREATE FUNCTION fn_AllEmployeesAndTownsWhichContainLetters(@setOfLetters NVARCHAR(200), @string NVARCHAR(200))
    RETURNS BIT
        AS
        BEGIN
            DECLARE @length INT, @i INT
            SET @length = LEN(@string)
            SET @i = 1
            WHILE (@i < @length)
                BEGIN
                    IF CHARINDEX(SUBSTRING(@string, 1, @i),@setOfLetters) <= 0
                        RETURN 0
                    ELSE
                        SET @i = @i + 1
                END
            RETURN 1
        END GO

Comment: well, what data is being passed to it?
Comment: a column [Firstname] from a table, the column has many nvarchar values & im trying to check if any of those strings match the @setOfLetters (no matter what the order of the letters is)
Answer: CREATE FUNCTION fn_AllEmployeesAndTownsWhichContainLetters(@setOfLetters NVARCHAR(200), @string NVARCHAR(200))
RETURNS BIT
AS
BEGIN
    DECLARE @length INT, @i INT
    SET @length = LEN(@string)
    SET @i = 1
    WHILE (@i < @length)
        BEGIN
            IF CHARINDEX(SUBSTRING(@string, 1, @i),@setOfLetters) > 0
                RETURN 1
            ELSE
                SET @i = @i + 1
        END
    RETURN 0
END


Symfony2 Error Security.yml

Question: I am learning 'Symfony2' and I was following this:
http://symfony.com/doc/current/cookbook/security/entity_provider.html#configure-security-to-load-from-your-entity
But, when I make the changes in security.yml as mentioned in the document, I get the following error:

[Symfony\Component\Debug\Exception\ContextErrorException]
Notice: Undefined index: algorithm

This is the code which is giving me the error:

# app/config/security.yml
security:
    encoders:
        AppBundle\Entity\User:
            algorithm: bcrypt

Please help me with this. It should not show an error as it is in Symfony2 Docs.
Comment: try `composer self-update` first
Comment: I did that after installing the bundle. But, still got the same error.
Answer: replace in your config.yml
to:
<code>security:
    encoders:
        AppBundle\Entity\User: bcrypt
</code>

Symfony2 Error Security.yml


DETERMINISTIC and NON-DETERMINISTIC function in MySQL

Question: my understaning for Deterministic function is that :

always produces the same result for the same input parameters

as per my understanding below function is Nonderministic function
<code>CREATE FUNCTION foo (val INT) READS SQL DATA
BEGIN
   DECLARE retval INT;
   SET retval = (SELECT COUNT(*) FROM table_1 WHERE field_1 = val);
   RETURN retval;
END;
</code>
If i dont use Deterministic or Nondeterministic keyword in function will it degreade performance or is it necessary for execution plan.
Comment: `If neither DETERMINISTIC nor NOT DETERMINISTIC is given in the routine definition, the default is NOT DETERMINISTIC.`. And `Declaring a nondeterministic routine as DETERMINISTIC might lead to unexpected results by causing the optimizer to make incorrect execution plan choices. Declaring a deterministic routine as NONDETERMINISTIC might diminish performance by causing available optimizations not to be used.`. See [13.1.16 CREATE PROCEDURE and CREATE FUNCTION Syntax](https://dev.mysql.com/doc/refman/5.7/en/create-procedure.html).
Answer: When you declare a function to be deterministic, the query planner knows it can take advantage of cached results for that function. It may speed things up. Pretty much no function that looks in tables can be deterministic.
If you're not sure whether your function is deterministic, it probably isn't.


When, if ever, should a normality test be performed on real-world data?

Question: I've recently come across some research studies and internal reports from my company where multiple mean-comparison tests are performed.
The procedure is often as follows: first, the data is checked for normality. If normality is not rejected (with a <5% p-value), a T-test is performed to compare means. Otherwise, non-parametric tests are used instead.
However, from my understanding of Statistics, I see something very wrong about that approach:
First, no real-world data is normal. Small samples are the only reason why normality is not rejected.
Second: it is often the case that, when making the same experiment under slightly different conditions (winter/summer, last year/this year, here/a few km away...), we manage to reject normality only some of the time, resulting in choosing a different testing procedure once we already studied the data. This reminds me a bit of HARKing
Third: if we only care about mean values, we can always perform a T-test. We can get significant differences between populations in a non-parametric test even if they all have the same mean, variance (or any other magnitude of interest)
So, in short: Is this approach legitimate despite all these issues? Under what circumstances? Are those issues real or am I missing something?
Answer: There is a marvelous thread on this site: "Is normality testing 'essentially useless'?". It indicates that your take on this matter is essentially correct.
If you have a small sample size then you won't have enough power to detect a true deviation from normality; $p \ge 0.05$ in a normality test doesn't demonstrate normality, it simply doesn't rule it out at that (arbitrary) probability cutoff.
If you have a very large sample size then you typically will rule out normality.
And in either case you've used the data to choose the test, violating the assumptions of the test that you choose.
The one place where you aren't quite right is the statement that "if we only care about mean values, we can always perform a T-test." Yes, you can always calculate a t statistic but the significance test for that t-statistic does assume normally distributed data,* even in tests that allow for different variances between groups. It turns out that t-tests often work well enough when the normality assumption doesn't hold. As another answer to your question notes, transformations of data often can help make data conform better to that assumption.
Also, you don't comment on your company's use of multiple t-tests when there are multiple means to compare. That leads to multiple-comparison issues that might be more troublesome than choosing the tests for significant differences based on an initial normality test.
A Frank Harrell notes in one answer on that first thread, non-parametric tests have reasonably high power even if data are normally distributed, they work well without the normality assumption, and generalize to ordinal cumulative probability models when something more than a 2-sample comparison is needed.
So a more defensible strategy, if you have reason to believe that normality assumptions will be violated so strongly as to pose a problem for t-tests and the like, is just to go with non-parametric tests.

*This linked page notes 3 required assumptions: that the sample mean estimate be appropriately normally distributed, that the sample variance estimate be $\chi^2$ with appropriate degrees of freedom, and that these estimates be independent. What it doesn't make immediately clear is that the third assumption is characteristic only of normal distributions. See this answer, linked in a comment by @COOLSerdash, for more details.
Comment: @jkpate You are right to an extent, but the normal mean in a finite sample size is not guaranteed for other distributions the way it is for normal. You are, however, alluding to the fact that, through the power of the central limit theorem (Slutsky's theorem comes up, too), a "large" sample size drawn from a funky distribution might be "close enough" to normal for practical purposes.
Comment: The significance test for a $t$-statistic assumes that the *mean* follows a normal distribution. The central limit theorem shows that the distribution of the mean tends towards a normal distribution as sample size increases if the observations are i.i.d., even if actual data are not normal. Testing for normality of data is therefore doubly meaningless, since the test doesn't even assume it!
Comment: @jkpate The $t$-test *does* assume normal populations, not just normal means. See Glen_b's comprehensive answer [here](https://stats.stackexchange.com/a/253318/21054). The derivation of the $t$-statistic can be found in many textbooks, "Mathematical statistics with applications" by Wackerly, Mendenhall & Scheaffer, for example.
Answer: I can answer from experience with real-world microbiological data but cannot give an authoritative/general answer. The approach I use and preach involves the following:

Graph data as histogram(s) (I know there are issues with this but it's where I start). Does it look skewed? No? Don't rule out t-tests. Yes. Transform it with log, sqrt.
If wanting to compare two groups: Calculate variances for both groups and run Levene's test for equal variances on transformed data. Are variances similar (within about 5% of each other)? Yes. Perform t-test. No & sample size is <20? Use non-parametric tests.
Comment: But, in 2, couldn't I use a T-test with unequal variances?
Comment: A rule of thumb in my work is to avoid it for a sample size smaller than 30 because it's not very conservative. The lack of equal variances is more problematic than the lack of normality


Outlook 2010 search doesent work

Question: I have 50 pc's with office 2010 installed. All machines are running windows 7 x64 and joined to domain. (there is no office 2010 administrative policies defined).Both, windows and office are receiving critical and security updates from on site WSUS server.
The company depends a lot on sending and receiving mails. They receive about 3 000 legit mails per day and also many spam messages.
Suddenly, outlook 2010 search engine stopped working the for every user. It allows entering the term and finds a lot of results, but the result is not relevant to search term. Also, outlook is indexing non-stop so there is never results from week or two. Only older unrelated messages apear in search results.
All .pst are smaller that Microsoft allows for 2010. Email server is on vps server and all accounts are set up as pop3. On mobile phones search engine work well.
What can I do?
Thanks,
Carlo
Comment: try a scanpst run at first please, the tool is hidden in your office folder. it will scan the pst fir any corruption
Comment: I can't run scanpst on all computers because that takes time. Problem must be something else because the problem exist on all computers and different users receive different email messages so I don't belive that pst is corupted. But I can try run on one pc.
Comment: Please try one, my goal is to isolate the trouble, as the pst is a database file, and your symptom look like a corruption.
Comment: So this link fixed it for me:
https://support.microsoft.com/en-in/help/4022168/windows-7-sp1-windows-server-2008-r2-sp1-update-kb4022168
Answer:
Ensure Windows Search service is up and running
Make an index rebuild https://www.wintips.org/fix-outlook-search-problems/

Outlook 2010 search doesent work