Prove that $f$ is differentiable at $a$

Question: Let $f$ be a function with domain of an open disk $A \subset \mathbb R^2$. Suppose that its partial derivatives exists at $a\in A$ and that $\frac{\partial f}{\partial x}$ is continuous in $A$. Prove that $f$ is differentiable at $a$
I know that if I can prove that $\frac{\partial f}{\partial y}$ is continuous in $A$, then I'm done. However, from what given I can't see anything that can lead to that conclusion
Comment: Have a look at the *proof* of the result you are mentioning. Maybe this proof is flexible enough to allow you to show differentiability assuming only that one partial derivative is continuous.
Comment: @Etienne I looked at the proof and can't see any way to prove this using that proof.
Comment: So, look at the proof below.
Answer: Write $a=(x_0,y_0)$, and set (for $u,v$ small enough)
$$\Delta(u,v)=f(x_0+u,y_0+v)-f(x_0,y_0)-\left(\frac{\partial f}{\partial x}(x_0,y_0)\, u+\frac{\partial f}{\partial x}(x_0,y_0)\, v\right)$$
One has to show that $\Delta(u,v)=o(\Vert (u,v)\Vert)$ as $(u,v)\to (0,0)$, where $\Vert\;\;\Vert$ is any norm on $\mathbb R^2$.
The idea is to write $$f(x_0+u,y_0+v)-f(x_0,y_0)=f(x_0+u,y_0+v)-f(x_0,y_0+v)+f(x_0,y_0+v)-f(x_0,y_0)\, .$$
Since $\frac{\partial f}{\partial x}$ exists in $A$, one can find $c_{u,v}$ between $x_0$ and $x_0+u$ such that
$$f(x_0+u,y_0+v)-f(x_0,y_0+v)= \frac{\partial f}{\partial x}(c_{u,v}\, y_0+v) \, u\, . $$
This gives
\begin{eqnarray}\Delta(u,v)&=&\left(\frac{\partial f}{\partial x}(c_{u,v}, y_0+v)-\frac{\partial f}{\partial x}(x_0, y_0)\right)u+ \\
& &\left(f(x_0,y_0+v)-f(x_0,y_0)-\frac{\partial f}{\partial y}(x_0,y_0)\, v\right)
\end{eqnarray}
The first term in the right-hand side is $o(u)$ as $(u,v)\to (0,0)$ because $(c_{u,v},y_0+v)\to (x_0,y_0)$ and $\frac{\partial f}{\partial x}$ is continuous at $a=(x_0,y_0)$; and the second term is $o(v)$ by the definition of $\frac{\partial f}{\partial y}(x_0,y_0)$. Altogether, this gives $\Delta(u,v)=o(\Vert (u,v)\Vert)$ , as required.
Comment: From my understanding , you let $(x,y)=(x_0+u,y_0+v)$? what is $o(u)$ and $o(v)$?
Comment: @DianeVanderwaif Yes, $(x,y)=(x_0+u,y_0+v)$. The notation "$o(u)$" means "something negligible with respect to u". And likewise for $o(v)$.
Comment: I talked to my professor, and she said I need to somehow link this problem to the definition of differentiable function that is $f$ is differentiable on $D$ if for $(x_0,y_0)\in D$, $f(x,y)= f(x_0,y_0)+ \frac{\partial f}{\partial x}(x_0,y_0)(x-x_0) +\frac{\partial f}{\partial y}(x_0,y_0)(y-y_0)+r(x,y)$ and $lim_{(x,y) \to (x_0,y_0)} \frac {r(x,y)}{\sqrt {(x-x_0)^2 +(y-y_0)^2}}=0$
Comment: Your professor is right, of course. The limit above says that $r(x,y)$ is $o(\Vert (x-x_0,y-y_0)\Vert)$ as $(x,y)\to (x_0,y_0)$. You should see the link with my answer...
Comment: I wonder if you can go to the chat room with me now ?
Comment: I'd rather not chat. Are you in trouble with my answer?
Comment: yes, right after the line say that Since $\frac {\partial f}{\partial x}$ exits in $A$ Did you missed $\frac {\partial f}{\partial y}$ or you just left it out intentionally? If so, how cna you do that?
Comment: At this point I do not need $\frac{\partial f}{\partial y}\cdot$ I apply the mean-value formula to the 1-variable function $x\mapsto f(x, y_0+v)$ between $x=x_0$ and $x=x_0+u$.
Comment: ok, and from there, what did you o to have the equation $\triangle (u,v)$ after that, the oen that hev partial derivative respect to $y$?
Comment: I'm afraid I don't understand your question
Comment: a) $f(x0+u,y0+v)−f(x0,y0+v)=∂f/∂x(cu,vy0+v)u.$

This gives

b) $Δ(u,v)=(∂f∂x(cu,v,y0+v)−∂f∂x(x0,y0))u+(f(x0,y0+v)−f(x0,y0)−∂f∂y(x0,y0)v)$

how do you got from a) to b)? Substitution some how?
Comment: Yes, exactly. In the formula for $\Delta(u,v)$, you replace $f(x_0+u,y_0+v)-f(x_0,y_0+v)$ by what you have in (a).

Prove that $f$ is differentiable at $a$


Visual Sound 1 Spot Power Supply Hum

Question: I am using a Visual Sound 1 Spot power supply to power my pedal board. Every time I plug in my BOSS RC-2 to the power supply I get a hum. If I power the RC-2 with a battery the hum goes away. I have tried all types of power chaining configurations with no success.
Is there a ground issue going on with the RC-2 that can be corrected? Or do I need to step it up to a Voodoo Lab Pedal Power to resolve this problem?.
Answer: The hum you are hearing is probably the alternating current from the mains adapter. The reason there is no hum with the battery is because batteries are direct current, and have no oscillations in the current.
My suggestion would be to move the pedals away from the mains plug, or anything large and metal (laptops, televisions, radiators). Or you could try plugging the line out from the pedal board into a DI Box, and then into the amp. DI boxes are fairly cheap, with decent ones being as low as £20-30. Here is a Behringer one.
If that fails, try changing cables. Bad cables can be the source of unwanted noise.
Hope this helps
Answer: What you are hearing also could be a ground loop. Daisy chain power adapters suffer from this issue because the ground line on every pedal is shared. Not all pedals isolate their grounds appropriately so you will hear a little hum, which may get worse as you add more pedals to the chain. This is a reason why certain power supplies tout "isolated grounds" as a feature on their units. I highly recommend powering your pedals with one of these units. Despite their moderate expense, the benefits of a power supply such as this outweigh the shortcomings greatly.

Visual Sound 1 Spot Power Supply Hum


What can we say about the convergence of $LU$ given the convergence of $A$?

Question: Given a sequence of matrices $A_{i}$ which we know converges to a matrix $A$, are we able to say anything about the convergence of the LU decompositions for the $A_{i}$? In other words, knowing that $A_i$ converges, can we say that $L_i$ and $U_i$ converge, where $L_iU_i = A_i$?
Answer: The LU decomposition is not unique in general. If you assume, for example, that the element on the diagonal of L are all 1, then it is unique. The problem is that you can choose $A_i$ which have LU decompositions, but converge to some $A$ which doesn't have an LU decomposition. For example, take
$$\left(\begin{array}{cc} a & 1\\ 1 & 1 \end{array}\right)=
\left(\begin{array}{cc} 1 & 0\\ \frac{1}{a} & 1 \end{array}\right)\cdot
\left(\begin{array}{cc} a & 1\\ 0 & \frac{a-1}{a} \end{array}\right)
$$
As $a\to 0$, both of the $L$ and $U$ matrices have entries that go to infinity.


Can I redirect the user to some other page if the result of a view is empty?

Question: How do I redirect the user to some other page, when the view returns empty result?
Comment: **See also:** http://drupal.stackexchange.com/questions/37655/how-to-redirect-based-on-views-results
Answer: In your views No results behavior Choose ' Global: Text area ' choose php filter and add the following code.
<?php
 drupal_goto('node/1'); //path to redirect
?>

Comment: Thanks a lot. This is exactly what I did a few minutes ago :)
Comment: This has security implications, it requires enabling PHP code through PHP filter, which is generally discouraged. https://github.com/dreftymac/public.lab/blob/master/topic/d7/php-filter-implications.md dmid://pageredir_methodic_guard
Answer: Better yet do it in your views-view.tpl.php and avoid using PHP in UI like.
  <?php if ($rows): ?>

      <?php print $rows; ?>

  <?php elseif ($empty): ?>

      <?php drupal_goto('some_page'); ?>

  <?php endif; ?>

if you want to pass query to new url use this for goto
drupal_goto('your_url', array('query'=>array(
'variable_name1'=>'variable_value1',
'variable_name2'=>'variable_value2',
'variable_name3'=>'variable_value3',
...... ...
)));

or if you want to goto an anchor on page use this
drupal_goto("node", array('fragment' => $node->nid));


Assumptions of cluster analysis

Question: Apologies for the rudimentary question, I am new to this form of analysis and have a very limited understanding of the principles so far.
I was just wondering if many of the parametric assumptions for multivariate/univariate tests apply for Cluster analysis? Many of the sources of information I have read regarding cluster analysis fail to specify any assumptions.
I am particularly interested in the assumption of independence of observations. My understanding is that violation of this assumption (in ANOVA and MAVOVA for example) is serious because it influences estimates of error. From my reading so far, it seems that cluster analysis is largely a descriptive technique (that only involves statistical inference in certain specified cases). Accordingly, are assumptions such as independence and normally distributed data required?
Any recommendations of texts that discuss this issue would be greatly appreciated.
Many Thanks.
Answer: Well, clustering techniques are not limited to distance-based methods where we seek groups of statistical units that are unusually close to each other, in a geometrical sense. There're also a range of techniques relying on density (clusters are seen as "regions" in the feature space) or probability distribution.
The latter case is also know as model-based clustering; psychometricians use the term Latent Profile Analysis to denote this specific case of Finite Mixture Model, where we assume that the population is composed of different unobserved groups, or latent classes, and that the joint density of all manifest variables is a mixture of this class-specific density. Good implementation are available in the Mclust package or Mplus software. Different class-invariant covariance matrices can be used (in fact, Mclust uses the BIC criterion to select the optimal one while varying the number of clusters).
The standard Latent Class Model also makes the assumption that observed data come from a mixture of g multivariate multinomial distributions. A good overview is available in Model-based cluster analysis: a Defence, by Gilles Celeux.
Inasmuch these methods rely on distributional assumptions, this also render possible to use formal tests or goodness-of-fit indices to decide about the number of clusters or classes, which remains a difficult problem in distance-based cluster analysis, but see the following articles that discussed this issue:

Handl, J., Knowles, J., and Kell, D.B. (2005). Computational cluster validation in post-genomic data analysis. Bioinformatics, 21(15), 3201-3212.
Hennig, C. (2007) Cluster-wise assessment of cluster stability. Computational Statistics and Data Analysis, 52, 258-271.
Hennig, C. (2008) Dissolution point and isolation robustness: robustness criteria for general cluster analysis methods. Journal of Multivariate Analysis, 99, 1154-1176.
Answer: There is a very wide variety of clustering methods, which are exploratory by nature, and I do not think that any of them, whether hierarchical or partition-based, relies on the kind of assumptions that one has to meet for analysing variance.
Having a look at the [MV] documentation in Stata to answer your question, I found this amusing quote at page 85:

Although some have said that there are as many cluster-analysis methods as there are people performing cluster analysis. This is a gross understatement! There exist infinitely more ways to perform a cluster analysis than people who perform them.

In that context, I doubt that there are any assumptions applying across clustering method. The rest of the text just sets out as a general rule that you need some form of "dissimilarity measure", which need not even be a metric distance, to create clusters.
There is one exception, though, which is when you are clustering observations as part of a post-estimation analysis. In Stata, the vce command comes with the following warning, at page 86 of the same source:

If you are familiar with Stata's large array of estimation commands, be careful to distinguish between cluster analysis (the cluster command) and the vce(cluster clustvar) option allowed with many estimation commands. Cluster analysis finds groups in data. The vce(cluster clustvar) option allowed with various estimation commands indicates that the observations are independent across the groups defined by the option but are not necessarily independent within those groups. A grouping variable produced by the cluster command will seldom satisfy the assumption behind the use of the vce(cluster clustvar) option.

Based on that, I would assume that independent observations are not required outside of that particular case. Intuitively, I would add that cluster analysis might even be used to the precise purpose of exploring the extent to which the observations are independent or not.
I'll finish by mentioning that, at page 356 of Statistics with Stata, Lawrence Hamilton mentions standardized variables as an "essential" aspect of cluster analysis, although he does not go into more depth on the issue.
Answer: Spatial cluster analysis uses geographically referenced observations and is a subset of cluster analysis that is not limited to exploratory analysis.
Example 1
It can be used to make fair election districts.
Example 2
Local spatial autocorrelation measures are used in the AMOEBA method of clustering. Aldstadt and Getis use the resulting clusters to create a spatial weights matrix that can be specified in spatial regressions to test a hypothesis.
See Aldstadt, Jared and Arthur Getis (2006) "Using AMOEBA to create a spatial weights matrix and identify spatial clusters." Geographical Analysis 38(4) 327-343
Example 3
Cluster analysis based on randomly growing regions given a set of criteria could be used as a probabilistic method to indicate unfairness in the design of institutional zones such as school attendance zones or election districts.
Answer: Cluster analysis does not involve hypothesis testing per se, but is really just a collection of different similarity algorithms for exploratory analysis. You can force hypothesis testing somewhat but the results are often inconsistent, since cluster changes are very sensitive to changes in parameters.
http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_introclus_sect010.htm

Assumptions of cluster analysis


Conditional Expectation of Poisson Process?

Question: Fix s,t such that s < t. If we are given that $N(t)=n$ then what is $\mathbb{E}[N(s)|N(t)=n]$? Intuitively I would imagine a uniform distribution so that $\mathbb{E}[N(s)|N(t)=n]=\frac{ns}{t}$ But is this correct? And if so, how would I prove it?
Answer: Your guess is right. This follows from the uniformity of the Poisson process: The distribution of the number of points in a subset $S$ of $[0,t]$ depends only on the measure of $S$, and, given the number of points in $[0,t]$, this is only compatible with the linearity of expectation if the expectation is proportional to the measure of $S$.
(If you want a more rigorous proof, this is straightforward if $\frac st$ is rational, since we can then divide $[0,t]$ into equal parts, some of which make up $[0,s]$. For $\frac st$ irrational, you might have to make a limit argument using countable additivity.)
Answer: Note that given $N(t)  = n$, $N(s)$ can take only the values $0,1,...,n$, because $N$ has increasing paths. Now, for each $ 0 \leq k \leq n$ integer, $$P[N(s) = k | N(t) = n] = \frac{P(N(s) =k , N(t) = n)}{P(N(t) = n)} = P(N(s) = k) \frac{P(N(t) - N(s) = n-k)}{P(N(t) = n)}$$
where you know that $N(t) - N(s)$ is a Poisson random variable independent of $N(s)$ which is also Poisson. Thus one can calculate the above ratio.
Finally,
$$
\mathbb E[N(s) | N(t) = n] = \sum_{k=0}^n k P[N(s) = k | N(t) = n]
$$
so we can calculate this sum as well.
Comment: I can see that this is probably supposed to become a binomial distribution, but my maths are giving me $\binom{n}{k}s^kt^{-n}(t-s)^{n-k}$, which isn't quite right, is it?
Comment: Then you must show your maths : I will try to do it as well.
Comment: Isn't N(t)-N(s) not poisson at all but rather Skellam-distributed?
Comment: No, the point is that Nt is not independent of Ns. Check the properties of the Poisson process.
Comment: Yes, you are right. They would be totally independent if not for the fact that they are mutually overlapping (in fact superset/subset) intervals. I figured out the problem, by the way. $\binom{n}{k}s^kt^{-n}(t-s)^{n-k}$ is indeed correct, simply not sufficiently simplified. It becomes $\binom{n}{k}(\frac{s}{t})^k(1-\frac{s}{t})^{n-k}$
Comment: Thanks for confirming. Now of course, just taking the expectation gives you your answer of $\frac{ns}{t}$, right? Finally, also appreciate Joriki's answer, because his heuristic will help you in problems where computations are more difficult than here, because you will see an end to the computation, which will be your guide.


Unable to connect signal from qobject

Question: I've created a simple class inherited from QObject and created a signal, like this:
testobject.h:
#ifndef TESTOBJECT_H
#define TESTOBJECT_H

#include <QObject>

class testObject : public QObject
{
    Q_OBJECT
public:
    explicit testObject(QObject *parent = 0);

signals:
    somethingChanged();

public slots:

};

#endif // TESTOBJECT_H

testobject.cpp:
#include "testobject.h"

testObject::testObject(QObject *parent) :
    QObject(parent)
{
}

And then tried to make an QEventLoop that should stop when the signal is emitted:
testObject *foo = new testObject;
QEventLoop loop;
connect(foo, SIGNAL(somethingChanged()), loop, SLOT(quit()));
loop.exec();

But compiler complains like this:
error: no matching function for call to 'TestObjectHere::connect(objectTest&, const char*, QEventLoop&, const char*)'

How should I fix this?
Comment: Did you renamed the class _testObject_? If so did you _run qmake_ before you tried to build your project?
Comment: No, _testObject_ is the class created by Qt Creator. I've tried to run qmake and cleaning/rebuilding my project, but with no results
Comment: Where do you call the _connect_ it's inside a QObject class? Anyway try with the fully qualified name: _QObject::connect(..._
Comment: inside `void testFunction()`, called from constructor of form. QObject::connect giving the same error
Answer: I think you need a pointer to QObject:
connect(foo, SIGNAL(somethingChanged()), &loop, SLOT(quit()));

edit: the error message complains about types that are not visibile from your sample:

error: no matching function for call to 'TestObjectHere::connect(objectTest&, const char*, QEventLoop&, const char*)'

also objectTest& should be changed to a pointer, instead of a reference. In the code posted, foo is a pointer, then you should have a mismatch between actual code passed to compiler and what you show.
Try to act similarly on source, for instance, prepend the pointer to operator, as we have done for target.
Answer: Combine the two: CapelliC 's answer and my comment:
QObject::connect(foo, SIGNAL(somethingChanged()), &loop, SLOT(quit()));

Comment: Exactly what I wanted to post. Thanks, guys!

Unable to connect signal from qobject


Why is $ \cos(x, y) $ given with two arguments in this paper?

Question: In the paper Phrase-Based & Neural Unsupervised Machine Translation on page 4 the authors give a probability equation:
$$\Large{ p(t_j|s_i) = \frac{e^{\frac{1}{T}\cos(e(t_j), W e(s_i))}}{\sum_ke^{\frac{1}{T}\cos(e(t_k),W e(s_i))}} }$$
Here, twice the authors use $cos$ with two arguments, both at the top and the bottom of the fraction. There is no reference to $\cos$ indicating any other function in the paper. The paper does mention a rotation matrix, which leads me to believe that $\cos$ is used in its classical trigonometric form. I have looked online for instances where this notation is used, but could not find any.
Can someone explain what the double arguments mean in this instance?
Comment: I think it is a scalar product. The parentheses are overloaded, serving both to indicate the product $(v,w)$ and the argument of $\cos$.
Comment: Since the two arguments are vectors, the author might refer to the cosine of the angle enclosed between the two vectors. For unit vectors, this cosine is simply the scalar product between these two vectors ...
Comment: Could it be a dot product inside the $\cos$ ? I means $\cos()$
Comment: It cites the Conneau article for the result, I would look there for more clarification. It also specifies $W$ is a rotation matrix of some sort, perhaps the intent is to write $e(t_j) \cdot W$, the only way to know for sure is to look at the original paper.
Comment: Seems likely to be a dot product, as suggested by zwim. Then you're computing cosine similarity between the embeddings of $t_j$ and $s_i$ (once $s_i$ is moved to the target space), which is a thing a reasonable person might compute.
Comment: @zwim Given that you were the first to comment the correct answer, feel free to answer the question so that you can receive the appropriate credit.
Comment: I have looked this up in the Conneau article, they state that $\cos$ in this case refers to the cosine similarity function. I am not sure what the proper procedure is for answers in the comments, but I'll be happy to mark as correct whomever formulates this as an answer to the question.
Answer: This answer was provided by @zwim in the comments. When we refer to the Conneau article cited in the paper, we find that $\cos$ refers to the cosine similarity function, which can take two vectors as an input.


setting up nginx with django and php on aws

Question: I am trying to set up nginx for django app and php on AWS / Linux AMI. Nginx has already been configured to work for multiple django apps simultaneously and all works fine.
Now I need to include the third party solution based on php. This should work on separate url /dash/.
I went through many tutorials and "stack" answers, but none worked for me.
I have already installed php and php-fpm. I modified config file at /etc/php-fpm-5.5.d/www.conf and tried using both socket and TCP/IP:
listen = 127.0.0.1:9000
and also
listen = /var/run/php-fpm.sock
After restarting php-fpm service I checked that the socket has really been created. Then I modified nginx accordingly:
location ~ /dash/$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #fastcgi_pass   127.0.0.1:9000;
    fastcgi_pass unix:/var/run/php-fpm.sock;
    fastcgi_index  index.php;
    include        fastcgi_params;
}

I created the test.php file to test php and also placed the third party solution to the /usr/share/nginx/html/. When I try to visit https://DOMAIN/dash/ I got 404 error (or I got blank page if I remove try_files setting). However, when I try to visit https://DOMAIN/dash/index.php or https://DOMAIN/test.php, the browser offers me a file to download - the actual index.php file I expected to produce the html for me. I get the same result using wget.
service php-fpm status claims php-fpm-5.5 (pid 12345) is running... so I supposed the php files should be processed.
I already tried to change php-fpm config by changing attributes listen.owner and list.group as well as user and group to nobody, ec2-user or nginx but I still get the same 404.
I have already tried the parameter
fastcgi_param  SCRIPT_FILENAME ...
but as I was not sure what exactly should be here I removed it. I suppose now we use the default from the fastcgi_param file:
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
If you see some obvious mistake or something I overlook, please let me know. I apologize for the wrong terminology if any.
Answer: Your location needs to process URIs that end with .php. If your configuration is downloading your PHP files, you probably already have the root set correctly.
Many installations have a suitable value for SCRIPT_NAME within the included fastcgi_params file, but the example below shows it stated explicitly (just in case).
For example:
root ...;

location ~ \.php$ {
    try_files $uri =404;
    #fastcgi_pass  127.0.0.1:9000;
    fastcgi_pass   unix:/var/run/php-fpm.sock;
    include        fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME $request_filename;
}

The fastcgi_split_path_info and fastcgi_index directives are not required in this case. Always place fastcgi_param statements after the include statement, otherwise your directives may be silently overridden.
Comment: Thank you for explanation. I have changed the location to process .php files but in this case the browser does not offer the files to be downloaded. Now I get 500 when I go to the /dash/index.php but it is the problem of the script itself, I believe.
Comment: I checked the test.php and it works, so the third party solution is not working actually. Thank you once again.


Proving $\sup(A+B)=\sup(A)+\sup(B)$

Question:
Possible Duplicate:
How can I prove $\sup(A+B)=\sup A+\sup B$ if $A+B= \lbrace a+b\mid a\in A, b\in B\rbrace $

here's a homework question I'm currently working on:

Let $A,B \subset \mathbb{R}$ non-empty sets bounded from above and from below. Show that
$A+B$ is upper bounded and that $\sup(A+B)=\sup(A)+\sup(B)$
$A+B=\{a+b:a\in A, b \in B\}$

It was pretty easy to show to $A+B$ is upper-bounded by $\sup(A)+\sup(B)$, but I'm not quite sure how to prove that this is also the supremum. Any hints?
Thanks!
Comment: Let $c$ some upper bound of $A + B$. Then for $a \in A$ $c-a$ is an upper bound of $B$, therefore ...
Comment: I think that I saw at least *two* of these questions posted on the site before.
Comment: Take $(a_n)_n \subset A$ to be the sequence such that $\lim_n a_n = \sup(A)$, similarly for $b_n$. What can you say about $(a_n+b_n)_n$ ?
Answer: Well $a+b\leq \sup(A)+sup(B)$ then $\sup(A+B) \leq \sup (A)+\sup(B)$ for the other inequality consider $a_{\epsilon}\in A$ such that $ a_{\epsilon}>\sup A- \epsilon /2$ and $b_{\epsilon}\in B$ such that $ b_{\epsilon}>\sup B- \epsilon /2$ then
$\sup(A+B)\geq a_{\epsilon}+b_\epsilon>\sup A +\sup B-\epsilon$ for any $\epsilon>0$ then
$\sup(A+B)\geq \sup A +\sup B$ $\blacksquare$
Comment: Isnt't there a dot missing prior to "for the other..."?

Proving $\sup(A+B)=\sup(A)+\sup(B)$


Musical Harmony: When to use more than three chords

Question: I understand that I, IV, and V chords in both major and minor keys are common chords that make up a good progression. I understand that those 3 chords cover all the notes diatonic to the key that we need to make up a melody:
<code> -  scale degrees
I:  1, 3, 5
IV: 4, 6, 1
V:  5, 7, 2
</code>
At what stage do we need to use other chords, like ii, iii, vi, or viio?
Comment: There are scholarly answers to this vote-worthy question, but my simple answer is "You use more than three chords when you *learn* enough about music to *know* more than three chords."
Comment: Woody Guthrie said, "If play more than three chords, you're just showing off." We use the ii, iii, vi and VIIdim pretty much _to_ show off.
Comment: Specified the question, and added some information to clarify what the asker (assumedly) already understands.
Comment: @VarLogRant You play VIIdim, *not* to show off, but you use it instead of a V7(b9) (a dominant) chord. VIIdim contains exactly the same notes, but the tonic. Thus they can (often) be played interchangeable.
Comment: It's a musical choice, not a stage. If you cannot hear a reason for using more than three chords then don't bother. ,.
Answer:
At what stage do we need to use other chords, like ii, iii, vi, or
  viii?

To cut through the academia: we need to use other chords when they make the sound we want to hear.
Let's say you're singing in the key of C major.
Sing a G over a C chord. It sounds a certain way.
Sing a G over a G chord. It sounds different.
Sing a G over an Em chord. It sounds different again.
Sing a G over an Am7 chord. It sounds different again.
Those are all chords in the key, which contain a G.
Which of those is correct at a given moment in the melody? That's entirely subjective. You can change how a melody is perceived by changing the chords below it.
Of course, familiar tunes usually have a familiar chord progression, and if you deviate from that, it will jar to the audience.
Answer: Given the set of all possible diatonic melodies, you could theoretically harmonize them using only three chords, but in doing so you give up control of the harmonic rhythm. You would end up changing chords at odd times in order to catch melody notes where they fall.
Consider a tune in C major, and in one bar you have the notes E, C, and A--in that order. To harmonize this (albeit in a very rudimentary and amusical way; though it serves to illustrate the point), you could use a I chord for the first two notes and a IV chord for the last one.
However, the rhythm of the notes could be anything, and could dictate that you change chords at a strange time. Also, the harmonic rhythm of the music may only be asking for one chord change for the entire bar! To solve this problem, I would use a vi chord--it covers all of the melody notes in that bar, and does not require a change in the middle.
Answer: Luckily, not all melodies use only the note material from a diatonic scale. Most songs use leading-tones to move the melody from one mode to another (which is called tonal modulation).
Furthermore, a lot of modern Western music use a circle progression, in the harmonization of a melody, as each chord has its own place and feel in a harmonic progression. In a circle progression, you'll often see chords getting "dominatized" (making a minor chord to a major), to create suspense and a feeling that the chord pulls towards another chord.
Theoretically you could harmonize a melody (which only used notes from the diatonic modes!), with only I, IV and V, but much more often you'll want to break this pattern up with different cadences, such as ii - V - I, the interrupted cadence V - VI to create a more livid and exciting arrangement.
Comment: Interestingly, you could harmonise any diatonic melody with Imaj13!


Which K-mean algorithm I have to use for this problem?

Question: Perform a k-means Clustering (non-iterative algorithm) using k=2 randomly initialised centroids (cluster prototypes), and the Euclidean distance.
At the moment I manage to understand you can use different algorithms to run K-means clustering (Lloyd, Forgy's, McQueen, Hattigan), but I understand all of the algorithm are iterative and I don't find or understand the non-iterative idea of non-iterative clustering.
Please, could some one clarify me that?
Thanks
Comment: Please add the `[self-study]` tag & read its wiki. Then tell us what you understand thus far & where you're stuck.
Answer: What non-iterative version of k-means was discussed before? The "default" version - Lloyds algorithm - is iterative. So you are probably meant to use MacQueens, or a matrix based dual form, depending on what was discussed.
Comment: But, I have understood that McQueen is an iterative method too, isn't?
Comment: From my understanding of the _original_ publication, it does a single pass over the data. But you also would initialize it with the first k objects as centers (because you haven't seen other data yet) then. So there probably is another non-iterative algorithm in your class/book.
Answer: An example
Lloyd's algorithm is the standard k-means clustering algorithm and it is iterative. You chose k random starting points from your data set and compute the (Euclidean) distance of each point to each cluster center. You assign each point to its nearest cluster. After the assignment of one point to one cluster, you recalulate the mean of that cluster. After you've done this for all points, your first iteration is complete and you start from the beginning, i.e. you start a new iteration. The cluster means will have changed during your first iteration, which makes it necessary to, again, calculate the distance of each point to each cluster center, and see if there aren't perhaps some points that are now closer to other cluster centres.
In principle you could also stop the Lloyd's algorithm after your first round of assigning points and your algorithm would be non-iterative. The quality of your solution will, however, be not that great.
MacQueen's algorithm is non-iterative in the sense you choose your k random starting points and assign all your points to those centers only once. Algorithmically, MacQueen's does nearly the the same thing as Lloyd's: you go through each point and compute the increase in variance for each cluster (this is where it is mathematically different to Lloyd's), if it were assigned to it. You chose to assign the point to the cluster, whose variance increase is minimally. After you have gone through all points once you stop and your MacQueen's algorithm terminates. From an algorithmic point of view, this is where MacQueen's and Lloyd's are different.
In principle you could also continue with more iterations, this would make your algorithm iterative.


MySQL per-database replication?

Question: So, my problem is interesting: we want to migrate from one server to another. We made a master-slave replication, but my boss came with the idea to make migration one database at a time.
So he asked me to setup at the new server another MySQL instance, let the slave almost as-is and make the new instance be the new master incrementally, one database at a time. Is it possible, that is, can I transfer the database 'x' from old master to new master and just tell slave to synchronize 'x' at the new master from now on?
I've read at this old thread ( Mysql Replication - are per-database threads possible? ) that this was not possible at that time. This can be done now?
Thanks!
Lucas Bracher.
Answer: Yes, you can do this. MySQL's replication allows you to specify which schemas to replicate[1] or not, look for the replicate_wild_do_table parameter.
However, it is also very silly to do this, as you will need some downtime for each migration to make sure there is no data loss, and I also can't think of a good reason not to simply replicate all the databases.
[1] The slave will still fetch the complete binlog, but only execute statements that match the filter(s)
Answer: You could do something like this, but there's no benefit.
The thing you can't do is "tell slave to synchronize 'x'"  That's not how replication works.  Replication just replays events from the master starting from the position you tell it to.  So you are required to make sure you take a snapshot of the data from the master at a consistent point in time, and copy that data to the slave before you start replication.
There's no real advantage to doing it one database at a time from the master to the slave.  In fact, it's much more difficult.
The easiest way to set up a slave is to make a full backup of your master, making use to record the binlog position, then restore that backup to the slave, and start replication from the recorded binlog position.
But lets step back and take a look at what you're really trying to do:
You want to migrate to a new server, and let the slave be "master" for one database at a time.
This is simple.
So here is your replication: Master -> Slave
You set up the slave to be a complete copy of the master, and replicate changes so they stay in sync.
What does it mean for the slave to be master now?  It just means you tell your application to use the slave to do all the reading and writing.  That's it.  Once you have replication set up, there's no other mysql changes to make.
Promoting a slave to a master is an application configuration change only  (in your case where you have a master mysql server with one slave replicating from it.)
So if you can change your application config to use a different mysql database for each database it's trying to use, then you can migrate on db at a time.
Simple.
Comment: A note about backups: Choices for backing up MySQL data include: stopping the server and copying the files :: mysqldump (-F|--single-transaction) :: LVM snapshot :: innobackup/xtrabackup
Answer: Nope -- MySQL replication is all-or-nothing(ish).  You can't slave one MySQL server from two separate masters.

MySQL per-database replication?


Type mismatch, "char" does not match with "char[]" in Processing

Question: I am trying to run this Processing code taken from this website to create a wavelength meter.
/***************************************************************************
Created by dbc0301
***************************************************************************/

import processing.serial.*;
Serial port;

PFont myFont;

int tmp;
//int begin='$';//begin
int end='\r';//end
char rev[] = new char[15];//datas
int revFlag=0;

int[] data=new int[10];//F1,F2,F3,F4,F5,F6,F7,F8,Clear,NIR
//int F1,F2,F3,F4,F5,F6,F7,F8,Clear,NIR;

//Stimulus Function
float[] Fx={0.07763, 0.34806, 0.09564, 0.02910, 0.51205, 1.02630, 0.64240, 0.04677};
float[] Fy={0.00218, 0.02980, 0.13902, 0.60820, 1.00000, 0.75700, 0.26500, 0.01700};
float[] Fz={0.37130, 1.78260, 0.81295, 0.11170, 0.00575, 0.00110, 0.00005, 0.00000};

int textHight=25;
float rt=1;//Length scaling

void receiveDatas(){
    for(int i=0;port.available()>0;i++){
      tmp=port.read();
      if(tmp!=end){
        rev=char(tmp);
      }else{
        rev=char(tmp);
        revFlag=1;
        tmp=port.read();
        break;
      }
    }
}

void setup(){
  //size(1074,241);
  size(1250,301);
  background(0);//white255 black0
  noStroke();
  myFont = createFont("Microsoft YaHei", 20);
  textFont(myFont);

  println(Serial.list()[0]);
  port = new Serial(this,Serial.list()[0],115200);
}

void draw(){
  receiveDatas();
  if(revFlag==1){
    String[] m=match(new String(rev), "(.*?):(.*?)\r");//Regular Expression Matching
    //printArray(m);
    try{
      if(m[1].equals("F1")){
        data[0]=int(m[2]);
      }else if(m[1].equals("F2")){
        data[1]=int(m[2]);
      }else if(m[1].equals("F3")){
        data[2]=int(m[2]);
      }else if(m[1].equals("F4")){
        data[3]=int(m[2]);
      }else if(m[1].equals("F5")){
        data[4]=int(m[2]);
      }else if(m[1].equals("F6")){
        data[5]=int(m[2]);
      }else if(m[1].equals("F7")){
        data[6]=int(m[2]);
      }else if(m[1].equals("F8")){
        data[7]=int(m[2]);
      }else if(m[1].equals("Clear")){
        data[8]=int(m[2]);
      }else if(m[1].equals("NIR")){
        data[9]=int(m[2]);
      }else{
        print("Wrong datas!");
      }
    }catch(NullPointerException e){
      println(rev);
      printArray(m);
    }finally{}
    revFlag=0;
    //printArray(data);
    //delay(10);
  }

  /*Display*/
  //rectMode(CORNER);
  background(0);
  textSize(20);

  fill(#8b3dc5);
  rect(0,0,data[0]*rt,30);//F1
  text(data[0], data[0]*rt, 0+textHight);//textHeight: veritcal height of text

  fill(#00528e);
  rect(0,30,data[1]*rt,30);//F2
  text(data[1], data[1]*rt, 30+textHight);

  fill(#00b1ed);
  rect(0,60,data[2]*rt,30);//F3
  text(data[2], data[2]*rt, 60+textHight);

  fill(#01ffcd);
  rect(0,90,data[3]*rt,30);//F4
  text(data[3], data[3]*rt, 90+textHight);

  fill(#00af50);
  rect(0,120,data[4]*rt,30);//F5
  text(data[4], data[4]*rt, 120+textHight);

  fill(#ffff01);
  rect(0,150,data[5]*rt,30);//F6
  text(data[5], data[5]*rt, 150+textHight);

  fill(#ffc000);
  rect(0,180,data[6]*rt,30);//F7
  text(data[6], data[6]*rt, 180+textHight);

  fill(#c10005);
  rect(0,210,data[7]*rt,30);//F8
  text(data[7], data[7]*rt, 210+textHight);

  fill(#ffffff);
  rect(0,240,data[8]*rt,30);//Clear
  text(data[8], data[8]*rt, 240+textHight);

  fill(#888888);
  rect(0,270,data[9]*rt,30);//F8
  text(data[9], data[9]*rt, 270+textHight);

  //delay(1);

  /*Color Temperaure*/
  float X,Y,Z,x,y,n,temp;
  X=(data[0]*Fx[0] + data[1]*Fx[1] + data[2]*Fx[2] + data[3]*Fx[3] + data[4]*Fx[4] + data[5]*Fx[5] + data[6]*Fx[6] + data[7]*Fx[7]);//20/1000;//20 is the interval of integration. 1000 is used to converted the value into a real number between 0~1
  Y=(data[0]*Fy[0] + data[1]*Fy[1] + data[2]*Fy[2] + data[3]*Fy[3] + data[4]*Fy[4] + data[5]*Fy[5] + data[6]*Fy[6] + data[7]*Fy[7]);//20/1000;//But it is meaningless to multiply this number here since it will be reduced in the next step
  Z=(data[0]*Fz[0] + data[1]*Fz[1] + data[2]*Fz[2] + data[3]*Fz[3] + data[4]*Fz[4] + data[5]*Fz[5] + data[6]*Fz[6] + data[7]*Fz[7]);//20/1000;

  x=X/(X+Y+Z);
  y=Y/(X+Y+Z);

  n=(x-0.3320)/(0.1858-y);
  temp=437*n*n*n+3601*n*n+6831*n+5517;
  print(temp);
  println("K\n");

}

It is giving me this error on line 24 and 26:

Type mismatch, "char" does not match with "char[]"
Comment: @PMF It's Processing code _talking_ to an Arduino.
Comment: That's because `rev` is a `char[]` (meaning, a `char` array), but you assign a single `char` to it.
Comment: I'm confused. This isn't valid arduino (C++) code. It more looks like java, but Java doesn't run on Arduinos.
Comment: rev=char(tmp); -> what does char(tmp) return? if it's a char, you'll need to point to an index of rev to assign the value, like: rev[0]=char(tmp);,
Answer: The problem is that rev is an array. If you want to put tmp in rev, do something like rev[0] = char(tmp). I don't understand well your code, but if you want every letter you press to be added to tmp, you could make a variable to take count of how much letters were pressed, and do rev[typed] = char(tmp) where typed is the variable in question. Also, this code will probably confuse most of the community, go to discourse.processing.org to ask Processing questions. Hope i could help, though!

Type mismatch, “char” does not match with “char[]” in Processing


Does the activity in IPL count by ICC?

Question: I want to know, if a player takes wicket, scores runs etc. in IPL (Indian Premier League), will it be counted by ICC (In their record/history)?
Answer: The International Cricket Council (ICC) is the international governing body of cricket.
IPL is one of the domestic cricket competitions held in India. It's not an international T20 cricket series. The performances(runs scored, wickets taken etc) will not be counted for any ICC awards or for any ICC rankings. But those IPL stats will be added to the Twenty 20 career of the cricket players but not to the Twenty 20 internationals.
Not only IPL, all the domestic as well as international T20 activities will be added to the Twenty 20 career of respective players. For example, if you see the runs scored by Chris Gayle in Twenty 20 matches, it will include the runs that he scored for West Indies and for other domestic teams like Jamaica Tallawahs, Kolkata Knight Riders, Royal Challengers Bangalore etc.
You can also refer this post about the difference between Twenty 20 and T20I.
Comment: Might be useful to include the difference between Twenty 20 and T20I in the answer itself, because (1) it saves time reading some other web-page (2) the web-links can change Dynamically, so the information might not be available later.

Does the activity in IPL count by ICC?


f is a function from R to R and there exists a continuous function g from R to R such that f=g a.e., then does it imply that f is continuous a.e.?

Question: I think it does imply but I am not sure. My argument was f=g on a finite set, so barring those finite points we can say that f is continuous, so f is continuous on all but countably many points which imply f is continuous almost everywhere.
Comment: Welcome to MSE. For some basic information about writing mathematics at this site see, *e.g.*, [basic help on mathjax notation](/help/notation), [mathjax tutorial and quick reference](//math.meta.stackexchange.com/q/5020), [main meta site math tutorial](//meta.stackexchange.com/a/70559) and [equation editing how-to](//math.meta.stackexchange.com/q/1773).
Comment: a.e. does not mean that the exception set is finite, but has measure $0$. So $f=g$ except on a finite set is not true.
Answer: Let $f(x)=1$ for $x$ rational and $0$ for $x$ irrational Let $g(x)=0$ for all $x$. This is a counter-example.
Comment: @RajatMishra No. Continuous almost everywhere means there exists a set $E$ of measure $0$ such that $f$ is continuous at $x$ whenever $x \notin E$. The function I have defined is not continuous at any point.
Comment: But isn't f continuous a.e. as Q is a measure zero set in R .?
Comment: Got it.. Thanks..


Confusion matrix, false negative

Question: I would like to know how to calculate the false negative, the true negative, the false positive and the true positive to form a confusion matrix. A numeric example would clear all doubts I think. Thanks.
Answer: You question may be ill-posed, but let me see if I can provide some thoughts.
Does this Example work?
Matlab even has a Command with  examples.
Regards -A
Answer: True positives are cases predicted positive which are actual positive
False positives are cases predicted positive which are actual negative (false alarms)
False negatives are cases predicted negative which are actual positive (missed cases)
True negatives are cases predicted negative which are actual negative
Just count these up and put them in your confusion matrix. If you want rates, Wikipedia has a concise description.
Answer: I am posting my little cheat sheet that helps me remember easily. Every application has a structure it maintains in the calculation so you may want to check that out. This structure is from scikit-learn.
You may watch this video to gain a deeper understanding.

Confusion matrix, false negative


Microsoft Azure - Deploying ASP.NET solution - Path too long error

Question: First, I'd like to explain that I tried the suggestions offered here:Path too long error when building a windows azure service. None of these solutions seem to work for my situation.
To summarize, I'm simply trying to to deploy an ASP.NET web forms app to my already-established Azure web app service. I see the following error:
Copying file packages\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.2.0\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.2.0.nupkg to C:\Users\stevieray8450\AppData\Local\Temp\WebSitePublish\FrankiesDiscountAutos1-982367110\obj\Debug\Package\PackageTmp\packages\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.2.0\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.2.0.nupkg failed. The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.  FrankiesDiscountAutos1      0
The path is ridiculously long, as you can see. Are there any other suggestions? Much appreciated!
Comment: If it is useful, please mark it that will help more communities who has the same issue.
Answer: I encountered this issue before. And I resolved it
by setting the _CSRUN_STATE_DIRECTORY to a shorter path, say "C:\A" for example. It is also in you mentioned SO thread. We also can get more detail information from this document. If you have't tried this, please have a try.

Note: Make sure that you close Visual Studio and shutdown the development fabric by using the "csrun /devfabric:shutdown" command I mentioned above or by clicking "exit" on the Windows Azure the tray icon.


how to keep file and folder permissions from changing

Question: I have a directory of files and folders that are added and removed and the permissions that I had set keep changing. How can I permanently keep the permissions on a specific path so that no matter what happens in its folders all files and folders inside that folder will recursively follow the permissions set.
The permissions I had set is the following:
sudo chmod 755 -R /var/www/uploads
sudo chown www-data:www-data -R /var/www/uploads

I'm not sure what user group is used by php/apache when I write the code to delete the files and I'm guessing that would be why it cant do it.
Comment: I don't think Unix has a way to force recursive permission assignment like this.
Comment: makes no sense though cause i can do this via terminal but when i try with phps exec function it wont work.
Comment: I don't understand. These commands only change the permissions one time, they don't affect new files that you create.
Comment: Does the `www-data` user have permission to use `sudo`? If not, it won't be able to execute those commands.
Comment: what i did was set the permission then upload a few files via ftp to see if the unlink() function would work and it threw permission errors at me.
Comment: What are the permissions changing to?
Comment: the files are getting removed but not the directories. the directory permissions are being set to 755 (as i had set) and the user group being set to root.
Comment: is that because i uploaded the files as the user root?
Answer: Have you looked into using the umask command to set the permissions mask on the directory?  There is a great explanation of the umask and how it works on Linux.  I believe that correctly using umask and chmod should resolve the issue.
Answer: You can try to use ACLs see here.  Specially the Default ACL:
"Directories can be equipped with a special kind of ACL -- a default ACL. The default ACL defines the access permissions all objects under this directory inherit when they are created. A default ACL affects subdirectories as well as files."
Answer: You're fighting with the system here.  You may find an obscure way to prevent permissions changes from working, but that will likely lead to errors of various sorts, some of which may be fatal.  It may also lead apps intended security measures to be incorrectly set up.
You should switch focus to why the permissions are getting mucked up.  The main tools you'll need to focus on are the umask settings of your web server processes and your users, and depending on the permissions schema you use, you might make use of the directory sticky bit (ie chmod g+s).  The directory sticky bit causes new files and folders to inherit the group of the parent directory if the user creating the directory is in that group.
Without more details about your expected permissions schema, and the unexpected changes, it's hard to say much more.
Note though that you probably don't want to make your files chmod 755.  They'll more likely want to be set to 644.  e.g.
find /var/www/uploads -type d -print0 | xargs -0 chmod 2755
find /var/www/uploads -type f -print0 | xargs -0 chmod 644


Two basic questions on PDEs (trace operator and Sobolev space)

Question:
I am a bit unsure about the role of the trace operator. I understand that if you have a PDE that is solved by a function $u$ in some Sobolev space, then it's not necessarily defined on the boundary since $u$ is in $L^p$ and so can be "redefined" on the boundary as it's a null set. But sometimes we have boundary conditions that $u$ needs to satisfy so that uniquely fixes $u$. If we don't have such boundary conditions, why does it matter what $u$ is on the boundary? What role does the trace operator play?
If $u$ is in $H^{r+2}(\Omega)$ for all $r$ where $\Omega$ is compact, then $u$ is also in $C^k(\overline{\Omega})$ for all $k$. This is a fact but I don't know why? How does existence and integrability of $u$ and its derivatives imply continuity of $u$ and its derivatives?
Comment: Too tired now to explain in detail. Maybe I'll do so tomorrow if no one else does. In the mean while, I addressed both issues in [my lecture notes](https://documents.epfl.ch/users/w/ww/wwywong/www/lecturenotes/NotesOnSobolevSpaces.pdf). The answer to the first question, in the context of PDEs, basically boils down to _a priori estimates_. The second question is answered by Morrey's inequalities. Another good reference that addresses the issues is Adams' _Sobolev spaces_.
Comment: To give one version of a quick summary to how trace theorems work: you define on $W^{k,p}\cap C$ (continuous functions) which is dense in $W^{k,p}$. The estimates show that the mapping into $L^q$ is bounded and linear. So by the [BLT theorem](http://en.wikipedia.org/wiki/Continuous_linear_extension) there is a unique continuous extension to the whole of $W^{k,p}$.
Comment: Thanks. I don't suppose the rest of the CCA Analysis lecture notes are available for public consumption?
Comment: AFAIK the course websites are only available for CCA students. But individuals may have the notes on their websites.
Answer: As Willie explained the intuition of the definition for the trace operator, maybe I can say some words about the boundary condition in Differential Equations, and hope that it can help. Take the elliptic equation as example, if we want to consider the shape of a membrane under outer force, we are lead to equation like $-\Delta u=f$, assume the boundary of the membrane is good enough and is fixed (actually now the boundary function is the trace of the shape function), then this is the Cauchy problem for the equation.
Moreover, because in elliptic equation we have good enough a priori estimate(use Newton potential we could see what the solution looks like), we can solve this Cauchy problem for general boundary data(which might not be continuous, for example $L^p$), in this case the solution is not continuous up to the boundary, but converge in $L^p$ sense, which is similar to the definition of trace operator.
So for me, "trace" (generalization of the boundary value problem)just makes the problem well-posed.


How do I find suitable chords for a melody or a song? Or How do I come up with chord progression?

Question: I have spent some time reading a book that taught me different types of chords and different scales and I understand them very well. But the book didn't really expand on how to actually use these chords to write your own music. How do you find the right or suitable chords for a melody you have written, is there any rules I have to learn? When coming up with a chord progression for example, is there any rules I have to follow?or is it just what best fits and sounds right. If this is a topic that needs a lot of explanation then I totally understand. I just need to know what I should do next (get another book to learn about it, read examples to gain more experience, etc..)
I know this question might have been asked a lot but in my case I don't think I need any further knowledge on more types of chords for now but just want to use apply the chords I have learnt to write my own music.
Comment: Everyone has to find their own process for composing. If you don't already know how to *play* a lot of songs, I would go there next. That will help you "feel" how songs work. One way to start composing is to copy existing material and them mutate it in some way.
Comment: You say you know different _types_ of chords, but how about different _roles_ of chords? Or how about the the individual notes that make up the chords - do you know what the role of each note is? Have you tried putting chords together? Have you tried finding suitable chords to melodies - do you have specific difficulties with it?
Comment: What style? Schubert song, Cole Porter song, lady Ga Ga song...?
Comment: @David what sort of progressions and melodies have you tried so far, and what kind of problems did you encounter with it? Do you have a specific example melody for which you have not been able to find any suitable chords?
Answer: Reading about it is not particularly a productive way to go. Assuming you play an instrument, it makes a lot more sense to get on and play. Play about with different chords. Feel and hear how they interact with each other. Find ones that don't follow each other well.
There are no rules. There are guidelines. It's called music theory. It's no substitute for the real, live sound of music.
For starters, there are chord families. Discussed frequently on this site. Chords built on the diatonic notes of a key. Majors on I, IV and V. Minors on ii, iii and vi.
Just about any musical phrase can be accompanied using two or three of those chords. Or even just one! The idea is to listen to that phrase, and find chords which match its notes. Not one chord for each note, but maybe one for each bar, or possibly two for each bar. A clue is that the notes from the melody usually match a note or two from the chord which fits best. Which often means there's a choice of chord. Say the tune in key C, has the notes C E F E; C would fit - but so would Am, and maybe Fmaj7. Your job is to decide which is a best fit - bearing in mind the preceding and successive bars, and the chords you decided fitted there.
Answer: The best way to learn this is by doing. Take a very familiar melody and try to figure out chords that work. Start with something simple like "Happy Birthday". The melody starts on the dominant note of whatever key you're in. (For example, if you're in C major, the melody starts on G.) The first chord of a piece of music in a major key is usually the I chord. No exception here. Happy Birthday can be done with just the I, IV, and V7 chords. If you do the work of experimenting around, you'll probably come up with this:
      I           V7         V7          I
Happy birthday to you. Happy birthday to you.
      I             IV
Happy birthday dear person.
      I        V7 I
Happy birthday to you.

This isn't the only right answer, of course. It could potentially be this:
      I           iii        V7          I
Happy birthday to you. Happy birthday to you.
      vi7           ii6
Happy birthday dear person.
iv6   I        vii° I
Happy birthday to   you.

...or any number of variations. (Note the 6s are meant to indicate 6th chords, not 1st inversion.) It's a skill that comes with practice. Do so by trying to figure out the chord progressions of songs you like. A great deal of music has been analyzed and can be found online. If you're stumped on a particular chord, you can look it up. You can also check your work against it (knowing that what you find online is sometimes wrong).
When it comes to composing your own music, there is no established harmony for your melody, so you can try different chords until you find a progression which both fits the melody and is pleasing to you. (Remember music is an art form and there is a lot of subjectivity to it.) Another way to go about it is to come up with a chord progression first and then improvise a melody over it.
If you do this enough, you'll find that progressions commonly fall into these formulas.
Major - Start with I, go to any other chord and jump in:

                      ┌──>── I ──>───┐
iii  ─>  vi  ─>  [ii or IV]  ─>  [V or vii°]  ─>  I  ─>  any chord
 └────────────────<──────────────────┘

Minor - Start with i, go to any other chord and jump in:

VII  ─>  III  ─>   VI   ─>  [ii° or iv]  ─>  [V or vii°]  ─>  i  ─>  any chord
 └────────────────<───────────────┘

Notice the first version of "Happy Birthday" falls into the formula for major keys. It begins with I, goes to any, which happens to be V, which leads back to I. I goes to any, which is IV this time. It takes the upper path from IV to I to V and lands back at I. It's not always this simple, of course, but this is the basis of a lot of music.
Comment: How come the 4 magic chords don't fit in your formulas?
Comment: What are the 4 "magic chords"? Are you talking about I V vi IV? It's a notable exception. The formulas are not meant to cover every possibility, of course. But they do demonstrate the most common conventions, like the dominant chord resolving to the tonic. They're not *my* formulas; you find these in plenty of material about chord progressions.
Comment: Yes, these chords, or the minor version i VI III VII. I understand it doesn't cover all possibilities, but putting aside perhaps the most common one makes it less reliable. V -> iv and V -> IV movements are far more common than V -> iii, in my experience. I'm just saying this because I liked your answer, but I wouldn't be comfortable upvoting a suspicious formula for chord progressions.
Comment: I'm glad you liked the rest of my answer; thanks. The formulas are based on circle progressions—moving up a forth or down a fifth until you hit V and resolve to I—which have been a part of the pedagogy of harmony for centuries. IMO, it's an important first step for the OP to understand.
Answer: There is a prescription that places chords under melody in a way that produces harmonious results.  Classical western harmony theory, which in many cases covers church style choir harmonization called homophony.  Tim's answer touches upon it.  And it sounds like you read about it.  Basically you can harmonize any melody using the I, IV and V (or V7) chords since they cover the entire scale (sounds like the beginning of a bad joke about rock and roll songs but it's true in classical music too).  The basic patterns are pretty simple and tested over time to produce results.
In any key the following chords cover (or contain) the following notes:
I {1, 3, 5}
IV {4, 6, 1}
V {5, 7, 2}
V7 {5, 7, 2, 4}
There is more to the story than that.  There is a method for picking the right inversion of each chord in such a way that you do not create any discordant sounds, sudden jumps in voice etc.  This works well for creating smooth chord melodies on Jazz guitar as well.  Like I said, it's well tested and "culturally approved".  But that is only one way to look at things.
For one thing the approach is best suited for songs that are mostly diatonic (on the major scale).  Accidentals that indicate a key change are not a problem as you can use the same rules in the new key.  But get too funky and the approach may get frustrating.  It also assumes a strict rhythmic parallelism where all voices follow the same structure and merely harmonize each other.  There are certainly many other approaches to writing a supporting section to a melody.
You haven't really stated what style the song is or if it's even diatonic.  Another answer mentioned the Blues.  Here you have 3 dom7 chords none of which are in the same key, and one can play a pentatonic melody over it all and sound okay.  Not to mention, if you start using exotic modes to write melodies standard western harmony theory will probably not get you anywhere.  A lot of rock musicians start composing with a riff, i.e. the rhythm section first, then add vocals over it (melody second).  If you were inspired to write a melody first then you're following a more traditional path (I think) but it doesn't have to be that way.
Personally, I am an advocate for learning classical music theory and harmony but with the caveat that they are one of many tools in the musician's arsenal.  You can always just play around until you find something that fits and you might create something new.  On this point I disagree with one of the other the answer.  Yes, it's true that the 12 bar blues is basically the same progression for 1000's of songs, and so are the lyrical themes (my woman left me, took my money, took my booze, messed around with my friend, woe is me)... If you want to write a blues tune you can recycle 80% of what's in the template and fill in a new melody and solo, etc.  Same holds for Rhythm Changes (I --> vi (or VI7) --> ii --> V7) etc.  There are about a half dozen sets of changes that are so over used they cover a large % of the Real book (if Jazz and show tunes are your thing).  But it isn't true that there are no new progressions.  In a lot of modern music rhythm players often start with some exotic set of chords (as stated previously).
Answer: To follow is a collection of disorganized thoughts on the topic.
You can play almost any piece in the world somewhat convincingly with only the I, IV and V chords. The only real secret that I know to harmonizing melodies with chords is to use your ears and try them out. Eventually, you will start to hear the chord sound you want in advance, and you will know instinctively exactly which chord it is that will give it to you.
My piano teacher taught me to improvise (in a limited sense) with this approach. Take a tune, for me usually a hymn, and then play it.
Almost always, a song starts on its tonic (I). Sometimes, it helps to arpeggiate instead of playing block chords when you're starting out, because you can hear the individual chord tones better.
It really doesn't take that long to figure it out--and once you do, you can start trying to hear other chords, like the vi chord, or the ii chord.
Oftentimes, adding the 7th to the V chord will give the song a small "lift." Use (or even overuse) this effect.
Answer:
...any rules I have to follow?

No. But, sort of yes. If you don't think about "rules", but instead think about "norms" or "models", then yes you have something to follow. Following models is a time honored method of learning.

...find the right or suitable chords for a melody...

You must study harmony and analyze the harmony of songs you want to emulate. Study will help you learn norms and terminology. Analysis will reveal the expressive effect of chords in real music.
But don't get fixated on chord progressions or matching chords to melodies. You should also study how chords relate to musical form.
Some chord progressions are like their own mini forms. 12 bar blues, I vi IV V the do-wop progression, passamezzo antico, are some progressions you could explore. This flips the question around and fits melody to existing harmony. In terms of "rules" the chord structure is fixed while the melody is sort of "free."
Traditional music form is defined by the chords used to end phrases. 32 bar song form is a great way to understand form in the world of popular music. Jazz and show tunes like 'I got Rhythm' and 'Over the Rainbow', are 32 bar song forms, but there are many examples from 1950's and 1960's rock music too. In terms of "rules" chords and melody are very free, but the phrases are expected to end in certain ways.

...But the book didn't really expand on how to actually use these chords to write your own music.

The first level of approach - let's call it the harmonization level - might be something like: my first note is A I'll use an A major chord, my next note is B I'll use a E major chord.
The second level - the formal level is like: I end bar 8 on the V chord (ex. G7) so on bar 16 I will end on the I chord (ex. Cm.)
I suspect an explanation of song form was missing from the book.
Answer: What you're trying to do is accomplish a number of things simultaneously:

you want the movement of your melody to be interesting and appropriate to the style
you want the motion of the chords to be interesting and appropriate to the style, and possibly result in suitable cadences at particular points in the piece
you want the melody and the chord progression to fit together harmonically - sometimes with the melody note being a chord tone (providing stability), sometimes with it not being a chord tone (providing tension)
you want the melody and the chord progression to fit together rhythmically - sometimes with the two moving together to provide cohesion, sometimes with the motion of one anticipating the motion of the other to provide 'drive'.

Thinking about what musical style you're targetting is particularlaly important when it comes to choosing chords to go under a melody, as different musical genres have different 'vocabularies' of chords. For example, beginner exercises in harmony would often start by having the student choose between the major I , IV, and V chords according to the melody note - but in some genres, those would be odd chords to base a progression around.
So one exercise you could try is to start with a style in mind, and...

write a melody that sounds appropriate for a particular style
come up with what you think would be the most archetypal chord progression for that melody in that style
try changing the chords and melody a little to 'spice things up'
Answer: Chord progressions are repeated all the time in songs. Observe popular songs and see the patterns of progressions.  Take one you like and start writing a melody over it.  Don't think you will invent something new.  Think about the blues; they use a 12 bar chord progression in different keys that has been used in thousands of songs.
Chord progressions certainly don't fall under copyright either.
Answer: I use an app on my tablet. I select the key and scale and it gives me a grid of chords and their variations to choose from. From there I can select chords and it will play them so I see how different progressions sound. I use Chordbot but there are many others. Find one that suits you.
Answer: The following is based on my personal research from a long time ago, and for a theoretical explanation of why it works I recommend the book "Forward Motion" by Hal Galper.
I write training software for musicians, and at one point I worked on some code to do exactly that: given any melody, choose some chords that would go well with it. The melody could be anything, based on a common scale, or made of entirely random notes.
The system that worked best was the following. (And anyone who knows enough music theory will easily understand why it worked, even when the melody is made of random notes. Again, the book Forward Motion explains it very well too).

In every bar, some notes are most important: the notes on the down beat of beat 1 and 3 (assuming 4/4 time)
Downbeat notes on beat 2 and 4 are the second-most important notes.
Upbeat notes (8th notes on "and") are less important
Other 16th notes are the least important

Established that, my program would select chords that A) always contain notes of type (1) above (notes on beat 1 and 3), and possibly also of type (2) above (beat 2 and 4). And very optionally, also of type (3) above.
That still left plenty of alternatives to choose from. I.e. Many different chords we possible. But virtually any chords that fulfilled the above conditions would sound right. Sometimes it would sound obvious, other times it would sound a bit weird, but always "in".
To do this by hand instead of a program like mine, highlight these "pillar" notes (especially on beat 1 and 3), and simplify your melody so that it is made only of those notes. Then select chords that include those notes. Then play the whole melody on those chords. Try a few different alternatives. And enjoy the process!


endMethod never called in TaskFactory.FromAsync()

Question: I have the following Silverlight code.
Container container = new Container("http://localhost:8080/odata");
DataServiceQuery dsq = container.MyEntity;
IEnumerable result = Task<IEnumerable>.Factory.FromAsync(dsq.BeginExecute, dsq.EndExecute, null).Result;

The problem I am experiencing is that dsq.EndExecute is never called.  I watched the HTTP traffic in Fiddler and the request to http://localhost:8080/odata/MyEntity goes out and the response below is received. The Task just doesn't seem to acknowledge that a response was received.
HTTP/1.1 200 OK
Server: ASP.NET Development Server/220.127.116.11
Date: Mon, 20 May 2013 15:04:16 GMT
X-AspNet-Version: 4.0.30319
DataServiceVersion: 3.0
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Content-Type: application/atom+xml; charset=utf-8
Content-Length: 562
Connection: Close

<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="http://localhost:8080/odata/" xmlns="http://www.w3.org/2005/Atom"
    xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
    xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
    xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
  <id>http://schemas.datacontract.org/2004/07/</id>
  <title />
  <updated>2013-05-20T15:04:16Z</updated>
  <link rel="self" href="http://localhost:8080/odata/MyEntity" />
  <author>
    <name />
  </author>
</feed>

Am I doing something wrong?
Comment: Does result end up with any value?
How do you know **dsg.EndExecute** is never called?
Have you tried to wrap **dsg.EndExecute** to set a breakpoint there?
Comment: I have tried wrapping it in an anonymous function and setting a break point.  It's never hit and Result never returns at all.  It's just stuck waiting for a response that has already come.
Comment: Even if you were calling form a UI thread I would expect it to Block the UI but not to dead lock.
I expect that, if **dsg.EndExecute** isn't called the task will never complete and you never get a result, right?
Comment: If you call it the old fashioned way, will **dsg.EndExecute** be called?
If you call it synchronously, will it complete?
Answer: I got around this problem by just avoiding FromAsync() all together.  The following code works for me.
var result = Task.Factory.StartNew(() => dsq.BeginExecute(null, null))
    .ContinueWith(t => dsq.EndExecute(t.Result)).Result;

Answer: Don't call Result. You should await the result instead. In many situations, Result will deadlock a GUI application (including Silverlight).
I explain this deadlock more fully on my blog and in an MSDN article.
Comment: While this is true, I'm not concerned with blocking the UI thread at this point.  I'm just trying to get a value back.  Haven't been able to get that to work yet.
Comment: Did you read the links I posted? I'm not talking about *blocking;* I'm talking about *deadlock.*
Comment: I see. I misunderstood. I thought you were referring to blocking the UI thread.  I have a dilemma, though. The async call to my WCF service is being made within an implementation of *TResult IQueryProvider.Execute(Expression expression)* so I don't think I have the option to make this method async.  What do you recommend?
Comment: In that situation, it shouldn't cause a deadlock. The deadlock I described only happens if you block on an `async` method, which you don't have. If you remove the `Result` and put trace/breakpoint inside a `ContinueWith` instead, is it ever hit?
Comment: No, the endMethod `dsq.EndExecute()` is never called so nothing after that ever executes.  Doesn't matter if it's `.Result` or `.ContinueWith()`.
Comment: Are you using a custom proxy or doing anything weird with the channel?
Comment: I don't think so.  The only thing I can think of that's out of the ordinary is that I don't have a WCF Data Service server side.  I'm using `System.Web.Http.OData.EntitySetController` in ASP.NET Web API, but I believe this shouldn't matter as Web API now implements a fully-functional OData interface.
Comment: I haven't used OData since the old days. I recommend you copy this additional information into your question, and I'm going to withdraw this answer.
Answer: Have you tried adding async/await?
public async void foo()
{
   IEnumerable result = await Task<IEnumerable>.Factory.FromAsync(
      dsq.BeginExecute, dsq.EndExecute, null);
}


2 drive failures in zpool raid

Question: I have a question if I'm going to be able to restore this partition if I order replacement drives. zpool clear didn't seem to do anything.
<code>  zpool status Partition1
  pool: Partition1
 state: UNAVAIL
status: One or more devices are faulted in response to IO failures.
action: Make sure the affected devices are connected, then run 'zpool clear'.
   see: http://illumos.org/msg/ZFS-8000-JQ
  scan: scrub repaired 0 in 10h33m with 0 errors on Sun Jun 29 10:33:28 2014
config:

        NAME                                            STATE     READ WRITE CKSUM
        Partition1                                      UNAVAIL      0     0     0
          raidz1-0                                      UNAVAIL      0     0     0
            gptid/7880bcd3-9f15-11e2-8042-14dae968612d  ONLINE       0     0     0
            gptid/79212bbb-9f15-11e2-8042-14dae968612d  ONLINE       0     0     0
            17842932853166739482                        REMOVED      0     0     0  was /dev/gptid/79cd72d2-9f15-11e2-8042-14dae9686
12d
            5304850985652021287                         REMOVED      0     0     0  was /dev/gptid/7a75bff5-9f15-11e2-8042-14dae9686
12d
            gptid/7b2692b0-9f15-11e2-8042-14dae968612d  ONLINE       0     0     0
</code>
Guessing raidz1-0 means it is z1 raid? I won't be able to send it to a professional, so any input from you guys would be helpful.
Answer: A RAIDZ1 pool in ZFS can sustain a single disk failure. Two drives failed means that the pool is faulted/failed/unusable.
So no, you're out of luck with this pool and may want to reach out to the FreeNAS support or other ZFS experts to see what's salvageable.
Do you have any backups?
Comment: no backups I never guessed 2 drives would go at once, but did just get both drives back online. It looks like some of the data is still there as some software residing on that partition started working. Looks like all of my 3D/CAM work is still good. Hopefully they keep chugging along until I can get a replacement as from what I understand you can't upgrade from z1 to z2 without destroying the pool first.
Comment: What type of hardware is this? Have you ruled out problems with the controller or the disk backplane?
Comment: Mini ITX motherboard using onboard sata slots in a 3u rackmount case. Home built freenas. Never had an issue before with the hardware. A reboot is what fixed it.
Answer: As ewwhite said, raidz1 is like raid5, only one disk can fail without loss. But if you can get those other disks back in there and get them to work, you have a chance. That's likely not going to happen, but if you care about the data (in which case you should have had backups), you can try it. Just stick an apparently dead disk in the fridge to cool it, then use dd to image the bad disk to another good disk if it runs at all, until it fails, then repeat, etc.. Then you might be able to get the pool online with the new copy on the good disk, and you might lose a few files rather than a whole pool.
And if the bad still spin up and you can read them, but they just had too many errors for ZFS to keep them, you don't even need the fridge. Just clone them, or even just zero the bad sectors, and do the same.
Comment: Thank you for the little fridge trick. I did get lucky and got both drives back online. Thinking it is the cable connection either way I'm not going to take any chances. Got the very important stuff off, and am .7z the rest to rebuild to z1.

2 drive failures in zpool raid


Prove a Norm-Based Identity Involving Convex Combination

Question:
Let $\textbf{x},\textbf{y} \in \mathbb{R}^n$ and $\theta \in [0,1]$.
I would like to show that
$$
\theta \|\textbf{x}\|^2 + (1-\theta) \|\textbf{y}\|^2 - \| \theta \textbf{x} + (1-\theta) \textbf{y} \|^2 = \theta (1-\theta) \|\textbf{x} - \textbf{y}\|^2 .
$$

My try:
Note that, by triangle inequality, we have
$
 \| \theta \textbf{x} + (1-\theta) \textbf{y} \|^2
 \leq (\| \theta \textbf{x}  \|  + \|  (1-\theta) \textbf{y} \|)^2 = \theta^2 \|  \textbf{x}  \|^2 + 2\theta (1-\theta) \| \textbf{x}\| \| \textbf{y}\|  +   (1-\theta)^2 \| \textbf{y} \|^2.
$
This implies that
\begin{align*}
  \theta \|\textbf{x}\|^2 + (1-\theta) \|\textbf{y}\|^2 - \| \theta \textbf{x} + (1-\theta) \textbf{y} \|^2
  & \geq \theta \|\textbf{x}\|^2 + (1-\theta) \|\textbf{y}\|^2 - [\theta^2 \|  \textbf{x}  \|^2 + 2\theta (1-\theta) \| \textbf{x}\| \| \textbf{y}\|  +   (1-\theta)^2 \| \textbf{y} \|^2] \\
  & = \theta \|\textbf{x}\|^2 (1-\theta) + (1-\theta) \|\textbf{y}\|^2 \theta -  2\theta (1-\theta) \| \textbf{x}\| \| \textbf{y}\|   \\
 & =  \theta (1-\theta) [ \|\textbf{x}\|^2  +  \|\textbf{y}\|^2  -  2 \| \textbf{x}\| \| \textbf{y}\| ]   \\
  & =  \theta (1-\theta) [ \|\textbf{x}\|-  \|\textbf{y}\|]^2   \\
 \end{align*}
Then I get stuck since the reversed triangle inequality works the other way around. Any comment/suggestion is appreciated.
Comment: I presume you mean the Euclidean norm. Expand out $\| (1-\theta) \textbf{y} \|^2$ and $ \theta (1-\theta) \|\textbf{x} - \textbf{y}\|^2$ using the dot product and the dot product terms will cancel.
Comment: You should state which norms you are considering in the question.
Comment: Thanks, @Zoe Allen. But I was thinking that identity can hold for any $\ell_p$-norm, not just Euclidean 2-norm.
Answer: There is no need to use triangle inequalities here. Just recall that $\lVert x\rVert^2 = \langle x,x\rangle$, and use the bilinearity of the scalar product:
\begin{align*}
\theta \lVert x\rVert^2+(1-\theta)\lVert y\rVert^2-\langle\theta x+(1-\theta)y,\theta x+(1-\theta)y\rangle & = \theta \langle x,x\rangle+(1-\theta)\langle y,y\rangle \\
& \qquad - \theta^2\langle x,x\rangle-(1-\theta)^2\langle y,y\rangle \\
& \qquad -2\theta(1-\theta)\langle x,y\rangle \\
& = \theta(1-\theta)(\lVert x\rVert^2+\lVert y\rVert^2-2\langle x,y\rangle)\\
& = \theta(1-\theta)\lVert x-y\rVert^2.
\end{align*}
Comment: No, it does not in general. It is easy to write down a counterexample. Take e.g. $n=3$, $x=(1,2,0)$, $y=(1,1,1)$, the $\ell_3$-norm, and $\theta = 0$.
Comment: Thanks. @Gibbs. If the norm is not 2-norm but any $\ell_p$-norm, I am wondering if the identity still holds.
Comment: I see. Thanks a lot!
Answer: This is false for other $\ell_p$ norms. Try substituting in $x = e_1$ and $y = e_2$ and $\theta = \frac{1}{2}$, for example. You get a formula which you eventually simplifies to $p=2$.
Comment: I see. Many Thanks!!


Notations mentioned in answers re. trombone

Question: Would someone please explain the notations E2, F3, etc. which are used in answers on this site regarding trombone?  I'm not familiar with those.
Answer: It's Scientific Pitch Notation that is used to notate the note itself and the octave it is in.
For example E2 tells you that it is specifically the E on the first ledger line under the bass clef.


Transaction Log backup fails if no full backup exists

Question: ...at least I think so.
I recently revamped my backup routine on my development server. I created a maintenance plan for user databases that did some weekly cleanup tasks, daily full backups and transactionlog backups at key points throughout the day.
All has been working well until today, when a received an email notifying me that the lunchtime backup had failed. The log viewer didn't reveal much, other than that a certain number of DBs were backed up success fully, before ending the log entry with:
<code>[snipped] Source: ...  The package execution fa...  The step failed.
</code>
Not exactly revealing
It occurred to me that the only change to previous attempts was that I'd created a new (small and unremarkable) database this morning.
I restarted the SQL Server Agent, and tried manually re-running the (transaction log backup) step but it failed again.
However, running the full backup step (thus creating the first full backup for my new DB) worked - furthermore, re-running the transaction log backup step again also worked.
It appears that the transaction log backup struggled because of the lack of a full backup or previous transaction log backup.
Is this the expected behaviour? On the one hand, at a primitive level this sort of makes sense, but really, I'd expect it to handle such a scenario more gracefully.
If so, is there a way to automatically handle this? It won't happen that often, but I can't be relied to remember to backup the DB when I create it, especially since it's only in the early stages of development.
If not, what is the likely cause of this behaviour? Can I avoid it?
Comment: This is expected - just run a full backup after the database is created.  You can justify this by saying you're testing the full backup process.
Comment: SCM - The backup isn't a problem... it's the inconvenience. I don't like to have to remember to do things (usually because I forget), and avoiding unnecesary job 'failures' is important for the reason I gave to NYSA.
Answer: Yes, this is expected behavior.  In order for the transaction logs to be useful, there needs to be a full backup to use as a starting point for rolling forward.
Don't worry about it too much.  If you create a new database, the first day you will get that error.  The log backups for the other DBs will succeed, as you saw, but that error will just make it LOOK like the step failed when in reality only the one DB failed.  Then, that night (or whenever), it will do the full backup.  After that, the trans log backups will be successful for the new DB.  Basically, you would have one day or errors when you create a new DB until the full backup job runs.
Comment: I'll try to remember to do a backup immediately - I can imagine a scenario where I ignore a backup failure email thinking it's because of a new DB - only to find at my cost that there was a genuine problem elsewhere.
Answer: I put a flag on my list of DBS to back up that indicates that it has been backed up.  The backup script won't do Txn backups until it equals 1.  In my full backup script I set the flag to 1.  Presto, no more failures.


Cross entropy and the fitness function

Question: I'm training some neural networks using NEAT C++, and would like to use the cross-entropy error function:
$$E = -t\ln(y) -(1-t)\ln(1-y)$$
to train a network for a two-class classification problem.
NEAT C++ is a C++ library that allows one to use a special kind of neuro evolution (namely that of augmenting topologies) to train the networks. Yet to be able to use it, one needs to define a fitness function (and not an error function, such as the one above).
Question:
How can I construct a fitness function from the cross-entropy error function?
Everything below this line is wrong I guess because $E\in [0,\infty]$, and thus it's impossible to define a maximum. How should I do it then?

I was thinking about this: calculate the maximum error $E_{\text{max}}$ somehow and define the fitness, given a certain network output $y$, as:
$$f(y)=E_{\text{max}} - E(y)$$
This way the fitness will be $0$ when $E(y)=E_{\text{max}}$ and it should reach a maximum if $E(y)=0$.
Is this the right method? If so how do I calculate the maximum error $E_{\text{max}}$?
note: NEAT does not allow the use of negative fitness functions, so using $f(y)=-E(y)$ would not work. Also I would like to refrain from using arbitrary stuff such as $f(y)=10000000 - E(y)$.
Comment: if you take exponential of -E, isn't it the likelihood, thus always positive with the same rank ordering?
Comment: @Memming: how stupid of me not to think about that...
Comment: @Memming This would lead to $E=y^t(1-y)^{1-t}$. But then wouldn't that be the same as using the absolute distance as error $E = t-y$ and defining the fitness as I did above: $f(y) = E_{\text{max}} - E(y)$. Because $t$ can only be $0$ or $1$, one of $y^{1-t}$ and $y^t$ will equal $1$, and for the other one the exponent is $1$, leaving $f=y$ or $f=(1-y)$ depending on the value of $t$.
Answer: First of all: NEAT is an algorithm that is usually used for reinforcement learning. I guess it won't work very well in your case. You should rather find a good network architecture by cross-validation and train your network with stochastic gradient descent, conjugate gradient, ...
Since it is just a fitness function it usually does not matter if it has an upper bound. You almost certainly will not find a perfect solution in every classification problem. So you should think about another stop criterion than "find the maximal fitness".
However, you could take -E. Its upper bound is 0.
Comment: @alfa NEAT is genetic algorithm for evolving neural networks, see the [wiki page](http://en.wikipedia.org/wiki/Neuroevolution_of_augmenting_topologies), although it wouldn't surprise me if there was a similarly named RL algorithm which is causing the confusion.
Comment: You can find some publications about NEAT at the NEAT user page (http://www.cs.ucf.edu/~kstanley/neat.html#papers). Its original purpose was reinforcement learning and I have never seen anything about NEAT and supervised learning.
Comment: @alfa I see I was the one confused, sorry about that. So, I know next to nothing about GAs and I'm having trouble picturing how a optimization technique which doesn't explicitly work with the form of the function being optimized can be "for" reinforcement learning. Mind explaining?
Comment: I did not really understand this question. Can you rephrase it?
Comment: $-E$ wont't work because, for some reason, NEAT doesn't play well with negative fitness. Also, this is for a school project so wheter NEAT is the best choice doesn't matter very much. What would you recommend for stopping criterium?
Answer: You'll also see the function you've described referred to as the log loss in the machine learning literature. It is a loss function, you do not want to maximize it, you want to minimize it.
If you have a minimization problem, you can simply negate it to obtain a maximization problem.
Since you need non-negative values just add the minimum value of your negated objective. You can find this minimum because your data is finite, i.e. the worst you can do is get everything wrong.
edit: An alternative, still assuming your problem is binary prediction, would be to simply maximize
$$\sum\mathbf{1}\{y = t\},$$
since you generally don't need a differentiable function for genetic algorithms anyway.
Comment: Speaking from experience, it helps if fitness functions are smooth. Just minimizing the empirical risk will probably fail.

Cross entropy and the fitness function


How to make css-animation of rotation around full circle

Question: I have the element which rotate sometimes by transform: rotate(). I want to smooth transition between states by using transition: transform. The problem is that degrees in rotate() are hardcoded to be always between -360 and +360, so after one full round degree's value jumps from 359 to 0 and animation does full circle back instead of smooth small animation to the right. Is there any way to make transition works "by the shortest way"?
Update: angle calculates from camera position so I can't use unlimited degrees value right now.
Clarification: I can't change js code right now, only CSS. So only [0, 360) degrees at this moment. Demo only simulates situation I'm in.
DEMO

o = document.querySelector("#arrow");
t = document.querySelector("#text");
angle = 0;
delta = 2;
FULL_TURN = 360;

document.querySelector("html").addEventListener("mousemove", (e) => {
  if (e.buttons === 1) {
    if (e.movementX > 0) {
      angle += delta;
    }
    if (e.movementX < 0) {
      angle -= delta;
    }
    angle %= FULL_TURN;
    o.style.transform = "rotate(" + angle + "deg)";
    t.innerText = angle + "deg";
  }
})
#arrow {
  font-size: 6em;
  width: 150px;
  text-align: center;
  user-select: none;
  transform-origin: 50% 60%;
  transition: transform 0.2s linear;
}
Drag mouse left or right
0deg

↑

Answer: You can just count the "rounds" and add 360 per round to your angle:
value = angle + rounds*360;

See this working example:

o = document.querySelector("#arrow");
t = document.querySelector("#text");
angle = 0;
delta = 2;
FULL_TURN = 360;
rounds = 0;

document.querySelector("html").addEventListener("mousemove", (e)=>{
 if (e.buttons === 1) {
    if (e.movementX > 0) {
       angle += delta;
       if (angle >= 360) rounds++;
    }
    if (e.movementX < 0) {
       angle -= delta;
       if (angle <= -360) rounds--;
    }
    angle %= FULL_TURN;
    value = angle + rounds*360;
    o.style.transform = "rotate(" + value + "deg)";
    t.innerText = angle + "deg";
  }
})
#arrow {
  font-size: 10em;
  width: 150px;
  text-align: center;
  user-select: none;
  transform-origin: 50% 60%;
  transition: transform 0.2s linear;
}

body {
  padding: 10px;
}
header {
  margin-bottom: 10px;
}
Drag mouse left or right
0deg

↑

Comment: Angle calculate from camera position so I can't use unlimited degrees value right now, on the demo I just simulated it. I can't change camera code for now.
I've updated the question.
Comment: I see you really wants to help and doing your best, but the problem is that I can't change js code at this moment, only css.


FontAwesome character added via CSS only appears when logged in

Question: I'm pretty new to Drupal and CSS; I'm stumped with this issue. I have a FontAwesome camera character that I've written to appear before my caption div in Flexslider. Here's what I have:
<code>div.flex-caption:before {
    content: "\f083";
    font-family: fontawesome;
    margin-left:10px;
    padding: 10px;
}
</code>
This works fine when I'm logged in as a user to the site, but the icon doesn't appear if I'm not logged in to my Drupal site. Not sure why—any ideas? I'm using Drupal 7.31
Edit: Just to clarify, all other FontAwesome characters are working fine. It's just this particular bit of code that isn't working.
Answer: Is it possible that your CSS rule is in the CSS for your administrative theme (by default "Seven"), but not in the theme for your public (non-logged-in) users (by default "Bartik")?
If so, you need to copy this CSS fragment into the public theme too.
Comment: I should have been more clear in my question, so apologies for that—I'm only a site administrator working on the local site of a bigger organization. The main CSS and theme info is 'locked' for us and we cannot access it; but we are allowed to make local CSS changes using the Sweaver module. As far as I can tell, all of the Sweaver CSS additions have affected the public theme as you can see them regardless of whether you're logged in. Only this FontAwesome character has been a problem. Let me know if you need more clarification on that


Mensagem "Undefined index" ao acessar índice do $_POST

Question:

Adicione a nota dos seus alunos

        <form method="post" action= "index.php">

            Nome:
            <input type="text" class="form-control" name="nome">

            Nota1:
            <input type="text" class="form-control" id="nota1">

            Nota2:
            <input type="text" class="form-control" id="nota2">

            Nota3:
            <input type="text" class="form-control" id="nota3">

        </form>

        <form><button type="button" class="btn btn-lg btn-danger" data-dismiss="modal">Fechar</button>
        <input type="submit" name="addbtn" value="Adicionar" class="btn btn-lg btn-sample"></form>

     <?php
    include("config.php");
    $con = mysqli_connect("localhost","root","","alunos");
    $nome = $_POST['nome'];

    if (isset($_GET['addbtn'])) {

    $query = "INSERT INTO `aluno` (`id`, `nome`, `nota`, `nota2`, `nota3`) VALUES (NULL, $nome, '10', '20', '30')";

    mysqli_query($con, $query);
    }

    ?>

O que há de errado que não está detectando a parte  $nome = $_POST['nome'];?
Notice: Undefined index: nome in C:\xampp\htdocs\index.php on line 112
Comment: O POST só existe na hora que você envia o formulário, então você  também tem que verificar se existe o $_POST['nome']
Comment: if (isset($_GET['addbtn']) && isset($_POST['nome'])) {
Comment: Você coloca o botão submit fora do primeiro bloco  que é os que contém os campos. Tente colocar dentro dele e pode remover o segundo bloco .
Answer: Na primeira vez que você acessa a página, você está fazendo uma requisição HTTP utilizando o método GET, portanto não estarão definidas nenhuma informação na variável global $_POST. Desta forma, quando você tenta obter o valor de $_POST["nome"], ele não existe, gerando o erro. Você só pode acessar este valor se o PHP estiver tratando uma requisição HTTP com o método POST. Para fazer esta verificação, basta fazer:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    ...
}

No seu caso, ficaria algo como:
<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    include("config.php");
    $con = mysqli_connect("localhost","root","","alunos");
    $nome = $_POST['nome'];

    if (isset($_POST['addbtn'])) {
        $query = "INSERT INTO `aluno` (`id`, `nome`, `nota`, `nota2`, `nota3`) VALUES (NULL, $nome, '10', '20', '30')";
        mysqli_query($con, $query);
    }
}

?>

Perceba que eu alterei também de $_GET["addbtn"] para $_POST["addbtn"] pois seria o mais lógico para este caso. Aliás, no seu código HTML, o botão addbtn está em um formulário diferente dos campos. Não vejo isso fazer muito sentido. Acredito que você deveria deixá-lo no mesmo formulário que os campos de textos.
Comment: Teria como o POST ser sem dado. Por exemplo `curl -X POST https://site.com` (ou com outros dados, sem o `nome`). Isso continuaria disparando o `notice` no `$nome = $_POST['nome'];`, por que continuaria não existindo, apesar do método ser POST. Acredito que seria ideal um `isset($_POST['nome'])`.
Comment: Opa, muito obrigado, só um detalhe: printando a váriavel **$nome** na inserção  eu deveria usar dessa forma **'".$nome."'** , correto? Ou existe outra?
Comment: @SkullFire Utilizando aspas duplas para string o PHP consegue analisar variáveis no seu interior, não necessitando fazer a concatenação. Então algo como `"insert into ... values (null, '$nome')"` já iria funcionar também.
Comment: Por incrivel que parece não funcionou dessa forma
Comment: @SkullFire deu algum erro?
Comment: Não, só não inseriou na tabela. Usando **'".$nome."'** enviou de boa.


Vector Proof of Diagonals of a Rhombus

Question: I'm stuck on trying to provide a proof in relation to: "prove that the diagonals of a rhombus bisect the angle of the rhombus using vector methods." I'm unsure what that means, so any help would be greatly appreciated!! Thanks!
Answer: Hint:  let $\vec u, \vec v$ be the vectors originating from a vertex and drawn  along the two adjacent sides, with $\langle \vec u, \vec u\rangle=\Vert\vec u\Vert^2=\Vert\vec v\Vert^2=\langle \vec v, \vec v\rangle$ since the sides of a rhombus are all equal. Let $\alpha, \beta$ be the angles between the diagonal $\vec u + \vec v$ and $\vec u, \vec v\,$, respectively. Then:
$$
\cos \alpha = \frac{\langle \vec u, \vec u + \vec v\rangle}{\Vert\vec u\Vert\,\Vert\vec u+\vec v\Vert} = \frac{\Vert\vec u\Vert^2 + \langle\vec u, \vec v\rangle}{\Vert\vec u\Vert\,\Vert\vec u+\vec v\Vert} = \frac{\Vert\vec v\Vert^2 + \langle\vec u, \vec v\rangle}{\Vert\vec v\Vert\,\Vert\vec u+\vec v\Vert} = \frac{\langle \vec v, \vec u + \vec v\rangle}{\Vert\vec v\Vert\,\Vert\vec u+\vec v\Vert} = \cos \beta
$$
Comment: Greatly appreciated! So I use the same method when I'm proving for a different angle in the rhombus?
Comment: @W.Nguyen Right, this works no matter which vertex you choose initially.

Vector Proof of Diagonals of a Rhombus