"almost surely" convergence of a special sequence of random variables

Question: Let $X_1,X_2,\dots$ be a sequence of equally distributed random variables.
Suppose that $\forall n\in\mathbb{N}:\mathbb{E}[X_n]=0$ and $\lim\limits_{n\to\infty}\mathbb{E}[X_n^4]=0$.
Prove or Disprove: $X_n\stackrel{\text{a.s.}}\to0$.
I feel that the statement is true and I tried to prove it.
I said that since the random variables are all equally distributed then the random variables $|X_1|,|X_2|,\dots$ are also equally distributed.
So, $\forall n,m\in\mathbb{N}:\mathbb{E}[|X_n|]=\mathbb{E}[|X_m|]$. Let's call this value $S$.
Since $\lim\limits_{n\to\infty}\mathbb{E}[X_n^4]=0$, it  must be that $S=0$ (not sure about this).
Therefore, $P[X_n=0]=1$ and $X_n\stackrel{\text{a.s.}}\to0$.
Is it true?
Comment: Are you sure you have your hypothesis right? Does "equally distributed" mean "identically distributed"?
Comment: What is your definition of "equally distributed"?
Comment: But then it's trivial: $\mathbb E[X_n^4]$ are all the same, so all are equal to $0$.
Comment: I have translated it from another language. I think that they mean "equally distributed". Otherwise the sequence is constant, right? @kimchilover
Comment: The implication "$P(X_n=0)=1$" is false. Note that $X_n=\pm 1/n$ with probability 1/2 works.
Comment: I think $\forall t\in\mathbb{R}:F_X(t)=F_Y(t)$. @RobertIsrael
Comment: Yes, thank you. As I am not sure what the TA meant, is there some other definition for which it is not trivial? @RobertIsrael
Comment: Perhaps "equally distributed" means that for each $n$ there is some interval $[a_n, b_n]$ on which $X_n$ has uniform distribution.  Then
$\mathbb E[X_n^4] \to 0$ implies $a_n \to 0$ and $b_n \to 0$, and that implies $X_n \to 0$ a.s.
Answer: As mentioned in the comments we have $E[X_n^4]=0$, i.e.
\begin{align}
\int_\Omega |X_n|^4 \,dP = 0
\end{align}
And that means $X_n=0$ a.s.


navbar responsiva nao aparece quando mudo o tamanho da janela

Question: Estou fazendo um header completo com grid. O problema é que eu fiz um hamburguer menu. Entao fiz esta funcao para ao clicar ele aparecer e ao clicar novamente ele esconder. Porem se eu aumento a janela(resize) depois de clicar no icone para esconder, ele continua escondido( nao aparece o nav). Quero que ao aumentar a janela este comando da funçao nao funcione. Ou volte para display:grid;

function icondisplay() {
    var iconmenu = document.querySelector('#menuicon i');
    var header = document.querySelector('header');
    var nav = document.querySelector('nav');
    if ((header.style.gridTemplateRows == '1fr 2fr') || (nav.style.display == 'grid')) {
        header.style.gridTemplateRows = '';
        nav.style.display = 'none';
    }
    else {
        header.style.gridTemplateRows = '1fr 2fr';
        nav.style.display = 'grid';
    }

}
@media screen and (max-width: 480px){
 nav{
    display: none;
    grid-row: 2/3;
    grid-column: 1/3;
     margin: 0;
 }
 header{
    grid-template-columns:50% auto;
    justify-items: center;
 }
 ul{
    grid-template-columns: 1fr;
    grid-template-rows:repeat(4,1fr);
    grid-row-gap: 50px;
}
#menuicon{
    display: grid;
    align-content: center;
}

Início

Produtos

Contato

Sobre

Answer: Consegui !
Procurei muito e vi que dava pra utilizar resize !
Aqui a soluçao.
window.onresize = function () {
    if (window.innerWidth > 480) {
        nav.style.display = 'grid';
        header.style.gridTemplateRows = '';
    }
    else { nav.style.display = 'none';
    header.style.gridTemplateRows = ''; }

};


Build process tools for JavaScript

Question: I am starting a new project - a reasonably large application - that features just JavaScript code (excepting a little HTML/CSS) and have been giving some thought to a suitable build process and the tooling options available. I'd love to hear from anyone who has had similar choices to make recently.
Some requirements
I do have some essential requirements (I might add more bells and whistles later, but these are really necessary):
- Minification of code: I'd like the option to be really aggressive with this for staging/production builds (think Closure Compiler with advanced optimisations.)
- Code quality checking: JSLint or similar - something to throw up any glaring issues with the code.
- Unit testing: I have a very strong preference for JsTestDriver when it comes to unit testing JS - the ability to test multiple browsers simultaneously (and quickly!) and to automate easily are the main attractions. That said, I'd happily look into alternatives.
- Continuous integration-friendly: we make use of a CI server (BuildBot, for the record) and any build script(s) would have to be easily automated.
Possible solutions
I've already thought of a couple of possibilities (some details are guesswork, do correct me):
Ant
Pros:
- Seems to involve the least work, not least because of the excellent HTML5 Boilerplate build script as a starting point
- Many tools are written (or have wrappers) in Java - including JSLint/Hint, Closure Compiler and JsTestDriver
- Ant scripts are standard fare when it comes to CI servers
- Happily cross-platform
Cons:
- Running many JAR files possibly a bit slow? (I'm thinking in terms of initialisation more than execution)
Ruby/Rake
Pros:
- (Well-written) Ruby scripts are quite probably nicer to deal with than piles of XML
- There are wrappers (often gems) for many relevant tools, such as JSLint, JSTestDriver and UglifyJS
- Equally cross-platform
Cons:
- Knowledge of Ruby involved to modify the build process. While this isn't a huge deal, we're not a Ruby shop and the alternatives don't have quite the same barrier to entry
- Few of the tools actually run in Ruby and are actually wrappers around Java or JavaScript code executing - this seems like it may slow things down
Node (and probably something like Jake)
Pros:
- Plenty of tools available in JavaScript (and as modules available to Node) - JSLint/Hint, UglifyJS etc.
- Presumably pretty quick (this blog post illustrates UglifyJS outpacing Closure Compiler quite comprehensively, for one)
Cons:
- Node (particularly NPM) doesn't seem quite there on Windows yet (we have some developers running Windows)
- There doesn't seem to be any existing support for using JsTestDriver from a Node app (but a wrapper could be written)
Based on that, Ant seems the favourite at present.
Comment: the html5 boilerplate build.xml isn't that great - you'll want to stay away from ant-contrib.  it's the quickest way to get a rat's nest of unmaintainable gunk.  I'd recommend you stay away from ant.   If you go that way -let ant be ant, don't try to make it feel like  a scripting language.
Comment: Maybe Gradle with some plugins ex. http://eriwen.github.io/gradle-js-plugin/ ?
Answer: A brief follow-up now that the project is complete:
Ant was chosen to build the project, but later on I wished I'd used a Node-based solution. While you can make Ant do most things, it's often verbose or necessary to write a lot of Java code to make it do anything out of the ordinary. Node and NPM improved on Windows significantly throughout the lifetime of the project and there are now a surfeit of testing solutions (BusterJS is interesting me most) that can easily be called from a Node script.
I was intrigued to see the release of Grunt, which seems like it could have been particularly useful for a project like this. I'd be keen to hear people's experiences of this tool used with projects of reasonable size (for reference, the project I have just completed had around 120 JavaScript source files.)
Answer: Over a year later, but...
If r.js + RequireJS is your thing, and you want automated builds plus development aid/help like linting, minification, concatenation, asset compilation, etc, check out Mimosa.  It'll do a lot of those things right out of the box with minimal configuration.
Answer: I like RequireJS for dependency management/dynamic script loading, and building a single file.
For continuous integration check out TeamCity from JetBrains.
Comment: RequireJS is definitely useful for managing dependencies and relationships between JavaScript files, but I was more interested in an overall build script or system that could make use of (for example) RequireJS's r.js optimiser.
Answer: Gulp
There is a new build tool called gulp that uses node streams, so it does not have to write any temporary files between steps (like grunt).  It's fast.

Build process tools for JavaScript


What do you call a minor triad with a 4th in the bass?

Question: Is this chord still a minor triad if you use a 4th in the bass or does the chord change? Can anyone think of any examples in pop or rock music where this is used?
thank you
Comment: So a minor chord with a 4th of the minor scale in the bass. For example, Aminor with a D in the bass.
Comment: Can you clarify what you mean by "4th" in the bass? Do you mean it's in second inversion?
Answer: I see three distinct possibilities based on how you are actually thinking about the chord itself:

If you really just consider it an A minor chord, it might just end up being a slash chord with a non harmonic tone in the bass. So it would be Am/D.
I would most likely name it D7sus2 which is spelled D E A C. This makes most sense to me since there's no third, but a there is a 2nd/9th present which make sense for the sus.
Another possibility is if you want to look at all the notes together as one unit then I'd view this as an inverted C6/9 chord which is spelled C E (G) A D. The G is not there, but omitting the 5th is quite common in actually playing chords which will show more of the quartal/quintal nature of the notes themselves, but is a streach naming wise.
Answer: I agree 100% with what Dom said, I just wanted to add that identifying a chords name often requires looking at its siblings and/or the key the piece is written in. Taking your example with A- and D in the bass I would interpret it as either

D7sus2: D E (F#) A C
D-7sus2: D E (F) A C

because of the D in the bass. Not applicable to rootless voicings of course.
Comment: Correct, they are omitted, but if your piece is written in e.g. D-Minor, as a purist you would call the chord D-7sus2 to outline the omitted diatonic third.
Comment: That really makes no sense. If a third is part of the chord, it is not a sus chord. **D-7(sus2)** is not a purist notation, it is a confusing and not very common notation. The only times I have seen this used it was either attempting to communicate that the sus chord was based on a minor chord (usually unnecessary), or it was used incorrectly to name an extended 7th chord. In any case, I don't see why this is in an answer to _this_ question.
Comment: @jdjazz -- but sus chords don't contain 3rds, so this adds information that is irrelevant to the actual chord name; you can easily see what the chord movement is by looking at the next chord.
Comment: Thirds are omitted in sus chords, so those two chords look like **D9** and **D-9**.
Comment: @DavidBowling, I don't think it's illogical. A sus chord omits a major or a minor third. D7sus would imply resolution to a major third, but D–7sus would imply resolution to a minor third. Communicating which is intended gives helpful information to, e.g., a soloist who is likely to play the third when improvising over the sus chord.
Comment: @DavidBowling, chords do more than just tell the comping instrument what notes to play. They communicate harmonic information to the soloist. There are many scenarios where one can't simply look at the next chord to find the resolution. In jazz, it's not uncommon, for example, to have consecutive sus chords moving up/down half steps, thirds, etc. If a composer wants the soloist to use the minor third over the major third, D–7sus would be the perfect way to communicate this.
Comment: @jdjazz -- if you have a series of sus chords following each other, it isn't immediately obvious to me how **C-7(sus4)** would convey useful information. If the melody contains a minor third here, maybe. When I improvise over changes, I always at least scope out the chords and the melody first; if there is no melody to see but only changes, this might be helpful. But these are somewhat special circumstances. My original point was that the note collections in this answer are 9th chords, not sus chords. This at least deserves some comment in the answer, I believe. But this all may be OOB the OP
Comment: @DavidBowling it's a way for the composer to tell the soloist, "if you're going to make your lines resolve, then resolve to the minor third not the major third." Also, Keith Jarrett and Brad Mehldau (probably others too) will sometimes voice a sus chord with the major third as a tension/non-chord tone. I recall Keith putting the major third in a really high register. Brad will pretty frequently voice the chord with the major third and fourth a half step apart in the mid register. Writing D-7(sus4) tells the comping instrument which third to use as a non-chord tone if they're going that route.
Comment: @jdjazz - usually, when improvising, I'll have a pretty shrewd idea as to whether a sus chord relates more strongly to a maj or min if the third was to be there, looking at its context. Don't think, in most cases, that it's necessary to be that precise, and I often will use a third (of either persuasion) in a sus bar. But including the third as well as a 'sus' in a chord makes it definitely an 'add 9' or 'add 11'.   When comping, again, I should know if the 'original' chord would have been maj or min., and if it's written as sus, that's surely what is required, without the third there - unless
Comment: the writer meant add something, in which case, it ought to be put in.


Laravel validation: value has to be in array only if field is required

Question: I am using Laravel 5.3 and I need to validate a field
The field I need to validate is only required if another field has the value 1 and this works.
If the field is required, the value entered must be in a given array.
The problem is the value being validated is NULL so doesn't appear in the array and validation fails
Here is my rule so far
$test->other_field = 0
$test->my_field = NULL;

$rules = array(
    'my_field' => 'required_if:other_field,1', //|in:' . implode(',', $array),
);

The required_if works fine but if i uncomment the in part, the validation fails
Answer: I solve it by creating a new FormRequest and adding the following code.
public function rules(Request $request)
{
    if($request->has('other_field '))
    {
        $rules = array(
            'my_field' => 'in:' . implode(',', $array)
        );

        return $rules;
    }
}


Confidence intervals of percentiles in non-linear regression

Question: I'm fitting a log-logistic model, $Y=1/\left(1+10^{((\log10(a)-\log10 (X))/b)}\right),$
to toxicity data ($X$ are concentrations and $Y$ are mortalities) using SPSS and Graphpad Prism. I get the fitting parameters, $a$ (the LC50) and $b,$ with the corresponding 95% confidence intervals. However I'm interested in a lower level of effect, the concentration causing a 5% mortality, i.e. the $0.05$ percentile in the function above. I can work out the value using the equation but how could I obtain confidence intervals for that value?
Thanks
Comment: Do you mean fitting your regression equation and then solving for the input value that results in 5% mortality? If so, do you know how to solve this problem for another mortality percentage, perhaps 50%?
Comment: In Graphpad you can simply just use the Calculate 'ECanything' model which calculates 95% intervals https://www.graphpad.com/support/faq/how-can-i-determine-an-ec90-or-any-ec-value-other-than-ec50/
Comment: Hi Dave, for the 50% effects there is no problem since that is the 'a' parameter, provided with its confidence intervals by any statistical package
Answer: Framing the Question
The model supposes that when $n$ subjects are given a dose $x \gt 0$ and independently develop toxic responses, the count of those responses $Y(x)$ has a Binomial distribution with count parameter $n$ and probability parameter
$$p(x;a,b) = \frac{1}{1 + 10^{(\log(a) - \log(x))/b}} = \frac{1}{1 + \exp\left(\beta_0 + \beta_1 \log(x)\right)}$$
where $\beta_0 = \log(10) \log(a) / b$ and $\beta_1 = -\log(10) / b.$
If we knew the true values of the $\beta_i$ and assuming $\beta_1 \ne 0,$ then for any quantile $0 \lt q \lt 1$ this could be solved for $x$ to estimate the dose $x_q$ at which the chance of a toxic response is $q:$
$$x_q = x_q(\beta_0, \beta_1) = \frac{-\log\left(\frac{1}{q} - 1\right) - \beta_0}{\beta_1}.$$
Another way to state this is that
$$\beta_0 + \beta_1 x_q = -\log\left(\frac{1}{q}-1\right).\tag{*}$$
Because the $\beta_i$ are estimated from dose-response data, the corresponding $x_q$ is uncertain: the question asks for a confidence interval for it.
Theory and Analysis
Because this model is usually estimated with Maximum Likelihood, and the fitted model does not change when it is reparameterized, it is convenient to make $x_q$ one of the parameters.  Exploiting $(*)$ makes this fairly simple to do, because
$$\beta_0 + \beta_1 = \beta_0 + \beta_1 x_q + \beta_1(x-x_q) = -\log\left(\frac{1}{q}-1\right) + \beta_1(x-x_q).\tag{**}$$
The new parameters are $x_q$ and $\beta_1.$  Let
$$\Lambda(x_q, \beta_1)$$
be the log likelihood for the parameters in terms of this parameterization.
By definition, the parameter estimates $(\hat{x_q}, \hat{\beta_1})$ optimize the log likelihood.  If instead we specify $x_q$, the optimal value of $\beta_1$ can change, becoming (say) $\hat{\beta_1}(x_q)$.  The log likelihood decreases by an amount
$$\Delta(x_q) =  \Lambda(\hat{x_q}, \hat{\beta_1}) - \Lambda(x_q, \hat{\beta_1}(x_q)) .\tag{***}$$
Twice this difference is the deviance.  Given the data, it depends only on $x_q.$  The theory of Maximum Likelihood indicates this deviance follows a Chi-squared distribution with one degree of freedom.  When it is large, the stipulated value of $x_q$ is inconsistent with the data.

To find a two-sided confidence interval $[x_q^{(l)}, x_q^{(u)}]$ for $x_q$ with confidence level $1-\alpha,$ find the two solutions to the equation $$\Delta(x_q) - \chi^2_1(1-\alpha) = 0\tag{****}$$ where $\chi^2_1(1-\alpha)$ is the upper $1-\alpha$ percentile of the Chi-squared distribution with one degree of freedom.

One of the solutions will be less than $x_q(\hat{x_q}, \hat{\beta_1})$ and the other will be greater.
Illustrations
Suppose $150$ subjects were divided randomly into six groups of $25$ each and given doses of $1, 2, 4, 8, 16,$ and $32$ units.  The mortality counts in those groups were $1, 6, 15, 24, 25$ and $25,$ respectively.  We shall estimate the dose $x_q$ at which there is $100q = 5\%$ mortality and construct a $95%$ confidence interval for it (so that $\alpha = 1 - 95/100 = 0.05$).

Figure 1: The responses (as the proportion of dead subjects per group) plotted against dose (on log-linear scales).  The low horizontal line shows the level $q=0.05.$
These groups are large enough to give us some confidence in the (asymptotic) theoretical justification of the Maximum Likelihood theory and the low mortality in the lowest group suggests this range of doses might have included $x_q$ itself (so that we don't have to extrapolate it below the smallest dose).  Let's therefore proceed with the calculations.  I will illustrate them with R commands, but I imagine the SPSS and GraphPad commands would be similar.
fit <- glm(cbind(response, count-response) ~ log(dose), X, family="binomial")

Here, X is a data frame recording the doses in the variable dose and the counts of subjects and deaths in the variables count and response, respectively.  Here is part of the model summary:
Coefficients:
            Estimate Std. Error z value Pr(>|z|)
(Intercept)  -3.3498     0.6371  -5.258 1.46e-07 ***
log(dose)     2.9198     0.4868   5.998 2.00e-09 ***

Residual deviance:   1.3819  on 4  degrees of freedom

The "residual deviance" of $1.38$ essentially gives us the (negative of the) baseline value in $(***)$ for evaluating $\Delta.$  The parameter estimates are $\hat{\beta_0} \approx -3.35$ and $\hat{\beta_1}\approx 2.92.$  They correspond to this dose-response curve:

Given any positive dose x.q, a similar command fixes its value in the model and estimates $\hat{\beta_1}(x_q)$ using an "offset" term:
fit.q <- glm(cbind(response, count-response) ~ I(log(dose / x.q)) - 1, X, family="binomial",
               offset=rep(-log(1/q - 1), nrow(X)))

This implements the model $(**).$  For instance, with $x_q$ set to $2,$ the model summary is
Coefficients:
                 Estimate Std. Error z value Pr(>|z|)
I(log(dose/x.q))    4.556      0.461   9.884   <2e-16 ***

Residual deviance:  14.597  on 5  degrees of freedom

The new estimate of the slope, $\hat{\beta_1}(x_q) \approx 4.56,$ differs appreciably from the original estimate of $2.92.$  More importantly, the deviance has increased to $14.60.$  The value of $\Delta$ therefore is $14.60 - 1.38 = 13.22.$  This is large: it is the  $99.97^\text{th}$ percentile of the Chi-squared distribution with one degree of freedom.  Thus, $2$ is too high: $x_q = x_{0.05}$ is likely less than $2.$  That is evident in the plots.
The upper $1-\alpha= 0.95$ percentile of the Chi-squared distribution is $3.84.$  We proceed to solve $(****)$ with this value.  I used the uniroot function in R.  It returned the values $x_{0.05}^{(l)}=0.663$ and $x_{0.05}^{(u)}=1.670:$ these are the endpoints of the desired confidence interval.

Figure 3: The Maximum Likelihood fit with $x_{0.05} = 1.670$ is shown in red and that with $X_{0.05} = 0.663$ is shown in blue.
The red curve attains the level $q=0.05$ at $x=1.670,$ which I marked with a red vertical line; and the blue one equals $q=0.05$ at $x=0.663$ (which is to the left of the plot, being less than the lowest dose in the experiment).  Since the conclusion that $x_{0.05}$ exceeds $0.663$ is somewhat of an extrapolation, it's not well supported and so maybe we should be content to report this confidence interval as ranging from "less than the lowest dose" up to $1.670.$
Simulation
I generated the previous example randomly from the model with $\beta_0=-4,$ $\beta_1=3.$  To evaluate the procedure, I did this another 8000 times (this took 40 seconds, so it wasn't much of a wait) and computed the $95\%$ confidence interval for $x_{0.05}$ in every case.  Here is a plot of the first 100 of these intervals:

Blue points show the lower endpoints and red points show the upper endpoints.  The true value of $x_{0.05} = \exp((\log(1/0.05-1) - (-4)/3) \approx 1.422$ is shown with a horizontal line.  The intervals that do not include the true value are highlighted in black: there are 10 of them in the figure and 435 in the entire simulation.
The proportion of these simulated intervals that include the true value is $7565 / 8000 \approx 0.9456,$ close to the desired confidence of $95\%.$  In this example, at least, the Maximum Likelihood theory is behaving exactly as we might hope.  The figure provides even better information: it shows how much the endpoints are likely to vary around the true value.  It looks like this experiment will pin it down to within a factor of two or so.
Comment: In statistical writing (as in mathematics) "log", unless otherwise specified, normally means natural log.
Comment: Hi Whuber, thank you for your quick and comprehensive response. I'm not familiar with R yet but have to get into it. However I get a bit lost with the logarithms. I think In your equation (*) it should be naperian log (ln) rather than decimal log, and most likely the same in the beta-sub-i expressions above. Is that correct? Thanks


Windows 2003 - logging off the Administrator account makes web applications inaccessible

Question: Consider a web application installed on a Windows Server 2003 SP2 machine with the admin account. The application is accessible in the server as well as in the network when at least one session of the admin account is logged in. If there are no active sessions of the admin account, the web application is not accessible via the network, nor accessible locally when logged in with another user account.
What would cause the web application to be inaccessible there's no Administrator session?
Please suggest anything that might help find the solution.
Answer: How are you starting this web application?
Edit:

From comment: through IE, xx.xx.xx.xx/clientname/0/System/Session/Login.asp sorry if had misunderstood your question.

So it is running under IIS, not as a separate executable launched within the login session.
Next things to do:

What user identity is being used by IIS to run it?
Is there anything in the event log? E.g. failures from IIS, login failures from the user identity, ...

To determine #1 use "Internet Information Services (IIS) Manager" (from administration tools). Go to the root of the web application matching the URL (this might be the folder containing login.asp, or an ancestor: look for a folder with a gearicon). Open up the properties and go to the Virtual Directory tab. Look at the Application Name. Go to the Application Pools and look at the properties of the node named for the application name. The identity tab will tell you which user account is being used to run the web application.
Comment: through IE, http://xx.xx.xx.xx/clientname/0/System/Session/Login.asp

sorry if had misunderstood your question.
Comment: Hi Richard

As our's is an IIS 5 based application, we have set the Web sites -> services property to run in "Run WWW/ service in IIS Isolation mode". Becuase of this property the application pool property has disappeared and Application protection is enabled.
Comment: @Saravana... and under 2003 it is IIS6 which included a lot of security changes. You really need to break out the (remote) debugger and do lots of logging to track this down.
Answer: You shouldn't be running the application as admin. Use a separate account, preferably one that has only just enough access to do what it needs to do. Then make sure it's running as a service, not an application.


linux redhat + hung + reason for hung

Question: I have linux redhat machine - 6.8
and from the /var/log/message file I see the following lines:
from my point is seems that linux is hung because the bad connection to the server - 220.127.116.11 ,
is it correct ?
<code> Oct 30 04:39:40  guard_tap[18038]: Delayed server connection to 220.127.116.11 error: Connection timed out
 Oct 30 04:40:31  kernel: INFO: task oracle:16131 blocked for more than 120 seconds.
 Oct 30 04:40:31  kernel:      Tainted: G        W  -- ------------    2.6.32-642.4.2.el6.x86_64 #1
 Oct 30 04:40:31  kernel: "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
 Oct 30 04:40:31  kernel: oracle        D 0000000000000001     0 16131      1 0x00000000
 Oct 30 04:40:31  kernel: ffff8801012a7a98 0000000000000082 ffff8801012a79e8 ffffffffa03093ee
 Oct 30 04:40:31  kernel: ffff8801012a7a18 ffffffffa0309c90 ffff880700b057c0 ffff8801012a7a48
 Oct 30 04:40:31  kernel: ffff880700b05870 ffff88082ba2e448 ffff88010c6e3ad8 ffff8801012a7fd8
 Oct 30 04:40:31  kernel: Call Trace:
</code>
Answer: That could be just coincidence
Your real issue is this
<code>INFO: task oracle:16131 blocked for more than 120 seconds
</code>
So you should check your Oracle alert log file.
Comment: can you explain the meaning of INFO: task oracle:16131 ?  ( what is the number 16131 ? )
Comment: is this number is the number of the oracle proccess?
Comment: Yes, it's PID - Process ID

linux redhat + hung + reason for hung


What is the best way to hide/encrypt a String in ObjC/C?

Question: I have a string in my code that I use as a secret when I communicate with my server. What is the best way to encypt this string to ensure that a hacker will not be able to find it out by searching my binary or looking into the memory during run time? (if possible to prevent at all?)
What are some measures you would suggest to at least make this as diffcult as possible?
Answer: A far better approach would be to monitor use from your server and try to detect usage patterns that did not match your application - such as knowing it would always make one kind of request before another, or that an iPhone ID you pass up as a parameter to a call was not used excessively from multiple sources.  You could have it make an initial call when the app first starts and record on the server the phone ID to allow other calls.
There are multiple ways to approach the problem, but they are all server based - anything in the client can and will be seen by a hacker.  Anything the client says must always be treated as a lie, for sometimes it will be.
Answer: Technically it's not possible, one can always at least memory scrape the code just after decryption before the connect, and as the whole decryption algorithm needed is also already available in the code. A disassembly will allow one decrypt the data straight from the binary.
In practise as this is a closed platform (from the fact you used the iphone tag), it'll only be major hackers that would manage to get it even if it's just a plain hexadecimal string in the binary.
Comment: What are some measures you would suggest to at least make this as diffcult as possible?
Comment: Just put the string in place - it will be meaningless to someone scanning for strings.  Then always use HTTPS in communicating with your server so it can't be snooped.  Of course, then you have to pay the performance penalty for using HTTPS but it's the only way to keep it even kind of secret.
Comment: Well, why exactly do you need this string, is it to try to make it so only your binary connects to your server?


Kubernetes: How do we List all objects modified in N days in a specific namespace?

Question: We have multiple people ( with admin access ) doing the deployments in kubernetes cluster. We are finding it difficult to manage who has modified which object.
We can control the access and privileges using RBAC with roles and role bindings. We are planning to implement well defined roles and rolebindings for different groups.
We would also want to list all objects modified in N days in a specific namespace. Is there a way to display the objects using kubectl? please let me know
Answer: This probably can't be done easily just with kubectl.
But you might look into Kubernetes auditing. It causes the API server to record all requests to the API, and you can query them in different ways. For example, it should be possible to query the audit logs for all the objects that have been specified in the last N days.


How to add LVM logical volume data domain with iSCSI as storage type on oVirt?

Question: I am trying to add a storage domain on oVirt with iSCSI as storage type, first i need to know whether i am doing this correctly.My understanding is there must be a storage server (target) and Initiator (for the case of oVirt this is oVirt Engine).
So i set up an iSCSI target this is the output of targetcli ls on target server
# targetcli ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- bamboo_disk .................................................... [/dev/mapper/cl-bamboo_lv (300.0GiB) write-thru activated]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2017-01.ovirt.bamboo:bamboo ................................................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.2017-01.ovirt.bamboo:ovirt ....................................................................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ........................................................................... [lun0 block/bamboo_disk (rw)]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ................................................................... [block/bamboo_disk (/dev/mapper/cl-bamboo_lv)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]

then i edited /etc/iscsi/initiatorname.iscsi file and added this line
InitiatorName=iqn.2017-01.ovirt.bamboo:ovirt

Now on oVirt Administration portal when i try to add a data domain with iSCSI as storage type, the targer is discovered but when i try to login i end up with this error message
Error while executing action: Failed to login to iSCSI node due to authorization failure

image showing this error
Surprisingly i can login into the target from the machine that running oVirt Engine and the disk sda is added
[root@ovirt ~]# iscsiadm -m node -T  iqn.2017-01.ovirt.bamboo:bamboo -p 10.1.10.3:3260 -l
Logging in to [iface: default, target: iqn.2017-01.ovirt.bamboo:bamboo, portal: 10.1.10.3,3260] (multiple)
Login to [iface: default, target: iqn.2017-01.ovirt.bamboo:bamboo, portal: 10.1.10.3,3260] successful.
[root@ovirt ~]# lsblk
NAME                       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                          8:0    0  300G  0 disk
sr0                         11:0    1 1024M  0 rom
vda                        252:0    0  600G  0 disk
├─vda1                     252:1    0    1G  0 part /boot
└──vda2                     252:2    0  199G  0 part
  ├─cl_ovirt-root          253:0    0  100G  0 lvm  /
  ├─cl_ovirt-swap          253:1    0  3.9G  0 lvm  [SWAP]
  └─cl_ovirt-home          253:2    0    2G  0 lvm  /home

My questions, how comes i can login into the target and the disk is created but when i do it on Ovirt Engine Administration portal i end up with errors? does oVirt Engine use a different Initiator Name from the one in the  /etc/iscsi/initiatorname.iscsi file? is there somewhere i can configure oVirt Engine to use a particular Initiator Name?  what am i doing wrong? is the whole approach incorrect?
Comment: Nothing about your approach is incorrect, and you've done everything right... up until the Ovirt stuff. I think it's probably pulling an initiator name from somewhere else when you use the portal rather than iscsiadm. Is there nowhere in the Ovirt portal configuration that you can put an initiator name?
Comment: Actually that what i was asking my self too, i should have put that on the list of questions. i did not see anywhere on the oVirt Administration portal to configure the initiator name.
Answer: First of all, the initiator cannot be the engine. It needs to be one of the hosts that are actually running VMs. The engine doesn't even need access to the iscsi network, because the hosts are doing all the storage manipulations.
The valid initiator name thus, is the one configured on the virtualization hosts, not the engine.
Comment: Thanks a lot, this has been very helpful,  i am having a difficult time setting up an oVirt platform, i find oVirt to have very insufficient documentation.
Comment: new documentation has just been rolled out yesterday


How to fix destroyed software RAID after Ubuntu upgrade

Question: I upgraded a headless server from Ubuntu 12 to 14 following the built-in do-release-upgrade script. It seemed to run fine until I rebooted, and was left with an unusable machine. After the grub screen, all I get is a stream of messages that, after 30 minutes, haven't ended. The messages are streaming so quickly, I can't even see them well enough to google the errors.
How do I go about diagnosing this?
Also, how do I backup the hard drive? Using a LiveUSB, I'm able to see the hard drives, but I can't mount them because they're part of a software RAID. Running mount /dev/sdb1 /mnt gives me the error:
mount: unknown filesystem type 'linux_raid_member'

I read here that I might have to rebuild the array with mdadm, but is that possible from a LiveUSB that shouldn't be able to write to the drives?
Answer: I think your LiveUSB doesn't have MD drivers built-in, and that's why it doesn't recognize the RAID members.
You need to see if you can manually load the MD module on your LiveUSB, or then find another boot media which has MD drivers available. For example, System Rescue CD is one option.
Comment: Yes, following my link, I'm able to temporarily rebuild the array using mdadm in a LiveUSB, but I still don't know what caused the problem to begin with.


Observation and conjecture on Lychrel numbers

Question: A palindromic number (also known as a numeral palindrome or a numeric palindrome) is a number that remains the same when its digits are reversed.
Consider a number $n>0$ in base $b\geq2$, where it is written in standard notation with $k+1$ digits $a_{i}$ as:
$${\displaystyle n=\sum_{i=0}^{k}a_{i}b^{i}}$$with, as usual, $0\leq a_{i}<b$ for all $i$ and $a_{k}\neq0$. Then $n$ is palindromic if and only if $a_{i}=a_{k-i}$ for all $i$. Zero is written $0$ in any base and is also palindromic by definition.
In this context, a Lychrel number is a natural number that cannot form a palindrome through the iterative process of repeatedly reversing its digits and adding the resulting numbers. It is conjectured that $196$ and other numbers that have not yet yielded a palindrome are Lychrel numbers, but no number in base 10 has yet been proven to be Lychrel.
I was curious about the sequence of "candidate Lychrel" numbers, which can be found at https://oeis.org/A023108. I tried to find some kind of pattern among them, and I found the following: every number of the form $99k-2$ is a candidate Lychrel for $1<k<9$. This "curious" fact led me to check if some similar property ocurred for higher candidate Lychrel numbers, and I have checked that every number of the form $999k-1$ is a candidate Lychrel for $1<k<10$ excepting $k=5$, which is a palindromic number; and every number of the form $9999k$ is a candidate Lychrel for $1<k<10$. I have not checked further, only that $99999*2+1$ is also a candidate Lychrel.
Clearly, it can be made the following rough conjecture:
Conjecture. Let it be some number in base $10$ of  the form $n=999...9k-m$. Let us denote with $j$ the number of "9" composing the form of $n$. Then, if $1<{k}<9$, $j\geq2$ and $m=4-j$, $n$ is either a palindromic number or a Lychrel number.
Any guess about the relationship between this clear pattern, and the dynamic of the add-and-reverse-digits process? Any counterexample to the conjecture?
Thanks in advance!
Answer: There is a counterexample.
Take $(j,k)=(6,2)$ for which we have
$$n=(10^j-1)k-(4-j)=2000000$$
This is not a palindromic number.
Also, this is not a Lychrel number since under the "add reverse" operation, we have $$2000000+2=2000002$$ which is a palindromic number.

Added :
Let us call a number good if it is either a palindromic number or a Lychrel number.
According to A023108, we have the followings :

For $j=2$, $n=(10^2-1)k-2$ is good for $k=2,3,\cdots, 8$.

For $j=3$, $n=(10^3-1)k-1$ is good for $k=2,3,\cdots, 8,\color{red}{9}$.

For $j=4$, $n=(10^4-1)k-0$ is good for $k=2,3,\cdots, 8,\color{red}{9,10,11}$.

For $j=5$, $n=(10^5-1)k+1$ is good for $k=2$.

Also, we can see the followings :

For $j=6$ and $k=2$, $n=2000000$ is not good.

For $j=7$ and $k=2$, $n=20000001$ is not good.

For $j=7$ and $k=3$, $n=30000000$ is not good.

For $j=8$ and $k=3$, $n=300000001$ is not good.

For $j=8$ and $k=4$, $n=400000000$ is not good.

So, it seems that there are functions $F(j),G(j)$ such that $n=(10^j-1)k-(4-j)$ is good for $j\ge 2$ and $F(j)\le k\le G(j)$.
Something like
$$F(j)=2+(j-5)\left\lfloor\frac j6\right\rfloor,\qquad G(j)=j+6+\left\lfloor\frac j4\right\rfloor$$
Comment: @Juan Moreno : I've added some thoughts, and I agree that there is a pattern. I don't think that I can answer your question in your comment, but considering what I've added in my answer, I conjecture that $n=(10^j-1)k-(4-j)$ is good for $j\ge 2$ and $2+(j-5)\left\lfloor\frac j6\right\rfloor\le k\le j+6+\left\lfloor\frac j4\right\rfloor$ though it might be very difficult to prove/disprove my conjecture.
Comment: thanks, good counterexample! I did not know if it was worthy to deepen in this conjecture. Any idea /guess/heuristic why all the numbers I identified of the form $(10^j-1)k-(4-j)$ up to $(j,k)=(5,2)$ are Lychrel candidates? Even when the conjecture is proved to be false, it seems to be a pattern there.
Comment: @matlove, I agree that it could be difficult to prove the conjecture, I do not have the slightest idea of how to do that. I will work on it, lets see if I get something interesting. Thanks for your feedback & contribution!


Como comparar idade com data de nascimento em JavaScript?

Question: Estou com uma dúvida tremenda. Não me pergunte por quê, mas tenho que comparar a idade digitada com a data de nascimento digitada pra ver se elas batem mas não consigo.
Por favor, quem puder me ajudar eu agradeço.
Comment: como é que a data é inserida?
Comment: Mostre como está seu código até agora.
Comment: converta a data inserida em idade.. então compare a idade inserida com o resultado da data..
Answer: Amigo, você pode verificar subtraindo o ano de nascimento pelo ano atual, caso a data de nascimento informada não tenha passado ainda, subtraia 1.
Neste link tem um exemplo de parte da sua pergunta, a pessoa precisava saber a idade a partir da data de nascimento.

Como calcular a idade de uma pessoa com JS, a partir da data de nascimento?

Após descobrir a idade usando esta função, basta fazer um if simples comparando as idades.
Segue o exemplo http://jsfiddle.net/897d6btq/, espero que ajude. :)
Outra solução mais elegante é você construir uma Regex.
Comment: Amigo, editei a resposta com o exemplo, espero que ajude. :)
Comment: Oi Daniel, podes dar exemplos para a resposta ficar mais completa?


Como criar variáveis dinâmicas no javascript dentro de um loop

Question: tenho o seguinte código e queria dar uma melhorada nele.
 if(id == 1)
        if(myWindow1){
        myWindow1.form_1.submit();
        myWindow1 = "";

    }
    if(id == 2)
        if(myWindow2){
            myWindow2.form_2.submit();
            myWindow2 = "";
        }

    if(id == 3)
        if(myWindow3){
            myWindow3.form_3.submit();
            myWindow3 = "";
        }
    if(id == 4)
        if(myWindow4){
            myWindow4.form_4.submit();
            myWindow4 = "";
        }
    if(id == 5)
        if(myWindow5){
            myWindow5.form_5.submit();
            myWindow5  = "";
        }

onde myWindow ... e um popup que pode ter sido criado. Se eu sei a quantidade de popup que foram criadas( e sei ) poderia fazer mais ou menos dessa forma (como faço em PHP)
while($contador < $qtdAlgo){
 $nomeVariavel = ${"myWindow". $contador}
 $contador++;
}

Assim iria pegar todas variaveis que ja existem e conseguiria fazer algo com elas... Existem uma forma para eu manter meu código la em cima
{ myWindow1.form_1.submit() } ?
Obs. o form_1 também teria que ser concatenado.
ou seja mais ou menos assim
myWindow {contador} .form_ {contador}.submit();
Comment: Podes fazer myWindow[contador]
Comment: Seria interessante ver como são criados os popups.
Answer: for(var i=0; i < qtdeForms; i++) {
    var formCount = i + 1;
    if ( 'myWindow' + formCount in window) {
         window['myWindow' + formCount]['form_' + formCount].submit();
    }
}

Isto pode resolver o teu problema, mas aconselho você a trocar de lógica, pois desta forma o seu código tende a piorar cada vez mais.
Answer: Porque vc nao coloca todos os ids em um array, depois vc faz um loop, e depois dentro do loop vc nao faz o que precisa com os ID?
// Array inicial
var IDformularios = [1, 2, 3, 4, 5]

var validaFormularios = function (formularios) {
  var forms = window.IDformularios || []
    if (!forms.length) {
        return new Error('Nao tem formularios')
    } else {
    // LOOP
        forms.forEach(function(form) {
      var nome = 'form'+form
      // EXECUTA LOGICA
          executaLogicaNoFormulario(form)
      // OU CRIA SUA VARIAVEL AQUI
      criaVariavelDinamica(nome)
        })

    }
}

var executaLogicaNoFormulario = function (formulario) {
    if (!formulario) {
        return new Error('Nenhum formulario')
    } else {
        // Logica para o formulario
        console.log('[executaLogicaNoFormulario]: executaLogicaNoFormulario: ', formulario)
    }
}

var novoPopUp = function (nome, id, blababla) {
    if (!nome && !id) return // sem nome e sem ID
    var forms = window.IDformularios || []
    forms.push(id)
    window.open(/* seus popups ... */)
}

var criaVariavelDinamica = function ( nome ) {
  if( window[nome] == null ){
    console.log('nova variavel adicionada:', 'window.'+nome);
    window[nome] = ''
  } else {
    console.log('Variavel ja existe: ', 'window.'+nome);
  }
}

validaFormularios(IDformularios)


Pentatonic scales fingering

Question: Can anyone tell me how they work these scales fingering?
I work them in groups having the same fingering. For example, one day I practice C, F, and G. My fingering is as follows:

LH: 3-2-1/2-1
RH: 1-2-3/2-1

That's for one octave.
I do the same for more than one octave; however, it feels like a little "too much work" compared to standard "classical" scales.
Any insight?
For the black keys, I work a similar system depending on their position, with a bit of adaptation.
All I do is always based on classical because it's the source of most music.
Just need to know what more experienced pianists think!
Answer: This is a really interesting question. I have never thought about this before, but here's what I'm thinking after playing around a bit.
For the white key scales that you mentioned, my first thought would be to use 1-2-3/1-2 (for the right hand ascending) like you have been doing.
I think a feasible alternative would be to use the gap between the thumb and forefinger to travel the gap in the scale. That would mean using 2-3-1/2-1 for the right hand ascending.
If we tried to do "less work" than two turns per octave, I think a 1-2-3/1-2-3/... pattern works quite well. You'd be matching five turns to every three octaves, though, so it might not be as easy to manage. After playing a while, I like how it feels - it's a fun way to play the scale, and it definitely feels like less work than the other methods above.

Pentatonic scales fingering


This loop outputs always the same number (iPad c compiler)

Question: #include <stdio.h>
#include <math.h>

int main(void)
{
    printf("Hello, World!\n");
    int n;

    for(int i = 1; i<30; i++)
    {
        n = i*i+i+i+i+1;
        printf("\n");
    }

    return 0;
}

I'd like this code to execcute a certain number for every value of i. However it always outputs 664.
Anyone knows why?
Comment: I would rather say it outputs hello world followed by a number of new lines... Post the actual code.
Comment: Always output  664? I dont even see where you write the output
Comment: Please see [ask] and [mcve].
Comment: see this https://ideone.com/wwNSZ1
Answer: I think you forgot to print n, if I understood you correctly.
The command printf("\n"); should only print a new line.
Try instead: printf("%d\n",n);.
Answer: Add
   printf("%d\n",n);

With your code i got compilation error "error: 'for' loop initial declaration used outside C99 mode"
Did you compile by turning on C99 mode?
By using
    -std=c99

after successful compilation(Note: Add the above printf line) got the different values on execution.


Sampling from matrix-variate normal distribution with singular covariances?

Question: The matrix-variate normal distribution can be sampled indirectly by utilizing the Cholesky decomposition of two positive definite covariance matrices. However, if one or both of the covariance matrices are positive semi-definite and not positive definite (for example a block structure due to several pairs of perfectly correlated features and samples) the Cholesky decomposition fails, e.g.
$\Sigma_{A} =
\begin{bmatrix}
1 & 1 & 0 & 0\\
1 & 1 & 0 & 0\\
0 & 0 & 1 & 1\\
0 & 0 & 1 & 1
\end{bmatrix}  \quad $or another example:$ \quad \Sigma_{B} =
\begin{bmatrix}
4 & 14 & 0 & 0\\
14 & 49 & 0 & 0\\
0 & 0 & 25 & 20\\
0 & 0 & 20 & 16
\end{bmatrix}$
Where $\Sigma_{B}$ is generated from $R$ (correlation matrix this time) = $\Sigma_{A} $
and $D$ (standard deviations) = $\begin{bmatrix}
2 & 0 & 0 & 0\\
0 & 7 & 0 & 0\\
0 & 0 & 5 & 0\\
0 & 0 & 0 & 4
\end{bmatrix}$ via $RDR$.
Is it possible to adapt the SVD based sampling technique for the multivariate normal case that overcomes this difficulty to the matrix-variate case?

This question is different from this post in that it is not clear if the lower diagonal produced by the SVD based sampling technique will suffice, since it is potentially quite different from one produced by a Cholesky decomposition that might be performed in this case by removing duplicate features and/or samples from the covariance matrices, performing the decomposition, and putting them back in. Also, the mentioned post is not concerned with positive semi-definite matrices.
Comment: When you say, "this method breaks down." Is the basic problem you can't do a Cholesky decomposition of a singular matrix?
Comment: Why not remove duplicate variables before Cholesky (or similar matrix square root)? Those with 100% correlation you can simply copy from their twins afterwards
Comment: @MatthewGunn I guess that seems to be it. Then the solution is basically similar to what was posted for the multivariate Gaussian.
Comment: @Aksakal How would you do this specifically in a simple example?
Comment: A comment I wrote in the duplicate thread points out that matrix square roots are not unique.  Therefore, your question is not any different from the question there: it is immaterial that the SVD might produce a different square root than the Cholesky decomposition.  Moreover, your question explicitly concerns semidefinite matrices: they are positive but of reduced rank, exactly as in the duplicate.  The duplicate completely and thoroughly answers your questions.  Moreover, some of the answers you have already received here duplicate answers there!
Comment: @whuber Alright. Even though the question of the duplicate post mentions "What should I do if CC is not positive semidefinite?" (which the covariances here are) the listed answers essentially are the same and applicable to the matrix-variate case (the later was not immediately apparent to me). Is this a duplicate as well then, http://stats.stackexchange.com/questions/159313/generating-samples-from-singular-gaussian-distribution/159322#159322 ?
Comment: The duplicate question may be worded in a confusing manner: your matrices are positive semidefinite but not positive definite--and that is exactly what the poster of the duplicate meant, too. (I just made a small edit to fix that up.)  I believe you did indeed find another duplicate--thank you.  I'm a little embarrassed at not noticing that, because I answered it, but evidently I had forgotten all about it. (I have just closed that one as a duplicate, so that every one of these threads points to the first one posted on the subject.)
Answer: This sounds more like an issue with singular covariance matrices than with random matrices vs. random vectors. To handle the latter issue, do everything as a random vector, and then in the last step, reshape the vector into a matrix.
To handle the former problem:
If your desired covariance matrix is singular...
Let $\Sigma$ be a singular covariance matrix. Because it's singular, you can't do a Cholesky decomposition. But you can do a singular value decomposition.
[U, S, V] = svd(Sigma)

The singular value decomposition will construct matrices $U$, $S$, and $V$ such that $ \Sigma = U S V'$ and $S$ is diagonal. Furthermore, $U = V$ (because $\Sigma$ is symmetric). The number of positive singular values will be the rank of your covariance matrix.
You can then construct $n$ random vectors of length $k$ with.
X = randn(n, k) * sqrt(S) * U'
Let $\mathbf{z}$ be a standard multivariate normal vector. The basic idea is that:
\begin{align*}
\mathrm{Var}\left(US^{\frac{1}{2}} \mathbf{z} \right) &= US^{\frac{1}{2}} \mathrm{Var}\left( \mathbf{x} \right)S^{\frac{1}{2}}U' \\
&= U S U'\\
&= \Sigma
\end{align*}
Once you get a vector $US^{\frac{1}{2}}\mathbf{z}$ you can simply reshape it to the dimensions of your matrix. (Eg. a 6 by 1 vector could become a 3 by 2 matrix.)
The SVD on a symmetric matrix $C$ is a way to find another matrix $A$ such that $AA' = C$.
Optional step to be a more clever mathematician and more efficient coder
Find the singular values below some tolerance and remove them and their corresponding columns from $S$ and $U$ respectively. This way you can generate less than a $k$ dimensional random vector $\mathbf{z}$.
Comment: Actually, the lower triangular obtained in this way ($US^{1/2}$) is different from the one produced by the Cholesky decomposition. See:  http://math.stackexchange.com/a/307208. Not sure if this will do for sampling from the matrix-variate normal in the way given here: https://en.wikipedia.org/wiki/Matrix_normal_distribution#Drawing_values_from_the_distribution.
Comment: @baf84b4c The SVD doesn't produce a lower triangular matrix. It is not a Cholesky decomposition.
Comment: Ah, yes. So, theoretically, if I had a positive definite matrix I could do both Cholesky decomposition and the SVD approach (which would be overkill). This means I would get a different kind of sampling by doing $LX$, where $L$ is the lower triangular obtained from the Cholesky decomposition and $US^{1/2}X$ according to your approach. And both should be correct?
Comment: Let $\mathbf{z}$ be distributed standard multivariate normal. $\mathrm{Var}(A'\mathbf{Z}) =A'\mathrm{Var}(\mathbf{Z}) A= A'A$. So **ANY** matrix $A$ such that $A'A=\Sigma$ will make $\mathbf{x} = A\mathbf{z}$ have covariance matrix $\Sigma$ that you want. And $A$ is not unique!. Perhaps do out the two-dimensional case by hand if you want to see that. If $x_1 = a z_1 + bz_2$ and $x_2 = c z_1 + d z_2$ you have four variables: $a$, $b$, $c$ and $d$. But there are only three constraints (i.e. (i) variance of $x_1$ (ii) variance of $x_2$ and (iii) covariance of $x_1$ and $x_2$)
Answer: If the only problem is in failure of Cholesky decomposition, then I'd try reducing the rank of matrix then duplicating the removed variables. Here's MATLAB example:
CODE:
%% singular cov matrix
C = [1 0.5 0.5; 0.5 1 1; 0.5 1 1]
chol(C)

%% reduce rank by removing duplicates
c = C(1:2,1:2)
h = chol(c)

%% bring back the twins

H = [h h(:,2)]

%% test Cholesky
r = randn(500,2);
cr = r*H;

cov(cr)

OUTPUT
C =

    1.0000    0.5000    0.5000
    0.5000    1.0000    1.0000
    0.5000    1.0000    1.0000

Error using chol
Matrix must be positive definite.

c =

    1.0000    0.5000
    0.5000    1.0000

h =

    1.0000    0.5000
         0    0.8660

H =

    1.0000    0.5000    0.5000
         0    0.8660    0.8660

ans =

    1.0063    0.4705    0.4705
    0.4705    0.9914    0.9914
    0.4705    0.9914    0.9914

>>

For the matrix in your example, H matrix will be very simple:
1 1 0 0
0 0 1 1

Comment: For the mentioned case of binary block structured covariance matrices, there seems to be an even simpler solution that doesn't involve any Cholesky decomposition, since it would just be a diagonal matrix after removing the duplicate pairs?
Comment: If it's all 1's and 0's, then yes, it's even simpler. You don't need any Cholesky at all. Just get the IIDs and duplicate as necessary.
Comment: Thanks. I see now that I can't simply reduce the rank by removing duplicates because the duplicates are actually in the correlation matrix and not the covariance matrix. For the later case an SVD based approach might be necessary.


Formal test to justify the use of sampling weights in survey data

Question: Is there a formal method/test/proof that one can use to justify the use of sampling weights when using survey data? You could compare the coefficients in both regressions, the R2, etc. But is this enough?
I ask this because there tests and estimation methods available for my software (Stata) is restricted when using weights.
Notice that the use of weights many times means that the sample sizes differ among regressions (as some observations have weight equal to zero).
Answer: Bollen et. al. (2016) wrote a pretty accessible paper following the suggestions from Fuller (2009) and Pfeffermann (1993) to utilize Hausman (1978) test.
Generally, Hausman test compares two sets of coefficient estimates that are expected to perform differently depending on whether a statistical model is correctly specified. If it is, there usually exists an asymptotically efficient estimate (e.g., a maximum likelihood one). If the model is misspecified, this great estimate often breaks down and may become inconsistent. That's where the other estimates comes to rescue that is robust to model misspecification, and consistent regardless of whether the model is specified correctly or not.
In the current setting, the efficient model is the one without weights (because adding weights usually leads to losses of efficiency known as design effects), while the robust model is the model with the full svy specification. If we are talking about regression, then the simple model is that of homoskedastic regression; the violations include the informative design features, where any of stratification, clustering, and unequal weights may be related to the outcome. Then with some tweaks you can form the Hausman test between the two; in Stata, you may have to use hausman, force option to override Stata's (generally justifiable) thinking that sandwich estimators should not be used in Hausman tests.
P.S. Zero weights sound iffy to me.
Comment: That reference was great!!! But now I feel you answer is incomplete **if it is to help others to give an quick overview of the issue**. As such I encourage you to write a more complete one, by, for example, pointing out the two type of methods (Hausman-RE-FE-style of tests and weighted association tests), and the incomplete state of the literature. This issue is of great importance and it seem researchers do not pay much attention to this. A more complete answer would help in that direction.(1/2)
Comment: In any case, I resolved my issue and implemented **9 tests (!)** in Stata to evaluate my weights, all with their proper reference! I am very happy! (2/2)
Comment: I write up what I have time for. Feel free to extend my answer or post your own.


Need to format power shell output

Question: I am pretty new to powershell and have been trying various ways to split the results from the following powershell script I found but have had no luck. At the moment the script list everything  in 4 columns with no gap in between the results of each server.
(when it finishes with the results for one server I would like a gap or even a header with the server name between each result to make it easier to read when run against multiple servers)
any help to get this formatted would be appreciated.
Get-WmiObject -ComputerName ("server1","server2") Win32_UserProfile | % {
  $userinfo = [WMI] ($_.__Path -Replace "Win32_UserProfile", "Win32_SID")
  New-Object PsObject -Property @{
    ComputerName= $_.__Server
    Domain      = $userinfo.ReferencedDomainName
    User        = $userinfo.AccountName
    LastUsed    = $_.ConvertToDatetime($_.LastUseTime)

  }
} | export-csv -NoType c:\Results.csv

Answer: I'm going to assume that when you say you want "easier to read" output, you mean want easier to read output on the console, and not in that CSV file.  Because CSV files are not meant to be pretty or easy for humans to read - CSV files are meant to be easy for computers to process.
So to that end, I've just ignored the Export-CSV cmdlet at the end. In my opinion, getting nice console output and getting efficient CSV data are two totally separate goals.
When I run your script, the output looks like this:
User            ComputerName    Domain          LastUsed
----            ------------    ------          --------
Ryan            SERVER1         SERVER1         9/25/2014 11:53:54 PM
NETWORK SERVICE SERVER1         NT AUTHORITY    9/25/2014 11:53:54 PM
LOCAL SERVICE   SERVER1         NT AUTHORITY    9/25/2014 11:53:54 PM
SYSTEM          SERVER1         NT AUTHORITY    9/25/2014 11:53:54 PM
Ryan            SERVER2         SERVER2         9/25/2014 11:53:54 PM
NETWORK SERVICE SERVER2         NT AUTHORITY    9/25/2014 11:53:54 PM
LOCAL SERVICE   SERVER2         NT AUTHORITY    9/25/2014 11:53:54 PM
SYSTEM          SERVER2         NT AUTHORITY    9/25/2014 11:53:54 PM

I see what you mean about the console not separating out or putting any "gap" between each computer.
So I made some modifications to your script:
:NextComputer Foreach ($Computer In "localhost", "localhost")
{
    Write-Host "                                      " -ForegroundColor Green -BackgroundColor Black
    Write-Host " Massive Flashy Header For $Computer! " -ForegroundColor Green -BackgroundColor Black
    Try
    {
        $Profiles = Get-WMIObject -ClassName Win32_UserProfile -ComputerName $Computer -ErrorAction Stop
    }
    Catch
    {
        Write-Error "Error while getting user profiles from $Computer`: $($_.Exception.Message)"
        Continue NextComputer
    }
    Write-Host " User profiles found: $($Profiles.Count)               " -ForegroundColor Green -BackgroundColor Black
    If ($Profiles.Count -LT 1)
    {
        Continue NextComputer
    }
    $ProfileCollection = @()
    :NextProfile Foreach ($Profile In $Profiles)
    {
        $UserInfo = [WMI] ($Profile.__PATH -Replace "Win32_UserProfile", "Win32_SID")
        $ProfileCollection += New-Object PsObject -Property @{
            ComputerName = $Computer
            Domain       = $UserInfo.ReferencedDomainName
            User         = $UserInfo.AccountName
            LastUsed     = $Profile.ConvertToDatetime($Profile.LastUseTime)
        }
    }
    $ProfileCollection | Format-Table -AutoSize
}

And now the output looks a little more readable, since the results from each computer are now separated from one another:
 Massive Flashy Header For SERVER1!
 User profiles found: 4

User            ComputerName Domain          LastUsed
----            ------------ ------          --------
Ryan            SERVER1      SERVER1         9/25/2014 11:56:50 PM
NETWORK SERVICE SERVER1      NT AUTHORITY    9/25/2014 11:56:50 PM
LOCAL SERVICE   SERVER1      NT AUTHORITY    9/25/2014 11:56:50 PM
SYSTEM          SERVER1      NT AUTHORITY    9/25/2014 11:56:50 PM

 Massive Flashy Header For SERVER2!
 User profiles found: 4

User            ComputerName Domain          LastUsed
----            ------------ ------          --------
Ryan            SERVER2      SERVER2         9/25/2014 11:56:50 PM
NETWORK SERVICE SERVER2      NT AUTHORITY    9/25/2014 11:56:50 PM
LOCAL SERVICE   SERVER2      NT AUTHORITY    9/25/2014 11:56:50 PM
SYSTEM          SERVER2      NT AUTHORITY    9/25/2014 11:56:50 PM

More to your liking, yes?
Comment: yeah that looks really good - I will need to export this into something so since you said csv is not good do you have any suggestions on what I can export this to? HTML? xls? can this be exported?
Comment: CSV is fine to store this kind of data in, if I were you I'd be fine with storing the output from your original script in a CSV just like it was. If you want to make something that is pretty and easy on the eyes, then yes HTML is the way to go.

Need to format power shell output


Pass datas to another component in Vuejs?

Question: I have this filter function (belongs a List component), then I need to pass the results to another component, (they are sibling) to fill my DataTable (parent component):
async filtroVariaveis () {
                try {
                    this.loading = true;

                    this.variaveis = await this.variaveisService.listVariables();

                    let idGrupos = null;
                    if (!this.grupos[0] && this.maquinaSelecionada[0]) {
                        idGrupos = this.gruposOpcoes.map(m => m.id);
                    }

                    if (!this.grupos[0] && !this.maquinaSelecionada[0] && this.areaSelecionada[0]) {
                        const idMaquinas = this.maquinasOpcoes.map(m => m.id);
                        const grupo = this.gruposOpcoes.filter(a => idMaquinas.includes(a.id_maquina));

                        idGrupos = grupo.map(a => a.id);
                    }

                    if (this.grupos[0]) {
                        idGrupos = this.grupos.map(g => g.id);
                    }

                    const tipos = this.tipoVariavel.map(t => t === "Analógica" ? t = "ANALOGICA" : "DIGITAL");
                    const tag = this.tagInput || this.variaveis.map(t => t.tag);
                    const descricao = this.descricaoInput || this.variaveis.map(d => d.descricao);

                    this.filtroAplicado = ((await this.variaveisService.listVariables(idGrupos, tipos, tag, descricao)) || []);
                } catch (err) {
                    console.log(err);
                }

this.variaveisService is my Axios services that communicates with my API.
My List component:
<template>
<two-cards>
        <template #header>

Filtros

            <slot>
                <router-link
                    to="/variaveis/add"
                    class="btn btn-success text-white align-self-center"
                >
                Adicionar variável
                </router-link>
            </slot>
        </template>
        <template #one>
            <form class="mt-2" @submit.prevent="filtroVariaveis">

                        Tag:

                        Descrição:

                        Área
                            <vue-multi-select
                                class="multi-100"
                                v-model="areaSelecionada"
                                @input="checarArea"
                                search
                                historyButton
                                :options="{ multi: false, labelName: 'nome' }"
                                :selectOptions="areasOpcoes"
                                :btnLabel="() => areaSelecionada[0] ? areaSelecionada[0].nome : 'Selecione'"
                            />

                        Máquina
                            <vue-multi-select
                                class="multi-100"
                                v-model="maquinaSelecionada"
                                :disabled="!areaSelecionada[0]"
                                @input="checarMaquina"
                                search
                                historyButton
                                :options="{ multi: true, labelName: 'nome' }"
                                :selectOptions="maquinasOpcoes"
                                :btnLabel="() => customLabel(maquinaSelecionada)"
                            />

                        Grupo
                            <vue-multi-select
                                class="multi-100"
                                v-model="grupos"
                                search
                                historyButton
                                :options="{ multi: true }"
                                :selectOptions="gruposOpcoes"
                                :btnLabel="() => customLabel(grupos)"
                            />

                        Tipo
                            <vue-multi-select
                                class="multi-100"
                                v-model="tipoVariavel"
                                search
                                historyButton
                                :options="{ multi: true }"
                                :selectOptions="tiposOpcoes"
                                :btnLabel="() => customLabel(tipoVariavel)"
                            />

                    <button
                        class="btn btn-success tcs-btn"
                        type="search"
                    >
                        <SearchIcon />
                    </button>

            </form>
        </template>
        <template #two>
            <GenericList
                title="variáveis"
                :linhas="linhas"
                data-table-state-name="Variável"
                add-route="add_variavel"
                edit-route="edit_variavel"
                :cols="['#', 'Tag', 'Descrição', 'Tipo']"
                :cols-name="['id', 'tag', 'descricao', 'tipo']"
                :cols-map="i => [i.id, i.tag, i.descricao, i.tipo]"
            />
        </template>
    </two-cards>
</template>

computed: {
            linhas () {
                return this.lista.map((row) => ({
                    href: { name: this.editRoute, params: { id: row.id }},
                    cols: this.colsMap(row)
                }));
            }
        },

My GenericList component, where I need to put this datas:
<template>

        <DataTable
            scroll
            :async="pagination"
            :loading="loading"
            :colunas="parsedCols"
            :linhas="linhas"
            :errMsg="errMsg"
            :state="dataTableState"
            @state-change="setStateDataTable"
        >
            <template #results-page v-if="pagination">
                <select
                    class="custom-select ml-1"
                    :value="results"
                    @input="changeResults"
                    data-cy="resultados-pagina"
                >
                    <option value="10">10 por página</option>
                    <option value="20">20 por página</option>
                    <option value="50">50 por página</option>
                    <option value="100">100 por página</option>
                    <option v-if="canShowAllResults" value="-1">
                        Mostrar todos
                    </option>
                </select>
            </template>
            <template v-for="col in cols" v-slot:[col]="{ value, item }">
                <slot :name="col" :value="value" :item="item">
                    <router-link
                        v-if="value && value.rota && value.nome && value.id"
                        :to="{ name: value.rota, params: { id: value.id } }"
                        title="Ir para a edição"
                        >
                        <edit-icon size="16" /> {{ value.nome }}</router-link
                    >
                </slot>
            </template>
        </DataTable>
        <Paginator
            :page="page"
            :pages="pages"
            :count="count"
            :disabled="loading"
            :first="first"
            :last="last"
            @paginate="paginate"
        />

</template>

props: {
        loading: Boolean,

        title: {
            type: String,
            required: true
        },

        addRoute: {
            type: String,
            required: true
        },

        editRoute: {
            type: String,
            required: true
        },

        dataTableStateName: {
            type: String,
            required: true
        },

        lista: {
            type: Array
        },

        linhas: {
            type: Array
        },

        cols: {
            type: Array,
            required: true
        },

        colsMap: {
            type: Function,
            required: true
        },

        colsName: {
            type: Array,
            required: true
        },

        canShowAllResults: {
            type: Boolean,
            default: false
        },

        showInativos: {
            type: Boolean,
            default: false
        }
    },

data () {
    return {
        errMsg: "",

        pagination: false,
        page: 0,
        pages: 1,
        results: 20,
        first: 0,
        last: 0,
        count: 0
    };
},

computed: {
    dataTableState () {
        return this.$store.state.dataTables[
            "dataTable" + this.dataTableStateName
        ];
    },

    parsedCols () {
        return this.cols.map((c, idx) => this.colsName[idx] ? c : { value: c, sortable: false }
        );
    }
},

I dont know how to fill this DataTable, someone can helps me?
Comment: Depends on the position of the 2 components. are the components sibling ? or parent to child?
Comment: @ElsaKarami They are sibling..
Answer: you can use $emit and $on for passing data between sibling components.
please look at this example
when you pass data into another component you have to set this line:
this.$root.$emit('eventing', data);

and after that, you can receive data into the destination component like this example:
1)
mounted() {
  this.$root.$on('eventing',this.functionName);
}

OR
2)
mounted() {
    this.$root.$on('eventing', data => {
        console.log(data);
    });
}

please pay attention, you had better set $off into the destination component
1)
 beforeDestroy() {
    this.$root.$off("eventing", this.functionName);
  }

OR
2)
beforeDestroy() {
  this.$root.$off("eventing");
}

you can find data you need into arguments in the this.functionName
Comment: this.$root.$emit('eventing', data);
and inside GenericList page , you need to set $on like :

`mounted() {
    this.$root.$on('eventing', data => {
        console.log(data);
    });
}`
Comment: This seems to work, thanks Elsa! The console is already showing me what I want, but I still don't know how to fill the table with this results, if you can help me with that I really really appreciate...
Comment: thank you. you need to set v-if inside table tag. because the table render before call emit
Comment: In my Generic List component:   `mounted () {
   this.$root.$on("filtroVariaveis", data => {
    this.pagination = true;

    console.log(data);
   });
  }`
Comment: you can set like this:

 beforeDestroy() {
    this.$root.$off("filtroVariaveis");
  }

after mounted part
Comment: Where I put `this.$root.$emit('eventing', data);`?
Comment: when you need to pass data into second component. for example, I need to pass data when I click btn into the first component
Comment: when you need the data into the second component?
Comment: I need when I click to do the search, this result is what will fill my table. I'm a beginner so I don't really know what to do.. I understand your example I just don't know how to do it.
Comment: So I would like how I could do this, with real examples according to what was shown in the question
Comment: it's ok. I can help you. you need to set '$emit' inside response API after search. do you call API after click?
Comment: Yes, I call in here: `this.filtroAplicado = ((await this.variaveisService.listVariables(idGrupos, tipos, tag, descricao)) || [])` in my List component, inside the filter function. Passing my datas
Comment: Do you want my DataTable component to? Maybe can be useful
Comment: what is the btn :    `

`
Comment: you need to set $emit inside this.variaveisService response
Comment: `  ` Is a search icon for the user click
Comment: why you don't have @click="searching" in this btn?
Comment: Like this? this.filtroAplicado = ((await this.variaveisService.listVariables(idGrupos, tipos, tag, descricao), this.$root.$emit()) || []);
Comment: I have the `@submit.prevent="filtroVariaveis`
Comment: no . can i see this function this.variaveisService.listVariables?  you call this service here . i wanna see inside this.variaveisService.listVariables service
Comment: `async listVariables (idGrupos, tipos, tag, descricao) {
  const response = await this.axios.get("variables", {
   params: {
    id_grupos: (idGrupos || []).join(","),
    tipos: (tipos || []).join(","),
    tag,
    descricao
   }
  });
  return response.data;
 }`
Comment: I opine you can set $emit  before `return response.data`
Comment: This service is used in other parts of the project, wouldn't that cause problems?
Comment: `this.filtroAplicado = ((await this.variaveisService.listVariables(idGrupos, tipos, tag, descricao)) || []);`

`if (this.filtroAplicado && this.filtroAplicado.length){
this.$root.$emit ....
}`
Comment: $emit(what)? And what I do in GenericList to listen that?
Comment: I accept your answer anyway! :)
Comment: `beforeDestroy() {
  this.$root.$off("eventing");
}` You mentioned it, how do I use it?
Comment: can i see `this.$root.$on` code you used it?
Comment: Thanks again :) Last question, "to set v-if inside table tag" thats inside GenericList too, right? But I already have `v-if="pagination"` so I have to do something inside this?
Comment: your welcome. you can define variable for fill with data inside $on like this:
`mounted () {
this.$root.$on("filtroVariaveis", data => {
this.pagination = true;
this.searchResult = data
}); }`

and you can improve your v-if like this:  `v-if="pagination && searchResult"`
Comment: Hi again Elsa! I still haven't been able to fill the DataTable, can you help me? I opened a new question https://stackoverflow.com/questions/69712392/datable-in-vuejs-is-not-filled


Lost in DateTime in powershell

Question: I somehow is lost in DateTime in Powershell
My Function To validate DateTime. Note It was sleeker but I was lost so started explicit returns of Good Bad. Don't Mind that. I want to capture the  following

Start Time and End Time entered is correct (not junk)
End Time is bigger than Start Time
End Time is larger than current Time in UTC
Start Time is larger than current time in UTC

function IsValidTimeStamp($startDate,$endDate)
{
    [ref]$parsedDate = (Get-Date).ToUniversalTime()
    if (!([DateTime]::TryParseExact($startDate,"M/d/yy H:mm",[System.Globalization.CultureInfo]::InvariantCulture,
        [System.Globalization.DateTimeStyles]::None,$parseddate))){
            return ("Bad")
        }
    elseif(!([DateTime]::TryParseExact($endDate,"M/d/yy H:mm",[System.Globalization.CultureInfo]::InvariantCulture,
        [System.Globalization.DateTimeStyles]::None,$parseddate))){
            return ("Bad")
        }
    elseif(!(Get-date $([datetime]::ParseExact($endDate,"M/dd/yy H:mm",$Null))) -gt (Get-Date $([datetime]::ParseExact($startDate,"M/dd/yy H:mm",$Null)))){
            return ("Bad")
        }
    elseif((Get-date $([datetime]::ParseExact($startDate,"M/dd/yy H:mm",$Null))).ToUniversalTime() -gt $([System.DateTime]::UtcNow)){
            return ("Bad")
        }
    elseif((Get-date $([datetime]::ParseExact($endDate,"M/dd/yy H:mm",$Null))).ToUniversalTime() -gt $([System.DateTime]::UtcNow)){
            return ("Bad")
        }
    else
        {return ("Good")}
}

Now when I enter the a proper date which is less than current UTC time
$startDate = '03/20/23 14:00' & $endDate = '03/20/23 14:30'
Something is not correct. Most Likely the statement
elseif((Get-date $([datetime]::ParseExact($startDate,"M/dd/yy H:mm",$Null))).ToUniversalTime() -gt $([System.DateTime]::UtcNow)){
            return ("Bad")
        }
 elseif((Get-date $([datetime]::ParseExact($endDate,"M/dd/yy H:mm",$Null))).ToUniversalTime() -gt $([System.DateTime]::UtcNow)){
            return ("Bad")
        }

Strangely if you see both the results are returning false as even though I am using a not operator

I am calling the function like this below
 if ((IsValidTimeStamp $($LINE.Start_Time) $($LINE.End_Time)) -eq "Good"){
                #Basic validation of DateTime is successful
               ###Do something else ###
}
else{
       echo "Failed to validate dateTime"
}

As asked below copy pasting the commands ran on the console
PS D:\Maintenance-Window> $startDate = '03/20/23 14:00'

PS D:\Maintenance-Window> $endDate = '03/20/23 14:30'

PS D:\Maintenance-Window> [ref]$parsedDate = Get-Date

PS D:\Maintenance-Window> !([DateTime]::TryParseExact($startDate,"M/d/yy H:mm",[System.Globalization.CultureInfo]::InvariantCulture,
        [System.Globalization.DateTimeStyles]::None,$parseddate))
False

PS D:\Maintenance-Window> !([DateTime]::TryParseExact($endDate,"M/d/yy H:mm",[System.Globalization.CultureInfo]::InvariantCulture,
        [System.Globalization.DateTimeStyles]::None,$parseddate))
False

PS D:\Maintenance-Window> !(Get-date $([datetime]::ParseExact($endDate,"M/dd/yy H:mm",$Null))) -gt `
            (Get-Date $([datetime]::ParseExact($startDate,"M/dd/yy H:mm",$Null)))
False

PS D:\Maintenance-Window> (Get-date $([datetime]::ParseExact($startDate,"M/dd/yy H:mm",$Null))).ToUniversalTime() -gt `
            $([System.DateTime]::UtcNow)
False

PS D:\Maintenance-Window> !(Get-date $([datetime]::ParseExact($startDate,"M/dd/yy H:mm",$Null))).ToUniversalTime() -gt `
            $([System.DateTime]::UtcNow)
False

If you look closely the last two commands are exactly the same one with the Not symbol in front. Since the input time has passed than current UTC time I expected a True.
EDIT Final Script
function IsValidTimeStamp($startDate,$endDate)
{
    [ref]$parsedDate = (Get-Date).ToUniversalTime()
    if (!([DateTime]::TryParseExact($startDate,"M/d/yy H:mm",[System.Globalization.CultureInfo]::InvariantCulture,
        [System.Globalization.DateTimeStyles]::None,$parseddate))){
            return ("Bad")
        }
    elseif(!([DateTime]::TryParseExact($endDate,"M/d/yy H:mm",[System.Globalization.CultureInfo]::InvariantCulture,
        [System.Globalization.DateTimeStyles]::None,$parseddate))){
            return ("Bad")
        }
    elseif(!((Get-date $([datetime]::ParseExact($endDate,"M/d/yy H:mm",$Null))) -gt (Get-Date $([datetime]::ParseExact($startDate,"M/d/yy H:mm",$Null))))){
            return ("Bad")
        }
    elseif(!((Get-date $([datetime]::ParseExact($startDate,"M/d/yy H:mm",$Null))).ToUniversalTime() -gt $([System.DateTime]::UtcNow))){
            return ("Bad")
        }
    elseif(!((Get-date $([datetime]::ParseExact($endDate,"M/d/yy H:mm",$Null))).ToUniversalTime() -gt $([System.DateTime]::UtcNow))){
            return ("Bad")
        }
    else
        {return ("Good")}
}

Comment: Are you deliberately mixing ```d``` and ```dd``` for the "day" part of your date format string?
Comment: Your `!` operations negate the `(Get-Date ...).ToUniversalTime()` part only, i.e. you're negating a `[datetime]` instance, which is always `$false`.
Comment: How do we compare a datetime with current universal time. Am I doing something incorrect. It is really strange why it won't work
Comment: @mclayton a very good catch. My Input dates were a mistake. M/d/yy H:mm
Comment: @mklement0 I understood what you are saying. How do I make the whole statement as negate. As you understand I want to return bad if input date is -lt than utc date it is bad
Comment: @mklement0 bracket Issue. I see added additional bracket.
Answer: function IsValidTimeStamp($startDate, $endDate){
try { (get-date) -lt $startDate -and [datetime]$startDate -lt
$enddate } catch { $false } }

get-date
Monday, March 20, 2023 2:13:58 PM

isvalidtimestamp 3/21 3/22
True

isvalidtimestamp 3/21 3/20
False

isvalidtimestamp 3/21 3/21
False

isvalidtimestamp 3/23 3/24
True

isvalidtimestamp 3/23 0/24
False

Comment: Nicely done; one wrinkle: If you pass invalid date strings, the function call breaks fundamentally rather than returning `$true` or `$false`. You can fix that with `function IsValidTimeStamp($startDate, $endDate){ try { (get-date) -lt [datetime] $startDate -and [datetime] $startDate -lt $enddate } catch { $false } }`. Note that use of `-as` is tempting, but `-as` actually performs _culture-sensitive_ conversions, unexpectedly - see [GitHub issue #8129](https://github.com/PowerShell/PowerShell/issues/8129).
Comment: for that TryParseExact first and return false if not parsing for the two dates. Thank You guys for all the ideas i think  i am able to fix it.
Answer: When comparing two datetime ranges there are 7 different results
Comment: Well My Input Time (start and end time) should be always greater than current Time. If not its bad time entered

Lost in DateTime in powershell


ML technique recommendations where each feature has multiple properties and the number of features per observation varies

Question: Here is an abstracted version of the problem I am facing.
I wish to predict the true value of a variable from multiple noisy predictions as to its value. There are three complicating factors:
For each observation, I receive multiple noisy predictions from different sources. The sources may each provide valuable information, but are likely to differ in their accuracy (I'm using accuracy in its common sense rather than as a technical term here).
Each prediction is timestamped, with later predictions tending to be more accurate than earlier ones. The function which defines the relationship between time and accuracy is strictly increasing but otherwise unknown (e.g. it may be discontinuous, the order rather than the amount of time elapsed may be the only thing that matters).
The number of predictions obtained from any given source is not constant across observations (and the number of predictions for any given observation varies from source to source).
Just to provide a very rough illustration:
obs 1:
y = 2.5,
x[t=10,s=1] = 2.6,
x[t=7,s=3] = 2.2,
x[t=4,s=1] = 2.3,
x[t=3,s=3] = 3.1
obs 2:
y = 4.2,
x[t=8,s=3] = 4.5,
x[t=3,s=1] = 3.7,
x[t=2,s=1] = 3.8
x[t=1,s=2] = 3.8
etc
So what do I do guys? I'm having real trouble seeing how to translate this data into a table of features. The main problem I can see is that the source, timestamp, and value for each observation of x seem to be inseparable and thus ought to be coded as a single feature. But this appears to be impossible.
I suppose modelling each source separately and ensembling the models would be easier, but it doesn't seem ideal. For instance, even if source 1 is generally more accurate, it shouldn't be weighted as highly if its predictions are on average earlier for a given observation.
I imagine that some kind of neural network would be best at aggregating these data in such a way as to take advantage of all the potential non-linearities, but I'm struggling to work out would the best algorithm would be and how to engineer features for it.
Comment: Is each sensor specific to each output, or does each sensor measure each output? When you say accuracy is non-decreasing: is that absolute or in expectation? If absolute then you could ignore all but the latest. Is the probability of observing a measurement independent of the value measured? Or do measurements happen more frequently based on the value of y?
Comment: Output is uni-dimensional. That is, for each observation, we have some number of sources each making some number of measurements as to a single output value. The sources are constant across observations (we can make the assumption that each source makes at least one prediction of each output - I'll edit the example).

Accuracy is increasing in expectation, by which I mean that the variance of the white noise in each prediction is falling (but there could still be valuable information in those previous observations).
Answer: Try this for the x samples:

Treat the indexes of x (time and source) and its values as separate columns (e.g. x now has examples of 3 fields like (t,s_t,x_t)).
Discretize your timestamps (e.g. granularity of 1 sec ou 1 min).
At the instants t that don't have data, fill the fields with the mean of the other examples. A worse but easier workaround is filling with dummy values (e.g. zero).

For y:

Use LSTM to map from x but take only the last output to compute the result (e.g. add a regression layer at the end)
OR
Use LSTM and aggregate all outputs (e.g. with mean and variance) and do regression with the result (e.g. with regression layer at the end)
Comment: Thank you - I will try this. One question, I am concerned that accuracy does not vary with time in a smooth manner. For instance, it might be a step function. That is, the sensor may provide an update when the sensor receives enough additional information to refine the prediction. In that case the time elapsed is irrelevant. Do you think I could model this by encoding a one-hot vector of features of dim(T*S) with a value of one if sensor s provided an update at t (alongside the vector of values with mean used for missing data)? Or by some other means?
Comment: By "one-hot vector of features of dim(T*S)" you mean represent your time series as one big vector?
Comment: Anyway I think you can put that as input feature as well. Instead of using mean for missing data you can also interpolate neighboring values. And you can also represent the sources as one-hot encoding instead symbol.
Comment: Thanks very much for your help. LSTM definitely looks interesting so I will try that.
Answer: You do not provide much detail in your question, so the answer is likewise somewhat vague. What is clear is that you have a panel data structure. Check Wikipedia for how this is usually formatted. Given that your observations are unequally spaced, you will have many missing data points. There are two solutions to this:

Reduce missing values by downsampling the observed data, which obviously results in information loss.
Create new data that resembles the observed data with a (multiple) imputation process. This does not result in information loss, but may seriously bias the results. How serious depends on many factors.

But in the example that you describe, there may be another interesting solution. If the sensors all measure the same thing, but with differing accuracy, then they can represented as measurements of a single sensor with a varying (but known) accuracy. This collapses one dimension of the panel, thus reducing the amount of missing data. But no information needs to be lost because the accuracy of the different sensors can be encoded as sampling weights.
Comment: Thank you for your suggestion. Just to be clear, the approach would be to estimate the relative accuracy of each sensor - for instance, by calculating the mean squared error of the latest (most accurate) prediction for each sensor - and then weighting all of each sensor's predictions accordingly? Am I right in thinking that this makes assumption that the function that describes the increase in a sensor's accuracy over time is the same for each sensor?
Comment: Note that each observation has an individual sample weight, so there is no other restriction than that they sum to one over the entire sample. The problem is how to obtain a set of reasonable sample weights. Ideally, one would know the relative accuracy of each sensor at each point in time, but this is likely unavailable. If sensor accuracy does not change over time, one could estimate the *average* relative accuracy of each of the sensors - and assign sample weights that remain constant over time. But I would not know how to assign sample weights if sensor accuracy *does* change over time.
Comment: How about:

- fit separate models for each sensor to derive separate functions for the variation of accuracy over time.

- in the full dataset, weight each prediction at each time accordingly, allowing you to treat each sensor the same way

- refit using the same technique as in the first stage.

The question then is what technique to use? LSTM (as mentioned by the other commenter) looks like it could be promising (but I have no experience with neural nets). But I don't know if there's something better for unevenly-space time series data.
Answer: I'm a bit of a one-trick pony lately, but this seems like a perfect case for Bayesian methods. You need incremental information, and the fact that the observations are noisy further supports the case for them.
Your goal would be to get $p(Y|S,P,X, [T])$, where the parameters are:
$S$ - Source
$P$ - Precision (i.e. reliability of the source)
$X$ - Value measured by the Source.
$T$ - Time (optional, and will complicate matters)
For multiple sources, you can then combine these into the final posterior distribution via the same general procedure.
In particular, if you ignore Time and your sources are some physical measurements (or are otherwise very macro-scale), it should be safe to model them all as Gaussians. This would let you plug in the numbers to an already established equations in a fairly straightforward fashion.
To spare some virtual trees, and since I don't know if you know the source precision or not, you can find them here.
Comment: Thanks for your comment - the issue is that I have reason to believe that time is the most important feature when it comes to accuracy. That is, later values carry much more information than earlier values, irrespective of the source (so you'd rather use the latest value from a single source than aggregate all values from multiple sources). In addition, the precision of the sources is unknown Would there be a way to incorporate this into a Bayesian methodology? Maybe by starting with the average latest signal as the mean of a Gaussian for a prior? Not sure how to proceed from there.
Comment: You can account for time, I thought you meant it increases the precision - but you just have a preference for fresher data, so it's just another variable that can be modelled as independently influencing the prediction. I would wrangle it to 'offset from now into the past' and make it exponential. The precision being totally unknown can be handled; you can either just straight up assume it arbitrarily for each source, model it as a Gamma, or establish it empirically if you can.
Comment: Thanks - can you point me to any sources on practical model fitting using Bayesian methods? I am familiar with it on a theoretical/mathematical level (conjugate priors, data augmentation, max a posteriori) but don't know where to start with putting it into practice.
Comment: Have you had a look at Bayesian Methods for Hackers? It's available as, of all things, a Git repo, for free. You can find it at: https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers


show if $r \to b + \varepsilon$ then $\sin(r) = \sin(b)\cos(\varepsilon) + \cos(b)\sin(\varepsilon) \approx (-1)^n\varepsilon$

Question: I'm looking at circular motion, and looking at the radial vector $r$ and seeing what happens when $r$ changes by a small $\varepsilon$ (if $r$ was initally $b$). I'm trying to form a second order ODE for $\varepsilon$ and I have a $\sin(b+\varepsilon)$ to take care of and the solutions show that: if $r \to b + \varepsilon$ then $\sin(r) = \sin(b)\cos(\varepsilon) + \cos(b)\sin(\varepsilon) \approx (-1)^n\varepsilon$.
I understand the equality part from the double angle formulae but where did the $(-1)^n\varepsilon$ come from?
Comment: What is $n$ supposed to be? Note that $\sin \epsilon\approx\epsilon$.
Comment: @SanathDevalapurkar an integer im assuming - the question does not state it
Answer: Thinking about it this must be a typo and I think it should be $\sin(r)\approx (-1)^n\epsilon+\sin(b)$
since $r\to b+\epsilon$$\,$, $b$ could be larger or smaller than $r$, so equivilantley, we could have $\epsilon\gt 0$ or $\epsilon\lt 0\,$, thus:
$\cos(b)\sin(\epsilon)\approx(-1)^n\epsilon$
and $\sin(b)\cos(\epsilon)\approx\sin(b)$
thus:
$\sin(r)=\cos(b)\sin(\epsilon)+\sin(b)\cos(\epsilon)\approx(-1)^n\epsilon+\sin(b)$
Which actually does make sense since it is saying that if $r$ varies slightly, the value $\sin(r)$ changes slightly as well.
Comment: I have edited my answer, and I think it makes sense, but I hope it helps :)
Comment: There are a couple things I don't see. First, if you replace $\cos\epsilon$ with $1$, why wouldn't you replace $\sin\epsilon$ with $0$? Second, you seem to replace $\cos b$ with $1$, I don't see why you do that.
Comment: well $|cos(b)|\le 1$ and since $\epsilon$ is small it dominates the term, so we can "let" $cos(b)=1$, whereas for small $\epsilon$, $\sin(\epsilon)$ behaves very much like $\epsilon$ and it is the dominating term, so we include it.
Comment: I don't see it (and I agree that it is probably a failure in the formulation of the question). It could be that $\cos b=1/10$, say. Then you are saying that $\frac1{10}\sin\epsilon\approx\epsilon$ and that $\sin\epsilon\approx\epsilon$, from where you conclude that $\frac1{10}\epsilon\approx\epsilon$.
Comment: @MartinArgerami
Yes this is because $\epsilon$ is very very small, so multiplying by a number of "moderate" size like $1/10$ makes almost no difference
Comment: @MartinArgerami
and $\sin\epsilon=\epsilon-\epsilon^3/3!+\epsilon^5/5!\pm...$, and every time you square or cube $\epsilon$ it gets much much smaller, thus $\sin\epsilon\approx\epsilon$


Get key in groovy maps

Question: def map = [name:"Gromit", likes:"cheese", id:1234]

I would like to access map in such a way that I can get the key
something like the output should be
map.keys returns array of string. basically i just want to get the keys
output:
name
likes
id

Answer: try map.keySet()
and if you want an array:
map.keySet() as String[]; // thx @tim_yates

Or, more groovy-ish:
map.each{
    key, value -> print key;
}

Warning: In Jenkins, the groovy-ish example is subtly broken, as it depends on an iterator. Iterators aren't safe in Jenkins Pipeline code unless wrapped in a @NonCPS function.
Comment: or `map.keySet().collect()`
Comment: or `map.keySet() as String[]`
Comment: or `map.keySet() as List`.
Answer: def map = [name:"Gromit", likes:"cheese", id:1234]

println map*.key

In groovy * is use for iterate all

Get key in groovy maps