A Collatz generalization and approximation of a bounded-unbounded point of Collatz-like Functions

Question: I have been working on Collatz-like functions to test the probabilistic heuristic argument in favor of all trajectories being bounded (ending in a cycle) and have come up with a generalization to test this argument empirically. This leads me to two questions.
Let $f:\mathbb{N} \to\mathbb{N}$. The Collatz function states that the following iterated map will eventually equal to 1:
$$f(n) =
\begin{cases}
n/2,  & \text{if}\  2\mid n\\
3n+1, & \text{otherwise} \\
\end{cases}$$
My generalization is as follows:
Let $G:\mathbb{R} \to\mathbb{Z}$ defined as
$$G(x) =
\begin{cases}
x/2,  & \text{if}\  2\mid x\\
2\lceil ax \rceil, & \text{otherwise} \\
\end{cases}$$
where $a, x \in \mathbb{R}$. The Collatz function is the case when $a = 1.5$. Likewise, the $5n+1$ problem is the case when $a=2.5$.
I conjecture in line with the heuristic argument that if $-2 \leq a \leq 2$ then for any $x_0$, repeated iteration of $G$ on $x_0$ will yield a bounded trajectory. However, if $a>2$ or $a<-2$, for some $x_0$, repeated iteration of $G$ on $x_0$ will yield an unbounded trajectory. Note, $G(x)$ is bounded if for all $x_0$ we end in a cycle whereas unbounded means that G has at least one trajectory that diverges to infinity.

Is this a known generalization of the Collatz function? I have check as much as I could and found only discontinuous generalizations such as 1, 2, and 3.  On the other hand, $G(x)$ is continuous in the sense that it allows for both $x$ and $a$ to be any real numbers. Having this flexibility provides a way to test the probabilistic heuristic argument in favor of bounded trajectories by varying $a$ as close to 2 as possible, i.e. if $log(|a|) + log(1/2) < 0$, then for all $x_0$, iterations of $G(x)$ on $x_0$ will yield a cycle.

The function $H$ below is more global than $G$. Empirically, a bounded-unbounded point seems to exist for $H$ somewhere in the range  $c \leq 2b^2$. Is there a better way to approximate the bounded-unbounded point for the generalization $H$ than testing different values of $c$ for a given value of $b$.

$$H(x) =
\begin{cases}
\frac{x}{b},  & \text{if}\  b\mid x\\
b\lceil \frac{cx}{b^2} \rceil, & \text{otherwise} \\
\end{cases}$$
where $b,c \in \mathbb{N}$. The Collatz function is when $b = 2$ and $c = 6$.
Using Excel, when $b=3$, for $c \leq 16$, H appears bounded for all $x$ but for $c \geq 17$ it appears unbounded. Similarly, when $b = 5$, for $c \leq 35$, H appears bounded for all $x$ but for $c \geq 36$ it appears unbounded. For $b=7$ the demarcation point appears to be $c=65$. Taking the ratio $\frac{c_{max}}{b^2}$ where $c_{max}$ is the bounded-unbounded demarcation  point, gives
$\frac{c_{max}}{b^2}=2.0$ when $b = 2$
$\frac{c_{max}}{b^2}=1.8$ when $b = 3$
$\frac{c_{max}}{b^2}=1.5$ when $b = 4$
$\frac{c_{max}}{b^2}=1.4$ when $b = 5$
$\frac{c_{max}}{b^2}=1.4$ when $b = 6$
$\frac{c_{max}}{b^2}=1.3$ when $b = 7$
Seems that as $b \to \infty$ then, $\frac{c_{max}}{b^2}\to1$.
Any help will be greatly appreciated.
Comment: Math777 - no counterexamples so far, but I'm just playing a bit around. $G(x)$ is a nice idea, indeed, but I don't think I'm going to involve myself too much...
Comment: I observe that $G$ takes any $x \in \Bbb{R} \smallsetminus \Bbb{Z}$ to $G(x) \in \Bbb{Z}$, so letting $x$ be non-integral doesn't add anything.
Comment: Using Pari/GP (instead of excel) confirms @ericTowers cycle. Simply said, $g°^{764}(86)=86$
Comment: @GottfriedHelms You are correct. An oversight on my part. The formula I used in excel, with 19 in A1,  is =IF(MOD(A1,2)=0,A1/2,CEILING(9/4*A1,1)*2). Have you come across any counterexamples to the conjecture concerning G(x)? I haven't so far.
Comment: I'm curious: How does your analysis categorize the eventual behaviour of $19$ under iteration of $G$ when $a = 9/4$?  I find it is cyclic, with period $764$...
Comment: If I understood your question correctly, I would say that the closer '$a$'  approaches 2 from the right, the longer some cycles will be. Likewise, the closer '$a$' approaches 2 from the left, the longer it takes for $x$ to reach a cycle. So you may expect longer cycles if $a = 2.01$. On the other hand, the closer '$a$' is to $0$, the faster $x$ reaches a cycle.
Comment: I'm not asking about your conjecture.  I'm asking about your Excel calculations about a specific data point.
Comment: @EricTowers I completely misinterpreted your question. It is true, as Gottfried Helm pointed out, that when $a = 9/4$, $G^{764} $$(19)=19$  where  $G^i(x)$ is the $i$th iteration. This is expected. The two categories that values of $a$ will produce are all cycles (trivial or nontrivial) or at least one diverging trajectory (with trivial and/or nontrivial cycles).
Comment: Hmm, it seems the excel-calculation is wrong here. Pari/GP gives the sequence of iterates `19, [86,43,...,344,172],[86,43, ...` (where I've inserted the brackets to make the cycle better visible). The $19$ is ***not*** part of a cycle, so $G^{764}(19)=172$ instead, and only $G(19)=86$ is part/is beginning of a cycle. So if actually Excel gave $G(19)=19$ there must have been some numerical error... (and I may advertize for using something like Pari/GP for your calculations)
Comment: @GottfriedHelms Do you mind sharing your Pari/gp function. I posted a question in Stackoverflow but that site seems overwhelming busy (https://stackoverflow.com/questions/70524440/how-to-write-an-iterated-function-in-pari-gp). You could post it there. Thanks.
Comment: Math777 - see q&d Pari/GP approach for documentation in the new answer. Hope I didn't refer too much to my user-specific functions ("msep(matrix,columns)" to distribute the entries of a matrix in "columns" many columns) is one but can be omitted)
Answer: According to request of the asker, here is some Pari/GP -code, partly function-definitions, partly experimenting to get list of results.
<code>\\ test collatz with *real* bases for existence of cycles and/or divergence
\\ https://math.stackexchange.com/questions/4340764/a-collatz-generalization-and-approximating-the-bounded-unbounded-point-of-collat
\\ example set global variable "base" to some example value:

  base=9/4

g(x)=if(! (x % 2),x/2,2*ceil(base*x))

\\ alternative. g1(x) works on and produces only odd numbers. May be more
\\ efficient
g1(x)=my(A);A=valuation(x,2);x>>=A;x=2*ceil(base*x);A=valuation(x,2);x>>=A

  \\ print 800 steps of iterations, distributed over 5 columns ("msep(...,5)"),
  \\ beginning at a0=19 ("msep()" is user defined function)
printp( msep(Mat(vectorv(800,r,if(r==1,a0=19,a0=g(a0)))),5))

  \\ print the same, with a0=86, in one column but showing the index as well:
for(k=1,800,if(k==1,a0=86,a0=g(a0));if(a0==86,print([k,a0])))

  \\ print 800 steps of iterations, distributed over 10 columns,
  \\ beginning at a0=19 ("msep()" is user defined function)
  \\ we see, that a0=19 is not itself cyclic! but g(19)=86 is!
printp(msep(Mat(vectorv(800,r,if(r==1,a0=19,a0=g(a0)))),10))
</code>
Here we use two example bases, and call a loop, which checks for cycles in $a_0=1..999$ (only odd $a_0$) and cycle-lengthes of at most $10\,000$ iterations steps:
<code>fmt(2000);base=sqrt(5);fmt(200) \\ use another base. Take care, that
 \\ over many iterations numbers with many digits shall occur; choose
 \\ accordingly *big* decimal precision! (here 2000 dec digits)

fmt(2000);base=Pi-1;fmt(200)
  \\ or try this base near 2

\\ a loop to find cycles and protocol them:
{print("Base:",base);cyclist=List();
 forstep(a0=1,999,2,
   dir=Map();
   a1=a2=a0;found=0;ix1=ix2=0;mapput(dir,a1,0);
   for(k=1,10000,         \\ test for cycles with length up to 10 000
          a1=g1(a1);      \\ use g1() to document only odd steps
          if(!mapisdefined(dir,a1,&ix1),mapput(dir,a1,k);next());
          a2=a1;found=ix2=k;break();
       );
   if(!found, listput(cyclist,Str(a0," --- nothing found"));next());
     \\ find minimal element of the found cycle
   len=ix2-ix1; mina1=a1;for(k=1,len,a1=g1(a1);mina1=min(a1,mina1));
     \\ document the parameters for this a0, be it cycle or not:
   listput(cyclist,
      strprintf("%3d : %3d-->%3d cyclen:%3d enter cyc at val:%4d at pos:%3d \n",a0,mina1,mina1,len,a2,ix1));
   next();
   );
   cyclist=Mat(Col(cyclist)); \\ convert "cyclist" from Map to Mat
   printp(cyclist[1..8,]) } \\ show the first 8 entries.
</code>
This gave the following protocol (base = $\pi-1$). Only odd numbers were documented (using function $g_1(x)$) :
<code>    1 :   3-->  3 cyclen:  8 enter cyc at val:   3 at pos:  1 \n
    3 :   3-->  3 cyclen:  8 enter cyc at val:   3 at pos:  0 \n
    5 :   3-->  3 cyclen:  8 enter cyc at val:  11 at pos:  1 \n
    7 :   3-->  3 cyclen:  8 enter cyc at val:   7 at pos:  0 \n
    9 :   3-->  3 cyclen:  8 enter cyc at val:  11 at pos:  2 \n
   11 :   3-->  3 cyclen:  8 enter cyc at val:  11 at pos:  0 \n
   13 :   3-->  3 cyclen:  8 enter cyc at val:   7 at pos:  1 \n
   15 :   3-->  3 cyclen:  8 enter cyc at val:  15 at pos:  0 \n
   17 :   3-->  3 cyclen:  8 enter cyc at val:  11 at pos:  3 \n
   19 :   3-->  3 cyclen:  8 enter cyc at val:  41 at pos:  1 \n
   21 :   3-->  3 cyclen:  8 enter cyc at val:   7 at pos:  4 \n
   23 :  63--> 63 cyclen: 10 enter cyc at val:  63 at pos:  4 \n
   25 :  63--> 63 cyclen: 10 enter cyc at val:  63 at pos:  3 \n
   27 :  63--> 63 cyclen: 10 enter cyc at val:  63 at pos:  2 \n
   29 :  63--> 63 cyclen: 10 enter cyc at val:  63 at pos:  1 \n
   31 :   3-->  3 cyclen:  8 enter cyc at val:  11 at pos:  4 \n
   33 :   3-->  3 cyclen:  8 enter cyc at val:  33 at pos:  0 \n
   35 :  63--> 63 cyclen: 10 enter cyc at val:1639 at pos: 46 \n
   37 :   3-->  3 cyclen:  8 enter cyc at val:  11 at pos:  2 \n
   39 :   3-->  3 cyclen:  8 enter cyc at val:   7 at pos:  5 \n
   41 :   3-->  3 cyclen:  8 enter cyc at val:  41 at pos:  0 \n
   43 :  63--> 63 cyclen: 10 enter cyc at val:  63 at pos:  5 \n
   45 :   3-->  3 cyclen:  8 enter cyc at val:   7 at pos:  3 \n
   47 :   3-->  3 cyclen:  8 enter cyc at val:  33 at pos: 25 \n
   49 :   3-->  3 cyclen:  8 enter cyc at val:  11 at pos: 18 \n
   51 :   3-->  3 cyclen:  8 enter cyc at val:  11 at pos:  7 \n
   53 :   3-->  3 cyclen:  8 enter cyc at val:  33 at pos:  3 \n
   55 :   3-->  3 cyclen:  8 enter cyc at val:  11 at pos:  6 \n
   57 :   3-->  3 cyclen:  8 enter cyc at val:  33 at pos:  2 \n
   59 :   3-->  3 cyclen:  8 enter cyc at val:  11 at pos:  5 \n
                                            61 --- nothing found
   63 :  63--> 63 cyclen: 10 enter cyc at val:  63 at pos:  0 \n
   65 :  63--> 63 cyclen: 10 enter cyc at val:1639 at pos: 47 \n
   ...
</code>
and this is the version using $g(x)$ which allows to display even values in the orbit (which also means, the documented cycle-lengthes are longer than with $g_1(x)$):
<code>    3 :   3-->  3 cyclen: 25 enter cyc at val:   3 at pos:  0 \n
    5 :   3-->  3 cyclen: 25 enter cyc at val:  22 at pos:  1 \n
    7 :   3-->  3 cyclen: 25 enter cyc at val:   7 at pos:  0 \n
    9 :   3-->  3 cyclen: 25 enter cyc at val:  22 at pos:  5 \n
   11 :   3-->  3 cyclen: 25 enter cyc at val:  11 at pos:  0 \n
   13 :   3-->  3 cyclen: 25 enter cyc at val:  14 at pos:  3 \n
   15 :   3-->  3 cyclen: 25 enter cyc at val:  15 at pos:  0 \n
   17 :   3-->  3 cyclen: 25 enter cyc at val:  22 at pos:  9 \n
   19 :   3-->  3 cyclen: 25 enter cyc at val:  82 at pos:  1 \n
   21 :   3-->  3 cyclen: 25 enter cyc at val:  14 at pos: 13 \n
   23 :  63--> 63 cyclen: 31 enter cyc at val: 126 at pos: 10 \n
   25 :  63--> 63 cyclen: 31 enter cyc at val: 126 at pos:  7 \n
   27 :  63--> 63 cyclen: 31 enter cyc at val: 126 at pos:  4 \n
   29 :  63--> 63 cyclen: 31 enter cyc at val: 126 at pos:  1 \n
   31 :   3-->  3 cyclen: 25 enter cyc at val:  22 at pos: 13 \n
   33 :   3-->  3 cyclen: 25 enter cyc at val:  33 at pos:  0 \n
   35 :  63--> 63 cyclen: 31 enter cyc at val:3278 at pos:136 \n
   37 :   3-->  3 cyclen: 25 enter cyc at val:  22 at pos:  7 \n
   39 :   3-->  3 cyclen: 25 enter cyc at val:  14 at pos: 17 \n
   41 :   3-->  3 cyclen: 25 enter cyc at val:  41 at pos:  0 \n
   43 :  63--> 63 cyclen: 31 enter cyc at val: 126 at pos: 14 \n
   45 :   3-->  3 cyclen: 25 enter cyc at val:  14 at pos: 11 \n
   47 :   3-->  3 cyclen: 25 enter cyc at val:  66 at pos: 77 \n
   49 :   3-->  3 cyclen: 25 enter cyc at val:  22 at pos: 57 \n
   51 :   3-->  3 cyclen: 25 enter cyc at val:  22 at pos: 23 \n
   53 :   3-->  3 cyclen: 25 enter cyc at val:  66 at pos:  9 \n
   55 :   3-->  3 cyclen: 25 enter cyc at val:  22 at pos: 20 \n
   57 :   3-->  3 cyclen: 25 enter cyc at val:  66 at pos:  6 \n
   59 :   3-->  3 cyclen: 25 enter cyc at val:  22 at pos: 17 \n
                                            61 --- nothing found
   63 :  63--> 63 cyclen: 31 enter cyc at val:  63 at pos:  0 \n
   65 :  63--> 63 cyclen: 31 enter cyc at val:3278 at pos:140 \n
  ...
</code>
Comment: Appreciated. Would it have been better to post this answer over  https://stackoverflow.com/questions/70524440/how-to-write-an-iterated-function-in-pari-gp as requested?
Comment: @Math777 - hmm, don't know. But feel free to copy&paste this answer to any place you like, I'm currently much involved with different things... :-(


Erro limpar campo TextWatcher

Question: Pessoal utilizo o TextWacher no EditText, funciona perfeitamente e quando finalizo o cadastro coloco campo.setText(""); ele não limpa, fechar a aplicação e mostra um erro.
meu classe TextWatcher:
public class MoneyTextWatcher implements TextWatcher {
    private final WeakReference<EditText> editTextWeakReference;
    private final Locale locale;

    public MoneyTextWatcher(EditText editText, Locale locale) {
        this.editTextWeakReference = new WeakReference<EditText>(editText);
        this.locale = locale != null ? locale : Locale.getDefault();
    }

    public MoneyTextWatcher(EditText editText) {
        this.editTextWeakReference = new WeakReference<EditText>(editText);
        this.locale = Locale.getDefault();
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable editable) {
        EditText editText = editTextWeakReference.get();
        if (editText == null) return;
        editText.removeTextChangedListener(this);

        BigDecimal parsed = parseToBigDecimal(editable.toString(), locale);
        String formatted = NumberFormat.getCurrencyInstance(locale).format(parsed);

        editText.setText(formatted);
        editText.setSelection(formatted.length());
        editText.addTextChangedListener(this);
    }

    private BigDecimal parseToBigDecimal(String value, Locale locale) {
        String replaceable = String.format("[%s,.\\s]", NumberFormat.getCurrencyInstance(locale).getCurrency().getSymbol());

        String cleanString = value.replaceAll(replaceable, "");

        return new BigDecimal(cleanString).setScale(
                2, BigDecimal.ROUND_FLOOR).divide(new BigDecimal(100), BigDecimal.ROUND_FLOOR
        );
    }
}

A chamada no edit:
txtValorRecarga.addTextChangedListener(new MoneyTextWatcher(txtValorRecarga, mLocale));

E como estou limpando em outro método após a conclusão do envio do formulário:
txtValorRecarga.setText("");

Se alguém puder ajudar.
Answer: Voce pode tentar isto:
editText.removeTextChangedListener(yourTextWatcher);

Comment: O editText já é meu edit, e o yourTextWatcher o que seria?
Comment: O yourTextWatcher seria o seu editTextWeakReference

Erro limpar campo TextWatcher


In a piece for piano and vocals, when I move the vocal part down an octave do I also need to move the piano part down an octave?

Question: I'm a (not so experienced) guy and would like to try and learn a piece that has both a vocal part and a piano part.  Since I'm a male, I think I need to sing the piece from the image I've attached (and other pieces with a similar range) down an octave.  Is that standard practice for males?
If I do that, does that mean that I should also play the piano down an octave? On both hands?  I'm asking because I hear that the melody is generally supposed to be the highest part (in order to make it stand out).  But in the piece I've attached and others I've seen, bringing the vocal part down an octave would make it lower than the piano accompaniment's highest notes.  And then I've also seen pieces where bringing the left hand of the piano part down an octave would bring it off of an 88 key piano entirely.
So, if I sing the melody line an octave lower, should the piano accompaniment change too?
Comment: In answer to your question about transposing a female part down an octave: it will work sometimes but not always. It's more likely to work if you're transposing soprano to tenor or alto to baritone.
Answer: Basically no.  The problem is that a piano has disharmonicity and particular overtones.  Transposing a piano part one octave up makes it tinny and makes the bass notes not really register well as the building block of the harmonies.  Transposing it down one octave makes the basses muddy like anything and the chords a heavy-impact mess rather than a harmonic framework.
It is interesting that the guitar (which is played one octave lower than it is written) will have its root notes and chords work out better for accompaniment at their actual pitch than a piano would.
There is also this thing with male/female formants that makes a male voice one octave lower than a female voice actually blend better with the overtones of the female voice.
So basically transposing the piano part down along with the singing is a bad idea both because the piano sounds bad as accompaniment in that range and because of the different character of male and female voice.
Even when assuming a duet voice played in the piano, the piano's octave for the sake of harmonising is less important than it would be for a continuous-tone instrument like a reed organ or violin because there is no sustained equality of volume, the piano being a percussive instrument.
Comment: I'd love to see evidence/sources for "a male voice one octave lower than a female voice actually blend[s] better with the overtones of the female voice".
Answer: No.  Try it and you will see how awful it sounds.
There may be exceptions to this general rule, but they will be rare.  In fact, it is common for song collections to be available in different keys for high, medium, and low voice.  Were they specific to male or female singers, there would be twice as many editions, labeled for soprano, tenor, mezzo soprano, baritone, contralto, and bass.
Answer: Play the piano part as written.
In most song accompaniments (except in special situations like songs for young children, or where the player is meant to be leading the audience singing, etc) the accompaniment does not "double" the voice part, and it will work fine sung in either a male or a female voice range.
There may be a few exceptions to this in songs written in the past, where (1) the lyrics implied strongly that the singer could only be either male or female, and (2) LGBT was not yet a thing. But there is no "general rule" that applies to those rare situations - you just have to consider each song on its own merits.
Comment: Even if the lyrics imply that the narrative voice is of a particular gender, a singer of the other gene can often sing the song.  It's acting, after all.


What's the difference between univariate and multivariate cox regression?

Question: I'm dealing with oncology patients so it would be nice to know whether to use univariate or multivariate cox regression. I have some books on survival analysis but they don't elaborate the academic difference and interpretation of results regarding both methods.
Answer: I think that many people who use the words "multivariate regression" with Cox models really mean to say "multiple regression." (I will confess to having done that myself; it's common in the literature.) "Multiple regression" means having more than one predictor in a regression model, while "multivariate regression" is a term perhaps better reserved for situations where there is more than one outcome variable being considered together. In a Cox regression you are typically modeling just a single outcome variable, survival of some sort.
If you are preparing results for publication in a medical journal, the editors and reviewers will typically expect to see a table of single-variable relations of predictor variables to outcome (your "univariate" regressions). These single-variable relations, however, are seldom very informative due to relations among the values of the predictors and potential interactions among the predictors with respect to outcome.
These issues can be handled by Cox multiple regression, which gives you the best chance of evaluating each of the predictors with all the others taken into account, and which allows directly for testing of interactions. You have to be careful not to evaluate too many predictors together in a model, however. A useful rule of thumb is that you should limit your analysis to no more than 1 predictor per 10-20 events (recurrences or deaths in oncology) in a standard Cox multiple-regression model.
Note that there can be a true multivariate Cox regression that evaluates multiple types of outcome together (e.g., both recurrence and death times in cancer studies), or that treats multiple events on the same individual with multivariate techniques, as in standard multivariate linear regression. This paper is one often-cited reference, in case that is what you actually mean. But in my experience, I think most people in the clinical literature say "multivariate Cox regression" when they really mean "Cox multiple regression."
It would be wise to get some more direct advice from a local statistician, as there are many issues that need to be considered in building a reliable survival model. Working with an experienced practitioner can also be an efficient way to learn for yourself.
Comment: See [this page](http://stats.stackexchange.com/q/1053/28500) for many suggestions about references on survival analysis. As you will learn from those references, what matters for modeling is how many of the patients had "events" (e.g., recurrences) rather than the total number of patients. It seems that you will be OK on that basis provided that your recurrence rate is over 10% or so. You should still look for experienced help; try emails to people whose work you admire to ask for suggestions on statisticians who could help you. If this work is worth doing, it's worth doing well.
Comment: One important caveat, especially for oncology: a randomised trial may well have a single-variable (treatment-only) model for its primary analysis.
Comment: Thanks for the input. Unfortunately, I cannot find a biostatistician with extensive experience in survival models, so I would typically need to do my own research on textbooks or papers (if you have any suggestions, they are welcome). So far, I have 10 predictors for a sample of 1660 patients tested for disease free survival.
Answer: You should opt to do multivariable cox regression analysis (Not multivariate). As rightly point out by @EdM multivaraite means having more than one outcome variable, whereas, in survival analysis you have only one outcome variable, i.e. time-to-event of interest. Since, in oncology the group of patients under study, in most cases, is heterogenous, my advice would be to conduct multivariable analysis.


Log-likelihood of a exponential distribution

Question: I have an exercise that I don't quite understand:
The life of 100 lamps has been measured. Each lamp has been used with a intensity between 0 and 1, where 0 is off and 1 is the maximum intensity. It is known from experience that lamps of this type have an exponentially distributed for who long they last where the expected value can be written:
$$
\mu(s) = \frac{\beta}{s},\quad s>0,
$$
where β> 0 is an unknown parameter and s is the power (how bright they shine) at which the lamp is used.
The first task: Write down the log-likelihood for β given the observations.
My question is where to start? Should it be:
$$
Ln[\mu(\beta,s)] = ln(\beta) - ln(s)
$$
or am I doing it wrong?
Comment: Please add `self-study` as a tag and provide more details on your issues.
Answer: You start at the definition of the (negative) log-likelihood
$$\lambda = -\log P = -\log \prod_i p_i = -\sum_i\log p_i$$
where $P$ is the probability of observing the event that you observed (some lamps blew up and others did not). The big event that you observed consists of multiple small events, one for each lamp. Since lamps are independent, big event is a product of small events. Now you need to correctly plug in your probability distributions, simplify, and you should be done
Comment: How can you study log-likelihoods if you don't understand what a probability distribution is??? Log-likelihood is a much more advanced concept. Read this link, understand it, then come back https://towardsdatascience.com/probability-concepts-explained-probability-distributions-introduction-part-3-4a5db81858dc
Comment: Are the negative log-likelihood function since by time the glow of the lamps are getting weaker?

so i plug in () in p? So that I get log (lambda) = - sum( log(beta)-log(s)?
Comment: $\mu$ and $\beta$ are parameters. You must plug in the probability distributions into $p$. In your case they are exponential. Make sure that you evaluate the probability distributions at the observations that you acquired. Log-likelihood will depend both on parameters of the distributions, as well as on the exact observations on which lamps blew up and which did not
Comment: What is my "probability distributions"? Is that 1/s? I don't quite understand the concept. I do know how to use the log-likelihood on i.e. Possion distribution, but I don't understand this one and your answer.


How to set configuration value for drush site install?

Question: I have set a central translations directory(sites/all/translations) for my multisite installation profile so that each site does not have to download translations that were already downloaded.
I have set this via global settings file that I am including in the site's settings file, but it did not helped. Then I have added locale.settings.yml config into the profile, still no change. This works always AFTER the site was installed.
In the site installer there is a condition that checks if the config value for the directory exists in the global config variable, it will use that value or if not it will use the site's own translations directory by default.
So I think that during the installation process using config won't work and the only way is to use the global config variable.
So my question is how I can provide this variable to drush's site install command?
I am talking specifically about this: core/includes/install.core.inc:411
<code>  // Register the file translation service.
  if (isset($GLOBALS['config']['locale.settings']['translation']['path'])) {
    $directory = $GLOBALS['config']['locale.settings']['translation']['path'];
  }
  else {
    $directory = $site_path . '/files/translations';
  }
  $container->set('string_translator.file_translation', new FileTranslation($directory));
  $container->get('string_translation')
    ->addTranslator($container->get('string_translator.file_translation'));
</code>
Comment: I don't get what you are asking. If you want to control that path, then put just put it in settings.php?
Comment: @Berdir https://www.drupal.org/node/2646560
Answer: It is not possible to override this since the install_check_translations() has this hard-coded.


CheckStyle IDEA using suppression file for custom checks

Question: I have a maven repo with custom checks which I want all the other maven repos to depend on. I want to suppress checks for some generated code in one of my repos. There are 2 ways I can setup suppression file:

Have suppression file in the custom check repo, then specify SuppressionFilter in custom check style xml:
<module name="SuppressionFilter">
   <property name="file" value="${samedir}/checkstyle_suppressions.xml"
   default="src/main/resources/checkstyle_suppressions.xml"/>
</module>

Then in the maven plugin section of the pom.xml file of repo that I want to run custom checkstyle on:
    <suppressionsLocation>checkstyle_suppressions.xml</suppressionsLocation>
    <suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>

Do not put the SuppressionFilter section in the custom checkstyle xml. Have the same pom.xml setup for the repo to be checked. The suppression file can be placed local to the repo to be checked.

Both of the approach work with command line "mvn clean validate". But neither works with CheckStyle IDEA plugin for Intellij. The Intellij plugin complains it couldn't find the suppression file for the 1st method above.
I don't want to force every repo to have a suppression file if they don't need it. I wonder if there is a way to make suppression work for CheckStyle IDEA without having to have multiple copies of the same suppression file (1 in custom check repo, 1 in local repo).
Thanks!
Comment: Link to Github issue: https://github.com/jshiell/checkstyle-idea/issues/262
Answer: The logic the plugin uses is

does the file path resolve?
does the file path exist relative to the rules file?
does the file path exist relative to the module content roots, the module file or the project base directory?

If not, it gives up. So there's two possibilities:

there's a bug in the logic. Raise an issue on GitHub please.
it doesn't fit your use case. Raise a feature feature on GitHub, with a example to reproduce the problem and how you think resolution should be changed to fit your needs.

The code's in the resolveAssociatedFile method of https://github.com/jshiell/checkstyle-idea/blob/master/src/main/java/org/infernus/idea/checkstyle/model/ConfigurationLocation.java if you're interested.


When my response has a very skewed distribution, is it called unbalanced or imbalanced?

Question: It is only a question of terminology. I am not a native speaker and was wondering, which term is used in what situation.
Comment: (1) in machine learning I'd use "class imbalance" (2) for more traditional statistics (maximum likelihood) would use "skewed" (3) would not use unbalanced often, if at all
Comment: Patrick "unbalanced" usually refers to the design, not the response. @charles It's not clear why you'd add "(maximum likelihood)" there  -- a statistician that *doesn't* maximize likelihood would be just as likely to say "skewed". (Also, you have me curious -- would you really call it "class imbalance" even if your response didn't have classes?)
Answer: As far as I know, the only proper term for a skewed distribution is "skewed". "Imbalanced" seems to be used for categorical variables, where skewness isn't useful.
Comment: Not the question, but I see no objection to talking about the skewness of an ordinal variable, although have some queasiness about measuring it!


Extracting strings from a list by a specific word

Question: I have this column of addresses in pandas and I want to select only those addresses in the US, however I either get an empty string or thrown an error.
Here's what I have done:
0             238 Lincoln St, Hahnville, LA 70057, USA
1             101 Home Pl Ln, Hahnville, LA 70057, USA
2          1250 Poydras St, New Orleans, LA 70113, USA
3         1117 Broadway STE 401, Tacoma, WA 98402, USA
4              2715 N Junett St, Tacoma, WA 98407, USA
5          Hillstrust Primary School, 29 Nethan St, Govan, Glasgow G51 3LX, UK
6                                5778+JM Godalming, UK
7       569 Durham Rd, Low Fell, Gateshead NE9 5EY, UK
8                 Pennine Way, Barnard Castle DL12, UK
9               14 Studios Rd, Shepperton TW17 0QW, UK

matching = [s for s in final_data["full_address"] if "USA" in s]
matching
#returns: TypeError: argument of type 'float' is not iterable

#Whereas
ab = [final_data["full_address"]]
matching = [s for s in ab if "USA" in s]
matching
#returns: []

Expected output:
0             238 Lincoln St, Hahnville, LA 70057, USA
1             101 Home Pl Ln, Hahnville, LA 70057, USA
2          1250 Poydras St, New Orleans, LA 70113, USA
3         1117 Broadway STE 401, Tacoma, WA 98402, USA
4              2715 N Junett St, Tacoma, WA 98407, USA

Comment: https://stackoverflow.com/questions/22341271/get-list-from-pandas-dataframe-column-or-row
Comment: `df[df['full_address'].str.contains('USA')]`?
Answer: Try this:
import pandas as pd

data = {
    'full_address': [
        '238 Lincoln St, Hahnville, LA 70057, USA', '101 Home Pl Ln, Hahnville, LA 70057, USA', '1250 Poydras St, New Orleans, LA 70113, USA',
        '1117 Broadway STE 401, Tacoma, WA 98402, USA', '2715 N Junett St, Tacoma, WA 98407, USA', '5778+JM Godalming, UK', '569 Durham Rd, Low Fell, Gateshead NE9 5EY, UK',
        'Pennine Way, Barnard Castle DL12, UK', '14 Studios Rd, Shepperton TW17 0QW, UK'
    ]
}

df = pd.DataFrame(data)

matching = df[df['full_address'].str.contains("USA")]
print(matching)

Output:
                                   full_address
0      238 Lincoln St, Hahnville, LA 70057, USA
1      101 Home Pl Ln, Hahnville, LA 70057, USA
2   1250 Poydras St, New Orleans, LA 70113, USA
3  1117 Broadway STE 401, Tacoma, WA 98402, USA
4       2715 N Junett St, Tacoma, WA 98407, USA

Answer: Hello I have tried to recreate your scenario and in this it is working I just added a query with contain statement on specific column which is here is country
    import pandas as pd

    # Build cars DataFrame
    names = ['238 Lincoln St, Hahnville, LA 70057, USA', '101 Home Pl Ln, Hahnville, LA 70057, USA', 'Hillstrust Govan, Glasgow G51 3LX, UK']

    dict = { 'country':names}
    cars = pd.DataFrame(dict)

    b = cars.query('country.str.contains("USA")', engine='python')
    print(b)


How can I disable validation for an input that is disable in Angular?

Question: I have a form and in it some inputs. The inputs have css class: pointer-events: none, which disables the ability to edit the input (disable). I have the form validation done, unfortunately the button to save, does not unlock for me. Does this validation still work underneath despite the disable class being set? How could I achieve something like this, so that I only have to fill in the inputs that are not disable, and on this basis I can click on my button?
<input
   formControlName="numbers" [ngClass]="{'disabled-style': control.get('isTrue').value"
   [required]='control.get('isTrue').value'/>
<button (click)="save()">Save status</button>
</form>

Answer: If an input field is disabled using CSS (pointer-events: none in this case), it will still be considered as part of the form, but it won't be editable by the user. However, disabled fields are typically not included in form submission, so if you're relying solely on HTML form submission behavior, the disabled fields won't be included.
If you're using Angular's reactive forms, Angular will still consider disabled fields for validation purposes, regardless of their disabled status. Therefore, if you're using Angular's form validation mechanisms, disabled fields will still be validated.
In your case, it seems like you want to enable the "Save" button only if certain conditions are met, including whether the input field is not disabled. One way to achieve this is to dynamically enable/disable the button based on the validity of the form and the state of the input fields.
Here's an example of how you might do this in your Angular component:
<form [formGroup]="myForm">
  <input formControlName="numbers" [ngClass]="{'disabled-style': control.get('isTrue').value}" [required]="!control.get('isTrue').value" />
  <button (click)="save()" [disabled]="!myForm.valid || control.get('isTrue').value">Save status</button>
</form>

And in your component class:
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

@Component({
  selector: 'app-your-component',
  templateUrl: './your-component.component.html',
  styleUrls: ['./your-component.component.css']
})
export class YourComponent implements OnInit {
  myForm: FormGroup;

  constructor(private fb: FormBuilder) { }

  ngOnInit(): void {
    this.myForm = this.fb.group({
      numbers: ['', Validators.required],
      isTrue: [false] // Assuming this is a boolean control indicating whether the input should be enabled/disabled
    });

    // Subscribe to changes in the isTrue control to dynamically update validation
    this.myForm.get('isTrue').valueChanges.subscribe(value => {
      if (value) {
        this.myForm.get('numbers').clearValidators();
      } else {
        this.myForm.get('numbers').setValidators(Validators.required);
      }
      this.myForm.get('numbers').updateValueAndValidity();
    });
  }

  get control() {
    return this.myForm.controls;
  }

  save() {
    // Your save logic here
  }
}

In this example:

The "Save" button is disabled if the form is invalid
(!myForm.valid) or if the isTrue control is set to true.
The validation of the numbers field is dynamically updated based on
the value of the isTrue control. If isTrue is true, the
validation is cleared, allowing the field to be considered valid even
though it's disabled.

With this setup, the button will only be enabled if the form is valid and the conditions for enabling/disabling the input field are met.
Comment: This answer looks AI generated
Comment: a FormControl "disabled" is not invalid (the [status](https://angular.io/api/forms/FormControlStatus) of a form control can be VALID, INVALID, PENDING **or** DISABLED. So, if our formControl is disabled, it's not invalid and out FromGroup is not invalid. So you **should** disable the formControl instead clear validators.


Metric validity in Nearest Neighbors

Question: Does kNN algorithm require that the distance follows distance axioms? What happened if I apply a metric which fails:
<code>d(a,c) < d(a,b) + d(b,c)
</code>
Same question for KMeans clustering?
Comment: see my edit, it was a bit late when i answered yesterday, and it didnt cover everything
Answer: kNN only requires a proximity measure where the smaller value means closer. That is because kNN compares the new observation with the training examples and finds the k closest ones (the first k with the lowest proximity value).
For kMeans use search.
EDIT:
Even though kNN doesnt need the triangle equation, it runs in O(n*m) time, where n is the size of the training set and m is the size of the evaluated set. Optimizations usually require at least the triangle equation to stand, although some of them have more constraints (eg: k-d trees only work in euclidean space). See this question for more info.

Metric validity in Nearest Neighbors


Moved site to new server and I can't log in

Question: I'm migrating a client's site to a different server because we're changing web hosts. The domain name still points to the old site for now and I either use an ip address or a temporary url to preview the new site. However, since I moved it, I can no longer log in, I get an "access denied" error message. Is this a known issue? How can I resolve it?
EDIT: I oddly don't have this problem when I download the site to my hard drive and run it locally.
Comment: Did you clear out the sessions table and all of the cache tables?  Also, are you 100% positive that you are pointing to the correct database in settings.php?
Comment: I had this problem and running this in mysql: `repair table sessions;` resolved the issue.
Answer: This happened to me so many times back in the days of Drupal 6.
99% of the time it was caused by the anonymous user record having been removed from the users table in the database.
Try adding a user to that table with a uid of 0 (and all other fields empty); if the above is what's causing the problem, that should fix it.
Comment: Try looking in sites/default/settings.php at the `$cookie_domain` variable...does it match the new site's URL?
Comment: Thank you for your reply, Clive, but there already is such a user in the table... any other ideas? Thanks!
Comment: No but it's commented out... so I'm wondering if it would have any bearing. Also I tried playing around with it earlier on. to no avail unfortunately.
Comment: Hmm that's odd, especially since you mention the same codebase works on your local machine. I would guess that narrows it down to server configuration. Do you know if PHP sessions are enabled on the remote server?
Comment: Clive's $cookie_domain fix is the one I most often encounter, statistically speaking.


How to upload data via SQL to Amazon Redshift?

Question: I created a cluster and connected to the database via SQL Workbench, but how can I upload data via SQL to Amazon Redshift?
I guess I have to use Amazon S3 but I could not find a sample video or text that describes it well.
Comment: You mean put data in Redshift ? Yes you need to use S3 and execute a COPY command. Several documentations available.
Comment: @JonEkiz there is no other way ?
Answer: There are two ways to insert information into Amazon Redshift:

Via the COPY command
Via INSERT statements

It is not recommended to use INSERT statements because they are not efficient for large data volumes. They are okay for doing ETL-type processes such as copying data between tables, but as a general rule data should be loaded via COPY.
As per Using a COPY Command to Load Data, the COPY command can load data from:

Amazon S3 (recommended, highly parallel)
Amazon EMR (Hadoop)
Amazon DynamoDB
Via SSH from remote hosts

The load from Amazon S3 is performed in parallel across all nodes and is the most efficient way to load data.
The Amazon Redshift COPY command can read several file formats:

Delimited (eg CSV)
Fixed-Width
AVRO
JSON
And these formats can also be compressed (eg gzip)

Bottom line: Get your data into Amazon S3 in a compatible format, then use COPY to load it.
Also, try to understand DISTKEY and SORTKEY to get full performance benefits out of Redshift. Definitely read the manual -- it will save you more time than it takes to read!
Comment: What do you mean by an "sql file"? What is the format of the data in the file? And yes, you put the data in an S3 bucket, then run the `COPY` command within Redshift to import the data. If you're new to Redshift, try the [Introduction to Amazon Redshift self-paced lab](https://amazon.qwiklabs.com/focuses/2366) (it's free).
Comment: Well, I have a 5 GB sql file.As far as I understand, we first drop this file to S3 and then use the copy method to retrieve the data from S3.


How to create a view to count comments per user?

Question: I am trying to create a view with a table that shows all the users and the total number of comments that user posted in descending order. I am not sure what I am doing wrong but I spent hours on this already...
Can anybody point me to the right direction?
The closest I got is I created a view of comments so far with the author name that I tried to aggregate. But I am getting all sorts of weird results.
Comment: Without knowing what you did so far we can't tell you what you are doing wrong...
Comment: @leymannx Thank you for your quick reply. I got it working after all. I appreciate your willingness to help :) Thanks
Answer: I got it! Sharing my way ;)
What I did:

Created a view of comments of my type.
As fields, I added Author uid twice.
Set aggregation (COUNT) on the second Author uid.
Added a sort criteria for aggregated (Count) Author uid as descending.

woala... Wasn't that hard after all :)
Comment: This is not working for me. If I compare counts vs a comment view searching by uid, the totals are quite different.


RI-CLPM - Testing whether between and within effects significantly differ

Question: I am currently using a random intercept cross-lagged panel model (RI-CLPM; Hamaker, 2015) to assess between and within effects. For the same variables, we find a negative relation at the between level (correlation between random intercepts), but a positive relation at the within level (deviation at time t as a predictor of the outcome at t+1). I was wondering whether one would be able to conduct a test to assess whether the two effects are indeed different. After some searching, I found that the following formula may be used here, but I am unsure whether that is the case:

Does anyone have any thoughts on this? Or does anyone know of a paper that attempts to do the same?
Best,
Wout de Vries
Hamaker, E. L., Kuiper, R. M., & Grasman, R. P. P. P. 2015. A critique of the cross-lagged panel model. Psychological Methods, 20(1): 102–116.
Answer: I don't think that this formula would be correct because the coefficients are from the same sample. You would have to take into account the covariance of the coefficients as well. See, for example:
https://saturncloud.io/blog/how-to-compare-two-regression-coefficients-in-panel-data-multilinear-regression/#:~:text=The%20t%2Dtest%20is%20a%20statistical%20test%20that%20can%20be,two%20coefficients%20is%20statistically%20significant.
https://andrewpwheeler.com/2016/10/19/testing-the-equality-of-two-regression-coefficients/
A simpler way to test this hypothesis may be to constrain the paths to be equal and conduct a nested-model chi-square difference test relative to the model with freely estimated paths. Alternatively, you could conduct a Wald test of parameter constraints in software such as Mplus (using the MODEL CONSTRAINT and MODEL TEST options in Mplus).


Compare two lists in python and obtain non-equality

Question: This piece of code in theory have to compare two lists which have the ID of a tweet, and in this comparison if it already exists in screen printing , otherwise not.
But I print all or not being listed.
Any suggestions to compare these two lists of ID's and if not the ID of the first list in the second then print it ?
Sorry for the little efficient code . ( and my English )
What I seek is actually not do RT ( retweet ) repeatedly when I already have . I use Tweepy library , I read the timeline , and make the tweet RT I did not do RT
def analizarRT():
    timeline = []
    temp = []
    RT = []
    fileRT = openFile('rt.txt')
    for status in api.user_timeline('cnn', count='6'):
        timeline.append(status)
    for i in range(6):
        temp.append(timeline[i].id)
    for a in range(6):
        for b in range(6):
            if str(temp[a]) == fileRT[b]:
                pass
            else:
                RT.append(temp[a])
    for i in RT:
        print i

Solved add this function !
def estaElemento(tweetId, arreglo):
    encontrado = False
    for a in range(len(arreglo)):
         if str(tweetId) == arreglo[a].strip():
            encontrado = True
            break
return encontrado

Comment: Please edit the question and fix the indent error.
Comment: Can you please clearly explain, which list you are trying to compare against which other list? I only see one list in the code.
Comment: List 1 -> timeline, List 2 -> fileRT...anyway it is indifferent , fileRT has 6 elements (ID ) to compare with each list item timeline
Answer: Its a simple program, don't complicate it. As per your comments, there are two lists:)
1. timeline
2. fileRT
Now, you want to compare the id's in both these lists. Before you do that, you must know the nature of these two lists.
I mean, what is the type of data in the lists?

Is it

list of strings? or
list of objects? or
list of integers?

So, find out that, debug it, or use print statements in your code. Or please add these details in your question. So, you can give a perfect answer.
Mean while, try this:
if timeline.id == fileRT.id should work.
Edited:
def analizarRT():
    timeline = []
    fileRT = openFile('rt.txt')
    for status in api.user_timeline('cnn', count='6'):
        timeline.append(status)
    for i in range(6):
        for b in range(6):
            if timeline[i].id == fileRT[b].id:
                pass
            else:
                newlist.append(timeline[i].id)
    print newlist

As per your question, you want to obtain them, right?. I have appended them in a newlist. Now you can say print newlist to see the items
Comment: Thanks for the reply. very instructive.
Comment: Add some details dude, we can get this thing done :)
Comment: Thanks you Shiva Shinde !. Great Idea's....my data is different !
Comment: So, you mean this **list = ['Shiva', 123, 'Shinde', 456]**

and both timeline & fileRT are in same format?
Comment: Please try the above code, let me know if its working :)
Comment: Negative values keeps repeating , it does not recognize that the values are repeated !! ... Grrrrrrrrrrr
Comment: Add this above your nested-for-loop **print timeline[0].id**, see what it prints. In the same way, **print fileRT[0].id** and see what it prints
Answer: your else statement is associated with the for statement, you probably need to add one more indent to make it work on the if statement.


Prove that $\frac{1}{f\circ g} = \frac{1}{f} \circ g$

Question: I have to prove or disprove this:
$$\frac{1}{f\circ g} = \frac{1}{f}\circ g$$
or
$$\frac{1}{f\circ g} = f \circ \frac{1}{g}$$
I know that for the first if $f=\frac{1}{x}$ and $g=0$
then we can undefined for the $LHS$ and $0$ for the $RHS$.
The second is a bit easier but I'm having trouble formulating the prove, well disprove actually for both.
Comment: You need to properly specify domain and codomain for this to be a well-posed problem and any sensible choice will eliminate the "undefined" example as that is just a result of imprecision; also note that both sides are undefined for the choice you give.
Comment: Does it seem like there is any reason it should be true?
Comment: The first is true.  $\frac 1f\circ g(x)=\frac 1{f(g(x))}$ and $\frac 1{f\circ g}(x)= \frac 1{f\circ g(x)}= \frac 1{f(g(x))}$.  But the second is just nuts.  $f\circ 1{g}(x)=f\circ 1{g(x)} = f(\frac 1{g(x)})$ but $\frac 1{f\circ g}(x)= \frac 1{f\circ g(x)}= \frac 1{f(g(x))}$. Those aren't the same.
Answer: Big picture:
Composition is not reversible.  $h\circ j \ne j\circ h$ in general.
But it is associative.   $h\circ (j\circ k) = (h\circ j)\circ k$ because... well, you only are going in order.  If $k(x) = y$ and $j(y) = w$ and $h(w) =z$ then $[(h\circ j)\circ k](x) = (h\circ j)(k(x)) = (h\circ j)(y) = h(j(y))= h(w) = z$
while $[h\circ (j\circ k)](x) = h([j\circ k](x))=h(j(k(x))) = h(j(y))=j(w) = z$.
It's almost impossible to imagine how it is not.
....
Soooooo.... if $h(x) =\frac 1x$ then
$\frac 1{f\circ g} = h\circ (f\circ g) = (h\circ f)\circ g = \frac 1f \circ g$.
But $f\circ \frac 1g = f\circ h \circ g\ne h\circ f\circ g = \frac 1{f\circ g}$.
.......
If that is glib then just shove an elments into them and see what happens.  Let $g(x)=y$ and $f(y) = w$ then $\frac 1{f\circ g}(x) = \frac 1f\circ g(x) = \frac 1w$..... it works.
But
$f\circ \frac 1g(x) = f\circ \frac 1y$ and if we let $f(\frac 1y) = v$ and
$\frac 1{f\circ g}(x) = \frac 1{f(g(x))} =\frac 1{f(y)} = \frac 1w$.  The is utterly no reason that $\frac 1w = \frac 1{f(y)}$ should be equal to $v=f(\frac 1 y)$.
Coming up with a counter-example should be easy.  Just find an $f$ and $y$ where $f(\frac 1y)\ne \frac 1{f(y)}$ and a $g$ and $x$ were $g(x) = y$.
$g(x) = x+3$ and $f(y) = x^2 +5$ then $f\circ \frac 1g = (\frac 1{x+3})^2 + 5$ whereas $\frac 1{f\circ g} = \frac 1{(x+3)^2 + 5}$ for example.
Comment: just out of curiosity, the notation $\frac{1}{f\circ g}$ is necessarily informal, right? I mean...it doesn't make any sense to talk of a "fractional set of ordered pair" (where $f\circ g$ is the set of ordered pairs) . Only $\frac{1}{f\circ g (x)}$ makes technical sense, yes?
Comment: It's no more or less informal than the notation $\frac 1f$ is.  I don't think is informal.


Why don't we measure the size of intervals starting from zero?

Question: Note: italics such as "2nd" refer to my proposed notation; existing notation is written without italics: "2nd".
Why is the interval between C and D called a 2nd, as they are 1 note apart? Surely this should be called a 1st? Similarly, the interval between C and E should be a 2nd, from C to F should be a 3rd, and so on; rather than an "octave" we have rather a 7th. ("heptave"?) Naturally, the interval from middle C to middle C is a 0th, as the same note is at a distance of 0 from itself.
This would greatly simplify matters. For instance, if one makes a triad by stacking two 2nd's, then the resulting interval between the top and bottom notes is a 4th, as one would expect from 2 + 2 = 4. The same would be true for any addition of intervals. In contrast, in the currently-used notation if one stacks two 3rds, the resultant interval is a 5th. This is clearly the sort of off-by-one error that results from starting measurements from one. Are there any reasons besides existing tradition (which is of course quite a compelling argument) why this notation persists?
Comment: Because only programmers count starting at zero.  I like your system, especially since I made an off-by-one error today asking (erroneously) about 16va instead of 15.
Comment: I don't see how it makes any difference as long as the convention is well documented and well understood. VB programmers start arrays at index 1, most others at zero. Americans call the ground floor the first, Brits don't. It is not a problem.
Comment: A very plausible reason is historical.There is no notation for zero using Roman numerals. The Romans counted "inclusively" starting from 1 - for example the 13th day of a month was "the third day after the 11th day", not "the third day after the 10th". It seems likely that "inclusive" counting for naming musical intervals was well established before the concept of zero first became known in Europe, around 1200 AD - but I don't know a good authority for that statement about early music theory.
Comment: We have the opposite problem with numbers for the harmonic series: usually, the fundamental tone (with a frequency of, say, 1) is not called the first harmonic or overtone at all.  The note an octave higher (frequency of 2) is called the first harmonic, an octave and a fifth (frequency 3) is called 2, and so forth.  Don't spread this confusion.  The fundamental *is* the first harmonic.
Comment: It definitely would be better, but what can we do? Heck, even _mathematicians_ still use 1-based indexing (albeit not for something that's nothing but a difference), we're not going to convince a majority of the far more traditionalist musician occupation that zero-based is sufficiently advantageous to switch...
Comment: @Mike Actually, that question was the motivation for this question.
Comment: One is the note where you start
Comment: @ScottWallace No, the fundamental is *not* the first harmonic. It is, however the first partial.
Comment: See also: [Was the term "octave" coined after the development of early music theory?](https://music.stackexchange.com/a/107068/70803).
Comment: If you move enough (perfect) fifths you end up outside the scale and need flats and sharps anyway, not sure but maybe if you want consistency you could mentally map it to either string length ratios or to 0-11 indexed.
Comment: @user3235 - so "harmonic" is the same as "partial minus one"?  That's kinda silly.
Comment: @ScottWallace Yes, the harmonic number is the partial number minus 1.  It makes more sense if you think of all of the frequencies being a part (partial) of a tone, including the fundamental.  Harmonics, on the other hand, are only the frequencies **above** the fundamental.
Comment: @user3235 So what's the point of the "harmonic" designation?  It doesn't fit the math and adds nothing.  I say silly.
Comment: @ScottWallace Harmonics have a scientific lineage. Specifically in physics and electronics, harmonics are overtones of the fundamental that are integer multiples of the fundamental.
Comment: @user3235 Yes.  The first integer is one, it's the first harmonic, and it's also the fundamental.
Comment: @ScottWallace
Partials include all frequencies that constitute a tone, including the fundamental.
Overtones are all frequencies "over" the fundamental.
Harmonics are not so cut and dried.
According to Wikipedia "The difference between "harmonic" and "overtone" is that the term "harmonic" includes all of the notes in a series, including the fundamental frequency (e.g., the open string of a guitar)."
I disagree, since no guitarist ever refers to open strings or fretted notes as "harmonics".
The term harmonics is reserved for notes where a finger stops the fundamental from sounding.
Comment: @user3235 Yes, that's the way the terms are often used.  You are of course free to use whatever convention you like.  I will stick with the mathematically more accurate one.
Answer: I really think the answer to this question has most to do with how music is composed. Tonal composers are not really thinking at all about the math behind the intervals; they're thinking about the sounds.
Another way of looking at this is that all tonal music is scale-based, and when playing a scale from bottom to top you number the notes starting from 1. The names for intervals come right out of these scale formations. i.e. The "first note of the scale" and the "fifth note of the scale" create an interval of a "fifth". (And in order to figure out the quality of the interval--major or minor--you always need to construct a new scale starting on the bottom note, so the off-by-one issue doesn't really arise.) No one before the advent of computer technology would ever think of calling the first element of any ordered set of things the "zeroth" item.
That's as far as I'm going to try to go on the "why 1-indexing makes sense" route, but I want to give you this additional nugget to chew on:
We DO have zero-indexed intervals in modern music called 12-tone technique. Not only is this zero-indexed, but it's in base 12! (When you think about it, using zero-indexing in tonal music doesn't completely solve the problem of mathematical consistency, because you're still in base 10 and not base 7...)
12-tone technique is a MUCH more mathematical approach to composition, so it makes sense to use a number system that is more mathematically consistent (or in this case, completely consistent with 12-tone-equal-temperment).
It's interesting to watch musicians without a mathematical background try to get their heads around 12-tone analysis -- thinking with zero-index is hard enough for a non-programmer, but then switch out of base 10 and give equal importance to all of the chromatic notes and all of a sudden nothing makes sense anymore. ;-)
Comment: Just a quick addendum I've thought of since writing this: Since nearly all western music theory is learned with a keyboard (or at least with one close by), there is a strong STRONG link between counting on one's fingers and playing the first five notes of a scale. I'd bet that's where a good portion of this really comes from.
Comment: The most mathematically sound would be to always use zero indexed ordinal numbers. Ordinals describe the distance from the starting element. When you say "1st" it really means "0 steps from start" and "3rd" means "2 steps from start".
Comment: Yes please, using 0-indexed base-7 interval names would be awesome! That would give us names like 8th->10, 9th->11 and 13th->15. Which means that the names instantly shows what they are. That a 13th interval is an octave plus a 6th is not obvious, but it is very obvious that a 15 interval is a 10 plus a 5.
Answer: Let's think of a the C major scale. What note do you start on? You would start on a C. Would it make sense to call it the first note of the scale or the zeroth note of a scale? Most people would call that the first note of a scale as do musicians. That is why a D would be a second away because it is the second scale degree and then E is a 3rd away because it is the 3rd scale degree. This is why intervals are the way they are because the naming is more based on the position of the note on a scale (scale degrees) then the actual distance between the notes.
Let's just do a comparison with zero based note indexing and one based indexing:
    Notes:  C D E F G A B C D E  F  G  A  B  C
    Zero:   0 1 2 3 4 5 6 7 8 9  10 11 12 13 14
    One:    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

While it is easier to figure out compound intervals (intervals above an octave), I think it would be harder to think about the scale degrees that the intervals represent. To think that the second note of a scale is a 1st seems just if not more confusing to me than the distance  of one note to the next note being a 2nd.
Since music itself revolves around the use of scales it makes more sense to look at it from a scale degree point of view than an actual distance point of view. Sure counting intervals would be easier, but at least I feel it would be more difficult to look at from the perspective of a scale.
Comment: Yes ... but no. An interval is inherently about the _distance_ between two pitches. In a logical sense a distance of zero would unambiguously mean the same pitch. However, the tradition is that an interval of a 1st means "the same pitch" and an interval of a second means the next consecutive pitch in a scale. In practice we don't often talk about an interval of a "first" so the confusion only arises when we talk about intervals larger than an octave, e.g. what is an interval of two octaves called?
Comment: Right, but if we had just always called the initial note the 0th scale degree, that wouldn't seems weird at all.
Comment: @RichardPadley My point was the names of intervals relate to the scale degree. An F is the 4th scale degree of a C scale and is a 4th in distance. In music those two ideas are intertwine.
Comment: It's probably appearing confusing because we're so used to the original numbering system. Dom, from C to F, distance-wise, is actually 3 in distance. I don't mean a third, but look - C-D-E-F ;there are only 3 spaces.Space = distance. Was there ever a year 0 A.D. Doubt it. The first note in a key (root note) needs to be 1, just like the winner of a race (the first) is 1.                          However, when we talk about which octave a note is in, don't we use , for example, Co ?
Answer: The intervals come from note positions in the scale. The primero is the tonic, so the C in C major. The D would be the secondo, and the interval is a second. etc...
Answer: These off-by-one errors don't stem from 1-indexing of the notes but from the fact that instead of defining the (numerical) interval from X to Y as the number of increases from X to Y (which is Y-X), we define it as the number of notes from X to Y inclusive (which is Y-X+1). This is perfectly natural from a musical point of view: play three successive notes of the scale and you have a third.
Using the Y-X -definition for an interval does not greatly simplify the mathematics either. For example even with the traditional definition you can add any successive intervals A1, ..., An together by (A1-1)+(A2-1)+...+(An-1)+1 (proof: exercise).
Comment: Isn't counting inclusively the same thing as 1-indexing?
Answer: A slightly different answer from the others is this: the issue comes up when you think of intervals in cardinal terms rather than ordinal terms.  While it isn't "wrong" to do so, it isn't "wrong" to think of them ordinally either.
Historically, intervals have been perceived as a musical entity in their own right, rather than a quantification of a distance between two notes.  Therefore, the classification of intervals involves their being arranged in order, from smallest to largest.
This point is important to the reason for ordinality.  Two people singing the same note are singing an interval called a "unison", or "singing in unison".  This interval is also called the Prime interval, or interval of a first.  Therefore, the interval that is one more than the first is called the interval of a second, and so on.
I won't get into why there are only 8 intervals in a 12-note scale...
Comment: What do you mean by "Historically, intervals have been perceived as a musical entity in their own right, rather than a quantification of a distance between two notes"? Are you talking about counterpoint? (Since this was answered so long ago, is there some sense in which this is true, and some sense in which it isn't?)
Comment: @awelotta Are you familiar with "diabolus in musica"? That would be an example of what I mean by an interval perceived as a musical entity.
Comment: Yet, people (nowadays at least) call that interval the "tri"-tone as well, which doesn't diminish the emphasis on it's dissonance than an ordinal label. How is "quantification" of distance different from "musical entity"?
Comment: @awelotta Well, how do you think it's different?
Comment: Ordinal labels suggests an underlying scale, as mentioned by the other answers. And unison emphasizes that the notes are the same. Is this what you had in mind?
Comment: @awelotta Ok. No, I had something else in mind. Again, while ordinal labels suggest an underlying scale, so do cardinal labels. But the original idea behind intervals was the first interval, the second interval, the third interval, etc. In this case, it's the intrinsic nature of the interval, rather than the number of notes on the scale that they are apart, that determines what interval it is. (Why are fourths and fifths perfect? Because they don't vary in the modes that were commonly in use. ...
Comment: ... The exception was Lydian mode, which used "round B" to avoid *diabolus in musica*, and as such became the first accidental.) The concept of quantity of scale degrees defining the interval came later.
Comment: So what you're saying is: Ordinal names are more like nouns (e.g. a fourth; or; the interval, which is the fourth of the eight/infinite intervals); whereas cardinal names are more like descriptions (e.g. this interval is three-big). ?
Comment: @awelotta I could go along with that. :) When I think about a piano passage that's in octaves, for example, I'm thinking more about the thicker sound, and what octaves sound like. I'm not thinking about an interval of an 8th, or two notes seven scale degrees apart, or two notes in a 2:1 frequency ratio, or anything like that. So yeah, an octave is a noun in that sense.
Answer: Yes!! This is why I prefer set theory. In the definition of interval and sets used in that system, 0 is always the starting point (usually, nowadays, C is arbitrarily defined as 0. So what used to be called a M3, is just pi4 (pitch interval four), and a m7th is pi10. The old system however, is just too well known to eradicate, and that's probably just as well...
Answer: The best answer here is given by user19146, that the reason is historical.
According to an article in Scientific American, zero reached Europe by the 1100's, but it was not in common use. Sir Isaac Newton used Roman numerals in the late 1600's, so it is no surprise that music used system starting from one.
While a zero based interval system is preferrable, the current system is just too entrenched to be changed. Very much the way the U.S. will probably never convert to metric.


Knockout-Validation - Date greater than another date

Question: I've been looking at the different methods of using knockout-validation to compare dates. I can't get it to work with my obervables in a validatedObservable object.
I need the validatedObservable for checking if the validation passed/ failed on the button click - it's my grouping of controls.
Here's my demo:

<form>

            Name:
            <input type="text" data-bind="value:contactForm().name" value="" />

            From:
            <input type="text" data-bind="value:contactForm().fromDate" value="" />

            To:
            <input type="text" data-bind="value:contactForm().toDate" />

    <button type="button" data-bind='click: submit'>Submit</button>
</form>

I basically can't get the this line working:
toDate: ko.observable('2014-11-10').extend({date: true, min: this.fromDate })

anyone any ideas?
Answer: That's because you're using this in an object literal creation (when you refer to fromDate in toDate declration), and upon constructing that object, this is still referring to the encapsulating function context (myViewModel in this case).
Try this instead (based on this answer):
self.contactForm = ko.validatedObservable({
            name: ko.observable().extend({ required: true }),
            fromDate: ko.observable('2014-11-10').extend({ date: true }),
            toDate: ko.observable('2014-11-10'),
            init: function() {
                this.toDate = this.toDate.extend({date: true, min: this.fromDate});
                return this;
            }
        }.init());

Comment: Thank you for this, was at it for hours


Getting an error on field module when saving a node

Question: When I'm saving a node using node_save, I'm getting the following fatal error:
Fatal error: Maximum execution time of 30 seconds exceeded in /data/www/www.example.com/htdocs/modules/field/field.attach.inc on line 664
This is not happening every time node_save is called, only for a certain new node and I can't find anything strange about the fields I'm populating. Any clue?
Comment: Try to install xhprof and check why node_save works so long
Answer: I would check cck fields to find which one causes the issue first and go from there, the error message related to 'fetch entities from cache, if applicable'.


Python / Pygame - Get a square to change colour with classes

Question: I am making a little project for a Battleships game, but I am having a little trouble with getting the code to understand when I click on the object, I want it to change colour.
So far I have this class:
class Tile:
def __init__(self, xstart, ystart, game_display, colour):
    self.tile = pygame.Rect(xstart, ystart, 50, 50)
    pygame.draw.rect(game_display, colour,  self.tile, 1)
    print(self.tile)

def ChangeColour(self, game_display, colour):
    pygame.draw.rect(game_display, colour,  self.tile, 0)

I create the board using this function I made:
def new_board():
global board
xstart = 70
ystart = 50
#pygame.draw.rect(game_display, BLACK, (70, 50, 500, 500), 3)
for square in range(PLAYER_NUMBER_SQUARES):
    board.append(Tile(xstart, ystart, game_display, BLACK))
    xstart += 50
    if xstart == 570:
        ystart += 50
        xstart = 70
return board

So far, I has added the square / rectangle objects to the list "board", when the player clicks, I get the pixel and use this method to get which square it is that has been clicked:
def get_x_number(x):
index = None
if x >= 70 and x < 120:
    index = 70
if x >= 120 and x < 170:
    index = 120
if x >= 170 and x < 220:
    index = 170
if x >= 220 and x < 270:
    index = 220
if x >= 270 and x < 320:
    index = 270
if x >= 320 and x < 370:
    index = 320
if x >= 370 and x < 420:
    index = 370
if x >= 420 and x < 470:
    index = 420
if x >= 470 and x < 520:
    index = 470
return index

def get_y_number(y):
index = None
if y >= 50 and y < 100:
    index = 70
if y >= 100 and y < 150:
    index = 120
if y >= 150 and y < 200:
    index = 170
if y >= 200 and y < 250:
    index = 220
if y >= 250 and y < 300:
    index = 270
if y >= 300 and y < 350:
    index = 320
if y >= 350 and y < 400:
    index = 370
if y >= 400 and y < 450:
    index = 420
if y >= 450 and y < 500:
    index = 470
return index

(I know this is a slightly more long winded way, but if there is a better way, let me know, tried loops, couldn't get it to work.)
Finally, I get to where it will get the clicked square, however it doesn't change the square, this is because when I index the square out of the list, it returns this: <__main__.Tile object at 0x068A5590>
How can I get it to return the pygame.Rect rather than this? I have had a look into classes, tried __repr__ and __str__ and had no joy, if someone can assist me, that would be great!
Thank you!
Answer: I recommend making your Tile class a pygame.sprite.Sprite subclass and then adding all tiles to a sprite group. That allows you to update and draw all sprites by calling sprite_group.update() and sprite_group.draw(screen). Pygame sprites need an image (which has to be a pygame.Surface instance) and a rect attribute.
To check for collisions you can first iterate over the sprites in the sprite group and then use the collidepoint method of the sprite's rect to see if it collides with the mouse position, e.g. sprite.rect.collidepoint(event.pos) or pygame.mouse.get_pos(). If it collides with the mouse, call the change_color method and fill the image of the sprite with the new color (or you could also replace the image).
import pygame as pg

GREEN = pg.Color(0, 200, 90)
BLUE = pg.Color(0, 90, 200)

class Tile(pg.sprite.Sprite):

    def __init__(self, position):
        super().__init__()
        self.image = pg.Surface((50, 50))
        self.color = GREEN
        self.image.fill(self.color)
        self.rect = self.image.get_rect(topleft=position)

    def change_color(self, color):
        self.color = color
        self.image.fill(self.color)

def main():
    screen = pg.display.set_mode((800, 600))
    clock = pg.time.Clock()
    all_sprites = pg.sprite.Group()
    # Create the tiles and add them to the all_sprites group.
    for y in range(10):
        for x in range(12):
            all_sprites.add(Tile((x*51, y*51)))

    done = False

    while not done:
        for event in pg.event.get():
            if event.type == pg.QUIT:
                done = True
            # If a mouse button was pressed.
            elif event.type == pg.MOUSEBUTTONDOWN:
                # Iterate over the sprites in the group.
                for sprite in all_sprites:
                    # Check if the sprite's rect collides with the mouse pos.
                    if sprite.rect.collidepoint(event.pos):
                        # Finally change the color.
                        sprite.change_color(BLUE)

        all_sprites.update()
        screen.fill((30, 30, 30))
        all_sprites.draw(screen)

        pg.display.flip()
        clock.tick(30)

if __name__ == '__main__':
    pg.init()
    main()
    pg.quit()

Comment: Here's a [pygame sprite tutorial](http://programarcadegames.com/index.php?chapter=introduction_to_sprites⟨=en#section_13). Of course you can also keep using a normal class and a list for the moment, however, sprites and groups are usually a bit more comfortable to use.
Answer: So, I think it'd be substantially easier to use a loop (as you asked for suggestions).  In this method you get access to all tiles that were pressed, then you can execute changeColor.
import pygame

class Tile:
    def __init__(self, xstart, ystart, game_display, colour):
        self.tile = pygame.Rect(xstart, ystart, 50, 50)
        self.game_display = game_display
        self.colour = colour
        self.draw()

    def draw(self):
        pygame.draw.rect(game_display, colour,  self.tile, 1)

    def changeColour(self, colour):
        self.colour = colour
        self.draw()

    def doesHit(self,point):
        return self.tile[0] <= point[0] and self.tile[2] > point[0] and self.tile[1] < point[1] and self.tile[4] >= point[1]

def getTile(x,y):
    global board
    point = (x,y)
    for tile in board:
        if tile.doesHit(point):
            print("hit detected!")
            #now we have direct access to all tile information via tile!


What is the difference between Symmetric vs Skew Symmetric?

Question: I want to know the difference between Symmetric Symmetric vs Skew Symmetric?
Answer: $$
\mathbf{Symmetric}: \quad M^T=M
$$
$$
\mathbf{Skew\text{-}symmetric}: \quad M^T=-M
$$
Answer: A symmetric matrix satisfies $A^T = A$
A skew-symmetric matrix satisfies $A^T = -A$.
Additionally, it is a fact that every matrix can be written as the sum of a symmetric matrix and a skew-symmetric matrix:
$$
A = \frac{1}{2}(A + A^T) + \frac{1}{2}(A - A^T)
$$
then $B = \frac{1}{2}(A + A^T)$ is symmetric since
$$
B^T = \frac{1}{2}(A + A^T)^T = \frac{1}{2}(A^T + A) = B
$$
and $C = \frac{1}{2}(A - A^T)$ is skew-symmetric:
$$
C^T = \frac{1}{2}(A - A^T)^T = \frac{1}{2}(A^T - A) = -C
$$
Answer: Skew-symmetric:
$A=-A^T$
Check out this definition


Composer - enabling update by deletion of entry in composer.lock

Question: I regularly observe the following behaviour:
When I try to execute composer update mynamespace/myproject, it fails because if conflicts with a dependent project "mynamespace/mydependency", which is 'locked' at a specific version - the version specified in the composer.lock file. I don't get what 'locked' means in that context, but I observe that the update works well once I deleted the entry
{
  name : "mynamespace/mydependency"
  ...
}

from composer.lock. This behaviour is in contrast to what I understood so far that the composer.lock file was supposed to do - recording what exact versions are installed without specifiying any restrictions on composer.json.
Since my assumption has been proven wrong, I would be thankful to some clarification.
Comment: @yivi On further consideration, you're right, the question's a dupe, it's just that the accepted answer on the original isn't very helpful. I've moved my answer over to the original and voted to close this one.
Comment: Does this answer your question? [What means "locked at"  in composer](https://stackoverflow.com/questions/57414286/what-means-locked-at-tag-in-composer)
Comment: It doesn't make it less of a dupe, @Nico
Comment: @yivi it's a bit funny that the other question has been posted by the same user
Answer: Never ever edit the lock file by hand, that will only cause trouble. If updating a single dependency does not work, you've found the reason already: cause it's still needed in the current version by any other dependency.
To see why an update is not possible, you can use composer why-not, followed by the package name and the version you want to update to. For example, the following command could list why exactly updating to v3 is not possible:
composer why-not mynamespace/myproject 3.0

Now, you can either decide to skip the update for now, or add any of the packages that are listed there to your update command such that these also receive an update.
NB: it's very common that updating a single component (and nothing else) is not possible, especially if this is not a minor update


How print sql count on jsp?

Question: Root Cause
org.hibernate.exception.SQLGrammarException: could not execute query
Exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
I have dao
 public List<Book> task3() {
    Session session = this.sessionFactory.getCurrentSession();
    String sql = "SELECT books.genre, COUNT(*) AS counter FROM books  GROUP BY genre";

    SQLQuery query= session.createSQLQuery(sql);
    query.addEntity(Book.class);

    List<Book> authorList1   = query.list();

    return authorList1;
}

and controller
@RequestMapping(value = "/task3", method = RequestMethod.GET)
public String task3(Model model){
    model.addAttribute("task3", this.bookService.task3());

    return "task3";
}

How corect output this information on jsp?
I was tried like this but wrong :
 <c:if test="${!empty task3}">

            name
            genre
            rating
            published

        <c:forEach items="${task3}" var="author">

                ${author.name}
                ${author.genre}
                ${author.rating}
                ${author.published}

        </c:forEach>

</c:if>

enter code here
enter code here

Comment: Please post more from the exception, to see why it failed. Try to replace ! with "not"
Comment: @Adina Stacktrace:
 org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:584)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:481) java.lang.NumberFormatException: For input string: "id"
 java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
Comment: Do you have imported taglib for c : <%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> ?
Comment: @Adina yes I do
Comment: Ok, then the jsp engine is not configured correctly. Please paste your dependencies.
Comment: @Adina hibernate 4.3.5; spring(core, mvc) 4.0.3
Answer: I think this is because your service returns a list of Object[] not the Author entity ,
so you have to  call list after query.AddEntity(...) otherwise those line of code are useless ,
so your taks2() service method should be  as below :
public List<Author> task2() {

    Session session = this.sessionFactory.getCurrentSession();
    String sql = "SELECT sombra.author.*  FROM author, book_author WHERE author.id = book_author.`book_id` GROUP BY name ORDER BY COUNT(*) DESC";

    SQLQuery query= session.createSQLQuery(sql);
    query.addEntity(Author.class);
    query.addEntity(Book_author.class);

    List<Author> authorList1   = query.list();

    return authorList1;
}

How print sql count on jsp?


How to distinguish between custom modules and contrib modules?

Question: We have taken a project where we have to upgrade a site from d6 to d7.
But their module structure is poor, and does not distinguish between custom and contrib modules. We also want to know what's upgradable, and what isn't?
This would be helpful for sending project estimation.
Is there a way to do this using drush perhaps?
Comment: If you do `drush up` then it should say "Failed to check available update data for ...." which are the custom modules, all the others are contrib. Probably the same thing as going to the update tab in the modules admin screen (forgot if it's the same for D6).
Answer: If you want know which module has been upgraded or not and what things upgrade in module then you can use hacked module of drupal.
Go to hacked module configuration and click on "list project" Let it do the work.It will process the modules and will check for the changes.
Once it completes the process you will get a list of module along with the number of changes done in the modules.
Now open the directory sites/all/modules/ and check the modules which are displayed in the list you got after hacked process.The listed modules in the result are the contrib modules and rest of the modules should be custom.
Answer: Found a way to do the first part,  and list all the custom modules.
Quite cool approach I felt -:
grep -rL --include "*.info" "datestamp" .

Pipe to wc -l to see the number of custom modules grep -rL --include "*.info" "datestamp" . | wc -l
Comment: Good one. Possibly not accurate. Once there was a total repackaging, see [here](http://drupal.stackexchange.com/a/87749/16495). If script is fast enough, you can get duplicated timestamps. Now, if you remove duplicates, you will possibly have some modules counted as one in that situation. But if you do not, you will count things like Views & Views UI as separate modules, and that's not what you usually want.
Answer: You can list all contrib modules by running:
drush pm-updatestatus

all other which will say:

No release history was found ...

they're most likely custom modules.

Another way is to list all the project values from .info file and check whether the project exists in Drupal.org, e.g. using callback to https://updates.drupal.org/release-history/project_name/7.x. See: How to download programmatically a module?. E.g.

find . -name "*.info" -exec sh -c 'eval $(grep "project\s\+=.\+" "{}" | tr -d " "); curl -s "https://updates.drupal.org/release-history/$project/7.x" | grep "project_status" && echo {} is contrib || echo {} is custom' ';'


URL Redirect Mod_rewrite with htaccess in WordPress

Question: I have created some custom menus using functions.php in WordPress and I was hoping to use the htaccess to redirect those URLs to something friendly. For instance, one of the custom menus I have look like this for the menu: http://www.website.com/wp-admin/admin.php?page=for_buyers
How can I re-write it to be more like this:
http://www.website.com/wp-admin/for-buyers/
Also, My custom sub-menu look like this:
http://www.website.com/wp-admin/admin.php?page=marketing_materials
I want it to be more like this:
http://www.website.com/wp-admin/for-buyers/marketing-materials/
Answer: This has not been tested, the best is to modify vhosts, but you can use perdir .htaccess:
in /.htaccess, we can add this:
RewriteCond ${REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_FILENAME} !-f
RewriteRule ^wp-admin/for-buyers/$ /wp-admin/admin.php?page=for_buyers [L]

RewriteCond ${REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_FILENAME} !-f
RewriteRule ^wp-admin/for-buyers/marketing-materials/$ /wp-admin/admin.php?page=marketing_materials [L]

This ruleset does this:

http://www.website.com/wp-admin/for-buyers/ => /wp-admin/admin.php?page=for_buyers
http://www.website.com/wp-admin/for-buyers/marketing-materials/ => /wp-admin/admin.php?page=marketing_materials

Or in /wp-admin/.htaccess:
RewriteCond ${REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_FILENAME} !-f
RewriteRule ^for-buyers/$ /wp-admin/admin.php?page=for_buyers [L]

RewriteCond ${REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_FILENAME} !-f
RewriteRule ^for-buyers/marketing-materials/$ /wp-admin/admin.php?page=marketing_materials [L]

Comment: Should I add the above lines to my theme directory or create a new .htaccess and insert it inside my /wp-admin/ folder? It's not picking the rewrite for some reasons
Comment: It's better done in your root directory /, parent dir of wp-admin. IE, DOCUMENT_ROOT directory in your apache server.
Comment: I have tried the followings and it still not working: `# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^wp-admin/for-buyers/$ /wp-admin/admin.php?page=for_buyers [L]

# END WordPress`


Hide Title Bar in Service.Is it possible?

Question: I want to hide title bar in Service without using Activity.Can I somehow do so?I thought it might work with requestWindowFeature and NO_TITLE_FEATURE but android studio says that it can't resolve this method.May be somebody can help me?
Comment: `Service` have no UI. So there is no `ActionBar` or `Toolbar` to hide.
Answer: No, the title bar is part of the Activity. Therefore the Activity must control what window features it uses or doesn't use.


como abrir mais de uma View em uma controller?

Question: Tenho uma controller chamada Pedido:
[HttpPost]
public ActionResult Pedido()
{
    return View();
}

Como abrir mais de uma View em uma Controller?
Ao chamar uma Controller gostaria de abrir duas views.
Obs: Gostaria de abrir e abas diferentes.
Answer: No controller, creio que não consiga retornar duas views de uma vez.
Não sei se é o seu caso, mas consegue redirecionar para rotas diferentes,
return RedirectToRoute(new { controller = "controlador", action = "ação" });.
Answer: Até onde eu sei não tem como você abrir duas Views.
A Action do seu Controller deve retornar uma View apenas.
Porém na sua View você pode criar abas.
Answer: A action retorna somente uma view, o que dá para fazer é nessa view chamar um ajax que abra a nova view em outra aba mas... não sei se é o melhor a se fazer.
Answer: O controller permite direcionar apenas a uma view. Porém você pode, no load da sua view, abrir uma nova aba com javascript.
Em sua view, adicione essa função a um bloco de script:
function novaaba() {
    window.open("SUA_URL_AQUI", '_blank');
}

E então a chame no load do seu body, dessa forma:

Answer: Dentro da sua view de pedidos você terá que chamar uma view parcial.
<fieldset>
     <lengend>Itens do pedido</legend>
     @Html.Partial("ItemDoPedido", idPedido)
</fieldset>


Inverse Fourier Tranform of $e^{-|\xi|^{2s}}$ is in $L^p$

Question: Problem
We wish to show that $ \mathcal{F}^{-1}[ e^{-|\xi|^{2s}}] \in L^{p}(\mathbb{R^2}) $, for all $ p \in [1,\infty], \ s\in(0,1) $.
That is, we wish to show that $ (\int_{\mathbb{R}^2} | \int_{\mathbb{R}^2} e^{2 \pi i x\cdot\xi} e^{-|\xi|^{2s}} \text{d}\xi |^p \text{d}x )^{1/p} < \infty $, for $p \in [1,\infty)$.
My Attempt
My thinking was that we could simply observe that $ e^{-|\xi|^{2s}} \leq 1 $, and then only consider:
$ (\int_{\mathbb{R}^2} | \int_{\mathbb{R}^2} e^{2 \pi i x\cdot\xi} \text{d}\xi |^p \text{d}x )^{1/p} = (\int_{\mathbb{R}^2} | \int_{-\infty}^{\infty} e^{2 \pi i x_1 \xi_1} \text{d}\xi_1 \int_{-\infty}^{\infty} e^{2 \pi i x_2 \xi_2} \text{d}\xi_2  |^p \text{d}x )^{1/p} $
We then use the fact that $ \int_{-\infty}^{\infty} e^{2 \pi i x_1 \xi_1} \text{d}\xi_1 = \frac{1}{2 \pi} \delta(x_1) $.
Now, I believed that, by the usual properties of the Dirac-Delta Distribution, we could say that:
$ \int_{-\infty}^{\infty} \frac{1}{2 \pi} \delta(x_1) \text{d}x_1 = \frac{1}{2\pi} $
and thus $ (\int_{-\infty}^{\infty} |\frac{1}{2 \pi} \delta(x_1)| \text{d}x_1)^{1/p} = \frac{1}{2\pi} $.
However, after some research online, it's come to my attention that this is NOT true, and in fact the dirac delta distribution is not in $L^p$, for any $p$.
As such, I am now lost as to how I can prove the above claim. Any hints/advice appreciated. Thank you.
Update
The case $p = \infty$ is actually quite easy to prove, so I only need help with the case $p \in [1,\infty)$.
Comment: With $e^{-|\xi|^{2s}}\leq 1$ you throw away the good decay that your function has.
Comment: The inverse FT is well known to probabilists. It is the density function of a symmetric stable random variable and it does belong to every $L^{p}$.
Comment: Do you have a source/proof of this?
Comment: Yes, it does seem that I need to use this somehow, but I'm not sure how, since there is apparently no general formula in terms of $x$ for the inverse FT...
Answer: Let $f(\xi)=e^{-|\xi|^{2s}}$, where $0<s<1$. Since $f\in L^q(\mathbb{R}^n)$ for any $q\in[1,\infty]$, we have
$$
F=\mathcal{F}^{-1}(f)\in L^p(\mathbb{R}^n)
\qquad\textrm{for}\quad
p\in[2,\infty],
$$
by the Hausdorff-Young inequality.
So far, we have only used the decay of $f$. Now we want to exploit the regularity of $f$, which is related to the decay of $F$. We start by noting that
$$
|x|^2F=c\mathcal{F}^{-1}(\Delta f),
$$
where $c$ is a constant (involving $i$, $\pi$ etc.). Compute the Laplacian of $f$ as
$$
\Delta f(\xi)=e^{-|\xi|^{2s}}(c_1|\xi|^{4s-2}+c_2|\xi|^{2s-2}),
$$
where $c_1$ and $c_2$ are again constants. Since $s>0$, it is easy to see that $\Delta f\in L^{1+\varepsilon}(\mathbb{R}^2)$ for some $\varepsilon>0$. This gives us $|x|^2F\in L^q(\mathbb{R}^2)$ for some $q<\infty$ by Hausdorff-Young, and thus
$$
F\in L^p(\mathbb{R}^2)
\qquad\textrm{for}\quad
p\geq1.
$$
Let me clarify the last step a bit further. Since $F$ is smooth, it suffices to show that
$$
\|F(x)\|_{L^1(Q)}<\infty
\qquad\textrm{with}\quad
Q=\{|x|>1\}.
$$
Thus we compute
$$
\int_Q|F(x)|dx=\int_Q|F(x)||x|^2|x|^{-2}dx
\leq
\||x|^2F\|_{L^q(Q)}\||x|^{-2}\|_{L^{r}(Q)},
$$
where $r$ is the Hölder conjugate of $q$. The crucial point is that $r>1$, and hence $|x|^{-2}\in L^r(Q)$, because $q<\infty$.
Comment: @Diger: It is true that $\Delta f\in L^1$, but it only implies that $|x|^2F\in L^\infty$, which would give $F\in L^p$ for $p>1$. To get this with $p=1$, we want slightly more, that is $\Delta f\in L^{1+\varepsilon}$.
Comment: It is probably not true that $\Delta f\in L^p$ for $11$ is enough to give $|x|^2F\in L^q$ with some $q<\infty$.
Comment: How do you deal with the pole at $0$ of $\Delta f$?
Comment: @D.Thomine the pole is absolutely integrable. This is really the thing that gives decay to $F$.
Comment: Oh, that's on $\mathbb{R}^2$. I was wondering what was wrong with my understanding of this question.
Comment: Hi, thank you very much for your answer. It has been very helpful!

However, towards the end, I believe there is a mistake. It does not seem to me, having checked an integral calculator, that $\Delta f \in L^1(\mathbb{R}^2)$. The integral is divergent for, say, $s = 0.5$.

Edit: Never mind haha. My mistake!
Comment: Having refreshed the page, I see that you have made an edit to your answer. Thank you very much for all your work! Could you please explain your last step, going from $|x|^2F \in L^q(\mathbb{R}^2)$ for sufficiently large  $q<\infty$, to $F \in L^p(\mathbb{R}^2)$ for $p\geq 1$?
Comment: @DavidHughes: I have updated the answer.
Comment: Why is it only $$\Delta f \in L^{1+\epsilon}(\mathbb{R}^2)$$ for $\epsilon>0$ and not for $\epsilon=0$?!
Comment: I'm also not sure I get this step right: By Hausdorff-Young it follows $\Delta f \in L^p(\mathbb{R}^2)$ for $1<p<2$, so that $|x|^2 F \in L^q(\mathbb{R}^2)$ for some $2<q<\infty$. Maybe that is clear to you, but it is not to me that you mean it.
Comment: Just curious, can the Hausdorff-Young or Hölder inequality be used for any complex valued functions, when the absolute value inside the p-norm is understand in its sense to be a real valued function? So $f(t)\in\mathbb{C}$ where $t\in\mathbb{R}$ is real, but $f$ is generally complex valued.
Comment: They are valid if you replace the absolute values by the modulus, i.e., $\sqrt{\bar{z}z}$.


Lasso: Effect of $l_1$ Constraint on $RSS$?

Question: I have a problem that I'm trying to figure out.
Problem: Suppose we estimate the regression coefficients in a linear regression model by minimizing
$\sum_{i=1}^n (y_i - \beta_0-\sum_{j=1}^p \beta_j x_{ij})^2$ subject to $\sum_{j=1}^p \lvert{\beta_j}\lvert \le s$
for a particular value of s. Indicate which is correct:
(a) As we increase s from 0, the training RSS will:
i. Increase initially, and then eventually start decreasing in an inverted U shape.
ii. Decrease initially, and then eventually start increasing in a U shape.
iii. Steadily increase.
iv. Steadily decrease.
v. Remain constant.
(b) Repeat (a) for test RSS.

I saw someone who wrote that for (a) RSS will steadily decrease and for (b) it will decrease initially then increase in a U shape.
I don't understand why this is though. My whole understanding of Lasso is that is seeks to decrease variance and increase bias. Less variability should lead to a lower RSS and MSE. And I understand that as we increase s, we "relax" the constraint on our prediction coefficients and thus they will eventually just get the Least Squares Estimator.
Sorry if this seems totally off. I'm trying to wrap my mind around this :/ Thank you in advance.
Comment: You are correct that as we increase $s$, LASSO becomes closer to OLS. Try to elaborate the phrases "decreases variance" and "lower RSS" - i.e., variance and RSS of what?
Comment: Are you asking me to elaborate the question's phrases or my interpretation? I guess I have some conceptual misunderstanding. I'm not sure how testing and training RSS is affected though. Is this relating to overfitting? I.e., constraining too much leads to overfitting of training data? But how do we know how the test data will behave?
Answer: As discussed in comments under the question, this problem is based on understanding two concepts:

$s$ controls the regularization strength: $s=0$ enforces an intercept-only model, $s=+\infty$ permits unconstrained least squares
Overfitting means low RSS on train data, but high RSS on new data

Some misunderstanding may arise from using the term "variance" loosely. LASSO (or any other regularization, for that matter) reduces the variance of the estimate of underlying function, $\hat{f}(x)$, taken over various samples of $x$. In other words, new training data will produce similar estimates.
Thus, for (a) we have that relaxing LASSO regularization leads to less shrinkage, larger coefficients, and smaller train-data RSS. At some point, overfitting kicks in, and while train-data RSS continues to increase, test-data RSS will start decreasing.
(For the boundary case when none of the $x$ are predictive and the true model is $y=\beta_0 + \epsilon$, the correct answer is (b) iv, as we start with the optimal model $\beta_j=0$ and any relaxation only introduces overfit.)
Comment: So does this imply that training and test RSS behave opposite to each other? Also, if $s=0$ is this still overfitting? Can't this be seen as the opposite since we now are left with just the intercept and no slope. Why wouldn't this have higher RSS than the Least Squares Estimator? So for a you say that training data RSS will decrease and then start to increase?

Sorry for my confusion. This is a new concept for me.
Comment: @Nicklovn overfitting by definition means having a good fit (RSS) in test data that cannot be replicated in new data. A regularized model cannot have higher training RSS than a simple least squares model, so it cannot be _more overfit_ than OLS. Hope that answers some of the questions.