Calculate the confidence interval of parameter of exponential distribution?

Question:
How can I calculate the confidence interval for parameter $\alpha$ of
  exponential distribution ?

I think I can use test-t. Knowing that:
$$mean = {1\over\alpha}$$
I found that :
$${1\over {\bar X + \frac{S}{\sqrt{n}}\cdot t_{\alpha/2,n - 1}}}<\alpha<{1\over {\bar X - \frac{S}{\sqrt{n}}\cdot t_{\alpha/2,n - 1}}}$$
Is this right? In general, can I use test-t for determining the confidence interval of an exponential distribution ?
If not, is there any other possibility to do this ?
Comment: If either Answer is a useful, please click one of them to accept, so it will eventually drop off the queue of questions without satisfactory answers. If you need something further, please be specific.
Answer: A t-interval would be a very approximate procedure here. It is intended for use when the data are at least roughly normal, and the exponential distribution is very far from normal. (Such a procedure
might be OK for really large samples.)
CI based on gamma distribution. Here is a better way: If $X_1, X_2, \dots, X_n$ are a random sample
from $Exp(rate=\alpha)$ then $\alpha \bar X \sim Gamma(n, n).$
Let $g_L$ cut off probability 2.5% from the lower tail of this
distribution and $g_U$ cut off 2.5% from its upper tail. Then
$$P(g_L \le \alpha \bar X \le g_U) = P(g_L/\bar X \le \alpha \le g_U/\bar X) = 0.95.$$
Thus a 95% CI for $\alpha$, is $(g_L/\bar X,\; g_U/\bar X).$
For example, let $n = 20$ and $\bar X = 6.32.$ Then you
can use R (or other statistical software) to obtain
$g_L = 0.611,$ and $g_U = 1.484,$ so that
the CI is
$(0.097, 0.235).$  In R, the procedure was:
<code> x = rexp(20, .2)                      # generate fake data, rate = .2
 mean(x)                               # find sample mean
 ##  6.322473
 qgamma(c(.025,.975), 20, 20)/mean(x)  # 'qgamma' is quantile fcn; 95% CI
 ##  0.09661188 0.23464596
</code>
In this case the data were generated to have $\alpha = .2,$ so
we know the CI covers $\alpha.$ Most statistical software
packages have the ability to find quantiles (inverse CDFs)
of gamma distributions. (The Wikipedia 'exponential distribution'
article has an equivalent formula using the chi-squared distribution,
if you must use printed tables.)
Comparison with inferior t-interval. The "95%" t CI is $(3.638, 9.007)$ for $\mu = 1/\alpha$
and so $(0.111, 0.275)$ is the CI for $\alpha.$
But such intervals
from the t distribution do not have an actual
95% confidence level because the distribution theory is
incorrect. (The actual coverage probability depends on $n;$
for $n = 20,$ it is about 92% instead of 95%. Other values
I approximated by simulation are: 88% for $n=5$; 93% for $n=50.$)
Addendum: From a theoretical point of view, $\bar X$ is a 'sufficient statistic' for estimating $\alpha.$ This means that the sample SD $S$ is providing less than optimal information about $\alpha.$ The t-interval uses both $\bar X$ and $S,$ and to the extent that $S$ influences the answer, the t-interval must be an inferior method. For small $n,$ the role of $S$ is very prominent.
Notice that the method with the gamma distribution requires you to compute only $\bar X$ from the data; computing and using $S$ is not only extra work, it is counterproductive extra work.
Answer: An alternative method is to use a Bayesian approach (in which case, the interval estimate calculated is not a "confidence interval" but a "credible interval").  The idea is to treat the rate parameter $\lambda$ as a random variable.  For observations $$X_i \sim \operatorname{Exponential}(\lambda)$$ the conjugate prior is Gamma distributed; i.e. the choice $$\lambda \sim \operatorname{Gamma}(a,b)$$ gives a posterior distribution for $\lambda$ that is also gamma:  that is to say, $$\lambda \mid \boldsymbol x \sim \operatorname{Gamma}(a + n, b + n \bar x)$$ where $\boldsymbol x = (x_1, x_2, \ldots, x_n)$ is the sample (all distributions are parametrized by rate).  Specifically, then, given the prior parameters $a, b$ that inform your "belief" about $\lambda$, and the observed sample $\boldsymbol x$, the posterior distribution which takes into account the data you observed, has the density function $$f(\lambda \mid \boldsymbol x) = \frac{(b + n \bar x)^{a+n} \lambda^{a+n-1} e^{-(b + n \bar x)\lambda}}{\Gamma(a + n)}.$$   Hence, we can construct a $100(1-\alpha)\%$ credible set in a number of ways.  One way is to find the interval for $\lambda$ such that the tails of the posterior distribution contain $\alpha/2$ probability:  that is, we need to find $\lambda_L < \lambda_U$ such that $$\int_{\lambda = 0}^{\lambda_L} f(\lambda \mid \boldsymbol x) \, d\lambda = \int_{\lambda_U}^\infty f(\lambda \mid \boldsymbol x) \, d\lambda = \frac{\alpha}{2}.$$  Another is to find the interval with highest posterior density (HPD) such that $f(\lambda_L \mid \boldsymbol x) = f(\lambda_U \mid \boldsymbol x)$ and $$\int_{\lambda = \lambda_L}^{\lambda_U} f(\lambda \mid \boldsymbol x) \, d\lambda = 1-\alpha.$$  As you can see, interval estimates are not unique and can be constructed in different ways and with different approaches.  The advantage of the Bayesian method is that the real thing of interest you get is the posterior (and that this posterior is easily updated with new data).  The downside is that you might not always know what to choose for the prior parameters.
Comment: If one chooses a minimaly-informative prior with $a$ and $b$ both very small, then the Bayesian posterior probability interval (credible interval) is numerically very similar to the frequentist interval in my Answer. (But the philosophical interpretations of Bayesian interval estimates and frequentist confidence intervals are different.) However, it is difficult to believe that a competent researcher approaches data collection without  'hunches' that might be turned into an informative prior.
Comment: @BruceTrumbo Indeed.  In applied statistics, Bayesian methods are quite attractive for this precise reason.  At the same time, there is a certain awareness of not giving the appearance of manipulating the analysis (which I think is the main reason why there is reluctance to use informative priors or at the least, to report the results with minimally informative or non-informative priors in conjunction).  Yet frequentists make similar assumptions when, for example, they calculate sample size and power based on historical data.


Set default value for taxonomy list using form_alter

Question: how do I Set default value for taxonomy list?
I have tried altering form with the following line included, but it didn't work:
<code>$form['taxonomy'][3]['#default_value'] = 6;
</code>
3 is my VOC ID and 6 TID that I want to select as default
Comment: Which version of Drupal ?
Comment: I am using Drupal 6
Answer: If you are using hook_form_alter I believe this will work
<code>$form['taxonomy'][3]['#default_value'] = array(0 => 6);
</code>


xenserver - install centos issue

Question: I got a new server with xenserver installed on it and I'm using the xenclient remotely. Can someone let me know what URL I need to use to install from url for centos 5.4 x64? Alternative is to mount the netinstall iso on the server however I can't find any instructions on how to do that.
Any help would be much appreciated :)
Answer: you need to get a mirror close to your region then you will need to provide the following
<code>http://your_mirror
/5.4/os/x86_64
</code>
for example http://centos.arcticnetwork.ca/5.5/os/x86_64/  - because some mirrors don't have the 5.4 anymore you may need to search a bit.
Answer: You could also set up an ISO library in XenCenter using an existing NFS or CIFS share where you can store the ISO images you want to install from. If you don't have any NFS share yet, I would recommend creating a fileserver VM using the TurnKey Linux Fileserver appliance.
This way you don't need to mount the net install ISO, you can simply "insert" it into the VM's optical drive and boot the VM from it. However, if the net install ISO doesn't contain the proper kernel for XenServer, than you should use the "Other" template instead of a "CentOS" template when creating the VM in XenCenter, and convert it into a PV guest after the installation is complete, since you'll get a HVM guest this way. You can find my instructions for that here.

xenserver - install centos issue


Function for the upper left part of a circle

Question: What is the function corresponding to the upper left quarter of a circle ? Where $x$ goes from 0 to $x_\text{max}$, and $y=f(x)$ goes from $y_\text{min}$ to $y_\text{max}$.
Comment: What is your ultimate goal here? Is this a homework problem?
Answer: Maybe you are thinking of shifting the upper half-circle $y=\sqrt{r^2-x^2}$ to an arbitrary center $(x_0,y_0)$ to get $y=y_0+\sqrt{r^2-(x-x_0)^2}$? To get the upper left corner of that, restrict $x$ to $[x_0-r,x_0]$. If the lower bound on $x$ is $0$, then $x_0=r$, which implies that $y_max-r=y_min=y_0$. Is that what you are looking for?
If, on the other hand, you want an ellipse (with axes parallel to the $x$ and $y$ axes), then the radius $r$ needs to be replaced by two lengths, the distance from center in the $x$ and $y$ directions. These distances are usually denoted $a$ and $b$, and called the semi-major (for the larger) and semi-minor (for the smaller length) axes. So from the equation
$$
\left(\frac{x-x_0}{a}\right)^2 +
\left(\frac{y-y_0}{b}\right)^2 = 1
$$
to get a function, you need to solve for $y$. When you take the square root, you need to introduce a $\pm$ sign, but for the upper half, you choose the positive square root. If you see how the above equation corresponds to the schematic diagram of the ellipse, and if you are given corner/edge and/or central points, then you can quickly solve your problem for the constants $a,b,x_0$ and $y_0$.
The above ellipse lies in the rectangle where $x\in[x_0-a,x_0+a]$ and $y\in[y_0-b,y_0+b]$. Thus we have the correspondence
$$
\matrix{
x_\text{min} = x_0-a &\qquad&
y_\text{min} = y_0-b \\
x_\text{max} = x_0+a &\qquad&
y_\text{max} = y_0+a
}
$$
for the "edges" or horizontal & vertical extreme points/tangents
of the ellipse, and the functional form
$$
y = y_0 \pm b\sqrt{a^2-(x-x_0)^2}
$$
for the top (choosing the $+$ from $\pm$)
and bottom  (choosing the $-$ from $\pm$)
halves of the ellipse.
If you are given the minimum and maximum $x$ and $y$ values, you can use the above equations to find the center $(x_0,y_0)$ and the "radii" $a$ & $b$.
Do you see how to do that? A hint is that the $x$ coordinate of the center,
$x_0$, is the average value of $x$ on the ellipse, or, algebraically, that you should try adding the equations above in each column separately.
Is this what you need? What are you ultimately trying to accomplish? Do you need the functional form (or would perhaps a parametric form better suit your goals)?
Comment: If you type this equation on google: 100+sqrt((1000-100)^2-(x-(1000-100))^2)
You will see that y is between 100 and 1000 (this is what I want, Y is always between 100 and 1000), and y is between 0 and 1800 according to the curve, but I want y to be between 0 and eg 7000 (not 1800). How can I modify this function according to this even if it will not be a part of a circle but a part of an ellipse.

Here I want y_low = 100, y_up = 1000, x_low = 0, x_up = 7000


Why post.post in my model isnt being displayed in html? (Post)

Question: Hi I am trying to display {{post.post}} in html, it worked previously but now it doesn't. The name of the user and date show, and the post is working.. but no success in displaying post.post. Wheres the problem? I've displayed the output below and highlighted something that could give an indication. TIA
html:
{% extends 'base.html' %}

{% block body%}

Home

    <form method="post">
        {% csrf_token %}
        {{ form.as_p }}
        <button type="submit">Submit</button>
</form>

{{ text }}

{% for post in posts %}

{{ post.post }}

Posted by {{ post.user.get_full_name}} on {{ post.date }}

{% endfor %}

{% endblock %}

models.py:
class Post(models.Model):
    post = models.CharField(max_length=500)
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    date = models.DateTimeField(auto_now_add=True)

views.py:
class HomeView(TemplateView):
   template_name = ('home/home.html')

   def get(self, request):
     form = HomeForm()
     posts = Post.objects.all()

     args = {'form': form, 'posts': posts}
     return render(request, self.template_name, args)

   def post(self, request):
     form = HomeForm(request.POST)
     if form.is_valid():
        post = form.save(commit=False)
        post.user = request.user
        post.save()
        text = form.cleaned_data['Post']
        form = HomeForm()
        return redirect('home:home')

     args = {'form': form, 'text': text}
     return render(request, self.template_name, args)

output:
hfdhdth
Posted by john wick on Oct. 11, 2018, 6:56 p.m.
vdfgrgrtg
Posted by john wick on Oct. 11, 2018, 6:56 p.m.
'btgthh' <------AFTER THIS DOESNT DISPLAY
Posted by john wick on Oct. 11, 2018, 6:56 p.m.

Posted by john wick on Oct. 11, 2018, 7:13 p.m.

Posted by john wick on Oct. 11, 2018, 7:13 p.m.

Posted by john wick on Oct. 11, 2018, 7:13 p.m.

Comment: is this in the get request or post request?
Comment: I don't know its in post request I think
Answer: You aren't including the posts in the context data for the post request when the form isn't valid, you simply just need to add this to the context
args = {'form': form, 'text': text}

to
args = {'form': form, 'text': text, 'posts': Post.objects.all()}

Comment: really weird...im going to take a break but thanks for the help. I got this after I typed that code in terminal:
In [2]: Post.objects.exclude(post="").values_list('post', flat=True)
Out[2]:
really weird seemed like it just bugged out
Comment: this didn't fix it
Comment: @JosephS - Then your problem isn't anything to do with your code shown here. Most likely, those other posts just don't contain any text, Try doing `Post.objects.values_list('post', flat=True)` in a terminal or just output somewhere
Comment: did that ...NameError: name 'Post' is not defined
Comment: @JosephS - Yes you'd need to import it.. just include it in the context of your get request if thats easier.
Comment: In [3]: Post.objects.values_list('post', flat=True)
Out[3]:
Comment: @JosephS - Right, so you have a load of posts without any text in the post
Comment: Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181699/discussion-between-josephs-and-sayse).
Comment: I see but I write text in the field? sorry don't want to turn this into a chat for guidelines sake
Comment: @JosephS - That may be but you're db still contains lots of posts you've made erroneously, `Post.objects.exclude(post="").values_list('post', flat=True)`, might help you to visualise this better but basically your problem is with the data, not the code
Comment: managed to fix it
views.py: text=form.cleaned_data['post']

forms.py: post=forms.Charfield()


Why $x \mapsto f(x) + \frac{x}{n}$ is a strictly increasing function? and how to prove that $A$ ia an interval?

Question: I am trying to solve the following problem:
Let $I$ be an interval and $f: I \to \mathbb{R}$ be increasing. Show that $f$ is measurable by first showing that, for each natural number $n$, the strictly increasing function $x \mapsto f(x) + \frac{x}{n}$ is measurable, and then taking pointwise limits.

But I do not understand the function $x \mapsto f(x) + \frac{x}{n}$ is strictly increasing even thought there no restriction on $x$. Sorry if my question is stupid. Could someone help me in understanding this please?

Also, I know that if we define $f_n(x) = f(x) + \frac{x}{n}$ for each natural number $n$ and we fix a real number $c$ and define $B = \{x \in I: f_n(x) > c \}$ then, to solve the problem, we should show that $B$ is an interval. I feel like the Intermediate Value Theorem would help here but how? or just the strictly increasing property of $f_n(x)$? Any explanation will be greatly appreciated!
Comment: For $x < x'$, you know that $f(x) \le f(x')$. Thus $f(x) + \frac{x}{n} < f(x') + \frac{x'}{n}$.
Answer:
We are told that $f$ is (presumably weakly) increasing i.e. if $x<y$ then $f(x)\le f(y)$. Thus, if $x<y$ then $f(x)+\frac{x}{n}\le f(y)+\frac{x}{n}<f(y)+\frac{y}{n}$. So $x \mapsto f(x) + \frac{x}{n}$ is strictly increasing. More generally, if you add a weakly increasing function to a strictly increasing function then you will get a strictly increasing function (by the exact same steps).

We can just use the strictly increasing property. How might you tell that $B$ is an interval? Well, one sufficient condition is that if you pick any two points in $B$, every value between them is included (e.g. if $1,2\in B$, then $[1,2]\subseteq B$). So, let's pick $x,y\in B$ with $x<y$. Then, pick a value between them: $z$ satisfying $x<z<y$. We know that $f(x)>c$ and $z>x$ and $f_n$ is strictly increasing, so $f(z)>c$, so $z\in B$ as required.


Inverter lista simplesmente encadeada

Question: Fiz a implementação de uma lista encadeada e o método para listar os elementos, mas queria agora printar ela invertida (Por exemplo: 1>2>3 = 3>2>1). Alguém poderia me ajudar?
//iniciamente a minha lista não aponta para lugar algum
public static Nodo inicio = null;

public static void print() {

    if (inicio == null) {
        System.out.println("Nada a exibir - a lista está vazia!");
    } else {
        Nodo aux = inicio;
        while (aux != null) {
            System.out.print(aux.getChave() + " ");
            aux = aux.getProx();
        }
    }
}

public void inserir(int e) {
    //criar um novo Nodo
    Nodo novo = new Nodo();
    novo.setChave(e);    //inserindo elemento
    novo.setProx(null); //depois dele não vem ninguém

    if (inicio == null) {
        inicio = novo; //aponto para o novo nodo
    } else {     //ja tem gente na lista ai precisa percorrer até chegar na null
        Nodo aux = inicio; //joga o aux no inicio
        while (aux.getProx() != null) {
            aux = aux.getProx();
        }
        aux.setProx(novo);
    }
}

A implementação da classe Nodo é a seguinte:
public class Nodo {

    public int chave;
    public Nodo prox;
    public Nodo ant;

    //+ métodos acessores
}

Comment: Coloca um print depois do metodo recursivo, assim ele vai printar de trás pra frente. Se colocar o print antes do metodo recursivo, ele vai printar na ordem.
Comment: Faltam informações, não sei como o Nodo foi implementado.
Comment: Pronto, atualizei!
Answer: Uma alternativa é primeiro inverter a lista, usando este algoritmo:
public void inverter() {
    Nodo prev = null;
    Nodo next = null;
    Nodo current = inicio;
    while (current != null) {
        next = current.getProx();
        current.setProx(prev);
        prev = current;
        current = next;
    }
    inicio = prev;
}

Basicamente, você parte do início e vai iterando na lista, e a cada nó você faz o elemento N ser o próximo do elemento N + 1. Por fim, o início da lista passa a ser o último nó encontrado. Repare que se a lista for vazia (ou seja, se inicio for null), ele nem entra no while, e ao final, o início continua sendo null (a lista continuará - corretamente - vazia).
Para entender melhor como esse algoritmo funciona:

Depois de inverter a lista, basta imprimí-la normalmente, usando o método print().

Sem precisar inverter a lista
Outra alternativa, mas sem precisar inverter a lista, é imprimí-la recursivamente:
public void printInvertido(Nodo nodo) {
    if (nodo != null) {
        printInvertido(nodo.getProx());
        System.out.print(nodo.getChave() + " ");
    }
}

Neste caso, não precisa inverter a lista, basta chamar printInvertido(inicio). As chamadas recursivas vão sendo feitas para todos os elementos da lista, e como a impressão só ocorre depois destas, os elementos são impressos na ordem inversa.
Obs: o método acima não trata o caso da lista vazia, então bastaria criar mais um método para tratar este caso:
public void printInvertido() {
    if (inicio == null) {
        System.out.println("Nada a exibir - a lista está vazia!");
    } else {
        printInvertido(inicio);
    }
}

Assim, basta chamar printInvertido() diretamente. Se a lista for vazia, imprime a mensagem específica. Caso não seja vazia, chama o método recursivo, que imprime a lista invertida.
Lembrando que, caso a lista seja muito grande, essa quantidade toda de chamadas recursivas pode causar um StackOverflowError.

Outra alternativa: transformar a lista em duplamente encadeada
Que tal aproveitar que a sua classe Nodo também possui uma referência para o elemento anterior? Ou seja, vamos torná-la duplamente encadeada - estou assumindo que o campo ant não foi criado à toa.
No seu código atual você não usa a referência para o anterior, então bastariam alguns ajustes para usar esta informação. Por exemplo, poderia ser criada uma classe Lista assim:
public class Lista {

    private Nodo inicio = null;
    private Nodo fim = null;

    public void inserir(int e) {
        Nodo novo = new Nodo(e);
        if (inicio == null) {
            inicio = fim = novo; // aponto para o novo nodo
        } else { // insere no final
            fim.setProx(novo);
            novo.setAnt(fim);
            fim = novo;
        }
    }

    public void print(boolean invertido) {
        if (inicio == null) {
            System.out.println("Nada a exibir - a lista está vazia!");
        } else {
            // se for invertido, começa do final, senão, começa do início
            Nodo aux = invertido ? fim : inicio;
            while (aux != null) {
                System.out.print(aux.getChave() + " ");
                // se for invertido, vai para o anterior, senão, vai para o próximo
                aux = invertido ? aux.getAnt() : aux.getProx();
            }
        }
    }
}

E na classe Nodo, acrescentei este construtor:
public Nodo(int chave) {
    this.chave = chave;
    this.prox = null;
    this.ant = null;
}

Pois me parece que não faz sentido criar um Nodo cuja chave não tenha algum valor, então não teria necessidade de existir o construtor sem argumentos (pois no seu código você cria um Nodo e depois seta o valor da chave, mas se este é obrigatório, por que não manter apenas um construtor que obriga a passar este valor?). Só crie construtores que façam sentido.
Agora eu tenho o início e o fim da lista, e o método inserir sempre insere no final, ou seja, logo depois de fim. Veja que eu acerto as referências para o próximo e o anterior, assim a lista será duplamente ligada.
Já no método print() eu passo um parâmetro indicando se deve imprimir invertido ou não. Dependendo do valor deste booleano, eu começo do início ou do fim da lista, e no while eu avanço para o anterior ou para o próximo (no caso, invertido ? fim : inicio significa que, se invertido for true, eu uso o fim, e se for false, eu uso o inicio - a mesma lógica vale para determinar se eu pego o próximo ou o anterior).
Sendo assim, se eu chamar print(false), ele imprime a lista na ordem normal, e print(true) imprime na ordem inversa. Ex:
Lista list = new Lista();
for (int i = 0; i < 10; i++) {
    list.inserir(i);
}
System.out.println("Ordem normal: ");
list.print(false);

System.out.println("\nInvertida: ");
list.print(true);

Saída:
Ordem normal:
0 1 2 3 4 5 6 7 8 9
Invertida:
9 8 7 6 5 4 3 2 1 0

Comment: Adorei o gif da inversão!
Comment: @JeffersonQuesado Esse gif é muito bom, né? Teria sido muito mais legal se minhas aulas de estruturas de dados tivessem sido com gifs...
Comment: Sanou todas as minhas duvidas, perfeito!

Inverter lista simplesmente encadeada


Is Arellano-Bond estimator applicable?

Question: I consider the model
$$y_{it} = \rho y_{it-1} + X_i\beta + \alpha_i + u_{it},$$
where $\alpha_i$ are unobservable individual effects. I am interested in estimation of $\rho$, while other coefficients are of a bit lesser interest.

Is this model the right choice if I am interested primarily in $\rho$?
Is Arellano-Bond estimator applicable to this model? (my $X_i$ do not vary in time as in classic dynamic panel model).

If no, what can I use instead?
Answer: When $X_i$ is not time-varying, you may redefine
$$
\alpha_i=X_i\beta + \alpha_i
$$
to obtain the baseline Arellano-Bond model
$$y_{it} = \rho y_{it-1} + \alpha_i + u_{it},$$
in which you can use the corresponding estimator provided the other assumptions (e.g., no serial correlation in $u_{it}$) are met.

Is Arellano-Bond estimator applicable?


What is meant by "streaming data access" in HDFS?

Question: According to the HDFS Architecture page HDFS was designed for "streaming data access".  I'm not sure what that means exactly, but would guess it means an operation like seek is either disabled or has sub-optimal performance.  Would this be correct?
I'm interested in using HDFS for storing audio/video files that need to be streamed to browser clients.  Most of the streams will be start to finish, but some could have a high number of seeks.
Maybe there is another file system that could do this better?
Comment: Streaming Access Pattern in HDFS is: Write Once, Read Any Number Of Times, But Don't Try To Change The Contents Of The File.
Answer: HDFS stores data in large blocks -- like 64 MB.  The idea is that you want your data layed out sequentially on your hard drive, reducing the number of seeks your hard drive has to do to read data.
In addition, HDFS is a user-space file system, so there is a single central name node that contains an in-memory directory of where all of the blocks (and their replicas) are stored across the cluster.  Files are expected to be large (say 1 GB or more), and are split up into several blocks.  In order to read a file, the code asks the name node for a list of blocks and  then reads the blocks sequentially.
The data is "streamed" off the hard drive by maintaining the maximum I/O rate that the drive can sustain for these large blocks of data.
Answer: Streaming just implies that it can offer you a constant bitrate above a certain threshhold when transferring the data, as opposed to having the data come in in bursts or waves.
If HDFS is laid out for streaming, it will probably still support seek, with a bit of overhead it requires to cache the data for a constant stream.
Of course, depending on system and network load, your seeks might take a bit longer.
Answer: For Streaming Data From the Hadoop: The Definitive Guide, 3rd Edition:

HDFS is built around the idea that the most efficient data processing
  pattern is a write-once, read-many-times pattern. A dataset is
  typically generated or copied from source, and then various analyses
  are performed on that dataset over time. Each analysis will involve a
  large proportion, if not all, of the dataset, so the time to read the
  whole dataset is more important than the latency in reading the first
  record.
Comment: How is this an answer?


How may we find this limit?

Question: $$\lim\limits_{x \to 0}\left[{\sum\limits_{n=0}^{\infty}\left(\frac{x}{e^{(nx)^2}}\right)}\right]$$
This is from an MMF thread.
http://www.mymathforum.com/viewtopic.php?f=22&t=45776
Thank you for your consideration in this matter.
Comment: This is nothing more than the derivative of a [Jacobi theta function](http://en.wikipedia.org/wiki/Theta_function).
Comment: Hi there Mr. TNT , as you can see i'm trying to understand this problem. :)
Answer: Let us only consider $x > 0$, the $x < 0$ case follows by parity.
The function $t\mapsto e^{-t^2}$ is strictly decreasing on $[0,\infty)$, hence
$$xe^{-(nx)^2} > \int_{nx}^{(n+1)x} e^{-t^2}\,dt.\tag{1}$$
Sum it up:
$$x\sum_{n=0}^\infty e^{-(nx)^2} > \int_0^\infty e^{-t^2}\,dt = \frac{\sqrt{\pi}}{2}.\tag{2}$$
On the other hand,
$$xe^{-((n+1)x)^2} < \int_{nx}^{(n+1)x} e^{-t^2}\,dt,$$
so
$$x\sum_{n=0}^\infty e^{-(nx)^2} = x + x\sum_{n=0}^\infty e^{-((n+1)x)^2} < x + \int_0^\infty e^{-t^2}\,dt.$$
Comment: @neofoxmulder We have $\lim\limits_{x\to 0^+} x\sum e^{-(nx)^2} = \sqrt{\pi}/2$, and $\lim\limits_{x\to 0^-} x\sum e^{-(nx)^2} = -\sqrt{\pi}/2$ by parity, so the limit doesn't exist [if it existed, it could only be $0$]. The $M$-test is sufficient to conclude uniform (and absolute) convergence, but you can have uniform convergence also if the $M$-test fails, if the regions where each function is "large" play nicely together and don't overlap much.
Comment: Well, seems my answer is unnecessary now. Note however the limit  as $x\to 0^{-}$ is the opposite of the limit from the right.
Comment: But you beat me by two minutes, ten seconds, leave it up. Yes, by parity we have two different one-sided limits.
Comment: This is what I was trying to do in a very wrong way :) +1
Comment: @ Arkamis , when you deleted your post all the comments got deleted too. @ Daniel Fischer , the limit DNE? @ anyone , is the M - test an If and only If? In other words , if the M - test fails then is uniform convergence of the series inconclusive by the M - test? Thank you for your replies and effort in this matter.
Comment: Thank you , that's good to know , and thank's for editing my tex to make the math look better. :)
Answer: Argue $$\lim_{\varepsilon \to 0^+}\sum_{n\geqslant 0}\varepsilon \exp(-\varepsilon^2n^2)=\int_0^{\infty}e^{-x^2}dx \tag 1$$
ADD I leave the following as a record after Daniel posted the proof if $(1)$, which anyone interested can mimic and prove
PROP Let $f: [0,\infty)\to [0,\infty)$ be a monotone decreasing integrable function over its domain. Then $$\lim_{\varepsilon \to 0^+}\sum_{n\geqslant 0}\varepsilon f(\varepsilon n)=\int_0^{\infty}f $$
Comment: You are an evil genius ! :-)

How may we find this limit?


getting 500.30 error after restart app service in azure

Question: after I restarted my app service I getting 500.30 error and I am new to AZURE services any tutorials or articles that helps I really would appreciate that
Comment: Welcome to Stack overflow. [How to ask?](https://stackoverflow.com/help/how-to-ask) You need to provide more details of your problem so that you can get appropriate answers. what is the app you have deployed, which language it is implemented? Is it working fine in your local machine?
Answer: Based on our investigations , we have understood that Http status code 500.30 occurs in .Net core web applications.

Http 500.30 status code occurs when The worker process fails. The app doesn't start.
The ASP.NET Core Module attempts to start the .NET Core CLR in-process, but it fails to start. The cause of a process startup failure can usually be determined from entries in the Application Event Log and the ASP.NET Core Module stdout log.

To know more information about the error Go to Azure Portal > your App Service > under development tools open console. We can run the application through this console and thus visualize the real error that is causing our application not to load. For that put, the name of our project followed by ".exe" and press the enter key.

please refer these documents for more information about  500.30 In-Process Startup Failure & for Troubleshooting  on Azure App Service.
Comment: This was so incredibly helpful to me.


UFW allow outbound from ip address, deny from others

Question: I am trying to allow outbound connections from a specific IP address and deny outbound from all other ip addreses on port 80, but can't seem to crack it:
These are the commands:
ufw deny out 80
ufw allow out from xxx.xx.xx.xx

However it is not allowing outbound connections to port 80 from xx.xx.xx.xx:
80                         DENY OUT    Anywhere (out)
Anywhere                   ALLOW OUT   xxx.xx.xx.xx (out)

What am I doing wrong ?
Answer: The following would prevent outgoing traffic on port 80 but to the ip xxx.xx.xx.xx

change the default outgoing open in ufw
ufw deny out 80

allow outgoing to the specific ip:
ufw allow out to xxx.xx.xx.xx port 80


Como recuperar um token de acesso com JavaScript?

Question: Tenho uma api e estou consumindo ela no frontend.
minha api na url /login me gera um token de acesso.
Preciso dentro do meu login.js fazer uma requisição POST que retorne o token.
Observação,  o token retornado não é um json, quando faço um teste no insonia para ver se a api está devolvendo o token ele apenas me retorna o token como um texto enorme, e preciso via JavaScript este retorno e salvar  em uma variável.
<code>btnEntrar.onclick = async e  =>{
    e.preventDefault();

    if (email.value == '' || senha.value == '') {
      return
    }
    let paylog = {"email": email.value, "senha":senha.value}

    const response = await fetch('http://localhost:8080/login', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(paylog),
    });
    const data = await JSON.stringify(response)
    console.log(response)
</code>
O retorno é um erro falando que não é um json válido.

Uncaught (in promise) SyntaxError: Unexpected token 'p',
"persidh.cr"... is not valid JSON VM43:1
Answer: Vamos lá.
Você não precisaria do JSON.stringfy.
Isso somente irá transformar em um texto transformado DE json para string.
Como você recebe já uma string, ele te retorna dizendo que tem um token inválido (não reconhece como json pra poder transformar)
Tente deixar na penultima linha somente data = response.
e consolar isso
Comment: O pessoal não responde, mas so avalia negativo uma resposta que ajudaria a pessoa. Stackoverflow Brasil ta virando piada com a comunidade que se acha Deus


Ativar e desativar alarmes do Android via código

Question: Estou criando uma aplicação e em determinada parte irei necessitar que o aplicativo ative e desative alarmes (do próprio celular). Procurei na internet mas não encontrei nada que me ajudasse no descrito. Não sei quais classes ou biblioteca podem ser usados e se é realmente possível.
Comment: A que alarmes se refere?
Comment: Como já dito "[...] ative e desative alarmes (do próprio celular)"
Comment: O que são *"alarmes (do próprio celular)"*?
Comment: Os alarmes que vem em um app "de fabrica", que já vem junto com o celular. Me refiro aos despertador, quando digo alarme.
Answer: Não tem como fazer isso. Não tem nem como você pegar a lista de todos alarmes ativos no sistema, por exemplo. A não ser que o app que iniciou o alarme forneça servicos para tal, usando ContentProvider por exemplo.
O que você pode fazer é usar o Do not disturb. Quando o seu app iniciar, você lança uma intent ativando o dnd e quando fechar lanca uma desativando.
Esse link pode te ajudar na implementacao https://stackoverflow.com/questions/31862753/android-how-to-turn-on-do-not-disturb-dnd-programmatically
Lembrando que você vai ter que, dependendo da versao do android(6.0+), pedir permissão ao usuario para usar esse serviço.


Is it possible to invoke a SQL function like GETDATE() when inserting or updating via Simple.Data?

Question: For overall data consistency, I generally I prefer storing the current datetime for new/updated records with the current time on the database server, as it may not be in sync with the invoking server (and if using multiple web servers, they may also be out of sync with each other).
Is it possible to do this via Simple.Data, without having to resort to a stored procedure call?
Answer: Currently there is no Simple.Data reference to GETDATE. It's something I plan to address in v2; I will see if the code can be retro-fitted to v1.
Comment: Thanks; I have a local clone and wouldn't mind helping/testing if needed.
Answer: I'm not familiar with Simple.Data
But can you try adding a default to the column:
 RecordLastUpdatedOn datetime2(7) Null default(GetDate())

You can add it after the column is created by using the alter column/add constraint method.
Answer: I don't know anything about Simple.Data but you could let SQL Server handle generating the DateTime.
Just leave the INSERTED column empty and SQL Server will set the default to the current date.
CREATE TABLE Table(
    INSERTED DATETIME DEFAULT (GETDATE())
);

Comment: Thanks, I'm aware of defaults, but they only solve the problem for inserts.


Visual Studio 2015 Update 2 Codelens enabled, but not functioning

Question: enter image description hereI had to reinstall VS2015 and updated to Update 2.   Codelens is present and all checked, but no references are present in any of my solutions.
enter image description here
I've uploaded an image.... all Codelens checkboxes are checked... bit of a stumper
Answer: I have installed the VS2015 Update 2 couple of weeks back and everything works great for me, including CodeLens. Can you please provide a screenshot of the problem you are seeing?
I would suggest you to check your 'CodeLens' settings under Tools -> Options -> All Languages Menu and ensure CodeLens is enabled.
Comment: EDIT: Tried opening in 'safe mode' to rule out plugins but no change.  I thought perhaps the functionality was redacted from the Enterprise SKU?
Answer: The whole Show References option is missing for me since I installed Update 2! Apparently so is Show CodeHealth - I didn't even know that was an option.
VS Version is Enterprise 2015 v14.0.25123.00 Update 2
I have many add-ons so I have a sneaking suspicion one of them is interfering here, but was definitely working prior to Update 2.
Comment: your test and tested by ones are also missing, if you aren't seeing those references AT ALL, like in the screenshot, then something has gone wrong, and it can't find or load those providers (tests, tested by depend on references).  you might need to try `devenv /setup` as admin, or even repair your VS if that is missing.
Comment: For anyone coming across this post, running a "repair" on the Update 2 setup resolved the issue
Answer: If you aren't seeing the References indicator AT ALL in the settings window, like in the screenshots above, then something has gone very wrong with your VS install, and it can't find or load those CodeLens providers (tests, tested by depend on references).
you might need to try

devenv /setup as admin, -or-
add/remove programs -> visual studio 2015 -> "modify" or "change" depending on OS version and choose "Repair" from the Visual Studio installer


When arranging/transcribing a song, how do know what chords are being played?

Question: I'd like to arrange a song that doesn't have or has little guitar onto fingerstyle guitar. Finding individual notes is tedious but simple, but how do you find chords, especially when it's not even the same instrument? I often see people, on YouTube for example, arrange something like this onto piano or guitar. I realize that arranging a song is a difficult process, but I find it hard to believe that it's simply a guessing game to find the chords, as trying to guess individual notes is already a long and tedious process.
One way I can think of to do this is to just guess what sounds right, and while there are some people who do actually do that, there are many that make pretty accurate versions of the song they're arranging.
My confusion comes with the part after you identify the first notes. Okay, I've got the first few notes. Now what? How do I put this into a form that's friendly to fingerstyle guitar? How do I even make a chord out of this? Do I just create chords from the root note until I find one that sounds good or right? If so, how do I determine how many notes should be in the chord? I feel like the difficultly is logarithmically increasing each time I ask a question!
Comment: Does this answer your question? [How can I transcribe music by ear?](https://music.stackexchange.com/questions/92897/how-can-i-transcribe-music-by-ear). There are numerous other questions on how to transcribe, e.g. https://music.stackexchange.com/questions/46/how-to-transcribe-music-by-ear
Comment: @piiperiReinstateMonica: I think that *ear-training* apps can help with this problem, so I wouldn't damn all apps right away. However I agree that guessing or looking up the solution is no good here.
Comment: You practice, and you get better at it. There's no trick. Start practicing immediately. Put away the computer, smartphone, apps, youtube, all of that. They don't help. Take an instrument like a guitar or piano. Using the chords C major and G major, find out how to accompany "Mary had a little lamb". You are not allowed to look at any computer screen or smartphone before you've tried to do that for one hour. Put all electronics away from you. In a separate room. One hour.
Comment: @Ramillies - Makes me wonder how we managed before apps came to our rescue. But manage we did ! And do apps actually teach us anything, or merely do it for us?
Comment: @Tim — well, perhaps you had another person do the thing that the app does for you? Like, if you wanted to practice interval recognition, another person would sit at the piano and play random intervals which you had to name? The app does just the same thing, the only difference is that you don't need the other person.
Comment: I updated my question
Answer: Experience. And, there's only one way to gain that. Know which harmonies and chords are likely to be the ones used in any particular key, have a good ear to listen out for secondary dominants. By starting with simple three chord songs, Happy Birthday comes as one, you can gently work through to more complex songs. Use those with fewer instruments and vocalists, as this will keep the waters clearer.
Comment: I updated my question


Add conditions on Where in Views 3

Question: How can I do to add more conditions on WHERE, like this
WHERE view conditions ... AND ( (sentence 1 AND sentence 2) or (sentence 3 AND sentence 4) or ... )
This view is in a user profile and this conditions depens on profile data.
Thanks
Answer: I guess the option you need is in the "Filter Criteria" section, in the dropdown next to the "Add" button. If you fold down that menu you will see the "And/Or, Rearrange" option in which you can create sets of conditions.
Comment: It's a good solution but my problem is that query modification must be done in code.
Comment: Ah ok, then please update your question with some code and explain what you have tried.

Add conditions on Where in Views 3


Proper embouchure to leak air while playing EWI?

Question: If you read enough beginner resources for Akai EWI players, you'll keep seeing people mention that you need to let air leak out the sides of your mouth while you play, to avoid building up backpressure. See the question "I cannot blow enough air through my [EWI]. What can I do about this airflow problem?" on Patchman's FAQ, or the bottom of this answer on the site.
But even though it sounds simple enough, I've been struggling to figure out how to do this for myself. If I leave my mouth really open, the leaking air is distracting and it's hard to maintain good control over the dynamics. If I leave it open just enough to let air leak out, eventually the gaps close while I'm tonguing, and then it feels really counterintuitive to get them open again. I can get the best results so far if I just barely put my mouth over the mouthpiece, but from watching people play on YouTube this doesn't seem to be common, and it makes it hard to control the bite sensor.
I would love to read a more detailed description of how to get the right embouchure to achieve this airflow. As you're getting ready to play, how do you put your mouth around the mouthpiece? As you play, does air leak out at a constant rate, or does it change depending on what you're playing? Are there suggested exercises for practicing this? For background, I'm coming to the EWI from flute, so I would especially appreciate an answer that doesn't assume knowledge of other instruments with mouthpieces closer to the EWI's.
Answer: Leaking air out of the sides of the embouchure is a really bad habit to get into if you also play real wind instruments. It can be audibly distracting and it's also totally unnecessary. Oboe players have exactly the same problem that not enough air goes through the instrument. They cope by exhaling at the end of a phrase to empty the lungs before inhaling, and this is the technique you should use on EWI. If you're coming from flute (where you have the opposite problem) it's going to take a bit of work to get used to this.
Comment: Agreed.  Why not simply take less air in if you know the EWI doesn't take much air?  Compare with alto and soprano recorders, which certainly don't require a lot of air volume.


How do I best show that Likert-responses for one set of questions differ from another set of questions tested in the same population?

Question: Let me preface this by saying I am very new to research / statistics so I don't know much and I apologize for the basic questions.
I have data from a Likert-type survey (Strongly Disagree, Disagree, Neutral, Agree, Strongly Agree) that consists of twelve questions assessing bias. The first six questions assess perceived age bias (bias one thinks exists in the world) and the latter six questions assess personal age bias (bias one personally has). The likert responses can be collapsed to leave essentially three categories: Unbiased, Neutral, Biased.
My hypothesis was that there was no difference between perceived and personal age bias. I'm not sure what the best way to test this hypothesis is with my data...
Since Q1 - 6 measure perceive bias while 7 - 12 measure personal bias, I thought about aggregating results for Q1-6 and comparing that to results for Q7-12. I could then do something like a Chi-square to show a difference in distribution between the two and a post-hoc standardized residual analysis to pinpoint which response category is weighing in the most on that difference.
Also, if I do aggregate the results...what do I do if there is an outlier response that throws things off? Is there a better way to go about this? I pretty much want to say something like "Responses to the perceived bias questions were to show bias compared to the personal bias questions" or whatever I find.
Sorry for the long post, and I am grateful for the help.
Answer: Please explain what you mean by 'collapse'. I can imagine several
ways to do this, even though I suppose it results in some loss in
information, and thus fear it may be a bad idea.
I cannot imagine how you you could get a genuine 'outlier' from such Likert data. If you have values from one or more subjects that
'throw things off', then maybe you have made a mistake or maybe
there is an unexpected outcome in your data that's trying to tell
you something. Please explain what the 'outlier' is and why you think it is a barrier to analysis.
After collapsing, suppose each subject has a 'Perception' score x1, which
can take values -1, 0, 1. Similarly, each subject has a 'Personal' score
x2, which can take values -1, 0, 1.
Then you wonder whether a subject's two scores have the "same distribution."
Speaking very loosely, as you certainly are, that might mean any one
of several things. For example, two possible interpretations (among several) might be:

Looking across subjects, difference scores d = x1 - x2 would tend to be $0.$ (Mean or median $0.)$

It is often possible to predict a subject's x2 score from his/her x1. (Dependence between x1 and x2.)

How to do a test might depend on your method of 'collapsing' and would
certainly depend on what interpretations you have in mind. (Paired Wilcoxon test for the first, chi-squared test of independence for the second.)
Please clarify your question. Then maybe one of us can make suggestions how to analyze your data.
Comment: For some studies I think Bayesian analysis is clearly the best choice. But, IMHO this is not likely to be one of them. // You have some thinking to do to sharpen up what you want to find from your data, how you want to measure that, and what test to use for analysis. I think you are more likely to find useful specific guidance on that from traditional frequentist sources.
Answer: I would encourage that you consider reframing your research question. Statistically speaking, you cannot prove the absence of a difference unless you plan on using Bayesian methods. I'll explain what I mean using a simple example of how you might use your data.
Say that you decide to take the mean rating of items 1-6 and 7-12. To do this, you might document a rating of "Strongly Disagree" as a 1, "Disagree" as a 2, "Neutral" as a 3, etc. You could then average the two parts of your scale so that each person has an average rating of perceived age bias and an average rating of personal age bias. You might then use a paired sample's t-test to "test" whether the average rating of these constructs differ within individuals. Under standard null hypothesis testing, the following would be your null and alternative hypotheses:
$H_0: \mu_d = 0$
$H_a: \mu_d \ne 0$
Just for clarity, $\mu_d$ is the mean difference (i.e., the average difference in the perceived age bias and personal age bias for each person). This null hypothesis test should illustrate that the null hypothesis (that there is no average difference) is your research hypothesis. At first glance, that should mean that your question is answerable since you could test that hypothesis; however, the issue with frequentist methods is that we are testing whether we can reject the null hypothesis. Frequentist null hypothesis tests can only ever have two results: reject the null hypothesis (result is statistically significant) or fail to reject the null hypothesis (result is not statistically significant).
So, depending on your statistical orientation, framing your question as trying to show the absence of an effect is not possible. From a scientific integrity perspective, your research question and hypothesis shouldn't be trying to prove a negative either.
Not all hope is gone, however. Like I mentioned, you could use Bayesian methods to estimate the evidence for the null relative to the alternative hypotheses. Or, you could reframe your statistical hypothesis. For example, instead of saying that there is no difference between the two subscales, you could test whether results are negligibly different from zero (or effectively zero). This framework is the two one-sided t-test (TOST).
As far as strategies for answering a question of whether people respond to items similarly or differently, I'm going to assume that items are repeated on the scale. In other words, the same items are given on the perceived bias and personal bias scales (e.g., Q1 = Q7, Q2 = Q8, etc.). the Item Response Theory framework gives a few resources for doing this analysis. You could test directly whether there is differential item functioning depending on whether an item is for personal bias or perceived bias, but this would assume that it's safe to say that there is a single latent variable (i.e., bias) as opposed to two separate latent variables (i.e., personal bias and perceived bias). Item Response Theory generally requires a fairly large sample (e.g., 250-500 people). You could do a chi-square for each item where you check whether counts of endorsements for the different Likert ratings versus whether the item is for perceived or personal bias, but you would need to adjust your p-values for multiple observations. The issue is that you would run into the fact that a non-significant result can't be taken as meaning that there is no difference.


Error SQL: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax

Question: I've been trying to do a JDBC connection with MySQL using the preparedStatement.
Here is my code so far:
package uni.jdbc.preparedStatement;
import java.sql.*;

public class Main {

    public static void main(String[] args) {

        try {

            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/banco_Teste","root","password");

            //ADD
            String resultSet1 = "INSERT INTO Clientes(nome) VALUES(?)";
            String resultSet2 = "INSERT INTO Clientes(nome) VALUES(?)";

            //UPDATE
            String resultSet3 = "UPDATE Clientes SET nome = ? WHERE id = ?";
            String resultSet4 = "UPDATE Clientes SET nome = ? WHERE id = ?";

            //DELETE
            String resultSet5 = "DELETE FROM Clientes WHERE id = ?";
            String resultSet6 = "DELETE FROM Clientes WHERE id = ?";

            //SELECT
            String select = "Select * FROM Clientes";

            try (PreparedStatement pS = conn.prepareStatement(resultSet1 + resultSet2 + resultSet3 + resultSet4 + resultSet5 + resultSet6 + select)){

                //INSERT
                pS.setString(1, "João");
                pS.setString(2, "Maria");
                pS.execute(resultSet1 + resultSet2);

                //UPDATE
                pS.setString(1, "John");
                pS.setString(2, "Marya");
                pS.execute(resultSet3 + resultSet4);

                //DELETE
                pS.setString(1, "John");
                pS.setString(2, "Marya");
                pS.execute(resultSet5 + resultSet6 );

                //SELECT
                pS.execute(select);

            }catch (SQLException e){

                e.printStackTrace();

            }

        }catch(SQLException | ClassNotFoundException e){

            e.printStackTrace();

            System.out.println("Conexão falhou!");

        }
    }
}

Here is the query:
create database banco_Teste

use banco_Teste

CREATE TABLE Clientes(

    id_cliente INTEGER PRIMARY KEY AUTO_INCREMENT,
    nome varchar (100)

)

The problem is: as I run, the following error is returned:

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?)INSERT INTO Clientes(nome) VALUES(?)' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:768)
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:653)
at uni.jdbc.preparedStatement.Main.main(Main.java:46)

Could it be a version problem? The connector version is 8.0.27.
Comment: You need to use `pS.execute()`. Also, you need to ensure you're actually executing/preparing a valid statement, because your current statement is not valid.
Answer: resultSet1 + resultSet2 + resultSet3 + resultSet4 + resultSet5 + resultSet6 + select

will give you an error because a the end, the result of your query look like this :
INSERT INTO Clientes(nome) VALUES(?)INSERT INTO Clientes(nome) VALUES(?)UPDATE Clientes SET nome = ? WHERE id = ?UPDATE Clientes SET nome = ? WHERE id = ?...

what is syntaxically incorrect as stated in your exception. What you have to do is to add ; at the end of your queries.
Your queries should look like this :
    //ADD
    String resultSet1 = "INSERT INTO Clientes(nome) VALUES(?);";
    String resultSet2 = "INSERT INTO Clientes(nome) VALUES(?);";

    //UPDATE
    String resultSet3 = "UPDATE Clientes SET nome = ? WHERE id = ?;";
    String resultSet4 = "UPDATE Clientes SET nome = ? WHERE id = ?;";

    //DELETE
    String resultSet5 = "DELETE FROM Clientes WHERE id = ?;";
    String resultSet6 = "DELETE FROM Clientes WHERE id = ?;";

    //SELECT
    String select = "Select * FROM Clientes;";

This link can help you for more details.
I am a bit confused about this call :
pS.execute(resultSet1 + resultSet2);

as per the Java Doc, there is no such method.


Using Telerik MVC grid, editing row blanks TimePicker and DateTimePicker

Question: I have a Telerik grid populated by an Ajax command similar to the following:
PowerStatusGrid.cshtml
@{Html.Telerik().Grid(Model)
.Name("PowerStatusGrid")
.DataKeys(k => k.Add(o => o.StatusItemId))
.Columns(columns =>
{
    columns.Bound(o => o.ItemName).Title("Name").Width(250).ReadOnly(true);
    columns.Bound(o => o.DateTimePicker).Title("Date/Time").Width(150);
    columns.Command(commands =>
    {
        commands.Edit().ButtonType(GridButtonType.BareImage).HtmlAttributes(new { @class = "grid-edit-button" }).ImageHtmlAttributes(new { @alt = "Edit", @title = "Edit" });
        commands.Delete().ButtonType(GridButtonType.BareImage).HtmlAttributes(new { @class = "grid-delete-button" }).ImageHtmlAttributes(new { @alt = "Delete", @title = "Delete" });
    }).Width(90).Visible(KC.UI.Helpers.Helper.CanSaveResource(Convert.ToInt32(ViewData["resourceId"])));
})
.Resizable(resizing => resizing.Columns(true))
.Scrollable(c => c.Height("100px"))
.DataBinding(dataBinding => dataBinding.Ajax()
                .Select("ResourcePowerStatusGridBinding", "Resource", new { resourceId = ViewData["resourceId"] })
                .Update("ResourcePowerStatusGridUpdate", "Resource", new { resourceId = ViewData["resourceId"] })
                .Delete("ResourcePowerStatusGridDelete", "Resource", new { resourceId = ViewData["resourceId"] }))
.Editable(editing => editing.Mode(GridEditMode.InLine))
.ClientEvents(events => events.OnDataBound("defaultGridDataBound").OnEdit("defaultGridEdit"))
.NoRecordsTemplate("Loading...")
.Render();
}

I have an editor template like so:
DateTimePicker.cs
@( Html.Telerik().DateTimePicker()
          .Name("DateTimePicker")
          .Value(DateTime.Now)
  .HtmlAttributes(new { @class = "ui-widget" })
)

The property is covered by a custom field in a partial class that maps to my data structure with a UIHint:
ResourceStatusItem.cs
public partial class ResourceStatusItem
{
    [UIHint("DateTimePicker")]
    public DateTime? DateTimePicker { get; set; }
}

I have functions to do the binding and updating:
Controller.cs
[OutputCache(Duration = 0)]
    [GridAction]
    public ActionResult ResourcePowerStatusGridBinding(int resourceId, string exportCols)
    {
        return returnResourcePowerStatusGrid(resourceId, exportCols);
    }

    [OutputCache(Duration = 0)]
    [GridAction]
    public ActionResult ResourcePowerStatusGridUpdate(int id, int resourceId)
    {
        var uow = new UnitOfWork();
        var rep = new ResourceRepository(uow);
        var listItems = rep.GetResourcePowerStatus(resourceId);
        var item = listItems.FirstOrDefault(x => x.StatusItemId == id);

        if (item != null && TryUpdateModel(item))
        {
            item.StatusItemId = id;
            item.DateTime = item.DateTimePicker != null ? item.DateTimePicker : item.DateTime;
            rep.SaveResourceStatusItem(item);
        }

        return returnResourcePowerStatusGrid(resourceId);
    }

private ActionResult returnResourcePowerStatusGrid(int resourceId, string exportCols = null)
    {
        UnitOfWork uow = new UnitOfWork();
        var rep = new ResourceRepository(uow);
        var reps = rep.GetResourcePowerStatus(resourceId);

        if (reps != null)
        {
            foreach (var m in reps)
            {
                m.ItemName = m.ItemName;
                m.DateTimePicker = m.DateTime;
                m.StatusItemId = m.StatusItemId;
            }
        }

        return View(new GridModel
        {
            Data = reps
        });
    }

When viewed, the time and date for Date/Time look just fine. When I click in to edit, I get the DatePicker and TimePicker icons, but the textbox is blank. Cancelling brings back the original date/time values for display. Because of my conditional tertiary operator assignment above, if the user does nothing with the Date/Time field, then it retains its prior value. But I would really like to keep the current value and let the user modify it from there. By trial and error, I've verified that the DatePicker works fine, but both the DateTimePicker and the TimePicker just will not display.
I found a similar question where the person wound up answering their own question by saying that they just stopped using the time field, but that is not an option for me. The Telerik forums seem to have wholly moved over to their RadEditor, so there's no support there. Is there a way to get the existing value to consistently show up inside the DateTimePicker control on edit?
Answer: Hot damn, I found an answer!
By hooking into the OnEdit event, and re-setting the value of the DateTime picker, you can make it register the correct value. My Client Events line is now .ClientEvents(events => events.OnDataBound("defaultGridDataBound").OnEdit("resourcePowerStatusRowEdit"))
and I added the following to my .js file:
function resourcePowerStatusRowEdit(e) {
    if (e.dataItem.DateTimePicker)
        var sDate = new Date(e.dataItem.DateTimePicker);
    else
        var sDate = new Date();

    if (isNaN(sDate.getMonth())) {
        sDate = new Date();
    }
    //this will apply the format to the date picker that you want to show in the editing mode
    $('#DateTimePicker').val($.telerik.formatString('{0:MM/d/yyyy hh:mm}', sDate));
    $('#DateTimePicker').focus();
}

There is no doubt a more refined way to do this, but this solves my immediate problem.


Python: How to move a file with unicode filename to a unicode folder

Question: I'm having hell with moving a unicode named file between unicode named folders in a Python script under Windows...
What syntax would you use to find all files of type *.ext in a folder and move them to a relative location?
Assume files and folders are unicode.
Answer: The basic problem is the unconverted mix between Unicode and byte strings. The solutions can be converting to a single format or avoiding the problems using some trickery. All of my solutions include the glob and shutil standard library.
For the sake of example, I have some Unicode filenames ending with ods, and I want to move them to the subdirectory called א (Hebrew Aleph, a unicode character).
First solution - express directory name as byte string:
>>> import glob
>>> import shutil
>>> files=glob.glob('*.ods')      # List of Byte string file names
>>> for file in files:
...     shutil.copy2(file, 'א')   # Byte string directory name
...

Second solution - convert the file names to Unicode:
>>> import glob
>>> import shutil
>>> files=glob.glob(u'*.ods')     # List of Unicode file names
>>> for file in files:
...     shutil.copy2(file, u'א')  # Unicode directory name

Credit to the Ezio Melotti, Python bug list.
Third solution - avoiding destination Unicode directory name
Although this isn't the best solution in my opinion, there is a nice trick here that's worth mentioning.
Change your directory to the destination directory using os.getcwd(), and then copy the files to it by referring to it as .:
# -*- coding: utf-8 -*-
import os
import shutil
import glob

os.chdir('א')                   # CD to the destination Unicode directory
print os.getcwd()               # DEBUG: Make sure you're in the right place
files=glob.glob('../*.ods')     # List of Byte string file names
for file in files:
        shutil.copy2(file, '.') # Copy each file
# Don't forget to go back to the original directory here, if it matters

Deeper explanation
The straightforward approach shutil.copy2(src, dest) fails because shutil concatenates a unicode with ASCII string without conversions:
>>> files=glob.glob('*.ods')
>>> for file in files:
...     shutil.copy2(file, u'א')
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/usr/lib/python2.6/shutil.py", line 98, in copy2
    dst = os.path.join(dst, os.path.basename(src))
  File "/usr/lib/python2.6/posixpath.py", line 70, in join
    path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 1:
                    ordinal not in range(128)

As seen before, this can be avoided when using 'א' instead of the Unicode u'א'
It this a bug?
In my opinion, this is bug, because Python cannot expect basedir names to be always str, not unicode. I have reported this as an issue in the Python buglist, and waiting for responses.
Further reading
Python's official Unicode HOWTO
Comment: Worked - Thanks! Also +1 for the detailed explanation
Answer: Use Unicode string everywhere:
# -*- coding: utf-8 -*-
# source code ^^ encoding; it might be different from sys.getfilesystemencoding()
import glob
import os

srcdir = u'مصدر الدليل' # <-- unicode string
dstdir = os.path.join('..', u'κατάλογο προορισμού') # relative path
for path in glob.glob(os.path.join(srcdir, u'*.ext')):
    newpath = os.path.join(dstdir, os.path.basename(path))
    os.rename(path, newpath) # move file or directory; assume the same filesystem

There are many subtle details in moving files; see shutit.copy* functions. You could use one that is appropriate in your particular case and remove source files on success e.g., via os.remove().


LeNet5 "symmetry breaking" step, is (was) it important?

Question: Reading through Yann LeCun's original paper on LeNet5, I have come across something that I haven't seen before in convolutional neural network architectures.  (Maybe that's just because I'm late to the party.)
 Table I on page 8 shows that the connections between layers S2 and C3 are deliberately incomplete.  The authors state that this incomplete connection serves two purposes:
1) To reduce the size of the tensor being passed between these layers (obviously a more pressing concern in 1998 than today), and
2) To "break symmetry" in the model, forcing different and complimentary connections between the features in these two layers.
I have looked at several web pages where people implement what they call "LeNet5", and none of them seem to bother with this symmetry-breaking step.  It could be a bit challenging to implement with standard CNN software such as Keras, freezing only some of the weights and allowing others to vary.  None of the more modern CNN visual processing architectures I have examined (AlexNet, Inception, etc.) seem to bother with symmetry-breaking either.
Symmetry-breaking vaguely resembles a regularization technique, at least to me.  Once we get to using dropout or batch normalization, are we effectively accomplishing the same goal as symmetry-breaking by different means?
Answer:
More importantly, it forces a break of symmetry in the network. Different feature maps are forced to extract different hopefully complementary, features because they get different sets of inputs.

As you quoted, symmetry breaking is a way to force different feature extraction. Another way to do this is randomly initializing the weights of a NN. Since all your hidden units will not have the same weights initially, there are good chances of them converging via different paths to different final values. You will find this explanation here interesting. As this answer says, the random initialization of the weights will achieve the symmetry breaking objective, and that's the reason we didn't see this issue in AlexNet, Inception etc.
To further answer your question on using dropout, batch normalization– yes they are a way of introducing randomizations in your network and hence they should suffice.
see the comment here
Comment: Welcome to [Stats.SE]. Thank you for your answer. Can you please edit you answer to expand it, in order to include the main points of the link you provide? It will be more helpful both for people searching in this site and in case the link breaks. By the way, see some tips on [answer], on [formatting help](https://stats.stackexchange.com/help/formatting) and on writing down equations using [LaTeX / MathJax](https://math.meta.stackexchange.com/q/5020).
Comment: Thanks @Ertxiem, I've updated the answer
Comment: one should be dubious about the supposed "explanations" in most neural networks research.  In any case, Lenet5 was certainly randomly initialised as are all(?) neural nets.
Answer: Regarding your implementation question, you could add a linear layer with identity activation and initialize the weights as zeros or ones as you wish (i.e. the layer is a binary mask). This layer should be fixed (i.e. not trained).
You can initialize the mask however you wish to achieve the desired wiring.


Is it Possible to display Custom VF page upon Clicking Approve/Reject Link in Standard sales force chatter page?

Question: Please let me know is it possible to display the custom visualforce page upon clicking the Approve/Reject Link on the record instead of  displaying standrad Salesforce Approve  page.
If it is  possible then please let me know how that could be acheived?
Answer: Follow the below approach to override standard approval process page.

Create a custom visualforce page: start by copying the standard approval/rejection page.
Create a controller with methods for approve/reject/cancel. The Approval Process API is available in the Apex reference book.
Create a home page component with Javascript to override the "Approve/Reject" button on Lead.
Add this home page component in home page layout.

VisualForce Page
<apex:page controller="ProcessInstanceController" tabStyle="Lead">
    <apex:form>
        <apex:sectionHeader title="Lead" subtitle="{!objLead.Name}"/>
        <apex:pageBlock title="Approve/Reject Approval Request">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Approve" action="{!approve}"/>
                <apex:commandButton value="Reject" action="{!reject}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="1">
                <apex:pageBlockSectionItem >
                Name <apex:outputField value="{!objLead.Name}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                Lead Owner <apex:outputField value="{!objLead.Owner.Name}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                Rejection Reason (Mandatory while Rejection)<apex:inputField value="{!objLead.Rejection_Reason__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                Comments (Mandatory while Rejection) <apex:inputTextArea value="{!objLead.Comments__c}" rows="5" cols="100"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller
public class ProcessInstanceController {
    public String processId;
    public String leadId;
    public ProcessInstance objProcessInstance;
    public Lead objLead {get; set;}
    public PageReference redirectPage;
    public ProcessInstanceController(){
        processId = ApexPages.currentPage().getParameters().get('id');
        leadId = ApexPages.currentPage().getParameters().get('leadId');
        objLead = [select Name,Owner.Name,Rejection_Reason__c,Comments__c from Lead where id =:leadId];
        redirectPage = new PageReference('/'+leadId);
    }
    public PageReference Approve(){
        Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
        req.setComments(objLead.Comments__c);
        req.setAction('Approve');
        req.setWorkitemId(processId);
        Approval.ProcessResult result =  Approval.process(req);
        update objLead;
        return redirectPage ;
    }
    public PageReference Reject(){
        Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
        req.setComments(objLead.Comments__c);
        req.setAction('Reject');
        req.setWorkitemId(processId);
        Approval.ProcessResult result =  Approval.process(req);
        update objLead;
        return redirectPage ;
    }
    public PageReference Cancel(){
        return redirectPage;
    }
}

Home Page Component


Where to learn about model categories?

Question: A model category (introduced by Quillen in the sixties) is a category equipped with three distinguished classes of morphisms (weak equivalences, fibrations and cofibrations) satisfying some axioms designed to mimic the structure of the category of topological spaces. They provide a framework to study homotopy theory which applies to topological spaces (algebraic topology), chain complexes (homological algebra), and much more. In particular the notion of Quillen equivalence allows one to say when two categories are the same "up to homotopy".

What are good places (book, lecture notes, article...) to learn about model categories?

Assume that the reader is reasonably familiar with category theory, and perhaps with the basics of algebraic topology or homological algebra if some motivation is needed. I would also be interested in more advanced books that deal with finer points of model category theory (localizations come to mind).
This question is inspired by this previous one where the OP asked whether to learn $\infty$-category theory. I believe knowledge of model categories is rather essential to learn $\infty$-category, as for example many coherence results are stated in the form of "Such and such categories of $\infty$-categories are Quillen equivalent". As far as I understand much of $\infty$-category is also designed with model categories in mind, basically "what happens if I'm in a category of bifibrant objects and derived hom spaces". See also the MO question Do we still need model categories?

If possible try to argue why the book/paper you're mentioning is a good place to learn (and not just assert so), please. By now I think the subject is settled enough that there are several good books about it, and I think it would be nice to condense information about all these books in one place, instead of relying on hearsay.
Comment: Heh, I just stumbled upon this old question. Six years later, and I'm the one teaching model categories :) I gave a lecture at the University of Paris on the subject: idrissi.eu/class/20-21-homotopie/ (the videos are in English but the notes are in French though).
Answer: I like

Philip S. Hirschhorn. Model categories and their localizations. Mathematical Surveys and Monographs 99. Providence, RI: American Mathematical Society, 2003, pp. xvi+457. ISBN: 0-8218-3279-4. MR1944041.

First, a word of warning: the book is divided into two parts, but the first part depends logically on the second part. Thus, beginners should start at Chapter 7, not Chapter 1. The great thing about [Hirschhorn] is that all the definitions and results are stated carefully and clearly, so it serves very well as a reference. It also goes as far as constructing mapping spaces and homotopy (co)limits for a general model category, which might be considered advanced topics.
One downside of [Hirschhorn] is that it takes the standard model structures on $\mathbf{Top}$ (or, more precisely, a convenient subcategory) and $\mathbf{sSet}$ for granted. It also assumes some familiarity with basic homotopy theory for some proofs, but this is probably fair enough.
Now, as for whether you need model category theory for $(\infty, 1)$-category theory, that's a discussion for another day...
Answer:
W. G. Dwyer and J. Spaliński. "Homotopy theories and model categories". In: Handbook of algebraic topology. Amsterdam: North-Holland, 1995, pp. 73–126. DOI: 10.1016/B978-044481779-2/50003-1. MR1361887.

This paper is an introduction to the theory of model categories. The prerequisites needed to read it are very limited, and most (if not all) the proofs are detailed. All the basics of model categories are explained: basic definitions, homotopy category, derived functors, homotopy pushouts and pullbacks... Two fundamental examples (topological spaces and bounded below chains complexes) are also made explicit.

Where to learn about model categories?


Ideas for how to use the minor(add9) chord

Question: I've started writing a piece of music for guitar which starts with a really cool arpeggio with the Dm (add9) chord. However, I don't really know how to progress from here and I'm noodling with a few things and would like assistance. I've toyed with moving on to a Gsus4 arpeggio or something of the like.
What pieces of music use the minor add9 as a root chord that i can look at for ideas and how can it be used within a piece of music when it is the root? I want to create a minor sounding piece which builds tension and any ideas as to how to work this in would be great as I know I've got a good start but need a nudge in the right direction.
Comment: Hello and welcome to Music.SE! You can read [here](https://music.stackexchange.com/help/on-topic) about what questions are considered "on topic." Questions asking for recommendations of songs which fit particular criteria are off topic because they're often too specific to help future users. You might be able to rephrase this question by asking what functions a `min9` chord can serve when used in bar 1. This might solicit answers like: it can be a ii chord in a ii-V-I, it can be a vi chord in a vi-ii-V-I, it can be a i chord in a i-iv progression, etc.
Comment: 'Laura' (jazz standard) springs to mind - even though the chords are simple, but the melody puts the 'add9' bit in.
Comment: What is your voicing of Dm(add9) ?
Comment: I wrote a song whose verse progression is :G Dm(add9) X 4, F#m7 Em F#m7 G6, F#m7 Em D C B. G -> Dm(add9) sounds good, Dm(add9) ->  F#m7 is very interesting: the A and E stay constant, D -> C# and F -> F#.
Comment: Nice! I'll try this out
Answer: Here You will find all the triad chords contained in a Dm key. Try playing around those chord and you might found something inspiring. However, I would not personally spend to much time on this as the result might end up really conventional and boring. when you are feeling comfortable try going of book and for example voice your chords in unexpected ways.
Answer: If you are looking for a more modern/popular type of song, I'm fairly sure that Drive by Incubus uses that chord. It is also prevalent in jazz all over the place.


Pizza combinations possible given our options

Question: I own a pizza shop and have tried to come up with the different possibilities of pizza options available given our toppings for any given pizza.  We have 4 crust options thin, regular, thick,gluten free we then have six (6) sauces plus no sauce and can be split 1/2 and 1/2, we have three cheese options, plus no cheese and can be split 1/2 and 1/2, 9 meat options 1/2 and 1/2, 9 vegetable options 1/2 and 1/2, 2 fruit options 1/2 and 1/2, 4 fish options 1/2 and 1/2, 4 seasoning options for the crust 1/2 and 1/2.  We also allow for these options to be used on 1/2 of any pizza excluding the 3 crust options for the crust must be the same for the complete pizza no matter what toppings are placed on it.  I am trying to figure out a baseline of just who many combinations we offer of pizza from our menu.  Thank you
Comment: Are there any other limitations in terms of what can be combined? Can I choose all 6 sauces or only 1? Can I put a sauce on half of the pizza? Can no sauce be used?
Comment: There are infinitely many ways to split a circular pizza into $2$ halves. So you can, for example, split the cheese into $2$ halves and split the meat into $2$ **other** halves. If you allow a different split for each category, then you have infinitely many pizza combinations. So we are forced to assume that you allow only a single split.
Comment: pretend you are building a pizza step by step and at each step ask yourself how many options you have for that step and multiply that number by the answer to the previous step
Comment: Can you have a split 1/2 and 1/2 from sauce 1 and sauce 2 on half of a pizza, and another split 1/2 and 1/2 from sauce 3 and sauce 4 on the other half of the pizza?
Comment: Can the gluten-free crust option be prepared in thick, thin and regular?
Answer: Total Pizzas (Bold Lines are What I've Assumed): 3 sextillion, 615 quintillion, 561 quadrillion, 838 trillion, 447 billion, 72 million, 116 thousand, 736
Far less than the number of stars in the universe.
Multiply together the number of options in the selected lines below to get these total combinations. For lines with (each half) multiply the number twice.
Crust Options if gluten-free thickness cannot be specified: 4
Crust Options if gluten-free thickness can be specified: 8
Sauce Options if at most 1 Permitted per half (Each Half): $7$
Sauce Options if any number Permitted Per half (Each Half): $2^7=128$
Cheese Options if at most 1 permitted per half (Each Half): $4$
Cheese Options if More than 1 Allowed (Each Half): $2^4=16$
Topping + Seasoning Options assuming any number allowed (Each Half):
$2^{(9+9+2+4+4)}=2^{28}=268435456$


Dropbox File Download/Upload

Question: I am having some issues with connecting dropbox to my app. I have printed the exception stack, and it shows that the error was caused by a dropboxunlinkedexception. I am not exactly sure what is wrong in my code. If anyone can take a look and help me figure out dropbox's API that would be great.
Full code:
http://pastebin.com/2ZAZgwEC
Dropbox relevant code:
http://pastebin.com/T2C1AiLz
Comment: I dont know about your problem but i fully recommend you to start searching on how to use the for loop!!! It will be very useful in your case based on your code lines...
Answer: https://www.dropbox.com/developers/start/setup#android
I think documentation is very clear about what to do integrate dropbox in your application.
Does your manifest file contains
<activity
  android:name="com.dropbox.client2.android.AuthActivity"
  android:launchMode="singleTask"
  android:configChanges="orientation|keyboard">
  <intent-filter>

    <data android:scheme="db-INSERT-APP-KEY-HERE" />
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE"/>
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

and also internet permission?
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

dropboxunlinkedexception occurs when you try to download or upload a file without successful login. Check authentication part here https://www.dropbox.com/developers/start/authentication#android and this should sort your problem
Comment: This is the tutorial I based my code off off. My manifest contains both of those parts of code. It seems like the app keeps moving on before it asks me to authenticate with dropbox.
Comment: Okay i got ur problem. what u can do is just make a sample application place 2 buttons authenticate and download. Do authentication on authenticate button and download file on click of download button that should  work.

Dropbox File Download/Upload


Long division answer differs to calculator answer

Question: Can someone make sure I'm not going mad, I'm doing very simple long division: $271÷15$.
I work it out as $18.06\bar 3$ but a calculator returns $18.0\bar 6$?
What's going on here? Do I  have a mental block or something?
Comment: Both are wrong.  It will be $18.0\overline{6}$.
Comment: Well, it may be a classic case of the silly mistake called "calculation error". To pinpoint it, it would be helpful if you posted photo of your long division. P.S. pardon the unfunny sarcasm.
Comment: Probably an error in your long division, and an error in what you plugged into, or read from, the calculator, or typed into your question.
Comment: @JMoravitz OP may have missed a zero. Probably the silly mistake called "typing error".
Comment: Sorry, I did mean 18.0666r on calculator, not sure I know how to post a pic tho lol
Comment: $\dfrac{271}{15} = 18+\dfrac{1}{15}\,$ and $\,\dfrac{1}{15}= \dfrac{1}{10}\dfrac{10}{15} = \dfrac{1}{10}\dfrac{2}{3}= 10^{-1}\ 0.\overline{6} = 0.0\overline{6}\ \ $
Answer: @Aaron Wilden see the image I have attached below.
Comment: Nice job.......
Comment: Indeed, also in the U.S. +1
Comment: @amWhy This is the exact manner in which long division is introduced to 3rd/4th graders in India. So I guess, your comment should be directed to our textbooks :)


Can't read mahout output of PFPGrowth

Question: i am successfully running Parallel FPGroth Algorithm of Apache mahout on top of hadoop.
But the generetaed output text files are not readable as you can see below
SEQorg.apache.hadoop.io.TextDorg.apache.mahout.fpm.pfpgrowth.convertors.string.TopKStringPatterns������3G9��y'����e�����1���2�����������1���������t�5�1���������t�4�1�����������1�4227�����������3�1�����������1�3476���������t�1�1340���������h�1�5795���������N�1�2701���������K�1�3610���������@�1�2106��������
...
Running RecommenderJob and ItemSimilarityJob with the same input file generates correct
output files.
Any ideas?
Answer: These output files are sequence files, not text files. They contains key/value pairs of type <Text, TopKStrinPatterns>
You can get hadoop to read the sequence files and output the textual versions of these objects using the fs shell command, combined with -text and -libjars:
hadoop fs -libjars /path/to/mahout/lib.jar -text /path/to/hdfs/output/part*

If you want these files to be text rather than sequence then you'll need to amend the driver which runs the job, and change the job to use TextOutputFormat, rather than SequenceFileOutputFormat:
// job.setOutputFormat(SequenceFileOutputFormat.class);
job.setOutputFormat(TextOutputFormat.class);

Can't read mahout output of PFPGrowth


Como posso mudar atributos de arquivos no windows com python?

Question: Estou tentando deixar um arquivo .txt oculto. Como posso fazer isso utilizando linha de comando python?
Answer: No windows podes fazer assim:
<code>import ctypes
FILE_ATTRIBUTE_HIDDEN = 0x02

ret = ctypes.windll.kernel32.SetFileAttributesW('CAMINHO/PARA/FICHEIRO.txt',
                                                FILE_ATTRIBUTE_HIDDEN)
if ret:
    print 'Ficheiro definido para oculto'
else:  # se retornar algum erro
    raise ctypes.WinError()
</code>
Resposta retirada daqui.
Não testei porque não tenho windows, por isso não tenho a certeza se vai resultar, se não resultar diz que eu retiro a resposta daqui


Run a process from C with a seccomp profile

Question: I want to run a process with a seccomp profile applied to it (can be from C, terminal, etc.). In particular, I would like the target command to not be allowed to read and write any files, and it can just print to the console. The temporary C outline I have is this:
int main() {
    scmp_filter_ctx filter = load_filter();
    seccomp_load(filter);
    // execl([sample command with arguments], 0);
    execl("ls", 0)
}

The problem I am having is that the execl uses some sys calls that are blocked in my profile. How can I ensure that the only gets applied only to the [sample command with arguments]. Again, this does not have to be in C. Basically, I want to run some executables, and apply seccomp to those processes. I am using Ubuntu 18.04.
Answer: exec* calls are frontend to execve, which implementation in user space looks like this:
int execve(const char *filename, char * const argv[], char * const envp[]) {
    return syscall(SYS_execve, filename, argv, envp);
}

ref: https://stackoverflow.com/a/7381910/544721
Therefore, you may want to instrument your desired binary to execute seccomp filters code after being loaded. e.g.  via binary instrumentation (to add extra code) of actual binary.
Answer: This is not a simple problem. As already pointed out, execl() is a library function that calls execve(2). However, presuming that the program you are launching is dynamically linked (e.g., ls as above), your seccomp filter would also need to allow all of the system calls that the dynamic linker (ld.so(8)) employs to load shared libraries needed by the program. Examples of such system calls (which may vary according to the version of the dynamic linker on your system) are access(), openat(), close(), read(), mmap(), mprotect(), and more. (You can see examples of those systems calls by doing an strace(1) of a simple "hello world" C program.
As Grzegorz Wierzowiecki points out, your only really alternative is to instrument (modify) the target program so that it loads a filter after it has been launched. (There are tricks involving the use of LD_PRELOAD, but these are not foolproof.)
Answer: You could write your seccomp filter so that it only allows that exact call to execve. It is possible to check arguments for equality.
Comment: This is not correct. The various arguments to `execve()` are strings (or arrays of pointers to strings), and in a seccomp filter it is not possible to dereference pointer arguments and check what they point to.
Comment: Right but you could create the filter with hard-coded pointer addresses into read-only memory.


How to use the distributive law correctly in propositional logic?

Question: Can someone explain how in propositional logic these are equivalent :
<code>A ∧ B ∧ (¬B ∨ ¬C) ≡ A ∧ B ∧ ¬C
</code>
Because using the distributive law I would get:
<code> ≡ (A ∧ B ∧ ¬B) ∨ (A ∧ B ∧ ¬C)
 ≡  A ∨ (A ∧ B ∧ ¬C)
 ≡ (A ∨ A) ∧ (A ∨ B) ∧ (A ∨ ¬C)
 ≡  A ∧ (A ∨ B) ∧ (A ∨ ¬C)
</code>
Answer: Hint. B ∧ ¬B is false, so what is A ∧ B ∧ ¬B ?
Comment: Oh I see, so A ∧ B ∧ ¬B must be false , leaving just A ∧ B ∧ ¬C
Comment: Well done, you got it.
Answer: Your first use of the distributive law was correct.  Now note that the statement $A\wedge B\wedge \neg B$ is a contradiction, and therefore we have $$\begin{array}{rcl}A\wedge B \wedge (\neg B \vee \neg C) &\equiv& (A\wedge B \wedge \neg B) \vee (A \wedge B \wedge \neg C)\\&\equiv &(A\wedge (B \wedge \neg B)) \vee (A \wedge B \wedge \neg C)\\ &\equiv& (A\wedge F)\vee (A \wedge B \wedge \neg C)\\& \equiv&F \vee (A \wedge B \wedge \neg C)\\&\equiv& (A \wedge B \wedge \neg C) \end{array}$$ Where $F$ denotes falsem.


Batch download PDF using Python

Question: I'm trying to use Python to batch download PDF's. The process of manually downloading the files are:

Open https://www.ffiec.gov/nicpubweb/nicweb/HCSGreaterThan10B.aspx
Click on any bank on the list. Let's say I pick the first one, JP Morgan.
Click Create Report for the 4th report from the top (i.e.,
Banking Organization Systemic Risk Report (FR Y-15))
Click Your request for a financial report is ready
Download the PDF that opens up with the following url https://www.ffiec.gov/nicpubweb/NICDataCache/FRY15/FRY15_1039502_20160630.PDF
Repeat this process for every bank on the list

To download the PDF for JP Morgan, my code is as follows
import urllib2

url = 'https://www.ffiec.gov/nicpubweb/NICDataCache/FRY15/FRY15_1039502_20160630.PDF'
res = urllib2.urlopen(url)
with open('jpm.pdf', 'wb') as handle:
    handle.write(res.read())

The code works on my machine but not on someone else's. I suspect this has to do with the NICDataCache part of the url. I've been to this url so the code knows where to grab the PDF; for someone who hasn't been to the site, if they punch in the above url, they get

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

I can try to have Python simulate the button-clicking above and then download the PDF that opens up but was wondering if there's an easier way to do this -- a way that doesn't require me to visit every single url I want to download from. Thanks.
Comment: Try with [python requests](http://docs.python-requests.org/en/master/) library
Answer: On the list of banks, notice the integer in parentheses.
Assumption: that integer uniquely identifies that bank.
This is the url that creates the cached resource for you to access:
https://www.ffiec.gov/nicpubweb/nicweb/FinancialReport.aspx?parID_RSSD={bank_id}&parDT=20160630&parRptType=FRY15
Notice the {bank_id} in the URL. I put that there. If you substitute any of the given integers wrapped in parens from the list of banks, it will generate the cached resource.
Then, if you visit this URL: https://www.ffiec.gov/nicpubweb/NICDataCache/FRY15/FRY15_{bank_id}_20160630.PDF
It will respond with the PDF for that bank.
Essentially, you need to go through the list of banks from the first page, generating the cached resource for each bank that you want (by using the first URL as a template, injecting the bank number), then you pull PDFs from the second URL template.
Comment: Is there a way to load the cached resources "silently" in the background? I can do webbrowser.open(cached_resource_url) for each bank but this will open up a bunch of browser tabs. Thanks.

Batch download PDF using Python


Why does my code generate the Cumulative distribution function (CDF) greater than 1?

Question: I want to plot Cumulative distribution function (CDF) of a set of values, Z using MATLAB. When I use the following code, the CDF would not be between 0 and 1! I would appreciate if you could help me.
function plot_cdf(Z)
numberbin=100;
[n,x] =hist(Z,numberbin);
pdf=n/sum(n(:))/diff(x(1:2));
cdf = cumsum(pdf);
plot(cdf)
end

Comment: It would help people trying to help you if you provided sample `Z` values.
Answer: You need
cdf = cumsum(pdf) * diff(x([1 2]));

This is because the cdf is the integral of the pdf. To compute the integral, you approximate it as a Riemann sum: sum the function values (cumsum(pdf)) and multiply by their separation along the x axis (diff(x([1 2]))).


How do I conduct an F-test for change in R^2 within SAS?

Question: Suppose I have a simple model that looks something like this:
y = {Block 1} x1 x2 x3 x4 {Block 2} x5 x6 x7 x8
If I want to conduct an F-test to see whether Block 2 produces a significant change in R^2, how would I do that?
Comment: Duplicate of: http://stackoverflow.com/questions/33506140/sas-sequential-hierarchical-regression-change-in-r2-between-models-and-f-test
Answer: You get the R^2 for the full model (X1-X8) called R^2c and the R^2 for the reduced (X1-X4) called R^2r.
F = [(R^2c-R^2r)/(8-4)]/[(1-R^2c)/(N-8-1)]
with 4 and N-8-1 df where N is the number of observations.
Comment: Thanks! Pardon my ignorance, but is there a name for this method? Or is this just literally what an F-test is?
Comment: I don't know of any special name. It is a test of the significance of the difference between two regression models. If the models differ it means leaving out X5-X8 signicantly lowers the R^2. You can find the equation expressed in terms of sums of squares here. http://onlinestatbook.com/2/regression/multiple_regression.html
Comment: @DavidLane, I believe that formula is the partial F test. OP may want to look into Partial $R^2$ as well.


Como abrir um arquivo .fdb?

Question: Preciso abrir um arquivo de banco de dados (<code>.fdb</code>), mas não sei como. O que devo fazer para abrir este arquivo?
Nele há uma lista que eu quero passar para o Excel.
Answer: Pode usar qualquer linguagem que tenha suporte ao Firebird, ou pode usar um gerenciador para ele, como o Flame Robin, InterBase Query, FBExport, FenixSQL, Marathon, IBExpert (conforme comentário abaixo), entre outros, opção não falta.
Coloquei no GitHub para referência futura.
Comment: tem o ibexpert tbm
Comment: Bem lembrado, adicionado.
Comment: Estava meio perdido, pelo que pude entender o funcionamento de todos são bem semelhantes, Obrigado!
Comment: Um dos melhores e que eu uso é o IBExpert citado, além de ser um simples executável (que não exige instalação) é leve e completo!
Comment: ESF Database Migration Toolkit `pago`

Como abrir um arquivo .fdb?