What are state of the art methods for creating embeddings for sets?

Question: I want to create embeddings in $R^D$ for sets. So I want a function (probably a neural network) that takes in a set $ S = \{ s_1, \dots, s_n \} $ (and ideally of any size, so the number of elements might vary but anything is good) and produces vector. Ideally, the set embedding function is ordering invariant (the way sets are) so a straight LSTM isn't quite what I want (since thats for sequences), unless modified and ideally referenced in some published paper.
$$ f_{\theta}(S) = e_S \in R^D$$
what are state of the art (SOTA) methods for this task?
The silliest method I know is just embed each element seperately and then take the sum, so:
$$ f_{\theta}(S) = \sum_i g(s_i) $$
or perhaps better with some sort of attention:
$$ f_{\theta}(S) = \sum_i \alpha(S) g(s_i) $$
but ideally if something is already a paper then it's already been tested better than my random idea...
BTW, the only thing I am aware of is in this paper: https://arxiv.org/abs/1606.04080 but seems rather old (2016) and as of the writing of this question we are 2020.

Related:

Reddit: https://www.reddit.com/r/deeplearning/comments/fi4f77/what_are_state_of_the_art_methods_for_creating/
Quora: https://www.quora.com/How-does-one-embed-sets-in-machine-learning
Answer: Indeed, in the last to-three years there have been some important publications on this topic. I do not know all of them, and cannot give a complete survey of the current status. One important paper though is Deep Sets, which presented a canonical architecture for dealing with such problems.
The main problem is to find an architecture that is able to deal with an input sequence of variable length, whose ordering is irrelevant, and the output of the network should be invariant to permutations of it.
It is shown that one can achieve this with a set function of the form
$$
f(\mathcal{X}) = \rho\left( \sum_{x \in \mathcal{X}} \phi(x) \right)
$$
The idea is that we embed each set element with feature mapping $\phi$, and aggregate the embeddings into an invariant, fixed-size description. In this case, it is a sum, but it could be any other permutation invariant operation (at least in general). Then a final function $\rho$ processes the aggregate.
This is represented in the following figure
Comment: Thanks a lot, that's helpful to me.  But the reasoning in that paper seems to have a problem.  First, in the continuum-case it made the restriction that the # of elements is fixed and finite.  This is an acceptable restriction.  Then it proves that any invariant function must be of the form of the formula you cited.  But in practice, when the theorem is applied, $\rho$ would be FIXED and then there'd be no guarantee that such a family of functions is dense in the function space desired.  In other words, once $\rho$ is fixed then there may be some invariant functions that can't be approximated.
Comment: do you know how that compares to transformers (without positional encodings)? seems they have tried it! https://arxiv.org/abs/1810.00825


What are some uses of logistic regression at scale?

Question: Many libraries that scale linear and logistic regression assume a tall-skinny design matrix (many samples, few features), but I don't understand why you would need billions of samples if your data has 250 features.
In what scenarios would more data help? It seems like, instead of using more computational resources, you could simply sub-sample the data and achieve comparable accuracy in scenarios where the feature count is relatively small.
When feature count is high, say 100k, would having samples on the order of billions help? How do we decide how many samples are needed for a given modeling problem?
Perhaps more data helps with imbalanced data? e.g. when performing binary logistic regression for outlier detection, where the occurrence of positive samples is very small.
Any help here would be greatly appreciated.
Comment: "250 features" really means only 250 features *given to you.*  As soon as you consider nonlinear relations and interactions in your modeling, the number of potential features to include explodes.  That design matrix might not look so skinny after all ;-).
Comment: Maybe it really matters if you can predict a probability of $0.5001$ instead of $0.5000$. To get that kind of resolution, you might need a lot of samples.
Comment: do you have a specific paper/model at mind? They usually include motivation for their research. Also, scale means different things for different people, you have papers that deal with situations with billions of samples for 250 features, but also for 100k features.
Comment: Can you give examples of libraries, the classic example I know of is vowpal Wabbit that scales for large number of features ( basically sparse features from one hot encoding) and large number of samples ( to handle the disjoint sets of one hot encoding)  eg estimating the click through rate of Amazons product catalog
Answer: Facebook's revenue in 2020 was 86 billion dollars, mostly by selling ads. So if your large scale logistic regression model can improve the click-through rate by 0.01%, you would make facebook 8.6 million dollars per year (86000000000*0.0001), which is enough money to justify spending a couple of millions on some grad students or engineers to work on that.
I don't know if there is a use case for fitting 250 PARAMETERS on billions of samples. But fitting tens of thousands of parameters is quite common. A paper might showcase a method on the 250 parameter toy problem, but my guess would be the real motivation is to fit bigger models. Also, these papers usually don't just fit your vanilla logistic regression, but some kind of regularized generalized linear model and a lot of things can be expressed as regularized logistic regression or GLM.
Even without being Facebook, you can find a problem that could be expressed as a model with billions of samples and hundreds of thousands of parameters. A lot of things can explode really quickly if you allow them to. For example, on a map, each point in a grid is a separate observation that, of course, needs to be modeled to take spatial relationships into account. Nevertheless, all of a sudden, you might have millions of "data points." You might have a time series, where of course, each measurement is a separate data point, and if you measure every millisecond, or if you measure for a long time, all of a sudden, you have millions or billions of data points.  If you measure how something spatial changes across time, possibly with respect to some variables, e.g., fMRI signal in a brain, EEG signal on a scalp, smog in a city, global temperature, algae on a lake... you can easily get a problem of a scale you were talking about.
These problems might not always be looked at as large-scale logistic regression problems, but if there was a technology to efficiently fit those models, use cases would come by themselves.
tl;dr: time series, maps, and images. Could you just downsample it? Yes, but you wouldn't need to.
Answer: Your general premise is correct: you don't need more data than you need. But also, as noticed in the other answer and comments, it may be more tricky than you're assuming. First of all you need large enough, high-quality sample of data. Using more data than is needed for the desired precision would be wasteful. On another hand, logistic regression is a pretty fast and cheap model to train, at least as compared with many other machine learning models, so you wouldn't usually care that much. You want the libraries to be scalable for cases where it's needed, but this doesn't mean that you always need to push as much data as you can to the algorithm.


Are grace note pairs and a mordent played differently?

Question:
When I play the mordent and the graces notes highlighted, they sound the same. Should they be approached differently? Why would they be notated differently?
Comment: @lazy, it's a Chopin waltz
Comment: What period of style are we talking about here?
Comment: Waltz in A minor.
Answer: The difference is timing. The grace notes happen before the primary note; the mordent happens after (or rather during) it.
You can play it with more freedom than this, but here's a rough way to think of it, quantizing the graces to fit into a sixteenth-note's duration:

There should also be implications about emphasis, besides simple timing. For both ornaments, the actual beat should be the strongest note, and the graces should be de-emphasized. Resist the urge, for example, to blurt out the latter grace notes just because they appear to start a measure; instead lean into the the true downbeat.
Comment: OP's example is Chopin, where this is good advice. For Bach, though, the grace notes should start on the beat.
Comment: I think you've got the order wrong for the prall trill, i.e. the first two notes should be fast.
Comment: @Peter Also in Bach style the prall trill would be executed as a full trillo.
Comment: @Lazy Good point, that's probably true. Though probably "three equal triplet-style notes" is also an option?


startup class and main method for SkyLine

Question: i need sample main method (for startup) with fake Data for this code (Skyline divide and conquer)
link : https://github.com/mouhyi/Algorithms/blame/master/SkyLine.java
Example code:
public static class runClass {
        public static void main(String[] args)
        {
            Building[] arr = {{1, 11, 5}, {2, 6, 7}, {3, 13, 9},
                    {12, 7, 16}, {14, 3, 25}, {19, 18, 22},
                    {23, 13, 29}, {24, 4, 28}};
        }

    }

Answer: The algorithm requires an array of Building objects, not a 2-d array of integers. The Building class is defined inside the SkyLine class, so this is how you need to define your data.
public static void main(String[] args) {
    SkyLine.Building[] arr = new Building[] {
        new SkyLine.Building(1, 11, 5),
        new SkyLine.Building(2, 6, 7),
        new SkyLine.Building(3, 13, 9),
        new SkyLine.Building(12, 7, 16),
        new SkyLine.Building(14, 3, 25),
        new SkyLine.Building(19, 18, 22),
        new SkyLine.Building(23, 13, 29),
        new SkyLine.Building(24, 4, 28)
    };
}


Irreducibility of an integer polynomial with exponents in linear sequence?

Question:
Let $b$ and $n$ be two positive integers. Is there are a general result which tell us when the polynomial $$1+x^{b}+x^{2b}+x^{3b}+\cdots+x^{nb}$$
  is irreducible over the integers?

I know that $$1+x+\cdots+x^{n-1}$$
is irreducible if and only if $n$ is prime. I also know that $$1+x^n$$ is irreducible if and only if $n=2^k$ for some $k\geq 0$. However, I'd like to look at a linear sequence and know irreducibility before painstakingly looking for factors.
I've noticed that the $n$ above in the question must be even for otherwise we could factor out $1+x^b$. But other than that I haven't made much ground except for particular values of $n$. I'm kind of hoping for a 'one-fell-swoop' result, but if there isn't, I'd like a recommendation for a general plan of approach for determining irreducibility of these polynomials.
Any help is appreciated.
Answer: As pointed out by Bruno Joyal, your polynomial is
$$
f_{b,n}(x)=\frac{1-x^{b(n+1)}}{1-x^b}.
$$
Therefore all the primitive roots of unity of order $b(n+1)$ are zeros of $f_{b,n}(x)$. The minimal polynomial of those roots of unity is the cyclotomic polynomial $\Phi_{b(n+1)}(x)$.
Hence the cyclotomic polynomial is always a factor of $f_{b,n}(x)$. As the cyclotomic polynomials are all irreducible, $f_{b,n}$ is irreducible if and only if it is equal to $\Phi_{b(n+1)}(x)$. On the other hand
$$
\deg\Phi_{b(n+1)}(x)=\phi(b(n+1)).
$$
So a necessary and sufficient condition for the irreducibility of $f_{b,n}(x)$ is that $\phi(b(n+1))=bn$.
But if $n+1$ is not a prime number, then $\phi(n+1)<n$. This implies that there are more than $b$ numbers in the range $1\ldots b(n+1)$ that have a non-trivial common factor with $n+1$, namely those with a remainder modulo $n+1$ that has a common factor with $n+1$. So in that case $\phi(b(n+1))<bn$.
Hence $n+1$ must be a prime number $p$. Now, if $b$ has a prime factor $q$, $q\neq p$, then
$$\phi(bp)\le bp(1-\frac1q)(1-\frac1p)=bn(1-\frac1q)<bn.$$ On the other hand, if $b=p^k$, then $b(n+1)=p^{k+1}$. In that case $$\phi(b(n+1))=\phi(p^{k+1})=(p-1)p^k=nb.$$ Therefore we have proven

Answer. The polynomial $f_{b,n}(x)$ is irreducible in $\Bbb{Z}[x]$ if and only if $n+1$ is a prime number $p$, and $b=p^k, k\ge0$.
Comment: A nice solution Jyrki! +1


Php date add one day from database information

Question: I have this line of code:
<?= date('F dS, Y',$user_info['date_of_birth']) ?>

It gets the unix birtday date per user and converts it in a normal date.
The only problem is that it will show one day earlier.
For example, the unix date in the database is 11th may 1990.
In the view it will output, 10th may 1990.
Do you know how to fix this issue?
Thanks in advance
Comment: I'd look at timezone issues.
Comment: That's maybe the problem. Do you know how I can just add + one day to the line of code above?
Comment: Don't do that. Fix the issue so your timezones match up.
Comment: Oke but just to know? Do you know how to do it?
Answer: To explicitly answer your question, you can do the following:
<?=date('F dS, Y',($user_info['date_of_birth'] + 86400))?>

Where 86400 is the number of seconds in a day.

However, as others suggested, you can and should sync up the database and Php to UTC/GMT time.
For Php timezone, do the following at top of your scripts:
date_default_timezone_set('UTC');

For SQL, that depends on the database you're using (I don't believe you specified the database you're using).
Comment: Thank that works perfect. And I will look at the timezones now!
Answer: Check into synchronizing your MySQL and PHP timezones.  Check out this similar question/answer:
Set timezone in PHP and MySQL
Comment: Thanks! for the info:) But do you know how to add +1 day in the line of code above?
Comment: Try something like this: date('F dS, Y', strtotime($user_info['date_of_birth'] . ' +1 day')) .
Comment: I do agree with chris, you should probably just take the steps to align timezones so you don't run into similar issues elsewhere in the application.
Comment: When I tried your code I got an output of   December 31st, 1969 and it suppose to be 11th may 1993
Answer: It is probably time on you server is wrong. Is you have accesse to it shell you can check it by date command:
[centos@application ~]$ date
Tue Jul  5 04:17:00 UTC 2016

if not then you probably will have to do like this :
define('TIMEZONE_OFFSET', 86400);
<?=date('F dS, Y',($user_info['date_of_birth'] + TIMEZONE_OFFSET))?>

Again if you have access to mysql console check its timezone settings.
set-timezone-in-php-and-mysql
Also set manually php defaulte timezone:
date_default_timezone_set('UTC');


arrumar diretório

Question: Gostaria de saber como adicionar o nome do usuario onde esta em aspas escrito "devo colocar o nome do usuário aqui"
#include "stdafx.h"
#include<iostream>
#include<Windows.h>
#include<lmcons.h>

using namespace std;

int main() {
//User Name
TCHAR username[UNLEN + 1];
DWORD username_len = UNLEN + 1;

GetUserName((TCHAR*)username, &username_len);

wcout << username << endl;

//Computer name
TCHAR compname[UNCLEN + 1];
DWORD compname_len = UNCLEN + 1;

GetComputerName((TCHAR*)compname, &compname_len);

wcout << compname << endl;

cin.get();

system("reg add HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /t REG_SZ /v formula /d C://users//"DEVO COLOCAR O NOME DO USUARIO AQUI"//downloads//formula.exe");

return EXIT_SUCCESS;

}

Answer: Existem algumas formas de fazer o que pretende. De entre as várias mostro duas.
sprintf
Com sprintf consegue interpolar uma string com quaisquer valores que queira. Precisa primeiro de construir a string em forma de char[] que irá levar o texto final e de seguida chamar sprintf sobre ela:
char username[] = "carlos";
char cmd[200];
sprintf(cmd, "reg add HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /t REG_SZ /v formula /d C://users//%s//downloads//formula.exe", username);

system(cmd);

Olhe atentamente para o texto utilizado no sprintf que tem %s no local onde é colocado o nome.
Veja este exemplo no Ideone
Concatenação de string
Utilizando o operador + sobre uma string de c++ consegue concatenar um char[] diretamente, tornando todo o processo fácil também:
char username[] = "carlos";
string cmd = "reg add HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /t REG_SZ /v formula /d C://users//";
cmd += username;
cmd += "//downloads//formula.exe";

system(cmd.c_str());

Veja também este exemplo no Ideone
Esta versão tem algumas diferenças a salientar. O comando é construido como string e não char[]. Por este motivo a chamada ao system que é suposto passar o char* tem de ser com cmd.c_str() para obter a string em formato char[].

arrumar diretório


Telerik RadOpen Command Reloads Parent Window and Scrolls

Question: I am creating a modal popup window using the Telerik RadOpen function on an Asp.Net webpage.  The popup window appears correctly, but the parent window refreshes and scrolls the popup down the page.  How do I create the popup without scrolling the parent window.
The code I am using to create the popup is:
btnEdit.OnClientClick = _
     "radopen('newDialog.aspx?id=" + _id.ToString() + _
     "&_newid=" + _newId.ToString() + "', 'newDialog'); return false;"

I have already tried adding
<%@ Page MaintainScrollPositionOnPostback="true" %>

but this did not fix the problem.
Answer: Do you have a handler to some of the RadWindow's event? For example the OnClientShow? It may be invoking an AJAX request or changing the scrolling position. Other than that your code should work properly (and it does on my end) as it prevents the postback from the button. You can also try adding the attribute to the HTML click event:
  btnEdit.Attributes.Add("onclick", _
 "radopen('newDialog.aspx?id=" + "id" + _
 "&_newid=" + "newId" + "', 'newDialog'); return false;")

Also confirm you have a RadWindowManager on the page as otherwise you would get a JavaScript error and there would be a postback. Then in the code-behind you could be creating a RadWindow that is actually shown.


Knights and knaves: Who are B and C? (task 26 from "What Is the Name of This Book?")

Question: I have the following issue #26 from What Is the Name of This Book? of R. Smullyan:

There is a wide variety of puzzles
  about an island in which  certain
  inhabitants called "knights" always
  tell the truth,  and others called
  "knaves" always lie. It is assumed
  that  every inhabitant of the island
  is either a knight or a knave. I shall
  start with a well-known puzzle of this
  type and then  follow it with a
  variety of puzzles of my own.
According to this old problem, three
  of the inhabitants — A, B, and C —
  were standing together in a garden. A
  stranger passed by and asked A, "Are
  you a knight or a knave?" A  answered,
  but rather indistinctly, so the
  stranger could not make out what he
  said. The stranger than asked B, "What
  did A say?" B replied, "A said that he
  is a knave." At this point the third
  man, C, said, "Don't believe B; he is
  lying!" The question is, what are B
  and C?

I supposed that truth tables can be used, and composed the following:
<code>   |   |   |      F1      |   F2   |    G
===|===|===|==============|========|=========
 A | B | C | B ↔ (A ↔ ¬A) | C ↔ ¬B | F1 ^ F2
===|===|===|==============|========|=========
 1 | 1 | 1 |      0       |   0    |    0
 1 | 1 | 0 |      0       |   1    |    0
 1 | 0 | 1 |      1       |   1    |    1
 1 | 0 | 0 |      1       |   0    |    0
 0 | 1 | 1 |      0       |   0    |    0
 0 | 1 | 0 |      0       |   1    |    0
 0 | 0 | 1 |      1       |   1    |    1
 0 | 0 | 0 |      1       |   0    |    0
</code>
Provided that:

We use $A$, when A is a knight, and
$\neg A$, when A is a knave.
$F1$ is what B said ($A \leftrightarrow \neg A$),
i. e. B said that A said he's knave.
Therefore, B is telling the truth if
and only if he's a knight ($B$).
$F2$ means that C is a knight if and
only if he's telling the truth, i. e.
B is a knave ($\neg B$).
$G$ allows us to select only those
claims amongst $F1$ and $F2$
which are true.

can I safely say that we have only two cases, when $G$ is true and the following conclusions can be made:

B is a knave, because there are $0$s (false) in the appropriate rows.
C is a knight, because B is telling lies, and there are $1$s (true) in the appropriate rows.
We cannot say what is A exactly, because we couldn't make out what he said, and there are two cases in the table with $0$ and $1$ in the appropriate rows, where $G$ is true.

Please tell me if my calculations and the truth table are right, not only the conclusion. The best answer is one, which either explains what I'm missing in my truth table, or contains a correct one instead of mine, being supposedly wrong. I'm trying to figure out how they can be used, and I guess this issue is quite simple to play with, after all you have the same reasoning in your mind.
Thanks in advance.
Comment: Your calculation of F1 is wrong, and I also think you don't need it (why assume that there must be a knight?). Besides, you can reason that B must be lying (since A must have said he's a knight), and so C must be telling the truth.
Answer: A truth table is really the wrong tool for this; and your table contains errors. For example, you assert that A v B v C is always true, even in the case when A, B, and C are all false! Truth tables (when correctly filled out) are useful in some situations, but the proper approach to this problem is to take a more direct deductive route.
First, we adopt the rule that knights always speak true statements, and knaves never do, and everyone is either a knight or a knave (and not both, unless they never speak!).
Under these assumptions, no one can say "I am a knave": a knight cannot say it, because it would not be a true statement; and a knave cannot say it because it would be a true statement.
Therefore, when B states "A said 'I am a knave'", then it is immediately the case that B is stating a falsehood, and thus we have proven that B is a knave.
Since C states a truth (i.e., that B has stated a falsehood), C cannot be a knave; therefore we have proven C is a knight.
That is much simpler and clearer than a logic table... in my humble opinion!
Comment: The book has explanation similar to yours. I'd like to know how the truth table should look like though, so that I know what I'm missing besides $F1$ is not needed as @Yuval and you already mentioned.
Comment: I edited to indicate that your calculation of F1 is incorrect. It's still, in my opinion, not a particularly fruitful way to approach this problem.
Answer: To learn about how to use truth tables, and formal logic in general, to solve Smullyan's puzzles on Knights and Knaves you can read Smullyan's own "Logical Labyrinths" esp. chapter 8: Liars, Truth-tellers and propositional logic.  (Publisher's link; Google Books link; Amazon link.)
If I am not mistaken, I think he also explains a bit about this stuff in "Forever undecided".
Answer: The problem is this:
We have three inhabitants A, B and C.
B said "A said "A is a knave"", and C said "B is a knave".
So the information we have is (if you read the first paragraph of the chapter I referred to in my previous answer and carefully follow the instructions):
$k_B \leftrightarrow (k_A \leftrightarrow \neg k_A)$
$k_C \leftrightarrow \neg k_B$
Your truth table for both formulas (as it is now written) is correct, you simply used A instead of $k_A$, but that's all. To know which are the possible situations under the givens, you just look for the rows that give simultaneously a value 1 for both formulas. These are the two rows with a 1 in the last column of your table.
What the table is telling you, then, is that there are only two possible situations. In both of them B is a knave and C is a knight. So that's true no matter the situation. Instead, you cannot tell what A is because A can either be a knight or a knave.
Comment: Actually, I think we are only given $k_B \boxed\rightarrow (k_A \leftrightarrow \neg k_A)$, but logically that is of course equivalent.
Answer: I agree with Chas Brown that the truth table is more work-intensive than required, but it can be used.  What you need to do is (correctly) calculate the truth value of the statements for each possibility of knight/knave assignment.  Then see if the truth value corresponds to the type for each person.  This is a poor selection of a problem to demonstrate the method.
But we will try.  The first column would be A's statement, which as Chas points out, is "I am a knight" regardless of his status.  The second column would be the truth value of B's statement, which as Chas says is always false.  The third column would be the truth value of C's statement, which is always true.  Then the fourth column would be whether the truth value in the second column corresponds to B's type.  This is correct if B is a knave.  Similarly the fifth column would be whether the truth value in the third column corresponds to C's type, which is true if C is a knight.  The sixth column would be the and of the fourth and fifth.  Lines where the sixth column shows true are possible assignments.
Answer: Your table is incorrect in the F1 column in that $A \vee B \vee C$ should evaluate to 0 when all three are  0 (the bottom line).  Otherwise your calculations are OK.  Edit:  this column has been removed.
The definition of F1 is not what you want.  F1 is supposed to represent whether A spoke the truth, so should just be A.  Edit:  as this column has been removed, this does not apply.
Edit:  this is incorrect as I misread the table.  See the paragraph below.  The definition of G is the biggest error.  G should be $(A \leftrightarrow F1) \wedge (B \leftrightarrow F2) \wedge (C \leftrightarrow F3)$.  This is the heart of the matter.  You want A to have spoken the truth if and only if A is a knight, and the same for B and C.  G should always be of this form (maybe more terms if you have more individuals involved) and will pick out the lines where the truth value of the statements matches the type of the individuals.
Added:  G is correct.  Your F1 says "B spoke properly for his type" and F2 says "C spoke properly for his type".  So you want to find the cases both spoke properly.  The fact that the 1's appear opposite B=0, C=1 both times says that B is a knave and C is a knight.
Comment: I suspect all are clear that we don't know what A said, we only know what he could've said and what couldn't. Because if he would have said something like *"I have bananas in my ears"*, we wouldn't even consider his claims, or even would be unable to answer what B and C are.
Comment: That is true, but we know the truth value of what he said matches his type.  This is why I said F1 should be A.  If you follow it through, this is not contributing to the solution at all, because we don't know what A is at the end.  I was trying to stay in the spirit of your table.  The heart of the other arguments that B is a knave comes out in your table under F2 when you say $B \leftrightarrow (A \leftrightarrow \neg A)$. As $(A \leftrightarrow \neg A)$ is always false, this requires B to be false.
Comment: A could have said a lot of things.  The one thing he cannot have said is "I am a knave", which marks B as a liar.  If B claimed A said "I have bananas in my ears", even observing no bananas in A's ears would only tell us that (at least) one is a liar.
Comment: I just got rid of $F1$ in the question, it has actually been put there because of one of the next issues after #26 (this one) stating that there would be at least one knight amongst inhabitants. Nothing seems to confuse me any more.
Comment: @Yasir Arsanukaev:  Looking at your table again, I see that you put the equivalence I said you should have in G into the F1 and F2 columns.  So F1 represents "B spoke in conformance with his type", not "B told the truth".  In that case your G is correct.  I will edit my response.
Answer: Here is a solution that does not use truth tables, but instead we calculate the solution.
Let's write $\;T(x)\;$ for "$\;x\;$ is a knight", so that $\;\lnot T(x)\;$ stands for "$\;x\;$ is a knave": I chose $\;T\;$ as a mnemonic for 'always speaks the Truth'.
The 'axiom' underlying many of these puzzles is:
\begin{align}
\newcommand{\says}[2]{#1\text{ says }\unicode{x201C}#2\unicode{x201D}}(0) \;\;\; & \says{x}{\phi} \;\Rightarrow\; (T(x) \;\equiv\; \phi) \\
\newcommand{\cansay}[2]{#1\text{ can say }\unicode{x201C}#2\unicode{x201D}}
\end{align}
Formalizing the story, you are given that
\begin{align}
(1) \;\;\; & \says{B}{\says{A}{\lnot T(A)}} \\
(2) \;\;\; & \says{C}{\lnot T(B)} \\
\end{align}
From $(1)$ we can derive
\begin{align}
& \says{B}{\says{A}{\lnot T(A)}} \\
\Rightarrow & \;\;\;\;\;\text{"by $(0)$"} \\
& T(B) \;\equiv\; \says{A}{\lnot T(A)} \\
\Rightarrow & \;\;\;\;\;\text{"weaken -- otherwise we cannot apply $(0)$ again"} \\
& T(B) \;\Rightarrow\; \says{A}{\lnot T(A)} \\
\Rightarrow & \;\;\;\;\;\text{"by $(0)$ and transitivity"} \\
& T(B) \;\Rightarrow\; (T(A) \;\equiv\; \lnot T(A)) \\
\equiv & \;\;\;\;\;\text{"logic: simplify"} \\
(1') \;\;\; \phantom{\equiv} & \lnot T(B) \\
\end{align}
In other words, $\;B\;$ is a knave.
From $(2)$ we can now derive
\begin{align}
& \says{C}{\lnot T(B)} \\
\Rightarrow & \;\;\;\;\;\text{"by $(0)$"} \\
& T(C) \;\equiv\; \lnot T(B) \\
\equiv & \;\;\;\;\;\text{"by $(1')$; simplify"} \\
(2') \;\;\; \phantom{\equiv} & T(C) \\
\end{align}
In other words, $\;C\;$ is a knight.


highstock charts - button for date range

Question: in my application I use angular Highstock for charts. I have a lot of data (many millions), and now i want to put the existing buttons for set date range (1week, 1 month, 3 months, 1year, all), but also to click on any button to send a new request to the server to not accumulating data. Example, if pressed button "one week", that only the server retrieves the data for one week, if you click on a button to one month, to take data for a single month. I do not want to call unnecessary data, and that the server slows down, if I'm looking for data for one month, and the server comes back to me all data. Here is the code. Thanks in advance
<code>> https://jsfiddle.net/tf7pr1ft/
</code>
Comment: Have you already look into lazy loading Highcharts example? http://www.highcharts.com/news/48-loading-millions-of-points-in-highcharts
Comment: Hm...  Nice..   I never see this example.  Thnx i will try
Answer: Thnx to @Grzegorz Blachliński i fix this. here is code
<code> $scope.chartConfig1 = {

            xAxis: {
                ordinal: false,
                //za dodat date range postavit events i range selectors
                events : {
                afterSetExtremes: getDateRange //here i add my custom function
            }

            },
            yAxis: {
                plotLines: [{
                        color: '#FF0000',
                        width: 1,
                        value: 11.50,
                        label: {text: '11.50'}
                    }]

            },
            options: {
                chart: {
                    zoomType: 'x',
                    backgroundColor: 'rgba(255, 255, 255, 1)',
                    polar: true,
                    type: 'line',
                    borderRadius: 5

                },
                legend: {
                    enabled: true
                },
                rangeSelector: {
            selected : 0, //here i defined default range
             enabled: true,
                    inputStyle: {
            color: 'black'
        }
                },
                navigator: {
                    enabled: true
                }
            },
            series: [],
            title: {
                text: 'Solar and Battery voltage average'
            },
            useHighStocks: true
        },
        $scope.chartConfig1.series.push({
            id: 1,
            name: "Solar voltage average",
            data: $scope.data[0],
            tooltip: {
                valueDecimals: 2
            }
        },   {
            id: 2,
            name: "Battery voltage average",
            data: $scope.data[1],
            tooltip: {
                valueDecimals: 2
            }
        }
        );
</code>
and here is my custom function
<code>getDateRange = function (e) {
                        var date1 = new Date(e.min);
                        var date2 = new Date(e.max);
                        var timeDiff = Math.abs(date2.getTime() - date1.getTime());
                        var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

                      $http.get(serviceBase + 'aaaaa/aaaaaa/' + $stateParams.klupaID + '/aaaaaaa?days=' + diffDays, function(data){
                  //ukoliko buden dodavat još koji config obavezno dodat broj koliko ih ima na i<=8
                  for (i=1; i<=8; i++){
                      $scope.chartConfigString = 'chartConfig' + i;
                     $scope.chartConfigString.series[0].setData(data);
                  $scope.chartConfigString.hideLoading();

                  }
                });
           };
</code>
Now i have another problems, i want to have four selectors (buttons), 1months, 3months, 1year and ALL. I set default range, when open app, on 1month, and here is problem. Buttons for another range is disabled, beacause i get data from url only for one month. I want to have enabled all buttons for select any range. Thnx


Multer file upload not working multipart/form-data image

Question: I am using nuxt.js. I used a package vue-picture-input and am using this tutorial to upload the image file. To upload it to the server using axios on my api:
export default function (url, file, name = 'avatar') {
  if (typeof url !== 'string') {
    throw new TypeError(`Expected a string, got ${typeof url}`);
  }

  // You can add checks to ensure the url is valid, if you wish

  let formData = new FormData();
  formData.append(name, file);
  const config = {
    headers: {
      'content-type': 'multipart/form-data'
    }
  };

  return axios.post(url, formData, config);
};

I double checked before sending, the formData indeed has the image. This request then goes to the backend and received by the following code:
const storage = multer.diskStorage({
    destination: 'some-destination',
    filename: function (req, file, callback) {
        crypto.pseudoRandomBytes(16, function(err, raw) {
            if (err) return callback(err);

            callback(null, raw.toString('hex') + path.extname(file.originalname));
        });
    }
});

var upload = multer({ storage : storage})

router.post('/upload/add', upload.single('avatar'), (req, res) => {
    if (!req.file) {
        console.log("No file received");
        return res.send({
          success: false
        });

    } else {
        console.log('file received');
        return res.send({
          success: true
        })
    }

    // Everything went fine
})

I know I am doing this in a weird way - using formData instead of actually submitting an html form..but in my scenario its better. Whenever I run this code, the response is always success: false.
Does that mean it can't find the formData image? I would really appreciate it if you could help me debug this. Cheers.
Answer: While researching a similar problem I came across this post. I have this working in a similar way. It might help to remove the content-type header, it is set by axios/formdata automatically for me. It should include a boundary generated by formdata like this.
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary5g0xJihuBbfw8DEp


How to compose better chromatic harmony

Question: I've been composing for a couple of years and I have a pretty good understanding of how to choose chords for melody in a diatonic context. However, when I try to introduce some quirky elements to my own music, it always seems to fail a bit.
Attached is an example with the score. My goal was to make a simple 8-bar exercise, where I harmonize my melody with diatonic triads, but I wanted to add some unexpected spice in a couple of bars, just for fun. I adjusted some of the melody notes to be out of key, and then I tried to harmonize it by using chromatic harmony. For example, in bar 4, I go from E♭ major chord to a G major chord, and I chose G major just because coming from E♭, I could keep the G as a common tone.
The problem is that I would like to know better what I am doing when re-harmonizing. When I listen to the excerpt, I'm not sure if the chromatic stuff works here, it's maybe a bit too random. I'm quite new to this stuff, and I would like to expand my harmonic language so that I wouldn't have to rely just on diatonic chords or secondary dominants.
Or is the problem that I try to introduce too spicy elements to a piece that is otherwise very vanilla, in other words, the contrast is way too sudden and harsh? How exactly does one introduce chromatic harmony to a diatonic piece so that it doesn't sound too weird?
https://musescore.com/user/36873917/scores/6508576
Comment: listen to other composers like Bernstein (e.g. Westside Story (Sgt. Kruppke), Prokofiev, (Peter and the Wulf - the Cat theme), Shostakovich (Symph. 7), or start with Bruckner Symph. 7
Comment: Diatonic music uses many common patterns, where sequences of chords are associated with other musical ideas (eg tension, rhythmic stress, cadence, modulation, prolongation). These are so common and standard that we say these chords have function, in the sense of functional harmony. Chromatic harmony has its own patterns, endemic to whichever style of music you're interested in, and the best way to learn them is to listen to and analyze music that uses them. Developing an ear for these patterns. along with knowing general counterpoint and voice leading will be valuable for writing it yourself.
Answer: I am not sure about being "quirky".  At the end of the day you have to like what you've done and since music is an art form no one can say it's "wrong".
However, there are some classic patterns in western music that serve a purpose or function and this determines how chords follow each other in succession.  I am not sure where you learned harmony theory, if you are self taught, by example, or from a book.  But the first thing to know is how the I, IV, and V or V7, lay over the major scale.  These are really the only three chords you need to harmonize a melody in a given key (major key as a reference).
I --> (1, 3, 5)
IV --> (4, 6, 1)
V7 --> (5, 7, 2, 4)
No surprise that the arpeggios of the chords are the notes they harmonize (most of the time).  There is no law that says you can't harmonize the 2 with a IV chord, in fact this would be a IV6 and sound cool.  But the classic approach to beginner harmony is to start with the above map.
Now it helps to understand the movement of the intervals from one note to another as that serves a purpose.  It is often said in western music that the movement from IV-->I and V-->I have a sense of closure of finality.  These are called cadences, or resolutions (I may be using vocabulary incorrectly).  The V7-->I has the strongest sense of finality from among all possible changes.  The IV-->I is often called the Amen cadence and appears a lot in church music.  All of these changes have a few things in common among which are chromaticism, 4-->3 and/or 7-->8 in terms of scale degrees of the key signature.  In fact the V7-->I has both of these.  The IV--> only has 4-->3.  To make the IV-->I cadence stronger some people move to the minor IV chord IV-->iv-->I.  This introduces a chromatic walk down from 6-->b6-->5 in terms of key scale degrees.
This is not the only feature of a cadence but it is one that is very often and easily capitalized on.  So, rather than just add "quirky" things, I'd encourage you to think about ways to introduce meaningful chord movement that follows either IV-->I or V-->I.
There are a few things you can do to "add" to your harmonies.
The first is to introduce what I'd call a cycle extension (or back cycle) in the progression, a very common trick.  As as example let's say you are going to move from I to IV.  Try putting the I7 right before the IV chord.  This is a V7-->I cadence in the key of the 4th, and introduces an accidental relative to the original key, namely the b7.  You can do this to your heart's desire and many scores are filled with such extensions.  For example, C-->E7-->Amin-->C7-->F-->G7-->C, which is really just C-->Amin-->F-->G7 with the V7 placed strategically before the Amin and F chords.
Another way to spice up your chord progressions is through chord substitutions.  This is very common in Jazz but applies to all forms of music.  The idea starts with understanding how chords are related to each other.  For example any Major chord, and its relative minor are so compatible they can be interchanged.  Specifically, the chords I6 and vi-7 are identical.  Next is any Major chord and the min a 3rd above it.  These two add to create a Maj7, example I + iii = IMaj7.  So the group of chords (I, iii, vi) can, in theory be thought of as serving the same function.  More intricate substitutions include the b5 (or tritone) sub, which is most commonly applied to a V7 chord but could be inserted anywhere.  This creates a lot of chromaticism.  Following a circle of 5ths (or 4ths) like B7-->E7-->A7-->D7-->Gmaj, and applying this sub will get you B7-->Bb7-->A7-->Ab7-->Gmaj.
There are endless extensions of the things I've listed but in short these all follow a simple set of rules in harmony that attempt to create close movement into chord tones.
If you haven't looked at any books I'd recommend a few:
[1]  Basic Theory-Harmony, A Text and Work Book for the School Musician
By Joseph Paulson, Irving Cheyette
[2]  How to Create Jazz Chord Progressions by Chuck Marohnic
[3] Modulation by Max Reger
Answer: It sounds like you're off to a good start, but I agree that it sounds a bit random. This exercise you have written falls clearly in the Western tonal system, and in that system each pitch has a function - what I mean is that certain pitches have pull toward other pitches.
But in your piece, you just go to the new chord, then right back to where you were. That's why it sounds "random" - the chromatic pitches make you think you're going somewhere new, but when you got right back to the tonic it makes the listener think "Was that right?"
This is especially jarring because of where in the phrase you added the chromatic notes - during the cadence. Tonal music is centered around the tension of going from dominant to tonic (E♭ to A♭, in your case). You have chosen to add your notes right at the cadence point, so, again, you are setting the listener up to go one place but not completing the transition.
You have several options to adjust this piece, here are two:

Modulate - The chord you have inserted is a G major triad, which is the dominant of the key of C major. So you could use the G major triad as pivot chord to a new key. All you would need to do is transpose your last 4 measured up a major third to C major, and adjust the notes on the last eighth note of measure 3.

Colorful chromaticism - Sometimes chromaticism is just used for color, and not actually as a change in direction. One technique of adding color to a chord is by using a common-tone diminished chord. In this chord, you take one pitch from the chord you are on (in your case, G from the E♭ triad) and build a diminished seventh chord off of, then return to original chord. So that create a Gdim7 chord (G-B♭-D♭-F♭) to replace your G major triad. This G diminished chord will also resolve nicely to your Ab chord in measure 5, so you wouldn't need to change the last four measures, but you would want to change to melody in measure four to match this new harmony.

Ultimately, you are the composer, so you have to decide what sounds "good" to you, but hopefully these techniques will give you some new ideas to explore.
Answer: There are (at least) two methods of using chromatic harmony in a piece. The two do blend into each other and can be used in varying ways themselves. First: essential chromaticism uses chromatic notes in a functional way. Second: nonessential chromaticism inserts chromatic tones in a mainly diatonic context.  More at my answer here: What are the uses of chromaticism?
Many composers do start with highly chromatic stuff and then drift into using non-essential chromatic material. I'd guess because non-essential chromatic writing highlights the chromatic.
A simple and highly useful chromatic procedure is the use of secondary dominants. In a major key, all chords can be preceded by their own dominant. The most common is to use the II or II7 chord as a dominant of V. (Written as V/V read "five of five.") For example, many popular songs (country and earlier style rock) use the pattern I-IV-I-V-I; in the key of C, this would be C-F-C-G-C. The sense of closure can be enhanced by inserting a D (or D7) chord before the G giving I-IV-I-V/V-V-I (or I-IV-I-II-V-I) or C-F-C-D-G-C. No key change happens. The idea can be extended as in a common bridge from the 1930s or 1940s, I-I7-iv-II7-V7 or C-C7-f-D7-G7. One can also use exchange a major chord for a minor on the same root or vice-versa. These are particularly easy (even in improvisation) and usually can be used to good effect. There are a few more complicated techniques (still non-essential) that are nice: one is the use of the major chord built on the flat 2, Db in the key of C, but almost always in 6-3 position. In C the chord would be F-Ab-Db-F; this chord has a funny resolution in that the Db can go directly to B (the flat 2 directly to 7, an augmented second.) Sometimes a passing tonic 64 is put in between to make voice leading easier. F-Ab-Db-F to G-C-E-G to G-B-D-F or something similar. (The chord is called the Neapolitan Sixth.) This chord can be put in various places before the V chord. Instead of I-ii-V-I, one might have I-N-V-I (where N is the Roman Numeral for this chord; it doesn't have any other good description.)
Likewise, there is a set of Augmented Sixth chords built on the flat 6 step. In C (major or minor) these are Ab-C-F#, Ab-C-D-F#, and Ab-C-Eb-F# called the Italian, French, and German Sixths respectively.) The notation is intentional as the resolution is to move the augmented sixth (Ab-F#) outward by a semitone: giving G-G with some filler. G-C-E-G is common to avoid parallel fifths (which are often allowed in these types of progressions) or to G-B-D-F or G-B-D-G. In a minor key, the resolution would go to G-C-Eb-G or its equivalent in another key. With some practice, one can use these in improvisation too.
Note that this use of Augmented Sixths isn't the same as the jazz-oriented tritone-substitution. There Ab-C-Eb-F# is treated enharmonically as Ab-C-Eb-Gb and used to resolve to Db. Some composers (Schumann and Beethoven a couple of centuries ago) would do things such as approach the chord from Db as a V chord and then resolve into C as though it was a German Sixth. Db-F-Ab-Db (through some manner) to Ab-C-Eb-F# to G-C-Eb-G to G-B-D-F ane a quick key change. The reverse is also possible.
These are a few of the chromatic techniques that can be used without (mostly) changing keys.
Answer: Try out playing around with a motive

in the mediant key: C->Ab or Eb,
transpose a motive a minor third up, going through all 4 keys of a dim 7 chord (Bruckner)
write counterpoints in intervals of minor 3rds and dim. 5ths
transpose a semi tone up or down, you can harmonize with triads of the root or a tritone,
look up and study the augmented 6th chords (Germnan, French, Italian. - probably you know them - also the Neapolitanian).
Answer: You really have two questions in one: how to learn chromatic harmony, how to revise this example.
Obviously, explaining chromatic harmony can't fit into a Q&A answer, but perhaps at least a topic list would be helpful:

chromatic embellishment of diatonic melody, not really harmony, but it could help with blending in chromaticism
secondary dominants, especially important is the full diminished seventh chord which is normally on the leading tone but can be treated so any of its four tones becomes a leading tone for distant tonics. Ex. in C major, V7/V is D7 or F#o7 whose various tones lead to potential tonics G, Bb, Db, E and those tonics could be major or minor, that's a lot of chromaticism!
borrowed chords, this mostly gives you minor forms of subdominant chords in a major key
get acquainted with the common chromatic chords Neapolitan and Augmented Sixth usually found in minor
learn about jazz harmony especially the tritone substitution and the use of altered dominants in minor
chromatic mediants (some overlap with borrowed chords) very colorful and dramatic
parallelism, sometimes called chord planing, you can hear this in Impressionism like Debussy or jazz
use exotic scales like whole tone, octatonic, etc.
chromatic, harmonic sequence. Diatonic sequences move through varying chord qualities. An easy way to get chromatic harmonies is to sequence one chord type. Seventh chords provides lots of color. A common way to sequence is root progression by descending fifth sequenced up/down by whole/half steps. A staple of jazz is a sequence of dominant seventh chords by descending fifths. Sequencing minor sevenths and half-diminished sevenths will also give you interesting colors.

That's a lot of work on, but it gives you an idea of the many ways you can approach chromaticism. Keep in mind some approaches work mostly around functional, tonal harmony while others involve other musical aspects like voice leading and a general sense of dissonance resolving to consonance.
I had two main thoughts about your example:

highlight the root movement by step of G major to Ab major with parallel motion
accentuate rhythmically the "surprise" of a G major chord in the key of Ab major

In this part the G up to Ab and bass B down to Ab is the part where we get root progression by step. The contrary motion looks like an effort to avoid parallel octaves which is part of the harmonic vocabulary of common practice music.

But this isn't a common practice progression, so why play by those rules? The quirkiness of this part comes from the progression by step and harmonizing a major chord on the leading tone. If the intention is quirkiness, don't try to hide it, flaunt it! Make the "slide" of root progression by half step really felt.
I think the G chord could benefit with a bit more dramatic rhythm to accentuate the quirkiness of the harmony. The melodic figure in that part...

...mirrors the flowing figure at beats 3,4 of m. 2 which has a gentle feel over the subdominant pedal...

...but you could work with the sixteenth not figure just before for a snappier rhythm...

That may seem a subtle difference in what to reuse, but I think it can provide a different character.
Below is a sketch (the bass part isn't meant to be the actual accompaniment) with bar four in parallel motion and a different re-used rhythm, the harmony is root position and the treble centers around G to emphasize the parallel movement...

How to compose better chromatic harmony


Zoom image in a NSScrollView in objective-c

Question: I have two NSScrollView's with scroll synchronized with each other (using Apple's example) and it is working. Next I implemented a zoom that would zoom both images (they have the same size by definition). The code for the zoom was adapted using code from here, which I present here:
    if (oldZoomValue > [sender floatValue]) // then we are zooming in
{
    float zoomFactor = 1 + oldZoomValue - [sender floatValue];

    oldZoomValue = [sender floatValue];

    NSRect visible = [synchroS_ScrollView documentVisibleRect];
    NSRect newrect = NSInsetRect(visible, NSWidth(visible)*(1 - 1/zoomFactor)/2.0, NSHeight(visible)*(1 - 1/zoomFactor)/2.0);
    NSRect frame = [synchroS_ScrollView.documentView frame];

    [synchroS_ScrollView.documentView scaleUnitSquareToSize:NSMakeSize(zoomFactor, zoomFactor)];
    [synchroS_ScrollView.documentView setFrame:NSMakeRect(0, 0, frame.size.width * zoomFactor, frame.size.height * zoomFactor)];
    [[synchroS_ScrollView documentView] scrollPoint:newrect.origin];

    NSRect visibleI = [synchroI_ScrollView documentVisibleRect];
    NSRect newrectI = NSInsetRect(visibleI, NSWidth(visibleI)*(1 - 1/zoomFactor)/2.0, NSHeight(visibleI)*(1 - 1/zoomFactor)/2.0);
    NSRect frameI = [synchroI_ScrollView.documentView frame];

    [synchroI_ScrollView.documentView scaleUnitSquareToSize:NSMakeSize(zoomFactor, zoomFactor)];
    [synchroI_ScrollView.documentView setFrame:NSMakeRect(0, 0, frameI.size.width * zoomFactor, frameI.size.height * zoomFactor)];

    [[synchroI_ScrollView documentView] scrollPoint:newrectI.origin];
}
else
{
// the equivalent but for zoom-out
}

If I use the zoom functionality without synchronized Scroll's, both images on the NSScrollView are zoomed nicely as expected. However, if they are synchronized, the program crashes with it seems to be a stack of several calls: on the main thread, it shows a lot of things like
#18 0x0000000100003e37 in -[SynchroScrollView synchronizedViewContentBoundsDidChange:] ()

and on the GDB:
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
sharedlibrary apply-load-rules all
[Switching to process 33162 thread 0x0]
[Switching to process 33162 thread 0xac03]
[Switching to process 33162 thread 0x903]
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
...
(gdb)

Can anyone point me a direction for debug or have any idea what is happening?
Thank you for your help.
Answer: I'm not sure where you call the code for zooming the scrollView, but maybe zooming in scrollView A triggers zooming in scrollView B, which in turn triggers zooming in scrollView A again, creating an endless loop. changing the bounds in the  synchronizedViewContentBoundsDidChange method would call the same method again and again.
I know this question is a few months old, but maybe this helps :)


Is Python's epsilon value correct?

Question: According to Wikipedia:

Machine epsilon is defined as the smallest number that, when added to one, yields a result different from one

In Python, epsilon can be found using sys.float_info.epsilon and returns a value equivalent to 2^-52. However, I can add any number greater than 2^-53 to 1 and still get a result different to one.
But by the above definition of epsilon, adding any value less than epsilon to one should give one.
Does this mean that sys.float_info.epsilon is returning an incorrect value, or that Python is using some other definition of epsilon?
The following code illustrates this, with the floating point numbers printed out in hex format.
import sys
import numpy
print 'epsilon=%g' % sys.float_info.epsilon
# output: 2.22045e-16
epsilon = sys.float_info.epsilon
print 'epsilon(hex) = %s' % float.hex(epsilon)
# output:  0x1.0000000000000p-52

one = numpy.float64(1.0)

delta = float.fromhex('0x1.fffffffffffffp-53')
print 'delta = %s' % float.hex(delta)

print 'epsilon - delta = %s' % (float.hex(epsilon-delta))
#output: 0x1.0000000000000p-105

print '\n1.0 + epsilon = %s' % (float.hex(one+numpy.float64(epsilon)))
#output: 0x1.0000000000001p+0

print '\n1.0 + delta = %s' % (float.hex(one+numpy.float64(delta)))
#output: 0x1.0000000000001p+0
# since delta is smaller than epsilon, I expected 0x1.0000000000001p+0

delta1 = float.fromhex('0x1.0000000000001p-53')
print '\n1.0 + %s = %s' % (float.hex(delta1), float.hex(one+delta1))
#output: 0x1.0000000000001p+0
# since delta is smaller than epsilon, I expected 0x1.0000000000001p+0

delta2 = float.fromhex('0x1.0000000000000p-53')
# note: delta2 = epsilon / 2.0
print '\n1.0 + %s = %s' % (float.hex(delta2), float.hex(one+delta2))
# 0x1.0000000000000p+0

The resulting output is
epsilon=2.22045e-16
epsilon(hex) = 0x1.0000000000000p-52
delta = 0x1.fffffffffffffp-53
epsilon - delta = 0x1.0000000000000p-105

1.0 + epsilon = 0x1.0000000000001p+0

1.0 + delta = 0x1.0000000000001p+0

1.0 + 0x1.0000000000001p-53 = 0x1.0000000000001p+0

1.0 + 0x1.0000000000000p-53 = 0x1.0000000000000p+0

Answer: I think that what you you are seeing is how Python's float type handles rounding when it runs out of precision. The Wikipedia text you quoted describing epsilon appears to leave this part out.
In your example, 1 + delta gets rounded up to 1 + epsilon. Even though a float can specify the differences between delta and epsilon, it cannot represent the difference between 1 + delta and 1 + epsilon. As you have noticed (with your delta2 test), the largest number that gets rounded down to 1 rather than up to 1 + epsilon appears to be 1 + epsilon/2.
So, a correct definition of what epsilon means in Python might be:
epsilon is the smallest positive floating point number such that (1 + epsilon) - 1 equals epsilon.
Comment: I don't think it's Python's rules, it's IEEE's. I like your conclusion, except that zero meets the requirement too. Perhaps if you restated it to be "the smallest *nonzero* floating point ..."
Comment: Good point about zero. In fact, probably `-2/epsilon` (`-2**53`) would count too (while being much "smaller" in the "closer to negative infinity" sense), so I've adjusted my definition to specify a positive number.
Answer: That definition is wrong: machine epsilon is the number eps such that 1+eps is the next number after 1.  Thus with standard rounding, u = eps/2 is the smallest number that when added to 1 gives a value greater than 1.  This quantity u is often called the unit roundoff or machine unit.
(For IEEE64, eps=2^(-52), u = 2^(-53).)
By the way, for most practical purposes, the unit roundoff u is more useful than eps: for example, u is the maximum relative error when a value is rounded to a normalized machine number.
Reference: Higham, Accuracy and Stability of Numerical Algorithms, pages 37, 38.

Is Python's epsilon value correct?


How to set up multi users on dev server with git and github

Question: I'm working on lamp application.  We have 2 servers (Debian) Live and Dev.
I constantly work on dev main to add new features and fix bugs.
When happy all works well I scp the relevant code to the Live system.  Database (mysql) is local to each machine.
Now this is pretty basic setup really and I want to improve the workflow a bit. I use git and github for version control. Admittedly I've only really used one branch.  Their can be 3 different developers who work on the code at different times.   We all use the same linux username to connect to the dev server and edit the code directly when needed. I usually then commit and push the code at the end of the day to github.
One thing to bare in mind is it isn't easy to run this code on a local machine as there are many apache and subdomain configurations that wouldn't work on a local machine so it is important to work on the dev server not locally.
I need to create a new process because we need to have a main trunk now and a branch with a big code re-write.
What is the best way to do this.  Should I create different unix logins for each developer and set up different working areas on the dev server for there changes?  e.g.
/var/www/mysite_derek
/var/www/mysite_paul
/var/www/mysite_mike
my thinking is they can do a pull from the main branch and then create there own branch and merge it back in.  I'm not sure how this will work though with git locally and with github.
will i need to create different github user accounts as well.
I'd like to do this the 'right' way and future proof for having lots of potential developers but I also don't want to over complicate it.  I simple and elegant solution is preferred.
any recommendations or suggestions?
Comment: You say you need to have a main trunk now as well as a branch ; does that mean there will be multiple dev servers? or still just one?
Answer: A solution that we use with about 12 developers is the following. It works very well and makes for a flexible setup without needing to modify the server's config anymore. It probably won't scale to 40-50 devs due to network latency and speed of server storage.
We share the /var/www/ tree via Samba, so the Windows clients can use their local IDE's and VCS-clients to edit on the LAMP server. No-one has an account on the Linux server.
Create your directory structure like this:
<code>/var/www/mysite.com/www/derek/
/var/www/mysite.com/www/paul/
/var/www/mysite.com/www/mike/
</code>
In your internal DNS, create a wildcard record that points **.dev* to your lamp server's IP address. I'm assuming 220.127.116.11 here.
In Apache, define a virtualhost that looks similar to this:
<code><VirtualHost 220.127.116.11>
   ServerName lamp.dev
   ServerAlias *.dev
   VirtualDocumentRoot /var/www/%-3.0.%-2/%-4/%1/
</VirtualHost>
</code>
The important parts are the ServerAlias wildcard, which makes this vhost respond to all incoming requests that end with '.dev'. The other important one is the VirtualDocumentRoot, which looks complex but isn't so bad. It simply cuts the incoming hostname into parts and constructs the DocumentRoot out of the parts. You can read more about it here.
Now, any developer can visit http://derek.www.mysite.com.dev/ and view their personal working-copy of mysite.
Adding a new site, subdomain or developer is simply a case of creating the right directories on the Samba share.
For deploying to the Production servers, I would recommend you ditch scp and look at Capistrano, and the excellent centralized web frontend Webistrano. Capistrano is a
bit Rails-centric, but it only takes a few lines to adapt to PHP for example. Webistrano provides a central GUI where you can deploy or update a site straight from version control at the push of a button. Having easily scripted deployments, that can be repeated reliably and rolled back in case of problems should not be ignored.
Comment: @Derek The samba method would be too slow over the internet, but you could combine it with linux accounts on the server. Would be slow and go against the idea of DVCS though. We use a VPN to access the Samba share and dev server, but I would like to have the speed of a local DVCS back.
Comment: do u use git / svn with that?
Comment: one thing the developers are not in one office and the server is a hosting company so I don't think that would work well for that but not sure. its defo interesing though and might lead me to solving my problem a different way.
Comment: We use SVN with that. Users simply use use their local svn client to checkout to the correct dir on the Samba share. It's slower than your local harddisk, but quite workable on a LAN. SVN doesn't like Samba shares though. Takes a few config tweaks on the server. I'd imagine that Git, Hg or Bzr would be faster and easier due to simpler working-copies.
Comment: @Derek I edited my answer to provide some info on deployment.


Negative variances in Kalman smoother (FFBS)

Question: I have implemented the forward-filtering-backwards-sampling (ffbs) algorithm.
It consists of kalman filtering forward in time (to obtain mean and sigma). Then  it uses these values and the Kalman smoother backwards in time to get mean and Sigma for all time points.
My problem is that the Kalman smoother seems to get negative variances. Can this be the case - and if so, how does it affect my results?
The code is made in R (and Sigma_predictions and Sigma_upates are obtained from the Kalman filter)
<code># ---- KALMAN / FORWARD FILTERING ----

# Kalman filter iterations

# Kalman loop starts
for(i in 1:big_t){ # Loop through each time point

  # In the first iteration the inittial value is set
  thisIsTheFirstValue <- (i == 1)
  if(thisIsTheFirstValue){
    phi_upd <- mean_0
    sigma_upd <- sigma_0
  }

  # Prediction step
  phi_pre <- (Gamma %*% phi_upd) + Theta
  sigma_pre <- (Gamma %*% sigma_upd %*% t(Gamma)) + Psi_cov

  # Update step
  v <- y[, i] - (alpha + B %*% phi_pre) # y_t - f_t
  big_F <- (B %*% sigma_pre %*% t(B)) + epsilon_cov # epsilon_cov = sigma * Idnetity matrix
  inv_F <- solve(big_F, tol = 1e-40)
  # Calculate updates
  phi_upd <- phi_pre + (sigma_pre %*% t(B) %*% inv_F %*% v)
  sigma_upd <- sigma_pre - (sigma_pre %*% t(B) %*% inv_F %*%  B %*% sigma_pre)

  # save values in the arrays (used later in backward sampling step)
  phis[, i] <- phi_upd
  phi_predictions[ , , i] <- phi_pre
  sigma_predictions[ , , i] <- sigma_pre
  phi_updates[ , , i] <- phi_upd
  sigma_updates[ , , i] <- sigma_upd

} # end for loop

# ---- BACKWARDS SAMPLING ----

# Find h_t and H_t by backwards sampling
loop_seq <- seq(from = (big_t - 1), to = 1, by = -1)
for(t in loop_seq){

  # In the first iteration the inittial value is set
  thisIsTheSecondLastTimePoint <- (t == (big_t-1))
  if(thisIsTheSecondLastTimePoint){
    phi_next <- matrix(rmvnorm(1, mean = phi_updates[ , , big_t], sigma = (sigma_updates[ , ,  big_t])), nrow = (p+1), ncol = 1)
# Save phi drawing
  phi_array[ , , big_t] <- phi_next
  }

  # Calculate mean value dep. on this value
  inv_sig_pred <- solve(sigma_predictions[ , , t+1])
  mean_t <- phi_updates[, , t] + (sigma_updates[, , t] %*% t(Gamma) %*% inv_sig_pred %*% (phi_array[ , , (t+1)] - phi_predictions[ , , t+1]))
  sigma_t <- sigma_updates[ , , t] - (sigma_updates[, , t] %*% t(Gamma) %*% inv_sig_pred %*% Gamma %*% sigma_updates[, , t])
  # Make the drawing
  phi_next <- t(rmvnorm(1, mean = mean_t, sigma = sigma_t))

  # Save phi drawings
  phi_array[, , t] <- phi_next
}
</code>
It is a state-space system, I am considering.
lambda is set to 0.5.
All is set due to an article, I am following.

The mathematical calculations are (sorry for a changed notation):

The problems, I am facing are problems with diagonal elements being negative in the H_t-matrix.
The diagonal of the first calculated H_t I get:

The diagonal of the second calculated H_t I get:
Comment: Is t(Gamma) > 1? I don't know what your algorithm is supposed to do, so I don't know  whether your problem is due to algorithm deficiency or implementation error. Is sigma_t actually a covariance matrix (not just 1 by 1 variance)?
Comment: What is t(Gamma)?  Where is the closing parenthesis for the first character in: (sigma_updates[, , t] %*% t(Gamma) %*%
Comment: I think it is there (or am I wrong?).  The line was just broken into two lines. It should be seen clearer now, as I set them to one.
Comment: Show us mathematically what the covariance update formulas are, and specifically what covariance is coming out with negative (variances?, meaning diagonal elements? or eigenvalues?).  Are there some number of updates before the negative variances occur?
Comment: Hope it makes sense.
It is already in the first iteration, that negative variances occur.
Answer: You appear to be getting roundoff error level negative variances.  Subtraction is a dangerous thing. There is a perhaps a better "root cause" fixing up which can be done, by modifying the updating equation.
But in the absence of that, one quick "fix", which I'm not saying is a good thing to do here, is to adjust the covariance matrix on each iteration to be symmetric positive semidefinite, with some minimum eigenvalue value, eigmin (a very small positive number).  Do this by first symmetrizing, then eigenvalue eigenvector decomposiition, then replacing eigenvalues below eigmin with eigmin, then reconstituting the matrix. Symmetrize if needed at the end.
Symmetrization: $H = 0.5*(H + H^T)$
Let V = eigenvector matrix of H, D = diagonal; matrix of eigenvalues of H.  Therefore, $H = VDV^{-1}$.  Replace diagonal elements of D below eigmin by eigmin, resulting in $D_{adjusrted}$. Now form $VD_{adjusted}V^{-1}$, and symmetrize if necessary.
Comment: @Dorthe Does my answer help you or is it off the mark?


Adicionar regra para apenas o admin conseguir listar todos os documentos de uma coleção no firestore

Question: Olá, estou estudando como funcionam as regras de segurança do firestore e me deparei com a seguinte situação.
Tenho uma coleção chamada: "restaurantes" com três documentos "uid1, uid2 e uid3". Foi ai que surgiu uma dúvida.
1 - Existe alguma forma de garantir que apenas o Admin consiga listar todos esses restaurantes?
2 - como garantir que apenas o restaurante com "uid1" consiga atualizar os seus próprios dados e não modificar os outros restaurantes?
Answer: Sim existe, você deve informar diretamente nas Rules no seu firebase console.
por padrão as suas rules devem vir assim:
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

você pode editar manualmente ou...
-ir na opção laboratório de testes
coloque o caminho até a sua coleção restaurantes, rolando mais para baixo você terá o campo de UID. Adicione o usuário que você quer que tenha acesso à este local
OBS: você pode conseguir esse UID, diretamente no painel autenticação do seu Firebase, procure pelo user que deseja e copie o UID.

Essa é a forma mais simples de fazer essa configuração.
Answer: Seu eu não me engano, nas regras tem a opção de deixar publico a leitura e escrita no banco, podendo alterar individualmente cada uma.
Só não sei se eh possível fazer isso para cada documento individualmente.


how to get banner image based on the role?

Question: I want to have a banner in home page which should change according to the logged in user role.How can i achieve this?
I'm trying edit 'page--front.html.twig'. But i'm not able to fetch logged in users role.How to check user roles inside this twig file?
Comment: How to check user roles inside this twig file? You can do this inside of twig without php. This question is valid for all templates http://drupal.stackexchange.com/questions/226314/restrict-node-to-user-role-in-a-template-file
Comment: How you create banner?
Comment: Different banner image, for different roles i have.when user logs in , depending on the Role of that user,banner image should change.
Comment: I am asking how you have create the banner means you are creating banner using view/block or some custom code or contributed module.
Comment: It is just a image.[] I tried adding in custom block also and tried adding in 'page--front.html.twig' also. But i didn't get proper output.
Comment: Thank you.. {% if 'example_role' in user.getroles  %}
  The user has the role "example_role".
{% endif %}   works fine
Answer: Considering you have created multiple Blocks for individual role  from Drupal admin UI.

You can restrict each block role wise.
Comment: and in Pages tab put ``
Answer: Go to your theme's folder and in your themename.theme file add:
function themename_preprocess_page(&$variables) {
  if (\Drupal::service('path.matcher')->isFrontPage()) {
    $variables['role'] = \Drupal::currentUser()->getRoles();
  }
}

Then in your page--front.html.twig, example:
{% if role == 'administrator' %}

{% elseif role == 'anonymous' %}

{% endif %}

Note: If you need to be able to switch these images in the future and the person who maintains the site does not know Twig or FTP, this is the better answer.
Comment: thanks for the answer.But {{ role }} variable i couldn't print in front twig file.
Answer: You can create the slider as a block and set the permission of that block according to required roles.
Comment: Can you add some more details to better explain how/why this answer solves the question? FYI: your answer showed up in the "low quality posts" (which puts it as risk of being deleted via moderation), hence my comment here ...


Probability that piecewise continuous $X(\omega) \ \in A, \ A \in \mathcal{B}$

Question: I solved this problem, but since my understanding of Borel sets and $X^{-1} \in \mathcal{B}$ is still not polished, I decided to ask it.
On a probability triple with Lebesgue measure on $[0,1]$, a random variable is defined such that
$$
X(\omega) = \left\{
\begin{array}{l}
1 & \omega \in [0,\frac{1}{4})\\
2\omega^2  & \omega \in [\frac{1}{4}, \frac{3}{4})\\
w^2 & \omega \in [\frac{3}{4},1]
\end{array}
\right.
$$
If $A=[0,1]$, what's the $P(X \in A$). So I split $A$ into $4$ disjoint subsets, $A_1 \ldots A_4$:
$$
A=[0,\frac{1}{4}),[\frac{1}{4},\frac{3}{4}), [\frac{3}{4},1), \{1\}
$$
when $A=1, X$ is a simple random variable, so
$$
A_4 = \{\omega:X(\omega)=1\} \rightarrow P(X \in A_4) = \frac{1}{4}-0
$$
For $A_1$, I think $P(X \in A_1)=0$, because $\{ \omega: 0 < X(\omega)<\frac{1}{4}\}$ is not defined. \
For $A_3, P(X \in [\frac{1}{4}, \frac{3}{4})) = \frac{\sqrt{3}-1}{\sqrt{8}}$
Lastly, $P(X \in [\frac{3}{4}, 1)) = 1-\frac{\sqrt{3}}{2}$
Putting it all together, $P(X \in A) = \frac{1}{4} + \frac{\sqrt{3}-1}{\sqrt{8}} + 1-\frac{\sqrt{3}}{2} \approx 0.64$
If that's correct, what would be the probability $P(X \in A^c) = P(X>1)$? From the definition of $X(\omega)$, it should be
$$
A^c = \{\omega:1 < X(\omega)\leq \frac{9}{8}\} \Leftrightarrow X^{-1}((1,\frac{9}{8}]) = \bigg[\frac{1}{\sqrt{2}}, \frac{3}{4}\bigg] \Rightarrow P(X^{-1}) = \frac{3}{4}-\frac{1}{\sqrt{2}} \approx 0.04
$$
so they don't sum to $1$! Then either my calculation for $P(X \in A)$ is incorrect, or definition of $A^c$.
Answer: Verify that $X \notin A$ iff $\frac 1  {\sqrt 2} <\omega <\frac  3 4 $ and $X \in A$ iff $\omega >\frac  3 4 $ or $\omega <\frac 1 {\sqrt 2}$. ( I am ignoring possible equalities because Lebesgue measure of a single point is $0$).
Hence $P(X \in A)=\frac 14 +\frac 1 {\sqrt 2 }$ and $P(X \notin A)=\frac  3 4 -\frac 1 {\sqrt 2}$ and these add up to $1$.
Comment: But $A \cap [0, \frac{1}{4}]=\emptyset$ and $X([0, \frac{1}{4}])=1$, right?
Comment: First of all you should learn to distinguish between $X \in A$ and $A$ itself. It is hard to read what you write. It is not true that $(X \in A) \cap [0,\frac  1 4]$ is empty. In fact $X\in A$ for all points of $[0,\frac  1 4]$. Secondly the value of $X$ at one point does not matter for calculating the probabilities. @Alex
Comment: $X(\omega)$ for $\omega \in [0,\frac{1}{4}]$ is a simple random variable, so $P(X=1)=\frac{1}{4}$
Comment: @Alex $P(X=1)=\frac 1  4$ is correct.
Comment: For $\frac{1}{4} < \omega <\frac{3}{4}, P(X(\omega) \in A =[\frac{1}{4}, \frac{3}{4}]) = \sqrt{\frac{3}{8}} - \frac{1}{\sqrt{8}}$ because $(X^{-1}(\frac{1}{4}) = \frac{1}{\sqrt{8}}), X^{-1}(\frac{3}{4}) = \sqrt{\frac{3}{4}}$
Comment: https://math.stackexchange.com/a/3739036/38873
Comment: Besides, I still don't understand which function maps $X(\omega)$ to $A=[0,\frac{1}{4}]$
Comment: You have a wrong approach to the  whole thing. $A=[0,1]$ is a fixed set. It make no sense to bring in $A=[0,\frac 1  4]$. Start afresh and try to verify what I have written in my answer. @Alex


statistical method for finding significant numbers in a set

Question: Suppose that we have a population of $N= 1000$ people and they want to select 5 items (for simplicity) $\{A, B, C, D, E\}$ (but actually number of items is in the order of thousands). Number of selections for items is $\{3, 142, 52, 633, 800\}$. Each person (selector) is free to select as many items as they want. Selecting of one item may affect for selection of another item by one person. For example, if items are goods in a supermarket, the first person may select items $A$ and $C$. The second person may select all items. We want to find "the minimum number of selections", named $T$, so that if number of selections for an item is larger than $T$, we can say that item is interesting or popular for the population since at least $T$ people have selected that item. We want to find this number ($T$) by "a statistical method".
As an another example, for each item, we can assign a value to it by the percentage of people who have selected that item. So, we have a range of 0 (no person has selected it) to 100% (all people have selected that item). Definitely, 100% means popularity or significance for that item for the population. But We want to find what is the minimum percentage so that we can say that item is still popular. In other words, is the range of popularity from 20-100% or 10-100% or ....? We want to find a statistical measure for defining popularity of significance.
Thanks.
Comment: No. Depending on your context, what is "important" would be very different.
Comment: Use the following rule: $$\text{a number $x_i$ is significant if $x_i=42$}$$
Comment: This question is unanswerable because it needs a definition or quantitative description of what you might mean by "interesting or popular."
Comment: we want to find important based on a statistical test.
Comment: Can a person select more than 1 of the same item? Say pick A two times?
Comment: No. Each person can select each item just once.
Answer: Your question is circular. You say you want to use a test find the 'important' values. And when asked what you mean by 'important' you say the 'important' values are ones that pass the test.
To make sense of this it might be most useful for you to look at numerical or graphical summaries of your data.
Then from the summaries try to get an intuitive view of what you mean by 'important'.
That might lead you to your own general criterion for importance. (Opinions of others may differ.)
Using R statistical software:
x =  c(3 , 4 , 52 , 633 , 1000, 0, 6915 , 890 , 500)
summary(x)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
     0       4     500    1111     890    6915
sd(x)
[1] 2212.417  # sample standard deviation

The mean and median are two ways of describing the center of the data.
The mean (average) would be the balance point if you consider the values
plotted along a line, giving each equal weight (red line below). Are the
below-average values important because they are "more typical" or is the largest value important because it has such a large influence on the mean?
stripchart(x, pch=20)
 abline(v = mean(x), col="red")

The median is the middle
value, if the observations are sorted (halfway between the two middle values
if the sample size is even). Here the middle value of the sorted data is $500.$
sort(x)
[1]    0    3    4   52  500  633  890 1000 6915

In a boxplot, the box shows the extent of the middle half of the data (from the first to third quartile in the summary). The median is at the line within the box. So-called "whiskers" may extend partway to the minimum or maximum, but the most extreme values might be
plotted separately. Because the plot extends so far to the right to include the maximum value the scale doesn't show much detail for the values around $0.$
Which is more 'important' to you--the half of the values inside the box or the half outside the box?
Some people might think that the maximum value $5915$ is the only really 'important' one, and
some might think it should be disregarded entirely because it is so much different from the others--not typical, perhaps some sort of mistake.
boxplot(x, col="skyblue2", pch=20, horizontal=T)

There are many possible numerical and graphical descriptions of data because different situations make it appropriate to focus on different values as being 'important'.

Addedum per Comments: Suppose there are Five categories of items and 1000 subjects, each of whom is asked to choose 2 favorites. Then you might say each of the five
counts is roughly distributed as $\mathsf{Binom}(n=1000, p=2/5),$ in which case one would expect 95% of counts to be between 370 and 430 inclusive. So any item with
less than 370 'votes' might be considered 'unpopular' and and any item with more than 430 might be considered 'popular'.
However, the vector of counts
$(360, 420, 402, 398, 411),$ even with one slightly 'unpopular' count, would
not be enough evidence to say that categories are of 'significantly' unequal popularity overall at the 5% level of significance (P-value is $0.066 > 0.05.)$
sum(dbinom(370:430, 1000, 2/5))
[1] 0.9510791

prop.test(c(360,420,402,398,411), rep(1000,5))

        5-sample test for equality of proportions
        without continuity correction

data:  c(360, 420, 402, 398, 411) out of rep(1000, 5)
X-squared = 8.8167, df = 4, p-value = 0.06585
alternative hypothesis: two.sided
sample estimates:
prop 1 prop 2 prop 3 prop 4 prop 5
 0.360  0.420  0.402  0.398  0.411

If you think something similar to this approach may be useful, please edit your question
with enough specific information that one of us might follow up usefully.
Comment: Suggest you 1) Edit your Question with that explanation [Not everyone reads Comments.]  2) **Clarify your counts:** there seem to be some typos there. 3) Give some idea what you mean by important: Letter chosen by more than half? Letter chosen by more than avg nr, of subjects? Enough difference in numbers of choices to show not all equally popular? 4) Make rules for subjects clear: Can subjects choose as many as they like? Limit of say 5 per subject? // Any clue about what you are doing and what your purpose is might be helpful.// See my Addendum. But others may have useful answers.
Comment: Thanks for the comments. Let me clarify my mean by importance. Suppose that a population (N= 1000) want to select some items {A ,B ,C ,D ,E ,F ,G, H, K, L} . Item A is selected by 3 people, item  by 4 people and ..... Cont.
Comment: Now we want to find which items are not important for the people (or which items are important) based on a statistical test. Definitely item  E is important since all people have selected it. Can we say C is important for the population (52 people have selected that)? In other words, what is the T so that if number of selectors for an  item is larger than T, we can say that item is important for the population and if it is less than T, that item is not important (or interesting) for that population.
Comment: @BrucET Thanks for your comments. I posted the edited question in a news post:    https://stats.stackexchange.com/questions/492958/statistical-method-for-finding-minimum-numbers-of-selections-for-popularity-of-a
Answer: If you have the data to place the orders in a contingency table then you can compute conditional probabilities of selecting the other items. Based on that you can make decision rules to add the items to the list.
For instance a hypothetical table, showing the frequency of items being bought together (where X means that the item is bought without another item) could be:
    A    B    C    D    E    X
A   0    0    0    3    0    0     3
B   0    0    10   2    100  30    142
C   0    10   0    0    30   12    52
D   3    2    0    0    422  206   633
E   0    100  30   422  0    248   800
X   0    30   12   206  248  0
    3    142  52   633  800

The decision rules are not easy to determine. You might select the items with the highest frequencies, or you could select the items which have highest positive correlation (items for which the conditional frequency is higher than the non-conditional frequency).
For example let's compare the frequency of selections dependent on having already selecting D
$$\begin{array}{}
& A & B & C & D & E \\
\text{conditional on D} & \frac{3}{633}& \frac{2}{633}& \frac{0}{633}& \frac{0}{633}& \frac{422}{633}\\
\text{unconditional} & \frac{3}{1000} & \frac{142}{1000} & \frac{52}{1000} & \frac{633}{1000} & \frac{800}{1000}
\end{array}$$
So somebody that has selected item D is likely gonna buy item E as well (probability 2/3), but this probability is lower than the unconditional probability (4/5). So while this item E has the highest probability conditional on item D, the item D is actually reducing the probability of buying item E.
On the other hand, the item A has only very low probability of being bought (1/211), but it is higher than the even more low unconditional probability (3/1000).
Which items you should place in the list, on what basis/grounds, is unclear. The question does not specify this clearly. The question sounds like related to a webshop which provides suggestions based on the contents of the current shopping car. In that case the underlying goal is probably more sales. Suggesting items that are more likely to be bought is not necessarily generating more sales. These items might already get sold without being suggested. What is needed is suggesting items that are more likely to be sold when they are suggested in comparison to not being suggested. For this you'd need to do some experimentation like A/B-testing.


finding solution in real numbers, two variables

Question: With a problem expressed in a varaible $x$ like
$$3y−6x=12$$
I can get a graph of that, or solve for $y$ in terms of $x$, but how do I find the real number (non-complex) solution, assuming, as is the case here, that there is one?
Comment: I'd actually love to see this question remain, as it gives future readers a hint: sometimes you can't solve a problem because you're trying to solve something different than what you're asked. In many areas of math, a tiny change converts something straightforward into something very difficult. So a good first step when you're stuck is, "Re-read the question, slowly, carefully, doubtingly."
Comment: oops, I think I misread my graph. I thought the points on the axes were where it was intersecting the real number line! Please delete this question.
Comment: If you want to delete your question then unaccept the accepted answer by clicking on the green tickmark again and then click on delete question below your question...
Answer: solving for $y$ we obtain:
$$3y=12+6x$$ dividing by 3 we get:
$$y=4+2x$$
Answer: $$3y-6x=12$$ is of the form $y=mx+c$ which represents a straight line.We have infinite solutions.In fact for every real $x$ we have a corresponding $y$ satisfying the equation.
Answer: If you are getting fractions while plotting graph, first you should make the equation simple as $$ y = 4 + 2x $$
Then when you get equation like in form & $y=f(x)$ then by putting ( natural numbers ) you get "y" for that value of "x".
Like this you don't get fractions for plotting graphs
Answer: it represent a straight line every point is a solution
ie
You should have given two equations which would beCoincident lines
Infinite number of solutions. the pair of linear equations is consistent and dependent.
Comment: Where do you find a pair of equations?There is only one equation given...
Comment: Your answer is also wrong...
Comment: Because there are no pair of equations to be a dependent system of equations...
Comment: The question itself is wrong
Comment: I just explained him
Comment: Now see it please


What's this curved line after this note?

Question:
It's not a slur because it doesn't connect to any other notes, so what is it?
Answer: It's called a fall. It's sort of like a glissando; it means to bend the note downward. Searching YouTube for "saxophone fall demonstration" will provide tutorials for how to do it and what it sounds like.
Comment: Ideally it's a *portamento* (continuous pitch change) rather than a *glissando* (discrete pitches, like doing a smear on a piano keyboard).
Comment: Also sometimes found in vocal music.
Answer: Since you're asking specifically about sax: yes, it's a fall. But what's a fall consist of? A few bits and pieces. the most effective isn't just falling from the note shown, but playing that note, then slurring to the note above - a semitone or tone, depending on where you are works best.
A rough chromatic scale downwards is good, rather than just the diatonic scale notes, down to an octave below the written note. Fingering sometimes prohibits this, so a couple can be missed out - after al, the fall is so fast, no-one will hear!
The other factor is that the fall is a decrescendo, going from the note above the written one down to the lowest played, which will be hardly audible. Like you've run out of breath. In the example shown, the note value is a crotchet - a quarter note - we don't see what follows, but the fall shouldn't last longer than that crotchet anyway. At which point the player will probably need to inhale for the next phrase - a fall often comes at the end of a phrase.
Comment: (not the DV) Slurring *above*?
Comment: @Tom - slurring the note played, the note above, and every note on the way down - one breath.
Comment: I'll never learn how to produce a good answer if the downvoters don't tell me what I'm doing wrong.


DrupalGap Frontpage not displaying

Question: I am following the drupalgap hello world creation tutorial, however all i tried to make the hello world proven to be unsucessful.
here is the frontpage config fron settings.js
i did the installation on mobile folder and the setting file is settings.js
// App Title
drupalgap.settings.title = 'gsam';

// App Front Page
drupalgap.settings.front = 'hello_world';

the module name is gsam with directory structure:
mobile/app/modules/custom/gsam

and here is my gsam.js,
when every i load my server pointing to the mobile I have 404, that is after i placed this code.
/**
 * Implements hook_menu().
 */
function gsam_menu() {
  var items = {};
  items['hello_world'] = {
    title: 'DrupalGap',
    page_callback: 'gsam_hello_world_page'
  };
  return items;
}

/**
 * The callback for the "Hello World" page.
 */
function gsam_hello_world_page() {
  var content = {};
  content['my_button'] = {
    theme: 'button',
    text: 'Hello World',
    attributes: {
      onclick: "drupalgap_alert('Hi!')"
    }
  };
  return content;
}

Answer: One possible reason could be the apparent failure to refer the your custom module in your project settings.js. This file resides in mobile/app/modules/custom/gsam/www/app. Edit the file and add the following code in the custom module section:
Drupal.modules.custom['gsam'] = {};

drupalgap.settings.front = 'hello_world';

DrupalGap Frontpage not displaying


Some inequality I stumbled upon, $b^3-a^2b+2a \geq 0$

Question: $b^3-a^2b+2a \geq 0$
Given: $(a,b) \in \mathbb{N}$ and a>b.
Find when this holds.
This is an inequality I stumbled upon while I was surfing, and like any other day, I sat down trying to think about it. In general, playing with it gives me that $b \geq 3$ "guarantees" no value of $a$. Although proving the statement formally seems to take me forever. Initially, I tried to bring it to quadratic form in $a$, and if $b$ behaves like a constant, then we can see $P(a) \geq 0$ which imposes $D \leq 0$, but that implies $b^4+1 \leq 0$ which is absurd in the field we are working on. This somehow convinced me to try working on the cubic which doesn't seem to be factorizable either.
I would love a solution that could include the remedy and why my approach didn't work.
Thank you.
Comment: Try to prove that $f(a)=b^3-a^2b+2a$ is a decreasing function of $a$.
Comment: Ok @youthdoo so since $f'(a)=2-2ab$ and $(a,b) \in \mathbb{N}$ this implies $f'(a)<0$ thus the function is decreasing. Can you tell me how to proceed?
Answer: With $a, b \in \mathbb{N}$ and $a > b$, the only solution is $a = 2, b = 1$. To prove this, we rewrite the inequality as $$ba^2-2a-b^3 \leq 0,$$ with $a^2$ coefficient $b$, which is positive, and discriminant $4\left(b^4+1\right)$, which is also positive. Thus the solution over $\mathbb{R}$ is $$\frac{2-2\sqrt{b^4+1}}{2b} \leq a \leq \frac{2+2\sqrt{b^4+1}}{2b},$$ i.e. $$\frac{1-\sqrt{b^4+1}}{b} \leq a \leq \frac{1+\sqrt{b^4+1}}{b}.$$ Imposing the constraints $a > b$ and $a \in \mathbb{N}$, we require there to be an integer strictly greater than $b$ and less than or equal to $\frac{1+\sqrt{b^4+1}}{b}$. Since $b$ itself is a positive integer, this means the latter must be at least $b+1$, so $$\begin{align*}\frac{1+\sqrt{b^4+1}}{b} \geq b+1 &\iff 1+\sqrt{b^4+1} \geq b^2+b \qquad \text{(as } b > 0 \text{)} \\ &\iff \sqrt{b^4+1} \geq b^2+b-1.\end{align*}$$ If $b^2+b-1 \leq 0$, then this will automatically be true; but it's easily checked that there is no such $b \in \mathbb{N}$. Therefore, both sides will necessarily be positive, so we can square both sides to give $$\begin{align*}&b^4+1 \geq b^4+2b^3-b^2-2b+1 \\ &\iff 2b^3-b^2-2b \leq 0 \\ &\iff 2b^2-b-2 \leq 0 \qquad \text{(as } b > 0 \text{)} \\ &\iff \frac{1-\sqrt{17}}{4} \leq b \leq \frac{1+\sqrt{17}}{4} \\ &\iff b = 1 \qquad \text{(as } b \in \mathbb{N} \text{)}.\end{align*}$$ Finally, setting $b = 1$ in the original inequality yields $$\begin{align*}a^2-2a-1 \leq 0 &\iff 1-\sqrt{2} \leq a \leq 1+\sqrt{2} \\&\iff a \in \{1,2\} \qquad \text{(as } a \in \mathbb{N} \text{)}\end{align*}$$ but since $a > b$, only $a = 2$ is a valid solution, completing the proof.
Comment: That is really elegant I must say (in the sense that no advanced stuff was used) and pretty much every step explains itself. Thanks a lot!
Comment: As an aside, you can greatly simplify the work by observing that $(1+ \sqrt{b^4 + 1) } / b <   ( 1 + b^2 + 1/(2b^2) ) / b   $. The RHS is clearly  $ < b+1$ EXCEPT when $ b =1$. Hence, we must have $b =1 $, and subsequently show that $ a = b+1$.  $\quad$ This in part explains why you and I end up with the same $ 2b^2 - b - 2 \leq 0 $ inequality.
Comment: You're very welcome! It's indeed the case that with polynomial inequalities in only $2$ variables, you generally don't need any advanced techniques. In this case it was particularly nice as the highest power of $a$ in any of the terms was $a^2$, so, with it being quadratic, there were straightforward expressions for the roots. If it was e.g. $a^3b$ instead, then you'd need to use calculus, along the lines of what the commenter above suggested.
Comment: AMGM isn't involved. Just 1/ Binomial theorem $1+b^4 < [ b^2 + 1/(2b^2) ]^2$ and 2/ Comparing terms: (1+1/(2b^2) ) < 2 $.
Comment: Ah, yes, my mistake.
Answer: First, for the error in your reasoning:
Note that (with $b$ fixed) solving for $P(a) \geq 0 $ does not impose $ D \leq 0$.
That is true only if $P(a) \geq 0 $ for all values of $a$ (which the problem doesn't require).
In this case, substantiated by your observation that $ D = 1+b^4 > 0 $, we know that for each $b$, there will be some positive and negative values of $P(a)$.
To find which are the valid $a$ values, we have to find the roots of the quadratic equation. This is essentially shown by Prasiortle.

Now, for a quick solution:
Write the inequality as $ \frac{2}{b} \geq \frac{ a^2 - 1}{a}$.
Observe that for $ a \geq 2$, we always have $ a < a^2 - 1$.
Hence, for this inequality to hold true, we must have $ \frac{2}{b} \geq \frac{ a^2 -1 }{ a} > 1 $, or that $ b =1$.
Thus, this gives us $ 2a \geq (a^2 -1 )$, or that $ a = 2$.

Now, for my original solution using a different method.
Let $ a = b + k$ where $ k$ is a positive integer.
Then the inequality becomes
$$ 2b + 2k \geq 2b^2k + bk^2. $$
From here, since

$2b < bk^2$ except when $ k = 1$
$2k \leq 2b^2k$

It follows that we must have $k = 1$.  This then gives us
$$2b + 2 \geq 2b^2 + b $$
and solving the quadratic shows us that the only positive integer solution is $ b = 1$.
Hence, the only solution is $ (a, b) = (2, 1)$.
Comment: @TheRevolution My approach gets rid of the cubic term, which is why I chose it. $\quad$ Another way of writing it (which I've just added) is that we want $ 2a \geq b (a^2 - 1) $ ,and since $ a < a^2 - 1$ for $ a \geq 2$, we must have $ 2 > b \Rightarrow b = 1$.
Comment: Thanks a lot for pointing out my original mistake. I really wanted that :)
Comment: Also this solution is quite unique and feels natural as well.


What is a "link template" in a token?

Question: When configuring a webform submission URL by using tokens, I noticed this entry that specifies a link template:

<code>[webform_submission:url:?]
</code>
The URL of the webform submission. Replace the '?' with the link
  template. Defaults to 'canonical' which displays the submission's
  data.

What is a link template? Can I customize or define my own? How would I know what other tokens can be used in place of 'canonical'?
Answer: Link templates are defined in the entity class. For webform_submission:
<code> *   links = {
 *     "canonical" = "/admin/structure/webform/manage/{webform}/submission/{webform_submission}",
 *     "access-denied" = "/admin/structure/webform/manage/{webform}/submission/{webform_submission}/access-denied",
 *     "table" = "/admin/structure/webform/manage/{webform}/submission/{webform_submission}/table",
 *     "text" = "/admin/structure/webform/manage/{webform}/submission/{webform_submission}/text",
 *     "yaml" = "/admin/structure/webform/manage/{webform}/submission/{webform_submission}/yaml",
 *     "edit-form" = "/admin/structure/webform/manage/{webform}/submission/{webform_submission}/edit",
 *     "notes-form" = "/admin/structure/webform/manage/{webform}/submission/{webform_submission}/notes",
 *     "resend-form" = "/admin/structure/webform/manage/{webform}/submission/{webform_submission}/resend",
 *     "duplicate-form" = "/admin/structure/webform/manage/{webform}/submission/{webform_submission}/duplicate",
 *     "delete-form" = "/admin/structure/webform/manage/{webform}/submission/{webform_submission}/delete",
 *     "collection" = "/admin/structure/webform/submissions/manage/list"
 *   },
</code>
Source: https://git.drupalcode.org/project/webform/blob/8.x-5.x/src/Entity/WebformSubmission.php
Comment: Awesome! Thanks, 4x4.

What is a "link template" in a token?


CalcI -- Fundamental Theorem of Calculus Question

Question: So I'm given:
$h(1) = -2$
$h'(1) = 2$
$h''(1) = 3$
$h(2) = 6$
$h'(2) = 5$
$h''(2) = 13$
The question is find $$\int_{1}^{2} h''(u) \text{d}u$$
So based on the Fundamental Theorem of Calculus (part 2) $\int_{a}^{b} f(x)\text{d}x = F(b) - F(a)$
I would figure that :
$h''(u) = h'(2) - h'(1) == 3$
Is that the right way of looking at this?
Thanks for any insight.
Comment: Thanks for the edits Moron. Each time I'd go to edit, it would bark and say you'd already done it ;)
Comment: Are you given that $h''(u)$ is continuous?
Comment: Oh, yes sorry. $h''(u)$ is continuous everywhere
Comment: Then looks like you have it :-)
Comment: Excellent. The stumbling point is that I was wondering if the extra information the question provided was supposed to be used somehow. Thanks for the quick responses.
Comment: @Natey: I have added an answer. Please check the tick mark next to it. This will prevent this question from being bumped up periodically.
Comment: Don't you mean $\int_{1}^{2} h''(u) \text{d}u = h'(u)|_1^2 = h'(2) - h'(1) = 3$?
Answer: Given that $h''(u)$ is continuous, you have it right.
Answer: $h(x) = a x^3 + b x^2 + c x +d $
$h^{\prime\prime}(x) = 6ax + 2b$
to find $a$ and $b$ solve the equations
$h^{\prime\prime}(1) = 3$ and $h^{\prime\prime}(2) = 13$
now
$\int_1^2h^{\prime\prime}(x)dx = \left[3ax^2+2bx\right]_1^2 $
Comment: Where exactly did $h(x) = ax^3 + bx^2 + cx + d$ come from? Never mind, I see how you worked backwards. However, I think that's a little too involved for the question, as asked in the book. The reason I think that is because the question before it, which was similar, has an answer in the back which correlates to how I solved it above.