Why does a minor sixth chord contain a major 6th interval?

Question: This is something that has always puzzled me. Perhaps I am going about this the wrong way but when I build chords I always build them based on the scale that corresponds to the quality of the chord.  For example...
CMaj7 = C-E-G-B ; Same notes that are in the CMaj Scale
Cmin7 = C-E♭-G-B♭ ; Same notes that are in the Cmin Scale
C7 = C-E-G-B♭ ; Same notes that are in the Cmix scale
CM6 = C-E-G-A ; Same notes that are in the CMaj scale
but....
Cm6 = C-E♭-G-A ; Same notes as the c min scale except for A (Should be A♭)
Why does Cm6 have a major 6th interval and why is it not built on the minor scale?
Comment: Not sure if your question is quite a duplicate, but I think this question and it's answers will give you the info you need: http://music.stackexchange.com/q/16932/9198
Comment: The minor-ness of the third is much more important than the major-ness of the sixth.
Comment: `I always build them based on the scale that corresponds to the quality of the chord.`  That's your problem; that's not how chords are defined.  A C Major chord is exactly the same no matter whether you "select" the notes from the keys of C Major, A Minor, F Major, D Minor, etc.  It's even the same if you're playing a piece in C# Major and the composer decided to throw one in for some reason.
Comment: I agree with everyone that this isn't the best way to conceive of chord construction. However, if this is just a mnemonic device for remembering—and if you're already using Mixolydian to remember one of the chords—why not conceive of the min6 chord as being built like a Dorian scale?
Comment: Yes, you're going about it the wrong way.  That's all there is to say really.
Comment: the m6 chord occurs as the ii chord in a major key. it naturally contains a minor third and a major 6th. for an example of an m6 that contains a minor-6th, look no farther than the iii chord of a major key.
Comment: Ok so I would say after reviewing these answers that the short answer is that a m6 chord is built on the the Dorian mode which makes sense! But I am also seeing that this is not the best way to view the building of chords. It's just easier for me to visualize than building on intervals.
Comment: Does this answer your question? [Why does a Cm13 chord use A instead of A♭?](https://music.stackexchange.com/questions/16932/why-does-a-cm13-chord-use-a-instead-of-a)
Answer: The chord C-Eb-G-A has a major sixth in it because it provides the harmonic tension characteristic of this chord's sound, namely by virtue of the augmented fourth between Eb and A. An Ab would not produce this same tension. The chord is called "minor" because of the quality of the triad C-Eb-G. The word "minor" in this case has nothing to do with the quality of the sixth. If you like you can think of it as a Cmin add6 chord. In any event, try not to get too caught up in the name, because as this wikipedia article explains, there are several different names for this chord.
Concerning the scale the chord is built on, I would argue that it's not the melodic minor scale because that would imply that the sixth would have to rise through the seventh and up to the tonic. In practice, this added note is generally used for the harmonic interest it adds, not any melodic directionality. So if this chord sounds like a tonic chord in a piece, a more appropriate scale origin would be the:
C Dorian scale:

    C  D  Eb  F  G  A  Bb  C

Note that this chord quality is often used for the subdominant in minor keys. So this same chord, C-Eb-G-A could easily serve as the subdominant in G minor, and in this case it would be derived from the G natural minor scale.
Comment: I agree, and especially since Cm13 contains the notes of the C Dorian Scale, not the C melodic minor scale.
Answer: The Cm6 chord has a major 6th interval in it simply because the "minor" refers only to the second note; it informs us that the second note is a minor third.
The notation and terminology is such that "minor chord" doesn't simply mean "everything that has a major/minor designation must be minor".
Unfortunately, it is not consistent, either. Or, fortunately, depending on the point of view. It turns out that things are the way they are because compactness of common forms beats consistency.
In this case, the Cm6 means the "Cm" triad, plus a 6th.  If there is just an "m", it makes the triad minor.
The confusing thing, perhaps, is that the "default flavor" for a 6th is major, but for a 7th it is minor.
That is to say, if nothing else is written other than the digit 6, it's a major 6th.  A minor chord with a minor 6th would be written "Cmm6": a Cm plus a m6.
The opposite default applies to the 7th degree. A 7 by itself is minor, rather than major.
What is worse, the letter M doesn't apply to the triad, but to the 7th degree.  Thus C7 means the C triad (i.e. major), with a minor 7th.
There is a certain logic to it nevertheless, which is why you don't really have to think about this.  The default triad is major, so you write C for the C major triad, and use an explicit m for the minor triad only. This means that the upper case M never refers to the triad, and the lower case m always does. Given that convention for triads, the rest of it follows. The letter m is occupied by denoting the triad, but the letter M is free, having no use. So the convention is that CM7 denotes the major 7th, and the absence of M, C7, denotes the dominant.  The opposite convention wouldn't work that well. If C7 denoted the major 7th chord rather than the dominant, we would have to write CMm7 for the dominant, which is clumsy for such a frequently needed chord (already verbose without any additional voices like 9ths, 11ths and so on, and alterations).
The 6th interval has no such issue: we make it default to major, and that works because it appears often, over either a major or minor triad. If an explicit M had to be written to get a major 6th, then the nice notations like Am6 and C6 would become AmM6 and CM6, or perhaps CMM6.  Am6 would still exist, and would denote the much more rare Amm6 chord.
In any case, all the cases not covered by common usage can just use two m's to spell out which triad and which 6th or 7th. The notation being the way it is lends a terse expression to all the chords that come up in the musical traditions to which that notation is tied.
Answer: Chord symbols are not intended to be related to a "key". The symbols are an attempt to describe the chord itself with no indication of value in relation to the key in which it is performed.
A minor 6th chord uses a major 6th interval because the "minor" word applies only to the 3rd in the chord (the difference between whether it is a minor or major triad), and the 6th is a given that it is a major 6th. The same idea is apparent with a dominant 7th chord.
A chord with the notes: (C E G B flat) is a dominant 7th chord, or it can be called a (C major flat 7) chord, but requires much more space and energy to describe it. The chord symbol system is used as a sort of shorthand for harmonization and therefore terms are used sparingly. So, the symbol (C 7th) is used to indicate a (C E G B flat) chord because this dominant 7th chord is the most common 7th chord used historically, and the C major seventh chord is written in the symbol (C maj 7th) to indicate that the major seventh interval is used instead of the more common flat or dominant seven.
With the sixth chord, we have the same idea, but it is reversed, the major interval is much more used historically than the minor sixth interval, so the longer description lies with the lessor used version of the sixth chord. (C minor 6th) or (Cm6) is (C - E flat – G – A) where the "minor" applies only to the third interval. The (C minor-minor 6th) or (Cm m6th)or (Cm b6th) would be the notes C - E flat - G - A flat. Where the small b should be a flat sign.
Answer: Just because the chord is named C, doesn't mean that it only belongs to some C scale (either major or minor or whatever); it could belong to other scales as well.
This would be the case if it were the melodic minor scale. In Jazz, the C melodic minor scale is: C,D,Eb,F,G,A,B,C -- which is just like the C major scale with a flatted third.
Also, this chord could belong to another scale as well; to the Bb major scale ( or the G natural minor scale). Both of these scales have Eb, but A natural, thus resulting to the C-Eb-G-A chord you mentioned.
Answer: which minor mode are you speaking of? There are 3 of these:

natural minor (minor 6, minor 7) aka Aeolien
harmonic minor (minor 6, major 7)
melodic minor (major 6 and 7).

The "m6" chord is related to melodic minor mode.
The "mM7" chord can be related to either the harmonic minor or the melodic minor mode.
The "m7" chord can be related to the natural minor scale or the dorian scale (minor 3rd, major 6th, minor 7th) or the phrygian scale (minor 2nd, 3rd, 6th and 7th), although you will generally have more indications by the author if he wants something specific. By default "m7" means dorian, and you will have "mb9b6" for phrygian and and "mb6" for natural minor.
These are only the most common modes. See The Scale Syllabus  for more possible modes.
Answer: The fact that a m6 chord is based on the melodic minor scale has already been pointed out in other answers. I'd like to add that a minor triad with a minor sixth is just an inversion of a major seventh chord, so it wouldn't add anything new. E.g., a C minor triad with a minor sixth would have the notes
C Eb G Ab
which is just the first inversion of an Ab major seven chord:
Ab C Eb G
Comment: Well, that's also true of the maj6 chord, which is just an inversion of a minor 7th (C–E–G–A vs A–C–E–G). And the proper min6 is just an inverted half-dim chord (C–Eb–G–A vs A–C–Eb–G).
Comment: @PatMuchmore: Thanks for pointing this out, that's of course true. The big difference is - and I should have written it in my answer - that with a C6 (Am7) or a Cm6 (Am7/b5) *both* notes (A and C) can reasonably be perceived as root notes. This is not the case with Amaj7/C, where the C is not perceived as the root due to the chord's interval structure.
Answer: I think you are approaching this the wrong way around. These jazz chords are seventh chords build around the idea of having certain triads and adding colour to there sound by adding a certain type of seventh to them.
Only the dominant seventh is a type of chord that you would use in traditional harmony. The other types of chord are just interesting variations.
These seventh chords are often more interested in what type of seventh the chord has that just the mere nature of the third.
Sixth chords are different though. That sixth has a distinctly dissonant quality. This means that sixth chords are often just a type of passing chord which leads in a interesting way to other chords.
This is probably why the nature of the sixth is not reflected in the notation but rather just the indication of what type of triads it is. This may very well be more useful to a jazz player when deciding what chords to follow the sixth chord up with.
Answer: I'm with you on the CMaj7 and the Cmin7.  After that, I start to get a little queasy.
In general, you should be building chords based on the scale of the key you are in.  So, think of your C7 as being the dominant in the key of F (or f minor).
Things make better send to most of us mere mortals if we learn them in a specific tonal context.
Answer: It does simply because it is defined to be with those intervals. Instead of worrying about it, consider that it is a "magic" chord - that is what this one is - and enjoy the sound. Play the C Eb G A chord with any one of the constituent notes moved to the bass, e.g. Eb C G A (bottom note first) then think, what next? You will find that there are an enormous number of chords, not necessarily in the key of C minor, which sound good and natural after it. Chords don't mean much unless leading somewhere. In the example Eb C G A try following this with another made by moving any 2 of the notes by a semitone - so we might get D C F# A, and instant D7 chord asking please to resolve to G major: G D G B. There are thousands of possibilities, it's indeed useful chord.
Answer: Cm6 is as C, Eb, G, A as an M6 instead of m6. Cb6 Contains C, E, G, Ab as an m6 as an Mb6. Cmb6 Contains C, Eb, G, Ab.
Answer: The simplest way to comprehend this is the word  'Major' is only linked to Maj7 chords. This means, I only pronounce the word 'Major' just for 'Maj7' chords.  For example, if I called a C chord simply a 'C'(or dominant C) and not 'C Major'. Then only I can comprehend and differentiate between:-
C7 Chord: 1-3-5-b7
CMaj7 Chord: 1-3-5-7
Therefore, there is only a C6(C major w /the 6th note) and Cmin6(a C minor w/the 6th note). NO 'C Major6' or 'C Maj6'!!
Why does a Cmin6 have a Maj6 interval and not a min6?
Because the minor interval itself is derived from a major's. Cmin intervals: 1=C, b3=Eb, 5=G. If Cmin6 is built on its own minor scales, then Cmin7 C, Eb, G, A instead of C, Eb, G and Bb. Because according to its minor scale , the 7th interval is already Bb.
Comment: Please check the last paragraph. It's inaccurate.


How to launch a long running Java EE job?

Question: I need to fire off a long running batch type job, and by long we are talking about a job that can take a couple of hours. The ejb that has the logic to run this long running job will communicate to a NoSQL store and load data etc.
So, I am using JMS MDBs to do this asynchronously. However, as each job can potentially take up to an hour or more (lets assume 4 hours max), I dont want the onMessage() method in the MDB to be waiting for so long. So I was thinking of firing off an asynchronous ejb within the onMessage() MDB method so that the MDB can be returned to the pool right after the call to the batch ejb runner.
Does it make sense to combine an asynchrous ejb method call withing an MDB? Most samples suggest using 1 or the other to achieve the same thing.
If the ejb to be invoked from the MDB is not asynchrous then the MDB will be waiting for potentially long time.
Please advise.
Answer: I would simplify things: use @Schedule to invoke @Asynchronous and forget about JMS. One less thing that can go wrong.
Whilst not yet ready for prime time, JSR 352: Batch Applications looks very promising for this sort of stuff.
https://blogs.oracle.com/arungupta/entry/batch_applications_in_java_ee
Comment: Hi Andre, your answer is relevant now since JSR 352 is now mature. However, it seems not possible to fire up a batch job from a JMS Message listener in this version `BatchRuntime.getJobOperator().start("job_id", new Properties())`

The batch job gets stuck in STARTED status
Answer: It's a matter of taste I guess.
If you have a thread from the JMS pool running your job or if you have an async ejb do it, the end result will be the same - a thread will be blocked from some pool.
It is nothing wrong with spawning an async bean from a MDB, since you might want to have the jobs triggered by a messaging interface, but you might not want to block the thread pool. Also, consider that a transaction often time out by default way before an hour, so if you do MDB transactional by some reason, you might want to consider fire of that async ejb inside the onMessage.
Comment: thanks Petter. So generally, am I correct in thinking that firing an async bean from with the onMessage (of an mdb) will prevent the mdb from being blocked from the pool? This is what I want, but you are right, the async ejb itself will block a thread anyway, but at least there is a messaging interface to launch the jobs.                          --                                                                             one other thing, the mdb wont be transactional. Should I set a time out flag in the async ejb thats invoked from the mdb or the mdb in this case?
Answer: I think Petter answers most of the question. If you are only using mdb to get asynch behaviour, you could just fire the @Asynchronous asap.
But if you are interested in any of the other features your JMS implementation might offer in terms reliability, persistent queues, slow consumer policies, priority on jobs you should  stick to mdb:s
One of the reasons behind introducing @Asynchronous in ejb 3.1  is to provide a more lightweight way to do asynchronous processing when the other JMS/MDB features are not needed.
Comment: thanks Aksel. I was always under the impression that mdb being blocked for hours was a bad thing to do which is why I thought of the asynch ejb method invocation from within the mdb freeing it up straight away. Perhaps I'm incorrect here and can just let the mdb wait until the bulk load job is completed. Like you say I can make use of other mdb feature in this case.


Commerce: Show taxes on checkout

Question: I am having problems with a porjectr of mine. Seems the taxes are not showing up until AFTER the order is put through. Here is a screenshot of what I mean.
I would like to have taxes show up at the button right before total. Can anyone point me in the right direction? Thank you.
i.stack.imgur.com/3hMWC.png
Answer: Taxes are dependent on shipping address so adding a tax line item to the cart does not make sense. Try looking at one of the tax rules on /admin/config/workflow/rules/components to see how the tax line item is added to an order. By default, tax line item is added in the pane that comes after a customer has entered her shipping address and before payment is submitted. Adding a tax line item to a cart requires a custom line-item type and a shipping address to be provided for tax calculation.

Commerce: Show taxes on checkout


When do you have to apply continuity correction?

Question: I've solved the following problem.

An electronics firm receives, on the average, fifty orders per week for a particular silicon chip. If the company has sixty chips on hand, use the Central Limit Theorem to approximate the probability that they will be unable to fill all their orders for the upcoming week. Assume that weekly demands follow a Poisson distribution.

$
\mu = \lambda = 50; \sigma = \sqrt\lambda = 5\sqrt2; n = 1$
Therefore $$P(X>60) = 1 - P(X<60) = 1 - P(Z<\frac{60-50}{5\sqrt2}) = 1 - P(Z<\sqrt2) = 0.07927 $$
But if we apply continuity correction,
$$P(X>60) = 1 - P(Z < \frac{60.5-50}{5\sqrt2}) = 0.0694$$
So, when and why should I or should I not use continuity correction?
Answer: It's usually better to do the continuity correction when approximating an integer-valued distribution by a normal distribution, but it may not make any significant difference when the normal approximation is very accurate, which occurs for Poisson($\lambda$) for very large $\lambda$. This is just because $\Phi(x)$ and $\Phi(x+0.5/\sigma)$, where $\Phi$ is the standard normal CDF, are not really all that different when $\sigma$ is huge. In this problem $\sigma$ is just $\sqrt{50}$ which is not really all that big, so it makes a pretty significant difference.
With that being said, software can more directly evaluate the desired quantity without having to use a normal approximation at all. For example you can ask Matlab for poisscdf(60,50,'upper') which gives about 0.0722. You can see that this is somewhat closer to your continuity-corrected result than the other one.
Comment: Thanks for the explanation, it makes a lot of sense now. What I'm noticing is that rounding in these kind of problems leads to greater error than I would've thought


Adam (adaptive) optimizer(s) learning rate tuning

Question: I'm reading Hands-On Machine Learning with Scikit-Learn, Keras & Tensorflow and on page 325 (follows up on 326) there's a following piece of text on learning-rate:

The learning is arguably the most important parameter. In general, the
optimal learning rate is about half of the maximum learning rate (i.e.
the learning rate above which the training algorithm diverges, as we
saw in Chapter 4). One way to find a good learning rate is to train
the model for a few hundred iterations, starting with a very low
learning rate (e.g., 1e-5) and gradually increasing it up to a very
large value (e.g., 10). This is done by multiplying the learning rate
by a constant factor at each iteration (e.g., by exp(1e6/500) to go
from 1e-5 to 10 in 500 iterations). If you plot the loss as a function
of the learning rate (using log scale for a learning rate), you should
see it dropping at first. But after a while, the learning rate will be
too large, so the loss will shoot back up: the optimal learning rate
will be a bit lower than the point at which the loss starts to climb
(typically about 10 times lower than the turning point). You can then
reinitialize your model and train it normally using this good learning
rate. (...)

My question is: does it apply to any group of optimizers or to SGD in particular?
Answer: Adam is an adaptive algorithm, so it self-tunes during the training. In many cases you would get away with the default hyperparameters and they would not need tuning. As you can learn from this thread sometimes tuning the learning rate may lead to improvements, but also the range of known best values is smaller as compared to other algorithms. However it should usually not be your first concern. Also notice that for $\beta_1$ and $\beta_2$ hyperparameters the general advice is not to change the defaults, you should do it only when you have a good reason for that.
Answer: I've done some experimenting. I've used this tutorial, so objects like models or generators refer to the concepts from it and need to be implemented. I've tested for 4 models in total (linear, dense, conv and lstm), each with 2 optimizers (adam and SGD). Below is a screenshot from tensorboard that  all the combinations behaved in the same way.

Below is the code I've used.
<code>import math
import typing
from datetime import datetime
from itertools import product

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import ticker
from tensorflow import keras
from tensorflow.keras import callbacks, optimizers, losses

from tftst import models, window
from tftst.config import PLOTS_DIR, LOGS_DIR

START_LR = 1e-8
END_LR = 1e-1
STEP = 20
EPOCHS = int(math.log(END_LR / START_LR, 10)) * STEP + STEP

def adam() -> optimizers.Adam:
    return optimizers.Adam(START_LR)

def sgd() -> optimizers.SGD:
    return optimizers.SGD(START_LR, momentum=0.9)

def tune(m_producer: typing.Callable[[], keras.Model], o_producer: typing.Callable[[], optimizers.Optimizer], gen: window.WindowGenerator):
    model = m_producer()
    print(f'Tuning LR for model: {model.name}')

    optimizer = o_producer()
    optimizer_cls = type(optimizer).__name__

    current_time = datetime.now().strftime("%Y%m%d-%H%M%S")
    logs = LOGS_DIR / f'lr-tuning-{model.name}-{optimizer_cls}-{current_time}'

    model.compile(loss=losses.MeanSquaredError(), optimizer=optimizer)
    history = model.fit(gen.train, epochs=EPOCHS, callbacks=[
        callbacks.LearningRateScheduler(lambda epoch: START_LR * 10 ** (epoch / STEP)),
        callbacks.TensorBoard(str(logs), write_graph=False),
    ])

    plt.semilogx(history.history['lr'], history.history['loss'])
    plt.axis([START_LR, END_LR * 1e1, 0, 3])

    ax = plt.gca()
    x_major = matplotlib.ticker.LogLocator(base=10.0, numticks=5)
    ax.xaxis.set_major_locator(x_major)
    x_minor = matplotlib.ticker.LogLocator(base=10.0, subs=np.arange(1.0, 10.0) * 0.1, numticks=10)
    ax.xaxis.set_minor_locator(x_minor)
    ax.xaxis.set_minor_formatter(matplotlib.ticker.NullFormatter())

    img = PLOTS_DIR / f'{model.name}-{optimizer_cls}-lr-tuning.png'
    plt.savefig(img)

    plt.title(f'{model.name}-{optimizer_cls}')
    plt.show()

if __name__ == '__main__':
    print('Tuning started')
    print(f'Start LR: {START_LR}')
    print(f'End LR: {END_LR}')
    print(f'Epochs LR: {EPOCHS}')
    print(f'Step: {STEP}')

    ww = window.WIDE_WINDOW
    wcw = window.WIDE_CONV_WINDOW

    for opt, tup in product([sgd, adam],
                            zip(
                                [models.linear, models.dense, models.conv, models.lstm],
                                [ww, ww, wcw, ww]
                            )):
        mod = tup[0]
        win = tup[1]
        tune(mod, opt, win)
</code>


How to place after each 5th item in a view a different content type?

Question: I want to create a view with news which outputs another content type after every 5th result, in my case a newsletter subscription.
How can I do this?
Comment: This isn't doable from the Views UI. You'd need to create two result sets from a query, and in the main output, insert a row every 5th result. You'd also have to account for paging, etc.
Answer: Views paging isn't conditional, so you can't assign different filters and other settings to different sets of result items.
But you can achieve what you want by creating different Views displays, each with its own filter settings, then display them one below the other on a page, style the output so it looks like it's coming from the same source.
If you make the different displays to be Attachment types, you will be able to make them display before or after the display they're attached to, all through the Views interface. If your original display is of Page type it's the most convenient to make the other ones as Attachment types.
You could also create Blocks display types, but then you have to place each one individually in a region of your theme and order them the way you want.
Use Views Displays
Here are steps how to do it:

Edit your original view display to only show 5 items of only the one Content type you want to show up first.
Duplicate that display as an Attachment, then override the filter to show a different content type and set it to attach after the first display
Duplicate the Attachement and repeat the edit: override the filter to show the third content type and set it to attach after the first display
Repeat again if you have more content types
Use CSS to style the attachments without gaps in between them so they look like they are one unit in your design


Form Redirect not working if 'destination' is in URL

Question: In one of my forms, I'm trying to set a $form_state['redirect'] so the form will go to that destination after the user clicks one of the action buttons.
If I inspect $form_state['redirect'] both before and after I add the redirect, it is NULL before, and after contains the proper array. Here's how I'm setting up the redirect:
$form_state['redirect'] = array(
  'my/custom/path/' . $nid,
  array('query' => drupal_get_destination()),
);

I want to preserve the destination from the form that the user's viewing to the next path (that's why I'm calling drupal_get_destination(), which returns an array with 'destination' => 'some/path/here' inside.
It seems that, because there's already a destination in the path of the current form, the form redirects to that destination no matter what I put in my own form submit handler (see above code). I even tried using drupal_goto() and that didn't redirect the user either.
Answer: When a form is processed, the value of $form_state['redirect'] is sent to drupal_goto(), and drupal_goto() always favors $_GET['destination'] over its own $path parameter.
For the sake of completeness, in Drupal 6, you were somewhat out of luck without setting your own headers in hook_exit():
function mymodule_exit($destination = NULL) {
  $my_destination = 'foo/bar';
  header('Location: ' . url($my_destination));
  exit;
}

In Drupal 7, hook_drupal_goto_alter() was added for this specific use case:
function mymodule_drupal_goto_alter(&$path, &$options, &$http_response_code) {
  $path = 'foo/bar';
}

Another option for Drupal 7, which is closer to what you want to do, is to reset the static cache for drupal_get_destination()  in your submit handler using drupal_static_reset():
function mymodule_form_submit($form, &$form_state) {
  // See note
  $form_state['redirect'][] = drupal_get_destination();
  $form_state['redirect'][] = 'foo/bar';

  unset($_GET['destination']);
  drupal_static_reset('drupal_get_destination');
  drupal_get_destination();
}

Since you call drupal_get_destination() immediately after the reset, Drupal is blissfully unaware of the destination parameter for the rest of the page build, including when it calls drupal_goto().
Note: I changed the code for defining $form_state['redirect'] because you never want to overwrite the variable: other submit handlers might've defined their own redirects. Drupal will always use the last item in the array, so if you want foo/bar to override the destination parameter (and every other redirect defined up to that point), it needs to be last.
Comment: Perfect, and very good explanation. I actually found a little more by working through the flow of a processed form - drupal_goto() is ultimately the reason my simple 'redirect' wasn't working. I needed to overwrite $_GET['destination'] too.
Answer: Thanks for this, but for some reason this didn't work when I tried it.  I got a fatal error -- the data sent in the example answer above doesn't satisfy the requirements of drupal_goto()
It may be because this answer is rather old, but I was able to get it work with this instead:
function mymodule_form_submit($form, &$form_state) {

  $form_state['redirect'] = array(
    'foo/bar', array(
      'query' => drupal_get_destination()
    )
  );

  unset($_GET['destination']);
  drupal_static_reset('drupal_get_destination');
  drupal_get_destination();

}

I know this violates this note:

you never want to overwrite the variable: other submit handlers
  might've defined their own redirects.

But, in this case, you do definitely want to overwrite the variable.  You wouldn't be setting this value unless you wanted to disregard other module's set values.  Also, I think you have to because of the way drupal_goto() works with the query parameter.  This may also be why the original answer was throwing fatal errors on my site.
Comment: This answer helped me realize that in some circumstances, you may want to completely override the `$form_state['redirect']`, or you may get a WSOD with competing redirects.
Answer: set form #action
global $base_path;
$form['#action'] = $base_path . '/node/'.$form_state['node']->nid.'/mytab';

Comment: This doesn't issue a redirect as OP asked, but submits the form to a different path.
Comment: -1 I think calling `drupal_goto()` in `hook_node_insert()` will screw things up (because `drupal_goto()` calls `drupal_exit()` preventing the new node from being saved).
Comment: true - in a node_insert hook .. (edited the answer)


How many factors does 6N have?

Question: Given a number $2N$ having 28 factors another number $3N$ having 30 factors, then find out the number of factors of $6N$.
Comment: Hello ! Are you sure this is a question related to the *Mathematica* system and not to mathematics as general ?
Answer: Let $p_i$, be primes in increasing order. Consider the prime factorization of $n$.
$$ n = 2^{a_1} \times 3^{a_2} \times \prod p_i^{a_i}, $$
where $a_i$ are non-negative integers. For this question, let the indexing run over $i\geq 3$.
You are given that
$$ (a_1 + 2) \times (a_2 +1 ) \times \prod (a_i + 1) = 28 $$
and
$$( a_1  + 1) \times (a_2 + 2) \times \prod(a_i + 1) = 30 $$
The factors of 28 are $1, 2, 4, 7, 14, 28$. The factors of 30 are $1, 2, 3, 5, 6, 10, 15, 30$.
A quick check shows that the possible values of $a_1$ are 2 or 5.
If $a_1 = 2$, then we must have
$$ \frac{ a_2 +1 } { a_2 + 2} = \frac{7}{10},$$
which has no positive integer solution.
If $a_1 = 5$, then we must have
$$\frac{a_2 + 1} { a_2 + 2} = \frac{4}{5}, $$
which has a positive integer solution $a_2 = 3$. This implies that $\prod (a_i+1) = 1$. Hence, the number of factors of $6n$ is
$$( a_1  + 2) \times (a_2 + 2) \times \prod(a_i + 1) = 7 \times 5 \times 1 = 35 $$
In this case, $n = 2^5 \times 3^3$.
Comment: You are welcome.
Answer: If you multiply a number $n$ by any prime number, then its number of divisors is multiplied by $\frac{m+1}m$ where $p^{m-1}$ is the highest power of $p$ dividing$~n$. This is because the multiplicity of $p$ in divisors of $n$ can be any one of the $m$ values $0,1,\ldots,m-1$, but that multiplicity can be chosen among the $m+1$ values $0,1,\ldots,m$ for divisors of $pn$ (for prime numbers other than $p$, the same set of multiplicities is available in both cases).
So in the problem here let $k$ be the number of divisors of $n$ without factors $2$ or $3$, and $a-1,b-1$ the multiplicities of the primes $2$ and $3$ in$~n$, respectively. So $k,a,b$ are positive integers and $n$ has $kab$ divisors in all. We are given that $28=k(a+1)b$ and $30=ka(b+1)$, which implies that $\frac{28}{30}=\frac{14}{15}=\frac{(a+1)b}{a(b+1)}$. The factor $7$ in the numerator cannot come from $b$ (given that $b+1$ divides $~30$ and that $\frac{a+1}a\neq1$), so it must come from the factor $a+1$. Since $a$ divides $30$, the only possibility is $a=6$, which indeed gives a solution namely $(k,a,b)=(1,6,4)$. So we find $n=k2^{a-1}3^{b-1}=2^53^3$, and $6n=2^63^4$ has $k(a+1)(b+1)=35$ divisors.
Answer: If $2n$ has 28 divisors, then $2n$ is of the form $a^6.b$, where b has 4 divisors.  Note that if chose $2^13$ or $2^26$ here, then the third multiple would have more than $30$ divisors, since it would be $3*13* or $2*27$ divisors required.
Since $3n$ does not have a divisor of the form $a^6$, we see that  $a=2$, and that n is at least $2^5$.  The reminder takes $b$ has $4$ divisors, and 3b has $5$, so $ b=3^3$. So the number is $864$, which has $6*4=24$ divisors, its second and third have $28$ and $30$ divisors.
Likewise $6n$ has 7*5 or $35$ divisors.  It is the $5184$.
One can also see that if $6n=2^a 3^b c$, then for $2n$ to have 28 divisors, and $3n$ to have 30 divisors, then $7|a-1$ and $5|b-1$.  This, and that $ab+b=28$ and $ab+a=30$, means that $a-b=2$, then $a=6, b=4$ is the only solution here.
Comment: -1 Why must $2n$ be of the form $a^6 \times b$ (presumably with $\gcd(a,b)=1)$? The number $2^{27}$ has 28 divisors and doesn't fit your format.
Comment: Because $3$ must divide it. to get $ab+a=28$, and $ab+b=30$, then $b-a$ cant be 2 if $b$ is greater than 10.
Comment: @CalvinLin Because neither $27$ or $13$ divide $30$, which is the second condition.  Only $6$ does.
Comment: Why can't it be $2^{13} \times 3$ then? You simply swept a lot of cases away without explaining what is happening, and why they are rejected.
Comment: @CalvinLin Because 13 does not divide 30, and we know that $3n$ has 30 divisors.
Comment: Precisely. My point is that "then 2n is of the form $a^6 \cdot b$" does not follow immediately form just "If 2n has 28 divisors". You need to use the other conditions too.

How many factors does 6N have?


How to add a extra products fields on ubercart check out pane table?

Question: Hi im looking to add some extra fields on the check out pane, i mean fields from the product like some attributes, theres any possibility?
Please if someone how to do this let me know!
Thank's to everyone who can help me!
Answer: You can go for Ubercart Webform Integration
<code>This module integrates two other modules: webform and ubercart. It allows you sell
products directly from your webforms. It is particularly suited to be used as part of a
registration system.
</code>


Combining categorical and continuous features for neural networks

Question: Is it OK to combine categorical and continuous features into the same vector for training deep neural networks? Say there is a categorical feature and continuous feature that I want to feed into a deep neural net at the same time. Is this the way to do it?
<code>categorical feature (one-hot encoded) = [0,0,0,1,0]
continuous feature (number) = 8
final feature vector passed into neural network = categorical feature vector CONCATENATE continuous feature = [0,0,0,1,0,8]
</code>
Basically, the question is, is it OK to have a one-hot encoding and a continuous feature together in one feature vector?
Comment: See also: https://stats.stackexchange.com/questions/306610/neural-network-mlp-for-regression-with-3-continuous-features-1-categorical
Comment: See also: https://stats.stackexchange.com/questions/139129/how-to-recode-categorical-variable-into-numerical-variable-when-using-svm-or-neu
Answer: Yes, that is one typical way of doing it. But, you need to standardize your features so that gradient descent doesn't suffer, and the regularization treats your weights equally. One way is to standardize the numerical features and then concatenate the one-hot vectors, and the other way is standardizing together. As far as I see, there is no consensus over the two.
Answer: Yes, this is absolutely standard.


What is the difference between intervention and conditional distribution?

Question: Suppose that the distribution $P_{C,E}$ is entailed by a structural causal model $\ell$
$C := N_C$
$E := 4C + N_E.$
Given than $N_C$ and $N_E$ are iid $\mathcal{N}(0,1)$ and the graph $C\to E.$ Then:
$P_E^{do(C:=2)} = \mathcal{N}(8,1) = P_{E|C=2}$
$P_C^{do(E:=2)} = \mathcal{N}(0,1) \ne P_{C|E=2}.$
My focus is in the second intervention $P_C^{do(E:=2)}.$ The conditional distribution of $C$ given $E=2$ is different from the distribution of $C$ after intervening and setting $E$ to $2.$ But how so? I fail to see why. $C$ is not a function of $E.$
Source:
Elements of Causal Inference (3.2 page 34). Jonas Peters, Dominik Janzing and Bernhard Scholkopf.
R Code Snipped:
<code>C <- rnorm(300)
E <- 4*C + rnorm(300)
c(mean(E), var(E))
# [1] 0.1236532 16.1386767

# do(C:=2);
C <- rep(2,300)
E <- 4*C + rnorm(300)
c(mean(E), var(E))
# [1] 7.936917 1.187035
</code>
Answer: It is true that $C$ is not a function of $E;$ moreover, as the causal diagram $C\to E$ clearly says, we are thinking of $C$ as a cause of $E.$ However, in a causal diagram, you can use the $\newcommand{\doop}{\operatorname{do}} \doop$ operator on any variable you like; doing so deletes all arrows going into that node. This is "graphical surgery", so to speak. If we are intervening on $E,$ we must delete all arrows going into $E,$ except from the exogenous variables $N_C,N_E,$ etc.; this produces the graph $C\; E,$ with no arrows at all. We simultaneously modify the structural equations so as to set $E=2.$ That is, the structural equations become
\begin{align*}
C&=N_C\\
E&=2.
\end{align*}
Hence, $C$ is distributed according to $N_C$ when we intervene on $E.$ So much for $P(C|\doop(E)).$
What about $P(C|E)?$ This is going to be a similar calculation as before, except that we don't do graph surgery. Graph surgery equals intervention equals the $\doop$ operator. The only relationship we have between $C$ and $E$ is the equation $E=4C+N_E.$ When doing mere conditionals (without the $\doop$ operator), it is perfectly permissible to use any of the structural model equations. But they will not be modified this time, because we're not intervening. Hence, you get
\begin{align*}
2&=4C+N_E\\
\frac{2-N_E}{4}&=C\\
\frac12-\frac{N_E}{4}&=C.
\end{align*}
In summary: the $\doop$ operator forces graph surgery and structural equation model alteration. Regular conditional probabilities do not.
Comment: Interesting! Thanks. I plugged your Pc|e derivation to r and got a N(0.5,0.06). Indeed different than N(0,1)


What is the angle between the direction of $A$ and the positive direction of x?

Question:
The x component of vector $A$ is 25.0 m and the y component is 40.0 m. (a) What is the magnitude of $A$? (b) What is the angle between the direction of $A$ and the positive direction of x?

I solved (a). When attempting (b) I tried using the formula $\tan\theta=\frac{a_y}{a_x}=\frac{40}{-25}=-1.6$, thus $arctan(-1.6)=-58º$ but the answer key is $122º$.
Any help is appreciated.
Answer: It appears that you might mean for the point to be (-25,40) although you stated (25,40). The atan2(y,x) function using (-25,40) will yield ~122 deg.


dmitri shostakovich vs Dimitri Schostakowitch vs Shostakovitch

Question: I have inherited a lot of... I will be honest I am not sure what to call them. Would they be called classical, symphony?
I came across a collection of Dmitri Shostakovich or Dimitri Schostakowitch or just Shostakovitch, A google search will show me the same person,  I am curious which is right or are they the same people and why the different spelling of the First and Last Name?
Please see attached pic of all 3 Albums
Comment: I'm voting to close this question because this describes a language-transliteration issue, the only relation to music being that here the name of a composer is affected. *Music Fans* might be more appropriate for that reason, but possibly some more language-related board exists.
Comment: Unbelievable no. of visits to a seemingly (to me) trivial question, with pretty obvious answers. Hardly a musical theory/practice related one though. vtc.
Comment: Hah.  I once (yeah I'm old) was searching "Tchaikovsky" in a library card catalog.  Rather a lot of different spellings.
Comment: @guidot Actually, I'm torn toward regarding this as on-topic under "music history." The minute discussion in the comments is certainly not what we're here for, but the core question is common and reasonable enough that this could be helpful.
Answer: The right spelling is Дмитрий Дмитриевич Шостакович. Or Дмитрий Шостакович if omitting the patronymic.
He was Russian.
Transliteration of his name into the Latin alphabet varies:
Dmitri Dmitriyevich Shostakovich (English transliteration),
Dmitri Dmitrijewitsch Schostakowitsch (German transliteration),
Dmitri Dmitrievitch Chostakovitch (French transliteration),
Dmitrij Dmitrievič Šostakovič (scientific transliteration),
and so on.
Adding: To copy (and edit) this from my comment below before an admin comes and deletes them all, Dimitri is a cognate of Dmitrij. (Cognate: a variant of a word evolved from the same older form, usually in a different language.) Replacing people's names with their cognates more familiar to the audience used to be common practice, for example you've probably heard of the writer Leo Tolstoy, whose name was actually Lev (Лев), or you might have come across another composer named as Peter Ilyich Tchaikovsky, rather than directly transliterated Pyotr (Пётр). Nowadays this practice is on its way out and people's names are more often given in their original foreign form.
Comment: **Comments have been [moved to chat](https://chat.stackexchange.com/rooms/147389/discussion-on-answer-by-divizna-dmitri-shostakovich-vs-dimitri-schostakowitch-vs); please do not continue the discussion here.** Before posting a comment below this one, please review the [purposes of comments](/help/privileges/comment). Comments that do not request clarification or suggest improvements usually belong as an [answer](/help/how-to-answer), on [meta], or in [chat]. Comments continuing discussion may be removed.
Answer: To add to the other answer, re. Dmitriy vs Dimitriy. The name was originally Dimitriy, from the Greek Demetrius. In modern Russian, it's contacted to Dmitriy, but in more conservative settings, e.g. church, it's still Dimitriy and the diminutive forms, Dimich, Dima or Dimka, still retain the first i. There's a comprehensive entry on the Russian Wikipedia: https://ru.m.wikipedia.org/wiki/%D0%94%D0%BC%D0%B8%D1%82%D1%80%D0%B8%D0%B9 auto translate works well. The older form was more popular when Shostakovich become famous, he was most likely published under it in the West.
Comment: @Eugene Just so we're on the same page about which time period we're talking about, at the time of the revolution Šostakovič was 11 years old. His active career years span from 1920s to 1970s. What's more, the article you link says nothing of the sort you claim - it just notes that the name Dimitrij is used specifically in the context of the orthodox church, gives the old Russian form of the name as Dmitr (Дъмитръ), and lists a number of Russian orthodox church holidays. At the end there's a list of surnames derived from the name.
Comment: Very interesting — can you link any source to confirm or illustrate this? All modern Russian editions I've seen of his work use Дмитрий, [his Russian Wikipedia article](https://ru.m.wikipedia.org/wiki/Шостакович,_Дмитрий_Дмитриевич) only uses the modern spelling as far as I can see, and I can't find early Russian facsimile sources to check (my Russian google-fu isn't up to much). Unfortunately the few scores of his that are on IMSLP have his name Romanised, or else are surname-only.
Comment: @PPL I've added an article to the Russian wiki about the name itself. As to Shostakovich himself, I don't know any direct sources, but pronouncing Dimitriy is one of the tropes I've often seen in movies/shows about pre revolutionary Russia, to show the characters are "old times" and it's the right time period, so....
Comment: In [another article](https://ru.wikipedia.org/wiki/Дмитрий_(значения)) linked from there that lists notable historical bearers of the name Dimitrij or Dmitrij, Byzantine political figures are all listed as Dimitrij; Russian princes are all listed as Dmitrij, ever since the 13th century; saints are listed as Dimitrij again; orthodox bishops and patriarchs (for whom it's not their birth name but assumed) are all listed as Dimitrij as well; and anyone else is missing altogether.
Comment: @Divizna that's just modern convention. E.g. we know that Duke Dmitriy Donskoy was spelled Dimitriy historically, e.g. here, from a 17th century history book: https://en.m.wikipedia.org/wiki/Dmitry_Donskoy#/media/File%3ADmitri_Donskoy.jpg, but since he's also a saint, he will be Dmitriy in a textbook and Dimitriy in a religious book. Similarly if a Dmitriy dies tomorrow, at the funeral, he will be Dmitriy.


How to return to Root View Controller

Question: I am currently working on an app which presents a screen modally and another custom progress indicator modally. Is it possible to return to the root View Controller seamlessly?
Home -> screen1-> screen2(Custom progressIndicator)
I want to dismiss the custom progressIndicator (and the screen presented modally) and return to my home (root) View Controller in one go.
 self.navigationController?.popToRootViewControllerAnimated(true)

Thank you for the help!
Answer: You need to dismiss presented model then you can pop all the pushed view controllers. As presented model would not be in the stack of the navigation.
self.dismissViewControllerAnimated(true, completion: {});

Then you can pop to base view controller.
self.navigationController.popViewControllerAnimated(true);

Answer: If you use presentViewController, you can use
[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];

to go back to root view. It works on IOS9.
Answer: Swift 4
self.dismiss(animated: true, completion: {});
self.navigationController?.popViewController(animated: true);

Answer: In Swift 3 this will work:
self.dismiss(animated: true, completion: {});
self.navigationController?.popViewController(animated: true);

How to return to Root View Controller


How to keep persistent data in a function?

Question: I have a function that receives a number from 1 to 999. I want to know if this number has changed since the last time the function was called.
For example, if I called it in this order, its expected behaviour would be:

hasUpdated(1) // output false
hasUpdated (2) // output true
hasUpdated(1) // output true (because I've switched to 2 before, so
the number has been updated).

I wrote the following closure function:

const hasUpdated = (data) => {
  let updated = false;
  function checkIfUpdated (data){
    if(updated){
      return true
    }
    if(!updated && data > 1){
      updated= true
      return true
    }
    if (!updated && data === 1) {
      return false
    }
  }
  checkIfUpdated(data)
}

Its result is:

hasUpdated(1)  // output false
hasUpdated (2) // output true
hasUpdated(1) // output false

So there it doesn't doesn't properly save the value. How to fix it?
Answer: You're creating a new closure and a new updated variable every time you call hasUpdated. What you need to do for keeping a persistent variable is create the closure only once. Also you will need to keep the data of the last call to compare to, not just an updated flag.
function makeUpdateTest(initialValue) {
  let oldData = initialValue;
  return (newData) => {
    const updated = newData !== oldData;
    oldData = newData;
    return updated;
  };
}

const hasUpdated = makeUpdateTest(1);
console.log(hasUpdated(1)) // false
console.log(hasUpdated(2)) // true
console.log(hasUpdated(2)) // false
console.log(hasUpdated(1)) // true

A hasUpdated2 = makeUpdateTest() would keep a separate state.


Procmail and PHP script

Question: I am using postfix and procmail. But I have a problem with procmail and php.
The php-code /home/www/cron/mail_visirun.php run without any problem, but if /home/www/cron/mail_selva.php shoud be run on the logfile comes an error message:
My procmail file:
My php file /home/www/cron/mail_selva.php:
LOGFILE=/var/log/procmailrc.log
VERBOSE=yes
ATTACHinvoice=`echo /home/dok/dispo/RGein`
ATTACHselva=`echo /home/dok/dispo/Selva`
:0
* ^From:.*visirun
| /usr/bin/php /home/www/cron/mail_visirun.php

:0c
* ^email@example.com
! firstname.lastname@example.com

:0
* ^email@example.com
| munpack -q -C $ATTACHinvoice

:0c
* ^From:.*selva
! firstname.lastname@example.com

:0c
* ^From:.*selva
| munpack -q -C $ATTACHselva

:0
* ^From:.*selva
| /usr/bin/php /home/www/cron/mail_selva.php

:0
* ^email@example.com
| /usr/bin/php /home/www/cron/mail_selva.php

:0 w
! firstname.lastname@example.com

The php file /home/www/cron/mail_selva.php:
<?php
echo "OK";
?>

My logile:
procmail: Executing "/usr/bin/php,/home/www/cron/mail_selva.php"
procmail: Error while writing to "/usr/bin/php"
procmail: Assigning "LASTFOLDER=/usr/bin/php /home/www/cron/mail_selva.php"

I can not understand why one script run and another script give an error.
Comment: Well, are the scripts different? If so, then that's why one runs and the other gives an error.
Answer: The error is that your PHP script fails to read its standard input.  Procmail detects this, and regards the delivery as unsuccessful.
If the plan is for the script to do something useful with its standard input, just do that, and the error will go away.
If not, maybe explain in more detail (probably in a new question by now) what your script does and what you hope should happen when Procmail pipes the current message into it.

Stylistic remarks:

You want to get rid of the crazy Useless Use of echo in backticks.   Change variable=`echo value` to variable='value' (possibly without the quotes, if the value does not require quoting).
The w flag on the final recipe is weird.  I'm not sure what you could expect that to do.  What is your intention?
The repeated conditions are not an error, but slightly problematic.  I would refactor so that you only have one regex to update if you ever should need to.

:0
* ^From:.*selva
{
  :0c
  ! firstname.lastname@example.com

  :0c
  | munpack -q -C $ATTACHselva

  :0
  | /usr/bin/php /home/www/cron/mail_selva.php
}

Then you're still stuck with the  ^email@example.com with an identical delivery action.  Maybe things could still be refactored.

Procmail and PHP script


How to write "$X$ is the set of all positive integers greater than or equal to $10$" with mathematical notations?

Question:
How to write "$X$ is the set of all positive integers greater than or equal to $10$" with mathematical notations?

I was thinking $X=\{n:n\ge10\in\mathbb Z^+\}$, but I'm not too sure if this is correct. What is the right way of writing this?
I also remember a notation like $\mathbb Z_{\ge10}$ but I'm not sure if that's right either.
Comment: I would write this as $X=\{n\in\mathbb Z_{++}\,|\,n\geq10\}$. I write $\mathbb Z_{++}$ instead of $\mathbb Z_+$ to emphasize that $0$ is excluded from the definition of "positive integers."
Answer: \begin{align}
X &= \{n : \textrm{$n$ is a positive integer greater than or equal to $10$}\} \tag{1}  \\
&= \{n : n \in \mathbb Z^+ \textrm{ and } n \geq 10\}  \tag{2} \\
&= \{n \in \mathbb Z^+ : n \geq 10\} \tag{3} \\
&= \{10,11,12,\dots\} \tag{4}
\end{align}
$(1):$ Yes, you can use words.
$(2):$ This is the most correct.
$(3):$ The standard notation for the latter.
$(4):$ This is well understood, although it is a bit vague.
Comment: Wait is it $X=\{n\in\mathbb Z^+:n\ge10\}$ or $\{n\in\mathbb Z^+|n\ge10\}$? or does it not matter?
Comment: Doesn't matter. I like to use dots instead of a bar.


How to use checkbox under description of any webform field?

Question: I am using webform module where I have a text field named Mobile Phone Number.
I wanted to use checkbox under the text field as shown below:

The content can be written in the description of that text field. But how do I use the checkbox as I shown above.
Note: I tried to enter the html form tags in the description but didn't help.
Answer: You will create a check box component fields below mobile phone number fields after "yes|I am providing my express..." in OPTIONS .
   Create Check box -> Options -> "yes|I am providing my express..."

and align with CSS code
Comment: Where is options box in webform's text field?
Comment: rewrite my answer now please check
Comment: This is available with the webform's select field not with the textfield. I want it in the textfield's desciption so that it will be available just under my text box. If you mean using a separate checkbox then align it with css code then it might work but not a good idea.
Answer: use hook_form_alter hook to alter the form (in template.php):
<code>function MY_THEME_form_alter(&$form, &$form_state, $form_id)
{
  if($form_id == 'MY_WEBFORM_FORM_ID' /* you can find formid with dpm function from Devel module or you can also use PHP's debugging functions, e.g. dpm($form_id) */) {
    $form['my_checkbox'] = array(
      '#type' => 'checkbox',
      '#title' => 'Your Long Description',
      '#weight' => 50, /* this value must be something like `phone number field's weight + 1` */
      ...
    );
  }
}
</code>
and flush the cache..
Comment: Is there any other easy way to do this without using hook_form_alter since this is just for one particular case.
Comment: @NewDrupalUser Altering th form not such a bad way, even this is a single case. In other hand, by hooking into the form you can get other advantages such as adding custom submit handler, validation handler and so on.. (likely you will need them..)
Answer: I created a select field form component with label name as 'agree' and tick marked multiple so that checkbox will appear and provided a single key|value pair as shown below.

Keep this select component under the mobile phone number component. It will appear exactly next to mobile phone number component then just hide the label, make proper alignments using css.


DNS grey listing and long retry intervals - standard practices?

Question: My company's ISP has implemented what I'll term DNS "grey listing" (or they have a configuration problem) - they are blocking inbound DNS queries between [resolver IP, server IP] pairs that haven't attempted a query in the last 60 seconds. So the if the first query fails, further queries succeed so long as less than 60 seconds have passed since the previous attempt. I assume this is to hide hosts from scans, under the assumption that a legitimate resolver will retry the query. They may even be blocking all UDP packets to combat port scans, but I haven't found a way to test this yet.
It turns out that Cisco IronPort devices generally have a retry interval longer than 60 seconds. (15 seconds to try each secondary DNS server, then 60 seconds before retrying the primary) My company can't receive email from most organizations with IronPort devices.
My feeling is that at least one of these behaviors is just wrong. So my questions are:
1) What are the recommended retry intervals for DNS resolvers? Can you reference an RFC or other source, or is it a de facto industry standard?
2) Is DNS or UDP "grey listing" a standard practice? References?
EDIT - Some additional background details:
Both of my company's DNS servers are affected, as is our ISP's primary nameserver. Their secondary nameservers, which actually reside outside their network, and nameservers upstream from any affected hosts are not affected. We also have a second ISP, and DNS queries that come in through that route are not blocked. Packet traces on our external firewall shows that we answer all DNS queries received - the dropped queries aren't delivered to our networks. My main goal in asking this question is to have a standards document to show our ISP (or less likely, Cisco) that their behavior is broken and needs to be fixed.
Comment: I haven't found any standards on these, but I did find someone trying to do UDP grey listing: http://serverfault.com/questions/644869/how-to-drop-first-udp-packet-from-a-source-with-iptables
Looks like serverfault users are against this practice
Comment: Is this device in line with the ISP's recursive/caching DNS servers, their authoritative servers (ones that host domains for their customers), or both? This isn't really specified.
Comment: @AndrewB My company's servers and our ISP's servers are authoritative for their respective domains. I'm not sure which device you're referring to? The IronPort devices are outside these networks.
Answer: DNS servers fall into a few different groups:

Authoritative server
Public recursor
Non-public recursor

In none of those cases will it make any sense to try to hide their existence. The authoritative DNS servers have to be publicly reachable in order to do the task they were set up for in the first place. A public recursor is pointless if you try to hide its existence. And if you run a recursor which is not supposed to be public, then instead of trying to hide it, simply block requests to it from an unauthorized client IP.
From your question it sounds like the DNS server you are asking about is authoritative for your zone. So I assume it is an authoritative DNS server.
Both authoritative DNS servers and public recursors receive queries from arbitrary client IP addresses, and that means they could potentially be used in amplification attacks.
Unfortunately the DNS protocol offers no good protection against such attacks. The behavior you describe might be a very poor attempt at protecting against such attacks.
There are ways in which a DNS server can protect against amplification attacks without as much of an impact as what you describe.

Don't apply countermeasures when no attack is happening. Instead look for the ICMP error responses that an attack would cause, and apply countermeasures when a possible attack has been detected.
Don't drop requests, instead send a reply with no answer section and set the truncated bit. This will cause any proper DNS client to retry using TCP.
Since TCP is more resistant to spoofing, replies can be send without worrying about amplification attacks.
Remember IP addresses which successfully queried over TCP. Those can be allowed to query over UDP in the future.

What I describe here is not some official best practices, it is to the best of my knowledge the best you can do to protect against amplification attacks with the DNS protocol as it looks today. I am not aware of any actual implementation of this approach.
Comment: I'm leaning towards the idea that this is actually a UDP policy to combat port scanning, rather than being specific to DNS. However I can't think of another UDP port that generates a response that is likely to be open.
Comment: @adipy If the goal is to slow down port scans, then a rate limit on ICMP errors would be sufficient. Moreover since packets to open ports don't generate ICMP errors, they won't be negatively impacted by such a rate limit.
Comment: That would be better - I should have said I suspect it's a _misguided_ UDP policy. But at this point I'm taking shots in the dark. We have a service request open with the ISP now, I'll know soon enough what they're doing.


GMM EM algorithm complexity per iteration

Question: I was fitting GMM clusters with diagonal covariance on my data using EM with $n$ (=5e6) points, each having $m$ (=160) dimensions. I wanted to get around $k$ (=400) clusters. But this is taking a lot of time.
My question are:

What is the per iteration complexity of GMM EM given $n$, $m$ and $k$?
Which parameters might help me the most in reducing the runtime most while giving useful clusters?
Also what is the suggested number of iterations required for EM to converge given this metadata? I'm currently working iterating 100 times.
How is this affected by going from diagonal covariance to other covariances(tied covariance or full covariance)?
Answer: Over a year after this was asked, but for anyone in a similar situation my suggestion would be to use Principal Component Analysis (PCA) to reduce the number of dimensions without sacrificing too much variance.  This should make your clustering less computationally intensive.
Answer: I think it is cubic in the number of dimensions - because there is a matrix inversion step while computing the E-step. Specifically, while calculating the density of each point $(x-\hat\mu)^T\hat{\Sigma}^{-1}(x-\hat\mu)$, we need to invert the covariance matrix. In general, it is $O(m^3)$.
It is linear in the number of components and number of datapoints - I agree with the justifications given in the other answers.
A general rule of thumb is that we do not look for a large number of clusters. This is because the intended purpose of clustering is to 'summarize' the data. Moreover, there are no right or wrong clusters - just that the clusters have meaningful interpretations or not - e.g. 'points in cluster 1 predominately have characteristic A while points in cluster 2 have predominately characteristic B'. So, while you may look for $k = 400$ number of clusters, it is important to check if you can meaningfully interpret them.
I have run GMM EM algorithm using Python's sklearn on data with $n = 1e6$ datapoints, $m = 200$ dimensions and $k=5$ clusters in less than 3 minutes. I believe reducing $k$ may help your cause of reducing the runtime in this specific case.
Comment: I see your point but it's not so relevant in my opinion because you invert the matrix once only.
Answer:
answer: quadratically with $m$ (nb. dimensions), linearly with $n$ (nb. points) and linearly with $k$

One can see this easily in the fact that the main computation happens in the calculus of
$$\Sigma_{c} = \sum_{i=1}^n (x_i-\mu_c)(x_i-\mu_c)'.$$

Adding one more point gives one more iteration of the sum (linear).
Adding one more dimension makes the matrix $\Sigma$ increase in size, so $O(m)$ more terms to compute.

Finally I would say linearly with $k$ (nb. of clusters) "because you compute one more matrix and vector per additional cluster" (although this was not explicit in my course).
Note that if you specify the covariance to be diagonal or spherical.


Unable to push docker image into GCP container registry [permission error]

Question: I am trying to push a docker image into my container registry on google cloud platform. I am able to build my image successfully on my local machine. I tried the following command:
sudo docker push eu.gcr.io/$PROJECT_ID/$CONTAINER_NAME
I get a permission denied error:

unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication

I tried following the steps in the provided link, specifically the gcloud credential helper instructions. I also tried gcloud auth configure-docker and gcloud auth login, all to no avail. Regarding IAM permissions my personal email is listed as Owner and Storage Admin role. I also have manually set up a service account with Owner and Storage admin roles. My $GOOGLE_APPLICATION_CREDENTIALS environment variable points to a json file extracted from this manually created service account. gcloud auth configure-docker provides the following output:
WARNING: Your config file at [/home/awa5114/.docker/config.json] contains these credential helper entries:

{
  "credHelpers": {
    "gcr.io": "gcloud",
    "us.gcr.io": "gcloud",
    "eu.gcr.io": "gcloud",
    "asia.gcr.io": "gcloud",
    "staging-k8s.gcr.io": "gcloud",
    "marketplace.gcr.io": "gcloud"
  }
}
Adding credentials for all GCR repositories.
WARNING: A long list of credential helpers may cause delays running 'docker build'. We recommend passing the registry name to configure only the registry you are using.
gcloud credential helpers already registered correctly.

At this point, I really don't understand why I am getting denied permission to push this image into the container registry. Any help would be most welcome. Thanks very much.
Answer: It is likely that your account doesn't have permission to store/write the docker image in GCR. The GCR in GCP is backed by a Google cloud storage bucket and your account needs a write permission on the bucket.
For eu.gcr.io, the equivalent bucket is gs://eu.artifacts.$PROJECT_ID.appspot.com.
Try to grant your account, a roles/storage.objectAdmin role at the bucket level. Of course, you can do this at the project or org level as well.
You can find details - https://cloud.google.com/container-registry/docs/access-control#permissions


What's the difference between convolutional neural network and convolutional auto encoders?

Question: What's the difference between convolutional neural network and convolutional auto-encoders?
This paper explains both but I find it hard to pinpoint the difference: http://people.idsia.ch/~juergen/icann2011stack.pdf
Many thanks!
Answer: A convolutional autoencoder is a type of convolutional neural network. However people probably refer to convolutional neural networks as supervised convolutional neural networks, i.e. with a softmax classifier or a SVM classifier on top while a convolutional autoencoder is an unsupervised network, so it tries to reconstruct the input using learned features and might have an $L2$ error loss like $\|f(x) - x \|_2$ where $f(x)$ is the network output and $x$ is the input image. The term autoencoder is used to represent the fact that we are trying to reconstruct the input, and thus requires no labels.
We design the conv autoencoder so that it does not simply learn the identity function (as in simply returning the input image without really producing any meaningful intermediate feature representation), for example sometimes by producing intermediate representations of a reduced dimensionality, among others methods.
Comment: In summary, convNets (supervised, used for classification, and the output is what we are looking for) convAutoEncoders (unsupervised, used for encoding, and the intermediate representation is what we are looking for). Does this sound as a fair summary?
Answer: Auto-encoders are models that learn the non-trivial identity function. What it means is that they try to learn a manifold on which the data lies on and can be used to generate the samples from the learned manifold. Convolution auto-encoders carry the same features except the fact that convolutional layers are present in the model.


Bind de tipo complexo com AngularJS

Question: Estou estudando AngularJS e Asp.net MVC e não consegui fazer bind de uma propriedade CPF da classe Pessoa quando realizo um POST:
Classe Pessoa:
public class Pessoa
{
   protected PessoaFisica() { }

   public Int32 PessoaFisicaID{ get; set; }
   public String Nome { get; set; }
   public Cpf CPF { get; set; }
   ...

}

Classe CPF:
public partial class Cpf
{
        protected Cpf() { }
        public Int64 Numero { get; private set; }
        ...
}

Controller AngularJS:
...
vm.salvar = function () {

            var pessoaFisica = new Object();
            pessoaFisica.PessoaFisicaID = vm.PessoaFisicaID;
            pessoaFisica.Nome = vm.Nome;

            //Bind do CPF com problema :-(

            //Tentativa 1:
            //pessoaFisica.CPF = new Object();
            //pessoaFisica.CPF.Numero = vm.CPF;

            //Tentativa 2:
            pessoaFisica.CPF = vm.CPF;

            //Uso o $http.post()
            ajaxService
                    .ajaxPost(
                        pessoaFisica,
                        '/Home/Criar',
                        this.salvarPessoaFisicaOnSuccess,
                        this.salvarPessoaFisicaOnError
                    );
        }
        ...

Minha Tela:

Na primeira tentativa usei o código abaixo, mas não funcionou:
//Tentativa 1:
pessoaFisica.CPF = new Object();
pessoaFisica.CPF.Numero = vm.CPF;

Erro: System.MissingMethodException: Nenhum construtor sem parâmetros foi definido para este objeto.

Na segunda tentativa usei o código abaixo e também não funcionou:
//Tentativa 2:
pessoaFisica.CPF = vm.CPF;

Chega nulo no controller do Asp.net MVC:

O que eu poderia estar ajustando para conseguir fazer o bind do CPF informado?
Comment: Tentou tirar o `private` do `set` da propriedade `Numero` na classe `Cpf`?
Comment: Ajustei o código conforme a resposta do @Randrade, porém continuou com o mesmo erro.

***System.MissingMethodException: Nenhum construtor sem parâmetros foi definido para este objeto.***

Depois de um bom tempo tentando descobrir ("*debugando*") identifiquei que o erro ocorre porque a classe CPF tem um construtor **protected**, consegui realizar o bind alterando o acesso para **public**. Mas será que a solução é colocar acesso público mesmo?
Answer: Você pode resolver esse problema criando o Objeto desta forma:
var pessoaFisica = {
    id: 1,
    Nome: 'Renan',
    Cpf: {
        Numero: '232432'
    }
};

Mas dessa forma você não está utilizando o AngularJS em si, e sim criando um objeto normal em javascript.
Utilizando Angular, seu objeto seria algo como isso:
$scope.person = {
  'id': '1',
  'nome': 'Renan',
  'Cpf': {
     'Numero': '1234678'
  },
}

E dessa forma você passa o $scope.person como objeto.
$http.post("Pessoa/Criar/", { person : $scope.person});

Neste site você possui alguns exemplos de como utilizar Angular.
Nesta Pergunta você possui alguma respostas de como utilizar Angular para essa finalidade.
Answer: Precisa ajustar sua ViewModel para receber a mesma estrutura que está vindo do seu post request.
public class PessoaViewModel
{
    public int PessoaFisicaID { get; set; }
    public string Nome { get; set; }
    public CPF cpf { get; set; }
}
public class CPFViewModel
{
    public string Numero { get; set; }
}

Veja se resolve, e de um retorno.
Comment: Isso resolveria se minha classe CPF tivesse um construtor público. Veja na pergunta que ela não tem. Conforme comentário que adicionei na pergunta, só consegui fazer o bind depois que alterei o construtor da classe CPF de **protected** para **public**. A dúvida agora é: Colocar o construtor da classe CPF como **public** é a solução para fazer bind do objeto pessoa? Seria impossível fazer o post se meu objeto Pessoa se o seu Cpf não tiver um construtor público?
Comment: @Renan, a classe CPF deveria ser CPFViewModel tbm. A ideia é construir um ambiente que receba os valores via request, após isso transporte esses valores para suas classes de modelo.
Comment: Mas então caso eu deixe o contrutor de CPF com acesso **protected** eu vou precisar criar essa classe **de novo** no Asp.net MVC (dessa vez com contrutor *public*) para conseguir fazer o bind? A outra alternativa seria deixar o contrutor de CPF com acesso público para eu não precisar recriar essa classe (como a CPFViewModel), seria isso?
Comment: @Renan, não precisa mexer na sua classe. Basta criar uma classe nova, chamada CPFViewModel, para receber os dados vindos do request. Depois vc passa os dados para um objeto da sua classe CPF.

Bind de tipo complexo com AngularJS


Construindo DataGrid com C# WPF em tempo de execução

Question: Tenho um DataTable onde vou armazenar alguns dados que o usuário informa e através dele quero passar as informações para o DataGrid.
gvDados.ItemsSource = dt.DefaultView; //Essa é a ligação entre o DataTable e a Grid

No caso o usuário informa o nome da coluna e clica no botão AdicionarColuna, que tem o seguinte código:
private void btnAddColuna_Click(object sender, RoutedEventArgs e)
{
    bool valida = true;
    int nroColunas = dt.Columns.Count;

    for (int i = 0; i < nroColunas; i++)
    {
        if (dt.Columns[i].ToString().ToUpperInvariant().Equals(ttbColuna.Text.ToUpperInvariant()))
            valida = false;
    }

    if (valida)
    {
        // gvDados.Columns.Clear();
        DataGridTextColumn c = new DataGridTextColumn();
        c.Header = ttbColuna.Text;

        gvDados.Columns.Add(c);

        cbbColunas.Items.Add(ttbColuna.Text);

        dt.Columns.Add(ttbColuna.Text, typeof(string));
        ttbColuna.Text = "";
    }
    else
        MessageBox.Show("Já existe uma coluna com esse nome","Sistema Comercial |B ",MessageBoxButton.OK,MessageBoxImage.Error);
}

Com esse método ele gera as colunas, que eu quero e adiciona a coluna no DataTable e na DataGrid, é correto fazer isso?
Pois se eu colocar apenas no DataTable não é visualizado na DataGrid
Até então está tudo ok, porém quando eu vou adicionar uma linha no DataTable para que ela possa aparecer na DataGrid não dá certo, aparece uma linha porém em branco sem os dados ...
Digamos que o usuario adicionou duas colunas, Tamanho e Cor então meu DataTable teria que receber
dt.Rows.Add(ttbTamanho.Text, ttbCor.Text);

As informações ficam no DataTable, porém não são exibidas no DataGrid.
Existe algum meio de colocar as informações no DataGrid sem usar o DataTable ou alguma método que faça com que apareça as informações, levando em consideração que as colunas e linhas são adicionadas em tempo de execução
Answer: O que você está pedindo pode ser meio complexo. Vou te dar alguns guias e dicas que podem facilitar sua vida.

Existe algum meio de colocar as informações no DataGrid sem usar o DataTable?

Sim, qualquer objeto que implemente IEnumerable pode ser a fonte de dados. Por exemplo: List<Produto> ou ICollection<Categoria>, inclusive um List<dynamic> são fontes válidas.
AutoGenerateColumns
A propriedade AutoGenerateColumns definida como true irá gerar as colunas automaticamente após ter a fonte de dados definida. Se sua fonte de dados for um List<Pessoa>, e a Pessoa possua os atributos Nome, Telefone e Cidade, será gerado três colunas automaticamente.
CanUserAddRows
Com essa propriedade true, se você definiu a fonte de dados como um objeto do tipo List<Pessoa>, as linhas inseridas na DataGrid serão refletidas na coleção (objeto). Note que nessa abordagem, se você adicionar um item na coleção via aplicação(código), essa linha não será refletida na DataGrid.
 <DataGrid x:Name="DataGrid1" AutoGenerateColumns="True" CanUserAddRows="True" />

Code-Behind
private List<Pessoa> pessoas;
public MainWindow()
{
    InitializeComponent();
    pessoas = new List<Pessoa>();
    DataGrid1.ItemsSource = pessoas;
 }

ou
    var listaDinamica = new List<dynamic>
    {
        new { Nome = "José", CPF = "000.000.00-00"},
        new { Nome = "Pedro", CPF = "111.111.11-11"}
    };

    DataGrid1.ItemsSource = listaDinamica;

ObservableCollection
Acredito que esse seja o melhor tipo de coleção para se trabalhar com DataGrid no WPF. Funciona assim:
    private ObservableCollection<Pessoa> pessoas;
    public MainWindow()
    {
        InitializeComponent();
        pessoas = new ObservableCollection<Pessoa>();
        DataGrid1.ItemsSource = pessoas;
     }

Usando ObservableCollection, se você adicionar uma pessoa na lista via código, irá refletir na DataGrid. Se o usuário adicionar uma linha na DataGrid, irá refletir no objeto pessoas
https://msdn.microsoft.com/pt-br/library/ms668604(v=vs.110).aspx
Comment: Obrigado sua resposta foi muito útil e conseguiu me ajudar! se pude me ajudar também nessa agradeço: http://pt.stackoverflow.com/questions/183435/defini%C3%A7%C3%A3o-de-row-header-de-um-datagrid-atrav%C3%A9s-das-linhas-de-uma-coluna-de-um-da


Download file associated to export button in webpage from terminal

Question: I would like to download the file that is produced by clicking on the "EXCEL Document" button in the bottom right of this page from the terminal.
Is it possible to do that from a unix bash?
Also within R or using python would be ok.
http://www.vivc.de/index.php?r=eva-analysis-mikrosatelliten-vivc%2Fresultmsatvar&EvaAnalysisMikrosatellitenVivcSearch%5Bleitname_list%5D=&EvaAnalysisMikrosatellitenVivcSearch%5Bleitname_list%5D%5B%5D=ABADI&EvaAnalysisMikrosatellitenVivcSearch%5BName_in_bibliography%5D=
Thanks
Answer: The requests library may be what you're looking for.  You'd need the URL to pass in to requests.get

import requests
r = requests.get('http://google.com')
r.raise_for_status() # Will error out if there's an issue with the get request
print(r.content)

outputs
<!doctype html><meta content="Search the world\'s information, including webpages, images, videos and more. Google has many special features to help you find exactly what you\'re looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><scr...

Comment: Please see [answer].
Comment: @BenYarmis What URL should I pass to the function? The one associated with the button or the URL of the page, like www.vivc.de ?
Comment: @LiPaPe you would pass in the url associated with the button.  This site in particular, however, looks like it does some additional work after a popup is opened to get the file you want.


Upgrading from d6 to d7: getting puzzling 'requirements problem' error

Question: I am trying to upgrade from d6 to d7 and I'm getting a requirements problem immediately after running upgrade.php. It seems there's some crucial information missing. For me, at least: absolutely no clue what is happening here.
I've got the Ad module (as well as ad_image, ad_flash) enabled
The error that is thrown back at me is:

upload (Missing): Unresolved dependency, Flash Ad requires this module.
  upload (Missing): Unresolved dependency, Image Ad requires this module.

See screenshot
Answer: Before upgrading the drupal core, you must deactivate your contrib modules. I think you did not.?
Upgrade the core first. Then upgrade any contrib modules.
If you have used cck in drupal 6, you will need the cck module to do the migration.
Comment: I obviously did not. Sorry for not having read the instructions more carefully, totally missed that.


getClass().getResource() retorna nulo

Question: O seguinte codigo finciona normalmente:
package com.lucasdaniel;

package com.lucasdaniel;
import java.net.URL;

public class Main {

    public static void main(String[] args) {
        new Subclass();
    }

    static class Subclass {
        public Subclass() {
            URL resource = getClass().getResource("css.css");
            System.out.println(resource);
        }
    }
}

Mas quando eu crio o module-info.java, o resource recebe null.
o build.gradle está assim:
plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

group 'com.lucasdaniel'
version '1.0-SNAPSHOT'

mainClassName = "untitled/com.lucasdaniel.Main"

repositories {
    mavenCentral()
}

javafx {
    version '11.0.2'
    modules = ['javafx.fxml', 'javafx.controls']
}

os arquivos do projeto estão assim:
Comment: Você está executando ele dentro de um JAR?
Comment: não estou executando em jar
Answer: Use o getResource da classe
URL resource = Subclass.class.getClassLoader().getResource("css.css");

getClass().getResource() retorna nulo


Real Analysis, Folland problem 5.5.55 Hilbert Spaces

Question:
problem 3.5.55 - Let $\mathcal{H}$ be a Hilbert space.
a.) (The polarization identity) For any $x,y\in\mathcal{H}$ $$<x,y> = \frac{1}{4}(\lVert x + y \rVert^2 - \lVert x - y\rVert^2 + i\lVert x + iy\rVert^2 - i\lVert x - iy\rVert^2)$$
b.) If $\mathcal{H}'$ is another Hilbert space, a linear map from $\mathcal{H}$ to $\mathcal{H}'$ is unitary if and only if it is isometric and surjective.

Attempted proof a.)$$\lVert x + y \rVert^2 = \lVert x \rVert^2 + \lVert y \rVert^2 + <x,y> + <y,x> $$
$$-\lVert x - y \rVert^2 = -\lVert x \rVert^2 - \lVert y \rVert^2 + <x,y> + <y,x> $$
$$i\lVert x + iy\rVert^2 = i\lVert x \rVert^2 + i\lVert y \rVert^2 +  <x,y> - <y,x> $$
$$-i\lVert x - iy\rVert^2 = -i\lVert x \rVert^2 - i\lVert y \rVert^2 +  <x,y> - <y,x> $$
Adding the above gives the result
Attempted proof b.): Suppose, $f$ is a unitary linear map from $\mathcal{H}$ to $\mathcal{H}'$. We need to show that $f$ is isometric and surjective. Since $f$ is a unitary linear map we know from Folland that $f$ is also an invertible linear map that preserves inner products: $$\langle fx,fy\rangle_{2} = \langle x,y\rangle _{1} \ \ \forall \ x,y\in\mathcal{H}$$
Set $y = x$, then we have $\lVert fx\rVert_{2} = \lVert x\rVert_{1}$ thus an isometry.
I am not sure how to proceed further or if this approach is incorrect somehow. Any suggestions is greatly appreciated, I will update more as I keep thinking about it.
Comment: You use the polarization identity to show that preserving the norm is the same as preserving the inner product
Comment: For part a, your 4th line should start with: $-i\lVert x-iy\rVert^2$, not $-i\lVert x+iy\rVert^2$.
Answer: You have proved that it is an isometry. It must be surjective for else it wouldn't be invertible.
Now assume that we have a surjective isometric linear mapping. We have to prove that it preserves inner products.
$<fx,fy>=\frac{1}{4}(||fx+fy||^2+||fx-fy||^2+i||fx+ify||^2-i||fx-ify||^2)$
$=\frac{1}{4}(||f(x+y)||^2+||f(x-y)||^2+i||f(x+iy)||^2-i||f(x-iy)||^2)$
$=\frac{1}{4}(||x+y||^2+||x-y||^2+i||x+iy||^2+||x-iy||^2)$
$=<x,y>$
QED.
Comment: You put QED at the bottom. But isn't the converse of the argument for b.) complete?
Comment: @Wolfgang What do you mean with that?
Comment: Since you have shows that it preserves inner products. Then have we proved the converse of the proof for b.)?
Answer: Unitary means invertible and inner-product-preserving:
$$\langle fx,fy\rangle_2=\langle x,y\rangle_1.\tag1$$
On the other hand, surjectivity is logically "half" of bijectivity, and isometric means $$\lVert fx\rVert_2 = \lVert x\rVert_1.\tag2$$
However, a linear map $f:\mathcal{H}\to\mathcal{H}'$ is invertible if it's bijective and its inverse is bounded:
$$\lVert fx\rVert_2\ge c\lVert x\rVert_1
\qquad\text{for some}\quad c>0.\tag3$$
As you noted (and Folland does right after the definition of a unitary map, on page 176), setting $y=x$ shows that $(1)\implies(2)$, inner-product-preserving linear (unitary) maps are isometries. Since unitary maps are also invertible, they must be surjective. This proves one direction: an invertible inner-product-preserving linear map is a surjective isometry.
However (to prove that a surjective isometric linear map is invertible and inner-product-preserving), note that an isometry also has bounded inverse, $(2)\implies(3)$, as seen from their definitions on page 154, taking $c=1$. Isometries are clearly injective since $x\ne y\implies$ $0\ne\lVert{x-y}\rVert=$ $\lVert{f(x-y)}\rVert=$ $\lVert{f(x)-f(y)}\rVert\implies$ $f(x)\ne f(y)$, but if we are given that $f$ is also surjective, then it is therefore bijective and hence also invertible, by definition. We thus only need to show that a surjective isometry is also inner-product-preserving. For this, we'll use the polarization identity from part a to show that preserving the norm entails preserving the inner product.
To verify part a, first note what Folland uses in the proof of the Parallelogram Law, proposition 5.22:
$$\lVert x\pm y\rVert^2=\lVert x\rVert^2\pm2\,
\text{Re}\langle x,y\rangle+\lVert y\rVert^2,$$
where $2\text{Re}\langle{x,y}\rangle=
\langle{x,y}\rangle+\langle{y,x}\rangle$
since the summed terms are complex conjugates.
Noting that
$$\lVert x\pm iy\rVert^2=\lVert x\rVert^2\pm2\,
\text{Re}\langle x,iy\rangle+\lVert iy\rVert^2,$$
and $\langle x,iy\rangle=-i\langle x,y\rangle$ so that
$$\text{Re}\langle x,iy\rangle=\text{Im}\langle x,y\rangle,$$
we conclude that
$$\begin{align}
\langle x,y\rangle
&=\text{Re}\langle x,y\rangle+i\,\text{Im}\langle x,y\rangle\\
&=\text{Re}\langle x,y\rangle+i\,\text{Re}\langle x,iy\rangle\\
&=\tfrac14\left[
\left(\lVert x+y\rVert^2-\lVert x-y\rVert^2\right)+i
\left(\lVert x+iy\rVert^2-\lVert x-iy\rVert^2\right)\right]\\
&=\tfrac14\left(
\lVert x+y\rVert^2-\lVert x-y\rVert^2+i
\lVert x+iy\rVert^2-i\lVert x-iy\rVert^2
\right).
\end{align}$$
Note the negative sign by the second term, correcting a typo in the book for part a. Finally, the conclusion of part b follows from $(2)$ since $f$ is an isometry:
$$\begin{align}
\langle fx,fy\rangle
&=\tfrac14\left(
\lVert fx+fy\rVert^2-\lVert fx-fy\rVert^2+i
\lVert fx+ify\rVert^2-i\lVert fx-ify\rVert^2
\right)\\
&=\tfrac14\left(
\lVert f(x+y)\rVert^2-\lVert f(x-y)\rVert^2+i
\lVert f(x+iy)\rVert^2-i\lVert f(x-iy)\rVert^2
\right)\\
&=\tfrac14\left(
\lVert x+y\rVert^2-\lVert x-y\rVert^2+i
\lVert x+iy\rVert^2-i\lVert x-iy\rVert^2
\right)\\
&=\langle x,y\rangle.
\end{align}$$
Comment: To understand you correctly, are you saying that I have proved the forward direction? Now, I need to prove the converse?
Comment: Yes, @Wolffang. The meat of one direction is showing (1) implies (2) and we've done that. The meat of the converse is showing (2) implies (1) and Hasan Saad has done that, as Adam Hughes suggested. The first paragraphs of my post elaborate the conditions of each side, drawing the plan for both directions of the argument.


Prove about distribution function $F(x)$

Question: Can you tell me steps how to prove that
$\int_{-\infty}^\infty F(x) \text{d}F(x) = 0,5$?
Comment: Welcome to CV. This question is much too brief. You're assuming that the equation is sufficient information to obtain a response. This is not the case. You need to elaborate on your objectives in posing this question, and why you're interested in a proof or risk having the question removed.
Comment: Is this a question from a course of textbook? Please add the `[self-study]` tag & read its
[wiki](http://stats.stackexchange.com/tags/self-study/info). Then tell us
what you understand thus far, what you've tried & where you're stuck. We'll
provide hints to help you get unstuck. Please make these changes as just
posting your homework & hoping someone will do it for you is grounds for closing.
Comment: I'm voting to keep this closed because the question does not comply with the site's self-study policy.
Comment: Did you try integration by parts?
Comment: [Related, more general, question](http://stats.stackexchange.com/q/194459/6633) that asks for the value of $$\int_{-\infty}^\infty G(x)\,\mathrm dF(x)$$ where $G(x)$ and $F(x)$ are CDFs.
Answer: A simple (and obvious) substitution solves this immediately.
Simply by looking at the integral, the substitution $u=F(x)$ leaps out from the page and tugs at our locks. The result (the remainder of which is even simpler, and which I leave for you) follows. (Keep in mind this is a definite integral. Pay attention to the limits.)
As JohnK explains in comments, this result will be valid for continuous distributions.
Comment: @JohnK Keeping in mind the [guidelines](http://stats.stackexchange.com/tags/self-study/info) on answering `self-study` questions, in particular the first two points, and yet the need to actually answer questions rather than leave them unanswered, what would you suggest that would still leave the OP something substantive to do? The guidance in the answer leads to an immediate solution to an essentially trivial question. I did try putting the substitution in anyway, but took it out again as it seems to give away too much.
Comment: That could have been a comment, no?
Comment: @JohnK on a different sort of question, I definitely agree that it would be more like a comment, and I also agree that as it stands it's less than ideal as an answer. My question in the previous comment was not rhetorical -- I would like to give an answer that better meets the two conflicting goals here and would appreciate any thoughts you have on that.
Comment: Glen, I understand the conflicting ideas here. On the one hand it is a self study question so you don't want to give it away. On the other, answers need to be more than two-liners. In my opinion, a good answer here would offer the substitution, make a comment about how general this result is-it's for all continuous distributions- and ask the OP to fill in the details.
Comment: @JohnK It's a reasonable position on things; I have done as you suggest.
Comment: Thank you. And don't get me wrong, I was among the people who upvoted this answer as I think it is way more elegant than the alternative offered.
Answer: Integration by parts:
$$\int_{-\infty}^\infty F(x)f(x) \text{dx} =F^2(x)|^{\infty}_{-\infty}-\int_{-\infty}^\infty f(x)F(x) \text{dx}$$
Adding $\int_{-\infty}^\infty F(x)f(x) \text{dx}$ to both sides of the equation:
$$2\int_{-\infty}^\infty F(x)f(x) \text{dx} =F^2(x)|^{\infty}_{-\infty}=1-0$$
Dividing by 2
$$\int_{-\infty}^\infty F(x)f(x) \text{dx}=\frac{1}{2}$$
Comment: Please see the [help](http://stats.stackexchange.com/help/on-topic) as it relates to homework-style questions and the [guidelines](http://stats.stackexchange.com/tags/self-study/info) on answering `self-study` questions, in particular the first two points. I think this is a good, useful answer, but it looks like the OP is doing study-work and as such we probably should lean more toward hints and guidance than explicit complete answers, especially when the OP has not shown an attempt.


Random Sampling from Farlie-Gumbel-Morgenstern bivariate exponential distribution

Question: I would like to obtain an algorithm for generating iid samples from Farlie-Gumbel-Morgenstern bivariate exponential distribution (as described in the book by Johnson and Kotz as Gumbel's Model II Distribution) along with theoretical justification if possible. Also are there R packages which implement the algorithm ? I came upon the VGAM package which contains functions only for estimating parameters of the distribution.
Answer: The cdf of a two-dimensional Farlie-Gumbel-Morgenstern distribution is given by
$$F(x,y)=\underbrace{(1-e^{\alpha_1x+\beta_1x^2})}_{F_x(x)}\underbrace{(1-e^{\alpha_1x+\beta_1x^2})}_{F_Y(y)}[1+\lambda\,e^{\alpha_1x+\beta_1x^2}\,e^{\alpha_1x+\beta_1x^2}]$$
with $|\lambda|<1$ and $\alpha_i,\beta_i>0$ for $i=1,2$. This implies that, if $(X,Y)\sim F$, then $(F_X(X),F_Y(Y))$ is distributed from the Farlie-Gumbel-Morgenstern copula$$G(u,v)=uv(1+\lambda(1-u)(1-v)$$with uniform marginals. The associated density is$$g(u,v)=1+\lambda(1-2u)(1-2v)$$ meaning that the conditional
density of $U$ given $V=v$ is also $g(u,v)$ and the corresponding cdf
$$G(u|v)=u+\frac{\lambda}{4}(1-2v)[1-(1-2u)^2]$$Therefore, inverting
$$G(u|v)=\omega\qquad\omega\in(0,1)$$is straightfoward. This suggests the following simulation scheme:

Generate $V,W\sim\mathcal U(0,1)$
Invert $W=G(U|V)$ to derive $U$
Invert $F_X(X)=U$ and $Y=F_Y(V)$ to derive $X$ and $Y$, respectively.


familyof seminorms on normed spaces

Question: Let $(X,\|\cdot\|)$ be a normed space. It is known that the norm $\|\cdot\|$ induces a topology, known as the norm topology $\tau$ on $X$. Then the pair $(X,\tau)$ is a locally convex topological vector space. With this, $\tau$ can be generated by a family $P$ of semi-norms on $X$.
Question: Is it necessary that $\|\cdot\|$ is in $P$?
Answer: No, it is not necessary that $\lVert\,\cdot\,\rVert$ belongs to the family $P$. Unless $X = \{0\}$, when there is only one seminorm on the space - we could work around that if we allow $P = \varnothing$. And if $\dim X = 1$, then all seminorms on $X$ are constant multiples of the norm, and we must put at least one non-zero multiple of the norm in the family. Of course we could always take $P = \{ 2\cdot \lVert\,\cdot\,\rVert\}$ for $\dim X > 0$ and obey the letter of the law but violate its spirit.
More interesting, we can always take a family consisting of seminorms that are not norms if $\dim X > 1$. For a closed linear subspace $F$ of $X$, the norm induces a quotient norm on $X/F$,
$$\lVert \pi(x)\rVert_{X/F} := \inf \{ \lVert x-y\rVert : y \in F\} = \operatorname{dist}(x,F),$$
where $\pi\colon X \to X/F$ is the canonical projection. We can pull that back to a seminorm on $X$, by defining $p_F(x) := \lVert \pi(x)\rVert_{X/F}$.
Then $p_F$ is a continuous (with respect to $\tau$ of course) seminorm on $X$, with kernel $F$. Hence, taking a family $\mathscr{F}$ of nontrivial closed subspaces of $X$, we obtain a family $P = \{ p_F : F\in \mathscr{F}\}$ of continuous seminorms on $X$. Since all seminorms are continuous, the topology induced by $P$ is coarser than $\tau$.
It remains to see that one can arrange it so that the induced topology coincides with $\tau$. One way is to include two complementary subspaces in $P$. If $G,H$ are two closed subspaces such that
$$\alpha\colon G\times H \to X,\quad \alpha(x,y) = x+y$$
is a topological isomorphism, then $\{ p_G, p_H\}$ induces $\tau$. To see that, we note that the restriction of $p_H$ to $G$ is a norm which is equivalent to the restriction of $\lVert\,\cdot\,\rVert$ to $G$. Since $G \cap \ker p_H = G\cap H = \{0\}$, it is a norm, and it is continuous as the restriction of a continuous seminorm. Since $\alpha$ is a topological isomorphism, there is a $c > 0$ such that $\lVert x+y\rVert \geqslant c(\lVert x\rVert + \lVert y\rVert)$ for all $(x,y) \in G\times H$, hence
$$p_H(x) = \inf \{ \lVert x+y\rVert : y \in H\} \geqslant c\lVert x\rVert$$
for all $x\in G$. The same holds when we interchange the roles of $G$ and $H$, whence
\begin{align}
\max \{ p_G(x+y), p_H(x+y)\} &= \max \{ p_G(y), p_H(x)\}\\
& \geqslant \frac{1}{2}(p_G(y) + p_H(x))\\
&\geqslant \frac{c}{2}(\lVert y\rVert + \lVert x\rVert)\\
& \geqslant \frac{c}{2}\lVert x+y\rVert
\end{align}
for $x\in G, y\in H$, so $\max \{p_G, p_H\}$ is a norm that induces a finer topology than $\tau$ on $X$. Since it is also a $\tau$-continuous norm, it is equivalent to $\lVert\,\cdot\,\rVert$.
Finally, we need to see that in every normed space of dimension $\geqslant 2$ there are complementary subspaces. Let $\lambda \neq 0$ be a continuous linear form, and $x_0\in X$ with $\lambda(x_0) = 1$. Then $\ker \lambda$ and $\operatorname{span} \{x_0\}$ are complementary subspaces. $\ker \lambda$ is closed since $\lambda$ is continuous, and $\operatorname{span} \{ x_0\}$ is finite-dimensional, hence closed. The map $x \mapsto (\lambda(x)\cdot x_0, x - \lambda(x)\cdot x_0)$ is continuous, and its inverse $\alpha \colon (\operatorname{span} \{x_0\}) \times (\ker \lambda) \to X,\; (x,y) \mapsto x+y$ is also continuous, hence a topological isomorphism.
Comment: I did not expect a detailed answer sir. Thank you very much.

familyof seminorms on normed spaces