How do I use Spark ORC indexes?

Question: What is the option to enable orc indexing from spark?
          df
            .write()
            .option("mode", "DROPMALFORMED")
            .option("compression", "snappy")
            .mode("overwrite")
            .format("orc")
            .option("index", "user_id")
            .save(...);

I'm making up .option("index", uid), what would I have to put there to index column "user_id" from orc.
Answer: Have you tried : .partitionBy("user_id") ?
 df
        .write()
        .option("mode", "DROPMALFORMED")
        .option("compression", "snappy")
        .mode("overwrite")
        .format("orc")
        .partitionBy("user_id")
        .save(...)

Comment: I think partitionBy will create a new file per user, rather than create an index. But you're only one that answered so I give you the bounty.
Comment: @ForeverConfused i am researching on this. Will let you know soon.
Comment: @Achyuth, have you found any approach to create index in ORC file? I found nothing till today. It seems to me the only way to leverage index in ORC file is using Hive. Please correct me if it's wrong. Thanks!
Comment: @JamesGan Thats true, The file is already indexed on many thing, stats collumn offset etc. The best way to achieve the performance is by creating an orc files which are around 200 to 300 mb.
Answer: According to the original blogpost on bringing ORC support to Apache Spark, there is a configuration knob to turn on in your spark context to enable ORC indexes.
# enable filters in ORC
sqlContext.setConf("spark.sql.orc.filterPushdown", "true")

Reference: https://databricks.com/blog/2015/07/16/joint-blog-post-bringing-orc-support-into-apache-spark.html

How do I use Spark ORC indexes?


Why did the Apache directive to handle a clean URL get changed?

Question: I noticed that the clean URLs implementation has gotten more complicated in Drupal 7. Rather than RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] used in Drupal 6, Drupal 7 .htaccess has simply RewriteRule ^ index.php [L], with a comment that says "Clean URLs are handled in drupal_environment_initialize()".
I read through drupal_environment_initialize() and understand that it's using REQUEST_URI to manually set $_GET['q'], but why the change? I see the comment:
// When clean URLs are enabled, emulate ?q=foo/bar using REQUEST_URI. It is
// not possible to append the query string using mod_rewrite without the B
// flag (this was added in Apache 2.2.8), because mod_rewrite unescapes the
// path before passing it on to PHP. This is a problem when the path contains
// e.g. "&" or "%" that have special meanings in URLs and must be encoded.
$_GET['q'] = request_path();

I've got some idea what this is saying, but can anyone explain in fuller terms the reasons behind the change? If it wasn't done this way before, was something (minorly or seriously) broken in Drupal 6 and prior?
Answer: There was something seriously broken, but it only affected a handful of cases due to fringe nature of the issue. Essentially, what happens is roughly (%26 == &):
Request: /lost%26found
Rewrite: /index.php?q=lost&found

The issue here is obvious when you see it this way: you end up with two $_GET variables, q = 'lost' and found which isn't set properly. Since the q variable is truncated, you end up with the wrong page or a 404 error.
Drupal 7 fixes this by simply redirecting to index.php and then parsing the original query string manually itself, bypassing Apache and PHP's parsing of it entirely.
Answer: Using the rewriting rule used in Drupal 6 there would be a problem when the path contains escaped & or % that are changed back to respectively & and % from the "mod_rewrite" Apache module. The solution would be using the following rewriting rule, but it would require Apache 2.2.8 or higher, when Drupal 7 is compatible with any Apache 2.x versions.
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,B]

Between being compatible only with Apache 2.2.8 and higher, or being compatible with all the Apache 2.x versions, they preferred to the compatible with all the Apache 2.x versions.
To understand why unescaping & and % is a problem, suppose a third-party module is able to handle a path such as title/12&id=13; the path would be changed to index.php?q=title/12&id=13 instead of index.php?q=title/12%26id=13. The effect is that the module would get title/12 as path, instead of title/12&id=13.


Binding on Guitar Neck Cracking/Peeling/Splitting

Question: I bought a guitar about 6 months ago from a guy in Chicago, getting it shipped all the way to Australia. When it arrived (Epiphone Sheraton II) i noticed that there was somewhat of a crack on the neck where the fret-board meets the head-stock. It looks like the previous owner has changed the nut which I suspect may have caused the crack/split/peel. I haven't actively noticed any progression of the peeling/cracking/splitting.
So what I want to ask is, do you think I should get it looked at by a Luther? Is there anything i can do myself? Or is it harmless and I should leave it be?
I appreciate any input on the matter.
PS. I also hang my guitar on my wall when im not playing it during the day and put it bad in its case during the evenning, should I stop hanging it from the wall? It is quite bottom heavy, so I imagine that it could put some unwanted tension on the neck that could potentially contribute to the current problem.
Best Wishes,
Trash Incarnate
Comment: Shame - they're lovely guitars - I use one. Pics will help, but have you asked the previous owner about it? When guitars fall over, that place is often where damage occurs - I've mended several with breaks there.
Comment: Makes sense NOT to hang it anywhere at the moment...
Comment: It could be a paint crack, but without a photo it's hard to tell. Can you edit the question with an uploaded photo?
Comment: Could do with some other pic. angles. It may be that the neck split at the nut position, causing a new nut to need fitting. As Jamie says, it doesn't look right. Mine is nothing like that one. Sounds like a luthier trip is in order!
Answer: I think you're right in saying the previous owner has changed the nut, I don't know that model of guitar personally, but to me that really doesn't look right, or like it even fits. I'd definitely have a Luther take a look at it, because that does look like a crack in the wood and not just the binding or paint. It doesn't hurt to be a little over cautious sometimes and like Tim said, it's best not to hang it from the wall until you know for certain. Try and use a regular guitar stand if you've got one.
Answer: It appears from the photo that you have a slight crack in or near the joint where the headstock meets the neck.  This is typically the weakest part of a guitar neck.  Many guitars have a separate piece of wood from which the headstock is carved and it is joined to the neck with a glue joint.  But it is also where the neck get's thinnest to allow for the angle of the headstock.
It is common for guitar headstocks to break during flights on an airplane.  It used to be thought (and some still believe) that changes in the atmospheric pressure/air temperature during flight (combined with string tension) was a contributing factor to this but the truth is that most damage occurs due to rough handling by the baggage handlers.
It is recommended that when you ship a guitar, that you support the headstock inside the shipping box or case by stuffing packing material around it, filling all the voids, so it is stabilized.  A sudden jolt to a guitar neck due to something like tossing the case into a luggage hold - could easily crack or snap an unsupported headstock.
If you have not already done so, you might want to seek some relief for the damage if it occurred during shipping, or from the original seller if he/she failed to disclose the damage.
If applying pressure to the cracked headstock causes it to open slightly (get a little larger) it can be repaired by injecting the right type of glue into the crack with a hypodermic needle and then clamping it. Or for a larger crack, you can push the glue in with a stiff piece of paper or plastic film.
There are tons of videos like this one How to repair a cracked headstock on YouTube which show different ways of repairing cracked headstocks and guitar necks.  But unless you are very handy with tools, you might want to have an experienced guitar repair technician or luthier make the repair for you.
If the crack does not seem to move or open up when you flex the headstock, it might be fine to just play the guitar and hope for the best.  Maybe you use this guitar for a drop or flat tuning to put a tad less string tension on the neck and it might help prevent the crack from getting worse.
If you do notice it starting to get worse, it is probably best to get it repaired before it breaks completely off.  Although even if it breaks completely off the neck, it can still be repaired.  And the good news is, with the right glue, the repair is likely to be stronger than the original wood.
Good luck!
Answer: It looks like the instrument took a hit to the headstock at some point.  If you can't flex it or hear it rattling and it isn't changing, it probably isn't something to worry about.  Alternatively, it is possible that there was some kind of acute thermal stress, perhaps during its flight to down-under.
Also:  the strings put more than 100lbs of force on the neck, while hanging it from a wall puts about 6lbs.  I wouldn't worry about hanging it from a wall.


make 'href' tag point to separate item in a loop

Question: Please I want to create a separate download link to file in a folder, I displayed the title from the database in a loop.
$sql = "select title from item
        where own_id = {$id} and item_type='lecture'  ";

$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($rows = mysqli_fetch_assoc($result)) {
        echo ""."Download" .""."  ".$rows['title']."
 ";
    }
}

I want the 'href' to point each file not just one as shown
Answer: try echo "<input type='text'>";
or
try : echo "<input type=\"text\">";
Answer: Hi I assume the files name is like this [title].pdf.zip so your code should be :
$sql = "select title from item
        where own_id = {$id} and item_type='lecture'  ";

$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($rows = mysqli_fetch_assoc($result)) {
        echo ""."Download" .""."  ".$rows['title']."
 ";
    }
}

Comment: Just what I want


setTimeout is not getting called

Question: I have wrapped my function call in a setTimeout method like this with for example a 2 second delay. But it is NOT doing anything. It is not causing any delay.
What have I wrote wrong?
onclick="setTimeout(MyOriginalFunction('2004', 'Y', 'M', '12'),2000);"

Comment: The argument to `setTimeout` has to be a reference to a function, not a function call itself.
Answer: Try this for passing parameter in setTimeOut function.

function GiveMeCall(name){
alert('Called me '+name);
}
<button onclick="setTimeout(function(){GiveMeCall('Rahul')},2000);"
 >click me</button>

Please have a look it is getting called. let me know if this is helpful for you.
This SetTimeout function only look for reference of the function.

function MyOriginalFunction(){
alert('Called me');
}
<button onclick="setTimeout(MyOriginalFunction,2000);"
 >click me</button>
Comment: what about the parameters for the function? how would you pass those?

setTimeout is not getting called


Can a breath controller be used with a keyboard?

Question: I was watching a youtube video and saw a piano like instrument that was new to me, and have had a hard time identifying what it was.  I loved the timbre and the idea for it:
Eric Clapton Live Performance of Somewhere over the Rainbow at 2:15
I did looking around, and found something called a "melodica".  It seems similar, but there are differences:

Melodica has less range.
It is higher pitched.
Melodica has a brighter sound, but I like the dark sound of the instrument in the video.
The mouth piece seems different.

Can anyone identify the instrument by name or possibly by a reference to somewhere it is sold?  (I'm not asking for advertising, but if it is the only way to identify something then it is still much appreciated.)
Also the name of the performer might be useful too, since I can find other videos of him playing the instrument.
I also noticed that in the last few seconds of the video, he is playing without the mouth piece in.  Perhaps it is not an "instrument" so much as an accessory for a keyboard?  I don't know.  Thanks for any help.
Comment: **Welcome to Music.SE!** Usually questions about identifying instruments get closed, because they are not useful to future readers. **However, I think this should stay open. Looking at the clip, the performer seems to be playing keyboard using a "breath controller". Very interesting...** (As you say, an accessory.) It might possibly be helpful to change this question to be more general, and not specifically about this one song/performer; you could still use this song as an example.
Comment: @BobBroadley Thank you, this is my first post to this stackexchange (although I have used others).  I'll look up breath controller, and please feel free to edit my post if you think it may be better presented.
Comment: Breath Control is part of the Midi spec, CC2. Whether anything is mapped to use it or not, is of course, another matter - but through a sequencer you could variably map to volume/expression, 'brightness' of one sort or another, attack, etc. (& thank you for knowing how to use YouTube time-stamps. Most considerate.)
Comment: There used to be dedicated wind controllers, set up for saxophone-style playing - see http://windsynth.net/faq.html - though idk whether you can still get them
Answer: It probably depends on the keyboard's expander whether it supports this kind of input.  It probably is linked to the "expression" controller or pedal.  An obvious candidate for Midi expanders dealing with this kind of input are those which specifically support use with an accordion since reasonably recent accordion midification sets usually include a pressure sensor.
Another good candidate are normal keyboards which are also available in an "accordion" version (for example, among the oldtimers the Solton/Ketron MS-80 is an accordion keyboard version of the MS-100, so the MS-100, a regular keyboard, is a good candidate for breath controllers).
Of course this also means that electronic accordions (or their keyboard variants) are sort of predestined as a controller for creating music controlled by pressure, and if you use the bellows rather than a mouthpiece, you even remain able to sing along.  And you can even get acoustic-only accordions for that kind of expressive play.
The acoustic flat hand-sharing-manual keyboard variant is a harmonium.  However, the have a lot more inertia regarding the bellows control: you can use them for general loudness variations, but they don't really work well for actual articulation.
Comment: I remember my first ever Frankfurt Musik Messe way back in the late 80s/early 90s… I couldn't believe how many synths had been turned into accordions - DX7 was the weirdest, closely followed by the Novation BassStation ;)
Answer: What was David Sancious playing in Eric Clapton's 'Live tour 2001' Show?  Probably a Peavey DPM C8 controller…discontinued now.  Or a Kurzweil K2600. And some sort of breath controller.


"Allow multiple values" vs "Allow multiple filter values to work together"

Question: In Views, when adding an Argument for a vocabulary term id, I'm presented with the following 2 options:
Allow multiple values
If selected, users can enter multiple values in the form of 1+2+3 (for OR) or 1,2,3 (for AND).
Allow multiple filter values to work together
If selected, multiple instances of this filter can work together, as though multiple values were supplied to the same filter. This setting is not compatible with the "Reduce duplicates" setting.
The first option is perfectly clear to me. The second, however, I'm struggling with. What exactly does it do, and how does this differ from the "Allow multiple values" option?
Can the two of these options be used together? If so, what would be the expected outcome?
Thanks!
Answer: Allow multiple filter values to work together is used when you want to pass multiple arguments to and match against one field.
In other words allows for 'many to one' joins
In a sense it is similar to 1, 2, 3, however if you need to pass multiple sets like 123+345 and 889+678 there need to be 2 separate joins to the same table.
(assuming sometable has multiple results for your desired value like:
|nid|yourvalue|
|1  |123      |
|1  |345      |
|2  |678      |
|3  |222      |
|1  |789      |
|1  |823      |
|1  |845      |
|2  |678      |
|3  |222      |
|1  |889      |
select node.title from node node
join sometable sometable_1 on sometable.yourvalue in (123,345)
join sometable sometable_2 on sometable.yourvalue in (889,678)
Therefore 'Allow multiple filter values to work together' is the only way to get view to return nid 1
this is useful when you need to pass arguments that come from different sources (i.e. 1 could be taxonomy terms from 2 different vocabs).
I used this only when dealing with entityreference field that references terms from different vocabularies


$A^TPA-P$ is negative definite, does it imply that $APA^T-P$ is negative definite

Question: If $P$ is positive definite, and if $A^TPA-P$ is negative definite, does it imply that $APA^T-P$ is negative definite?
Comment: Welcome to MSE. Please read this text about [how to ask a good question](https://math.meta.stackexchange.com/questions/9959/how-to-ask-a-good-question).
Comment: Any conditions on A? Otherwise you can just pick P to be the unit matrix and A to be triangular to get a counterexample
Comment: The condition on A is that its eigenvalues are in the unit circle.
Answer: No. Take this example $$P=\begin{pmatrix}1&0\\0&2\end{pmatrix},\quad A=\begin{pmatrix}0&1\\0&0\end{pmatrix}$$
Then $$A^TPA=\begin{pmatrix}0&0\\0&1\end{pmatrix}<P$$
but $$APA^T=\begin{pmatrix}2&0\\0&0\end{pmatrix}\not\le P$$
Comment: Eigen values of A are both zero and do not lie on the unit circle as given by op.


Flickity is-selected issue

Question: I'm trying to educate myself about Flickity. The carousel auto plays and the selected cell (denoted by the grey background) is automatically in the middle. I would like the selected cell not to be in the middle. I'm looking for a way to may it be the cell to the left, so it is above the dots (desktop view).
Hope that makes sense. Here is the jsfiddle for it.
The only method that I can think of is using jQuery to find the prev sibling for the "is-selected" class and adding a class to it, but I was hoping there may be a simpler method
Thanks in advance for your feedback!

Answer: add this
<Slider
options {{
cellAlign: 'left' //this part will shift your entire slide to left
}}>

...

Comment: Welcome to Stack Overflow. Please include an explanation of how this solves the problem.

Flickity is-selected issue


Which is the safe path to add some diy module into python initial environment?

Question: I've add a self-made module which prints a paragraph whchi is similar to import this  into
the path /usr/lib/python2.7.
This is the first time I did things like this, would it cause some kind of trouble in the future?
If it's not safe, what should I do to have my personal module automatically involved in the initial path without any statements in a file, which path is safer?
ps: I'm using Ubuntu14.04
Answer: You can look into this.py, I think there is nothing else you need to do (No need to do converting job like this.py).
this.py
s = """Gur Mra bs Clguba, ol Gvz Crgref

Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
Nygubhtu cenpgvpnyvgl orngf chevgl.
Reebef fubhyq arire cnff fvyragyl.
Hayrff rkcyvpvgyl fvyraprq.
Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.
Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.
Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.
Abj vf orggre guna arire.
Nygubhtu arire vf bsgra orggre guna *evtug* abj.
Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!"""

d = {}
for c in (65, 97):
    for i in range(26):
        d[chr(i+c)] = chr((i+13) % 26 + c)

print "".join([d.get(c, c) for c in s])

Comment: My paragraph is different, I think my previous description may lead to some misunderstood. Sorry
Comment: @Zen What's the difference? Update it in your question, please.


Errors with PCoA in R due to large dataset

Question: For my workproject I have to perform a PCoA (principal coordinate analysis aka multidimensional scaling).
However when using R to perform this analysis I run into a few problems.
The function cmdscale only accepts matrix or dist as input, the dist function gives the error:
Error: cannot allocate vector of size 4.2 Gb
In addition: Warning messages:
1: In dist(mydata[c(3, 4)], method = "euclidian", diag = FALSE, upper = FALSE) :
  Reached total allocation of 4020Mb: see help(memory.size)
2: In dist(mydata[c(3, 4)], method = "euclidian", diag = FALSE, upper = FALSE) :
  Reached total allocation of 4020Mb: see help(memory.size)
3: In dist(mydata[c(3, 4)], method = "euclidian", diag = FALSE, upper = FALSE) :
  Reached total allocation of 4020Mb: see help(memory.size)
4: In dist(mydata[c(3, 4)], method = "euclidian", diag = FALSE, upper = FALSE) :
  Reached total allocation of 4020Mb: see help(memory.size)

And when I use a matrix it changes the input into this:
     [,1]
[1,] Integer,33741
[2,] Integer,33741

The contents of the dataset cannot be posted online however I can give you the dimensions:
The dataset is 33741 rows long and 11 columns wide with the first column being an ID and the other 10 values that need to be used for the PCoA.
As you can see in the error I only use 2 columns and I already get a memory error.
Now for my questions:
Is it possible to either manipulate the data in such a way that I can manage with the memory limit for the dist function?
What am I doing wrong with the matrix function that it changes the vectors into a 2 column 2 row output?
What I have tried:
Clearing with garbage collection, restarting the GUI, restarting the system.
System:
Windows 7 x64
i7 920qm 1.8ghz
4GB DDR3 ram
Code used:
mydata <- read.table(file, header=TRUE)

mydist <- dist(mydata[c(3,4)], method="euclidian", diag=FALSE, upper=FALSE)
mymatrix <- matrix(mydata[c(3,4)], byrow=FALSE)
mymatrix <- matrix(cbind(mydata[c(3,4)]))

mycmdscale <- cmdscale(mydist, k=2, eig=FALSE, add=FALSE, x.ret=FALSE)
mycmdscale <- cmdscale(mymatrix, k=2, eig=FALSE, add=FALSE, x.ret=FALSE)

plot(mycmdscale)

Of course I did not run the code in this order but this code contains the methods I have tried to load the data.
Thanks in advance for any replies.
Answer: I know this is old, but thought I'd pitch in what I got...
I am a little surprised @Gavin Simpson did not mention computing a Principal Coordinate Analysis on a Euclidean distance matrix is identical to a Principal Component Analysis (at least with using scaling=1 for both).
This is according to p. 143 in Borcard, D., Gillet, F., & Legendre, P. (2011). Chapter 5 Unconstrained Ordination (pp. 115–151). New York, NY: Springer New York. doi:10.1007/978-1-4419-7976-6
I can run this fine on my current local machine
System: Windows 7 x64 i5-2500 3.3ghz 8GB RAM
library(vegan) # to perform PCA and associated operations
library(ggplot2) # plotting (not necessary, but nice)
library(grid) # arrow()

#make a big test set like OP's
test<-data.frame(id=seq(34000), var1=rnorm(34000), var2=rnorm(34000),
                 var3=rnorm(34000),var4=rnorm(34000),var5=rnorm(34000),
                 var6=rnorm(34000),var7=rnorm(34000),var8=rnorm(34000),
                 var9=rnorm(34000),var10=rnorm(34000))
#calculate PCA
test.pca<-rda(test, scale=TRUE)

#calculate percent variation on each axis
test.pca.percExp<-round(eigenvals(test.pca)/sum(eigenvals(test.pca))*100, 2)

#extract scores for plotting
test.pca.sc<-scores(test.pca, choices=c(1,2),
                           display=c("sites", "species"), scaling=1)

test.pca.site<-data.frame(test.pca.sc$sites)
test.pca.spe<-data.frame(test.pca.sc$species)
test.pca.spe$VAR<-rownames(test.pca.spe)

#make the plot
test.pca.p<-ggplot(test.pca.site, aes(PC1, PC2)) +
  xlab(sprintf("PC1 %s%s", test.pca.percExp[1], "%")) +
  ylab(sprintf("PC2 %s%s", test.pca.percExp[2], "%"))

#add points and biplot arrows to plot
test.pca.p +
  geom_point() +
  geom_segment(data = test.pca.spe,
               aes(x = 0, xend = PC1, y = 0, yend = PC2),
               arrow = arrow(length = unit(0.25, "cm")), colour = "grey") +
  geom_text(data=test.pca.spe,
            aes(x=PC1,y=PC2,label=VAR),
            size=3, position=position_jitter(width=-2, height=0.1))+
  guides(color = guide_legend(title = "Var"))

#hard to see the points with arrows, so plot without the arrows
test.pca.p +
  geom_point()

I stumbled on this question because I had the same problem with a Manhattan distance matrix, which my answer would not help with (as far as I know, there might be a way to transform the data prior to PCA that would give the same result..).  This answer would essentially give the result I believe the OP was looking for though.  Hopefully that helps someone else too...
Answer: You have far too little memory to do this operation in R, which holds all objects in memory. I  may not have the exact calculation quite correct (I forget the size of R's objects) but just to hold the dissimilarity matrix you'll need ~9GB of RAM.
> print(object.size(matrix(0, ncol = 34000, nrow = 34000)), units = "Gb")
8.6 Gb

dist will get away with less in the internal representation as it is really only storing 0.5 * (nr * (nr - 1)) doubles (nr is number of rows in the input data):
> print(object.size(numeric(length = 0.5 * 34000 * 33999)), units = "Gb")
4.3 Gb

[Which is probably where the error you are seeing is coming from]
Realistically you'll need upwards of 20-30GB of RAM to do anything useful with the dissimilarity matrix once you've computed it. Even if you could compute them, the eigenvectors of the PCoA solution will need ~ 9Gb of RAM, just on their own.
So a more pertinent question is; what do you hope to do with c. 34000 samples/observations?
To get the matrix from mydata[3:4] you can use
as.matrix(mydata[3:4])

or, if you have factors and want to preserve their numeric interpretation
data.matrix(mydata[3:4])

Comment: So I have tried to use your methods to load in the matrix, these methods do work to create a matrix. However the function to perform a PCoA (cmdscale) does not accept these types of matrixes, it ask for: Error in cmdscale(testmatrix, k = 2, eig = FALSE, add = FALSE, x.ret = FALSE) :
  distances must be result of 'dist' or a square matrix.  I doubt it is possible to perform the analysis with the limited memory I have but any ideas are welcome.
Comment: Well I hope to perform a Principal Coordinate analysis over the samples, however the company I work for does not have a server capable of handling these kind of computations so I was trying to make a workaround for local computers. I have the day off today so I cannot try the data.matrix yet but I will get back to you tomorrow if it worked. Thank you for your time already because this does give me an indication of what I need to tell my boss.
Comment: @Sinshz Those two things are not related. I thought the two questions were unrelated; apologies for that. What I show is how to get a matrix from selected columns/components of a data frame. `dist` will still fail for you because the number of rows of the data will require more RAM to store it than your machine has available to it.
Comment: I thought so, I guess I will have to convince my superiors to either buy a decent server or to drop the matter and leave it to an external company (I suspect the latter). Thank you for your time.
Comment: @Sinshz You don't need a decent server; a good quality Xeon-based workstation with 64Gb RAM should be ample - though you'd want to check first. You'd get one of those for $3-4000 these days depending on how many CPUs with how many cores you want.


how to redirect user login from other server?

Question: The user login is from the other drupal site using cas(Central Authentication Service). Then it will lead to my main site and an authenticated user can view the contents. The main site is used Drupalgap to redesign the interface for mobile.
Now, when using the web browser, it works fine to login and start to view the contents. However, I don't know how to do it for Drupalgap. I saw some apps can login with the account from other sites, once the login is successful, it will redirect and come back to the app.
Does anybody know how to do it?
My attempt is trying to use the login url from the other site.
bl('Login', 'www.example.com/cas', { InAppBrowser:true });
This will open a new web browser, not inside my app page. When successfully login, there's a link to go back to my main site. These are operating through the new web browser, not inside my original app.
Comment: You can try installing CAS client module. And configure it
Answer: On the Drupal side, create a custom module to implement hook_form_alter() and use it to attach a custom #submit handler to the user_login_form. In the custom submit handler, you can redirect the user to the headless DrupalGap web app:
/**
 * Implements hook_form_alter().
 */
function example_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'user_login_form' && arg(0) == 'drupalgap') {
    $form['#submit'][] = 'example_user_login_form_submit';
  }
}

function example_user_login_form_submit($form, &$form_state) {
  $uid = 123; // This id will be somewhere in the $form or $form_state object.
  drupal_goto('https://example.com/#user_' . $uid);
}

Replace drupalgap with your service endpoint path, but by default it is drupalgap.
Comment: thanks for your reply. but my drupalgap and the drupal site are not in the same domain. How do I redirect the authorized drupal site user back to my drupalgap on the other domain?


Regression equivalent of a within-subjects t-test

Question: Let's say I examine the effect of two treatments on a dependent variable $y$. Let $y_{i1}$ be the value the variable of interest of subject $i$ for treatment $1$, and $y_{i2}$ be defined analogously.
To find if one treatment was better than another, I can simply do a paired t-test.
I'm wondering if the following is the regression equivalent:
$y_{i1} - y_{i2} = \beta_0$, and simply testing for the significance of the constant.
I also suspect that the relative effectiveness of the treatments may vary with some control variable (e.g. age), and hence might want $y_{i1} - y_{i2} = \beta_0 + \beta_1X$ (where $X$ is a control variable such as age).
Is this correct?
Answer: Yes, you are correct. Subtracting the outcomes at both times, and testing the intercept or whether the mean statistically differs from zero is equivalent to a paired t-test. Only complaint I would have is it is difficult to say one treatment is better than the other using a paired design. Maybe if the order of treatment was random across the individuals, then just maybe. But then, one might consider thinking differently about the analysis.


Erro ao colocar Virtualbox como serviço

Question: Criei um serviço no windows pra para poder configurar minha VM no modo Headless, com o comando:
sc.exe create DailyLubuntu binpath= "\"C:\Program Files\Oracle\VirtualBox\VBoxHeadless.exe\"  startvm Daily LUbuntu - Lucas" DisplayName= \"Daily Lubuntu VM" start= "auto"

O serviço foi criado com êxito, porem quando vou inicializar o serviço com o comando:
> net start DailyLubuntu

, aparece este erro:

Erro de sistema 2. O sistema não pode encontrar o arquivo especificado. Para obter mais ajuda, digite NET HELPMSG 2186.
Comment: Se você tentar iniciar a VM pelo VirtualBox, funciona?
Comment: Quando inicializo pelo VirtualBox ela funciona
Comment: Só para te avisar. Neste momento há 3 votos para fechar a sua pergunta como fora do escopo por não ser sobre programação (mas nenhum destes votos é meu). Eu pessoalmente, não saberia dizer se o fechamento por este motivo é válido ou não.
Answer: Existe um projeto chamado VBoxVmService que faz esse serviço por você. Basta instalar, alterar o arquivo VBoxVmService.ini dentro de C:\vms e reiniciar o serviço.

Erro ao colocar Virtualbox como serviço


Login in Active Directory Domain (Samba 4) and mount -t cifs on debian

Question: I've configured Samba 4 with bind and kerberos to work as an Active Directory authentication server. I've also configured "home share" so I can login to any Windows machine in my Domain and work with my files.
In addition I want to access my files on Debian Desktop. I've installed realmd and sssd on Debian Desktop and I am able to login in my Domain. But when I'm trying to mount my files using:
mount -t cifs -o user=szymon //192.168.1.1/netlogon/szymon files/

I have problem with proper uid and gid mapping. Result of ls -l:
drwxrwx---+ 13 3000000 users 0 lis 5 11:49 files
-rwxr-xr-x 1 firstname.lastname@example.com domain email@example.com 79 lis 5 14:14 wfmount

I even cannot cd into files/.
How can I setup Samba 4 to mount my Share with correct permissions?
Answer: Your linux client needs a way to translate AD users to unix users.
This is usually done by the winbindd service, which is a part of the samba4 suite (to be installed and configured on the client).


Find actual viewport height - minus the chrome

Question: HI,
Can anyone tell me how to get the actual viewport height? If i use  window.innerHeight or $(window).height() (jquery) I get back a value that looks like it's taking the browser chrome in to account. I need the height of the actual viewport. When I measure the viewport height using a ruler plugin in the web dev toolbar (firefox) the value is different than what the window.innerHeight provides me with.
Comment: Can you show an example? Which browsers does this happen in?
Comment: `window.innerHeight` doesn't take the browser chrome into account, that's what `window.outerHeight` does.  It does include the horizontal scrollbar, if present.
Comment: $(window).height() in jquery only returns the viewport height, not browser height.
Comment: Oh ok, It's just that when I alert out window.innerHeight i get 760. but if i measure the actual area from a screengrab or using the ruler function in firefox plugin then i get back 726.
Answer: Try:
document.body.clientHeight
document.body.clientWidth

Comment: That gets the height of the document, not the window - i.e. if the window has scrollbars it will get the full length of the page, including the parts off-screen.
Answer: You can also try:
document.documentElement.clientHeight
document.documentElement.clientWidth


Simple question on Medical Data analysis

Question: I am investigating a medical device and really it is just a proof of concept. 20 patients all with a problem (disease x) does our medical device detect disease x. Each patient undergoes one trial and the outcome is either that the problem was correctly identified or that it was missed.
What hypothesis do you think is satisfactory and what statistical analysis would be correct.
Also what would my CI really show in this example.
Comment: As the ideal is surely that your question and any answers help others too, please edit the uninformative title to something more precise.
Comment: +1 for the suggestion by @NickCox . OP: please update your question title so that it will be helpful for other readers.
Comment: I think you could estimate the rate at which the device correctly identifies the disease when the disease is present.  You could also estimate the type-ii error rate, or false negative rate, that is, when the disease is present, but the device failed to detect it.  As you say, the confidence interval for these estimates would be helpful.  But it would also be helpful if you also tested the device on those without the disease.
Comment: _Sensitivity_ is P(pos test | has disease). _Specificity_ is P(neg test | no disease).  A bogus test that  _always_ shows positive (regardless of disease state), would have sensitivity 1 and specificity 0. In practice, a trade-off btw sensitivity and specificity is sought, often by use of an OC curve
Comment: If you want to turn this information into a hypothesis test, you could use a null hypothesis, e.g., that the device identifies the disease when present better than 50%, or, say, better than 80%.  Likewise with the false negative rate.  But it seems like computing rates and confidence intervals would be more useful.  Except maybe to include  a null null that the device is better 50/50, but this would also be clear in the confidence interval results.
Comment: Would it make sense to turn this into the following test...

H1 -> The device has 90% sensitivity in detecting disease X.

What statistical approach would I take.

Thank you so much!  Can I reward people on this platform?
Comment: Yes, send cash or checks to...  Just kidding.  I'll write up my thoughts as an answer shortly.  From there you can upvote or select as the accepted answer....  Well, the H1 would be more like "the detection rate† is greater than 90%", or is "not 90%".  You could do that as formal hypothesis test...  If you present the rate and the confidence interval, and that interval includes 90%, that would suggest that the rate is not different than 90%... (†): I'm avoiding "sensitivity" just because I'm not sure what it means.
Comment: Thanks, @BruceET . I added this terminology to my answer, which was helpful.
Comment: Please edit your title to indicate the nature of the problem you're asking about. Telling us you need help is pointless -- we already know that, that's what everybody wants.
Answer: I think a simple approach would be to estimate the rate at which the device correctly identifies the disease when the disease is present (sensitivity). You could also estimate the false negative rate; that is, when the disease is present but the device failed to detect it (1 - sensitivity). Including the confidence intervals for these estimates would be helpful.
But it would also be helpful if you also tested the device on those without the disease.
If you wanted to use a formal hypothesis test, the nullest of null hypotheses to test against would be Ho: The device has a 50% chance of detecting the disease when the disease is present. Rejecting this null hypothesis may not be very impressive to the audience, but at least does suggest that the device "works"  in some sense, especially at the proof-of-concept stage.
Proportions other than 0.50 in a null hypothesis could be tested against.  But with a (smallish) sample size of 20, you might be surprised that you may not be able to reject the null hypothesis for say, P = 0.70 or P = 0.80.
For this reason, unless there is a null proportion for which there is good reason to test the measured sensitivity against, I would recommend instead using the estimate and confidence interval approach.  Or using that approach augmented with the test against the null hypothesis of P = 0.50.
A hypothetical example follows.  It can be run in R or at https://rdrr.io/snippets/ .
In this hypothetical example, there are 20 observations, all of which are positive for the disease in reality.  The device detects the disease in 18 of the observations, and fails to detect in 2 observations.
Total     = 20
Detected  = 18
Failed    = Total - Detected

The output for the binomial test gives us an estimate for the sensitivity (0.9); and the 95% confidence interval for this estimate (Clopper-Pearson) (0.68 to 0.99).
It also reports a p value for the test against the default null hypothesis, P = 0.50 (p =  0.0004).
binom.test(Detected, Total)

   ### Exact binomial test
   ### p-value = 0.0004025
   ### 95 percent confidence interval:
   ### 0.6830173 0.9876515
   ###
   ### probability of success
   ###                    0.9

We could do the same test for the count of failed observations.  The p value will be the same, but the results will give us the confidence interval for the proportion of failed observations.
binom.test(Failed, Total)

   ### 95 percent confidence interval:
   ###    0.01234853 0.31698271

We could test against another null hypothesis, say that P = 0.75.
binom.test(Detected, Total, p=0.75)

   ### p-value = 0.1931
   ### alternative hypothesis: true probability of success is not equal to 0.75

(Not shown here, you could also use a one-sided hypothesis test.)
If the confidence intervals for both proportions are being presented, it is my understanding that using a method for simultaneous multinominal proportions may be more appropriate.  Here, the Sison-Glaz method is used.
library(DescTools)

observed = c(Detected, Failed)

MultinomCI(observed,
           conf.level=0.95,
           method="sisonglaz")

   ###      est lwr.ci    upr.ci
   ### [1,] 0.9   0.85 1.0000000
   ### [2,] 0.1   0.05 0.2485667

A plot of estimates and confidence intervals may be helpful.  Here, all the estimates and confidence limits are retyped manually as X, Y, LCI, and UCI.  I used the results from the Sison-Glaz method.
X = c("Detected", "Failed to Detect")
Y = c(0.90, 0.10)
LCI = c(0.85, 0.05)
UCI = c(1.00, 0.249)

Data = data.frame(X, Y, LCI, UCI)

library(ggplot2)

ggplot(Data,
       aes(x     = X,
           y     = Y)) +

    geom_bar(stat = "identity",
             color = "black",
             fill  = "dodgerblue",
             width =  0.7) +

    geom_errorbar(aes(ymin  = LCI,
                      ymax  = UCI),
                      width = 0.2,
                      size  = 0.7,
                      color = "black"
                      ) +
    theme_bw() +
    theme(axis.title = element_text(face = "bold")) +
    theme(axis.text = element_text(face = "bold")) +

    ylab("Rate\n") +
    xlab("\n")

Comment: No, problem, @kristian .  That's what this website is about.  We have all benefited from the understanding and generosity of those before us, and personally I have benefited greatly from searching on Cross Validated and similar sites.
Comment: Sal this is incredibly helpful. I posted on this website even though I am not a contributing member and am so grateful that the community (and yourself) has helped so much. This answer has largely contributed to my MHRA submission! I am useless at stats as this question shows so cannot help out others in turn - so just wanted to say a genuine thank you to yourself and all that answer! :)


Change datatype from int64 to string in mongodb for nested array

Question: I have an array like below for gc collection where I need to change datatype from int64 to string for CardNumber.This should be done for all records in this collection.I wrote the script as below but on executing there is no conversion happening.Any help would be appreciated.
    Eg: GiftCardSale[2 element]
       [0] GiftCardId 62e201874a555cb001d2d723
           CardNumber 5678967546738766 (Int64)
           Amount 20
       [1] GiftCardId 62e201874a555cb001d2d723
           CardNumber 6789879874673829  (Int64)
           Amount 10

db.gc
  .find(
    {
      GiftCardSale: {
        $elemMatch: {
          CardNumber: { $exists: true, $type: 18 },
        },
      },
    },
    {
      _id: 2,
    }
  )
  .forEach(function (doc) {
    db.gc.update(
      {
        _id: doc._id,
      },
      {
        $set: {
          'GiftCardSale.$[etl].CardNumber': {
            $toString: '$GiftCardSale.$[etl].CardNumber',
          },
        },
      },
      { arrayFilters: [{ 'etl.CardNumber': { $type: 18 } }], multi: true }
    );
  });

Answer: You could update all your documents with a single pipeline.
db.gc.update({
  "GiftCardSale.CardNumber": {"$type": "long"}
},
[
  {
    "$set": {
      "GiftCardSale": {
        "$map": {
          "input": "$GiftCardSale",
          "as": "sale",
          "in": {
            "$cond": [
              {"$eq": [{"$type": "$$sale.CardNumber"}, "long"]},
              {
                "$mergeObjects": [
                  "$$sale",
                  {"GiftCardSale": {"$toString": "$$sale.CardNumber"}}
                ]
              },
              "$$sale"
            ]
          }
        }
      }
    }
  }
],
{
  "multi": true
})

Try it on mongoplayground.net.
Answer: You may want to have a look at my answers in detail to a similar question below. Change int datatype to string in mongodb


Encrypted filesystems and the Linux buffer cache

Question: I currently use Berkeley DBs fronted by a Java server for a high-performance disk-backed cache. Provided you warm it up before allowing it to face live traffic, your update rate is low, and your working set fits in memory, the Linux buffer cache does an excellent job. It's measurably faster than memcache, in part because you don't need to context switch to the memcached and back on read. We're very happy with the performance.
We're going to be adding some data to the cache that we're not comfortable leaving on disk in plain text. We've measured and are unhappy with the performance of decrypting during request processing, so we're looking for solutions that decrypt only when the data is loaded from disk and then keep it available in memory.
Before building something that does this, I wanted to find out if we can simply slide in an encrypted filesystem and continue to rely on the OS to manage the cache for us. I haven't found any documentation that tells me at what layer the decryption is done.
So my question is: Can anyone tell me, for any particular Linux encrypted FS, whether the (en|de)cryption is done below the buffer cache (and therefore the cache contains plaintext) or above (and the cache contains ciphertext)?
Answer: The buffer cache sits below the actual filesystem, so it will cache encrypted data.  See the diagram at IBM's Anatomy of a Filesystem.  Since you want to cache unencrypted data, so long as your encrypted filesystem was created using the 'loop' device the buffer cache will also contain an unencrypted copy of your data, and so it should be fast (at the cost of more memory for FS buffers in-use).
Answer: I haven't played with this, but am pretty sure that buffer cache and VM are not aware of the encryption, so you should see comparable performance with your usage.


spherical coordinates cross prodct

Question: On the one hand, |$\hat{z} \times \vec{r}| = |r(\hat{z} \times \hat{r})|=rsin\theta $. direction ???
On the other hand, $\hat{z} \times \vec{r}=r\hat{z}\times({\hat{\rho}+\hat{z})} = r\hat{\varphi}$.
Generally I want to calculate $\hat{z} \times \vec{r}$ but I seem to get different answers in different method. What have I done wrong?
*$\rho$ is the radial component in cylindrical coordinates. $\phi$ is the azimuth angle and $\theta$ the polar angle.
Answer: Your error is in the second line: because you assumed $\vec{r} = r \hat{\rho} + r\hat{z}$ (which is clearly false because the length of the LHS is $r$, while on the RHS it is $\sqrt{2}r$). The correct equation is
\begin{align}
\vec{r} = (r \sin \theta)\, \hat{\rho} + (r \cos \theta)\, \hat{z}
\end{align}
If you plug this in, there's no contradiction anymore. The direction of the cross product $\hat{z} \times \vec{r}$ is
\begin{align}
\hat{\phi}&= -\sin \phi \, \hat{x} + \cos \phi \, \hat{y}
\end{align}

spherical coordinates cross prodct


Uniform convergence of series

Question: $$\sum_{n=1}^\infty \frac{3^x(n+2)}{n!}, x\in E = (0 , +\infty)$$
It is likely easy, but for me it is new thing and I don't know how to start to solve this. Could you give me any tips?
Comment: Are you sure? $$\sum_{n=1}^\infty \frac{3^x(n+2)}{n!}=3^x\sum_{n=1}^\infty \frac{(n+2)}{n!}$$
Comment: Agree with @Aforest. One you've taken $3^x$ outside the sum, think about the sum as a Taylor series (or the sum of two Taylor series) and put it into closed form. Uniform convergence is not really an issue here, it's just a sequence convergence independent of $x$.
Comment: @ScottBurns You have described convergence, not uniform convergence.  Can you show that for all $\epsilon>0$, there is a number $N_0$ independent of $x$, such than whenever $N>N_0$, $$3^x\sum_{n=N}^\infty\frac{n+2}{n!}<\epsilon?$$
Comment: @Dr.MV You're right ! The range of the function $3^x$ must be specified as bounded. The result holds for any fixed bounded domain $D\subset \mathbb{R}$ or $D\subset \mathbb{C}$.
Comment: Note the sequence $3^x s_n$ is uniformly convergent in $x\in(0,\infty)$ if and only if $s_n$ is constant for $n$ sufficiently large, as $3^x$ is unbounded on $(0,\infty).
Comment: Aaargh! I was just looking on it as $3^x (3e+1)$. You are quite correct.
Answer: There exists a number $\epsilon=1$ such that for all $N$, there exists a number $x_N=\log_3((N+2)!)$ and there exists a number $N+1>N$ such that
$$\begin{align}
3^{x_N}\left|\sum_{n=1}^\infty \frac{n+2}{n!}-\sum_{n=1}^{N+1}\frac{n+2}{n!}\right|&=3^{x_N}\sum_{n=N+2}^\infty\frac{n+2}{n!}\\\\
&\ge \frac{3^{x_N}}{(N+2)!}\\\\
&=1 \\\\
&=\epsilon
\end{align}$$
This is precisely the negation of uniform convergence.

Uniform convergence of series


How do I access the node's uid in hook_node_access()?

Question: I have implemented hook_node access so that two users cannot view each other's posts if they do not have the right permission (I implemented the permission in hook_permission). I use a comparison with $node->uid as follows:
 function mymodule_node_access( $node, $op, $account)
 {
   global $user;
   $type = is_string($node) ? $node : $node->type;

   switch($type)
   {
    case "myCustomType":

      if ( ($user->uid != $node->uid) && !user_access("view other's posts"))
       {
              return NODE_ACCESS_DENY;

       }
       break;

   }

}

Everything works fine but I do get the following warning:

Notice: Trying to get property of non-object in mymodule_node_access().

This is caused by this: $node->uid. Drupal complains that $node is a  not a stdobject (it seems to actually be string containing the node's type). Yet the code still works which I do not understand why.
What is the proper way to access the node's uid from hook_node_access?
Answer: The $node parameter is

Either a node object or the machine name of the content type on which to perform the access check.

When that hook is invoked with the create op, there's no node object available, so $node is a string.
You're already handling that bit, but you're missing a check on the $op parameter. The reason it's working is because when your function is invoked with the op you're trying to target (probably view), $node is an object and has a uid property.
With your current code, you'll get one of those notices every time someone other than user 1 tries to create a node, because $node is not an object.
Try re-working your code like this:
function mymodule_node_access( $node, $op, $account)
 {
   if ($op == 'create') {
     $type = $node;
     // You can be reasonably sure that $account is the user who's trying to create the node here.
     // You'll probably want to ignore this bit and check $op specifically for the
     // actions you're looking for; this is just here to show the workflow.
   }
   else {
     if ($node->type == 'myCustomType') {
       // Be sure to use the $account var here, not the global $user object
       if ( ($account->uid != $node->uid) && !user_access("view other's posts", $account)) {
       return NODE_ACCESS_DENY;
     }
   }

   return NODE_ACCESS_IGNORE;

Answer: You'll find the uid in the $account object with $account->uid.
Comment: I already have the current user's uid using $user->uid. What i need is the current's node uid (the uid of the creator of the node). $account seems to refer to the user currently viewing the node, not the creator of the node.
Comment: Hmm... maybe it bails out when the node hasn't been saved yet. When it's being created node->uid isn't available.
Answer: The value passed in $node could also be the content type of the node being created; that is why the following line is necessary to get the content type.
$type = is_string($node) ? $node : $node->type;

The reason the code works is that a non initialized variable, or object property, is set to NULL. In your case, the control statement is really executing the following code, when the node is being created.
  if (($user->uid != NULL) && !user_access("view other's posts")) {
    return NODE_ACCESS_DENY;
  }

Since $user->uid is never NULL, that is the reason why the code work the same, even if it raises a PHP warning.
To avoid the warning message, it is enough to execute code similar to the following one.
 function mymodule_node_access( $node, $op, $account) {
   if (($op == 'view') && ($node->type == "myCustomType") && ($user->uid != $node->uid)) {
     return user_access("view other's posts") ? NODE_ACCESS_ALLOW : NODE_ACCESS_DENY;
   }

   // Returning nothing from this function would have the same effect.
   return NODE_ACCESS_IGNORE;
 }

I changed the code because I think that what you are trying to do is the following:

When the content type is myCustomType, the user is viewing a node created by another user, and the user who is watching the node has the view other's posts permission, allow that user to see the node
When the content type is myCustomType, the user is viewing a node created by another user, and the user who is watching the node doesn't have the view other's posts permission, don't allow that user to see the node

What your code is doing is:

When the content type is myCustomType, the user is viewing/editing/deleting a node created by another user, and the user who is acting on the node doesn't have the view other's posts permission, don't allow that user to do anything on that node the node
In the other cases, let the other modules decide about the access permission

What I notice is that:

Despite the permission is "view other's posts," it is applied even when the currently logged-in user is doing something else than viewing the node
In the case the currently logged-in user has the view other's posts permission and is doing something on the node created by somebody else, it lets other modules decide the user's permission to access the node

If the permission is really about any operation done on a node, then it should be renamed, or the code should use more than one permission. The latter is what the Node module does, since for every content type there are a permission to create a node of that content type, to edit nodes of that content type, and to delete nodes of that content type.


Exercise on Metric space

Question: I hve this exercise it is very simple but i don't know how to write the answer
Let $A$ be a nonempty set in $(E,d)$, for $\varepsilon>0$ we note $$V_{\varepsilon}(A)=\{x\in E, d(x,A)<\varepsilon\}$$ how to prove that

$\displaystyle\bigcap_{\varepsilon>0} V_{\varepsilon}(A)=\displaystyle\bigcap_{\frac1n\in\mathbb{N}^*} V_{\frac1n}(A)$ and that
$ V_{\varepsilon}(A)=\displaystyle\bigcup_{x\in A} B(x,\varepsilon),$ for all $x>0$

Thank you very much.
Comment: A nice way to prove that two sets $A$ and $B$ are equal is to show that an element of $A$ is necessarily an element of $B$ and vice versa.
Comment: I think in second statements there should be $\bigcup$ not $\bigcap$
Comment: hhhh i know this but if i have $\forall \varepsilon>0, \inf_{y\in A} d(x,y)<\varepsilon$ how to introduce $\frac1n$ you  think that i dn't try to prove this ??
Answer: Hint
Let $x \in \bigcap_{\varepsilon>0} V_{\varepsilon}(A)$, then $\forall \, \epsilon >0$ $x \in V_{\varepsilon}(A)$. Using the Archimedean property we get that for each $\epsilon >0$, $\exists \, n_{\epsilon} \in \mathbb{N}$ such that $n_{\epsilon}\epsilon >1$. See if you can proceed from here.
Comment: we have $\forall \varepsilon>0, \exists n\in \mathbb{N}^*, \varepsilon>\frac1n$ but we need $\forall n\in \mathbb{N}^*$
Comment: Note that if $m < n$ then $V_{\frac{1}{n}} \subseteq V_{\frac{1}{m}}$.
Comment: I don't understand you $\varepsilon$ is a positive real so if i have $\inf_{y\in A} d(x,y)=d(x,A)<\varepsilon >\frac1/n$ how to obtain that for all $n\in \mathbb{N}^*, d(x,A)<\frac1n$
Answer: I'll just write some hits so you can finish it
Hints to the first equality:

Note that the right side is a subset of the left side
If $\epsilon>0$ then there exists an $n\in\mathbb{N}$ such that $1/n<\epsilon$. Use this to prove the other inclusion.

Hints to the second equality (which has $\cap$ instead of $\cup$):
$x\in V_x(a)\iff d(x,A)<\epsilon\iff \exists a\in A: d(x,a)<\epsilon$
Answer: I will prove the first one and leave the second one for you.
As @Matthe Leingang suggest, we first show that
$$\bigcap_{\epsilon>0}V_\epsilon (A)\subset \bigcap_{n\in \mathbb N}V_\frac{1}{n} (A) \tag 1$$
Take $x\in \bigcap_{\epsilon>0}V_\epsilon (A)$ and we want to prove that $x\in \bigcap_{n\in \mathbb N}V_\frac{1}{n} (A)$. Fix arbitrary $n\in \mathbb N$, we can always have $\epsilon_n>0$ such that $\epsilon_n<1/n$. Because $x\in \bigcap_{\epsilon>0}V_\epsilon (A)$ and hence in particular $x\in V_{\epsilon_0}(A)$ and thus $x\in V_\frac{1}{n}(A)$. Therefore, we have $(1)$. The other direction is similar.
Comment: please why you fixe $n$ and why there exists $\varepsilon_n$ directly ? thank you

Exercise on Metric space


Prove that $|\sin n|+|\sin (n+1)| > 2\sin(1/2)$ for all $n\in \mathbb N$

Question:
Show that
  $$|\sin{(n)}|+|\sin{(n+1)}|>2\sin{\dfrac{1}{2}},n \ge 1,n\in \mathbb N$$

My try: let
$$F(n)=|\sin{(n)}|+|\sin{(n+1)}|$$
then
$$F(n+\pi)=|\sin{(n+\pi)}|+|\sin{(n+\pi+1)}|=|\sin{(n)}|+|\sin{(n+1)}|=F(n)$$
and
$$F(\pi-n)=|\sin{(\pi-n)}|+|\sin{(\pi-n+1)}|=|\sin{n}|+|\sin{(n-1)}|\neq F(n)$$
so we must prove when $n\in (0,\pi)$,
have
$$F(n)>2\sin{\dfrac{1}{2}}$$
when
$n\in (0,\pi-1)$,then
$$F(n)=\sin{n}+\sin{(n+1)}=\sin{n}(1+\cos{1})+\sin{1}\cos{n}$$
and
$n\in(\pi-1,\pi)$,then
$$F(n)=\sin{n}-\sin{(n+1)}$$
How prove it this two case have $F(n)>2\sin{\dfrac{1}{2}}$? Thank you
and I know this well know inequality
$$|\sin{x}|+|\sin{(x+1)}|+|\sin{(x-1)}|\ge 2\sin{1},x\in \mathbb R$$
Comment: When $n=0$, $\text{LHS} = \sin1 = 0.8414, \text{RHS} = 0.959$?
Answer: Observe that
$$
f(x)=\big|\sin x\big|+\big|\sin (x+1)\big| =\left\{
\begin{array}{rll}
\sin x+\sin(x+1) & \text{if} & x\in[0,\pi-1], \\
\sin x-\sin(x+1) & \text{if} & x\in[\pi-1,\pi], \\
-\sin x -\sin (x+1) & \text{if} & x\in [\pi,2\pi-1], \\
-\sin x+\sin(x+1) & \text{if} & x\in [2\pi-1,2\pi].
\end{array}
\right.
$$
Also note that
$$
\sin x+\sin(x+1)=2\sin(x+½)\cos(½),\quad
\sin x-\sin(x+1)=-2\sin(½)\cos(½+x).
$$
Then show a corresponding inequality in each subinterval.
Unfortunately, the inequality does not hold (for $n=0$ is not true!). The one that does hold is
$$
\big|\sin x\big|+\big|\sin (x+1)\big|\ge \sin 1.
$$
Comment: Oh,Thank you,I forget!
Answer: The inequality is going to be really hard to prove.  Consider $n=22$:
$$\sin(22)=-0.00885130929,\quad\sin(23)=-0.84622040417,\quad 2\sin(1/2)=0.9588510772$$
This example comes from the approximation $\pi=22/7$.  In general, $k\pi$ is occasionally close to an integer $n$, so that $|\sin(n)|\approx0$ while $|\sin(n+1)|\approx|\sin(1)|=0.8414709848$.
Answer: Using induction and the formula $$\sin(nx)=2^{n−1}\Pi_{k=0}^{n−1}\sin(x+\frac{\pi k}{n})$$
which is not very hard to prove by induction (again) for instance, $\sin(2x)=2\sin(x)\cos(x)=2\sin(x)\sin(x+\pi/2)$.
1). $n=1$ case is shown above $|\sin{(1)}|+|\sin{(1+1)}|=\sin(1)(1+2\sin(1+\frac{\pi}{2})>2\sin{\frac{1}{2}}$;
2). $n=k$ assumption case, $|\sin{(k)}|+|\sin{(k+1)}|=2^{k-1}|\sin(1)||\sin(1+\frac{\pi}{k})|\dots|\sin(1+\frac{\pi(k-1)}{k})|(1+2|\sin(1+\frac{k\pi}{k+1}))>2\sin{\frac{1}{2}}$
3). $n=k+1$ then
$$|\sin{(k+1)}|+|\sin{(k+2)}|=2^k|\sin(1)||\sin(1+\frac{\pi}{k})|\dots|\sin(1+\frac{\pi(k-1)}{k})||(1+2\sin(1+\frac{(k+1)\pi}{k+2}))|$$=$\left\{|\sin{(k)}|+|\sin{(k+1)}|\right\}\left\{2\frac{|\sin(1+\frac{k\pi}{k+1})|+2|\sin(1+\frac{(k+1)\pi}{k+2})|}{1+2|\sin(1+\frac{k\pi}{k+1})|}\right\}>
....>2\sin{\dfrac{1}{2}}$
Here $\dots$ means we need to prove $\left\{2\frac{|\sin(1+\frac{k\pi}{k+1})|+2|\sin(1+\frac{(k+1)\pi}{k+2})|}{1+2|\sin(1+\frac{k\pi}{k+1})|}\right\}>1$.
Note $$\left\{2\frac{|\sin(1+\frac{k\pi}{k+1})|+2|\sin(1+\frac{(k+1)\pi}{k+2})|}{1+2|\sin(1+\frac{k\pi}{k+1})|}\right\}=2\left\{\frac{1+2\frac{|\sin(1+\frac{(k+1)\pi}{k+2})|}{|\sin(1+\frac{k\pi}{k+1})|}}{\frac{1}{|\sin(1+\frac{k\pi}{k+1})|}+2}\right\}>2\left\{\frac{1+2}{\frac{1}{|\sin(1+\frac{k\pi}{k+1})|}+2}\right\}>1$$.
Here $\frac{|\sin(1+\frac{(k+1)\pi}{k+2})|}{|\sin(1+\frac{k\pi}{k+1})|}>1$ and $\min(\sin(1+\frac{k\pi}{k+1}))>\frac{1}{4}$ are used due to sin function's increasing characteristics from $[0,\frac{\pi}{2}]$ where $1$ is within it.
Suppose now, it is proved $|\sin{(n)}|+|\sin{(n+1)}|>2\sin{\dfrac{1}{2}},n \ge 1,n\in \mathbb N$.
Comment: There must be a better way to prove $|\sin{(1)}|+|\sin{(1+1)}|>2\sin{\frac{1}{2}}$ instead of using $|\sin{(1)}|+|\sin{(1+1)}|=0.983$ and $\sin{\frac{1}{2}}=0.959$.


Beta coefficients from stratified analysis when there are covariates?

Question: Suppose I have a regression model shown below
Model 1:
$$
Y = \beta_0^\ + \beta_1SEX\ + \beta_2ALCOHOL\ + \beta_3SEX*ALCOHOL\
$$
The predictors I am interested in are SEX (binary: 0 female, 1 male) and Alcohol consumption (binary: drinker, non-drinker). Suppose that I found a significant interaction between SEX and ALCOHOL and decided to stratify the data by sex. So I would have two new models:
Model 2a:
$$
\text{Female: }
Y_F = \beta_0^\ +  \beta_2ALCOHOL\
$$
So for the female subset, the intercept is still $ \beta_0$ and the slope for ALCOHOL is $ \beta_2$
Model 2b:
$$
\text{Male: }
Y_M = (\beta_0^\ + \beta_1) + (\beta_2\ +\beta_3) ALCOHOL
$$
For the male subset, the intercept is now $\beta_0^\ + \beta_1$ and the slope for ALCOHOL is $\beta_2^\ + \beta_3$
This is pretty straightforward. If you fit a model like this in any statistical package, you would get this kind of result. However, if say, in the model, I actually included an additional variable AGE, which is a covariate (assuming that it does not interact with either SEX or ALCOHOL), the original model would be the one below:
Model 3:
$$
Y = \beta_0^\ + \beta_1SEX\ + \beta_2ALCOHOL\ + \beta_3SEX*ALCOHOL\ + \beta_4AGE\
$$
Further suppose that we still have a significant interaction between SEX and ALCOHOL and I would like to stratify the data again. I would get two models below if I followed the logic above:
Model 4a:
$$
\text{Female: }
Y_F = \beta_0^\ + \beta_2ALCOHOL\ + \beta_4AGE\
$$
Model 4b:
$$
\text{Male: }
Y_M = (\beta_0^\ + \beta_1) + (\beta_2\ +\beta_3)ALCOHOL + \beta_4AGE\
$$
However, the actual beta coefficients obtained using a computer program can be very different from what you obtain using the updated equations above. The difference in $\beta_0$ makes sense, because the stratified models in 4a and 4b still assume the pooled mean for age; namely, it estimates $\bar{Y}$ at the mean of all subjects' age, whereas in the stratified analyses done by a computer program, the intercepts of the models estimate $\bar{Y}$ at the mean age of a sub-group.
However, I wonder why the slopes are different. In other words, why are the slopes in Models 4a and 4b different from those produced by a statistical package.
Answer: Here's an intuitive answer:
When you stratify those last models, as you note, the intercept changes. However, the actual values do not change, so the mean predicted value should not change. But if you kept the coefficients the same, the mean predicted value would change - by just as much as the intercept changed.
Comment: I'm not sure this is what the OP is asking.  I think s/he wants to know why $\beta_4$, $\beta_2$ and $\beta_3$ are different in models 4a, 4b and 3.
Comment: I think that's what I answered.... but perhaps not.

Your answer is also right.
Comment: Yes, now that I look again at your answer I see you are right too - we just took it from different ends (so to speak).
Answer: When you fit models 4a and 4b you are allowing the estimates of $\beta_4$ to be different for the two different sex groups.  In effect, you are not fitting model 3 in two steps, but a variant on model 3 that has an interaction between sex and age.  So there is no real reason the coefficients in 4a and 4b should match those in 3.
Once $\beta_4$ is different, the other estimates are bound to be different in 4a and 4b from their estimates in 3, unless age is perfectly orthogonal to sex and alcohol (which is vanishingly unlikely).


Does Akaike's Information Criterion correspond to a type of regularization?

Question: According to this source, Akaike's Information Criterion can. be defined as:
$AIC = N \log(\frac{SSE}{N}) +2(k+2)$
with SSE the sum of the squared errors, and k the number of parameters in the model.
The first part looks like a loss function, so it seems that minimizing AIC means minimizing the loss as well as the complexity of the model (assuming smaller k implies less complexity).
Am I correct in interpreting the second term $2(k+2)$ as leading to a type of regularization similar to lasso or ridge regression? And is this reason why it is used instead of the MSE or the MAPE in forecasting models?
If this is indeed the case, why can't the second term just be $k$, instead of $2(k+2)$.
Answer: It can indeed be interpreted as a type of regularization, but it is not similar to lasso or ridge regression.  The latter two regularize by penalizing nonzero values of the parameter estimates as part of the estimation procedure, whereas AIC, in effect, penalizes the number of parameters included in the model - which is typically specified by the modeler, not internally to the estimation procedure (with exceptions for certain automated model selection procedures such as stepwise regression.)
AIC is intended to facilitate comparisons between models, and the coefficient of 2 multiplying the $k$ is derived from asymptotic considerations.  These slides provide a very accessible introduction to how the AIC is derived. I agree the additive "4" is not useful and can be removed.   However, given the derivation, it's clear that the factor of "2" should remain - it makes the penalty for adding parameters to the model twice as large as otherwise, so it really isn't the same as a penalty of just $k$, and does have some asymptotic optimality properties.


Buzz in electric guitar recording

Question: I use some sort of synthesizer or something that has a plug in,plug out,line in, line out. I plug my guitar into it and then into an amp so I can hear it, then I use a 3.5mm aux cord to plug into my computer. I use audacity to record because I couldn't figure out the daw or whatever virtual recording studio things. When I record the guitsr has a low buzzing sound on it throughout the whole track. Through noise cancellation I can cut it out a little but it still sounds wierd. How can I record a better sound?
Additionally, if I purchased this
http://www.amazon.com/gp/aw/d/B000J5UEGQ/ref=mp_s_a_1_21?qid=1446091936&sr=8-21&pi=AC_SX110_SY165_QL70&keywords=audio+interface&dpPl=1&dpID=61zyGSCoRnL&ref=plSrch
Would I be able to record my guitar and a microphone at the same time and plug it into my computer using an aux cord?
Comment: Seriously? It's highly unlikely you'll get half decent results when you plug a guitar into "some sort of synthesizer or something". Get a ruddy simple audio interface with high-Z instrument input. They're available from as little as 20 € nowadays.
Comment: The noise is probably coming from the aux chord which is probably unshielded, and if you have it connected to the mic-in jack and have the computer mic input set up with +gain, it will be worse. At the least you should be connected via line-in not mic. Computers generate a lot of noise and an unshielded aux cable is likely going to act as an antenna. You might pick up HD noise especially
Comment: My friend gave it to me because he wasn't using it. It's a digitech rp200
Comment: Duuuuude just get a super cheap usb audio interface. Your noise could be coming from your digitech, the guitar itself, noisy power outlet, unshielded cables, etc. Too many bad variables in your setup right now. Eliminate the main culprit: the digitech. Use computer or phone plugins with some sort of amplitube or guitar rig setup. Something like the link below should work just fine. http://www.music-group.com/Categories/Behringer/Computer-Audio/Audio-Interfaces/UCG102/p/P0198
Answer: Unfortunately, the answer to your question is no... The device you linked to is a Behringer mixer. It is not designed to record audio to your computer. Although you could do it in theory, it's not the right way to record. Like some other folks have suggested, your best bet would be to invest in a low-cost audio interface with a high impedance input for your guitar. Also, since you want to record vocals and guitar simultaneously you're going to want to get yourself a two-channel interface. Lastly, make sure you get an interface with phantom power should you ever decide to record using a condenser mic. Read more on phantom power here.
This Behringer interface might actually do the trick. At 30 bucks, you're not going to get a super high-quality piece of gear, but for someone just getting into recording, $30 is a pretty small investment.
Hope that helps. Good luck!

Buzz in electric guitar recording


How to remove mymodule configurations on uninstall

Question: I have created a custom module and created a yml file to create a menu
system.menu.custom_menu.yml

id: custom_menu
label: 'Custom menu'
description: 'Custom menu.'
langcode: en
locked: true
dependencies:
  - mymod

When I installed my module it creates the the custom menu.
But then When I uninstall the module and try to install it again I get the following exception
exception 'Drupal\Core\Config\PreExistingConfigException' with message 'Configuration objects (system.menu.custom_menu) provided by mymod already exist in active configuration' in
/var/www/drupal8/core/lib/Drupal/Core/Config/PreExistingConfigException.php:70

What I am doing wrong? Is there any way to remove my configuration (system.menu.custom_menu) from the configurations when I uninstall my module?
Comment: Similar problem? (unfortunately unanswered): http://drupal.stackexchange.com/questions/164612/how-to-remove-a-configuration-object-from-active-config-in-drupal-8
Comment: Easy Install module is there to solve and avoid this issue completely https://www.drupal.org/project/easy_install
Answer: The easiest way is to ensure that the config has a dependency on your module.
dependencies:
  module:
    - yourmodule
  enforced:
    module:
      - yourmodule

Then Drupal will automatically remove that configuration and also warn in the UI that it will be removed.
Note that this only works for new installations, it won't fix existing ones.
An alternative is to put the configuration in config/optional instead of config/install, then it will only be created if it doesn't exist yet and the dependencies are met.
Comment: Any explanation for the "enforced" bit? I mean, a dependency is a dependency. Isn't its enforcement a given? Is that's what's necessary for the uninstall?
Comment: I just observed on un-installing a module in d8, drupal cleans-up all the configuration. I had some configurations on config/install/module.settings.yml I installed the module, looked into config db table, I could see the configurations in the table, then I simply uninstalled the module re-check the config table and configurations are gone! Am I missing something here?
Comment: Looks like this approach doesn't work with Entity Reference fields at the moment.  I created a bug report: [Config entities removed in wrong order causes PDOException](https://www.drupal.org/node/2762381)
Comment: Normal dependencies are calculated by code. Just becaouse you define a node type doesn't mean that anything specifically depends on your module. Saving a config entity re-calculates dependencies and your module will not be in that list.. unless you explicitly add it as an enforced dependency.
Comment: "Note that this only works for new installations, it won't fix existing ones." - is there any manual SQL tweak that will fix this? I've tried `DELETE FROM config WHERE ...` and a `drush cr` after `pm-uninstall` but when I next `en`/`pm-uninstall`, the `enforced:` is still not respected. Is the dependency tree stored elsewhere?
Comment: I think the "problem" here was that I was trying this out with purely example data, whereas: (a) `ConfigDependencyManager::$data` only has entries that have a UUID (so `views.settings` isn't even present); and (b) `ConfigManager::findConfigEntityDependentsAsEntities()` filters out anything with an unrecognized config prefix (so if your module decides to set `views.foo` on Views' behalf, it won't be recognized). Basically: "'enforced:' only makes sense for config_entity" is the key, but I don't think that's necessarily clear.
Comment: This solution works for disabling parent modules when you have a sub-modules. Otherwise when using itself as a dependency you will not be able to re-enable your module.


Adjunction in Abelian Categories

Question: Let $C,D$ be arbitrary categories and $F:C\to D, G:D\to C$ functors. We say $F,G$ are adjoint if for every $X\in C, Y  \in D$ there is an isomorphism of Hom-Sets between $Hom_D(FX,Y)\cong Hom_C(X,GY)$, which is natural in $X$ and $Y$.
If for example $C,D$ are abelian, we have an abelian group structure on the Hom-Sets. Does anything interesting happen if we add the condition that the natural isomorphism must be an isomorphism of abelian groups and not just sets?
Answer: Every adjunction between abelian categories in fact preserves the abelian group structure on the Hom-sets.  First, note that $F$ and $G$ will both preserve biproducts (since $F$ preserves colimits and $G$ preserves limits).  It follows that $F$ and $G$ preserve the addition operation on Hom-sets, since it can be constructed in terms of biproducts.  But now the adjunction bijection $\operatorname{Hom}_D(FX,Y)\to\operatorname{Hom}_C(X,GY)$ is given by taking a morphism $FX\to Y$, applying $G$ to get a morphism $GFX\to GY$, and then composing with the unit of the adjunction $X\to GFX$.  Both steps of this preserve addition of morphisms, and hence so does the adjunction bijection.

Adjunction in Abelian Categories


Do sport players have pension rights?

Question: Do players have pension benefits or retirement plans?
Unlike other employees, they can't work until the age of 65 and usually have a second career after they retire from their sport, generally before the age of 40.
Is there something official?
Comment: Does this question refer to athletes in the tagged leagues only? ... all american leagues/sports associations? or globally?
Answer: All major leagues in USA have Players Association who have official pension benefits plan for their players.
Those plans contain retirement benefits and other rights.
The players are eligible for a pension from the players association league they belong in:
1) National Football League Players Association
Full NFL pension plan

The NFL Players Association retirement plan package includes four
  plans:

Severance Pay Plan: A player with two credited NFL seasons (on the active roster, injured reserved or physically unable to perform list
  for three games in each of two seasons), receives $10,000 for every
  year played between 1993 and 1999 and $12,500 for every year from 2000
  on.
Player Annuity Program: A player with four credited NFL seasons receives an annuity valued at $65,000 at age 35 or five years after
  his last credited season, whichever is later.
Second-Career Savings Plan or 401(K): A player with two credited seasons will receive a $2 match for every $1 contributed to the plan
  up to a maximum club contribution of $20,000 per year.
Bert Bell/Pete Rozelle Retirement Plan (pension): A player with at least three credited seasons earns a benefit credit for every season
  he plays. The benefit credits add up to monthly pension checks that
  player receive starting at age 55.

2) National Basketball Players Association (NBPA)
Full NBA pension plan
The pension plan in the NBA is calculated as $306 for every month in the NBA.

For example Gary Payton played in the NBA for 17 seasons or 204 months.
  204x306=62,424. Gary Payton's pension will be $62,424 per year or
  $5,202 per month. A player with only three years in the NBA would get
  $11, 016 per year or $918 per month.

The pension is eligable to players strating the age of 50,
A player can opt to collect the pension at the age of 45 but only 2/3 of what it would be at 50.
The minimum season to be eligible to NBA pension is three seasons of playing.
3) Major League Baseball Players Association
Full MLB pension plan

Arguably, Major League Baseball ("MLB") offers one of the best pension
  and healthcare programs in all of sports. Players vest in their
  pensions after 43 days on the active roster and just one day qualifies
  a player for lifetime healthcare. Playing isn't even a requirement,
  benchwarmers may qualify for benefits as well. After 43 days, players
  qualify for the minimum benefit of $34,000 per year and those with 10
  years of service receive a pension of approximately $100,000 annually.
  In 2010, the MLB Players' Pension Plan reported assets of over $1.3
  billion for approximately 8,200 participants.

4) National Hockey League Players Association
Full NHL pension plan

21.2.    Basic Plan Benefits.
(a) Each player entitled to a full credited year of service for the 1993/94 playing season and thereafter shall have allocated and
  credited to an account established in his name, for his sole benefit,
  the following:
(i) for players who have received credit for less than 400 games played, the amount of $8,000 CDN per year; and
(ii) for players who have received credit for 400 games played or more, the amount of $12,500 CDN per year.

Sources: 1 2 3 4 5

Do sport players have pension rights?


Passing multiple parameters to django url template

Question: I am trying to pass multiple url parameters from a django templated to be used by a view function. Below are my codes :
A snippet from the template from where the parameters will be passed onto :
Assign

The view function :
def assign_recommended_project(request, group_id, client_id, project_id):
    group = StudentGroup.objects.get(id=group_id)
    group.client = client_id
    group.project = project_id
    group.save()
    project = Project.objects.get(id=project_id)
    project.is_assigned = True
    project.save()
    return redirect("coordinator_view_groups")

The  url of the view function :
 path(
        "coordinator/assign_recommended_project/<str:group_id/str:client_id/str:project_id",
        assign_recommended_project,
        name="coordinator_assign_project_recommendations",
    ),

This is the error that is shown :

Can someone please help me solve this. Thanks.
Answer: You need to open and close the angle brackets (<…>) for each parameter, so:
path(
    'coordinator/assign_recommended_project/<str:group_id>/<str:client_id>/<str:project_id>/',
    assign_recommended_project,
    name='coordinator_assign_project_recommendations',
),
Answer: path(
        "coordinator/assign_recommended_project/<str:group_id>/<str:client_id>/<str:project_id>",
        assign_recommended_project,
        name="coordinator_assign_project_recommendations",
    )


Python's platform module does not detect windows 10

Question: I am working on Windows 10 presently and need to put some code if the platform is Windows 10. So, I checked in python docs and read about platform module. This is what the documentation says :

platform.win32_ver(release='', version='', csd='', ptype=''):
  Get additional version information from the Windows Registry and return a tuple (release, version, csd, ptype) referring to OS release, version number, CSD level (service pack) and OS type (multi/single processor)

When I tried the same function on my Windows 10 machine I got below :
>>> platform.win32_ver()
('8', '6.2.9200', '', u'Multiprocessor Free')

But, I was expecting the release to be 10 instead of 8.
So, any idea if I am missing something here ?
Also, can somebody please tell me if there exists any other way to detect if the windows platform is Windows 10 ?
Comment: And does that tuple reflect what's actually in the registry?
Comment: Seems a fix is scheduled to make it into Python 2.7.11 for this: http://stackoverflow.com/a/33436827/2448495 – to be released in December, 2015.
Comment: Possible duplicate of [Why does platform.release() return "8" in Windows 10?](http://stackoverflow.com/questions/33431155/why-does-platform-release-return-8-in-windows-10)
Answer: The problem is python uses GetVersionEx to determine the version.
As you can read here, Microsoft doesn't support this anymore and offers a different API.
However, you can always call the new API yourself, or check the registry value at HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion.
You can also use WMI to get the Win32_OperatingSystem instance.
I'd also like to note that specific version checking is generally considered a bad practice.


Recursive Bayes Learning

Question: I'm trying to work through an example from Richard Dudas Pattern Classification on Recursive Bayes Learning. My main question is why do we choose the $max[D^n] $ in: $$max[D^n] \le \theta \le 10 $$
In this example, we look at data points $ \{4, 7, 2, 8\} $ where after each iteration the LHS of the inequality is the max value of all observed data points. Conceptually, I'm just not 100% on why this it converges to maximum, instead of say, the arithmetic mean? Any explanation or intuition for this would be appreciated!
I have included pictures (from the book) of the example.
Posterior Density Recursion Relation
Comment: The data come from a uniform$[0, \theta]$ distribution (likelihood) where we assume $\theta$ is between 0 and 10 (prior). So $\theta$ is the upper bound for the data that we expect to see. After observing some data points, we know $\theta$ has to be at least as large as the largest observed point, otherwise it wouldn't be an upper bound for the data anymore.
Answer: This is standard Bayesian analysis, where

posterior $\propto$ prior x likelihood

In this case the data is made of iid observations from a $\mathcal{U}(0,\theta)$, hence with density$$\frac{1}{\theta}\mathbb{I}_{0\le x\le \theta}$$
The prior $\pi(\theta)=\mathbb{I}_{\theta\le 10}$ thus gets updated as
\begin{align}
\pi(\theta|x_1) &\propto \mathbb{I}_{\theta\le 10} \times \theta^{-1}\mathbb{I}_{x_1\le \theta}=\theta^{-1}\mathbb{I}_{x_1\le\theta\le 10}\\
\pi(\theta|x_1,x_2) &\propto \theta^{-1}\mathbb{I}_{x_1\le\theta\le 10} \times \theta^{-1}\mathbb{I}_{x_2\le \theta}=\theta^{-2}\mathbb{I}_{\max\{x_1,x_2\}\le\theta\le 10}\\
\pi(\theta|x_1,x_2,x_3) &\propto \theta^{-2}\mathbb{I}_{\max\{x_1,x_2\}\le\theta\le 10} \times \theta^{-1}\mathbb{I}_{x_3\le \theta}=\theta^{-3}\mathbb{I}_{\max\{x_1,x_2.x_3\}\le\theta\le 10}\\
\end{align}
and so on. (For the Uniform distribution, $\max\{x_i,i=1,...,n\}$ is a sufficient statistic.)

Recursive Bayes Learning


Não estou conseguindo pegar o id Fullcalendar V4

Question: Não estou recebendo os valores quando clico no compromisso.
Eu sempre recebo "Indefinido"
Alguém pode me dizer o que estou fazendo errado ..?
Muito Obrigado.
Eu fiz esse exemplo no CODEPEN caso alguém queira ver o problema ao vivo.
https://codepen.io/egameiro/pen/Rwbgemx
Veja abaixo meu código.

var calendarEl = document.getElementById('calendar');

var calendar = new FullCalendar.Calendar(calendarEl, {
  plugins: ['interaction', 'dayGrid', 'timeGrid'],
  defaultView: 'dayGridMonth',

  locale: 'pt-br',
  header: {
    left: 'prev,next today',
    center: 'title',
    right: 'dayGridMonth,timeGridWeek,timeGridDay'
  },
  navLinks: true, // can click day/week names to navigate views
  selectable: true,
  selectHelper: true,
  //selectMirror: true,
  editable: true,
  eventLimit: true, // allow "more" link when too many events

  //events: event1,
  events: [{
    id: '10',
    title: 'Meeting',
    start: '2019-08-01T10:30:00',
    end: '2019-08-01T12:30:00'
  }],

  eventClick: function (event) {
    alert(event.id);
    alert(event.title);
    alert(event.start.format('DD/MM/YYYY HH:mm:ss'));
    return false;
  },

});

calendar.render();
Answer: Olá, para funcionar você precisa remover as aspas do id, assim como no exemplo :

  events: [{
    id: 10,
    title: 'Meeting',
    start: '2019-08-01T10:30:00',
    end: '2019-08-01T12:30:00'
  }]


How to calculate the sum for each option of all webform results in a Drupal webform grid?

Question: I created a webform in drupal, and added a grid component in it. The grid has 13 questions and 3 options (good, bad, terrible). It's like a poll and people come and answer the questions.
In results, I already have the sum for each option in each question. What I also need is the sum for each option for all questions togehter. For example I need a sum row in grid footer!
I tried webform submissions in views, but it does not give me the data stored in grid.
Be aware that I'm noob in PHP and I don't know how to make TPL files.
image in this link says it all:
thanks
Answer: Create a 'webform submission' view. By using the Views Calc module you can display the sum of each field at bottom of the table/grid.

This module adds simple calculations to a views table. Requires the Views module.
You can SUM, AVERAGE, COUNT, MIN, MAX, or AVG selected columns. A plug in theme makes the view look more spreadsheet-like (right justifies numeric fields, shades calculated columns and rows, and underlines calculated rows).

Image from module page
Answer: The answer as suggested by Krishna Mohan is indeed a valid approach, here are some more suggestions to further enhance it.
The table in the OP is similar to this one:

The Views Calc module can be used to transform that table so that the calculations in the last rows (with Count, Sum and Max) get added to it (as shown in the answer as suggested by Krishna Mohan).
By replacing the columns '# Fish', 'Weight' and 'Big Fish' with 'good', 'bad' and 'terrible' (as in the question), and by asking for only the 'sum' to be added, it should answer the question I think, no?
To ask for the 'sum', just select it from the selection list, similar to what is shown in this screenshot:

For more details (step-by-step instructions), refer to the community documentation about the Views Calc module.
Disclosure: I'm a co-maintainer (not owner ...) of this module,
I hope this does not violate the site's policy on self-promotion.
Answer: If you would like to sum every column, the alternative module that you can use is Views Aggregator Plus.


Como usar outra linguagem que não JavaScript no browser?

Question: Apesar da enorme pluralidade de linguagens de programação em diversos ambientes (desktop, servidor, dispositivos móveis), o browser continua suportando uma e somente uma linguagem: JavaScript. A razão disso me escapa: ainda que exista o problema da compatibilidade (quem faz um site ou web app quer que ele funcione em qualquer browser), nada impede que outras linguagens sejam usadas e "compiladas" para JavaScript. Isso pode ser feito ou no lado do servidor (ex.: Google Web Toolkit) ou cliente (ex.: processing.js). Ainda que me pareça uma "gambiarra", funciona, e interesse nisso não falta (antigamente a plataforma PyPy suportava compilação Python para JavaScript, mas da última vez que chequei essa funcionalidade estava abandonada).
Existe alguma maneira padronizada (ou em processo de padronização, à la HTML5) de se oferecer suporte a outras linguagens de programação no browser, que não dependa da instalação de plugins (ex.: Java, Flash, Silverlight)? De preferência, algo que funcione exclusivamente no lado cliente (como o exemplo do processing.js) sem demandar um programa específico no lado do servidor (e consequentemente um round-trip a ele sempre que um código tenha de ser interpretado).
E se não existe, há algum obstáculo conhecido que inviabilize tal coisa? Em outras palavras, é apenas por falta de interesse dos fornecedores que isso ocorre, ou há algum problema ainda em aberto que impeça tal coisa - seja em caráter privado ou que dependa de consenso entre os diferentes major players (padronizadores, fornecedores de browsers, etc)?
Answer: Existem alguns impedimentos técnicos que dificultam a implementação de um ambiente multilinguagem no browser.
A linguagem Javascript possui bindings no Webkit (por exemplo) que é uma das engines web, entre o runtime c++ e a VM javascript (V8 no caso do chrome e JavascriptCore no caso do safari)
Primeiro que qualquer candidato a linguagem alternativa ao Javascript, precisaria ter uma VM também plugada diretamente no Webkit, com os respectivos bindings entre o runtime c++ e o runtime da VM.
O Webkit teria que ser reescrito para suportar (em runtime), duas ou mais VM's alternando-se de acordo com o código do usuário ou desenvolvedor
O projeto Dart da Google, tentou isso(e ainda tenta), sendo possivel usar esse branch do Chrome, chamado Dartium.. Mas ao que parece existem sérios problemas com os garbage collectors devido a duas ou mais VM's terem de ser carregadas em um mesmo processo, dividindo regiões de memória.. degradando consideravelmente a performance.
Uma das limitações é que a lógica DOM está escrita em C++, e a VM da linguagem precisa fazer operações bastante caras a nível de eficiência toda vez que precisa se comunicar com o runtime nativo em c++;
Possibilidade: reescrever a lógica DOM, HTML, SVG, etc.. em cada linguagem script.. mas.. não existem muitos ganhos pois essas linguagens tendem a serem menos eficientes do que a C, portanto o ganho na comunicação acaba se perdendo em outros lugares :(
Também existem problemas de compatibilidade:
Imagina, por exemplo, se a partir de 2014 browsers com javascript e dart sejam lançados.. os desenvolvedores precisariam checar se o browser suporta Dart ou outro script pra a partir dai, resolver enviá-lo ou browser.. (mas esse também é um dos motivos pelo qual Dart compila para Javascript.. não havendo problemas nesse caso), mas se a linguagem implementada não tiver esse transpiler.. nada feito
Outra possibilidade seria usar uma IR - Intermediate Representation - de um compilador, onde essa IR fosse tão poderosa que várias linguagems possam ser implementadas em cima dessa representação.
Dois grandes exemplos são o bytecode java, que permitiu várias linguagens distintas funcionarem na JVM, e também mais recentemente o projeto LLVM, com o seu "bitcode" próprio. (outras idéias de nota são o asm.js da mozilla.. mas que não são tão ambiciosas assim quanto uma IR universal)
Com essa idéia seria possivel ter apenas uma VM no browser, implementar o Javascript de forma a produzir essa IR, e deixar assim em aberto para que outros desenvolvedores feras em compiladores possam implementar linguagens distintas para o browser (ou quem quer que embarque essa VM)
Nota: as IR JVM assim como LLVM possui limitações para linguagens dinâmicas por terem sido pensadas para a realidade de linguagens estáticas em seu design.. A LLVM ainda produz um bytecode com alguns elementos não portáveis com instruções para os processadores específicos.. não sendo uma IR "universal".
O projeto da Google o Pnacl, usa uma VM LLVM modificada, com um bytecode propriamente universal.. problemas: LLVM foi feita para compilação AOT, portanto demora pra compilar, pois busca produzir um código final extremamente otimizado, ao contrário das VM JIT's como V8, Dart e Lua que buscam também rapidez ao produzir o código.
Como visto não existe um caminho fácil para essa tão sonhada plataforma, mesmo que haja vontade em perseguir esse caminho, é preciso muito investimento pra bancar uma equipe de alto nível, por no mínimo uns 2 anos, para sair com um resultado aceitável
A melhor pedida agora é ver se o projeto Dart consegue ser embarcado junto ao Chrome, tendo pelo menos uma plataforma dual.. pois para essa plataforma "universal", é preciso de um milagre, vontade e uma boa soma de dinheiro para torná-lo realidade.
Obs: Estou usando IR no sentido de bytecode (retargatável) final, e não no sentido de representação intermediária interna dos compiladores(IR nível 1), como comumente definem a IR a literatura especializada em compiladores
Comment: Valeu, era esse tipo de resposta que eu estava procurando. De fato, as linguagens alternativas ou "se compilam" para JavaScript ou são interpretadas em JavaScript, ambas as estratégias com suas desvantagens (ex.: performance ruim). Agora estou entendendo melhor os desafios técnicos que inviabilizam a abertura para mais linguagens.
Answer: Como foi citado nessa resposta, os navegadores não itnerpretam, por padrão, outras linguagens internamente. Mas,como alternativa, surgem bibliotecas em outras linguagens feitas em javascript e frameworks que geram javascript.
Um bom exemplo de biblioteca "tradutora" é a Bryton, que permite a utilização da tag


Show that function is uniformly continuous

Question: The function is defined as $f(x)=\frac{1}{1+|x|}$ and $f:\mathbb{R}\to\mathbb{R}$.
I now inserted the function into the definition for uniformly continuous functions and got an expression like
$\delta \cdot \frac{1}{(1+|x|)(1+|x_0|)}=\epsilon $.
How can i go on to estimate a value for $\epsilon$?
Comment: You want to get a value for $\delta$ and it is enough if we get one that satisfies $\delta\cdot\frac{1}{(1+|x|)(1+|x_0|)}\leq\delta\cdot\frac{1}{1\cdot 1}<\epsilon$, where the first inequality is always true. Therefore, any $\delta$ that is positive and smaller than $\epsilon$ will do.
Answer: $$|f(x)-f(y)|= |\frac{|x|-|y|}{(1+|x|)(1+|y|)} | \le | |x|-|y|| \le |x-y|.$$