Why do "in tune" bass lines sometimes seem sharp to me?

Question: I've noticed that certain bass and baritone register sounds often seem sharp to me, even when they are ostensibly in tune- the notes are checked with a tuner or generated by a digital synth that won't go out of tune. I've also noticed that some sounds seem to go even sharper at high volumes. What is causing this discrepancy between perceived pitch and the "actual" pitch of the instrument?
I've read unsourced claims that at high volumes, high frequencies sound sharper and low frequencies sound flatter. I haven't found good reputable or detailed sources for this.
I was reminded of this phenomenon by this question.

I've tried to recreate the sharp-sounding garageband synth, but I can't recreate the effect of it going sharp at high volumes.  So here is the original synth.  (I made this song as a joke.)  I also just found that the pitch misperception is stronger (and happens at lower volumes) through headphones/eq with more bass.
Comment: @Dekkadeci On your smartphone, without headphones?  If yes, then that's nearly the opposite of the "ideal" listening situation I described, so I'm not surprised that you don't hear it.  I can't hear it on headphones if I high pass the signal either.
Comment: Is it more noticable with some instruments than others? Say a bass guitar frequently sounds sharp, a piano less so, vocals very rarely? I think the answer is 'inharmonicity', but it affects different instruments differently.
Comment: I totally expect inharmonicity is one reason why an instrument may sound sharp.  You could expand that into an answer.  I don't think it's the only factor though.  I noticed the "high volume => seems sharp" effect the most with a certain saw-like synth from the garageband app, which is probably not inharmonic.  I may be able to find/provide a sample, but I don't have an iPad anymore.  I've also noticed perception errors with sine basses when I first got bassy headphones years ago, but I think I'm just used to them now and no longer hear them as being out.
Comment: Some clarifications that would be helpful: 1) Does it "sound" sharp, or "feel" sharp (i.e., you know the pitch is accurate, but you respond to it as though it's sharp); 2) Does it sound sharp compared to another instrument playing the same pitch or compared to other pitches generated by the same source? 3) Related to #2, what is your reference point for sensing a pitch is sharper than expected?
Comment: Are you sure it's not everyone else going flat?
Comment: @Aaron 1) Well, both.  My fine pitch perception is not great, but I have had a perceptual error of nearly a semitone under "ideal" conditions, so I'm clearly hearing it sharp.  2) It depends.  In the garageband synth case that I mentioned, it sounded like the synth slightly raised in pitch as I raised the volume, and then went back down as I lowered the volume.  The other instruments didn't necessarily sound like they also went sharp, but I didn't notice them ever sounding out of tune with the now-sharp-sounding instrument either.
Comment: I added a link to a recording of that garageband synth...  I'm a little afraid that it might detract from the question, since I'm interested in all causes of pitch misperception, not just whatever applies to this one case, and perhaps other people may not hear the same going-sharp effect that I hear with this particular example.  But the recording is there nonetheless
Comment: Although I was listening to your video on my smartphone, I couldn't replicate the "going sharp with louder volume" effect on it, not even by quickly shifting the volume back or forth while the song was playing the same 2 notes in the bassline.
Comment: I can confirm that I experience the same phenomenon. When just the baseline starts a song, I can hear myself predict the next notes when they come in, and they all sound ostensibly flat when they do. In Queen's Another one Bites the Dust, and Duffy's Mercy, listen to the baseline and sing what you think the higher octave would be, and play it through until the rest of the band comes in. The baseline is sharp or the band is flat right? It's such a weird experience and I don't know if it's me that's wrong or something else.
Comment: @HeatherGray For those specific examples- Another One Bites the Dust is in a nonstandard tuning (the whole song is sharp), and I think the bassline in Mercy actually is sharp.  At least, my tuner says so, about 30 cents sharp, but it jumps around a lot.
Answer: You are right about loud bass notes sounding different to what they are. Whenever I tuned the bottom E by ear prior to a gig (off the 3 treble strings ADG) I would check it by tuner with disappointment that 'my ear was deficient'. What the tuner says is correct pitch (41.2 Hz) always sounded sharp to me, and what my ear said was in tune the technology says is flat. I think it has something to do with sound pressure and the effect on the human ear drum - and partials creating inharmonicity. On a piano the bass notes are tuned flatter and the treble notes sharper - stretching the octaves aka the Railsback Curve
Answer: [This would probably better fit as a comment as I do not have any references to support it, like you I am looking forward for other answers…]
All these bass sounds are not pure sine tones thus, they will generate harmonics according to the harmonic series: the first one will at the octave, the second one at the octave plus a fifth plus roughly 2 cents compared to 12TET. Usually the volumes of these harmonics will be lower than the fundamental tone.
That said, the human ear is more sensible to mid range sound than to bass sounds. That means that the perception of the harmonics will be boosted compared to the fundamental tone as these harmonics are at higher frequencies. The second harmonic, which is a bit sharper than the fifth obtained from equal temperament will thus be boosted compared to the fundamental for bass sounds. Maybe that is what is driving this perception phenomenon?
Comment: I'm quite confident that the second harmonic, at only 2 cents sharp, is not contributing much to this perception error of much more than 2 cents.  If you look at the first, say, 20 harmonics, then you might have something, but the first 20 harmonics seem overall to be flat compared to 12-TET more than they are sharp.
Comment: @Edward Honestly, I was never very good in tuning so I trust you on that. As said that read more am hypothesis than a real answer!
Answer: For what it's worth, the headphones or speakers you're using can change a lot of these characteristics.
I remember when the foam padding on my headphones wore off and I replaced them with padding made by a third-party manufacturer which was too thick. Low frequencies leak out a lot due to the distance between the speaker and ear, amounting to an inherent treble-boost which I usually fix with a treble reducer equalizer setting.
My experience so far (somewhat subjective) is that treble and midrange hold better over a long range, while low frequencies (with sufficient amplitude) are better at going through walls (you can confirm this by standing outside an overly noisy club with speakers belting out boosted EDM basslines).
Comment: This doesn't really answer the question.  There's no mention of pitch in your answer.
Answer: Many bass instruments with primary resonators have disharmonicity affecting the tone: partial vibration modes that end up having higher frequency than a proper harmonic.  Those blend better with higher pitches when those sharp overtones match the other pitches than when the fundamental is "correct".
Prime suspects here are string instruments with comparatively thick strings, like bass guitars.  However, if the prime source of overtones is by distortion of the fundamental rather than by overamplification of physical overtones, disharmonicity should not come into play.  So it's more a "funky" or "twangy" bass that will be affected than a "hard rock" bass sound.
This theme of "distortion of the fundamental" is also applicable to wind instruments operating on interrupted air streams, like reed and brass instruments (so they should now show disharmonicity) but not flutes.  Flutes, however, tend to have rather few overtones and thus are not all that helpful for establishing a harmonic base.
The lower bass notes of a piano tend to require tuning lower than "appropriate" (stretch tuning), particularly of upright pianos which have shorter and thicker strings compared to grand pianos.
Bowed string instruments are rather complex since their overtones to a good degree come from the sticking action of the bow, but the bowing action itself causes pitch shifts in the attack phase as well as loudness dependent pitch shifts.  This is partly compensated by today's bowed string instruments almost universally being fretless and thus amenable to on-the-fly corrections by the player.
Generally continuous-tone music instruments facilitate oscillators that are fed from some energy source.  More energy is fed into the oscillators for louder notes, requiring more of a phase-lead and possibly resulting in a higher frequency for higher volumes.  However, the tap-off of energy into sound can counterbalance this again, so the net result really depends on multiple balancing factors, and some aspects of musical instrument design may focus on making pitches reliable across different loudness by design or during the process of intonation.
TLDR: can of worms.
Answer: It may be that your perception is "correcting" the equal temperament physical pitch to something that makes more sense to your brain, e.g. just intonation where the ratios between the pitches are more in line with the actual overtones present.
("more in line" because of inharmonicity.)


Showing $\mathbb{R}/\mathbb{Q}$ is not Hausdorff

Question: I stumbled upon this link while googling for an answer to the same question.
Under point number 3, the sole answer mentions an example where it is said $\mathbb{R}/\mathbb{Q}$ is not Hausdorff,  because the topology generated is trivial, assuming $\mathbb{R}$ has the standard topology. I agree with the conclusion but I think the reason given is wrong. I just wanted to cross-check my argument.
If I take $ (\mathbb{R}/\mathbb{Q}) \backslash  [e]  $
where e is the equivalence class of the Euler number $e$,
then the inverse of the projection map $\pi: \mathbb {R}\rightarrow \mathbb{R}/\mathbb{Q}$ is $\mathbb{R}\backslash \{e\}$ which is an open set in $\mathbb{R}$.
And so the topology consists of open sets other than $X$ and $\phi$, which means
the topology is not trivial.
Is there something wrong with the above argument?
NOTE: I agree with the conclusion though. Let $U \neq \phi$ be an open set in
$\mathbb{R}/\mathbb{Q}$ . Let $q\in \mathbb{Q}$  then if $[q] \notin U$,
$\pi^{-1}(U)$ will consist of only irrationals which cannot be open,
and so the space is not hausdorff, since any two non-empty open sets have non-empty intersection containing atleast $[q]$.
Comment: $\pi^{-1}(\mathbb{R/Q} \setminus [e]) = \mathbb{R} \setminus (e + \mathbb{Q})$, which contains no intervals.
Comment: The inverse of the projection map seems to also contain $e+0.0123$.
Answer: Let's get really broad, and also hope I'm not making any major errors. Forgive (or fix) the awful variable names.
Let $D$ be a dense set in a space $S$.
Let $f\colon S \to X$ be any continuous surjection that is constant on $D$, and suppose that $f$ maps every element of $D$ to $q$.
Let $U \subseteq X$ be a non-empty open set, so $f^{-1}[U]$ is a non-empty open set.
Then $f^{-1}[U]$ contains an element, $b$, of $D$, so $q\in U$.
So we see that every non-empty open set in $X$ contains $q$, so $X$ cannot even be $T_1$, let alone Hausdorff, unless it contains at most one point.
Comment: Here, im assuming $X$ is the quotient space $S/D$?
Comment: @MyMathYourMath, it doesn't have to be in general (I don't assume a topological group), but with regard to the question, $S=\mathbb{R}$, $D=\mathbb{Q}$, $X=\mathbb{R}/\mathbb{Q}$, and $f$ is the canonical mapping.
Comment: does $f^{-1}(U)$ contain an element of $D$ by density?
Comment: @MyMathYourMath, exactly. It's a non-empty open set in $S$, so it must contain an element of $D$.
Comment: Huh, you just made me realize $f$ doesn't even have to be a quotient map!
Comment: Thanks, just trying to really understand why $\Bbb{R} / \Bbb{Q}$ is non-Hausdorff. Thanks for this solution! it totally makes sense!!
Comment: @MyMathYourMath, ah, it seems the original question was actually meaning the adjunction space by $\mathbb{R}/\mathbb{Q}$, but the same argument works whichever kind of quotient it is. Either way, $f(\mathbb{Q})$ is a singleton.
Answer: The topology is trivial: every open set in $\mathbb{R}$ contains a complete set of coset representatives for $\mathbb{R}/\mathbb{Q}$.  So if $U\subseteq\mathbb{R}/\mathbb{Q}$ is open and nonempty, $\pi^{-1}(U)$ is open in $\mathbb{R}$ and $\pi(\pi^{-1}(U))$ is all of $\mathbb{R}/\mathbb{Q}$.
Comment: Oh I see where my confusion is occuring. The answer uses $\mathbb{R}/\mathbb{Q}$ as the collection of cosets of $\mathbb{Q}$ where $\mathbb{R}$ is considered as a group, but the book I am using uses this notation for the concept of adjunction space, as mentioned in this link on Wikipedia http://en.wikipedia.org/wiki/Quotient_space under the tag adjunction space. Well, anyway the topologies in both senses are non-Hausdorff. :-)
Answer: The topology $\Bbb R\backslash \Bbb Q$ is trivial topology and hence not Hausdorff. It is trivial as follows:
Let $x \in \Bbb R$. If $x \in \Bbb Q'$, then, equivalence class of $x$ is $$[x] = x + \Bbb Q \\= \{x+p\,|\; p \in \Bbb Q\}$$  Similarly, if $x \in \Bbb Q$, then the equivalence class of $x$ is $\Bbb Q$ (easy to see).
Also note that all of these are closed sets and there is no open set in $\Bbb R$ which is saturated for if it were open, then there should be an open ball contained in the set, around every point of the set. But clearly, we can always find a point in these open balls which is not in the set. This can be prevented only if we take the set $\Bbb R$ and thus, $\phi$ and $\Bbb R$ are the only saturated sets in $\Bbb R$.
Since open sets in quotient topology are in one-one correspondence with the saturated open sets in original space, the topology on $\Bbb R\backslash \Bbb Q$ is trivial.
Comment: @MyMathYourMath yes it is. Because if you take any open interval around a rational, you can always find one irrational in it.
Comment: Is $\Bbb{Q}'$ the limit points of the rationals?


R neural net training and prediction

Question: I am trying to form a model on a set of data that I gathered from MT4. The OHLC and some MA slopes.
I am trying to get the best guess for price change in the future.
I am using
<code># Packages
require(quantmod) #for Lag()
require(nnet)
require(caret)

#Fit model
model <- train(change ~ Lag(change) + high + low + slope13 + slope50 + slope200, mt4,
method='nnet', linout=TRUE, trace = FALSE,
           #Grid of tuning parameters to try:
           tuneGrid=expand.grid(.size=c(1,5,10),.decay=c(0,0.001,0.1)))
ps <- predict(model, mt4)

#Examine results
model
plot(CHANGE)
lines(ps, col=2)
</code>
The output from the model is not so good from what I understand from the RSquared.
<code>6828 samples
   6 predictors

No pre-processing
Resampling: Bootstrap (25 reps)

Summary of sample sizes: 6828, 6828, 6828, 6828, 6828, 6828, ...

Resampling results across tuning parameters:

  size  decay  RMSE     Rsquared  RMSE SD   Rsquared SD
  1     0      0.00483  0.00021   0.000124  0.000262
  1     0.001  0.00483  0.000464  0.000124  0.000669
  1     0.1    0.00483  0.00115   0.000125  0.0016
  5     0      0.00499  0.000452  0.00074   0.000537
  5     0.001  0.00484  0.000271  0.000123  0.000356
  5     0.1    0.00485  0.00109   0.000131  0.00183
  10    0      0.00485  0.00087   0.00012   0.00129
  10    0.001  0.00486  0.000408  0.000121  0.000699
  10    0.1    0.005    0.000638  0.000434  0.00121
</code>
Questions:

Am I training my model incorrectly because of such the bad output?
How do I get the best guess for the next bars change that I am training for? Even though this model appears horrible it would be nice to know how to get the output.
Answer: Your results look about right to me.  Predicted prices changes in financial markets is difficult.
Also, when cross-validating time series data, you can't randomly assign each observation to a fold (this is what caret does).  You need to be aware of the time-series structure of your data.  Take a look at this code for some examples.

R neural net training and prediction


Localization of sheaves: 'particular' proof wanted

Question: The question is closely related to this one. Although the OP accepted
already an answer there, I think that
a subtely detail is still not solved and would like to ask about
it here explicitely.
The OP asked:

Let $(X,\mathscr{O}_X)$ a ringed space and $\mathscr{F}$ an
$\mathscr{O}_X$-module. Let $U\subseteq X$ be an open subset,
and suppose we have $\mathscr{F}|_U=\mathscr{O}_U$, then for
$x\in U$, how does this imply $\mathscr{F}_x=\mathscr{O}_{X,x}$?
The explanation I saw was "because localization preserves exactness",
but I don't quite understand how does it work here. Can somebody explain?

And I think that it might be considered as important part of this problem to understand
not only why $\mathscr{F}_x=\mathscr{O}_{X,x}$ is here true as result, but
by how explicitely a proof should work, which uses the fact that
'localization preserves exactness' as tool.
Some user's including myself posted a proof but no one used explicitely
localization preserves exactness as an input. That is the question is
if there is a proof of $\mathscr{F}_x=\mathscr{O}_{X,x}$ which uses
this feature of localizations?
Comment: why the downvote?
Answer: Question: "And I think that it might be considered as important part of this problem to understand not only why Fx=OX,x is here true as result, but by how explicitely a proof should work, which uses the fact that 'localization preserves exactness' as tool."
Answer: You must specify why you speak about "localization". If $i: U \rightarrow X$ and $j:\{x\}\rightarrow U$ is the inclusion maps it follows (since topological inverse image is a functor) that there is an isomorphism of functors
$$(i \circ j)^{-1}\cong j^{-1} \circ i^{-1},$$
hence for any sheaf of abelian groups $F$ on $X$ you get isomorphisms
$$ F_x \cong (i \circ j)^{-1}F \cong j^{-1}i^{-1}F \cong j^{-1}(F_U) \cong (F_U)_x$$
where $F_U$ is the restriction of $F$ to the open set $U$.
Note: Localization in commutative algebra is exact in the following sense: For any multiplicative subset $S \subseteq A$ where $A$ is a commutative unital ring and any short exact sqeuence
$$0 \rightarrow E \rightarrow F \rightarrow G \rightarrow 0$$
of $A$-modules, it follows the sequence
$$0 \rightarrow S^{-1}E \rightarrow S^{-1}F \rightarrow S^{-1}G \rightarrow 0$$
is an exact sequence of $S^{-1}A$-modules. But in your case you are speaking of ringed spaces and hence this method does not apply.
Since you are considering arbitrary ringed spaces you cannot "localize" - it has no meaning. Localization (in the sense of commutative algebra) applies when $(X, \mathcal{O}_X)$ is a scheme - it has an open cover $U_i:=Spec(A_i)$ of affine schemes.
If $f\in A$ where $A$ is a commutative unital ring and $f\notin  \mathfrak{p}$ where $\mathfrak{p}$ is a prime ideal in A, let $S:=A-\mathfrak{p}$ and $T:=\{1,f,f^2,..,\}$. It follows $T \subseteq S$ is a subset.
There is a canonical map
$$i: A \rightarrow A_f:=T^{-1}A$$
and let $S_f:=i(S) \subseteq A_f$. There is a canonical isomorphism
$$(A_f)_{\mathfrak{p}}\cong S_f^{-1}T^{-1}A \cong S_f^{-1}(A_f) \cong S^{-1}A :=A_{\mathfrak{p}}$$
since localization is "transitive". Hence you get an isomorphism of rings
$$I1.\text{  }A_{\mathfrak{p}} \cong (A_f)_{\mathfrak{p}}.$$
If $X:=Spec(A), U:=D(f):=Spec(A_f)$ the isomorphism in $I1$ proves that
there is an isomorphism of rings
$$\mathcal{O}_{X, \mathfrak{p}} \cong A_{\mathfrak{p}}\cong (A_f)_{\mathfrak{p}} \cong \mathcal{O}_{U, \mathfrak{p}}.$$
Hence for affine schemes a similar result holds using "transitivity" of localization - not "localization preserve exactness". Similarly if $E$ is any $A$-module and $\mathcal{E}:=\widetilde{E}$ it follows there is an isomorphism
$$\mathcal{E}_{\mathfrak{p}} \cong E_{\mathfrak{p}} \cong (E_f)_{\mathfrak{p}} \cong (\mathcal{E}_U)_{\mathfrak{p}}.$$
Hence for any quasi coherent $\mathcal{O}_X$-module you may use "transitivity of localization" to prove the same result.
Note: To take the stalk of a sheaf of abelian groups is a topological construction, and this makes sense for any sheaf of abelian groups on any topological space. In the case of an affine scheme $X:=Spec(A)$, it agrees with the $A_{\mathfrak{p}}$-module $E_{\mathfrak{p}}$ corresponding to the prime ideal $\mathfrak{p}$.
Question: "And yes, my understanding of 'localization' is exactly that one from commutative algebra you explaned in your Note. And the core of my question is if exactly this comm alg characterization can be explicitely used to prove the claim."
Answer: The answer is "no". If $(X, \mathcal{O})$ is an arbitrary locally ringed space you do not have an open cover $U_i:=Spec(A_i)$ of $X$ of affine schemes $U_i$. If you want to use localization in the sense of commutative algebra you need such an open cover and the relation $\mathcal{O}_x \cong A_{\mathfrak{p}_x}$ where $\mathfrak{p}_x \subseteq A$ is the prime ideal corresponding to $x\in U:=Spec(A) \subseteq X$.
Comment: On your question why I speak about "localization":
take a look in the motivation of my question. In this
(https://math.stackexchange.com/questions/4094375/localization-of-sheaves/4094492#4094492)
the OP noted that the argument that $\mathscr{F}_x=\mathscr{O}_{X,x}$ holds
"because localization preserves exactness". So I'm speaking about
'localization' because I'm quoting the original source of the
proof, but how this fact is used to show the claim I want to find out;
that's exactly the motivation of the question.
Comment: And yes, my understanding
of 'localization' is exactly that one from commutative algebra you explaned
in your **Note**. And the core of my question is if exactly *this*
comm alg characterization can be explicitely used to prove the claim.


HuggingFace BetterTransformer in `with` context - cannot disable after context

Question: I am writing a custom with context manager to temporarily make the model a BetterTransformer model while calling trainer.evaluate().
I evaluated before, in, and after the with context. I noticed that the evaluation after the with context still uses BetterTransformer. This is a problem because the trainer.train() call afterwards will also use BetterTransformer, resulting in poor training due to padding.
How do I create a custom with context that only uses BetterTransformer inside the context, not afterwards?
Please find the MWE gist here.
I created a custom context manager:
class BetterTransformerContext:
    """Temporarily replace a model with a BetterTransformer model."""

    def __init__(self, model):
        self.model = model
        self.original_model = None

    def __enter__(self):
        self.original_model = self.model
        self.model = BetterTransformer.transform(self.model)
        return self.model

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.model = self.original_model
        # self.model = BetterTransformer.reverse(self.model)  # NOTE: same result

The output is as follows. Evaluating without BetterTransformer handles approximately 100 it/s, with BetterTransformer handles approximately 115 it/s. As you can see, evaluating after the context still results in 115 it/s.
========== Without Optimum (-> should be slow) ==========
BT before context:  False
100%|█████████████████████████████| 204/204 [00:01<00:00, 103.09it/s]
0.3161764705882353
========== With Optimum (-> should be fast) ==========
BT in context:  True
100%|█████████████████████████████| 204/204 [00:01<00:00, 116.68it/s]
0.3161764705882353
========== Without Optimum (-> should be slow) ==========
BT after context:  True
100%|█████████████████████████████| 204/204 [00:01<00:00, 116.53it/s]
0.3161764705882353

Answer: I found a solution by using a custom context manager on the trainer object, as opposed to applying it on a model object.
The custom context manager is as follows:
class BetterTransformerTrainerContext:
    """Context manager to wrap trainer.model with BetterTransformer."""
    def __init__(self, trainer):
        self.trainer = trainer

    def __enter__(self):
        self.trainer.model = BetterTransformer.transform(
            self.trainer.model, keep_original_model=True
        )
        return self.trainer

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.trainer.model = BetterTransformer.reverse(self.trainer.model)

It can be used as follows:
print("=" * 10, "With Optimum (-> should be fast)", "=" * 10)
with BetterTransformerTrainerContext(trainer) as _optimum_trainer:
    eval_accuracy = _optimum_trainer.evaluate()["eval_accuracy"]
    print(eval_accuracy)

I hope this might be helpful to someone else.


Erro na hora de retornar um vetor char

Question: Estou tentando fazer uma função que lê um arquivo .json e retorna o conteudo. Apesar da leitura bem sucedida, na hora retornar ou imprimi na serial, apresenta-se alguns caracteres a mais " @⸮4!@". Alguem poderia me ajudar a resolver?
No arquivo .json
[{"nome":"Julio","sobrenome":"Carvalho","senha":"123","id":0}]
Na função de leitura
File users = SPIFFS.open("/users.json" , "r");
    if(!users){Serial.println("file open failed");}
    Serial.println(users.available());
    char usuarios[users.available()];
    for (int aux=0; users.available(); aux++){
      Serial.println(users.available());
      usuarios[aux] = char(users.read());
      Serial.println(usuarios[aux]);
    }
    Serial.println(users.available());
    users.close();
    Serial.print(usuarios);
    return usuarios;

Answer: Consegui resolver, bastou passar a variavel char usuarios[users.available()] para String usuarios. Isso provavelmente estava acontecendo pela variavel em char não ter o tamanho correto e armazenar lixo de memoria nas posições exedentes.

Erro na hora de retornar um vetor char


Create a RSS feed of file attachments to a particular node

Question: I am looking to create a RSS feed of file attachments, filtered by the node they are attached to.
for instance the feed URL would be:
node/253/rss-attachments.xml

where 253 is the node ID in question. Using views 3 + drupal 7 I am able use 'files' as a base table, and create a list of files with a contextual filter of node ID, however upon adding the RSS display it complains saying:

Style RSS Feed requires a row style but the row plugin is invalid.

I have the feeling that a custom row style plugin is required here. Does anyone have any ideas as to what options exist now for solving this issue?
Thanks
Answer: You can use Views RSS module for creating complex feeds with Drupal Fields. The module provides a lot of RSS settings:

RSS format plugin "RSS Feed - Fields" with settings
Support for core fields.
Enclosure elements

The result can look like this:


Can you give me an example of topological group which is not a Lie group.

Question: I know the definitions of Lie group and topological group are different. Can you give me an example of topological group which is not a Lie group.
Comment: Does anyone have an example of  a smooth manifold that can be made into a topological group but not a Lie group?
Comment: @IshanBanerjee, https://en.wikipedia.org/wiki/Hilbert%27s_fifth_problem.
Comment: Another example, which is connected but not locally connected, is https://en.wikipedia.org/wiki/Solenoid_(mathematics)
Answer: Another example is the rationals under addition with the subspace topology induced from inclusion in $\mathbb R$. Since the rationals are countable, they can't be a manifold of dimension exceeding $0$, so the only possibility would be a $0$ manifold. However, the topology on the rationals is not discrete, so they do not form a $0$-manifold either.
Answer: The Cantor set is a topological group. It is homeomorphic to $\{0,1\}^{\omega}$ in the product topology, which is a topological vector space over $\mathbb{Z}_2$. As the set is totally disconnected and not discrete it is easy to see that it cannot be a manifold.
Comment: @SamaelManasseh Yes but the product topology is not discrete.
Comment: what topology of {0,1}? discrete ?
Answer: The $p$-adic numbers are a topological group, but not a Lie group.
There are many profinite groups which are not Lie groups, for example the profinite group completion of a knot group.
Comment: (But of course, the $p$-adic numbers provide an example of a $p$-adic Lie group).


Laravel Eloquent - Inserting multiple records

Question: How do we insert multiple records using eloquent in Laravel?
Basically this:
<code>            Teacher::create([
                'user_id' => $user->id,
                'college_id' => $collegeId,
                'first_name' => $this->faker->firstName(),
                'last_name' => $this->faker->lastName()
            ],[...],[...]);
</code>
Answer: Okay, I just came across the github request where Taylor replied that it is not possible with Eloquent and to use Query builder instead.
Here is the link to the issue:
https://github.com/laravel/framework/issues/1295
Comment: Yep, however mind that you won't get any `Eloquent` features with this - timestamps, events etc.


Is right this chromatic polynomial for this Bridge Graph?

Question: I have the following graph:
Bridge Graph with N = 8
And I need to find its chromatic polynomial.
Based in my notes, I have reached the following result:
$$Pg(x) = \frac{((x-1)^4 + (x-1))^2}{x(x-1)} $$.
It is because I have applied this formula:
$$Pg(x) = \frac{Pg1(x) Pg2(x)}{Pkr(x)} $$.
Taking the Bridge Graph and the previous formula, I have replaced with:
$$ Pg1(x) = Pg2(x) = Pc4(x)= (x-1)^4+(x-1) $$
Because both sub-graphs are cycles.
On the other hand, the Pkr(x) in this case is equals to  Pk2(x). So, the chromatic polynomial for a complete graph with n = 2, could be expressed as :
$$x(x-1)$$
So, my main doubt is if this reasoning is right. Because I'm not sure about my resolution and I think that Ia have missing something in the final response.
Thanks a lot!
Answer: The formula
$$
   P_G(x) = \frac{P_{G_1}(x) \cdot P_{G_2}(x)}{P_{K_r}(x)}
$$
that you are using is appropriate when $G$ is the clique sum of the graphs $G_1$ and $G_2$ along a copy of $K_r$.
The graph you give,

is not a clique sum of two cycles. Instead, it is a clique sum (along a $K_2$) of the graph induced by vertices $\{a,b,c,d,e\}$ and the graph induced by vertices $\{d,e,f,g,h\}$.
Both of these are not cycles, but cycles with an extra leaf vertex. Here is how we deal with that extra vertex. If the cycle has chromatic number $(x-1)^4+(x-1)$, then there are always $x-1$ ways to color the leaf vertex with a color different from its only neighbor, so in this case we have $P_{G_1}(x) = P_{G_2}(x) = (x-1)^5 + (x-1)^2$.
Applying the formula, we get
$$
   P_G(x) = \frac{[(x-1)^5 + (x-1)^2]^2}{x(x-1)} = x^8-9 x^7+36 x^6-82 x^5+114 x^4-96 x^3+45 x^2-9 x.
$$
(A quick sanity check which this result passes and yours does not is that the degree of $P_G(x)$ must be the number of vertices in $G$.)
Answer: Using standard techniques:
$$x^8-9 x^7+36 x^6-82 x^5+114 x^4-96 x^3+45 x^2-9 x$$


Establishing additive and multiplicative inverses for a finite field

Question: I am struggling with the following problem:

Let $F$ be a finite field, and let $G$ be a subset of $F$ with the following properties: $0$ and $1$ are in $G$; whenever $a$ and $b$ are in $G$, $a + b$ and $ab$ are in $G$. Prove that $G$ is a field.

So I know that $G$ will inherit the associative, distributive and commutative properties from $F$, meaning that all that remains if to establish that there exists additive and multiplicative identities for all elements in $G$.
Could someone kindly point me in the right direction with this one?
Comment: The hypotheses that $0,1 \in G$ are somewhat more than necessary: all that is needed is for $G$ to contain at least two distinct elements.
Answer: Use the fact that:
If $G$ is a finite group and $H$ be a subgroup of $G$ such  that $a,b\in H\implies ab\in H$ then $H$ is a subgroup of $G$ .(Why?)

Only thing that remains to show is that $a\in H\implies a^{-1}\in H$ this is true since the group is finite for any $a\exists n\in \mathbb N$ such that $a^n=1\implies a.a^{n-1}=a^{n-1}.a=1$ .thus $a$ has an inverse

Can you complete now ?Remember a field is a group with both the binary operations
Answer: Your reasoning is great so far. Here is a hint for both additive and multiplicative inverses:
If $A$ is a finite group with operation $\star$, then for any given $a\in A$, the inverse of $a$ is a power of $a$; that is, for some $n$, we have
$$a^{-1}=a^{n}=\underbrace{a\star a\star\cdots\star a}_{n\text{ times}}$$
That's because any element of a finite group has finite order (e.g., by Lagrange's theorem), so there is some $k\geq 1$ for which $a^k=1$; then we have
$$a^{k-1}\cdot a=a^k=1$$
which implies $a^{k-1}$ is the inverse of $a$.
The particular groups to use this observation on would be $(F,+)$ and $(F\setminus\{0\},\,\times\,)$.
Comment: Thank you for your help, I hadn't thought of using Lagrange's Theorem. I am struggling a little to understand how your 'star' operator could be anything other than multiplication? Does extending Lagrange's Theorem also help to establish the existence of the additive identity?
Comment: The symbol $\star$ is just a notation, you can use the symbol $+$ just as well. Then the content of my answer becomes
$$-a=na=\underbrace{a+a+\cdots+a}_{n\text{ times}}$$
and
$$(k-1)a+a=ka=0$$
"Additive notation" vs. "multiplicative notation" makes no difference.
Answer: A finite (and non-empty) subset $S$ of any group $(G,\ast)$ closed under the group operation $(\ast)$ is a subgroup ($G$ need not be finite). The proof is similar to Zev Chonoles':
Let $a \in S$. By closure, all positive powers of $a$:
$a, a\ast a = a^2, a\ast a\ast a = a^3$, etc. are all in $S$.
Since $S$ is finite, these all cannot be different. Hence there exist two (positive) integers $m < n$, such that $a^m = a^n$. It follows that for $k = n - m$, that:
$a^k = a^{n-m} = a^na^{-m} = a^n(a^m)^{-1} = a^n(a^n)^{-1} = e_G$ (Note here, we are working "in $G$" to prove something about $S$, because we do not yet know if $a^{-m}$ lies in $S$, but it certainly lies in $G$).
Since there is some $k \in \Bbb Z$ with $k > 0$ such that $a^k = e_G$, there must be a least such positive integer (the positive integers are well-ordered). Let's call it $t$.
We have $\{a,a^2,a^3,\dots,a^{t-1}\} \subseteq S$, and these are all distinct, by the minimality of $t$. Clearly, $a^{t-1} = a^ta^{-1} = e_Ga^{-1} = a^{-1}$ (in $G$ - note this is the unique inverse of $a$ in $G$), and thus $a^{-1} \in S$, for any $a \in S$.
Hence $S$ contains all inverses, and consequently the identity $e_G$ as well, and is thus a subgroup of $G$.
If $G$ itself is finite, of course, any subset will be, as well.
Note that $(F,+)$ and $(F-\{0\},\cdot)$ are groups, by definition of a field, and $F$ is finite.
Answer: Apply the more general fact below to $G \subseteq (F,+)$ and to $G\setminus0 \subseteq (F\setminus0,\cdot)$.

Let $M$ be a monoid with cancellation.
  If $S$ is a finite submonoid of $M$, then $S$ is a subgroup of $M$.

We need to prove that every element $a\in S$ has a two-sided inverse in $S$.
Indeed, take $a\in S$ and consider $f: S \to S$ given by $f(x)=ax$. Then:

$f$ is makes sense because $S$ is closed under the operation of $M$.
$f$ is injective because $M$ has cancellation.

Therefore, $f$ is surjective because $S$ is finite. In particular, $e \in S$ is in the image of $f$, that is, there is $b \in S$ such that $ab=e$.
By considering $x \mapsto xa$, we conclude in the same way that there is $c \in S$ such that $ca=e$.
Finally, $c=ce=c(ab)=(ca)b=eb=b$, which means that $ab=e=ba$, and $a$ is invertible in $S$.


How to fix "Undefined index"

Question: I'm working on displaying information about users on their profile pages.
I want to display a field; if this field is not completed then I display a text message, else, I display its value.
I've written this code:
<?php
     $username = $user_profile['field_username'];

     if($username == "") {
       echo 'Please enter a user';
     } else {
       print render ($user_profile['field_username']);
     }
?>

I get this error:

Undefined index : field_username

But the code is working properly.
Answer: With the following line of your code:
$username = $user_profile['field_username'];

It always gets executed and check index field_username. So in case if the index doesn't exist it throws error.
If you replace your code with the following
if(empty($user_profile['field_username'])) {
  echo 'Please enter an user';
} else {
  print render ($user_profile['field_username']);
}

It will not always check field_username index but only if it is not empty.
Answer: The error:

Undefined index : field_username

informing you that you've Undefined index in your array.
It is similar to:

PHP: Notice: Undefined variable

which says that you've Undefined variable.
Either way, it is just a notice, so the code always would work in that kind of error without affecting any functionality. These kind of messages are displayed on the screen, to help programmers to track the potential code issues.

Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.php.net

In your case the notice in the following code:
$username = $user_profile['field_username'];

means that PHP couldn't find field_username key inside the $user_profile array. This could mean several things, such as typos, missing field name, loading empty object or the one without that field, etc.
You can of course disable that kind of errors, but the real problem is that your code isn't written well and it takes some time and experience to follow the coding standards which helps you to avoid such issues.
To avoid the notice, your code can be simplified to one-line of code:
echo !empty($user_profile['field_username']) ? render($user_profile['field_username']) : t('Please enter a user');

If you've more questions about your code quality, you can always ask at Code Review Stack Exchange.
For more reading, check: PHP: "Notice: Undefined variable" and "Notice: Undefined index" at SO

How to fix "Undefined index"


What order should configuration import and module updates be run?

Question: Since the schema version of modules is stored in the key-value storage, it is unique to each site and is not synced through configuration management.  That makes sense, since updates may need to make adjustments that are not encapsulated in config (such as database updates), but there are other changes that may also be included in config (e.g. adding a new config value).

Are there any risks to running config import and database updates in either order?
What is the preferred order for running those operations?
Do update hooks need to make any special accommodations for config items that may have already been imported?
Are there any other operations that may be required to fully update the production environment?
Comment: Related issue: https://www.drupal.org/node/2901418:
Answer: Updates must be run before configuration is imported
A pending issue against core will ensure that the code and schema versions match before allowing configuration to be imported.

Problems with config import before updates

An update hook relying on a configuration value could end in a different result than if it were run on the pre-import value.
An update could potentially fail if it tried to create configuration entities that already exist.

Concerns for config import after updates

If an update that introduces a new configuration entity is run first, it will create a new configuration item that will have a differing UUID than the one that is in config.  However, once the config is imported the entity should be replaced with the config version.
There could be a potential problem here if replacing the entity would affect associated content.  For example, if an update migrates content from one field to another, on config import the field would be completely replaced and the content potentially lost.  In this instance the deployment process may need to be adjusted to run the updates on the target environment and export the resulting configuration.
Comment: I had previously left an answer that order doesn't matter (just that the order of updates and config should be the same as it was implemented). I'm thinking I was wrong, because you should always export config after updating. So, on local, update then export, on deploy, update then import.
Comment: As the linked issue discusses, there is a case where our entity updates require a new field to be imported or else the post_update hook will fail. In this case, we need the config import done _before_ the database updates. Seems the freshest take on this is here: https://www.drupal.org/project/drupal/issues/2901418


$\pi_q(S^n) \cong \pi_q(\Bbb RP^n)$

Question: I'd like to prove that $\pi_q(S^n) \cong \pi_q(\Bbb RP^n)$ when $q>1$ and $n>1$. Do I have to prove this by cases? I mean, the cases $q<n$, $q=n$ and $q>n$? Or can I prove it directly? Which theorem or result could I use?
Comment: Another way of seeing this is via the long exact sequence for homotopy groups associated to a fibration $F \to E \to B$.  Since $S^n$ is a 2-fold covering of $RP^n$, you have the fibration $S^n \to RP^n$ with discrete fibers.  Applying $\pi_q$ termwise to the exact sequence, you get the desired isomorphism (when $q > 2$).
Answer: In general, if $p : X \to Y$ is a covering map, then $p_* : \pi_q(X) \to \pi_q(Y)$ is an isomorphism for $q > 1$.
To see this, first note that any map $f : S^q \to Y$ lifts to a map $f' : S^q \to X$ because $S^q$ is simply connected. Therefore $f = p\circ f'$ and hence $[f] = [p\circ f'] = p_*[f']$; that is, $p_*$ is surjective. For injectivity, suppose $[g] \in \pi_q(X)$ is in the kernel of $p_*$ so that $p_*[g] = [p\circ g] = 0$. Then there is a homotopy $H : S^q\times[0, 1] \to Y$ between $p\circ g$ and a constant map $c$. As $g$ is a lift of $p\circ g$ there is a homotopy $H' : S^q\times[0, 1]$ between $g$ and $c'$, a lift of $c$ - here we have used the homotopy lifting property, see Proposition $1.30$ of Hatcher's Algebraic Topology for example. As $S^q$ is connected, $c'$ must also be constant, and hence $g$ is nullhomotopic, i.e. $[g] = 0$. Therefore $p_*$ is injective and hence an isomorphism.
As $p : S^n \to \mathbb{RP}^n$ is a covering map for any $n$, so we see by the above that $p_* : \pi_q(S^n) \to \pi_q(\mathbb{RP}^n)$ is an isomorphism for $q > 1$.
Comment: Do you mean $[f]=[p \circ f']$ and $p_*[g]=[p \circ g']$?
Comment: Yes to the first one, no to the second - at no point is there a map called $g'$.
Comment: The only part I don't understand is "As $S^q \times [0,1]$ is connected, $c'$ must also be constant. Are you using uniqueness of the lifting? Isn't it enough that $S^q$ is connected since it's the domain of $c'$?
Comment: You are correct, $c' : S^q \to X$, so only the connectedness of $S^q$ is relevant.

$\pi_q(S^n) \cong \pi_q(\Bbb RP^n)$


Continued fraction proof from matrix form

Question: By using the definition
$$\pmatrix{p_n&p_{n-1}\\q_n&q_{n-1}} = \pmatrix{a_0&1\\1&0} \pmatrix{a_1&1\\1&0} \cdots \pmatrix{a_n&1\\1&0}$$
I need to show that $p_n/q_n$ is the continued fraction $[a_0;a_1, ..., a_n]$
Answer: The continued fraction notation means $$[a;m] = a + 1/[m].$$
From $$\pmatrix{p_0&p_{-1}\\q_0&q_{-1}} = \pmatrix{a_N&1\\1&0}$$ we take the base case to be $(p_0,q_0) = (a_N,1)$, $(p_{-1},q_{-1}) = (1,0)$. This holds trivially.
We show the rest by induction. If $p_n/q_n$ is the convergent for $[m]$ then $$p_{n+1}/q_{n+1} = a + 1/[m] = a + q_n/p_n = \frac{a p_n + q_n}{p_n}.$$
So to complete the proof we check $$\pmatrix{p_{n+1}&p_{n}\\q_{n+1}&q_{n}} = \pmatrix{a p_{n} + q_n &p_{n}\\p_{n}&q_{n}} = \pmatrix{a&1\\1&0}\pmatrix{p_n&p_{n-1}\\q_n&q_{n-1}}.$$


Is there a characterization of groups with the property $\forall N\unlhd G,\:\exists H\leq G\text{ s.t. }H\cong G/N$?

Question: A common mistake for beginning group theory students is the belief that a quotient of a group $G$ is necessarily isomorphic to a subgroup of $G$.  Is there a characterization of the groups in which this property holds?
If this question is too broad, I might ask if such a characterization exists for $p$-groups.

History: I originally posed the opposite question, regarding groups for which $\exists N\unlhd G\,:\, \not\exists H \unlhd G\, \text{  s.t. } H \cong G/N$, and crossposted this to MO.  I received an answer there to the (now omitted) peripheral question about probability, which shows that most finite groups probably have this property.  After this, I changed the question to its current state, as this smaller collection of groups is more likely to be characterizable.
Comment: There is a discussion of this here: http://groupprops.subwiki.org/wiki/Quotient_group_need_not_be_isomorphic_to_any_subgroup
Comment: I found this paper https://link.springer.com/article/10.1007%2FBF01228254
Comment: Note that all quasisimple groups have the property.
Comment: A genuinely quasisimple group $G$ , that is one with a non-trivial center, has a homomorphic image which is not a subgroup, namely $G/Z(G).$
Comment: If $G$ is a free group of rank $\ge 2$ then $G'$ has the required property.
Comment: @yatima2975 I don't think that is in fact a restatement unless every subgroup $H$ can be put into a subnormal series. This won't be the case in general, for instance in any finite non-nilpotent group.
Comment: how do you define the probability space?
Comment: All finite abelian groups *don't* have the property, and non-abelian groups of order $\,p^3\,\,,\,\,p$ a prime have it.
Comment: @DonAntonio: Are you sure about your statement for non-abelian groups of order $p^3$? $Q_8$ has the property, but a non-abelian group of order $p^3$ and exponent $p$ (implying $p>2$) doesn't have it.
Comment: I made a mess with "the property", which by the OP must be that there exists a subgroup such that non-homomorphic image of the grous is isomorphic to it, so you are right: $\,Q_8\,$ does have it taking $\,\langle i\rangle\cong C_4\leq Q_8\,$. I confused things this since "the property" in this case is defined by negation: NOT having a subgroup...etc. Thanks.
Comment: A rather trivial restatement of the property, but with obvious routes to generalization: consider all subnormal series  $1 =H_0 \triangleleft H_1 \triangleleft \cdots \triangleleft H_n = G$ of $G$. The property now says that the set of top factors $G / H_{n-1}$ has an element that is not isomorphic to any in the set of bottom factors $H_1 / 1$. Are there any results on when composition factors are freely permutable?
Comment: Every torsion-free hyperbolic group $G$ has such a subgroup $N$ *if* all hyperbolic groups are residually finite. This is because all hyperbolic groups being residually finite is equivalent to all hyperbolic groups having a subgroup of finite index. If $G$ is torsion-free hyperbolic and $N$ is a finite-index subgroup then $G/N$ is torsion and so cannot embed into $G$.
Comment: Take any vector space $V$, and $W \subset V$ a subspace of $V$,  and let $W'$ be the orthogonal complement of $W$, $W' \cong V/W$.
Answer: In the comments, Charles Hudgins was kind enough to link me to Ying, J.H. Arch. Math (1973) 24: 561. This was a paper leading up to John Hsiao Ying's 1973 PhD thesis, Relations between subgroups and quotient groups of finite groups. As far as I can tell, the thesis is not available online anywhere; however, I was recently able to track it down from the library at State University of New York at Binghamton. I will summarize here what I learned from reading his research, and also aggregate some of the information from the help I've gotten from you lovely people. Shout out to Dr. Ying, if you're out there somewhere.
There are still open questions littered throughout this answer and around this topic in general, which will hopefully draw some interest from all of you. Please feel free to ask new questions based on this one, or to edit this answer with updated information if you know something I don't.
Definitions
First of all, it turns out there is some existing terminology for studying the relationship between subgroups and quotients. As we have seen in the history of this question on MSE and MO, it is easy to confuse the condition defining these groups with a number of subtley different conditions, each which have different consequences. The paper introduces the groups that are the topic of this question as those "satisfying condition (B)," but the thesis goes on to give them a name: Q-dual groups. There are several related definitions, the most relevant of which I will condense as follows.

An S-dual group satisfies $\forall H\leq G,\:\exists N\unlhd G\text{ s.t. }H\cong G/N$ -- that is, each subgroup of $G$ is isomorphic to a quotient group of $G$.

A Q-dual group satisfies $\forall N\unlhd G,\:\exists H\leq G\text{ s.t. }H\cong G/N$ -- that is, each quotient group of $G$ is isomorphic to a subgroup of $G$.

A group which is S-dual and Q-dual is self-dual.

Actually, there are two definitions for a self-dual group. The one I've picked comes from Fuchs, Kertész, and Szele (1953). In the context of Abelian groups, there is an alternative definition, which Baer will roar at you about in these papers if you care.
Examples and nonexamples
So, what do we know about Q-dual groups?
To begin with, Q-dual groups are rare. Here Derek Holt presents evidence that most groups are not Q-dual, where "most" is defined in the sense that if $g(n)$ denotes the fraction of isomorphism classes of finite groups of order $\leq n$ that are not Q-dual, $g(n)\to 1$ as $n\to \infty$. On the other hand, it's also important to note that S-dual groups are more rare than Q-dual groups, which is something that Ying points out.
Let's look at some examples, some from the comments, some from papers. Here are some groups which are Q-dual:

Finite simple groups

Symmetric groups

Hall-complemented groups (for each $H\leq G$, there is a $K\leq G$ with $H \cap K = \mathbf{1}$ and $G=HK$)

Higman-Neumann-Neumann type universal groups (see Higman, Neumann, and Neumann (1949))

The semidirect product $A\rtimes \langle z \rangle$ of an abelian $p$-group $A$ with a power automorphism $z$ of prime power order.

Some groups that are not Q-dual:

Some simple examples: $C_3\rtimes C_4$, $C_4\rtimes C_4$, $C_5\rtimes C_4$ with a nontrivial center
Any quasisimple group (that isn't simple)
The commutator subgroup of a free group of rank $2$
Finitely generated linear groups over a field characteristic $0$. More generally, by Selberg's lemma and Malcev's theorem, any torsion-free hyperbolic group that is residually finite is not Q-dual (which may constitute all torsion-free hyperbolic groups; see here)

Relating this to other properties,

Q-dual groups may or may not be solvable and vice versa
Q-dual groups may or may not be nilpotent and vice versa (this relationship discussed in a section below)
Q-dual groups may or may not be $p$-groups and vice versa
the Q-dual property is not subgroup closed (see example in last section)

Reduction to smaller order
It's often desirable to throw away irrelevant parts of a group when studying a property.

Let $G$ be Q-dual. If there exists an element of prime order in the center that is not a commutator, then $G$ has a non-trivial, cyclic direct factor.

This dovetails nicely with the next theorem.

Let $G$ be Q-dual. If $G=H\times \langle x \rangle$, $H$ and $\langle x \rangle$ are Q-dual.

This lets us reduce away cyclic direct factors.
Building examples of Q-dual groups
To build new Q-dual groups from old ones, take any Q-dual group $H$ that has a unique non-trivial minimal normal subgroup. Given a prime $p\not\mid |H|$, $H$ has a faithful irreducible representation on an elementary abelian $p$-group $C_p^{\; n}$, so we can build $G=C_p^{\; n}\rtimes H$, which is Q-dual by the theorem. You can keep going with that, tacking on as many primes as you like.
Next we have a large class of easily constructed Q-dual groups.

Let $A$ be an elementary abelian $p$-group and $\varphi\in\operatorname{Aut}(A)$ have prime order. Then $A\rtimes \langle \varphi \rangle$ is Q-dual.

It's possible that this family comprises all nonabelian Q-dual $p$-groups of class $2$ with exponent $p$, but this is open.
Relationship to nilpotency
Ying's work focuses largely on nilpotent groups, based on the observation that the Q-dual condition is most pronounced in groups with many normal subgroups. Together with the (almost surely true) conjecture that most finite groups are nilpotent, this seems like a pretty good place to start.

A nilpotent group $G$ is Q-dual if and only if all of its Sylow subgroups are Q-dual.

(Actually this is proven in a paper by A.E. Spencer, which I have yet to get ahold of. I'll post a link when I do.)
This is fair enough, and lets us reduce to studying $p$-groups. From here, he delves into nilpotency class.

Let $G$ be an odd order Q-dual $p$-group of class $2$. Then $G'$ is elementary abelian.

The additional hypotheses that $p$ be odd and the nilpotency class be $2$ are important. The counterexample given is the dihedral group of order $16$, whose commutator subgroup is cyclic of order $4$, and which has nilpotency class $3$. It's important to note that this is a $2$-group, however, and it may be that this is what causes the generalization to fail, not the higher class. In particular, it is still open (as of 1973!) whether odd $p$-groups of class greater than $2$, or $2$-groups of class $2$, have elementary abelian commutator subgroups.

Let $G$ be an odd order Q-dual $p$-group of class $p$. Furthermore, suppose $\Omega_1(G)$ is abelian. Then $G=A\rtimes \langle z \rangle$ where $A$ is abelian, $z$ has order $p$, and $[a,z]=a^{\operatorname{exp}(A)/p}$ for all $a\in A$.

When $\operatorname{exp}(G)>p^2$, this becomes an if and only if.

Let $G$ be a $p$-group of class $2$ with $\operatorname{exp}(G)>p^2>4$. Then $G$ is Q-dual if and only if $G=A\rtimes \langle z \rangle$ where $A$ is abelian, $z$ has order $p$, and $[a,z]=a^{\operatorname{exp}(A)/p}$ for all $a\in A$.

That is a pretty thorough characterization of this special case. When $\operatorname{exp}(G)\leq p^2$, things get more complicated.

Example. Let $p$ be an odd prime, $|a|=p^2$, $|b|=|c|=p$, $[a,x]=a^p$, $[a,y]=b$, $[c,z]=a^p$, and all other commutators between $a,b,c,x,y$ and $z$ equal to $1$. Then $\left(\langle a\rangle\times \langle b\rangle\times \langle c\rangle\right)\rtimes \langle x,y,z\rangle$ is a finite Q-dual $p$-group of class $p$ and exponent $p^2$.

This example shows that the Q-dual property is not subgroup closed, via the subgroup $\langle a,c,x,z\rangle$. It also shows that finite Q-dual $p$-groups of class $2$ need not contain an abelian maximal subgroup. It is still open whether there are counterexamples of this nature for odd primes $p$.


Pandas Python Script Error - AttributeError: 'DataFrame' object has no attribute 'append'

Question: Have this section of code
repTab = pd.DataFrame([[reply.author.name, gottem, reply.created_utc]])
repHolder = repHolder.append(repTab)

getting this error
return object.getattribute(self, name)
AttributeError: 'DataFrame' object has no attribute 'append'

Tried to fix it to support the updates since code was last used with this:
repTab = pd.concat((reply.author.name, gottem, reply.created_utc))
repHolder = repHolder.append(repTab)

but that didn't work either and just gave different errors
Not sure how to rewrite it for the current version of pandas
Comment: "but that didn't work either and just gave different errors" - no, it gave you one error, because you tried one thing, and once there is an error everything stops. Did you try reading that error? Did you try reading the documentation for `pd.concat`, in order to understand what should be passed to it? Do you see how the data you pass to `pd.concat` in this attempt, differs from `repTab`? "Not sure how to rewrite it for the current version of pandas" - why do you expect that this has to do with the Pandas version? Did you test the same code with the older version?
Comment: Read the docs about `concat`: https://pandas.pydata.org/docs/reference/api/pandas.concat.html?highlight=concat#pandas.concat
Answer: Concat like this:
repTab = pd.DataFrame([[reply.author.name, gottem, reply.created_utc]])
repHolder = pd.concat([repholder, repTab])


What is the difference between legitimate doubling and un-stylistic voice leading?

Question:
Here is part of a string section I am working on with 2 violas, 3 celli and 2 double basses. I am trying to learn from a composers point of view how many independent voices there are here? My guess is that there are only 3 and they are played by the cellos. The others are either unison or octave doublings. My guess is that the viola at the beginning doubles the 1st cello at the unison while the higher viola  in bar 26 doubles the 2nd cello at the octave. The basses double the lowest cello at the octave below and in unison. These are my guesses and I could be wrong so pelase correct me?
If I am correct however, how does one distinguish such lines as doubles or as new "voices"? My guess is that when a musical line is doubled, it must be doubled in a certain way to be considered a legitimate double. In this case, the upper viola comes in at the second hypermeasure. If you introduce that second viola half way through the bar would it still sound like a double or be considered bad voice leading? Or perhaps, the only thing that matters when doubling is that for it sound like doubling, all the notes should be consistently doubled from the beginning to the end of a phrase or hypermeasure as in this case. Although that doesnt work because many times the whole orchestra might play in unison and then branch out into independent voices in the middle of a phrase switching from one melody doubled in various octaves back to independent voice leading again. It seems confusing, some clarification on the topic would be very helpful.
Comment: By definition, doubles are not "voices" they are like EQ to thicken a texture at a specific area in the frequency spectrum. Doubles consistently move in parallel similar motion to thicken a texture. Doubles in 4 part writing or counterpoint need to maintain independence via voice leading rules and how you move to and from them is what creates independence.. Doubling is not independence. It is like layering sound.
Comment: Isn't a double any additional voice sounding at the octave or unison? I don't think doubling has to begin or end at any specific times because it's a change in texture, not tonality. You can have any number of voice start or end the same pitch class at any time and it becomes a timbral melody, not a tonal melody.
Comment: I think you've got the right answers contained in the question and these comments, and you just need confirmation/clarification. Yeah, afaik "true doubling" can come and go, it doesn't matter on which beat or for how long, just as long as it doesn't "intermingle" with separate voice leading.
Comment: I think we're each misunderstanding each other.
Comment: I think what you meant by "timbral" melody is exactly what I mean by tones that thicken the texture by layering notes and when you say "tonal" melody you mean a melody that is part of the voice leading. Is this right?
Answer: You don't need to 'guess' whether one instrument is doubling another's line!  It's clearly shown in the notation.
Anyway.  This isn't 'part writing' in the manner of a SATB vocal exercise.  The object isn't to maintain a constant, rich texture with independent voices following the principles of effective voice leading.   There's a melody, mostly doubled by first cello and viola with occasional moments of harmonic reinforcement.   Then there's a more rhythmic accompaniment in lower cellos and basses.  Two musical elements, a varying texture.  And it's fine for the texture to vary in density, as long as it doesn't happen by mistake and you like the effect!
Listen to it.  Do you like the way the melody is occasionally harmonised with an extra voice above?  The way the lower instruments move from an open 5th to wider intervals, then everyone (almost) falls into unison at bar 29?   Fine!  These are composing decisions, not rule-following.
Comment: In orchestral writing many if not most of the times the piece is written with correct voice leading and many times in 4 parts and then thickened via doubling. The 3 cellos here still move independently like 3 independent voices
Comment: Look again.  The two lower cellos and the basses have block chords and a definite rhythmic function.  The other instruments have a more melodic function.   There's little real counterpoint.   And that's all OK!
Comment: THe basses are not part of the voice leading. They just double the lower cellos to provide low end weight. The voice leading is in the cellos in 3 parts. Please explain why I am wrong? THe chord progression is Dm, Bb/D and Gm/D,C/D it is a pedal point under a i VI iv bVII progression
Comment: Well, OK.  You seem to have good understanding of what you've written.  So what's the problem?  Are we just arguing over labels?
Comment: Im hoping to get some discussions re the title. Like under what circumstances doubling becomes parallel octaves and 5ths. My harmony book "shows some examples amd then shows reductions with basic voice leading but it is very brief. Something like an example with doubling and then why it is not considered a voice leading error would be most helpful. That is what Im lookibg for IOW.
Comment: You can double at the unison, you can double in octaves and 5ths.   It's not an either/or.
Comment: We tend not to do either in SATB writing.  We do it all the time in orchestral writing.
Comment: Laurence SATB writing forms the basis for much orchestral writing


How to make an image stretchable like it's being viewed on a image viewer?

Question: I'm trying to make a personal website that is just an image (for now till I have web dev classes)
As the title says, I want to make an image stretchable like it's being viewed on an image viewer. When I view the page there's the image, but I could scroll down to see the rest of an image and I don't want that. When I say "like it's being viewed on an image viewer" I mean have black bars on sides like here:

I have no idea where to start nor how to search for it, that's why I'm asking here.
Here's the source code of my site rn (it's atrocious)
Comment: Please see [ask] and take the [tour]. You need to show some code here in your question. Also, [never link "here"](https://www.smashingmagazine.com/2012/06/links-should-never-say-click-here/#here-conceals-what-users-are-clicking).
Comment: It would be super helpful if you could make a small bit of your code available as demo instead of us looking through a github repo. That said, you're either looking for [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size) or [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit). For both, `cover` will stretch the img or bg until the smallest side fills the container, and `contain` will stretch the img or bg until the largest side fills the container. Cover will fill the whole area, and contain will scale until it hits an edge.
Comment: Welcome to Stack Overflow!  Please see [Something in my web site or project doesn't work. Can I just paste a link to it?](https://meta.stackoverflow.com/q/254428/328193)  Relevant code needs to be included in the question to produce a [mcve] which demonstrates the problem, as well as information about the problem itself and what debugging you have done.  To learn more about this community and how we can help you, please start with the [tour] and read [ask] and its linked resources.
Comment: As for the functionality you're describing... If I were to attempt this, my initial approach would be to figure out how to style an image to (1) take up 100% of the window height and no more, and (2) keep its aspect ratio (either automatically or by re-calculating it in code).  I'd try to apply this either to an `` element or to a `` with an image as a `background`.
Comment: Stretchable, as in you want to stretch the image and deform it somehow?
Comment: Please make this a code snippet instead of linking to your git repo.
Comment: Looks like I only needed to add object-fit: contain; on img and set height to 100%.
Also, I'm sorry for poorly making this question, I didn't know this site is super serious when it comes to coding, should've just ask for this on Reddit
Answer: I've added some JavaScript code within the  tag in the HTML file to enable opening an image when it's clicked, and I've also implemented functionality for a cancel icon to close the image. I'm making an effort to enhance the design of your website as well.
index.html
<!DOCTYPE html>

        <title>Luka tv</title>
        <meta charset="utf-8">
        <link rel="stylesheet" href="style.css">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

✖

style.css
body {
    margin: 0;
    font-family: 'Poppins', sans-serif;
    font-size: xx-large;
    color: white;
    height:100vh;
}

* {
    border: 0; box-sizing: border-box;
}

#container {
    min-height: 100vh;
    width: 100%; max-width: 1200px; margin: 0 auto;
    border: 4px solid white;
    justify-content: center;
    align-items: center;
}

h1 {
    /* background-color: rgba(30,30,30,.6); */
    display: flex;
    align-items: center;
    text-align: center;
    margin-top: 69px;
    margin-left: 21px;
    margin-right: 21px;
    /* padding: 2rem; */
}

span {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* phone styles */

@media screen and (min-width: 320px) {
    body {
        background-color: #000069;
    }

    h1 span::before{
        content: "Hello mobile user, please rotate your screen. Thanks";
    }

    img {
        visibility: hidden;
        position: relative;
        top: 0;
        left: 0;
    }

    .container {
        position: relative;
    }
}

/* tablet styles ig */

@media screen and (min-width: 700px) and (min-height: 210px) {
    body {
        background-color: #000096;
    }

    h1 span::before{
        content: "Hello tablet user, please rotate your screen. Thanks (also I'm not centering this text, fuck you)";
    }
}

/* wysi styles */

@media (min-width: 727px) and (max-width: 727px) and (min-height: 211px) and (max-height: 211px) {
    body {
        background-color: black;
    }

    h1 span::before{
        content: "WYSI";
    }
}

/* tablet styles again */

@media screen and (min-width: 728px) and (max-height: 212px) {
    body {
        background-color: #000096;
    }

    h1 span::before{
        content: "Hello tablet user, please rotate your screen. Thanks (also I'm not centering this text, fuck you)";
    }
}

/* desktop styles */

@media screen and (min-width: 769px) {

    body {
        background-color: white;
    }

    h1 span::before{
        content: "";
        background-image: url(webpage.png);
    }

    #container {
        border: 0px;
        min-height: auto;
    }

    img {
        visibility: visible;
    }

}

img {
    width: 50%;
    border:5px rgb(255, 221, 0) solid;
    transition: all ease .4s;
}
img:hover {
    opacity:0.7;
    border:5px rgb(255, 255, 0) solid;
    scale: 102%;
}
img.show {
    border:none;
    transition: none;
}
img.show:hover {
    opacity:100;
    border:none;
    scale:100%;
}
img.show{
    display: block;
    margin: 0 auto;
    width: 90%;
}
p{
    position:fixed;
    top: 0;
    right: 3%;
    cursor: pointer;
}
p.unshow{
    display: none;
}
p.show{
    display: block;
}

Comment: Don't think this is an answer to the question


What is wrong with this iOS animation block?

Question: + (void) AnimateSwitchingWithParent: (UIViewController *) ParentController From: (UIViewController *) From To: (UIViewController* ) To {

To.view.frame = ParentController.view.bounds;

[UIView transitionFromView:From.view toView:To.view
        duration:1
        options:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL];

ParentController.view = To.view;

[To viewWillAppear:true];
}

this is my function to make animation that will be called if want to change view from 1 view to another view, but I have problem, I have a viewController named filter, at there I have Button called Reset that will reset all of content inside
but to show that the reset have done, I want to call
[self AnimateSwitchingWithParent:self From:self To:self];
but the result is My View was blank. how can it be? any one have another way?
Comment: PLEASE start using naming conventions, i.e. correct upper and lower case. It makes reading and understanding code so much easier (and prevents bugs as well).
Answer: If you have to flip the current view controller's view while resetting content, use the transitionWithView:duration:options:animations:completion: method.
Example
[UIView transitionWithView:self.view
                  duration:1.0f
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                animations:^(void) {
                    [self resetStuff];
                }
                completion:nil];

Side Note
You current implementation in the question will be useful to switching views in the view hierarchy. Say From.view is the subview of ParentController.view then the statement below will replace From.view with To.view as the subview of ParentController.view.
[UIView transitionFromView:From.view toView:To.view
    duration:1
    options:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL];

You definitely don't need to do this,
ParentController.view = To.view;

Doing that will replace the ParentController's view which might be different from what you intended and definitely in contradiction to the transition animation on the line before.
You must definitely not be calling,
[To viewWillAppear:true];

directly.
To my understanding you should be able to remove the last two lines.


Stored procedure error 'Invalid Column'

Question: I want to change the below C# code from ordinary SQL to a stored procedure but it always show error on columns that they are Invalid Column. What is wrong with the stored procedure?
CREATE PROCEDURE [dbo].[usp_AdminRegPage1]
     (@VendorId VARCHAR)
AS
BEGIN
    SET NOCOUNT ON;

    SELECT WorksPackage,MajorWorks FROM dbo.RegPage1 WHERE Vendor_Id = @VendorId;
END

protected void DisplayRecord()
{
     SqlConnection SqlCon = new SqlConnection(GetConnectionString());
     string sql = "SELECT WorksPackage,MajorWorks from RegPage1
                                                 WHERE Vendor_ID='"+lblPage1ID.Text+"'";
     var da = new SqlDataAdapter(sql, SqlCon);
     var ds = new DataSet();

     da.Fill(ds);

     if (ds.Tables[0].Rows.Count > 0)
     {
        txtMajorPackages.Text = ds.Tables[0].Rows[0]["WorksPackage"].ToString();
        txtRegP1Works.Text = ds.Tables[0].Rows[0]["MajorWorks"].ToString();
     }
}

Comment: Where is the code that calls the proc?
Comment: Could there be another `RegPage1` table in a different schema? What column is being reported as Invalid? And we may need to see the calling code.
Comment: What is the error? Does there any data exist? What is the data type of your VendorId  column?
Comment: If you're working in a case sensitive collation, then `Vendor_ID` and `Vendor_Id` aren't the same column.
Comment: What shows an error? If you are talking about intellisense just ignore it and try it. You may need to refresh the cache (`Ctrl` + `Shift` + `R`). Also declare a length for your `varchar` parameter as the length defaults to 1.
Comment: Sorry.still I am not write code for calling the SP.My question is that the 'SELECT' command is working fine then why it show error as 'Invalid column name WorksPackage' in SQL editor?
Comment: Sounds like the name of that column is something different. Check the column name in sql server
Comment: I think column name "WorksPackage","MajorWorks"  did not match with column names of your table . pls check that first
Comment: Also what SQL editor are you using? SSMS or Visual Studio?
Comment: @MartinSmith : I am using SSMS, now the problem is solved after ignore the intellisense.
Answer: Something like this should do the job
public void DisplayRecord()
{
    SqlDataReader rdr = null;

    // create and open a connection object
    SqlConnection SqlCon = new SqlConnection(GetConnectionString());

    try
    {

        SqlCon.Open();

        // 1. create a command object identifying
        // the stored procedure
        SqlCommand cmd = new SqlCommand(
            "usp_AdminRegPage1", SqlCon);

        // 2. set the command object so it knows
        // to execute a stored procedure
        cmd.CommandType = CommandType.StoredProcedure;

        // 3. add parameter to command, which
        // will be passed to the stored procedure
        cmd.Parameters.Add(
            new SqlParameter("@VendorId", lblPage1ID.Text));

        // execute the command
        rdr = cmd.ExecuteReader();

        // iterate through results, printing each to console
        while (rdr.Read())
        {
            txtMajorPackages.Text = rdr["WorksPackage"];
            txtRegP1Works.Text = rdr["MajorWorks"];
        }
    }
    catch (Exception ex)
    {

    }
    finally
    {
        SqlCon.Close();
    }
}

Example taken from this website  http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07.aspx
Comment: Thanks MVCKarl.This will help me to call the SP.
Comment: Please tick or uptick if it helped you. Thanks

Stored procedure error 'Invalid Column'


como posso inserir múltiplos linhas uma vez só usando Sql?

Question: Exportei um registro de dados do Sqlite para Sql Server com Dump. Preciso pegar esses registros e inserir dentro de uma nova tabela que eu criei para receber esses registros dentro do meu banco de dados no Sql server. O problema é que tenho muitos linhas para inserir.Há mais de 1.000 linhas e gostaria de saber se existe uma maneira mais simples de fazer isso que repetir 1000 vezes os insert into nomeDaTabela values...
ex:
INSERT INTO MyTable VALUES ("John", 123, "Lloyds Office");
INSERT INTO MyTable VALUES ("Jane", 124, "Lloyds Office");
INSERT INTO MyTable VALUES ("Billy", 125, "London Office");
INSERT INTO MyTable VALUES ("Miranda", 126, "Bristol Office");
INSERT INTO MyTable VALUES ("John", 123, "Lloyds Office");
INSERT INTO MyTable VALUES ("roger", 23, "Nuvens");
INSERT INTO MyTable VALUES ("jose", 500, "London Office");
INSERT INTO MyTable VALUES ("elanda", 126, "Paris");

Vamos imaginar que esses insert tem mais de 1.000
será que há como fazer de um jeito mais fácil sem repetir 1.000 vezes?
aqui está um print de como está os registros:
Comment: aproveita que tá no notepad++ e faz um macro alterando o texto pra sua necessidade, mais simples...
Comment: Não entendi, vc tem o dump do sql lite com os insert ou não?
Comment: De onde vem as informações? Excel? Outra tabela?
Comment: Esses registros estavam no sqlite.fizemos um conversão para sql server. precisava criar um banco no sql server e gravar esses dados que estavam no Sqlite dentro do Sql server. @rray
Comment: coloque como os dados estão atualmente, seja csv ou xml
Comment: @RovannLinhalis um macro?? não entendi o que é rsrs desculpa.
Comment: Você tem o sql management (ssms) instalado? não é só copiar esses inserts colar e dar um F5 para executar todos de um vez?
Comment: entendi...sim eu poderia até mas tiver que inserir mais um covert(varbinary(max) para  converter imagem então fiz direito para não ter mais trabalho depois.so que eu devo fazer isso para todas as linhas
Comment: @rray quero acreditar que esse seja o dump do sqllite e esteja com estrutura diferente do sql server, não é possível... rs  Gladiador... usar macros no np++ : https://www.youtube.com/watch?v=xQaxDeCwMRg
Comment: Já deu pra entender melhor o problema agora ... se for para colocar essa função em cima de algum valor pode tentar usar o modo coluna do np++ ou um pouco de regex :D
Comment: @rray salvou meu dia cara hahaha valeu.
Comment: @RovannLinhalis agora entendi o que você quis dizer com Macro no notepad++ isso também funcionou bem que dá um pouco de trablho.VALEU por ajudar, valeu mesmo!!
Comment: disponha. Não esquece de postar como foi resolvido seu problema para encerrar a questão
Answer: Existe sim alguns meios mais simples de copiar esses dados:
Linked Server
Pode fazer um linked server do servidor de origem no servidor de destino. Desta forma poderá fazer um insert baseado em um select.
Importação de dados
Pode importar os dados pelo wizard do sql server, clicando com o botão direito no banco de dados de destino, vá em tarefas e importar dados, como na figura a seguir

Editar manualmente os registros na tabela
Ainda existe a possibilidade de clicar com o botão direito na tabela de destino no object explorer e clicar no item "Editar 200 linhas superiores". Com esta opção a tabela abrirá como num excel. E será possível colar os registros caso os mesmos estejam na área de transferência (tanto como origem em um grid, resultado de select ou um excel).
Comment: eu vou tentar fazer desse jeito agora depois te falo. fico grato por você ter respondido :)
Comment: As importações de dados aceitam diversos tipos de origem e conexões de dados.
Comment: @Gladiador, funcionou? Se sim, marque a resposta como uma resposta válida para a pergunta.
Answer: Vá no seu sqlite é faça uma consulta que gere as querys:
select 'insert into ..... values ('+Campo+','..... from sua tabela....

O resultado deve ter o 'script de carga'
Outra opção é exportar a estrutura do banco usando o SQLite Browser, usando a opção Export to SQL.
EDIT
Você pode usar o o resultado de um select para incluir registros numa tabela:
insert into tabela values select campos from tabela.....

Comment: essa parte de exportar a estrutura ja foi feito.E me gerou um monte de insert. Agora precisa só inserir esses dados exportados dentro de uma nova tabela no Sql.
Answer: Então pessoal com a ajuda de vocês consegui resolver esse mistério. para substituir no lugar certo, tive que usar uma expressão regular pelo site https://regex101.com/ testar se ele conseguiria achar exatamente a onde eu deveria fazer meu replace. A minha expressão regular no meu caso foi VALUES .*, ([0-9]{5}), de 5 digitos.'
Depois que ele achou eu só substitui com valores que eu queria em uma linha e  Usei o macro do Notepad++ como foi recomendado por alguém aqui para repetir a mesma ação para todas as linhas e depois jogar no sql e executar os registros e inserir no banco.


Time Series plot in R

Question: The following R codes produce one graph for time series, while the next chunks of codes produce 8 graphs. Why?
births <- scan("http://robjhyndman.com/tsdldata/data/nybirths.dat")

birthstimeseries <- ts(births, frequency=12, start=c(1946,1))
birthstimeseries

plot.ts(birthstimeseries)

The 2nd chunks of codes:
library(Matrix)

i <- c(1, 3, 8, 4, 2, 7, 6, 9, 1, 4, 10, 5, 11, 2, 12)
j <- c(2, 5, 3, 8, 6, 2, 4, 2, 4, 5, 2, 7, 3, 2, 1)
x <- rpois(15, 5)
M4 <- sparseMatrix(i, j, x = x)
M4_regular_matrix <- as(M4, "matrix")

timeseries <- ts(M4_regular_matrix)
print(timeseries)

plot.ts(timeseries)

Also, in the first graph, how is the plot drawn? Is it, for the year 1946, it connects all the points from Jan to Dec, and the last point of 1946 is connected to the first point of 1947, and so on?
Answer: ts represents data which has been sampled at equispaced points in time, indicated by frequency
The first example is a single timeseries sampled $12$ times a year (i.e. monthly) and gives a plot based on using $1946$ for January 1946, $1946.083$ for February 1946, adding $\frac1{12}$ for each month up to $1959.917$ for December 1959. Each point is connected to the next. Adding a couple of vertical lines to your code shows the starting point is $1946$ and the ending point is just before $1960$:
abline(v=1946, col= "red")
abline(v=1960, col= "red")

The second example is $8$ different timeseries (columns in the matrix), which plot.ts shows separately.  Since you generate these using rpois without setting a seed, the values will change each time you run it, but you will get something like this:

If you wanted the second plot to look like the first you could do something like this (it starts by default at $1$ and goes up in steps of $\frac1{12}$)
timeseries3 <- ts(as.vector(M4_regular_matrix), frequency=12)
plot.ts(timeseries3)

to see
Comment: How can I make the 2nd one a single time series?
Comment: @user149054 I have added a third chart

Time Series plot in R


O gera o erro Can't set headers after they are sent,está executando 2 vezes

Question: Ele está executando o conteudo o validator 2 vezes, sou novo com Node.js e não sei o que está acontecendo.
Quando o validator retorna um erro á API para, quando não tenho retorno de um erro á api funciona normal.
function alterar(req,res){

    validator.validaValores(req.body,(err,data) => {
        if(err){
            console.log(err)
            return res.status(500).json(err)
        }else{
            console.log("Teste")
            repository.alterar(req.body, (err,data) => {
                if(err){
                    return res.status(500).json(err)
                }else{
                    res.status(200).json({mesage: 'Alterado com sucesso!'})
                }
            })
        }
    })
}

Este é o erro, os dois console.log() que dou no código aparecem ali, porém deveria aparecer apenas aquele com o mensagem de erro.
{ erro: 'Dados inválidos!' }
Teste
    _http_outgoing.js:489
        throw new Error('Can\'t set headers after they are sent.');
        ^
Error: Can't set headers after they are sent.
    at validateHeader (_http_outgoing.js:489:11)
    at ServerResponse.setHeader (_http_outgoing.js:496:3)
    at ServerResponse.header (/home/thiago/projeto/projeto/projeto_api/node_modules/express/lib/response.js:767:10)
    at ServerResponse.send (/home/thiago/projeto/projeto/projeto_api/node_modules/express/lib/response.js:170:12)
    at ServerResponse.json (/home/thiago/projeto/projeto/projeto_api/node_modules/express/lib/response.js:267:15)
    at repository.alterar (/home/thiago/projeto/projeto/projeto_api/src/core/valores/teste/testeController.js:39:37)
    at sql.request.input.input.input.input.input.execute (/home/thiago/projeto/projeto/projeto_api/src/core/valores/teste/testeRepository.js:48:17)
    at /home/thiago/projeto/projeto/projeto_api/node_modules/mssql/lib/main.js:1632:20
    at Request.userCallback (/home/thiago/projeto/projeto/projeto_api/node_modules/mssql/lib/tedious.js:1137:61)
    at Request.callback (/home/thiago/projeto/projeto/projeto_api/node_modules/tedious/lib/request.js:39:27)
[nodemon] app crashed - waiting for file changes before starting...

Comment: Não faz sentido ele entrar nos dois na mesma rodagem, talvez esteja rodando mais de uma vez, veja isso. E não precisa do `return` em caso de erro, pode removê-lo. E o erro pode estar sendo exibido, pois quando você faz `.json(err)`, o conteúdo deve ser um json válido, talvez seja somente uma string, ou código, etc.
Comment: Obrigado @LucasCosta eu fiz o teste e ele está executando 2 vezes,vou tentar fazer com que ele tenha uma unica execução agora
Answer: O problema era que estava sendo executado duas vezes a função do meu validator então solucionei da seguinte forma:
function alterar(req,res){
try{
    validator.validaValores(req.body,(err) => {
        if(err){
            throw err
        }else{
            repository.alterar(req.body, (err,data) => {
                if(err){
                    throw err
                }else{
                    res.status(200).json({mesage:'Alterado com sucesso!'})
                }
            })
        }
    })
}catch(err){
    return res.status(500).json(err)
}

}
Troquei os return por throw usando try catch para capturar o erro e assim finalizar a function alterar deixando apenas dois retornos.


Likelihood ratio test overestimates significance. More appropriate test?

Question: I'm trying to find words that have a significantly distribution in one small portion of a large corpus than they do in the entire corpus.  I'm using the standard likelihood-ratio test statistic
$$\chi^2 = 2 \sum_{i} O_i log(O_i/E_i)$$
where the two classes are the small portion of the corpus and the rest of the corpus.
The problem that I run into is that the small portion of the corpus is so much smaller than the whole corpus that the expected number of occurrences of any word in that small portion is on the order of 0.001.  Therefore, the fact that a word occurs at all in the small portion is taken to be very significant, even if it's a very common word like a, the, of, or another stopword.
Is there a way to do a better estimate that doesn't underestimate expected values so badly?  Or would a different test be more appropriate here?
Thanks so much for your help.
Comment: Do you choose the words you suspect of being over-represented based on looking at the data, or do you have a hypothesis developed beforehand you want to check?  Which way would make quite a difference to the approach.
Comment: Just how small is the small portion, i.e. how many words?
Comment: I want to choose the over-represented words based on the scores provided by the test, so that I can set some threshold and list of words that characterize the smaller segment.  (The smaller segment by the way is usually on the order of 100 words, while the whole corpus is ~1,000,000)
Comment: I suspect that 100 words is just too small to identify over-represented words.
Answer: The likelihood ratio test is intended to test to see which model in hierarchical order better fits the data.  it is not intended to be used the way you are using it.  I think you want to compare two distributions which can be accomplished with a chi-square test, two-sample K-S test or other tests of that type.


Call a Function with an unknown length of arguments from a list

Question: This may be a basic question, but I haven't been able to figure it out.
I have a function that takes in multiple arguments, as kwargs, so I can call it with 1, 2,3 or any amount of arguments. I also have a list whose length is unknown and I want to call the function with each item in the list.
So if I have a list like
[1, 2, 3]
I want to call the function like
f(1,2,3)
and if I have
[1,2]
f(1,2)
Comment: `f(*l)` where `l` is your list
Answer: I think that should answere your question:
<code>def func(*args):
    print(f'number of arguments: {len(args)}')
    print(f'first argument: {args[0]}')
    print(f'second argument: {args[1]}')
    print(f'last argument: {args[-1]}')

func(1, 2, 3)
func(1, 2)
func(*[1, 2, 3])
</code>


samba net usershare returned 255 error

Question: I just did a update to my system, one of which was Samba for UBUNTU 10.04 and now it will not allow me to get privilages when I use Nautilus.
Any ideas on how I can get this back?
Answer: Is a permission problem described here https://answers.launchpad.net/ubuntu/+source/nautilus/+question/31818
Quick fix:
<code>chown root:sambashare /var/lib/samba/usershares
</code>
Regards

samba net usershare returned 255 error


Forcing a Brownian Motion to Stay Between Two Values?

Question: Consider a Wiener Process (https://en.wikipedia.org/wiki/Wiener_process):
A Wiener process $W(t)$, $t \in [0, \infty)$, is a real-valued continuous-time stochastic process that satisfies the following properties:

$W_0 = 0$
$W$ has independent increments: for every $t > 0$, the future increments $W_{t+u} - W_t$, $u \geq 0$, are independent of the past values $W_s$, $s < t$.
$W$ has Gaussian increments: $W_{t+u} - W_t$ is normally distributed with mean 0 and variance $u$, i.e., $W_{t+u} - W_t \sim \mathcal{N}(0, u)$.

Thus, in general:
$$W(t) = \sum_{i=1}^{t-1} (W_i - W_{i-1})$$
$$(W_i - W_{i-1}) \sim \mathcal{N}(0, dt)$$
Here is my attempt to simulate a Wiener Process in the R programming language:
library(ggplot2)

n <- 1000  # Number of steps
dt <- 1/n  # Time step

dW <- rnorm(n, mean = 0, sd = sqrt(dt))
W <- cumsum(dW)

df <- data.frame(time = seq(0, 1000, length.out = n), Wiener = W)

p <- ggplot(df, aes(x = time, y = Wiener)) +
    geom_line() +
    labs(title = "Wiener Process", x = "Time", y = "Value") + theme_bw()

print(p)

My Question: I am interested in learning if it is possible to mathematically define the Wiener Process such that the range can only be between two numbers $a$ and $b$?
For example, imagine a coin where the probability of success itself evolves as a stochastic process. That is, the probability of getting heads on the $n_{th}$ turn depends on the history of the previous flips according to a Wiener Process. In this case, I would have to define a Wiener Process between $0$ and $1$.
From a programming perspective, I think this might be possible: Every time the Wiener Process takes a value of $0$ or $1$, you can "force" it to take a value of 0.01 or 0.99 and resume the simulation:
n <- 1000  # Number of steps
dt <- 1/n  # Time step

dW <- rnorm(n, mean = 0, sd = sqrt(dt))

W <- numeric(n)
W[1] <- 0.5  # Start in the middle of the interval [0, 1]

# Generate the Wiener process
for (i in 2:n) {
  W[i] <- W[i-1] + dW[i]

  # If the process hits 0 or 1, reset to 0.01 or 0.99 respectively
  if (W[i] <= 0) {
    W[i] <- 0.01
  } else if (W[i] >= 1) {
    W[i] <- 0.99
  }
}

df <- data.frame(time = seq(0, 1, length.out = n), Wiener = W)

p <- ggplot(df, aes(x = time, y = Wiener)) +
  geom_line() +
  labs(title = "Bounded Wiener Process", x = "Time", y = "Value") +
  theme_bw()

print(p)

But is it possible to mathematically define the Wiener Process according to these constraints? I am interested in mathematically defining a Wiener Process like this so I can infer well-known theoretical properties from it. In the way I have done it (Bounded), I am not sure if theoretical properties can be inferred from this.
I am aware that there is something called a Geometric Brownian Motion in which the Logarithm of the process is analyzed such that negative values can not be taken - but I am not sure if there are any formulations which allow the process to naturally lie within two values (Probability of a Brownian motion staying within double linear barriers).
Is this possible?
Thanks!
Note: Here are multiple simulations:
 n <- 1000  # Number of steps
    dt <- 1/n  # Time step

    df <- data.frame()

    for (j in 1:100) {
      dW <- rnorm(n, mean = 0, sd = sqrt(dt))
      W <- cumsum(dW)
      temp_df <- data.frame(time = seq(0, 1, length.out = n), Wiener = W, process = j)
      df <- rbind(df, temp_df)
    }

    color_gradient <- scale_color_gradient(low = "red", high = "blue")

    p <- ggplot(df, aes(x = time, y = Wiener, color = process)) +
      geom_line() +
      labs(title = "Multiple Wiener Processes", x = "Time", y = "Value") +
      theme_bw() +
      color_gradient

    print(p)

Comment: Wait, I think I found something? https://en.wikipedia.org/wiki/Reflection_principle_%28Wiener_process%29
Comment: https://en.wikipedia.org/wiki/Reflected_Brownian_motion
Comment: I believe that reflecting Brownian motion is related to solutions of Laplace's equation with homogeneous Neumann BCs in the same way that the expected time to hit the boundary of standard Brownian motion is related to harmonic functions with homogeneous Dirichlet BCs.
Answer: This is a case of Reflected Brownian Motion.
If the interval was $[0, \infty)$, we could realize it as the well known $Y_t := |B_t|$ for $B$ a Brownian Motion.
For the interval $[0,1]$, we can insert $B$ into a triangle wave function to get $f(B_t)$. In our case,
$$X_t = f(B_t) = 2 \left|\frac{B_t}{2}-\lfloor \frac{B_t}{2}+\frac{1}{2}\rfloor \right|.$$
What this really means is that if the Brownian Motion $B$ passes over a boundary, it gets evaluated "oppositely" by $f$, just as in the case of $Y_t = |B_t|$.
As a different point of view, we can also transfer the Brownian Motion $B$ onto a circle by taking $Z_t := e^{2 \pi i B_t}$, or equivalently, by letting the angle $/2\pi$ be given by the fractional part $ \{B_t \} := B_t - \lfloor B_t \rfloor$.
Let $X_t$ be the arc distance $/\pi$ from the rightmost point on the circle. Then, the right point corresponds to $X_t=0$, the left one to $X_t=1$, and it is the same as living in the interval $[0,1]$ with a reflecting boundary. Actually, the above formula resembles this analogy! (For $[0, \infty)$, we would take a "circle with infinite radius".)
In conclusion, in both options we copied the interval and identified points on the copies. At the beginning, we copied it infinitely many times and layed out the copies out next to each other (sticking one end per interval together). In the second version, we copied the interval only once and sticked both ends together to arrive at a circle.
Comment: thank you so much for your answer! I am trying to self teach myself about these concepts (e.g. https://math.stackexchange.com/questions/4825422/creating-a-simulation-to-disprove-the-law-of-large-numbers) and really appreciate your help! Its really cool when I naively imagine some concept and realize that this concept already exists!
Comment: Is there a way to generally define a brownian motion such that it does not exceed (a,b)?
Comment: I posted a follow up question here: https://math.stackexchange.com/questions/4826708/understanding-the-triangular-wave-function


Probability that one is a male

Question: i have the following question: A lady gave birth to a triplet, you know that at least one of them is male. You met her on the street with one child, what's the probability that he's a male?
I'm trying to do this by definition so i said:
$|\Omega| = 2^3$, the events are $A=$("at least one is a male") and $B=$("you met a male"). $P(A)=\frac78$ and $|B|=?$ and i want to calculate $P(B|A)$. That's where i get stuck. Can anyone offer an explanation?
Comment: The probability that '*he*'s a male' is 1! :)
Answer: There's a $3/7$ chance of one male child, a $3/7$ chance of two, and a $1/7$ chance of three, so the total probability is $\left(\dfrac{1}{3} \times \dfrac{3}{7}\right) + \left(\dfrac{2}{3} \times \dfrac{3}{7}\right) + \left( \dfrac{3}{3} \times \dfrac{1}{7} \right) = \dfrac{4}{7}.$ Alternatively, if you want Bayes' theorem, $P(\text{meeting a boy}) = \dfrac{1}{2}$ if you know nothing about the woman's family, $P(\text{at least one boy}) = \dfrac{7}{8}$ if you haven't met any of the woman's children, and of course $P(\text{at least one boy}|\text{meeting a boy}) = 1$, so by Bayes,
$$P(\text{meeting a boy}|\text{at least one boy}) = \frac{P(\text{meeting a boy}) P(\text{at least one boy}|\text{meeting a boy})}{P(\text{at least one boy})} = \frac{ (1/2) \times (1)}{7/8} = \frac{4}{7}.$$
For the question you ask in comments, "Given that you met a (presumably randomly selected) boy, what's the chance that she has at least one girl?" $$P(\text{at least one girl}|\text{meeting a boy}) = \frac{P(\text{at least one girl}) P(\text{meeting a boy}|\text{at least one girl})}{P(\text{meeting a boy})}.$$ The prior probabilities $P(\text{at least one girl}) = 7/8$ and $P(\text{meeting a boy}) = 1/2$, same as above, and $P(\text{meeting a boy}|\text{at least one girl})$ is the same (by symmetry) as $P(\text{meeting a girl}|\text{at least one boy})$, which is $3/7$, the complement of the probability that we calculated in the first problem. The probability is $\dfrac{(7/8) \times (3/7)}{1/2} = \dfrac{3}{4}$. Alternatively, taking a page from drhab's answer here, of the seven equally likely triplets BBB BBG BGB BGG GBB GBG GGB, there are $12$ boys of whom $9$ appear with at least one girl, and $9/12 = 3/4$.
Comment: See main answer.
Comment: Thanks, i was looking for a solution that uses bayes. I have another question regarding this one, and it would be a waste to open a new topic for that. "Given that you've met a male, what's the probability that the lady has also a female?". I'm trying to use bayes for that but i always reach a probability greater than 1. Could you give me a hint on how to approach this?
Answer: Alternatively you can think of 8 triplets (BBB,BBG, et cetera).
Symmetrically there are $12$ boys and $12$ girls.
Now the triple GGG is taken away so that $12$ boys and $9$ girls remain all having equal probability to be met on the street.
That gives probability $\frac{12}{12+9}=\frac47$ to meet a boy.
Comment: +1: This is a useful trick for dealing with probabilities.
Comment: Ooh, this is clever.
Answer: The answer depends on how "you know that at least one of them is male".
Here are two different types of scenarios:

Someone one day just told you that this woman had a triplet and that 'at least one of them is a boy'
You met this woman some day before on the street (or store, or ..) and she had 1 child with her that was a boy, and she told you this was one of a triplet that she had

Notice that in both scenarios you know that she had a triplet and that at least one of them is male.
In scenario 1 (which I would guess is what the book/instructor is looking for), you use the calculation used by ConnorHarris, since out of the 8 possible and initially equally likely triplets (MMM, MMF, MFM, FMM, MFF, FMF, FFM, FFF), you can rule out the FFF one, so you have a $\frac{3}{7}$ chance of one male and two females, a $\frac{3}{7}$ chance of two male and one female, and a $\frac{1}{7}$ chance of all three being male, and so the probability of the one child being with her today being male is:
$\left(\dfrac{1}{3} \times \dfrac{3}{7}\right) + \left(\dfrac{2}{3} \times \dfrac{3}{7}\right) + \left( \dfrac{3}{3} \times \dfrac{1}{7} \right) = \dfrac{4}{7}.$
In scenario 2 (which is actually a far more likely kind of scenario to happen in the real world; indeed, note that you are meeting her today in that exact kind of situation ...), there is a $\frac{1}{4}$ chance that both other children are female, a $\frac{1}{2}$ chance that there is one more male and one more female, and a $\frac{1}{4}$ chance that both other children are male. In other words, there is a $\frac{1}{4}$ chance of one male and two females, a $\frac{1}{2}$ chance of two male and one female, and a $\frac{1}{4}$ chance of all three being male.
So now you get that the probability of the one child with her today being male is:
$\left(\dfrac{1}{3} \times \dfrac{1}{4}\right) + \left(\dfrac{2}{3} \times \dfrac{1}{2}\right) + \left( \dfrac{3}{3} \times \dfrac{1}{4} \right) = \dfrac{2}{3}.$
In sum: the question is actually ambiguous, and even though the book is most likely looking for the answer compatible with scenario 1, if a situation like this ever comes up in real life, you are more likely to deal with a scenario 2 type situation!

Probability that one is a male