How to Overcome High Action/Heavy Gauge Strings on a 12-string?

Question: I've played the guitar for over 40 years—I'm now 59 and I started when I was 11 or so. I've played professionally, been in many bands, played every sort of guitar imaginable and even been a bass player for several of those years.
Now, however, I've been on 12-string for going on two years. Why 12-string? Because I've always loved the sound, and besides—I know I'll never be a guitar hero, so why not try to explore the realm of unique sounds? Everyone plays the 6-string—hardly anyone I've heard plays the 12-string, except as an afterthought to a six.
I had had a 12-string years ago but when I started up again this time around two years ago I found it incredibly difficult to just press down the strings!
After two years, however, I'm fairly used to it and can press the down well enough; my problem this time comes down to high action/heavy gauge strings.
The guitar people who are dealing with my two 12-strings have done their best to accommodate my request for the lowest possible action/lightest possible gauge strings, but past a point it's obvious that there is going to be buzzing, tuning problems and so on with BOTH these requests.
So the latest incarnation that they sent back after restringing and re-setting up is a 12-string with .011-gauge strings and, to me, incredibly high action, even though the tech told me proudly he had "lowered the action to the lowest" he'd ever accomplished on a 12-string.
But now I find it almost impossible to play the chords I was playing before . . . the strings are just too high and the force required to push them down is just too great!
My question here is, will I ever get to the point that I will be able to play this guitar, or am I just banging my head against a brick wall? How do I get around the high action? It feels (although it isn't!) that the strings are a centimetre from the fretboard (they're more like 3 mm).
Now, I remember when I could barely play this guitar with the lightest strings (.009s) and lowest action possible (it led to much buzzing and other problems) but I despair at ever being able to play it now.
Don Felder of the Eagles once said of the 12-string—that he used to write Hotel California—that it made his fingers bleed and you needed the "hands of a gorilla" to play it, but I can't believe this is true.
CAN I ever get to the point where I can play this thing? I do NOT want to play it like a 6-string. I realize that soloing on a 12-string is a ridiculous idea. I want to use it more as almost a harp.
What should I practice to increase hand strength, and especially accuracy at just being able to press the two strings of each course down properly?
I can't find anything on YouTube for 12-strings specifically and what I do find usually treats the 12-string as just a different kind of 6-string.
Many thanks for any advice provided!
Comment: As I am about to purchase a 12 string guitar (I'm very similar to the OP), this question and its answers are very important for me. I saw a 12 string tutorial on youtube which suggests that placing a capo on the second fret both returns a down-tuned guitar to standard pitch but also *lowers the action*. The guitar which I have my eye set on - a Fender CD-160SE 12-String V-2 - seemed very easy to play, but I will check it again before I buy.
Comment: Exactly what 12 string guitar is it - they vary an awful lot.
Comment: A lot of people tune 12 strings down to D for this very reason; it lowers the action and releases string tension.  I actually really like the sound of 12 strings tuned a little lower too, I don't think you lose anything doing this.  And if you want to play something using open chords "at pitch" without transposing, you can always just capo 2.
Comment: Also, have you tried martin's silk and steel strings?  I've not tried them on a 12 string, but they're light (I think 11.5?), low tension (which will lower action), and sound GREAT. They're not "muddy" or "muted" like some people assume, and they're not just for finger pickers either. I mainly use a flatpick, and I have the standard set on my main acoustic 6 string now simply because I like the tone so much.  Shimmery and clear, and dynamically responsive.  For me, the fact that they're nice and easy under the fingers is just a bonus but for your purposes I imagine it'd make a real difference.
Comment: (For reference, I have them on a big solid topped dreadnought which protects like nobody's business.  I've don't know how they'd sound on a quieter guitar, but they sound beautiful on what I'm playing.)
Comment: Yup, Silk and Steel is what I always use! I had never heard of them until they were suggested right here in one of my posts. (Oops, can't use paras in these comments boxes; see my reply in a general reply below =+)
Comment: What gauge do you have on it?  I use 10s on my 12 string and can play fairly easily on it.
Comment: Sounds like maybe you need a new guitar tech, or at least a second opinion. If you were playing it with .009s, previously, and went to .011s, they're going to sit way higher in the nut slots than the .009s. If the tech did nothing to address this, then there is still a lot of room to improve your action. In the mean time, try down-tuning and capo, as suggested by Some_Guy. Or try .010s like ggcg and see if that solves anything.
Answer: It is possible to set the action of a 12 string to be very low and be adjusted for very light gauge strings, but you lose volume and tone.  I have set up an acoustic 12 string to play like an electric, using electric gauge strings (.008s). The tone wasn't great but the play-ability was very easy, so it is possible to get a soft playing 12 string, you just have to shop around, and find a competent technician.
The ability to lower that action of a 12 string guitar is entirely dependent on the build of the guitar.  If the guitar neck has a large 14th fret hump, or the the bridge lip to the saddle is too high, it will be impossible to lower the action further than those things allow.
You should have your nut slots checked for proper setup.
For lighter playing action you want the smaller gauge strings in the pair to be set to the same height as the top of the thicker strings, making it easier to be more accurate on your finger placement on the strings.  Stock 12 strings usually have the nut slots all cut to the same depth making the smaller strings lower than the larger strings. For even better setup you can have the strings set to the same height at the saddle, which also improves the play-ability significantly.
With a good setup a 12 string shouldn't require much more hand strength than a 6 string.
For accuracy practice on the courses, look at working on mandolin style tremolo picking. By practicing tremolo across both strings of a course you can tell when your finger isn't aligned in-between the strings.
A 12 string was the first guitar I owned, and I still play one regularly.  It is entirely possible to play solo lines on one, and I really like the way the Blues sound in it. Fingerpicking is also possible on a 12 string, and I have seen players use a slide on them.
Comment: I found a good article on setting up 12 strings: https://www.premierguitar.com/articles/22046--string-setup-secrets
  - they recommend keeping the strings set to the fret height at the nut for tuning stability,  but I'm willing to trade a little tuning for ease of play...
Comment: Wow! Great article! Why isn't there a magazine for 12-strings? There's probably one called Machine Head Today, why not 12-strings? Let's start one . . . I'll be the managing editor. Alphonso can be the Editor. Some_guy can be some guy.
Answer: Sometimes you have to do what is right for you. I purchased an electric mandolin, and it came with heavy gauge phosphor bronze strings. You had to tune them up until they felt like rebar, and I felt that they were on the brink of snapping. Going against all sorts of mandolin lore, I decided to simply use a couple of sets of light electric guitar strings. Instantly the string tension was lower, tuning was easier and the tone was, if anything, improved. You could use light gauge electric guitar strings on an acoustic. It wouldn't do any damage, though it would offend the purists.
12 String guitars don't have to be unplayable and nasty. From my somewhat limited experience the nut slots tend not to be cut deep enough on , so you have to put a lot of effort into squeezing the strings down. On my 12 string, a cheap Stagg electro-acoustic piece of nonsense, I filed the nut slots deeper and filed the saddle down. I also checked than the neck relief was flat. The next stage would be to make sure the frets are level. Do this and you should be able to use gauge 8 strings without issue. Granted it still isn't the easiest guitar to play as the neck is thicker, but it is a lot easier to play than when it left the factory.
Answer: Some just are not easy to play, even given the lightest strings and enver will be. I cannot get my Tanglewood Oddesey to go any lower. If you can't get a 12 string to a state where its actually a pleasure for you to play, with your geometry and attributes, then take a trip to a local music store and try whatever they have to gain some perspective on what is possible with other models.


Create simulation to see whether Chi Squared is suitable

Question: I'm wondering about the following

The threshold is that the chi-squared distribution should be a good
approximation to the chi-squared statistic under the null hypothesis.
As the number of cells increases, it starts to matter very little what their
expectations might be. Generally, when testing at a 5% or 1% level, you're fine
even with 20% low-expectation cells.

Is there any literature that supports this statement?

When in doubt, run a small simulation with your data. R has that built right
in to its chi-squared test function.

How would one go about writing a simulation to demonstrate this?
example data
df <- structure(list(x = structure(c(1L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 5L, 1L, 1L, 3L, 1L, 1L, 3L, 6L, 1L, 1L, 1L, 3L, 1L, 1L, 4L, 3L, 3L, 4L, 1L, 1L, 5L, 5L, 4L, 3L, 3L, 3L, 1L, 1L, 3L, 3L, 3L, 1L, 1L, 1L, 4L, 1L, 1L, 3L, 1L, 3L, 1L, 1L, 1L, 6L, 3L, 3L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 8L, 3L, 3L, 4L, 3L, 1L, 1L, 3L, 1L, 3L, 1L, 1L, 1L, 3L, 1L, 4L, 3L, 4L, 3L, 4L, 1L, 3L, 1L, 1L, 4L, 1L, 1L, 3L, 2L, 1L, 1L, 1L, 3L, 3L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 3L, 1L, 1L, 3L, 1L, 3L, 3L, 1L, 3L, 1L, 1L, 3L, 1L, 3L, 3L, 4L, 1L, 3L, 6L, 3L, 3L, 1L, 1L, 5L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 3L, 3L, 3L, 3L, 4L, 3L, 1L, 1L, 1L, 6L, 4L, 3L, 1L, 3L, 3L, 3L, 1L, 1L, 1L, 3L, 1L, 3L, 1L, 1L, 5L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 1L, 1L, 6L, 3L, 1L, 1L, 4L, 3L, 4L, 4L, 3L, 3L, 1L, 1L, 6L, 1L, 1L, 3L, 8L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 5L, 5L, 1L, 5L, 1L, 1L, 1L, 3L, 1L, 3L, 1L, 1L, 1L, 1L, 3L, 3L,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0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L)), row.names = c(NA, -707L), class = "data.frame")

Comment: What's the source of the quotes?
Comment: From a comment online @corey979 [here](https://stats.stackexchange.com/questions/395244/if-i-have-less-than-5-elements-in-a-cell-is-there-a-way-to-use-chi-squared?noredirect=1#comment741422_395244)
Comment: The easy way is via `chisq.test(..., simulate.p.value=TRUE)`.
Comment: Although I had forgotten, a search of this site shows I answered your question at https://stats.stackexchange.com/a/135888/919
Answer: We want to know whether under the null the chi-squared distribution is a good approximation to the chi-squared statistic. In fact, we are specially interested in knowing whether under the null hypothesis the probability of rejecting the null equals the significations (5% or 1%).
The null hypothesis depends on whether we are talking about an independence (or homogeneity) test or a goodness of fit test. However, we can generate samples using the null and check how many of them would be rejected.
For example, let's suppose we want to run a goodness of fit test with  element sample size 150 and probabilities (.4, .4, .1, .05, .03, .02). We can run the following simulation (very inefficient code left for clarity):
> probs <- c(.4, .4, .1, .05, .03, .02)
> n <- 150
> probs*n #expected values
[1] 60.0 60.0 15.0  7.5  4.5  3.0
>
> s <- 1e5
> res <- rep(NA, s)
> for (i in 1:s) {
+   mostra <- sample(1:6, n, replace = TRUE, prob=probs)
+   mostra <- factor(mostra, levels=1:6)
+   res[i] <- chisq.test(table(mostra),
+                        p=probs)$p.value
+ }
There were 50 or more warnings (use warnings() to see the first 50)
> hist(res)
> table(res<.05)/s

  FALSE    TRUE
0.94909 0.05091
> table(res<.01)/s

  FALSE    TRUE
0.98761 0.01239

Although we have some rather small bins - at least, borderline cases, the histogram (not included) shows that p-values distribution is approximately uniform and we can see that we would be rejecting about 5% and about 1% under those significations. Therefore, chisq.test seem to be working quite well for that test.
Comment: how would one go about writing a simulation for this though? I've added some example data to the OP
Comment: You have here one example code. I tried to copy your data but it doesn't seem to work. I think there is a problem with parentheses count and - maybe - with a too long line.
Comment: thanks, I'm a little unsure how to interpret the part about the uniform distribution. Because the p-values are roughly uniform (I've plotted them from your code), we would reject ~5% if we were to reject values <0.05 (as in `table(res<0.05)/s`). If the test wasn't working so well would we expect to see this value increase / decrease? (I've tried using different probabilities, and it seems pretty robust)
Comment: example with different probabilities : http://vpaste.net/torSn , which still seems to work out alright even though ~40% of the cells have what could be considered a low count
Comment: About uniform distribution of p-values: P-values are computed by evaluating the inverse distribution function of a chi squared distribution on the the statistics. If the statistics is actually distributed according to that chi squared distribution, it will be uniformly distributed between 0 and 1. For example, 5% of all values of the test statistic will be under the 5% p-value threshold - and the same is true for any other percentage.
Answer: The solution by @Pere sets up the simulation but then extract p-values from the Chi-squared test. However, the p-value is based on the chi-squared approximation and the goal of the simulation is to avoid making the approximation in the first place.
So extract the statistics instead of the p-values. Then after a large number of simulations check how often the simulated statistic is at least as large (i.e., at least as extreme) as the observed statistic. This is the simulation p-value.
You can actually do this quite easily with chisq.test since it has an option to simulate rather than approximate the p-value. I assume that what the comment to your previous question refers to.
chisq.test(df$x, df$y, simulate.p.value = TRUE, B = 10000)
#   Pearson's Chi-squared test with simulated p-value (based on
#   10000 replicates)
#
# data:  df$x and df$y
# X-squared = 21.191, df = NA, p-value = 0.0032

If you want to write a simulation yourself here is one way to do. It is not the same method as what you get with simulate.p.value = TRUE. This uses permutations, not bootstrapping.
library("tidyverse")

# Write function to extract chi-square statistic
chisq.stat <- function(df) {
  # Suppress the warning about "incorrect chi-squared approximation."
  # We can ignore it because we want the statistics, not the p-value.
  t <- suppressWarnings(chisq.test(df$x, df$y))
  pluck(t, "statistic")
}

df <- tibble(x = x, y = y) %>% drop_na()

Xsq.obsr <- chisq.stat(df)
Xsq.obsr
# X-squared
#   21.1907

Xsq.perm <- df %>%

  # Will do 10000 permutations each with its own id `rep`
  crossing(rep = seq(10000)) %>%
  group_by(rep) %>%
  # Create permutations by shuffling y while keeping x in place
  mutate(y = sample(y, replace = FALSE)) %>%
  ungroup() %>%

  # Compute the chi-square test statistic for each permutation
  nest(- rep) %>%
  mutate(statisic = map_dbl(data, chisq.stat))

pval.perm <- mean(Xsq.perm$statisic >= Xsq.obsr)
pval.perm
# [1] 0.0029


htaccess redirect from variable URL to clean URL

Question: I have a site that had URLs that looked like this all from the index.php page. It was a first attempt at writing for databases several years ago.
www.domain.com/index.php?p=page1
www.domain.com/index.php?p=page2
I have changed to a wordpress site and want to redirect anyone accessing the page to the new url. Such as
www.domain.com/page1
www.domain.com/cat/page2
I have the redirect written like this but it just redirects every one to the home page.
<code>Redirect 301 /index.php?p=page2 http://www.domain.com/page_newname_2/
</code>
Thanks for any help, I have searched and can't seem to find an answer that is close or makes sense.
-Brian
Comment: there is also this at the top of htaccess file. Forum limited me to 2 links in post.
Redirect 301 /index.php?p=home http://www.domain.com/
Answer: Redirect old page to new post page using Wordpress!
if so, go to plugins, add new, enter Redirection. The very first plugin by John Godley will do just what you need.
Manual download page for plugin redirection
after installing you will find it in Tools -> Redirection
Comment: The old website was not wordpress but this works perfect, Thanks soo much!!!!! I've been waiting on an answer in another forum for a few weeks and a few minutes here and I get a perfect solution amazing!
Comment: @BrianYork If you are satisfied with the answer, you should consider [**accepting**](http://stackoverflow.com/faq#howtoask) it, selecting the check mark in the upper left of this answer.


Compare two datatables in vb.net

Question: DataTable One contains only one column (Code)
Code
3
7

And Second Datatable also contains only one column (ProductCode)
ProductCode
2
3
6
7

I want to compare if all values of first datatable exist in second datatable using the best technique. currently i am using for each but one time it is FALSE and Second time TRUE so it does not look practical.
Applicable = False
For Each chkRow As DataRow In chk.Rows
   For Each dtRow As DataRow In dt.Rows
      If chkRow("ProductCode") = dtRow("Code") Then
         Applicable = True
         Exit For
       Else
         Applicable = False
       End If
    Next
Next

Please suggest better solution.
Comment: Your question has been rolled back to the original version, which has an answer. Such a drastic edit changes the original question too much, and you should consider creating a new question.
Answer: I would tend to use a LINQ query:
Dim codes = table1.AsEnumerable().
                   Select(Function(row) row.Field(Of Integer)("Code"))
Dim productCodes = table2.AsEnumerable().
                          Select(Function(row) row.Field(Of Integer)("ProductCode")).
                          ToArray()

If codes.All(Function(code) productCodes.Contains(code)) Then
    '...
End If

Note that there is a ToArray call for the productCodes but not codes. That's because productCodes needs to be enumerated multiple times and you don't want to do that on a deferred query.
Comment: @abdullah, Declare it.
Comment: @abdullah, it appears that I originally used the wrong name for Lambda parameters but @Jimi has kindly edited that for us. That's what I get for typing code directly into an answer instead of into the IDE and then copy/pasting. I've also added a missing closing parenthesis to the `If` statement.

Compare two datatables in vb.net


Need help selecting test for nominal IV with categorical DP

Question: I am going to attempt to give you as much background as possible.
My independent variable is nominal and describes the number of days after which an insect was exposed to new conditions (0,1,3,5,7).
The dependent variable is the insect's condition after the experimental period (Healthy, Sick, Dead, Diapause).
From exploratory analysis, there are very clear connections between Days and Condition.   When I graph the percentage of each outcome against days, there are very obvious correlations.  I.e., Dead is a very rare outcome at Day=0 but become steadily more common as Day increases.
What I am missing at this moment, however, is the appropriate stat test to demonstrate this trend is statistically relevant.  Any help would be greatly appreciated.  I am using SPSS.
1) All insects are individuals and were recorded as such, so yes I can say #42 has a discrete outcome.
2) It's a 0,1,3,5,7 scale because those are the only days such manipulations were possible for a combination of logistical and physiological reasons.
3) No outcomes are reversible and all observations were made on the same day REGARDLESS of what day the environmental changes were initiated, 28 days after adult emergence.  So it not that the 7 day data set was older than the 0 day data set, it's just that the environmental change happened at day 7 instead of day 0.
Comment: Given the extra detail here it seems that overall counts ignore the detail you have on individuals. In that case a transition probability matrix and Markov chain ideas seem relevant. I can't advise on how much of that you can do in SPSS.
Answer: Number of days looks quantitative to me. "Nominal" means that the data labels are just names, with not even any order to them, but that is not the case here.
But why can't days be e.g. 2, 4, 6, or more? Is this something to do with observing, i.e. people only looked at the insects on certain days?
I don't think we have enough background here. Are you monitoring individual insects, so that you can track say insect #42 Healthy -- Healthy -- Sick -- Dead? Or you are just counting totals of the categories?
If you have individual trajectories you can look at transition probabilities using Markov chain ideas; otherwise this is essentially a table of counts with time flavour and bar charts and a chi-square test might be a starting point.
Presumably "Dead" is irreversible but otherwise what are the rules? Is any transition between Healthy, Sick and Diapause allowed? (If you say bug on this forum, people are more likely to think of software, not entomology, so you need to explain.)
Facetious aside: the observation that the longer you wait, the likelier it is that insects have died seems unsurprising to this amateur; you need a statistical test to back that up???
Comment: Thanks Nick!  I included answers to your concerns as edits in the original question.
Comment: Also, I should make a note here that I was attempting to "simplify" the categories by calling them Healthy, Sick, Dead, Diapause.  The truth is this is a parasitoid study, and I was concerned my outcomes might just confuse people.  The actual categories are "Para with hatch", "Para without hatch", "Healthy host, no para", "Diseased host, no para".


error in suds-jurko setup command: use_2to3 is invalid

Question: enviroment info:
python3 --version:Python 3.6.5
pip3 --version:pip 21.2.4
when i execute : "pip3 install -r requirements.txt" there is a error:error in suds-jurko setup command: use_2to3 is invalid
Answer: Based on comments here, I was able to install this package using
pip install "setuptools==58.0.0"
pip install -r requirements.txt --use-deprecated=legacy-resolver

Answer: The 2to3 error is an error thrown to cover up another error.  To find out the real error, you have to build from source.
1.Download source: https://pypi.org/project/suds-jurko/#files
2.Compile:
unzip suds-jurko-0.6.zip
cd suds-jurko-0.6
python setup.py install

I don't remember the 'real' error I received, but here is the solution:
1.Create Symlinks from /lib to /local/lib:
ln -s /usr/lib/python3.6 /usr/local/lib/python3.6
ln -s /usr/lib64/python3.6 /usr/local/lib64/python3.6

2.Probably not best practice.. give permission recursively:
chmod 777 -R /usr/local/lib/python3.6/site-packages/

3.Install setuptools
pip3 install --user "setuptools==58.0.0"

4.Install suds-jurko using regular pip and not pip3.  Also install without root privileges.
su -c "python -m pip install suds-jurko --user" YOURUSERNAME

Answer: Use a community fork of suds-jurko. It is releasing packages under the main suds package name
Details: suds-commutity


Probability distribution for a geometric distribution don't add up to 1

Question: Say I'm rolling 2 dies, numbered 1 to 10.
A successful outcome is considered rolling a multiple of 4.
Therefore, probability of success $=0.25$ and prob of failure $=0.75$.
This is an example of a geometric distribution.
I can roll a maximum of 6 times.
I made the prob distribution chart to represent all the different possibilities, but my values don't add up to $1$.
I don't understand what I'm doing wrong.
\begin{align}
\text{Roll} &\text{ Number}  & &\text{Probability} &&\\
X &= 1 && (0.75)ˆ0(0.25) && 0.25 \\
X &= 2 && (0.75)ˆ1(0.25) && 0.1875 \\
X &= 3 && (0.75)ˆ2(0.25) && 0.140625 \\
X &= 4 && (0.75)ˆ3(0.25) && 0.10546875 \\
X &= 5 && (0.75)ˆ4(0.25) && 0.079101562 \\
X &= 6 && (0.75)ˆ5(0.25) && 0.059326171
\end{align}
Any help would be appreciated.
Comment: It seems that your error stems from believing that each outcome, $1 \rightarrow 20$ is equally likely.  But that is not the case.  Consider how many ways you can get the outcome of $10$ and of $2$, to take just one example comparison.
Comment: I don't understand.I drew up a table listing all the different outcomes I could get using the 2 dies.I had 25 out of a 100 outcomes that were multiples of 4.Isn't that my probability of success?
Comment: Did you consider the case of $6$ failures  ? If you add $0.75^6$ to your sum, you get $1$ within your accuracy.
Comment: Ohh.I get it now.Thankyou for pointing that out.Should I frame the question a bit differently?Are all the required variables clearly defined?
Comment: Yes, please edit the question. Denote $X$=number of trials needed to get a success. And $X>6$ means that you got $6$ failures.
Answer: Since the random variable $X$ has not been precisely defined, we will supply a (speculative) definition.
The game consists of rolling the two dice repeatedly. We stop when we roll a sum divisible by $4$ or when the total number of rolls reaches $6$. Let $X$ be the number of rolls.  It is indeed true that the probability of getting a sum divisible by $4$ on a roll of the two dice (probability of a success) is $0.25$.
For $k=1$ to $5$, the probability that $X=k$ is given by the familiar geometric distribution. Thus $\Pr(X=k)=(0.75)^{k-1}(0.25)$.
But $k=6$ is special. We have $k=6$ precisely if there have been $5$ failures in a row. Thus $\Pr(X=6)=(0.75)^5$.
Remark: Or else we could say that $X=6$ can happen in two ways: (i) our first sum divisible by $4$ occurs on the $6$th roll or (ii) the $6$th roll results in failure. Then we get $\Pr(X=6)=(0.75)^5(0.25)+(0.75)^6$. That turns out to be the $(0.75)^5$ that we obtained in a simpler way in the answer above.
Comment: That seems to give me the correct answer.Could you please explain why I would do (0.75)^5 for X==6?
Comment: I have added a remark that does $\Pr(X=6)$ in a more complicated way. But for the simple way, recall that if we did $6$ rolls we are forced to stop. So if we have had $5$ failures in a row, we are allowed one more roll, but that's all. Thus we end up doing $6$ rolls precisely if we have not had a success on the first $5$ trials. That probability is $(0.75)^5$.


Python generics: how to create object of an appropriate class?

Question: I have the following code (this code is just for testing):
from typing import TypeVar, Generic, Type
import abc

class BaseMultiplier(abc.ABC):
    @abc.abstractmethod
    def multiply(self, n):
        pass

class MultiplierByTwo(BaseMultiplier):
    def multiply(self, n):
        return n * 2

class MultiplierByThree(BaseMultiplier):
    def multiply(self, n):
        return n * 3

Multiplier = TypeVar('Multiplier', Type[MultiplierByTwo], Type[MultiplierByThree])

class MultiplierCreator(Generic[Multiplier]):
    def create(self) -> Multiplier:
        # I need to create an instance of Multiplier here
        pass

class MultiplierByTwoCreator(MultiplierCreator[MultiplierByTwo]):
    pass

class MultiplierByThreeCreator(MultiplierCreator[MultiplierByThree]):
    pass

So how can I create an instance of an appropriate Multiplier class in create method?
So the following code must not raise any exceptions:
creator_by_two = MultiplierByTwoCreator()
assert type(creator_by_two.create()) == MultiplierByTwo

creator_by_three = MultiplierByThreeCreator()
assert type(creator_by_three.create()) == MultiplierByThree

Thanks in advance.
Answer: class MultiplierCreator(Generic[Multiplier]):
    def create(self) -> Multiplier:
        return self.multiplier()

class MultiplierByTwoCreator(MultiplierCreator[MultiplierByTwo]):
    multiplier = MultiplierByTwo

class MultiplierByThreeCreator(MultiplierCreator[MultiplierByThree]):
    multiplier = MultiplierByThree

By adding class attributes to the subclasses of MultiplierCreator that contain the related Multiplier subclass you can then use the inherited method create() to call this class attributes and return an instance of it. Hope this is what you are looking for.
Aside from that, to check whether an object is of the correct type you may want to use isinstance():
assert isinstance(creator_by_two.create(), MultiplierByTwo)
assert isinstance(creator_by_three.create(), MultiplierByThree)

Hopefully this can help you.
Comment: Yes, now I use a property containing an appropriate class. But I thought using generics would let me get rid of redeclaring methods in every child class.


Manually obtain view produced by content negotiation

Question: I have looked in the docs to determine how to make a call to get back the same view that content negotiation returns and I can't find out how to do this.
I have configured content negotiation to return XML and JSON which works fine as far as the response goes but I also need to 'call' content negotiation manually.
We store request/response in our DB and I would like to call content negotiation with my object and have it return back JSON/XML as it would with the response. I know I can do the work by inspecting the accept header, queryParam, and defaults; however, I would prefer to use the same method(s) content negotiation uses.
Anyone know how to manually call 'Content Negotiation' with my response object and have it determine whether it should return back XML/JSON as it would with the response?
Comment: I think the question is quite hard to answer.
Comment: After looking at the spring code, I found a fair solution that will resolve my issue.
Answer: Ok so after some debugging I figured out what works for my case.
With my manually configured content negotiation listed below.
<code>@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
    public static final String FORMAT_PARAM = "format";

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.favorPathExtension(false)
                  .favorParameter(true)
                  .parameterName(FORMAT_PARAM)
                  .useJaf(false)
                  .defaultContentType(MediaType.APPLICATION_XML)
                  .mediaType("xml", MediaType.APPLICATION_XML)
                  .mediaType("json", MediaType.APPLICATION_JSON);
    }

}
</code>
I can inject the ContentNegotiationManager into the service that needs this information and make a call to resolveMediaTypes and this will get me the media type that will be used in the response.


A singular $2×2$ matrix

Question: We assume a singular $2×2$ matrix $A=\begin{pmatrix}
a & b \\
c & d \\
\end{pmatrix}.$ Then $ad=bc$ and $A^2=(a+d)A$ and $A^n=(a+d)^{n-1}A.$ So
$$B=\sum_{n = 0}^{+\infty} \frac {A^{2n}}{(2n)!} = I+ \sum_{n = 1}^{+\infty} \frac {(a+d)^{2n-1}}{(2n)!}A$$
By the ratio test, the series $\sum_{n = 1}^{+\infty} \frac {(a+d)^{2n-1}}{(2n)!}$ converges and we have:
$$\sum_{n = 1}^{+\infty} \frac {(a+d)^{2n-1}}{(2n)!} = \frac{\cosh (a+d) -1}{a+d}$$
Could $B$ be a zero matrix?
Comment: I don't think this will be true in general. Even if you take a special case when A is nilpotent matrix, then B will be a non-singular matrix. So you have a counter-example.
Answer: $B=0\implies 0=\det A=(\frac {a+d}{1-\cosh (a+d)})^2\implies a+d=0$, a contradiction.

A singular $2×2$ matrix


How can I add some conditional Javascript to my Asp Hyperlink's NavigateUrl property?

Question: So I have a Hyperlink on my asp.net page. When the person clicks that link, it carries out some action. Now I want to be able to add a javascript alert (confirm, actually) as to whether the user is SURE he/she wants to carry out the action? If yes, then carry out the action, otherwise do nothing. How do I do this?
My current code just has a link to the action:
Link1.NavigateUrl = "./Actions.aspx?action=abort&job=" + JobID;

Answer: I'm not at my development environment to test this out, but something like this should work for you:
Link1.NavigateUrl = "./Actions.aspx?action=abort&job=" + JobID;
Link1.Attributes["onclick"] = "return confirm('Are you sure?');";

Comment: Thanks Jason. If I leave the NavigateUrl as it is, and add the onclick attribute, I get the following error: "Server error in application--The resource cannot be found, HTTP 404" which is BS cuz if I don't add the onclick line, everything works as expected.

"The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly"

It's talking about Actions.aspx, which definitely exists.
Comment: Could I get you to load the page, view source, find the hyperlink tag and paste the HTML here for me to review?  It may just be a simple syntax issue.
Comment:
Abort
Comment: Are the `'` in the `onclick` and the `&` in the `href` artifacts of your copy & paste?  Or are they actually escaped like that when you view source?
Comment: Nevermind, I realized the actual Actions file wasn't checked into source, and hence the 404. Thanks Jason :)


Google Maps V3, how to get array of markers/overlays?

Question: Now obviously if I was just adding them in a normal fashion I would just keep them in an array along the way but in my case the markers are being loaded in, but I am using a KML layer.
So after the KML loads and the markers show up I basically just want to know how many there are, and I can figure out some dumb hack for this (loading the KML file again with jQuery and counting it there or something), but ideally I just want something like myArray = map.getMarkers() or myArray = map.getOverlays(), does anything like that exist?
It seems such a simple task, not why it is taking me so long to find the answer. Maybe it just isn't possible?
Answer: There's no such thing, you have to keep an array and add the object IDs everytime you insert one.
Comment: The thing is I'm not inserting them at all, I'm loading them from an external KML file with 'kmlLayer = new google.maps.KmlLayer({map: map, url: url});' which is an XML file with coordinates.
Comment: oh I see. Maybe you can provide us codes or a sample page on how you fetch your data
Answer: I'm not sure if you're able to access the markers once you've added them in using a KLM layer. If you don't have that many markers, then I would say load them using the regular Marker class.
Maybe I didn't do it right, but last time I tried implementing markers using KLM layers I wasn't able to add any events to them, or access them at all.
If you only need to count them, then I would say load that same KML file using AJAX, and parse it as an XML and you can grab the elements from there to count them.
Comment: Yeah, that's how I was doing it in v2 I was just hoping with v3 the KML support would be better because it has the potential to be a quite elegant solution. Oh well.
Comment: From my experience KML is really convenient if you're adding a lot of markers, it really improves the drawing on the map. In my case I was trying it with 15,000+ markers, and it drew them on the map in a split second using KML, but it took a few seconds to render on Firefox, and slightly quicker on Chrome using the Marker class.
Answer: You can't access the markers in a KmlLayer (it is rendered as map tiles by Google's servers). You could use a FusionTableLayer (you can import KML into the FusionTable, then modify the query to that FusionTable to filter the markers) or a third party KML parser like geoxml3 or geoxml-v3 (which render the KML using native Google Maps v3 objects).
example using geoxml3
example using FusionTables


Invalid argument error when I want to instantiate i2c device in linux

Question: I have an RTC chip on my board that I want to add it to linux as i2c device. I have an script that runs at startup of my embedded linux and in it I have this line :
echo ds1337 0x68 > /sys/bus/i2c/devices/i2c-3/new_device

sometimes it works, but sometimes it gives an error :
root@t1042d4rdb:~# echo ds1337 0x68 > /sys/bus/i2c/devices/i2c-3/new_device
-sh: echo: write error: Invalid argument

how I can fix this unstablity ?
Comment: I would use `i2ctransfer` for this, not plain echo.
Comment: as I read about this command, it uses for writing in i2c devices like i2cset , but I want to add my device and introduce device to OS to be able to read and write to it
Comment: Then you need to write a low-level driver. I have never done this before, as I have written only drivers on top of an existing I2C infrastructure. What is easier in the end depends on what environment (particularly programming language) you want to use to talk to your device.
Comment: Why don't you add the RTC in your device tree?
Comment: thank you, It can be a solution that I must test it. but my question is about "invalid argument" in that command! because this command is correct!
Comment: So, what is the problem to add it to your Device Tree Source file, compile and use?
Answer: After sending the command after boot for the first time you will see that it throws this error when you try to send it again.


Figuring out how to mock the window size changing for a react component test

Question: So basically when the component mounts, I have an event listener listen for resize events. It toggles the isMobileView state and then passes it into the children as a prop. So it's imperative that this works and is tested. I'm fairly new to testing and I'm trying to figure out a way I can write a test that resizes the window and makes all the logic happen and test that it executed how it should.
Here is the code -
componentDidMount() {
    this.setMobileViewState()
    window.addEventListener('resize', this.setMobileViewState.bind(this));
}

setMobileViewState() {
    if(document.documentElement.clientWidth <= this.props.mobileMenuShowWidth) {
        this.setState({ isMobileView: true })
    } else {
        this.setState({ isMobileView: false })
    }
}

I know the code works, but I want to write a test for it. Basically just something that makes sure the state changes correctly.
Answer: Using Jest and Enzyme you can do the following. Jest has JSDOM baked in. In your tests Jest provides the window object and it is represented by global (I think that the default window.innerWidth set by Jest is 1024px):
test('Test something when the viewport changes.', () => {

    // Mount the component to test.
    const component = mount(<ComponentToTest/>);

    ...

    // Change the viewport to 500px.
    global.innerWidth = 500;

    // Trigger the window resize event.
    global.dispatchEvent(new Event('resize'));

    ...

    // Run your assertion.
});

Comment: It seems this no longer works: `Property 'innerWidth' does not exist on type 'Global'`
Comment: according to docs at https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth, innerWidth is read only. should we use window.resizeBy(x, y); instead?
Comment: I'm on Jest 23.6.0 and it works for me, maybe needs an upgrade ♂
Comment: Confirmed working still in Jest 24.1.0 as well.  the `resizeBy` would make sense to use but Jest does not implement that and the `innerWidth` is not read only
Comment: i tried setting innerWidth on window object but my @media css query didn't seem to kick in for the test. does this only work for 'global' object in node.js, or should it work for 'window' object in browser too?
Comment: Working fine in Jest 21.2.1
Comment: I recommend putting this in a `beforeEach(() => { global.innerWidth = 500; global.dispatchEvent(new Event('resize'))'; });` so that you have control of the `window.innerWidth` for subsequent specs.
Comment: would we need to reset the window width after the test is run? would be better to mock the property getter for the particular test instead of changing it directly on global
Comment: Works fine in 2022, using `@testing-library/jest-dom: 5.16.2`.
Comment: Interesting @crevulus It does not work for me, my tests just hang. Using 5.16.1 and Node 14.
Answer: If you are getting the typescript error message

Cannot assign to 'innerWidth' because it is a read-only property.

Try:
Object.defineProperty(window, 'innerWidth', {writable: true, configurable: true, value: 200})

Answer: Try this line:
window = Object.assign(window, { innerWidth: 500 });

Answer: For anyone who's using react-testing-library, there is a native way to achieve it using fireEvent as well.
  import { fireEvent } from '@testing-library/react';
  ...

  it('should resize', () => {
    window.innerWidth = 500;
    fireEvent(window, new Event('resize'));

    // your test here
  });

Comment: Don't see any TS requirement in the question.
Comment: NB: this will only work in JS.
window.innerWidth is a readonly property - you will get build errors.
See @Lauren Madigan's annswer above if using TS
Answer: It worked for me with testing library:
  it('should resize', () => {
    const altImage = 'test'

    window.innerWidth = 500

    fireEvent(window, new Event('resize'))

    waitFor(() => {
      expect(screen.getByAltText(altImage)).not.toBeInTheDocument()
    })
  })

Answer: jest.spyOn(window.screen, "width", "get").mockReturnValue(1000);

Comment: Please don't post code-only answers. The main audience, future readers, will be grateful to see explained *why* this answers the question instead of having to infer it from the code. Also, since this is an old question, please explain how it complements the other answers.
Answer: I did it this way with testing library:
function fireResize(width) {
  window.innerWidth = width;
  window.dispatchEvent(new Event('resize'));
}

it('some test', async () => {
  ....
  await waitFor(() => {
   fireResize(500);
  });
  ....
});

Source: https://medium.com/@dawchihliou/testing-react-hooks-6d3ae95cd838


Problems with range of songs

Question: I started singing when I bought a guitar (a year ago).
Since that, I noticed I can't sing properly almost all songs I play.
I've searched a bit and found out some texts about vocal range.
My range now is from F2 to D4 and falsetto up to C5.
When I checked a table of common vocal range by types, it seems like I have a baritone range but without the high notes.
Recorded 3 audios to try show you what happen (all recorded during night):
Low register: Hurt - Johnny Cash
Medium to high register: Space Oddity - David Bowie (falsetto only for the highest note)
High register: All of me - John Legend (a lot of falsetto. Tried full voice in the end. Did not work)
Should I focus on my bottom range or should I try high notes?
In other words, am I a untrained bass or a untrained baritone?
If I should try high, what am I doing wrong while trying sing high?
Thanks!
Answer: Not listened to your voice, but with a range of two octaves and more, it's enough for most pop type songs.
The problem is most likely that you're trying to sing in the recorded key. It obviously was a good key for the artist, but you haven't the same range as them.
Listen to some songs that have been recorded by many different artists. It will become clear that they're not all in the same key. Some will argue that the song isn't as good in any other key - that's subjective. Most times it'll sound better if the key matches the singer's range.
Taking a song in, say, E, that's too high in parts, you can transpose it down a tone to D, or a couple of tones to C, to get it into your range. Simple thing - find the highest notes that you struggle with, sing them gradually lower and lower, till you're happy they sound o.k. That's your new key. It probably won't make the lowest notes in that song too low. If it does, then the range of that song is too big for your voice. Find another! Song, not voice!
The downside of all this is that the voicing of some of the chords won't sound the same as in the original recording, although if the song needs to go up a bit, a capo is your lifesaver. Bear in mind that a lot of songs went through key changes before they were ever recorded. 'Hotel California' certainly wasn't written in Bm, the key the Eagles recorded it in.
Comment: I change the key when I play the song on guitar. But when I sing along the singer its not possible. But, the problem you pointed out occurs a lot. I play the song much lower to hit the high notes thereupon I cant hit the lowest note (My range is shorter than 2oct btw).
Answer: This website can help you: Song to Sing (https://songtosing.net/)
First you will have to input your vocal range: F2 to D4 in your case.
Based on that the website will offer you the songs that fit your voice. You can filter them by singing difficulty and by music style.
For any song that you can not sing in original key the website will offer you a transposition needed. Basically you will know on which thread to put your cappo.
Answer: I personally believe you are a baritone, as your lows sound very throaty, but that very well could simply be improper technique. As I'm sure the majority of responses reply with, the best and only surefire way for you to ever know your voice type is simply getting a vocal tutor.
Answer: While vocal training can extend your range and improve the notes within it, the usual solution to a song being outside your range is to change the song's key. Professional singers choose a particular song's key primarily because the chosen key lets them sound best. So if singing a song in B brings your voice to the extreme low end of your range, try singing it in C or D instead.
If you want to really sound your best and know what voice classification you'd have in classical music, you will need to take professional voice lessons.

Problems with range of songs


Random variable that symbolizes time

Question: Small question on exponential distribution

Let $X$ be a random variable and the duration of a phone call. We know that already $1$ minute has passed. How big is the probability that the phone call goes on for $3$ additional minutes? The CDF is $$F(x)=1-e^{(-1/4\cdot x)}$$

So my thought is to use the formula for the conditional probability:
$$P(X \ge 4 | X > 1) = \frac{P(X \ge 4 \cap X > 1)}{P(X > 1)}$$
I know that $P(X > 1)= e^{(-1/4)}$ but I'm not sure how to compute $P(X \ge 4 \cap X > 1)$. Is this the same probability as $P(X\ge4)$? I mean if $4$ minutes pass, this also implies that $1$ minute has passed.
Comment: Yes, you're right about $X\ge4 \implies X>1$
Comment: @GNU Supporter Thank you
Answer: $P(X \geq 4 \cap X>1) = P(X \geq 4)$ since $\{X \geq 4\} \subset \{X >1\}$.

Random variable that symbolizes time


Does the piano really originate as a combination between drumming and guitar?

Question: I heard this concept from one my friends, who is a guitar player, that first the guitar and the drum were created, and then somebody decided to drum on guitar and so was the piano born.
I really thought about this since the piano is really a guitar where keys hammer the strings like a drum.
Comment: The concept is ludicrous, and needs a lot more convincing information from your friend. Drums have skins, which are missing from pianos. And how do pianos change the length of their strings, as guitars do? Maybe he meant banjos?
Comment: Each string in a piano is a certain length. Each string stays that certain length. On guitar, there are normally six strings, of certain length. If that length could not be changed by fretting, a guitar would only play six separate notes. As it is, a guitar can play 48.
Comment: Playing different pitch notes on a guitar string necessitates changing their speaking length - by fretting in different places. Pianos and drums don't do that.
Comment: The two instruments probably have a common ancestor if you go far enough back in history and choose your evidence carefully enough, but saying a piano is a drum guitar is no more valid or helpful than saying a guitar is a drum piano. I'm really not sure what this question is seeking to achieve, hence the downvote. Sorry!
Comment: Is your last paragraph trying to explain why you found this intriguing, or is it trying to explain why you feel that it sounds plausible?
Comment: @awelotta Both I presume
Comment: @Tim The guitar doesn't change the length of her strings.
Comment: @Tim Pianos do.
Comment: @SteveMansfield "the guitar is a drum piano" ... i... don't really understand this. "The piano is a drum guitar" makes at least some kind of intuitive sense—you take outstretched strings (like a guitar) and drum on them (like a drum) to get a piano. how does one think of the guitar as a "drum piano" ?
Answer:
Is a piano really a drum guitar?

'Drum guitar' sounds cute, but there are more precise words we can use.
The piano and the guitar are both chordophones, using strings to make their sound. The piano is a 'struck' or 'percussive' chordophone, while the guitar is generally a plucked chordophone (though some percussive techniques are possible).
The practice of classifying instruments is called 'organology'. One classification is the Hornbostel–Sachs system, which sees the Piano as a 'board zither'.

first a guitar was created and a drum, and then somebody decided to drum on guitar and so was the piano born

I'm not an expert on the history of the piano, but from a quick google around, that does not seem correct. When it comes to struck chordophones, the piano seems to have been predated by the hammered dulcimer:

and the piano itself seems to have originally evolved from the harpsichord, rather than the guitar. According to http://www.piano-keyboard-guide.com/history-of-the-piano.html, the early piano may have simply been seen as a type of harpsichord:

Many years after the first version of the piano was created it was still called a harpsichord. This has made it difficult to know this specific aspect of the history of the piano, whether the great composers of the age such as Scarlatti or Vivaldi knew of its existence. The word pianoforte, shortened later to piano, appeared only in 1732.
Answer: The other answers are great, but I would like to add some historical context.
The piano was developed from the family of harpsichord instruments (including several variants like virginals) in the 18th century. The predecessor of the harpsichord is believed to be the medieval psaltery and to some extent the organ. The psaltery is most likely of middle eastern origin.
The modern guitar evolved from the baroque guitar, which substituted the earlier vihuela, a common instrument in Renaissance Spanish music. The predecessor of both the baroque guitar and the vihuela is the lute and the arabic oud.
Although there might be a common predecessor to both psaltery and oud, it is located deeply in prehistoric times.
Answer: (PhD in music history, so I will just pontificate in as officious a manner as possible)
(also, former harpsichord student - I've always maintained that piano is a percussion instrument, so the notion of a 'drum guitar' is seriously LOL. But if you drum a guitar you get, I dunno, a flamenco guitar with touch plates?)
The piano was one of a huge number of 17th- and 18th-century experimental keyboard instruments. In pre-industrial times, it was easy to make keyboard instruments with all sort of weird designs. Most of these vanished; a couple had brilliant futures.
The best-known keyboard instruments were: the organ, which continued on through with various designs but no interruptions, the harpsichord (which plucked metal strings), which gradually dwindled out during the 18th century, and the fretted clavichord, which was by far the most common instrument, at least in Germany and Iberia. This worked by touching the strings with little brass blades. "Fretted" means that each set of strings could play more than one note, for example C and C-sharp would be played on the same set of strings by shortening the string, sort of like a guitar (they did this by angling the key-levers).
In addition to these 3 standard instruments, there were all sorts of experiments including the unfretted clavichord (each key played only one set of strings), the piano, the tangentenflügel (the strings were hit by jumpy little "jacks"), the lautenwerk (a harpsichord with gut strings, which must have been a monster to keep in tune), the geigenwerk (which produced a continuous sound by means of cranked rosin wheels; you can find modern replicas on youtube and they sound weirdly awful), the cembal d'amour (a kind of double-length clavichord), etc., etc.
The piano, in fact, was invented maybe independently several times, the first in Italy in the early 18th century, where it kind of died out, and then again in Germany a few decades later, with a different design. It took a little while to get enough kinks worked out before it started to catch on (JS Bach helped a bit here, actually, advising one of the makers about the tone).
So, the piano is just a survivor from the experimental period, and there's no historical connection with the guitar.
But I like the idea, anyway.
Answer: Yes it is "true". But I wouldn't call this ancestor a guitar but a Psaltery, kind of Dulcimer.
In particular, the entry on Wikipedia about the Piano is correct.
Btw: In modern music (mostly, but not solely), the piano is sometimes regareded as a drum-instrument, see e.g. some compositions of Cage or Bartok.
Comment: So guitar came first, then dulcimer / piano camer after?
Comment: @awelotta I think first came the drum, then the voice, then the brass, then the string or guitar, then piano.
Comment: I've never seen a piano classified as a percussion instrument
Comment: @skinnypeacock Edit: You may want to listen to this pieces:
- Bela Bartok - Out of Doors - With Drums and Pipes:
https://www.youtube.com/watch?v=BUuIc_Tj1mA
- John Cage Sonata no.5: https://www.youtube.com/watch?v=DiXS2WnlfSE
Answer: My understanding has always been that the piano was derived from the idea the increased dynamics could be achieved in the harpsichord if the strings were hammered instead of plucked, but I can imagine that those dynamics may have been realized when someone hammered the strings on a guitar or dulcimer or a harp. I have not come across actual documentation to verify this idea and I don't know if it even exists. I can only say for sure I haven't heard this story before.


Why do I get so different estimations with glm and glmer?

Question: I am using the glmer function (lme4 package) to get estimations in a Poisson regression model (generalized linear model).
I wanted to compare the estimations for the fixed effects with those obtained with the glm function.
I was surprised to see big differences !
 I know that glmer includes random effect; but that does not suffice to explain theses differences.
Could someone explain to me what I missed in my approach ?
EDIT and ANSWER :
Put an offset term in both glmand glmer
    library(surrosurv)
    library(survival)
    library(lme4)

     data(colon)
     colon1 = subset(colon, etype == 1)
    # Poissonization

   don_pois = poissonize(colon1, interval.width = 365.25, factors = c ('surg', 'rx'), compress = FALSE)
   names(don_pois)[3] = 'trt'; names(don_pois)[4] = 'trialref'

    fitpoi_glmer   <- glmer(
                    formula = event ~ -1 + interval + ( 1 | trialref ),
                    data = don_pois,
                    family = poisson(link = "log")
                     )

    fitpoi_glm <- glm(
      formula = event ~ -1+ interval + offset(log(time)),
      data = don_pois,
      family = poisson(link = "log")
    )

    summary(fitpoi_glmer)$coefficients
    summary(fitpoi_glm)$coefficients

# Survival graphics

   fixed.coef.glmer = summary(fitpoi_glmer)$coefficients[,'Estimate']
     risks0 = exp(fixed.coef.glmer[grep("(?!.*:)interval.*", names(fixed.coef.glmer), perl = T)]) * 365.25
     surv0 <- c(1,exp(-cumsum(risks0)))
     x = seq(0, max(colon1$time), length.out = length(surv0))
     plot(x, surv0, type ='l', col = 'blue', lwd = 2)

     risks3 = exp(coef(fitpoi_glm)[grep("(?!.*:)interval.*", names(coef(fitpoi_glm)), perl = T)]) * 365.25
     surv3 <- c(1,exp(-cumsum(risks3)))
     lines(x, surv3, type ='l', col = 'pink', lwd = 2)

     # Comparison with survfit
     lines(survfit(Surv(time, status)~1, data = colon1 ), lty = 2, conf.int= FALSE)

Comment: It seems you are right ! With adding the offset term, the two estimates are similar. Thanks a lot for your help, I was on this problem, my all day.
Comment: Glad I could help. You could answer your own question to "close" it.
Comment: What if you include the offset in `glmer`?
Answer: The apparent differences came from a simple oversight in the glmer formula.
We had to add an offset term!
I am editing the question.


How to load data from multiple CSV files into nested dictionary?

Question: I have multiple CSV files that have a date as the filename (dd-mm-yyyy.csv). All files are in the following format, including also date value as a column value:
date,        id,     name,   value1, value2, value3
03-09-2020,   3,     ACME,     123,    456,    789

How could I merge my data across all the files in one directory into nested dictionary based on the id? For example for id=3 it would look like:
dictionary = {'id': 3
{name: 'ACME'
{'date': '03-09-2020' {'value1': 123, 'value2': 456, 'value3': 789}}
{'date': '02-09-2020' {'value1': 987, 'value2': 654, 'value3': 321}}
{'date': '01-09-2020' {'value1': 231, 'value2': 564, 'value3': 979}}}}

My aim is to merge all files with daily data into one master file. Could someone help me with this? Thank you in advance!
Comment: Using a nested dictionary isn't really necessary and unless you need it for something else it is quite impractical.
Answer: I would suggest the following structure:
d={3 : {'name':'ACME', 'values':{
'03-09-2020': {'value1': 123, 'value2': 456, 'value3': 789},
'04-09-2020': {'value1': 100, 'value2': 200, 'value3': 300},
.....}}}

And the code to build this is the following
import pandas as pd:
def load_file(file):
    df=pd.read_csv('newcv.txt', sep=',')

    for i in range(len(df)):
        d[df['id'].iloc[i]]['name']=df['name'].iloc[i]
        d[df['id'].iloc[i]]['values'][df['date'].iloc[i]['value1']=df['value1'].iloc[i]]
        d[df['id'].iloc[i]]['values'][df['date'].iloc[i]['value2']=df['value2'].iloc[i]]
        d[df['id'].iloc[i]]['values'][df['date'].iloc[i]['value3']=df['value3'].iloc[i]]

You can run this function for the files in your directory
Comment: Hi archer, thank you for your help so far. I've tried the code above and got `SyntaxError: invalid syntax` and arrow pointing to the bracket at the end of this row: `d[df['id'].iloc[i]]['values'][df['date'].iloc[i]]['value1']=df['value1'].iloc[i]]`
Answer: If your only goal is to merge all the files:
import os

files = os.listdir(directory) # insert your directory
files = [file for file in files if '.csv' in file]

cols = []
data = []

for file in files:
    with open(directory + '/' + file, 'r') as f:
        text = f.read().split('\n')
        cols = text[0].replace(' ', '')
        data += text[1:-1] # remove column names and blank at end of csv

data = [line.replace(' ', '').split(',') for line in data] # assuming there is a comma and tab between columns
data = sorted(data, key=lambda x: (int(x[1]), x[2], x[0])) # sort data by id, then name, then date

with open('master.csv', 'w+') as f:
    data = [cols] + [','.join(line) for line in data]
    f.write('\n'.join(data))

Comment: Hi hhaefliger, for some reason I'm getting `FileNotFoundError: [Errno 2] No such file or directory: '04-08-2020.csv'`but my file is in the selected directory. Would you know why I'm getting this error?
Comment: it throws this error after running this loop: for file in files:
Comment: Hi sorry about that, I forgot to add directory/ before
Comment: I've fixed it now
Comment: thank you for your help! the loop worked now and I got until this moment: `data = sorted(data, key=lambda x: (int(x[1]), x[2], x[0]))` after running this it says `IndexError: list index out of range` I'm wondering if I should change anything in this line?
Comment: full error: `Traceback (most recent call last):
  File "", line 1, in
  File "", line 1, in
IndexError: list index out of range`
Comment: could you print line[0] of data
Comment: make sure that there is a comma and a tab between each column in the files
Comment: just checked. It is that
Comment: it should work now. I also made it remove the inconsistent spacing from the final file
Comment: it worked! but now when saving the output it says: `Traceback (most recent call last):
  File "", line 2, in
  File "", line 2, in
AttributeError: 'list' object has no attribute 'join'`
Comment: Just fixed that as well, I had inverted the items passed to the join function
Comment: It produced an empty csv file. Would you be able to help with this? There wasn't any error message this time.
Comment: never mind! I was doing something wrong :) it worked! thanks for your help!
Comment: Great, no problem
Answer: Your sample dictionary is not valid so not requires interpretation.
I recommend using a combination of set_index() a lambda function to generate dict of values and then to_dict()
import io
df = pd.read_csv(io.StringIO("""date,id,name,value1,value2,value3
03-09-2020,3,ACME,123,456,789
02-09-2020,3,ACME,987,654,321"""), sep=",")
(df.set_index(["id","date"])
 .assign(values=lambda x: x.apply(lambda r: {k:v for k,v in r.items() if "value" in k}, axis=1))
 .loc[:,["name","values"]]
 .to_dict(orient="index")
)

output
{(3, '03-09-2020'): {'name': 'ACME',
  'values': {'value1': 123, 'value2': 456, 'value3': 789}},
 (3, '02-09-2020'): {'name': 'ACME',
  'values': {'value1': 987, 'value2': 654, 'value3': 321}}}


Install .NET 3.5 quietly

Question: How do I install the .NET Framework 3.5 quietly? I mean, is there any command or batch to install it quietly?
Best regards
Answer: Yes, there is:
<code>Dotnetfx35.exe /q /norestart
</code>
Comment: Dotnetfx3.exe /q /norestart  or  dotnetfx.exe /q:a /c:"install /l /q
Comment: may ask if the .net already exist will it replace it or just don't install
Answer: http://sojoe.info/2006/12/21/how-to-install-microsoft-net-framework-30-silently/

Install .NET 3.5 quietly


Spring e EJB têm as mesmas funcionalidades?

Question: Spring e EJB têm as mesmas funcionalidades?
Se não, da para usar os dois em uma mesma aplicação?
Comment: Recomendo utilizar o CDI ao invés do Spring e serviços REST seguindo uma arquitetura de microserviços ao invés de EJBs. Para produtos mais novos, essas tecnologias se mostram bastante vantajosas.
Comment: Agradeço a dica, sou seguir. Atenciosamente
Answer: Não, eles possuem propósitos diferentes. O Spring é uma framework que trabalha com injeção de dependências. O objetivo é facilitar a criação de objetos deixando isso a cargo de providers específicos e não das classes que utilizam as dependências. Já o EJB é utilizado para o desenvolvimento de projetos que utilizam uma arquitetura SOA. Seu objeto é permitir a implementação de funcionalidades como serviços. Assim os sistemas tornam-se mais modulares e reusáveis, facilitando ainda a entrega contínua por serviço. Ambos podem ser utilizados na mesma aplicação, e inclusive são com muita frequência.
Comment: "No mercado atualmente é utilizado mais o CDI ". Qual a fonte desta informação? Tanto Spring quanto EJB (ou melhor, Java EE) são bem parecidos quando as funcionalidades que entregam: http://stackoverflow.com/a/29093892/2387977
Comment: http://blog.caelum.com.br/java-ee-versus-spring-retomando-a-discussao/. Uma referência, mas existem outras.
Comment: Me corrija se estiver enganado, mas no link que colocou mostra justamente o contrário: spring era mais utilizado. O artigo também é um pouco antigo, de 2012. Se for pegar um gráfico mais novo (para ser feito a justiça), usando "CDI", o mercado mostrava mais interesse que no Spring em 2012, mas já foi alcançado pelo Spring: http://www.indeed.com/jobtrends/q-java-and-ejb-q-java-and-spring-q-java-and-cdi-q-java-and-j2ee.html?relative=1, provavelmente pelo Spring 4 e suas inovações. Ainda assim, o número de vagas abertas não me parece confiável para saber qual é mais usado no mercado.
Comment: Essa é uma eterna discussão, foge do escopo do stackoverflow. O CDI é algo emergente, se você aplicar no mercado de produtos legados o spring e EJB estarão em alta. Mas pro futuro não vejo esse cenário durando muito.
Comment: Mudei a resposta para não dar margem a debates extensos.


Change computer identity while logged in via RDP

Question: If I'm logged in to an SBS 2011 server through RDP and I go into System settings and change the computer identity (machine name and domain) - will I be locked out, as the admin user I'm logged in as was created while the domain was called something else?
Comment: Are you trying to rename the SBS server?! .. Avoid very bad idea!!
Comment: I never tried with SBS 2011 but with Windows, I've done it many times. The change only takes place after reboot. So you will get told to reboot the server, reboot it and then it will have a new name.
Answer: I don't know that you'll be locked out, but that doesn't mean I'd recommend it.  Exchange and the other services on your SBS box will likely have an epic fit if you rename them.
Renaming an Exchange server is not supported, according to this.
As for renaming the domain, it's not supported with Exchange 2007 and 2010 (SBS 2011 comes with Exchange 2010).  Quoting the Introduction to Administering Active Directory Domain Rename:

The domain rename operation is not supported in Microsoft Exchange
  Server 2007 or Exchange Server 2010. DNS domain rename is supported in
  Exchange Server 2003. However, renaming of the NetBIOS domain name is
  not supported in any version of Exchange Server. Other non-Microsoft
  applications might also not support domain rename. For more
  information about other Microsoft applications that are incompatible
  with domain rename, see article 300684
  (http://go.microsoft.com/fwlink/?LinkId=185229) in the Microsoft
  Knowledge Base.

In short:  I'm almost certain that your login will work but that Exchange and Sharepoint won't.
Sorry.


Why can I play a melody starting with any key, or even change the key in the middle of the melody?

Question: I just realized that I can play any melody starting with any key on a piano, and it sounds weird only for the first key I press, and afterwards I have trouble remembering what the original sounded like.
For example, mary had a little lamb melody can be played with

c, bb, ab or b# a# g#
c#, b, a
d, c, a#
d#, c#, b
e, d, c
f, d#, c#
f#, e, d
g, f, d#
g#, f#, e
a, g, f
a#, g#, f#
b, a, g

This phenomenon really screws with my head when I'm trying to pick correct keys from memory, since any single sound i think of out of context can be satisfied by any key, in some context, and in most cases I can't quite remember the context correctly.
Can somebody explain what is going on here? Why do I remember all of these variants as equivelent, even though they're clearly distinct key sequences with quite varying key gaps in some of them? I am extremely confused, since even the basic do, re, me, fa, so, la, si, do(cdefgab) melody can be played with any key as "do", but they won't all be white consecutive keys anymore, for example, I can do so with b,c#,d#,e,f#,g#,a#,b and no longer be able to recall what the cdefgab even sounded like afterwards, and unlike original it hits every black note in one sequence.
Another consequence of this is  that it's possible to, if I mess up a note, to keep playing as if I didn't mess up, pretending that that key was the key I wanted to hit, and it'll only sound weird for the instant I hit the wrong note, but not afterwards(although at the moment of the wrong note, it's tricky to realize how much to alter the original melody for it to work out).
For example, I can play mary had a little lamb as follows:
a,g,f,b,c#,c#,d,d,d,e,e,e, g,f,d#,c,d,d,d, a#,g#,g#,a#,g#,f#,f#
and get really confused about what just happened - I know it sounded weird, but I can't remember what I just heard, in my memory all I remember is the original tune as if there was nothing wrong.
Comment: The start of "Mary Had a Little Lamb" cannot be c, a#, b#. Do you mean C, A#, G# (or C, Bb, Ab)?
Comment: Music is not about notes, it's about intervals. https://en.wikipedia.org/wiki/Interval_(music)
Comment: Also, your "a,g,f,b,c#,c#,d,d,d,e,e,e, g,f,d#,c,d,d,d, a#,g#,g#,a#,g#,f#,f#" melody no longer sounds like "Mary Had a Little Lamb" the moment you hit the "b,c#,c#,d," stretch. You only return to sounding like "Mary Had a Little Lamb" at the "a#,g#,g#,a#,g#,f#,f#" stretch.
Comment: @Dekkadeci: sure! C Bb Ab
Answer: You've realised that you can play any tune in any of the twelve keys. You also may have realised that the spacing - in tones and semitones - doesn't change at all. Yes, the physical spacing does, due to the set up of black and white keys on a piano. It would be folly to have qa piano with only white keys - it would be too wide! But if you did, the spacing for the tune would be the same wherever you started.
If you played the tune on one string of a guitar, the spacing would be like that, except as you went higher, the frets would get smaller.
The making mistakes is explained by your inner music staying in the same key as you started - the wrong notes will sound wrong, but once you're back on track, they get forgotten in the pleasure of hearing the song literally back on track.
The do, re, me is interesting. Some countries use fixed do, which is always C, whereas others use moveable do, where do is the root (key) note in a key.
Also be aware that the first note of a lot of tunes is not the actual key note. That's the case with 'Mary Had a Little Lamb'. Start on your no. 12, B A G, it's actually in key G, not B. And your first example can't be right.
Answer: You realized two phenomena:

Melodies are identified by the notes' pitch positions relative to a tonal center, not by their absolute pitches.
If you move a melody line up or down, you move the tonal center as well. When that happens, your ear cannot make sense of the notes in the old key, and so it begins to re-identify what the tonal center is. After a few notes you get used to it, and it feels like the same melody again - until the next change. Deliberate relocation of the tonal center is called a modulation.

I thought your "a,g,f,b,c#,c#,d,d,d,e,e,e, g,f,d#,c,d,d,d, a#,g#,g#,a#,g#,f#,f#" idea was funny, so I made an arrangement for it:

I split the melody to segments, and every modulation spot is preceded by one or two chords that have a "dominant" function in the next key. The chords establish the new tonal center (key), preparing the ear to understand the following melody notes in their context. You could do modulations even like an abrupt "cold start" without any warning or warming up.
(Apologies for the incorrect enharmonic spelling of Cb as "B")
Answer:
If every key was white, the pattern would be the same in each variant

Yes - and that would mean you were using an example of an isomorphic keyboard, which is a keyboard deliberately designed so that the same interval pattern relates to the same shape on the keyboard. This type of keyboard has seen an uptick in popularity recently, helped by the fact that if you don't mind playing on a touchscreen, an isomorphic layout is easy to create in software.
So although you've worked out that the various keys in which you were playing your tune needed the same interval pattern, the reason that the physical 'shape' of what you play is not the same in each case is because the traditional piano keyboard is not isomorphic.


SAS: Flat line forecast ARIMA model?

Question:

I'm trying to forecast a large dataset using ARIMA (The data does not have seasonality), I ended up getting an ARIMA(2,1,2) model where the log of volume was taken due to increase in variance over time. The model appears to fit well and the plot of residuals look good. However upon forecasting the model (for 5 years on a monthly basis) the forecast flattens out. I was wondering if this is to be expected given the large volume of data?
The last plot shows the forecasted volume with the confidence intervals plotted. I also would like to know if there is a way to make the last plot look nicer? I have been unable to get a plot of the forecast at the end of the time series data that looks nice.
Here is my code and the excel file:
<code>* Open the file;
data intel_stock;
infile 'path' dlm=',' firstobs=2;
input Date anydtdte10. Volume;
format Date date10.;
Timeref=_n_;
logvolume = log(Volume);
run;

* Plot the data ;
proc sgplot data=intel_stock;
series x=Timeref y=Volume/markers;
xaxis values=(1 to 5000 by 1);
run;
* Variation seems to increase greatly over time, hence we take the log of volume ;

proc sgplot data=intel_stock;
series x=Timeref y=logvolume/markers;
xaxis values=(1 to 5000 by 1);
run;
* Plot shows a good amount of variance removed ;

* selecting an ARIMA model ;
proc arima data=intel_stock;
identify var= logvolume(1);
estimate p = 2 q = 2 ;
forecast lead=60 interval=month id=Date out=forecast;
run;

* Merge forecast and volume into the same dataset and remove log from forecast ;
data intel_forecast;
update intel_stock forecast;
by Date;
if Date <= '19APR2021'D  then forecast = "NULL";
else forecast = exp(forecast);
if Date <= '19APR2021'D  then L95 = "NULL";
else L95 = exp(L95);
if Date <= '19APR2021'D  then U95 = "NULL";
else U95 = exp(U95);
run;

* Plot the forecast ;
proc sgplot data=intel_forecast;
series x=Date y=Volume/markers;
series x=Date y=forecast/markers;
series x=Date y=L95;
series x=Date y=U95;
xaxis values=(1 to 1000000 by 1);
run;
</code>
https://www.kaggle.com/tosinabase/intel-stock-prices-historical-data-intc
Answer: ARIMA models usually flatten out, especially if:

you have a nonseasonal model (as here)
you have an $\text{ARIMA}(p,1,q)$ model without an intercept where the $\text{ARMA}(p,q)$ model on the increments (i.e., on the differenced series, since you have $d=1$) converges to zero - again, this seems to be the case here.

This is very often the best possible expectation forecast.
We have a number of similar threads that may be helpful.

SAS: Flat line forecast ARIMA model?


rubygems error installing rails

Question: I get this error when trying to install ruby gems on my amazon instance. Can anyone explain?
ubuntu@ip-myinstance:~$ sudo apt-get install rubygems

Reading package lists... Done
Building dependency tree
Reading state information... Done
Package rubygems is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  ruby

E: Package 'rubygems' has no installation candidate

I didn't understand that message. I was following directions from http://www.frontcoded.com/rails-on-amazon-ec2-ubuntu.html which says to do that. Also I tried
which rubygems

And that came out blank. If possible I would like to take down this question to stop the negative votes. Thank you.
Comment: Did you read the message from apt-get?
Answer: You are trying to install the wrong package. In modern Ruby, rubygems come as part of it. The message you got also says so.
Even if there were a problem on the server side, not being able to download something through apt-get has nothing to do with whether rubygems site is down.
The message you got, which gives you an alternative suggestion, indicates that the relevant site (apt-get) is not down.
You can check the status of certain websites by using services like this.

rubygems error installing rails


Removing same records in reverse order after a self join

Question: I'm trying to get these two rows side by side in one row, so I've done an inner join
;WITH data AS
(
    SELECT 1 id, 'a' AS c1 UNION ALL
    SELECT 1 id, 'b' AS c1
)
SELECT *
FROM data d
INNER JOIN data d2
    ON d.id = d2.id
    AND d.c1 <> d2.c1

This returns two rows, a-b and b-a, which are basically the same but in reverse order. How can I remove this quasi-duplicate?
-- expected results would be just one row (1, a, b)
SELECT 1 d1_id, 'a' AS d1_c1, 'b' AS d2_c1

Note, there could be more than two records sharing the same id. For example,
SELECT 1 id, 'a' AS c1 UNION ALL
SELECT 1 id, 'b' AS c1 union all
SELECT 1 id, 'c' AS c1

sql server 2012
edit: Just figured it out. Row_number will get me what I need.
;WITH data AS
(
    SELECT *
        ,ROW_NUMBER() OVER(PARTITION BY id ORDER BY c1) rn
    FROM (
    SELECT 1 id, 'a' AS c1 UNION ALL
    SELECT 1 id, 'b' AS c1 union ALL
    SELECT 1 id, 'c' AS c1
        ) z
)
SELECT *
FROM data d
INNER JOIN data d2
    ON d.id = d2.id
    AND d.c1 <> d2.c1
WHERE d.rn = 1

Comment: possible duplicate of [Please explain the parts of a PIVOT](http://stackoverflow.com/questions/5443505/please-explain-the-parts-of-a-pivot)
Comment: You're looking for a pivot. Using a join will lead to a contrived solution and not work at all for more than 2 rows.
Comment: I've solved it using row_number (I think). See edit.
Comment: you have edited your question @Gabe but i have wrote the query same as you but my question (A,b) and (A,c) are coming but what about (B,C)combination
Comment: @mohan111 Hmm, you're right. (B,C) combination is not being included. I don't how to include that combination of (B,C). Fortunately, the current solution uses 'A' as an anchor to bring in all the other possible values 'B' and 'C'. That might just be enough for my needs.
Answer: @Gabe, Would this work?
DECLARE @Table TABLE (Col1 VARCHAR(10), Col2 VARCHAR(10))

INSERT  @Table
VALUES  ('B', 'A')
        ,('A', 'B')
        ,('D', 'C')
        ,('C', 'D')
        ,('DD', 'CC')
        ,('CC', 'DD')
        ,('DA', 'CB')
        ,('CA', 'DB')

SELECT  t1.Col1
        ,t1.Col2
FROM @Table AS t1
    LEFT OUTER JOIN @Table AS t2
    ON t1.Col1 = t2.Col2
    AND t1.Col2 = t2.Col1
WHERE   t2.Col1 IS NULL
      OR t1.Col1 < t2.Col1

Comment: Thanks Gabe for your responce
Answer: ;WITH data AS
(
    SELECT 1 id, 'a' AS c1 UNION ALL
    SELECT 1 id, 'b' AS c1 UNION ALL
    SELECT 1 id, 'C' AS C1
),Data1 AS
(
SELECT ROW_NUMBER()OVER (PARTITION BY d.ID ORDER BY d2.ID DESC)AS RN,d.id,d.c1,d2.id As ID1,d2.c1 As C2
FROM data d
INNER JOIN data d2
    ON d.id = d2.id
    AND d.c1 <> d2.c1

),REsult AS
    (
    Select CASE WHEN ISNULL(ASCII(d.id),0)< ISNULL(ASCII(d.id1),0) THEN d.c2 ELSE d.c1 END Col1,
     CASE WHEN ISNULL(ASCII(d.id),0)> ISNULL(ASCII(d.id1),0) THEN d.c1 ELSE d.c2 END Col2,
     ROW_NUMBER()OVER (PARTITION BY d.ID ORDER BY d.ID DESC)AS RN FROM Data1 d )

SELECT
         t1.Col1
        ,t1.Col2
FROM REsult AS t1
    LEFT JOIN REsult AS t2
    ON t1.Col1 = t2.Col2
    AND t1.Col2 = t2.Col1
WHERE   t2.Col1 IS NULL
      OR t1.Col1 < t2.Col1

Comment: The row_number has to be in the first CTE before the self-join. The current solution wouldn't return (A,C) combination. See my edit in the question


List of standard comments for review

Question: When reviewing questions by new users, I often find myself commenting roughly the same again and again.
In spirit of the Repository of useful pro-forma comments I would like to collect a list of generic comments for quick copy & paste access, specifically for Magento.SE.
A standard comment that explains why a question might be off topic or should be improved is better than no comment.

From the meta thread linked above:

To use, click "edit", and fetch the snippet's markdown source code.

Note: For these snippets to be easy to copy&paste, do not use the editor's linking method, but inline links, like so:
[This is a link](http://www.this.is.the.url)

Magic links might help too:

See [so].

Even better for easy usage: add the comment as
source code for copy and paste

and as

quote for preview
Answer: Context: No fit for Q&A
Shopping List Questions
"Shopping list" questions are not a good fit for StackExchange Q&A
(see: https://meta.stackexchange.com/questions/158809/why-are-shopping-list-questions-bad) -
you'll get better results at the Magento forums (https://community.magento.com/t5/Find-an-Extension-that/bd-p/find-extension)
or Reddit (http://www.reddit.com/r/Magento)

Preview:

"Shopping list" questions are not a good fit for StackExchange Q&A
  (see:
  Why are "shopping list" questions bad?)
  - you'll get better results at the Magento forums (http://community.magento.com) or Reddit
  (http://www.reddit.com/r/Magento)

Asking for Discussion
Open questions and discussions are not a good fit for StackExchange Q&A - you'll get better
results at the Magento forums (http://community.magento.com) or
Reddit (http://www.reddit.com/r/Magento)

Preview:

Open questions and discussions are not a good fit for StackExchange
  Q&A
  - you'll get better results at the Magento forums (http://community.magento.com) or Reddit
  (http://www.reddit.com/r/Magento)
Answer: Context: Insufficient information
Question contains attempted solution, but doesn't describe actual problem
What is the **actual** problem you're trying to solve? (see [xyproblem.info](http://xyproblem.info/))

What is the actual problem you're trying to solve? (see xyproblem.info)

Question only contains an error message
Please don't just dump error messages in the question form. You should at least explain
when it happens and if you did any changes before. To debug errors, follow this guide:
https://magento.stackexchange.com/questions/428/fundamentals-for-debugging-a-magento-store

Please don't just dump error messages in the question form. You should
  at least explain when it happens and if you did any changes before. To
  debug errors, follow this guide:
  Fundamentals for debugging a Magento store

Question contains code but does not explain what it does
If you post code, please explain what this code is supposed to be doing, what actually
happens and where you need help. You should not expect us to run the code in our head and
guess the problem.

If you post code, please explain what this code is supposed to be
  doing, what actually happens and where you need help. You should not
  expect us to run the code in our head and guess the problem.

CSS question with screenshot
Debugging CSS is hard and even harder without knowing the source. This is a task that can
best be done on site and not a good question for the StackExchange Q&A. However, if you want
to try your luck, a screenshot is not enough information to help you. Please provide as much
information as possible: Which theme are you using? Were there any modifications to the
theme? Did it work correctly before and if so, what has been changed (for example
installed extensions)?

Debugging CSS is hard and even harder without knowing the source. This
  is a task that can best be done on site and not a good question for
  the StackExchange Q&A. However, if you want to try your luck, a
  screenshot is not enough information to help you. Please provide as
  much information as possible: Which theme are you using? Were there
  any modifications to the theme? Did it work correctly before and if
  so, what has been changed (for example installed extensions)?

Frontend question with URL ("this is my site, X does not work, please help")
Debugging JS/CSS is a task that can
best be done on site and not a good question for the StackExchange Q&A. However, if you
want to try your luck, please provide as much information as possible: Which theme are you
using? Were there any modifications to the theme? Did it work correctly before and if so,
what has been changed (for example installed extensions)? Do not just drop a URL - this can
help to provide context but eventually you will fix your problem and the question remains
without value for future visitors.

Debugging JS/CSS is a task that can best be done on site and not a
  good question for the StackExchange Q&A. However, if you want to try
  your luck, please provide as much information as possible: Which theme
  are you using? Were there any modifications to the theme? Did it work
  correctly before and if so, what has been changed (for example
  installed extensions)? Do not just drop a URL - this can help to
  provide context but eventually you will fix your problem and the
  question remains without value for future visitors.

"Error" question with URL (same as above but not frontend specific)
Please do not just drop a URL and say "it does not work" - this can help to
provide context but eventually you will fix your problem and the question
remains without value for future visitors. Explain what happens, add error
messages or screenshots to the post, and also add any information that
might be relevant (like Magento version, recent changes)

Please do not just drop a URL and say "it does not work" - this can
  help to provide context but eventually you will fix your problem and
  the question remains without value for future visitors. Explain what
  happens, add error messages or screenshots to the post, and also add
  any information that might be relevant (like Magento version, recent
  changes)
Comment: The "Question only contains an error message" refers to https://magento.stackexchange.com/questions/428/fundamentals-for-debugging-a-magento-store which is for Magento 1 and is locked. Can we do anything about that? Or refer to some other question or article? What is your idea on this?
Answer: Context: First question w/ few information
Hi and welcome to Magento SE, feel free to check out this post on how to ask a question: https://magento.stackexchange.com/help/how-to-ask .
Please provide more information such as **missing info #1, missing info #2 and missing info #3** so we can help you fixing your problem.

Hi and welcome to Magento SE, feel free to check out this post
  on how to ask a question:
  https://magento.stackexchange.com/help/how-to-ask . Please provide more
  information such as missing info #1, missing info #2 and missing info #3 so we can help you fixing your problem.
Answer: Context: Too broad
General too broad
(add example tutorials, blog posts, articles if you'd like)

The question you are asking is too broad and it cannot be answered within the scope of this Q&A website. Please search for a tutorial on this topic and if you encounter more specific issues, feel free to ask them here, providing enough context.

Asking to write a complete module with almost no information
(adjust as needed, e.g. "payment module")
Asking for a walkthrough to a complete module is a bit too much for the Q&A format of this
site. Besides that, with this vague information it's not even possible to give a good answer.
We simply don't know your requirements. I'd suggest you to try starting and if you hit a
wall, ask for help here and explain exactly what you try to do, why you are doing it and
what does not work / where you need help.

Preview:

Asking for a walkthrough to a complete module is a bit too much for
  the Q&A format of this site. Besides that, with this vague information
  it's not even possible to give a good answer. We simply don't know
  your requirements. I'd suggest you to try starting and if you hit a
  concrete wall, ask for help here and explain exactly what you try to
  do, why you are doing it and what does not work / where you need help.
Answer: Context: First answers, not following the guidelines
Link to blog or article
Welcome to Magento SE. If you post links in an answer, please make sure that the answer is
still valuable, if the link becomes dead at some time: For example, summarize the linked
article or quote the relevant parts. This is important because StackExchange aims to be a
knowledge database, not a support forum that helps one person right now. Future visitors
should still benefit from the questions and answers.

Welcome to Magento SE. If you post links in an answer, please make
  sure that the answer is still valuable, if the link becomes dead at
  some time: For example, summarize the linked article or quote the
  relevant parts. This is important because StackExchange aims to be a
  knowledge database, not a support forum that helps one person right
  now. Future visitors should still benefit from the questions and
  answers.

Self-answered question with answer in question
Welcome to Magento SE. Please do not post answers as questions. You can however answer
your own question (it's even encouraged!), if you want to share a solution for a problem
where no question exists yet. Please rephrase the question so that it is an answerable
question and post your solution as an answer. Thanks!

Welcome to Magento SE. Please do not post answers as questions. You
  can however answer your own question (it's even encouraged!), if you
  want to share a solution for a problem where no question exists yet.
  Please rephrase the question so that it is an answerable question and
  post your solution as an answer. Thanks!

Only code in answer
Welcome to Magento SE. If you post code as an answer, please at least explain
briefly what this code is doing and where it belongs. Answers with code but no
explanation are rarely useful.

Welcome to Magento SE. If you post code as an answer, please at least
  explain briefly what this code is doing and where it belongs. Answers
  with code but no explanation are rarely useful.
Answer: Context: Technically incorrect or problematic answers
This is for answers with questionable advice. Usually this does not mean that they should be flagged, but probably downvoted.
Delete var/session on a production site:
Deleting `var/session` on a production site is never an appropiate solution. See also:
https://magento.stackexchange.com/questions/94589/keeping-customers-logged-in-after-deleting-var-session

Deleting var/session on a production site is never an appropiate
  solution. See also:
  keeping customers logged in after deleting var/session in magento

Using ObjectManager directly:
Using the `ObjectManager` directly is highly discouraged as it goes in against its design. You should use constructor dependency injection instead. See also:
https://magento.stackexchange.com/questions/117098/magento-2-to-use-or-not-to-use-the-objectmanager-directly

Using the ObjectManager directly is highly discouraged as it goes in against its design. You should use constructor dependency injection instead. See also:
  Magento 2: to use or not to use the ObjectManager directly?
Answer: Context : Send Notification
When more than one user commented on OP's question, but the commenter did't tag a username when writing a comment, in that case, commented users don't get a notification.
If you want to notify the user, please [@tag](http://meta.stackexchange.com/q/43019/307988) their name in the comment.

List of standard comments for review


How to resolve the error when posting a new node with Image Field and Entity Reference?

Question: I'm trying to create a new node using Drupal 7 + Services 3. The node type is 'activity_photo' has an image field, and a reference to a node. This is what I'm posting to the service
{
 "type":"activity_photo",
 "field_node_reference":{
 "und":[{
 "target_id":"x (1273)"
 }]
 },
 "field_photo":{
 "und":[{
 "fid":"20077"
 }]
 }
}

The response is status 200:
{"nid":null,"uri":...}

My error log shows the following:

Notice: Undefined index: display_field in file_field_widget_value()
Warning: end() [function.end]: Passed variable is not an array or object in file_managed_file_validate()
Notice: Undefined index: nid in _node_resource_create()

Any help on how to proceed?
Answer: In the end I changed the entity reference field to select list and posted like this:
{
 "title":"test",
 "type":"activity_photo",
 "language":"und",
 "field_node_reference":{
 "und":[1273]
 },
 "field_photo":{"und":[{"fid":"8880"}]}
}

also, I found my own modules was implementing hook_form_alter for this form, and this had further complications to be addressed to get it to work. So any hook_form_alter is something to remember when looking for similar problems.