Finding two skew symmetric matrices with same exponential value

Question: I've have the following problem.
I need to come with an example for two skew symmetric matrix $A,B$ such that $\exp(2\pi A)$ = $\exp(2\pi B)$
I tried matrix $2x2$ but I guess this is useless to just try, I probably need to construct the matrix by some thm.
Now, Only I know is that the function $F$ defined by $F(A) = \exp(A)$ has the next properties:

derivative near 0 is the identity matrix
$F$ itself is diffeomorphism of neighborhood contains 0 to neighborhood of $I_n$

How can I proceed from here?
Answer: Hint: If we let $J = \begin{bmatrix}0 & -1 \\ 1 & 0\end{bmatrix}$, then $\exp(\theta J) = \begin{bmatrix}\cos \theta & -\sin \theta \\ \sin \theta & \cos\theta\end{bmatrix}$.
Can you find two numbers $\theta_1 \neq \theta_2$ such that $\exp(\theta_1 J) = \exp(\theta_2 J)$?


How to export / feature the "picture guidelines" field

Question: I have some legal mentions to put under the file upload form of user account.
I would like to put them a feature some elements about user configuration, but I'm not able to find which variable (i.e. Strongarm or anything else) is mapped to field "Picture guidelines"
(available in Home » Administration » Configuration » People).
Could someone give me a hint, or is it even possible ?
Answer: Use Strongarm to export the variable called user_picture_guidelines.
Comment: Ah ! Indeed I've already exported it ... and so it was not available to export in feature GUI. Thanks :)


High Level Time Series Forecasting Question given a set of unknown data sets

Question: I have this question regarding 4 data sets where one of the data sets is missing half of the data. The data is relatively correlated, but not perfectly. How may we construct a model to produce the fourth data source's missing data? Suppose this data is generally upward trending with seasonal cycles, as well as a large dip in 2020.
As a side note, this is a purely theoretical question and I'm just curious how other's would approach such a problem. I'm not looking for some good library to use or any complex algorithm, but rather high level reasoning for how to create a good predictor. Thank you!
Comment: So if this is a "purely theoretical question" why is pandas functionality important? In general, the best solutions involve customized code, not just a rearrangement of several library functions.
Comment: Yes, you're right. I edited the question to reflect this.
Answer: 1] Develop a Seasonal ARIMA model for each of the 4 series.
2] Back out shocks (residuals) for "non-missing" days.
3] Collect shocks $(\varepsilon_1,\varepsilon_2,\varepsilon_3,\varepsilon_4)$ over the "non-missing" days.
4] Estimate their joint distribution function as $$
F(\varepsilon_1,\varepsilon_2,\varepsilon_3,\varepsilon_4) = C_{\alpha,\rho}\Bigl(F_1(\varepsilon_1),F_2(\varepsilon_1),F_3(\varepsilon_1),F_4(\varepsilon_1)\Bigr),
$$
where $C_{\alpha,\rho}()$ is some standard Copula family. The joint cdf implies conditional cdf $F(\varepsilon_4\, |\, \varepsilon_1,\varepsilon_2,\varepsilon_3)$.
5] Simulate $\varepsilon_4$ out of $F(\varepsilon_4\, |\, \varepsilon_1,\varepsilon_2,\varepsilon_3)$ for those days when $(\varepsilon_1,\varepsilon_2,\varepsilon_3)$ are available.


Partial fractions ODE first order

Question: Given the problem: $\frac{dx}{dt} = 3x(x-5)$ The answer is supposedly:
$\dfrac{40}{8-3e^{-15t}}$ with $x(0) = 8$
first off you can't have a negative power in the denominator it should just be $e^{15t}$.
I know for a fact I did my partial fractions correctly:
$1 = \dfrac{A}{3x} + \dfrac{B}{x-5}$ translates to: $Ax-5A+15xB$
At $x = 0: A = -\frac{1}{5}$
At $x = 5: B = \frac{1}{15}$
Of course this comes to:
$\int \dfrac{\dfrac{-1}{5}}{3x} + \dfrac{\dfrac{1}{15}}{x-5}$
which becomes:
$-\frac{1}{15}\ln \vert 3x \vert + \frac{1}{15} \ln \vert x - 5 \vert = t + c$
multiply by $-15$ to give:
$\ln \vert 3x \vert - \ln \vert x-5 \vert = -15t + c$
multiplying by $e$:
$3x-x +5 = Ce^{-15t}$
$2x = Ce^{-15t}-5$
$x(t) = \dfrac{2}{Ce^{15t}} - 5$
$8 = \dfrac{2}{C}-5 \to C = \dfrac{2}{13}$
Now I am thinking there is either a mistake in the book or they "simplified" it somehow
Comment: @K.Gibson You made a mistake on the left hand side when "multiplying by $e$" (which is not the correct terminology)
Comment: what does he mean 15 isn't possible. That was derived from Partial fractions.
Comment: What do you mean by "first off you can't have a negative power in the denominator it should just be $e^{15t}$."? Why should one be able to write negative exponents in the denominator?
Comment: well in the answer they have a a negative power in the denominator when we have $x^{-2}$ we dont write $\frac{1}{x^{-2}}$ we write $\frac{1}{x^2}$
Comment: Well whats the issue?
Comment: Also, $\int \frac{1}{3x}dx\neq \ln|3x|$
Comment: It has to. What are you going to do add  one to the power and get 0 for a power which equals 1?
Comment: $\frac{1}{3} ln \vert 3x \vert$
Comment: That is also wrong. You also don't need to do partial fractions to solve this problem.
Comment: you mean that its not equal to a ln? That doesnt make sense i dont follow
Comment: See [here](https://socratic.org/questions/what-is-the-integral-of-int-1-2x-dx).
Comment: I misread: [WolframAlpha](https://www.wolframalpha.com/input/?i=y%27+%3D+3y+%28+y+-+5%29+and+y%280%29+%3D+8) confirms that it should indeed say $e^{\color{red}{+}15}$ in the denominator.
Comment: You did not do the partial fraction decomposition formally correct, as the start should be $$\frac1{3x(x-5)}=\frac{A}{3x}+\frac{B}{x-5}.$$ Then multiplying away the denominators lead to the equation $$1=A(x-5)+B(3x).$$
Answer: Before giving you a complete solution I want to point out the mistakes in your solution.

Your partial fractions are correct.
As mentioned in the comments $\int \frac{1}{ax} dx \ne \ln | a x |$. Instead we have
$$
\int \frac{1}{ax} dx = \frac{1}{a} \int \frac{1}{x} dx = \frac{1}{a} \ln | x|
$$
for $a \ne 0$.
We have $e^{\ln(a) - \ln(b)} \ne a - b$. This is because $\ln(a) - \ln(b) = \ln \left(\frac{a}{b}\right)$ and therefore
$$
e^{\ln(a) - \ln(b)}
= \frac{a}{b}.
$$
Also, as mentioned in the comments, raising both sides to the power of $e$ is called exponentiating, not multiplying by $e$.

Here's how I would do it:

Using separation of variables we write
$$
\frac{x'(t)}{x(t)(x(t) - 5)} = 3
$$
and then integrate
$$
\int_{y_0}^{y} \frac{x'(t)}{x(t)(x(t) - 5)} dt = \int_{y_0}^{y} 3 dt = 3(y - y_0)
$$
Now do partial fractions:
$$
\frac{1}{x(x - 5)} = \frac{A}{x} + \frac{B}{x - 5}
\implies 1 = A(x - 5) + B x
$$
Now plugging in $x = 0$ we have
$$
1 = -5 A
\implies A = - \frac{1}{5}.
$$
Plugging in $x = 5$ we have
$$
1 = 5B
\implies B = \frac{1}{5}.
$$
Therefore we get
$$
\frac{1}{x(x - 5)}
= \frac{1}{5(x - 5)} -\frac{1}{5x}.
$$
This now gives by substitution
\begin{align}
\int_{y_0}^{y} \frac{x'(t)}{x(t) ( x(t) - 5)} dt
& = \int_{x(y_0)}^{x(y)} \frac{1}{r(r - 5)} dr
= \frac{1}{5}\int_{x(y_0)}^{x(y)} \frac{1}{r - 5} -\frac{1}{r} dr \\
& = \frac{1}{5} \left( \ln \left| \frac{x(y) - 5}{x(y_0)} \right| - \ln\left| \frac{x(y)}{x(y_0)} \right| \right)
= \frac{1}{5} \ln\left| \frac{(x(y) - 5)x(y_0)}{x(y) x(y_0)} \right| \\
& = \frac{1}{5} \ln\left| \frac{x(y) - 5}{x(y)} \right|
\end{align}
Therefore, we have
\begin{align}
\frac{1}{5} \ln\left| \frac{x(y) - 5}{x(y)} \right|
= 3(y - y_0)
\implies & \ln\left| \frac{x(y) - 5}{x(y)} \right|
= 15(y - y_0) \\
\implies & \frac{x(y) - 5}{x(y)} = e^{15(y - y_0)} \\
\implies & x(y) = \frac{5}{1 - e^{15(y - y_0)}}
\end{align}
Now we have $x(0) = 8$.
Plugging in we have
$$
x(0) = \frac{5}{1 - e^{-15y_0}} \overset{!}{=} 8
\implies e^{-15y_0} = \frac{3}{8}
\implies y_0 = \frac{\ln\left(\frac{8}{3}\right)}{15}
$$
Plugging in we obtain
$$
x(y)
= \frac{5}{1 - e^{15(y - \frac{\ln\left(\frac{8}{3}\right)}{15}}}
= \frac{5}{1 - e^{15y - \ln\left(\frac{8}{3}\right)}}
= \frac{5}{1 - \frac{e^{15y}}{\frac{8}{3}}}
= \frac{5}{1 - \frac{3e^{15y}}{8}}
= \frac{40}{8 - 3e^{15y}},
$$
as required.

Also notice that by dividing by $x(x-5)$ we exclude the constant solutions $x \equiv 0$ and $x \equiv 5$. Both solve the differential equation but not the initial value problem because they don't fulfil $x(0) = 8$.
Answer: HINT
\begin{align*}
\frac{1}{3x(x-5)} = \frac{1}{3}\times\frac{1}{x(x-5)} = \frac{1}{15}\times\frac{x - (x-5)}{x(x-5)} = \frac{1}{15(x-5)} - \frac{1}{15x}
\end{align*}
Answer: Another way would be to explicitly calculate the coefficients of the partial fractions.
We are given that
$$\frac{dx}{dt}=3x(x-5)$$
which rearranges to (observing that $x\equiv 0$ and $x \equiv 5$ are solutions to the ODE but not the IVP)
$$\frac{1}{x(x-5)}dx=3dt \implies-\frac{1}{5}\Big(\frac{(x-5)-x}{x(x-5)}\Big)dx=3dt\implies -\frac{1}{5}\Big(\frac{1}{x}-\frac{1}{x-5}\Big)dx=3dt$$
so that
$$-\frac{1}{5}\ln|x|+\frac{1}{5}\ln|x-5|=3t+C \implies\ln\Big(\frac{|x-5|}{|x|}\Big)=15t+C$$
which reduces to
$$x=\frac{5}{1-Ce^{15t}}$$
Evaluating the initial condition of $x(0)=8$ forms
$$8=\frac{5}{1-C}\implies C=\frac{3}{8}$$
where
$$x=\frac{5}{1-\frac{3}{8}e^{15t}}=\frac{40}{8-3e^{15t}}$$
Answer: You can, as alternative solution method, avoid using a partial fraction decomposition by treating the ODE as a Bernoulli DE
$$
x'=3x^2-15x
$$
so that by setting $u=x^{-1}$ you get
$$
u'=-x^{-2}x'=15x^{-1}-3=15u-3
$$
which now is a linear first order DE in $u$ and additionally separable. Integration leads to
$$
5u(t)-1=e^{15t}(5u(0)-1)\implies 5\frac{x(0)}{x(t)}=x(0)+e^{15t}(5-x(0))
\\~\\
x(t)=\frac{5x(0)}{x(0)+e^{15t}(5-x(0))}.
$$
Answer: $$  1 = \frac{A}{3x} + \frac{B}{x-5} $$
if and only if
$$  (3x)(x-5) = A(x-5) + B(3x)  \text{,}  $$
with $x \not\in \{0,5\}$.  How do we get "$15xB$"?

Partial fractions ODE first order


Strong Markov property and time homogeneity

Question: Let $X$ be a Markov chain with state space $\mathcal{S}$ and denote $\mathbb{N} := \{ 0, 1, \cdots\}$. We know that for any stopping time $\tau < \infty$ and any bounded measurable function $\phi : \mathcal{S} \longrightarrow \mathbb{R}$, there exists a function $\psi : \mathbb{N}\times \mathcal{S} \longrightarrow \mathbb{R}$ such that
\begin{align}
\mathbb{E}[\phi(X_{\tau+1}) \; | \; \mathcal{F}_{\tau}] = \psi(\tau, X_{\tau})
\end{align}
I need to show that $X$ is temporally homogeneous if and only if, for all $\tau$ and $\phi$, the above $\psi$ does not depend on $\tau$ (namely it takes the form $\psi(X_{\tau})$).
I am trying to use smoothing property of conditional expectation to solve this:
\begin{align}
\mathbb{1}_{\{\tau = n\}} \; \mathbb{E}[\phi(X_{n+1}) \; | \; \mathcal{F}_n] &= \mathbb{1}_{\{\tau = n\}} \; \mathbb{E}[\phi(X_{n+1}) \; | \; X_n] \\
&= \mathbb{E}[\phi(X_{\tau+1}) \; | \; X_{\tau}] \\
&= \psi(X_{\tau})
\end{align}
I cannot figure out if I have implicitly used time homogeneity here. I also don't know how to establish the sufficiency (how time-homogeneity results from sole dependence of $\psi$ on $X_{\tau}$). I would appreciate any insights on this.
Comment: @user2348674: I also noticed that your acceptance rating is zero :-(
You won't get as much attention if you do not ever accept answers.
Comment: Why repost an exact copy of a question you already asked (and that people commented)?
Comment: @Did My previous question[link](http://math.stackexchange.com/questions/1771678/strong-markov-property-proof) was on the proof of strong Markov property whereas this question is on time-homogenous implications of Strong Markov property.
Comment: @par Thanks for pointing that out; I am relatively new here and did not know that I need to do that. Thanks :) !
Comment: @user2348674: you should go back and accept some answers; it will help your cause.
Comment: @user2348674 A question on exactly what you call "time-homogenous implications of Strong Markov property" was posted recently with the same typographical and notational choices and some basic blunders in it were signalled. Now as then, $\mathbb{1}_{\{\tau = n\}} \; \mathbb{E}[\phi(X_{n+1}) \; | \; X_n]= \mathbb{E}[\phi(X_{\tau+1}) \; | \; X_{\tau}]$ is simply impossible.
Comment: @Did I would appreciate it if you send me the link to that question; I am searching for that too ...
Comment: In discrete time, the strong Markov property is a trivial (if important) consequence of the simple Markov property. To involve it in a discussion of time-homogeneity simply clouds the issue.
To start to answer your question, what (precisely) do *you* mean by "temporally homogeneous"?
Comment: By "temporally homogeneous" I mean the simple time-homogeneous property of Markov chains: $P(X_{n+1} = j \; | \; X_n = i) = P(X_1 = j \; | \; X_0 = i)$ for all $n \ge 0$.
Comment: So you are assuming the state space $S$ to be countable?
Comment: Yes, $\mathcal{S}$ is countable here
Answer: So, because $X$ is a Markov chain, there is a function $p:\Bbb N\times S\times S\to[0,1]$ such that $\Bbb P[X_{n+1}=j\,|\,\mathcal F_n] = p(n,i,j)$, a.s. on $\{X_n=i\}$, for each $(n,i,j)\in \Bbb N\times S\times S$. And $X$ is temporally homogeneous if and only if $p(n,i,j) = p(m,i,j)=p(i,j)$ for all $(i,j)\in S\times S$, for all $m$ and $n$.
Added: This answers "I need to show that $X$ is temporally homogeneous if and only if, for all $\tau$ and $\phi$, the above $\psi$ does not depend on $\tau$ (namely it takes the form $\psi(X_{\tau})$)." If $X$ is temporally homogeneous, then $\Bbb E[\phi(X_{n+1}\,|\,\mathcal F_n]=\sum_{j\in S}p(X_n,j)=:\psi(X_n)$ doesn't depend on $n$. From this it follows by conditioning on the value of $\tau$ that $\Bbb E[\phi(X_{\tau+1}\,|\,\mathcal F_\tau]=\psi(X_\tau)$.
Conversely, if   $\Bbb E[\phi(X_{\tau+1}\,|\,\mathcal F_\tau]=\psi(X_\tau)$ for all $\phi$ and $\tau$, then taking $\phi=1_{\{j\}}$ and $\tau=n$ (non-random) we have   $\Bbb P[X_{n+1}=j\,|\,\mathcal F_n]=\psi_j(X_n)$ for some function $\psi_j$ with values in $[0,1]$. Consequently, $\Bbb P[X_{n+1}=j\,|\,X_n=i]=\psi_j(i)$. Define $p(i,j):=\psi_j(i)$ and note that $\sum_jp(i,j)=1$. It follows that $X$ is temporally homogeneous.
Comment: Is this an answer to the original question I posted? Seems to me this is only the definition of temporal homogeneity of a Markov chain ....


Definition of Bias and Variance in classification problems

Question: I was looking into a StatQuest video and he gave the meaning of bias and variance in regression problems
Correct me if I'm wrong

Bias is the sum of squares error between the predicted and actual values In a data set,
A low bias means the error is low, and it is accurately able to find the relationship between our x and y values ,
A high bias means our error is high, and it is unable to accurately find the relationship between our x and y values, this is known as under fitting, it goes very badly on training data and test Data

2.Variance is the sensitivity of our model to different data sets
A low variance model, our line of fits wouldn't be affected much by change in data sets, meaning the difference in y values for the different data sets wouldn't be much , he used the case of having similar sums of square errors, meaning accuracy is similar and consistent
A high variance model, our lines of fits change a lot, across data sets, meaning the y values are far apart for different data sets, he used the case of having vastly different sum of square errors, meaning accuracy across different data sets was inconsistent, this is known as over fitting, it goes well on training sets but very badly on data sets
My issue comes with classification problems, how can I be able to use this StatQuest definition to explain bias and variance in KNN and Decision trees
I appreciate all answers, and would like an easy one as I relatively new to this field
Thank you for your answers in advance
Answer: When you look at a learning problem (classification being an particular example), you search for a function $\widehat f$ such that $\widehat{f}(X)=Y$ where $X$ is the features variable and $Y$ is the answer (label) variable (the class in classification). Using $\widehat f$, you try to approximate some $f^*$ which is most of the time the minimize of some loss function, for example in classification this is
$$f^* = \arg\min_f \mathbb{P}(f(X)\neq Y).$$
So in fact, you use $\widehat f$ as an estimator of $f^*$. As such, the bias is a notion of distance between $\widehat f$ and $f^*$. This could be the squared distance or something but in fact given the problem, the bias will be better understood as $Bias = \mathbb{P}(\widehat f(X)\neq Y)-\mathbb{P}(f^*(X)\neq Y)$. This is a sort of approximation error. Here you have to understand that the larger the set $\mathcal{F}$ of function from which you choose $\widehat f$, the smaller it is. For example, in decision trees, if your tree is very deep then it is easier to approximate $f^*$.
Now, for the variance this is a bit more complex because in classification, the variance as you call it must also take into account the complexity of the set $\mathcal{F}$, for example you could define it with $\sup_{f\in \mathcal{F}}Var(f(X))$ but in fact there are better way to do this (see Rademacher complexity or VC dimension, but this is complex and outside the scope of this post). To give the idea, just think that the variance term will get larger and larger the more complex $\mathcal{F}$ is, it is linked to the fact that it is difficult to find a function in $\mathcal{F}$ if $\mathcal{F}$ is huge.
This is the reason why choosing for example the depth of a decision tree, or the number of nearest neighbors in KNN, is a bias/variance tradeoff.
Comment: You really complicated this answer tbh , I said I was new to the field, and your notations are confusing, thank you though , I'll wait for an easier answer
Comment: The only notations I used are probability, variance and supremum. If you really don't know what this is, I think you can search wikipedia to have your answer.
Comment: For example the argmin formula seems wrong to me, isn't it argmin (f(x) -y) not equals to, that is the Function approximation that gives the lowest loss
Comment: no the argmin is good, you want to search for a function that minimize the probability of making a mistake. In classification, f and y have value either 0 or 1. You use f(x)-y in regression.
Comment: Can you refer me to the reference for the bias and variance in classification?
Comment: So bias is the probability of your function approximation making a mistake ?, so the larger the set of F is, the smaller the bias, can you enumerate on this
Comment: No the bias is not the probability of making a mistake. It is the probability of your function to make a mistake minus the probability of the function that you are trying to approximate make a mistake. You need a baseline. You may want to look at posts where overfitting is mentionned in stackExchange, you can also look at this post https://www.kaggle.com/dansbecker/underfitting-and-overfitting and for a more in depth course https://www.coursera.org/learn/ml-classification
Comment: Thank you for the Kaggle link, it has clarified a lot


How to migrate from MS Access to SQL server 2005?

Question: I have a VB.NET windows application that pulls information from an MS Access database. The primary role of the application is to extract information from Excel files in various formats, standarize the file layout and write that out to csv files.  The application uses MS Access as the source for the keys and cross reference files.
The windows app uses typed datasets for much of the user interaction between the database. The standardization is done on the on each clients machine.  The application is not... how can I say this...FAST :-).
Question: What is the best way to migrate the DB and application to SQL Server 2005. I am thinking it might be a good idea to write the code for the standarization in and SSIS packages.
What is the appropriate way to go about this migration?

The application pulls data from 250 excel files each week and approximatley 800 files each month with an average of about 5000 rows per file.  There are 13 different file formats that are standarized and out put into 3 different standard formats.  The application takes between 25 min. and 40 min to run depending on which data run we are taling about.  95% of the appliction is the standarization process. All the user does is pick a few parameters then start the run.
Answer: Microsoft provide a free tool to migrate an Access Database to SQL Server. Once you've upgraded you should be able to change your connection string to point at SQL Server.
Comment: You mean "to migrate a JET database to SQL Server." If your MDB has Access objects in it (forms/reports/etc.) then those will *not* be migrated to SQL Server, for obvious reasons.
Answer: You might want to run your app through a profiler to ensure that the Access DB is really what's slowing down your app, and not something else.  It would be a shame to go through all the work to convert it over to SQL server, and have nothing to show for it.
Answer: The Access upsizing wizard can be used as a starting point.
You may be able to change the backend to be SQL Server with linked tables in Access without changing your front end.  Then, you can modify the front end to go directly to SQL Server at will.
Unless you are hitting Access very heavily, I doubt that it is your bottleneck.
As far as reading the Excel files, SSIS can do it, but it might not be as reliable as the mechanism you are using in VB.NET right now, if your VB.NET code has a lot of smart logic to deal with a degree of variation in the input files
As far as writing data out to CSV, SSIS is fine, and I've found SSIS to be a pretty good performer.
If you could give more details about the workflow and how much the user interacts with the database versus the program pulling configuration, it might be easier to help with your architecture.
SSIS is very configurable on the fly (package configuring itself somewhat while it is running), and in many cases it could be programmed to read a variety of Excel files and convert them to CSV, but it's not as configurable on the fly as a hand-coded system.  It is also possible to use the SSIS object model to generate packages programmatically and then execute them - this does not have some of the limitations of a package configuring itself, but the object model is pretty complex.
Answer: Making sure the scope is clear:

Use a .NET program to
drive an Access database front-end which enables you to
Extract data from a number of Excel spreadsheets,
Massaging the data appropriately, and
Save the result in a CSV file.

What sorts of volumes are we talking about? How many clients, how many spreadsheets per client, how many rows per spreadsheet (I think it would be 32767 max for a single spreadsheet, right? And how much time are we talking about?
Seems like a lot of moving parts. And Access usually is a pretty good tool (with VBA) to do this sort of thing by itself.
It doesn't seem like enough volume to provide a major time sink for a well-designed Access database front-ending Excel to accomplish the whole process using VBA. If your alternative involves installing and operating SQL Server (in place of Access) on each client, I would be surprised if the admin and operational overhead doesn't increase.
Comment: Access is also an excellent tool to use to move data between disparate data sources, such as SQL Server and Excel.
Answer: So Weekly, per client:
250 files at 25 minutes
= 10 files / minute
or 6 seconds per file.
Monthly, per client:
800 files at 40 minutes
= 20 files/minute
or 3 seconds per file.
My expectation would be less than 1 sec. per file (5000 rows) round trip including:
a. Import or attach xls to mdb,
b. Transform via Access SQL
c. Export to csv
The only explanation that comes to mind is that perhaps the .NET app is reading, transforming, and saving a row at a time. Is that possibly the case?
If you convert to SSIS, then that probably obsoletes the .NET app, because SSIS will want to handle the ETL (and save) itself. So you will basically be rewriting the software. But you may have better resources for SSIS than for Access. But it seems to me like overkill. BUt then .NET rather than VBA also is maybe overkill; and rewriting in VBA is work, too. The least effort would I think be to see if you can do the entire ETL (and save) using Access SQL for most of it, and using VBA just for scripting, to iterate through input files in a directory or some such.
I think you could at least prototype the basic use cases and find out if you can find out pretty quickly where the time is being spent now (as suggested by earlier responses.) But that would be worth finding out before committing redevelopment resources aimed at the wrong part of the problem. If you can expand a bit in those areas, I could probably direct you further. But Access is pretty well suited for this sort of thing, at (IMHO) a lower TCO than SQL Server + SSIS + .NET.
Not to mention that I'd be surprised if the csv files are the true end point, which may play a role in the decision. Isn't the Excel data really ending up further down the path?
Finally, how objectionable is a 25-40 minute process that presumably is unattended, can run over lunch break, and maybe basically works ok?

Notes:

Per week

Excel Files 250
Minutes 25
Minutes/File    0.1
Sec/File    6

Per month

Excel files 800
Minutes 40
Minutes/File    0.05
Sec/File    3


A loop was detected in the property expressions

Question: I'm working on a VS 2012 Express WPF project (C# code-behind) and I'm getting the error "A loop was detected in the property expressions".  Now before I continue, I know why I'm getting it - I'm just not sure what to do about it or if it even needs to be handled because even though it shows up in the error list and is underlined in blue, the program compiles and runs just fine.  I've Googled this of course and results have varied.  My question is a two-parter but first, here's the rundown:
The offending code:

As you can see, it's a style for Button that refers to Button which is what causes the issue.  The first workaround I read involved separating the code like so:


Uniform and absolute convergence of infinite trigonometric product

Question: This is an exercise given to us in our analytic number theory class:
Prove that $ \prod \cos(\tfrac{z}{2^n}) $ is uniformly and absolutely convergent on every closed disk $ \{ |z| \leq R \} $, hence its value $ P(z) $ is an analytic function on $ \mathbb{C} $. Evaluate $ P(z) $ in simple terms.
We don't have a textbook for the course. I think I need to use the Weierstrass M-test here but I am not sure how to proceed. Any suggestions?
Answer: Let $P_n(z)=\prod_{k=1}^n \cos\left(\frac{z}{2^k}\right)$. Inductively we have
\begin{align}
P_1(z)\cdot \sin\left(\frac{z}{2}\right)&=\cos\left(\frac{z}{2}\right)\sin\left(\frac{z}{2}\right)=\frac{1}{2}\sin z,\\
P_2(z)\cdot\sin\left(\frac{z}{2^2}\right)&=\cos\left(\frac{z}{2}\right)\cos \left(\frac{z}{2^2}\right)\cdot\sin\left(\frac{z}{2^2}\right)\\
&=\frac{1}{2}\cos\left(\frac{z}{2}\right)\sin\left(\frac{z}{2}\right)=\frac{1}{2^2}\sin z ,\\
&...\\
&...\\
P_n(z)\cdot\sin\left(\frac{z}{2^n}\right)&=P_{n-1}(z)\cos\left(\frac{z}{2^n}\right)\sin\left(\frac{z}{2^n}\right)\\
&=\frac{1}{2}P_{n-1}(z)\sin\left(\frac{z}{2^{n-1}}\right)=...=\frac{1}{2^n}\sin z .
\end{align}
Therefore we have $$
P_n(z)=\frac{1}{2^n}\frac{\sin z}{\sin\left(\frac{z}{2^n}\right)}=\frac{\sin z}{z}\cdot\frac{\frac{z}{2^n}}{\sin\left(\frac{z}{2^n}\right)}\to \frac{\sin z}{z}\quad (\, n\to \infty\,)
.$$
Thus, in simple terms, $P(z)=\frac{\sin z}{z}.$
Uniform and absolute convergence:
We can rewrite $$\prod_{n=1}^\infty \cos\left(\frac{z}{2^n}\right)=\prod_{n=1}^\infty (1+a_n),$$
where $a_n=\frac{1}{2}\left\{\left(e^{i\frac{z}{2^n}}-1\right)+  \left(e^{-i\frac{z}{2^n}}-1\right) \right\}.$
We have for $|z|\le R$  that
\begin{align}
\left|e^{\pm i\frac{z}{2^n}}-1\right|&=\left|\frac{1}{1!}\left( \pm i\frac{z}{2^n} \right)+\frac{1}{2!}\left( \pm i\frac{z}{2^n} \right)^2+\cdots   \right|\\
&\le \left|\frac{1}{1!}\left( \frac{R}{2^n} \right)+\frac{1}{2!}\left( \frac{R}{2^n} \right)^2+\cdots   \right|\\
&=e^{\frac{R}{2^n}}-1\\
&\le \frac{e^R-1}{2^n},
\end{align}
since $e^x-1\le \frac{e^R-1}{R}\,x$ for $0\le x\le R.$
Therefore we have $|a_n|\le   \frac{e^R-1}{2^n}$ which ensures uniform and absolute convergence of $\sum_{n=1}^\infty a_n$.


Invariance of measure on upper half plane

Question: The upper half plane has the measure $|y|^{-2}dxdy$. Show that it is invariant under the action of $SL(2, \mathbb{R})$.
I don't understand what any of this means. First, I don't understand what they mean when they say that $|y|^{-2}dxdy$ is a measure. Second, I don't even know what I am being asked to show.
Comment: The measure is given in terms of its density w.r.t. Lebesgue measure. I.e., the measure of a Borel set $A$ would be $\mu(A) = \int_A |y|^{-2} \, dx \, dy$. You are asked to show that $\mu(A) = \mu(g(A))$ for all $g \in SL(2,\mathbb{R})$. What exactly is unclear?
Comment: That's exactly the explanation I was looking for. I just didn't understand their notation or the meaning of invariance.
Answer: Let $T = \begin{pmatrix} a & b \\ c & d \end{pmatrix} \in SL(2,\mathbb{R})$, let $T(z) = x_1 + iy_1$ where $z=x_2 + iy_2$. Then, for any Borel set $A \subset\mathbb{H}^2$, consider
$$
\mu(T(A)) = \int_{T(A)} \frac{dx_1 dy_1}{y_1^2}
= \int_A \frac{\partial(x_1,y_1)}{\partial(x_2,y_2)} \frac{dx_2 dy_2}{y_1^2}
= \int_A \left| \frac{dT}{dz} \right|^2 \frac{|cz+d|^4}{y_2^2} dx_2 dy_2,
$$
where $\frac{\partial(x_1,y_1)}{\partial(x_2,y_2)} = \left| \frac{dT}{dz} \right|^2$ follows from the Cauchy-Riemann equations and $y_1 = \frac{y_2}{|cz+d|^2}$ comes from the change of variables. Now, remark that
$$
\frac{dT}{dz} = \frac{d}{dz} \left( \frac{az+b}{cz+d} \right)
= \frac{a(cz+d)-c(az+b)}{(cz+d)^2}
= \frac{ac-bd}{(cz+d)^2}
= \frac{1}{(cz+d)^2},
$$
so we can conclude that $\mu(T(A)) = \int_A \frac{dx_2dy_2}{y_2^2} = \mu(A)$; that is, the action of the fractional linear transformation $T$ on $\mathbb{H}^2$ preserves the hyperbolic measure $\mu$.
Answer: When dealing with manifolds, volume forms are often conflated with measures. Here, the volume form on the upper half plane is $|y|^{-2}dxdy$, so the measure of a Borel set is its integral with respect to that volume form.
The group $SL(2,\mathbb{R})$ acts on the upper half plane by fractional linear transformations,
$$\begin{pmatrix} a & b \\ c & d\end{pmatrix}z = \frac{az + b}{cz + d}.$$
Your job is to show that this action is measure-preserving.


Getting letter from loaded text

Question: I have a code. It loads text from this:

mapa = loadFromFile("level1");

And loadFromFile:
function loadFromFile(id) {
var level = document.getElementById(id).text;
var lines = level.split("\n");
for (var i = 0; i < lines.length; i++) {
    var line = lines[i];
    if (!line.trim())
        continue;
    var letter = line.charAt(2);
    alert("Second: " + letter + " ");
}
}

But it doesn't work :/ Alert in browser is empty.
Why?
Comment: You should [debug](https://developers.google.com/chrome-developer-tools/docs/protocol/1.0/debugger) and see step by step what are your variable values.
Comment: can you precise what is the element retrieved by document.getElementById?  and what is the value of the `level` variable ?
Comment: I found why is it wrong. var line looks like ".......0013435535" ("." == [space]). Do you know how to remove spaces from string?
Answer: I corrected your function :
function loadFromFile(id) {
    var level = document.getElementById(id).text;
    var lines = level.split("\n");
    //lines.length - 1 to parse each lines from 0 to 8 (9 numbers)
    for (var i = 0; i < lines.length - 1; i++) {
        var line = lines[i].trim(); //trim to remove white spaces
        if(line.length)  //if the line is not empty
        {
            var letter = line.charAt(1); //second letter
           alert("Second: " + letter + " ");
        }
    }
}

Note that an array starts to 0, so the second letter is the charAt(1) and you have to count from 0 not from 1 :
000122341 => 9 numbers
for 1 to 10 => 9 numbers
for 0 to 10 => 10 numbers
for 0 to (10 - 1) => 9 numbers
See fiddle for a working example !
Answer: The problem is that your variable line contains space at the beginning it is like ..000122  (where each dot is a space) you need to remove those extra spaces to get the value you want.

Getting letter from loaded text


R detect increasing/decreasing trend of time series

Question: I have lots of time series with periods: day, week or month. With stl() function or with loess(x ~ y) I can see how trends of particular time series look. I need to detect if trend of time series is increasing or decreasing. How can I manage that?
I tried to compute linear regression coefficients with lm(x ~ y) and play with slope coefficient. (If |slope|>2 and slope>0 then increasing trend, else if |slope|>2 and slope<0 – decreasing).
Maybe there is another and more effective method for trend detection? Thank you!
For example: I have timeserie1, timeserie2. I need a simple algorithm that would tell me that timeserie2 is an increasing algorithm, and in timeserie1, the trend isn't increasing or decreasing. What criteria should I use?
timeserie1:
1774 1706 1288 1276 2350 1821 1712 1654 1680 1451 1275 2140 1747 1749 1770 1797 1485 1299 2330 1822
1627 1847 1797 1452 1328 2363 1998 1864 2088 2084  594  884 1968 1858 1640 1823 1938 1490 1312 2312
1937 1617 1643 1468 1381 1276 2228 1756 1465 1716 1601 1340 1192 2231 1768 1623 1444 1575 1375 1267
2475 1630 1505 1810 1601 1123 1324 2245 1844 1613 1710 1546 1290 1366 2427 1783 1588 1505 1398 1226
1321 2299 1047 1735 1633 1508 1323 1317 2323 1826 1615 1750 1572 1273 1365 2373 2074 1809 1889 1521
1314 1512 2462 1836 1750 1808 1585 1387 1428 2176 1732 1752 1665 1425 1028 1194 2159 1840 1684 1711
1653 1360 1422 2328 1798 1723 1827 1499 1289 1476 2219 1824 1606 1627 1459 1324 1354 2150 1728 1743
1697 1511 1285 1426 2076 1792 1519 1478 1191 1122 1241 2105 1818 1599 1663 1319 1219 1452 2091 1771
1710 2000 1518 1479 1586 1848 2113 1648 1542 1220 1299 1452 2290 1944 1701 1709 1462 1312 1365 2326
1971 1709 1700 1687 1493 1523 2382 1938 1658 1713 1525 1413 1363 2349 1923 1726 1862 1686 1534 1280
2233 1733 1520 1537 1569 1367 1129 2024 1645 1510 1469 1533 1281 1212 2099 1769 1684 1842 1654 1369
1353 2415 1948 1841 1928 1790 1547 1465 2260 1895 1700 1838 1614 1528 1268 2192 1705 1494 1697 1588
1324 1193 2049 1672 1801 1487 1319 1289 1302 2316 1945 1771 2027 2053 1639 1372 2198 1692 1546 1809
1787 1360 1182 2157 1690 1494 1731 1633 1299 1291 2164 1667 1535 1822 1813 1510 1396 2308 2110 2128
2316 2249 1789 1886 2463 2257 2212 2608 2284 2034 1996 2686 2459 2340 2383 2507 2304 2740 1869  654
1068 1720 1904 1666 1877 2100  504 1482 1686 1707 1306 1417 2135 1787 1675 1934 1931 1456 1363 2027
1740 1544 1727 1620 1232 1199

timeserie2:
 122  155  124   97  155  134  115  122  162  115  102  163  135  120  139  160  126  122  169  154
 121  134  143  100  121  182  139  145  135  147   60   58  153  145  130  126  143  129   98  171
 145  107  133  115  113   96  175  128  106  117  124  107  114  172  143  111  104  132  110   80
 159  131  113  123  123  104  101  179  127  105  133  127  101   97  164  134  124   90  110  102
  90  186   79  145  130  115   79  104  191  137  114  131  109   95  119  173  158  137  128  119
 109  120  182  140  133  113  121  110  122  159  129  124  119  109  108   95  167  138  125  105
 139  118  115  166  140  112  116  139  121  109  164  135  118  121  112  111  102  169  136  151
 132  135  130  112  156  134  121  116  114   91   86  141  160  116  118  112   84  114  165  141
 109  123  122  110  100  162  145  121  118  115  107  103  162  142  130  139  134  121  118  164
 147  125  120  134  107  130  158  141  144  148  124  135  118  212  178  154  167  155  176  143
 201  170  144  138  152  136  123  223  189  160  153  190  136  144  276  213  199  211  196  170
 179  460  480  499  550  518  493  557  768  685  637  593  507  611  569  741  635  563  577  498
 456  446  677  552  515  441  438  462  530  699  629  555  641  625  544  585  705  584  553  622
 506  500  533  777  598  541  532  513  434  510  714  631 1087 1249 1102  913  888 1147 1056 1073
1075 1136  927  922 1066 1074  996 1189 1062  999  974 1174 1097 1055 1053 1097 1065 1171  843  441
 552  779  883  773  759  890  404  729  703  810  743  743  946  883  813  876  841  742  715  960
 862  743  806  732  669  621

Comment: @Tom Yes, what you say is evident in a plot of the data. (Indeed, a plot shows three separate sudden level shifts, not just one). But characterizing this as differing from a "trend" does not do justice to your analysis, which I know will reveal subtle details in the behavior of this time series. I would like to suggest the O.P. would be better served by clear characterizations of the data behavior rather than by discussions of possible definitions of "trend." She asks for an alternative to testing a least squares slope--and that is a *de facto* indication of what *she* means by "trend."
Comment: Your second example doesn't have a trend so you should not be detecting one. At period 230, the data has a level shift(ie 0,0,0,0,0,1,1,1,1,1,1,etc) which is different than a trend. Also, there is a change in the variance at about 200 which can be identified using the Tsay test. See more here www.unc.edu/~jbhill/tsay.pdf
Answer: You can apply a zero phase shifter filter and cut out all frequencies higher than some threshold; this would give you a "trend" of sorts.
For example, look at this question, "How do I run a high pass or low pass filter on data points in R?"
They show how to use Butterworth low pass filter. The problem with that filter is that it's not zero phase shift, i.e. as you see the low frequency component's phase is shifted relative to the original signal. You may want to find the filter which does not shift the phase. If this were economic data, I would suggest Christiano's filter as per "The Band Pass Filter" by Lawrence J. Christiano and Terry J. Fitzgerald (1999). For physical data, there must be a ton of zero phase shift filters available.
UPDATE:
Here's an example of applying the low band pass filter to the LOG of the second time series. The LOG is required to even out the variance.

UPDATE2:
Here's a sample decomposition in frequency domain with frequency bands: irregular [2-19], cyclical [20-99], and trend [100-$\infty$] (in period lengths). The frequency bands have to be chosen carefully based on the understanding of the underlying phenomenon.
Comment: I was puzzling over this answer for awhile and finally realized you must be using the word "trend" in much the same way many statisticians would use "smooth." Then it all makes sense. We should hope the O.P. will soon clarify what *she* means by "trend."
Comment: It doesn't quite seem that way.  When you filter out high-frequency components you are removing some of the "irregular" (read: noise) and perhaps a tiny part of the cyclical portion, but the trend, the medium- and long-term cyclical components, and the seasonal components will all remain.
Comment: for a trend you would use low band pass filter. let's say you have several years of monthly data series. in this case the low band could be 10 years cycle, so you cut out all frequencies higher than 1/10 (when time is in years). the threshold really depends on the phenomenon, in economic data the business cycles could be 10-15 years long, so you may need to set the low band to 1/16
Comment: As your new illustration shows, when you are too aggressive in the filtering you lose obvious trends, too: your *smooth* is so strong it misses almost all of the last third of the data. Regardless, this definitely is not a decomposition into the qualitative notional components described by the Wikipedia article you reference. Another concern with the filtering approach (however it is conducted) is the statistical one: how do you *test* whether there is a "trend" and whether it is up or down?
Comment: yes, i'm using "trend" as in time series decomposition sense: y = trend + cyclical + seasonal + irregular, e.g. http://en.wikipedia.org/wiki/Decomposition_of_time_series

the trend would be a "very low" frequency component in this context. how low depends on the problem
Comment: you have a good point on being "too agressive", and that's why I was being careful not to actually suggest the lower band value. i am suggesting the time series decomposition in frequency domain, which is quite popular these days. for instance, consider a widely used [X-13](https://www.census.gov/srd/www/x13as/) algorithm developed at US Census to deseasonlize the monthly series. they have a de-trending step, which is essentially an application of a special filter, not unlike a simple low band pass filter in my example
Comment: The problem with power transforms to decouple the relationship between the expected value and the error variance is that it is often the wrong procedure. The data set shows a deterministic change in error variance at or about period 225 which suggests GLS or Weighted Least Squares ( see http://www.unc.edu/~jbhill/tsay.pdf ). This procedure to detect the structural change in error variance leading directly to GLS is incorporated in AUTOBOX ( http://www.autobox.com ) which I helped write to implement Tsay's ideas.
Comment: if you look at the diff(log(ts)) it won't show any obvious sign of a structural break, will look like a any other constant variance model. what you call a structural change could simply be a random jump, which changes the level, and the variance changes proportionally. log-transform cures this
Answer: Trend detection in a time series can be done simply wrong or more aggressively. A series can have values that exhibit a trend, e.g. 1,2,3,4,5, and then a change in trend at one or more points in time, e.g. 7,9,11,13,15,... Another example is 1,1,1,1,1,2,3,4,5,6 where no trend is present for the first 5 readings, and then a trend ensues. A series like 1,1,1,1,1,2,2,2,2,2 is said to have a level shift (change in intercept). AUTOBOX is a piece of software  that uniquely (to my knowledge) incorporates analytics to detect, test and incorporate time trends. I was one of the developers and extended the analytics in this particular area. The procedure that you are trying to use (incorrectly in my opinion) is model presumptive, i.e. no pulses, no level shifts, no seasonal pulses, no ARIMA structure, constant error variance, etc. Another possible bad example of an assumed  model is to use
$[1-B]y(t)=\theta_0 +[MA/AR]a(t)$, as again, one is assuming a particular structure.
The idea here is that the ARIMA model might be incorrect or that $\theta_0$ is changing (thus different trends) at different points in time.
The whole idea is to let the data "speak" and the analysis "listen" and detect the "correct model" or at least a "useful model".
Orson Bean – or maybe it was somebody else – once said, "A trend is a trend…until it bends, and when the trend bends, the trend is at an end." Local time trends in time series require identification of the break points and then estimation of the local trend. Some useful material/references can be found at http://www.autobox.com/OLDWEB/udontsay.html
If you wish to post some data, please do so, and I will post some results back to you.
Comment: A trend is a trend is a trend\ But the question is, will it bend?\
Will it alter its course\Through some unforeseen force\And come to a premature end? Alexander Cairncross
Comment: In that case, Marta, it sounds like you are testing for a *global* "trend" (in the sense of differences in typical values between the two ends of the time series) and not local trends as described in this answer.  Is that correct?
Comment: @Nick Thank you!  Because it took some effort to hunt down the source, here it is: [*Economic Forecasting*, Presidential Address to the Royal Economic Society, July 3, 1969](http://www.jstor.org/discover/10.2307/2229792?uid=3739864&uid=2134&uid=2&uid=70&uid=4&uid=3739256&sid=21103591522363).  Cairncross opened his speech with a Lincoln quotation followed by this original limerick (facetiously attributed to "Stein Age Forecaster"). The subsequent remarks make it clear he was referring to forecasting--extrapolation of trends.
Comment: @whuber, you are right, I'm looking for global trend. Sorry if my question was misleading.
Comment: Thank you for the answer. I will study your information. I also have posted some data.
Comment: Actually, I can't use another software. I must do it with R. So I need a simple algorithm, that tells true/false. True-if in timeserie is increasing/decreasing trend
Comment: @marta for example if the series is 1,2,2,2,2,2,2,2,3 . Do you want a procedure to give you a "yes" or a "no" ?
Comment: @IrishStat, in yout example I won't to procedure find any increasing trend.
Comment: @marta your answer confuses me . Please respond yes if you think there is a trend or no if you think there is no trend
Comment: @IrishStat, no.
Comment: @Marta I ran the series 1,2,2,2,2,2,2,2,3 through AUTOBOX and  Y(T) =  2.0000                                marta1  . Thus the answer was "no" as two pulses were detected
       +[X1(T)][(- 1.0000)]             :PULSE             1
       +[X2(T)][(+ 1.000)]              :PULSE             9
      +                    +   [A(T)]


hibernate, mix load with criteria possible?

Question: is it possible to mix a session.load(class, id) with a flexible criteria (criteria api)?
I need something like :
select * from entity where id = 1 AND name = 'miller'

I use the generic approach for the find by id:
public T findById(ID id, boolean lock) {
    T entity;
    if (lock)
        entity = (T) getSession().load(getPersistentClass(), id, LockMode.UPGRADE);
    else
        entity = (T) getSession().load(getPersistentClass(), id);

    return entity;
}

and would like to extend this by
    Criteria criteria = session.createCriteria(getPersistentClass());
    criteria.add( Restrictions.eq("name", "miller"));

where ("name", "miller") will be replaced by something generic.
Answer: Load and criteria can't be mixed. Load creates a proxy if the instance isn't in cache yet. The purpose of load (and get) is that its arguments are the keys for the cache (class and id) and it doesn't need to flush the session before. Criteria is a kind of query. When you already know the id, you don't need a query anymore. I mean, does id = 1 AND name = 'miller' make any sense?

Just write you own "Get":
public TEntity secureGet<TEntity>(int id, string user)
{
  // avoid flushing, only when you never expect that the user name
  // in the object to be loaded has changed within the current session.
  // this is very performance relevant.
  session.flushMode = FlushMode.Never;
  return session
    .createCriteria(typeof(TEntity))
    .add( Restrictions.idEq(id))
    .add( Restrictions.eq("name", user))
    .UniqueResult<TEntity>();
  session.flushMode = FlushMode.Auto;
}

(Sorry for possible syntactic errors, I'm not a java programmer)
Comment: Yes it makes sense as part of an authorization concept. I could check if the current user is allowed to see the data with id=1.
Comment: @dodiddone: What is your plan to accomplish that? Wouldn't you need another table with user permissions in regards to the specific records from the Entity class?
Comment: added an example implementation.
Comment: @Olaf yes, that is correct, i simplified the example, i additional entities with user permissions etc.


How can I merge and update a comma separated string to an existing column in SQL?

Question: I've a table as follows:
CREATE TABLE [dbo].[FileInfo]
(
    [FileId]         INT          NOT NULL,
    [FileAttributes] VARCHAR(512) NULL,
    PRIMARY KEY ([FileId])
);

DataType to upsert the above table
CREATE TYPE [dbo].[FilesInfo_List_DataType] AS TABLE
(
    [FileId]         INT          NOT NULL,
    [FileAttributes] VARCHAR(512) NULL,
    PRIMARY KEY ([FileId])
)

Stored procedure to upsert the above table:
CREATE PROCEDURE [dbo].[FileInfo_Save]
    @FilesList [dbo].[FilesInfo_List_DataType] READONLY
AS
BEGIN
    SET NOCOUNT ON;

    BEGIN TRY
        BEGIN TRAN
            UPDATE f
            SET f.FileId = fl.FileId,
                f.FileAttributes = fl.FileAttributes
            FROM
                [dbo].[FileInfo] f
            INNER JOIN
                @FilesList fl ON f.FileId = fl.FileId

            IF (XACT_STATE()) = 1
            BEGIN
                COMMIT TRAN;
            END
    END TRY

    BEGIN CATCH
        ---------- OMMITTED --------
    END CATCH
END

Now I want to modify the update statement to satisfy the below conditions.

If FileAttributes is null or empty, update it with the incoming value.
If FileAttributes is non empty, split the existing value by comma, do the same for the incoming value, merge both the lists of strings without duplicates, order the final string collection in alphabetic order, then join them all back using comma as separator and set it as the new value.

Case 1: When value is empty, set the incoming value.
The incoming value is
(FileId, FileAttributes) => (3, 'approved,reviewed')

Table before update:

FileId
FileAttributes

1
final,finance,order

2
protected,read_only,recovered

3

Table after update:

FileId
FileAttributes

1
final,finance,order

2
protected,read_only,recovered

3
approved,reviewed

Case 2: when value is not-empty and the incoming value is
(FileId, FileAttributes) => (3, 'approved,archive,marked_for_delete')

The FileAttributes is a comma-separated text field. The incoming string may or may not contain some of the values already present. The existing and the incoming values should be merged without duplicates and written back as alphabetically ordered and comma-separated string.
Table before update:

FileId
FileAttributes

1
final,finance,order

2
protected,read_only,recovered

3
approved,reviewed

Table after update:

FileId
FileAttributes

1
order,final,finance

2
read_only,protected,recovered

3
approved,archive,reviewed,marked_for_delete
Comment: Which dbms are you using? (The above code is product specific.)
Comment: The real question is why are you storing delimited data in the first place? Ideally you should fix your design and store the data in a *normalised* format. Then, if you need to *present* the data in a delimited format you can do that then.
Comment: *"Because there are plenty of other columns"* sounds like you think the solution is a different type of denormalisation. You should have a separate table for your `FileAttributes` data.
Comment: SQL Server. The code added here is a pseudo code. To better explain the requirement. Also, re-designing the tables is not an option. The actual tables are much more complex and just one column has the update logic as described in the question.
Comment: Because there are plenty of other columns and we don't want to duplicate all those values to have 1 to n mapping between file id and attributes. These kinds of upserts are very rare. Delimited data (partial or full) is used to upsert and whatever gets stored will be consumed as is. The individual values are not queried anywhere else.
Comment: Well, this is pretty easy to achieve. What you need is to create a correlated subquery where you create a new string which contains old + "," + new values, then split the string by ",", then do a distinct of values and then do a STRING_AGG back together ordered by name. Of course all this should handle NULLs on both sides correctly, but it's pretty easy as well
Answer: On SQL Server 2017 and later you may try something like this:
https://dbfiddle.uk/P4d8pmw-
CREATE TABLE [dbo].[FileInfo]
(
    [FileId]         INT          NOT NULL,
    [FileAttributes] VARCHAR(512) NULL,
    PRIMARY KEY ([FileId])
);

CREATE TYPE [dbo].[FilesInfo_List_DataType] AS TABLE
(
    [FileId]         INT          NOT NULL,
    [FileAttributes] VARCHAR(512) NULL,
    PRIMARY KEY ([FileId])
)

INSERT INTO [dbo].[FileInfo] ([FileId], [FileAttributes])
VALUES
    (1, 'order,final'),
    (2, 'protected,read_only'),
    (3, '');
GO

DECLARE @FilesList [dbo].[FilesInfo_List_DataType];

INSERT INTO @FilesList ([FileId], [FileAttributes])
VALUES
    (1, 'final,finance,order'),
    (2, 'protected,read_only,recovered'),
    (3, 'approved,reviewed');

SELECT * FROM FileInfo

UPDATE f
SET f.FileAttributes =
    CASE
        -- If existing is empty, set it
        WHEN f.FileAttributes IS NULL OR LEN(TRIM(f.FileAttributes))=0 THEN fl.FileAttributes
        -- If not empty, merge and sort the existing and incoming values
        ELSE (
            SELECT STRING_AGG(v, ',') WITHIN GROUP (ORDER BY v ASC)  AS result
            FROM (
            SELECT Lower(value) as v FROM STRING_SPLIT(trim(f.FileAttributes), ',')  WHERE LEN(value)>0
            UNION  -- union does DISTINCT
            SELECT Lower(value) as v FROM STRING_SPLIT(trim(fl.FileAttributes), ',') WHERE LEN(value)>0
            ) a
            )
        END
FROM
    [dbo].[FileInfo] f
INNER JOIN
    @FilesList fl ON f.FileId = fl.FileId;;

SELECT * FROM FileInfo

It uses STRING_AGG which is SQL Server 2017 and newer and STRING_SPLIT  which is SQL Server 2016 and newer.
This UPDATE command should produce the result:
UPDATE f
SET f.FileAttributes = (
            SELECT STRING_AGG(v, ',') WITHIN GROUP (ORDER BY v ASC)  AS result
            FROM (
            SELECT Lower(value) as v FROM STRING_SPLIT(trim(f.FileAttributes), ',')  WHERE LEN(value)>0
            UNION
            SELECT Lower(value) as v FROM STRING_SPLIT(trim(fl.FileAttributes), ',') WHERE LEN(value)>0  ) a
            )
FROM
    [dbo].[FileInfo] f
INNER JOIN
    @FilesList fl ON f.FileId = fl.FileId;


Can I somehow convert Binding to String?

Question: I am trying to call a function that looks like this
func customTextField(placeholder: String, text: Binding<String>) -> some View {
        ZStack(alignment: .leading){
            if text.isEmpty{
                VStack {
                    Text(placeholder)
                        .font(.system(size: 14))
                        .fontWeight(.regular)
                        .foregroundColor(Color(red: 0.5803921568627451, green: 0.5803921568627451, blue: 0.5803921568627451))
                        .padding()

                    if placeholder == "Your message type here..."{
                        Spacer()
                    }
                }
            }

            TextField("", text: text)
                .font(.system(size: 14))
                .foregroundColor(.black)
                .padding()

        }
        .frame(height: placeholder == "Your message type here..." ? 170 : 54)
        .background(RoundedRectangle(cornerRadius: 16).stroke(text.isEmpty ? Color.clear : Color("orange")))
        .background(Color.white)
        .cornerRadius(16)
    }

But as text is a Binding<String> I can't use .isEmpty() on it. I don't want to create another struct view for it.
What would be the best approach for this?
Answer: You simply need to call wrappedValue on a Binding to access its underlying value, there's no need for any type conversion.
So do
text.wrappedValue.isEmpty

instead of
text.isEmpty


Cubic Formula Doesn't Seem to Work for $x^3+3x^2-50x-52=0$

Question: So I'll jump right into it. I've derived the following formula set for solving cubics of the form $ax^3+bx^2+cx+d=0$:
$$z_{k\pm}=\sqrt[3]{\frac{9abc-2b^3-27a^2d}{54a^3}\pm\sqrt{\frac{4ac^3+27a^2d^2-18abcd-b^2c^2+4b^3d}{108a^4}}}$$
$$x=z_{k\pm}-\frac{\left(\frac{-b^2}{3a^2}+\frac{c}{a}\right)}{3z_{k\pm}}-\frac{b}{3a}$$
The idea is that you solve for the 6 $z$-values defined by $k=0, 1, 2$ and each of these $k$-values has a positive and negative result based upon the selection for the $\pm$ sign. Also note that this derivation is heavily based upon this article (http://math.sfsu.edu/smith/Documents/Cubic&Quartic.pdf). The article dictates that these 6 $z$-values translate to only 3 distinct $x$-values (since cubics only have 3 solutions).
This all went smoothly and I was able to successfully show the viability of the formula set by solving the cubic $-2x^3+3x^2-x+5=0$. The formula was successful in capturing all 3 $x$-values without any issues.
However, upon further inspection of the formula, I have noticed an issue when the radicand of the square root is negative. This would make the radicand of the cube root imaginary, thus leaving $z$ with no real solutions; hence, $x$ would have no real solutions when $\frac{4ac^3+27a^2d^2-18abcd-b^2c^2+b^3d}{108a^4}\lt0$. Of course this cannot be true since every cubic has at least one real solution.
To test this theory I tried to solve
$$x^3+3x^2-50x-52=0$$
using the formula. This cubic does indeed make the radicand of the square root negative and happens to have three real roots: $-1, -1-\sqrt{52}, -1+\sqrt{52}$. However, upon solving the formula for these values, $z_{0+}$ and $z_{0-}$ were complex and $z_{1+}$ gave a domain error on my TI-84+ calculator. My reference article provides some insight into dealing with a negative radicand, but it doesn't make sense to me. Any help is greatly appreciated!
Comment: Have a look at the paragraph "general cubic formula" in the Wikipedia [here](https://en.wikipedia.org/wiki/Cubic_equation) where you will see how your formula must be used.
Comment: I suggest editing in the calculation that derived these roots.
Comment: $x=\{-1,-1-\sqrt{53},-1+\sqrt{53}\}$
Comment: Have you looked at Cardano's formulae? They were published in 1545 in Latin. https://en.wikipedia.org/wiki/Cubic_equation#Cardano's_method
Comment: Which roots? The successful one or the unsuccessful one?
Comment: Would recommend substituting your expression for z into the solution. It's more clear and perceptible written out in full, even if it's less concise.
Answer: For negative radicands, the 6 $z$-values translates into 3 distinctive $x$-values as well.
Take the example $x^3+3x^2-50x-52=0$ given in the post, $z$'s are evaluated as
$$z_{k\pm} =\sqrt[3]{\pm \sqrt{-\frac{53^3}{27}}}= \pm\sqrt{\frac{53}3}e^{i \frac{1+4\pi k}6},\>\>\>k=0,1,2$$
and the corresponding $x$'s are
$$x_{k\pm} = z_{k\pm} +\frac{53}{3z_{k\pm}}-1
= z_{k\pm} +{z_{k\mp}}-1=2Re(z_{k\pm})-1
$$
Explicitly, the 6 $x$-values are
\begin{align}
x_{0+} & = 2\sqrt{\frac{53}3}\cos\frac\pi6-1=\sqrt{53}-1\\
x_{0-} & = -2\sqrt{\frac{53}3}\cos\frac\pi6-1=-\sqrt{53}-1\\
x_{1+} & = 2\sqrt{\frac{53}3}\cos\frac{5\pi}6-1=-\sqrt{53}-1\\
x_{1-} & = -2\sqrt{\frac{53}3}\cos\frac{5\pi}6-1=\sqrt{53}-1\\
x_{2+} & = 2\sqrt{\frac{53}3}\cos\frac{3\pi}2-1=-1\\
 x_{2-} & =- 2\sqrt{\frac{53}3}\cos\frac{3\pi}2-1=-1\\
\end{align}
of which, only 3 values, $-1$, $\sqrt{53}-1$ and $-\sqrt{53}-1$, are distinctive, as expected.
Answer: This is called "casus irreducibilis". To solve it, you need to use a different function. $1$ way to do this is with trigonometry. $$ax^{3}+bx^{2}+cx+d=0,\ x=\frac{2\sqrt{b^{2}-3ac}\cos\left(\frac{1}{3}\cos^{-1}\left(-\frac{b^{3}-4.5abc+13.5a^{2}d}{\sqrt{\left(b^{2}-3ac\right)^{3}}}\right)\right)-b}{3a}$$ This is basically the expression that Quanto generates by hand in his derivation. If you want to get radical expressions, use the rational root theorem to get $1$ solution, then solve for the other $2$. $$x_{2,\ 3}=\frac{\sqrt{b^{2}-4ac-3a^{2}x_{1}^{2}-2abx_{1}}-b-ax_{1}}{2a}$$ Side note: The form you got the formula in is more complicated than it needs to be. An equivalent simplified form is $$ax^{3}+bx^{2}+cx+d=0,\ x=\frac{\sqrt[3]{\sqrt{\left(b^{3}-4.5abc+13.5a^{2}d\right)^{2}-\left(b^{2}-3ac\right)^{3}}-\left(b^{3}-4.5abc+13.5a^{2}d\right)}-\sqrt[3]{\sqrt{\left(b^{3}-4.5abc+13.5a^{2}d\right)^{2}-\left(b^{2}-3ac\right)^{3}}+\left(b^{3}-4.5abc+13.5a^{2}d\right)}-b}{3a}$$


Represent transformation respect to the following basis

Question: Suppose I have the following transformation matrix
$$A = \pmatrix{0 & 1 \cr \frac{-1}{2} & \frac{1}{2}}$$
How would you represent it respect to this basis:
$$B = \left\{ \pmatrix{2 \cr 4}, \pmatrix{1 \cr 3} \right\}$$
? And why?
Answer: $$A \pmatrix{2 \cr 4}=\pmatrix{0 & 1 \cr \frac{-1}{2} & \frac{1}{2}}\pmatrix{2 \cr 4}=\pmatrix{4\\1}=\frac{11}{2}\pmatrix{2 \cr 4}-7\pmatrix{1 \cr 3}$$
$$A \pmatrix{1 \cr 3}=\pmatrix{0 & 1 \cr \frac{-1}{2} & \frac{1}{2}}\pmatrix{1 \cr 3}=\pmatrix{3\\1}=4\pmatrix{2 \cr 4}-5\pmatrix{1 \cr 3}$$
So
$$A_{B,B}=\pmatrix{\frac{11}{2}&4\\-7& -5}$$


Function breaks chart.js

Question: I am trying to insert my chart.js into a Drupal page.
Here is the fully functional fiddle:
http://jsfiddle.net/vy0yhd6m/80/
When I enter that into a basic page content item in Drupal, the chart will not display.
However, if I remove scaleLabel(), it works and displays perfectly on the Drupal page. For some reason, adding that function in the Full HTML content item makes the chart disappear, even though it works perfectly in the above JS Fiddle.
scaleLabel: function(label){return  ' $' + label.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");}

Does anyone have any idea on why this is happening?
Comment: What text filters are enabled on the "Full HTML" format? "Full HTML" doesn't mean that your content isn't being transformed by some kind of text or sanitization filter.
Comment: Convert URLs into links, Convert line breaks into HTML (i.e.  and ), and Correct faulty and chopped off HTML. Turning these filters off did not make an impact. In the source code of the page, I see that my JavaScript is in there unaltered. Thanks for your help.
Answer: So I realized I was using an outdated version of Chart.js (from an old production site).
I just updated to the latest version, and now all is well with the world.
Thanks.

Function breaks chart.js


Using XNA libraries in Windows Phone Silverlight Application

Question: I am developing for Windows Phone. I want to ask can I use XNA libraries in Windows Phone Silverlight Applications?
Answer: Yes you can. For example, when using MediaLibrary for playing songs, you have to use XNA libraries. If you want to mix XAML and XNA, you have a special project type just for that purpose. This is useful when building games that have lots of UI for leaderboards, settings, etc.


How can quality of a domestique be rated?

Question: Various criteria, such as number of wins, UCI points, are good for comparing GC contenders and sprinters. Climbing times and wattage can say a lot about quality of a climber.
But quality of domestiques is a very important factor in order to achieve team's objectives in any race, too. I am not able to think of some (at least partially) objective criteria to evaluate domestiques.

Are there some criteria by which performance of domestiques can be rated?
Are there some websites which give rankings/ratings of cycling domestiques?
Answer: A domestique's number one aim is to help their team leader win, so you can just count the number of wins a rider has been on the same team as. Cycle Sport magazine used to publish a list every year - I think it was usually one of Mark Cavendish's team mates at the top of the list.
Edit: Check the image posted with Martin's comment. It shows that in 2010 the "award" went to Bert Grabsch of HTC-Columbia. In fact 8 of the top 10 were HTC-Columbia riders - the team that Cavendish and Andre Greipel rode for that year.
Comment: I was able to get 2010 December issue of Cycle Sport magazine into my hands. And I can confirm that it contains a ranking called *Domestique of the Year*. See these pictures: http://i.stack.imgur.com/fdD6O.png and
http://i.stack.imgur.com/amJz1.png (I hope that this can be considered fair use.)
Comment: The problem with just counting wins is that it favour domestiques on sprint teams, because they get a higher total of wins. A domestique for a grand tour winner could do a big job for his captain, but it won't show in the statistics as more than one win.


Find Max in Nested Dictionary

Question: d = {
    "local": {
        "count": 1,
        "health-beauty": {
            "count": 1,
            "tanning": {"count": 1}
        }
    },
    "nationwide": {"count": 9.0},
    "travel": {"count": 0}
}

In this instance "nationwide" is the largest.
Code is below to make it easier to attach to scripts:
d = {'travel': {'count': 0}, 'local': {'count': 1, 'health-beauty': {'count': 1, 'tanning': {'count': 1}}}, 'nationwide': {'count': 9.0}}

Comment: you should have made local.tanning the biggest ... as it is none of the answers would find it...
Comment: Was looking at `print max(d, key=lambda x: x[1])`
Comment: If "tanning" was 10, and you need to catch that, you might need to flatten the dictionary. Try something like this [http://stackoverflow.com/questions/6027558/flatten-nested-python-dictionaries-compressing-keys](http://stackoverflow.com/questions/6027558/flatten-nested-python-dictionaries-compressing-keys)
Comment: Could you show an example?
Comment: @sehe I have subsequently realized that this should have been a comment. The reason that I ended up with posting an answer is that I lack the score for comments.
Anyhow, here's the example of the result:
`>>> x = {
        'a':1,
        'b':2,
        'c':{
            'aa':11,
            'bb':22,
            'cc':{
                'aaa':111
            }
        }
    }

>>> {'_'.join(k):v for k,v in flattenDict(x).items()}
{'a': 1, 'b': 2, 'c_aa': 11, 'c_bb': 22, 'c_cc_aaa': 111}`

Let me know once you get this comment, so I can delete the answer. Cheers.
Comment: Dropping links as answers is frowned upon. At least show the gist of the answer, adapting it to the specific question. Otherwise, this is not an answer and should have been a comment (possibly a suggested duplicate)
Comment: @sehe check the top answer to [this](http://stackoverflow.com/a/6043835/1405399) question. It has example.
Answer: >>> max(d, key=lambda x: d[x]['count'])
'nationwide'

Comment: this wont work .. say if your internal dict is biggest(since it doesnt even consider the nested dictionaries)
Comment: change `d['local']['tanning']["count"]` to `10` I will bet you that it doesnt return tanning ...
Comment: @JoranBeasley I know it. Just that each count (as I understand) is the sum of nested dictionaries. If `d['local']['tanning']['count']` is `10`, `d['local']['count']` is also `10`(or more)... So no need to check
Comment: @JBernardo exactly, I ++ each parent too!
Answer: This should work for nested dictionary:
def find_max(d, name=None):
    return max((v, name) if k == "count" else find_max(v, k) for k, v in d.items())

>>> find_max(d)
(9.0, 'nationwide')

Comment: that wont work I dont think... local has a key count and more entries that each have their own count...

Find Max in Nested Dictionary


VectorList class constructor

Question: for my assignment we are making a VectorList class and I had a question about the constructor. This is the class declaration:
#include <iostream>
#include <vector>
using namespace std;
template< typename NODETYPE >
class VectorList
{
 public:
  VectorList(); // constructor
  ~VectorList(); // destructor

  void insertAtFront( const NODETYPE & );
  void insertAtBack( const NODETYPE & );
  bool removeFromFront( NODETYPE & );
  bool removeFromBack( NODETYPE & );
  bool isEmpty() const;
  void print() const;
 private:
  vector< NODETYPE > *vList;  // list data as a vector
};

I thought for the constructor I would use vList = new std::vector; but the assignment has this:
template< typename NODETYPE >
VectorList< NODETYPE >::VectorList()
: // Fill in the missing code
{
  // empty body
}

So I cannot put vList = new std::vector; in the constructor body as he wants it empty. I am unsure of what to do at this point.
Comment: Try reformatting your post so that it is easier to see your code. Select the text content and click the code button in the toolbar. It is difficult to answer your question if it is hard to see your code.
Comment: Does your vList have to be a pointer to a vector?  if it's not a pointer it will get initialized automatically to an empty vector.
Answer: Your teacher is fishing for a constructor initializer list. This lets you initialize members before the constructor is run:
template< typename NODETYPE >
VectorList< NODETYPE >::VectorList()
    : vList(new std::vector)
{
}

This is the standard way to initialize members since it is equivalent to initializing at declaration time for normal variables, e.g.
int a(3);    // Calls int constructor with 3. Note int a = 3; does same (no call to operator=)

If you had a class member variable declared as int a;, the initialization can't be done at declaration, but putting it in the constructor runs after the object is already created. This is really assignment, and takes place using operator= instead of the object's constructor. It is equivalent to:
int a;    // Create an int
a = 3;    // Uses operator= to do assignment

Note also that you are using namespace std; in what I assume is a header file; this is a bad idea as it will pollute the namespace of any file that #includes your header, and could potentially cause name conflicts (and thus subtle errors). After removing that line you'll have to add the std:: prefix before your vector< NODETYPE > declaration.
Finally, in the code you've posted so far, there's no need to allocate vList on the heap (with new) when you can have a regular vector object as a member variable:
vector< NODETYPE > vList;

This would simplify your code and reduce the possibility of introducing subtle memory-management bugs. You wouldn't need your initializer list anymore, and the destructor would also have nothing to do. Additionally, you wouldn't have to worry about defining a custom copy-constructor and assignment operator to make copy and assignment safe/work properly.

VectorList class constructor


Help me understand the proof of $a \equiv b \mod m \Rightarrow r_m(a)=r_m(b)$

Question: Let:
$r_m:\mathbb{Z}\rightarrow R_m$
where
$r_m(a)=r\Leftrightarrow a \equiv r \mod m $ and $r\in R_m$
where $R_m$ is the set of residues modulo $m$.

I understand the above proof until $r' \equiv r'' \mod m$. I don't know how to use Proposition 19.2.2 to conclude that $r'=r''$.

Can someone please make this step more explicit?
Answer: Tell me if it helps:
$a= Q_{m(a)}m +R_{m(a)} \quad,\quad R_{m(a)}<m$
$b= Q_{m(b)}m +R_{m(b)} \quad,\quad R_{m(b)}< m$
$a ≡ R_{m(a)} \pmod m$
$b ≡ R_{m(a)} \pmod m$
So, $a ≡ b \pmod m \implies R_{m(a)} ≡ R_{m(b)} \pmod m \implies R_{m(a)} = R_{m(b)} +Km$, $K \in \mathbb {Z^+}$
$R_{m(a)} < m \implies K=0  \implies  R_{m(a)} = R_{m(b)}$
Answer: $a=mq_a+r \land b=mq_b+r' \implies 0 \leq r,r'<m$
$a \equiv b \pmod m \implies r\equiv r' \pmod m$
$0 \leq r<m \quad,\quad -m> -r' \geq 0 \implies 0 \leq \lvert r-r'\rvert <m \implies r=r'$
Comment: In the second line, is '$a \equiv b \pmod m \implies r\equiv r' \pmod n$' suppose to be '$a \equiv b \pmod m \implies r\equiv r' \pmod m$'?
Comment: @mauna: Sorry, thank you.


Barra de progresso bootstrap acompanhando duração de video youtube

Question: como fazer a barra de progresso do bootstrap acompanhar o seguimento do video youtube (iframe) implantado na pagina html

var player,
  time_update_interval = 0;

function onYouTubeIframeAPIReady() {
  player = new YT.Player('video-placeholder', {
    width: 600,
    height: 400,
    videoId: 'Xa0Q0J5tOP0',
    playerVars: {
      color: 'white',
      playlist: 'taJ60kskkns,FG0fTKAqZ5g'
    },
    events: {
      onReady: initialize
    }
  });
}

function initialize() {

  // Update the controls on load
  updateTimerDisplay();
  updateProgressBar();

  // Clear any old interval.
  clearInterval(time_update_interval);

  // Start interval to update elapsed time display and
  // the elapsed part of the progress bar every second.
  time_update_interval = setInterval(function() {
    updateTimerDisplay();
    updateProgressBar();
  }, 1000);

  $('#volume-input').val(Math.round(player.getVolume()));
}

// This function is called by initialize()
function updateTimerDisplay() {
  // Update current time text display.
  $('#current-time').text(formatTime(player.getCurrentTime()));
  $('#duration').text(formatTime(player.getDuration()));
}

// This function is called by initialize()
function updateProgressBar() {
  // Update the value of our progress bar accordingly.
  $('#progress-bar').val((player.getCurrentTime() / player.getDuration()) * 100);
}

// Progress bar

$('#progress-bar').on('mouseup touchend', function(e) {

  // Calculate the new time for the video.
  // new time in seconds = total duration in seconds * ( value of range input / 100 )
  var newTime = player.getDuration() * (e.target.value / 100);

  // Skip video to new time.
  player.seekTo(newTime);

});

// Playback

$('#play').on('click', function() {
  player.playVideo();
});

$('#pause').on('click', function() {
  player.pauseVideo();
});

// Sound volume

$('#mute-toggle').on('click', function() {
  var mute_toggle = $(this);

  if (player.isMuted()) {
    player.unMute();
    mute_toggle.text('volume_up');
  } else {
    player.mute();
    mute_toggle.text('volume_off');
  }
});

$('#volume-input').on('change', function() {
  player.setVolume($(this).val());
});

// Other options

$('#speed').on('change', function() {
  player.setPlaybackRate($(this).val());
});

$('#quality').on('change', function() {
  player.setPlaybackQuality($(this).val());
});

// Playlist

$('#next').on('click', function() {
  player.nextVideo()
});

$('#prev').on('click', function() {
  player.previousVideo()
});

$('pre code').each(function(i, block) {
  hljs.highlightBlock(block);
});
<!DOCTYPE html>

  <meta charset="UTF-8">
  <title>How to Control YouTube's Video Player with JavaScript</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

0:00 / 0:00

              70% Complete

        play_arrow

        pause

Comment: Mostre o que vc já fez pra gente ter uma ideia.
Comment: da uma olhada ae
Answer: Eu alterei o seu exemplo pra barra de progresso funcionar.
Coloquei uma versão no JSFiddle, eu utilizei o moment.js pra mexer com tempo.
Os métodos e valores foram tirados da documentação da API, Link.
O métodos updateTimerDisplay() updateProgressBar() ficaram implementados assim:
function updateTimerDisplay() {
    if((player.getPlayerState() == 5) || (player.getPlayerState() == -1)) {
        let total = moment.utc(player.getDuration() * 1000);
        $('#duration').text(total.format('mm:ss'));}
        if(player.getPlayerState() == 1) {
        let minutos = moment.utc(player.getCurrentTime() * 1000);

        $('#current-time').text(minutos.format('mm:ss'));
    }
}

function updateProgressBar() {
    if(player.getPlayerState() == 1) {
        let duracao = player.getDuration();
        let atual = player.getCurrentTime();
        atual = parseFloat(atual.toFixed(6));
        let porcentagem = (atual * 100) / duracao;
        $('#progress-bar').css("width", porcentagem + "%").attr("aria-valuenow", porcentagem);
    }
}


Low p-value, but many trials

Question: I am not well-versed in statistics, so please bear with me. I will try to explain things to the best of my knowledge.
I have some hardware that produces a signal, this signal has an offset and I want to subtract this baseline from my signal. This is the procedure I use to determine the baseline:
I take many noise samples (with long time between them to avoid any correlation) and from these I obtain the mean (my baseline) and the standard error on the mean (sample standard deviation / sqrt(samples)).
This looks good, but I now want to determine when I need to calibrate my baseline again, so I repeat the same procedure and obtain a new_mean, new_std_error, new_number_of_samples. I perform a two-tailed Welch's unequal variances t-test on these and if the p-value is low enough (say 0.05) I determine that my baseline has changed and I need a new calibration.
What is the problem?
My device has 256 channels, and if I perform this procedure on all channels I will most certainly obtain a low p-value for a couple of channels by pure luck. I don't think that this means these channels need a new baseline.
Other device has 20 thousand channels, even more likely to get a low p-value for some channels. Do you have any suggestion on how to deal with this? How could I determine if there is any actual reason to update the baseline of any given channel?
Thanks
Comment: That you're asking this question means you already get the issues with multiple comparisons, but there is [a classic XKCD cartoon](https://xkcd.com/882/) on this topic that you might enjoy and might like to have available to show colleagues who do not yet get it.
Comment: Surely when recalibration is required relates to *how much* rather than *whether* there's a difference. There's certain to be a difference, that's not an interesting or useful hypothesis. Presumably what matters is detecting it has become non-trivial before it is particularly consequential.
Comment: @Glen_b Could you expand on what you mean? And if you have a suggestions different to the current answer I would appreciate a lot if you post an answer. What do you mean by `how much` rather than `whether`? Isn't that what I am getting out of the `p-value`? Given `how much` the value has changed, I want to see if it is statistically significant to justify a recalibration.
Comment: "how much" rather than "whether" is the distinction between a large effect size (large enough to matter) and a small one (so small it would have no practical importance); it's perfectly possible to reject a null at a small effect size. If I'm measuring human temperature, a 0.01 degree bias in my instrument is irrelevant for almost any practical purpose, even if I have a sample large enough to detect that it's present. But a *half* degree bias could matter quite a bit, even if I didn't take a sample size large enough to find it. ... ctd
Comment: ctd ... In short, equality-null hypothesis tests don't address *how much*.  It may make sense to tailor your detection effort toward the smallest effect that would potentially be of some practical import. That might involve a test (such as an equivalence test or something similar) or it might involve something else (e.g. interval estimation to mention one possibility). Solving the right problem (rather than banging a square peg into a round hole) is the first and perhaps most important issue in a piece of statistical work
Comment: Ok, I see. That makes a lot of sense. Can you suggest any material/keywords to Google? If I understand correctly, my hypothesis should not be that the means are equal; it should be that they are not different enough up to the level I care about. Right?
Comment: See the comment from a few seconds before your comment just now.
Comment: Thanks, I will keep thinking about it.
Answer: When deciding whether to adjust the baseline you need to consider more than just the long run rate of adjusting it when that channel does not actually need it.
The p-value is an index of the strength of evidence in the data against the null hypothesis according to the statistical model. In the hypothesis testing framework you make a decision on the basis of the relationship between that p-value and a pre-determined fixed threshold. That threshold should be set to a level that is chosen to optimise not only the long run rate of false positives (i.e. channel adjustments that are made but not needed), but also the power to detect false nulls (i.e. detect occasions where a channel needs adjustment) and the necessary sample size. The considerations of threshold and sample size involve thinking about the consequences of false positive and false negative errors. DO NOT use p=0.05 as a threshold and think that you are 'doing' statistics!
What are the consequences of adjusting the baseline of a channel that does not actually need adjustment? If they are trivial then adjust when there is modest evidence against the null hypothesis that the baseline is correct. What are the consequences of failing to adjust an out of baseline channel?
I would suggest that you consider a procedure where you monitor the channels and whenever a channel's p-value (or other index of out of balance condition) is low enough you sample again and adjust if a second p-value is also low. The chances of getting a spuriously low p-value two times in a row is very low, but if the channel needs adjustment then it should regularly give low p-values. That way you will hugely reduce the rate of false positive errors without also greatly reducing the ability to detect the need to adjust. (This assumes that a fresh sample of values has minimal cost.)
On a non-statistical level, why not use an AC-coupling approach (capacitative coupling) for the hardware? That is often used when there can be baseline drift and it deals with the problem very gracefully. It can also be done digitally. See here: https://en.wikipedia.org/wiki/Capacitive_coupling
Comment: As usual, a classy answer from Michael Lew.  A complementary aspect that you could add to the strategy would be to adjust only when consecutive p-values are sufficiently low and the degree of baseline shift is great enough to matter.
Answer: This is closely related to the concept of change detection.
For example the CUSUM algorithm may be suitable. Basic implementation is:

Cumulatively sum (sample - current_baseline) as data arrives.
For every sample subtract some fraction of the standard deviation from the cumulative sum.
If sum goes below 0, clamp it to 0. If sum goes above N times standard deviation, consider a change to have occurred.

Compared to taking discrete samples and computing statistics on them, a continuous process will react faster to a consistent change, such as new baseline value. The cumulative structure also means that small changes in baseline will still be eventually be detected, even if they don't immediately cross the threshold.
If you prefer the statistics structure, you can use a similar cumulative approach: expand the new sample count as long as the baseline is in effect. The longer this goes on, the smaller p will become and eventually it will cross even a very low p criteria.
This does not eliminate the fundamental problem of setting a threshold: a very small baseline change is indistinguishable from random variation for a very long time. But a cumulative approach should eventually detect even a tiny baseline change.
Answer: From a purely statistical perspective, this is exactly what multiple testing correction is for. The first "design" question for you is what exactly you would like to control:

Either you want to keep the probability that there is any false positive (i.e. spuriously significant test) below a certain threshold $\alpha_1$ - this leads to the so-called Bonferroni correction method, where you essentially multiply your raw p-values with the number of tests (in fact, there exists a number of variations on this, but all of them share this goal and principle)
Alternatively, you could say that of your "hits" of low p-values, you'd like, in expectation, at most a certain fraction $\alpha_2$ to be false positives, i.e. randomly spuriously significant tests, so that on average a proportion of $(1-\alpha_2)$ of your significant tests results from a real signal. This leads you to the False-Discovery-Rate family of methods, which prescribe a somewhat more complex procedure to correct your raw p-values

The former is evidently much more conservative than the latter, but there is no "objectively correct" choice - rather it really depends on the tradeoff between false positive and false negative rate. From your description, it seems that the FDR correction could be more suitable to your problem, but the decision ultimately rests with you.

Low p-value, but many trials


Is it possible to trigger a webform submit via url?

Question: I have set up a webform for simple user polling with an yes/no option, with a submit button.
<code>  [ ] Yes
  [ ] No

  Submit
</code>
and the parameter is pass via URL as default, e.g.:
<code> http://example.com/event_form?option=y
</code>
Currently, the webform link is sent via email. So users click the link, open a browser, select an option or use the default, press submit, and see the confirmation message.
Is it possible to automate the submit click? Such that the submit button is automatically clicked after clicking on the link in email?
Comment: It is easy if you know how to write module. Are you expecting to have a solution with contrib modules?
Comment: As long as it works with the webform module, please explain how to do that with a module...
Answer: Inject some javascript into the body using PHP can make auto submit to work by a param in URL:
<code> http://example.com/event_form?autosubmit=yes&option=y
</code>
For example, the webform node ID is 101:
<code><?php if ($_REQUEST['autosubmit']) { ?>

    <script>
    (function ($) {
        $(document).ready(function(){
            $('form#webform-client-form-101').submit();
        });
    })(jQuery);
    </script>

<? } ?>
</code>


Why do we say "Residual standard error"?

Question: A standard error is the estimated standard deviation $\hat \sigma(\hat\theta)$ of an estimator $\hat\theta$ for a parameter $\theta$.
Why is the estimated standard deviation of the residuals called "residual standard error" (e.g., in the output of R's summary.lm function) and not "residual standard deviation"? What parameter estimate do we equip with a standard error here?
Do we consider each residual as an estimator for "its" error term and estimate the "pooled" standard error of all these estimators?
Comment: I think that's an R thing. I don't think other software necessarily uses that phrasing, & 'residual standard deviation' is common in textbooks, eg. I don't have an answer, but I always thought it was weird that R uses that phrase.
Comment: @Tim, it might correctly be considered *an estimate of the standard deviation of the errors*, but the residuals are not technically the errors themselves. Nor is it the standard error of the error SD, for what that's worth.
Comment: @gung it's funny how using specific software shapes your thinking: I'd never call it "residual sd" - residuals are not data but errors, so residual error seems to be proper name. But if you think about it it really seems an R-thing.
Comment: @gung: that could be the explanation! When googling "residual standard error" in quotes I get only 0.1% of the hits than without quotes...
Comment: I could put that as a (non-)answer, if you'd prefer.
Comment: Since your (non-)answer is enormously calming: "Yes, please" :-)
Comment: @gung I agree and that is what I mean by software shaping your thinking about things.
Answer: I think that phrasing is specific to R's summary.lm() output.  Notice that the underlying value is actually called "sigma" (summary.lm()$sigma).  I don't think other software necessarily uses that name for the standard deviation of the residuals.  In addition, the phrasing 'residual standard deviation' is common in textbooks, for instance. I don't know how that came to be the phrasing used in R's summary.lm() output, but I always thought it was weird.
Comment: To corroborate gung, I cite from the R documentation of `stats::sigma`: *The misnomer "Residual standard error" has been part of too many R (and S) outputs to be easily changed there.*
Comment: @AndréTerra, the correct degrees of freedom is n - p, which is what summary uses. sd uses var which uses n - 1 degrees of freedom. If you manually compute the standard deviation of the residuals dividing by n - p then you will get the same answer as what summary provides.
Comment: How is `summary.lm(reg)$sigma` different from `sd(reg$residuals)`?
Answer: From my econometrics training, it is called "residual standard error" because it is an estimate of the actual "residual standard deviation". See this related question that corroborates this terminology.
A Google search for the term residual standard error also shows up a lot of hits, so it is by no means an R oddity. I tried both terms with quotes, and both show up roughly 60,000 times.
Comment: Interesting. But why would you call an estimate of a standard deviation of *any* random variable (like an error term; and not a specific estimator) a "standard error"?
Comment: My thinking is we need to have a name for the estimate (to distinguish from the actual value), any name is as good as another. But surely someone more knowledgeable about the etymology can offer a better reason. Note that there is definitely a parallel with the coefficient standard error, which is the estimate of the coefficient estimate 's standard deviation.
Comment: *"A Google search for the term residual standard error also shows up a lot of hits, so it is by no means an R oddity."* This argument ignores the fact that R is (one of) the most popular programming language for statistics.
Answer: This is really, really confusing use of the term "standard error".  I teach Introductory Statistics at a college, and this is one of the most confusing details in R for students (along with R using standard deviation and not variance in its various pnorm, qnorm, etc. commands).
A standard error, from a statistical sense, is defined as "a standard deviation of an estimator/statistic".  It is a resampling concept: the standard error of the slope estimate, for example.  If you were to resample your data, the estimate of the slope will vary, and this type of standard deviation we call a standard error.
But the standard deviation of the residuals is not a resampling concept – it is directly observable in the data.  So what R reports as "residual standard error" really is an "estimated standard deviation of the residuals".  It is like the difference between $s$ (an estimated standard deviation) and $\sigma$ (a true/theoretical standard deviation), not the difference between $\sigma$ (a true/theoretical standard deviation) and $\sigma/\sqrt{n}$ (a true/theoretical standard error).
Answer: As in mentioned by a comment by NRH to one of the other answers, the documentation for stats::sigma says:

The misnomer "Residual standard error" has been part of too many R (and S) outputs to be easily changed there.

This tells me that the developers know this terminology to be bogus. However, since it has crept into the software, changing to correct terminology is difficult and not worth the trouble of doing so when experienced statisticians know what is meant.
Comment: Ha, so cool, Dave. Thanks!
Answer:
Put simply, the standard error of the sample is an estimate of how far the sample mean is likely to be from the population mean, whereas the standard deviation of the sample is the degree to which individuals within the sample differ from the sample mean.

Standard error - Wikipedia, the free encyclopedia
Comment: This is true, but does not actually answer the question. What R calls the "residual standard error" is not "an estimate of how far the sample mean is likely to be from the population mean".
Answer: A fitted regression model uses the parameters to generate point estimate predictions which are the means of observed responses if you were to replicate the study with the same XX values an infinite number of times (when the linear model is true).
The difference between these predicted values and the ones used to fit the model are called "Residuals" which, when replicating the data collection process, have properties of random variables with 0 means. The observed residuals are then used to subsequently estimate the variability in these values and to estimate the sampling distribution of the parameters.
Note:
When the residual standard error is exactly 0 then the model fits the data perfectly (likely due to overfitting).
If the residual standard error can not be shown to be significantly different from the variability in the unconditional response, then there is little evidence to suggest the linear model has any predictive ability.
Comment: Good attempt at explaining it but this story is not compatible with the definition of the standard error. The standard error is the standard deviation of the sampling distribution of the mean, but the distribution of the residuals is not a sampling distribution.  Specifically, the standard error depends on N but the standard deviation of the residuals does not.
Answer: For the nls (nonlinear least squares fit) R function, the "Residual standard error" seems to be:
$$\sqrt{\frac{\mathrm{RSS}}{n-p}}$$
where RSS is the "residual sum-of-squares", n is the number of observations and p is the number of estimated parameters. There's absolutely no description in the documentation, this assumption is based on a "numerical experiment".


Find all numbers $p$ so that $f$ is continuous on $(- ∞, ∞)$

Question: $$
F(x)= \begin{cases}px^2& x\leq2\\
      2x+p& x>2\end{cases}
$$
I'm confused how to set up this problem.. can anyone help get me started?
Comment: There's only one possible point of discontinuity.  Make sure the graph approaches the same value from both sides of this potential jump discontinuity.
Answer: A function is continuous on $(a,b)$ if for all points in $(a,b)$, $\lim_{x\to a^+}f(x)=\lim_{x\to a^-}f(x)=\lim_{x\to a}f(x)=f(a)$. Hence, find $p$ so that ($f$ is continuous everywhere, but is possibly discontinuous at $x=2$ - let's check):
$$\lim_{x\to 2}(2x+p)=\lim_{x\to 2}(px^2)\\
\implies 4+p=4p\\
\implies p=\dfrac{4}{3}$$
Comment: Typo in the sign ! Cheers.
Answer: The only place where the function can't be continuous is at $x=2$ because it's a piece wise function. In order for it to be continuous, both parts must have the same value at $x=2$:
$$px^2=2x+p \; \text{(at x=2)}$$
$$p(2)^2=2(2)+p \Rightarrow 4p=4+p$$
$$\therefore p=\frac43$$


Remove database name from ODBC (SQL Server) table list

Question: This seems to be something new, or at least since the last time I created an ODBC connection to SQL Server from Minitab 16.
When I created a new ODBC connection, the database name is now in the dropdown list.

As you can see, I can't read the full table name, and several of my tables have similar names.  It didn't always include the database name, is there some option I need to uncheck or something to remove it?
Comment: The screenshot you posted is not the ODBC Data Source Administrator tool that ships with Windows.  To setup a Windows ODBC DSN, launch the ODBC administrator tool from Control Panel (System-->Administrative Tools-->ODBC Data Sources) or by running odbcad32.exe from a command-prompt.  If you need help with a specific application that uses ODBC, I suggest you specify the application name in your question.  It looks like it may have an issue with Windows 7.
Comment: This specific instance i shappening in Minitab 16.  I just tried doing it in Access, and it only showed "dbo.MyTableName" in the list, so you may be correct that it's application-specific.
Comment: I suggest to install the latest product updates to Minitab 16.  I see they have critical updates for Windows 8.1.
Comment: How have you created the ODBC connection in Windows?
Answer: This happened during upgrade of your SQL Server - 2012.
In SQL server fully qualified table names are in the following format:
[database].[schema].[table]

In SQL Server Management Studio you can configure/alter all the defaults.
You can set up the default schema on a per-user basis:
Security > Logins > (right click) user > Properties >
User Mapping > Default Schema

Luckily, SQL Server 2012 addresses this security issue by allowing us to assign a default schema for Windows Groups, which helps organizations simplify their database schema administration.
The following Transact SQL (T-SQL) demonstrates the process of assigning the default schema for Windows Group:
-- Creating Default Schema "ProdAdmins" for Windows Group "MyDomain\ProdDBAs"

CREATE SCHEMA [ProdAdmins] AUTHORIZATION [MyDomain\ProdDBAs]
GO

-- Set Default Schema for Windows Group "MyDomain\ProdDBAs"

ALTER USER [MyDomain\ProdDBAs] WITH DEFAULT_SCHEMA=[ProdAdmins]
GO

The following links may help you:
http://blog.mclaughlinsoftware.com/2012/09/16/setup-sql-server-schema/
http://searchsqlserver.techtarget.com/feature/SQL-Server-2012-security-Changes-for-the-newest-version
Answer: I did a from-scratch experiment on my system to get a grasp of the situation:
First Lets add User DSN to my machine [Windows 7]  and remote [SQL Server 2012] by doing the following:
Control Panel > Set up data sources (ODBC) > User DSN [Tab]    >      Press Add button

Choose "SQL Server Client 11.0" and press finish
You will see something like the following:

and follow the wizard to the end(I chose master as my default database in the wizard).
Now what? Lets see if we can use this inside our client application (visual Studio 2013 in my case):

Go to "Server Explorer" > "Data Connections" > Right click and "Add Connection..." > "Change Data Source to "Microsoft ODBC Data Source" > Press OK >

Now the Data Source which you added earlier [Test_Plan2] will appear in Data Source Specification

Test the connection and Press OK.
Now use this newly created connection by querying it

[Right click on the newly created ODBC connection and choose "New Query" : You dont even need to select any table at all if-you-don't-want-to but if you want select the the ones you need] > Close it and write your SQL query
SELECT * FROM MSreplication_options

I did not have that database name issue at all.
Answer: It turns out this is a function of Minitab and there's no way to actually change it.  It's just how the program was designed.


How to calculate the difference in cents between a note and an arbitrary frequency?

Question: Let's say I have the note A 440Hz and the frequency 450Hz. How do I calculate the distance in cents between that note and that frequency?
Answer: c = 1200 × log2(f1/f0)
The frequency f of a note n semitones away from A4 is (Wikipedia):

f = 2n/12 × 440 Hz

More generally, to calculate one frequency from another based on their distance in semitones:

f1 = 2n/12 × f0

To answer your question, solve for n to get semitones:

n = 12 × log2(f1/f0)

And multiply by 100 for cents:

c = 1200 × log2(f1/f0)

Given your example, the distance in cents between 440 Hz and 450 Hz:

c = 1200 × log2(440/450)
c = –38.9

so 440 Hz is about 39 cents below 450 Hz.
For more information, see the mathematics of musical scales. There's also some information about the logarithmic scale in the linked entry for musical cents.
Answer: The first formula shown on you wiki link is the one you want:
From wiki:
""If one knows the frequencies a and b of two notes, the number of cents measuring the interval from a to b may be calculated by the following formula (similar to the definition of decibel):

Likewise, if one knows a note a and the number n of cents in the interval from a to b, then b may be calculated by:

E.G. for your given two frequencies, 440Hz and 450Hz
3986*log(450/440)= 38.9 cents
and in the other direction:
3986*log(440/450)= -38.9 cents
And checking our answer with the second formula:
440*2^(38.9/1200) = 450.0 Hz
http://en.wikipedia.org/wiki/Cent_%28music%29
Comment: +1 for putting it in functions you can actually find on a calculator. However it might be worth pointing out that log2(b/a) = log10(b/a)/log10(2) = ln(b/a)/ln(2). Thus the correct value of the constant 3986 is 1200/log10(2)=3986.31371 etc. The fundamental maths is easier to remember than a mysterious constant.