Why Bb7#9 in 'Michelle' and not Bbm7?

Question: The second chord in the first Verse of the song 'Michelle' by the Beatles is often interpreted as Bb7#9. Isn't that a bit of an overkill? I actually don't really hear the major triad dominantly and if I emphasize the D it sounds pretty 'strong'. Playing it as just  Bbm7 doesn't change the vibe much too me, so I wondered if there is a good reason to interpret the chord as a major chord with additional tones and not vice versa.
Comment: «My belle» ne sont pas des mots qui vont très bien ensemble...
Comment: *I think* there's a `d` in the harmony of the voices in the previous "Mi-chelle" (the F key), the change of notes of the voices is not that swift, so for an instant there's a major sensation of the IV minor.
Comment: I've always played it as ivm7, so can't figure out which version you're referring to, and in which key. Which words in particular are sung at that bar?
Comment: My songbook says Bbm7. (Well, one of my songbooks. The other says Gm7, but that's just because the whole song is transposed from F to D there.)
Comment: @Tim I understood the question to mean the bar that sings "ma belle". And about the key, well... I'm a little confused here. F minor, it seems by the signature, but where I'd expect the tonic, the chord is F major. Weird.
Comment: Yes I meant the 'my belle' chord. One source would be the Wikipedia article of the song: https://en.m.wikipedia.org/wiki/Michelle_(song) under 'musical structure'. Also here: https://tabs.ultimate-guitar.com/tab/the-beatles/michelle-chords-17324 . Admittedly both not very reliable sources and I am relieved that I am not the only one hearing it as a minor chord
Comment: Haha sorry, ma belle
Comment: @Divizna - I'm sticking with ivm7, whatever key it's written in!
Comment: I wouldn't trust Ultimate Guitar to find the cords in my pyjamas... or the key I open the door in my pyjamas when the postman calls...
Comment: @Tim And here I was hoping you'll tell me what key that is... Ah well. At least you seem very sure it's F something. (Yeah, I'm quite sure it can't be Ab major too.)
Comment: @Divizna - no; Ab is where I used to live...
Comment: → the F *chord* I meant.
Answer: The answer to your title question is: because that's what Paul wrote and played. The fact is, and I'm a little surprised to say, it IS a Bb7#9. I always thought based on the melody and the fact that his guitar is a bit buried in the mix there that it was a Bbm7 but was proven wrong by this video of Paul playing it:

He plays the song in C with capo 5 making it sound in the key of F (and F minor) and at 0:42 you can actually see him play this chord: 1-3-1-2-4-4 or 6-8-6-7-9-9, not accounting for the capo. The notes are: Bb-F-Ab-D-Ab-C#, Bb7#9. The guitar chord sounds crystal clear on the video, but not on the original studio recording.
Mike Pachelli, an amazing guitarist who does very accurate transcriptions of Beatles tunes confirms this at around 6:42 of this video:

_
Comment: @Aaron I assume you mean Bbm7. Just because something sounds fine doesn't make it right or accurate.
Comment: Yes, Bbm7. Typo. But I think your comment gets exactly at the heart of the question: is it better to be right or to be effective? Both you and OP agree that Bbm7 sounds better despite the fact that Bb7#9 is correct. Without that discussion, this is really just a transcription, "what chord is this" question.
Comment: I think the "real" question is, why does it matter, since the Bm7 sounds fine.
Comment: @Aaron Rather than the Db in the Bbm7 being essential, I argue in my answer that it is the D in the Bb7 that is essential, while the C#/Db is an add-on, thus getting at the heart of the question, short of inviting Paul McCartney himself to contribute the answer to Music.SE :-)   (need to hurry since he's 81 now).
Comment: @GratefulDisciple I agree that the D makes it a V-I relationship to the Eb but I disagree that the C#/Db is just an add on because it is a melody note and that makes it important and essential.
Comment: Thx for this nice answer!
Comment: @JohnBelzaguy The more I look at this, the more I can see why the majority of scores have Bbm7, thus sacrificing the "D".  I would characterize these 2 options as a debate on "how to perform" two intentions (harmonic V-I, and the melody).  Those with *less* resources (say a single guitar/piano accompanying singer) who prioritize consonance with the melody can choose Bbm7, OR can have a little dissonance with the guitar/piano playing Bb7.  But those with *more* resources can separate the D to backing vocals and the Db to lead singer.  Paul McCartney wants both, so he plays Bb7#9 on his guitar.
Comment: @GratefulDisciple This has been a bit of a revelation for me because I have listened to this song many times but more from an enjoyment perspective then an analytical one. The BGV's also clearly have the D so even if I were creating an "easy piano" or "easy guitar" arrangement I would not want to sacrifice it. I think my choice would be Bb7 with the C#/Db in the melody. And of course as you say more resources and skill lead to more options.
Answer: If we listen to the recording version (where the backing vocal in the mix is more audible) and look at what they are singing in this score, for the 2nd chord after the F, the backing vocal sings Bb7 for the full 3 beats during which the melody (2nd beat "ma" is having a Db, the #9).  Bb7 makes perfect sense harmonically here, since it's the dominant 7th of the 3rd chord Eb6.

In contrast with your opinion, if we change Bb7 to a Bbm7 that WILL change the character of the accompaniment, so the "D" should be preserved to be consistent with the backing vocal and also serving as a more pointed dominant chord to Eb, which Paul McCartney consistently does.
But why does Paul McCartney also play the #9 (C#)?  If we see the score linked above where the guitar part is fully written out, we can see the chromatic motif very evident in the 4-measure introduction, the motif he continues into the chorus right after the intro:

In the intro, the most prominent single-note sequence we hear in the guitar (more obvious in the recording version) are the very notes responsible for the chord progression Fm-Fm(maj7)-Fm7-Fm6-Dbmaj7-C, which are F-E-Eb-D-Db-C.
Right after the intro when he starts singing the melody, he then continues this chromatic motif in the top note that is also responsible for the chord progression F-Bb7#9-Eb6-Ddim7-C-Bdim7-C, which are C-C#-C-B-C-B-C, although not as audible as the intro, following the chromatic rising & falling contour of the melody.  (We can hear this much better in the White House video.  In the last 4 chords he didn't follow the score.)

Conclusion: In my opinion, Bb7#9 is fulfilling a dual function: as V7 to the 3rd chord, and as #9 preserving the chromatic motif.  Adding the C# to the D in Bb7 also makes the chord more dissonant than a simple Bbm7, making it more consistent with the pattern of alternating consonant chords (F, Eb6, C, C) with dissonant chords (Bb7#9, Dbdim7, Bdim7).
Yes, I found a lot of scores on the Internet with Bbm7 chord such as here, here, and here.  I also found scores with Gm7 when the key signature is D minor such as here and here.  Even a score with F major as the key signature such as here which still has Bbm7 as the 2nd chord.  I'm not sure whether they are official or not.  But I also find 2 identical looking "for purchase" versions (a piano reduction score) here and here where the key signature is F minor and has Bb7#9 as the 2nd chord.  In that version, the piano notes form a Bb7 chord (without the #9) vindicating my analysis above where the harmonic accompaniment (which is done by backing vocal in the recordings) is intended to be Bb7, but in live performances Paul McCartney adds the #9 in his guitar.
Comment: An interesting synopsis. +1.
Comment: Great answer, thx!

Why Bb7#9 in 'Michelle' and not Bbm7?


Nested Dictionary to dataframe

Question: I have a nested dictionary that looks like this(this is pretty shortened version):
my_dict = {('rs1', rn1): {u'rs2': u'rs3', u'rs4': u'rs5', u'rs6': u'rs7', u'rs8': u'rs9', u'rs10t': u'rs11', u'rs12': u'rs13', u'rs14': u'rs15', u'rs16': u'rs17', u'rs18': u'rs19'}, ('rs21', rn2): {u'rs22': u'rs23'}, ('rs24', rn2): {u'rs25': u'rs26', u'rs27': u'rs28', u'rs29': u'rs30'}

And I would like to have an excel that looks like

Im trying with:
    new_list = []
for k1 in remove_empties_from_dict(combined_dict):
     curr_dict = remove_empties_from_dict(combined_dict)[k1]

     for k2 in curr_dict:
         new_dict = {'col1': k1, 'col2': k2}
         for k3 in curr_dict[k2]:
             new_dict = {'col1': k1, 'col2': k2, 'col3': k3}
             for k4 in curr_dict[k2][k3]:
               new_dict= {'col1': k1, 'col2': k2, 'col3': k3, 'col4': k4}

new_list.append(new_dict)
df = pd.DataFrame(new_list)
print df

It says an error:
"for k4 in curr_dict[k2][k3]:
TypeError: 'float' object is not iterable"
Any idea how to change inner values to strings, apparently they are floats.
Thank you!
Comment: Possible duplicate of [Construct pandas DataFrame from items in nested dictionary](https://stackoverflow.com/questions/13575090/construct-pandas-dataframe-from-items-in-nested-dictionary)
Comment: I checked it out, but its not, since he puts rs_2 on top of the column. On index values, I would like to have it in the table.
Answer: As @Fozoro suggests, you can do it with the following steps:
my_dct = {('rs1', "rn1"): {'rs2': 'rs3', 'rs4': 'rs5', 'rs6': 'rs7',
                           'rs8': 'rs9', 'rs10t': 'rs11', 'rs12': 'rs13',
                           'rs14': 'rs15', 'rs16': 'rs17', 'rs18': 'rs19'},
          ('rs21', "rn2"): {'rs22': 'rs23'},
          ('rs24', "rn3"): {'rs25': 'rs26', 'rs27': 'rs28', 'rs29': 'rs30'}}
newdf = pd.DataFrame.from_dict({(i,j): my_dct[i][j]
                               for i in my_dct.keys()
                               for j in my_dct[i].keys()},
                                orient='index').rename(columns={0:"Column 4"})
newdf["Column 1"] = newdf.index.str[0].str[0]
newdf["Column 2"] = newdf.index.str[0].str[1]
newdf["Column 3"] = newdf.index.str[1]

Comment: Thank you for your time! it gives me an error at line.
    newdf["Column 1"] = newdf.index.str[0].str[0]
that says: "Can only use .str accessor with Index, not MultiIndex"
Comment: which python version do you use ?
Comment: Im currently using 2.7
Comment: Can't requirement for work. I think I am pretty close to solving it. Ill edit the code, maybe you can help from there :) Thanks a lot :)

Nested Dictionary to dataframe


$f(x)=x\left ( \sqrt{x} +\sqrt{x+9}\right )$ is this continuous and differentiable at $x=0$?

Question: Do we need to take into consideration that the domain of $x$ is only $(0,\infty )$??
And Then only check the differentiability for $x>0$??
Also, $$lim_{x \to 0} x\left ( \sqrt{x} +\sqrt{x+9}\right )$$
$$lim_{x \to 0} \frac{x\sqrt{x}}{x\sqrt{x}}+ \frac{x\sqrt{x+9}}{x\sqrt{x}}$$
$$lim_{x \to 0} 1+ \frac{\sqrt{x+9}}{\sqrt{x}}$$
How do we proceed from here?
Comment: The domain is $[0,\infty)$. Your equation is well defined at zero.
Comment: To be safe, you must specify limit from the right, as limit from the left is outside of your domain at $x=0$
Comment: Is my function well defined at $x=0$? The term $\frac{\sqrt{x+9}}{\sqrt{x}}$ becomes $\infty$ , so isn't it undefined?
Comment: Indeed your function is defined at zero. $f(0)=0\cdot(0+3)=0$
Answer: Continuity at $0$ is clear. Next you can certainly try and find the derivative at $0$ (some call it the "right derivative" as the point can only be approached from the right); since $f(0)=0$ we have
$$
\lim_{x\to0}\frac{f(x)-f(0)}{x-0}=
\lim_{x\to0}(\sqrt{x}+\sqrt{x+9})=3
$$
(write $x\to0^+$ if you prefer).
In the image below, the function has the green graph, the tangent at the origin has the red graph.
Answer: Theorem: The product and sum of functions continuous at $x = x_0$ is continuous at $x = x_0$.
It follows immediately that the function in question is continuous at $x=0$ from the right.
$$\lim_{x \to 0^+} \frac{f(x) - f(0)}{x-0} = \lim_{x \to 0^+} \frac{x( \sqrt{x} + \sqrt{x + 9})}{x} = \lim_{x \to 0^+} (\sqrt{x} + \sqrt{x + 9})$$
Which exists by the same theorem described above.
Answer: The domain is $[0,\infty)$ and so your limit is kind of already able to be evaluated, even though it technically doesn't exist (a left hand limit is needed and doesn't exist). $f(x)=0(\sqrt{0}+\sqrt{9})=0$. However, it is not differentiable since the derivative requires the function to be defined in a neighborhood around the point, i.e. $\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$ which needs a left and right hand limit. As the function is not defined to the left, the limit doesn't exist and the derivative doesn't exist. This is true in general for an endpoint of a function. We can however look at $$\lim_{h\to 0^+}f'(x)$$ which I'll leave to you.


In principle, is it possible to create the sound of an instrument from the waveform of a different instrument?

Question: Say I have the waveform of instrument 1 (bass guitar for example) and it contains the frequencies typical of a vastly different instrument, instrument 2 (alto flute for example). In principle, is it possible to process the bass guitar waveform using filtering, attenuation, boosting, algorithms, etc, to produce an approximation of the flute?
If so, is this called synthesis?
If not, why not?
Comment: @AndyBonner Nitpicking but a high pass does not make a low pitch into a high pitch, it only keeps the hight frequencies already present in the original signal.
Comment: Comparing my answer to others has shown me that this question is unclear. The answer could be "yes" if **any** processes are allowed, and in that case you could take any noise or even no noise at all and craft an approximation of any instrument and this **would** be synthesis. If only some processes are allowed, such as only real-time processes or subtractive processes, then the answer is "no" and none of those processes would be called synthesis. Can you please clarify what kinds of processes you're talking about?
Comment: @user45266 - in theory. In practise from a bass guitar, you'd and up with more noise-floor than anything else, if you push it too far.
Comment: The answer is: yes, and the terms _synthesis_ and _sound design_ are what you're looking for.
Comment: One obvious limitation: a high-pass filter can make a low pitch into a high pitch, but I'm not aware of a way to do the opposite (at least… not a quick and easy practical one that I can imagine a straightforward approach for).
Comment: @Tom I think Andy Bonner meant for a low frequency composite waveform, you could lop off everything below a certain frequency, and if you strategically cut away any overtones of the actual fundamental that wouldn't be part of an arbitrary new lowest note, you'd hear a higher note than before.
Comment: You can make a bass sound like a guitar, as eminently proven by Royal Blood… but the rest devolves into the theoretical quite rapidly.
Comment: which is more complicated than a simple high-pass, but their point was that you can't do the same in reverse since a high frequency simply won't contain many of the overtones of a lower note, ie. you can't add any of those, so you can only get so close.
Comment: @Tetsujin Yes, in theory. Why anyone would do this is beyond me!
Comment: A synthesis (heh) of all the answers: The challenge is (as always with trying to emulate instruments) achieving the desired result. Is it possible to change a sound a lot? sure. Is it possible to change it so much that someone would have difficulty identifying the original instrument? of course. Past that point, the task of *convincing the listener that it is another specific instrument* is the difficulty... and is what the field of synthesis spent decades on.
Comment: You can find an example of this in Kanye's Runaway: https://www.youtube.com/watch?v=VhEoCOWUtcU&t=369s where he distorts his voice to sound sort of? like a guitar
Answer: I don't exactly disagree, with Hoagie's answer, but fact is, that the original waveform is not of much help in case of such different instruments, where the waveforms exhibit no similiarity.
You save nothing compared to starting from scratch with adding sine waves in the appropriate ratios, which I consider as strict form of synthesis.
Answer: Sort of.  The sustain portion of most instrument sounds has a relatively simple, regular waveform which can be manipulated to sound like another instrument.  I wouldn't call this 'synthesis', that implies starting from nothing. Modification, transformation perhaps?
But a whole LOT of an instrument's character is contained in the attack portion of the note, often a much more complex, even chaotic waveform.  This part of the sound is much more difficult to deconstruct and modify.
Some of the most useful sounds in our toolbox come from the 'hybrid synthesis' era, notably the Roland D-50 and the Yamaha SY range.   A sampled attack was followed up by a synthesised sustain and release. The brief sample gave authenticity, the synthesised sustain was very controllable.  Best of both worlds.
Answer: I'm going to answer a qualified
No
You'd struggle to make the bass sound like a flute because while it does have a harmonic spectrum that could be filtered in some ways to be similar to a flute, it would be very hard to get the right formant, you'd have to add some noise, and you'd be pretty well stuck on re-creating the transients and ability of the flute to sustain.
It would be even harder to process a flute to sound like a bass - much of the harmonic content of a bass just isn't present in the flute. And none of the noise and inharmonic partial are available on the flute.
You could probably make a clarinet and maybe an oboe sound like a flute, but not a flute like an oboe.
You can definitely make a bass sound like a piano, and maybe the other way around.
There is at least one process that is commonly called "synthesis" that uses existing sounds to make new ones. That is granular synthesis. That process takes samples of sound and slices then into very short bits called "grains" and then used the grains to make new waveforms. Really you're not using the characteristics of the source sound at all in granular synthesis, which is why it's called synthesis.
Answer: What does make different instruments sound differently? How do you distinguish, say, a trumpet (sound) from a violin (sound)?
There are two (three) things the ear relies on: volume, but it would be easy to play a recording with more or less volume, so this is a neglectable difference.
The two important differences are:

the intrinsic curve, also called ADSR (attack, decay, sustain, release) is the way the single tone develops over time. A tone starts to sound (attack), stabilizes (decay), sounds out for some time (sustain) and then fades out (release)

the overtone composition is the way each instrument emphasizes (or deemphasizes) certain partial harmonics in a characteristic way. Every real tone a real instrument produces is not only the base frequency but also many partial harmonics of that base tone. Some of these partial harmonics are louder (emphasized) than others and which one these are depends on the sort of instrument which produces the tone. If we talk about a "warm tone" or a "metallic tone", etc., this sum of partial harmonics is meant.

So, - in principle - the answer is: "yes", because - "in principle", as you said in the title, with enough sound engineering (some Fourier analysis and sound synthesis, as @NuclearHoagie said), you can indeed produce whatever sound you want from whatever sine wave you start with. Basically every classical synthesizer does exactly this - to some extent.
If this in principle possible method is - in practice - practical is another question.  You can approach the sound of an instrument, but the more musical training one has the better will he be able to differentiate between "almost this instrument" and "exactly the instrument". Notice that the amount of calculation necessary to get it exactly right is exponentially higher than to get it almost right.
This is why modern synthesizers, instead of making sounds from pure sine waves, use samples as base of their sound production. Samples are recorded sounds of real instruments which are then processed.
Comment: Very well articulated. I leaned a few things from your answer. Thank you (and others) for sharing your knowledge.
Comment: There's more to the attack than can be defined in a volume envelope.   See my reply in this thread.
Comment: @Laurence: I am aware of that and I never said it is only volume. I said the ADSR is *how the tone develops over time*, I did not say that is only (changes in) volume. In fact, tones usually also contain more or less noise (for instance: slap bass), which also contribute to the chracteristic sound.
Answer: By the Fourier theorem, every sound can be decomposed into a sum of pure sine waves. Finite duration or non-repeating sounds require summing an infinite number of sine wave to perfectly reconstruct, but you can get arbitrarily close with a finite number of sine waves.
You can break down the waveform of any noise into its constituent pure frequencies. You can also generate any waveform by combining only pure frequencies. So long as the frequencies needed to construct the second sound are present in the first, then you can do it. If you don't have the necessary frequencies, you can compress or stretch the original waveform appropriately until you do.
Note that this is primarily a theoretical argument - if you have even a single sine wave, you can create any possible wave form by copying, modifying, and combining waves. Whether this is actually practical or in any sense worthwhile is a different story. In principle, though, any sound can be decomposed into sine waves, any sine wave can be turned into any other sine wave, and any sound can be synthesized as the sum of sine waves.
Comment: @Steve - the answer is "Yes… but…" Like the answer to "Can I build an ocean-going boat with just an axe & some trees?" is "Yes… but…"
Comment: A funny consequence of this is that you could theoretically with sufficiently precise signal filtration make every possible sound out of sufficiently-populated white noise... so *technically* the snare drum can do anything your instrument can :P
Comment: "You can break down the waveform of any noise into its constituent pure frequencies" Ummm… maybe… but how? Are you thinking FFT? Even with that you can't extract a bass sound from a flute. You'd have to synthesize a lot of content and then it's no longer really turning a flute into a bass. It's just pitch tracking the flute and then synthesizing a bass sound at the same pitch.
Comment: @Tetsujin: Good analogy — but even beyond that, it seems like saying "Can I build an ocean-going boat from just an axe and a bunch of Ikea bookshelves?" The "but" is all the obvious difficulties, *plus* that you'd do better by starting at the lumberyard instead of Ikea.
Comment: Indeed. I never claimed it was insoluble… just has rather a large '…but' [I used to work with some of the early physical modelling guys, early 90's… which proved if nothing else if you "Science the sh*t out of it" [Matt Damon, Martian] eventually you'll get there ;)
Comment: @ToddWilcox I'm not an audio engineer, but do have a background in signal processing.  Can't you run a very narrow bandpass filter to get rid of everything but one frequency? I agree it's not really practical and not particularly "turning a bass into a flute", it's just turning a bass into sine waves and then sine waves into a flute. It's a bit like turning lead into gold by breaking the atom into subatomic particles and reassembling them.
Comment: Fourier only works with a periodic signal.

So, this could work with sustained sound instruments (organ, winds, bowed strings...) without taking into account attack and release, and without effects (vibrato, tremolo...), but it won't work with a percussive instrument (piano, marimba, plucked strings, timpani...).
Comment: @user45266 Funny that you mention white noise and snare drums.  You can add more attack to your drum sounds, snare especially, by adding white noise.  You noise-gate it and sidechain it to the original drum track so you hear little bursts whenever the drum hits.  Then you filter it appropriately and blend it in to taste.  Transients are basically just noise, after all. :)
Comment: There are examples on Youtube of people using a synth piano to simulate human speech with exactly this kind of synthesis. (For clickbait reasons, the video authors often incorrectly describe this as some kind of auditory illusion.)
Comment: I thought the answer was Yes, but wasn't entirely confident. Many thanks.
Comment: @Tetsujin, very well said. That's why I say "in  principal". And for ocean-going boats, I think the early polynesians did solve that problem :)
Comment: @user45266 Absolutely agree. I wanted to make my question easier so I constructed it using 2 vastly differnt instruments. But the math doesn't care if it's given a waveform from Sir Paul or the white noise from the vacuum cleaner.
Comment: Fourier always comes up with this topic.  I have one reply - Do it then!
Comment: @Steve Physics and acoustics care. Not every sound contains the essential components of every other sound. Some sounds contain more harmonic content than others. Since the bass has more than the flute, it's sort of possible to go from bass to flute but not the other way around.
Comment: Ok, let's run a very narrow band pass filter. At what frequency? I guess the question doesn't specify whether it's about real-time performance processing or not. If it's not real time, then yes, we can pull very narrow bands of pretty much sine waves from a bass sound. And we could select a few of them to get a flute-like sound. But we couldn't do it the other way. So unless the question is *only* about bass to flute and not about any instrument to any other, the answer is no.
Comment: @ToddWilcox Select a sine wave in the frequency domain using a filter. Slow/speed it up in the time domain to get a different frequency. Recombine as many sine waves as needed to replicate an arbitrary waveform to arbitrary precision. All sine waves are essentially identical, if you have one sine wave, you can make any sine wave by changing the frequency and amplitude. I don't see why you can't pitch-shift and recombine the high frequencies of a flute to get a bass.
Comment: @Yukulélé The Fourier transform works on non-periodic signals. It requires an infinite sum of exponentials, but you can get an arbitrarily good approximation by using arbitrarily many terms. Or, just treat finite-duration waveforms as periodic by having them repeat. There are a few workarounds, we just need to reproduce the sound, not one isolated note of the sound.
Comment: @NuclearHoagie IMHO, the process you just described is synthesis and isn't how I interpreted the question. It's possible you have the correct interpretation of the question and I have the wrong one.
Comment: You *could* create a "bass flute" sound by recording a flute and then playing it back at a slower speed.  Or would that be considered "cheating"?
Answer: I think you are focusing too much on the content of the wave package from the source instrument. Look at it this way instead:

can you determine the intended timbre, dynamics, pitch etc from the recording?
do you have a model mapping these states from the source instrument to states of the target instrument?
do you have a model capable of creating or transforming sound based on this target instrument state?
do you have recordings of the target instrument to compare to

If you have these you can just tune the parameters of your model until it sounds nice, for example using some form of gradient descent after turning it into a optimization problem as in machine learning. Step 1/2 can probably be replaced entirely by some fancy embedding, and maybe the ground truth in step 4 can just be some kind of (text, sound) pairs or something plus a model mapping the text to the embedding used in step 1/2 for the target instrument and a model mapping the source instrument to text. Not sure.
I think this is pretty much what would happen if you told a person to play something, then the text would just be sheet music or some language, and the embedding would be whatever your body does to make it move.
Answer: Yes.  This is what a guitar synthesizer is, at some level.  That said, a guitar is very different from a flute.  For one example, the note onset is extremely different between a wind instrument and a plucked instrument, so such a synthesizer would need to apply assumptions about information that just isn't there on the guitar to come up with an acceptable flute.  The level of satisfaction with the process will have to do with how good those assumptions are, and how they can change from situation to situation.
Getting such synthesizers better might be a good role for AI.


Problemas com o botão no Javascript

Question: Boa noite. Estou aprendendo Front End e fazendo alguns exercícios online, e nesse código aqui eu deveria colocar a velocidade que um carro se movimenta, apertar o botão de verificação e concluir se ele está acima ou abaixo da velocidade permitida. Só que toda vez que eu vou apertar o botão ele nunca funciona. E não é só nesse exercício, mas em qualquer outro que eu faça o botão não funciona de jeito nenhum. Onde eu estou errando? Grato pela atenção.
<!DOCTYPE html>

    <meta charset="UTF-8">
    <meta name="viewpoint" content="width-device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie-edge">
        <title>DETRAN</title>

Sistema de multas

    Velocidade do carro: <input type="number" name="txtvel" id="txtvel"> Km/h
    <input type="button" value="verificar" onclick="calcular()">

Destacando o problema, caso alguém não tenha entendido a minha pergunta.
    <input type="button" value="verificar" onclick="calcular()">

Comment: Troquei e deu certo sim. Muito obrigado!
Comment: declarou var RES no inicio mas  usou REST.innerHTML ="'.. EM ....var res = window.document.querySelector('div#res');.. acrescenta o T. ficando var rest = window.document.querySelector('div#res');... então teu código ira funcionar.
Comment: tera que verificar se mesmo o input em branco ao clicar no botão ira aparecer a mensagem.. tente fazer um if para se o campo estiver vazio apresenta uma mensagem que o campo nao pode estar vazio :)
Answer: Você errou  alguns nomes de variáveis, como res voce colocou rest, comentei o código para lhe ajudar a entender. Sugiro começar a usar o terminal do navegador para descobrir os erros, ajuda muito.

<!DOCTYPE html>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DETRAN</title>

Sistema de multas

    Velocidade do carro:

        <input type="number" name="txtvel" id="txtvel"> Km/h

    <input type="button" value="verificar" onclick="calcular()">

Problemas com o botão no Javascript


Caratheodory: Measurability

Question: Let $\mathcal{A}$ be an algebra over $X$ and $\mu:\mathcal{A}\to[0,\infty)$ a finite, positive and countably additive set function.
Consider the induced outer measure:
$$\mu^*(A):=\inf_{A\subseteq\bigcup_k E_k}\sum_k\mu(E_k)$$
Then the following are equivalent:
$$\forall B\subseteq X:\mu^*(A\cap B)+\mu^*(B\setminus A)=\mu^*(B)$$
$$\mu^*(A)+\mu^*(X\setminus A)=\mu^*(X)$$
How do I prove this and what happens if the assumption of an algebra is dropped?

Besides, the statement becomes wrong for noninduced outer measures:
$$X=\{1,2,3\}:\quad\mu^*(\varnothing)=0,\mu^*(X)=2,\mu^*(A)=1\text{ for }A\neq\varnothing,X$$
Answer: To answer this question, it turns out to be easiest to forget about the definition of measurability and instead work with properties of the class of measurable sets.
Let us write $\mathcal{M}$ for the class of $\mu^\ast$-measurable sets and recall that this is a $\sigma$-algebra containing $\mathcal{A}$ and that $\mu^\ast |_{\mathcal{E}}$ is a complete measure.
The last ingredient that we need is that for each $B \subset X$ there is a set $M_B \in \mathcal{M}$ with $B \subset M_B$ and such that $\mu^\ast(B) = \mu^\ast(M_B)$ holds. To see this, note that the definition of $\mu^\ast$ yields for each $n \in \mathbb{N}$ a family $E_k^{(n)}$ of sets in $\mathcal{A} \subset \mathcal{M}$ with $B \subset \bigcup_k E_k^{(n)}$ and with
$$
\mu^\ast(B) \leq \mu^\ast\left(\bigcup_k E_k^{(n)}\right) \leq \sum_k \mu^\ast(E_k^{(n)}) \leq \mu^\ast(B) + \frac{1}{n}.
$$
Now take $M_B := \bigcap_n \bigcup_k E_k^{(n)}$.
Now assume that $B \subset X$ with
$$
\mu^\ast(X) = \mu^\ast(B) + \mu^\ast(B^c) = \mu^\ast(M_B) + \mu^\ast(M_{B^c}).
$$
Then $M_{B^c} \supset B^c$ and hence $M_{B^c}^c \subset B \subset M_B$ with
$$
\mu^\ast(M_{B^c}^c) = \mu^\ast(X) - \mu^\ast(M_{B^c}) = \mu^\ast(M_B).
$$
But this implies $B = M_{B^c}^c \cup N$ for a $\mu^\ast$-Null-set $N = B \setminus M_{B^c}^c \subset M_B \setminus M_{B^c}^c$.
Hence, $B \in \mathcal{E}$ is measurable.
The only properties really used in this proof is that each of the sets in $\mathcal{A}$ is measurable with $\mu^\ast(A) = \mu(A)$. This remains true when the algebra $\mathcal{A}$ is replaced by a semiring (as long as $\mu$ is still a "measure" on $\mathcal{A}$).

Caratheodory: Measurability


Searching for keywords in region body

Question: I am trying to implement a simple search functionality in Piranha CMS. This uses a separate controller and an input string "q" which is the result of a form GET-call. The string is splitted at each space into a list of strings called Keywords.
I have achieved a simple search which successfully retrieves pages and posts based on title and post's excerpt and body. However since the pages consists of arbitrary regions one cannot simply query those directly. I have tried getting the value of the Region's body in multiple ways but I end up getting a NotSupportedException with the following message:

The specified type member 'Body' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

I figured out that I am would get this if Body is not mapped to a column in the database. However, the information must be stored somewhere and since I would like to use the supplied DataContext without accessing the database directly I am wondering how to get the content prior enumeration.
I can see that the content is loaded at enumeration but I want to avoid loading all pages and instead doing the filtering in the query.

Can someone please guide me in the correct direction. I have supplied a snippet from the Controller which successfully queries posts and pages by title.
using (Piranha.DataContext db = new Piranha.DataContext())
{
    var pages = db.Pages.Include("Regions").Where(p => Keywords.Any(keyword => p.Title.Contains(keyword)));
    var posts = db.Posts.Where(p => Keywords.Any(keyword => p.Title.Contains(keyword) || p.Excerpt.Contains(keyword) || p.Body.Contains(keyword)));

    if (pages != null)
    {
        foreach (var page in pages)
        {
            Model.Results.Add(new SearchResultsModel.SearchResult()
            {
                Title = page.Title,
                Id = page.Id
            });
        }
    }

    if (posts != null)
    {
        foreach (var post in posts)
        {
            Model.Results.Add(new SearchResultsModel.SearchResult()
            {
                Title = post.Title,
                Id = post.Id
            });
        }
    }
}

Thanks in advance.
Answer: Yes, database structure for pages is rather complex, and in order to support all kinds of objects as region body the data is serialized as JSON. The Body property is in fact an ignored property that contains the deserialized JSON data for the region. Unfortunately the "real" body of the region (which you could run a LINQ query on) is hidden to avoid confusion. You can find it here:
https://github.com/PiranhaCMS/Piranha/blob/2.2.4/Piranha/Entities/Region.cs#L80
However, your use case is completely valid, and if you're compiling against source code and have a fork on GitHub, feel free to change the access modified to public and send me a pull request. I'll include it in the next release!
If you're using NuGet packages you'll have to to some real SQL and wait for the patch to be released.
I've added a feature request issue on the GitHub repo here:
https://github.com/PiranhaCMS/Piranha/issues/365
Regards
Håkan
Comment: Thanks, I changed the visibility of InternalBody and it works like a charm. For future purposes the complete page-query is now `var pages = db.Pages.Include("Regions").Where(p => Keywords.Any(keyword => p.Title.Contains(keyword) || (p.Regions.Any(r => r.InternalBody.Contains(keyword)))));`. One must also pay attention to special characters like å/å, ä/ä et.c. I have filed a pull request on the changes so it should be in the main repository as soon as you have merged it.

Searching for keywords in region body


Can I remove the "summary" from the "Text (formatted, long, with summary)" widget?

Question: When creating a new content type, by default it has the Body field, which has a Field type of Text (formatted, long, with summary).  For this content type, I don't want authenticated users to see the summary.
What's the proper way to hide the "edit summary" part for non-admin users?  Or, am I better off deleting the default Body field and creating a new custom field?
Answer: Well, that was easy.  On admin/structure/types/manage/page/fields/mycontenttype, you just have to uncheck the box for "Summary input."
Answer: For those who may be looking for the D7 version of @Patrick Kenny 's answer:

https://{{mysite.foobar.com}}/admin/structure/types/manage/{{mycontenttype}}/fields/body


How to get the median of Z=f(x,y)?

Question: Defining $Z=f(x,y)$ in interval $[q,1][q,1]$,$x,y$ are all i.i.d. uniform.
I know that, if $f(x,y)$ is non-increasing or non-decreasing for both $x$ and $y$, the median of $z$ is $f((1-q)/2,(1-q)/2)$. But if $f(x,y)$ is non-increasing or non-decreasing for only $x$, and it is not non-increasing or non-decreasing for $y$.
How can I get the median of $Z$?
The figure of $Z$ is as follows:
Answer: Monte Carlo solution coded in R.
<code>N <- 10^6
f <- function(x, y) x^2 + y^2 # or whatever
x <- runif(N)
y <- runif(N)
median(f(x, y))
</code>
Comment: thank you very much!I know this method, but I want to get the expression of the median of $Z$.just like the one-dimension. Do you know how to express the median of $Z$?
Comment: $Z$ is one-dimensional. The median of Z is a real number $m$ such that $P(Z\leq m)=F_Z(m)=1/2$. Hence, if you want an analytic expression for $m$, the first step is to compute $F_Z$, the distribution function of $Z$, and then work with it. In general, there will be no closed form for $m$.

How to get the median of Z=f(x,y)?


What is the difference between variable ratio matching and fixed ratio 1: n matching with a caliper

Question: What is the difference in the underlying procedure between the two?
For fixed ratio matching with a caliper, would the caliper be applied after fixed ratio 1: n matching? If so, would it result in variable number of controls matched to each treated?
Answer: This of course will depend on the software you use. I'll discuss the methods broadly and then their implementation in the MatchIt for R.
In fixed $k$:1 matching with a caliper, each treated unit receives $k$ matches or as many matches are in the caliper, whichever is smaller. For example, for 4:1 matching, one treated unit may receive 4 matched controls if 4 or more are within its caliper. Another treated unit may only receive 2 matched controls if only 2 are within its caliper. Another treated unit may receive no matches if no control units are within its caliper. If doing matching without replacement, one reason there may not be many control units within a treated unit's caliper is that control units have already been used up as matches for other treated units.
In variable ratio matching, each treated unit receives a different number of matches. How the number of matches to allocate to each unit is decided depends on the algorithm used. You don't need a caliper for this method, though. One method of variable ratio matching is called "extremal" matching, as described by Ming and Rosenbaum (2000). They developed an algorithm for propensity score matching that guarantees an "optimal" allocation of control units to treated units. There is a formula that describes how many matches each treated unit receives. The formula makes it so that hard-to-match units receive fewer matches and easier-to-match units receive more matches.
In the MatchIt package, you can request variable ratio matching using the min.controls and max.controls arguments supplied to matchit(). These are the two arguments required for extremal matching. When method = "nearest" for nearest neighbor matching, Ming and Rosenbaum's algorithm is used. When method = "optimal" for optimal matching, the optimizer automatically finds the right number of matches for each treated unit to minimize the within-pair distances. It turns out that when using the propensity score, optimal matching finds the same allocation as nearest neighbor matching does using Ming and Rosenbaum's algorithm, which is further evidence that the algorithm is optimal. A benefit of the optimal matching approach is that distance measures other than the propensity score difference, such as the Mahalanobis distance, can be used.
If you use the Matching package, you may find something similar to variable ratio matching. If two control units are equally close to a treated unit, they will both be matched to it, even if you only request 1:1 matching. This creates a variable ratio match because treated units receive different numbers of matches. This behavior is controlled by the ties option; setting it to FALSE prevents this from occurring. Ties are actually very rare when you have continuous covariates, but in Matching, the distance.tolerance argument can be set so that two control units that are each within some threshold of a treated unit will be considered tied. Setting distance.tolerance = 0 removes this behavior.
Variable ratio matching doesn't require a caliper. The number of matched controls depends on an algorithm that aims to optimize a criterion (either theoretically or empirically). Fixed $k$:1 matching with a caliper may happen to yield a variable number of matches for each unit, but that is determined by how many matches fall within a treated unit's caliper. It's possible for some units to receive no matches. Though both methods may end up yielding a variable number of control units matched to each treated unit, this is intentional in the case of variable ratio matching and incidental in the case of fixed k:1 matching with a caliper.

Ming, K., & Rosenbaum, P. R. (2000). Substantial Gains in Bias Reduction from Matching with a Variable Number of Controls. Biometrics, 56(1), 118–124. https://doi.org/10.1111/j.0006-341X.2000.00118.x
Comment: @hehe See the documentation for it [here](https://kosukeimai.github.io/MatchIt/reference/method_optimal.html#variable-ratio-matching).
Comment: Thank you! This is incredibly helpful. I did not know that optimal matching has a variable ratio matching option. There is a lot to learn in this field.


Shiny WebApp and UI: add style and dropdown menu in the header

Question: I'm just starting using R and Shiny App and I'm a bit confused about how to achieve what I'm trying to do. I want to change the UI of my Shiny App. As a C# developer, I work with HTML/CSS, AdminLTE and so on. I can't find a proper documentation how to change the UI in a Shiny App.
What I want to achieve in the UI is something like the following image:

First, I removed the sidebar. Now, my problem is to box the UI. In the header, I want to add a dropdown menu with few options. Then, I want in the middle of the page to have a panel with 2 column: in the first column first row I desire to see the graph generate by R, then same text around it to explain the graph.
On top of that, I want to change the style for example of tabs or buttons.
After 2 days of work, I wrote this code but it is very far from what I want to achieve.
library(shiny)
library(shinydashboard)

# Define UI for application that draws a histogram
ui <- navbarPage(
    "Test",
    tabPanel(
        "Introduction",
        titlePanel(
            div(
                windowTitle = "Test window"
            )
        ),
        div(class = "my-class",
            h3("LAI287 basal insulin study"),
            p("Lorem ipsum dolor sit amet..."),
            p("Lorem ipsum dolor sit amet..."),
            actionButton(
                inputId = "btnStart",
                label = "Start analysis",
                className = "btn-primary"
            )
        )
    ),
    tabPanel(
        "Attribute specification"
    ),
    tabPanel(
        dropdownMenu(type = "notifications",
                     notificationItem(
                         text = "5 new users today",
                         icon("users")
                     ),
                     notificationItem(
                         text = "12 items delivered",
                         icon("truck"),
                         status = "success"
                     ),
                     notificationItem(
                         text = "Server load at 86%",
                         icon = icon("exclamation-triangle"),
                         status = "warning"
                     )
        )
    )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
    output$distPlot <- renderPlot({
        # generate bins based on input$bins from ui.R
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)

        # draw the histogram with the specified number of bins
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
}

# Run the application
shinyApp(ui = ui, server = server)

The result of this code is in the following screenshot. The only dropdown I found was for messages or notifications.

I know AdminLTE quite well but I don't understand how to write the code for Shiny App. Do you have any idea or suggestion how I can implement this UI? Is there any good tutorial I can read?
Update
I found some documentation on RStudio Shiny dashboard. First, I don't understand the difference between dashboardPage and navbarPage. Can I add a navbarPage to a dashboardPage?
From the documentation, I added this code:
box(
  title = "Histogram", status = "primary", solidHeader = TRUE,
  collapsible = TRUE,
  plotOutput("plot3", height = 250)
),

box(
  title = "Inputs", status = "warning", solidHeader = TRUE,
  "Box content here", br(), "More box content",
  sliderInput("slider", "Slider input:", 1, 100, 50),
  textInput("text", "Text input:")
)

and I expect something like

but my result is like that (thanks Jan for the menu)

I saw on the other page of the documentation that it is possible to add
dashboardPage(skin = "blue")

but in my case I don't have a dashboardPage.
Answer: Are you aware of the navbarMenu function? You can add menu items to the navbarPage with it:
navbarPage("App Title",
  tabPanel("Plot"),
  navbarMenu("More",
    tabPanel("Summary"),
    "----",
    "Section header",
    tabPanel("Table")
  )
)

Layouting can be done with fluid layouts, e.g.
fluidRow(
    column(width = 4,
      "4"
    ),
    column(width = 3, offset = 2,
      "3 offset 2"
    )

See the layout guide for the necessary details.
Comment: Thank you, this is the first part :) How can I box the page? How can I add the frame in the middle of the page?
Answer: If you are familiar with AdminLTE then I strongly recommend using bs4Dash.  It is a very robust package that allows for the use of boxes and other features that are regularly a part of AdminLTE (including Bootstrap 4).  But the core of the language is still Shiny, so you may need to work through a few basic examples before attempting anything with greater complexity.
You can change colors, font-sizes, etc. in bs4Dash by following the instructions on this page.
For a demo of what is possible, see here.
I've provided a very basic example at the bottom of this answer.
Otherwise adding a dropdown navigation in bs4Dash is a bit tricky, and will require a combination of Javascript, CSS, and HTML.  Luckily, you can modify all of these things.
Good luck!
library(shiny)
library(bs4Dash)

ui <- dashboardPage(
    header = dashboardHeader(
        leftUi = tagList(
            dropdownMenu(
                badgeStatus = "info",
                type = "notifications",
                notificationItem(
                    inputId = "notice1",
                    text = "Put text here!",
                    status = "danger"
                )
            ),
            dropdownMenu(
                badgeStatus = "info",
                type = "tasks",
                taskItem(
                    inputId = "notice2",
                    text = "My progress",
                    color = "orange",
                    value = 10
                )
            )
        )
    ),
    dashboardSidebar(disable = T),
            body = dashboardBody(
            fluidRow(
                column(width = 8,
                       box(width = NULL, title = "Old Faithful Geyser Data",
                           collapsible = F,
                           wellPanel( sliderInput("bins",
                                                  "Number of bins:",
                                                  min = 1,
                                                  max = 50,
                                                  value = 30)),
                           plotOutput("distPlot")
                       ),
                       box(width = NULL, title = NULL, collapsible = F,
                          fluidRow(
                              column(width = 5,
                                     tags$img(src = "https://i.stack.imgur.com/EslMF.png", width = '100%')
                                     ),
                              column(width = 7,
                                     tags$h4("Card Title"),
                                     tags$p("Some text here")
                              )
                          )
                       )

                      ),
                column(width = 4,
                       box(width = NULL, title = "Header", status = "info", collapsible = F),
                       box(width = NULL, title = "Header", status = "success", collapsible = F),
                       box(width = NULL, title = "Header", status = "secondary", collapsible = F)
                       )
                     )
                ),
            controlbar = dashboardControlbar(
                collapsed = FALSE,
                div(class = "p-3", skinSelector()),
                pinned = TRUE
            )
            )

server <- function(input, output) {

    output$distPlot <- renderPlot({
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)

        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
}

shinyApp(ui = ui, server = server)


Calculus Made Easy Exercise 8 Question 6

Question: Find the slope, at any given point, of the curve whose equation is $\frac{x^2}{3^2}+\frac{y^2}{2^2}=1$; and give the numerical value of the slope at the place where $x = 0$, and at that where $x = 1$.
Comment: Welcome to MathSE.  Please [edit] your question to show what you have attempted and explain where you are stuck so that you receive responses that address the specific difficulties you are encountering.  This [tutorial](https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference) explains how to typeset mathematics on this site.
Comment: I'll help the reading if you use MathJax
Comment: Have you tried implicit differentiation?
Answer: For the curve, $\frac{x^2}{3^2}+\frac{y^2}{2^2}=1$, we have to use implicit differentiation to find the "slope" at a given point.
$$\frac{d}{dx}\frac{x^2}{3^2}+\frac{d}{dx}\frac{y^2}{2^2}=\frac{d}{dx}1$$
$$\frac{18x}{81}+\frac{8y}{16}\frac{dy}{dx}=0$$
$$\frac{18x}{81}=-\frac{8y}{16}\frac{dy}{dx}$$
$$\frac{\frac{18x}{81}}{-\frac{8y}{16}}=\frac{dy}{dx}$$
$$-\frac{288x}{648y}=\frac{dy}{dx}$$
$$-\frac{4x}{9y}=f'(x)$$
Now you just have to plug in the values to find the derivative at a given point


Finding the Absolute Max & Min Values

Question: This problem is giving a bit of trouble. This is for my Calculus one class and am trying to better understand this problem. Any help would be much appreciated.
$f(t) = 6t + 6 \cot (\frac{t}{2})$
The given intervals are:
$ [ \frac {\pi}{4},\frac{7\pi}{4}]$
Here's what I have:
I found that $f'(t) = 6 - \frac{1}{2}\csc^2 (\frac{t}{2}) = 0$
then I got to this point and drew a blank:
$\csc(\frac {t}{2}) = \sqrt{12}$
Answer: There's an arror in $f'(t)$. It should be $6(1-\frac{1}{2}\csc^2\frac{t}{2})$. So,
$$\csc\frac{t}{2} = \pm\sqrt{2}$$
Now, $\frac{t}{2}\in(\frac{\pi}{8},\frac{7\pi}{8}), \csc(\frac{t}{2})>0$
$$\sin\frac{t}{2} = \frac{1}{\sqrt 2}$$
So we have $\frac{t}{2} = \frac{\pi}{4}$ or $\frac{3\pi}{4}$.
Now check for extrema.
Answer: Don't forget to use the chain rule when taking the derivative of $cot(\frac{t}{2})$. You have to multiply $-csc^2(\frac{t}{2})$ by the derivative of $\frac{t}{2}$, which you can find using quotient rule or constant multiple rule since $\frac{t}{2}=\frac{1}{2}t$. This should help get you back on the right track!

Finding the Absolute Max & Min Values


How to set WINS through GPO?

Question: I'm looking to set our WINS servers via GPO, is that possible?  We have 2 SSID which our clients can connect to (one which connects to a DHCP we control, the other to a different DHCP we don't - each with their own WINS).
We do a lot of mapping via DFS so that's why we need our wins servers.
Help?
Answer: There's no direct mechanism to assign a WINS server via GPO, unfortunately. When you can't assign the WINS server via DHCP, your best bet would be to do this via a logon script using the netsh command.
Answer: The command for setting WINS is below:
Netsh interface ip set wins name="Local Area Connection" source=static addr=192.168.100.3
There is a netsh wins command as well, but that is for Winsock. Lost some time on that one before...
Also, if you are setting WINS on the wireless connection, the name will be different of course. Just run ipconfig to see what the name should be. It needs to be exact as far as I know.
Comment: +1 Thank you for the explination and command example!
Answer: Group policy is not the mechanism to set network configurations.  DHCP already has that covered.  If you are having a problem using wins (I presume because for some reason you cannot replicate to the other wins server) I would instead use dns.  See How DFS Works in Environments Without WINS

How to set WINS through GPO?


applescript works natively but not in Filemaker

Question: I have a .jar file which runs from terminal and sends a HL7 file to an ip address and port, using minimal lower layer protocol.  This works fine from within Terminal and also works well when scripted in applescript editor using the following script:
do shell script "/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/java -jar /Applications/dcm4che-1.4.32/bin/hl7snd.jar mllp://10.0.0.2:2575 /Applications/dcm4che-1.4.32/bin/worklist/file.txt"

However when i try and automate this by performing the same applescript within Filemaker pro 12, I get this error:
JavaVM: Failed to load JVM: /System/Library/Frameworks/JavaVM.framework/Versions/1.6//libserver.dylib

Any help with this issue would be much appreciated.
Answer: I was having this same issue in filemaker 11 in mountain lion and I just found a solution. You have to unset the environment variable that filemaker is setting for java. To do this, add this before the java command:
unset JAVA_JVM_VERSION

So your full script would be:
do shell script "unset JAVA_JVM_VERSION;java -jar /Applications/dcm4che-1.4.32/bin/hl7snd.jar mllp://10.0.0.2:2575 /Applications/dcm4che-1.4.32/bin/worklist/file.txt"

Comment: That unset command worked a treat!!!  Thanks so much, this has been a really big help!
Answer: Do you escape your double-quotes correctly in FileMaker? If you paste the ENTIRE applescript command into the Data Viewer in FileMaker, does it look correct?
It looks like not the entire path is loaded correctly...


How to subset a data frame and apply the same function over and over?

Question: I have a question that seems rather simple but I can't find a solution for it.
I have a data frame with 57 countries and their GDP over 20 years (1140 observations in total). I want to apply the HP Filter from the package mFilter on each country and then save each result as a new variable. Like this:
df <- read.csv("QNA_26062015181325399.csv")

usa <- subset(df, Country == "United States", select = c("TIME", "Value") )

usa.filtered <- hpfilter(usa$Value, type = "lambda", freq = 1600))

The problem is I need to repeat this procedure for each country. Is there I can automate this process without having to type the same code 57 times?
Comment: you may take into consideration the `plyr` package which is the practical application of the split-apply-combine procedure. [Here](http://www.jstatsoft.org/v40/i01/paper) you can find the paper about that procedure with example of that package.
Answer: You can split your data by Country and lapply the function
lapply(split(df[,c("TIME", "Value")], df$Country),
    function(x) hpfilter(x$Value, type = "lambda", freq = 1600)
)

Comment: `by` is also a nice combination of `split` + `lapply`
Comment: Is there a way to quickly save each of the newly-generated filtered series as new variable?
Comment: @DPinto You should save them in a list instead of a new variable
Answer: If you want to use plyr try:
library("plyr")
f = function(x) {
    hpfilter(x$Value, type = "lambda", freq = 1600)
}
dlply(df[, c("TIME", "Value", "Country")], .(Country), f)

Comment: Note that if the intermediate data.frame isn't stored, there's no point subsetting out TIME, Value and Country.
Answer: This is a plyr solution:
library("plyr")
hpList <- dlply(df, .(Country), function(x) hpfilter(x$Value, type = "lambda", freq = 1600))

Alternatively, you could split the data first and then process it:
countryData <- dlply(df, .(Country), `[` , j = c("TIME", "Value"))
hpList <- llply(countryData, function(x) hpfilter(x$Value, type = "lambda", freq = 1600))


Is it possible to implement a dynamic tree of components in JSF?

Question: I am attempting to construct a component tree in JSF 1.2 (Mojarra) where the tree consists of multiple types of junction and leaf nodes.  Each leaf node needs to render in a unique way and needs to be posted-back with potential changes.  The purpose is to allow the user to update processing logic where each leaf node represents an operation, such as "value equals" or "value not equal".
For example:
Root
|
+- InternalNode1 (type I_A)
|  |
|  +- LeafNode1 (type L_A)
|  |
|  +- LeafNode2 (type L_B)
|
+- InternalNode2 (type I_B)
   |
   +- LeafNode3 (type L_B)
   |
   +- LeafNode4 (type L_A)

Each type of leaf node needs to render differently, depending on the needs of that node type.  Additionally, the tree will be modifiable and nodes can be added or removed with Javascript and updates posted back to the server, etc.  For example, in the above tree, LeafNode4 could be removed, or its type changed to L_B.
Is this even possible with JSF components?  Am I going about it the wrong way by attempting to use polymorphic UI components?
Answer: You might want to look at <rich:tree>.
Comment: Thank you for your reply.  Depending on the route I take, I may be able to use some of the concepts discussed.  Using RichFaces probably won't be an option at my place of employment however :-)
Answer: It is possible to build a component tree programmatically, but this would be the wrong approach for your use-case. It would generally be unsecure to allow the user-agent to manipulate such server-side code.
It would be better to use a model to manage your tree structure (which is essentially the approach Don Roby is suggesting.) The data that makes up this model can then be validated like any other user input to ensure attackers aren't trying to put server-side data into an invalid state.
JSF's declarative approach makes it challenging to do this out of the box (you can see a crude tree rendering example here.) If you don't want to drag in a 3rd party library (or write your own control) you may be better off handling all the tree UI in JavaScript and using a JSF hidden field to transport it to/from the server.
Comment: Thank you for your response.  I am interested in the custom `UIComponent` approach you mentioned where the component contains my data model.  My trouble is understanding how the data is reconstituted on post-back.  If the leaf nodes of the data model contain pluggable classes (polymorphic) that each have varying inputs/selects/etc, then do I need code in the component's `decode` method to parse that out and recontruct the tree?  The JavaScript/hidden field solution are also interesting.  It could be possible to manipulate a JSON tree and parse that and get away from the entire component idea.
Comment: @MGE - generally, you would decode submitted data in the `Renderer` from the request parameter map. If you want to allow forms to send data back to the server, you'll probably need to use hidden fields anyway. Which approach you take is largely a matter of personal preference - do you want the deserialization logic in beans, a `Converter` or a `Renderer`? Do you want a `Renderer` to emit the tree as HTML or parse data in JS and recreate on page load? You are going to have to write the JavaScript to a greater or lesser extent anyway.


How to search data with ng-click in angular js

Question: I want to search data with ng-click function in angularJS, but when I try this code, it doesn't work.
First my button code:
<button id="veg" ng-click="myFilter = {type: 1}" title="veg">

My data display code:
<div class="side-body padding-top fade in  tab-pane"  id="<?php echo $tt3->id; ?>">

        <div ng-if='r.pro_category == <?php echo $tt3->id; ?>'
             ng-repeat = "r in groups | filter : searchGroups | filter:myFilter">

@{{r.pro_name }}

@{{r.price}}

My script code:
var GroupsApp = angular.module('GroupsApp',[]);
GroupsApp.controller('GroupsController', function ($scope, GroupsService) {

    getGroups();

    function getGroups() {
        GroupsService.getGroups()
            .success(function (grps) {
                $scope.groups = grps;

                 return (val.type != 2);
                console.log($scope.groups);
            })
            .error(function (error) {
                $scope.status = 'Unable to load Product data: ' + error.message;
                console.log($scope.status);
            });
    }
});

var url = window.location.pathname;
var productid = url.substring(url.lastIndexOf('/') + 1);

GroupsApp.factory('GroupsService', ['$http', function ($http) {
    var GroupsService = {};

    GroupsService.getGroups = function () {
        return $http.get('../showproduct/'+productid);
    };
    return GroupsService;
}]);

When I run above code it doesn't show anything.
Comment: your code is of angularJs type, and you tagged into Angular2. make correction please
Comment: Please explain *it doesn't show anything*
Comment: Means data shows perfecty in normal. Now i have some flag or type for product. For that i have define button. so when i add ng-click in button as mention in my code it doesn't filter data...filter like veg or non-veg @PankajParkar
Comment: ok thanks @PardeepJain can you help me  to slove my problem
Answer: <button href="#" id="veg" ng-click="myFilter = {active: 1}" title="All Menu Items"  class="bbb1 btn btn-info btn-lg "  >


systemd unit on separate partition fails to load on reboot

Question: I have a .service on a separate partition which is linked with "systemctl enable" but does not automatically start on boot. Running "systemctl status" claims "failed to load" and it works if I run systemctl daemon-reload.
My guess is that this happens because it's on a separate partition and I was able to workaround this by doing "cp -t /etc/systemd/system" explicitly.
This seems like something that should "just work", what am I missing?
Answer: Yes, this is expected and it's documented in the systemctl(1) man page, under the enable command:

The file system where the linked unit files are located must be accessible when systemd is started (e.g. anything underneath /home or /var is not allowed, unless those directories are located on the root file system).

The reason for the limitation is that systemd scans all units and assembles a transaction at startup. Mounting other filesystems is done through units, so units in other filesystems will not be available until the transaction is already in progress. systemd will not rescan the units and recalculate the transaction after those filesystems are mounted.
Copying the units into the root filesystem is an appropriate workaround, as you already found out.
Comment: This is disappointing: systemd could just reload symlinks as partitions go up.
Comment: I ran into something like this with 219. Systemd would not enable the service if link is to another partition with "Invalid argument" error, without ever explaining what exactly is wrong (yet agree to start/stop it).
Comment: @cdleonard Part of the problem is that you need a full picture to properly resolve dependencies. For example, what if the unit from the other partition declares it wants to run *before* starting a webserver or a database, but by the time it's available those services are already up? Also, recalculating the whole dependency graph is pretty expensive, so doing so when partitions being mounted means your boot will be slower. And systemd is all about fast boot.
Comment: A clear error message would be enough...
Answer: Workaround is possible.
Create unit that will call:
systemctl daemon-reload; systemctl start <your service>

Make this unit to start after mounts.
Comment: My service is on the `/usr/local/` partition, should I use `Wants=usr-local.mount` or `After=usr-local.mount` or `Requires=usr-local.mount` for my timer to start upon reboots ? And in which section(s) of the service ?


How do I calculate if the degree of overlap between two lists is significant?

Question: If I have two lists A and B, both of which are subsets of a much larger list C, how can I determine if the degree of overlap of A and B is greater than I would expect by chance?
Should I just randomly select elements from C of the same lengths as lists A and B and determine that random overlap, and do this many times to determine some kind or empirical p-value? Is there a better way to test this?
Comment: You should use Colin's answer, still your idea of making Monte Carlo simulation is also correct.
Answer: If I understand your question correctly, you need to use the Hypergeometric distribution. This distribution is usually associated with urn models, i.e there are $n$ balls in an urn, $y$ are painted red, and you draw $m$ balls from the urn. Then if $X$ is the number of balls in your sample of $m$ that are red, $X$ has a hyper-geometric distribution.
For your specific example, let $n_A$, $n_B$ and $n_C$ denote the lengths of your three lists and let $n_{AB}$ denote the overlap between $A$ and $B$. Then
$$n_{AB} \sim \text{HG}(n_A, n_C, n_B)$$
To calculate a p-value, you could use this R command:
<code>#Some example values
n_A = 100;n_B = 200; n_C = 500; n_A_B = 50
1-phyper(n_A_B, n_B, n_C-n_B, n_A)
[1] 0.008626697
</code>
Word of caution. Remember multiple testing, i.e. if you have lots of A and B lists, then you will need to adjust your p-values with a correction. For the example the FDR or Bonferroni corrections.
Answer: csgillespie's answer seems correct except for one thing: it gives the probability of seeing strictly more than n_A_B in the overlap, P(x > n_A_B), but I think OP wants the pvalue P(x >= n_A_B). You could get the latter by
<code>n_A = 100;n_B = 200; n_C = 500; n_A_B = 50
phyper(n_A_B - 1, n_A, n_C-n_A, n_B, lower.tail = FALSE)
</code>
Comment: +1 for `lower.tail=FALSE`. Very small p-values (< 1e-16) are truncated otherwise.


Select query for frozen list Cassandra

Question: I am trying to write a cassandra query for searching data in frozen list below is my table. Thanks in advance
<code>deviceid           | streamid | datalist
--------------------+----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 0x236A906D3F4CDB72 |      110 | [{date: '2018-09-26 11:49:52.295000+0000', values: '30AEA4807704,-74'}, {date: '2018-09-26 11:49:54.232000+0000', values: '30AEA4807704,-74'}, {date: '2018-09-26 11:50:22.531000+0000', values: '30AEA4807704,-73'}, {date: '2018-09-26 11:50:24.538000+0000', values: '30AEA4807704,-73'}, {date: '2018-10-04 05:54:48.189000+0000', values: '30AEA4807704,-73'}, {date: '2018-10-04 05:55:55.243000+0000', values: '30AEA4807704,-73'}]
</code>
Comment: What exactly are you trying to query? Could you also share your table definition?
Comment: and query that you're trying to write
Answer: You can not search on data that is in the frozen list.

Select query for frozen list Cassandra


What type of panel data model to run for forecasting on a site level basis?

Question: I am trying to forecast monthly energy volume on a site-level basis (around 2,000 individual sites). I have monthly data for each site for at least two years. I also have attributes such as square footage, building type, cost, location, etc.
Do I need to run an individual model for each site for the forecast to be most accurate?
I will be using R to perform the analysis. Any suggestions, tips, information, etc. will be VERY appreciated as I am currently in information overload :).
Answer: Maybe facebook's Prophet would be useful?  According to the github site, prophet is a "tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth."  They claim it scales well.
I have not used it but plan on evaluating it at some point.


Apache AGE- Get all Edges

Question: I'm using the Apache AGE extension, I have a graph named Family with a vertex named PERSON. And many edges such as CHILD_OF, GRANDCHILD_OF, UNCLE_OF, AUNT_OF.
Now what I want is to display all the edges present in the graph.
I can get the Vertices using the query:
SELECT * FROM cypher('Family', $$
MATCH (a)
RETURN a

This would list down all the vertices and their properties.
I want to do the same with edges, how would I do that?
Answer: To display all the edges you can use the MATCH clause as
SELECT * FROM cypher('Family', $$
MATCH (a)-[e]->(b)
RETURN e

Now if you want to put a filter on which edge to display based on label, you can do as
SELECT * FROM cypher('Family', $$
MATCH (a)-[e: CHILD_OF]->(b)
RETURN e

Read about MATCH clause in the doc
Answer: You can use the command.
SELECT * from "Family"._ag_label_edge;

This will return a table with a list of all the edges with their properties.
You can use a similar command for vertices also.
SELECT * from "Family"._ag_label_vertex;

Answer: You can use the Match all the edges by the following format:
    SELECT *
    FROM cypher('Family', $$
      MATCH (a1:PERSON)-[r:<edge_label>]->(a2:PERSON)
      RETURN type(r)
    $$) as (r agtype);

"edge_label" can be CHILD_OF, GRANDCHILD_OF, UNCLE_OF, AUNT_OF any of them.

Apache AGE- Get all Edges


React-Table get row where button is clicked

Question: I'm working on a litte React project with React-Table. I have one column with the Header Optionen, where I have a button in every cell.

render() {
    const columns = [{
      Header: 'Baumart',
      accessor: 'baumart'
     },{
     Header: 'Größe',
     accessor: 'größe'
     },{
     Header: 'Anzahl',
     accessor: 'anzahl'
     },{
     Header: 'Preis pro Baum',
     accessor: 'preis'
     },{
     Header: 'Optionen',
     accessor: 'platzhalter',
     Cell: ({ cell }) => (
      <button id="test" onClick={this.deleteRow(this)}>
       Löschen
      </button>
    )
     }]
    return (
      <>

        <ParticleBackground/>

                  Weihnachtsbaumverkauf

                  Warenkorb

                <Link to="/shop" className='warenkorb'></Link>

              <ReactTable
                data={this.state.tabledata}
                columns={columns}
                showPaginationBottom={false}
              />

Impressum • Datenschutzerklärung
Copyright © 2021 - 2022

      </>

    );
  }
}

These buttons have the job to delete a row with the help of an axios request.

deleteRow(data) {
    return function () {
      api.post('/delete', {
        baumart: data.state.tabledata[0].baumart,
        größe: data.state.tabledata[0].größe
      })
   }
}

It works kinda fine, but onClick={this.deleteRow(this)} only gives me the full table as a param and when I click any of my buttons the first row in my table gets removed.
So I had to find a solution...
data.state.tabledata[0].baumart always gives me the baumart of the first row and
data.state.tabledata[1].baumart always gives me the baumart of the second row
Instead of 0 or 1,2,3,4,5...n I need a const or state of the current row where one of my buttons got pressed.
I would be very grateful for every help.
PS: I'm really sorry for my english, still trying to improve it.
Comment: You probably can find a better package for tables in React, but for this case that `Cell` function takes some cell info as an argument, perhaps you can extract the row info from there.
Comment: @tromgy could you show me how? I am fairly new to react and it would be a great help.
Comment: There is not enough information in your question to give a more definitive answer. Could you provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)?
Answer: Cell provides arguments like value and row, which you can use in order to identify which row's cell was clicked. Following snippet can help you -
 Cell: (props) => (
         <button id="test" onClick={alert(JSON.stringify(props))}>
            Löschen
         </button>
      )


Inequality involving closure and intersection

Question: Let the closure of a set $A$ be $\bar A$. On Page 62, Introduction to Boolean Algebras,Steven Givant,Paul Halmos(2000), an exercise goes like,

Show that $P \cap \bar Q \subseteq \overline{(P \cap Q)}$, whenever $P$ is open.

I felt muddled in face of this sort of exercises. Is there some way to deal with these problems and be assured about the result?
Answer: Suppose $x \in P \cap \overline{Q}$.  To show that $x \in \overline{ P \cap Q }$ we will show that every open neighbourhood of $x$ meets $P \cap Q$.
If $U$ is any open neighbourhood of $x$, then as $x \in P$ it follows that $U \cap P$ is also an open neighbourhood of $x$.  As $x \in \overline{Q}$, then $U \cap P$ meets $Q$, or, $U \cap ( P \cap Q ) = ( U \cap P ) \cap Q \neq \emptyset$.  Therefore $x \in \overline{ P \cap Q }$.
Answer: Let $x$ in $P\cap\bar Q$. Since $x$ is in $\bar Q$, there exists a sequence $(x_n)_n$ in $Q$ such that $x_n\to x$. Since $x$ is in $P$ and $P$ is open, $x_n$ is in $P$ for every $n$ large enough, say, $n\geqslant n_0$. Hence, for every $n\geqslant n_0$, $x_n$ is in $P\cap Q$. Thus, $x$ is in $\overline{P\cap Q}$ as limit of $(x_n)_{n\geqslant n_0}$.
Comment: This only works if the space in question is Fréchet-Urysohn.
Comment: What if at point $x$, there is not a countable basis?
Comment: @ArthurFischer: Is it possible to adapt this sequence argument to a net one?
Comment: @MettaWorldPeace: Probably so, but there is no need. See Arthur's answer for an alternative.
Comment: @MettaWorldPeace:  Yes, of course.  If $\{ x_\sigma \}_{\sigma \in \Sigma}$ is a net in $Q$ converging to $x$, then there is a $\sigma^\prime \in \Sigma$ such that $x_\sigma \in P$ for all $\sigma \geq \sigma^\prime$.  Take the subnet determined by the directed set $\Sigma^\prime = \{ \sigma \in \Sigma : \sigma \geq \sigma^\prime \}$.  This is a net in $P \cap Q$ which converges to $x$.
Comment: @ArthurFischer *This only works if the space in question is Fréchet-Urysohn*. Yes.


Migration with ID already exists

Question: My migration is not showing up in drush migrate-status. When I try to reimport them with drush config-import --partial --source="modules/custom/complinetmigration/config/install" I get the following error message.

The import failed due for the following reasons:
  Unexpected error during import with operation create for
  migrate_plus.migration.complinet_xml_to_node2: migration entity with ID market_center_to_D8 already exists.
Comment: This could be because the `migrate_plus.migration.complinet_xml_to_node2` was renamed, or there is already another migrate config with the id `market_center_to_D8`.

You can find the config id in the data column of the config table in the database.
Answer:
Try deleting the existing migration by doing drush cdel migrate_plus.migration.MIGRATION_ID
I think the id in your YML file is not the same as the MIGRATION_ID part of your YML file name.
Answer: You can try some way below:

Try import single with drupal cis (this option will override if config exited)
Delete config with command:
drush config-delete migrate_plus.migration.complinet_xml_to_node2

and import again.

Migration with ID already exists


Fetch minimum value for each NTILE bucket in Hive

Question: I am trying to partition the data into percentiles (100 equal buckets) using NTILE window function for each merchant_id ordered by score column. The output of the query will contain merchant_id, score, and percentile for every record in the source table. (Sample code below)
CREATE TABLE merchant_score_ntiles
AS
SELECT merchant_id, score, NTILE(100) OVER (PARTITION BY merchant_id ORDER BY score DESC) as percentile
FROM merch_table

This will return sample output as follows:

merchant_id,score,percentile
1001,900,1
1001,800,1
1001,760,1
1002,900,2
1002,800,2
1002,750,2

Is there a way we can return only the minimum score for each merchant_id based on percentile column such as below?

merchant_id,score,percentile
1001,760,1
1002,750,2
Answer: You can try to use ROW_NUMBER window function in subquery before using NTILE window function
SELECT merchant_id,
       score,
       NTILE(100) OVER (PARTITION BY merchant_id ORDER BY score DESC) as percentile
FROM (
    SELECT *,ROW_NUMBER() OVER(PARTITION BY merchant_id ORDER BY score) rn
    FROM merch_table
) t1
WHERE rn = 1


Inheritance and Includes

Question: Lets say I have 2 classes.  One is BaseClass and one is DerivedClass, being a derived class of BaseClass.  I need to be able to create objects of both classes in another file.  By using an #include statement to include the derived class in the new file, I have access to the derived class directly and the base class indirectly (as the derived class includes it in its file).  Is it better to use this method of indirect "access" to the base class, or would it be better to directly include it alongside the derived class in the file?
Answer: The general advice is include what you use.
If you are coding to an API specification, and that specification does not explicitly detail the base-derived nature of the classes, then any changes to that relationship may break the includes that the files you depend on use.
See here as well.
If you are certain the BaseClass will always the base to the DerivedClass, then there may be little need include both, but for clarity, I would go ahead and do it anyway, it shows your intent.
Comment: Worth noting that with include guards the impact of multiple includes of the same file can be miniscule.
Comment: Worth mentioning is that you should always use header guards.
Comment: That makes total sense.  And while I wrote both classes and know that I they won't change in that respect, it seems to make more sense to include it directly.
Comment: I am not so sure of that: even with #ifndef #define the preprocessor still has  to parse the entire file to find the #endif
Answer: Including all needed headers instead of relying on transitivity gives has two advantages:

If your header files will be refactored, you will not need to change your cpp file.
It clearly identifies your intent for other developers.
Comment: What intent does an include statement reveal? It''s just a necessary evil.

Inheritance and Includes


Varnish does not purge my requests sent by Plone

Question: I have varnish 3.0.5 up and running, connecting to a Plone 4 backend. My requests are cached, but not purged reliably, actually only after expiration of the ttl.
plone.app.caching is the addon, which sends a purge request, every time an object is modified. This is the varnishlog:
   14 BackendOpen  b backend_0 127.0.0.1 54428 127.0.0.1 9088
   14 BackendXID   b 1585950387
   14 TxRequest    b PURGE
   14 TxURL        b /VirtualHostBase/https/example.com/path/VirtualHostRoot/pic/a.jpg
   14 TxProtocol   b HTTP/1.1
   14 TxHeader     b Host: localhost:9081
   14 TxHeader     b X-Varnish: 1585950387
   14 BackendClose b backend_0
   13 ReqStart     c 127.0.0.1 56614 1585950387
   13 RxRequest    c PURGE
   13 RxURL        c /VirtualHostBase/https/example.com/path/VirtualHostRoot/pic/a.jpg
   13 RxProtocol   c HTTP/1.1
   13 RxHeader     c Host: localhost:9081
   13 VCL_call     c recv pipe
   13 VCL_call     c hash
   13 Hash         c /VirtualHostBase/https/example.com/path/VirtualHostRoot/pic/a.jpg
   13 VCL_return   c hash
   13 VCL_call     c pipe pipe
   13 Backend      c 14 backend_0 backend_0
   13 ReqEnd       c 1585950387 1412603444.714001656 1412603505.824758053 0.000071526 0.000180483 61.110575914

Within default.vcl I have configured acl purgers,  basic vcl_hit and vcl_miss functions, and inside of vcl_recv I have:
if (req.request == "PURGE") {
    if (!client.ip ~ purge) {
        error 405 "This IP is not allowed to send purge requests.";
    }
    return (lookup);
}

When I open the image after purging, I still get the old version, until max age has expired.
This is the shortened log output:
3 RxURL        c /VirtualHostBase/https/example.com:443/path/VirtualHostRoot/pic/a.jpg
3 RxProtocol   c HTTP/1.0
3 RxHeader     c Host: enertour.bz.it
3 VCL_call     c recv lookup
3 VCL_call     c hash
3 Hash         c /VirtualHostBase/https/example.com/path/VirtualHostRoot/pic/a.jpg
3 VCL_return   c hash
3 Hit          c 1585950403
3 VCL_call     c hit deliver
3 VCL_call     c deliver deliver
3 TxHeader     c Cache-Control: max-age=0, s-maxage=240, must-revalidate
3 TxHeader     c X-Cache-Rule: plone.content.file
3 TxHeader     c Age: 181

What I've done until now is rewriting the hash value of the request, to match the hash of the purge request. They are identical, but my object is not purged and I can't figure out why? Is it because the requesting host changes?
Glad about any hints!
Comment: boernie: post this as an answer, and then set it as the 'correct' answer, so it shows up as answered, and others coming across can learn from your experience.
Comment: Could you please post your complete VCL.
Comment: Damn, I'm such a stupid! Looking again at my vcl today I figured out that during modifications the purge function slipped under the lines where I check the request types. Therefore a purge wasn't allowed and it finished in a pipe. Sorry for claiming your time!
Answer: Looking again at my vcl today I figured out that during modifications the purge function slipped under the lines where I check the request types. Therefore a purge wasn't allowed and it finished in a pipe.
The correct order is:
if (req.request == PURGE) {
  ...
  return (lookup);
}
if (req.request != "(GET|HEAD)" {
  ...
  return (pass);
}


What to use for node_prepare in Drupal 7

Question: I am converting a module from Drupal 6 to Drupal 7. I have come across a Drupal 6 functional call named node_prepare and I am not sure what needs to be done to make this work with Drupal 7. What should this function be replaced with?
Thanks.
Answer: You don't need to replace it with anything as it happens, you can just remove it.
All that function does is prepare the node body for display. Since the body is a field in Drupal 7, all that processing is done elsewhere, and it's not something you need to invoke manually any more.
Comment: Thanks, that makes it easy. All I then need to do is implement hook_view() to actually display the node as I would like it to be.


Why all dates columns in drupal are type=int and not type=date/timestamp/time?

Question: I want to make this question short, so as title says "Why all dates in drupal are INT" ?
I've notice that in Schema API there was "datetime" but it was removed in D7.
Also all tables that have time in it (cache_*,semaphore,node etc.) have INT instead of TIMESTAMP.
Before debating "INT vs TIMESTAMP" flame, I would like to remind you that:

DATETIME is obvious what the value represents.
INT is smaller
TIMESTAMP has both advantages.

The thing is that I want to understand what's "philosophy of drupal" for this.
Comment: Because Drupal doesn't just support MySQL as a backend, it also supports backends that do not have a `DATETIME`/`TIMESTAMP` type. If it's a problem see [the docs](http://api.drupal.org/api/drupal/includes%21database%21schema.inc/group/schemaapi/7) and use one of the db specific types (e.g. `mysql_type`) for your schema
Comment: Then I would guess their implementations are not uniform across the different DBMSs, and so can't be used generically
Comment: drupal supports postgres and sqlite. Both have DATETIME...
Comment: well that's my guess too... Just wanted to be sure!
Answer: I guess the main reason its that you cannot have two columns with TIMESTAMP and default NOW() value in MySQL according the documentation (see that answer). So seems to be the easier way to workaround it its to use int.


Conjugate beta / interpretation of the "continuous binomial" signal

Question: Note: this question has significantly evolved, thanks to inspiring comments by Tim.
Assume there is some "truth" $x\in[0,1]=Beta(1,1)$ that is signaled with some precision. I assume that the resulting posterior distribution (after receiving signal) of $x$ is $Beta(\alpha,\beta)$. To make the signal more explicit, I shall reparametrize the distribution as in this question and this paper (also accounting for uniform prior) with:$\alpha=1+s\phi$, $\beta=1+\phi(1-s)$, where $s\in[0,1]$ is a signal and $\phi$ is explicitly the precision parameter.
Since I know both the prior and the posterior, by Bayes rule, the signal $s$ given $x$ and chosen precision $\phi$ must follow:
$$
f(s|x,\phi)=\frac{\Gamma(2+\phi)}{\Gamma(1+s\phi)\Gamma(1+\phi(1-s))}\cdot{x^{s\phi}(1-x)^{\phi(1-s)}}.
$$
For $\phi\in\mathbb{N}$ and $s=k/\phi$ for $k\in\mathbb{N}$ this has a nice binomial interpretation: you make $n$ binomial experiments each with success probability $x$ and your signal is equal to the fraction of successes.
What could be an interpretation of a signal in the general case?  Is there some intuition?  Is this formulation ever used?
Comment: Why binomial and no other distribution that is "designed" for continuous data? Could you tell us more about your data and $j$ and $k$? I guess it's some kind of amount of signal through some amount of time?
Comment: There is no data, it is a theory model.
I assume that there is some "truth" $x\in[0,1]$ that is signaled with some chosen precision ($k$ in the example above, but a continuous variable would be even better). I had to assume some "signalling technology", and since I operate on $[0,1]$, the beta-binomial distribution seemed to be a reasonable choice. Also, it has a nice interpretation that the signal is $k$ pieces of evidence, each "persuasive" with probability $x$.
For technical reasons, a continuous signaling technology might be better - but I want sth tractable.
Comment: Wouldn't you rather want to treat the precision as something like [precision](https://stats.stackexchange.com/questions/183522/antonym-of-variance/183523#183523) parameter, rather then known (static) quantity? From what you're saying it seems that some kind of hierarchical Bayesian model may seem to be better, but it's hard to tell not knowing more details.
Comment: Yes, in general this is the way I think about precision - more precise signals give posteriors more concentrated around the truth. And it's not static - it is a choice of the person acquiring the signal (who also has to pay the cost $c(k)$).

In fact, a Gaussian model was my first choice, but I really want to stick to $[0,1]$. Binomial signals work well in getting more and more concentrated around true $x$, but their discreteness causes some complications in the proofs.
Comment: OK, so what about logistic regression-like hierarchical Bayesian model? You'd transform the linear, continuous "Gaussian" outcome to [0,1] by using logit function.
Comment: I will Google it :) As I said, since it is a model (meant to give insights, not to describe reality), my priority is tractability and nice intuition, and in this sense beta-binomial did a great job. I just have technical problems with mathematical proofs, especially if $k$ is small.
Comment: You may be also interested in http://stats.stackexchange.com/questions/194182/beta-as-distribution-of-proportions-or-as-continuous-binomial and http://stats.stackexchange.com/questions/67443/does-the-beta-distribution-have-a-conjugate-prior
Answer: Your equations and your nice intuition happens for all exponential families.
I would call your $\phi$ the "observation count" rather than precision since precision is usually the reciprocal of the variance.  (This is because I would interpret your Beta distribution as arising from a Beta-binomial model with $\phi$ Bernoulli observations.)
Your $(\phi s, \phi(1-s))$ are the natural parameters of the Beta distribution.  When you combine the evidence of two distributions while assuming independence, you just take the pointwise product of their densities (and divide out any double-counted information).  This is always the same as adding the natural parameters, which is what you've done.
Since $(\phi s, \phi(1-s))$ are natural parameters, another pair of natural parameters is $(\phi s, \phi)$.  It's not surprising to see that $\phi$ is a natural parameter since in the Beta-binomial model, $\phi$ was the number of observations, and combining evidence should add the number of observations.  In fact, every conjugate prior distribution of an exponential family has this "observation count" as a natural parameter.
As a contrast, for the normal distribution the natural parameters are $\left(\frac{\mu}{\sigma^2}, -\frac1{2\sigma^2}\right)$.  You can try the same calculations as in your question to verify that taking the pointwise product of densities is tantamount to adding natural parameters.
Comment: It was not explicitly an answer to my question, since my hope was more for a "story" that would describe the signal generating process with density as I derived. But your answer forced me to read and re-think the matter, giving me much deeper understanding on how the family of distributions is connected. So thanks!


Modifying 3 dimensional array in function in C

Question: I have a 3D array declared in main() function:
char currentPositions[5][6][2];
And i want to modify this array using another function:
SetDefaultPositions(currentPositions);
This function looks something like this:
void setDefaultPositions(char positions[5][6][2]){
    char defaultPositions[5][6][2] = {
        {"()", "()", "..", "..", "..", ".."},
        {"/\\", "/\\", "/\\", "/\\", "/\\", "/\\"},
        {"..", "..", "..", "..", "..", ".."},
        {"/\\", "/\\", "/\\", "/\\", "/\\", "/\\"},
        {"..", "..", "..", "..", "..", ".."}
    };
    positions = defaultPositions;
}

I tried using pointers but it keeps telling me things like this:
expected 'char (**)[2]' but argument is of type 'char (*)[6][2]'
warning: passing argument 1 of 'setDefaultPositions' from incompatible pointer type [-Wincompatible-pointer-types]
Or no errors, but printing currentPositions showed that it was empty.
I understand nothing, I also tried some solutions from web but I can't find someone with similar problem.
It's school project and I am not allowed to use global variables.
Comment: I think you want: `char defaultPositions[5][6][2] = { { {'(', ')'}, ...  }, { ... }, { ... }, { ... }, { ... } };` That is: `"()"` --> `{ '(', ')' }` And, for the assignment: `positions = defaultPositions;` --> `memcpy(positions,defaultPositions,5 * 6 * 2);`
Comment: @WeatherVane Arrgh! Fixed!
Comment: Aside: do you realise they are not C strings – there is no nul terminator?
Comment: `"()"` is _not_ a single character. So, it can _not_ be stuffed into a `char`. And, to use a character constant, you'd need `'()'` (single quotes). But, this is _two_ chars. So, again, not possible. You could (can only) do: `'('` or equiv.
Comment: The `positions = defaultPositions;` will have no effect for the caller. The array passed is in effect a pointer, so you are just overwriting the argument, not the array. And you can't copy an array with `=` anyway. *I tried using pointers* – please post a [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example), the shortest *complete* code that shows the problem.
Comment: @CraigEstey this works perfectly fine if I assign it to my variable in main
Comment: As mentioned, you are not assigning it to the array in `main()` that was passed. The passed array decays to a pointer, and what you are doing is to overwrite the pointer argument passed.
Comment: @WeatherVane

#include

void setDefaultPositions(char *(positions)){
    positions[0] = 'a';
    positions[1] = 'b';
}

int main()
{
    char currentPositions[2];
    setDefaultPositions(currentPositions);
    printf("%c, %c", currentPositions[0], currentPositions[1]);
    return 0;
}
Somethinh like this works perfectly fine on 1dimensional array, but i cannot figure out how to change a 3d array assigning a new one
Comment: Please edit the post to include formatted code!
Comment: @WeatherVane
Okay, so how can i make this work?
Answer: You can't pass an array to a C function. It decays to a pointer.
You can do it like this:
#include <stdio.h>
#include <stdlib.h>

void setDefaultPositions(size_t size, char positions[5][6][2]){
    char defaultPositions[5][6][2] = {
        {"()", "()", "..", "..", "..", ".."},
        {"/\\", "/\\", "/\\", "/\\", "/\\", "/\\"},
        {"..", "..", "..", "..", "..", ".."},
        {"/\\", "/\\", "/\\", "/\\", "/\\", "/\\"},
        {"..", "..", "..", "..", "..", ".."}
    };
    memcpy(positions, defaultPositions, size);
}

int main(void)
{
    char arr[5][6][2];
    setDefaultPositions(sizeof arr, arr);
    for(int j = 0; j < 5; j++) {
        for(int i = 0; i < 6; i++) {
            printf("%.2s ", arr[j][i]);
        }
        printf("\n");
    }
    return 0;
}

Program output:
() () .. .. .. ..
/\ /\ /\ /\ /\ /\
.. .. .. .. .. ..
/\ /\ /\ /\ /\ /\
.. .. .. .. .. ..

Bear in mind that the array elements are not strings – they have no terminator.
Comment: Thank you, now i understand it, works perfect
Answer: Arrays cannot be modified by an assignment because in C all values of arrays decay to a pointer to array's first element. Therefore, it not possible to execute:
array = value-of-array

Therefore arrays can only by assignment "by element" or with "memcpy()".
A quite reliable and type-safe method is passing a pointer to a whole array:
#include <string.h>

void setDefaultPositions(char (*positions)[5][6][2]) {
    char defaultPositions[5][6][2] = {
        {"()", "()", "..", "..", "..", ".."},
        {"/\\", "/\\", "/\\", "/\\", "/\\", "/\\"},
        {"..", "..", "..", "..", "..", ".."},
        {"/\\", "/\\", "/\\", "/\\", "/\\", "/\\"},
        {"..", "..", "..", "..", "..", ".."}
    };
    memcpy(positions, &defaultPositions, sizeof *positions);
}

int main(void) {
    char arr[5][6][2];
    setDefaultPositions(&arr);
}

Passing an array of a different dimensions (i.e. char[3][6][2]) will raise a warning from a compiler.
Comment: Did you test this? `sizeof *positions` is `12`.
Comment: @WeatherVane, No. It's 60, not 12. The code is correct. See https://godbolt.org/z/1YhsvdMo7
Comment: Since your edit it outputs the right values.
Comment: @WeatherVane, what warning? Have you seen the godbolt I've sent you?
Comment: Uh I thought I had copied your code.
Comment: `void setDefaultPositions(char positions [5][6][2])` ... `memcpy(positions, defaultPositions, sizeof defaultPostitions);` would make the API a bit less cumbersome.
Comment: @Lundin, but it silently accept a smaller array like `int[3][6][2]`. I know that modern compilers raise a warning in such a case but technically it is an overzealous notification until one declares parameter as `char positions [static 5][6][2]`.
Comment: Since `static` actually works on several compiler nowadays, then maintaining type safety in multi-dimensional array decay is a good use for that feature IMO.