Definir textos a JLabels dinamicamente conforme validação de campos de texto

Question: Eu tentei adicionar um label para cada componente obrigatório da minha tela que esteja vazio (campo 01 e campo 02), então eu criei uma lista de labels com a quantidade correspondente de campos/componentes. Porém, as tentativas que eu fiz para que ele "set" as mensagens correspondentes de cada label (com os nomes de cada campo) não funcionam adequadamente.
No exemplo eu usei apenas 3 campos do tipo JTextField, porém, a ideia, é que a quantidade de campos possa variar.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class AdicionaCmp extends JFrame {

    private MeuJTextField jTextField1 = new MeuJTextField(true, "Campo 01");
    private MeuJTextField jTextField2 = new MeuJTextField(true, "Campo 02");
    private MeuJTextField jTextField3 = new MeuJTextField(false, "Campo 03");
    private JButton jButton = new JButton("Validar");
    //private JLabel labelInferior = new JLabel();
    private Font fonte = new Font("Arial", Font.PLAIN, 10);

    private List<JLabel> listLabel = new ArrayList<>();
    private List<JComponent> listComponentes = new ArrayList<>();

    public static void main(String[] args) {
        EventQueue.invokeLater(AdicionaCmp::new);
    }

    public AdicionaCmp() {
        add(montaTela());
        //setSize(600, 350);
        pack();

        setVisible(true);
        actionButton();
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    private JComponent montaTela() {
        JPanel painelPrincipal = new JPanel();

        JPanel painel = new JPanel();
        painel.setLayout(new GridBagLayout());
        adicionaComponente(1, 1, 1, 1, painel, painelPrincipal);
        adicionaComponente(1, 1, 1, 2, jTextField1, painel);
        adicionaComponente(2, 1, 1, 2, jTextField2, painel);
        adicionaComponente(3, 1, 1, 2, jTextField3, painel);
        adicionaComponente(4, 1, 1, 1, jButton, painel);
        return painelPrincipal;
    }

    public void adicionaComponente(int linha, int coluna, int linhas, int colunas, JComponent componente, JPanel painel) {

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridy = linha;
        gbc.gridx = coluna;
        gbc.gridheight = 1;
        gbc.gridwidth = 1;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(5, 5, 5, 5);

        JPanel painelInterno = new JPanel();
        painelInterno.setLayout(new GridBagLayout());
        JLabel rotulo = new JLabel();

        if (componente instanceof MeuJTextField) {
            rotulo = new JLabel(((MeuJTextField) componente).getNome());
        }

        GridBagConstraints gbc1 = new GridBagConstraints();
        gbc1.gridx = 1;
        gbc1.gridy = 1;
        gbc1.anchor = GridBagConstraints.WEST;
        gbc1.insets = new Insets(5, 5, 5, 5);
        painelInterno.add(rotulo, gbc1);

        GridBagConstraints gbc2 = (GridBagConstraints) gbc1.clone();
        gbc2.gridx = 2;
        gbc2.fill = GridBagConstraints.BOTH;
        gbc2.gridwidth = GridBagConstraints.REMAINDER; //Especifica que esse componente é o último componente em sua coluna ou linha.
        painelInterno.add(componente, gbc2);

        GridBagConstraints gbc3 = (GridBagConstraints) gbc1.clone();
        gbc3.gridx = 2;
        gbc3.gridy = 2;

        listComponentes.add(componente);

        if ((componente instanceof MeuJTextField) && (((MeuJTextField) componente).eObrigatorio())) {

            JLabel labelInferior = new JLabel();

            for (int i = 0; i < listComponentes.size(); i++) {
                labelInferior = new JLabel();
                painelInterno.add(labelInferior, gbc3);
                setMessage(listLabel, ((MeuJTextField) componente).getNome());
                //listLabel.add(labelInferior);
            }
            listLabel.add(labelInferior);
        }

        gbc.anchor = GridBagConstraints.WEST;
        gbc.gridx++;
        gbc.gridheight = linhas;
        gbc.gridwidth = colunas;
        painel.add(painelInterno, gbc);
    }

    private void actionButton() {
        jButton.addActionListener(e -> {
            validaComponentes();
        });
    }

    private void setMessage(List<JLabel> listLabel, String message) {
        for (JLabel labels : listLabel) {
            labels.setFont(fonte);
            labels.setForeground(new Color(255, 21, 8));
            labels.setText(message);
        }
        pack();
    }

    private boolean validaComponentes() {
        java.lang.reflect.Field[] allFields = this.getClass().getDeclaredFields();
        for (java.lang.reflect.Field field : allFields) {
            if (Modifier.isPrivate(field.getModifiers())) {
                try {
                    field.setAccessible(true);
                    Object fieldValue = field.get(this);
                    if (fieldValue instanceof MeuJTextField) {
                        if (((MeuJTextField) fieldValue).isEmpty()) {
                            setMessage(listLabel, "O " + ((MeuJTextField) fieldValue).getNome() + " não pode ser vazio !");
                            return false;
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
        return true;

    }

    class MeuJTextField extends JTextField implements MeuComponente {

        private boolean eObrigatorio;
        private String nome;

        public MeuJTextField(boolean eObrigatorio, String nome) {
            this.eObrigatorio = eObrigatorio;
            this.nome = nome;
            setPreferredSize(new Dimension(200, 25));
        }

        @Override
        public String getNome() {
            return nome;
        }

        public boolean isEmpty() {
            return getText().trim().isEmpty();
        }

        @Override
        public boolean eObrigatorio() {
            return eObrigatorio;
        }
    }

    public interface MeuComponente {

        public String getNome();

        public boolean eObrigatorio();
    }
}

Comment: Com quantos campos você pretente fazer isso? Se for só com 3, é simples. Por isso que é importante fornecer o contexto completo no mcve.
Comment: @Articuno eu estava tentando fazer de um jeito que não fosse fixo, poderia variar .
Comment: Sugestão: edite a pergunta e adicione todas as informações já faladas aqui, porque nela você não diz nada de que o método não seja fixo pra apenas 3 elementos
Comment: @Articuno adicionei mais uma descrição
Comment: Posso sugerir uma alternativa minha de como fazer isso? Tô achando seu código muito bagunçado e cheio de coisas desnecessárias e/ou redundantes. Simplesmente não estou conseguindo nem aplicar minha ideia em cima dele.
Comment: @Articuno pode sim, toda ajuda é bem - vinda
Comment: Precisa mesmo usar recursividade?
Comment: @Articuno faz o seu exemplo, eu tento adaptar conforme a necessidade, você me fornecendo a base, já sera de grande ajuda !
Comment: Uma duvida, porque está adicionando JLabel de rotulo vazia quando não é um campo de texto?
Comment: @Articuno eu não ia colocar pra radioButton, mais acho que tirei do código ai, pra não poluir mais.
Answer: Conforme questionado nos comentários, esta resposta é uma forma alternativa ao que você já fez, que torna o código mais organizado e mais legível:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class ValidarCamposComLabelTest  extends JFrame{

    private List<MeuJTextField> fields =  new ArrayList<>();
    private List<JLabel> labels = new ArrayList<>();
    private JButton jButton = new JButton("Validar");

    private Font fonte = new Font("Arial", Font.PLAIN, 10);

    public static void main(String[] args) {
        EventQueue.invokeLater(ValidarCamposComLabelTest::new);
    }

    public ValidarCamposComLabelTest() {

        JPanel painelPrincipal = new JPanel();

        JPanel painel = new JPanel();
        painel.setLayout(new GridBagLayout());

        fields.add(new MeuJTextField(true, "Campo 01"));
        fields.add(new MeuJTextField(true, "Campo 02"));
        fields.add(new MeuJTextField(true, "Campo 03"));

        int linhaAtual = 1;

        for(int i = 0; i < fields.size(); i++, linhaAtual++) {
            adicionaComponente(linhaAtual, 1, 1, 1, new JLabel(fields.get(i).getNome()), painel);
            adicionaComponente(linhaAtual, 2, 1, 2, fields.get(i), painel);

            if(fields.get(i).eObrigatorio()) {

                JLabel label = new JLabel("");
                label.setFont(fonte);
                label.setForeground(new Color(255, 21, 8));
                adicionaComponente(++linhaAtual, 2, 1, 1, label, painel);
                labels.add(label);
            }
        }

        adicionaComponente(++linhaAtual, 1, 1, 1, jButton, painel);
        jButton.addActionListener(e -> validaComponentes());

        painelPrincipal.add(painel);
        add(painelPrincipal);
        pack();
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }

    private boolean validaComponentes() {
        boolean retorno = true;

        for(int i = 0; i <fields.size(); i++) {
            if(fields.get(i).isEmpty()) {
                labels.get(i).setText(fields.get(i).getNome() +  " não pode ser vazio !");
                retorno = false;
            } else {
                labels.get(i).setText("");
            }
        }
        pack();
        return retorno;
    }

    private void adicionaComponente(int linha, int coluna, int linhas, int colunas, JComponent componente,
            JPanel painel) {

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridy = linha;
        gbc.gridx = coluna;
        gbc.gridheight = linhas;
        gbc.gridwidth = colunas;
        gbc.insets = new Insets(5, 5, 5, 5);
        painel.add(componente, gbc);

    }

    class MeuJTextField extends JTextField implements MeuComponente {

        private boolean eObrigatorio;
        private String nome;

        public MeuJTextField(boolean eObrigatorio, String nome) {
            this.eObrigatorio = eObrigatorio;
            this.nome = nome;
            setPreferredSize(new Dimension(200, 25));
        }

        @Override
        public String getNome() {
            return nome;
        }

        public boolean isEmpty() {
            return getText().trim().isEmpty();
        }

        @Override
        public boolean eObrigatorio() {
            return eObrigatorio;
        }
    }

    public interface MeuComponente {

        public String getNome();

        public boolean eObrigatorio();
    }
}

Mudanças que fiz:

criei listas de campo(fields) e outra pra seus respectivos labels, e adicionei estes conforme a quantidade de campos;
a variável linhaAtual foi criada para poder termos controle da adição dos componentes adicionados na variável painel;
ao adicionar um label referente ao aviso de preenchimento de um campo de texto, é feito um pré-incremento na linhaAtual para que este componente seja adicionado na linha abaixo do campo de texto;
o método adicionaComponente() foi abstraido, de forma que ele agora pode ser usado para adicionar qualquer componente a qualquer painel da sua tela que tenha um GridBagLayout como seu layout, respeitando os valores passados para o GridBagConstraints;
o método validaComponentes() está mais enxuto graças as nossas listas de campos de texto e de labels, sem a necessidade de recursividade para varrer os campos. Com um adicional, ele agora também limpa os labels quando o campo passar na validação.

Reitero que apesar de funcional, eu particulamente acho essa forma de abordagem de validação bem ruim, encher a tela de labels pra mostrar mensagem de cada campo não melhora a UX de sua aplicação, muito pelo contrário.
Usando InputVerifier creio que fique mais amigável, se quiser um exemplo, veja neste link ou nesta resposta que fiz aqui no site.
Comment: apenas uma duvida, no caso de adicionar componentes que não sejam obrigatórios, ele vai me retornar um IndexOutOfBoundsException, já que a quantidade de componentes sera maior que a de labels, mesmo que eu coloque para setar apenas nos campos obrigatórios. Por exemplo, mude o campo 02 para não obrigatório.
Comment: @GustavoSantos basta você adicionar apenas campos obrigatórios na lista, uma vez que se um campo não é obrigatório, ele não precisa de um label para valida-lo.
Comment: já é feito assim, ele só adiciona para os obrigatórios, e para validar eu ainda adicionei mais uma condição "if (fields.get(i).isEmpty() && fields.get(i).eObrigatorio()) "
Comment: @GustavoSantos se somente campos obrigatórios é adicionado na lista, não tem como estourar indexoffbound. Confere ai, você deve estar adicionando campos não obrigatórios junto.


The intersection and sum of irrelevant ideals are also irrelevant

Question: Definition: A homogenous ideal $I \subset K[x_0,\dots,x_n]$ is irrelevant if $\left <x_0^r,\dots,x_n^r \right> \subset I$ for some $r > 0$.
For $I \cap J$, this is probably circular logic, to argue that $\left <x_0^r,\dots,x_n^r \right> \subset I \cap J \subset I$.
This is to say if $\left <x_0^r,\dots,x_n^r \right> \subset I$ and $\left <x_0^u,\dots,x_n^u \right> \subset J.$
For $I + J$, can one just set the second coordinate to be $0$?
Comment: For the intersection, $r$ night not be the same number for both ideals. You have to find a new $r$ that works for both.
Comment: @MattSamuel, what about the sum?
Comment: The sum is proved essentially the way you attempted to prove it for the intersection.
Comment: How do I use the fact that $I$ and $J$ are irrelevant ot help me...?
Answer: Suppose $I$ and $J$ are irrelevant; then $\langle x_0^r,\dots,x_n^r\rangle\subseteq I$ and $\langle x_0^s,\dots,x_n^s\rangle\subseteq J$ for some $r>0$ and $s>0$.
It's not restrictive to assume $r\le s$ (otherwise just switch the roles of $I$ and $J$). Since $x_i^s\in\langle x_0^r,\dots,x_n^r\rangle$, for $i=0,1,\dots,n$, we have
$$
\langle x_0^s,\dots,x_n^s\rangle\subseteq
\langle x_0^r,\dots,x_n^r\rangle\subseteq I
$$
and so
$$
\langle x_0^s,\dots,x_n^s\rangle\subseteq I\cap J
$$
For the sum it's even easier: any ideal containing an irrelevant ideal is irrelevant as well.
Comment: Wait, why are we alowed to assume $r \leq s$?
Comment: @jacobsmith Given two integers $r$ and $s$, one will be less than or equal to the other. If you don't like this style, just repeat the proof for the case $r>s$, but it's not necessary.
Comment: no that perfectly answers it...


How can you derive this integrating factor?

Question: Consider the differential equation $M(x,y)+N(x,y)\frac{dy}{dx}$. If an integrating factor takes the form $\mu=\mu(xy)$, show that the necessary condition is
$$\frac{N_x-M_y}{xM-yN}=F(xy)$$
I am not sure how to go about approaching this problem. Do I need to use relations between $\mu$ and the terms when it's only in terms of $x$ or $y$? Any help would be greatly appreciated. Thanks!
Answer: Hint: Indeed, you need to have
$$(\mu M)_y=(\mu N)_x$$
So $$\mu_y M+\mu M_y=\mu_x N+\mu N_x$$


Derivatives of output w.r.t input on a neural network trained with standardized data

Question: I'm using a neural network to model an unknown function for which I would also like to know the derivatives. The nn has four inputs and four outputs, and the training data is preprocessed using scikit-learn StandardScaler, i.e.,
$$
\hat{\bf{x}} = (\bf{x} - \mu_{x})/\sigma_{x} \quad \text{and} \quad \hat{\bf{y}} = (\bf{y} - \mu_{y})/\sigma_{y}
$$
As a result, I get the standardized data, means, and stds for each variable.
$$
\mu_{x_{1}},\mu_{x_{2}},\mu_{x_{3}},\mu_{x_{4}} \quad \text{and} \quad \mu_{y_{1}},\mu_{y_{2}},\mu_{y_{3}},\mu_{y_{4}}
$$
and
$$
\sigma_{x_{1}},\sigma_{x_{2}},\sigma_{x_{3}},\sigma_{x_{4}} \quad \text{and} \quad \sigma_{y_{1}},\sigma_{y_{2}},\sigma_{y_{3}},\sigma_{y_{4}}
$$
After training, I can use $\mu$ and $\sigma$ to transform the output back to the original scale of the data.
Now, I want to compute the derivatives of the nn output w.r.t the inputs. However, these also seem to be standardized.
$$
\frac{\partial y_{1}}{\partial x_{1}},\frac{\partial y_{1}}{\partial x_{2}},\cdots,\frac{\partial y_{4}}{\partial x_{3}},\frac{\partial y_{4}}{\partial x_{4}}
$$
How do I transform (unscale) the derivatives to the original data scale?
Thanks!
Answer: The derivatives you have are $\frac{\partial y_i}{\partial \hat x_j}$, and you have $\hat x_j=(x_j-\mu_j)/\sigma_j$. So, you just apply the chain rule for the derivative, meaning
$$\frac{\partial y_i}{\partial x_j}=\frac{\partial y_i}{\partial \hat x_j}\frac{\partial \hat x_j}{\partial x_j}=\frac{\partial y_i}{\partial \hat x_j}\frac{1}{\sigma_j}$$
and if the training data for the outputs is also standardized, you can obtain the expression
$$
y_i=\hat y_i\sigma_i + \mu_i
$$
and apply the chain rule twice to get
$$\frac{\partial y_i}{\partial x_j}=\frac{\partial \hat y_i}{\partial \hat x_j}\frac{\partial \hat x_j}{\partial x_j}\frac{\partial y_i}{\partial \hat y_i}=\frac{\partial y_i}{\partial \hat x_j}\frac{\sigma_i}{\sigma_j}$$
However, I'm not sure if this derivative is of any use to you.


Can $\sum_{n=1}^\infty\frac{H_{2n}}{(2n)^3}$, with $H_n$ the $n$-th harmonic number, be written in terms of $\zeta$ values?

Question: The Euler sums are given by
$$S_{p,q} = \sum_{n = 1}^{\infty} \frac{H_{n}^{(p)}}{n^q},$$
where
$$H_{n}^{(p)} = \sum_{j = 1}^{n} \frac{1}{j^p}.$$
According to Wolfram, Eq. (19), the following special case holds:
$$S_{1,3} \equiv \sum_{n = 1}^{\infty} \frac{H_{n}}{n^3} = \frac{5}{4}\zeta(4),$$
where $H_n = H_n^{(1)}$ is the $n$-th harmonic number. I am interested in the following "modified Euler sum":
$$\sum_{n = 1}^{\infty} \frac{H_{2n}}{(2n)^3} \equiv \frac{1}{8} \sum_{n = 1}^{\infty} \frac{H_{2n}}{n^3}.$$
Can it as well be expressed in terms of $\zeta$-values? I have not been able to locate any relevant literature.
Update I: For what it may be worth (it is not even strictly related to the original question of this post, although it does feature sums containing $H_{2n}$), I have been able to derive the following identity:
$$\frac{124}{5}\zeta(5) = 2\pi^{2}\ln2 + \frac{16}{\pi^{2}} \sum_{n=1}^{\infty}[\frac{6H_{n}}{(2n+1)^{4}} + \frac{H_{n}^{(2)}}{(2n+1)^{3}} - \frac{12H_{2n}}{(2n+1)^{4}} - \frac{4H_{2n}^{(2)}}{(2n+1)^{3}}],$$
where $H_{n}^{(2)} \equiv \sum_{k=1}^{n} 1/k^{2}$, as standardly. This has been done by considering a contour integral at infinity (as a limit, of course) of the function
$$f(s) = \frac{\Psi(s)}{s^{3}\cos(\pi s)^{2}},$$
the corresponding sum of all residues having to vanish. However, that identity leaves me no less stuck.
Update II: Using the following family of functions:
$$F_{k}(s) = \frac{\Psi(s)}{s^{k}\sin(\pi s)}[1 + \cos(\pi s)],$$
where $k$ is a natural number, I have been able to establish the following identity [note the condition on $k$]:
$$\sum_{n=1}^{\infty}\frac{H_{2n}}{(2n)^{k}} = 2^{-k} \gamma \zeta(k) + 2^{-(k+2)}(k+1)\zeta(k+1) - \frac{\pi}{4} \rm{Res}(F_{k};0),\text{ for } k \text{ even},$$
where $\rm{Res}(F_{k};0)$ denotes, of course, the residue of $F(s)$ at $s = 0$. It implies the following specific cases [note the presence of $n^{k}$ in the denominators of the sums, not $(2n)^{k}$ as above]
\begin{align}
\sum_{n=1}^{\infty}\frac{H_{2n}}{n^{2}} &= \frac{11 \zeta(3)}{4},\\
\sum_{n=1}^{\infty}\frac{H_{2n}}{n^{4}} &= \frac{37 \zeta(5)}{4} - 4\zeta(2)\zeta(3),\\
\sum_{n=1}^{\infty}\frac{H_{2n}}{n^{6}} &= \frac{135 \zeta(7)}{4} - 16\zeta(2)\zeta(5) - 4\zeta(4)\zeta(3).
\end{align}
Unfortunately, the method fails for k odd, in the sense that the resulting condition (of the sum of residues having to vanish) does not contain any harmonic numbers.
Comment: A CAS gives a rather simple expression except for one very **ugly** term.
Comment: Thanks for your comment. Maple, which I use, seems incapable of manipulating the sum. Are you using Mathematica?
Comment: No, I am using an old CAS which has been improved over the years to fit our needs in my research group.
Comment: @ClaudeLeibovici, you have your own CAS? That's amazing
Comment: @ClaudeLeibovici: Are you able to elaborate a bit on the first comment of yours?
Comment: @YuriyS. No,we started using *Maxima*  long time ago and we added quite many things for our specific needs. Nowdays, it is old, ugly (sometimes bug infested ..)
Comment: @ClaudeLeibovici, is the simple part $\pi^4/144$?
Comment: @YuriyS. Yes, this is the first term.
Answer: \begin{align}
\sum_{n=1}^\infty\frac{H_{2n}}{(2n)^3}&=\frac12\sum_{n=1}^\infty\frac{H_n}{n^3}+\frac12\sum_{n=1}^\infty\frac{(-1)^nH_n}{n^3}\\
&=\frac12\left(\frac54\zeta(4)\right)+\frac12S\\
&=\frac58\zeta(4)+\frac12S
\end{align}
\begin{align}
S&=\sum_{n=1}^\infty\frac{(-1)^n H_n}{n^3}=\frac12\int_0^1\frac{\ln^2x}{x}\sum_{n=1}^\infty H_n(-x)^n\ dx=-\frac12\underbrace{\int_0^1\frac{\ln^2x\ln(1+x)}{x(1+x)}\ dx}_{x=(1-y)/y}\\
&=\frac12\underbrace{\int_{1/2}^1\frac{\ln^2((1-x)/x)\ln(x)}{1-x}\ dx}_{x=1-y}=\frac12\int_0^{1/2}\frac{\ln^2(x/(1-x))\ln(1-x)}{x}\ dx\\
&=\frac12\left(\int_0^{1/2}\frac{\ln^2x\ln(1-x)}{x}\ dx+\int_0^{1/2}\frac{\ln^3(1-x)}{x}\ dx\right)-\int_0^{1/2}\frac{\ln x\ln^2(1-x)}{x}\ dx\\
&=\frac12\left(I_1+I_2\right)-I_3
\end{align}
Applying IBP for the first integral by setting $dv=\ln x/x$ and $u=\ln(1-x)$ and letting $x=1-y$ for the second integral, we have:
\begin{align}
I_1+I_2&=\frac13\ln^42+\frac13\int_0^{1/2}\frac{\ln^3x}{1-x}\ dx+\int_{1/2}^1\frac{\ln^3x}{1-x}\ dx\\
&=\frac13\ln^42+\int_0^1\frac{\ln^3x}{1-x}\ dx-\frac23\int_0^{1/2}\frac{\ln^3x}{1-x}\ dx\\
&=\frac13\ln^42-6\zeta(4)-\frac23\sum_{n=1}^\infty\int_0^{1/2}x^{n-1}\ln^3x\ dx\\
&=\frac13\ln^42-6\zeta(4)+\frac23\sum_{n=1}^\infty\left(\frac{\ln^32}{n2^n}+\frac{3\ln^22}{n^22^n}+\frac{6\ln2}{n^32^n}+\frac{6}{n^42^n}\right)\\
&=4\operatorname{Li_4}\left(\frac12\right)+4\ln2\operatorname{Li_3}\left(\frac12\right)+2\ln^22\operatorname{Li_2}\left(\frac12\right)+\ln^42-6\zeta(4)
\end{align}
Applying IBP for the third integral by setting $dv=\ln x/x$ and $u=\ln^2(1-x)$,
\begin{align}
I_3=\int_0^{1/2}\frac{\ln x\ln^2(1-x)}{x}\ dx&=\frac12\ln^42+\underbrace{\int_0^{1/2}\frac{\ln^2x\ln(1-x)}{1-x}\ dx}_{x=1-y}\\
&=\frac12\ln^42+\int_{1/2}^1\frac{\ln x\ln^2(1-x)}{x}\ dx
\end{align}
By adding the third integral to both sides, we get:
\begin{align}
I_3&=\frac14\ln^42+\frac12\int_0^1\frac{\ln x\ln^2(1-x)}{x}\ dx\\
&=\frac14\ln^42+\sum_{n=1}^\infty\left(\frac{H_n}{n}-\frac{1}{n^2}\right)\int_0^1 x^{n-1}\ln x\ dx\\
&=\frac14\ln^42+\sum_{n=1}^\infty\left(\frac{H_n}{n}-\frac{1}{n^2}\right)\left(-\frac{1}{n^2}\right)\\
&=\frac14\ln^42+\zeta(4)-\sum_{n=1}^\infty\frac{H_n}{n^3}\\
&=\frac14\ln^42-\frac14\zeta(4)
\end{align}
Grouping $I_1, I_2$ and $I_3$:
\begin{align}
S&=2\operatorname{Li_4}\left(\frac12\right)+2\ln2\operatorname{Li_3}\left(\frac12\right)+\ln^22\operatorname{Li_2}\left(\frac12\right)-\frac{11}4\zeta(4)+\frac14\ln^42\\
&=2\operatorname{Li_4}\left(\frac12\right)-\frac{11}4\zeta(4)+\frac74\ln2\zeta(3)-\frac12\ln^22\zeta(2)+\frac{1}{12}\ln^42
\end{align}
note that we used $$\operatorname{Li_3}\left( \frac12\right)=\frac78\zeta(3)-\frac12\ln2\zeta(2)+\frac16\ln^32$$
$$\operatorname{Li_2}\left( \frac12\right) =\frac12\zeta(2)-\frac12\ln^22$$
Finally $$\sum_{n=1}^\infty\frac{H_{2n}}{(2n)^3}=\operatorname{Li_4}\left(\frac12\right)-\frac34\zeta(4)+\frac78\ln2\zeta(3)-\frac14\ln^22\zeta(2)+\frac{1}{24}\ln^42$$
Comment: Thanks for your great efforts (point given). With the help of Maple, I have numerically 'verified' your final expression. But, very sorry to say, it is not of any use to me as it contains the polylogarithm Li(4,1/2), unless of course it can be explicitly evaluated like Li(2,1/2) and Li(3,1/2).
Comment: thank you. I don't think other solutions wont include $Li(4,1/2)$ .
Comment: I believe you are right.
Answer: An attempt to get an expression through the integrals.
$$\sum_{n \geq 1}\frac{H_{2n}}{n^3}=\sum_{n \geq 1}\frac{1}{n^3} \int_0^1 \frac{1-x^{2n}}{1-x}dx=$$
$$\int_0^1 \frac{dx}{1-x} \left(\zeta(3)-\sum_{n \geq 1}\frac{x^{2n}}{n^3} \right)=\int_0^1 \frac{dx}{1-x} \left(\zeta(3)-\text{Li}_3 (x^2)\right)=$$
Let's change the variable to $x=e^{-t}$, then we have:
$$=\int_0^\infty \frac{ dt}{e^t-1} \left(\zeta(3)-\text{Li}_3 (e^{-2t})\right)=$$
There are known integral expressions:
$$\zeta(3)=\frac{1}{2} \int_0^\infty \frac{u^2 du}{e^u-1}$$
$$\text{Li}_3 (e^{-2t})=\frac{1}{2} \int_0^\infty \frac{u^2 du}{e^{2t+u}-1}$$
So we can write:
$$=\frac{1}{2} \int_0^\infty \int_0^\infty\frac{ dt}{e^t-1}\left( \frac{1}{e^u-1}-\frac{1}{e^{2t+u}-1} \right) u^2 du=$$
$$=\frac{1}{2} \int_0^\infty \int_0^\infty\frac{ dt}{e^t-1} \frac{e^u (e^{2t}-1)u^2 du}{(e^u-1)(e^{2t+u}-1)} = \frac{1}{2} \int_0^\infty \int_0^\infty \frac{e^u (e^t+1)u^2  du~dt }{(e^u-1)(e^{2t+u}-1)}$$
So we have:
$$\sum_{n \geq 1}\frac{H_{2n}}{n^3}=\frac{1}{2} \int_0^\infty \int_0^\infty \frac{e^u (e^t+1)u^2  du~dt }{(e^u-1)(e^{2t+u}-1)}$$
We could set:
$$e^{-t}=x \\ e^{-u}=y$$
Then
$$\sum_{n \geq 1}\frac{H_{2n}}{n^3}=\frac{1}{2} \int_0^1 \int_0^1 \frac{ (1+x) \ln^2 y  ~dx~dy }{(1-y)(1-x^2 y)}$$
Which could be separated into two distinct parts:
$$\sum_{n \geq 1}\frac{H_{2n}}{n^3}=\frac{1}{2} \int_0^1 \int_0^1 \frac{  \ln^2 y  ~dx~dy }{(1-y)(1-x^2 y)}+\frac{1}{4} \int_0^1 \int_0^1 \frac{ \ln^2 y  ~dx~dy }{(1-y)(1-x y)}=$$
$$=\frac{1}{2} \int_0^1 \int_0^1 \frac{  \ln^2 y  ~dx~dy }{(1-y)(1-x^2 y)}-\frac{1}{4} \int_0^1 \frac{ \ln^2 y \ln(1-y) ~dy }{y(1-y)}$$
Mathematica gives for that last integral:
$$-\frac{1}{4} \int_0^1 \frac{ \ln^2 y \ln(1-y) ~dy }{y(1-y)}=\frac{\pi^4}{144}$$
So we can write (also taking the first integral w.r.t. $x$):
$$\sum_{n \geq 1}\frac{H_{2n}}{n^3}=\frac{1}{2} \int_0^1 \frac{ \tanh^{-1} \sqrt{y}  \ln^2 y  ~dy }{\sqrt{y}(1-y)}+\frac{\pi^4}{144}$$
The first integral can be simplified:

$$\sum_{n \geq 1}\frac{H_{2n}}{n^3}= 4\int_0^1 \frac{ \tanh^{-1} y  \ln^2 y  ~dy }{1-y^2}+\frac{\pi^4}{144}$$

No idea what to do with the last integral, Mathematica can't take it. However, the integrand is nice, there's not even any singularities.

We could try integration by parts with $$u=\tanh^{-1} y  \ln^2 y \\ dv=\frac{dy }{1-y^2}$$
$$I=\int_0^1 \frac{ \tanh^{-1} y  \ln^2 y  ~dy }{1-y^2}=(\tanh^{-1} y)^2  \ln^2 y \bigg|_0^1-I-2 \int_0^1  (\tanh^{-1} y)^2  \ln y  ~\frac{dy}{y}$$
So:
$$I=-\int_0^1  (\tanh^{-1} y)^2  \ln y  ~\frac{dy}{y}= \int_0^\infty t (\tanh^{-1} e^{-t})^2 dt$$
Not really a simplification, but also an interesting expression.
Moreover, it is very fitting for numerical computation of the integral, because for moderately large $t$ we have $$\tanh^{-1} e^{-t} \asymp e^{-t}$$ and so the integral becomes elementary.
Hence, we can write:
$$\sum_{n \geq 1}\frac{H_{2n}}{n^3} = \frac{\pi^4}{144}+4\int_0^\infty t (\tanh^{-1} e^{-t})^2 dt$$
$$\sum_{n \geq 1}\frac{H_{2n}}{n^3} \approx \frac{\pi^4}{144}+(1+2 \tau) e^{-2 \tau}+ 4\int_0^\tau t (\tanh^{-1} e^{-t})^2 dt$$
Where the last integral can be evaluated with any suitable numerical quadrature. $\tau=5$ already gives $6$ accurate digits for the series.
Comment: Like this?
$8 Li_4(1/2) + 7 ζ(3) log(2) - π^4/15 + (log^4(2))/3 - π^{2 }log^2(2) / 3 = 1.974627536841328495420378724802799591022217356151974$831372.
Comment: Nice way to do it ! $\to +1$
Comment: @ClaudeLeibovici, thank you. I made it a little less messy now
Comment: Thanks a lot for your great efforts (+1 from me). However, with no intention of being ungrateful, the formulas you provide are not of the form I would like: a sum of various $\zeta$-values; or for that matter, in a closed form. An aside: I have numerically verified your last expression, now with the correct factor of 4 in front of the integral :-).
Comment: @JohnFredsted, I would bet there's no expression as a finite sum of zeta values. That said, I don't claim this post answers your question, which is why I said it's an attempt. (Obviously, the term with $\pi^4$ is proportional to $\zeta(4)$)
Comment: @Lysistrata, I'm pretty sure polylogarithm is not a zeta value, but nice expression, how did you derive it?
Comment: @Lysistrata, that should really be added to your answer instead of commented here :)
Comment: @Lysistrata: I am afraid not, as $Li_{4}(1/2)$ is not in terms of fundamental constants, but thanks anyway for your efforts (I agree with Yurie that it deserves to be added to your answer). Perhaps I should be more precise: I would like the sum to be expressed, if at all possible, in closed form in terms of fundamental constants like $\pi$, $e$, $\gamma$, and a finite number of $\zeta$-values.
Answer: Tim Jameson's notes could be helpful:
Polylogarithms, multiple zeta values, and the series of Hjortnaes and Comtet,
https://www.maths.lancs.ac.uk/jameson/polylog.pdf
Comment: Thanks for your reply. It seems to me, though, that the given article contains no $H_{2n}$, but only $H_{n}$ (and $H_{n-1}$).
Comment: Apologies. I thought the biblio might point you to something useful. The only other good recent references to similar work is by Jonathan Borwein (with Zucker and Boersma) in the Ramanujan Journal, and some other notes of his scattered around Uni New South Wales websites and some he wrote with David Bailey.
Comment: No need to apologize. I did not look into the references. Perhaps I should have a go at that. I will let you know if I find something suited for my needs.
Comment: It's taking a while to sift through my notes and mental detritus. Your problem is almost identical to the equation at the bottom of page 12 of
Elementary methods for evaluating Jordan's sums and analogous Euler's type sums and for setting a σ-sum theorem,

G. Bastien.
https://arxiv.org/abs/1301.7662
Comment: Lysistrata: Interesting article, getting closer. It is unfortunate, though, that $a$ is required to be an integer. If $a = 3/2$ was possible, then Eq. (20) would be spot on. The equation you allude to contains $li_{4}$.
Answer: $$ T = \sum_{n\geq 1}\frac{H_n}{(n+1)^3}(-1)^{n+1} = \frac{1}{2}\int_{0}^{1}\frac{\log(1+x)\log^2(x)}{1+x}\,dx$$
can be seen to be equal to
$$ \frac{1}{24} \left(-\pi^4-4 \pi^2 \log^2(2)+4\log^4(2)+96\,\text{Li}_4\left(\tfrac{1}{2}\right)+84\log(2)\zeta(3)\right) $$
due to the polylogarithms machinery (see De Doelder, 1991, also mentioned by Flajolet and Salvy in 1998).
Of course $\sum_{n\geq 1}\frac{H_{2n}}{(2n)^3}$ is a linear combination of $T$,$\zeta(3)$ and $\zeta(4)$, hence it is inextricably related to the "ugly" terms $\log(2)\zeta(3)$ and $\text{Li}_4\left(\frac{1}{2}\right)=\sum_{n\geq 1}\frac{1}{2^n n^4}$.
Comment: Thanks for your reply. Why actually is $\sum_{n \ge 1} \frac{H_{2n}}{(2n)^{3}}$ a linear combination of  $T$, $\zeta(3)$ and $\zeta(4)$? It is not obvious to me, but perhaps I am just being stupid. The paper by Flajolet and Salvy looks highly interesting; thanks a lot for that link.
Comment: $$\sum_{n\geq 1}\frac{H_{2n}}{(2n)^3} = \frac{1}{2}\sum_{n\geq 1}\frac{H_n}{n^3}(1+(-1)^n)$$ Now $\sum_{n\geq 1}\frac{H_n}{n^3}$ is simple and the alternating sum immediately relates to the $T$ above by writing $H_n$ as $H_{n+1}-\frac{1}{n+1}$.
Comment: Thanks, you are absolutely right, of course; I was indeed being stupid :-).


NN Backpropagation: Computing $\frac{{\rm d}E }{{\rm d}y}$.

Question: I would appreciate some help on the following problem: I'm taking Hinton's coursera class on Neural Nets and I'm not sure I understand the step highlighted in the picture (see below).

Background:

$i$ is hidden layer
$j$ is the top layer
Neurons use logistic regression as their activation function

What I understand:
The chain rule allows you to "break down" the partial derivative and introduce a term that is helpful for your calculation:
$$\frac{\partial E}{\partial y_i}=\frac{\partial E}{\partial z_j}\cdot\frac{\partial z_j}{\partial y_i}$$
What I don't understand:
Where does the $\sum_j$ come from?  In other words, what's the proof that you can break down the left term into the sum of 3 components of the top layer (in this case).
Thanks for your help.
Link to class: https://www.coursera.org/learn/neural-networks/lecture/gcNo6/the-backpropagation-algorithm-12-min
Comment: @ConMan It is called the [total derivative](https://en.wikipedia.org/wiki/Total_derivative) : if $g(t) = f(x(t),y(t))$ then $\frac{\partial g}{\partial t} = \frac{\partial f}{\partial x}\frac{\partial x}{\partial t}+\frac{\partial f}{\partial y}\frac{\partial y}{\partial t}$
Comment: @GuillaumeG - I suggest you read up on the Jacobian matrix and the chain rule in higher dimensions. Essentially, the ordinary derivative applies when you've got a single underlying variable that you're differentiating with respect to, and the partial derivatives apply when you're only differentiating with respect to one variable out of many.

The Wikipedia article on the chain rule, particularly the section on higher dimensions, explains it a bit better: https://en.wikipedia.org/wiki/Chain_rule#Higher_dimensions
Comment: It's the chain rule for partial derivatives. Essentially, the derivative in the direction of a given vector is the sum of the derivatives of the components of the vector, weighted appropriately.
Comment: Hi ConMan. Thanks for your comment. I understand the chain rule. Can you explain the steps in between ? The chain rule only allows you to "slide in" one zj. Why the sum  over j ?
Comment: It's a specific version of the chain rule for functions of multiple variables (or equivalently, for functions of vectors). The following link from Khan Academy shows a demonstration (although it looks at the total derivative of the main function, and it's only applied to a 2-variable case): https://www.khanacademy.org/math/multivariable-calculus/multivariable-derivatives/multivariable-chain-rule/v/multivariable-chain-rule
Comment: Thanks ConMan. It starts making sense... Quick question. I see that your link refers to ordinary derivative (whereas I had a partial derivative). How do you reconcile the 2?
Comment: Ok perfect.Thanks @ConMan and user1952009.
Answer: This follows from the multivariate chain rule. Let's assume that $E$ depends on $z=(z_1,\ldots,z_n)$, but each $z_k$ depends on $y=(y_1,\ldots,y_m)$, i.e.
$$ E(z(y))=E(z_1(y),\ldots,z_n(y)). $$
We are interested in how the loss objective $E$ depends on some value in an earlier layer, say the output of the $i$th node, denoted $y_i$, in layer $\xi$, but that output affects $E$ only by its influence on the next layer (i.e., $\xi+1$), whose values we denote $z$.
Recall that in a fully connected network, each layer depends on all the values of the previous layer, so each $z_i$ depends on each $y_k$.
But we only care about $y_i$ for now, meaning we can ignore the other $y_k$, because we are interested in how perturbing $y_i$ affects $E$, and $y_i$ does not affect $E$ via the other $y_k$.
But $y_i$ does affect $E$ through $z$ (and only through $z$ actually).
And $y_i$ affects every $z_k$.
So we need to take the $\partial E / \partial z_k$ into account, as well as the $\partial z_k / \partial y_i$.
The way to combine these into a single number is specified by the multivariate chain rule:
$$ \frac{\partial E}{\partial y_i} = \sum_j  \frac{\partial E}{\partial z_j} \frac{\partial z_j}{\partial y_i}. $$
I'll add links to more formal derivations below.
But the rough intuition is this: $E$ depends on $y_i$ through its effect on each $z_k$ (captured by $\partial z_k / \partial y_i$), so ${\partial E}/{\partial y_i}$ should be a sum of these contributions (if we think of derivatives as a measure of local linear change, we can imagine adding the perturbation vectors induced by tweaking  together).
But not all the contributions to the network are equally important: if a $z_j$ doesn't affect $E$ much (i.e.,${\partial E}/{\partial z_j}$ is small), then the contribution of $y_i$ through $z_j$ should be down-weighted.
So we do a weighted sum over $\partial z_k / \partial y_i$,
with weights given by ${\partial E}/{\partial z_j}$.
Notice that when $n=1$ we recover the classical chain rule.
For more details see the links below.

Other questions on the origin of the multivariate chain rule are here, here, and here.
A related question on the role of the chain rule sum in artificial neural networks is here.


How to communicate within this system?

Question: We intend to design a system with three "tiers".

HQ, with a single server
lots of "nodes" on a regional basis
users, with iPads.

HQ communicates 2-way with the nodes which communciate 2-way with the users. Users never communicate with HQ nor vice-versa.
The powers that be decree a Windows app from HQ (using Delphi) and a native desktop app for the users' iPads.  They have no opinion on the nodes.
If there are compelling technical arguments, I might be able to beat them down from "decree" to "prefer" on the Windows program (and, for isntance, make it browser based). The nodes have no GUI, they just sit there playing middle-man.
What's the best way for these things to communicate (SOAP/HTTP/AJAX/jQuery/home-brewed-protocol-on-top-of-TCP/something-else?) Is it best to use the same protocol end to end, or different protocols for hq<-->node and node<-->iPad?
Both ends of each of those two interfaces might wish to initiate a transaction (which I can easily do if I roll my own protocol), so should I use push/pull/long-poll or what?
I hope that this description makes sense. Please ask questions if it does not. Thanks.

Update:
File size is typcially below 1MB with nothing likely to be above 10MB or even 5MB. No second file will be sent before a first file is acknowledged.
Files flow "downhill" from HQ to node to iPad.  Files will never flow "uphill", but there will be some small packets of data (in addition to acks) which are initiated by user action on the iPad.  These will go to the local node and then to the HQ. We are probably talking <128 bytes.
I suppose there will also be general control & maintenance traffic at a low rate, in all directions.
Answer: For push / pull (publish / subscribe or peer to peer communication), cross-platform message brokers could be used. I am not sure if there are (iOS) client libraries for Microsoft Message Queue (MSMQ), but I would also evaluate open source solutions like HornetQ, Apache ActiveMQ, Apollo, OpenMQ, Apache QPid or RabbitMQ.
All these solutions provide a reliable foundation for distributed messaging, like failover, clustering, persistence, with high performance and many clients attached. On this infrastructure message with any content type (JSON, binary, plain text) can be exchanged, and on top messages can contain routing and priority information. They also support transacted messaging.
There are Delphi and Free Pascal client libraries available for many enterprise quality open source messaging products. (I am am the author of some of them, supporting ActiveMQ, Apollo, HornetQ, OpenMQ and RabbitMQ)
Comment: I think you should have mentioned that you are the author of some of those client libraries.
Comment: I think you should provide URLs for them :-)    +1 & thanks.  YOu have listed many option, but if you *had* to choose, then which would you choose?
Comment: @Mawg: from the message brokers which are supported by Habari JMS Clients, I would recommend to take a look at Apache ActiveMQ. Commercial support available through Fusesource http://fusesource.com/, Fuse message broker is based on ActiveMQ. Two sample chapters (PDF) of the book "ActiveMQ in Action" are at http://www.manning.com/snyder/, a slideshow presentation is at http://www.slideshare.net/bruce.snyder/messaging-with-activemq-presentation. Second would be OpenMQ, a lean and solid product. The Habari client libraries are available from http://www.habarisoft.com/habari.html
Answer: Check out MessagePack: http://msgpack.org/
Also, here's more RPC discussion on SO:

RPC frameworks available?
MessagePack: fast cross-platform serializer and RPC - please share experience

ICE might be of interest to you:  http://zeroc.com/index.html
They have an iOS layer: http://zeroc.com/icetouch/index.html
Answer: IMHO there are too little requisites to decide what technology to use. What data are exchanged, how often, what size? Are there request/response time constraints? etc. etc. Never start selecting a technology before you understand your needs deeply.
Comment: +1 a fair enough comment. In fct, I have updated the question.

How to communicate within this system?


jQuery mouseover event on svg path

Question: I put a svg file on my website like this:
<object id="mysvg" type="image/svg+xml" data="mysvg.svg"></object>

I want to add a jQuery mouseover event on the path and not on the whole object. So the event will not be fired when I also mouseover the transparent areas.
I already tried to change the event from "mysvg" onmouseover to "path" mouseovering to check if it will work in general but I am not able to do it. Is there a way to fire the event only when the mouse is mouseover the generated path of the SVG?
Thanks :)
Comment: You will need to insert the svg directly into the HTML file.
Comment: This seems to work like a charm. Thanks!
Comment: write your mouseover code in the mysvg.svg file.
Answer: You will need to insert the svg directly into the HTML file

jQuery mouseover event on svg path


How to find increasing trend from a python list

Question: I want to print the increasing trend that I am getting between Jan and Mar, Sept to Dec. for the below provided data
Can you please help me with the logic, please.
I have tried the following code but its just not right:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
month=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec']

count=[100,200,300,100,120,100,90,80,90,100,110,120]
dicta={'month':month,'count':count}
input_data=pd.DataFrame(dicta)
print(input_data)
flag=0
counter=[]

indexer=[]
for index in range(len(input_data['count'].values)-1):

print('The index is',index)
a=input_data.iloc[index,0]
b=input_data.iloc[index+1,0]
if b>a:
    flag=flag+1
    print('if loop flag:',flag)
elif flag<2:
    flag=0
    print('elif loop flag')
else:
    counter.append(flag)
    print('else flag',counter)
    flag=0
print(flag)

Answer: You don't necessarily need all those imports for this.
trendList = []
trendStart = 0
trendEnd = 0
valuePrev = 0

count = 0
for value in count:
   count += 1
   if count == 1:
       valuePrev = value
       trendStart = count
   elif valuePrev <= value:     #extend if equal or greater
       trendEnd = count
       valuePrev = value
   else:                        #end trend if current is less
       trendEnd = count - 1
       trendList.append([trendStart,trendEnd])
       trendStart = count
       valuePrev = value
for trend in trendList:
    print str(trend[0]) + " to " + str(trend[1])

note this is looking STRICTLY at the values, not including months
Comment: You can also trim the trendList by:  if trendStart != trendEnd and trendEnd - trendStart > 1: trendList.append([trendStart, trendEnd])
Comment: Thanks for the code. But it identifies only the first trend. Somehow the second trend is not coming properly. Output i got is this:
1to3
4to4
5to5
6to6
7to7
8to8
9to9
10to10
11to11..it should be 8 to 11.
Comment: The code worked out fine once I added trendList.append([trendStart,trendEnd]) at the end of the first for loop.


Hypergeometric functions & integral

Question: I'm having difficulty re-deriving a result a calculation from a paper. The integral is
$$\int_0^{2\pi} \int_0^{2\pi} \frac{\sinh\eta}{(\cosh\eta-\cos\theta)^2}\left(1-c\sinh^2\eta\sin\phi\right)^\frac12d\theta d\phi,$$
where $\eta$ and $c$ are parameters such that $\sinh^2\eta = 2$ and $c\sinh^2\eta < 1.$
From what I've read about hypergeometric functions, one could potentially evaluate this using elliptic integrals of the first and second kind,
\begin{align*}
K(z) &= \int_0^{\pi/2} (1-z^2\sin^2 t)^{-1/2} dt \\
E(z) &= \int_0^{\pi/2} (1-z^2\sin^2 t)^{1/2} dt.
\end{align*}
These can be written in hypergeometric form as
\begin{align*}
K(z) &= \frac{\pi}{2}F(\frac{1}{2},\frac{1}{2};1;z^2)\\
E(z) &= \frac{\pi}{2}F(-\frac{1}{2},\frac{1}{2};1;z^2).
\end{align*}
The expected result of the integral is
$$S = 8\pi^2 \frac{b^2}{a} G_1(c/a).$$
where $a = \sqrt{c^2+b^2}$ and
$$G_1(x) = F(3/2,1/2,1;x^2)+x^2/2F(3/2,3/2,2;x^2).$$
I've tried doing this, but I am inexperienced in these calculations and it's going to take me a while. I'll keep working at it, but I was wondering if anybody could take a look and tell me whether I am even going about this in the right way.
Comment: Why don't you "solve" $$\int_0^{2\pi } {\frac{{\sqrt 2 }}{{{{\left( {\sqrt 3  - \cos \theta } \right)}^2}}}d\theta \int_0^{2\pi } {{{\left( {1 - 2c\sin \phi } \right)}^{\frac{1}{2}}}d\phi ,} } $$ then?
Comment: $$\int_1^\infty\frac{\log(x)}{a+bx}\,\mathrm{d}x$$ In Mathematica: `Integrate[Log(x)/(a+b*x),{x,1,Infinity}]`
Answer: Going off Peter's comment, note that your integral is separable, and can thus be factored into a product of two one-dimensional integrals:
$$\begin{split}&\int_0^{2\pi} \int_0^{2\pi} \frac{\sinh\eta}{(\cosh\eta-\cos\theta)^2}\left(1-c\sinh^2\eta\sin\phi\right)^\frac12\mathrm d\theta\mathrm d\phi=\\&\quad\left(\color{green}{\sinh\eta\int_0^{2\pi} \frac{\mathrm d\theta}{(\cosh\eta-\cos\theta)^2}}\right)\left(\color{blue}{\int_0^{2\pi} \sqrt{1-c\sinh^2\eta\sin\phi} \mathrm d\phi}\right)\end{split}$$
The first integral is elementary:
$$\color{green}{\sinh\eta\int_0^{2\pi} \frac{\mathrm d\theta}{(\cosh\eta-\cos\theta)^2}}=\frac{2\pi\cosh\,\eta}{\sinh^2\eta}$$
while the second requires the services of the incomplete elliptic integral of the second kind $E(\phi\mid m)$ (see Byrd and Friedman, formula 288.01 for the required identity):
$\displaystyle\begin{split}&\color{blue}{\int_0^{2\pi} \sqrt{1-c\sinh^2\eta\sin\phi} \mathrm d\phi}=\\&\Tiny 2\left(\sqrt{\frac{1+c\sinh^2\eta}{1-c\sinh^2\eta}}\;E\left(\arcsin\left(\sqrt{\frac{1+c\sinh^2\eta}{2}}\right)\mid\frac{2c\sinh^2\eta}{1+c\sinh^2\eta}\right)-\frac{c\sinh^2\eta}{\sqrt{1-c\sinh^2\eta}}+2\sqrt{1+c\sinh^2\eta}\;E\left(\frac{\pi}{4}\mid\frac{2c\sinh^2\eta}{1+c\sinh^2\eta}\right)\right)\end{split}$
Comment: J.M.,
thanks so much! I forgot to write this in the OP, but yes, of course let's split the integrals. I didn't know how to integrate $\int_0^{2\pi} (\cosh\eta-\cos\theta)^{-2} d\theta$ -- did you evaluate it or check with Wolfram?

Going to see if the answers agree, will accept if they do. Thanks again!
Comment: "I didn't know how to integrate..." - the Weierstrass substitution $u=\tan(\theta/2)$ is the first thing to try...

Hypergeometric functions & integral


Azure application can't access database on Azure VM

Question: I deployed a Asp.Net Core 2 application to Azure, using Visual Studio Community's Publish feature.  The non-database-dependent parts of the application function, but the database-specific code returns an error.
The application's database is a Sql Server instance installed on a Windows server hosted on a Azure VM (not an Azure SQL database).
To fix this, I:

determined the application's IP address using the Url property (xxx.azurewebsites.net) of the app's blade
added an inbound rule to the network security group's blade that allows all ports from this IP address
added an entry to the VM's Windows firewall to allow ports from this IP address

Unfortunately, this did not solve the problem.  What am I missing?
Incidentally, what's the recommended way to set the ASPNETCORE_ENVIRONMENT to development when publishing to Azure (to enable more-detailed error messages)?
Comment: Regarding your second question, see [.Net Core - Set Environment Variable in Azure Deployment Task](https://stackoverflow.com/questions/38761617/net-core-set-environment-variable-in-azure-deployment-task).
Answer: I am assuming that your web application is deployed to an Azure Web App. You may not have the correct outbound IP address for your VM hosting. Note that a Web App's inbound IP address may be different from the Web App's outbound address. To find the outbound addresses for your Web App, do the following:

Go to your Web App's management blade.
Choose the Properties menu item (under Settings). On this screen, there's a list of possible outbound IP addresses. Try whitelisting them all in your VM's firewall.


How to redirect WCF service calls to different operations based on the message content

Question: I have an operation (method) in a WCF service. the operation has a parameter of Json content.
<code>[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)]
string NotifyAuditLineUpdated(AuditLineUpdatedModel notification);
</code>
For this parameter AuditLineUpdatedModel, I have created a pre-definied class using DataContractAttributes and DataMemberAttributes to map the json message to an object during the deserialization.
However, I have a problem is that the client has a different Json message structures under same field name where I cannot combine all cases in a single class. In other words, the Json message has a field which could have different structure (not value); therefore, I'm trying to direct the call to a different operations which could satisfy the variety of the Json message.
So far I have found that WCF provides routing on the service level. I wonder if possible to route the calls on operation level. In other words, I have a single service with two operations of different parameter types. Is it possible to catch the call and check the message content, and then direct the call to a proper operation based on the message?
For your information, I have tried IDispatchMessageInspector (message inspector feature) of WCF. I was able to check the message content, but I am not able to redirect or change the destination (To uri) address.
Note: In addition, the client service is not able to send different uri requests for the two different cases.
Comment: -"but I am not able to redirect or change the destination (To uri)" - can you tell us why? If you have another service to process the new message type, you surely should be able to create a new service client for that service and process the message using the new service and then return the result back to the original service.
Comment: Hi @KosalaW, when I try to execute the following line, I'm getting an error request.Headers.Add(MessageHeader.CreateHeader("To", "To" , ));
Error Message: Envelope Version 'EnvelopeNone (schemas.microsoft.com/ws/2005/05/envelope/none)'; does not support adding Message Headers
Comment: See my answer below. Let me know if you have further questions. you should not have to add headers for the new service. You only need the body.
Comment: Answer updated to show IDispatchMessageInspector override.
Answer: This is just an example. The code is conceptual and you will have to implement it the way you want.
<code>[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)]
string NotifyAuditLineUpdated(AuditLineUpdatedModel notification);

// you can host this somewhere else
[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)]
string MyInternalService(AuditLineUpdatedModel1 notification);

public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext)
{
    object response;
    var isCallToMyInternalServiceRequired = VerificationMethod(request, out response);
    if(!isCallToMyInternalServiceRequired)
    {
        using(var client = new NotifyAuditLineUpdatedClient())
        {
            return client.NotifyAuditLineUpdated(response as AuditLineUpdatedModel);
        }
    }

    using(var client = new MyInternalServiceClient())
    {
        return client.MyInternalServiceClient(response as AuditLineUpdatedModel1);
    }
}

private bool VerificationMethod(object notification, out object output)
{
    // your validation method.
}
</code>
Comment: I think this is the best answer I got so far, but one thing would made this answer a complete one. Using this solution, I could call any method I need here by name based on the received request, but one thing would still cause an issue is that WCF will call the original client-request method, cannot I fully deviate the call to another method here?


How can I overdrive my tube amp at low volume?

Question: I recently bought a Marshall Origin 20C. Nice tube amp, with a beautiful (clean) sound. It's a single-channel amp, with 3-way EQ, volume and gain pots, brightness pot (called 'tilt') and a 3-lever power output, as well as a "boost" setting.
I can get a very nice clean sound out of it, but if I try to overdrive it, I can't seem to.
I don't gig, and I practice in my bedroom, so I use these settings:

power output set to "low"
"gain" all the way to the max
boost enabled
"volume" down to 1 or 2 to avoid annoying my neighbours.
Using a single-coil strat

Still, the sound is fairly clean, not breaking up much. I have seen several reviews where the amp is overdriven, resulting in a nice crunchy sound.
Is there something else I can try? Or should I just try to replace it with a 5W tube amp instead? The issue is that the Origin 5C does not seem to have a "gain" control.
Edit: I'm aware I can use an overdrive pedal. I want to get the O/D sound from the amp as well!
Thanks!
Comment: The volume pot on your guitar acts rather more like an overdrive control than a volume ccontrol per se at times like this. If that's not flat out, overdrive is unobtainable. Neighbours might not appreciate that. Using a good pair of cans is one solution, another is to use an overdrive or distortion pedal, which means you can keep the volume down.
Comment: I know I can use a pedal, thanks. I have a tube screamer. The thing is that I want to hear the TS interact with the tube distortion. What do you mean by "pair of cans"?
Comment: A pair of cans is worn over the head. There's a small speaker which goes over each ear. Headphones!!
Comment: Hey @Tim , why don't you write that as an answer and I'll accept it? It does add some value. I will also edit the title to "tube amp", so the answer will be more generic
Comment: Did the suggestion indeed solve the problem?
Answer: One option is to hook a "power soak" up to the output of your amp. Marshall used to make one, but I haven't heard of anyone using them in years. A friend of mine used one on stage for years and was very pleased with the way it worked. I suppose you might be able to find out about them by googling. I hope this helps.
Answer: I think what you are looking for is an amp attenuator or what I think the other answer referred to as a "power soak"  It will allow you to crank up the volume on the amp to drive those tubes while 'soaking' up most of the loudness and not getting you evicted while still getting those sweet tube tonez.  I know UA came out with a rather pricy 'the ox'.  Was also recently looking at 2notes that came out with some that also acts as a DI IIRC.
Answer: Marshall Amps are known for good 'gain' sounds.  Guitarist Slash is famous for using them for his classic rock sound, a lot of gain there.
Also single coil compared to humbuckers (or even P90's) are more brighter sounds.  Have your tried another guitar with this amp?
I think you need to turn your volume up more, sorry neighbours.
Answer: Get yourself a set of "YellowJackets" and a pair of EL84 tubes.
Swap out the EL34 tubes for the above configuration.
This will reduce the overall power output and might really sound great with the Hi/Med/Low power switch that amp already has. The EL84 tubes will "break-up" or become over-driven sooner, yet still keep that EL34 British tone.


Prove: $B(p,r)\subseteq B(x_{1},r_{1})\cap B(x_{2},r_{2})$

Question:
Let $(X,d)$ be a metric space such that $x_{1},x_{2}\in X$ and $r_{1},r_{2}>0$ and let assume that $p\in B(x_{1},r_{1})\cap  B(x_{2},r_{2})$. let $r=min\{r_{1}-d(p,x_{1}),r_{2}-d(p,x_{2})\}$ prove:
$$B(p,r)\subseteq B(x_{1},r_{1})\cap B(x_{2},r_{2})$$

Let $y\in B(p,r)$
$d(p,y)\leq d(p,x_{1})+d(x_{1},y)<r_{1}+d(x_{1},y)$ and
$d(p,y)\leq d(p,x_{2})+d(x_{2},y)<r_{2}+d(x_{2},y)$
$d(p,y)<r_{1}+d(x_{1},y)$ and $d(p,y)<r_{2}+d(x_{2},y)$
$d(p,y)-d(x_{1},y)<r_{1}$ and $d(p,y)-d(x_{2},y)<r_{2}$
How should I continue?
Comment: I believe should should rather look at $d(x_1, y)$ than $d(p, y)$, same goes for $x_2$
Answer: Hint: for every ball (skipping indexing):
$$
d(x,y)\le d(x,p)+d(p,y)\le d(p,x)+r-d(p,x)=r.
$$
Answer: If $y\in B(p, r)$, then $$d(p, y)<r\leq r_1-d(p, x_1)\Rightarrow d(p, y)+d(p, x_1)< r_1\Rightarrow d(y, x_1)< r_1\Rightarrow y\in B(x_1, r_1)$$ because $d(y, x_1)\leq d(p, y)+d(p, x_1)$ by triangle inequality. Similarly $y\in B(x_2, r_2)$.
Answer: Let $y\in B(p,r)$. So $d(p,y)<r$. Then $d(p,y)<r\leq r_1-d(p,x_1)$ and $d(p,y)<r\leq r_2-d(p,x_2)$. So $d(p,y)+d(p,x_1)< r_1$ and $d(p,y)+d(p,x_2)< r_2$. Therefore $d(y,x_1)< r_1$ and $d(y,x_2)< r_2$. Hence $y\in B(x_{1},r_{1})\cap B(x_{2},r_{2})$


Guitar Pick-up issue

Question: I've just bought a second hand ESP'81 humbucker pickup and have stuck it in a Les Paul project guitar of mine.
I am by no means an expert but I've used the wiring diagrams available to put it in there and everything seems to be soldered correctly.
On first plug-in the pickup sounded really thin, quiet and a little distorted in comparison to the stock neck pup I already had in the guitar.
I've just run a voltmeter over the '81 and i got a reading of 58.9ohms which seems like an insane amount of resistance.
Could this be the reason it sounds so weak? Do you have any suggestions for making the pup sing?
Answer: Reading the Wikipedia page for this item, the output impedance is rated at 10 k ohms.  However, you cannot measure output impedance by sticking an ohmmeter across the leads.
  Simple things to check:   is the full 9V showing on the battery output?  When you turn up the gain & pluck strongly , what is the output voltage? -- Wiki says it's rated around 4.5 V peak,  3 V rms.  Make sure your voltmeter is high enough impedance not to pull down the output.

Guitar Pick-up issue


Implementing Bayesian Linear Regression using PyMC3

Question: I am learning a Bayesian Approach towards implementing Linear Regression.
The motivation is that Bayesian Approach gives you a range on predictions which might be useful when investing money in capital markets or for any medical research.
So far what I've understood is that given a linear equation we are trying to estimate equation parameters using Bayes' theorem as suggested in this link.
According to Bayes' Theorem
$$ posterior \propto likelihood \times prior $$
What is the mathematical proof that in case of linear regression
if likelihood is $$ Y|X,\theta \sim N(\alpha \space + \space \beta x, \epsilon^2)  $$
and prior for mu $$ \mu \sim N(\mu, \sigma^2) $$ & prior for sigma is $$ \epsilon^2 \sim IG(\alpha,\beta) $$
then posterior distribution would be Normal Distribution.
Using this link I've implemented a basic linear regression example in python for which the code is
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pymc3 as pm
from scipy import optimize

alpha, sigma = 1, 1
beta = [1, 2.5]

# Size of dataset
size = 100

# Predictor variable
X1 = np.linspace(0, 1, size)
X2 = np.linspace(0,.2, size)

Y = alpha + beta[0]*X1 + beta[1]*X2 + np.random.randn(size)*sigma

# plt.plot(Y)
# plt.show()

basic_model = pm.Model()

with basic_model:
    # Priors for unknown model parameters
    alpha = pm.Normal('alpha', mu=0, sd=10)
    beta = pm.Normal('beta', mu=0, sd=10, shape=2)
    sigma = pm.HalfNormal('sigma', sd=1)

    # Expected value of outcome
    mu = alpha + beta[0]*X1 + beta[1]*X2

    # Likelihood (sampling distribution) of observations
    Y_obs = pm.Normal('Y_obs', mu=mu, sd=sigma, observed=Y)

    # obtain starting values via MAP
    start = pm.find_MAP(fmin=optimize.fmin_powell)

    # instantiate sampler
    step = pm.NUTS(scaling=start)

    trace = pm.sample(2000, step, start=start, cores=4)

pm.traceplot(trace)
plt.show()

pm.summary(trace)

summary_df = pm.summary(trace)

predictions = summary_df.loc['alpha','mean'] + summary_df.loc['beta__0','mean']*X1 + summary_df.loc['beta__1','mean']*X2 + np.random.randn(size)*summary_df.loc['sigma','mean']
upper_limit = summary_df.loc['alpha','hpd_97.5'] + summary_df.loc['beta__0','hpd_97.5']*X1 + summary_df.loc['beta__1','hpd_97.5']*X2 + np.random.randn(size)*summary_df.loc['sigma','hpd_97.5']
lower_limit = summary_df.loc['alpha','hpd_2.5'] + summary_df.loc['beta__0','hpd_2.5']*X1 + summary_df.loc['beta__1','hpd_2.5']*X2 + np.random.randn(size)*summary_df.loc['sigma','hpd_2.5']

plt.plot(predictions, label='Predictions')
plt.plot(upper_limit, label='Upper Limit')
plt.plot(lower_limit, label='Lower Limit')
plt.plot(Y, label='Actual')
plt.legend()
plt.show()

After analyzing the results from summary of trace plot I've observed that the estimates for beta__0 and beta__1 are not good. Below are the results.
             mean        sd  mc_error    hpd_2.5   hpd_97.5        n_eff      Rhat
alpha    0.992383  0.196083  0.002652   0.614840   1.381226  4978.643737  0.999964
beta__0  1.609108  1.973816  0.064427  -2.174173   5.570459   905.298746  1.001097
beta__1  0.099368  9.739603  0.321035 -19.832449  18.345334   889.614045  1.001005
sigma    0.989427  0.071813  0.000799   0.858429   1.137455  7452.629272  1.000030

Questions for which I need an answer are as follows:

Proof to the above mentioned prior and likelihood would give a posterior which follows a normal distribution.
I expected beta__0 to be approx 1 and beta__1 to be approx 2.5. Is there any reason that justify the bad results? In case of alpha and sigma the value of mean is approx. 1 which is quite close to actual value 1 that was used while generating dummy data.
How do we decide on likelihood and prior distributions when estimating model parameters using bayesian? Do I need to change sigma = pm.HalfNormal('sigma', sd=1) in code to IG distribution?
Is the implemented code for making predictions correct? I've used hpd_2.5 and hpd_97.5 as a lower and upper bound respectively to generate range of predictions is that correct? If yes, then how can upper limit values be lesser than value of lower limit?

Edit: Updated code with prediction vs actual plot. Not sure if the implementation is correct.
Comment: Per first question, see: https://en.wikipedia.org/wiki/Bayes'_theorem#Derivation
Comment: @alanocallaghan couldn't find any derivation proving that prior and posterior are conjugate distributions.
Comment: $p(\theta|X) \propto P(X|\theta) p(\theta)$ or as you put it $ \text{posterior} \propto\text{likelihood} \times \text{prior} $ is a general statement of Bayes theorem (ignoring the normalising constant) and does not depend on conjugacy. If you want a derivation of conjugacy for regression, see https://en.wikipedia.org/wiki/Bayesian_linear_regression and in particular you may find the referenced "O'Hagan, Anthony (1994). Bayesian Inference" useful.
Comment: The conjugate prior for linear regression is normal-inverse-gamma, not the normal and half-normal prior you've used.
Comment: @alanocallaghan is it wrong if we take normal and half-normal prior rather than normal-inverse-gamma? We won't be able to find analytically the conjugate prior in case of any complex equation. What would be done in that case?
Comment: I don't know what you mean by "find the conjugate prior analytically". You can find the posterior analytically if the prior is conjugate to the likelihood. As for whether this is an issue, HMC/NUTS and variational inference as implemented in PyMC3 don't require conjugacy, so no it's not a problem.
Answer: The reason you are getting bad results is because your X1 and X2 are perfectly correlated. Therefore there are many combinations of beta1 and beta2 that have the same result.
Use randomly selected X1 and X2 ( instead of linspace) for example to remove this problem.
To get credible intervals for the predictions, you just use the trace to calculate Y for each set of coefficients in your trace. That gives you samples from  posterior distribution of Y, and then need to calculate hpd ( probably pymc has function to calculate hpd given posterior sample)


Why these two songs sound similar?

Question: I'm not a music theory expert but found two songs that sound suspiciously similar and no information on the internet as to why, when or even if a major artist intentionally tried to pay homage or elegantly remix a song by a lesser known group. I'd like to know if the songs are indeed similar or if it is only my deceived perception. The songs in question are Contact by Daft Punk, starting at ~1:46, and When the Catholic Girls Go Camping by Giraffes? Giraffes!, starting at ~0:11.
Aren't the drum tempos and melodic progression the same in some sections of the songs? Are these songs close enough to consider Contact inspired or copied from When the Catholic Girls Go Camping?
Comment: I'm voting to close this question because in retrospect, the question doesn't fit this site. It would have been better on MusicFans, but is now too old to migrate.
Answer: The Giraffes? Giraffes! recording was released before the Daft Punk recording, but that doesn't necessarily tell us when either was written.
To me the obvious difference is with meters. Giraffes? Giraffes! mixes meters, but the Daft Punk stays in 4/4 time.
It's hard to compare the tempos with different meters, but the Giraffes? Giraffes! track feels faster to me.
They both have a kind of arpeggiated figure that moves upward, quickly, with an even rhythm. I think they both start on a minor chord, but they aren't exactly the same.
Was Daft Punk inspired by Giraffes? Giraffes! (?) Maybe. Did they copy the music?... The Daft Punk song uses a I V vi IV progression over and over which makes it seems pointless to talk about melodies and progressions. This kind of musical material is used in hundreds on songs. This music is about rhythm and sound production, not original melodic and harmonic ideas, and on those points the two tracks seem very different to me.
Personally, I am familiar with the Giraffes? Giraffes! track, but not the Daft Punk, and I prefer the one by Giraffes? Giraffes! Nevertheless, I don't think the Daft Punk track is a rip off.

Why these two songs sound similar?


Bean Validation Client-Side

Question: I have a problem with Bean Validation. If I generate the Code with wsimport all the generated models don't have the annotations on the fields. So when I validate the object it doesn't recognise any ContraintViolation.
Does anyone have a solution for this? Or does Bean Validation not work with wsimport?
Some Info:
Serverside => JAX-WS with Tomcat 8.0 and Metro
Clientside => JavaFX
Answer: Usually you would not validate a bean which is supposed to send to a remote endpoint. First of all you would have to duplicate any validation logic in the "client".
Second there might be other restrains then your bean validation. E.g. Business validation of any type.
I suggest you implement an endpoint which does the validation and sends back any validation result to the client.
Please do not neglect to validate before any change to the model is done. You can not trust any data send by a client.

Bean Validation Client-Side


Axiom of Regularity implies $X$ has an $\epsilon_x$-minimal element (wrong proof).

Question: Prove the next equivalence:
(1) Axiom or Regularity
(2) If $X$ is a non-empty set, $X$ has an $\epsilon_x$-minimal element. This means, There exists a $z \in x$ such that $\lnot (x \in_x z )$ for all $x \in X.$
I got (1) $\rightarrow$ (2) wrong in an exam.
Because I didn't prove that "the $z$ existed." I am not being able to understand this observation, and so, I don't know how to correct this proof, or taking it into the right direction. So here's my attempt:
The Axiom of Regularity says: Let $A$ be a set, with $A \neq \emptyset $.  There exists an $a \in X$ such that, if $b \in a$, then $b$ is not in $A$.
Proof. As $X$ is not empty, there exists a $z\in X$. If $z\in X, $ and for some $x$, $x\in X$ then, by the Axiom of Regularity, $x \notin_x z.$
So, $\lnot(x \in_x z).$
Comment: What does "$\in_x$" mean?
Comment: It means $\in$ restricted to the set $x$
Comment: Then you should write "$\in_X$" instead of "$\in_x$" (and usually we'd just write "$\in$," since we don't treat different membership relations simultaneously).
Answer: Your second-to-last sentence is a non-sequitur. If I understand it correctly, you're trying to say "If $x\in X$, then by regularity $x\not\in z$," where your assumption on $z$ is just "$z$ is in $X$."
But this isn't enough to conclude what you want! Consider $X=\{1, \{1\}\}$ and take $z=\{1\},x=1$. Then $z\in X, x\in X$, but $x\in z$.
Comment: If I exchange the choices of $x$, $z$for, "If $x\in X, $ and for some $z$, $x\in X$ then, by the Axiom of Regularity, $x \notin_x z.$
So, $\lnot(x \in_x z),$" there would be still something missing?
Comment: @Trux "by the Axiom of Regularity, $x\not\in z$." **How are you arguing this**? Right now $x$ and $z$ are just arbitrary elements of $X$; there's no reason for $x$ to not be an element of $z$. The axiom of regularity tells us that $X$ has some element $z$ with a certain property; you need to *use* the axiom of regularity, not just assert that it solves the problem. (Also what does "for some $z$, x\in X$" mean? We already know $x\in X$ by the previous phrase.)
Comment: By contradiction. Because of, Axiom of regularity, there exists an $x$, such that, if $x \in_x z$  then $x$ is not in $X.$ But $x \in X$, so $x \notin_x z$.
Comment: You have a typo in your statement of the axiom - that should be "there exists a $z$." More to the point, note that the way you use regularity is to *introduce* an element - e.g. "By regularity, there is some $z$ such that ..." You didn't do that at all in your original answer.


How to negate the definition of continuity using Generalized De Morgan's Law.

Question: The difinition of the Continuity is the following.
$f(x)$ is continuous at a point $a$ means for every $\epsilon > 0$ , we will get a $\delta > 0$ such that $|f(x) - f(a) < \epsilon|$ for all $x$ satisfying $|x - a| < \delta .$
By using quantifiers , we can write $(\forall \epsilon > 0) (\exists \delta > 0 ) [ \forall x ( |x- a | < \delta \implies |f(x) - f(a) | < \epsilon )]$
The negation of the above statement will be '$( \exists \epsilon > 0) ( \forall \delta > 0 ) [\exists c (|c - a | < \delta \implies |f(c) - f(a)  | \geq \epsilon )]$ .'
But I want to know how to do that using generalized De morgan's Law. Can anyone please help me?
Comment: Why [Generalized DeMorgan's Laws](https://math.stackexchange.com/questions/1542248/generalized-demorgans-law-proof) ?
Answer: The negation of the statement $A\implies B$ is not $A\implies \neg B$. The negation of the statement $A\implies B$ is, in fact, $A\land \neg B$. This can easily be seen if you rewrite $A\implies B$ as $\neg A\lor B$ (that's the definition of implication), then applying De Morgan's law.
Therefore, your solution is incorrect.
Comment: @sani For any expression $A$ and $B$, the expression $\neg(A\implies B)$ is equivalent to $\neg A\land B$, and **not** $A\implies \neg B$. Therefore, when negating the expression $|x-a|<\delta\implies|f(x)-f(a)|<\epsilon$, the negation of this expression is **not** $|x-a|<\delta\implies|f(x)-f(a)|\geq\epsilon$.
Comment: @sani Also, why did you invert two of your quantifiers, but not the third?
Comment: I did not understand your solution. What are A and B ? Why my solution is incorrect ? Please clearly mention.
Comment: Please read the whole expression. You might have missed the first two quantifiers in negated statement.
Comment: Instead of this ---$\exists  \varepsilon > 0 \ \ \  \ \forall \delta > 0 \ \ \ \ \exists x\in D  \ \ \ \left( |x-x_0|< \delta \wedge |f(x)-f(x_0)|\geq\varepsilon \right)$ , can I write -- $\exists  \varepsilon > 0 \ \ \  \ \forall \delta > 0 \ \ \ \ \exists x\in D  \ \ \ \left( |x-x_0|< \delta \implies|f(x)-f(x_0)|\geq\varepsilon \right)$ @5xum
Comment: Can you please answer my query? I am waiting. I am really confused if these two statements are equivalent or not. @5xum
Comment: @sani  I already told you. No, the statement $A\implies \neg B$ is **not** equivalent to $A\land \neg B$. That's still true no matter how many quantifiers you put in front of it.


Django Foreign key. Access in template

Question: I learn Django ORM. How can I get Photo in my template?
def index(request):
    animal = Animal.objects.all()
    return render_to_response('animal.html',
                              {'animal':animal,},
                              context_instance=RequestContext(request))

template:
{{ animal.name }}
{{ animal.photo.all }}

but this not working.
models:
class Animal(models.Model):
    name = models.CharField(max_length=255)

class Photo(models.Model):
    photo = models.ImageField(upload_to='media/images')
    animal = models.ForeignKey(Animal)

Answer: You need to read the documentation on following relationships to see how do you access related items.
In your case, each animal has a photo_set which is a way to get a list of all the photo objects belonging to that animal.
In your template, you would do:
{{ animal.name }}
{% for picture in animal.photo_set.all %}

{% endfor %}

Django Foreign key. Access in template


Transforming an image classification model into a hierarchical model

Question: I am using ResNet50 for extracting features from images. How I can remove the classification head of the network and  also because I need to split the network to have intermediate features how I can transform the network into such a hierarchical form that I can access to the intermediate network architecture as follows:
import torch
from torchvision.models import resnet50, ResNet50_Weights
import torch.nn as nn

class model(nn.Module):
    def __init__(self, pretrained=True):
        super(model, self).__init__()

        self.featureExtractor = resnet50(weights=ResNet50_Weights.IMAGENET1K_V2)

def forward(self, x):

      x1= self.featureExtractor_1(x)     #(number of feature maps:256)
      x2= self.featureExtractor_2(x1)    # (number of feature maps:512)
      x3= self.featureExtractor_3(x2)    # (number of feature maps:1024)
      x4= self.featureExtractor_4(x3)    # (number of feature maps:2048)

 return x1, x2, x3, x4

Although I know how to extract the intermediate features of the network by using hook method I do not know to to split the network into such a hierarchy?
Any idea?
Answer: You can do as follows:
import torch
from torchvision.models import resnet50, ResNet50_Weights
import torch.nn as nn

class model(nn.Module):
    def __init__(self):
        super(model, self).__init__()

        self.model = resnet50(weights=ResNet50_Weights.IMAGENET1K_V2)
        self.block1 = nn.Sequential(*list(self.model.children())[:5])
        self.block2 = nn.Sequential(*list(self.model.children())[5:6])
        self.block3 = nn.Sequential(*list(self.model.children())[6:7])
        self.block4 = nn.Sequential(*list(self.model.children())[7:8])

    def forward(self, x):

        x1 = self.block1(x)
        x2 = self.block2(x1)
        x3 = self.block3(x2)
        x4 = self.block4(x3)

        return(x1, x2, x3, x4)

x = torch.randn(1, 3, 256, 256)
model = model()
x1, x2, x3, x4 = model(x)

print(x1.shape, x2.shape, x3.shape, x4.shape)

Which gives:
torch.Size([1, 256, 64, 64]) torch.Size([1, 512, 32, 32]) torch.Size([1, 1024, 16, 16]) torch.Size([1, 2048, 8, 8])


Solving equations in cosines

Question: Consider the equation $9x^4+27x^3-33x^2-153x-101=0$. Its Galois Group is $C_4$. That means by Kronecker-Weber theorem that it is solvable in cosines. How can you find this solution?
For example, $x^3-3x+1$ has three nice roots: $2\cos{\pi\over 9}$,$2\cos{7\pi \over 9}$,$2\cos{13\pi \over 9}$. Of course, the equation above won't have such nice roots: but they must be expressible as linear combinations of cosines!
I am really interested in finding them. Thanks.
Comment: Are you looking for the roots? A procedure to find the roots? IT turns out that this can be solved by solving only quadratic functions, and so can be expressed using radicals. Is that what you want?Here are the roots: $[-\frac{\sqrt{6}\,\sqrt{13}+2\,\sqrt{5}\,\sqrt{13-3\,\sqrt{13}}+3\,\sqrt{6}}{4\,\sqrt{6}},-\frac{\sqrt{6}\,\sqrt{13}-2\,\sqrt{5}\,\sqrt{13-3\,\sqrt{13}}+3\,\sqrt{6}}{4\,\sqrt{6}},-\frac{2\,\sqrt{5}\,\sqrt{3\,\sqrt{13}+13}-\sqrt{6}\,\sqrt{13}+3\,\sqrt{6}}{4\,\sqrt{6}},\frac{2\,\sqrt{5}\,\sqrt{3\,\sqrt{13}+13}+\sqrt{6}\,\sqrt{13}-3\,\sqrt{6}}{4\,\sqrt{6}}]$
Comment: How do you know that the Galois group is $C_4?$
Comment: No, I can find roots using Ferrari's method myself
Answer: Here's a sketch of an algorithm. (No guarantees of speed.) Let $\alpha$ be a root of the polynomial $f$.

Compute the discriminant of $\mathbb Q(\alpha)$. Here it's $d:=3^2 \cdot 5^2 \cdot 13^3$.

We know that $\alpha \in \mathbb Q(\zeta_{d})$, but the degree is too large to compute in.
By Galois theory, there is a subgroup $H$ of $(\mathbb Z/d)^{\times}$ such that $\mathbb Q(\alpha)=Q(\zeta_{d})^H$, where the element $j\in (\mathbb Z/d)^{\times}$ is associated with $\zeta_d\mapsto \zeta_d^j$ in $G(\mathbb Q(\zeta_d)/\mathbb Q)$. We have $\mathbb Q(\zeta_{d})^H=\mathbb Q(\beta)$ where $\beta =\sum_{j\in H}\zeta^j$ is a sum of roots of unity (and hence cosines). How to find $H$?
Define the splitting set $\text{Spl}(f)$ to be the $p$ such that $f$ splits completely modulo $p$. By class field theory, $\text{Spl}(f)\bmod d=H$ (except possibly for primes that ramify).

Compute $H\subseteq (\mathbb Z/d)^{\times}$ by seeing if $f$ splits completely modulo lot of small primes, until these primes generate a subgroup of index 4.
Let $\beta =\sum_{j\in H}\zeta^j$ (probably find a quadratic satisfied by $\beta$ first) and factor $f$ in $\mathbb Q(\beta)$.

Solving equations in cosines


Surjective map from polynomial ring over a field to the field.

Question: Let $z\in R$ be fixed then the map $\phi:R[x]\rightarrow R $ defined as $\phi(f(x))=f(z)$ is surjective? Could someone please explain me why it is.
Comment: What if instead of $R$ there is $C$?
Comment: The proofs given by Math Gens, egreg, Clive make no assumption about the field / wirk with any field (in fact, with any ring)
Comment: Link to OP's [generalization](http://math.stackexchange.com/q/322365/23500), where $\phi:R[x]\rightarrow C.\ \ $
Answer: Let $r \in R$; where does $\phi$ send the polynomial $f$ given by $f(x)=x+r-z$?
[Edit] Or, far more simply, consider $f(x)=r$, as egreg points out in the comments.
Comment: Or the constant polynomial $f(x)=r$.
Comment: Ha! I never see the simple solution.
Answer: Hint $\,\ \phi\ $ restricts to the identity map on $\rm\,R,\:$ i.e. constants evaluate to themselves.