Does the concept of rhyme make sense when describing music?

Question: We're all familiar with the concept of lyrical rhymes. For example, the words through, curfew and blue all rhyme despite being spelled differently because the sound of their final syllable is the same.
But if you're analyzing instrumental, i.e. non-verbal music, does it make sense to say that two musical phrases rhyme?
Consider the opening of Beethoven's Fifth Symphony:

Could you say the second four-note phrase rhymes with the first? If we can agree that rhyme is a helpful musical term, what might the rules be? For instance, in the Beethoven example, if the second phrase ended with a leap up to a D rather than down to a D, would that still be a rhyme?
Or is rhyme too vague and ill-specified to be useful as a term of musical analysis?
BTW, I did try googling for this but got lots of hits related to songs for small children, rather than technical terminology for musical analysis.
Comment: curfew does not rhyme with the others due to difference in syllabic emphasis,  George& Ira Gershwin notwithstanding.  :-)
Comment: @CarlWitthoft - just omit the cur...  That's dogged determination!
Comment: *Motif* sometimes *motive* might fit.
Comment: You say potato…
Comment: +1 for making me think about this from a new perspective. And unrelated: can anyone back up @CarlWitthoft's rhyme definition? I don't remember emphasis/syllabic stress being a criterion for rhyming that I learned, but I'm not an expert...
Comment: @Tim  Then there's Guthrie,  " I don't want a pickle//just want to ride my motorsickle// I don't want to die // just want to ride my motorcyyyyy   ///.... cle"
Comment: I believe it's called '*poetic licence*' rhyming with pretty well whatever you like!
Answer: That particular choice of two four-note phrases I think doesn't "rhyme" particularly well. The first sequence goes G G G Eb (down a major third), the second goes F F F D (down a minor third), and the rhythm varies too. But if I have understood correctly, you might be referring to cases where there is a more direct mapping between phrases, for example if the second phrase maintained all the intervalic relationships, but modulated to a different key.
In that case, I think we call it a "Sequence". here's the Wikipedia link: https://en.wikipedia.org/wiki/Sequence(music)
I actually wasn't aware of this until I googled "modulated ostinato" and clicked around. We would have typically called this a motif (repeated musical idea) or an ostinato (type of motif where a melodic line in same voice is repeated) if it weren't for the change of key.
To be fair, there is a lot of ambiguity in differentiating between some of these concepts. Consider the Encyclopedia Britannica's definition of ostinato: "short melodic phrase repeated throughout a composition, sometimes slightly varied or transposed to a different pitch." The words "sometimes slightly varied or transposed" are interesting; under this definition, ostinato entirely captures the definition of a sequence.
So to summarise, depending who you ask this could be called a motif, an ostinato or a sequence.
That being said, because the example you gave has two fairly distinct four note phrases, and I am finding it hard to see how they might "rhyme", I may have jumped the gun, misunderstood what you were asking, and answered a different question!
Answer: Music is full of imitation, and of 'question and answer' phrases.
There are many techniques of musical imitation - a fragment is echoed, maybe transposed, inverted or otherwise modified, but it's a recognisable repetition.   And there are many techniques of rhyming - the simple match of a final syllable or more complex internal echoes.
We don't usually use the term 'rhyme' in music.  The concepts are obviously similar.  But I'd stick to the recognised musical terms when describing music.  There are plenty!
Comment: "We don't usually use the term 'rhyme' in music" Without context, that's a funny one :)
Answer: As @Tim mentioned in comments, you should identify this musical element as a motif. In purely musical terms a motif is basically a melodic element that lasts roughly 1 or 2 beats.
Many musical terms map over to linguistic or literary terms, but of course there is no absolute matching so we need to be careful about the comparisons we make.
I have seen music theory that associates rhyme with the endings of musical periods. That's your common "question/answer" or "antecendent/consequent" pairing of 8 bar phrases with the first ending on a dominant and the second ending on a tonic. The two ending chords are then analogous to rhymed words and the two 8 bar phrases are analogous to a rhymed couplet.
The Beethoven motif is not a musical period. So rhyme probably is the device to compare.
On thing you can do is associate musical beat units with word units. I mean that a beat is roughly equal to a word. Syllables of a word are then subdivisions of the beat. Motifs then are analogous to a word or a very short phrase.
Notice that the Beethoven motif is repeated. It's almost an exact rhythmic repeat (the second iteration is held longer) but pitch is changed upon the repeat.
So: repeat but change it a little.
A famous line that comes to mind is: it was the best of times, it was the worst of times...
In terms of duration, stress, repetition with variation, that seems like a good comparison to me.
The literary device is called anaphora (had to look it up!)
I think you could make some comparison to alliterative verse or assonance, but those units are maybe much shorter or suggest a repeated tone or chord.


How to trigger GKE autoscaling decision on demand?

Question: The GKE autoscaling process makes what they call "decisions" about whether or not to autoscale. The logs will include details explaining why the process decided not to do anything (noDecisionStatus), which is cool. Search bait: This can also be seen as a notification with the text "Can't scale up a node pool because of a failing scheduling predicate".
I've made some changes that should address the issues raised in the noDecisionStatus log entry. How do I get GKE to try making a decision again? It's been hours.
Comment: Same error. What changes have you made?
Comment: Various, in response to what Google suggests. Things like changing pod tolerations. I still have volume node affinity conflicts (which I totally expected and aren't an issue, lol, because of course there are conflicts) but I haven't dealt with them yet as I'm waiting to see if the other changes have any effect.
Answer: Looks like I just had to wait. I'm seeing the noDecisionStatus logs again.


How to disable dnsmasq cache

Question: I just want to disable the caching functionality, I do not need it and it only creates bad behavior in my environment.
Not interested in any other solution, if you do not know, do not comment.
Comment: That's some attitude, coming from someone who didn't read the man page.
Answer: From the manual page:
<code>-c, --cache-size=<cachesize>
    Set the size of dnsmasq's cache. The default is 150 names.
    Setting the cache size to zero disables caching.
    Note: huge cache size impacts performance.
</code>
Comment: Bernd, you give a lot of good help, especially in comments where you don't get points for it. So I'm upvoting this answer, partly as a proxy for all of that. But this question didn't deserve an answer.
Comment: Thanks for the compliment. Yes, I hope OP learns how to RTFM (and to switch off an attitude that comes across as arrogance).

How to disable dnsmasq cache


OpenVPN and nginx port sharing : Adress already in use

Question: I have an instance of nginx running on ports 80 and 443, and I would like to use openvpn with the port 443 in sharing.
So in my server.conf I have this
port 443
port-share 127.0.0.1 4433

proto tcp
;proto udp

And in my nginx.conf
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    client_max_body_size 2M;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    # OpenVPN
    server {
        listen 4433;
    }
}

But when I start nginx daemon first, the openvpn service can't boot with the error :
Mon Jan 18 13:36:19 2016 us=761548 TCP/UDP: Socket bind failed on local address [undef]: Address already in use

And if I start openvpn first, nginx returns :
[emerg] 5301#0: bind() to 0.0.0.0:443 failed (98: Address already in use)

I don't understand why the port-share feature doesn't work.
Comment: I tried : listen {my_public_ip}:4433 but I got same error : TCP/UDP: Socket bind failed on local address [undef]: Address already in use
Comment: On of your included nginx's files contains `listen 443`.
Answer: There has to be some .conf file in /etc/nginx/conf.d/, binding on port 443. This leads to the cannot bind error (only one application can bind to a port at a time, at least per listening address).
You write, that you have "nginx running on ports 80 and 443" - I suppose you defined this in the conf.d folder. Simply change the listen directive from 443 to 4433 and it should work.
Answer: You didn't read the documentation properly. Two daemons cannot share one bind.
In your nginx configuration you should define the following:
listen 127.0.0.1:4433 ssl;
Although my advice - avoid OpenVPN and especially avoid port-sharing in OpenVPN. Using port-sharing is making a parasite connection with the reliability of your web-server and your OpenVPN service. Furthermore, you are relying on the people who are not experienced enough in web-servers and HTTP, and this will lead to even more issues.


Is the statement $|a − b| \le \gcd(a, b)$ true?

Question: Is the statement $|a − b| \le \gcd(a, b)$ true?
How to prove the statement?
I've tried to use the FTA but I'm stuck there.
Comment: Lets try $a=2$ and $b=10.$
Answer: If $a=b$, then yes, otherwise the opposite $|a-b|\ge \gcd(a,b)$ is true, because $\gcd(a,b)|a-b$.
Comment: What if $a=b=2$?
Comment: That's straightforward, as $\gcd(a,b)$ divides both $a$ and $b$ by definition.
Comment: Good point, I should insist $a\not = b$.
Comment: Should I prove gcd(a,b)|a-b for this question?


get timestamp of most recent comment of an article

Question: I need the date of the last created/updated comment of an article. Are there any API functions in drupal 8 like node->most_recent_comment ? Or do I have to check every comments date of a node in a loop?
EDIT - Solution:
$node->comment->last_comment_timestamp;

Note that you'll have to change ->comment to the actual field name of the comments on your node.
Comment: check the comment_entity_statistics table. maybe there is a function as well but i havent checked.
Answer: As @IvanJaros pointed out the comments statistics are stored in a database table. You don't need an API function to get them. The comment module does this for you and places them in the field while loading the node from storage:
function comment_entity_storage_load($entities, $entity_type) {
  ...
  // Load comment information from the database and update the entity's
  // comment statistics properties, which are defined on each CommentItem field.
  $result = \Drupal::service('comment.statistics')->read($entities, $entity_type);
  foreach ($result as $record) {
    // Skip fields that entity does not have.
    if (!$entities[$record->entity_id]->hasField($record->field_name)) {
      continue;
    }
    $comment_statistics = $entities[$record->entity_id]->get($record->field_name);
    $comment_statistics->cid = $record->cid;
    $comment_statistics->last_comment_timestamp = $record->last_comment_timestamp;
    $comment_statistics->last_comment_name = $record->last_comment_name;
    $comment_statistics->last_comment_uid = $record->last_comment_uid;
    $comment_statistics->comment_count = $record->comment_count;
  }
}

So you can access the statistics directly from the node field:
$node->comment->last_comment_timestamp;
$node->comment->last_comment_name;
$node->comment->last_comment_uid;
$node->comment->comment_count;

Answer: I think you can do this:
$node->get('field_comments')->__get('created')->value;

Note that you'll have to change field_comments to the actual field name of the comments on your node.
Comment: You are right this shows the timestamp of the most recent comment: $last_date = $node->get('field_comments')->__get('last_comment_timestamp');
Comment: Please mark this as the accepted answer then.


Mongodb query combining $text search with $regex

Question: My dilemma is that mongodb $text searches must match an exact word: e.g. if trying to match a post with 'testing123' a search for 'test' will not match, but using $regex will match. Now, I want to make use of indexes too, but I also want partial matches.
My thinking is that I could combine them with an $or operator, but it is not working. Is this possible? Each query alone inside the $or work, but when combining them I get no matches.
If this is not possible, I have found a pretty good solution, here , but I would like the combined $or to work if possible, but any other suggestions are welcome.
const posts = await Post.find({
  name: { $regex: 'foo', $options: 'i' },
  $or: [
    { $text: { $search: text, $caseSensitive: false } },
    { text: { $regex: text, $options: 'i' } },
  ],
});

Answer: One way of doing this is to downcase the text into another field, then use $regex search on that field.

You have text that you want to search for any substring case insensitively:
MongoDB Enterprise ruby-driver-rs:PRIMARY> db.foo.insert({foo:'hello world TESTING123'})
WriteResult({ "nInserted" : 1 })

Step 1: add another field which stores the text in lower case.
MongoDB Enterprise ruby-driver-rs:PRIMARY> db.foo.insert({foo:'hello world TESTING123',foo_lower:'hello world testing123'})

Step 2: add index.
MongoDB Enterprise ruby-driver-rs:PRIMARY> db.foo.createIndex({foo_lower:1})
{
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 2,
    "numIndexesAfter" : 3,
    "commitQuorum" : "votingMembers",
    "ok" : 1,
    "$clusterTime" : {
        "clusterTime" : Timestamp(1597711723, 7),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    },
    "operationTime" : Timestamp(1597711723, 7)
}

Step 3: downcase the query to "testing123"
Step 4: use $regex.
MongoDB Enterprise ruby-driver-rs:PRIMARY> db.foo.find({foo_lower:{$regex:'testing123'}})
{ "_id" : ObjectId("5f3b2498f885e53d90f30979"), "foo" : "hello world TESTING123", "foo_lower" : "hello world testing123" }
MongoDB Enterprise ruby-driver-rs:PRIMARY> db.foo.find({foo_lower:{$regex:'testing123'}}).explain()
{
    "queryPlanner" : {
        "plannerVersion" : 1,
        "namespace" : "test.foo",
        "indexFilterSet" : false,
        "parsedQuery" : {
            "foo_lower" : {
                "$regex" : "testing123"
            }
        },
        "queryHash" : "0D14CC56",
        "planCacheKey" : "1974A2D4",
        "winningPlan" : {
            "stage" : "FETCH",
            "inputStage" : {
                "stage" : "IXSCAN",
                "filter" : {
                    "foo_lower" : {
                        "$regex" : "testing123"
                    }
                },
                "keyPattern" : {
                    "foo_lower" : 1
                },
                "indexName" : "foo_lower_1",
                "isMultiKey" : false,
                "multiKeyPaths" : {
                    "foo_lower" : [ ]
                },
                "isUnique" : false,
                "isSparse" : false,
                "isPartial" : false,
                "indexVersion" : 2,
                "direction" : "forward",
                "indexBounds" : {
                    "foo_lower" : [
                        "[\"\", {})",
                        "[/testing123/, /testing123/]"
                    ]
                }
            }
        },
        "rejectedPlans" : [ ]
    },
    "serverInfo" : {
        "host" : "serene",
        "port" : 14420,
        "version" : "4.4.0",
        "gitVersion" : "563487e100c4215e2dce98d0af2a6a5a2d67c5cf"
    },
    "ok" : 1,
    "$clusterTime" : {
        "clusterTime" : Timestamp(1597711761, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    },
    "operationTime" : Timestamp(1597711761, 1)
}

Comment: Could you give me a small example of what you mean?
Comment: Case-insensitive regexp matching does not support indexes, so you create another field where the text is downcased that you can search in a case-sensitive fashion.
Comment: how would this solve the issue with partial searches?
Comment: What does a partial search for exact word mean?
Comment: If I'm trying to match a post that has *testing123* and I only search for *test*, the $text $search will not match, but using a $regex will match. This is why I want to combine the two.
Comment: My answer provides a $regex solution which fulfills that requirement.
Comment: Yeah, but how to do I combine that with the $search? If you just add them as regular field queries together, it won't work.
Comment: Can you just give me a code example of what you're trying to say because I'm not getting it? I want both $regex and $search in the same query. Adding them together in an $or statement doesn't work and adding them both as their own field doesn't work. I'm assuming that there is no way to do this, but if you know please let me know.
Comment: You seem to be posing an XY problem. The answer I gave satisfies all of the requirements in your question (case insensitive search, any substring matches). If you have other requirements add them to the question. Using both $regex and $search is not a requirement.
Comment: If you would like an answer to include code, start by writing the code in mongo shell that inserts sample data and performs the query, add that to the question.


Clicar numa imagem aparecer uma div

Question: A minha dúvida é a seguinte, ao clicar na imagem 1 aparece a div 1, mas depois ao clicar na imagem 2, desaparece a div 1 e aparece a div 2, e depois ao clicar na imagem 3 desaparece a div 2 e aparece a div.
Como poderei fazer isso?
Obrigado.
Comment: Dependendo do que precisar fazer, talvez o que você esteja procurando seja por um Accordion.
Veja exemplo: https://jqueryui.com/accordion/
Answer: Pode fazer somente com CSS, usando o seletor target:

div { display: none }         /* Por padrão, os divs iniciam ocultos. */
div:target { display: block } /* Exibe quando o elemento é alvo. */

lorem cachorro lorem...

lorem gato lorem...

Comment: Criando um `` (contendo a imagem) para cada um dos divs, vinculando o `href` do link com o `id` do div.
Comment: No caso, como aplicaria 5 imagens e 5 divs? Obrigado.
Comment: Obrigado, consegui fazer é isso mesmo!
Comment: Agora que tentei aplicar ao meu exemplo, o site ficou todo bugado.
Comment: O que me refiro é que todas as divs ficam bugadas.
Answer: Olá, caso queira manipular melhor os objetos da página você pode utilizar jquery, fiz um exemplo básico
<!DOCTYPE html>

     <meta charset="UTF-8">
     <title>slider</title>

div1

div2

div3

ou somente com css você define o objeto/classe
div#img1:target { ..... }

Clicar numa imagem aparecer uma div


Workitems migration from TFS 2013 to Visual Studio Team Services

Question: What are the best practices to migrate workitems say PBIs/Features manually from TFS to VSTS? And how to ensure we don't lose any linking to changesets or other linked child workitems?
Have referred the below link and the migration tool mentioned is deprecated and would like to know any other options which will help to migrate the data.
How to migrate work items from TFS to VS Team Services (VS Online)
Answer: The recommend way for now is using  Migrate to Visual Studio Team Service, a  way import your TFS Database into Visual Studio Team Services which definitely along with data.
However, currently only the following versions of TFS are supported for import with this tool:

TFS 2017 Update 3
TFS 2018

You may have to upgrade your TFS server to use. Alternative, the Microsoft official option is using public API-based tools.
Personally, even though Team Foundation Server Integration Tools has been deprecated. You could still use this solution in your case.
Besides, if you have no work item customization, then OpsHub is an
   option.  VSTS Sync Migration Tools is another way.  But none offer a full fidelity migrations. Each tool has its own limitations.


Seachview buscar dados do fragmento

Question: No aplicativo possui toolbar e 2 tabs por meio do TabLayout com 1 fragmento em cada tab.
Eu quero colocar a biblioteca MaterialSearchView para implementar o searchview que vai ser feita pesquisando os itens do recyclerview que está na TAB Telefones .
Porém coloco o MaterialSearchView na activity_main.xml
<com.mancj.materialsearchbar.MaterialSearchBar
    style="@style/MaterialSearchBarLight"
    app:mt_speechMode="false"
    app:mt_hint="Pesquisar telefones"
    app:mt_maxSuggestionsCount="10"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/searchBar" />

Quando tento usar o MaterialSearchBar pelo fragmento da null point exception.
Eu tenho que colocar o MaterialSearchBar no xml da fragment ou tem algum modo de
usar no xml da activity?
Answer: Consegui resolver deixando o MaterialSearchBar no xml da actionbar e coloquei no fragmento desse jeito.
Antes
materialSearchBar = (MaterialSearchBar) view.findViewById(R.id.searchBar);

Mudei para
materialSearchBar = (MaterialSearchBar) getActivity().findViewById(R.id.searchBar);

Seachview buscar dados do fragmento


Skip Payment Step from Checkout process

Question: I have setup a Drupal Commerce website (using Drupal 7) with two shipping options:

Delivery by courier company
Pickup from store

The next step in checkout process is to choose the payment method. BUT...
if the second choice (pickup from store) is chosen, the only available payment method is Pay at store (offline payment). I have managed to show only this option through Rules. So far so good.
My concern is that for better user experience I have to make this step skipped. So after the Shipping step where the user selects the Pickup from store option, the next logical step is the Review pane for a final review by the user before complete the checkout process.
I have read that the Payment selection method (checkout step) is required for the Payment Redirection (I fail to understand it).
I have already tried to use hook_commerce_checkout_router, checking the $order shipping line and use the drupal_goto function redirect to the review page. My custom function is the following:
<code>function <myModule>_commerce_checkout_router($order, $checkout_page) {
  global $user;

  if ($checkout_page['page_id']=='checkout') {
    if (!empty($order->commerce_order_total['und']['0']['data']['components']['2']) && ($order->commerce_order_total['und']['0']['data']['components']['2']['name']=='flat_rate_from_store')) {
      drupal_goto('checkout/' . $order->order_id . '/' . $checkout_page['next_page']);
    }
  }
}
</code>
I get error "The page isn't redirecting properly". It is the same result as if someone is at the shipping step and manually tried to enter at the url the /review.
Do you think is possible to achieve skipping this step to speed up the checkout process or I have to give up trying ?
At year 2017 it is very important to give a user the best and the most logical way to move around in a website. Useless steps and clicks slow down the process and maybe end in frustration.
Answer: The problem is you're redirecting without also updating the order's status. The checkout router determines access to a checkout page by matching the order status to the URL, and it will prevent access to any page the order doesn't appear to have reached yet.
In your case, you should just use the same API function the Payment module uses when it needs to redirect past the off-site payment redirect page because an on-site payment method was used. The function is commerce_payment_redirect_pane_next_page() and you can view the function signature and docs in commerce_payment.module.
Comment: Your help is at the right direction @ryan-szrama. I don't know if i am at the right direction! I copy the _commerce_payment_redirect_pane_next_page_ and create _myModule_redirect_pane_next_page_ call it before drupal_goto function and it seems that works. But having the post #1 code above, the review page (my next page) is shown either *Next* button, either *Go Back* button... How can i call redirect_pane_next_page on Next button and redirect_pane_previous_page on Back button ?
Comment: I don't really follow, to be honest. This approach should let you skip pages you need to once the router tries to load them. If you need to interrupt the process to work through the next / previous buttons, you'd alter the checkout form to supply your own button submission logic.

Skip Payment Step from Checkout process


Estimating Population Total of a Lognormal distribution

Question: Say we're trying to model spending behavior and it has a lognormal distribution, lognormal(6.4, 0.8) with N=1000 independent observations, a vector named A.
What's the expected value of the total spend from this population and the associated uncertainty?
Is the expected value of the total spends point estimate simply $sum(A)$? Or is it $\text{exp}(6.4 + 0.5 \times 0.8^2) \times N$ (the expected value of the distribution times the number of observations)? Or is it something else entirely?
I've found a ton of resources about adding multiple lognormal distributions, but I can't seem to find anything about the population total.
Answer: It should be the expected value for a single sample times the number of samples. sum(A) is the actual value of your samples (i.e. not an expectation). There won't be any uncertainty regarding sum(A) - the samples are the samples, so imagine them as actual customers making purchases. The estimate of what those samples look like comes from the distribution itself.
Comment: Great thank you! Makes sense to me, I just ran simulations that lined up with that as well


breadcrumb not working with taxonomy

Question: Im using the zen theme to create a subtheme. I cannot display the breadcrumb properly. My url is using taxonomy as its parents so something along the lines of http://example.com/link1/title-article. I want the breadcrumb to be "Home > Link1 > title article.
Unfortunately I only have Home / title-article as the breadcrumb.
How can I resolve this? I havent changed the zen_breadcrumb function in the zen template..
Answer: The Crumbs module will do what you are looking for. It allows you to set the pattern for crumb generation. In your case the pattern for an article would be something along the lines of
[node:field_tags]
Home is automatically generated so this will give you a crumb path of: Home >> Taxonomy Term
If you want to include the article title, then you would just add [node:title] to the crumb pattern.
[node:field_tags]/[node:title]
Which would produce: Home >> Taxonomy Term >> Title

breadcrumb not working with taxonomy


infinite sum as integral for the counting measure

Question: Let $u: \mathbb{N} \to \mathbb{R}^+$ be a positive sequence. Then it is true that
$$
\int u d\mu = \sum_{n=1}^\infty u(n).
$$
For the measure space $(\mathbb{N}, \mathcal{P}(\mathbb{N}),\mu)$, where $\mu$ is the counting measure.  The proof uses monotone convergence theorem, and goes as follows:
Take the measure space $(\mathbb{N},\mathcal{P}(\mathbb{N}), \underbrace{\sum_{j=1}^\infty \delta_j}_{\mu})$.
Let $u: \mathbb{N} \to \mathbb{R}^+$ be a positive function ($u \geq 0$).
We define
$$
u_n(k) =
\begin{cases}
u(k) & k \leq n, \\
0 & k > n.
\end{cases}
$$
For all $n \in \mathbb{N}$, $u_n$ is a normal function since we have $u_n = \sum_{k=1}^n u(k)1_{\{k\}}$. Thus, the approximation cuts of $u$ after $n$. Moreover, we have
$$
\int u_n d\mu = I_\mu(f) = \sum_{k=1}^n u(k) \mu(\{k\}) = \sum_{k=1}^n u(k).
$$
Since we have $0 \leq u_n \uparrow u$, then it follows by MCT that
$$
\int_{\mathbb{N}} u d\mu \stackrel{MTC}{=} \lim_{n \to \infty} \int u_n d\mu = \sum_{k=1}^\infty u(k).
$$
Now can someone tell me under what condition this is true if $u: \mathbb{N} \to \mathbb{R}$ is not necessarily positive?
Comment: I think you confuses the definitions. The equality holds by the definition of the integral and has nothing to do with the monotone convergence theorem. Also if $u:\mathbb{N}\rightarrow\mathbb{R}^{+}$ then it is necessarily positive (again by definition).
Comment: Why it holds by definition?
Comment: Which definition of integration do you use?
Comment: For step functions / simple functions $f = \sum_{i=1}^N \alpha_i 1_{A_i}$: $I_\mu(f) := \sum_{i=1}^N \alpha_i \mu({A_i})$. For positive functions: $\int u d\mu := \sup\{I_\mu(g): g \leq u, g $ simple $\} \in [0,\infty]$. For general functions: $\int u d\mu = \int u^+d\mu - \int u^- d\mu$.
Comment: Alright so a simple function in this case is a function that is supported only on finitely many points. It is only left to understand why $\sup \{I_u(g):g\leq u, g \text{ simple} \} = \lim_{n\rightarrow\infty} I_u(u_n)$ where $u_n$ is $u$ restricted to the first $n$ points (i.e. $u_n(k)=u(k)$ if $k\leq n$ and $0$ otherwise). Does it explain?
Comment: Indeed simple functions are defined on only finitely many sets. Yes, I think I see the idea, but in proving the above equation for the sum and the integral, my book uses the MCT to get the limit out of the integral.
Comment: That's a bit odd. Because I don't see any limit in your question. Try to read again what's written in the book, there must be a sequence of integrals or otherwise it makes no sense.
Comment: Wait a sec, let me state the proof here
Comment: I added the proof in the question
Comment: I see, well that also works, I guess. Anyway, I don't understand your final question, do you ask whether the result holds if you let $u$ receive negative values?
Comment: Indeed, does this result hold for general $u$?
Comment: It holds for example if $\sum |u(n)| <\infty$. In this case you can permute the elements inside the sum (Are you aware of this result?)
Comment: Yes, I just found that.
Comment: So if the sum converges it is true right? and thus if $u$ is integrable, it seems.
Comment: If the sum convergence **absolutely** then it is true (See my answer). I'm quit certain it's wrong without the absolute value.
Comment: Ah yeah you are right
Answer: I prove

If $u(n)$ is a sequence such that $\sum_n |u(n)| <\infty$ then $\int u d\mu = \sum_n u(n)$

By the definition of integral we have $\int u d\mu = \int u^+ d\mu - \int u^- d\mu$
By what you just showed for $u^+,u^-$ we have $u^\pm = \sum_n u^\pm (n)$
Since the sum is uniformly convergence it is the same to sum from $1,2,...$ or to sum first the $n$ for which $u(n)>0$ and only then the $n$ for which $u(n)<0$.


$L^2$ is a subspace of $L^1$

Question: I know that $L^2\subset L^1$ and also $L^1, L^2$ are vector spaces so one thing is clear $L^2$ is a subspace of $L^1$. I was reading the definition of subspace of a normed linear space and it says that, Let $(X,||.||_X)$ be a normed linear space, then $Y\subset X$ is a subspace of a normed linear space if it is a vector space and the norm define in it is $||.||_{X|Y}$ that the same norm defined in $X$ but restricted to $Y$.
My question is we have $L^2$ is a subspace of $L^1$ and $L^1$ is a normed linear space with norm $||.||_1$ and $L^2$ is also a normed linear space with norm $||.||_2$ then how we will get here $||.||_2=||.||_{2|1}$,that is we should get the norm of $L^2$ by restricting the norm of $L^1$.Where I am making mistake ,please help.
Comment: $L^2$ is not always contained in $L^1$, to begin with. This is true in finite measure spaces, but not in general. And even if we have this inclusion, the norms are still different.
Comment: As an example of Mark's comment, consider the sequence $(1/n)_{n\in\mathbb{N}}$ it is an element of $\ell^2(\mathbb{N})$ but not of $\ell^1(\mathbb{N})$.
Comment: A susbpace (algebraic subspace) of a linear space may have different norms. Not all generate the same topology.
Answer: First, as mentioned in comments, $L^2$ isn't subspace of $L^1$ in general. If there is an infinite sequence $X_i$ of sets that are pairwise disjoint and each has measure greater than $\varepsilon$, then $f(x) = \sum_i \frac{\mathbb I_i(x)}{i\cdot\sqrt{\mu(X_i)}}$ is in $L^2$, but not in $L^1$.
Second, there is a conflict of definitions.
You can consider algebraic definition of subspace, that cares only about elements and algebraic operations (sum of vectors and multiplication by scalar). In this sense, $L^2$ is subspace of $L^1$ for finite measure spaces.
Or you can consider definition of subspace for normed spaces, that also requires norm on subspace to be induced by norm on the space. In this sense, $L^2$ isn't subspace of $L^1$. Moreover, norm in $L^2$ even isn't equivalent to norm on $L^1$ (and $L^2$ isn't even closed wrt $L^1$ norm).
Comment: so basically it is a subspace in sense of vector space but not in sense of Normed linear space.
Comment: Can you give some examples of normed linear space which has a subspace and norm is induced in the subspace. Actually I am confused about how to induce norm over subspace.
Comment: Take any subspace of $L^1$, for example subspace of functions that are zero a.e. on $[0, 1/2]$, with the same norm as in $L^1$.

$L^2$ is a subspace of $L^1$


Well-ordered set countability

Question: I know there are well-ordered sets that are not countable.
Suppose you are given an uncountable, well-ordered set $S$.
Isn't it possible to provide a bijection $f:\mathbb{N} \rightarrow S$ as following?
$S$ is well-ordered, so it has the smallest element, say $s_1$. $S \setminus$ {$s_1$} is also well-ordered, so there is the next smallest element, $s_2$, Similarly, there is the next smallest element $s_3$, and so on.
Continuing like this, define $f(i) = s_i$.
I know there is something wrong with this, but I cannot really see why...
Comment: Why should $f$ be surjective?
Answer:
Suppose you are given an uncountable, well-ordered set $S$.
Isn't it possible to provide a bijection $f:\mathbb{N} \rightarrow S$

No. $\mathbb N$ is countable. You will end up with a set of elements $\{s_1,s_2,s_3,\dots\}$, but there will exist elements you have not covered. There is nothing in your definition that demands you covered all of the elements.
An example (not a well ordered set, I know, but may still illustrate my point) is if you look at the set $$S=\left\{\frac12, \frac23, \frac34, \dots, \frac{n}{n+1},\dots\right\}\cup[1,2]$$
The procedure you described works on $S$, although $S$ is not well ordered. It takes $\frac12 = s_1$ as it is the least element. Then it takes $s_2=\frac23$ and so on. It produces $s_i = \frac{i}{i+1}$ which is an injection from $\mathbb N$ to $S$, but it does not cover the whole $S$.
Edit: In fact, you can even take the set $$T=\left\{\frac12, \frac23, \frac34, \dots, \frac{n}{n+1},\dots\right\}\cup\{1\},$$
whic is well ordered and is even countable, but your procedure still does not produce a bijection from $\mathbb N$ to $T$.
Comment: Why you say "not an unordered set", you mean not a well-ordered set?
Comment: Of course. Thank you.
Answer: Even if you made a mistake about surjectivity, as pointed out by 5xum and alex, you did a good thing: you proved that
given any two well-ordered sets, one is always the intial segment of the other! (which is, of course, true. The proof needs transfinite induction in general, but works exactly as your attempt of building the bijection)

Well-ordered set countability


parse-server upload size limit , more than 100MB?

Question: I am trying to upload a file to my parse server(using javascript sdk), but I need to make sure i can upload up to 500MB (for example).
Is it possoible to be done in parse-server ?
Can it be edited in some config file?
Thank you
Comment: I'd guess tweaking this would do it: https://github.com/ParsePlatform/parse-server/blob/ab06055369efee1e456dfdf5c3a86ceba0f4faf1/src/ParseServer.js `maxUploadSize = '20mb',`
Comment: any idea where would that be on the parse-server-example project? i would like to go from there and edit it if possible. [parse-server-example](https://github.com/ParsePlatform/parse-server-example)
Answer: As you mentioned you use parse-server-example.
So you will open index.js and in this code
var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',  // Don't forget to change to https if needed
  liveQuery: {
    classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
  }
});

You will keep all your code same but you will add a last line
var api = new ParseServer({
 ..........
  liveQuery: {
    classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
  }, //dont forget to add the coma after the last bracket
maxUploadSize: "500mb"  //you will now have 500mb limit :)
});

Comment: Is it built in to allow this to be configured with an environment variable?


Add class to ul element in views 3 unformatted list using templates or module code?

Question: I'm contributing to the Radix theme in D7 for panopoly, which uses Twitter Bootstrap.
I'm seeking out ways to implement as many of twitter bootstrap's awesome capabilities as possible, and thus not have to rely on overriding theme css, and to make it work 'natively' and rely on cleaner CSS.
So, the 'unstlyed' list property in Twitter Bootstrap is a perfect example of this.

...

However, I can't figure out how I would add this class to the views unformatted style by default using the theme.  Is this possible with template files, template.php code or an include file?  I would prefer to do this within the radix theme.  Help!
Comment: views-view-list.tpl.php would be the tpl file for views lists (grab from views theme and add to the radix templates view folder), but you would have an all or nothing modification if you went this route as you'd hard code in the class.
Answer: You could use the rewrite option in views to get the exact html output you need. Rewrite enables you to override the output of this field with custom text or replacement tokens. I use the last field, since the replacement tokens should be above the field you are rewriting. Make sure to go through set the field, label, wrapper html to None
In Views

Click on a Field
Click on Rewrite the output of this field
Add your code with the desired html output

Code

[field_degree]

[field_major]

Output

Certificate

Supervision

OR you can

Click Advanced
Click CSS class
Add the name of your class "unstyled" to the entire view.


Is there some way to convert a json file to an object model in Deno?

Question: Issue: When i try to read a file (student.json) and store it in a variable of type Student[] it says "Type 'unknown' is not assignable to type 'Student[]'." This is a typescript file.
import { Student } from "../Models/studentModel.ts";
import { readJson, writeJson } from "https://deno.land/std/fs/mod.ts";

const f = await readJson("../public/student.json");
const students:Student[] = f;

export const get_all_students = (ctx: Context) => {
  return ctx.json(students,200);
};

Expectation: I am trying to return the json from the file to the server.
Solutions tried: I have tried  Json.stringify(). It still gives me the same error.
Comment: Can you include the studentModel.ts and a fraction of the student.json?
Comment: https://github.com/denoland/deno/issues/6438
Answer: readJson method return promise type of unknown. The unknown type is only assignable to the any type and the unknown type itself.
If you want to force the compiler to trust you that a value of type unknown is of a given type, you can use a type assertion like this:
 const f = await readJson("./public/student.json");
 const students:Student[] = f as Student[];

Comment: Thank you. Type assertion is the way to go.
Answer: To solve the above error just use a type assertion:
const students = f as Student[];

I'm not familiar with deno, but pretty sure you could just write the file to response stream or serve it with appropriate headers. Not sure if that makes sense for your scenario.
Comment: Thanks. Didn't know about type assertions in TypeScript. Solved my problem right away.


Maximum Likelihood with Least Squared Error

Question: In the book Tom Mitchell - Machine Learning, while deriving Least Squared Error from maximum likelihood, the author considers the training dataset of the form: $<x_i, d_i>$ where:
$$d_i = f(x_i) + e_i$$
Here, $f(x_i)$ is the noise free value of the target function and $e_i$ is the random variable representing noise, which is distributed according to normal distribution with $0$ mean.
The author then says that given the noise $e_i$ obeys a Normal distribution with 0 mean and an unknown variance $\sigma^2$, each $d_i$ must also obey a Normal distribution with variance $\sigma^2$, centered around the true target value $f(x_i)$.
Can anyone please explain that if the error $e_i$ is Normally distributed, then why should $d_i$ also be Normally distributed ?
Comment: See https://en.wikipedia.org/wiki/Normal_distribution#General_normal_distribution. So if $f(x_i)$ can be treated as a constant (sometimes, you will encounter the terminology "fixed regressor" in econometrics), the linked result applies.
Comment: I rather mean that $f(x_i)$ is not a random process itself, but something which can be controlled through, say, experimental design. I assume that the author has such a scenario in mind when he writes about the "noise free value of the target function". Think the value of some drug mice get in analyses of the efficiency of a new drug. Of course, each $f(x_i)$ can be different, resulting in a different mean for each unit $i$.
Comment: @ChristophHanck So when you say that $f(x_i)$ can be treated as constant, you mean that for every x, ($x_1, x_2....x_n$) [considering n points], f(x) = c, which I don't think is the case here. For every new $x_i$, we will get a new $f(x_i)$
Answer: Let $z \sim \mathcal{N}(\mu, \sigma)$.  Then
$$ \dfrac{z-\mu}{\sigma} \sim \mathcal{N}(0,1)$$
Conversely, if $x \sim \mathcal{N}(0,1)$, then
$$ \mu + \sigma x \sim \mathcal{N}(\mu,\sigma)$$
The noise is normal $e_i \sim \mathcal{N}(0,\sigma)$, so if I add some noiseless constant to this random variable, the mean changes
$$ f(x_i) + e_i = d_i \sim \mathcal{N}(f(x_i), \sigma)$$
EDIT:  There is a slight abuse of terminology in most regression text.  Note that $d_i$ corresponds to observations of $x_i$.  So this means the conditional distribution of the outcome is normal, not the marginal.  Mathematically
$$ d_i \vert x_i \sim \mathcal{N}(f(x_i), \sigma)$$
Answer: Brief expansion of user Christoph Hanck's comment:
The measurements $x_i$ are assumed to be known exactly.* Under this assumption, $f(x_i)$ is distributed like a normal distribution with mean $f(x_i)$ and variance $0$. If $e_i\sim\mathcal{N}(0, \sigma^2)$, it follows that
$$\underbrace{d_i}_{\sim\mathcal{N}(f(x_i), \sigma^2)} = \underbrace{f(x_i)}_{\sim\mathcal{N}(f(x_i), 0)} + \underbrace{e_i}_{\sim\mathcal{N}(0, \sigma^2)}.$$
*This assumption can of course be criticized, see, e.g., this question.
Comment: If $x_i$ are assumed to be known exactly, then why will $f(x_i)$ always form a Normal Distribution ? - This doesn't seem correct
eg if the function f is an exponent function, then $f(x_i)$ will not form a Normal Distribution
Comment: @SaurabhVerma $f(x_i)$ follows a Dirac distribution, which can be represented as the limiting case of a normal distribution for $\sigma^2 \to 0$.
Comment: See, e.g., [here](https://math.stackexchange.com/questions/2072415/proof-that-the-limit-of-the-normal-distribution-for-a-standard-deviation-approxi) or [here](http://hitoshi.berkeley.edu/221a/delta.pdf).
Comment: I see where your confusion comes from - been there. :) The key is that $x_i$ follows a Dirac distribution, and you can transform a Dirac distributed variable nonlinearly as much as you want; it stays a Dirac distribution.


Jazz Theory: ii-V7-I Progression

Question: I'm working through Mark Levine's Jazz Theory book... at the start of Chapter 2 (page 15 first example) where he introduces the ii-V7-I progression in Eb major, he writes a progression that goes F-7 -> Bb7 -> Eb(delta symbol).
According to the start of the book he says the delta symbol (looks like a triangle) after a chord means that it is a Major Seventh Chord. However, the EbM7 used in the progression outlined above contains an F nat instead of a D nat.
Wouldn't it be a Eb-add9 chord and not a Eb7 if you use an F natural instead of the D natural?
The notes are: (Eb,F,G,Bb)
Coming from a tonal theory background, I am genuinely confused at why jazz musicians consider a Eb-add9 the same as a EbM7?
Answer: Page 15, right! On a dark night it would pass for an Eb maj9. It's not the only place in the book with spurious chords/names. I've started compiling a list of questionable statements, etc, either they're inaccurate , not explained well, or I'm not reading them right. Having said, it's a well thought of book, and contains many nuggets.
The basic premise fot ii-V-I is using four notes for each chord, as opposed to triads. You'll notice in figure 2-1 the Fm7 has F, Ab, Eb and G - actually an Fm9 - the 5 of chords is often laid to rest. Then Bb7 is Bb9.
When you get to page 59, there's an interesting c7b9 chord, written with C# in the dots...
Comment: The real question now boils down to: was this a typo, or should take the idea of a 9th as a replacement for a 7th in this context?
Comment: I found another possible example for your list: look at `page 43 figure 3-24` He has a Gsus => G7 except he uses an `a` in both chords; This also seems like a typo because you get the notes `(G,C,F,A)` => `(G,B,F,A)` which would make me think it should be notated as a Gsus11 => G7add9 ?
Comment: @KolobCanyon - thanks - I clocked the same sort on the following page some time ago! Surely, if something is being explained, accuracy or an explanation of why it's called that is needed. Typo? Who knows, but there seem to be quite a few.
Comment: @KolobCanyon - he is very careless about spelling throughout the book. He just doesn't care about correct spelling-sometimes he just uses enharmonics that aren't really correct, other times it's hard to understand what he's talking about. Tim-remember we discussed this a while back? It's a good book for getting 'the lay of the land' but  hard to nail down specifics there. That book gets the hype but after looking at quite a few, this one might be the best (not in ebook form): [**_Bert Ligon-Jazz Theory Resources_**](https://www.amazon.com/gp/product/0634038613/ref=oh_aui_detailpage_o01_s00)
Answer: Jazz musicians don't consider an Ebmaj7 chord the same as an Eb add9 chord. However, in many situations both chords can be used as a I chord in a major key.
Let me add some general background information, and one good reason why in a certain situation you might want to replace the maj7 chord by another chord which doesn't contain a major 7th.
An EbΔ chord indeed means a major seventh chord (see this question and its answers); so you have the notes
Eb - G - Bb - D
In jazz, the I chord in a major key can come in different flavors. One option is the major seventh chord, another the sixth chord (Eb6, with a C instead of the D), yet another a major ninth chord (with the D and the F added), and others. In your case, the author seems to have used an "Eb add 9" chord, i.e., an Eb major triad with an added F. Depending on the octave of the note F, that chord could also be called "Eb add 2".
If the melody allows it, any of these chords can be used as I chord. One case where you would not use an Ebmaj7 chord as the I chord, but rather an Eb6 (or Eb add 9) instead is when the root note Eb is used in the melody, because then you'd get a minor ninth interval between the D in the Ebmaj7 chord, and the Eb in the melody (assuming that the Eb is in the higher octave). Apart from that case, you can usually use any of the chords mentioned above.
Comment: I think the crux is - why did he write the chord symbol Ebmaj7 above an obviously different chord written in the dots? It's an educational book!
Comment: I guess it may be because you explained the different flavours of a I chord in jazz, but didn't say why you thought Levine used it in the example instead of the quoted Ebmaj7. 'Tweren't me - I always give a reason, otherwise the exercise is like a broken pencil - pointless.
Comment: @tim: Thanks for you comment. Anyway, I cannot know what Levine thought, and I don't have the book at hand to look at the example. I did give one frequent reason to avoid the maj7 chord in the last paragraph of my answer. This *could* also be the reason why the add9 chord is used, but that's just a guess. Otherwise, they can all be exchanged for one another, so any there need not be any specific reason other than that the author/composer just prefers one over the others.
Comment: @Tim: If he did so, then that's a serious problem in such a book.
Answer: The F would actually be a chordal ninth, not a sixth. (A sixth above Ef would be C.)
Adding upper extensions is pretty standard in jazz theory, so in this case the Efadd9 chord is considered more or less equivalent to the EfMaj7.
Edit: After looking at this example in my copy of the book, I wonder if it might actually be a typo on account of the treble clef ledger lines. Every other Maj7 chord on this page clearly has a major seventh...
Comment: What's really confusing to me is that it doesn't even contain the 7th. It would make total sense to me if it was an embellishment (e.g. contained the 7th and the 9th) but it is clearly labeled as a Major-Seventh chord but has no seventh
Answer: A major (pun intended) consideration to keep in mind is the improvisational nature of jazz. When you look at a lead sheet like this one, you can bet that every chord written on the page will be played 10-20 times. If we play each chord with the exact same voicing (the exact same combination of notes) every time, it will quickly become boring. So instead of dictating too many details, chord symbols often give just enough information for the comping instruments the guidance to avoid wrong notes but the freedom to use many different voicings.
So, the chord E♭Δ can be "voiced" many different ways. Adding upper extensions like the 9th does not change the quality of the chord, and neither does taking away those upper extensions. In fact, any note from the relevant scale(s) can be added to or removed from the chord, and as long as we're avoiding certain notes (like D♭) that would change the chord quality, we're all set. That said, finding voicings that sound good--and knowing when to use them--is an art form in and of itself.
Removing the 7th and adding the 9th doesn't necessarily change the chord from being an E♭Δ chord, because the chords are established more broadly by the context of the song (e.g., what the other musicians are playing over that chord, what voicings were played over that chord in previous choruses, what chord famous recordings use in that measure, etc.).
Comment: Also, a note from the melody may be added _or left out_ of a chord voicing. It seems like I often use an add9 or a 6 chord when playing chord melody on guitar if the 7th is in the melody over a major 7th chord (or even in the vicinity of a major 7th chord).
Comment: It's said that, apart from the root (which gives a chord its first name). the other important notes are 3 and 7. 3 denotes (sic) major or minor, and 7 can be any one of three different notes. I'd have thought that if a chord is written Ebmaj7, then the D ought to be included, whatever else is there. Levine has, in my opinion, plenty of sloppily written items, and could explain a lot better than he does. I stopped using the book because of this.
Comment: @Tim, I'm sure you're right that there are genres where, if the chord symbol is Ebmaj7, then the musicians and audience will expect the D. Factually, we can listen to a bunch of jazz records and hear that this isn't the case for many sub-genres of jazz. Pianists may not leave out the 7th on the *first* iteration through the form, but it happens frequently when comping over solos, etc.
Comment: I'm sure you're right, too. But in those cases, why bother putting any more than 'Eb' against that bar? We can mostly tell what extensions will fit, by the context around it. My beef is that it's supposed to be an educational book, and if I was as vague (inaccurate?) with my students, they wouldn't be happy - and neither would I !
Comment: @Tim, that makes sense to me and is a fair criticism. When I was learning rootless two-handed voicings for major chords, first I learned a voicing with the major 7th (G-D-F-Bb-Eb), and then I learned a quartal voicing with the 6th/13th in place of the 7th (G-C-F-Bb-Eb for Eb major). My teacher told me that the quartal voicing is a more modern sound, and it's still a good voicing for Eb∆ because it won't conflict with a soloist who is playing over Eb ionian. The interchangeability is an important lesson to teach early on, but it's important to explain the fact that interchange is occurring.
Comment: @Tim, the reason for not putting Eb is that it creates ambiguity about whether the 7th (if added/included) would be major or flatted. If I saw "Eb" on a jazz chart, my default mode as the comping instrument would be to never add a 7th on that chord (either flatted or major).
Comment: I tend to put some sort of 7th often; it's dictated by the sequence, sometimes spontaneously, sometimes after the first time around, as then I can judge which fits better, even if it's not notated.
Comment: @Tim, I'm thinking more of scenarios where any 7th at all sounds off. St. Thomas comes to mind. **[This lead sheet](http://www.guitarcats.com/images/JazzStandardCharts/Saint%20Thomas-315.jpg)** shows the first chord as C, but **[this lead sheet](http://2.bp.blogspot.com/-8_MVYt1vaF0/Vg1nIqfOZbI/AAAAAAAAHRc/uum1VsA_INE/s1600/st_thomas.jpg)** shows a C69 chord. Both a CMaj7 and C7 could sound a little odd unless the soloist clearly takes it in that direction. If I saw a "C" with nothing else, I would avoid the 7th altogether unless I heard the soloist playing either the major 7 or the flat 7.

Jazz Theory: ii-V7-I Progression


To evaluate the limits $\lim\limits_{n \to \infty} \{\frac{1}{1+n^3}+\frac{4}{8+n^3}+\ldots +\frac{n^2}{n^3+n^3}\}$

Question: To me it seems like that we need to manipulate the given sum into the Riemann sum of some function. First writing in the standard summation form;
$$\{\frac{1}{1+n^3}+\frac{4}{8+n^3}+\ldots +\frac{n^2}{n^3+n^3}\}=\sum\limits_{k=0}^n \frac{k^2}{k^3+n^3}$$
I have tried factoring out $\frac{1}{n}$ from the above sum. But I cant seem to get into the right form. Any help!
Comment: See http://math.stackexchange.com/questions/1279816/find-the-limit-lim-n-rightarrow-infty-sum-k-1n-frac1kn  and observe : $$\frac{k^2}{k^3+n^3}=\dfrac1n\cdot\dfrac{(k/n)^2}{(k/n)^3+1}$$
Comment: You can use sandwich law. What is the biggest numerator? and what is the smallest denominator? How can you bound the sum?
Comment: @labbhattacharjee That seems to do it. The answer turns out to be $\int_{0}^1 \frac{x^2}{1+x^3} = \frac{1}{3} \log 2$.
Comment: @lab bhattacharjee: Hmmm... It seems I'm very slow in using mathjax :( Please turn your comment as an answer; I'll delete mine.
Answer: You can proceed from here as $$\lim_{n\to \infty}\sum\limits_{k=0}^n \frac{k^2}{k^3+n^3}= \lim_{n\to\infty}\sum\limits_{k=0}^n \;\frac{1}{n}\frac{\frac{k^2}{n^2}}{\frac{k^3}{n^3}+1}= \lim_{h\to 0} \;h\sum_{k=1}^n \frac{{(kh)}^2}{1 + {(kh)}^3}= \int_0^1 \frac{x^2}{1+x^3} \mathrm{d}x\;.$$
Comment: Wow! Lab bhattacharjee has answered it already. ; /
Comment: Why the downvote? It seems it is wrong to post a right answer, isn't it?
Answer: Note that
$$\frac{k^2}{k^3+n^3}=\dfrac1n\cdot\dfrac{\left( \frac{k}{n} \right)^2}{\left( \frac{k}{n} \right)^3+1}$$
so you can rewrite the summation to be
$$\begin{align}\lim_{n\to \infty} \Big(\frac{1}{1+n^3}+\frac{4}{8+n^3}+\ldots +\frac{n^2}{n^3+n^3}\Big) &= \lim_{n\to \infty} \sum\limits_{k=0}^n \frac{k^2}{k^3+n^3}\\
&= \lim_{n\to \infty} \sum\limits_{k=0}^n \dfrac1n\cdot\dfrac{\left( \frac{k}{n} \right)^2}{\left( \frac{k}{n} \right)^3+1}\\
&= \lim_{h\to 0} \;h\sum_{k=1}^n \frac{{(kh)}^2}{1 + {(kh)}^3}\\
&= \int_0^1 \frac{x^2}{1+x^3} \mathrm{d}x\;\\
&= \frac{1}{3} \ln(1+x^3) \Big|_0^1\\
&=  \frac{1}{3} \ln 2
\end{align}$$
Comment: You are late :P
Comment: yup, ahhaha sorry I just seen all answers :(


Android getAllCellInfo() returns null

Question: I'm new to android, and I work on a project that goes to collect all cells information that observed by phone. I have used TelephonyManager.getAllCellInfo() method, but it always returns null.
My Code ::
public class NetworkCoverageActivity extends AppCompatActivity {
    private String str;
    private TextView TV;
    private Button getCellsInfoBtn;
    private TelephonyManager TM;
    private List<CellInfo> cellInfoList;
    private PhoneStateListener PSL;
    private int event;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_network_coverage);

        TV = (TextView)findViewById(R.id.iv);
        getCellsInfoBtn = (Button)findViewById(R.id.getCellsInfoBtn);
        TM = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        PSL = new PhoneStateListener();
        event = PSL.LISTEN_CELL_INFO | PSL.LISTEN_CELL_LOCATION;

        getCellsInfoBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                TM.listen(PSL, event);
                cellInfoList = TM.getAllCellInfo();

                if(cellInfoList != null)
                    TV.append("cellInfoList = null");
                else{
                    ...
                }
        }
    });
}

I'm working on android 4.4.2 level 17 and set min API level to 17. and I try to collect information from GSM network.
Also, I added the following permission to AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

Comment: possible duplicate http://stackoverflow.com/questions/16541172/getallcellinfo-returns-null-in-android-4-2-1
Comment: Some of the devices such as Samsung,Huawei doesn't have these API's which always return null.
Comment: As per the docs: This method is preferred over using getCellLocation(). However, for older devices, getAllCellInfo() may return null. In these cases, you should call getCellLocation() instead. Also, if no info is available, null is returned.
Answer: I have got the solution of my question. that's replaced getAllCellInfo() function by getNeighboringCellInfo() function, although I am running with android level 17 that should be support getAllCellInfo() function and getNeighboringCellInfo() function should be no longer supported.
Anyway, the following is the solution.
package ayad.bslm.com.networkcoverage;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.NeighboringCellInfo;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.List;

public class NetworkCoverageActivity extends AppCompatActivity {

    private TextView TV;
    private TelephonyManager TM;
    private List<NeighboringCellInfo> neighboringCellInfoList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_network_coverage);

        TV = (TextView)findViewById(R.id.iv);
        Button getCellsInfoBtn = (Button)findViewById(R.id.getCellsInfoBtn);
        TM = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

        getCellsInfoBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                neighboringCellInfoList = TM.getNeighboringCellInfo();

                if(neighboringCellInfoList == null)
                    TV.setText("neighboringCellInfoList == null\n");
                else
                    TV.setText("There are " + neighboringCellInfoList.size() + " Cells\n");
            }
        });
    }
}

Android getAllCellInfo() returns null


Empirical bootstrap CI - sample only has one data point

Question: I just learned about the empirical bootstrap and how it can be used to estimate confidence intervals. However, does the bootstrap work for the degenerate case where the sample only contains one data point?
In other words, is the following a valid application of the empirical bootstrap? Let's assume that we want to use empirical bootstrap to find an 80% confidence interval for the mean:

Sample a single data point $x_0$. The sample mean is $\bar{x} = x_0$.
Resample for n rounds, resulting in n resamples $x_0^*, x_1^*, ..., x_n^*$, where each contains a single data point $x_0$.
Compute the difference between each resample mean and the sample mean: $\delta_i^* = x_i^* - \bar{x} = x_0 - x_0 =0$.
Rank the differences and take the 10th and 90th percentiles, $\delta_{0.9}^*$ and $\delta_{0.1}^*$, which are both 0.
Compute the confidence interval as $[\bar{x} - \delta_{0.1}^*, \bar{x} - \delta_{0.9}^*] = [\bar{x}, \bar{x}] = [x_0, x_0]$.

The resulting confidence interval seems to implies a level of confidence that is incongruent with our intuition that a single data point would result in an unconfident estimation.
Is this a valid application of the bootstrap? If so, how do we know when to trust the results of the bootstrap - should we verify the sample size?
Reference: https://ocw.mit.edu/courses/mathematics/18-05-introduction-to-probability-and-statistics-spring-2014/readings/MIT18_05S14_Reading24.pdf.
Answer: The reference you included mentions this:

The bootstrap is based roughly on the law of large numbers, which says,
  in short, that with enough data the empirical distribution will be a good approximation of the true distribution. Visually it says that the histogram of the data should approximate the density of the true distribution.

This should give you the first hint that your example is probably not a good idea - the empirical distribution of a single data point is probably not a reasonable approximation to the "true" distribution, whatever that is.
Rubin's wonderful The Bayesian Bootstrap is a little more specific about some assumptions of the classical and Bayesian bootstraps:

...is it reasonable to use a model specification that effectively assumes all possible distinct values of X have been observed? Both the [Bayesian Bootstrap] and the [classical] Boostrap operate under this assumption. (p.4, Section 5; "Discussion of Model Specifications")

This should indicate in a straightforward way, I think, that your example is not a valid application of the bootstrap - unless the support of your random variable contains only $x_0$, your inference is making some curious model assumptions.
You may very reasonably point out that that's a surprising model specification - for example, it will never be satisfied for any continuous distribution! Rubin would, I think, agree with you, and point out that there's no quick fix here, along with the fact that blindly applying the bootstrap in all cases will hardly be a guarantee of good results. This assumption may be "close enough" for many cases, but a reasonable sample size and coverage over the support of the random variable are necessary to invoke a technique like this. He memorably concludes that article by noting that

Serious data analyses should always include serious consideration of model constraints...although the bootstrap and the BB may be useful in many particular contexts, there are no general data analytic panaceas that allow us to pull ourselves up by our bootstraps. (p. 5).
Comment: Thank you for the detailed answer! It makes sense that the bootstrap relies on the assumption that the empirical distribution is close to the true distribution, and that this assumption is violated when the sample is of size one.
Comment: You're quite welcome!


efficient algorithm for solving equation $\sum_n a_n/(x - x_n ) = 1$

Question: Here $x_n $ are real and $a_n$ are positive, and we have a finite summation.
The picture is very clear.
But what numerical algorithm is stable and efficient? Supposed $x_n $ are ordered in the increasing order, then between $x_n $ and $x_{n+1}$ there must be a root. One can use the bisection method, but it is slow. Or one can try Newton's method, but it is not necessarily stable.
Comment: @JackD'Aurizio.  Answer posted as promised.
Comment: Claude Leibovici is one of the greatest experts about this, let us try to summon him: @Claude Leibovici
Comment: It is now diner time. Be sure I shall write tomorrow morning. Cheers :-)
Comment: A trick I suggested once is to multiply $-1+\sum\frac{a_n}{x-x_n}$, when locating the root between $x_k$ and $x_{k+1}$, by $(x-x_k)$ or $(x-x_k)(x-x_{k+1})$, in order to ensure convexity/concavity (hence stability of a suitably arranged Newton's method) in a neighbourhood of $\frac{x_k+x_{k+1}}{2}$, or $x_{k}^+$, or $x_{k+1}^-$.
Comment: @ClaudeLeibovici Before answering... Just tell us what you've had for dinner Claude??? Friday dinner in Pau should be good!
Comment: @mathcounterexamples.net. Come to Pau and, being my guest, you will se ! Cheers :-)
Answer: I do not know the context of your problem but we worked a lot over years the problem of the solutions of the so-called Underwood equation which appear in shortcut distillation problems. It uses to write
$$\sum_{i=1}^n \frac{\alpha_i\, z_i}{\alpha_i- \theta}=1-q$$ where the $\alpha_i> 0$ and $z_i >0$ and $n$ can be very large (potentially up to thousands) and $q$ is given.
In chemical process design, this equation has to be solved zillions of times (optimization problems with hundreds of variables). Because of that, we needed very fast, stable and robust solutions.
Our most recent work was published in $2014$ in this paper (you can also find it here) where we proposed rapid and robust solution methods using convex transformations. Beside, and this is a key point, for any root, we proposed simple and efficient starting guesses which,typically,  make that very few iterations are required (this is illustrated in the first figure showing that the starting guess is almost the solution).
I consider that the paper is sufficient clear and detailed (with several examples) for helping you. In the case you have any problem, feel free to contact me (my e-mail address is in my profile).
Edit
If you want something simpler, considering for example (easy to generalize)
$$f(x)=\sum_{i=1}^6 \frac{a_i}{x- b_i}-1$$ for the root between $b_1$ and $b_{2}$ consider instead
$$g_{(1,2)}(x)=(x-b_1)(x-b_2) f(x)$$ which is
$$g_{(1,2)}(x)=a_1
   (x-b_2)+a_2 (x-b_1)-(x-b_1) (x-b_2)+$$ $$(x-b_1) (x-b_2)
   \left(\frac{a_3}{x-b_3}+\frac{a_4}{x-b_4}+\frac{a_5}{x-b_5}+\frac{a_6}{x-b_6}\right)$$ and then
$$g_{(1,2)}(b_1)=a_1 (b_1-b_2)\qquad \text{and} \qquad g_{(1,2)}(b_2)=-a_2 (b_1-b_2)$$ and now use for example subroutine rtsafe from "Numerical Recipes"  that utilizes a combination of bisection and Newton-Raphson steps (this is required since, between the bounds $b_1$ and $b_2$, function $g_{(1,2)}(x)$ goes through an extremum); the code is here. This works quite well without any convergence problem (but it is much less efficient than what was proposed in our paper). As you can see, the simple idea is just to remove the asymptotes (this is the so-called Leibovici & Neoschil method which has been widely used for this class of problems during the last $26$ years).
You could even restrict the search to the interval $(b_1,x_*)$ or $(x_*,b_2)$ where $x_*=\frac{a_1b_2+a_2b_1}{a_1+a_2}$ obtained by linear interpolation (you just need to check the value of $g_{(1,2)}(x_*)$).
Comment: (+1) as deserved.
Comment: @JackD'Aurizio. if you have time to waste, would you accept to read the paper and be critical ? Thanks.
Comment: I will do it, sure. I was just wondering: has anyone ever proposed a hybrid between your method and methods for simultaneous root finding through companion matrices?
Comment: Also: do you recall the first time we discussed about this problem here on MSE? I am not managing to find that relevant thread.
Comment: @JackD'Aurizio. You are totally wrong ! Big difference : **rhs=0**. It is https://math.stackexchange.com/questions/543020/searching-for-tighter-bounds . For sure, I remember. I spoke at noon about this answer from you to my coworker and coauthor of the paper. Cheers?
Comment: Of course you're right, but the idea of gaining convexity from a suitable separation of the terms defining $f(x)$ still applies to the $\text{RHS}\neq 0$ case, and can probably be used both for gaining good initial guesses and for ensure the stability of Newton's method or the secant-tangent method.
Comment: Sorry, but I cannot see why studying $g$ is simpler than $f$. What specific property does $g$ have?
Comment: @S.Kohn. Since the asymptotes have been removed, much less problems, faster convergence and so on. To that, add the initial estimates of the solution. Have you been able to look at the paper. Cheers.
Comment: @ClaudeLeibovici  I am now reading your paper. It is not so easy to follow. In equation (5), the variable $a$ suddenly pops up.
Comment: @S.Kohn. This is referring to a previous paper on a "similar" topic $(rhs=0)$. We did publish many papers in this specific area because of the very high importance of these equations in the industrial area (oil and gas mainly). My fist paper in this topic was in 1993.
Answer: This looks to me like the secular equation which is used in divide and conquer algorithm for the symmetric eigenvalue problem so it is widely studied and efficient and stable implementation should be available.
Here is an overview paper: A numerical comparison of methods for solving secular
equations
Here are some slides from Golub for secular equation.
Answer: Extended comment: This problem looks close to the central relation for the Durand-Kerner method: For a polynomial of degree $n$ and $n$ root approximations $z_1,...,z_n$ consider the partial fraction decomposition
$$
\frac{p(x)}{\prod_{j=1}^n(x-z_j)}=1-\sum\frac{w_j}{x-z_j}.
$$
Then by multiplying with $x-z_m$ and setting $x=z_m$ one finds $$w_m=-\frac{p(z_m)}{\prod_{j\ne m}(z_m-z_j)},$$ and the next root approximations are $z_j'=z_j+w_j$.
V. Pan published several papers/tech reports on fast computation of this iteration, acceleration of convergence beyond the Durand-Kerner, Aberth-Ehrlich methods, multi-pole expansion,... that make extensive use of the first equation.


Fast parallel multiplication method

Question: In page 6 of A very fast multiplication algorithm , how do the PAR-allel multiplication work ?
Why is 12021011 equivalent to 299 ?
Parallel Multiplication method
Answer: 12021011 is $100101011_2 = 299_{10}$ before the carry.
The rough idea of algorithm:
(1) divide the factors in chunks,
(2) do in parallel the product of chunks,
[now, we must shift and add the (many) chunks]
(3) do in parallel the shifts,
(4) take the (say) S shifted chunks in subsets of 2 and do in parallel the S/2 sums,
(5) repeat the procedure with the S/2 sums
...
Comment: Why is 12021011 equivalent to 100101011 in binary ?
Comment: Ok, I got it now. But why is this parallel multiplication method faster than [carry save array multiplier](https://i.imgur.com/oNmRaRa.png) ? Note that those '2' also needs additions by itself ....
Comment: @kevin it is hardware implementation. You should look at Wallace tree, carry save adder, carry skip adder to understand better.
Comment: @kelalaka Wallace tree is no longer used now due to its irregular and famously long routing.

Fast parallel multiplication method


Harmonic stop on cello without fingers

Question: I'm writing a solo cello piece, and I'd like one of the strings to stopped at the first harmonic (specifically, the G string) for the duration of the piece; The trick is, I need this to be done without the cellists fingers, so that they are free for other strings.  I was thinking maybe an earplug tucked between the string and the fretboard might provive the right amount of pressure, but I'm not sure, and I don't have a cello to test this out on.  Maybe there is already an established way to do this, but I've never seen it before.
Cellists, do you know of a better way to achieve something like this?
Comment: It's an intriguing idea, but I really doubt it's possible. An earplug would probably be too much pressure and take up to much string space to do anything other than mute it. Could you provide a few details about why you want to do this? I'm assuming the cellist needs to be able to play notes on the A, D and C strings but that the G never needs anything other than the harmonic? This evening I'll try a few things on my cello and see if anything does the trick.
Comment: I might try a wedge of soft wood, such as balsa. This could be easily placed under a single string,but it'll be a 'hard stop,' so you'll get the pitch you want but not a harmonic.  The problem you'll have is convincing a publisher to issue a wedge with each printed copy of sheet music!
Comment: There something like that for guitar, http://www.weaseltrap.com/capo.html. Perhaps they might do a custom order for a cellist?
Comment: That's correct, I'm hoping to allow C and D strings to be played normally at the same time as a sustained harmonic on the G string.  Thanks for your help!
Comment: That's kind of what I was thinking might work - or a triangular piece of rubber - something that creates a thin node point. But you'd need to make sure it doesn't work itself loose while bowing that string, I guess...
Comment: Earplug wouldn't work -- too soft. It would only act as a mute (and a bad one at that).

Guitars have frets, and the same thing would work here. By taking a small block of wood (most importantly a thin one) and just putting it there, you could create a consistent tone in that spot. As for harmonics...do you mean harmonic G? There are a bunch of ones in 1st position, but the wood block wouldn't work for them. I don't know of any way to replicate harmonics without fingers, but if it's a high-up harmonic, it wouldn't be an issue as you can just have the wood positioned to play the equivalent.
Comment: Let's see if we can define the problem. You need something that affixes to the violin securely, preferably above the nut, and touches the string's node lightly. Possibly something that can experimented on with a thick elastic band and stiff copper wire (with any sharp points or edges filed down or bent away from the fingers and instrument)?
Answer: Use something hard pushing the string away from the fingerboard.  Hard, just like the objects in John Cage's compositions for prepared piano: screws, clothespins, very hard rubber, etc.  Of course cellists don't want to damage their fingerboards or strings, so some compromise must be made.
Answer: (N.B. It is not a "fretboard", the cello has no frets; it is a fingerboard.)
An alternative would be to swap from a solo cello piece to a piece for two cellos. I would not necessarily call this a duet since one cellist would just be playing the first harmonic on the G string for the duration of the piece. This would also give you the option to change the droned harmonic occasionally during the piece.
There may be something in the ether at the moment of this kind of ensemble. I recently saw Nico Muhly's drones & violin and his drones & viola performed as part of the A Scream and an Outrage weekend.

Harmonic stop on cello without fingers


Como faço para conectar um programa em java com oracle 10g?

Question: Já tentei fazer o código abaixo mas não deu certo, estou usando Oracle 10g.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class AcessoBanco {

    public static void main(String[] args) throws Exception{
        String sql = "select id_usuario, nome_razao from usuario";
        String url = "jdbc:oracle:thin:@localhost:1521:xe";

        try(
        Connection con = DriverManager.getConnection(url, "david", "5550123");
        PreparedStatement stm = con.prepareStatement(sql);
        ResultSet rs = stm.executeQuery()){
            while(rs.next()){
                System.out.println(rs.getString("nome_razao"));
            }
        }
//      rs.close();
//      stm.close();
//      con.close();
    }
}

Comment: descreve o que exatamente você quer dizer com `não deu certo`
Answer: Você deve fazer o download do driver JDBC no seguinte link: Oracle Database 10g Release 2 JDBC Drivers.
Inclua o jar baixado ao Build Path do seu projeto.
Faça seu código carregar dinamicamente a classe oracle.jdbc.driver.OracleDriver antes de chamar o método getConnection(), assim:
Class.forName("oracle.jdbc.driver.OracleDriver");

Se código vai ficar assim:
try(Class.forName("oracle.jdbc.driver.OracleDriver"); //repare nessa linha
        Connection con = DriverManager.getConnection(url, "david", "5550123");
        PreparedStatement stm = con.prepareStatement(sql);
        ResultSet rs = stm.executeQuery()){
    while(rs.next()){
        System.out.println(rs.getString("nome_razao"));
    }
}

Comment: Mas eu já estou na classe principal, deu erro.
Comment: @user4873 veja o meu try como ficou


Why does mailman replace non-Latin letters with crooked ones?

Question: The essence of the problem is that when sending an html letter with formatted text inserted from another source containing non-Latin letters (for example, copied text from a web page in Polish), the letter reaches the mailing addressees with corrupted text: instead of non-standard letters (ą , ę, ż, ź), which are not in the English alphabet, codes in the form "С=3" are inserted, which makes the text unreadable. Plus, all the text formatting and tables in this email are falling apart. It turns out to be a mess of English letters, special symbols and numbers. How is this treated and is it treatable at all?
p.s. When sending the same letter directly to one or more recipients, the formatting does not break. The problem only occurs when sending via mailman to mailing lists. The problem does not occur 100% of the time. It all depends on the source from which the formatted text is copied. In all observed cases, it helps to first copy the text into Microsoft Word, and then from it into Thunderbird before sending.
Comment: I'll comment that the problem is that the HTML-formatted letter into which you're inserting the text is not marked as using the UTF-8 charset. When you copy into Word, then paste from there into TBird, Tbird sees that the text is Unicode and includes the charset indicator. There may be a way to tell TBird to  default to UTF-8, which should resolve this, but I'm not an expert at what's available in its settings.
Answer: It is not corrupted nor crooked, but Quoted-Printable Content-Transfer-Encoding (RFC 2045, 6.7).

The Quoted-Printable encoding is intended to represent data that
largely consists of octets that correspond to printable characters in
the US-ASCII character set.  It encodes the data in such a way that
the resulting octets are unlikely to be modified by mail transport.
If the data being encoded are mostly US-ASCII text, the encoded form
of the data remains largely recognizable by humans.

The form is not C=3 but the sequences start with = followed by two hexadecimal characters. E.g., unicode  U+1F913 nerd face is f0 9f a4 93 in UTF-8 and becomes =F0=9F=A4=93 in Quoted-Printable.


Ideal scoring rules for multitask classification?

Question: I am seeking advice for the best way to score a multi-output/multitask classification model's output.
Problem setup
A simplified version of the model is as follows:

Training data have F features, say they are descriptors of people (ethnicity, hair color, eye color, medical data)
Target variable is age

Obviously this is a regression problem, but just for fun I'd like to frame it as a classification problem using these bins:

Age <= 25,
25 < Age <= 35,
35 < Age <= 45, and
Age > 45

For each input "person" X, my model currently outputs probabilities of membership in each bin, that is: ( P(X <= 25yo), P(25yo < X <= 35), P(35yo < X <= 45yo), P(X > 45yo) ).
Main Question - How to score model output?
The low-hanging-fruit metric is calculating percent accuracy by finding the highest-probability age for each test-set person and comparing their binned real age, but I've read good arguments for using proper/strictly-proper scoring rules (e.g. Brier score/MSE, log scoring rule) instead of percent accuracy for binary classifiers from Frank Harrell and others here. I can't seem to find a classification scoring rule that generalizes to n-output/target variables, as there is in my my case where continuous output is discretized into mutually exclusive bins.
I could cook up some generalized metric by computing MSEs for each bin or something similar, but I figure I'd ask here for more informed minds if there's a standard approach here that I've overlooked.
Really appreciate any help, let me know if anything needs clarification.
Answer: There's some ambiguity (and I can't ask for clarification in the comments because I'm a new account).
I'd say first off all, in the scenario that you described, you're looking at an ordinal regression problem, not just a multi-class classification problem. That is, it's somewhere between a continuous regression task and a classification task. Accuracy is a bad measure, as you mention, because it 1) doesn't tell you whether you were close or not and 2) doesn't account for imbalance in the dataset.
Here is a paper that performs and ordinal regression task (specifically targetin age) in a neural network (CNN using faces as the inputs):
Rank consistent ordinal regression for neural networks with application to age estimation, where they propose a metric they call CORAL (COnsistent RAnk Logits), specifically as their loss function for training.
Prior to that they talk about how it's common to break the task up into K binary classification tasks (i.e. >= x or < x). I'm not sure on the specifics of how their loss function differs from previous attempts since what I describe next is very similar. In essence they are calculating cross-entropy loss (more on this below) for K binary classifiers and weighting them by class frequency.
For this paper, they chose to use MAE and MSE both as measures of model performance.  I recently did some ordinal regression on a task where the ranks happened to very nicely follow a Poisson distribution and found that mean Poisson deviance was a far better criterion than MSE or MAE. In classical ordinal logistic regression, some measures of pseudo-R^2 are also occasionally used (such as McFadens, see another comment on that here).
Now, if you're discussing a true multi-class classification problem (where there is no inherent ordering to the classes). You most likely want either weighted or regular categorical cross-entropy (weighted if you have imbalance during training).
For evaluating model performance of a multi-task classifier it depends on whether your classes are balanced or not, but generally I report both F1 score and accuracy as the major metrics and break precision/recall/accuracy out by class deeper in any reporting or examination of the model that I perform.
Both F1 score and accuracy can be balanced in various ways. For F1 score I like to report both weighted and micro-averaged F1 score. For a model that performs really well on all classes, all of these measures will converge.
Comment: Good that you recognized the ordinal nature of the categorized outcomes (+1). You might want to see Chapters 13 and 14 of Frank Harrell's [Regression Modeling Strategies](https://hbiostat.org/rmsc/ordinal.html) and its links for the highly general applicability of ordinal regression. Don't forget that F1 score and accuracy have limitations, noted in the question and in another answer.
Comment: +1, the ordinal aspect is indeed relevant here. (Not sure about OP's "real" application, as far as I understand, "age" is just a stand-in here.) Per the links in my answer, I have major reservations about *any* KPI that relies on "hard" classifications, be it accuracy, precision, F1 or any others, and indeed, the OP is asking about probabilistic classifications and proper scoring rules. Unfortunately, [I am not aware of any proper scoring rules for ordinal multiclass classifications](https://stats.stackexchange.com/q/64774/1352)... I'm sure there is a paper in there somewhere.
Answer: You can extend the log loss to the multiclass case. As you write, accuracy is not a good idea. (I assume you know binning is not good practice, and are only using it here to get mutually exclusive bins for classification. You can also use the log score for continuous predictions.)
Comment: OK - but note that the binning is problematic *both* for features and for outcomes. But that's a different question.
Comment: Thanks! I was just circling around to add that I found Brier's initial definition [1] for his score function, where he generalizes to the multiclass case. This is great to have two proper score functions, though.

Yep I'm binning just as you say; however, the binning is in the target variable, not the input features. There is still information loss as with feature binning, but I'm finding it gets expressed in some really neat ways. Thanks again - will accept answer and close in a few hours.

  [1]: https://en.wikipedia.org/wiki/Brier_score#Original_definition_by_Brier


Evaluating propensity score matches- what to do when ratio of variances or standardized means of difference go to infinity?

Question: I am working on a project where I am comparing the effects of a particular treatment on patients with other patients who didn't receive the treatment. As I am trying to replicate a randomized experiment using data from a observational experiment, I am using matching (I'm trying propensity score, euclidean and mahalanobis distance matching separately to see what produces the best matches) to find a subset of the control group that is best-matched to my treatment group. This essentially means finding control patients that are most similar to the treated patients, according to the available data (demographics and testing data).
For evaluating how well the groups are matched, it is common to look at the ratio of the variances for each co-variate between the treated and the matched control group, the ideal range of ratios being close to 1. It is also common to look at the standardized difference of means for each co-variate between the treated and matched control group, the ideal values considered to be less than 0.25 and as close to 0 as possible.
The problem I am coming across is that some of these covariates end up having a variance of 0 either in the treated set or the matched-control set. Which means all the patients in either the treated or control group are identical in terms of that co-variate. This means the standardized difference of means becomes infinity for a covariate when the standard deviation for that co-variate is 0 in the treated group. It also means that the ratio of variances can lead to a value of 0 or infinity.
What is the proper way to deal with such cases?
Answer: The effect of imbalance on the bias of the effect estimator has to do with the difference in means of each pretreatment covariate relevant to the outcome and the strength fo the relationship between the covariate and the outcome. We use standardized mean differences because it allows us to apply the same metric across all covariates and we can easily define standards for imbalance that don't require subject-matter knowledge for each variable. But if you knew exactly how much imbalance in the raw units of the variable would cause significant bias in the estimate, there would be no need to standardize the mean difference. For example, if the outcome depends heavily on age, an imbalance of 5 years between the treated and control might be too large. Dividing this mean difference by the standard deviation in the sample doesn't get you any closer to eliminating and predicting bias in your effect estimate; it's the mean difference that matters.
All this is to say that for the variable you can't standardize, don't standardize them. Look at the raw mean difference and try to make a conclusion about whether the raw mean difference indicates significant imbalance. You, of course, will have to back up your decision with substantive reasoning, but that shouldn't be too much of a challenge. Instead of examining variance ratio, you could examine the mean difference of the square of the (centered) variable, which gets you at the same diagnostic without having to take a ratio.
Another possibility is to estimate the standard deviation using a different population for which there is nonzero variance. If that population is the same population from which your sample was drawn, its standard deviation would be a good substitute for the sample standard deviation (which is zero).
One final thought is that the denominator of the standardized mean difference should be the value in the unmatched sample. Otherwise, changes in the mean difference are conflated with changes in variance.


How would you name F#7 to G in C major?

Question: How do you name what F#7 is to G in C major? I was thinking it may be V/iii/V but that seems complicated and inefficient.
Comment: You need to clear up your question. `V/iii` in `C` major is a `B7` chord not `F#7`. Don't try to clear up the confusion in comments. Fix the main question.
Comment: How did you discover in the first place, that it's F#7 to G? What are the exact notes in the F#7 chord, in which order? (If this is piano, it's necessary to include both hands in your answer.) What do **I** call F#7 to G, in C major? I call it "Probably A Mistake". :) I might also call it "Maybe This Ought To Be F# **Diminished** 7th"... possible?
Comment: In key C, iii is Em. Therefore V/iii will be B/B7.  Making your sequence B7>Em>G.  A cadence ending on V will be imperfect (on this side of the pond) in any case; it's the only cadence that does. The penultimate chord won't have much, if any, bearing on its name. You can edit the title to be apposite, in any case, rather than use a comment.
Comment: What I mean is that how B7 is to C, F#7 is to G, how would you name this in roman numerals? like if i play a progression, C-F-F#7-G7 what would you call the F#7 in roman numerals? It seems that it is the VII7 of V, but I rarely see VII7, in favor of V7/iii, so VII7/V doesn't seem "right" to me (i know that it is subjective, but I was wondering if there was a different way to put it.)
Comment: @MichaelCurtis I am aware, this is what i am trying to find out. what i am asking is what *is* F#7 to G (besides VII7 unless that is the only option possible) and how do you name it in roman  numerals?
Comment: What is the actual music? Do you have a longer passage? Provide some of the chords before and after the `F#7 G`. Depending on the before/after, you could have a non-functional chord, or you could have a key change, etc.
Comment: @MichaelCurtis I don't have an established specific example, but a progression could be C-F-F#7-G-G7-C.
Comment: @DavidR thanks for your insight. I have tried F#dim7, and I see why you prefer it over F#7, as it is what is in key for G (with the exception of Eb), but it does not have the same effect I get when I play F#7. The voicing was with F# as the root.
Answer: The sample progression...
C F F#7 G G7 C
The problem is, if you use Roman numerals to show F#7 as a secondary dominant, you write it with a slash, and the first part would be the dominant V7/?, and then the question mark would be replaced with the implied tonic. However, in that case the tonic would be either a Bm or B major triad. Neither of those chords is diatonic to C major and so we get into something you might call a "tertiary" dominant. But that is not a standard term in harmonic analysis.
You could write it with secondary slashes as you suggest and work it out like this...

   F#   Bm     G
 C:V /  iii /  V
   V of iii of V

But, that is complicated. It might be better to show a key change.
I suppose V/iii/V with a key change label would literally be...

   C  F     F#7    G     G7 C
C: I IV   G:V7/iii I   C:V7 I

But, if you want to follow a common deceptive resolution that moves to a submediant chord, it would be...

   C  F      F#7 G     G7 C
C: I IV   Bm:V7  VI  C:V7 I

I am away from a piano at the moment so I can't hear the progression and whether there is a true sense of a deceptive progression.
Another possible analysis is to treat the F#7 as a non-functional passing chord. Between the F chord and the G chord a F# triad just connects the two with all voices ascending by half step. The 7 of F#7 could then be a descent of F E D which is a smooth line reinforcing the passing motion idea. You could then analyze it as...

   C  F F#7  G G7 C
C: I IV p.c. V V7 I

p.c. would be an abbreviation for passing chord.
As a general rule, simpler is better in harmonic analysis, so I sort of lean toward the last analysis. The former requires two things simultaneously, a secondary relationship and a key change, and there isn't much going on to establish an implied key. A passing chord may be the simplest analysis and more truly descriptive of the harmonic effect.
Does the music sound more like a chromatic "slide" between F and G chords than a functional dominant resolving deceptively? If yes, then consider it a non-functional dominant and analyze it as such. To some degree the rhythm handling of the progression can make a difference. If F#7 is rhythmically unaccented, it probably lends itself to feeling like passing motion.
Answer: Within the confines of standard functional, Tonal harmony, F#7 to G doesn't have any particular designation. So what is really being discussed here is using Roman numerals as a substitute for fixed chord symbols — essentially the Nashville system, but with Roman numerals instead of arabic ones.
In the Nashville system, the chord would just be #47. Translating that directly would give simply #IV7.
But since there's an additional desire to show the relationship to the following chord, the label becomes VII7/V, meaning "a dominant seventh chord built on the seventh degree of G major". This is sufficient to express the chord clearly, as the "normal" seven chord would be viio (i.e., the upper-case Roman VII versus the lower-case Roman vii).
Answer: In the sample progression
   C F  F#7  G G7 C
C: I IV #IV7 V V7 I
The centre of progression is this #IV V7 I which is case of "double leading-tone" (as found in some classical works) : it adds a 2nd leading-tone to the G chord: to its root (F#→G), and to its fifth (A#→B).
If the F#7 was preceded by a C#m7 then you could also see it as deceptive cadence.
The cadence #iv7 VII7 I can be read as iim7/iii V7/iii I, which is deceptive as one expects a iii after the V7/iii. This cadence is a fairly effective cadence as it contains those 2 above-mentioned leading-tones.
    C C#m7    F#7    G G7 C
C: I                V V7 I
G:   ii7/iii V7/iii I
Answer: It has become clear through the comments that the music is your own composition, and the chords sound exactly as you intend them to sound. And it was already clear through other answers that this is not a standard well-known construction -- it's something that only belongs to this one piece of music, or it's part of your style but not part of everybody's style.
In a case like that, I'd say: Most of all, notate it in a clear and obvious way, so people won't get it wrong all the time. And try to see how these two chords fit into the way this piece goes, so that in the end your analysis helps demonstrate the logic of this piece, rather than just giving names to the chords. Hopefully, either they are part of some pattern (and should be explained according to that pattern), or they intentionally break a pattern (ditto), or the F#7 chord is a non-functional interesting chord that's interrupting a more ordinary pattern.
I just used the word "pattern" a lot. When stuck trying to analyze any music, "Look for patterns" is almost always a good place to start.

How would you name F#7 to G in C major?


What does disk I/O mean in Spark?

Question: My question is pure theoretical regarding the Spark and MapReduce processing.

What does disk I/O mean in context of Mapreduce and Spark?
I know that in the Spark the data is stored all over memory (RAM) during the computation. Where does MapReduce store the intermediate data? If the answer is disk, what exactly does the disk mean?
Does Spark have only 2 disk I/O's during the jobs? How many disk I/O's does MapReduce have?
Answer: In Spark, disk I/O refers to the input/output operations performed on disk storage devices during the execution of Spark jobs or tasks. When working with large datasets that cannot fit entirely in memory, Spark may need to read data from disk or write data to disk in order to perform various operations.
Disk I/O typically occurs when Spark needs to read data from external storage, such as reading input data from files stored on a distributed file system like Hadoop Distributed File System (HDFS) or writing output data to disk. It can also occur during shuffling of data between different stages or tasks within a Spark application.
Disk I/O operations tend to be slower compared to memory-based operations due to the mechanical nature of disk drives and the need to physically read or write data on disk platters. As a result, minimizing disk I/O is crucial for optimizing Spark application performance.
To mitigate the impact of disk I/O, Spark employs various techniques such as data partitioning, caching, and in-memory processing. By intelligently managing data placement and leveraging memory as much as possible, Spark aims to reduce the need for frequent disk I/O operations, thereby improving overall execution speed. Additionally, utilizing technologies like solid-state drives (SSDs) or distributed storage systems can further enhance disk I/O performance in Spark.

What does disk I/O mean in Spark?