$\int_0^1 f(x)g_n(x) dx \rightarrow 0$ for $f \in L^p, g_n \in L^q$

Question: Define:
$g_n(x)=n \chi_{[0,n^{-3}]}(x)$ for $n\in\mathbb{N}$.
Show that, if $f \in L^2([0,1])$, then
$\int_0^1 f(x)g_n(x) dx \rightarrow 0$.
My Idea would be to use the Hölder inequality.
First, I have to show that $(g_n)_n \in L^2$ for all $n \in \mathbb{N}$.
So, $\int_0^1 |n \chi_{[0,n^{-3}(x)]}|^2 dx=\int_0^{n^{-3}} n^2 dx= 1/n$
By the Hölder inequality:
$|\int_0^1 f(x) n \chi_{[0,n^{-3}]}(x) dx|\leq ||f||_2 ||g_n||_2$.
Now, since $||g_n||_2= \frac{1}{\sqrt{n}}$ and $||f||_2 < \infty$ we get:
$\lim_{n \rightarrow \infty} ||f||_2 ||g_n||_2=0$.
I would like to know if my calculations are right. I do think that this is how it should work, but I am always a little bit worried if Hilbert spaces come up, but I don't use the inner product.
Some question on the side.
Do I need to use the Hölder inequality, or is there another way to show this? If this does not depend on the Hölder inequality, and thus does not need for $\frac{1}{p}+\frac{1}{q}=1$. does this hold for $f \in L^1$, $f \in L^3 ,... $.
Comment: Your solution is fine.
Answer: You do use the inner product since $\langle f, g \rangle_{L^2} = \int f \text{ } \overline{g} \text{ } d \mu,$ which reduces to $\int f g d \mu$ when $g$ is real. As for the general case, you can use the general Hölder inequality $\Vert f g_n \Vert_1 \leq \Vert f \Vert_p \Vert g_n \Vert_q.$ To see when $\Vert g_n \Vert_q \to 0,$ we compute
$$\int_0^1 \vert g_n \vert^q d \mu = \int_0^{n^{-3}} n^q d \mu = n^{q-3},$$
so we obtain $\vert \int_0^1 f g_n d \mu \vert \leq n^\frac{q - 3}{q}\Vert f \Vert_p,$ which converges to $0$ whenever $q < 3.$ Thus the statement holds whenever $p > \frac{3}{2}.$ I hope this helps. :)
Comment: Adding to the first point, using the Hölder inequality as the OP does can be viewed as applying the Cauchy-Schwarz inequality in the Hilbert space $L^{2}$.
Comment: Precisely my point, cheers for expanding on that! :)


Crossvalidation in hierarchical bayesian models (HBMs)

Question: I am trying to find a way to cross-validate Hierarchical Bayesian Models used for predicting and modelling abundance in Species Distribution Models. For this purpose, I have tried posterior predictive checks proposed in Kéry & Schaub 2011, chapter 12.3.1 with the following modified $\chi^2$ discrepancy measure:
$$\sum_i{{(Y_i - EY_i)^2}\over{var Y_i + 0.5}}$$
(the 0.5 is added to prevent division by zero - this is slighlty modified Gelman 2004 (2nd edition, pg. 175) $\chi^2$ discrepancy).
As I want to test the predictive power of the model - at sites for which we don't have data - I split the data into fitting set and validation set and I did the predictive posterior checks in two variants:

on the fitted set
on the validation (i.e. cross-validation) set

Very simplified, the JAGS model including posterior predictive checks looks like this:
for (i in 1:sites) {
    log(lambda[i]) <- lambda_int + inprod(b_lambda[], envCov[i,]) + site_eff[i]
    site_eff[i] ~ dnorm(0, 1/(site_eff_sd*site_eff_sd))

    N[i] ~ dpois(lambda[i])

    for (j in 1:visits) {
        p[i,j] <- ... some predictor ...

        # posterior predictive checks, a la Kery, BPA chapter 12.3.1
        # done for all the sites (fitted/crossvalidatory)
        Y.new[i, j] ~ dbinom(p[i,j], N[i])
        E[i,j] <-     pow(    Y[i,j] - p[i,j] * N[i], 2) / (p[i,j] * N[i] + 0.5)
        E.new[i,j] <- pow(Y.new[i,j] - p[i,j] * N[i], 2) / (p[i,j] * N[i] + 0.5)
    }
}

# sites determined for fitting the model (other sites are for validation)
for (i in 1:fit_sites) {
    for (j in 1:visits) {
        Y[i, j] ~ dbinom(p[i,j], N[i])
    }
}

# classic PPC: on fitted data
fit <- sum(E[1:fit_sites,])
fit.new <- sum(E.new[1:fit_sites,])

# crossvalidatory PPC: on independent data
fit.cv <- sum(E[(fit_sites+1):sites,])
fit.cv.new <- sum(E.new[(fit_sites+1):sites,])

where Y[i,j] is the observed count of the species at site i on occasion j, N[i] is the actual latent abundance of the species at site i. First two thirds of the sites are used to fit the data, remaining third of the sites is reserved for crossvalidation only.
Questions:
1. Is this approach OK? Kéry doesn't mention crossvalidation, and Gelman 2004 has a note in chapter 8.2 which I do not understand (especially the italic part):

If a model is to be evaluated by its expected predictive fit to new
  data, a reasonable approach would seem to be cross-validation -
  fitting the model to part of a dataset and evaluating it on the rest -
  but it is not clear how to interpret this in terms of posterior inference. Conditional on a model being correct, we can directly
  assess it's predictive accuracy by comparing its fit to simulated
  replicated data sets $Y.new$ - but DIC and cross-validation attempt to
  do better and capture predictive error including model misfit.

2. Is the modification with + 0.5 OK for this purpose? I mean, couldn't it make any mess?
3. How to create easily interpretable measure to assess quality of the model? I mean something that would tell me 0% to 100% - from absolutely poor to absolutely perfect model. Kery is proposing two measures:

bayesian p-value   mean(simulations$fit.new > simulations$fit),
lack-of-fit ratio  mean(simulations$fit / simulations$fit.new)

But how to interpret those? Is e.g. a lack-of-fit ratio of 2 good or bad? I would like some measure which has clear scale like $r$ or $AUC$ where you can e.g. say that 1 is a perfect model, > 0.75 is good, < 0.5 is poor...
Here are few examples of results and plots, where I plot fit or fit.cv on the X axis and fit.new and fit.cv.new on the Y axis.
Example 1 - comparison of two models:
linear model PPC - fitted data:
          p-value lack-of-fit ratio
        0.9276667         0.9442094

linear model PPC - independent data:
          p-value lack-of-fit ratio
         0.000000          1.820381

superpredictor PPC - fitted data:
          p-value lack-of-fit ratio
        0.9810000         0.9213055

superpredictor PPC - independent data:
          p-value lack-of-fit ratio
         0.000000          1.742552

Example 2 - comparison of two models:
linear model PPC - fitted data:
          p-value lack-of-fit ratio
        0.7705333         0.9245741

linear model PPC - independent data:
          p-value lack-of-fit ratio
         0.002200          2.008853

superpredictor PPC -  fitted data:
          p-value lack-of-fit ratio
        0.7315333         0.9389283

superpredictor PPC -  independent data:
          p-value lack-of-fit ratio
         0.000000          2.985811

Example 3 - comparison of two models:
linear model PPC -  fitted data:
          p-value lack-of-fit ratio
        0.6679667         0.9722895

linear model PPC -  independent data:
          p-value lack-of-fit ratio
      0.005516667       1.341490485

superpredictor PPC - fitted data:
          p-value lack-of-fit ratio
        0.5848000         0.9869094

superpredictor PPC - independent data:
          p-value lack-of-fit ratio
         0.000000          2.012136

In models 1,2 I can tell that the superpredictor is better than the linear model, but how to get any idea of how good/poor both of the models are on a scale (absolutely poor) - (absolutely perfect)?
Would e.g. something like comparison with null model do the work? I have tried it:
Answer: I work on similar models using the same book so I encountered the same issues - thanks for interesting questions.
1. Can posterior predictive checks be performed using both fitted and out-of-sample data?
Yes - at least some authors propose to do both of these in the statistical literature (e.g., http://www.math.ntnu.no/~daniesi/INLA/Papers/festschrift.pdf). But they refer more specifically to CPO (conditional predictive ordinate) and PIT (probability integral transform)
However, Bayesian p-values and out-of-sample-based predictive probabilities seem to measure slightly different things. The latter ones measure your ability to predict new data, which is a blend of goodness of fit and model complexity (keep in mind that in some contexts, IT measures favouring parsimony such as AIC are asymptotically equivalent to leave-one-out CV).
The Bayesian P-value $\text{Pr}(T(Y^{rep})>T(y)|y,\theta)$ (using the fitted data only) would be instead the equivalent of your $R^2$ , a simple measure of fit, except that rather than using only a point prediction from the fitted model, it uses the whole posterior distribution of $y$ values.
Digging a little through the citation pipeline, the above paper refers to

Dawid, A. P. (1984).  Statistical theory: The prequential approach,
  Journal of the Royal Statistical Society. Series A (General) 147:
  278-292.
Pettit, L. I. (1990).  The conditional predictive ordinate for the normal distribution, Journal of the Royal Statistical Society: Series B 52: 175-184.
Marshall, E. C. and Spiegelhalter, D. J. (2003). Approximate cross-validatory predictive checks in disease mapping models. Statistics in Medicine 22, 1649–1660.

Many papers including a complicated model seem to have their own specific predictive measure based on out of sample data, thus perhaps that's appropriate for you too. Which brings us to what you're trying to do by using cross-validation: selecting a model balancing goodness of fit with complexity. On that point the following review might be up-to-date

Hooten, M. B., & Hobbs, N. T. (2015). A guide to Bayesian model
  selection for ecologists. Ecological Monographs, 85(1), 3-28.

I don't know if $\chi^2$ is the best distance/discrepancy measure, not entirely sure either if that makes sense to plot the independently obtained discrepancy values with those from the fitted data (but perhaps it does).

0.5 Correction.

$\text{Var}(Y_i)$ is likely to be above 0.5 if $N>>1$, which in turn depends on $\lambda$. You can always use 0.05, 0.1, 0.2 instead to check.

Measure of fit.

You seem to be looking for a $R^2$. But even with such measure, good or bad is context dependent, i.e. $75 \%$ will appear barely believable in some fields and ridiculously low in others.
Here's what I found on interpreting Bayesian p-values http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.310.145&rep=rep1&type=pdf (statisticians seem to debate their distribution btw).
One practical solution would be simulate data according to a model which you know to be close to your situation (similar sample sizes, number of sites, approximate abundances/occupancy etc.), then fit the simulated model to simulated data, and use the resulting Bayesian P-values as measures of "good" (as good as it is going to get) when interpreting those from your real data.
Lack-of-fit ratio: Looks like a comparison of mean squared errors. Isn't it mean(simulations$fit) / mean(simulations$fit.new), rather?
The same simulation approach could work to get sensible reference values. Also, if we were comparing to sets of replicated data, the discrepancy measures should follow two $\chi^2$ distributions which means the ratio follows an F - and gives access to a different kind of P-value.
[just throwing in ideas here]
The comparison to the null model makes more sense to me when you compare the predictive abilities of the models using the independent data.
EDIT 10/06
The discrepancy measure of Kéry and Schaub is in fact
$\sum_{i=1}^{n}{\frac{(Y_i-E(Y_i))^2}{E(Y_i)+0.5}}$, no variance term below.
EDIT2 10/06
For similar hierarchical models, I also get Bayesian P-values always above 0.5 (no matter how good the fit looks graphically) and very often close to 1, with Lack-of-fit ratios just below 1 (e.g. 0.8 or 0.9)


What is transactional memory?

Question: I'm confused because from reading the wiki page it seems like just having a checkValidate and commit system for loads and stores. Is the purpose to solve synchronization problems? Is it a software programming thing build on-top of current hardware, or is it a hardware implementation via an ISA? What's the difference between each (HW/SW) implementation?
Thanks.
Answer: Transactional Memory is the concept of using transactions rather than locks to synchronise processes that execute in parallel and share memory.
At a very simplified level, to synchronise with locks you identify sections of code (called critical sections) that must not be executed simultaneously by different threads and acquire and release locks around the critical sections. Since each lock can only be held by one thread at a time, this guarantees that once one thread enters a critical section, all of the section's operations will have been completed before another thread enters a critical section protected by the same lock(s).
Transactional memory instead lets you designate sections of code as transactions. The transactional memory system (which can be implemented in hardware, software, or both) then attempts to give you the guarantee that any run of a program in which multiple threads execute transactions in parallel will be equivalent to a different run of the program in which the transactions all executed one after another, never at the same time.
The transactional memory system does this by allowing transactions to execute in parallel and monitoring their access to transaction variables. If the system detects a conflict between two transactions' access to the same variable, it will cause one of them to abort and "rollback" to the beginning of the transaction it was running; it will then automatically restart the transaction, and the overall state of the system will be as if it had never started the earlier run.

One goal of transactional memory is ease-of-programming and safety; a properly implemented TM system which is able to enforce that transactions are used correctly gives hard guarantees that there are no parallelism bugs (deadlocks, race conditions, etc) in the program, and only requires that the programmer designate the transactions (and sometimes transaction variables, if the system doesn't just consider all of memory to implicitly be transaction variables), without needing to identify exactly what locks are needed, acquire them in the correct order to prevent deadlock, etc, etc. "Transacitons are used correctly" implies that there is no sharing data between threads without going through transaction variables, no access to transactional data except in transactions, and no "un-rollbackable" operations inside transactions); library based software transactional memory systems for imperative languages like C, Java, etc generally are unable to enforce all of this, which can re-introduce the possibility of some of the parallelism bugs.
Another goal of transactional memory is increasing parallelism; if you have a whole bunch of parallel operations which access some data structure, all of which might write to it but few of which actually do, then lock-based synchronisation typically requires that all of the operations run serially to avoid the chance of data corruption. Transactional memory would allow almost all of the operations to run in parallel, only losing parallelism when some process actually does write to the data structure.
In practice (as of when I researched my honours project a few years ago), hardware-based transactional memory hasn't really taken off, and current software transactional memory systems have significant overheads. So software transactional memory is more aimed at "reasonable performance that scales with the available processors moderately well and is pretty easy to code", rather than giving you absolute maximal performance.
There's a lot of variability between different transactional memory systems though; I'm speaking at quite an abstract and simplified level here.
Comment: I think you're overselling here. TM algorithms are subtle, just as much as are traditional synchronization techniques.  And the resulting bugs can be equally inscrutable.  In any case you generally need a working traditional variant anyway as a fallback for transaction collisions, so there's no free lunch.  STM has largely failed to catch on for these reasons.  HTM in Haswell looks promising, but more so from a performance perspective than an ease of programming one.
Comment: As my programming projects are **far** more limited by available programmer time than by execution speed, I'm more interested in ease-of-programming technologies than performance technologies. STM systems that provide the safety guarantees I'm talking about actually exist now and are usable by me now.
Comment: @AndyRoss: What do you mean by "failed in the market"? It has never really been *in* the market in the first place. It *is* fairly widely used in a few languages (Clojure and Haskell have it built in), but more generally, it has not failed, because it has not really been attempted at a large scale yet. If that constitutes "failed in the market", then I'd like to hear your case for HTM, because that's even less used today. A STM system implemented on top of C is going to be fairly useless, yes, but that doesn't mean "all STM implementations in all languages ever are doomed to fail".
Comment: @AndyRoss: as for your first comment, you might need to elaborate. STM algorithms are a lot easier to work with than traditional synchronization techniques. I can see how HTM-based programming could get a bit trickier, but for STM? I don't see it. I also don't see why you'd need a "traditional" fallback. Any reasonably well designed STM implementation won't need that. I suspect the problem is that *because* STM hasn't *yet* caught on, what we mean by it differs quite a bit. You are obviously thinking of some of the terrible low-tech C implementations which... are a pain to work with
Comment: But STM can be done *a lot* better, which seems to be what Ben and I have in mind.
Comment: **If** the STM system is aiming to provide strong safety guarantees **and** there is a mechanism for enforcing that (a) transactionally shared data is only accessed from within transactions (b) transactions never have side effects, then STM programs are guaranteed to be free of race conditions and deadlocks. Having worked on STM implementations, this is true. Poor use of such an STM system can give you abysmal performance due to contention, but it can't give you deadlocks or race conditions that only cause problems under extremely precise timing conditions.
Comment: Those preconditions aren't true of library based STM implementations for C though, because without language integration there's no way to enforce (a) and (b), and with C it's pretty hard to enforce anything anyway. I don't know as much about HTM, but my understanding is that you again require language integration to give safety guarantees, so using HTM from C or assembler doesn't come with the free lunch, no.
Comment: That's fine.  Just recognize that your perspective is one of an "STM fan".  But STM, quite frankly, has largely failed in the market.  I think you need to rethink this.  HTM has very clear and practical (if limited in scope) performance advantages and is worth investigating.  But no, neither is a panacea.
Comment: HTM is irrelevant to me while the computers I have, and those available to the users I want to run my programs, don't have HTM hardware. But I'm not so much an "STM fan" as a "safe parallel computation" fan. If HTM gives me that, then awesome; what I have seen of the field suggests it will not any time soon (but it may well speed up the *implementations* of safe STM systems, which would be nifty).
Comment: I'd welcome you editing in some more information from a "HTM fan" perspective to my answer. I was trying to avoid talking about any specific systems, but still give a very rough overview of the current "state of play". I'm aware that my knowledge of the HTM side is well below that of the STM side, and also that others *are* interested in systems with a performance advantage that don't provide safety guarantees.
Answer: At the implementation level, transactional memory is part of the cache layer.  It allows software to "try" some operations on memory, and then "commit" them later only if no other multiprocessors in the system modified any of the memory that was read or written.  In very parallel SMP environments where most accesses don't collide, this can be faster than having all threads locking the same (highly contended) synchronization primitives.
It makes the task of the application programmer more difficult, though, because the software has to be able to recover ("rollback") the transaction if the commit fails.
Answer: From the  gcc Wiki:
In general, implementations come in two forms: a Software Transactional Memory
(STM) system uses locks or other standard atomic instructions to do its job.
A Hardware Transactional Memory (HTM) system uses multi-word synchronization
operations of the CPU to implement the requirements of the transaction directly
(e.g., see the Rock processor). Because most HTM systems are likely to be best
 effort facilities (i.e., not all transactions can be executed using HTM),
practical TM implementations that incorporate HTM also have a STM component
and are thus termed Hybrid Transactional Memory systems.

What is transactional memory?


Too many bagging estimators?

Question: I am bagging 20 SVMs using the full training set. I have found the best SVM params using grid search. The validation performance is quite good, but performance on the training set is disappointing.
Can too many bagging estimators lead to over-fitting? What is a good heuristic for the number of estimators to use?
Answer: As far as know,

Overfitting means the predictor performs badly on testing data while it performs well on training data (I have not heard of word like "over-training", maybe you made some typos?)
Why do you train the 20 SVMs on full training set? I suppose you might train them on 20 different "bootstrapped" dataset in bagging.
I believe, in general, the number of SVMs should be the more the better (In theory, the expectation of the mean does not change, but the variance will be reduced more). But you can select it using cross validation.
In bagging, if the SVMs correlate together, the "averaging" is meaningless. So you might want to add more "randomness" into it. Please take a look at random forest, which use a randomly subset of features for each SVM. This will make the aggregated predictor perform better.

Too many bagging estimators?


Multi-Homed AD servers. 1 for production, and 1 for management

Question: In a multi-tenant environment, we have a client that is running a couple of active directory servers on servers that we manage for them.  The servers are multi-homed for a primary network which is connected to the client's VLAN and a management network that is connected to a private VLAN (isolated and promiscuous ports).  Services like Backups, Anti-Malware, Log Inspection, FIM (File Integrity Monitoring) and PAM services run over this management network as well as future services.  Client is utilizing Sharepoint and there are issues with their Sharepoint implementation. They have narrowed down the issues to the AD servers and have disabled these management NICs
Are there any recommended configurations for Sharepoint with a multi-homed environment in which it only uses one of the NICs and not both?  We have already completed the following on the AD servers:

Configure DNS to only listen for DNS queries on the primary NIC
Configured the management NIC to not register the connection's addresses in DNS

We made sure that there were no DNS entries using the management network's IP addresses in DNS

Configured the bindings in the Advanced Settings from the Network Connections window to list the primary NIC first.

Any and all additional recommendations are much appreciated.
Thanks,
Comment: The reason why the DC is multi-homed is because we manage it's security services as well as file and bare metal backups over this management network as I described above.  This is a client server that they are leasing from us and they are using this server as a domain controller (along with other servers in the environment for other purposes, web and SQL for instance).
Comment: Multi-homed domain controller?  That's a paddlin'.
Comment: Why specifically is the DC mutli-homed?
Answer: "Issues with SharePoint" is a bit vague to be useful.  You may want to narrow this down.  Was it DNS?  The DC Locator process?  Are they using DFS? Is it the authentication process that is failing, or do they have some custom code that is failing?
Multi-homed domain controllers will never work perfectly.
You also need to configure the "PublishAddresses" registry value:
Key: HKLM\SYSTEM\CurrentControlSet\Services\DNS\Parameters
Value: PublishAddresses
Value Type: REG_MULTI_SZ
Registry Value Data:<IP address of primary network adapter>

Without this setting, your DNS server may be registering both ip addresses. The interesting part of this is the management adapter address may not always be consistently registered, and since there are multiple ip addresses returned in a query for the domain, the same address is not always selected so reproducing the symptom may be elusive.
Even with PublishAddresses, it's possible that the domain controller may register itself on the other network adapter.  You may sometimes see this if you run:
nltest /dsgetdc:domain.com /server:dcname

You may notice the Address: registered is sometimes the management adapter.
It may be possible to workaround this by running a startup script that runs netsh to disable the management adapter and then re-enable it, but that also may not work reliably 100% of the time.
Another potential area of trouble could be the name servers registered for the zone/delegation in DNS. I would check in DNS to ensure there aren't any occurrences of the ip address of the management adapter for name servers or same as parent.  It should also go without saying that the domain controller name should not have both ip addresses registered using an A/AAAA record.  I would recommend using a different name for the A record for the management adapter.  (dcname-mgmt or something like that).
You may also want to check the ip addresses of your management network adapters and confirm they are not associated with the subnets of any existing sites, or any "catch all" subnets (like 10.0.0.0/8, 172.16.0.0/12, or 192.168.0.0/16).
Comment: Thank you for your response Greg.  I will be following up with my client to dig a little deeper, I just figured I would get some initial insight.  I realize that a multi-homed domain controller is not ideal and certainly not recommended in many ways but it's something we need to have on our client servers to maintain management and compliance of those managed services.
Answer: According to my client, they were having an issue with DNS resolving to the other IP address.  This was more of a timing issue as the DNS entries and DNS configurations on the other NIC were changed after the fact.  DNS chaching needed to be flushed on the other server that was authenticating against the domain controller after the changes were made.


Is there a real example in which a correlation finally leads to the discovery of a non-trivial causal relationship?

Question: More specifically, I am wondering if there is such an example satisfying the following criteria:

The example happened after 1888, it would be better to be after 1900—I think few people have the conception of correlation before Galton's 1888 paper.
The correlation found in the example is not easy to be investigated, but the correlation is non-trivial so that it is published first; then that correlation is investigated further, maybe with much more effort, and is finally confirmed as a result of a non-trivial causal relationship.
The correlation of $A$ and $B$ is a direct result of the causal relationship between $A$ and $B$, and not induced by a common cause $C$.

I understand that correlation is not causation.
Basically, I want to have examples showing that the investigation of correlations sometimes leads to the discovery of really non-trivial causal relationships, and that the conception of correlation really help for those pursuing causality.
Comment: "I think few people have the conception of correlation before Galton's 1888 paper." Paging 18th century Scottish philosopher David Hume…
Comment: Hume is frequently credited with persuasively arguing the concept that correlation is not causation
Comment: @Alexis Pardon me. Do you mean Hume has the conception of correlation? Or ask for some references?
Comment: @Alexis I see. Thanks for referring Hume. I didn't know that he had been considering the conception of correlation so long before.
Comment: @Alexis By the way, do you know any example showing that the conception of correlation and the use of a quantitative measure for correlation is indispensable for the discovery of a causal relationship?
Comment: 1/2 I think the folks doing counterfactual formal causal reasoning (e.g., those in the footsteps of Judea Pearl, including C. Glymour, M. Glymour, J. Robins, S. Greenland, P. Spirtes, and M. Hernán among others) would say that that there are necessary rules for producing correlations which can be interpreted causally. That said, there are other approaches (philosophical and methodological) to the analysis of causality. Levins' qualitative loop models are purely deductive in their analysis (though their predictions can be linked to correlations).
Comment: 2/2 Depending on your definition of correlation, you might or might not consider state space reconstruction methods in the tradition of Takens and especially Sugihara to be correlational measures used create causal evidence and discovery.
Answer:
Lung cancer was not even recognised medically until the 18th century, and as recently as 1900 only about 140 cases were known in the published medical literature. ... Tobacco was apparently not even suspected as a cause of lung tumours until the final decade of the 19th century. ... Scholars started noting the parallel rise in cigarette consumption and lung cancer, and by the 1930s had begun to investigate this relationship using the methods of case-control epidemiology.

Proctor, 2012. "The history of the discovery of the cigarette–lung cancer link: evidentiary traditions, corporate denial, global toll". Tobacco Control.


Ignorando uma linha de um arquivo txt

Question: Fiz uma leitura de um arquivo .txt onde desejo separo cada palavra por virgula, ou seja, ao se encontrar um espaço antes da palavra e depois.
Mas também necessito ignorar toda a linha do txt onde se encontra o caracter ##.
Abaixo segue o código que eu estava utilizando para separa em vírgula:
def LeArquivo(arquivo):
linhas = arquivo.readlines()

texto = []

for line in linhas:
    line = line.strip().split(' ')
    texto.append(line)

return texto

Aqui esta o código que eu estava tentando utilizar para retirar o ##
def LeArquivo(arquivo):
linhas = arquivo.readlines()

texto = []

for line in linhas:
    line = line.strip().split(' ')
    if line.find('##') != 0:
        texto.append(line)

return texto

Mas ocorre um erro ao executar: AttributeError: 'list' object has no attribute 'find'
Answer: Questão de ordem dos comandos, você está transformando a string lida em uma lista e aí fazendo a comparação mas como as listas não possuem o método .find() você obtém uma mensagem de erro.
Baseado na tua função uma versão passo a passo...
def le_arquivo(nome_do_arquivo):
    # 1. cria a lista
    texto = []
    # 2. Abre o arquivo para leitura
    with open(nome_do_arquivo, "r") as arquivo:
        # 3. Lê cada linha do arquivo por vez
        for linha in arquivo:
            # 4. Os dois primeiros caracteres não são "##"?
            if linha[0:2] != "##":
                # 5. Então quebre a string e adicione à lista
                texto += [linha.strip().split(" ")]
    # 6. Devolve a lista
    return texto

Uma outra coisa você poderia até substituir o line.find('##') != 0 por '##' not in line mas você estaria desnecessariamente processando uma string para depois não usá-la, daí fica mais eficiente você validar o caso para depois processar.
Comment: A condição também poderia ser `if(not linha.startswith('##')):...`. Boa resposta/explicação
Comment: cool! desconhecia o `"##" not in str`
Comment: Obrigado pela ajuda @Giovanni, funcionou perfeitamente aqui! Com as suas dicas até consegui fazer outras partes do código que eu precisava. Vlw!
Answer: Já agora uma versão mais compacta da versão (e menos legível) da resposta @Giovanni
(sou um bocado viciado em listas por compreensão)
def le(nome):
    with open(nome, "r") as arquivo:
        return[ l.split() for l in arquivo if "##" not in l ]
    return []

print(le("exemplo.txt"))

Ignorando uma linha de um arquivo txt


I am not able to import all vm in hyperv

Question: When importing the VM from hyper-v server not allow to import all VM?
New server 2016 is installed and tried to import the all VM but not allowed.
Comment: actual error messages would be helpful
Comment: Questions seeking installation, configuration or diagnostic help must include the desired end state, the specific problem or error, sufficient information about the configuration and environment to reproduce it, and attempted solutions. Questions without a clear problem statement are not useful to other readers and are unlikely to get good answers.
Comment: I installed server 2016 on new machine and tried to import all VM from old server but when selecting the VM there is no option to select the all VM. It allows only one VM at a time?
Comment: Edit it into the question, it should be self-contained.
Answer: that's is correct the importing through the console only allows one vm at a time to be imported. have your tried using powershell to import the VMs?


Using Javascript in Ruby

Question: In my Rails project, I have a file /app/assets/javascripts/bootstrap-tab.js which allows me to use tabs in my Rails project, which uses Twitter Bootstrap HTML.
I also have a file /app/views/folder1/show.html.erb that uses the tabs:

Tabs

Tab1

Tab2

        Text1

        <%= @myobject.name %>

        Text2

However I need it to know where the javascript file is. What is the ruby way to do this? Would I still just put something like

into the show.html.erb? And if so, what path would I put?
Comment: Are you using Rails 3? Is there a reason why you don't want to include it in the main asset pipeline (e.g. have `//= require bootstrap-tab.js` in your main `application.js` file)?
Comment: okay, that's what I was looking for. let me try that out.
Answer: There is no need for you to link to the Javascript file. Rails does this automatically and includes it in the Assets pipeline, which then makes it available to all your app. Read this guide: http://guides.rubyonrails.org/asset_pipeline.html. It discusses how to the asset pipeline works and its advantages.
If for some reason (I can't think of any), the javascript file is not being included in the asset pipeline even though it is in the appropriate location (as it seems to be), maybe you should explicitly include it in your application.js file.
Answer: If you want the js file to be added to only 1 view and not other then you could use something like this
<%= javascript_include_tag "bootstrap-tab" %>

For more read 3.1.2
http://guides.rubyonrails.org/layouts_and_rendering.html#asset-tag-helpers

Using Javascript in Ruby


What are the assumptions of factor analysis?

Question: I want to check if I really understood [classic, linear] factor analysis (FA), especially assumptions that are made before (and possibly after) FA.
Some of the data should be initially correlated and there is a possible linear relation between them. After doing factor analysis, the data are normally distributed (bivariate distribution for each pairs) and there is no correlation between factors (common and specifics), and no correlation between variables from one factor and variables from other factors.
Is it correct?
Answer: Input data assumptions of linear FA (I'm not speaking here about internal assumptions/properties of the FA model or about checking the fitting quality of results).

Scale (interval or ratio) input variables. That means the items are either continuous measures or are conceptualized as
continuous while measured on discrete quantitative scale. No ordinal data in linear FA (read). Binary data should also be avoided (see this, this). Linear FA assumes that latent common and unique factors are continuous. Therefore observed variables which they load should be continuous too.
Correlations are linear. Linear FA may be performed based on any SSCP-type association matrix: Pearson correlation, covariance, cosine, etc (though some methods/implementations might restrict to Pearson correlations only). Note that these are all linear-algebra products. Despite that the magnitude of a covariance coefficient reflects more than just linearity in relation, the modeling in linear FA is linear in nature even when covariances are used: variables are linear combinations of factors and thus linearity is implied in the resulting associations. If you see/think nonlinear associations prevail - don't do linear FA or try to linearize them first by some transformations of the data. And don't base linear FA on Spearman or Kendall correlations (Pt. 4 there).
No outliers - that's as with any nonrobust method. Pearson correlation and similar SSCP-type associations are sensitive of outliers, so watch out.
Reasonably high correlations are present. FA is the analysis of correlatedness, - what's its use when all or almost all correlations are weak? - no use. However, what is "reasonably high correlation" depend on the field of study. There is also an interesting and varied question whether very high correlations should be accepted (the effect of them on PCA, for example, is discussed here). To test statistically if the data are not uncorrelated Bartlett's test of sphericity can be used.
Partial correlations are weak, and factor can be enough defined. FA assumes that factors are more general than just loading pairs of correlated items. In fact, there even an advice not to extract factors loading decently less than 3 items in explotatory FA; and in confirmatory FA only 3+ is guaranteed-identified structure. A technical problem of extraction called Heywood case has, as one of the reasons behind, the too-few-items-on-factor situation. Kaiser-Meyer-Olkin (KMO) "sampling adequacy measure" estimates for you how weak are partial correlations in the data relative the full correlations; it can be computed for every item and for the whole correlation matrix. Common Factor analysis model assumes that pairwise partial correlations are enough small not be bothered about and modelled, and they all fall into that population noise for individual correlation coefficients which we don't regard any differently from the sample noise for them (see).  And read also.
No multicollinearity. FA model assumes that all items each posesses unique factor and those factors are orthogonal. Therefore 2 items must define a plane, 3 items - a 3d space, etc: p correlated vectors must span p-dim space to accomodate their p mutually perpendicular unique components. So, no singularity for theoretical reasons$^1$ (and hence automatically n observations > p variables, without saying; and better n>>p). Not that complete multicollinearity is allowed though; yet it may cause computational problems in most of FA algorithms (see also).
Distribution. In general, linear FA does not require normality of the input data. Moderately skewed distributions are acceptable. Bimodality is not a contra-indication. Normality is indeed assumed for unique factors in the model (they serve as regressional errors) - but not for the common factors and the input data (see also). Still, multivariate normality of the data can be required as additional assumption by some methods of extraction (namely, maximum likelihood) and by performing some asymptotic testing.

$^1$ ULS/minres methods of FA can work with singular and even non p.s.d. correlation matrix, but strictly theoretically such an analysis is dubious, for me.
Comment: ,could you read [this post](https://stats.stackexchange.com/questions/290589/what-kind-of-outlier-should-be-removed-from-factor-analysis/290609?noredirect=1#comment561343_290609),it seemed little different.
Comment: If `Binary data should also be avoided`,what else factor analysis method can we do for `binary data`?
Comment: dear ttnphns; I notice that you don't mention that the data are assumed normal and other online indicate that normality is not required. My query is if the latent variables are assumed normal, and the observations are modelled as a weighted sum of the factors does this then not imply a normal distribution on the observations? (I'm sorry im sure this is a dumb question)
Comment: @user2957945, Paragraph 7 says about normality. Normality assumption is necessary for some methods of factor extraction and for performin some statistical tests facultatively accompanying factor analysis. To your question: Yes, if factors are distributed normally and errors normally too, that will mean manifest variables are also normal.
Comment: ah, thanks @ttnphns; sorry to bother you -- I dont quite know how I managed to miss that.  Appreciate your help.
Answer: Much of the time, factor analysis is conducted without any statistical tests per se.  It is much more subjective and interpretive than methods such as regression, structural equation modelling, and so on. And generally it is inferential tests that come with assumptions:  in order for p values and confidence intervals to be correct, those assumptions must be met.
Now, if the method for choosing the number of factors is set to be the maximum likelihood method, then there is an assumption that goes with this:  that the variables input into the factor analysis will have normal distributions.
That the input variables will have nonzero correlations is a sort of assumption in that without it being true, factor analysis results will be (probably) useless:  no factor will emerge as the latent variable behind some set of input variables.
As far as there being "no correlation between factors (common and specifics), and no correlation between variables from one factor and variables from other factors," these are not universally assumptions that factor analysts make, although at times either condition (or an approximation of it) might be desirable.  The latter, when it holds, it known as "simple structure."
There is another condition that is sometimes treated as an "assumption":  that the zero-order (vanilla) correlations among input variables not be swamped by large partial correlations.  What this means in a nutshell is that relationships should be strong for some pairings and weak for others; otherwise, results will be "muddy."  This is related to the desirability of simple structure and it actually can be evaluated (though not formally "tested") using the Kaiser-Meyer-Olkin statistic, or the KMO.  KMO values near .8 or .9 are usually considered very promising for informative factor analysis results, while KMOs near .5 or .6 are much less promising, and those below .5 might prompt an analyst to rethink his/her strategy.
Comment: After application of Factor analysis, if we have used orthogonal rotation, we will be sure that there is no correlation between factors
Comment: As i read, that factor analysis starts with some correlation with variables and we try to make this correlation more and more clear
Answer: Assumptions underlying exploratory factor analysis are:
• Interval or ratio level of measurement
• Random sampling
• Relationship between observed variables is linear
• A normal distribution (each observed variable)
• A bivariate normal distribution (each pair of observed variables)
• Multivariate normality
Above from the SAS file


Squier Stratocaster's Bridge Lift After Restringing with Ernie Ball Beefy Slinkies

Question: Squier Strat, my high E string snapped yesterday, so I replaced all strings.
I used Ernie Ball's Beefy Slinky (2627) with following gauge numbers:

E (11)
B (15)
G (22p)
D (30)
A (42)
E (54)

When tuning, I found a LOT of resistance from the strings when tuning to standard EADGBE. My gut told me that something's off, and I saw the bridge lifting up all the way. Immediately relaxed pressure by loosening the strings, to not damage it.
My guess: I used the incorrect gauge (Guy at guitar center suggested 2627 Beefy Slinky). Please do offer your suggestions.
Comment: From Sweetwater: "These strings are perfect for those who love to detune their guitars." From a Google review: "These strings are super for their designed purpose. Low tuning. I used them on a Lap Steel Guitar in Low Open G; DGDGBE"
Comment: Store should have a micrometer. Take your old strings in & get them measured, assuming you want something similar. I use fat strings… but they're FAT.
Answer: Sounds like the old strings were a lot lighter in gauge. The compensating springs connecting the underside of the mechanism will need tightening (or even adding to) to compensate for the extra tension the new strings exert.
In fact, unless you want beefy strings, which will be more difficult to bend, but give you a fatter sound, go for a lighter gauge set anyway. The neck, thus action, will also probably need some tweaking to compensate too - trussrod most likely.
Not knowing what was already on, it's impossible to give any more than these vague instructions. But for me, they're too heavy for standard Strat playing.
Comment: I expect adjusting the springs would fix this up. I have used routinely "heavy lights" on a strat which are not all that different. I currently have the tremolo blocked, but prior to that I the spring tension was sufficient. Easy enough to adjust considering the OP prob has the back off to change the strings anyway. I don't use drop tuning
Comment: @Yorik - didn't consider it necessary to take the back plate off to change strings!
Comment: on a strat, the alignment of the slot (in the cover plate) with the string holes (in the tremolo mechanism) can be offset depending on the string tension.


Error: Do you have azure>=2.0.0 installed?

Question: I am getting below error when I run ansible playbook:

Do you have azure>=2.0.0 installed? Try pip install 'azure>=2.0.0' --upgrade- No module named containerservice

Ansible version:
ansible 188.8.131.52
config file = /var/www/Ansible/ansible.cfg
configured module search path = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.12 (default, Jul 18 2016, 15:02:52) [GCC 4.8.4]

Azure:
Name: azure
Version: 2.0.0rc5
Summary: Microsoft Azure Client Libraries for Python
Home-page: https://github.com/Azure/azure-sdk-for-python
Author: Microsoft Corporation
Author-email: firstname.lastname@example.com
License: MIT License
Location: /usr/local/lib/python2.7/dist-packages
Requires: azure-servicemanagement-legacy, azure-batch, azure-servicebus, azure-mgmt, azure-storage, azure-graphrbac

I tried to install this: pip install azure-mgmt-containerservice But, now below error is coming:

Installed resource client version is 0.30.0rc5. The supported version is 1.1.0. Try pip install azure>=2.0.0 --upgrade
Answer: Easiest way to fix this is to reinstall ansible with
pip install ansible[azure]

this will install all the azure dependencies automatically. there is currently a discrepancy between package(s) in azure 2.0.0 and ansible requirements for 184.108.40.206
ps. your azure module is really outdated. like 2 years outdated.
Comment: just delete it (azure module), you probably cannot update from rc5.
Comment: I ran the given command. Error: `Do you have azure>=2.0.0 installed? Try `pip install 'azure>=2.0.0' --upgrade`- No module named azure.mgmt.network.models`
Comment: Azure module is outdated means you're talking about `rc5`?
Comment: It's working. Thanks! Just installed `msrestazure` package after ansible installation. `sudo -H pip install msrestazure`


MySQL Error - Not sure whats wrong with SQL Command

Question: CREATE TABLE Sponsors (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Sponsor_Id` int(11) DEFAULT NULL,
  `Runner_Id` int(11) DEFAULT NULL,
  `Charity_Id` int(11) DEFAULT NULL,
  `Subscription_Id` varchar(25) DEFAULT NULL,
  `Customer_Id` varchar(25) DEFAULT NULL,
  `Customer_Email` varchar(75) DEFAULT NULL,
  `APM` int(11) DEFAULT '1',
  `MinAPM` int(11) DEFAULT '5',
  `MaxAPM` int(11) DEFAULT '100',
  `Created_at` int(11) NOT NULL,
  `CharityId` int(11) NOT NULL,
  `CharityName` varchar(250) NOT NULL,
  `CharityCity` varchar(250) NOT NULL,
  `CharityState` varchar(250) NOT NULL,
  `CharityCategory` varchar(250) NOT NULL,
  `Total_Donations` int(11) NOT NULL,
  `Monthly_Donations` int(11) NOT NULL,
  `Distance` float NOT NULL,
  PRIMARY KEY (Id)
)

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE Sponsors (
'Id' int(11) NOT NULL AUTO_INCREMENT,
  'Sponsor_Id'
Comment: I'd guess you're trying to run a dump file using an API that doesn't support multi-query.
Comment: You will also find that using straight single quotes won't work to delimit column names. Straight quotes are for string literals or date literals. Back-ticks are for delimiting identifiers like table names or column names.
Comment: just replaced the single quotes with back-ticks and still nothing.  You are correct that this is a dump file.  Exporting from one DB to another...
Comment: How are you running the dump file?
Comment: Are you running this as php? The comments under the answer you accepted suggests it. I also feel that you accepted the answer "just cuz". You state that there was already code used in yours and what the answer holds seem to contradict everything. @CorrieByrd
Answer: CREATE TABLE Sponsors (
  `Id` int(11) AUTO_INCREMENT NOT NULL,
  `Sponsor_Id` int(11) DEFAULT NULL,
  `Runner_Id` int(11) DEFAULT NULL,
  `Charity_Id` int(11) DEFAULT NULL,
    primary key (id)
)

Comment: nevermind....running it as query works...importing it from the SQL file is not....
Comment: primary key was at the bottom of the full code. i just added the rest of it.
Comment: no, it was always there, i just failed to post it here.
Comment: what mysql version are you using?
Comment: Also try running my answer as a query and let me know if you are getting any errors
Comment: I am using MySQL 5.5
Comment: yeah...thank you very much. i was beating my head against a wall.
Comment: ok great, so please can you mark this as the correct answer for other users to use as a reference


How to determine order of sarima?

Question:

hey, I have a dataset that contains hourly wind speeds. When I plotted my original acf, it showed seasonality at every 24 lags so I applied a difference of 24 to remove seasonality and another difference to remove trends. The diagrams shows the resulting acf and pacf, how do I determine the order of the arima model. Also I am seeing that at every 24 lags in the pacf there is a spike and decaying slowly, is this suppose to happen or does my dataset still contains stationarity?
Comment: show the original ACF/PACF
Comment: That does look very puzzling. What meteorology is it that implies that raw autocorrelations are negative at lag 1 hour and strongly negative at lag 24 hours (but negligible at 48(24)whatever hours)? Can you show the original data (or a sample of them)?
Comment: There is simple jargon for this that isn't even jargon: variation with time of day. Why call it seasonality?
Comment: Why don't you post the actual data ?
Answer: A good starting point can be the forecast package of prof Hyndman in R. The auto.arima() function can give you a suitable model and this can be a good starting point of your investigation. I have learned a lot from his open book https://www.otexts.org/fpp/
Comment: yes it does. various aspects like max seasonal differencing etc. can be explicitly given as argument. [documentation](https://www.rdocumentation.org/packages/forecast/versions/8.1/topics/auto.arima)
Comment: Does it handle seasonality?
Comment: unfortunately it assumes no pulses , no level shifts , no seasonal pulses , no local time trends, constant parameters over time , consyabt error variance over time ....
Comment: Unfortunately I am also pretty new to this forecasting business, I have learned a lot from your comments on this site. If you could elaborate how can the aforementioned be incorporated/handled it would be very helpful.
Comment: https://stats.stackexchange.com/questions/317734/interrupted-time-series-analysis-arimax-for-high-frequency-biological-data/317804#317804 where @adamo succinctly and quite correctly reflected "The correlogram should be calculated from residuals using a model that controls for intervention administration, otherwise the intervention effects are taken to be Gaussian noise, underestimating the actual autoregressive effect."
Comment: @IrishStat: I do not sufficient point that's why commenting here. Thank you very much for your very insightful response below. I will spend some more time reading and then will get back to you.
Answer: In response to Pankaj Joshi (thanks for asking !):  See Interrupted Time Series Analysis - ARIMAX for High Frequency Biological Data? where @AdamO  correctly reflected/opined "The correlogram should be calculated from residuals using a model that controls for intervention administration, otherwise the intervention effects are taken to be Gaussian noise, underestimating the actual autoregressive effect.". This comment reflects the fact that if there are interventions present they effectively mask the true (but unknown) arima structure. Prof. J.K.Ord once commented to me that is is like the "Alice in Wonderland effect".
Interventions must be specified either by the user or detected by Intervention Detection procedures. The problem/opportunity is to simultaneously identify BOTH arima structure & the Interventions as is done by AUTOBOX, a piece of software that I have helped to develop.
Since auto.arima naively assumes no Intervention series and constant parameters over time and constant error variance over time it is easily confused and delivers inadequate results which is frequently cited in these pages .
Complete transparency suggests that I mention https://cran.r-project.org/web/packages/tsoutliers/index.html as a tool to identify interventions which requires the user to pre-specify the form of the ARIMA model and fails to consider time varying parameters and time varying error variance.
So the erroneously suggested "logic" goes ..  use a two step approach STEP 1:... use auto.arima to identify the ARIMA portion assuming no interventions present in the data THEN in STEP 2 identify the interventions that were assumed not to be present in the first step. Patch the two answers together !
If you wish you can post your data and I will report the results of a simultaneous identification strategy where embedded interdependent heuristics are employed to simultaneously suggest a possibly useful answer.
Comment: Is there a way I can upload my dataset, it contains 14376 points? When I use the auto.arima in R it gives me a (0,1,1) model, however when I plot the acf of the residuals you can clearly see a periodic output. Any help?
Comment: hey i sent the document with the hourly wind speed data for you.
Comment: . I took the first 2400 and obtained a model that had an AR(1)  and a few hourly dummies …

There doesn't appear to be any justification for any differencing whatsoever  for the first 2400 values. Visually the first 2400 look like rest of jhe series thus I would go with seasonal dummies and an ar(1) plus pulse indicators
Comment: Finally .. if a series has a level shift (determinstic structure is present) the ACF will suggest non-stationarity (which is true). The correct remedy is to de-mean the series NOT to difference the series. The moral of my story is that a series may be non-stationary as suggested by the correlogram BUT the remedy is not necessarily differencing. Your series is driven by strong seasonal dummies (deterministic structure) and should be modelled using them

How to determine order of sarima?


Do I need stationary time series for Bayesian structural time series (BSTS)?

Question: I'm trying to model with BSTS, with exogenous variables.
It appears that my y-sequence is not stationary. Do I need to diff that to stationary? Or could BSTS handle that?
P.S. I'm using R package bsts
Thank you for your time!
All the best,
Kathy
Answer: No, you don't need to make the time series stationary.
BSTS should be able to handle that. Stationarity is a requirement specifically for AR and ARMA models.
BSTS is supposed to handle structural changes in the time series, which means that by definition it should be able to handle non-stationary data - since a structural change in the time series would imply changes to the mean and variance of the series.


Drupal Lightbox 2 not displaying image

Question: http://www.wmfs.net/blackcountrylevel3plan
I have the Isotope working with Lightbox2, however the Lightbox is just displaying a blank space and not the image.
I am trying different things to troubleshoot the problem, different configurations in Drupal, putting the JS in the header and footer, there are no significant JS errors in Web Inspector.
Any help is gratefully appreciated.
Ant
Answer: as i see in the console, you are using jquery.min.js?v=1.9.1
and lightbox.js is giving this error:

TypeError: $.browser is undefined

because this function has been remove since 1.9
I'll suggest you to use default jquery version 1.4.2 where $.browser is deperecated but should work or use another ligtbox module like colorbox
Comment: I'm using Colorbox now which works, but isn't working on mobile, instead of the JS effect the image is just linking to a larger image.
Comment: Looking for a fix now....

Drupal Lightbox 2 not displaying image


Listar dados de procedure sqlsrv PHP

Question: Bom dia,
alguém com experiência em PHP e drive sqlsrv da microsoft ?
Encontrei dificuldade para exibir dados de uma procedure no SQL SERVER com o driver "Microsoft sqlsrv".
Algo de estranho esta acontecendo que não gera nenhum retorno.
O que pode estar falando ou de errado no código por favor.
$serverName = "SRVSQLDEALER\XXX";

$connectionInfo = array( "Database"=>"DB", "UID"=>"USER", "PWD"=>"KEY");

$conn = sqlsrv_connect( $serverName, $connectionInfo);

if ( $conn ){

$var1 = '3610';
$var2 = '2020-10-29';

$procedure_params = array(

array(&$myparams['CodigoEmpresa'], SQLSRV_PARAM_OUT),
array(&$myparams['DataReferencia'], SQLSRV_PARAM_OUT)

);

$sql = "EXECUTE dbRedeMineira.dbo.whCRLDocumentosReceber @CodigoEmpresa = ?, @DataReferencia = ? " ;

$stmt = sqlsrv_query($conn,$sql,array($var1, $var2));

echo $conn."
";
echo $sql."
";
echo $stmt."

";

$numFields = sqlsrv_num_fields( $stmt );
$numListen = sqlsrv_num_rows( $stmt );
$numAfect  = sqlsrv_rows_affected( $stmt );
echo "Total de linhas > ".$numListen." .... Total de colunas > ".$numFields." .... Total afetado > ".$numAfect."

";

if (!sqlsrv_execute($stmt)) {
    echo "Your code is fail!";
die;
}

if ($stmt = sqlsrv_prepare($conn, $sql)) {

        while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {

              echo $row['DataReferencia']."
";

        }

    } else {
        echo "Statement could not be prepared.\n";
        die(print_r(sqlsrv_errors(), true));
    }

Sendo que esta exibindo uma query normal, retorna todos valores corretos.
            $stmt =sqlsrv_query($conn,"SELECT * FROM usuario");

            while( $row = sqlsrv_fetch_array($stmt)){

                echo $row['login']."
";
            }

Answer: A conexão consegui fazer da seguinte maneira
 try {
 $con = new PDO('sqlsrv:Server=SERVIDOR;Database=DB', 'USER', 'SENHA' );
 $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 } catch (Exception $ex) {
 print_r('Error: ' . $ex->getMessage());
 }

Agora só falta listar os dados.
Answer: tente assim amigo.
$query = "EXEC PROCEDURE @CodigoEmpresa = ?, @DataReferencia = ? ";

$prepare = $con->prepare($query);

$prepare->execute();

while ($result = $prepare->fetch(PDO::FETCH_ASSOC)) {
print_r($result['XXXXXXXXX']."
"); // colunas a serem exibidas
}

Comment: PErfeito, consegui assim obrigado.

Listar dados de procedure sqlsrv PHP


Does it make sense to use `ordered_set` for `select` statement with `>` and `<=` for lowering time compexity

Question: I use ETS table of type ordered_set, and row looks like {{integer_value, string}} (basically it has no value, only key).
When I perform ets:select(tab, [match_spec]), what match_spec does is selecting all rows, where integer_value meets greater than and lower than comprehensions.
I wonder, do I benefit and instead of scanning whole table, find both lower and upper bounds in logarithmic time and then get all elements in between, like I would expect from SQL table, or such functionality is not implemented in ETS and there is no particular benefit from using ordered_set instead of ordinary set?
Answer: Simple way is using timer:tc/3 function for getting execution time of your functions or ets module's functions.
You can profile your code using fprof or eprof for undestanding what function called and how much time it takes for its execution.
This can help you.
If you are not familiar with erlang profilers, i can show simple example of ets set and ordered_set with profilers.
Comment: I already discovered (in the topic last updated in 2011 :)) that `ets` scans whole table no matter what, whenever it is sorted set or not. But struggle to get info and 'freshness' of links makes me worry about how alive erlang community and erlang itself today


Filter variable by date

Question: I have a column in my data file in Stata for dates that looks like this:
1/29/2018 16:28:02

What is the syntax to filter by date?
For example, to find all observations where the date is January 29, 2018?
Something like keep if data > ???
The date is in red which I believe means string.
Answer: Consider the following toy example:
clear

input str20 string_date
"1/14/2018 18:28:02"
"1/19/2018 16:12:13"
"1/26/2018 17:54:43"
"2/11/2018 20:34:25"
"3/29/2018 22:21:01"
end

You first need to convert the string variable to numeric:
generate double numeric_date = clock(string_date, "MDY hms")
format numeric_date %tc

list

     +-----------------------------------------+
     |        string_date         numeric_date |
     |-----------------------------------------|
  1. | 1/14/2018 18:28:02   14jan2018 18:28:02 |
  2. | 1/19/2018 16:12:13   19jan2018 16:12:13 |
  3. | 1/26/2018 17:54:43   26jan2018 17:54:43 |
  4. | 2/11/2018 20:34:25   11feb2018 20:34:25 |
  5. | 3/29/2018 22:21:01   29mar2018 22:21:01 |
     +-----------------------------------------+

Then you must to find the unformatted value of interest:
display %15.0g numeric_date[4]
1834000465000

list if numeric_date == 1834000465000

     +-----------------------------------------+
     |        string_date         numeric_date |
     |-----------------------------------------|
  4. | 2/11/2018 20:34:25   11feb2018 20:34:25 |
     +-----------------------------------------+

or:
keep if numeric_date == 1834000465000

Type help format and help datetime_display_formats for more details on working with datetimes.

Filter variable by date


Enviar formulário com campos ocultos

Question: Galera, seguinte, eu tenho um formulário com dois selects ocultos, eles serão exibidos somente quando eu selecionar uma das opções no select pai, porém toda vez que faço o envio deste ele pega o valor de um select oculto. Tem alguma maneira de fazer com ele só pegue o valor se eu selecionar a opção no select pai ?
Este é meu formulário:
<form id="createusers" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" class="needs-validation" oninput='userrepassword.setCustomValidity(userrepassword.value != userpassword.value ? "Senhas não conferem." : "")' novalidate>

          <input id="username" name="username" placeholder="Usuário" type="text" aria-describedby="usernameHelpBlock" required="required" class="form-control">

Por favor, digite um nome de usuário válido.

        Digite um nome de usuário.

          <input id="userpassword" name="userpassword" placeholder="Senha" type="password" required="required" class="form-control" aria-describedby="userpasswordHelpBlock">

Por favor, digite uma senha.

        Digite uma senha para o usuário. Sua senha deve ter no mínimo 6 caracteres.

          <input id="userrepassword" name="userrepassword" placeholder="Confirme a senha" type="password" required="required" class="form-control" aria-describedby="userrepasswordHelpBlock">

Por favor, confirme a senha.

        Confirme a senha.

        Informe o grupo do usuário
        <select id="usergroup" name="usergroup" class="form-control" required>
          <option value="">-- Selecione uma opção --</option>
          <option value="neg">Negado</option>
          <option value="tot">Total</option>
          <option value="controlado">Controlado</option>
          <option value="restrito">Restrito</option>
          <option value="lib">Liberado</option>
          <option value="noc">No Cache</option>
        </select>

Por favor, selecione uma opção para informar o grupo do usuário.

        Selecione um grupo para o usuário.

        Selecione o grupo controlado para o usuário
        <select id="usergroup-controlado" name="usergroup" class="form-control">
          <option value="c01">Controlado 01</option>
          <option value="c02">Controlado 02</option>
          <option value="c03">Controlado 03</option>
        </select>

        Selecione o grupo restrito para o usuário
        <select id="usergroup-restrito" name="usergroup" class="form-control">
          <option value="r01">Restrito 01</option>
          <option value="r02">Restrito 02</option>
          <option value="r03">Restrito 03</option>
          <option value="r04">Restrito 04</option>
          <option value="r05">Restrito 05</option>
          <option value="r06">Restrito 06</option>
          <option value="r07">Restrito 07</option>
          <option value="r08">Restrito 08</option>
          <option value="r09">Restrito 09</option>
        </select>

            <input id="userconfirm_0" name="userconfirm" type="checkbox" required="required" class="custom-control-input" value="userconfirm">
            Confirme para criar o usuário

Por favor, confirme para criar o usuário.

        <button id="submitcreateuser" name="submitcreateuser" type="submit" class="btn btn-primary">Criar Usuário</button>

    </form>

E para ocultar estes selects uso os seguintes scripts:

E este é o script que faz o envio do formulário, onde obtenho as informações preenchidas:
<?php
        if(isset( $_POST['submitcreateuser'] )) {
            $fullname = $_POST["fullname"];
            $username = $_POST["username"];
            $userpassword = $_POST["userpassword"];
            $userrepassword = $_POST["userrepassword"];
            $networkaccess = $_POST["networkaccess"];
            $usergroup = $_POST["usergroup"];
            $createuser = "$username $fullname $networkaccess $usergroup $userpassword $userrepassword s -a; echo $?";

            echo "
 >> $createuser <<
";

        }
    ?>

Os selects ocultos são os do grupo Controlado e Restrito, quando selecionar essas opções ele abre outro select com as opções respectivas, tipo Controlado ele irá exibir o select Controlado 01, Controlado 02, Controlado 03. E assim serve também para a opção Restrito.
Tem algo de errado no meu formulário ?
Comment: Se a pergunta não estiver bem clara, peço por gentileza que me informem, pois estou precisando de ajuda com este projeto que irei apresentar.
Answer: Em todos os select você usa o mesmo name="usergroup" vai sobrescrever no envio.
Eu aconselharia você a tratar dentro do php como o amigo acima falou, no select exibido quando selecionado controlado no pai você coloca o name="usergroupcontrol" e em restrito coloca name="usergrouprestricted", ai com o nome do pai na variável $usergroup você sabe qual valor dos selects pegar.
Comment: Ah sim, eu pensei nisso, porém como eu vou passar isso pro script que faz a leitura das variáveis depois ? Exemplo, eu pego e divido os valores como você disse, no `select` Restrito colocaria o `name="usergrouprestricted"` e no script que faz o envio do formulário na linha onde passa todas as variáveis ficaria como ?

Enviar formulário com campos ocultos


Merge two different deep learning models in Keras

Question: I have two different types of data (image volumes and coordinates) and I would like to use a convolutional neural network on the image volume data and then after this I would like to append some additional information (ie. the coordinates of the volume).
Independently this should create a pretty solid predictor for my function. How can I implement this using Keras.
The only answers I have found online are either ambiguous or are using the deprecated methods which I have got to work. But I would really like to implement this using the current API that way I can more easily save the model for later use.
model = Sequential()
model.add(Conv3D(32, kernel_size=(3, 3, 3),
                 activation='relu',
                 input_shape=input_shape))
model.add(Conv3D(64, (3, 3, 3), activation='relu'))
model.add(MaxPooling3D(pool_size=(2, 2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
print(model.output_shape)

# The additional data (the coordinates x,y,z)
extra = Sequential()
extra.add(Activation('sigmoid', input_shape=(3,)))
print(extra.output_shape)

merged = Concatenate([model, extra])

# New model should encompass the outputs of the convolutional network and the coordinates that have been merged.
# But how?
new_model = Sequential()
new_model.add(Dense(128, activation='relu'))
new_model.add(Dropout(0.8))
new_model.add(Dense(32, activation='sigmoid'))
new_model.add(Dense(num_classes, activation='softmax'))

new_model.compile(loss=keras.losses.categorical_crossentropy,
              optimizer=keras.optimizers.Adadelta(),
              metrics=['accuracy'])

Answer: Sequential models are not suited for creating models with branches.
You can have the two independent models as Sequential models, as you did, but from the Concatenate on, you should start using the functional Model API.
The idea is to get the output tensors of the two models and feed them in other layers to get new output tensors.
So, considering you have model and extra:
mergedOutput = Concatenate()([model.output, extra.output])

This mergetOutput is a tensor. You can either create the last part of the model using this tensor, or create the last part independently, and call it on this tensor. The second approach may be good if you want to train each model separately (doesn't seem to be your case).
Now, creating the new model as a functional API model:
out = Dense(128, activation='relu')(mergetOutput)
out = Dropout(0.8)(out)
out = Dense(32, activation='sigmoid')(out)
out = Dense(num_classes, activation='softmax')(out)

new_model = Model(
    [model.input, extra.input], #model with two input tensors
    out                         #and one output tensor
)

An easier approach is to take all three models you have already created and use them to create a combined model:
model = Sequential() #your first model
extra = Sequential() #your second model
new_model = Sequential() #all these three exactly as you did

#in this case, you just need to add an input shape to new_model, compatible with the concatenated output of the previous models.
new_model.add(FirstNewModelLayer(...,input_shape=(someValue,)))

Join them like this:
mergedOutput = Concatenate()([model.output, extra.output])
finalOutput = new_model(mergedOutput)

fullModel = Model([model.input,extra.input],finalOutput)

Comment: Thank you very much for clarifying the example in the API. I appreciate it!
Comment: One more question, how can I save and load this kind of model. Is it sufficient to save just the fullModel?
Comment: Unfortunately I have never been able to save a model in keras. I don't know why. What I do is `fullModel.save_weights(filename)` and `fullModel.load_weights(filename)`. This is enough to save and load a learned model, but may cause difficulties when you want to start training again (the optimizer is lost in this process and will have to adjust itself again during training).
Comment: @DanielMöller Could you have a look at [this](https://ai.stackexchange.com/questions/18514/struggling-to-find-a-better-solution-for-merging-outputs-of-two-separate-layers)?
Answer: Use the functional API of Keras (https://keras.io/models/model/). You can just apply layers to your merged layer in Keras. The functional API works like this. You have a tensor and you apply a function to this Tensor. Then this is recursively evaluated. Because pretty much everything is a tensor in Keras this works quite nicely.
An example for this is:
activation = Dense(128, activation='relu')(merged)


Weighted homogeneous polynomial

Question: Why the polynomial $f(z_1,z_2,z_3,z_4):=z_1z_4+z_2^3+z_3^3+z_4^5$ is a weighted homogeneous polynomial with weights $\left(\frac54 ,3,3,5\right)$?
(Recall that a polynomial $f=f(z_1, \ldots, z_n)$ is called weighted homogeneous with weights $(w_1, \ldots , w_n)$ if it can be expressed as a linear combination of monomials $z_1^{i_1} \cdots z_n^{i_n}$ such that $\frac{i_1}{w_1}+ \cdots + \frac{i_n}{w_n}=1$.)
Answer: Say $z_i$ has weight $w_i$ for $1 \le i \le 4$. Then for the monomials in $f$ we have
$$z_1z_4 \to \frac1{w_1}+\frac1{w_4}, \quad z_2^3 \to \frac3{w_2}, \quad z_3^3 \to \frac{3}{w_3}, \quad z_4^5\to \frac5{w_4}$$
If we want all of them to be $1$, we need $$(w_1,w_2,w_3,w_4) = \left(\frac54 ,3,3,5\right).$$

Weighted homogeneous polynomial


How can I mix vocals well, with only a single line of recording?

Question: Basically, whenever I produce a song, I tend to record two simultaneous lines of vocals, with some distortion added. This sounds pretty good, but I really don't know how to make a single line of vocals without distortion sound good in a mix.
I always hear songs with a single line of vocals, with this crisp, clear sound, and I just don't know how to do that without distortion and/or a second line of vocals.
I use Logic Pro X. How can I get the crisp, clear sound with a single line of vocals that I hear in most songs today? Keep in mind, I'm okay with still using distortion.
Comment: We'd probably need at least a gear list, but the other consideration is you're suffering a bit of John Lennon-ism… he hated the sound of his own voice, which is why it's always doubled or echoed or in a 2-part.
Comment: @Tetsujin Since the vocals for the best-selling album of all time (Thriller) were recorded on an SM-7, and two multiplatinum albums from Alanis Morissette were recorded on 16 bit and 20 bit ADAT (Jagged Little Pill and Supposed Former Infatuation Junkie, respectively), I feel like the songs and the production work always are more important than the gear. Personally, my best recordings and mixes have not been the result of my using the best gear, but by my recording the best musicians with the most knowledge and experience and creativity.
Comment: If you are comfortable uploading a raw vocal take with no backing tracks that doesn't sound the way you want it to, that would help us better understand your challenges.
Comment: @Tetsujin IMPO, the gear doesn't matter very much.
Comment: If I had the patience or inclination, I could drop you a track simultaneously recorded on my Neewer BM700 & my Neumann U87, so you could compare :P [You know, I ought to actually do that so I've got a permanent reference… not the worst idea…] I have actually done perfectly useable vox on an SM58, so I kind of agree with you.
Comment: I'd still like to know what the signal path & environment is, distractions aside.Whether you're recording yourself or a series of pros, or amateurs. Also 'genre' in its broadest terms. I can't imagine this being folk or operetta, for instance.
Answer: Of course you could copy the track and add distortion to the copy and now you have a distorted copy. Personally I would not use the words "crisp" and "clear" to describe vocals that have any distortion on them.
As with most things, the best way to get a great vocal mix is to start with a great vocal recording. When pro tracks have clarity and transparency and high quality sound for a part, that's usually because of the recording engineer and the recording quality, not because of the mix.
The most popular way to mix vocals (and therefore what you're probably hearing) is to EQ the vocals to flatter them, use one or two stages of light compression, and then automate the volume levels to keep the vocals in the right place in the mix. Some non-pros might try finding a compression that prevents the need to automate, but there really is no substitute for fader automation on vocals.
Oh yeah, don't be afraid to aggressively high-pass vocals. Depending on the mix you might even get away with a high pass at 300 Hz. Just listen for the body of the voice and make sure you don't cut that out.
Depending on the song, some vocals may be hyper-compressed to get that very up-front sound. Even with that, automation is often still necessary to keep the vocals sitting right.
Even on tracks where I'm using a single reverb for all the instruments, I find giving the lead vocals their own reverb send helps keep the vocals on top of the mix. Pre-delay greater than 50 ms usually helps keep the vocals from being stuck in the back of the room by reverb, as well as making sure you don't wet them down too much. After that it depends on the track in terms of the right kind and amount of reverb.
As I mentioned at the top, none of that is likely to clarify a muddy recording. If the original recording isn't popping, it's going to be very hard to make it something it's not.

If you want to know how to record clear vocals, then having a very quiet room and getting the right mic position are probably the two biggest ingredients. Also the singer and their voice and tone and articulation are important here. A few singers I've worked with have always sounded muffled - I never figured out why that was or if there was anything they could change about how they sang to fix that.
Regarding mic position, definitely know your polar pickup pattern and make sure the mic is being addressed properly. Pointing the mic at the nose (for a brighter sound) or at the throat (for a deeper sound) can work better than right at the mouth in some cases.
It helps to know/assess the singer and also think forward toward the whole production to get an effective vocal recording. But if there's one track in most songs that all the other tracks have to play along with, it's the vocals. By that, I mean you can take a lot of artistic license with recording vocals, especially if you record everything else so that it works well with the way you recorded the vocals.
Don't place the mic too close or too far from the singer. Using your ears and experience is the best guide here, but closer than 6" should be rare, and farther than 24" would also be a bit unusual. If you're making muffled recordings, you might have the mic too close to the singer.
I almost always have the bass roll-off (high pass) turned on at the mic and/or preamp for voice. Even supposedly "deep" voices don't need those low frequencies.
Comment: I think this is a great anwere. I especially agree on the point that a good recording will have the most influence on the quality. I always say that with all that mixing you can only make the good sounding side of the audio stand out and make the bad sounding side become less noticeable, but you can not really turn bad sounding to good sounding. As you already mentioned in the comments, an example recording of OP would help to give more specific help and adress the specific problems OP is having.


window.open tamanho e lugar

Question: estou usando o windows.open para abrir queria que ele abrisse igual um do popads no canto de baixo do lado direito e resolvir usar o codigo tal mas ele n diminui de tamanho e n fica no cando direito igual alguem poderia me ajudar segue o codico q usei

Comment: não entendi nada
Comment: quando uso o codigo a cima ele abre uma janela e um tamanho mas n fica igual esse da ft q fica bem no canto direito e bem pequeno e queria que ficasse igual
Comment: Sua pergunta está muito mal formatada. Dê uma melhorada no português e acentuação para compreendermos o que você quer.
Answer: Não use valores em % no tamanho do popup porque o método não suporta. Use apenas valores em pixels (sem o px).
Assumindo uma popup de 300x200, para abrir no canto inferior direito, use como base de cálculo as dimensões da janela diminuindo os valores pelo tamanho da popup no top e no left:
document.onclick = function(e){
   myFunction();
}

function myFunction(){

   var lar_janela = window.innerWidth;
   var alt_janela = window.innerHeight;

   console.log(alt_janela);
   window.open("http://google.com", "_blank", "toolbar=false, scrollbars=false,resizable=false, top="+(alt_janela-200)+", left="+(lar_janela-300)+", width=300, height=200");
   document.onclick = null; // anulando na próxima execução.
}

window.open tamanho e lugar


Jquery not working with spring MVC project

Question: I am just trying to test jquery in one of my spring MVC project. I have added jquery-1.6.4.min.js file into WebContent/js/ folder. I am using jquery-1.6.4.min.js
Below is the code for my .jsp file. I don't understand where I am wrong. Is there anything else which I am not doing. I even have added the above .js file from windows->preferences-> javascript->include path->User Liberary

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring 3, MVC Examples</title>

Thanks in advance
Answer: I suspect your path is incorrect, relative and absolute path.
Can you change your source to http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js to isolate this.
Answer: Chin's suggestion to switch source to the online source is good: http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
To troubleshoot your current version - if you create a war from your project, is your /js directory in the right place? If the path is wrong, then the jquery definitely won't load. You can use FireBug to see if there are any JS errors as well.
Comment: Thanks Chin and Thanks JW01.. yes its working with if I give http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js and JW01 you right firebug is giving error that it can't load .js file. But still I can't understand why its not loading .js file even I have copied the full path from file prperties..Anyway thanks for your prompt help
Comment: @Harry, take a look at the structure of your war file - you'll want to see where your js directory is located relative to your jsp file.


Why 'emit' do not show a name only the first time I click a button?

Question: I want to use eventemiter to send a name when a click a button but does not work. The first time I click the button the name is not showed but if a click again then the name appears.
https://stackblitz.com/edit/angular-ue9dzk-extrange-emit
app.component.html
<hello *ngIf="name"></hello>
<show></show>

app.component.ts
import { Component } from '@angular/core';
import { NameService } from './name.service';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
})
export class AppComponent  {
  name: string;
  constructor(private nameService: NameService) {

  }

  ngOnInit() {
    this.nameService.show.subscribe(name => {
      this.name = name;
    })
  }
}

hello.component.ts
import { Component, Input } from '@angular/core';
import { NameService } from './name.service';

@Component({
  selector: 'hello',
  template: `<h1>Hello {{name}}!</h1>`,
  styles: [`h1 { font-family: Lato; }`]
})
export class HelloComponent  {
  name: string;
  constructor(private nameService: NameService) {

  }

  ngOnInit() {
    this.nameService.show.subscribe(name => {
      this.name = name;
    })
  }
}

name.service.ts
import {EventEmitter} from '@angular/core';

export class NameService {
  show = new EventEmitter();
}

show.component.ts
import { Component, Input } from '@angular/core';
import { NameService } from './name.service';

@Component({
  selector: 'show',
  template: `<button (click)="show()">Click to emit</button>`,
  styles: [`h1 { font-family: Lato; }`]
})
export class ShowComponent  {
  name: string;
  constructor(private nameService: NameService) {

  }

  show() {
    this.nameService.show.emit('World');
  }

}

Answer: EventEmitter is intended for use with @Output() bindings, because it has the option to emit values asynchronously. Don't use it with shared services.
<hello *ngIf="name"></hello>

The above creates the component when a value is emitted. After the value is emitted the component will subscribe to the service, but EventEmitter does not keep a history of previously emitted values. So nothing is received by the component.
See constructor:
https://angular.io/api/core/EventEmitter#constructor
It is rare that you need this feature, but there are cases were an @Output() binding needs to emit a value during the next change detection cycle. So in those cases you need to use EventEmitter, but you can use other Observable subjects as emitters for bindings.

but if a click again then the name appears

After the component is created it will receive emitted values, and the second time you click the button a second value is emitted which appears in the template of the component.
Most people who create a shared service will use BehaviorSubject with a default value, or ReplaySubject if they need to wait until a value can be emitted.
In the above example you have the logic *ngIf="name" which means you want to wait until a value is emitted. So you would use a new ReplaySubject(1) instead of EventEmitter.
export class NameService {
  show = new ReplaySubject(1);
}

Answer: That's because you are using *ngIf on hello app selector. Which will not initialize the hello component until the name variable in app.component.ts has value in it. So as you click on emit first time the name variable will be assigned a value first then your hello component will be initialized.
Then after your second click the name variable inside hello app will get assigned value "world" and then it will be displayed.
Solution is as below.
<hello>

    {{name}}

</hello>
<show></show>


Eigenvalue: How to make it more "eigen"?

Question: Suppose that $V$ is finite-dimensional linear space over $F$, $\lambda_1 ... \lambda_m \in F$, $E_1, ..., E_m$ are subspaces of $V$.
The question is, what additional constraints can be given such that a linear map, whose all eigenvalues and corresponding eigenspaces are $\lambda$'s and $E$'s, can be uniquely determined?
I'm asking this because that eigenvalues only give a "partial profile" of a linear map, it characteristics the linear map in an implicit way, this makes me feel that the definition of eigenvalue doesn't deserve its name, though I know maybe it's the best one. (Corrections are welcomed)
Thanks.
Answer: Suppose that the $\lambda_i$ and $E_i$ are given, that the $E_i$ are one-dimensional, and that they span $V$.  Then the linear operator is uniquely determined: any vector $v$ has a unique expression as $v = v_1 + \cdot + v_n$ with the $v_i \in E_i$, and the linear operator maps $v$ to $\lambda_1 v_1 + \cdots + \lambda_n v_n.$
(This is the case when the linear operator has $n$ distinct eigenvalues in $F$, where $n$ is the dimension of $V$.  If $F$ is algebraically closed, then the char. poly. will factor into $n$ linear factors, and this is the case that those $n$ factors are distinct; it is the typical, or generic, case.)
Comment: Your answer is beautiful and I am not trying to improve it, which is a more or less futile attempt. But, just to be pedantic, can we not weaken the condition that $E_i$'s are one-dimensional, to that the the linear transformation can be written as diagonal matrices when restricted to $E_i$ and in some appropriate bases for these subspaces?
Comment: @Doldrums: Dear Doldrums, Yes, we could do that.  Regards,
Answer: We can generalize the answer given by Matt E. Suppose the eigenspaces are $E_1, \dotsc, E_m \subset V$ with corresponding distinct eigenvalues $\lambda_1, \dotsc, \lambda_m$. Let $n_i = \dim E_i$ for all $i$ and $n = \dim V$. Then, the linear transformation is uniquely determined (call it $T$) if $n = n_1 + \dotsb + n_m$. In this case, $V = E_1 \oplus \dotsb \oplus E_m$ and so we can choose a basis $\beta_i$ for each $E_i$ and their disjoint union will form a basis $\beta$ for $V$ (well known theorem). Now $v \in \beta \implies v \in \beta_i \subset E_i$ for some $i$. Hence $T(v) = \lambda_i v$. So $T$ applied to the basis $\beta$ is known and thus $T$ is uniquely determined.
If $n > n_1 + \dotsb + n_m$, then there is a subspace $W$ so that $V = E_1 \oplus \dotsb \oplus E_m \oplus W$. The linear transformation $T$ is not uniquely determined in this case since $T$ can act in any way on $W$.


Rsyslog Remote Logging: Garbled Text when using TLS

Question: I've set up Rsyslog with TLS on two Debian machines and configured remote logging (log-server, log-shipper). However, I am getting "garbled" Text in the logs on the server:
Oct 22 07:58:45 log-shipper.example.org #000��}̪��#0009#000k#000�#000�#000��|��#0003#000g#000E#000�#000#026#001#000#000J#000#027#000#000#000#026#000#000#000#005#000#005#001#000#000#000#000�#001#000#001#000#000##000#000
Oct 22 07:58:45 log-shipper.example.org #000#014
Oct 22 07:58:46 log-shipper.example.org #026#003#001#000�#001#000#000�#003#003[̓#006�: �Q#035�'Q#035�o#014�#001V<��[��|ng�[ܴ#000#000r�,��̩���

Basically I followed the Rsyslog docs here, and also followed other tutorials on the Internet, but the result is always the same.
After having spent 2 days on this, I'm out of ideas. Anyone has a hint, or experienced it too?
Server config:
$ModLoad imtcp # TCP listener

# make gtls driver the default
$DefaultNetstreamDriver gtls

# certificate files
$DefaultNetstreamDriverCAFile /etc/ssl/certs/ca-cert.pem
$DefaultNetstreamDriverCertFile /etc/ssl/certs/server-cert.pem
$DefaultNetstreamDriverKeyFile /etc/ssl/certs/server-key.pem

$InputTCPServerStreamDriverMode 1 # run driver in TLS-only mode
$InputTCPServerStreamDriverAuthMode anon
$InputTCPServerRun 5822 # start up listener at port 5822

Client config:
# make gtls driver the default
$DefaultNetstreamDriver gtls

# certificate files
$DefaultNetstreamDriverCAFile /var/tmp/ca.pem
$DefaultNetstreamDriverCertFile /var/tmp/storage1-cert.pem
$DefaultNetstreamDriverKeyFile /var/tmp/storage1-key.pem

$ActionSendStreamDriverAuthMode anon
$ActionSendStreamDriverMode 1 # run driver in TLS-only mode
*.* @@(o)log-server.example.org:5822 # forward everything to remote server

Answer: This usually means there's something wrong with encryption, check what syslog says when rsyslog service is starting, if it's complaining about anything. Other than that, how did you setup Certificate Authority, as that's the trickiest part of whole setup?
Also, is your $DefaultNetstreamDriverCAFile same on both server?
Answer: Normally, I would comment but not enough rep in this community. I have seen garbled text like that before when I was doing an NMAP scan of a server and watching the results in Syslog. Someone has posted a longer snippet of the attack:
https://superuser.com/questions/1091351/rsyslogd-log-entry-about-attack-created-by-unknown-application
Please take a look and see if the logs reflect that attack.
I have also noticed while setting up logging to an Rsyslog server the inclusion of the #014 character (ie when I set up conversion from Windows EventLog events to Rsyslog server) but without the garbled text. When I switched to another Syslog format (ie getting logs in BSD Syslog format) I was no longer getting the #014 character. You may want to consider looking into another log collection software like NXLog for this to collect and centralize log collection.
Answer: For Ubuntu 18.04 I used the following syntax:
$DefaultNetstreamDriverCAFile /etc/ssl/certs/ca-cert.pem
$DefaultNetstreamDriverCertFile /etc/ssl/certs/server-cert.pem
$DefaultNetstreamDriverKeyFile /etc/ssl/certs/server-key.pem

# provides TCP syslog reception with encryption (TLS)
module(load="imtcp" StreamDriver.Name="gtls" StreamDriver.Mode="1" StreamDriver.AuthMode="anon")
input(type="imtcp" port="6514" )


Problema com Struct

Question: Estou com o seguinte erro no meu código:

error: request for member 'media' in 'dado', wich is of non-class type
  'DadosAluno [5]'

Código:
#include <iostream>
using namespace std;

struct DadosAluno{
        int idade[5];
        float media[5];
};

int main (){

    struct DadosAluno dados[5];
    int i;
    for (i=0; i<5; i++){
        cout<< "Digite a idade do aluno: ";
        cin>> dados.idade[i]; //O ERRO ESTÁ AQUI
        cout<< "Digite a média do aluno: ";
        cin>> dados.media[i];
    }
    cout<< endl;
    cout<< "Dados dos alunos:" << endl;
    for (i=0; i<5; i++){
        cout<< "Idade: " << dados.idade[i] << endl;
        cout<< "Média: " << dados.media[i] << endl;
    }

    return 0;
}

Answer: O que você quer é um aluno com cinco idades e cinco médias ou cinco alunos cada um com uma idade e uma média?

Se você quiser um aluno com cinco idades e cinco médias:
Então, o problema está nesta linha:
struct DadosAluno dados[5];

Que deveria ser isso:
struct DadosAluno dados;

Se o que você quer são cinco alunos cada um com uma idade e uma média:
Então o seu struct está errado. Ao invés disso:
struct DadosAluno{
    int idade[5];
    float media[5];
};

Você deveria usar isso:
struct DadosAluno {
    int idade;
    float media;
};

E nos lugares aonde você usa dados.idade[i] deveria ser dados[i].idade. Aonde usa dados.media[i] deveria ser dados[i].media.

Se o que você queria não é nenhuma das duas coisas acima, então por favor, explique o que você está tentando fazer.
Além disso, a sua mensagem de erro não corresponde exatamente ao código, uma vez que a variável se chama dados, mas a mensagem de erro se refere a uma variável dado (sem o s).

Problema com Struct


Making binary prediction with GPBoost (or MERF)

Question: My question is regarding this post from 1.5 years ago: Modelling clustered data using boosted regression trees
My label is a binary variable (yes/no). Is it possible to use GPBoost / MERF in order to make predictions for this binary variable? I wasn't able to find an answer to this question really quick. If no, which multilevel/mixed effects models can do this? I've already found Mixed Effects Logistic Regression.
Thanks,
Kind regards,
Olivier
Answer: Yes, we can use binary response variables. In GPBoost we set likelihood="binary". MERF in theory can also handle it, as based on the MERF's author's PhD thesis here binary outcomes are within the scope of the methodology but I see no such option in the MERF package itself.
I would suggest looking at bambi (in Python/PyMC3) or rstanarm (in R/Stan) too, you can define splines for your main fixed effects so they have non-linear influence in the response but also have a full MCMC approach in fitting the model and check the relevant diagnostics. (statsmodels often provides sub-optimal fitting results when dealing with mixed models.)
Comment: thanks! really clear, i will look into this !
Comment: Cool, I am glad I could help!
Comment: I also have another question: The goal is to make a generalizable model, so that everyone can use the model. To make things more clear: Optimally, my test set does not have an ID column (the random effect). Is it still possible to make predictions or does the test set NEED an ID column? If yes, can I assign a random number to the test set ID in that case? In this github link: https://github.com/fabsig/GPBoost/blob/master/python-package/gpboost/sklearn.py the default for group_data_pred is None
Comment: I  think this is rather involved to answer in comments, can you please make a new question?
Comment: Ok yes, I made a new question!


Get previous and next week days

Question: I'm able to list current week dates . But How to list previous / next week days ?
( I want to use a button to list previous and next week days. Whenever I click it will show one week before/ after )
<code>Calendar cal = Calendar.getInstance(Locale.UK);
        cal.set(Calendar.DAY_OF_WEEK,  cal.getFirstDayOfWeek());
        daydate = new SimpleDateFormat("dd.MM.yyyy");

        for (int i = 0; i < 7; i++) {
             dates[i] = daydate.format(cal.getTime());
            cal.add(Calendar.DAY_OF_WEEK, 1);
}
</code>
Comment: Add or subtract 7 days from the calendar? (read the docs!)
Comment: Both, I will use prev and next button to add and subtract. But couldnt set it.
Comment: You misunderstood.  You can add or subtract 7 days, or perhaps use week of the year.  http://developer.android.com/reference/java/util/Calendar.html
Comment: Opps, thanks, I got it now, I will use +7 and -7 with calendar date.
Answer: To display next week
follow below code.
<code>    List next = new ArrayList();
    for (int i = 0; i < 7; i++) {
    c.add(Calendar.DATE, 1);
    start = df.format(c.getTime());
    next.add(start);
    }
   textview.setText("" + next.get(0) + "-" + next.get(6));
</code>
Comment: You write 2 answers to this question. one for next week and other for previous week. you can write both in ONE.
Answer: To display previous week follow the below code:
<code>    List previous = new ArrayList();
            for (int i = 0; i < 7; i++) {
                c.add(Calendar.DATE, -1);
                start = df.format(c.getTime());
                previous.add(start);
            }
            textview.setText("" + previous.get(6) + "-" + previous.get(0));
</code>

Get previous and next week days


threshold in AchartEngine?

Question: I am new to android, and I have been using AChartEngine to make graphs
I would like to know if there any way to set a threshold line for a graph in AchartEngine?
An example might be to have thresholds in a temperature chart at 32 degrees F and 212 degrees F. Below 32 the line could be one color, it could be a different color between 32 and 212 and another color above 212.
Answer: You can do this with bar charts by enabling the gradient and setting the start and stop gradient colors, but not with line charts.

threshold in AchartEngine?