binomial expression of a powered term

Question: One answer to a previous question of mine asserted that $$k^2=\binom k2+\binom {k+1}2.$$
I checked that the formula is true. However, it intrigued me. Is there a similar expression for $k^3$? How would I find a binomial for $k^n$? This is not a duplicate question to the best of my knowledge.
Comment: I think this question is worthwhile keeping, I would like to answer it before it is closed.
Comment: Glad to know that you found that intriguing. As others have pointed out, the coefficients are Euler numbers. You can arrange them in a nice Pascal-like triangle format. There are some similarities: the first and last numbers of each row are $1$, and numbers on each row are symmetrical about the centre. For the $m$-th row (i.e. coefficients for the expansion of $k^m$), the numbers add up to m!. That said, one wouldn't need to know about Euler numbers to express $k^2$ in terms of binomial coefficients.
Answer: I looked this up on OEIS A008292 and
Wikipedia.
Apparently
$$k^m = \sum_{q=0}^{m-1} {k+q\choose m}
\langle {m\atop q}\rangle$$
with  $\langle  {m\atop  q}\rangle$  the Eulerian  numbers  that  have
generating function
$$\frac{t-1}{t-\exp((t-1)z)}.$$
We now prove this summation formula.
We have the following exponential generating function
$$G_k(z) = \sum_{m\ge 0} k^m \frac{z^m}{m!} = \exp(kz).$$
On the other hand the sum formula gives the EGF
$$H_k(z) = \sum_{m\ge 0}
\frac{z^m}{m!} \sum_{q=0}^{m-1} {k+q\choose m}
\langle {m\atop q}\rangle.$$
We can extend this to $q=m$ because the Eulerian number
$\langle {m\atop m}\rangle$ is zero to get
$$\sum_{m\ge 0}
\frac{z^m}{m!} \sum_{q=0}^{m} {k+q\choose m}
\langle {m\atop q}\rangle
\\ = \sum_{q\ge 0} \sum_{m\ge q}
{k+q\choose m} \frac{z^m}{m!}
\langle {m\atop q}\rangle.$$
Now introduce
$${k+q\choose m}
= \frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{(1+w)^{k+q}}{w^{m+1}} \; dw.$$
Substitute this into the sum to get
$$\frac{1}{2\pi i}
\int_{|w|=\epsilon}
\sum_{q\ge 0} \frac{(1+w)^{k+q}}{w}
\sum_{m\ge q} \frac{1}{w^m} \frac{z^m}{m!}
\langle {m\atop q}\rangle \; dw
\\ = \frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{(1+w)^{k}}{w}
\sum_{q\ge 0} (1+w)^q
\sum_{m\ge q} \frac{1}{w^m} \frac{z^m}{m!}
\langle {m\atop q}\rangle \; dw.$$
Now what we have here is a double
annihilated coefficient extractor
which we now collapse:
$$\frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{(1+w)^{k}}{w}
\sum_{q\ge 0} (1+w)^q
[t^q] \frac{t-1}{t-\exp((t-1)z/w)} \; dw
\\ = \frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{(1+w)^{k}}{w}
\frac{w}{1+w-\exp(z)} \; dw
\\ = \frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{(1+w)^{k}}{1+w-\exp(z)} \; dw.$$
The contribution  from the  pole at $w=\exp(z)-1$  which is  simple is
precisely
$$(1+(\exp(z)-1))^k = \exp(kz) = G_k(z),$$
QED.
There is another annihilated coefficient extractor at this
MSE link I and at this
MSE link II and also here at this MSE link III.
The Maple code for the initial lookup at the OEIS was as follows:

Q :=
proc(m)
    local s, sys, sol;

    s := expand(add(a[q]*binomial(k+q,m), q=0..m-1));

    sys := [coeff(s, k, m)=1];
    sys :=
    [op(sys), seq(coeff(s, k, q)=0, q=0..m-1)];

    sol := solve(sys, [seq(a[q], q=0..m-1)]);
    subs(sol[1], [seq(a[q], q=0..m-1)]);
end;
Answer: I'm not sure if there's a good way to do this in the general case, but just playing around with $k^3$, you know you need something with $\binom{k}{3}$ to get the cubic term. So:
$$\begin{split}
\binom{k}{3} &= \frac{k(k-1)(k-2)}6 = \frac{k^3-3k^2+2k}6 \\
\binom{k+1}{3} &= \frac{k(k+1)(k-1)}6 = \frac{k^3-k}6 \\
\binom{k+2}{3} &= \frac{k(k+2)(k+1)}6 = \frac{k^3+3k^2+2k}6
\end{split}$$
Adding the first and third lines lets you get rid of the $k^2$ term:
$$\binom{k}{3} + \binom{k+2}{3} = \frac{2k^3 + 4k}6$$
And then adding in 4 times the second line lets you get rid of the $k$ term:
$$\binom{k}{3} + 4\binom{k+1}{3} + \binom{k+2}{3} = k^3$$
Through similar fiddling, I can come up with:
$$k^4 = \binom{k}{4} + 11\binom{k+1}{4} + 11\binom{k+2}{4} + \binom{k+3}{4}$$
Though I do not know what the pattern is here.
Answer: By counting you have this:
$n^3$ is the ways to color $3$ objects with $n$ colors. So you can either color them with $1$ color in $n$ ways, or with $2$ colors, so you must choose the colors in $\binom{n}{2}$ ways and you choose which elements you want to color in $\binom{3}{2}2$, or in three colors in $\binom{n}{3}3!$ ways. By sum principle and applying a lot Pascal recurrence, you get
$$n^3=n+2\binom{3}{2}\binom{n}{2}+3!\binom{n}{3}=n+3!(\binom{n}{3}+\binom{n}{2})=\binom{n}{1}+\binom{n}{2}+5\binom{n}{2}+6\binom{n}{3}=\binom{n+1}{2}+5(\binom{n}{2}+\binom{n}{3})+\binom{n}{3}=\binom{n}{3}+5\binom{n+1}{3}+\binom{n+1}{2}=\binom{n}{3}+4\binom{n+1}{3}+\binom{n+2}{3}$$
Edit:(partial guess to generalize) It has something to do with Stirling numbers of the second kind. I used them in my counting, indeed $k^n=\sum _{i=1}^n\binom{k}{i}S_{n,i}i!$. and using that $i!S_{n,i}=\sum_{j=0}^i(-1)^{i-j}\binom{i}{j}i^n$ and somehow use Pascal recurrence over it.

binomial expression of a powered term


How can I add a comment form?

Question: I'm using views to display the fields of nodes. I prefer to use fields because it allows me to use relationships (bring in author profile picture etc.). Adding the Content: Comments field shows the list of comments as well as the comment form for each node. However, when hiding and rewriting the result and/or using the replacement pattern for Content: Comments, the comment form disappears.
What methods can I use to display the comment form for each node?
Comment: well for starters whay not make a custom block and attach it to you view as a footer ...
then look at the way core comments form works and build the form into that block ?
Comment: If I place a custom block into the view's footer, it will only show one block per view. I'm trying to place the comment form as a field per node. There was a module called Views PHP for Drupal 7, which allowed inserting PHP into the rows, however this was considered bad practice.
Answer:
However, when hiding and rewriting the result/and or using the
replacement pattern for Content: Comments, the comment form disappears
and only the comment list remains.

It's due to a Views UI bug as I was able to replicate the issue on a fresh install.
A workaround you can do is to do the re-writing via template file rather than via UI.
In your theme's /templates folder add:
views-view-fields--view-name--machine-name.html.twig
and print the view fields there
<code>{{ fields.title.content }} {# title field #}

{{ fields.comment.content }} {# comment field #}

{{ fields.field_name.content }} {# some other field #}
</code>
Flush all caches so template gets pickedup.

How can I add a comment form?


How to make plot titles more legible with matplotlib

Question: I'm running some ML algorithms and I have to output 25 plots, all same dataset but different values of lambda and sigma. Now the way they are outputting isn't ideal as you can't read the titles to know what the corresponding lambda, sigma values are. It also gives me an error when I use plt.tight_layout() saying UserWarning: Tight layout not applied. tight_layout cannot make axes width small enough to accommodate all axes decorations - which makes sense, I assume there's too many plots on one line to do this. Is there a way to do this 5x5 or do I need to split up the plots differently?
sigma_lst = np.logspace(1, 10, 5)
lambda_lst = np.logspace(1, 10, 5)

fig, axs = plt.subplots(5, 5,figsize=(15,15))

for lam in range(lambda_lst.shape[0]):
    for sig in range(sigma_lst.shape[0]):
        c = regularizedKernLSTrain(Xtr, Ytr, 'gaussian', sigma=sigma_lst[sig], lam=lambda_lst[lam])
        separatingFKernRLS(c, Xtr, Ytr, 'gaussian', sigma=sigma_lst[sig], Xte=Xts, axs=axs[lam,sig])
        axs[lam,sig].set_title('sigma = ' + str(sigma_lst[sig]) + ', lambda = ' + str(lambda_lst[lam]))

plt.tight_layout()

Any help on this would be great!
Answer: Here's a list of suggestions to save space:

put ticks and labels only on the y axes of the plots in the leftmost column
similarly, put ticks and labels only on the x axes of the plots in the bottom row
truncate the values for sigma and lambda to exponential notation.
only put values for sigma at the top of the corresponding column, and values for lambda at the left of the corresponding row
use Greek letters for sigma and lambda (λ and σ)
Comment: I put the axes only on the left and bottom accordingly - thanks for that! But how do I truncate the values?
Comment: @MOA: for example, `'%.1e' % 123.455` gives `'1.2e+02'`. See here for details https://docs.python.org/3/library/string.html#formatspec


What is the world record in high jump if you allow taking off on both feet?

Question: The current world record in normal high jump is 2.45 metres, set by Javier Sotomayor in 1993.
I read somewhere that in normal high jump, jumpers must take off on one foot. But if you relax the rules a bit and allow jumping with both feet, I guess it might be possible to jump even higher.
How high is it possible to jump allowing taking off with both feet?
Is there any such world record?
Update
I remember watching some international high jump competition in TV a few years ago. The Swedish TV commentator then made a comment about one of the high jumpers, that he almost jumped with both feet. The jumper clearly jumped with one foot, but I guess that by just changing his technique a bit he would jump with both feet. The height of his jump was somewhere around 2.30 metres. I would find it surprising if a two-feet jump would be significantly lower than that.
Comment: Here's a video, it said the man named 邱江明 won the Guinness World Records by 3.12 meters in 2009: http://video.sina.com.cn/p/news/s/v/2009-11-06/095060427128.html
Comment: Here is a youtube video of a world record high jump off two feet, 2.46 meters: http://youtu.be/yBCKQevaEmw I haven't found an official record for such a jump; everyone seems focused on the rule that you must jump from one foot.
Comment: The book "Sports Mechanics for Coaches" by Brendan Burkett says that elite gymnasts can cross a bar at 9 to 10 feet at the end of a tumbling run. Years ago, I read somewhere that tumbling runs were outlawed from the high jump back in the early 1900's. That may have been the motivation of the "must jump off one foot" rule.
Answer:
I read somewhere that in normal high jump, jumpers must take off on one foot.

Correct.  According to Rule 182 of the IAFF's 2012/2013 Competition Rules, the athlete must take off on one foot:

RULE 182  : High Jump
The Competition

An athlete shall take off from one foot.

As you correctly state, the world record for the high jump is 2.45 metres.
A quick search of the Guinness World Records show us that:

The highest standing jump onto a platform was 1.48 m (4 ft 10.27 in) by Jonas Huusom (Denmark) at Gerlev Sports Academy in Slagelse, Denmark, on 27 August 2011.
From a still, standing position, Huusom leaped to the top of 37 firm judo mats stacked one upon the other.

In addition to this record, this wiki page claims that the world record is 1.9m.
Now, there doesn't seem to be an official Guinness record for a vertical, running jump although there are some sites claiming jumps of around 1.55m.
Now neither of these are directly comparable seeing as there is a lot of difference between how the high jump and the vertical standing or running jumps are performed.
That said, with the high jump record being almost 0.5m higher than that of the standing jump I would probably maintain a hypothesis that the one foot jump would be better because of the technique involved, as well as the momentum caused through the bringing up the non-standing leg.
In addition, it appears that the high-jump rules have always requried the taking off being from one foot.
I did once read speculation that a gymnast could do a series of tumbles and somersaults before their final "high jump" which was higher than a one-foot launch but I'd need to see some research or historical evidence to agree with that.
Comment: Thanks for bringing up the idea of "a series of tumbles and somersaults". The accumulated rotational energy could then be used for jumping higher (at least in theory, I guess).
Comment: Gymnasts perform their tumbles on a spring floor, so their jumps are hardly comparable.
Comment: @ErikSjölund - yes, the theory works but I'm still trying to find some research on the theory.
Answer: The main reason for people jumping off one foot is that they can convert their forward motion into vertical motion better, so you can actually jump higher from one foot.
Additionally, you can convert momentum from the moving leg into additional vertical motion by swinging it forwards at speed and then up as you push up from the other foot.
The record for the Standing High Jump (off both feet) is held by Rune Almén at 1.90m.
Comment: I believe your answer, but it is not self-evident that you jump higher by jumping with one foot. Do you have any source for that information? Another thing: Although Standing High Jump is interesting I am more interested the case when you are allowed to run before jumping.


Receive DJI Tello's video stream using Java

Question: I'm trying to write a java application for controlling the DJI Tello drone.
I'm already able to send simple commands to the drone by using java.net.DatagramSocket as client.
The Tello SDK says:

It says I have to use java.net.DatagramSocket as the server to receive the video stream.
This is my try to receive the video stream:
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class TelloCamera extends Thread {
    private boolean isStreamOn;
    private DatagramSocket serverSocket;
    private byte[] receiveData = new byte[1470];

    public TelloCamera() {
        isStreamOn = true;
    }

    public void run() {
        try {
            serverSocket = new DatagramSocket(11111);
        } catch (SocketException e) {
            e.printStackTrace();
            return;
        }

        while (isStreamOn) {
            receiveData = new byte[1470];
            try {
                DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
                serverSocket.receive(receivePacket);

                String z = new String(receivePacket.getData());
                System.out.println(z);

            } catch (IOException e) {
                e.printStackTrace();
            }
            isStreamOn = false;
        }
        serverSocket.close();
    }

    public boolean isStreamOn() {
        return isStreamOn;
    }

    public void setStreamOn(boolean streamOn) {
        isStreamOn = streamOn;
    }
}

Main:
package tellotest;

public class maintellotest {

    public static void main(String[] args) {

        TelloCommander tello = new TelloCommander();
        tello.sendCommand("command");
        tello.sendCommand("streamon");
        TelloCamera camera = new TelloCamera();
        camera.start();

    }
}

Does anybody know why I get no string printed to console?
Answer: You have to send "streamon" command at 8889 port to Tello first and then listen at 11111 port. But in your code code, there is no code for sending the command. Try adding the code to send command first, send "command" then send "streamon" then listen on port 11111.
Comment: As you can see in the Main I am sending "command" and "streamon" via the TelloCommander object.
Comment: By the way, I am getting a string. Can you say what should I do with it. I want to convert it into a frame but IDK how?  Can anyone help me please. Thanks in advance.
Answer: I've also searched for a solution to this and came across a well implemented Tello java library, JTello @ https://github.com/xrv0/JTello.
In the library the author make use of JCodec (http://jcodec.org/) to decode the H.246 stream:
For example:
// byte[] message refers to the content of the datagram received from the drone over port 1111
// Allocate output frame of max size
Picture out = Picture.create(1920, 1088, ColorSpace.YUV420);
Picture real = decoder.decodeFrame(ByteBuffer.wrap(message), out.getData());

Answer: You need to create an InetSocketAddress with IP "0.0.0.0" and port 11111 and then bind the socket to it. And also remove isStreamOn = false from the while loop.


Como atualizar uma tabela através do AJAX?

Question: Ola. Eu gostaria de, ao clicar em "cadastrar" na div "cadastro-clientes" fosse atualizada a tabela de clientes na div "md-clientes", mas nao sei como fazer com que a tabela atualize sem atualizar o html todo.
DIV cadastro-clientes:

Cadastro de clientes

            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              ×
            </button>

            <form method="POST" id="cad-form" name="cad-form" action="cadastro.php">

                Qual o nome completo?
                <input class="form-control" name="nome" placeholder="Nome e sobrenome">
                E a data de nascimento?
                <input inputmode="numeric" name="data_nasc" class="form-control um" id="cad-dat-nasc" placeholder="Ex: 01/01/2020">
                Qual o telefone?
                <input inputmode="numeric" name="telefone" class="form-control um" id="cad-tel"placeholder="Ex: (99) 9 9999-9999">
                Onde mora?
                <input class="form-control" name="endereco" placeholder="Rua, numero, bairro e cidade">
                Qual o CPF?
                <input inputmode="numeric" name="cpf" class="form-control um" id="cad-cpf" placeholder="Ex: 999.999.999-99">
                E o RG?
                <input inputmode="numeric" name="rg" class="form-control um" id="cad-rg"placeholder="Ex: 99.999999-9">

                <button type="button" class="btn btn-outline-secondary" id="volta-btn">Voltar</button>
                <button type="submit" class="btn btn-outline-primary" id="cad-btn">Cadastrar</button>

            </form>

div md-clientes:

          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            ×
          </button>

Pesquisar clientes

            <input type="text" class="form-control center" placeholder="Informe o nome">

                        ID
                        Nome
                        Telefone
                        CPF
                        RG
                        Endereço

                      <?php
                        include("cadastro.php");
                        $grupo = exibirClientes(); ?>

                        <?php
                        foreach($grupo as $dados){
                        ?>

                              <?=$dados["nome"] ?>
                              <?=$dados["dataNascimento"] ?>
                              <?=$dados["telefone"] ?>
                              <?=$dados["cpf"] ?>
                              <?=$dados["rg"] ?>
                              <?=$dados["endereco"] ?>

                        <?php
                        }
                        ?>

            <button type="button" class="btn btn-outline-primary" id="md-cadastro">Cadastro</button>
            <button type="button" class="btn btn-outline-danger">Deletar</button>

javascript (ajax):
$('form[name="cad-form"]').submit(function(){
  var dados = $(this).serialize();
    $.ajax({
      url: 'cadastro.php',
      type: 'post',
      data: dados,
      success:function(data){
        if (data == "sucesso") {
          alert("Cliente cadastrado com sucesso! :)");
          }
          /*caso nao retorne "sucesso", mas realiza o cadastro, retorna oq houve
            de errado*/
          else {
            alert(data);
          }

        }
    })
    // "trava" o submit
  return false;
})

Obrigado desde já e tenham um ótimo dia!
Comment: Deixa eu ver se entendi, quer que ao cadastrar um novo item ele apareça automaticamente na div sem precisar atualizar?
Comment: Isso mesmo! No caso atual, o item so aparece na tabela quando atualiza o html
Answer: Você deve usar a função "append()" do jquery para adicionar os itens que vem do teu formulario na div do html

let nome = "";
let dataNascimento = "";
let telefone = "";
let cpf = "";
let rg = "";
let endereco = "";

let tr = `

            ${nome}
            ${dataNascimento}
            ${telefone}
            ${cpf}
            ${rg}
            ${endereco}

`;

$("body #tabela-clientes tbody").append(tr)

nas variáveis, você coloca os dados que vem do formulário, e assim que finalizar a requisição os itens serão adicionados (append) ao final da sua DIV. Assim...

$('form[name="cad-form"]').submit(function(){
  var dados = $(this).serialize();
    $.ajax({
      url: 'cadastro.php',
      type: 'post',
      data: dados,
      success:function(data){
        if (data == "sucesso") {

            let nome = "nomeQueVemDoForm";
            let dataNascimento = "datadeNascQueVemDoForm";
            let telefone = "telefoneQueVemDoForm";
            let cpf = "cpfQueVemDoForm";
            let rg = "rgQueVemDoForm";
            let endereco = "enderecoQueVemDoForm";

            let tr = `

                        ${nome}
                        ${dataNascimento}
                        ${telefone}
                        ${cpf}
                        ${rg}
                        ${endereco}

`;

            $("body #tabela-clientes tbody").append(tr)

        }
          /*caso nao retorne "sucesso", mas realiza o cadastro, retorna oq houve
            de errado*/
          else {
            alert(data);
          }

        }
    })
    // "trava" o submit
  return false;
})


What does it mean to say convolution implementation is based on GEMM (matrix multiply) or it is based on 1x1 kernels?

Question: I have been trying to understand (but miserably failing) how convolutions on images (with height, width, channels) are implemented in software.
I've heard people say their convolution implementation is done using GEMM, or done using "Direct convolution" or done using 1x1 kernels.
I find it very confusing and can't wrap my head around so many different ways it's described everywhere - I thought I understood a typical convolution like pytorch conv2d as a mathematical operation on an image, but what do they mean when someone says they do conv2d using one of the following ways?

1x1 kernels or 1x1 convolution (what does kernel even mean here)
GEMM
"direct convolution"

For doing Convolution using GEMM, what I understand based on this paper is that each of the input-image and filters are converted to 2d matrices using im2col and im2row ops and then these two are simply matrix-multiplied.
The 3d input image (height, width, input-channels) is converted to a 2d matrix, the 4-d kernel (output-channels, input-channels, kernel-height, kernel-width) is converted to a 2d matrix. Or does "GEMM-based implementation of convolution" mean something else? If that's what it means then how is it different than doing "convolution using 1x1 kernels"?
Answer:
1x1 kernels or 1x1 convolution (what does kernel even mean here)

You can have 3x3 convolution, so you have a square containing 9 elements sliding over the image (with some specified stride, dilation etc.). In this case you have 1x1 convolution so the kernel is a single element (with stride=1 as well and no dilation).
So instead of sliding window with summation you simply project linearly each pixel with this single valued kernel.
It is a cheap operation and is used as part of depthwise separable convolutions used in many modern architectures to increase/decrease number of channels.
GEMM
In the article you provided there is as the top:

[...] function called GEMM. It's part of the BLAS (Basic Linear Algebra
Subprograms)

So BLAS is a specification which describes a set of low-level algebraic operations and how they should be performed on computer.
Now, you have a lot of implementations of BLAS tailored to specific architectures or having some traits usable in some context. For example there is cuBLAS which is written and optimized for GPU (and used heavily by deep learning "higher level" libraries like PyTorch) or Intel's MKL for Intel CPUs (you can read more about BLAS anywhere on the web)
Usually those are written with a low-level (Fortran, C, Assembly, C++) languages for maximum performance.
GEMM is GEneralized Matrix multiplication routine which is used to implement fully connected layers and convolutions and is provided by various BLAS implementations.
It has nothing to do with the deep learning convolution per-se, it is a fast matrix multiplication routine (considering things like cache hit)
Direct convolutions
It is an approach which is O(n^2) complexity so you simply multiply items with each other. There is more efficient approach using Fast Fourier Transformation which is O(n*log(n)). Some info presented in this answer and questions about this part would be better suited for math related stackexchanges.


Error when \% is included in a sectioning command

Question: When I try to input a \% in a \subsection's title and Compile pdf, I get the following error:
File ended while scanning use of \@@BOOKMARK.
How should I do it?
EDIT
Here is a reproducible example. The file is encoded in UTF-8 format.
\documentclass[a4paper]{article}

\usepackage{fontspec}
\usepackage{hyperref}
\usepackage{longtable}
\usepackage{rotating}
\usepackage{tabularx}
\usepackage{lscape}
\usepackage[normalem]{ulem}

\setmainfont[Scale=1.0]{Times New Roman}
\setsansfont{Times New Roman}

\begin{document}

\section{Μέσες τιμές και 95\% Διαστήματα Εμπιστοσύνης}

\subsection{a \% b cd}

<<>>=
1+1
@

\end{document}

Comment: @RicardoSaporta why `\\%`? LaTeX is not R :)
Answer: It is perhaps a configuration problem of hyperref. I do not have Times New Roman, but I succeeded with xelatex (TeXLive 2012, Ubuntu 13.04) in RStudio (v0.98.312) and knitr using the configuration below:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{DejaVu Serif}
\usepackage[unicode=true,bookmarks=true,bookmarksopen=true]{hyperref}
\usepackage{xunicode}
\begin{document}

\section{Μέσες τιμές και 95\% Διαστήματα Εμπιστοσύνης}

\subsection{a \% b cd}

<<>>=
1+1
@

\end{document}

Output:

The document is UTF8 encoded. You probably need to tell hyperref the unicode option.
Comment: Thank you. It works even without xunicode. Do you think I should keep it?
Comment: @GeorgeDontas I'm not really a XeTeX expert, so I think you can go without xunicode if it works anyway


Integral involving log of exp

Question: I'd love to find out an expression for the indefinite integral
$$\int \frac{1}{\log(1+e^{\large x})} \mathrm{d}x$$
but I wasn't able to on my own. In fact I'll need to find the inverse of the resulting function. I suppose I could live with the series expansion but something more compact would be nice. Any help would be much appreciated.
Comment: W|A says "$\text{ no result found in terms of standard mathematical functions }$".
Comment: If you set $1+e^x=t$ the integral becomes $\int \frac{dt}{(t-1) \log t}=\int \frac{d \log (t-1)}{\log t}$ which probably doesn't have a closed-form solution
Comment: W|A is Wolfram alpha? Interesting, Mathematica merely did not give an answer. So it's likely that no closed-form exists in terms of any special function? Thanks!
Answer: Let $u=\log(1+e^x)$ ,
Then $x=\log(e^u-1)$
$dx=\dfrac{e^u}{e^u-1}du=\dfrac{1}{1-e^{-u}}du$
$\therefore\int\dfrac{1}{\log(1+e^x)}dx$
$=\int\dfrac{1}{u(1-e^{-u})}du$
Which relates to the incomplete polylogarithm function

Integral involving log of exp


servlet multithreading

Question: I understand that Servlet requests are by default multithreaded. I created a simple servlet using NetBeans, and it appears to be single threaded, on both Tomcat and JBoss.
I tested it using this code:
<code>protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

   System.out.println("access processRequest: " + this + " threadID: " + Thread.currentThread().getId());

    try {
        Thread.sleep(5000);
    } catch (InterruptedException ex) {
        Logger.getLogger(OctaveServlet.class.getName()).log(Level.SEVERE, null, ex);
    }

    System.out.println("exit processRequest: " + this + " threadID: " + Thread.currentThread().getId());

}
</code>
(processRequest is called from doGet)
I accessed this from 2 tabs in my browser almost at the same time, and if multithreading would have worked, I'd expect it to print the "access" with 2 different threads ID's, and then the "exit" of both threads.
Instead, I get this output:
14:53:41,839 INFO  [stdout] (http--127.0.0.1-8080-1) access processRequest: OctaveServlet@31ccfe threadID: 34
14:53:46,840 INFO  [stdout] (http--127.0.0.1-8080-1) exit processRequest: OctaveServlet@31ccfe threadID: 34
14:53:46,867 INFO  [stdout] (http--127.0.0.1-8080-1) access processRequest: OctaveServlet@31ccfe threadID: 34
14:53:51,867 INFO  [stdout] (http--127.0.0.1-8080-1) exit processRequest: OctaveServlet@31ccfe threadID: 34
As you can see it was just one thread.
Needless to say, I'm not implementing the SingleThreadModel.
Here are details of my system:
NetBeans 7.0.1, JVM: Sun java 1.6.0_26, Tomcat 7.0.14, JBoss AS 7, Ubuntu 11.04
Many thanks for any help,
Oded.
Answer: It's using one thread per HTTP connection (it's not exactly that when the server uses NIO, but you got the point). Your browser is apparently using the same HTTP connection in both tabs. Spawn two different browser instances (e.g. Firefox and Chrome) and you'll see that it works the way you expected.
Comment: Thanks! Wouldn't have guessed the browser was the culprit!

servlet multithreading


MIPS: Check how many alphabetic characters are in a string

Question: Right now I'm trying to load a null-terminated string and return the number of alphabetic characters that are in that string. Currently I have three functions: the Main, countAlpha (which is intended to count the number of characters), and isAlpha, which determines whether the character is alphabetic or not. I would like some help with my algorithm.
So, for my Main I load the string, jump and link to countAlpha, and then load the syscall commands to print int and exit the program.
For my countAlpha, which I am having trouble with, I want to create a for loop that goes through each character in the string and if isAlpha returns a 1 (indicating that the character is alphabetic), then increase the count.
isAlpha is straightforward-just determine if the character is between specific numbers in ASCII.
So I guess my question is how do I attack countAlpha. Thanks for your help. (Note: I don't want actual code, just tips and hints)
Comment: It's not clear if you want assembler help, C help, or somethign else.  Please add the appropriate tag and you'll g et more attention as well :)
Answer: Sounds like you want to test a return value / register for the call to isAlpha and add/increment a seperate register/count var everytime the test is true.  Or you could just add the return value directly to your count register every time through the loop if the value is returned as a 0 or 1.  Then, just setup your loop to keep going until the current character is a '\0' char.  Then your count register holds your final value.
Is this in-depth enough to help you out?
Comment: This is helpful, thank you! I was unsure if I would need a separate register actually so this clarifies it. Thanks again.


Polynomial expressions in localized ideal

Question: Let $A$ be a commutative ring and $S\subset A$ a multiplicatively closed subset. Fix a polynomial $f\in A[X]$ and define $I$ to be the ideal generated by elements of the form $f(a)$ with $a\in A$.
My question is:

Does the localized ideal $I_S$ contain all elements of the form $f(x)$ with $x\in A_S$?

This was motivated by this question/answer. There I prove the statement for polynomials of the form $f=X^n-X$. For $x=\frac{a}{s}\in A_S$ we have $$f(x)=\frac{1}{s^{n+1}}\left(sf(a)-af(s)\right)$$
And therefore $f(x)\in I_S$.
However I didn't manage to generalize this to arbitrary polynomials $f$. I would guess that one can explicitely write down some general formula for $f(\frac{a}{s})$ in terms of $f(a_i)$ where $a_i$ are suitable elements from $A$. But maybe there is also a 'nicer' proof that avoids these messy calculations (assuming the statement is indeed correct).
Comment: Doesn't a simple induction argument work? Have you tried other polynomials as well?
Answer: Notation: For a ring $A$ and a polynomial $f \in A[X]$, let me define $I_{A,f} = \langle \{f(a)\}_{a \in A} \rangle$ to be the ideal of $A$ generated by the values of $f$. For any ring map $A \to B$, there is a natural $B$-module morphism $I_{A,f} \otimes_{A} B \to I_{B,f}$.
Remark: If $(\deg f)! \in A^{\times}$ (e.g. if $f$ is linear), then $I_{A,f}$ is the ideal generated by the coefficients of $f$, hence $I_{A,f} \otimes_{A} B \to I_{B,f}$ is surjective for any ring map $A \to B$.
Proof: Let $f(X) = a_{d}X^{d} + \dotsb + a_{1}X + a_{0}$; then $I_{A,f} \subseteq \langle a_{d},\dotsc,a_{1},a_{0} \rangle$. We plug in $X=0,1,\dotsc,d$ to get $\begin{bmatrix} f(0) \\ f(1) \\ \vdots \\ f(d) \end{bmatrix} = V \cdot \begin{bmatrix} a_{0} \\ a_{1} \\ \vdots \\ a_{d} \end{bmatrix}$ where $V$ is the Vandermonde matrix corresponding to $0,1,\dotsc,d$. The determinant of $V$ is $\pm \prod_{0 \le i < j \le d} (i-j)$, which is invertible in $A$ by assumption; hence $V \in \mathrm{GL}_{d+1}(A)$ and so we can solve for $a_{0},\dotsc,a_{d}$ as $A$-linear combinations of $f(0),\dotsc,f(d)$. $\square$
Claim: For any multiplicative subset $S \subset A$, we have an equality $S^{-1}(I_{A,f}) = I_{S^{-1}A,f}$ of ideals of $S^{-1}A$.
Proof: Let $f(X) = a_{n}X^{n} + a_{n-1}X^{n-1} + \dotsb + a_{1}X + a_{0}$. We will show that \begin{align*} \textstyle f(x/s) = \frac{1}{s^{n}}(a_{n}x^{n} + a_{n-1}x^{n-1}s + \dotsb + a_{1}xs^{n-1} + a_{0}s^{n}) \end{align*} is an $S^{-1}A$-linear combination of $f(x),f(xs),\dotsc,f(xs^{n})$. Thus we want to solve the vector equation \begin{align*} \begin{array}{@{}c@{}}{\begin{bmatrix} a_{0} & a_{1}x & \dotsb & a_{n}x^{n}\end{bmatrix}}\\ \vphantom{\vdots} \\ \\ \\ \end{array} \begin{bmatrix} s^{n} \\ s^{n-1} \\ \vdots \\ 1 \end{bmatrix} = \begin{array}{@{}c@{}}{\begin{bmatrix} a_{0} & a_{1}x & \dotsb & a_{n}x^{n} \end{bmatrix}}\\ \vphantom{\vdots} \\ \\ \\ \end{array} \begin{bmatrix} 1 & 1 & \dotsb & 1 \\ 1 & s & \dotsb & s^{n} \\ \vdots & \vdots & \ddots & \vdots \\ 1 & s^{n} & \dotsb & s^{n^{2}} \end{bmatrix} \begin{bmatrix} b_{0} \\ b_{1} \\ \vdots \\ b_{n} \end{bmatrix} \end{align*} for $b_{i} \in S^{-1}A$. In fact we solve the equation \begin{align*} \begin{bmatrix} s^{n} \\ s^{n-1} \\ \vdots \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 1 & \dotsb & 1 \\ 1 & s & \dotsb & s^{n} \\ \vdots & \vdots & \ddots & \vdots \\ 1 & s^{n} & \dotsb & s^{n^{2}} \end{bmatrix} \begin{bmatrix} b_{0} \\ b_{1} \\ \vdots \\ b_{n} \end{bmatrix} \end{align*} in $\mathbb{Z}[s,s^{-1}]$ where we view $s$ as an indeterminate. For this, we recall that the inverse of the Vandermonde matrix \begin{align*} \begin{bmatrix} 1 & 1 & \dotsb & 1 \\ x_{0} & x_{1} & \dotsb & x_{n} \\ \vdots & \vdots & \ddots & \vdots \\ x_{0}^{n} & x_{1}^{n} & \dotsb & x_{n}^{n} \end{bmatrix} \end{align*} has entries \begin{align*} v_{i,j} = (-1)^{n-j} \frac{e_{n-j}(\{x_{0},\dotsc,x_{n}\} \setminus \{x_{i}\})}{\prod_{m \ne i} (x_{i}-x_{m})} \end{align*} for $i,j=0,1,\dotsc,n$, where $e_{i}$ denotes the $i$th elementary symmetric polynomial (defined as $\prod_{m=1}^{n}(X-x_{i}) = \sum_{i=0}^{n}(-1)^{i}e_{i}(\{x_{1},\dotsc,x_{n}\})X^{n-i}$). In our case, we have $x_{i} = s^{i}$ for $i=0,1,\dotsc,n$. Thus we get the formula \begin{align*} b_{i} &= \frac{1}{\prod_{m \ne i} (s^{i}-s^{m})}\sum_{j=0}^{n} s^{j}(-1)^{n-j}e_{n-j}(\{x_{0},\dotsc,x_{n}\} \setminus \{x_{i}\}) \\ &= s^{n}\frac{\prod_{m \ne i} (\frac{1}{s}-s^{m})}{\prod_{m \ne i} (s^{i}-s^{m})} \\ &= \pm s^{???} \frac{\prod_{m \in \{1,\dotsc,n+1\}\setminus \{i+1\}} (1-s^{m})}{\prod_{0 \le m < i} (1-s^{i-m})\prod_{i < m \le n} (1-s^{m-i})} \\ &= \pm s^{???} \frac{\prod_{m=1}^{n+1} (1-s^{m})}{\prod_{m=1}^{i+1}(1-s^{m}) \prod_{m=1}^{n-i}(1-s^{m})} \end{align*} so it suffices to show that, for any $n,k$, the polynomial $\prod_{m=1}^{k} (1-s^{m})$ divides $\prod_{m=n-k+1}^{n} (1-s^{m})$ in $\mathbb{Z}[s]$. (This seems related to the fact that binomial coefficients are integers but I don't know of a proof that can be made to work here, for example it is not always true that we can rearrange $k$ consecutive integers $n-k+1,\dotsc,n$ so that $m$ divides the $m$th integer $n-k+\sigma(m)$, see $\binom{7}{3} = \frac{7 \cdot 6 \cdot 5}{3 \cdot 2 \cdot 1}$.) So instead let $\Phi_{d}(s) \in \mathbb{Z}[s]$ be the $d$th cyclotomic polynomial, which is irreducible and satisfies $1-s^{n} = \prod_{d | n} \Phi_{d}$ for any $n$. For any $d,k$, the order of $\Phi_{d}$ dividing $\prod_{m=1}^{k}(1-s^{m})$ is $\lfloor \frac{k}{d} \rfloor$ so we conclude using that $\lfloor \frac{k}{d} \rfloor + \lfloor \frac{n-k}{d} \rfloor \le \lfloor \frac{n}{d} \rfloor$ for any $d,n,k$. $\square$
Remark: The analogous statement is true for multivariate polynomials as well, for example the above shows that $f(\frac{x}{s},\frac{y}{t})$ can be written as an $S^{-1}A$-linear combination of $f(s^{i}x,\frac{y}{t})$ for $i \ge 0$, each of which can be written as an $S^{-1}A$-linear combination of $f(s^{i}x,t^{j}y)$ for $j \ge 0$, etc.
Comment: Thanks for this detailed answer! Just one small question/remark: shouldn't it be $$v_{i,j}=(-1)^{n-j}\frac{e_{n-j}(\{x_0,\dots,x_n\}\setminus\{x_i\})}{\prod_{m\ne i (x_i-x_m}}?$$ Because in the link you gave for the inverse of the Vandermonde matrix the indices start at $1$ (and this seems to work in the $2\times2$-case, i.e. $n=1$). With this formula I get $$b_i=\pm s^{???}\frac{\prod_{m=1}^{n+1}(1-s^m)}{\prod_{m=1}^{i+1}(1-s^m)\prod_{m=1}^{n-i}(1-s^m)}$$
Comment: But then we can continue as you wrote. So this doesn't really change anything in the argument, I just want to make sure I understand the calculations.
Comment: Oops, thanks, I made the relevant edits.


Asymptotic distribution of $\sum X_{i}^2$

Question: We have $X_{1},X_{2},...,X_{n}$ as the independent standard normal random variables. Let us define:
$T_{n} = \sum X_{i}^2$ then what will be the asymptotic distribution of $\sqrt{n}(\frac{T_{n}}{n} - 1)$?
My approach:
Since $T_{n}$ is sum of standard normals, it will follow chi-square with $n$ degree of freedom. Hence, we can write:
$E(T_{n}) = n$
$V(T_{n}) = 2n$
It implies that:
$\frac{T_{n} - n}{\sqrt{2n}}$ will follow asymptotic standard normal. Even if I adjust the terms, I am not getting $\sqrt{n}(\frac{T_{n}}{n} - 1)$ for which I need the distribution.
I can probably think of following but I am not sure if it is correct.
Let $P_{n} = \frac{T_{n} - n}{\sqrt{2n}}$. We got that $P_{n}$ follows asymptotic $N(0,1)$. Let us define $C_{n} = \sqrt{2}P_{n}$. Hence, $C_n$ will follow asymptotic $N(0,2)$ and if we expand $C_n$, we will get:
$C_{n} = \sqrt{2}P_{n} = \sqrt{2}\frac{T_{n} - n}{\sqrt{2n}} = \sqrt{n}(\frac{T_{n}}{n} - 1)$. Hence, the required distribution is $N(0,2)$.
Is my approach correct? I am not sure if we can adjust the terms like this asymptotically? I know we can do the same in general when we are not talking in terms of asymptotic.
Answer: Yes, that is correct.  (Though you should remove the excessive notation.)  Using the asymptotic approximation (from the central limit theorem) you have:
$$\begin{align}
\sqrt{n} \cdot \bigg( \frac{T_n}{n}-1 \bigg)
&= \sqrt{n} \cdot \frac{T_n-n}{n} \\[6pt]
&= \sqrt{2} \cdot \frac{T_n-n}{\sqrt{2n}} \\[6pt]
&= \sqrt{2} \cdot \frac{T_n - \mathbb{E}(T_n)}{\mathbb{S}(T_n)} \\[8pt]
&\overset{\approx}{\sim} \sqrt{2} \cdot \text{N}(0,1) \\[16pt]
&\sim \text{N}(0,2). \\[6pt]
\end{align}$$
Comment: Thanks ben. I will take care of notations from next time.


When is it more appropriate to use linear or quadratic weights to measure inter-rater reliability (Fleiss's kappa or Gwet's AC1?)

Question: I am analysing the results of a linguistic acceptability judgment study where 36 speakers had to rate a finite number of sentences on a 7-point Likert scale (so an ordinal scale, although I am not excluding a linear interpretation of results). I am trying to measure multiple inter-rater reliability using Fleiss's kappa or Gwet's AC1 but I am unsure of how appropriate it is to use weights, especially linear or quadratic weights. Both types of weights give me higher coefficients but I don't know what would justify the use of weights, let alone the use of a specific type of weight. What would be most appropriate for Likert scale ratings of a set of similar stimuli (sentences)?
Answer: It depends on how much partial credit you want to give for being close but wrong. Quadratic is more forgiving and gives more partial credit than linear. I give some examples here.


p value and number of predictors

Question: I was going through the An Introduction to Statistical Learning: With Applications in R book and I am facing a bit of difficulty in understanding the below paragraph.I am including the paragraph itself because I do not want to tamper with the original information.

consider an example in which p = 100 and H0 : β1 = β2 =. . . = βp = 0 is true, so no variable is truly associated with the response. In
this situation, about 5% of the p-values associated with each variable will be below 0.05 by chance. In other words,
we expect to see approximately five small p-values even in the absence of
any true association between the predictors and the response. In fact, we
are almost guaranteed that we will observe at least one p-value below 0.05
by chance! Hence, if we use the individual t-statistics and associated pvalues
in order to decide whether or not there is any association between
the variables and the response, there is a very high chance that we will
incorrectly conclude that there is a relationship. However, the F-statistic
does not suffer from this problem because it adjusts for the number of
predictors. Hence, if H0 is true, there is only a 5% chance that the Fstatistic
will result in a p-value below 0.05, regardless of the number of
predictors or the number of observations.

I am not able to comprehend the relationship between p values and predictors.I tried searching also but everywhere the explanation is regarding p value and sample size only.
Answer: The paragraph adresses the problem of multiple testing, and discusses why we cannot just do $p = 100$ individual hypothesis tests with $H_0: \beta_k = 0$ for each individual predictor at the significance level $\alpha = 0.05$. Even if the null hypothesis is true there is still a chance that the specific $\hat{\beta}_k$ calculated from your sample leads to a rejection of $H_0$. The probability of rejecting $H_0$ even if it is true is equal to your significance level. So, in the example from the paragraph with 100 hypothesis tests and a significance level of 5%, the expected number of rejections is $0.05 \times 100 = 5$, even if all null hypotheses are true (assuming independence). And, as stated in the paragraph, the probability of observing at least one p-value below 0.05 is close to 1. If the multiple testing is not adjusted for, you will falsely conclude that there is evidence in your data at a 5% significance level of relation between predictor and response.
The paragraph then suggest using the $F$-statistic instead, and simultaneously test all $\beta_k$'s.

p value and number of predictors


Entity Query using conditions that ignore special characters

Question: I have an entity query where I search the body for user provided text.
I'm performing the query like so
<code>$searchterm = 'test';
    $query = \Drupal::entityQuery('node')
            ->condition('status', NODE_PUBLISHED)
            ->condition('body', $searchterm, 'CONTAINS');
</code>
This gives me the results I need, but what if I run into a situation where the body contains the text 'test-1' but I want searches for 'test1' to bring up that result.
Is there anyway that I can write a query that ignores all special characters in the field I'm searching?
Comment: No, the API doesn't support that. This is also not performant at all. Look at search api if you want to have a performant search with features like that
Answer: Drupal does not supply a solution to your problem out of the box.
However you can create a list of all the permutations and create a condition for each of them.

Code snippet
<code>$searchterm = 'test-1_2 3';

$query = \Drupal::entityQuery('node')
  ->condition('status', NODE_PUBLISHED);

// permutation generator function.
$permutations = function($source_term) {
  $result = [$source_term];
  $unprocessed_terms = [$source_term];
  $regex = '/[\W_]/'; // Selects all the non-alphanumeric characters and _

  while (!empty($unprocessed_terms)) {
    $unprocessed_term = array_pop($unprocessed_terms);
    $matches = [[]];

    // By using PREG_OFFSET_CAPTURE we get the position of the match.
    preg_match_all($regex, $unprocessed_term, $matches, PREG_OFFSET_CAPTURE);
    foreach($matches[0] as list($match, $pos)) {
      $result[] = $unprocessed_terms[] = substr_replace($unprocessed_term, '', $pos, 1);
    }
  }

  // the above algorithm will create duplicates.
  return array_unique($result);
};

// Create an OR condition group that contains a
// condition for each permutation term.
$query->condition($or = $query->orConditionGroup());
foreach ($permutations($searchterm) as $term) {
  $or->condition('body', $term, 'CONTAINS');
}

$nids = $query->execute();
</code>
Comment: P.S. performance of the above code can be improved greatly with caches.


I'm stuck in diatonic land. How do I get out?

Question: I've been playing a lot of diatonic everything. So basically just staying in the scale as I improvise with melody/chords. I play alot of songs by ear and I notice when they use accidentals but I don't really know the theory of how they do it besides that it just sounds good.
So I'm thinking it's just "whatever sounds good" and go with that. Or is there some theory in regards to how to add non-diatonic notes?
I want to play/improvise like this guy.
Comment: Everything you can hear in music has some theory that has been developed to explain it. The problem with this question, to me at least, is that for each accidental there's potentially a different theory. So it's not like there's one theory for how to use chromaticism. There are tons of them - countless ways to understand why certain things sound the way they do.
Comment: @foreyez in that recording, you're hearing pretty standard progressions that include chromatic passing chords and non-diatonic progressions. You don't need to learn theory so much as these standard progressions. Just as a ii-V-I is a nice cadence, so is `| ii min | iv min6 | I64 | V7 | I Maj |`. You're latching on to those more complex progressions. The recording almost certainly isn't improvised, btw.
Comment: That question is a bit more sophisticated. I'm just looking for a simple yes/no if it's by ear or not. I can handle it being by ear. I'm almost hoping it's that way. However, if there's theory to it I'd like to know what that general theory is.
Comment: @jdjazz in the youtube comments he says it is, but I agree with you that most of it was probably composed beforehand. thanks for mentioning "chromatic passing chords" and "non-diatonic progressions" these are keywords I wasn't aware of.
Comment: You play by ear, but 'notice when they use accidentals'. In a lot of tunes with improvisational propensities (most tunes!) the 'accidentals' occur when the chords stray from the diatonic ones. For example, in key C, there's an E chord (V/vi), or an A7 chord (V/ii) where non diatonic notes (accidentals if you like) work well. But in a tune in C, I'm quite likely to play Eb, or Gb, but over a C chord. Two very different scenarios. Which are you asking about?
Answer: Chromatic Passing Tones
Using bebop scales is a great option because they contain chromatic passing notes, which is the sound you're looking for. There are many different bebop scales:

By adding a chromatic passing tone, these bebop scales gain something valuable: the downbeats emphasize chord tones. For example, looking at the C major bebop scale, the notes that occur on downbeats are C-E-G-A. These notes spell out a CM6 chord. The downbeats of the C dominant bebop scale spell out C-E-G-B♭, a C7 chord. The C melodic minor bebop scale spells out C-E♭-G-A, a Cm6 chord. And the C harmonic minor bebop scale spells out C-E♭-G-B♭, a Cm7 chord.
These scales teach us that it's important to think about where we want to introduce non-scale tones.
Another way to introduce non-scale tones is to approach notes chromatically. Chord tones, for example, can be approached from a half step below or from a half step above. Between the two, it's more common to approach a chord tone from a half step below. A common improvisational exercise is to surround chord tones. In the example below, I'm surrounding each chord tone of CM6 using a half step below and a whole step above:

Chromatic Passing Chords
The video you shared doesn't contain many chromatic scale tones (only one that I heard). What you're hearing in that video is related--chromatic passing tones. The video also contains more complex progressions that, while non-diatonic, are still very standard.
The progressions you hear in the video almost certainly aren't being improvised. But to develop an ability to improvise chord progressions, you need to learn songs and build up your vocabulary of chord progressions. Start out by transcribing the chords to the song you linked to. Find other jazz songs with similar progressions, and take note of where they differ. As you expand your vocabulary of known progressions, you'll develop a variety of choices you might decide to use on-the-spot while improvising a progression.
Some of the non-diatonic progressions you'll hear in that song alone include:

| IV Maj | ♯iv dim  | I64    | V7    | I Maj  |
| IV Maj | ♯iv dim  | V7     |
| V7     | ♯v dim   | vi min |
| II7    | V7       | I Maj  | (note the II chord is dom7 rather than min7)
| I Maj  | ♭iii dim | ii min | V7    |
| ii min | iv min6  | I64    | V7    | I Maj  |

The best way to practice these is in context. Transcribe interesting chord progressions that you hear, play them on your instrument, try modifying them, and try combining different progressions. Categorize their function ("this one is a nice turn-around," etc.).
Comment: @Tim, I'm not familiar with any convention that V7/V is more correct than II7. I think it's six one way and a half dozen the other way. I personally prefer to think about the chord in terms of the tonic. Other references do use II7-V7-I too.
Comment: I keep coming back to this answer, good stuff!
Comment: I thought the general agreement on , say, D7 in key C was to call it V7/V rather than II7, as it actually is the dominant of the dominant.
Comment: I used II7 for many years, till I read Bert Ligon's 'Jazz theory Resources', which persuaded me that V7/V for example explained that pesky D7 better, but now, I'm undecided. As you say - 50:50...
Comment: @Tim, I'll have to check out that book. Foreyez, that's a good start, but the most helpful will be finding songs with the progressions you like. Learning them in the context of a full song/progression will build your sense of how to deploy those sub-progressions when improvising.
Comment: Much of this answer describes 'diatonic with decorations' rather than any true departure from diatonic.
Comment: @LaurencePayne, I'm not familiar with the term 'diatonic with decorations.' The question isn't about changing keys (I assume that's what you mean by "true departure"). Did you listen to the video in the original question? The progressions I've cited are all from that video. What is the question asking about, in your view?
Comment: It's not a standard term, but surely self-explanatory?   The first half (counts as 'much'?) of the answer is about passing notes.  Non-harmonic decorations.
Comment: @LaurencePayne, are you suggesting it isn't relevant to the question? You're drawing a distinction that the question itself doesn't make.
Answer: If you have a good understanding of diatonic systems, start thinking about the relationship between the notes outside of the scale and those inside the scale. As a baseline, it's important to understand that there is a relationship between all arbitrary collections of notes, diatonic or not. It's also helpful to know that for a given major key, seven notes are in the scale and only five are out, so you're already more than halfway there.
Let's say you're playing a tune with the chords C | Ami7 | Dmi7 | G7 |. Just before the transition between C and Ami7, someone plays a G#. How can you explain this note using an understanding of diatonic harmony? Well, G# is the leading tone of A minor, and its presence in the melody implies an E7 (or a G#o). Playing a G# effectively allows the soloist to imply a V7-i cadence going to that A minor. Because it also implies a G#o, you can also make a connection between any G# (... or B D F) diminished scale runs that you happen to hear in a C major system. You might also hear someone play the whole tone scale starting at C, going to G# and then landing on an A; you can explain the accidentals here (F# G#) by connecting those notes to E7-A. If someone played a Bb on this transition, you might rationalize it by noting that Bb7 is the tritone substitution of E7.
This is just an example and you can use that kind of analysis to explain the relationship between just about any set of notes. Indeed, you can certainly make more farfetched connections, but it's going to take more work for listeners to really grasp what you're doing. If you just start playing the Bb altered scale over that C major chord, you probably aren't going to be able to sell anyone on that connection. But you could get some pretty outside notes to sound "in" by properly contextualizing them; a fairly common example is people playing minor blues licks over tonic major chords, allowing you to get b3s and b5s to make sense in a major system.
I should reemphasize that this is kind of a wasted endeavor if your understanding of diatonic systems isn't really good. If it took you any significant amount of time to figure out why G# implies V7-of-vi in the key of C then your time is far better spent focusing on what that means than it is trying to explain every single note you see in a solo. But you should know that there is an explanation for virtually everything.
Answer: As some comments state (mine in particular).  Everything should be done by ear.
However there are some guiding principles for adding chromatics (accidentals) to a solo.  (dejavu, I feel like I answered almost the same question last week).

Leading tone principle.  When chromatics are added it is sometimes in leading up to a scale tone.  One case in point is the harmonic or melodic minor.  These have "accidentals" relative to the original key to produce a leading tone to the first note of the minor scale.  This can be done anywhere.
Other scales.  Two popular scales that have chromatic passing tones in them are the blues scale and the bebop scale.  The true blues scale is minor pentatonic with a flat 5 added.  The Bebop Ionian scale is major with a sharp 5 (flat 6) added.

Once you get used to the sound and feel using them in solos is easy.
I think this is a good starting point.  You can also make Bebop version of the melodic minor scale which sounds very cool.
Comment: Everyone seems to ignore the *major* blues scale. Just as used as its oppo!
Comment: The major bebop scale has a flat 6 rather than a flat 5. There's also a mixolydian bebop scale, a couple dorian bebop scales, a great melodic minor bebop scale, and a harmonic minor bebop scale.
Comment: Oops, I think you are correct.  I'll edit.
Answer: READ lots of music. Don't worry about improvising for now, just play 'what the guy wrote'. You'll discover all kinds of possibilities.  You can hang labels on them if you like.  But I'd rather you spent the time playing even MORE unfamiliar music.
Answer: Look up secondary dominants and borrowed chords and modal mixture Here a some good videos on those things. Signals studio music is a great Youtube channel if you want you can check out some more of his video it would be worth it.
Comment: yep already watched all those. signals music studio is awesome and has best radio voice ever. :)
Comment: @foreyez I think he may have the most aesthetically pleasing speaking voice of all the youtube music educators I know


Is a conditional distribution independent of the variable being conditioned on?

Question: This might seem like a bit of a silly question, but for some reason I'm having trouble convincing myself of it, so I thought I might solicit opinions on this site. Suppose random variables $(X,Y)$ have some joint distribution (bivariate normal if you'd like). Is the conditional distribution $(Y|X=x)$ independent of random variable $X$? I feel like it's vacuously true because $\text{P}(Y|X,X)=\text{P}(Y|X)$ but for some reason the intuition just isn't coming to me.
Comment: Well, the _mean_ of the conditional distribution of $Y$ given $X$ is a_ random variable_ that is a function of $X$. So you need to think a little bit about what exactly you are thinking about when you want to know whether the conditional distribution is independent of a random variable. Exactly _how_ are you defining independence of. a distribution (whether conditional or not is immaterial) and a random variable?
Answer: It depends what you mean by the "conditional distribution"
There are a number of ways this can be interpreted, and the answer depends on the interpretation.  To facilitate this analysis, suppose we define the conditional distribution function $F$ as the bivariate function:
$$F(y|x) = \mathbb{P}(Y \leqslant y | X = x)
\quad \quad \quad \text{for all } x \in \mathscr{X}.$$
If we consider the conditional distribution as the full bivariate function $F( \cdot | \cdot )$ then this object is fixed by the joint distribution of $X$ and $Y$, so it is a constant (and therefore trivially independent of $X$).  Similarly, if we substitute any constant arguments to reduce the function to a univariate function or scalar value, it is still a constant (and therefore trivially independent of $X$).  However, if we substitute one of the original random variables into its argument then it becomes a random variable, and it is now statistically dependent with the substituted random variable (and possibly also the other random variable).  This is summarised below.
$$\begin{matrix}
F( \cdot | \cdot ) & & & \text{Constant bivariate function} & & & \text{Independent of } X \text{ and } Y, \\[6pt]
F( \cdot | x ) & & & \text{Constant univariate function} & & & \text{Independent of } X \text{ and } Y, \\[6pt]
F( y | \cdot ) & & & \text{Constant univariate function} & & & \text{Independent of } X \text{ and } Y, \\[6pt]
F( y | x ) & & & \text{Constant scalar value} & & & \text{Independent of } X \text{ and } Y, \\[6pt]
F( \cdot | X ) & & & \text{Random univariate function} & & & \text{Not independent of } X, \\[6pt]
F( Y | \cdot ) & & & \text{Random univariate function} & & & \text{Not independent of } Y, \\[6pt]
F( y | X ) & & &\text{Random variable} & & & \text{Not independent of } X, \\[6pt]
F( Y | x ) & & &\text{Random variable} & & & \text{Not independent of } Y. \\[6pt]
F( Y | X ) & & &\text{Random variable} & & & \text{Not independent of } X \text{ or } Y. \\[6pt]
\end{matrix}$$
(Note that this is slightly simplified, insofar as I have not specified dependence on the other random variable; whether there is dependency with the other random variable depends on the original joint distribution and the conditional distribution.)
As you can see, the conditional distribution is independent of the random variable being conditioned on, so long as we take the conditional distribution to be a constant object.  If we condition on the random variable $X$ as a random variable then the conditional distribution becomes a random function (or random variable) that is not independent of $X$.
Answer: The immediate answer is that, if one considers the random variable $Z_k$ with cdf
$$F_k(z)=\mathbb P(Y\le z|X=k)$$
it is defined independently of $X$ and hence $Z$ is independent from $X$.
However, if the question is about the "random variable" $(Y|X=x)$, this object does not exist as such, i.e., separately from $Y$, marginal from the pair $(X,Y)$. That is, $Y$ enjoys both a marginal distribution and a conditional distribution, but remains the same random variable. The cdf $\mathbb P(Y\le z|X=k)$ is thus a characterisation of the conditional distribution of $Y$ when the realisation $X=k$ occurs. Since the conditioning event is $X=k$, the conditional distribution depends on it (or not when $X$ and $Y$ are independent), but it makes no sense to introduce independence once $X=k$ has happened.


Question about an equality

Question: Is this equality correct
$$ \frac{       0 + A \varepsilon e^{-a \varepsilon} + A 2 \varepsilon e^{-a2 \varepsilon}  + \dots         }{ A + A e^{-a\varepsilon} +  A e^{-a2\varepsilon} + \dots } = \frac{\varepsilon}{e^{-a\varepsilon} - 1}, $$
where $A$ and $a$ are constants and $\varepsilon$ is some small number? It seems to me that there should be no minus in the exponent on the r.h.s.
EDITS: Edits were made to correct the third term in the denominator and to add a negative sign in the exponents.
REMARK: This question was answered very well by @dxiv, so I don't understand why it's closed. @dxiv's answer was very helpful, indeed, and that can be useful for other readers of this site as well.
Comment: Why edit the question since it has already been answered, very well, at that?
Answer: Hint:  simplify $A$ between the numerator and denominator, and let $e^{-a \varepsilon}=b\,$ then the LHS is:
$$ \frac{\varepsilon \,( b + 2 b^{2}  + \dots)}{ 1 + b + b^{2} + \dots }$$
For $\,|b| \lt 1 \iff a \varepsilon \gt 0\,$ the series converge $\displaystyle\sum_{n \ge 0} n b^n = \frac{b}{(1-b)^2}$ and $\displaystyle\sum_{n \ge 0} b^n = \frac{1}{1-b}$.

[ EDIT ]   To sum up the comments, the above gives:
$$
\frac{       0 + A \varepsilon e^{-a \varepsilon} + A 2 \varepsilon e^{-a2 \varepsilon}  + \dots         }{ A + A e^{-a\varepsilon} +  A e^{-a2\varepsilon} + \dots } = \frac{\varepsilon \,( b + 2 b^{2}  + \dots)}{ 1 + b + b^{2} + \dots } = \frac{\varepsilon \,b}{1-b} = \frac{\varepsilon}{\cfrac{1}{b}-1} = \frac{\varepsilon}{e^{a \varepsilon}-1}
$$
This differs from the posted RHS of $\;\displaystyle\frac{\varepsilon}{e^{\color{red}{\mathbf{-}}a \varepsilon}-1}\;$ but that must have been a typo in the source text, since with a negative exponent $\,e^{\color{red}{\mathbf{-}}a \varepsilon}-1 \lt 0\,$ while the LHS is always positive.
Comment: Sorry, it's a typo. I'll correct it in the OP.
Comment: all constants are positive but I saw other typos which I'l correct in the OP.
Comment: @ganzewoort Updated my answer accordingly. Also, I guess that should be $\,e^{\color{red}{\mathbb{+}}a \varepsilon}-1\,$ on the RHS.
Comment: The English translation clearly shows a minus there but I guess it's a typo. If it's plus do we also get in the denominator (1 - b)?
Comment: @ganzewoort If it's a minus then $\,e^{\color{red}{\mathbf{-}}a\varepsilon}-1 \lt 0\,$ for $\,a \varepsilon \gt 0\,$, so the RHS would be negative, while the LHS is obviously positive. So, yes, I would assume that's a typo. As for the denominator, the ratio of the two sums above is $\displaystyle\frac{b}{(1-b)^2} \Big{/} \frac{1}{1-b} = \frac{b}{1-b}=\frac{1}{\frac{1}{b}-1}= \frac{1}{e^{a \varepsilon}-1}\,$.
Comment: @ganzewoort `if b>1` Then both series *and* their ratio diverge. Btw, I see you changed the sign again in the question on the RHS. That can't be right, simply because the LHS is always positive while the RHS goes negative with this latest change.
Comment: I understand, but I wanted to keep the equality the way it was in the initial OP, reflecting what I saw in the literature. The typos on the l.h.s. were mine and I corrected them.
Comment: @ganzewoort Understood. I added a note at the end to cover that.
Comment: You answered the question very well, I upvoted your answer and accepted it. The algorithm of the site, however, put it on hold although there's nothing else to be added to it. Therefore, I want to delete the the question. Do you mind?
Comment: @ganzewoort I don't have a problem, that's your call entirely.

Question about an equality


Se eu copiar direto a pasta do projeto do Visual Studio dá algum erro? Ou eu tenho que fazer algo a mais?

Question: Eu queria copiar a Solution do Projeto para o meu professor, posso ir no local do arquivo e somente copiar o projeto e mandar pra ele que vai funcionar?
Comment: Coloca no github e dá o link p/ o seu professor :) hehe
http://gabsferreira.com/criando-e-enviando-arquivos-para-seu-repositorio-no-github/
Comment: Sim, pode só copiar a pasta toda.
Answer: De forma geral é para funcionar. Se o VS dele for da mesma versão. Se forma mais atual é provável que funcione, mesmo que precisa de uma conversão automática, em versões mais antigas que a sua tem uma chance maior de não funcionar.
Claro que o projeto precisa estar em ordem, precisa copiar direitinho (tudo), tem que colocar no lugar certo.
Se o projeto tiver dependências além do que tem por padrão no VS terá que instalar essas dependências, mas em exercícios e coisas do tipo é improvável que tenha dependências extras. Pelo menos não deveria.
Estamos falando do projeto, se a aplicação vai rodar já é outro problema. Mas aí já é problema de deploy.
Answer: Copie tudo inclusive o arquivo .SLN

Ou você pode fazer algo mais bacana e colocar no Git.
http://gabsferreira.com/criando-e-enviando-arquivos-para-seu-repositorio-no-github/


HRESULT '8000000A' in Visual Studio 2017 for WPF Project

Question: I have created setup project for WPF application and need to setup automatic build.  So I am trying to build application from command prompt. I could not able to build setup project using following command.
<code>"Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv" D:\Projects\Pos.sln /rebuild "Release|Any CPU"</code>.
<code>   ` ------ Starting pre-build validation for project 'Pos.Setup' ------
ERROR: An error occurred while validating.  HRESULT = '8000000A'
------ Pre-build validation for project 'Pos.Setup' completed ------
11>------ Rebuild All started: Project: Pos.Setup, Configuration: Release ------
========== Rebuild All: 10 succeeded, 1 failed, 0 skipped ==========`
</code>
I have gone through the every website I could not able to find the answer for Visual Studio 2017.
Any help?
Comment: Why aren't you using msbuild?
Comment: msbuild will not support setup project (The project file "Pos.Setup.vdproj" is not supported by MSBuild and cannot be built). Am using visual studio installer -> Setup Project
Comment: It seems the problem could be no installer project vsix installed on your build machine. This error and a work round is covered here https://stackoverflow.com/questions/46570869/vsts-online-building-setup-projects
Comment: I found the reason behind this error is "the new IDEs do not support build outside the own process".

https://www.kunal-chowdhury.com/2016/07/visual-studio-error-code-8000000A.html.

But I did not found MSBuild path for VS2017 to add the register key.
@Andy
I am using GIT and I need to configure JENKINS automated build.
Answer: Execute the tool that adds the registry hack automatically, it's now part of the installation. I had the same problem today and I was able to fix it with this.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\VSI\DisableOutOfProcBuild\DisableOutOfProcBuild.exe

(change 2019 for 2017 for VS2017).
Found it on this post


Facing issue while querying from two tables using 'with' in sql

Question: spark_df = spark.sql("""
with api_users as
    (
        select
            distinct(user_id)
        from
            act_post
        where
            dt = '2022-08-15'
            and upper(api_source) = 'API'
        limit 100
    )
select
    user_id
from
    (
    unified_user_interest_profile
    )
where user_id in api_users.user_id
limit 100
""")

ERROR
Py4JJavaError: An error occurred while calling o75.sql.
: org.apache.spark.sql.catalyst.parser.ParseException:
mismatched input 'from' expecting <EOF>(line 15, pos 0)

== SQL ==

with api_users as
    (
        select
            distinct(user_id)
        from
            act_post
        where
            dt = '2022-08-15'
            and upper(api_source) = 'API'
        limit 100
    )
select
    user_id
from
^^^
    (
    unified_user_interest_profile
    )
where user_id in api_users.user_id
limit 100
.
.
.
.
.

ParseException: "\nmismatched input 'from' expecting <EOF>(line 15, pos 0)\n\n== SQL ==\n\nwith api_users as \n    (\n        select \n            distinct(user_id)\n        from \n            act_post\n        where \n            dt = '2022-08-15'\n            and upper(api_source) = 'API'\n        limit 100 \n    )\nselect \n    user_id\nfrom \n^^^\n    (\n    unified_user_interest_profile\n    )\nwhere user_id in api_users.user_id\nlimit 100 \n"

I am trying to create a temporary table as api_users and using the user_id column to query all the records from another table unified_user_interest_profile where user_id is present in  api_users.user_id
I am getting the above error and I couldn't understand what is the issue with it.
I am using this SQL command in pyspark to fetch the data.
Comment: Why don't you just do an inner join between 2 tables? the conditions looks straightforward to me
Comment: But I also need to filter the tables first. Not really sure how to do it @pltc
Answer: The conditions looks pretty straightforward, so you can just do an inner join based on user_id
from pyspark.sql import functions as F

api_users = (spark
    .table('act_post')
    .where((F.col('dt') == '2022-08-15') & (F.upper('api_source') == 'API'))
    .select('user_id')
    .distinct()
)

(spark
    .table('unified_user_interest_profile')
    .join(api_users, on=['user_id'], how='inner')
    .show()
)


How is a unique_ptr unique?

Question: I know unique_ptrs cannot be copied only moved and they have no reference counting. But we can have two smart pointers that share a resource:
Foo* f = new Foo;
auto p1 = std::unique_ptr<Foo>(f);
auto p2 = std::unique_ptr<Foo>(f);

Now both of these classes share a pointer to *f. Also, I know this will eventually cause UB because we will be doing double delete but still: What do we really mean by a unique_ptr being "unique" if this is possible?
Comment: I suppose that's up to the developer to make sure never happens. It's using a naked `new`, instead of the recommended `std::make_unique` which would keep this from happening. Some practices might be better than others. They're practices because they're not enforced by the compiler.
Comment: You can even `reintrpret_cast` a pointer to `House` into a pointer to `Cat` but it would sound oddy, right?
Comment: For what it's worth: replacing `unique_ptr` with `shared_ptr` in the example will cause exactly the same problems.  Why is it called `shared_ptr` when two instances pointing to the same object don't share ownership?
Comment: `unique` is to distinguish it from `shared`. There is one unique owner who manages the object's lifetime.
Comment: When constructed the way it was intended, no two unique_ptr instances can manage the same object.
Answer: Beside the fact that I do not believe that this is wanted or portable behaviour, I think that a unique_ptr is also a statement to other people working on the same project.
From the reference:

std::unique_ptr is a smart pointer that retains sole ownership of an
  object through a pointer and destroys that object when the unique_ptr
  goes out of scope. No two unique_ptr instances can manage the same
  object.

As I understand this, the behaviour of the sample you showed is actually not wanted and should not be used at all.
For people without knowledge of the subject (aka programming for dummies): What the OP does is like having two girlfriends, not knowing of each other. You're fine until they find out. When they do, and they definitely will, you'll probably wish you wouldn't have played with the fire.
Answer: To understand the terminology, you have to contrast unique_ptr and shared_ptr:

the former should be the sole responsible for managing the resource it points to
the latter should be sharing this responsibility with a set of peers

Often times, you will hear the term ownership to describe the responsibility of cleaning up.
Now, like many things in C++, you can attempt to subvert the system: only the intention is described, it's up to you to uphold your end of the bargain.
Answer: Your question is akin to,

How is a crescent wrench a wrench when I can use it to drive nails in
  to the wall?

In other words, just because you can incorrectly use a tool to do something that shouldn't be done with it, doesn't mean it can't do what it was designed to do.
A unique_ptr is unique in the sense that you won't make copies of the pointer if you use it correctly.  It ensures that there's only one controlling object, and that the controlled object is destroyed properly when the container is destroyed.
Answer: This is about ownership semantics:

Sole or unique ownership (e.g. std::unique_ptr and the old friend std::auto_ptr): only one pointer at a time owns an object.
Shared ownership (e.g. std::shared_ptr, boost::intrusive_ptr, linked_ptr): many pointers share the same object.
Answer: It's unique because, when used correctly, it represents a unique ownership model - only one pointer gives access to, and controls the lifetime of, an object. Compare this to shared_ptr, which represents a shared ownership model - more than one pointer can be used to access and manage the same object.
As you point out, you can break that model by messing around with dumb pointers (either keeping hold of the one used to initialise the smart pointer, or by using get() or similar to bypass the ownership model). As always, it's up to the programmer to be careful not to do the wrong thing with dumb pointers. There is nothing a smart pointer can do to control the use of dumb pointers.
Answer: Not wishing to put words in the OP's mouth, but I think the issue they may be raising might be to do with naming. Perhaps they are saying something like:
'Aaaaah! It makes no sense! The language is a work of lunacy! Lunacy, I tell you! Run! Run! Save yourselves!'.
If that's what the OP is hinting at then...
Rather than look for 'meaning' in C++ words and symbols, just try to remember their actual effects. eg 'unique' doesn't mean 'One only', even though it appears to mean exactly that, it merely has the effect of indicating that the ptr should be used in certain ways and not others. Similarly, 'Private' does not mean private, but has an effect on how something is shared. 'Static' things can move, and 'move' keeps things where they are to avoid copying them to a new location.
All you have to do is read the documentation forever, and accept the pain.
See also 'Alice Through The Looking-Glass'.

How is a unique_ptr unique?


Report file viewer for Magento 1

Question: Is there any file viewer for Magento 1.x ?
I need something to browse var/report folder from admin, and see error details
That for admin users of Magento, to know what happen, and decide call or no to developers support
Answer: Here is simple extension you can use, to allow admin check report error files
http://www.xpscommerce.com/magento-admin-view-var-report-errors/
Browse var/report folder from UI admin.

Report file viewer for Magento 1


Como usar um construtor com duas ou mais classes?

Question: Estou em desenvolvimento de uma biblioteca de orientação-a-objetos. Criei um iterator para meu futuro container. Tenho advance_iterator e regress_iterator. Ambos dão origem a bidirectional_iterator. O código é:
#ifndef OBJSTD_ADVANCE_ITERATOR
#define OBJSTD_ADVANCE_ITERATOR
#include <cstddef>
namespace objstd
{
    template <typename data_type> class advance_iterator
    {
        public:
        advance_iterator(data_type* data_ref)
        {
            this->data_reference = data_ref;
        }
        advance_iterator(const advance_iterator& it) = default;
        advance_iterator(advance_iterator&& it) = default;
        virtual bool operator > (const advance_iterator& it) const
        {
            return this->data_reference > it.data_reference;
        }
        virtual bool operator < (const advance_iterator& it) const
        {
            return this->data_reference < it.data_reference;
        }
        bool operator == (const advance_iterator& it) const
        {
            return this->data_reference == it.data_reference;
        }
        bool operator != (const advance_iterator& it) const
        {
            return this->data_reference != it.data_reference;
        }
        virtual bool operator >= (const advance_iterator& it) const
        {
            return (*this).operator>(it) || (*this).operator==(it);
        }
        virtual bool operator <= (const     advance_iterator& it)const
        {
            return (*this).operator<(it) || (*this).operator==(it);
        }
        virtual advance_iterator& operator+=(const size_t skips)
        {
            this->data_reference += skips;
            return *this;
        }
        virtual advance_iterator& operator++()
        {
            *this += 1;
            return *this;
        }
        virtual advance_iterator& operator++(int)
        {
            advance_iterator& state = *this;
            this->operator++();
            return state;
        }
        virtual advance_iterator operator+ (const size_t skips)
        {
            return this->data_reference + skips;
        }
        //must be declared virtual for non-conservational
        virtual data_type& operator*() const
        {
            return *this->data_reference;
        }
        protected:
        data_type* data_reference;
    };
}

#endif // OBJSTD_ADVANCE_ITERATOR

regress_iterator
#ifndef OBJSTD_REGRESS_ITERATOR
#define OBJSTD_REGRESS_ITERATOR
#include <cstddef>
namespace objstd
{
    template <typename data_type> class regress_iterator
    {
        public:
        regress_iterator(data_type* data_ref)
        {
            this->data_reference = data_ref;
        }
        regress_iterator(const regress_iterator& it) = default;
        regress_iterator(regress_iterator&& it) = default;
        virtual bool operator > (const regress_iterator& it) const
        {
            return this->data_reference > it.data_reference;
        }
        virtual bool operator < (regress_iterator& it) const
        {
            return this->data_reference < it.data_reference;
        }
        bool operator == (regress_iterator& it) const
        {
            return this->data_reference == it.data_reference;
        }
        bool operator != (regress_iterator& it) const
        {
            return this->data_reference != it.data_reference;
        }
        virtual bool operator >= (regress_iterator& it) const
        {
            return (*this).operator>(it) || (*this).operator==(it);
        }
        virtual bool operator <= (regress_iterator& it)const
        {
            return (*this).operator<(it) || (*this).operator==(it);
        }
        virtual regress_iterator& operator-=(size_t backwards)
        {
            this->data_reference -= backwards;
            return *this;
        }
        virtual regress_iterator& operator--()
        {
            *this -= 1;
            return *this;
        }
        virtual regress_iterator& operator--(int)
        {
            regress_iterator& state = *this;
            this->operator--();
            return state;
        }
        virtual regress_iterator operator- (size_t backwards)
        {
            return this->data_reference - backwards;
        }
        //must be declared virtual for non-conservational
        virtual data_type& operator*() const
        {
            return *this->data_reference;
        }
        protected:
        data_type* data_reference;
    };
}

#endif // OBJSTD_REGRESS_ITERATOR

E bidirectional_iterator é definido assim:
#ifndef OBJSTD_BIDIRECTIONAL_ITERATOR
#define OBJSTD_BIDIRECTIONAL_ITERATOR
#include "regress_iterator.hpp"
#include "advance_iterator.hpp"
namespace objstd
{
    template <typename data_type> class bidirectional_iterator : public advance_iterator <data_type>, public regress_iterator <data_type>
    {
    };
}

#endif // OBJSTD_BIDIRECTIONAL_ITERATOR

O problema é ao criar uma instancia do tipo bidirectional_iterator(ponteiro), pois o compilador não sabe como inicializar. O que estou fazendo de errado?
Answer: Em C++ os construtores não são herdados implicitamente pela classe derivada justamente para evitar esse tipo de ambiguidade. No C++11 você pode explicitamente herdar um dos construtores usando using, que não faria muito sentido no seu caso, já que existem duas bases.
A solução para você é implementar um construtor na sua classe:
template <typename data_type>
class bidirectional_iterator : public advance_iterator<data_type>,
                               public regress_iterator<data_type>
{
public:

    bidirectional_iterator(data_type* data_ref) :
      advance_iterator<data_type>(data_ref),
      regress_iterator<data_type>(data_ref) {
        // do nothing
    }

};

Comment: @LucasHenrique Opa, faltou o argumento template ali na inicialização. Corrigido.
Comment: Eu já tentei fazer isso, mas recebi o erro de que não há tais membros na classe.
Comment: Agora entendi; obrigado. Vou checar depois que dormir ^cansado^.
Comment: Guilherme, alguns erros me apareceram por ambiguidade e não sei o que fazer. Você pode me ajudar?
Comment: @LucasHenrique, será que você não está com algum problema de compilador? Eu testei [o código do Guilherme aqui](http://coliru.stacked-crooked.com/a/b934db8c66d91d4c) e não tive nenhum erro...
Comment: @Massa ele atualizou antes do teu comentário.
Comment: Então acho que você pode marcar a resposta dele como sendo a correta! :D


DRF HawkREST authentication failed with postman

Question: Im using this library: https://hawkrest.readthedocs.io/en/latest/
In my settings.py:
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'hawkrest.HawkAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
}

HAWK_CREDENTIALS = {
    'script-user': {
        'id': 'script-user',
        'key': 'aabbcc',
        'algorithm': 'sha256'
    },
}

In postman:

In console output:
access denied: MisComputedContentHash: Our hash b'l0mKQ9ZG6Df44jdvH1FthWGvtKN93umZdmQCqd7YcgI=' (sha256) did not match theirs

Comment: What version of Django are you using?
Comment: @ReinstateMonica latest one. 3.0.3
Answer: HawkREST only supports Django 1.11 through 1.8 and its github hasn't been updated in over 2 years, so it is likely that it won't work at all in your version.
Comment: i think this is not the case, I think postman is missing hash key-value in the Authorization header, not sure how to add. I ticked "Include payload hash" but it's not adding anything


column passed error while putting a list in a dataframe

Question: I have this list :
20161216014500
20161216020000
20161216021500
20161216023000
20161216024500
20161216030000
20161216031500
20161216033000
20161216034500
20161216040000
20161216041500
20161216043000
20161216044500
20161216050000
20161216051500
20161216053000
20161216054500

And I want after parsing it and putting it in the correct format by this code:
for row in rows:
    if "".join(row).strip() != "":
        chaine = str(row[0]+row[1])
        date = chaine[:10] + " " + chaine[11:]
        header = parseDate(date)
        header = str(header).replace('-','')
        header = str(header).replace(':','')
        header = str(header).replace(' ','')
        print header

I want to insert the header(the list above) in a dataframe using pandas:
newDataframe = pd.DataFrame(data, index=index, columns=header)

This is the error I get:
 14 columns passed, passed data had 1 columns

What is the reason of this error and how to correct it ?
Comment: Your code and data is incomplete, what is `data` here? additionally the error is clear, you're passing a list 14 columns but your data is a single column hence the error
Answer: You can do the same thing this way:
import pandas as pd
rows = ['20161216014500',
'20161216020000',
'20161216021500',
'20161216023000',
'20161216024500',
'20161216030000',
'20161216031500',
'20161216033000',
'20161216034500',
'20161216040000',
'20161216041500',
'20161216043000',
'20161216044500',
'20161216050000',
'20161216051500',
'20161216053000',
'20161216054500']

df = pd.DataFrame(rows, columns=['date'])

pd.to_datetime(df['date'], format='%Y%m%d%H%M%S')

df

output:
    date
0   20161216014500
1   20161216020000
2   20161216021500
3   20161216023000
4   20161216024500
5   20161216030000
6   20161216031500
7   20161216033000
8   20161216034500
9   20161216040000
10  20161216041500
11  20161216043000
12  20161216044500
13  20161216050000
14  20161216051500
15  20161216053000
16  20161216054500

Answer: import io
import pandas as pd

a = io.StringIO(u"""20161216014500
20161216020000
20161216021500
20161216023000
20161216024500
20161216030000
20161216031500
20161216033000
20161216034500
20161216040000
20161216041500
20161216043000
20161216044500
20161216050000
20161216051500
20161216053000
20161216054500""")

df = pd.read_csv(a, header=None, parse_dates=[0],
                       date_parser=pd.tseries.tools.parse_time_string)
df.head()

Output:
                    0
0 2016-12-16 01:45:00
1 2016-12-16 02:00:00
2 2016-12-16 02:15:00
3 2016-12-16 02:30:00
4 2016-12-16 02:45:00


Como fazer divisão de uma string com valor dinamico?

Question: Eu não sei se é o split que usa, no jquery, mas não estou tendo sucesso. Em meu código eu recebo o valor de ID que vem dinamicamente, quero dividir o ID em dois. Uma parte até o caracter 16 e depois o restante.. como posso fazer isso?
Comment: Por favor, mostre o seu código.
Comment: A função que procura é a [`substr`](https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/String/substr), mas como já comentado, será melhor se você [edit] a pergunta e adicionar o seu código para sabermos exatamente o que precisa e como resolver.
Comment: @Taynara Jaegger adicione o código à sua pergunta por favor.
Answer: O código a seguir fala por si só.
Ele pega um valor string, sua id dinâmica e reparte entre 2 variáveis(String):

var id = "suaIDgeradaDinamicamente";
var primeiraParteID = id.substring(0,16);
var segundaParteID = id.substring(16);

console.log("ID :"+id+" - "+id.length);
console.log("Primeira parte da id 0 até 16 caracteres :"+primeiraParteID);
console.log("Segunda parte da id :"+segundaParteID);
Comment: Muito obrigada funcionou para que eu estava precisando realmente, mais um aprendizado, estava usando o split e não conseguia, agora sei o que uso.
Comment: Ótimo, evitei o uso do split, porque isso não é muito complexo e o substring por ser nativo tem uma melhor performance.


HTML select is empty whatever I do

Question: I must be doing something very stupid.
Whatever I tried I always get an empty select.
This is the code:
<code>   <select>
       <option disabled="">jknjk</option>
       <option selected value="local"> Со склаа</option>
       <option value="preorder"> Предзаказ</option>
    </select>
</code>

I swear I used select elements before and never had problems with it.
But I have no ideas why it works so in this case when it shouldn't.
If I click it one time after loadiing - it can be used.
As one can see it has selected value  (in inspector)
Could it be some CSS what makes it behave so?
Full image
Full css styles attached to select element
Comment: Must be your CSS, works fine: http://jsfiddle.net/qyej6j4m/. Looking at the display it looks like you're using a dropdown plugin. Do you populate the select after the plugin is called?
Comment: @Sam: Input tags don't need to be closed in HTML5.
Comment: What about styles assigned to `select>option` ?
Comment: I think it's because you haven't closed a tag above. Your input tags perhaps. Try putting at the top.
Comment: Looking at the CSS, it is *not* a select replacement. Besides, it rather looks like a native control, not like a plugin.
Comment: Good point, just checked that. Perhaps another unclosed tag.
Comment: Not sure how relevant this may be, however try temporarily removing all bootstrap includes. I've heard of cases where, if you have multiple bootstrap includes certain aspects will not work. For example,  if you have bootstrap.js, you should not add bootstrap-dropdown.js.
Comment: Do you have a fiddle or complete code so we can examine it? A screenshot and some random CSS is not helpful.
Comment: It works here:  http://codepen.io/anon/pen/QbaLKy
Answer: This appears to be a Chrome bug, discussed on this question and this question. A work-around solution is to apparently set 'autocomplete="off"' on the form. Perhaps keep an eye on the status of the bug report that was filed in the second link, to see the bug fixed or find a permanent solution.

HTML select is empty whatever I do


Generators of $\text{GL}_2(\mathbb{Z})$ and $\text{SL}_2(\mathbb{Z})$.

Question: We denote by $(a,b,c)$ the integral binary quadratic form $q(x,y)=ax^2+bxy+cy^2$. Also, we denote by $\sim$ (resp. $\sim_+$) $\text{GL}_2(\mathbb{Z})$ equivalence (resp. $\text{SL}_2(\mathbb{Z})$ equivalence).
I know that for all $a,b,c\in\mathbb{Z}$ we have that $(a,b,c)\sim (a,-b,c)$ and
$$(a,b,c)\sim_+ (c,-b,a)\sim_+ (a,b+2a,c+b+a)\sim_+ (a,b-2a,c-b+a).$$
This is simply the fact that
$\begin{bmatrix}1 & 0 \\ 0 & -1\end{bmatrix}$
is in $\text{GL}_2(\mathbb{Z})$ and
$$\begin{bmatrix}0 & 1 \\ -1 & 0\end{bmatrix},\qquad \begin{bmatrix}1 & 1 \\ 0 & 1\end{bmatrix},\qquad\begin{bmatrix}1 & -1 \\ 0 & 1\end{bmatrix}$$
are in $\text{SL}_2(\mathbb{Z})$.
I want to know if all equivalent forms can be obtained by repeated applications of those rules. In other words, whether these matrices generate the respective groups or not.
(Since $\mathbb{Z}$ is an euclidean domain, I know that $\text{GL}_2(\mathbb{Z})$ is generated by elementary matrices but it's not clear to me that all elementary matrices can be written as a product of the ones above.)
Answer: It is true that $\mathrm{SL}_2(\mathbb Z)$ is generated as a monoid by
$$S = \begin{bmatrix}0 & 1 \\ -1 & 0\end{bmatrix}, \qquad  T = \begin{bmatrix}1 & 1 \\ 0 & 1\end{bmatrix},\qquad T^{-1} = \begin{bmatrix}1 & -1 \\ 0 & 1\end{bmatrix}$$
and thus $\mathrm{GL}_2(\mathbb Z)$ is generated by those matrices together with $\begin{bmatrix}1 & 0 \\ 0 & -1\end{bmatrix}$. See for example Modular group at Wikipedia, section "Presentation". I think this is originally due to Poincaré. Serre's book "Trees" contains more of this.
For references, Generators of $\text{GL}_{2}(\mathbb{Z})$ group, good reference book?


(Repost) Finance annual payment amount

Question: Example 2.6 A business owner takes out a loan of 450'000 on January 1 at a fixed-interest rate of 9% per year. It is payable over 15 years level payments due on each December 31 for the first 14 years and a final payment of 50'000 due on December 31 of the 15th year. Calculate the annual payment amount.
Final answer is 56032.
How do the book come up with answer?
Comment: What do you mean by "repost" ?
Comment: What are your thoughts on the problem? Can you experiment, in Excel for example, with numbers to see what fits?
Comment: see http://financeformulas.net/Loan_Payment_Formula.html
Answer: Hint: You just have to set equal the future value (end of year 15) of the loan and the future value (end of year 15) of the payments.
$$\underbrace{1.09^{15}\cdot 450,000}_{\text{future value of the loan}}=r\cdot \underbrace{\underbrace{\frac{1-1.09^{14}}{1-
1.09}}_{ \text{future value of the first 14 pmts}\\ \text{at the end of year 14  }}\cdot1.09}_{\text{future value of the first 14 pmts}\\ \text{at the end of year 15  }}+\underbrace{50,000}_{\text{future value of the last payment}}$$
The key point that the reference point in time on both sides of the equation is 15 years in the future.
Comment: Yes finally thanks! and I get the desired answer by solving for "r" @callculus
Comment: @Jaehaerys Your´re welcome. Nice that you´ve got the answer.

(Repost) Finance annual payment amount


java.lang.NoSuchMethodError: javax.persistence.Table.indexes()

Question: I'm trying to make maven aplication with database using hiberntate. And one error appears all the time when I want to use it in GUI after pressing the button.
  Session session =  Service.getSession();

here is an error:
Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:973)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
at models.Service.Service.<clinit>(Service.java:23)
at GUI.Student.RegisterOnExam.getSubjects(RegisterOnExam.java:108)

I tried to change dependences and hibernate.cfg.xml but it still does not work.
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>groupId</groupId>
<artifactId>Test</artifactId>
<version>1.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <phase>install</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/lib</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>${mainClass}</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <mainClass>main.java.Main</mainClass>
</properties>
<dependencies>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901-1.jdbc4</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.7.Final</version>
    </dependency>

    <dependency>
        <groupId>javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.12.1.GA</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.4</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.5</version>
    </dependency>

</dependencies>

Here is a Service class which I use to begin a transaction. I tried to change it too somehow.
package models.Service;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class Service {
    private static final SessionFactory sessionFactory;
    static {

            sessionFactory = new AnnotationConfiguration()
                    .configure().buildSessionFactory();

    }
    public static Session getSession()
            throws HibernateException {
        return sessionFactory.openSession();
    }

}

It seems the problem is in it but I don't think so. How can I correct my program?
Answer: buildSessionFactory() in your code is deprecated for the Hibernate version you are using. You will have to fix your code. This question explains more about the deprecated session factory.