Qual banco de dados ideal para o meu cenário?

Question: Estou desenvolvendo um sistema de automação comercial (C# e Windows Forms) que poderá ser instalado em uma ou várias máquinas na mesma rede local.
Também fiz a parte mobile do sistema, onde é possível fazer os pedidos através de qualquer dispositivo que contenha um browser (uma aplicação em ASP.Net que roda no IIS da máquina/servidor). Este também poderá ser acessado por N usuários. Sei que, em relação ao IIS, existe uma limitação de conexão simultânea que varia de acordo com a edição do Windows e versão do IIS.
apesar de não entender muito bem como essa limitação funciona, esta não é minha dúvida principal (seria uma limitação de requisições ao servidor?).
Estas aplicações utilizam o SQL Server 2012 Express.
Quero tornar esse sistema o mais simples possível no momento de instalação, onde qualquer usuário com o mínimo de experiência possa fazer o download e realizar a instalação ("next...next...finish") de forma autônoma.
Pesquisei sobre o SQLite, mas vi que não se comporta bem quando utilizado por outros computadores na rede.
Também vi o SQL Server Compact, mas não utilizei pelo mesmo motivo do SQLite.
O mais perto que cheguei, pelas pesquisas que fiz, foi o Firebird.
Minha principal preocupação é com a facilidade para fazer o download e realizar a instalação do sistema. O que eu queria mesmo era manter o SQL Server, mas é muito pesado (principalmente em relação ao tamanho do download) e complicado para um usuário comum realizar a instalação.
Devo ter mais alguma preocupação quanto ao funcionamento do sistema? Firebird mesmo?
Comment: @ítalo Camilo, Cada cliente(empresa que você atende) tem um servidor, onde fica o IIS e o SQL Server (2 servidores?) e as diversas máquinas clientes acessam o servidor do IIS para usar a aplicação, correto? Qual a versão do Windows instalada no servidor? e qual a configuração do servidor?Existe existe uma parte dos clientes(desktops) que acessam o banco com Windows Forms, correto?
Comment: Já pensou em utilizar o Postgres? Relativamente é bem simples a instação e o download bem pequeno(54MB), comparado a outros. além disso estamos falando de um dos melhores BD existentes no mercado.
Comment: Firebird é o que tem de mais tranquilo de instalar e se administrar que já encontrei até hoje. E se for acesso local, você pode usar o modo embedded, que dispensa instalação de servidor.
Comment: O modo embarcado não resolve o problema dele.
Comment: Por que não @bigown?
Comment: @EMBarbosa porque ele precisa de concorrência, que não é possível neste modo. Se ele já acha que o SQLite não pode lidar bem com a concorrência disto (e eu acho até que pode, tenho experiência com isto, em geral vendem uma ideia errada), imagine um produto que oficialmente não dá para fazer nada de concorrência.
Comment: Só o fato de ter um banco de dados centralizado já adiciona alguma complexidade ao deploy, fica bem difícil o *next next finish* - alguém terá no mínimo que informar qual será o servidor. Eu ficaria com o SQL Server mesmo, que tem instalação, configuração e gerenciamento facílimo comparado a outros SGBDs; além de toda robustez que você vai precisar.
Comment: @bigown mas ele não disse que está tendo dificuldade de concorrência, apenas que quer algo mais simples de ser instalado. De qualquer forma, a versão mais recente do Firebird permite sim acesso concorrente do BD, desde que feito na mesma máquina. http://stackoverflow.com/a/32903077/460775
Comment: @EMBarbosa Está implícito. Ele disse que o SQLite é problemático. Se for para usar sem concorrência, ele é a melhor solução que existe pronta. O FB embarcado tem pouca ou nenhuma utilidade como banco de dados,ele serve só como arquivador.
Comment: @bigown agora você já está trollando... deixa pra lá...
Answer: Há ainda a possibilidade do SQL Server Express LocalDb, que é praticamente seu SQL Server, mas baseado em um único arquivo MDF. O impacto sobre seu sistema será muito pequeno.
Outra coisa que você poderia fazer é oferecer seu sistema na nuvem. Não sei se você já pensou na possibilidade, mas poupa o cliente de fazer ele mesmo a instalação. Azure é uma opção.
Answer: O Firebird que não precisa instalar não é nada adequado para o que deseja, é absurdamente mais limitado que o SQLite. A versão que funciona bem (ainda que pouco escalável até a versão que eu conheço) tem que instalar, cairia no mesmo problema de instalar o SQL Server Express.
É possível usar o SQL Server LocalDB, mas ele não é adequado para vários cenários. Ele continua pesado para baixar e rodar, só não precisa de um processo de instalação complicado. Você precisaria analisar se é adequado pro seu cenário.
O SQLite é bem adequado para muitos casos, mesmo em rede, adotando um esquema de cliente-servidor, desde que o programador saiba o que está fazendo. Em geral ele acaba não sendo recomendado porque o programador, em geral, não sabe o que está fazendo. Ele é bem mais escalável do que as pessoas imaginam, e pode se comportar até melhor que o SQL Server Express em alguns cenários.
Outras soluções são menos adequadas ainda para o que está pensando. Ou invista o que for necessário para rodar o SQLite, ou aceite que terá que usar o SQL Server mesmo (partindo do princípio que não deseja fazer mudanças profundas no sistema), optando pelo Express ou LocalDB dependendo do seu caso.
Comment: Tenho que discordar, em especial da parte "Outras soluções são menos adequadas ainda para o que está pensando". Você não tem como analisar todas as outras soluções para saber que todas elas são menos adequadas.
Comment: Tecnicamente é verdade. Mas buscar soluções fora do padrão para alguém que procura algo simples é por si só uma impedimento, não estou só analisando o lado técnico, mas a condição apresentada na pergunta me deixa inferir que ele não vai querer soluções que criam mais complicadores. Só o fato de usar algo fora do padrão é um enorme complicador. O próprio uso do SQLite talvez seja um complicador e deixo isto claro na resposta. Falei dele porque estava na pergunta. Fiz uma análise do que está na pergunta. Se tem coisas fora da pergunta que dificultam ou facilitam a escolha, eu não posso dizer.
Comment: Por outro lado ninguém pode afirmar que qualquer solução é adequada para ele. Então olhando por esse ângulo, todas as respostas estarão erradas. Eu dei a melhor resposta possível, nem fechando demais o leque, nem deixando aberto demais.
Comment: Verdade. Por isso perguntas deste tipo nem são mais aceitas no SOen. São muito baseadas em opiniões ao invés de em dados realísticos. De qualquer maneira, só quis deixar registrado que discordo porque não temos informações suficientes.


How to check if request body is empty?

Question: I tried to do it like that
        if ($request_uri ~ ^/page/submit$ ) {
         set $test  A;
        }
        if ($request_body = '') {
         set $test  B;
        }
        if ($test = AB) {
          return 403;
        }

But I get 200 in answer for request curl --request POST http://example.com/page/submit
Comment: Why would you need to do this in your web server configuration, as opposed to in your web application's code?
Comment: Because I don't want even bootstrap my web application.
Comment: `$test` variable is not set to `AB` anywhere in your code, so that condition is always false.
Comment: @Dmitro, do you really have that much empty post requests, that you need to protect your backend from them? I doubt.
Answer: Try this, you have to append your tests so that you can test for "AB". But then, do you really need it in the server configuration?
set $test    "";
if ($uri ~* "^/page/submit$") {
    set $test    "A";
}

if ($request_body = '') {
    set $test    "${test}B";
}

if ($test = "AB") {
    return       403;
}

Comment: I have something like ddos

How to check if request body is empty?


Primal/Dual Proof.

Question: I have a test tomorrow in one of my classes and I am trying to solve a proof in the practice problems. I am unsure how to start or what methods to use.
Consider the primal/dual pair of LP's
(P):
max cx
Ax=b
x>=0

(D):
min yb
yA>=c
y is free

Suppose that (P) and (D) have primal/dual solutions x* and y* with objective value z*. Show that for any vector t, if we change the constraints in the (P) to (P'):
max cx
Ax=b+t
x>=0

then (P') is either infeasible or has an optimal solution x' with objective value z'<=z*+y*t.
Answer: If (P') is infeasible, then we have nothing to do.
Let $\mathbf{x'}$ be any feasible solution to the perturbed primal (P'), and $z=\mathbf{c}^T\mathbf{x'}$ be corresponding objective value.  (For consistency of the notations, we denote $\mathbf{x'^{*}}$ and $z'^*$ the optimal solution and objective value for (P') respectively.)
Consider $\mathbf{y^*}^TA\mathbf{x'}$.

$\mathbf{y^*}^TA\mathbf{x'} \ge \mathbf{c}^T\mathbf{x'}=z'$ since we have $A^T\mathbf{y^*} \ge \mathbf{c}$ (from which we take transpose: $\mathbf{y^*}^T A \ge \mathbf{c}^T$) and $\mathbf{x'} \ge 0$ from (P').
$\mathbf{y^*}^TA\mathbf{x'} = z^* + \mathbf{y^*}^T\mathbf{t}$

$A\mathbf{x'}=\mathbf{b}+\mathbf{t}$ from (P').
Multiply $\mathbf{y^*}^T$ on both sides of the above equation.
\begin{align}
\mathbf{y^*}^T A\mathbf{x'} = \mathbf{y^*}^T (\mathbf{b}+\mathbf{t})
\end{align}
$z^*=\mathbf{y^*}^T\mathbf{b}$ as $\mathbf{y^*}$ is the optimal solution of (D).
The RHS of the desired inequality appears.
\begin{align}
\mathbf{y^*}^T A\mathbf{x'} = z^* + \mathbf{y^*}^T \mathbf{t}
\end{align}

For any feasible solution $\mathbf{x'}$ to (P'), we have
$$z' \le \mathbf{y^*}^T A\mathbf{x'} = z^* + \mathbf{y^*}^T \mathbf{t}.$$
It remains to show the existence of an optimal solution.  We observe that (P') is bounded from the inequality we have just proved.  Therefore, (P') has an optimal solution $\mathbf{x'^*}$.

Primal/Dual Proof.


68% Confidence level in multinormal distributions

Question: I wanted to create some contour plot to give confidence level say at 68% and 95% of some 2-dim multivariate normal distribution. (later I will have to go to 3-dim). I was wondering whether there was some nice prescription in here like in the normal distribution that is given by 1sigma deviation, 2sigma deviation, etc. or shall I do numerical integration or similar ... I am a bit lost right now
Comment: For an example of how to do this in Excel, see http://www.real-statistics.com/multivariate-statistics/multivariate-normal-distribution/confidence-ellipse/
Answer: A $1-\alpha$ region ("interval") for a bivariate normal $N_2(\mu,\Sigma)$ is those $\mathbf x$ for which
$$({\mathbf x}-{\mu})^\top{\Sigma}^{-1}({\mathbf x}-{\mu}) \leq \chi^2_{2,{1-\alpha}}$$
where $\chi^2_{2,{1-\alpha}}$ is the $1-\alpha$ quantile of the $\chi^2_2$.
More generally, a $1-\alpha$ region for a $p$-variate normal is those $\mathbf x$ for which
$$({\mathbf x}-{\mu})^\top{\Sigma}^{-1}({\mathbf x}-{\mu}) \leq \chi^2_{p,{1-\alpha}}$$
---
Edit:
@MånsT is quite right to bring up the possibility that you may have been estimating parameters; if that's the case, then indeed things change as indicated in his comment.
Comment: +1 And if $\mathbf{\Sigma}$ is unknown but estimated by the sample covariance matrix $\mathbf{S}$, the region is given by a quantile of the F distribution: $\frac{n(n-p)}{p(n-1)}(\mathbf{\bar{x}}-\mathbf{\mu})^T \mathbf{S}^{-1} (\mathbf{\bar{x}}-\mathbf{\mu})\leq F_{p,n-p,1-\alpha}$.
Comment: Then, the quantile determines for any multivariate normal distribution the probability to expect some event in that region?
I mean, for a normal distribution, $\chi^2 = 1$ gives $1-\alpha = 68.27\%$. Does the same holds for any p-variate normal distribution? Maybe I didin get the idea ..
Comment: The quantile determines an ellipse which contains $1-\alpha$ of the probability in the bivariate case. In the trivariate case it generates an ellispoidal surface that contains $1-\alpha$ of the probability. That is a random observation from a $N(\mu,\Sigma)$ will lie inside those bounds with probability $1-\alpha$.
Comment: Ok, then what I have to do is to look for this $\chi^2$ value determining this quantile for some given p-value either in a table or some computer program where $\chi^2$ distribution is implemented if I understood propperly, sin't it?
Comment: Yes. For example, to enclose 95% of a bivariate normal with mean $(1,2)^\top$ and variance $\Sigma = \bigl(\begin{smallmatrix}
1&0\\ 0&\frac{1}{2}
\end{smallmatrix} \bigr)$, you find the values of $\bf{x}$ where $(x_1-1,x_2-2)\bigl(\begin{smallmatrix}
1&0\\ 0&2\end{smallmatrix} \bigr)(x_1-1,x_2-2)^\top \leq 5.99$, which is where $(x_1-1)^2 + 2(x_2-2)^2 \leq 5.99$, an ellipse in $(x_1,x_2)$ space.
Comment: Sorry, I see I started to respond to your first comment before your final edit of it; the 68% at 1 s.d. away from the mean only applies to a univariate normal.
Comment: @Glen_b Ok thanks, that's exactly what I wanted. Now it's perfectly clear for me how to find such a countour line. Thanks a lot! (Sorry for the delay, I was having lunch...)

So to sum up, in order to look for CL at some percentage (%) you just look for your $\chi^2$ value which gives you back the desired quantile as defined above. Perfect!


Get taxonomy terms value in views

Question: I have two content types

Program
Registration

and one taxonomy

Program type

Program content type having term reference with program type taxonomy
and registration having node reference with a program.
I am using views to list out all registrations.
How can I get the program type terms value in registration content type list?
Comment: Might I suggest an alternative approach using entity reference instead of term reference and node reference? That is if you can delete these fields and use the new one's to refer those entities.
Comment: Ok I changed it to entity reference but how to get the terms value?
Answer: Considering entity reference fields in the following manner:

Program having an entity reference field pointing to the terms of program type vocabulary.
Registration having an entity reference field pointing to nodes of type Program.

To achieve what you want:

Create a view of content. Of type "Registration". Add required fields from registration content type
Add a relationship of type "Entity reference: referring entity" with field from #2 above.
This will enable you to add attributes/fields from the "Program" content type.
Add a relationship of "Entity reference: referring entity" with the field from #1 above (pointing to terms). Important: Use the earlier relationship in this new relationship (i.e. nested relationship).
This will let you add attributes/fields from the taxonomy terms.

Get taxonomy terms value in views


Learning Algorithm and Saving Data in Software

Question: I'm coming from a web-development background and I am wondering how I would make a learning algorithm in Java/C++. Not so much the algorithm part, but making the program "remember" what it learned from the previous day. I would think something like saving a file, but I suspect their might be an easier way. Apologies if this question is just over the top stupid. Thanks.
Answer: I think that would depend a bit on the problem domain. You might want to store learned "facts" or "relationships" in a DB so that they can be easily searched. If you are training a neural network, then you'd probably just dump the network state to a file. In general, I think once you have a mechanism that does the learning, the appropriate storage representation will be relatively apparent.
Maybe if you can flesh out your plan on what kind of learning you'd like to implement, people can provide more guidance on what the implementation should look like, including the state storage.
Comment: You're answer was vastly more insightful then mine. +1
Answer: Not stupid, but a little ill-formed maybe.
What you're going to do as your program "learns" something is update the state of some data structure.  If you want to retain that state, you need to persist the data structure to some external store.  That means translating the data structure to some external formal that you can read back in without loss.
Java provides a straightforward way to do this via the Serializable interface; you Serialize the data by sending Serializable ojects out through an ObjectStream; the same ObjectStream will reload them later.
Answer: If you want to access and save large amounts of data maybe a database would work well.  This would allow you to structure the data and look it up in an easier manner.   I'm not too well versed on the subject but I think for remembering and recalling things a database would be vastly superior to a file system.
Answer: A robust/flexible solution in Java (C++ too, but I wouldn't know how) would be using a database.  Java 1.6 comes with the Apache derby database which can be embedded in your apps.  Using JPA (Java Persistence API) makes it easy to interface with any database you can find drivers for.
Answer: You should look into Neural Network software development. Here's a collection of nice Neural Network libraries for different languages. I am not sure if this is the easy way but once accomplished would be very handy.


Issue with high server load centos

Question: I'm having some major issues with one of my servers.
Server load is extremely high: load average: 142.28, 144.80, 139.6
The server is running Centos 6 and has a Perl image sharing script running on it. The server has moderate traffic but for some reason the load is extremely high.
Running iotop I see just a bunch of httpd requests but there's no iowait or problems with disc R/W.
Running the top command there's lots of CGI Zombie processes that are all "Defunct". I'm not sure how to handle them because I've set keepalive to off to prevent something like this from occurring.
I need some advise. I've looked at many questions on here and I'm not sure what to do. I've installed CSF and configured it to block possible DDOS attacks. I've also installed mod_evasive.
The server's obviously super sluggish. Any advise would be appreciated.
Edited
Running netstat -an | wc -l shows 13132 connections.
Comment: If a parent isn't reaping its children, you can get rid of the zombies by killing that parent. If the parent is PID 1, you'll have to reboot.
Answer: Apply Scientific Method

Install monitoring.
Gather data.
Analyze data.
Make decisions.
Make changes.
Monitor changes.

Issue with high server load centos


How to handle independent variable in regression where no relationship exists between samples

Question: I would like to use a multinomial logistic regression to get win probabilities for each of the 5 horses that participate in any given race using each horses previous average speed.
RACE_ID    H1_SPEED     H2_SPEED    H3_SPEED    H4_SPEED    H5_SPEED    WINNING_HORSE
1          40.482081    44.199627   42.034929   39.004813   43.830139   5
2          39.482081    42.199627   41.034929   41.004813   40.830139   4

I am stuck on how to handle the independent variables for each horse given that any of the 5 horses average speed can be placed in any of H1_SPEED through H5_SPEED.
Given the fact that for each race I can put any of the 5 horses under H1_SPEED meaning there is no real relationship between H1_SPEED from RACE_ID 1 and H1_SPEED from RACE_ID 2 other than the arbitrary position I selected.
Would there be any difference if the dataset looked like this -

For RACE_ID 1 I swapped H3_SPEED and H5_SPEED and changed WINNING_HORSE from 5 to 3
For RACE_ID 2 I swapped H4_SPEED and H1_SPEED and changed WINNING_HORSE from 4 to 1

RACE_ID    H1_SPEED     H2_SPEED    H3_SPEED    H4_SPEED    H5_SPEED    WINNING_HORSE
1          40.482081    44.199627   43.830139   39.004813   42.034929   3
2          41.004813    42.199627   41.034929   39.482081   40.830139   1

Is this an issue, if so how should this be handled? What if I wanted to add more independent features per horse?
Comment: Is the problem that, for example in  `RACE_ID` #1, that the value for `H5_SPEED` is could be the value for any of the 5 horses and is not linked specifically to the winning horse (i.e., horse #5)?  Or is it that across races, the number for the horses change.  That is, a hypothetical horse named "Foobar" could be horse #5 in `RACE_ID` #1 and also horse #4 in `RACE_ID` #2?  Hence, the same horse is re-labeled across races.
Comment: The latter, "Foobar" could be horse #5 in `RACE_ID` #1 and another hypothetical horse "Barfoo" could be horse#5 in `RACE_ID` #2. "Foobar" could also be horse #4 in `RACE_ID` #2 as you mentioned @jluchman
Comment: Another question is if "Foobar" won `RACE_ID #1` I could have put "Foobar"'s speed as `H3_SPEED` and changed `WINNING_HORSE` to `3` the numbering is arbitrary
Answer: If it is not possible to link the arbitrary horse numbering by race to a literal horse through some lookup table (which it sounds like it is not), it will not be possible to get meaningful probabilities for the horse numbers as they do not refer to the same horse across races.
It sounds like, across races, there may be multiple features for each horse other than speed.  If these 5 horse numbers always refer to the same literal horses (with arbitrary labels), and there are multiple features per race, it may be worthwhile to attempt to use those all the features to match the arbitrary horse labels to across races to harmonize labels for a literal horse.
The idea would then be for each race to attempt to match the horse labels based on the values of all the features.  An approach like this would make the strong assumption that the horses have a similar profile across races in terms of the values collected on each horse in each race.  That said, it may be the only way to get the data in shape for subsequent modeling.
In effect, what I'm recommending is a kind of fuzzy matching/data linking approach (see probabilistic data linking section at the wiki here).
Regarding the second question, changing the labels should not matter given they are (currently) arbitrary. Again, the important thing to do to make the probability estimates meaningful is to harmonize the literal horse to horse number mapping across races.
Comment: Would a conditional logit be better suited for this problem (https://data.princeton.edu/wws509/notes/c6.pdf) using something like pylogit in python or mlogit in R which allows me to use features that are attributes of the choice alternatives (the horses)
Comment: "If it is not possible to link the arbitrary horse numbering by race to a literal horse through some lookup table" Also for this it is possible as I have an id for each horse, but I am unsure on how to do the linking


Save multiple plots from a file list into a single file (png or pdf or other format)

Question: I have more than 10 files (in the end some hundreds...). which I generated in R in png format saved into a folder.
My question: How could I save these files into a multiplot (e.g. 4 figures on one page arranged in 2 rows and 2 columns)?
I know that this is possible to incorporate inside a plot loop by using par(mfrow=c(2,2)) but how could I do this outside just calling the files in the folder after they are generated?
Comment: this would help but in reality I have more than 10 files (in the end some hundreds...). If I understand correctly you have to call each file seperately in this solution?
Comment: What about the second solution in the same link.?
Comment: You could use the command `\includepdf[pages=1-3]{/tmp/figure.pdf}` to select multiple figures
Comment: I couldnt get it to work, also mainly because I've got png files and this is optimized for pdf files...
Comment: i'd use another tool for this, e.g ImageMagick `montage *.png -tile 2x2 multipage.pdf`
Comment: thank you @baptiste. This could work well as well. I am looking into it now.
Answer: Here a fast method to aggregate many png files:

read your png using readPNG
convert them to a raster , and plot them using grid.raster: very efficient.

Something like this :
library(png)
library(grid)
pdf('somefile1.pdf')
lapply(ll <- list.files(patt='.*[.]png'),function(x){
  img <- as.raster(readPNG(x))
  grid.newpage()
  grid.raster(img, interpolate = FALSE)

})
dev.off()

Edit : loading png , arranging them and merge them in the same pdf :
First you should store your png files in a list of grobs using rasterGrob :
plots <- lapply(ll <- list.files(patt='.*[.]png'),function(x){
  img <- as.raster(readPNG(x))
  rasterGrob(img, interpolate = FALSE)
})

Then save them using the excellent handy function marrangeGrob :
library(ggplot2)
library(gridExtra)
ggsave("multipage.pdf", marrangeGrob(grobs=plots, nrow=2, ncol=2))

Comment: @baptiste: When I set `do.call(marrangeGrob, c(plots, list(nrow=2, ncol=2)), top=NULL)`, this won't remove the number of pages and gives me an error. How could I control the size of the font or get rid of it completely?
Comment: you want all the options in the `list()`
Comment: the pdf (or any other) device lets you set width and height to whatever you want, so if you set width>height, that's landscape. I tend to stay away from the `paper` setting, personally. You can pass all those options through ggsave.
Comment: this is great for writing all files into one pdf file. I am however struggling to incorporate something like `par(mfrow=c(2,2))` so that I get more than one graph per page...
Comment: what command controls the title (page 1 of ...), at the moment the size of the title is huge?
Comment: @baptiste: is it also possible to arrange the resulting output in landscape format? haven't found anything in the documentation.


React / Redux custom middleware - useDispatch not updating the state

Question: I would like to create some middleware to check a tokens expires_at field refreshing the token if necessary and updating the state for the token fields.
I have used the redux toolkit to create the redux functionality, making use of slices. I have a slice that will update the state with token data and this works on the callback for the initial token.
When creating the middleware I can not get the slice to be called and therefore the state remains unchanged.
As a simple spike without an api call:
import { useSelector, useDispatch } from 'react-redux';
import { setTokens } from '../features/tokens/tokenSlice';

const refresher = () => ({ dispatch, getState }) => (next) => (action) => {
    const exp_at = useSelector((state) => state.tokens.expires_at);

    if(hasBreachedThreshold(exp_at)){
        dispatch = useDispatch();
        dispatch(
            setTokens({
            access_token: 'new token',
            expires_at: 637423776000000000, -- hard coded date way in the future.
        })
    }

    ... else carry on.
);

I would expect when the middleware is called, on the first pass hasBreachedThreshold() returns true and the dispatch method would call the slice reducer and update the state. Any further runs would pass over as hasBreachedThreshold() would return false - for a while anyway.
What is happening though is that the hasBreachThreshold always returns false because the state is never updated, causing an indefinite loop.
The middleware is configured correctly and is called.
The expires_at value is extracted from the state.
hasBreachThreshold() is tested thoroughly and behaves correctly.
Being fairly new to React / Redux I expect my understanding of how and when to use dispatch is wrong. I assumed I could use dispatch similarly to how I do in my components, is this not the case? or am I going about this totally the wrong way?
Answer: When writing a middleware you have already the dispatch function and Redux store available through the function params:
// Use `dispatch` & `getState`
const refresher = () => ({ dispatch, getState }) => (next) => (action) => {
    const exp_at = getState().tokens.expires_at;

    if(hasBreachedThreshold(exp_at)){
        dispatch(
            setTokens({
            access_token: 'new token',
            expires_at: 637423776000000000, -- hard coded date way in the future.
        })
    }
);

Also you have essential mistake of when to use React hooks, refer to Rules of Hooks.
Hooks are not available in context of Redux middleware.


Implicit function theorem and PDE; do we get uniqueness?

Question: Please see this page: The implicit function theorem: A PDE example.
In the implicit function theorem they quote, uniqueness is not mentioned. But the inverse function theorem (which is equivalent to the IMFT), we do get uniqueness. So am I right that the solution got by using the theorem is unique as well?
Answer:
Their statement of the Implicit Function theorem does contain a uniqueness part: "$F(x,y)=0$ if and only if".
However, this is a local statement, only for $(x,y)\in U\times V$. It does not exclude the possibility of having other solutions outside of small neighborhood $V$.
Comment: So this gives us a local (eg. short-time for parabolic pdes) solution, am I right? Strange that none of the source I have looked at points out local uniqueness.
Comment: @hopo2 The neighborhood is taken in the function space, not in the space-time coordinates. So it's not "short-time uniqueness", it's uniqueness among the functions that are close to the particular solution.


How to split time series into minutes and assign them a value in pandas?

Question: I am totally stucked with this excersise and do not know how to proceed.
I have data in form of
ID / From / To / Value

12 / 1.1.2021 7:50 / 1.1.2021 8:20 / 50
13 / 1.1.2021 8:00 / 1.1.2021 8:03 / 100
14 / 1.1.2021 9:12 / 1.1.2021 9:30 / 12

I need to split all time series into minutes and find out the sum of values for each minute, so, I should get something like
1.1.2021 7:59 50
1.1.2021 8:00 150
1.1.2021 8:01 150
....
1.1.2021 8:03 150
1.1.2021 8:04 50
...
1.1.2021 8:21 0
...
1.1.2021 9:12 12

I have no clue how to start.
Could you please, help?
Thanks.
zuzana
Answer: I think maybe something like this using apply and pd_date_range
df_new = (df.set_index(['ID','Value'])
        .apply(lambda x: pd.date_range(x['From'], x['To'],freq='min'), axis=1)
        .explode().rename('date').reset_index().groupby('date')['Value'].sum())

date
2021-01-01 07:50:00     50
2021-01-01 07:51:00     50
2021-01-01 07:52:00     50
2021-01-01 07:53:00     50
2021-01-01 07:54:00     50
2021-01-01 07:55:00     50
2021-01-01 07:56:00     50
2021-01-01 07:57:00     50
2021-01-01 07:58:00     50
2021-01-01 07:59:00     50
2021-01-01 08:00:00    150
2021-01-01 08:01:00    150
....

Comment: then groupby `date` and sum :-).
Comment: @QuangHoang ah missed that, nice one thanks!


Can $e^\frac{1+z}{z-1}$ be uniformly approximated in the disc by harmonic continuous functions

Question: Ie: For $f(z)=e^\frac{1+z}{z-1}$ is it true: $\inf\{||f-u||: \mbox{u is harmonic in the unit disc and continuous on the closed unit disc}\}=0$. Note the infinum is taken over the interior (ie: $|z|<1$)
Comment: No, there is no inf taken over $\{|z|<1\}.$ Rather, you are taking the inf over the sup norms, where the sup is taken over $\{|z|<1\}.$
Answer: No, in fact $\sup_{|z|<1}|f(z)-u(z)|\ge 1$ for all such $u.$ Proof: Observe that as $t \to 0^+,$ $f(e^{it})$ takes on every value in the unit circle infinitely many times. Using the continuity of $f$ at all boundary points save $1,$ we see there exists sequences $z_n,w_n$ in the open disc, $z_n, w_n \to 1,$ such that $f(z_n) \to 1, f(w_n)\to -1.$ Thus $f(z_n)-u(z_n)\to 1-u(1),$ while $f(w_n)-u(w_n)\to -1-u(0).$ Now one of $1-u(1),-1-u(1)$ has modulus at least $1,$ giving the result.


Flattening multiple tables to a single type

Question: I'm trying to model a database currently using EntityFramework's Fluent Configuration. I cannot edit or otherwise control the database schema. The entity I am trying to model has a lot of look-up tables - for example, one property (it's name) has a whole table devoted to it with a name associated with an id (which is it's language). In other words, it looks a bit like this in the database:
Entity
    string[] Names

Entity_Names
    string Name
    int LanguageId // 9 = English

However, I am trying to condense this into
Entity
   string Name // I only want the English name

Using a SQL query, this would be pretty simple - but how can I do this via Entity Framework's fluent configurations? There are a lot more of these instances as well, but this is the simplest example I could come up with.
Answer: If you do manage to flatten the model this way, it's almost certainly going to be a read-only view of the data. There's no way for Entity Framework to know that a string property should be looked up in another table and replaced with an integer id.
So that leaves two options if you're okay with it being view-only. Write a database view that replaces the ids with the strings and build an entity for that view.
Or build entities that are compatible with the schema model and project the data into a dto.
The second approach is the one I'd prefer as it means you'd still have a compatible entity model if you do need to CRUD.
Comment: This is fine, as the data I am reading for is immutable. I've decided that I can use a Discriminator column for this - `Map(m=>m.Requires(x=>x.LanguageID).HasValue(9))`


Undefined Constant and Assigning the return value of new by reference Error

Question: I have a database class in which I am calling a config file using required_once. In that I have declared some constants using define(). I am getting errors of Undefined constant and also assigning the return value of new by reference. Here is the config file code:
<?php

// Database Constants
defined("DB_SERVER") ? null : define("DB_SERVER", "localhost");
defined("DB_USER")   ? null : define("DB_USER", "root");
defined("DB_PASS")   ? null : define("DB_PASS", "");
defined("DB_NAME")   ? null : define("DB_NAME", "shareysmile");

?>

and here is my database class code (Both are in same directory so that's not the problem):
<?php
require_once("config.php");

class MySQLDatabase {

    private $connection;
    public $last_query;
    private $magic_quotes_active;
    private $real_escape_string_exists;

  function __construct() {
    $this->open_connection();
        $this->magic_quotes_active = get_magic_quotes_gpc();
        $this->real_escape_string_exists = function_exists( "mysql_real_escape_string" );
  }

    public function open_connection() {
        $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
        if (!$this->connection) {
            die("Database connection failed: " . mysql_error());
        } else {
            $db_select = mysql_select_db(DB_NAME, $this->connection);
            if (!$db_select) {
                die("Database selection failed: " . mysql_error());
            }
        }
    }

    public function close_connection() {
        if(isset($this->connection)) {
            mysql_close($this->connection);
            unset($this->connection);
        }
    }

    public function query($sql) {
        $this->last_query = $sql;
        $result = mysql_query($sql, $this->connection);
        $this->confirm_query($result);
        return $result;
    }

    public function escape_value( $value ) {
        if( $this->real_escape_string_exists ) { // PHP v4.3.0 or higher
            // undo any magic quote effects so mysql_real_escape_string can do the work
            if( $this->magic_quotes_active ) { $value = stripslashes( $value ); }
            $value = mysql_real_escape_string( $value );
        } else { // before PHP v4.3.0
            // if magic quotes aren't already on then add slashes manually
            if( !$this->magic_quotes_active ) { $value = addslashes( $value ); }
            // if magic quotes are active, then the slashes already exist
        }
        return $value;
    }

    // "database-neutral" methods
  public function fetch_array($result_set) {
    return mysql_fetch_array($result_set);
  }

  public function num_rows($result_set) {
   return mysql_num_rows($result_set);
  }

  public function insert_id() {
    // get the last id inserted over the current db connection
    return mysql_insert_id($this->connection);
  }

  public function affected_rows() {
    return mysql_affected_rows($this->connection);
  }

    private function confirm_query($result) {
        if (!$result) {
        $output = "Database query failed: " . mysql_error() . "

";
        //$output .= "Last SQL query: " . $this->last_query;
        die( $output );
        }
    }

}

$database = new MySQLDatabase();

?>

I can't understand the problem, can anyone help? Here are the exact errors I get:
Deprecated: Assigning the return value of new by reference is deprecated in D:\xampp\php\PEAR\Config.php on line 80

Deprecated: Assigning the return value of new by reference is deprecated in D:\xampp\php\PEAR\Config.php on line 166

Notice: Use of undefined constant DB_SERVER - assumed 'DB_SERVER' in D:\xampp\htdocs\sharesmile\src\database.php on line 18

Notice: Use of undefined constant DB_USER - assumed 'DB_USER' in D:\xampp\htdocs\sharesmile\src\database.php on line 18

Notice: Use of undefined constant DB_PASS - assumed 'DB_PASS' in D:\xampp\htdocs\sharesmile\src\database.php on line 18

Comment: `defined("DB_SERVER") or define("DB_SERVER", "localhost");` is the cleaner.
Comment: [defined](http://php.net/defined) always returns a boolean value. It never returns NULL.
Answer: It would appear that the config.php you are including includes D:\xampp\php\PEAR\Config.php, not your config file. This is due to the PEAR directory having a higher priority than . in your include path. Use the absolute path (__DIR__ . '/config.php') to make it work reliably, or change your include path.
Comment: Awesome catch! I didn't know this one.
Comment: The moral of the story: always read your error messages in full and investigate based on them.
Comment: Another case of not trusting relative( path)s. **:D**
Comment: Awesome Thanks mate now i understand that i must use the absolute paths..!!
Answer: Simply change
require_once("config.php");

with
require_once("../includes/config.php");

in your database.php file.
I am assuming both files are in the include directory here.


Unrepeated random() query

Question: I need to display 3 random images from SQLite database horizontally. Since it's impossible to make a horizontal ListView, I made 3 ListViews next to each other inside a horizontally oriented LinearLayout:
final ListView g = (ListView)findViewById(R.id.lstText1);
final ListView h = (ListView)findViewById(R.id.lstText2);
final ListView i = (ListView)findViewById(R.id.lstText3);

g.setOnItemClickListener(this);
h.setOnItemClickListener(this);
i.setOnItemClickListener(this);
// Set the adapter to our custom adapter (below)

g.setAdapter(new MySimpleCursorAdapter(this, R.layout.toplist,
    managedQuery(Uri.withAppendedPath(Provider.CONTENT_URI,
    Database.Project.NAME), new String[] { BaseColumns._ID,
    Database.Project.C_SMALLIMAGE}, null, null, "RANDOM() LIMIT 1"),
    new String[] { Database.Project.C_SMALLIMAGE }, new int[] {R.id.image1}));

h.setAdapter(new MySimpleCursorAdapter(this, R.layout.toplist,
    managedQuery(Uri.withAppendedPath(Provider.CONTENT_URI,
    Database.Project.NAME), new String[] { BaseColumns._ID,
    Database.Project.C_SMALLIMAGE}, null, null, "RANDOM() LIMIT 1"),
    new String[] { Database.Project.C_SMALLIMAGE }, new int[] {R.id.image1}));

i.setAdapter(new MySimpleCursorAdapter(this, R.layout.toplist,
    managedQuery(Uri.withAppendedPath(Provider.CONTENT_URI,
    Database.Project.NAME), new String[] { BaseColumns._ID,
    Database.Project.C_SMALLIMAGE}, null, null, "RANDOM() LIMIT 1"),
    new String[] { Database.Project.C_SMALLIMAGE }, new int[] {R.id.image1}));

Everything works, except the random shown images should be distinct from each other. Since I use 3 different ListViews, sometimes they show the same random images. How can I solve my problem? Maybe by modifying "RANDOM() LIMIT 1"?
Answer: FSM save us ... you're still here
ListView for single item is a bad idea
just put 3 ImagesView in Layout and do something like this
final ImageView[] images = new ImageView[3];
ImageLoader loader = new ImageLoader(this);

images[0] = (ImageView)findViewById(R.id.imageView1);
images[1] = (ImageView)findViewById(R.id.imageView2);
images[2] = (ImageView)findViewById(R.id.imageView3);

int counter = 0;

    Cursor c = managedQuery(Uri.withAppendedPath(Provider.CONTENT_URI,
                    Database.Project.NAME), new String[] { BaseColumns._ID,
                    Database.Project.C_SMALLIMAGE}, null, null, "RANDOM() LIMIT 3");
  if(c!=null && c.moveToFirst()){
     do{
       String url = c.getString(1);
       images[counter].setTag(url);
       loader.DisplayImage(url, this, images[counter]);
       counter++;
     }while(c.moveToNext());
  }

Comment: or ... Build static HashMap aaa; and in loop add this code aaa.put(images[counter], c.getLong(c.getColumnIndex(BaseColumns._ID))); then you can use this hash to obtain _id in onClickListener
Comment: onClickListener has only 1 param `View v` so you can  use my first advice and get id like this `MyTag tag = (MyTag)v.getTag(); long id = (long)tag.TagInTag;` or second advice and do this like `long id = aaa.get(v);`
Comment: you told me once I better use the listview -__- anyway thanks, why are you always there following me? hehe. I wanna make the OnClickListener how should I declare the long id, OnClick only allows me View as its argument
Comment: how about the onClickListener? How to make it possible for me to call the long id? : public void onClick(View v,long id) {
  Intent listIntent = new Intent(this, DetailsActivity.class);
  listIntent.setData(Uri.withAppendedPath(Uri.withAppendedPath(
    Provider.CONTENT_URI, Database.Project.NAME), Long
    .toString(id)));
  startActivity(listIntent);
  }
Comment: ... now u need to change ImageLoader class  and not use stringUrl as a tag for ImageView but `class MyTag { public String url; public Object TagInTag; }` in loop you should store value of c.getInt(c.getColumnIndex(BaseColumns._ID)) in MyTag.TagInTag and add this (MyTag) as a Tag to imageView ... you should also add onClickListener to imageView in Listener you should take back TagInTag(where you store _id of Project) and open Details with this _id ... and, no i'll not wirte code for you anymore ;P
Comment: Looks like there's one problem, so I chose your 2nd advice it works properly! Like the 3 random images are different between each other, and clickable to the DetailsActivity..BUT, everytime I open the ListView, then I hit back, the random images aren't clickable. Do you know where's the problem?
Comment: `HashMap aaa = new HashMap();` ---> I put this as Global Variable. Here's the loop--->  `if(c!=null && c.moveToFirst()){
             do{
               String url = c.getString(1);
               images[counter].setTag(url);
               loader.DisplayImage(url, this, images[counter]);
               aaa.put(images[counter], c.getLong(c.getColumnIndex(BaseColumns._ID)));
               counter++;
             }while(c.moveToNext());
          }`
Comment: and here's the onClick method: `  @Override
            public void onClick(View v)
            {
             Intent listIntent = new Intent(MainActivity.this, DetailsActivity.class);
             long id = aaa.get(v);
             listIntent.setData(Uri.withAppendedPath(Uri.withAppendedPath(
            Provider.CONTENT_URI, Database.Project.NAME), Long
            .toString(id)));
          startActivity(listIntent);
            }`
Answer: Get the rowcount, pick your random numbers in the range 0 to rowcount-1 at the client, then use LIMIT to choose the nth row...

Unrepeated random() query


Why is this probability statement true?

Question: I'm reading the proof to a martingale central limit theorem. In the statement of the theorem, we assume that $\eta^2$ is an almost surely (a.s.) finite random variable.
In case I, they wrote, "Suppose first that $\eta^2$ is a.s. bounded, so that for some $C (>1)$, $P(\eta^2 < C) = 1$." In case II, they wrote, "If $\eta^2$ is not a.s. bounded, then given $\epsilon > 0$, choose a continuity point $C$ of $\eta^2$ such that $P(\eta^2 > C) > \epsilon$". My confusion is about case II.
How come if $\eta^2$ is not a.s. bounded, then given $\epsilon > 0$, we can choose a continuity point $C$ of $\eta^2$ such that $P(\eta^2 > C) > \epsilon$? How do we show this?
Comment: How many points can there be where $\eta^2$ is *not* continuous?
Answer: We can find $R$ such that $\mathbb P(\eta^2>R)\lt \varepsilon$ (this because the sequence of sets $(\{\eta^2>R\})_{R\in\mathbb N}$ is non-increasing and the intersection is a set of zero measure).
Hence for each $t\geqslant R$, $\mathbb P(\eta^2>t)\lt\varepsilon$. Since the cumulative distribution function of a random variable is non-increasing, it has only countably many discontinuity points. Since the interval $(R,+\infty)$ is uncountable, there exists a continuity point of the c.d.f. of $\eta^2$ in this interval.
Comment: You only need the fact that $\eta^2$ is a random variable (it would also work for a.s. bounded random variables).
Comment: Thanks for your help. Also, you caught the typo in the book; we have that $P(\eta^2 > C) < \epsilon$, not $P(\eta^2 > C) > \epsilon$. Anyway, did we ever need to use that fact that $\eta^2$ is not a.s. bounded in order to get that $P(\eta^2 > C) < \epsilon$? Or did we just need to use the fact that $\eta^2$ is a random variable?

Why is this probability statement true?


Can we call submit handler of one form into another form?

Question: Can we call submit handler of one form into another form?
I have two forms say user profile form and  choose membership plan I want to unset submit function of choose membership plan and want to show in user profile form and also both forms field must save.
like  multi-step form.
<code> function myform_form_alter(&$form, &$form_state, $form_id) {
   if($form_id === "ms_membership_list_memberships_form") {
     $form['#validate'][] = "_myform_form_submit_handler";
   }
   if($form_id === "user_profile_form") {
     $form['#validate'][] = "_myform_form2_submit_handler";
   }
 }

 function _myform_form_submit_handler($form, &$form_state) {
   $form_state['rebuild'] = TRUE;
   $form_state['redirect'] = '/user/1/edit';
 }

 function _myform_form2_submit_handler($form, &$form_state) {
   $form_state['rebuild'] = TRUE;
   $form_state['redirect'] = '/ms/checkout';
 }
</code>
Answer: You could pass the page number as argument to your hook_menu()
<code><?php
function mymodule_menu() {
    $items['abc/def/%'] = array(
      'page callback' => 'mymodule_abc_view',
      'page arguments' => array(2),
    );
    return $items;
  }
</code>
Then if it is step-one for example, get your subscription plan form, render it then submit.
In the submit function use:
<code> <?php
// Force the form to rebuild. If we do not do this, the value(s) in $form_state['storage'] will be lost
$form_state['rebuild'] = TRUE;
//Redirect to step two
$form_state['redirect'] = 'abc/def/2';
</code>
In step 2 get the user profile so that in the next submission you'll have the data from both forms in the submit function.
Comment: $form_state['redirect'] not redirecting the page in submit function
Comment: Have you passed &$form_state as reference to the submit handler?
Comment: yes i passed it to submit handler ,my problem is page is redirecting to the same page
Comment: i have added the code above where i am doing wrong
Comment: That's the point exactly, you need to call drupal_get_form() to get the user form on the second page. You could also add the page number as a value to the $form_state variable to know which page the user is currently on


$\operatorname{U}(4n) \supset \frac{\operatorname{Sp}(n) \times \operatorname{Sp}(m)}{\mathbb{Z}_2}$ for some maximum of $m$?

Question: I know that the Sp($n$) group is a real Lie group which is compact, connected, and simply connected
with $n(2n+1)$real Lie algebra generators. It can be constructed out of the intersections between
a non-compact, simply connected, simple Lie group $\operatorname{Sp}(2n;\mathbf C)$ and the unitary group $\operatorname{U}(2n)$ as
related by
$$
\operatorname{Sp}(n):=\operatorname{Sp}(2n;\mathbf C)\cap\operatorname{U}(2n)=\operatorname{Sp}(2n;\mathbf C)\cap\operatorname {SU} (2n) \tag{1}.
$$
I also know that:
$$
\operatorname{U}(2n) \supset \operatorname{SU}(2n)
\supset\operatorname{Sp}(n) \supset \operatorname{U}(n) \tag{2}.
$$

Now can we show the following:
$$
\operatorname{U}(4n) \supset
\frac{\operatorname{Sp}(n) \times \operatorname{Sp}(1)}{\mathbb{Z}_2}? \tag{Q1}.
$$
$$
\operatorname{U}(4n) \supset
\frac{\operatorname{Sp}(n) \times \operatorname{Sp}(m)}{\mathbb{Z}_2} \text{ for some $n$, and for what maximum of $m$}? \tag{Q2}.
$$

Q1 and Q2 are my questions,
for what maximum of $m$?
Lie group experts, please illuminate! Thanks!
Comment: There is a natural and fairly-easily-answerable version of this question, but there is also the sorta-strict formal version which might ask for "any possible" injection, rather than a natural one. The former question I can answer, the latter I cannot easily. Please clarify?
Comment: whatever answer is fine. many thanks
Comment: @paul garrett  there is an answer for https://math.stackexchange.com/a/3756133/79069
Answer: The answer to Q1 is yes, since there is a standard homomorphism $Sp(n)\times Sp(1)\to SO(4n)$ with kernel $\mathbb Z_2$ and $SO(4n)\subset SU(4n)\subset U(4n)$. To see thist, you view $\mathbb R^{4n}$ as quaternionic $n$-space $\mathbb H^n$ and the standard inner product on $\mathbb R^{4n}$ as the real part of the quaternionic Hermitian inner product. THen $Sp(n)$ acts on $\mathbb H^n$ by quaternionically linear Hermitian maps. On the other $Sp(1)$ acts by quaternionic scalar multiplications, which preserve the real part of the quaternioncally Hermitian form, but are not quaternionically linear maps since the quaternions are non-commutative.
As you can see, this is very specific for $Sp(1)$, so I have no idea about Q2.
Comment: thanks very much for the quick answer +1.
Answer: I claim that for $m\geq 2$, there is no embedding of $(Sp(n)\times Sp(m))/ \mathbb{Z}/2\mathbb{Z}$ into $U(4n)$.  As Andreas shows, there is such an embedding when $m=1$.
As in my answer to a previous question of yours, we will study homomorphisms $Sp(n)\times Sp(m)\rightarrow U(4n)$.  We'll find that as long as $m\leq n$, there is a non-trivial homomorphism, but that no such homomorphisms have the right kernel.
To that end, we recall that a representation of a compact Lie group always decomposes as a direct sum of irreducible representations, and that an irreducible representation of a product of Lie groups is always given as an outer tensor product of irreducible representations.  That is, given irreducible representations $V_i$ of $G_i$, the representation of $G_1\times G_2$ on $V_1\otimes V_2$ given by $(g_1,g_2)\ast v_1\otimes v_2 = g_1 v_1\otimes g_2v_2$ is irreducible, and all such irreducible representations of a product arise in this fashion.
Now, the smallest (in terms of dimension) representation of $Sp(n)$ is the usual $2n$ dimensional one obtained from the inclusion $Sp(n)\rightarrow SU(2n)$, arising from the identification of $\mathbb{H}^n$ with $\mathbb{C}^{2n}$.
Suppose we have a homomorphism $f:Sp(n)\times Sp(m)\rightarrow U(4n)$.  Thought of as a representation, it decomposes as a sum $\sum \phi_i\otimes \psi_i$ where the $\phi_i$ are representations of $Sp(n)$ and the $\psi_j$ are representations of $Sp(m)$.
If $m\geq 2$, then we claim that each factor in this sum either has $\phi_i$ trivial or $\psi_i$ trivial.  That is, they cannot both be non-trivial.  For if $\phi_i$ and $\psi_i$ are both non-trivial, then $$\dim f \geq \dim (\phi_i\otimes \psi_i) = \dim \phi_i \cdot \dim \psi_i = 2n\cdot 2m = 4nm > 4m,$$  i.e., the image of $f$ lands in $U(4nm)$ and nothing smaller.  This contradicts that fact that $f$ has image in $U(4n)$.
(If $m=1$, we get no contradiction as long as $\phi_i\otimes \psi_i$ is the tensor product of the smallest representations and $f$ has no other summands.  This representation is precisely the one Andreas found.)
So, we now know that $f$ decomposes as $\sum \phi_i\otimes 1 + \sum 1\otimes \psi_j$ where $1$ denotes the trivial $1$-dimensional representation.  And note that there are certainly examples which are trivial on individual factors, at least if $m\leq n$.  Specifically, if $\phi$ and $\psi$ are the standard representations, then $\phi\otimes 1 + 1\otimes \psi$ is one such example.  This corresponds to the block embedding of $Sp(n)\times Sp(m)$ into $U(2n)\times U(2m)\subseteq U(4n)$.  If $m$ is much smaller than $n$, there will typically be many more options for embeddings.
However, because $f$ decomposes in that nice way, it is easy to see that $\ker f = (\cap_i \ker \phi_i)\times (\cap_j \ker \psi_j)\subseteq Sp(n)\times Sp(m)$.  In particular, $\ker f$ is not the diagonal $\mathbb{Z}/2\mathbb{Z}$.  So none of these homomorphisms have the right kernel.
Comment: As a by product of this answer, the smallest $U(k)$ that $(Sp(n)\times Sp(m))/\mathbb{Z}/2\mathbb{Z}$ fits into is $U(4nm)$.  If you change the kernel to something else, I don't know the answer.
Comment: thanks very much for the nice answer +1.
Comment: I thought you meant: "I claim that for $m\geq 2$, there is no embedding of $(Sp(n)\times Sp(m))/ \mathbb{Z}/2\mathbb{Z}$ into $U(4n)$." instead of "I claim that for $m\geq 2$, there is no embedding of $(Sp(n)\times Sp(1))/ \mathbb{Z}/2\mathbb{Z}$ into $U(4n)$." I had editted.
Comment: @wonderich:  Thank you for catching that typo!


Use a stochastic representation result (feynman kac theorem) to solve boundary value problem

Question: Use a stochastic representation result (feynman kac theorem) to solve the following boundary value problem :
$\frac{\partial V}{\partial t}+\mu x\frac{\partial V}{\partial x}+\frac{1}{2}\sigma^2x^2\frac{\partial^2 V}{\partial x^2}=0$
with $V(T,x)= \log(x^2)$
By Feynman-kac the solution should be $E[\log(X_T^2)|\mathscr{F}_t)]$
where we use the Ito process:$dX_t=\mu(X_t,t)dt+\sigma(X_t,t)dW_t$
and initial $X_t=x$.
Can I take $dX_t=\mu x dt+\sigma x dW_t$ here?
Which gives $X_T=x+\mu (T-t)+\sigma(W_T-W_t)$
Answer: I guess you got a typo a the start. Anyways, use
$\mathrm{d} X_s = \mu X_s\mathrm{d}s + \sigma X_s\mathrm{d}W_s $ to get
$$\log \frac{X_T}{X_t} = \left( \mu - \frac{1}{2}\sigma^2\right)(T-t) + \sigma (W_T - W_t)$$
Then $$
V(t,x) = \mathbb{E}[2\log X_T | \mathcal{F}_t] = 2\log x + (2\mu - \sigma^2)(T-t)
$$
Comment: Where does the log come from in front of $\frac{X_T}{X_t}$
Comment: And I don't see where the $2\log x$ comes from, in my calculation it is $x(2\mu-\sigma^2)(T-t)$
Comment: Note that $$\mathrm{d}\log X_s = \frac{1}{X_s}\mathrm{d} X_s + \frac{1}{2}\left( -\frac{1}{X_s^2}\right)\mathrm{d}[X]_s  = \frac{1}{X_s} (\mu X_s \mathrm{d}s + \sigma X_s \mathrm{d}W_s)  + \frac{1}{2}\left( -\frac{1}{X_s^2}\right)(\sigma^2 X_s^2 \mathrm{d}s) = \left( \mu - \frac{1}{2} \sigma^2\right) \mathrm{d}s + \sigma \mathrm{d}W_s$$
Comment: And the $2 \log x$? Why isn't it $x(2\mu-\sigma^2)(T-t)$?
Comment: Should the $X_t$ be there, at $X_T/X_t$? or shouldn't it be $ \log X_T= \log X_t +\left( \mu - \frac{1}{2}\sigma^2\right)(T-t) + \sigma (W_T - W_t)$
Comment: It is the same of course, I see it now


How big is infinity?

Question: This might be more philosophy than math, but it's been bothering me for a while.

Question: If there's an infinite amount of real numbers between $ 0 $ and $ 1 $, shouldn't there be twice the amount of real numbers between $ 0 $ and $ 2 $? Wouldn't that be $ 2 \times \infty $? What about the amount of real numbers between $ 0 $ and $ \infty $? Wouldn't that be $ \infty \times \infty $?

I guess the whole concept of infinity just kind of evades me. Any help would be appreciated!
Comment: "Infinity, is big. Really big. You just won't believe how vastly, hugely, mindbogglingly big it is. I mean, you may think it's a long way down the road to the chemist's, but that's just peanuts to infinity, listen..."
Comment: There are several different not necessarily compatible measures of size. In the sense of cardinality, the set $[0,1]$ and $[0,2]$ have the same (infinite) cardinality. In the sense of measure, one has measure $1$ and the other has measure $2$.  With shapes, there are several   measures of size (surface area, volume). They are useful in different contexts (painting, carrying).
Comment: @SanathDevalapurkar, define mathematics then.
Comment: I always wanted to answer this question with, simply, "bigger than that."
Comment: "Infinity is pretty huge" ...
Comment: Well, obviously 42
Comment: This question is not about mathematics.
Comment: You might also want to view Vi Hart's [How many kinds of infinity are there?](https://www.youtube.com/watch?v=23I5GS4JiDg).
Comment: These questions are becoming more frequent from new users and they are getting irrational upvoting. Attention moderators.
Comment: I don't entirely agree that this is not mathematics.  See what I wrote below.
Comment: You might find this short talk about [Cantor's diagonalization argument](http://ed.ted.com/lessons/how-big-is-infinity) interesting.
Comment: Careful about treating infinity as an object.  $3x = 2x + 1 \rightarrow x=1$ doesn't hold if you treat infinity as a possible value for $x$.  In general, infinity should be thought of as a property, "infinite", and I recommend interpreting it as "not among the finite numbers", which doesn't necessarily mean larger.
Comment: Think about something. It`s bigger that that.
Repeat.
Comment: How is this question getting more than 1 upvote/h ?
Comment: It's infinitely big.
Comment: [Related](http://math.stackexchange.com/questions/383811/how-big-is-the-size-of-all-infinities?rq=1) and [related](http://math.stackexchange.com/questions/283581/how-many-different-sizes-of-infinity-are-there?rq=1) and [related](http://math.stackexchange.com/questions/664862/how-do-we-assume-there-is-infinity?rq=1)
Comment: (Ignoring that infinity is not really a number but a cardinality...) Sure, there are twice as many real numbers between 0 and 2 as between 0 and 1. It's just that twice infinity is... infinity.
Comment: I want to point you to this vihart video: https://www.youtube.com/watch?v=23I5GS4JiDg
Comment: For every unique number x you find in [0,2] you can find a unique number x/2 in [0,1] but also the other way around for every unique number x in [0,1] you can find a unique number x*2 in [0,2]. Does this mean there are exactly the same amount of numbers in [0,1] as in [0,2]? –  Pieter B 46 secs ago
Comment: Your second sentence is very troubling. What do you think is special about the interval $[0,1]$? You could have chosen $[0,0.5]$, and you would then have concluded $[0,2]$ has $4\cdot\infty$.
Comment: There is a whole book on this topic.   "Infinity and the Mind: The Science and Philosophy of the Infinite" by Rudy Rucker. It explains all the different types of infinities in mathematics. Quite an intimidating read for the non-mathematicians, though.
Comment: I would also recommend "The Quest for Infinity" by Brian Clegg.  Highly readable, even for the non-mathematician.
Comment: @metacompactness: It's featured as a "Hot Network Question" in the sidebar and probably attacks a lot of non-mathematicians from other sites. After what I've seen on other questions I wish these featured questions would be locked from upvotes at the time of their "promotion".
Comment: Because the phrase "number of numbers", when you get to the reals, is vague and can mean *many* different things, I think that the Lebesgue measure should be mentioned. It encapsulates in what sense there can be "more" in one real set than another, even if they're equal in cardinality.
Comment: asking how big is infinity has no sense since it is has no size which can be actually counted.It is not possible to talk about it as in the sense of something which can be counted..thereforce infinty
Comment: https://www.youtube.com/watch?v=UPA3bwVVzGI <-- this video
Comment: The BBC In Our Time has a talk on infinity at http://www.bbc.co.uk/programmes/p0054927 (may not be available outside the UK)
Answer: I answered a similar question on May 13th:

There are many different things that could be called "the infinite" in mathematics.  None of them is a real number or a complex number, but some are used in discussing functions or real or complex numbers.

There are things called $+\infty$ and $-\infty$.  Those appear in such expressions as
  $$
  \lim_{x\to-\infty}\frac{1}{1+2^x} = 1 \text{ and }\lim_{x\to+\infty}\frac{1}{1+2^x}=0.
  $$
There is also an $\infty$ that is approached as $x$ goes in either direction along the line.  That occurs in
  $$
  \lim_{x\to\infty} \frac{x}{1-x} = -1\text{ and }\lim_{x\to1} \frac{x}{1-x}=\infty.
  $$
  The second limit above could be said to approach $+\infty$ as $x$ approaches $1$ from one direction and $-\infty$ if from the other direction, but if one has just one $\infty$ at both ends of the line, then one makes the rational function a continuous function at the point where it has a vertical asymptote.  This may be regarded as the same $\infty$ that appears in the theory of complex variables.
There are "points at infinity" in projective geometry.  This is similar to the "infinity" in the bullet point immediately preceding this one.  Two parallel lines meet at infinity, and it's the same point at infinity regardless of which of the two directions you take along the lines.  But two non-parallel lines pass through different points at infinity rather than the same point at infinity.  Thus any two lines in the projective plane intersect exactly once.
There are cardinalities of infinite sets such as $\{1,2,3,\ldots\}$ (which is countably infinite) or $\mathbb R$ (which is uncountably infinite).  When it is said that Euclid proved there are infinitely many prime numbers, this sort of "infinity" is referred to.
One regards an integral $\int_a^b f(x)\,dx$ as a sum of infinitely many infinitely small quantities, and a derivative $dy/dx$ as a quotient of two infinitely small quantities.  This is a different idea from all of the above.
Consider the step function $x\mapsto\begin{cases} 0 & \text{if }x<0, \\  1 & \text{if } x\ge 0. \end{cases}$  One can say that its rate of change is infinite at $x=0$.  This "infinity" admits multiplication by real numbers, so that for example, the rate of change at $0$ of the function that is $3.2$ times this function, is just $3.2$ times the "infinity" that is the rate of change of the original step function at $0$.  This is made precise is the very useful theory of Dirac's delta function.
There is the "infinite" of Robinson's nonstandard analysis.  In that theory, we learn that if $n$ is an infinite positive integer, then evern "internal" one-to-one function that maps $\{1,2,3,\ldots,n-3\}$ into $\{1,2,3,\ldots,n\}$ omits exactly three elements of the latter set from its image.  Nothing like that holds for cardinalities of infinite sets discussed above.
I'm sure there are other examples that I'm missing here.
Comment: Great answer. Arguably Euclid's proof of the infinitude of the primes doesn't need anything to do with cardinalities or collections of integers. Saying that there are infinitely many primes is shorthand for saying that no matter what bound you pick there's always a bigger prime.
Comment: Might want to mention the hyperreals and surreals as well.  (You allude to them with "Robinson's nonstandard analysis", but describing $\omega$ such that $\forall k \in \mathbb{N} \sum_0^k 1 < \omega$ might be clearer.)
Comment: It might also be worth mentioning infinite ordinals. Especially because that is one case where multiplying $\infty$ ($\omega$) by $2$ actually makes sense.
Comment: @Zack : By "hyperreals" do you mean something other than Robinson's theory that I mentioned in my answer?
Comment: @MichaelHardy At the time I wrote that I had forgotten that Robinson's theory and the hyperreals were the same thing.  As I tried to explain in my edited comment, I think a gentler introduction to Robinson's theory talks about $\mathbb{R}^\star \supset \mathbb{R}$ and the extended (infinite and infinitesmal) elements of $\mathbb{R}^\star$.  Conway's surreals, however, are their own thing AFAIK.
Comment: @MichaelHardy One question; about the parallel lines. Imagine two parallel lines parallel to X axis. Where they intersect - on the left or on the right? Or both, but still in single point? (The latter looks somehow "logical", but also it means that there is point on the place which can be reached in both directions...)
Comment: They meet at a single point at infinity that is approached by moving in either direction along the line.
Answer: User wrote:

If there is an infinite amount of numbers between $ 0 $ and $ 1 $, shouldn't there be twice that amount between $ 0 $ and $ 2 $?

No. Every real number in the interval $[0,1]$ can be mapped one-to-one to every real number in $[0,2]$ using the function $f(x)=2x$. So, there are no more numbers in $[0,2]$ than there are in $[0,1]$.
Comment: +1 - Why can't we all be more succinct?
Comment: @ANeves No, you're right. There are *more* real numbers than there are natural numbers. What this answer is claiming is that there are just as many real numbers in $[0,1]$ as there are in $[0,2]$.
Comment: @ANeves What does it mean that there are as many elements in $A$ as in $B$? Just that there exists a bijection $f:A\to B$, i.e. the elements of one set can be matched up 1-to-1 to all elements in the other set.
Comment: -1: I'm sorry, but this does not explain it to me. It makes sense, **but** if there are infinite natural numbers, and infinite real numbers between each natural number, how can the number of natural numbers and the number of real numbers be the same infinity, and not different orders of magnitude?
Comment: @ANeves to piggyback on what David was saying, though both the natural numbers and the real numbers are infinite, they are not equivalent in size. One thing many laypeople do not understand or realize is that infinity is not a number, it's not equal to any number, and that two infinities can be different (or the same) in size from one another.
Comment: (Btw, I can't really downvote with less than 150rep.) Ah, I see, thanks! Then I think this answer should actually be "No. **Infinity is not a number**, and (...)". The question being a layperson's, the answer should be to a layperson's.
Comment: (Set A being contained in set B, set B having items that are not in set A, and A having `just as many real numbers` as B... that still *does not work* in my head. But I can accept it - intuition can't always be right.)
Comment: "What does it mean that there are as many elements in A as in B? Just that there exists a bijection..." You speak of that "meaning" as it were some metaphysical truth, when it's just a mathematical definition - which makes sense, up to a point and in some definite context. Other has the right to claim "to speak of (or compare) the 'amount of elements' of infinite sets make no sense - end of history" hey, some even say "there are no such 'things' as infinite sets, they are only a sort of limit concept"
Comment: @leonbloy Yeah, it takes all kinds.
Answer: I have a rule of thumb: anything that says "infinity" (as opposed to $\aleph_0$, $\beth_2$, $\varepsilon_0$, $+\infty$, (projective) point at infinity, infinite, $\omega$, etc.) is probably not mathematics. It's not that mathematicians are afraid of the infinite -- hardly! -- but that it's an imprecise collection of heterogeneous concepts. Math is more precise than that.
In this case you're talking about the number of elements in a set (of real numbers), and so the particular concept you're talking about is called cardinality. The set [0, 1] has the same cardinality or 'size' as [0, 2]: precisely $2^{\aleph_0}=\beth_1.$
If you look at the fractions in [0, 1] and [0, 2] you'd find that, again, they have the same cardinality as each other, but a different cardinality from the above. This time they're 'just' $\aleph_0=\beth_0.$
If you drop all the way down to the integers the cardinality of the integers in [0, 1] is 2 while thee cardinality of the integers in [0, 2] is 3 and so these are no longer the same.
Comment: The first statement is wrong. Mathematicians work with the infinite just fine, and quite precisely. The problem is that when a *layperson* uses the word "infinity", they often  do so in an imprecise way that only loosely corresponds to a mathematical idea if at all. (and often resist the notion that there can even be mathematical ideas about the infinite)
Comment: @Hurkyl: Say what you will, this is my rule of thumb. If I see "$+\infty$" there's no problem, if I see "$\aleph_0$" there's no problem, but if I see "infinity" it's almost never mathematical. In fact this is one of my most useful heuristics, better than the "real math papers use TeX" heuristic.
Comment: @Steven: That's because the noun infinity usually crops up in *geometry*: e.g. positive and negative infinity of the extended reals (the same infinity that appears in "the limit is infinity"), or the points at infinity of the projective plane.
Comment: @Hurkyl To be fair, that could be argued to be a distinction between the infinite and the _word_ 'infinity', which - even in e.g. set theory - very seldom actually crops up (in lieu of more precise terms, of course!).
Comment: @Charles That is a far more cautious statement than your initial statement in this answer.
Comment: I second @Hurkyl's sentiment. I believe the first statement, as written, is misleading. Mathematicians use the word "infinity" or "infinite" quite frequently, but from the given context they can glean the precise meaning intended.
Comment: @StevenStadnicki: You beat me to it! Yes, that's precisely what I'm saying.
Comment: @Hurkyl Ack, very good point that!  I was somewhat primed for set theory because of the question (loosely, treating infinity as a _size_ rather than a _place_) but you're absolutely right that that's a precise and canonical concept.
Comment: @Hurkyl: I have no problem with $+\infty$ and $-\infty$, nor with "points at infinity" or any other concrete notion, but the fluffy unqualified "infinity" is rarely used in math.
Comment: @Brilliand: The purpose of the statement was just to provide a reference frame for understanding the main claim of the paragraph: that when mathematicians talk about the infinite they have a particular kind in mind, and "infinity" itself is ambiguous. If the topic was distinguishing mathematics from philosophy I would have been much more nuanced -- but to do so here would take away from my main point. (On the other hand, if what you're saying is that you're interested in my heuristics here, I could say a good deal -- ask a CW question and ping me.)
Comment: what the heck is ℶ symbol?
Comment: @Templar: The letter beth (or bet), the second letter in the Hebrew alphabet. $\beth_0$ is the cardinality of the integers (the 'smallest infinity') and they are defined recursively as $\beth_{n+1}=2^{\beth_n}$ where the symbol denotes cardinal exponentiation: if $\mathfrak{a}$ is a set, $2^\mathfrak{a}$ is the set of maps from $\mathfrak{a}$ to $\{0,1\}.$ So $\beth_1$ is the cardinality of the real numbers, a much larger infinite cardinal.
Comment: @J.Loreaux: I intentionally excluded "infinite" -- this is very common in mathematics.
Answer: Intuitively, you are treating the "quantity" called infinity just like an ordinary real number. This is the defect.
You have a definition of $\infty$ and prove whether it satisfies the properties of real numbers, if yes, then you may say that,

If there is an infinite amount of numbers between $ 0 $ and $ 1 $, shouldn't there be twice that amount between $ 0 $ and $ 2 $?

Note that you have assumed that the quantity $2$ $.$ $\infty$ is defined similarly as we define $x . y$ in $\mathbb {R}$.
Basically you may have assumed $\infty$ to be a very very big real number. This is the basic flaw, since $\infty$ is not a member of $\mathbb {R}$.
Answer: The ideas of being "of  the  same size", here , referring to your question we are dealing with cardinality,  that we understand in the world of the finite, break down when we have infinite sets. There are formal definitions of what it means for two infinite sets to have the same size/cardinality or, informally,  having the same amount of terms. There is a whole precisely-defined arithmetic of infinite cardinalities, with precisely-stated meanings, e.g.: $X^Y$ is the cardinality of all the functions from a set of cardinality represented by $X$ to a set with cardinality represented by $Y$.
Specifically, two infinite sets $X,Y$ have the same size if there is a one-one , onto map between them, i.e., if there is a bijection between $X,Y$ (there are related results like the Cantor-Schroder-Bernstein theorem that tell you that if there is an injection between $X,Y$ and an injection between $Y,X$ then there is a bijection between the two).
  In our case, since we can find a bijection between the two intervals $(0,1)$ and $(0,2)$, by our definition, the two have the same size (cardinality).
To answer your question, $2 \infty$ is decided by whther we can find a bijection between a set of that same infinite cardinality and the disjoint union of the set with itself.
Like Andre Nicolas stated in the comments, you can consider different measures of size, such as length, or measure in general. So one can have sets of the same cardinality but with different measure.
Comment: What is the downvote about?
Answer: Infinity can be as big as you want it to be. It can be in the interval between 0 and 1, or it can be in the interval between 0 and 2, or in the interval between $(-3)^7$ to $10^{10^{10^{34}}}$, etc. I take it you've heard the term "infinitesimally small."
Try to count how many rational numbers there are between 0 and 1. Better yet, try to count how many rational numbers there are between 0 and 1 which can be expressed with a denominator that is a power of 2. There is $\frac{1}{2}$. There is $\frac{1}{4}$ and $\frac{3}{4}$. And $\frac{1}{8}$, $\frac{3}{8}$, $\frac{5}{8}$, $\frac{7}{8}$, ... you get the idea. Now try the same thing between 0 and 2. There's 1. There's $\frac{1}{2}$ and $\frac{3}{2}$. And $\frac{1}{4}$, $\frac{3}{4}$, $\frac{5}{4}$, and well, you run into the same problem.
In your mind, imagine a typical 12-inch ruler. But with this ruler, you can make the tickmarks as small as you want, whereas with a real ruler, you would get to a point at which you have to make the tickmarks so small you can't even see them.
The concept of infinity can easily lead to a lot of paradoxes, as well as statements that look nonsensical, like $\infty^2 = \infty^\infty = \infty$. I suggest you read http://www.suitcaseofdreams.net/infinity_paradox.htm
Comment: Maybe only when a mathematician or a smart-aleck is asking. Assuming Tetyana Butler is right, I think that $\infty^\infty$ follows from her assertion that $\infty^2 = \infty$.
Comment: In what context is $\infty^{\infty} = \infty$ true?
Comment: I can "accept" $\infty^2 = \infty$ since this for example is true if we replace $\infty$ by any infinite cardinal. But I cannot think of a context where we can both make sense of $\infty^{\infty}$ and have it equal $\infty$.
Comment: Welcome to math.se! I didn't know you had an account here.
Comment: Thanks, Charles. Only very recently, after I suggested it to an OEIS contributor.
Answer: I think you should not try to tackle understanding "infinity" head on. It's literally too much for human mind. So I'll try to give an "intuitively" understandable answer, thus avoiding "infinity" from now on:
All the numbers in [0, 2] can easily fit into [0, 1]! We can play a game to show this:
You provide a number from [0, 2] and I'll return a number from [0, 1]. For any different numbers, I'll lose, if I fail to provide different numbers. I can only win, if I convince you that I won't lose.
<code>You may start with 2.</code>
I'll go with 1.
<code>Maybe 1?</code>
0.5
<code>square root of 2!</code> (square root of 2) divided by 2.
<code>Zero, got ya.</code> Nope, zero, too.
<code>Any number.</code> Half that number.
See, what I'm getting at? There are as many numbers in [0, 1] as there are in [0, 2], because I can define a method to get one for every one you provide. I'll assume this is convincing enough and I won the game.
So to measure something that is too huge to measure, you just compare it, piece by piece, to something about the same size. Well, actually you don't compare, but tell how you would compare. If you can find a way to compare, piece by piece, it's not bigger.
The problem is to find a way to compare piece by piece. The only help I can give you in this, is the advice to avoid confusing yourself by the-bad-word. Instead ask yourself: "Where does the huge number of pieces come from?"

[0, 2] looks twice as big as [0, 1]. But it's not, if you half it!
[0, x] looks x times as big as [0, 1]. So as long as you can divide by x, everything is fine.
We all know that dividing by zero isn't allowed. So we found something that's "smaller": [0, 0] has only one element, so it's clearly smaller.
I disallowed myself from using the-bad-word. So I need to put it like this: If x keeps growing. What will happen to say 1/x?

At some point <code>1 divided by ever-growing-x</code> will be indistinguishable close to 0. And if you can't distinguish between 0 and <code>1/ever-growing-x</code> the piece to piece comparison fails. This makes [0, ever-growing-x] "bigger" than [0, 1] or [0, not-growing-x].
The next step would be to have a look at y-growing-way-faster-than-x. But I guess that'd overdo things.
Comment: Excellent layperson answer.
Comment: Your example is correct, but you should also note that with this function you need to get all of the elements in [0,1].  I can map {0,1,2,3...} to [0,1] by sticking a decimal point on the left of the number, but [0,1] is bigger.
Comment: @CarlosBribiescas: You're right. But I wanted to keep it as simple as possible. So the comparison does only answer is A bigger than B with "yes" or "no". It does **not** answer "No, B is bigger than A.".
BTW: Yes, it is a layperson answer, because the OP indicated to be a layperson. So thank you, for the compliment.
Answer: This is a great anecdotal way to learn about different sizes of infinity.
Wikipedia Article - Hilbert's Hotel
So there are different sizes of infinity.  Suppose you have two sets <code>A</code> and <code>B</code> and both of those sets are full of infinite things, that is, each of those two sets has infinite items.  Not to say that they are they same size, one of their infinities may be bigger than the other.
If for every single item in <code>A</code> I can map it to exactly one item in <code>B</code> and I have all items in <code>B</code> covered, then the two sets are the same size of infinity.
If in all 1-1 mapping from <code>A</code> to <code>B</code> in which all items in <code>A</code> are used there are always items in <code>B</code> leftover, then the size of <code>B</code> is a bigger infinity than that of <code>A</code>.
Comment: I didn't use the normal "for all" terminology, but I think I addressed your point.  In my defense, its been a while... :-D
Thanks!
Comment: Yes, except for the mapping __s__ typo.
Answer: You need a little set theory to understand this concept well.
If a set s has infinite amount of elements then there exists a function f from S to a subset of S ( say T, note that T != S ).
Just that easy !
Now, Why does N (1, 2, ,3 , 4, ...) have infinite elements?
Consider f(x) = x + 1 it maps whole N to "N - { 1 }" therefore N so .
Why does R have infinite members!? Because we can find functions like f(x) = 1/x which map whole r between a subset of R ( here between 0 & 1 ).
That's all I known ... I hope it helps.
If you are interested in set theory I recommend "Lectures in logic & set theory vol2" ( hey I am not a mathematics expert if you ask a more experienced one you shall get better resources )
Answer: Infinity is so large, it can contain multiple copies of itself, within itself.  It's not at all like any of the other numbers, so many of the "common sense" approaches to infinity don't make a lot of sense.
That answer that pointed you to Cantor's Diagonalization Argument...  yes, that's the way to go...
Answer: If you want to be able to treat $\infty$ more or less as a real number, look into hyperreal numbers. A hyperreal number is essentially a number defined by a sequence, which may or may not be limited. Therefore it is possible to say that the sequence $\{2,4,6,...\}$ is twice as large as the sequence $\{1,2,3,...\}$, even though both approach $\infty$. However, good luck applying hyperreals to the set of numbers between $0$ and $1$. That particular type of infinity is very difficult to define or measure, and almost completely useless.

How big is infinity?


TypeScript: Iterating over the interface fields does not work

Question: I'm trying to iterate over the keys of an object that has an interface, but TypeScript does not recognise the type of the key.
interface Resources {
  food?: number
  water?: number
  wood?: number
  coal?: number
  stone?: number
  metal?: number
  oil?: number
  power?: number
}

class Game {
  resources: Resources = {}

  addResources = (newResources: Resources) => {
    Object.keys(newResources).forEach(key => {
      // Error:(17, 11) TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Resources'.
     //  No index signature with a parameter of type 'string' was found on type 'Resources'.
      if (this.resources[key]) {
        this.resources[key] += newResources[key]
      } else {
        this.resources[key] = newResources[key]
      }
    })
  }
}

How should I type it so Typescript will understand the iteration?
Answer: Yes, Object.keys() returns string[] and this is intentional https://github.com/Microsoft/TypeScript/issues/12870
(Object.keys(newResources) as Array<keyof Resources>).forEach(...) for the rescue.
UPD
(Object.keys(newResources) as Array<keyof typeof newResources>).forEach(...) also helps.
Comment: Hmm, this is very, very strange. Thanks.
Answer: The interface does not exist in the browser, TypeScipt is only a compiler concept. Once your code is compiled to JavaScript and running in the browser there is no concept of the interface left. The interface exists only to strongly type the code during development, it is completely lost at run time.
Comment: Yes, but Typescript complains about types specifically, which exist only at compile time too...
Answer: If you want to get rid of the compiler error add a dynamic property.
interface Resources {
  food?: number
  water?: number
  wood?: number
  coal?: number
  stone?: number
  metal?: number
  oil?: number
  power?: number
  [key: string]?: any
}

Comment: But then I could somewhere add a property with a typo, and compiler will not catch it...
Comment: Try creating an enum with the property names you want in it and the add that as the key type
Comment: `[key: string]?: any` does not define a property, it defines an [index signature](https://www.typescriptlang.org/docs/handbook/2/objects.html#index-signatures) that declares what types of keys and what types of values are valid for the type or interface.


Como descobrir o número de linhas e colunas de uma matriz criada dinamicamente?

Question: Com base nos meus conhecimentos, eu criei uma função que retorna uma matriz inicializada:
int** initMatriz(int rows, int cols){
    int i,j;
    int** matriz;

    //aloca memoria para todas as linhas
    matriz = (int**) malloc(rows * sizeof(int*));
    for(i=0; i < rows ; i++){
        //para cada linha eu aloco o nmr de colunas
        matriz[i] = (int*) malloc(cols * sizeof(int));
        //inicializa
        for(j=0 ; j < cols ; j++){
            matriz[i][j] = 0;
        }
    }

    return matriz;
}

No momento de inicializar:
int** matriz = initMatriz(rows, cols);

A partir desse ponto, como eu descubro o número de linhas e o número de colunas?
Answer:
int** matriz = initMatriz(rows, cols);

A partir desse ponto, como eu descubro o número de linhas e o número de colunas?

Bem, a resposta está ali mesmo. Basta você olhar para os parâmetros rows e cols e eles te darão a resposta.
Ok, talvez você queira saber como fazer isso caso você não tenha mais acesso aos valores de rows e cols. E a resposta é que não dá para fazer isso, ao menos não de forma portável. O valor do ponteiro é um número que diz em qual endereço de memória começa o bloco de memória que foi alocado, mas nada diz sobre o seu tamanho.
Se você conhecer os detalhes profundos da sua implementação de malloc, talvez você possa encontrar essa informação nas tabelas de alocação de memória que forem criadas ou em algum outro tipo de informação interna mantida pelo malloc. Entretanto, uma solução baseada nisso é inerentemente não-portável.
A solução adotada em quase todos os casos incluem você encapsular o ponteiro para o array e o tamanho do array alocado juntos em uma mesma estrutura para isso. Desta forma, você elimina o problema fundamental que é não ter o tamanho da área alocada juntamente com essa própria área. Por exemplo:
typedef struct {
    int rows;
    int cols;
    int** pointer;
} Matriz;

Matriz* initMatriz(int rows, int cols) {
    int i, j;

    // Aloca a memória para todas as linhas.
    int **matriz = (int**) malloc(rows * sizeof(int*));
    for (i = 0; i < rows; i++) {
        // Para cada linha, eu aloco o número de colunas.
        matriz[i] = (int*) malloc(cols * sizeof(int));
        // Inicializa.
        for (j = 0; j < cols; j++) {
            matriz[i][j] = 0;
        }
    }
    Matriz *resultado = (Matriz *) malloc(sizeof(Matriz));
    resultado->rows = rows;
    resultado->cols = cols;
    resultado->pointer = matriz;

    return resultado;
}

Para destruir uma matriz a fim de liberar memória:
void freeMatriz(Matriz *matriz) {
    for (int i = 0; i < matriz->rows; i++) {
        free(matriz->pointer[i]);
    }
    free(matriz->pointer);
    free(matriz);
}

Comment: @Skywalker Ou seja, primeiro você dá um `free(matriz->pointer)` e depois `free(matriz)`. Editei a resposta para mostrar isso.
Comment: Então Victor valeu pela resposta, eu estava usando essa estrutura ja, mas antes de chegar a usar ela eu tive essa duvida mesmo, pois achei interessante e não conseguia resolver de nenhuma forma. Pois para vetores iniciados normal, é possível achar o numero de posições. através do código sizeof(vetor)/sizeof(int), achei q daria certo, mas quando se inicia dinamicamente esse código ja nao serve mais. Mas graças a sua explicação me ajudou bastante a entender.
Comment: Só uma dúvida, o processo de liberação de memória, posso dar o free só na matriz? `free(matriz)` ou preciso dar um free primeiro no `pointer` e depois na matriz?
Comment: @Skywalker Para usar o `free`, o processo é simples (embora encontrar informações explicando isso pode não ser): Tudo o que você recebeu do `malloc`, você deve devolver com `free`. Se o `malloc` te deu um ponteiro `x`, então você deve devolver esse mesmo ponteiro com `free` no futuro. Você não deve passar para `free` algo que você não tenha recebido de um `malloc`. Você não deve chamar o `free` mais de uma vez para algum ponteiro recebido de `malloc`. Você não deve se esquecer de chamar o `free` para algo recebido de `malloc`.
Comment: Hum sim, então preciso dar um free para todas as colunas em um for e depois sim para o pointer, e posteriormente para a matriz. certo?
Comment: perfeito, obrigado @Victor Stafusa


Polynomial Regression using Gradient Descent for approximation of a sine in python

Question: According to answers of this topic: Polynomial regression using gradient descent I've written a code for polynomial regression of this data: http://illumina.ir/ML/data1.xlsx (the output is simply a sine function).
<code>import pandas
import numpy as np
import matplotlib.pyplot as plt

def gradientDescent(x, y, theta, alpha, n, numIterations):
    xTrans = x.transpose()
    for i in range(0, numIterations):
        hypothesis = np.dot(x, theta)
        loss = hypothesis - y
        cost = np.sum(loss ** 2) / (2 * n)
        #print("Iteration %d | Cost: %f" % (i, cost))
        gradient = np.dot(xTrans, loss) / n
        theta = theta - alpha * gradient
    return theta

ExcelData = pandas.read_excel('data1.xlsx', 'Sheet1')

xs=ExcelData[0]
#xs = xs / np.linalg.norm(xs) #normalize input examples
xs = xs / xs[99] #normalize input examples
ys=ExcelData['0.1']

m=7 #polynomial degree
n=len(ys) #number of examples
numIterations= 100000 #number of iterations
alpha = 0.01

y = np.zeros(shape=n)
x = np.zeros(shape=(n, m))
theta = np.ones(m)

for i in range(0, n):
    y[i] = ys[i]

for i in range(0, n):
    for j in range(0, m):
        x[i][j] = np.power(xs[i], j)

theta = gradientDescent(x, y, theta, alpha, n, numIterations)
print(theta)

plt.clf()
plt.plot(y)
plt.plot(np.dot(x, theta))
plt.savefig('testplot.png')
</code>
Here is the output:

The blue curve is the expected output and the orange curve is the approximation.
What's the problem with my code?
Comment: My understanding is that in this specific case, using a 7th order polynomial approximating function, gradient descent cannot make a better fit than standard linear methods - meaning that you could compare fitting results and see what the best possible result from the gradient descent should look like. Note that your initial parameter values are all 1.0, comparison with linear solver results would also allow experimenting with initial parameter values closer to those from the linear solution.
Answer: The gradient descent code looks fine to me (although you should not fix the number of steps but rather exiting when the gradient is small).
The issue is that the gradient descent converges to a local minimum, which is not necessarily the global minimum. The key points are that
(i) the polynomial fitting converges VERY slowly to the sin function. The 7th order approximation does not converge outside the first period for example (see http://www.wolframalpha.com/input/?i=Taylor+sin+x) and the gradient descent method will not be able to find a much better solution (it requires a higher order polynomial);
(ii) the coefficients of the Taylor series centered in 0.5 have very different magnitudes. You should find theta = [-197, +2766, -15877, +47085, -75701, +62590, -20863, +0]. Supposedly, the same applies for the coefficients of the global minimum of the gradient descent method*. Starting from a guesses of all ones is a very poor initial condition, you are too far away from the actual solution.
Hope this helps
*NB: the Taylor series coefficients are NOT the same coefficients that the gradient descent method should fine. The Taylor series best approximate the function close to the expansion point, with the error increasing away from it; in the least square fitting that underlies the gradient descent tries to minimize the overall error, there is no "favorite point" unless you use weighted sums.)


What is a more efficient way to keep a daily ranking log for each user with MySQL?

Question: I have a database called RankHistory that is populated daily with each user's username and rank for the day (rank as in 1,2,3,...).  I keep logs going back 90 days for every user, but my user base has grown to the point that the MySQL database holding these logs is now in excess of 20 million rows.
This data is recorded solely for the use of generating a graph showing how a user's rank has changed for the past 90 days.  Is there a better way of doing this than having this massive database that will keep growing forever?
Answer: How great is the need for historic data in this case? My first thought would be to truncate data older than a certain threshold, or move it to an archive table that doesn't require as frequent or fast access as your current data.
You also mention keeping 90 days of data per user, but the data is only used to show a graph of changes to rank over the past 30 days. Is the extra 60 days' data used to look at changes over previous periods? If it isn't strictly necessary to keep that data (or at least not keep it in your primary data store, as per my first suggestion), you'd neatly cut the quantity of your data by two-thirds.
Do we have the full picture, though? If you have a daily record per user, and keep 90 days on hand, you must have on the order of a quarter-million users if you've generated over twenty million records. Is that so?
Update:
Based on the comments below, here are my thoughts: If you have hundreds of thousands of users, and must keep a piece of data for each of them, every day for 90 days, then you will eventually have millions of pieces of data - there's no simple way around that. What you can look into is minimizing that data. If all you need to present is a calculated rank per user per day, and assuming that rank is simply a numeric position for the given user among all users (an integer between 1 - 200000, for example), storing twenty million such records should not put unreasonable strain on your database resources.
So, what precisely is your concern? Sheer data size (i.e. hard-disk space consumed) should be relatively manageable under the scenario above. You should be able to handle performance via indexes, to a certain point, beyond which the data truncation and partitioning concepts mentioned can come into play (keep blocks of users in different tables or databases, for example, though that's not an ideal design...)
Another possibility is, though the specifics are somewhat beyond my realm of expertise, you seem to have an ideal candidate for an OLAP cube, here: you have a fact (rank) that you want to view in the context of two dimensions (user and date). There are tools out there for managing this sort of scenario efficiently, even on very large datasets.
Comment: +1 If you could do some summarization of the results and keep them in the database instead of each individual row, that would probably help a great deal.
Comment: @Jon Was just thinking of adding that to my answer - good call!
Comment: Oh sorry, I meant I show a graph for the last 90 days not 30 days.
Comment: @James Simpson Okay. And do you indeed have ~200000+ users, or is something else about your model causing so many records to be created?
Comment: I do indeed have around 200,000 users, so the database is correctly storing 90 days for each user.
Comment: @James Simpson Fair enough - I've updated my answer based on these comments.
Answer: Could you run an automated task like a cron job that checks the database every day or week and deletes entries that are more than 90 days old?
Comment: That is what I currently do, but this makes the database still grow proportionately as new users join.
Answer: Another option, do can you create some "roll-up" aggregate per user based on whatever the criteria is... counts, sales, whatever and it is all stored based on employee + date of activity.  Then you could have your pre-aggregated rollups in a much smaller table for however long in history you need.  Triggers, or nightly procedures can run a query for the day and append the results to the daily summary.  Then your queries and graphs can go against that without dealing with performance issues.  This would also help ease moving such records to a historical database archive.
-- uh... oops... that's what it sounded like you WERE doing and STILL had 20 million+ records... is that correct?  That would mean you're dealing with about 220,000+ users???
20,000,000 records / 90 days = about 222,222 users
EDIT -- from feedback.
Having 222k+ users, I would seriously consider that importance it is for "Ranking" when you have someone in the 222,222nd place.  I would pair the daily ranking down to say the top 1,000.  Again, I don't know the importance, but if someone doesn't make the top 1,000 does it really matter???
Comment: Yes, that is correct, I have somewhere in that range of users.  So, doing this was a temporary fix until the user base continued to grow and is out of hand once again.


Apache closes connection too early

Question: I am trying to debug an issue we are having with some embedded devices when they are downloading Firmware over-the-air and closing connections too early, failing to get all data.
I tried downloading the file with curl and wget but it gets downloaded without problems and the checksums match.
The only "hint" that I could find is when I run curl with the verbose option (-v). I created a file with dummy content, only containing the word dummy many times over.
When I run curl -v http://myserver/dummy.txt I get this response:
dummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummClosing connection #0
ydummydummydummydummydummydummydummydummydummydummydummydummydummy
Why is there the "Closing connection #0" before the end of data?
The apache version is 2.2, we also have HAProxy in front of it, but I get the same "issue" if I curl locally on the machine.
Answer: TLDR: what you see is only a display artefact on your terminal and no indication of any issue with either your webserver or HAproxy closing connections too early.

I think that reeks of the counter intuitive effects of output buffering.
Default behaviour of Linux glibc is to do line buffering when standard output is sent to a TTY. That will buffer the output and only display a block of data on your terminal when either:

an end-of-line is observed
the output buffer is full
the program terminates.

It wouldn't surprise me if the "Closing connection" message  is sent to standard error  which gets displayed immediately but the last bit of content from your URL only comes out of the buffer when curl terminates.
You'll probably see a more intuitive and sequential result when you change the buffering with stdbuff and make the error and output modes unbuffered:
stdbuf -o0 -e0 curl -v http://myserver/dummy.txt

But also when you change your data to include more new-lines:
dummy
dummy
dummy
...

Comment: Thank you HBruijn, it is exactly as you described. stdbuf or a newline character displays the flow correctly

Apache closes connection too early