Playing Wav with Directsound

Question: I need to play multiple wave files which start at different times (not all together). I was trying to play the files using Directsound but a problem arised. I have the following code:
var dev = new Device();      //This line creates the problem
dev.SetCooperativeLevel(this, CooperativeLevel.Normal);
MemoryStream ms = new MemoryStream(Sample1);
soundBuffer = new Microsoft.DirectX.DirectSound.Buffer(ms, dev);
SecondaryBuffer sound = new SecondaryBuffer(ms,dev);
sound.Play();

The problem is when I type in the first line (var dev = new Device();), and compile the program an error occurs (ConsoleApplication1 encountered a problem and needs to close). This happens even when I remove all the code except the first line. The console error is as follows: "Mixed mode assembly is built against version v1.1.4322 of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information".
If this problem is not fixable, is there another way to play multiple sounds. The sound has to have minimum latency and must play instantly without any delays.
Answer: You need to edit your application configuration to include:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>

Which should allow you to use older .NET dlls.
Comment: Thanks for your fast reply! where should i go to edit the application configuration?

Playing Wav with Directsound


Can a runner run back to their original base during a stealing base?

Question: Can a baserunner run back to their starting base in a stealing base situation?
R1 steals legally 2B and 3B but then he wants to come back ti 1B, is legal ?
Answer: In the scenario you describe, no. Rule 5.09(b)(10) in the MLB rules, for example, prohibits running the bases in reverse order.
Comment: Because they did not legally advance to second in the latter scenario. There's no complexity in the question as asked (it specifically says 2nd and 3rd bases were *stolen*), though there has been a raft of questions (of varying specificity) recently, all asking variations on this theme.
Comment: This is correct, but it misses the complexity of the question.  Why can a runner not return to first base after stealing second, but they *can* return to first after touching second if there was a fly ball out on the play?
Comment: That should probably be in the answer (with the rules reference) to make this a great answer.  (Also, copy/paste the actual rule plus link to it - thanks for including the rule number but given they can change over time, it's best to include the text.)


Xcode 13 Warning - [NSKeyedUnarchiver validateAllowedClass:forKey:]

Question: I am using File Storage system for saving some data models confirming to Codable Protocol.
My Save function is as below:
<code>func save<T: Encodable>(value: T, for key: String, on path: URL) throws {
        let url = path.appendingPathComponent(key, isDirectory: false)
        do {
            try ANFileManager.createDirectoryAtPath(path: url.deletingLastPathComponent())
            let archiver = NSKeyedArchiver(requiringSecureCoding: true)
            archiver.outputFormat = .binary
            try archiver.encodeEncodable(value, forKey: NSKeyedArchiveRootObjectKey)
            archiver.finishEncoding()
            // then you can use encoded data
            try archiver.encodedData.write(to: url)

        } catch {
            throw StorageError.cantWrite(error)
        }
    }
</code>
My fetch function is as below:
<code> func fetchValue<T: Decodable>(for key: String, from path: URL) throws -> T {
        let url = path.appendingPathComponent(key)

        let data = try Data(contentsOf: url)
        let unarchiver = try NSKeyedUnarchiver(forReadingFrom: data)
        unarchiver.decodingFailurePolicy = .setErrorAndReturn
        guard let decoded = unarchiver.decodeDecodable(T.self, forKey:
            NSKeyedArchiveRootObjectKey) else {
                throw StorageError.notFound
        }

        unarchiver.finishDecoding()

        if let error = unarchiver.error {
            throw StorageError.cantRead(error)
        }
        else {
            return decoded
        }

    }
</code>
Save and fetch are working fine but at runtime seeing some below warning in xcode console.
<code>    *** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSString' (0x7fff863014d0) [/Applications/Xcode_13.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework]' for key 'NS.keys', even though it was not explicitly included in the client allowed classes set: '{(
    "'NSDictionary' (0x7fff862db9a0) [/Applications/Xcode_13.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework]",
    "'NSDate' (0x7fff862db798) [/Applications/Xcode_13.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework]"
)}'. This will be disallowed in the future.
</code>
What should be done to suppress the warning ?
Comment: May one ask why you are spending so much effort passing thru NSKeyedUnarchiver when a Codable can be so simply saved directly as property list or json?
Comment: Want to save file which is unreadable text at first.
Comment: Also, My models were migrated from NSCoding to Codable.
Comment: I'm sorry but that is ridiculous. The encoding for keyed archiver and for Codable property list is identical. There is nothing less "readable" in what you're doing. And they are Codable now so why live in the past?
Comment: Ok, I get that. I was using KeyArchiver for my Models Confirming to NSCoding. And continue with same storage function after converting the Models to Codable. I think I should change it now.
Answer: The problem is the failure to require secure coding on the unarchiver:
https://developer.apple.com/documentation/foundation/nskeyedunarchiver/1410824-requiressecurecoding
But more broadly it is very odd to pass through a keyed archiver when Codable is already saveable directly.
Comment: Because it needs to be true!
Comment: unarchiver.requiresSecureCoding = false, Added this but still seeing the same warning.
Comment: I tried removing all the code related to Keyed archiver but still, the app was seeing this warning. I think its the issue with firebase library because removing the Firebase initialization seems to remove the warning.


How do I notate a 'wailing' sound?

Question: I made this sound with my synthesized flute

There are three in this particular snippet. I did this by draggging a slider button up and down that allows me to move smoothly between different pitches.
I want to notate this in sheet music now however and I'm not sure what to put down.
My Question
How do I notate a 'wailing' sound?
I've heard this kind of thing plenty of times before when people improvise, so I suspect there's a way to do it.
Comment: @joseem's answer is great.  I think the squiggly lines on the staff make the most sense.  Are you notating this music on a classical western staff?
Comment: Yes. Its supposed to be
Comment: Curiously, the "squiggly" line is a glissando in music notation, which is not exactly the same as a portamento (for example a glissando in a piano would be a scale played extremely rapidly or even raking the fingers across the keys, producing an effect almost like, but not quite, a true portamento). For that reason I did not mention glissando in my answer below, but of course it can also be used, as did the transcriber of the Tangerine Dream piece. I agree with leftaroundabout's comment below, though, and would rather recommend the oblique straight line.
Answer: In classical terminology portamento would probably be the most appropriate naming for the effect you wish to notate, and the notation for that is a
slur connecting the notes in the "gliding" range extremities. A curved slur is the most common form of notation:

In some instruments that allow for portamento, like the trombone and timpani, a slur may imply portamento. In other instruments it may have specific meanings (like the bowings in bowed string instruments) or just mean to play legato (like in the piano). [thanks to @leftaroundabout for the improvement of this paragraph].
However I have also seen used an oblique "straight" slur (I'm not sure if it's still called a slur if it is a straight line) to indicate portamento, in situations where the round slur could be misinterpreted as a portamento when it was meant as legato.

The simultaneous use of the slur and "straight" line also can be used (as I understand it is used mostly with bow instruments, as the slur on it's own is used to indicate the intended bowing).

Any way, these are only suggestions. Your piece is specific and uses specific technology that may not be possible to notate (to your satisfaction, as notation is always an aproximation). So you should feel free to adapt, adopt, or develop your own form of notation, as many composers have done.
Just as an example of a possible approach to transcribing a synthesizer piece I include here a few excerpts of a transcription for a Tangerine Dream piece (Choronzon, from the 1981 album Exit). As can seen a combination of music notation, suggestive graphic signs and text indications is used. (I expect the inclusion of these small clips is considered fair use and does not infringe on copyright)
Comment: Great answer, though I wonder whence you procure that "general rule" of slurs automatically implying legato if possible on the instrument. As you say yourself, this is **not** the case for bowed string instruments, nor on woodwinds (which are more limited in portamento range, but e.g. oboe could certainly implement many half-tone slurs as portamenti), nor on guitar or keyboards with pitch-bending capability. In fact, trombone and timpani seem about the _only_ instruments where slurs are commonly understood as portamenti! So, I'd definitely put the oblique-line notation as first recommendation.
Comment: leftaroundabout, I got the information from an old notation manual, but my main instrument is the piano and I may have generalized too much the case of the remaining instruments. I'll edit and try to improve the answer as per your comment. Thanks a lot for it!
Comment: A slur in guitar music COULD be played portamento, as in a bend, or as a slide, or as a hammer-on/pull-off - assuming the pitch difference is less than, say, four frets. Or even as a combination of these.
Comment: A slur on guitar and indeed, most (all?) instruments means legato, It never means slide or bend. Slide and bend each have distinct markings themselves.

How do I notate a 'wailing' sound?


Trying to get just values and not the formulas from excel file with multiple sheets, on linux using Python

Question: I have a large excel file that has many sheets, and the main sheet in its formulas uses values from the other sheets. I need the main sheet exported or loaded with just the precalculated values and not the formulas or NaNs. I want to do that using python on Linux. It would be simple If I use windows and have Excel in it since I would just need to copy paste the sheet and it will store only values, and it is programable that way. But when it comes to linux it gets tricky. I already tried many known librarys and almost all seems to either not calculate the formulas or just give me the empty cells or NaNs. If you managed to successfully do it, please help. Since I haven't found solution on many posts here, I needed to create my own.
Comment: @Damiaan I use Calc, but wonder can we automate opening copying closing Calc with python?
Answer: Python and Excel can work together, but are not made for eachother. As a linux user myself: why don't you just use your Windows solution but with Calc from LibreOffice instead of excel? Calc can open Excel files and save it as Excel aswell.
EDIT:
If you use OpenPyXL you can use the data_only flag to get only the data, not the formulas. like in:
wb = openpyxl.load_workbook(filename, data_only=True)
I'm sure this is also a feature in other common Excel Python Parsers.
Comment: I use Calc, but wonder can we automate opening copying closing Calc with python?
Comment: You should take a look at Calc scripting. It supports Python. https://help.libreoffice.org/6.1/en-US/text/shared/guide/scripting.html
Comment: @PetarPetrovic I've edited my original answer with a solution using OpenPyXL.
Comment: I have already tried it. It seems like it works only if the sheet uses formulas just for the values whitin its sheet, but I mentioned that I am trying for the sheet that uses values from the other sheets whitin the same workbook for its formulas
Comment: @PetarPetrovic waht happens if you use Pandas then?
Comment: Pandas is the first lib that I tried, but as I already mentioned its either empty, Nan, or just formulas, and not the values. I don't know what cloudconvert.com/xls-to-csv is using, but it does a good job with exporting the values I need. But as I already mentioned I am trying to automate it with python, so I can't manually save or convert the excel file.
Comment: Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/244080/discussion-between-damiaan-and-petar-petrovic).
Comment: we can continue chatting


Chamar função somente quando a anterior encerrar

Question: eu tenho 2 funções sendo chamadas dentro de outra, o problema que a segunda função depende de alguns elementos que vem da primeira função. A 1° função faz uma requisição ajax que leva um certo tempo em segundos, e o problema estar ai. Esta indo para segunda função sem antes encerrar a primeira, e isso prejudica o funcionamento da segunda função.
Exemplo:
function gerador(){
          funcao1();
          funcao2();
 }

tem alguma forma de so chamar a função 2 quando encerrar a função 1? lembrando que eu não posso alterar a estrutura das funções, apenas posso chamar elas. Então tenho que ter uma solução fora delas.
Comment: O que você descreve é um caso de [Problema XY](https://meta.pt.stackoverflow.com/q/499). O AJAX tem mecanismo próprio para você detectar o sucesso da requisição e executar algo (`onreadystatechange `). Uma  pesquisada por AJAX aqui no site vai ter exemplos. Queira fornecer um [mcve] do problema, se os posts atuais do site não forem suficientes. Links para entender melhor o funcionamento do SOpt: [Tour], [Ask], [Manual de como NÃO fazer perguntas](https://pt.meta.stackoverflow.com/q/5483/70) e [Help]
Answer: Geralmente uma função assíncrona terá que fazer uso ou de callback, ou de promise.
Como na pergunta não foi especificado qual é o caso, vou ter que usar um exemplo genérico.
Se a sua função utiliza callbacks, você provavelmente terá que passar a funcao2 como parâmetro para a funcao1, dessa forma quando a funcao1 terminar de rodar, ela pode invocar a funcao2 para ser executada logo em seguida:
function gerador() {
    funcao1(retornoDaFuncao1 => funcao2(retornoDaFuncao1));
}

Agora se você está trabalhando com promises, você pode utilizar o callback dentro método then para invocar a funcao2:
function gerador() {
    funcao1().then(retornoDaFuncao1 => funcao2(retornoDaFuncao1));
}

Ou então utilizar os modificador async na sua função, que permite pausa-la até que uma promise termine de executar com o comando await. Note que isso só é possível se o retorno da funcao1 for um objeto do tipo Promise:
async function gerador() {
    var retornoDaFuncao1 = await funcao1();
    funcao2(retornoDaFuncao1);
}


What file permissions and ownerships are appropriate for the files directory and subdirectories?

Question:
Possible Duplicate:
What are the recommended directory permissions?

I've scoured the net, and it seems that everyone has different methods of doing this and I just want to get a quick straight answer if possible. So i'm on Centos with apache installed.
I know the files folder has to be 777, but 777 is insecure as anyone can write to it, but isn't that what we need since anonymous users have to write to it when they upload to the server like images or what not? And not to forget drupal throws an error if its not 777.
Also if my user for that domain is foo, then the ownership of files and all its items inside would be foo:foo  correct? But im reading it should be foo:www-data ? so which one is it?
Comment: Anonymous user will upload file, but its the Apache User which will write it to the DIR, so its enough if Apache User has read write access to files DIR instead of 777.
Answer: It depends somewhat on your server configuration but it doesn't have to be 777, and in fact it should not be 777 as that is a security issue.
The web server user (on your server, not your drupal site) is what has to be able to write to the files directory. Whether the drupal user is logged in or anonymous is unrelated.
For information on this see http://drupal.org/node/244924


Simplify two conditional probabilities

Question: Given $P(C) = P(A|B)$, is it possible to get $P(D|C)$ in terms of $A$, $B$, and $D$ only?
It seems like this should be some simple algebra, but I've been going around in circles trying to show it.
Comment: ...Bayes' Theorem?
Comment: I would think so, but that's where I can't seem to make the algebra work.
Comment: I'd summarize my issue as not realizing that you cannot assume there's any relationship at all between two events just because they have the same probability! Seems terribly obvious now.
Answer: It is not possible.
Suppose you are tossing a fair die.
Let $A$ be the event "the toss is even".
Let $B$ be the event "the toss is $≤3$".
Let $C_1$ be the event "the toss is $≤2$"  So, indeed, $P(C_1)=\frac 13=P(A|B)$.
Let $C_2$ be the event "the toss is either $2$ or $4$".  Then again we have $P(C_2)=\frac 13=P(A|B)$ .
Let $D$ be the event "the toss is $1$".  Then $P(D|C_1)=\frac 12$ but $P(D|C_2)=0$ so $P(D|C)$ can't be determined from $A,B,D$ alone.
Comment: Both answers are great but I'll pick this one cause it laid out the counterexample so clearly.
Answer: If you could write $P(D|C)$ in terms of $A$, $B$, and $D$ only, then given two events $C,C'$ such that $P(C) = P(C') = P(A|B)$ the probabilities $P(D|C)$ and $P(D|C')$ should be the same.
This is absurd. Take any $C$ and $C'$ that are disjoint and satisfy $P(C) = P(C') = P(A|B)\ne 0$. For example, consider flipping two fair coins, and let
$$ A = C = \{\text{coin 1 is heads}\}$$
$$ B = \{\text{coin 2 is heads}\} $$
$$ C' = \{\text{coin 1 is tails}\} $$
In this case, we have $P(C) = P(C') = P(A|B) = \frac{1}{2}$, and $P(C\cap C') = 0$.
If we let $D=C$, then $P(D|C) = 1$ and $P(D|C') = 0$. Thus, $P(D|C)$ can't be written in terms of $A$, $B$, and $D$ alone.

Simplify two conditional probabilities


How to prove that $\sum_{n}^{\infty}u_{n}^{2}\left(u_{1}+\cdots+u_{n}\right)^{-1}<\infty$ under these conditions?

Question: Suppose that $u_n$ is a decreasing sequence of positive numbers that converges to zero. Suppose moreover that $S_n = \sum_{k=1}^n u_k$ diverges. I would like to prove that the sum $\sum u_k^2 / S_k$ is finite, which I believe is true. Indeed, sum of the type $\sum u_k / S_k^{1+\epsilon}$ are finite, but I have not been able to exploit that. Comparison with an integral of the type $\int (f')^2(x)/f(x) \, dx$ has not revealed particularly helpful to gain any intuition. Have also tried to prove that this is a Cauchy sequence, but I always end up missing something.
Thank you.
Answer: Consider a sequence that really slowly tends to $0$. For example
$$u_n = \frac{1}{\sqrt{\log (n+1)}}.$$
Then you have
$$\frac{n}{\sqrt{\log (n+1)}} \leqslant S_n \leqslant \frac{n}{\sqrt{\log 2}},$$
and
$$\frac{\sqrt{\log 2}}{n\log (n+1)} \leqslant \frac{u_n^2}{S_n} \leqslant \frac{1}{n\sqrt{\log (n+1)}},$$
so in that case
$$\sum_{n=1}^\infty \frac{u_n^2}{S_n} = +\infty.$$
Generally, you have $S_n \leqslant n u_1$, and hence
$$\frac{u_n^2}{S_n} \geqslant \frac{u_n^2}{nu_1},$$
so it is a necessary condition that $\sum \frac{u_n^2}{n} < \infty$. That condition is however not sufficient, as $u_n = (\log (n+1))^{-t}$ for $\frac{1}{2} < t \leqslant 1$ shows, in that case $S_n \sim \frac{n}{(\log (n+1))^t}$ and $\frac{u_n^2}{S_n} \sim \frac{1}{n(\log(n+1))^t}$. On the other hand, we have $S_n \geqslant n u_n$, so the condition $\sum \frac{u_n}{n} < \infty$ is sufficient.
Answer: Hint: use that $S_n \geq nu_n$ for every $n \in \mathbb{N}$.
We then have $\frac{u_n^2}{S_n} \leq \frac{u_n}{n}$
If we call $U_n \overset{\Delta}{=} \sum_{i=1}^n \frac{u_k^2}{S_k}$, what can you say about the general term of the sum?
Comment: We need $\limsup r_n < 1$, which is indeed not always the case. (e.g. $u_n = 1 / \log(n)$ and $\sum u_n / n$ diverges). What do you really mean?
Comment: Did you mean $U_n \overset{\Delta}{=} \sum_{i=1}^n \frac{u_k^2}{S_k}$? I am still not seeing how to use the bound $u_n/n$. I played with similar ideas, introducing $r_k \to \infty$ with $\sum_{r_k}^{r_{k+1}} u_i \geq 1$ with no luck.
Comment: OK, a classical result to check if a serie is convergent is to look at the ratio of its general term.
Here we have $r_n =\frac{\frac{u_{n+1}}{n+1}}{\frac{u_n}{n}} = \frac{u_{n+1}}{u_n} \frac{n}{n+1} <1$


Mensagem no Botão Sair - Xamarin Forms

Question: Preciso de uma mensagem no Botão Sair (utilizarei o Navigation.PopAsync()) próximo do que fiz mas que funcione (esse não funciona):
//Botão Sair
void BtnSair_Clicked(object sender, EventArgs e)
{
   var result = DisplayAlert("Alerta", "Deseja realmente sair?", "Sim", "Não");
   if (result) {Navigation.PopAsync();}
}

Answer: Como pra alguns pode ser útil consegui resolver da seguinte maneira:
private async Task BtnSair_Clicked(object sender, EventArgs e)
{
  var result = await DisplayAlert("Alerta", "Deseja realmente sair?", "Sim", "Não");

  if (result)
  {
    await Navigation.PopAsync();
  }
}

Percebi que o DisplayAlert retorna Task e a variável esperava apenas bool, então na chamada do botão utilizei private async Task e depois await onde terá que aguardar retorno.

Mensagem no Botão Sair - Xamarin Forms


Why do we treat study standard errors as known in a meta-analysis?

Question: I wonder if anyone knows why it is that we treat study standard errors as known when conducting a meta-analysis? When conducting analysis of trial data, the error is treating as a quantity to be estimated (at least in the Bayesian code I've seen). In a meta-analysis however, we might say:
y[i]  ~ N(delta,sigma[i])
delta ~ N(u,tau)

leaving sigma as data instead of identifying it as a parameter. Is there a reason for this? Would we just never get stable estimates? Are there any consequences to this approach (i.e., underestimating uncertainty?)
Comment: This is because meta-analysis uses the aggregated data.
If the meta-analysis is performed using a random effect model, the estimate of between-study heterogeneity is produced in response to the amount of errors estimated from analysis of trial data.

I think your code should be changed. (y[i] ~ N(u,sigma) -> y[i] ~ N(u,sigma[i]), sigma[i] was data which was extracted from the original article along with y[i].)
Comment: @J-HYoon, why not turn that into an official answer? Otherwise this Q looks unanswered.
Comment: I think there is a typo in your formula.
Answer: (This answer is the same as the comment.)
This is because meta-analysis uses the aggregated data. If the meta-analysis is performed using a random effect model, the estimate of between-study heterogeneity is produced in response to the amount of errors estimated from analysis of trial data. I think your code should be changed: y[i] ~ N(u,sigma) should read y[i] ~ N(u,sigma[i]), where sigma[i] was data which was extracted from the original article along with y[i].
Answer: It's much easier -- especially back in the days before modern computing -- and it's a pretty good approximation, because small differences in the uncertainties don't have much impact on the final result.
Here's an example. Start with the meta-analysis that's in the logo of the Cochrane collaboration

Now adjust the standard errors for each trial by multiplying by independent $U[0.8,1.2]$, changing them up or down by up to 20%.  Re-do the meta-analysis. These are the confidence intervals from 100 replications (on the log odds ratio scale)

Even a 20% error in the SE doesn't make a big difference to the overall meta-analysis.  So people didn't worry.
Now that meta-analysis can easily model the uncertainties in the standard errors it's probably worth doing, but there were good reasons not to worry too much in the past.


Focus em campo inválido jQuery Validate

Question: Estou usando a biblioteca jQuery Validate para fazer algumas validações em um formulário e gostaria de sabe se alguém sabe como poderia fazer o foco ficar sempre no campo, no caso de ele ser inválido. Atualmente, ele sai do campo inválido mas não deixa submeter até ser corrigido. Segue código:

$(document).ready( function() {

 $("#cadastro").validate({
  // Define as regras, pega sempre pela ID. Se não passar (caso do combo) usa o Name.
  rules:{
   cracha:{
    // ordem será obrigatório (required), numérico e terá tamanho mínimo (minLength)
    required: true, number: true,  minlength: 4
   }
  },
  // Define as mensagens de erro para cada regra
  messages:{
   cracha:{
    required: "Passe o crachá! ",
    number: "Somente numeros!",
     minlength: "Minimo 4 digitos!"
   }
  }
 });
});

Alguma idéia?
Comment: Já deveria funcionar por _default_. Tenta por a opção `focusInvalid: true`
Comment: Deu certo....Obrigado!
Answer: O focus nos campos inválidos já deveria estar ativado por default. Mas você pode forçar a ativação setando nas opções, assim:
focusInvalid: true

Para mais informações veja a documentação do plugin: http://jqueryvalidation.org/validate

Focus em campo inválido jQuery Validate


Standard Score or z-score

Question: On the first periodic exam in Statistics, the population mean was 70 and the population standard deviation was 9. How to determine the standard score of a student who got a score of 88 assuming that the scores are normally distribtued?
Answer: We can use
$$Z=\frac{X-\mu}{\sigma} \Rightarrow Z=\frac{88-70}{9}=2$$

Standard Score or z-score


Mean comparison of two categorical variables

Question: I'd like to compare people's perception of safety at a certain location [which is a categorical variable on a scale of 1-10, with 1=feel very unsafe & 10=feel very safe] before and after being aware of some initiatives. Would a paired-sample t-test be appropriate or do I need to use non-parametric tests (e.g. Wilcoxon-Mann-Whitney test)?
Answer: If your data are ordinal ratings, then they cannot be normally distributed.  The Mann-Whitney (WMW) test is more appropriate.  If you have a true likert scale (that is, many likert items that measure the same thing and which are summed or averaged to give a single number for each person), and if the scores do not lie up against the limits of the scale, then the $t$-test may be used, but the WMW is likely to have greater power.


Cycles in permutations of a given size

Question: How would I find the number of permutations of $[n]$ in which all cycles have length $1$ or $2$?
I know how to do this if I have, say, $8$ numbers from ${{1,2,3,...,8}}$ and I want them to be broken into Count$(4, 3, 1)$. But not when I don't know how many cycles of $2$ and $1$ I want.
Note:
I'm looking for a way to derive a formula or something. I need to use it to prove by induction, I'm assuming, $r(n + 1) = r(n) + n · r(n − 1)$.
Comment: This is [OEIS A000085](http://oeis.org/A000085).  It is easy to derive the recurrence $a_n = (n-1)a_{n-2} + a_{n-1}$.
Comment: Is $[n] = \{1, 2, \cdots, n\}$?
Comment: @GilYoungCheong: yes!
Answer: These permutations are involutions, meaning $\sigma \in S_n$ with $\sigma^2=1$.
Online Encyclopedia of Integer Sequences A000085.  This was one of the first sequences in that library.

1, 1, 2, 4, 10, 26, 76, 232, 764, 2620, 9496

a(n) is also the number of matchings in the complete graph K(n).
a(n) is the number of partitions of a set of n distinguishable elements into sets of size 1 and 2.
a(n) = number of nonnegative lattice paths of upsteps U = (1,1) and downsteps D = (1,-1) that start at the origin and end on the vertical line x = n in which each downstep (if any) is marked with an integer between 1 and the height of its initial vertex above the x-axis. For example, with the required integer immediately preceding each downstep, a(3) = 4 counts UUU, UU1D, UU2D, U1DU.
a(n) = a(n-1) + (n-1)*a(n-2)
Comment: Involutions are not cycles, are they? Let me know if I am not right about this!
Comment: Oops. I misunderstood the question!
Answer: I will show why indeed $a_n = (n-1)a_{n-2}+a_{n-1}$ is the right reccurence relation. Clearly $a_1 = 1$. Let $S_n$ be a set of all permutations $\pi$ of length $n$. The number of permutations of length $n$ with cycles only of lengths $1$ and $2$ we will denote $a_n$.
Next, all permutations from $S_{n+1}$ can be constructed by following procedure from $\pi\in S_n$, where
$$\pi = \begin{pmatrix}
1 & 2 & 3 & \cdots & n \\
\pi(1) & \pi(2) & \pi(3) & \cdots & \pi(n)
\end{pmatrix}.$$
By adding 1-cycle $\pi(n+1)=n+1$ one gets $\pi^*\in S_{n+1}$
$$\pi^* = \begin{pmatrix}
1 & 2 & 3 & \cdots & n & n+1 \\
\pi(1) & \pi(2) & \pi(3) & \cdots & \pi(n) & n+1
\end{pmatrix}$$
and then by $n$ inversions to get another $S_{n+1}$ permutations of the form
$$\pi^*_i = \begin{pmatrix}
1 & 2 & 3 & \cdots & i & \cdots & n & n+1 \\
\pi(1) & \pi(2) & n+1 & \cdots & n & \cdots & \pi(n) & \pi(i)
\end{pmatrix}$$
In total $n!+nn!=(n+1)!$ distinct permutations. Now, it is clear that all permutations $\pi^*$ constructed by just adding $\pi(n+1)=n+1$ satisfy the original statement. The number of them is $a_n$. Next, since the inversion will increase the cycle length which has been swapped with by one (see this answer of mine), only those permutations $\pi^*_i$ with swap 1-cycle by 1-cycle are allowed. To know the number of these, we first define $\Pi_n$ a set of allowed permutations of length $n$, i.e. those with only 1-cycles and 2-cycles (there are $a_n$ of elements of this set), $j(\pi)$ as a number of 1-cycles in a given permutation. With this one can easily obtain the desired reccurence (will be added later in this proof)

GENERATING FUNCTION
Consider the sum
$$S_n(x,y) = \sum_{\pi\in\Pi_n}x^{j(\pi)}y^{n-j(\pi)}$$
This may look strange and meaningless, but you will see it is indeed fruitful. The reason is that
$$S_n(1,1)=a_n.$$
Trivially, we have $S_1(x,y)=x$. Let us express $S_{n+1}(x,y)$, since we can decompose it as permutations $\pi\in\Pi_n$ with added $\pi(n+1)=n+1$ (i.e. $\pi^*$, clearly $j(\pi^*)=j(\pi)+1$) and one with inversions such that they invert $\pi(n+1)=n+1$ with only 1-cycles (there are exactly $j(\pi)$ disting inversion to make an allowed permutation, similarly $j(\pi^*_i)=j(\pi)$), therefore
$$S_{n+1}(x,y) = \sum_{\pi\in\Pi_{n+1}}x^{j(\pi)}y^{n+1-j(\pi)}= \sum_{\pi\in\Pi_n}x^{j(\pi^*)}y^{n+1-j(\pi^*)} + \sum_{\pi\in\Pi_n}j(\pi)x^{j(\pi^*_i)}y^{n+1-j(\pi^*_i)}=
\sum_{\pi\in\Pi_n}x^{j(\pi)+1}y^{n-j(\pi)} + \sum_{\pi\in\Pi_n}j(\pi)x^{j(\pi)}y^{n+1-j(\pi)}= \left(x+y\frac{\partial}{\partial x}\right)S_n(x,y)
$$
By $S_1(x,y)=x$ we can therefore in the spirit of the previous relation define $S_0(x,y)=1$. We define a generation function
$$G(x,y,t)=\sum_{n=0}^\infty t^n S_n(x,y),$$
therefore
$$\frac{1}{t}(G(x,y,t)-1) = \left(x+y\frac{\partial}{\partial x}\right)G(x,y,t)
$$
According to wolphram alpha and by imposing $G(0,y,t)=1$ we get
$$G(x,y,t) = \exp\left(\frac{2x-tx^2}{2t y}\right) + \frac{1}{t}\sqrt{\frac{\pi y}{2}}\exp\left(-\frac{(tx-1)^2}{2t^2 y}\right)\left[\operatorname{erfi}\left(\frac{1-tx}{t\sqrt{2y}}\right)-\operatorname{erfi}\left(\frac{1}{t\sqrt{2y}}\right)\right]$$
Since $G(1,1,t) = \sum_{n=1}^\infty a_n t^n$ with $a_0=1$ we get
$$\sum_{n=0}^\infty a_n t^n = \exp\left(\frac{2-t}{2t}\right) + \frac{1}{t}\sqrt{\frac{\pi}{2}}\exp\left(-\frac{(t-1)^2}{2t^2 }\right)\left[\operatorname{erfi}\left(\frac{1-t}{t\sqrt{2}}\right)-\operatorname{erfi}\left(\frac{1}{t\sqrt{2}}\right)\right]$$

Cycles in permutations of a given size


Express the Markov property using the transition matrix

Question: Let $\{X_t; t \in \mathbb{N}_0\}$ be a discrete Markov chain with finite state space $\Omega$ and transition matrix $P$. Let $\{\mathcal{F}_t; t \in \mathbb{N}_0\}$ be the corresponding filtration.
I saw in a paper (but without justification) that the Markov property can be expressed as
$$\mathbb{E}[f(X_{t+1})|\mathcal{F}_t] = P f(X_t).$$
My question is:

How do I come to this? From which definition of Markov property do I need to start from? And is $f$ any function, or does it need to be bounded and measurable?

Any help would be appreciated.
Answer: Presumably, $\ f:\Omega\rightarrow V\ $ where $\ V=\mathbb{R}^n\ $$\big($or maybe $\ \mathbb{C}^n\ \big)$ and $\ Pf:\Omega\rightarrow V\ $ is the function defined by
$$
(Pf)(\omega)=\sum_{s\in\Omega}P_{\omega s}f(s)\ .
$$
For a discrete finite-state Markov chain, the Markov property reduces to
$$
\mathbb{P}\big(X_{t+1}\in A\,|\,\mathcal{F}_t\big)=\mathbb{P}\big(X_{t+1}\in A\,|\,X_t\big)\ ,
$$
or equivalently,
$$
\mathbb{P}\big(X_{t+1}=s\,|\,\mathcal{F}_t\big)=\mathbb{P}\big(X_{t+1}=s\,|\,X_t\big)
$$
for $\ s\in\Omega\ $. Also, by the definition of the transition matrix $\ \mathbb{P}\big(X_{t+1}=s\,|\,X_t\big)=P_{X_ts}\ $. So
\begin{align}
\mathbb{E}\big(f\big(X_{t+1}\big)\,\big|\,\mathcal{F}_t\big)&=\sum_{s\in\Omega}f(s)\,\mathbb{P}\big(X_{t+1}=s\,|\,\mathcal{F}_t\big)\\
&=\sum_{s\in\Omega}f(s)\,\mathbb{P}\big(X_{t+1}=s\,|\,X_t\big)\\
&=\sum_{s\in\Omega}P_{X_ts}f(s)\\
&=\big(Pf\big)\big(X_t\big)\ .
\end{align}
I can't see how the identity could be made sense of unless $\ f\ $ is a function on $\ \Omega\ $, in which case it's automatically measurable with respect to any $\ \sigma$-algebra on its codomain and the discrete $\ \sigma$-algebra on $\ \Omega\ $.
Comment: I've now inserted more details of the derivation.  However  I've only shown that the Markov property implies the identity, not that the identity implies the Markov property.  The reverse implication requires the identity to hold for a sufficient range of functions $\ f\ $. The set of indicator functions $\ I_{\{s\}}:\Omega\rightarrow$$\{0,1\}\ $ for all $\ s\in\Omega\ $ should suffice.
Comment: Where did you use the Markov property? How did you go from $\mathbb{E}\big(f\big(X_{t+1}\big)\,\big|\,\mathcal{F}_t\big)$ to $\sum_{s\in\Omega}P_{X_ts}f(s)$?


Let $\mu$ be the Lebesgue measure. Show, that if $A \subset B$ has an interior point, then $\mu(A) > 0$

Question: Let $A \subset B$ be a Lebesgue measurable set with at least one interior point.

Show, that $\mu(A) > 0$

For any $0 \le \alpha < \mu(A)$ there is a set $A_{\alpha} \subset A$ such, that $\mu(A_{\alpha}) = \alpha$

My proof
ad 1.
$x \in A$ is an interior point, if there exists a neighborhood $U(x)$ such that $U(x) \subset A$ and $U(x) \neq \varnothing$
Because we assume, that $A$ has at least one interior point, then this means that there exists at least one non-empty neighborhood $U(x) \subset A$
Using the properties of our Lebesgue measure, we get, that $\mu (U(x)) \le \mu(A)$. But because $U(x) \neq \varnothing$, then we get $0 < \mu (U(x)) \le \mu(A)$
ad 2.
Let's say, that $A = A_1^1 + A_1^2$ such, that $\mu(A_1^1) = \mu (A_1^2) = \frac{1}{2} \mu(A)$
We repeat this process over and over again (so we'd have $A_1^1 = A_{2,1}^1 + A_{2,1}^2$ such that $\mu( A_{2,1}^1) = \mu ( A_{2,1}^2) = \frac{1}{2} A_1^1 = \frac{1}{4} A$ etc.), until we have divided our set $A$ into such small pieces, that we can construct our set $A_{\alpha}$ with measure $\alpha$
For example: Let $\alpha = \frac{3}{4} \mu(A)$, then our $A_{\alpha} = A_1^1 \cup A_{2,1}^1$ for example.

Are my proofs correct? Do they need extra commentary? Can I somehow express them in a more abstract and mathematical way (especially ad 2.)?
Comment: Are $A$, $B$ subsets of $\mathbb{R}$ or subsets of $\mathbb{R}^n$?
Comment: Unfortunately, there's no information about this whatsoever
Answer: For part 1 you have to prove that $\mu(U(x)) > 0$. For part 2 you have to specify how you were able to decompose your $A$ into $A_1^1$, $A_1^2$, and you have to show how to find $A_{\alpha}$ for all $\alpha \in [0, \mu(A))$, not just $\alpha = \frac{3}{4}$. It's not obvious to me how to do number $2$ based on what you've written, say for $\alpha = \frac{1}{\sqrt{2}}\mu(A)$.
Comment: Isn't $\mu (U (x)) > 0$ obvious, because $U(x) \neq \varnothing$? What I mean with part 2 is that you divide the set $A$ into such small sets that if you want to have a set $A_{\alpha} \subset A$ such that $\mu (A_{\alpha}) = \alpha$, then you just take a specific sum of those small sets (like my short example with $\frac{3}{4} \mu(A)$
Comment: There are sets $S \neq \emptyset$ such that $\mu(S) = 0$, e.g. any countable set $S$. How do you divide $A$ into such small sets? What is the proof that such a division exists?
Comment: If we assume that we are in $\mathbb{R}$, then it's pretty easy to prove that $\mu (U(x)) = 0 \: \Leftrightarrow \: U(x) = \text{ singleton, or }\varnothing$ and that we are able to divide our set $A$ into small sets.
Comment: @anon That's not true. $\mu(\mathbb{Q}) = 0$, and $\mathbb{Q}$ is countable. For an uncountable set of measure $0$, the Cantor set is an example. To prove 1, note that if $U$ is a nonempty open set, then $U$ contains an open cube $Q$ of positive side length $s$. Hence $\mu(U) \geq \mu(Q) = s^n > 0$. If it's easy to prove, then include the argument (or at least a sketch) in your proof.
Answer: Part 1 is easy, so I skip it. I work on Part 2.
I assume that you are working on $\mathbb{R}$ rather than $\mathbb{R}^{n}$.
Define $f:[0,\infty)\rightarrow\mathbb{R}$ by $f(x)=\mu\left([-x,x]\cap A\right)=\int_{-x}^{x}1_{A}d\mu$.
Clearly $f$ is continuous and $f(x)\rightarrow\mu(A)$ as $x\rightarrow \infty$ by continuity
of measure. Moreover, $f(0)=0$. Now, given $\alpha$ with $0<\alpha<\mu(A)$,
we can choose a sufficiently large $x$ such that $f(x)>\alpha$.
Observe that $f(0)<\alpha<f(x)$. By intermediate value theorem, there
exists $x'\in(0,x)$ such that $f(x')=\alpha$. Define $A_{\alpha}=[-x',x']\cap A$,
then $\mu(A_{\alpha})=f(x')=\alpha$.
Comment: But my proof for part 1 is alright? To part 2: The condition would be $0 \le \alpha < \mu (A)$, not $0 < \alpha$ if that's important somehow?
Comment: If $\alpha=0$, just choose $A_\alpha =\emptyset$.
Comment: So what about my proof for ad 1? I think I need to assume here that $U(x)$ is a ball $K(x, \varepsilon)$ to make sure that (in $\mathbb{R}$) its measure is greater than zero?


LDAP - Grant user write permission to group / organizationalUnit

Question: I tried to grant cn=admin,ou=Administrators,dc=example,dc=com full write access to ou=People,dc=example,dc=com so that this admin can create (and of course read) new entries under ou=People and also can modify them (e.g. changing passwords).
My ldif file looks like
dn: olcDatabase={1}mdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {4}to dn.subtree="ou=People,dc=example,dc=com" by dn.exact="cn=admin,ou=Administrators,dc=example,dc=com" write

After running it with
ldapadd -Y EXTERNAL -H ldapi:/// -f permission.ldif, I just got
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "olcDatabase={1}mdb,cn=config"

Anyone can explain what is wrong here and how to do it correct? Tried quite a lot things which I found online.
Answer: After a few more trial and errors I found a working solution.
Take a look at this ldif:
dn: olcDatabase={1}mdb,cn=config
changetype: modify
delete: olcAccess
-
add: olcAccess
olcAccess: {0}to attrs=userPassword by self write by dn="cn=admin,ou=Administrators,dc=example,dc=com" write by anonymous auth by * none
olcAccess: {1}to attrs=shadowLastChange by self write by * read
olcAccess: {2}to dn.subtree="ou=People,dc=example,dc=com" by dn.exact="ccn=admin,ou=Administrators,dc=example,dc=com" write
olcAccess: {3}to * by * read

/edit: Well, this lets you create new users under ou=People but you cannot change all attributes of them.
Comment: Is there any explanation for why the attribute cannot just be added, but has to be wiped and rewritten? Is it the order that matters? Thx


Proof of the derivative of $\sin{x}$ is $\cos{x}$

Question: I recently learned the proof that the derivative of $\sin x$ is $\cos x$ in Stewarts calculus book. However, in his proof he uses preconceived limit laws such as the sum and product law to evaluate the limit. My confusion is that these limit laws can only be used when the limit exists however we do not know the limit in this case we are trying to evaluate it so how can we use these limit laws must we resort to a geometric proof?
Comment: Giving a valid proof of something like the derivative of $\sin$ is *very* sensitive to your initial definitions. Could you give us your definition of $\sin(x)$? Also, since Stewart's book is not publicly available (and for the completeness of the question besides), could you provide the part of the proof you would like to clarify?
Comment: There are many proofs that amount to something like $$f(x) = \sin(x) \implies f'(x) = \cos(x) \cdot f'(0) \\ g(x) = e^x \implies g'(x) = e^x \cdot g'(0)$$ Is your problem, determining the proof of the existence and value of the derivative at zero?  In this instance, proving $\lim_{h\to 0} \frac{\sin(h)}h = 1$? (If so, there are several proofs, but each depends on how you defined the $\sin$ function, so as preferred_anon mentions in their comment,
 you'd need to specify which definition you are using)
Comment: The product law can be used because we can show *after the fact* that the limits exist. There is no circular argument.
Answer: There should not be any problem with limits...
$$\begin{align}\lim_{h\to 0} \frac{\sin(x + h) - \sin x}{h} &= \lim_{h\to 0} \frac{2\cos(x + \frac h2)\sin\frac h2}{h} \\&= \lim_{h\to 0} \left[\cos\left(x + \frac h2\right)\cdot\frac{\sin (h/2)}{h/2}\right] \\&\overset*= \lim_{h\to 0}\cos\left(x + \frac h2\right)\cdot\lim_{h\to 0}\frac{\sin (h/2)}{h/2} \\&= \cos x \cdot 1 \\&= \cos x\end{align}$$
Explanation for (*): Limit of product is equal to product of limits in this case since both expressions have limits
Comment: If you tell me where are you having a problem, I will try to elaborate on that part.
Comment: So I'm a bit confused on why you  can apply the limit laws such as the limit of a product is the product of the limits to evaluate the limit . The limit product law of works if both the limits exsist however in this case we are not sure whether the limits exsist or not we are trying to evaluate it
Comment: We are certainly sure that those limits exist. These are standard trigonometry limits that can be found thorugh a geometric approach, and that can be found plentyful on the internet. Both VIVID and Hamam make use of those limits
Comment: @Thehomeschooler $f(h) = \cos(x + \frac h2)$ is a continuous function which implies $\lim_{h\to 0}f(h) = f(0) = \cos x$. Also, it is a well-known fact that $\lim_{h\to 0}\frac{\sin h}{h} = 1$ some textbooks refer to it as "wonderful limit". It can be proven either with a geometric approach or Sandwich theorem or trivially by L'Hospital's rule (as imranfat mentioned)
Comment: Ah ok thanks a lot this was helpful.
Answer: Let $$f(x)=\sin(x)$$
and $ a,h \in \Bbb R$.
$$A(h)=\frac{f(a+h)-f(a)}{h}=$$
$$\frac{\sin(a+h)-\sin(a)}{h}=$$
$$\frac{\sin(a)\cos(h)+\cos(a)\sin(h)-\sin(a)}{h}=$$
$$\frac{\cos(h)-1}{h}\sin(a)+\frac{\sin(h)}{h}\cos(a)$$
and,
$$\lim_{h\to 0}A(h)=0+1.\cos(a)=f'(a)$$
Comment: Could you be more specific about how the limit of $A(h)$ becomes $\cos(a)$?
Comment: In your answer you used the limit laws such as the limit if a product is the product of the limits but the limit has to exsist to be able to use these laws so how can we prove without limit laws?


Problema com Like para Criteria

Question: Bom dia.
Estou com uma tabela no seguinte formato:

Preciso fazer um select para retornar o somatório de valores da infraestrutura agrupados por ano. Criei esta query no SQL:
select YEAR(dataCompraInfra), sum(valorCompraInfra), sum(valorVendaInfra) from
concessaoinfraestrutura WHERE dataCompraInfra LIKE '2011%' GROUP BY YEAR(dataCompraInfra);

A query funcionou, e me retorna os valores contidos na imagem abaixo. Contudo, quando tentei adaptar isso numa Criteria, é lançada exceção.
Resultado

Criteria
    Criteria crit = sessao.createCriteria(Infraestrutura.class);

    ProjectionList proj = Projections.projectionList();
    proj.add(Projections.sum("this.valorCompraInfra"));
    proj.add(Projections.sum("this.valorVendaInfra"));
    crit.add(Restrictions.like("this.dataCompraInfra", "2011", MatchMode.START));

    crit.setProjection(proj);

    lista = crit.list();

Exceção:
ADVERTÊNCIA: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
javax.el.ELException: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
    at com.sun.el.parser.AstValue.invoke(AstValue.java:238)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:818)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at br.com.somore.control.filter.ConexaoHibernateFilter.doFilter(ConexaoHibernateFilter.java:27)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
    at org.hibernate.type.TimestampType.toString(TimestampType.java:78)
    at org.hibernate.type.NullableType.nullSafeToString(NullableType.java:119)
    at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:160)
    at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:138)
    at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1769)
    at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1740)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1612)
    at org.hibernate.loader.Loader.doQuery(Loader.java:717)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
    at org.hibernate.loader.Loader.doList(Loader.java:2294)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
    at org.hibernate.loader.Loader.list(Loader.java:2167)
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1706)
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
    at br.com.somore.control.dao.concessao.InfraestruturaDAO.listarResumo(InfraestruturaDAO.java:158)
    at br.com.somore.control.beans.CenarioBean.calcularResumo(CenarioBean.java:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
    ... 34 more

Set 05, 2015 10:45:54 AM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
GRAVE: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
    at org.hibernate.type.TimestampType.toString(TimestampType.java:78)
    at org.hibernate.type.NullableType.nullSafeToString(NullableType.java:119)
    at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:160)
    at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:138)
    at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1769)
    at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1740)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1612)
    at org.hibernate.loader.Loader.doQuery(Loader.java:717)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
    at org.hibernate.loader.Loader.doList(Loader.java:2294)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
    at org.hibernate.loader.Loader.list(Loader.java:2167)
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1706)
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
    at br.com.somore.control.dao.concessao.InfraestruturaDAO.listarResumo(InfraestruturaDAO.java:158)
    at br.com.somore.control.beans.CenarioBean.calcularResumo(CenarioBean.java:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:818)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at br.com.somore.control.filter.ConexaoHibernateFilter.doFilter(ConexaoHibernateFilter.java:27)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

Lendo a exceção, conclui que o problema está em: crit.add(Restrictions.like("this.dataCompraInfra", "2011", MatchMode.START));
Alguém pode dar uma luz de como eu poderia retornar os valores por ano?
Comment: Coloca a instância do objeto list ai por favor, Cast Exception acontece porque o retorno do Hibernate não é do mesmo tipo da classe instanciada para o objeto list... Acho que vai ter que especificar o transform para o Hibernate. Posta o tipo ai que te ajudo
Answer: tenta assim:
crit.add(Restrictions.ge("this.dataCompraInfra", sDate));
crit.add(Restrictions.lt("this.dataCompraInfra", fDate));

onde sDate é um Date com valor 1/1/2011 e o fDate é um Date com valor 31/12/2011.

Problema com Like para Criteria


How do I plot the python output data in 3D with realtime update?

Question: I'm new to python and I coded a program with tons of 5 sets of 3 coordinates (5*3 lists). I wanted to track the position of the five points and hope it can update instantly while the program is running (if not that's fine). Since there are so many data (over 100000 sets), it is inconvenient to output and plot by matlab.
I downloaded VPython module but I cannot plot in 3d. I found VPython really convenient but my program involves complicated calculations so that loops can reduce many lines.
Sorry for a long question, but in short, I wanted a module or something can visualize output of my data in 3d and update from time to time. Thanks.
Python version: 2.7
Answer: It is possible to plot things in VPython. This page gives an overview of how to do that:
http://www.vpython.org/webdoc/visual/graph.html
As for the magnitude of points you are dealing with, you can have some counter that counts to, say, 50, then plots a point and resets itself. So it will plot only 1 out of 50 points, thus not causing a burden on the program.
<code>counter = 0
for/while ... :
    counter += 1
    if counter == 50:
         plot(point)
         counter = 0
    ...
</code>
Comment: VPython is a buggy and dead project. I can't even get it to run on Ubuntu 16. The last updates for it were nearly [5 years ago.](https://github.com/vpython/visual)


Ensemble time series model

Question: I need to automate time-series forecasting, and I don't know in advance the features of those series (seasonality, trend, noise, etc).
My aim is not to get the best possible model for each series, but to avoid pretty bad models. In other words, to get small errors every time is not a problem, but to get big errors once in a while is.
I thought I could achieve this by combining models calculated with different techniques.
That is, although ARIMA would be the best approach for a specific series, it may not be the best for another series; the same for exponential smoothing.
However, if I combine one model from each technique, even if one model isn't so good, the other will bring the estimate closer to the real value.
It is well-known that ARIMA works better for long-term well-behaved series, while exponential smoothing stands out with short-term noisy series.

My idea is to combine models generated from both techniques in order to get more robust forecasts, does it make sense?

There might be many ways to combine those models.

If this is a good approach, how should I combine them?

A simple mean of forecasts is an option, but maybe I could get better predictions if I weight the mean according to some goodness measure of the model.

What would be the treatment of the variance when combining models?
Comment: Even in the univariate case I struggle to imagine an automatic procedure - there's trend (stochastic or deterministic), possible transformations, seasonality (multiplicative or additive) to think about, & I find that to get to a model I use a lot of prior knowledge about what would be sensible for what a particular series represents in reality.  Still, the proof of the pudding is in the eating - I really just wanted to say not to forget to do out-of-sample comparisons with simple techniques- so good luck with it.
Comment: Your ideas sound great, but I'm not so sure about using *automatically* fit ARIMA models.  For univariate series perhaps ... Conventional wisdom is that Holt-Winters is pretty robust used automatically, so that could be your baseline for out-of-sample comparisons between methods.
Comment: @Scortchi I forgot to mention that all series are univariate! ;) I agree that Holt-Winters performs really good when used automatically, but I intend to get one more opinion from another model, to avoid cases where forecasts aren't so good. Sometimes HW shows strange trend behaviour.
Answer: Combining forecasts is an excellent idea. (I think it is not an exaggeration to say that this is one of the few things academic forecasters agree on.)
I happen to have written a paper a while back looking at different ways to weight forecasts in combining them: http://www.sciencedirect.com/science/article/pii/S0169207010001032 Basically, using (Akaike) weights did not consistently improve combinations over simple or trimmed/winsorized means or medians, so I personally would think twice before implementing a complex procedure that may not yield a definite benefit (recall, though, that combinations consistently outperformed selection single methods by information criteria). This may depend on the particular time series you have, of course.
I looked at combining prediction intervals in the paper above, but not at combining variance as such. I seem to recall a paper not long back in the IJF with this focus, so you may want to search for "combining" or "combination" through back issues of the IJF.
A few other papers that have looked at combining forecasts are here (from 1989, but a review) and here and here (also looks at densities) and here and here. Many of these note that it is still poorly understood why forecast combinations frequently outperform single selected models. The second-to-last paper is on the M3 forecasting competition; one of their main findings was (number (3) on p. 458) that "The accuracy of the combination of various methods outperforms, on average, the specific methods being combined and does well in comparison with other methods." The last of these papers finds that combinations do not necessarily perform better than single models, but that they can considerably reduce the risk of catastrophic failure (which is one of your goals). More literature should readily be found in the International Journal of Forecasting, the Journal of Forecasting and for more specific applications in the econometrics or supply chain literature.
Comment: Great point of view about combining models! Your answer was very constructive!
Comment: @Stephan Kolassa, would you have any comments on combining forward and backward predictors, as in Burg's method ?
Comment: @denis: I'm not familiar with forward or backward predictors, nor with Burg's method, sorry... although I would assume that combining forecasts/predictions (aka ensemble methods) will usually be beneficial.
Comment: Hi Stephan, great article. It looks the journal site has changed and it does not look possible to download your R code from the main site anymore. Are the hosting it on a different site now?
Comment: @Ian: you may not have access to it if you don't subscribe. Send me an email ([find my address here](http://forecasters.org/about/board-new/)), I'll send the scripts over. Give me a few days to dig them up.
Comment: @nalzok: I have been (and still am) traveling, but I will try to get back to you next week, OK?
Comment: @StephanKolassa Sure, thank you and enjoy yourself!
Comment: Hello Stephan, I'm having the same problem as @Ian. I have sent you an email but I'm not sure if the address is correct. Could you please send the R code and other relevant results to `email@example.com`? Thanks in advance!
Answer: Why not specify it further? I don't think that any one model you would produce could be better or good enough than a specific choice.
With that said, if you can narrow down your choices a bit to those you can test for, and the data input can be standardized, then why not write an automated testing procedure in R?
Say you decide your data will fall within a range to be estimated by five models as well as one "fallback". Say you can characterize the input by different tests. Then just go ahead and write an R (or a program like that) algorithm that runs this for you. This works if you could produce a flowchart of which model to run based on test data, that is if any point of the decision tree is binary.
If this is not an option because the decision may not be binary, I suggest you implement a rating system based on applicable tests and run some "extreme cases" simulated data through your grid to see if the results are what you are looking for.
You can combine these things obviously, for example testing for non-stationarity may be give a definitve yes-no, while other attributes may fall into a range such as multicollinearity.
You can draw this out on paper first, then build it, simulate it with known distributions you expect to have.
Then just run the R program everytime new data arrives.
I see no need to combine several models with the computational capabilities you most likely have at hand.
Comment: Narrowing the choices down is a good idea, like not using non-seasonal methods if the data are obviously seasonal. But even then, I would argue that averaging multiple seasonal models (additive vs. multiplicative seasonality, with or without trend etc.) will *on average* improve forecast accuracy. At least that is the impression I get from quite a bit of exposure to the forecasting community as well as to the M3 and similar forecasting competitions.
Comment: Do you have additional papers on this? I mean this would be a straight-forward yet relevant research subject. Very interesting idea, though just intuitively I don't agree that it necessarily would be better than a dynamic grid of models.
Comment: Good point. I edited my answer to include an additional paragraph with more literature pointers. I agree that this is straightforward and relevant, and it is still poorly understood why forecast averaging usually improves accuracy.
Comment: Yeah I mean you could model all sorts of distributional problems and attack it computationally and fundamentally. Thanks for the papers, very interesting.
Answer: There is a nice and simple formulae for combining two forecasting methods, you just weight them multipling the first by a and the other by (1 - a), where a is found by minimizing the variance of this combined forecast. As you know the errors of both forecasting methods, you can calculate the errors of the combination wich will depend on "a".
The calculation is simple when the mean of each method is = 0. For combining more than 2 methods the formulae is still "simple" in the sense that you can calculate it analytically "by hand", or also use the Solver option from EXCEL
Comment: Can you give reference to this method.

Ensemble time series model


How to fetch HTML created via a Forena report and store it as a node?

Question: I'd like to automatically (Rules) copy some HTML into a node . The HTML comes from a Forena report (already as an HTML document), created by the Forena module. In the Rules module I couldn't find anything exactly fitting.
It might be possible to develop a small module that fetches the Forena report (using some of the available Forena hooks) and create a node from it.
But is this the easiest way to go? It feels a bit like a detour, maybe I'm just overlooking some module or feature which can do that task?
Answer: You can have a look to the module "Feeds". It's aim is to provide a way to import content (node, term...) from CSV File, XML...
You can also specify interval between two importation. So you won't need rules.
Comment: Awesome! Thank you very much - that did exactly what I was aiming to do.
Answer: From the Forena project page: use Feeds to create nodes using Forena data blocks and/or reports. In other words: Forena can be used as a feeds importer (= to enable Feeds to go read from al kinds of database tables, external databases, etc. which Feeds out-of-the-box does not support). And Forena comes with various hooks to use Forena from within another module.
For more details about Forena, 2 types of documentation are available:

Community documentation, which includes a child page Video demos and tutorials containing a link also about using Forena to import data and reports based on data as drupal nodes (that video even demonstrates the creation of charts, so not just tabular reports).
Documentation that comes with Forena, which you can access right after install and enable of the module. Checkout the demo site for an online example of the current:

Forena documentation - use the link 'Reporting documentation' or visit relative link /reports/help.
Forena samples - use the link 'Reporting samples' or visit relative link /reports/samples (these samples are fully functional, so make sure to experiment a bit with it, such as the drill downs available on the SVG Graph sample).

The 7.x-4.x version also includes an amazing (I think) UI for either creating your reports (the WYSIWYG report editor) and/or for creating your SQL queries (the Query Builder).
Here are some variations of the external databases part mentioned above:

Using a SQLite instead of MySQL database: the Forena samples actually get shipped including a (Tiny) SQLite database. Go check it out in the demo site: the data shown there are data contained in the sampledb, which is in SQLite format.
Forena comes with a full suite of Supported database connections ... such as MySQL, MS SQL, Oracle, Postgress or any PDO compliant variation.

Disclosure: I'm a co-maintainer of Forena.


How to center text above a bar in Lilypond

Question: In my (MuseScore) sheets have a lot of custom bar number indicators, like this:

which help me quickly glance over the length of the sections. The bar count can also be above a bar containing notes:

Unfortunately, I'm having a hard time figuring out how to do this in Lilypond. I'm pretty sure this is possible but figuring out how-exactly is a bit of a pain.
When an empty-chord mark is used in a bar with notes, then the markup is displayed above the next note and not in the middle. So, as a workaround I could just use that but this is more of a challenge to understand how to use Lilypond to get what is needed.
Currently I'm trying to achieve this with Text Spanners, as I would like the number in parentheses to be centered above a bar.
All the examples override the text at the left and right edges of a spanner. I've also seen the span-type and span-text in some functions but am not sure how to use them.
I've also seen \textSpannerUp commands but have no idea how they are to be used.
Edit: The automatic bar numbers are positioned correctly when \set Score.centerBarNumbers = ##t is used. Meaning it is certainly doable.

The code is here but I don't know Scheme that well. :(
Answer: Quick and dirty way to do it:
markAtCenterAboveMeasure =
#(define-music-function (m music)
   (markup? ly:music?)
   #{
     \once\override
     Staff.MeasureCounter.text = #m
     <>\startMeasureCount
     #music
     <>\stopMeasureCount
   #})

\new DrumStaff \with {
  \consists Measure_counter_engraver
}{
  s1*7
  \markAtCenterAboveMeasure \markup\dynamic"(8)" s1
}

Comment: Quick and dirty does it! Edit: Any specific reason to use `\dynamic`? It seems to work just the same without both `\markup` and `\dynamic`.
Comment: Works well for blank bars but not when there are notes: https://imgur.com/a/9mcvKNE. It's fixed by having the notes afterwards in {}.
Comment: @AlenSiljak The choice for `\dynamic` was simply to mimic what your MuseScore example used. There is no real additional reason. About your second point: Yes, as with any music function you need to wrap multiple music events in a simultaneous music event. I thought this was obvious.
Answer: Since you are indicating bar numbers, perhaps it makes sense to try something like a modification of Measure-centered bar numbers, however this won't work for LilyPond versions earlier than v2.23.
Answer: Empty-Chord Marks
A simple solution for the blank bars can be the empty chord mark:
s1 <>^\markup {(2)} or simply s1 <>^"(4)".
This is not centered above the bar, unfortunately.
The good thing with a markup is that it can be customized in detail and extracted into a function which can be included in multiple score sheets.
Text Spanners
Using spanners, I've managed to do
    \override TextSpanner.text = "blah"
    \override TextSpanner.stencil = #ly:text-interface::print
    \override TextSpanner.font-shape = #'upright
    \override TextSpanner.side-axis = 0
    \override TextSpanner.direction = #'CENTER

    bd4 \startTextSpan sn bd sn \stopTextSpan

which produces

but is not centered, although it does span the whole bar.


Azure publish issues - Busy - Restarting - Busy - Cycling

Question: Azure is giving me a headache.
I started off with a tutorial. Created a new MVC 3 project published it. Took about 9 mins then it was working fine on my production VM.
Then I tried to publish a project I've been working on (MVC 3). It has the following dependencies:
Service.dll
Domain.dll
Autofac.dll
It works fine when I debug using the emulator.
It works fine when I unzip the package and deploy it to another server.
But when I publish to Azure Production I get the following:
1:42:31 PM - Preparing deployment for Website with Subscription ID: ...
1:42:31 PM - Connecting...
1:42:35 PM - Verifying storage account '...'...
1:42:38 PM - Uploading Package...
1:44:46 PM - Creating...
1:45:56 PM - Created Deployment ID: ....
1:45:56 PM - Starting...
1:46:34 PM - Initializing...
1:46:34 PM - Instance 0 of role Website is in an unknown state
1:46:34 PM - Instance 1 of role Website is in an unknown state
1:47:06 PM - Instance 0 of role Website is creating the virtual machine
1:47:06 PM - Instance 1 of role Website is creating the virtual machine
1:47:37 PM - Instance 0 of role Website is starting the virtual machine
1:47:37 PM - Instance 1 of role Website is starting the virtual machine
1:50:13 PM - Instance 0 of role Website is in an unknown state
1:50:13 PM - Instance 1 of role Website is in an unknown state
1:50:44 PM - Instance 0 of role Website is busy
1:50:44 PM - Instance 1 of role Website is busy
1:54:31 PM - Instance 1 of role Website is restarting
1:55:02 PM - Instance 1 of role Website is busy
1:56:40 PM - Instance 1 of role Website is cycling
1:57:43 PM - Instance 0 of role Website is cycling
I've tried number of times. With no success.
Update
I forgot to mention that I have the facebook C# sdk DLLs
I've used trial and error to find that the Facebook.Web.Mvc dll is causing me issues.
It has been included inside the bin folder but still no good.
Answer: The Azure environment doesn't have all the MVC 3 assemblies.  You need to make sure you reference them all in your project and set CopyLocal = true so that the assemblies get included in your Azure package.  Azure will go through this infinite cycle if it can't find all the dependencies for your project.
The assemblies you need to reference are:

Microsoft.Web.Infrastructure
System.Web.Helpers
System.Web.MVC
System.Web.Razor
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor

One blog I saw also mentioned needing WebMatrix.Data, but I found I did not need this one in my  project.
If you have any other assemblies you are referencing that are not part of the .NET Framework, you will also need set CopyLocal = true on those as well.
Also, make sure your Azure storage setting is NOT set to "Use development storage" when you deploy to Azure -- this will cause the same problem.
If the above doesn't solve the problem, check this site for some other possible causes.
Answer: As Brian Rogers notes the requirement for asp.net MVC assemblies and points to a good resource for reasons of role being cycling. One Additional thing can help with MVC specifically. You can right click on your Web Application Proejct and select "Add Deployable Dependcies" then select ASP.NET MVC3. This will make sure all MVC3 required assemblies are with your project when depeployed.
Comment: Note: When you select the first option "ASP.NET MVC", you don't need to select the 2nd option "ASP.NET Web Pages with Razor syntax".
Comment: Why is the second option even there then??
Comment: You might have normal ASP.NET Web Pages with Razor syntax, instead of ASPX syntax.
Comment: FYI: "Add Deployable Dependcies" was removed from Visual Studio 2012, since it is not needed anymore. http://connect.microsoft.com/VisualStudio/feedback/details/735553/add-deployable-dependencies-missing-from-vs11-beta
Comment: Miguel, when adding comments, please pay attention to the dates of questions and answers. This question has been asked in `January 2012`, and VS 2012 was RTM in `August 2012`. So your comment coming more than an year later is just irrelevant.
Comment: Actually, I really appreciate that comment. I was already starting to look for "Add Deployable Dependencies" in VS 2013 :)
Answer: Set the reference attribute "copy local" to "true" for each of the references used in the project. This worked for me.
Answer: I ran into a similar issue after updating my project to use Azure .NET SDK version 2.0.
The update procedure changed the configuration files but did not update the versions referenced by the projects. I solved this by manually removing the references to the old 1.8.* versions of the DLLs and then adding references to the 2.0. versions.
Answer: Please verify any third party dlls which were build for only 32 bit or 64 bit in your solution..these kind of dlls caused to the role cycling and busy..


absolute convergence of $\sum _{n=1}^{\infty} a_n$ imply?

Question: Question is :
If $\sum _{n=1}^{\infty} a_n$ is absolutely convergent  then which of the following is not true?

$\sum_{m=n}^{\infty}a_m\rightarrow 0$ as $n\rightarrow \infty$
$\sum_{n=1}^{\infty}a_n\sin n$ is convergent.
$\sum_{n=1}^{\infty}e^{a_n}$ is divergent.
$\sum_{n=1}^{\infty}a_n^2$ is divergent.

First thing I would like to concentrate on is third option (as it is easy :P)....
absolutely convergence of $\sum _{n=1}^{\infty} a_n$ imply $a_n\rightarrow 0$ i.e., $e^{a_n}\rightarrow 1$ i.e.,$\sum_{n=1}^{\infty}e^{a_n}$ is divergent.
I guess second option is most probably true..
It is for sure absolute convergence as $|a_n\sin n|\leq |a_n|$ for all $n$....  I could not give concrete argument for convergence.
I guess fourth option is false...
absolutely convergence of $\sum _{n=1}^{\infty} a_n$ imply $a_n\rightarrow 0$ i.e., after certain stage $|a_n|<1$ i.e., $|a_n^2|<|a_n|$ So, we would have convergence of $\sum_{n=1}^{\infty}a_n^2$.
I do not understand what is actual point of first option...
Could some one confirm if this justification for second/third/fourth options is sufficient and help me to understand what first option is...
Thank you.
Comment: 2. Actually, you have $|a_n \sin n|\leq|a_n|$ hence $\sum a_n\sin n$ converges absolutely by comparison. 1. Note that $\sum_{m=n}^\infty a_m=\sum_{m=1}^\infty a_m- \sum_{m=1}^{n-1}a_m$.
Comment: @julien : I have already done for absolute convergence of second option.... I was looking for just convergence.... Fourth optionn I was thinking of what you have written but that was not taking me to anywhere...
Comment: 2. You missed the absolute value. And absolute convergence implies convergence. 1. So the series $\sum_{m=1}^\infty a_m$ converges. What does this mean?
Comment: Oh yes... That was actually a typo.. :D.. absolute convergence implies convergence... Yes.. I have missed that point... I was sure that convergence need not imply absolute convergence and i was thinking absolute convergence also does not imply convergence...Face palm!
Comment: Ah! Absolute cv does imply cv. By the Cauchy criterion.
Comment: Fine fine... But I could not think of anything about first option.... How can you say that the series $\sum_{m=1}^{\infty}a_m$  converges....
Comment: Suppose we have absolute convergence, and we are trying to look for convergence i.e., we need to have an $N\in \mathbb{N}$ such that $|a_n+a_{n+1}+a_{n+2}+\dots+a_{n+m}|<\epsilon$ for all $n>N$ and for all $p$ but then,  $|a_n+a_{n+1}+a_{n+2}+\dots+a_{n+m}|\leq |a_n|+|a_{n+1}|+\dots+a_{n+p}$ but this is always less than $\epsilon$ as the series is absolutely convergent.... so, absolute convergenc implies convergence..
Comment: Oh yes... Sorry for troubling you... I got it... $\sum_{m=1}^{\infty}a_m$ converges
Comment: The first one was answered here (and probably in some other places on this site): http://math.stackexchange.com/questions/616383/if-sum-a-k-is-convergent-is-limit-of-a-k-0
Comment: This question is related to the fourth bullet: http://math.stackexchange.com/questions/255614/prove-that-sum-n-1-infty-a-n2-is-convergent-if-sum-n-1-infty-a
Comment: @MartinSleziak Thank you for your link... That was useful.. :)
Comment: @PraphullaKoushik I found it going through the list of related questions (on the right).
Answer: $\newcommand{\ra}{\operatorname{\rightarrow}}$
I assume that the terms of your series are real numbers.
1) First notice that the absolute convergence implies that each "infinite tail" $\sum_{n=N}^{\infty} a_n$ is convergent.The condition $\sum_{m=N}^{\infty} a_m \rightarrow 0$ as $N \rightarrow \infty$ is precisely the assertion that the sequence of partial sums $\sum_{k=1}^n a_k $is a Cauchy sequence.  Since $\mathbb{R}$ is complete, this is equivalent to the convergence of the series.  Since absolutely convergent series are convergent, this does follow from absolute convergence.
Here the absolute convergence was used only to see that $\sum_{m=N}^{\infty} a_m$ is a real number.  If we interpreted the statement as $\sup_{k \geq N} |\sum_{n=N}^{N+k} a_n| \ra 0$ as $N \ra \infty$, then we do not need absolute convergence to deduce this.
2) The inequality $|a_n \sin n| \leq |a_n|$ shows that $\sum_n |a_n \sin n| \leq \sum_n |a_n| < \infty$, so the series $\sum_n a_n \sin n$ is absolutely convergence and thus convergent.
Simple convergence of the $a_n$'s is not enough.  E.g. one could take $a_n = \frac{\sin n}{n}$.  It is delicate to show that this series is convergent -- one needs something like Dirichlet's Test -- but it does converge.  Then $\sum_n a_n \sin n =
\sum_n \frac{ \sin^2 n}{n}$, and this is divergent because e.g. $|\sin n| \geq \frac{1}{2}$ for at least $\frac{1}{3}$ of the $n$'s between $1$ and $N$.
3) What you say is correct.  Notice that you used much less than absolute convergence of the series but only that $a_n \ra 0$.
4) As you say, absolute convergence implies $a_n \ra 0$, hence $a_n^2 \leq |a_n|$ for sufficiently large $n$, hence by comparison $\sum_n a_n^2$ is convergent.
Simple convergence of the $a_n$'s is not enough: take $a_n = \frac{(-1)^n}{n^{\frac{1}{2}}}$.
Comment: I am very happy that this has question got your view... I would say i am a big fan of you... :D keeping that aside...I am very happy with your answer and i like "Simple convergence of the $a_n$'s is not enough" part... Though i did not understand immediately how did you got that example  of simple convergence is not enough, I would like to work on that...Thank you so much for sparing your time...
Answer: The last one is not true since for large $n$, $|a_n| < 1$ so $a_n^2 < |a_n|$ for all such $n$.
The rest are true.  Any series that is convergent must have its terms go to zero.  This is true by the cauchy criterion.  Choose $\epsilon > 0$.  Pick $N$ so $m, n \ge N\implies
|s_m - s_n| < \epsilon$, where the $s_n$ are the partial sums.  Let $m = n+1$; we have $|a_{n+1}| < \epsilon$ for $n\ge N$.
Comment: I don't understand your intention... That part I have already proved....
Comment: I am familiar with what all you have written and i have already written in my question... Please help me to see how could this imply that any of the above options is true/false...


How to handle csv file with multiple delimiters in PySpark and Scala Spark?

Question: I have the following scenario to handle in PySpark.
I have csv data in the following format where delimiter is @|# and the data in name column is enclosed in double quotes. Header is also separated by same delimiter @|#
name@|#age@|#gender
"Name1"@|#34@|#Male
"Name2"@|#60@|#Female

And I need to clean the data and get a dataframe like below
+----------+-----+------------+
| Name     | Age |  Gender    |
+----------+------------------+
| Name1    | 34  |  Male      |
| Name2    | 60  |  Female    |
+----------+-----+------------+

Also, in Scala Spark how can we achieve the same?
Answer: You can read about which options you can set for reading from csv here(python doc) or here(scala doc)
For your case, you need "sep" and "header":
python:

spark.read.options({"sep":"@|#", "header":"true"}).csv("path_to_file")

or scala:

spark.read.options(Map("sep" -> "@|#", "header" -> "true")).csv("file.csv")

Comment: It's not clear from documentation. I've checked source, there is not difference between "sep" and "delimiter": `val delimiter = CSVUtils.toChar(parameters.getOrElse("sep", parameters.getOrElse("delimiter", ",")))`
Same for [spark2](https://github.com/apache/spark/blob/v2.4.8/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVOptions.scala#L86) and [spark3](https://github.com/apache/spark/blob/v3.3.1/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv/CSVOptions.scala#L100):
Comment: Isn't it "delimiter" instead of "sep" or maybe both work ?
Comment: @AmauryLeRouxDupeyron I don't see any mention of "delimiter" option in the doc
Comment: please review this [link](https://spark.apache.org/docs/latest/sql-data-sources-csv.html), although at the bottom of the page, within the list of the possible property names we only found mention of "sep", in very all code examples they use instead the "delimiter" keyword


Create Swift optionals from cast NSDictionary object

Question: I'm trying to cast an Objective-C NSDictionary's values to 2 Swift optionals.
These values may be missing from the original NSDictionary, in which case the function can safely be called with nil arguments.
Is there a better way of doing this?
@objc
track(_ data: NSDictionary) {
  // Cast NSDictionary to Swift dictionary
  guard let dataDictionary = data as? [String: Any] else {
      return
  }

  // Extract (optional) values
  let value = dataDictionary["value"]
  let name = dataDictionary["name"]

  // Cast Objective-C optionals if possible, otherwise assign nil
  let floatValue: Float? = (value as? CGFloat != nil) ? Float(value as! CGFloat) : nil
  let stringName: String? = (name as? NSString != nil) ? name as! String : nil

  // Function arguments:
  //    name: String? = nil
  //    value: Float? = nil
  Tracker.track(name: stringName, value: floatValue)
}

Comment: `let stringName: String? = name as? String` should be enough for the second one. But I guess that `let floatValue = (data["value"] as? NSNumber)?.floatValue; let nameValue = (data["name"] as? String)`. would work.
Comment: @Larme `let floatValue = (data["value"] as? NSNumber)?.floatValue; let nameValue = (data["name"] as? String)` works great. I would be happy to accept this as an answer. Hugely appreciated, thank you!
Answer: Firstly
let stringName: String? = (name as? NSString != nil) ? name as! String : nil

Can be simplified as
let stringName: String? = name as? String

But if we want to make the modification earlier, we can avoid the [String: Any] from the start:
let floatValue = (data["value"] as? NSNumber)?.floatValue
let nameValue = data["name"] as? String

If data["value"] doesn't exist, it will be nil. If it's not a NSNumber (since it's the Objective-C basic way to encapsulate Float into a Object) it will be nil. In the end, the floatValue will be nil or have the real value.
Same logic for the nameValue.


Algorithm for finding maximal "reduction" of an integer matrix

Question: Given a $m\times n$ matrix of non-negative integers. A "reduction" of this matrix can be done on one row/column of this matrix, by subtracting the minimum of the row/column from all other numbers of that row/column. For example,
$$
\begin{bmatrix}
 29 & 19 & 17 & 12 \\
    32 & 30 & 26 & 28 \\
    3  & 21 & 7  & 9  \\
    18 & 13 & 10 & 15
\end{bmatrix}
$$
can be "reduced" on the second row by subtracting 26 from all four numbers, resulting in
$$
\begin{bmatrix}
 29 & 19 & 17 & 12 \\
    6  & 4  & 0  & 2  \\
    3  & 21 & 7  & 9  \\
    18 & 13 & 10 & 15
\end{bmatrix}
$$
Such reduction can be repeatedly done on every row/column, and the result is always still a non-negative integer matrix. On the other hand, each row/column can be effectively reduced only once, because subsequent reductions end up subtracting 0 and do not change the matrix.
Hence, reduce each row and column once in any order, and the matrix is completely reduced. The question is: consider the sum of numbers in the final matrix, what is the minimum of this sum, among all possible completely reduced matrices? Further, how do we find out an ordering of reductions that achieves the minimum?

The order of reduction does affect the sum of numbers in the final matrix. For the matrix above, reducing [row 1, row 2, row 3, row 4, col 2] gives a sum of 73, while reducing [col 1, col 2, col 3, col 4, row 1, row 2] gives a sum of 81.

I am interested in an (efficient) algorithm that solves this problem (or better still, if there exists a closed form of the minimum). One can always brute-force through all $(m+n)!$ ordering of reductions and find the minimum, but that would be quite uninteresting.
Comment: Do we need a maximal reduction each time we reduce a row or column, and can we reduce by a chosen amount ? The latter is polynomial, I don't know for the former.
Comment: In fact, I think that these problems are equivalent
Answer: Lets first assume that we are allowed to reduce a row or column by a chosen amount, and not necessarily doing a full reduction.
Let $A =(a_{i,j})_{1\leq i \leq m, 1\leq j \leq n}$ be the matrix.
Let $x_i$ be the amount reduced in on the line $i$ and $y_i$ be the amount reduced in on the column $i$. We want to minimize $\sum_{i,j} a_{i,j} - x_i - y_j$, under the constraints $x, y \geq 0$, $x_i + x_j \leq a_{i,j}$. This is a linear program, so it can be solved efficiently. Moreover, the underlying matrix is totally unimodular, so we have strongly polynomial algorithm, and if $A$ is an integer matrix, we will get an integer optimal solution.
Let $G$ be the complete bipartite graph formed with $m$ vertices $X_i$ in one part and $n$ vertices $Y_i$ in the other part, and let $a_{i,j}$ be the weight of the edge $(X_i,Y_j)$. Then the problem becomes equivalent to find a vertex-weight function $x, y \geq 0$ (with $x_i$ the weight of vertex $X_i$, and $y_i$ the weight of vertex $Y_i$) such that $a_{i,j} \geq x_i + x_j$.
Shrijver[1] refers to it as the w-stable set problem.
Now, lets show that we can find on ordering of the rows and columns such that at each step, the reduction is maximal. Assume that $\forall i,j$, $a_{i,j} > x_i$, $a_{i,j} > y_j$. Then it is possible to increase any $x$ or $y$ and get a better solution. So lets choose an $a_{i,j}$ such $a_{i,j} = x_i$ (or $a_{i,j} = y_i)$, and lets reduce the corresponding row (or column). Let set $x_i = 0$, the coefficients must still form an optimal solution, so we can keep going until we reduced everything.
[1]: Schrijver, Alexander, Combinatorial optimization. Polyhedra and efficiency (3 volumes), Algorithms and Combinatorics 24. Berlin: Springer (ISBN 3-540-44389-4/hbk). xxxvii, 1881 p. (2003). ZBL1041.90001.
Comment: A few issues: (1) I understand that $x_i$ and $y_j$ refers to the amount reduced on every number in the row/column, so the target function should be $\sum_{i,j} a_{i,j}-nx_i-my_j$. The linear program part still holds, very cool. (2) I don't quite get how the bipartite form of the problem helps in solving it. Do you only refer to it because that's how the book states and solves the problem?
Comment: $x_i$ and $y_j$ are in the inner sum. If you get them out, you get $n\sum_i x_i+m\sum_j y_j$. I referred to the graph interpretation because I believed it was insightful and its nice to have a name we can refer to the problem (though it does not seems to be wildly known, maybe this problem have another name)


Running LaraDock on Mac Silicon computer (MacBook Pro 2021) with Docker Desktop gives Apache2_1 exited with code 2

Question: On a Mac Silicon computer (MacBook Pro 2021):

git clone firstname.lastname@example.com:laradock/laradock.git
cd laradock
cp .env.example .env
docker-compose build workspace
docker-compose build apache2
docker-compose up apache2 workspace ------> Apache2_1 exited with code 2

Running Docker Desktop for Apple M1 (v.4.3.0) on MacOS Monterey 12.01
Answer: Fount the solution myself. This was the solution:
Edit: /apache2/Dockerfile
*// First line, edit it like this:*
FROM --platform=linux/x86_64 webdevops/apache:ubuntu-18.04

*// At the end of the file, add this:*
RUN wget -O "/usr/local/bin/go-replace" "https://github.com/webdevops/goreplace/releases/download/1.1.2/gr-arm64-linux" \
    && chmod +x "/usr/local/bin/go-replace" \
    && "/usr/local/bin/go-replace" --version

Then do this:
docker-compose build apache2
docker-compose up apache2
Result: Apache is running fine!
Answer: If you have the latest Laradock, you should go to the directory of Apache2, you should see a file called 'Dockerfile', open that file with VS Code or any IDE.
At about line 34, there is a flag that says:
ARG APACHE_FOR_MAC_M1=false

you should change the line to true, it should look like this;
ARG APACHE_FOR_MAC_M1=true

After changing this you must run in the terminal the following commands:
docker-compose build --no-cache apache2

and
docker-compose up -d apache2

After that, it should work!


What operations are allowed when I transform a system of linear equations to another form that maintains the same solutions?

Question: For example, if I row reduce a system of linear equations to a simpler form that involves free variables and variables that depend on those free variables, how do I know these variables in this new reduced system has the same solution set as the original system?
I think the thing I'm having trouble with is understanding what operations are allowed when I transform a system of linear equations to another form that maintains the same solutions. Sometimes I'm worried that the new system has gained or lost solutions.
Answer: The action should be reversible. This means that when you do a simplification of equation (1) to equation (2), in order for the equations (1) and (2) to mean the same thing, you need (1) to imply (2) and (2) to imply (1). For a very simple example, suppose $a, b \in \mathbb{R}$ is given and you want to solve $a + x = b$ for $x \in \mathbb{R}$. You can check that $a + x = b$ and $x = b - a$ are equivalent because you can get from $a + x = b$ to $x = b - a$ by subtracting $a$ from both sides, and you can get from $x = b - a$ to $a + x = b$ by adding $a$ to both sides.
The technique of "row reduction" solves the equation $Ax = 0$ for $x$ by successively multiplying $A$ on the left by invertible matrices. This maintains the set of solutions $x$ since if $E$ is invertible, then $Ax = 0$ if and only if $EAx = 0$


Are the principal congruence subgroups of SL(2,Z) normally generated by a single element?

Question: Let $N\ge 3$, then would I be correct in saying that the principal congruence subgroup $\Gamma(N)$ (defined to be the 2x2 matrices in $SL(2,\mathbb{Z}$) congruent to the identity mod $N$) is the smallest normal subgroup of $SL(2,\mathbb{Z}$) containing the matrix $[[1,N],[0,1]]$?
Edit: I'm beginning to feel like this is false. If it's false, is there a way to describe the generators which are not parabolic (ie, conjugate to $[[1,N],[0,1]]$)?
Answer: If $X(N)$ has genus $g$, then $\pi_1(X(N))^{ab} = \mathbb Z^{2g}$, and $\pi_1(Y(N))^{ab} = \mathbb Z^{2g + s -1}$, where $s$ is the number of cusps. Since $\pi_1(Y(N)) = \Gamma(N)$ for $N\geq 3$, it must be that $\Gamma(N)^{ab} = \mathbb Z^{2g+s-1}$. In particular, $\Gamma(N)$ cannot be generated by less than $2g+s-1$ elements.
Comment: Ah of course! Thank you for your answer. I think my original titular question still stands though...