Compare 90th percentiles of two samples (confidence interval, test)

Question: I have a dataset of ambulance response times before and after a quality improvement change. I'm looking to see if there is a difference in response times before and after the change. Specifically, I'm trying to report the 90th percentile values in two groups (Before and After), the difference between their two 90th percentiles, the $95$% confidence interval (CI) around that difference, and a $p$-value.
In R, the dataset might look like this:
set.seed(123)
data <- data.frame(
  Group = sample(c("Before", "After"), 100, replace = TRUE),
  ResponseTime = rnorm(100, mean = c(10, 15), sd = 2)
)

I can easily test the difference of means using the t.test function:
t.test(data$ResponseTime[data$Group == "Before"],
       data$ResponseTime[data$Group == "After"])

I can also calculate the 90th percentiles like so:
before <- quantile(a$ResponseTime[a$Group=="Before"], probs = 0.9, na.rm = T)
after <- quantile(a$ResponseTime[a$Group=="After"], probs = 0.9, na.rm = T)

But I can't figure out how to compare the two.
My questions:

Does this even make sense?
If it does make sense, what test would I use to compare the 90th percentiles?
Comment: A bootstrap and a permutation test will get you a CI and *P*-value respectively, without many distributional assumptions. Inference towards the tails of a distribution is always a bit less reliable compared to some central measure, how big is your sample?
Comment: With times I'd be inclined to consider ratios rather than differences; it's a lot easier to save 5 minutes on a 1 hour time than on a 10 minute time. Meanwhile, you can't do it at all with a 4 minute time. ... but you could maybe save say 8% in each of those cases.
Comment: total sample is 28,981. 14,551 in the After, 14,430 in the before groups.
Comment: can you plot the(combined) distribution. maybe possible to estimate full distribution parameters.
Comment: An interesting alternative to the bootstrapping method could be a Fiducial approach where we might consider probabilities that specific percentiles in the sample are the 90th percentile of the true distribution and based on that compute a Fiducial distribution for the difference between the percentiles.
Comment: A confidence interval for a percentile is called a *tolerance limit* -- that's worth investigating.  (The two endpoints of the CI are different kinds of tolerance limits.) A nonparametric confidence interval (which might be a good choice here) is described at https://stats.stackexchange.com/questions/99829.  A similar approach (based on rank statistics of the combined dataset) provides an excellent nonparametric test of equality of any two percentiles. @PBulls Usually both the bootstrap and permutation tests can be computed using combinatorics: subsampling isn't even needed.
Answer: You can use a bootstrap to generate a confidence interval on this quantity, and a permutation test for the P-value. Let's go over an example for both.
I'm not going to assume your response times are normally distributed, and I'm going to use a smaller sample than your actual dataset of $n=28{,}981$. The large sample size will work to your advantage for inference but will make these methods more computationally heavy than they already are.
To show you what we'll work with for inferring the 90th percentile of 'After' - 'Before' response time:
n <- 220
set.seed(1)
Group <- sample(1:2, size=n, replace=TRUE)
Resp <- rexp(n, rate=1/c(10, 15)[Group])

data <- data.frame(
   G = c("Before", "After")[Group],
   R = Resp
)

We know the exact quantity that we're trying to estimate here which is qexp(.9, 1/10) - qexp(.9, 1/15) $=-11.51$; you don't have this luxury in your real data. The assumed distribution has a pretty flat cumulative density towards the top however, so the upper quantiles are going to be pretty susceptible to sampling effects (read: vary from draw to draw).
The bootstrap is easy enough to implement manually, but let's use boot.
resamples <- 1E4
## Function to calculate statistic of interest
## Relies on reference level sorting *last*!
qdiff <- \(d) diff(tapply(d$R, d$G, quantile, probs=.9))

## Wrapper for boot
bootfun <- function(data, i) qdiff(data[i,])

bootstrap <- boot::boot(data, statistic = bootfun, R = resamples)
boot::boot.ci(bootstrap, type = c("perc", "basic", "norm"))
> Intervals :
> Level      Normal              Basic              Percentile
> 95%   (-17.94,  -0.86 )   (-16.29,  -0.21 )   (-20.98,  -4.90 )

There is probably more than one package that'll do permutation testing for you as well, you can do it by hand too:
nA <- sum(data$G == "After")
rows <- seq_len(nrow(data))

permute <- vapply(seq_len(resamples), \(i) {
   data$G <- c("B", "A")[1 + (rows %in% sample(rows, size=nA))]
   qdiff(data)
}, numeric(1))

permute_P <- mean(abs(permute) > abs(qdiff(data)))
> 0.0102

This is really just scratching the surface & doesn't address a few possible extensions or things to be worked out still:

which bootstrap confidence interval to use (they all come with trade-offs).
directly estimating the quantile sampling variance (requires assumption on its distribution).
the bootstrap CI and permutation P-value do not have the direct relation that most parametric tests have, so you might get inconsistent results (e.g. P < 0.05 but 95% CI includes 0). You could back-transform the bootstrap CI into a P-value but I wouldn't recommend it.
while these methods come with relatively few assumptions, they can still go awry (e.g. highly skewed distributions, non-exchangeability) though your large sample size should help. A particular point I didn't go into is that this assumes your 'Before' and 'After' samples are independent, if this is some kind of within-cluster sample (same unit measured twice) you'd do well to account for that too. In the same vein, this bootstrap sampled from both groups randomly (because their size wasn't fixed in the design either), you may want to preserve some sampling features there.
as was mentioned in the comments, maybe you want to look at other quantities than absolute time difference; the same methods can be applied then.
Comment: (+1) Excellent answer. Flipping the axes on your graph would underline the problem even more. Naturally each graph shows the same idea with different conventions.
Comment: @SextusEmpiricus I explicitly left open *which* interval because it'd depend on the distribution & has ample discussion on this site already. See also `boot.ci` docs or any intro text, in display order they are normal-approximate (based on $\sigma$ of bootstrap means), 'hybrid' Efron's quantiles (basic), and raw quantiles. Other options with more parametric assumptions exist. What is your definition of a CI then? I went ahead & checked 95% coverage in the first 1E4 seeds here, the raw quantile does best at just under 96% (so slightly conservative), followed by normal at <93% and basic at <90%.
Comment: A confidence interval is an interval for which the frequency that the interval contains the true value is equal to the nominal percentage when conditioning on the true value of the parameters. A simple example of a bootstrap distribution that will never give a correct confidence interval is the estimation of the parameter $\theta$ for an uniform distribution $U(0,\theta)$ (like the German tank problem). The use of bootstrap distributions is an approximation with the assumption that the distribution is symmetrical and not changing much when the location is shifted.
Comment: The problem with the ambulance response times here (estimating the 90th percentile) is not exactly the same as the german tank problem (estimating the 100th percentile), and it is also about estimating a difference instead of an absolute value. So probably the approach with bootstrapping may give a good indication. However, I would not blindly apply it without some analysis of the type of problem and distribution and checks whether a bootstrap distribution might give a false idea of the fiducial distribution.
Comment: How are these confidence intervals computed? Are they a 95% region created by using the quantiles of the bootstrapping sampling distribution? But that's not a confidence interval.
Comment: @NickCox you make a very fair point, but it felt wrong not having the horizontal axis be time (maybe I've made too many survival curves).
Comment: Indeed; each tribal tradition usually boils down to whatever is consider the outcome or result of interest being plotted vertically. Or the convention that time is plotted horizontally is triumphant (not necessarily in Earth sciences or archaeology!).
Answer: in R, quantreg package has rq funtions can handle this.
library(quantreg)
library(tidyverse)

set.seed(123)
# here, i made some minor modifications to your data, so expected q90 difference is 5.0
Group = sample(c("Before", "After"), 100, replace = TRUE)
data <- data.frame(
  Group = factor(Group, levels = c('Before', 'After')),
  ResponseTime = if_else(
    Group == 'Before',
    rnorm(100, mean = 10, sd = 2),
    rnorm(100, mean = 15, sd = 2),
  )
)

model <- rq(ResponseTime ~ Group, data, tau = 0.90)
summary.rq(model, se = 'boot')

result is
Call: rq(formula = ResponseTime ~ Group, tau = 0.9, data = data)

tau: [1] 0.9

Coefficients:
            Value    Std. Error t value  Pr(>|t|)
(Intercept) 12.22249  0.87235   14.01104  0.00000
GroupAfter   4.89747  0.92706    5.28282  0.00000

for more detail, refer to summary.rq help docment.
Answer: The answer by @PBulls is excellent, and I would just like to add a thought here:
What do you need the P value for actually? The use of P values is widespread in empirical research but even experts like Statisticians, Epidemiologists or Psychometrists are bound to interpret them incorrectly (see for example the study quoted in Gigerenzer et al's "The Null Ritual"). An extensive list of misinterpretations is collected in Greenland et al's paper, and with your sample size of 28,000 most tests will yield a "significant result" anyway, even for tiny differences. My recommendation is therefore not to bother too much with P values (short of abandoning them altogether as suggested by McShane et al) and focus on something else instead.
If you have the possibility, in communicating your results, focus on effect sizes and variability, displayed in graphs or summarized in confidence intervals, as encouraged for example by Dunkler et al. for transplantation medicine. This will hopefully lead to discussions and further insights, like "for which circumstances was response more time reduced, and for which less so?" such that the merit of current measures to reduce response times can be discussed and improvements can be suggested.
Comment: Thanks, Geeeero. I'm a physician who does some research and tries to understand and use good methodology. I agree completely with you and hate p-values. I've found that I get papers returned from peer-reviewers who insist on p-values. Even when using large datasets. I make the same arguments you presented, but sometimes the nature of peer-review is if you want to get published, sometimes you have to relent. I really do appreciate your thoughts!
Answer: Here is an approach for the computation of the intervals using a fiducial distribution. The steps are as following

Compute fiducial distributions for the two individual percentiles. This can be done by considering the probabilities that the true percentile $\theta_{90}$ is below a particular order statistic $P(\theta_{90}<x_{(i)})$. This probability can be computed with a beta distribution.
See also: How to obtain a confidence interval for a percentile?

Interpret the fiducial distributions as probabilitiy distributions (this is an approximation, the fiducial distribution does not behave exactly like a probability distribution) and compute the probabilities for the joint probabilities of the two parameters/percentiles to be inside the 2-d bins/cells created by the grid.

Compute boundaries based on the distribution and consider the bounds for the difference as boundary of regions that ensure the probability to be at least $\alpha \%$ (the computed joint probability is coarse/discrete and we can not nicely integrate it, but we can sum probabilities of all the cells through which the boundary passes)

The image below illustrates how this goes. For two samples $x$ and $y$ we draw a grid with grid lines corresponding to the values of the sample. We compute for each cell probabilities (depicted by a color in the image, purple is more probable and yellow less probable). For a line corresponding to some constant value of $x-y$ we consider all the cells that it passes through and in addition the cells above/below it (for lower/upper bound) and add up the probability to compute an estimate for the fiducial probability. The lines in the image below correspond to a 95% fiducial interval and it is computed such that the light shaded area is at least 95%. The actual coverage will be larger because the lines cover a larger area than the light shaded area.

Note 1: I created this approach quickly and do not know whether this has been described elsewhere before. What annoys me is that the actual coverage 0.9701 is different from the nominal coverage 0.95, even with large samples such as $n=500$. The method is an approximation, but I had hoped that the difference would have become smaller quickly with increasing sample size. I am not sure whether the discrepancy is because of the approximation errors (using discrete boundaries of the square grid) or because of the intrinsic error in the method which is the use of the fiducial distribution as if it is a true probability density independent from the sample.
Note 2: the problem with the discrete estimate of the density might be reduced by smoothening the distribution. I have left this out as it complicates the problem a lot and is not really necessary for a proof of principle.
Note 3: The computation with the matrices for the joint distribution takes a lot of time. As an alternative one can also use a Monte Carlo simulation after having obtained the one-dimensional fiducial distributions. Also, for repetitions with the same sample sizes and quantiles, the computations with the beta distributions can be stored and re-used.
Edit: I have implemented notes 2 and 3 and it appears that now for n=500 the actual coverage might be closer to the nominal coverage. This indicates that the discreteness of the fiducial distribution (not allowing to select exact 95% regions) plays a big role.
R-Code:
### function to compute fi% fiducial interval for difference in q-th quantiles
fi_dq = function(x, y, q = 0.9, fi = 0.95) {
  nx = length(x)
  ny = length(y)
  x = x[order(x)]
  y = y[order(y)]
  kx = 1:nx
  ky = 1:ny

  ### compute one-dimensional fiducial probabilities and related probabilities
  Fx = 1-pbeta(q,kx,nx+1-kx)    ## P(theta < x_k)
  Fy = 1-pbeta(q,ky,ny+1-ky)    ## P(theta < y_k)
  px = diff(c(0,Fx,1))
  py = diff(c(0,Fy,1))

  pxy = outer(px,py,"*")   ### cell probabilities
  diffxy = outer(x,y,"-")  ### cell values of difference

  ### compute fiducial lower boundaries
  lowerxy = rbind(diffxy[1,],diffxy)  ### add rows for edges
  lowerxy = cbind(lowerxy,lowerxy[,ny])

  lowerord = order(lowerxy)                  ### order values and add upp associated probabilities
  lower_diff = lowerxy[lowerord]
  lower_F = cumsum(pxy[lowerord])
  lower_k = max( which(lower_F < (1-fi)/2) )  ### compute a 1-alpha/2 boundary
  lower_bound = lower_diff[lower_k]

  ### compute fiducial upper boundaries
  upperxy = rbind(diffxy,diffxy[nx,])  ### add rows for edges
  upperxy = cbind(upperxy[,1],upperxy)

  upperord = rev(order(upperxy))
  upper_diff = upperxy[upperord]
  upper_F = cumsum(pxy[upperord])
  upper_k = max( which(upper_F < (1-fi)/2) )
  upper_bound = upper_diff[upper_k]

  return(c(lower_bound, upper_bound))
}

### some settings
set.seed(1)
n = 500
q = 0.9
fi = 0.95

### simulations to test true coverage probability
m = 10^4
set.seed(1)
bounds = sapply(1:m, FUN = function(s) {
  x = rexp(n,1/10)
  y = rexp(n,1/15)
  fi_dq(x, y , q, fi)
})

### effective coverage
true = qexp(q,1/10) - qexp(q,1/15)
mean((bounds[1,] < true)*(true < bounds[2,]))

### example from question
### results in -0.8429189  2.7977309
set.seed(123)
data <- data.frame(
  Group = sample(c("Before", "After"), 100, replace = TRUE),
  ResponseTime = rnorm(100, mean = c(10, 15), sd = 2)
)

fi_dq(x = data$ResponseTime[data$Group == "After"],
      y = data$ResponseTime[data$Group == "Before"],
      q = 0.9, fi = 0.95)

### illustration of joint fiducial distribution
set.seed(1)
n = 100
x = rexp(n,1/10)
y = rexp(n,1/15)
q = 0.9
fi = 0.95

nx = length(x)
ny = length(y)
x = x[order(x)]
y = y[order(y)]
kx = 1:nx
ky = 1:ny

Fx = 1-pbeta(q,kx,nx+1-kx)    ## P(theta < x_k)
Fy = 1-pbeta(q,ky,ny+1-ky)    ## P(theta < x_k)
fx = diff(Fx)
fy = diff(Fy)
pxy = outer(fx,fy,"*")
diffxy = outer(x,y,"-")

plot(-100,-100, xlim = range(x), ylim = range(y),
     xlab = "x", ylab = "y")

bounds = fi_dq(x, y, q, fi)

### color polygons based on probabilities (not densities)
p_area = 0
for (l in c(2:nx)) {
  for (m in c(2:ny)) {
    area1 = sum(diffxy[l+c(-1,0),m+c(-1,0)]>bounds[1])
    area2 = sum(diffxy[l+c(-1,0),m+c(-1,0)]<bounds[2])
    p = pxy[l-1,m-1]
    rp = (p/max(pxy))
    polygon(x[l+c(-1,0,0,-1)],y[m+c(-1,-1,0,0)],
            col = hsv(0.15+0.55*rp,
                      0.7-0.5*rp,
                      1-0.3*rp),
            lwd = 0.1)
    if (area1 < 4) {
      polygon(x[l+c(-1,0,0,-1)],y[m+c(-1,-1,0,0)],
              col = hsv(0,0,0,0.2),
              lwd = 0.1)
    }
    if (area2 < 4) {
      polygon(x[l+c(-1,0,0,-1)],y[m+c(-1,-1,0,0)],
              col = hsv(0,0,0,0.2),
              lwd = 0.1)
    }
    if ((area2 == 4)*(area1 == 4)) {
      p_area = p_area + p
    }
  }
}
p_area  ### manual computed check p_area should be at least 'fi' or larger

lines(c(-10,70),c(-10,70)-bounds[1], lwd = 2, col = 1)
lines(c(-10,70),c(-10,70)-bounds[2], lwd = 2, col = 1)

Alternative code that combines note 2 and note 3 by computing with monte carlo simulations and making the discrete fiducial distribution a piecewise linear continuous function.
### function to compute fi% fiducial interval for difference in q-th quantiles
### using a monte carlo approach
fi_dq_mc = function(x, y, q = 0.9, fi = 0.95, m = 10^3) {
  nx = length(x)
  ny = length(y)
  x = x[order(x)]
  y = y[order(y)]
  kx = 1:nx
  ky = 1:ny

  ### compute one-dimensional fiducial probabilities and related probabilities
  Fx = 1-pbeta(q,kx,nx+1-kx)    ## P(theta < x_k)
  Fy = 1-pbeta(q,ky,ny+1-ky)    ## P(theta < y_k)
  px = diff(c(Fx))
  py = diff(c(Fy))

  draw_xy = sapply(1:m, FUN = function(k) {
    draw_x = sample(1:(nx-1),1, prob = px)
    draw_y = sample(1:(ny-1),1, prob = py)
    samp_x = runif(1, x[draw_x],x[draw_x+1])
    samp_y = runif(1, y[draw_y],y[draw_y+1])
    return(samp_x-samp_y)
  })

  lower_bound = quantile(draw_xy,(1-fi)/2)
  upper_bound = quantile(draw_xy,1-(1-fi)/2)

  return(c(lower_bound, upper_bound))
}

### some settings
set.seed(1)
n = 500
q = 0.9
fi = 0.95

### simulations to test true coverage probability
m = 10^3
set.seed(1)
bounds = sapply(1:m, FUN = function(s) {
  x = rexp(n,1/10)
  y = rexp(n,1/15)
  fi_dq_mc(x, y , q, fi)
})

### effective coverage
### result is 0.955
true = qexp(q,1/10) - qexp(q,1/15)
mean((bounds[1,] < true)*(true < bounds[2,]))

Answer: In line with a poster above who suggested using ratios, you could graph the results as a series of ratios depending on (the 'before') response time.  The x-axis would be the (before) response times, let's say in 10-minute intervals, and the y-axis would be the ratios of after/before shown for each 10-minute interval.   A clustered boxplot would work very well for that too, so the range, median, mean and outliers of response times could be graphed for both before and after, at each 10-minute interval.
And needless to say, the response times could also be dependent on distance from the ambulance station to the incident, time of day, etc.  You might try getting someone to make a GPS analysis.
Comment: This is an interesting suggestion but how are you gonna get the response times for the y-axis and x-axis in 10-minute intervals? This requires some way to categorize the data according to additional variables and have several pairs (or larger groups) of before and after times. You suggest the use of extra variables in the final paragraph that may achieve this, but it might be good to explain this better.


Limit display object's drag coordinates in AS3

Question: how can i reference a display object's coordinates according to it's parent object or stage from within the class that creates the object?
essentially when i create a new sprite object from a custom class and add it to the display list, i'd like to include code within the custom class that limits the drag coordinates to the stage, or a section of the stage.
//Frame Script
import Swatch;

var test:Sprite = new Swatch();
addChild(test);

___________________

//Custom Class
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;

public class Swatch extends Sprite
    {
    public function Swatch()
        {
        init();
        }

    private function init():void
        {
        var swatchObject:Sprite = new Sprite();

        swatchObject.graphics.beginFill(0x0000FF, 1);
        swatchObject.graphics.drawRect(100, 100, 150, 150);
        swatchObject.graphics.endFill();

        swatchObject.addEventListener(MouseEvent.MOUSE_DOWN, onDrag, false, 0, true);
        swatchObject.addEventListener(MouseEvent.MOUSE_UP, onDrop, false, 0, true);

        this.addChild(swatchObject);
        }

    private function onDrag(evt:MouseEvent):void
        {
        evt.target.startDrag();
        //how to limit it's dragability to the Stage?

        }

    private function onDrop(evt:MouseEvent):void
        {
        evt.target.stopDrag();
        }
    }
}

Comment: Don't forget to listen for the Event.MOUSE_LEAVE event (attach `onDrop` to it), in case the user clicks on the object and let's go off-stage (although perhaps this is built-in to the `startDrag()` functionality already?). Reference: http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/Stage.html#event:mouseLeave
Answer: There is some native support for what you want to do. startDrag() accepts a rectangle as a parameter which restricts the region in which the drag can take place.
function startDrag(lockCenter:Boolean  = false, bounds:Rectangle  = null):void

Hope that helps,
Tyler.
Comment: ok, so the second parameter of startDrag is what i'm looking for.  how do i reference the stage from my object?  i tried including flash.display.Stage, and then trace(this.parent.stage.stageWidth) but it gave an error.
Comment: as long as you are on the display list, you can just say "stage.stageWidth", you don't need to import it
Comment: ok i figured it out.  i had to create an event listener for ADDED_TO_STAGE in my constructor targeting the init() function, otherwise stage was null when i tried referencing it.  forgot about that pitfall.


Prove C(A) is a subspace of a linear mapping from $R^n$ to $R^m$

Question: The exercise is the following:

The column space $C(A)$ of a linear mapping $A : \mathbb{R}^n \to \mathbb{R}^m$ is defined by
$$C(A)=\{y ∈ R^n |∃ x ∈ \mathbb{R}^m\text{ with }y=Ax\}$$
Prove that $C(A)$ is a subspace of $R^n$ .

I'm a little confused, say it's a mapping from $\mathbb{R}^3$ to $\mathbb{R}^2$, what does it mean this mapping for my column space? Am I making all the vector become a plane after applying the transformation $A$? I would like to understand what is actually happening before I can understand how I prove it to be true.
Comment: I am confused. Which new mapping? Is there some old mapping here?
Comment: i corrected my question, thanks
Answer: Suppose that you has a linear map $A$ from $\mathbb{R}^n$ to $\mathbb{R}^m$ (think about it as a $m \times n$ matrix with real entries). Then, the column space of $A$ is the set of all column vectors $y$ in $\mathbb{R}^m$ that can be written as $Ax$, for some column vector $x \in \mathbb{R}^n$ (observe that, the matrix multiplication is well-defined).
For example, if $A : \mathbb{R}^3 \to \mathbb{R}^2$ is given by the matrix
$$A = \begin{pmatrix} 1&3&2 \\ 1&4&1 \end{pmatrix}$$
then the columns of the matrix,
$$\begin{pmatrix} 1 \\ 1 \end{pmatrix}, \begin{pmatrix} 3\\4 \end{pmatrix}, \begin{pmatrix} 2\\1 \end{pmatrix} \in \mathbb{R}^2$$
are in the column space of $A$ since they can be written as
$$\begin{pmatrix} 1\\1 \end{pmatrix} = A \begin{pmatrix} 1\\0\\0 \end{pmatrix},
\begin{pmatrix} 3\\4 \end{pmatrix} = A \begin{pmatrix} 0\\1\\0 \end{pmatrix},
\textrm{ and}$$
$$\begin{pmatrix} 2\\1 \end{pmatrix} = A \begin{pmatrix} 0\\0\\1 \end{pmatrix}.$$
Answer: Consider a linear transformation $T:V\rightarrow W$ between finite dimensional vector spaces $V$ and $W$ over the same field $\textbf{F}$. The problem asks us to prove that $T(V)\subseteq W$ is a linear subspace. Indeed, this is the case.
In order to prove it, let us consider that $w_{1}$ and $w_{2}$ belong to $T(V)$. Given $a\in\textbf{F}$, we must prove that $aw_{1} + w_{2}$ also belongs to $T(V)$.
But, if $w_{1}\in T(V)$, there exists $v_{1}\in V$ such that $T(v_{1}) = w_{1}$. Similarly, if $w_{2}\in T(V)$, there exists $v_{2}\in V$ such that $T(v_{2}) = w_{2}$. Since $av_{1} + v_{2} \in V$, it is true that $T(av_{1} + v_{2})\in T(V)$, which implies that
\begin{align*}
T(av_{1} + v_{2}) \in T(V) \Longrightarrow aT(v_{1}) + T(v_{2}) \in T(V) \Longrightarrow aw_{1} + w_{2} \in T(V)
\end{align*}
just as desired. Hence $T(V)$ is a linear subspace of $W$.
Hopefully this helps.


Do I need training data in multiple languages for a multilingual transformer?

Question: I am attempting to train a transformer which can categorize sentences into one of n categories. This model should be able to work with a number of different languages - English and Arabic in my case.
Do I need to have labelled training data in both English and Arabic to fine tune a pretrained transformer, such as BLOOM, or can I fine tune the model using only English samples, and then the model should also work well on Arabic samples for my classificaiton task, since the fine tuning only trained the classification head?
My thoughts are that the pretraining of this model should allow it to transform the same input texts in English and Arabic to the same (or similar) embedding, which the classification head would have learned to then predict these embeddings accurately through the fine tuning.
Answer: The multilingual pre-trained models are in principle capable of so-called zero-shot language transfer, i.e., after being fine-tuned in one language, it should work in other languages covered by the representation as well. This, however, depends largely on the task: transfer in sentiment analysis seems to be easy, for more challenging tasks such as hate speech detection or fact-checking, the results are still very poor (in mid-2022).
When you have at least some data for Arabic, it is always better to use them. If you have unlabeled Arabic data for the task, you can use some data augmentation techniques.
BLOOM is a generative model and it is huge. If you are interested in closed-class categorization (rather than a generation), you should consider using encoder-only models such as mBERT, XLM-R, or RemBERT, which are considerably smaller are suitable for classification.


Converter minutos em horas

Question: Preciso converter dois valores de minutos para horas utilizando PHP.
valor1 = 278 min
valor2 = 1161 min

Comment: Dividir por 60 não resolve?
Comment: Vou dar -1 porque não pergunta de forma clara o que queria e depois altera a pergunta invalidando respostas feitas.
Comment: A pergunta era esta: "Olá, preciso converter dois valores de minutos para horas utilizando PHP."
Comment: Tem esta função pronta aqui https://stackoverflow.com/questions/8563535/convert-number-of-minutes-into-hours-minutes-using-php
Comment: @PauloRamos Pois eh. Faz uma pergunta de uma forma, a gente gasta tempo pra responder e depois muda o sentido da pergunta. É a mesma coisa que perguntar: "_Como faz sanduíche com pão e hamburguer?_".. aí depois muda: "_Com pão, hamburguer e presunto?_"... lastimável
Comment: Quando te pedem que horas são? Vc responde somente a hora, ou responde os minutos tbm?
Comment: Não é o caso. Estamos falando de programação.
Comment: Se vc tiver outra pergunta com o que vc quer, vc pode fazer, não há problema algum nisso. Vc não pode é mudar o sentido da pergunta.
Comment: Enfim, não quero saber somente a hora. Acredito q seja dúvida minha e de muitos neste fórum. Transformar minutos em h:i pesquisei em diversos fóruns... Todos sem solução. Peco desculpas se não fui claro, mas a ideia desde o início era está.
Comment: Vc não pediu minutos, pediu horas. Está bem claro na pergunta. Se se equivocou, tudo bem, não há problema, mas não pode mudar a pergunta invalidando respostas já feitas.
Comment: Vc poderia alterar a pergunta caso não houvessem respostas. É normal a gente se enganar, mas neste caso depois de 4 horas alterar a pergunta quando há respostas, não é possível. Se vc queria em h:m, tem uma resposta aí que lhe atente bem.
Comment: Ok poderia indicar qual delas?
Comment: Só tem duas respostas. A minha e de outro usuário.
Comment: Nenhuma resposta resolve os valores de minutos para horas. Irei abrir um novo questionamento.
Comment: Uai, então por que marcou a resposta? A gente só marca a resposta quando ela resolve o problema. Quando não resolve, vc pode questionar nos comentários da resposta.
Comment: Resolveu o questionamento que fiz, nao aquele editado.
Answer: $minutos_totais = 278;
$horas = floor($minutos_totais / 60);
$minutos = $minutos_totais % 60;

php > $minutos_totais = 1439;
php > echo floor($minutos_totais / 60);
23
php > echo $minutos_totais % 60;
59

Comment: @arllondias Sua crítica não parece fazer sentido pra mim, uma vez que o entendimento padrão de "converter minutos para horas" é justamente pegar uma quantidade X de minutos e devolver uma quantidade Y de horas. Portanto 1439 minutos são 23 horas. De qualquer forma o Victor já mostrou também o cálculo para saber quais os "minutos restantes".
Comment: Teste dessa maneira e não funcionou, coloquei em minutos totais 1439, que teria que retornar 23:59 minutos no caso, retornou 59.
Comment: @LINQ tem razão, antes da pergunta ser editada, me confundi e imprimi apenas o resultado da variável minutos. foi apenas falta de atenção, tudo certo.
Answer: Pelo enunciado da pergunta, a intenção é converter a quantidade de minutos em horas, e não retornar horas e minutos.
O correto seria apenas fazer a divisão dos minutos por 60, retornando o valor em horas com decimais (caso o valor não seja múltiplo de 60):
<?php
$valor1 = 278;
$valor2 = 1161;

// arredondando para 2 casas decimais
$valor1 = round($valor1 / 60, 2); // retorna 4.63
$valor2 = round($valor2 / 60, 2); // retorna 19.35
?>

Ou seja, 278 minutos equivale a 4,63 horas, e 1161 minutos a 19,35 horas.
Caso não queira as decimais (o resto que não completou 1 hora):
<?php
$valor1 = 278;
$valor2 = 1161;

// arredondando para 2 casas decimais
$valor1 = floor($valor1 / 60); // retorna 4
$valor2 = floor($valor2 / 60); // retorna 19
?>

Comment: Não resolve esta última, se for somar os dois passam de 24:00.
Comment: @LucasSpielmann Tudo bem, foi apenas um complemento ao primeiro exemplo.
Comment: Preciso que convertendo os min p horas, exiba horas e minutos em formato de h:i. Somando os dois valores totaliza 23:59
Comment: @LucasSpielmann Entendi. Mas a pergunta não diz isso.
Comment: @LucasSpielmann A pergunta só diz _converter minutos em horas_

Converter minutos em horas


Bound of trace norm

Question: Let $\mathcal{H}$ be a separable Hilbert space with complex scalar, $T_1$ be a self-adjoint positive linear operator with finite trace norm, that is
$$\|T_1\|_{tr} := \sum_i\langle T_1 e_i,e_i\rangle <\infty.$$
For another linear operator $T_2$, if for any $e\in \mathcal{H}$ we have
$$|\langle T_2 e,e\rangle|\leq \langle T_1 e,e\rangle,$$
will we have $\|T_2\|_{tr}\leq \|T_1\|_{tr}$?
Answer: I can at least give a partial answer here. First check that $T_2$ is of trace class: for every orthonormal basis $\{e_n\}_{n\in\mathbb N}$ of $\mathcal H$ one has
$$
\sum_{n=1}^\infty |\langle T_2e_n,e_n\rangle|\leq\sum_{n=1}^\infty \langle T_1e_n,e_n\rangle=\|T_1\|_1<\infty\,.
$$
This implies that $T_2$ is of trace-class. Now assume that $T_2$ is normal so there exists a complex null sequence $(\lambda_n)_{n\in\mathbb N}$ and an orthonormal system $(f_n)_{n\in\mathbb N}$ in $\mathcal H$ such that $T_2=\sum_{n=1}^\infty \lambda_n\langle \cdot,f_n\rangle f_n$ and thus
$$
\|T_2\|_1=\sum_{n=1}^\infty |\lambda_n|=\sum_{n=1}^\infty|\langle T_2f_n,f_n\rangle|\leq \sum_{n=1}^\infty \langle T_1f_n,f_n\rangle\leq \operatorname{tr}(T_1)=\|T_1\|_1
$$
as desired. One then gets the following partial result:

Let $T_2\in\mathcal B(\mathcal H)$ and $T_1\in\mathcal B_+^1(\mathcal H)$ with $|\langle T_2e,e\rangle|\leq\langle T_1e,e\rangle$ for all $e\in\mathcal H$. Then $T_2$ is of trace class. If $T_2$ is normal then $\|T_2\|_1\leq \|T_1\|_1$. For general $T_2$ one has $\|T_2\|_1\leq 2\|T_1\|_1$. The latter upper bound seems to not be sharp (see further below).

Proof. Indeed for all $e\in\mathcal H$
$$
\Big|\Big\langle \frac12(T_2+T_2^*)e,e\Big\rangle\Big|\leq \frac12( |\langle T_2e,e\rangle|+|\langle e,T_2e\rangle| )=|\langle T_2e,e\rangle|\leq\langle T_1e,e\rangle
$$
so, because $\frac12(T_2+T_2^*)$ is self-adjoint (hence normal) $\|\frac12(T_2+T_2^*)\|_1\leq\|T_1\|_1$ (analogously for $\frac1{2i}(T_2-T_2^*)$). Then
\begin{align}
\|T_2\|_1&=\Big\| \frac12(T_2+T_2^*)+i\Big(\frac1{2i}(T_2-T_2^*)\Big) \Big\|_1\\
&\leq \Big\| \frac12(T_2+T_2^*)\Big\|_1+\Big\|\frac1{2i}(T_2-T_2^*)\Big\|_1\leq \|T_1\|_1+\|T_1\|_1=2\|T_1\|_1\,.\tag*{$\square$}
\end{align}
However I am not sure whether this constant "2" can be removed in the non-normal case. The classic counter-example popping up in a number of related problems is the matrix
$$
T_2=\begin{pmatrix}0&1\\0&0\end{pmatrix}
$$
but even for $T_1=\frac1{2}\operatorname{id}_2$ (the "extreme" case where one still has $|\langle T_2e,e\rangle|\leq\langle T_1e,e\rangle$ for all $e\in\mathbb C^2$) one gets $1=\|T_2\|_1\leq\|T_1\|_1=1$. To ensure this is not an artefact of dimension two I looked at
$$
T_1=\begin{pmatrix}a^2+d^2&0&0\\0&b^2+f^2&0\\0&0&c^2+g^2\end{pmatrix}\qquad T_2\begin{pmatrix}0&2ab&2cd\\0&0&2fg\\0&0&0\end{pmatrix}
$$
which for all $a,b,c,d,f,g\in\mathbb R$ and all $e\in\mathbb C^3$ satisfy $|\langle T_2e,e\rangle|\leq\langle T_1e,e\rangle$ (obvious). However even through numerical simulation I could not find any $a,b,c,d,f,g$ which violate $\|T_2\|_1\leq\|T_1\|_1$. Maybe someone else can complete the puzzle here.

Edit (2020/02/13): Today I thought about using Wielandt's trick${}^1$ to extend the normal case to the general case: for arbitrary $T_2\in\mathbb C^{n\times n}$ the larger matrix
$$
\tilde T_2:=\begin{pmatrix} 0&T_2\\T_2^*&0\end{pmatrix}
$$
is obviously hermitian and the (non-zero) eigenvalues of $\tilde T_2$ are the (non-zero) singular values of $T_2$ and their negatives. Now if it were true that
$$
|\langle \tilde T_2z, z\rangle|\leq \langle \tilde T_1z,z\rangle\qquad\text{ for all }z\in\mathbb C^{2n}\tag{1}
$$
(where $\tilde T_1:=T_1\oplus T_1=\operatorname{diag}(T_1,T_1)\geq 0$) then the result for hermitian matrices (resp. normal operators) would imply that $\|T_2\|_1=\frac12\|\tilde T_2\|_1\leq\frac12\|\tilde T_1\|_1=\|T_1\|_1$ as desired.
Unfortunately, however, $|\langle T_2x,x\rangle|\leq\langle T_1x,x\rangle$ for all $x\in\mathbb C^n$ in general does not imply (1). For this take $T_1,T_2\in\mathbb C^{2\times 2}$ as above (so $|\langle T_2x,x\rangle|\leq\langle T_1x,x\rangle$ holds) but for $z=(1,0,0,1)^T$
$$
\Big|\Big\langle \begin{pmatrix}0&T_2\\T_2^*&0\end{pmatrix}z,z\Big\rangle\Big|=2\not\leq 1=\Big\langle\begin{pmatrix}T_1&0\\0&T_1\end{pmatrix}z,z\Big\rangle
$$
as is readily verified. One can trace back the failure of this trick to the fact that $|\langle T_2x,x\rangle|\leq\langle T_1x,x\rangle$ for general $T_2$ does not imply that $\|T_2\|\leq\|T_1\|$ where $\|\cdot\|$ is the usual operator norm on the Hilbert space $\mathbb C^n$. ${}^2$ This is consistent with the inequality $\frac12\|A\|\leq r(A)\leq\|A\|$ (with $r(A)=\sup_{x\in\mathcal H,\|x\|=1}|\langle Ax,x\rangle|$ being the numerical radius) and by assumption we only know that
$$
\frac12\|T_2\|\leq r(T_2)\leq r(T_1)\overset{T_1\text{ normal}}=\|T_1\|\,.
$$
Note that this factor $\frac12$ emerges for the same reason the factor $2$ emerges in the above statement, so getting rid of it (assuming that is possible) will require a different idea altogether.

 Footnote 1: This idea of relating $T_2$ to the hermitian "extension" $\tilde T_2$ in terms of eigenvalues / singular values is due to Wielandt (refer to footnote 4 in "Some metric inequalities in the space of matrices" (Ky Fan, A.J. Hoffman, 1955)), hence the name.
 Footnote 2: If $\|T_2\|\leq\|T_1\|$ then the matrix $\begin{pmatrix}T_1&\lambda T_2\\\lambda T_2^*&T_1\end{pmatrix}$ is positive semi-definite for all $\lambda\in [-1,1]$ (follows, e.g., from Proposition 1.3.2 in Bhatia's 2007 book "Positive Definite Matrices" because $T_1\geq 0$). Evaluating this at $\lambda=\pm1$ readily implies $2|\operatorname{Re}\langle T_2x,y\rangle|\leq\langle T_1x,x\rangle+\langle T_1y,y\rangle$ for all $x,y\in\mathbb C^n$ which is equivalent to (1). Therefore, in this special case, Wielandt's trick would lead to success.
Comment: Thanks for the self-adjoint case! I was actually very interested in the non-self-adjoint case. Maybe it is not true as it is not seen from any classic material. But as you mentioned, I haven't found any counter example as well.

Bound of trace norm


Find UMVUE of difference of parameters of two exponential distribution random variables

Question: Let $X_{1}, \dots, X_{n}$ be i.i.d. having the exponential distribution $Exp\left(0, \theta_{x}\right)$ with $\theta_{x}>0$, and $Y_{1}, \dots, Y_{n}$ be i.i.d. having the exponential distribution $Exp\left(0,\theta_{y}\right)$ with $\theta_{y}>0$.
Assume that $X_{i}$'s and $Y_{j}$'s are independent, but they are unobservable.
Suppose that our sample is $\left(Z_{1}, \Delta_{1}\right), \dots,\left(Z_{n}, \Delta_{n}\right)$, where $Z_{i}= X_{i}(1-\Delta_{i}) + Y_{i}\Delta_{i}$ and $\Delta_{i}=I(X_i \ge Y_i)$ for $i=1, \dots, n$.
Please find an unbiased estimator and the UMVUE of $\theta_{x}-\theta_{y}$.
Note that the probability density function (p.d.f.) of $Exp(a,\theta)$ is $\theta^{-1}e^{-(x-a)/\theta}I(x>a)$.

The parameter, $\theta$, is commonly called the MTBF (mean time between failures) or MTTF (mean time to fix).
The inverse of the parameter, $1/\theta$, is equal to the hazard rate.

This question is a part of Exercise 3.9 in Shao Jun (2003).

The following is my attempt.
Here is the skeleton of my solution.
We first find the complete and sufficient statistics $T$, and then try to construct the unbiased estimator $\widehat{S}$, then the UMVUE would be $\mathbb{E}[\widehat{S}\vert T]$.
Let $U_i = X_i - Y_i$.
When $u\le 0$, we have
\begin{align*}
  P(U_i \le u)
  & = P(X_i- Y_i \le u) \\
  & = \int_{0}^{\infty} \int_{x-u}^{\infty} \frac{1}{\theta_x\theta_y} \exp\left\{ -\frac{x}{\theta_x} -\frac{y}{\theta_y} \right\} d y d x \\
  & = \exp (u / \theta_y) \frac{\theta_y}{\theta_x + \theta_y} .
\end{align*}
This implies $P(\Delta_i = 1) = \frac{\theta_x}{\theta_x + \theta_y}$.
Further,
\begin{align*}
  P ( Z_i \le z, \Delta_i = 1 ) & = \frac{\theta_x}{\theta_x + \theta_y} - \frac{\theta_x}{\theta_x + \theta_y} \exp \left( - \frac{\theta_x + \theta_y}{\theta_x \theta_y}  z\right) \triangleq P_{1,i} , \\
  % & =
  P ( Z_i \le z, \Delta_i = 0 ) & = \frac{\theta_y}{\theta_x + \theta_y} - \frac{\theta_y}{\theta_x + \theta_y} \exp \left( - \frac{\theta_x + \theta_y}{\theta_x \theta_y}  z\right) \triangleq P_{0,i} .
\end{align*}
Then $Z_i$ and $\Delta_i$ are independent, $Z_i\sim E\left(0, \frac{\theta_x\theta_y}{\theta_x+\theta_y}\right)$, and $P_{Z_i,\Delta_i} (z,\delta) = P_{1,i}^{\delta} P_{0,i}^{1-\delta}$.
Notice that the p.d.f. of the joint distribution of $Z_i$'s and $\Delta_i$'s is given by
\begin{align*}
  & p\left( Z_1 = z_1, \dots, Z_n = z_n, \Delta_1 = \delta_1, \dots, \Delta_n = \delta_n \right) \\
  & = \prod_{i=1}^n \left[ \frac{\theta_x + \theta_y}{\theta_x \theta_y} \exp\left( - \frac{\theta_x + \theta_y}{\theta_x \theta_y} z_i \right) \left\{ \frac{\theta_x}{\theta_x + \theta_y} I (\delta_i = 1) + \frac{\theta_y}{\theta_x + \theta_y} I (\delta_i = 0)\right\} \right] I(z_i>0)\\
  & = \left(\frac{\theta_x + \theta_y}{\theta_x \theta_y}\right)^{n} \exp\left( - \frac{\theta_x + \theta_y}{\theta_x \theta_y} \sum_{i=1}^n z_i \right) \left( \frac{\theta_x}{\theta_x + \theta_y} \right)^{\sum_{i=1}^n \delta_i} \left( \frac{\theta_y}{\theta_x + \theta_y} \right)^{n- \sum_{i=1}^n \delta_i} I(z_{(1)}>0) \\
  & = \exp\left( - \frac{\theta_x + \theta_y}{\theta_x \theta_y} \sum_{i=1}^n z_i \right) \theta_x^{-n+\sum_{i=1}^n \delta_i} \theta_y^{- \sum_{i=1}^n \delta_i} I(z_{(1)}>0)
\end{align*}
Therefore, the joint distribution of $Z_i$'s and $\Delta_i$'s is from an exponential family with $T = (\sum_{i=1}^n \Delta_i, \sum_{i=1}^n Z_i)$ as the complete and sufficient statistic.
I don't know how to continue and if it will actually exist.
Thanks for any suggestions and answers.

(update)
Thanks for the suggestion from @Xi'an.
If we are interested in $1/\theta_x - 1/\theta_y$, we could construct an unbiased estimator according to $\frac{n-1}{n} \mathbb{E} \frac{\sum_{i=1}^n (1-\Delta_i)}{\sum_{i=1} Z_i} - \frac{n-1}{n} \mathbb{E} \frac{\sum_{i=1}^n \Delta_i}{\sum_{i=1} Z_i} = 1/\theta_x - 1/\theta_y$.
But in this question, we focus on $\theta_x -\theta_y$
Although $\mathbb{E}[X_i] = \theta_x$, we have $\mathbb{E}[X_i \vert Z_i,\Delta_i]$ is a function of $\theta_x$, $Z_i$ and $\Delta_i$.
However, $\mathbb{E}[X_i \vert Z_i,\Delta_i]$ is non-linear in terms of $\theta_x$.
So, I don't know how to continue.
Comment: In effect, you observe an *iid* sample $(Z_i)$ of an exponential distribution with (rate) parameter $1/\theta=1/\theta_x+1/\theta_y.$ Since $\theta$ is a symmetric function of the parameters, if you could find an unbiased estimator of $\theta_x-\theta_y$ it would necessarily also be an unbiased estimator of $\theta_y-\theta_x,$ immediately implying $\theta_x=\theta_y.$ Since you don't assume equality of the parameters, your objective is hopeless: such an unbiased estimator doesn't exist.
Comment: Thank you--I thought I might be overlooking something.  So that means you should be able to use the mean of the $\Delta_i$ to estimate the chance with which one distribution will exceed the other--and that ought to lead to an effective strategy for estimating another function of $(\theta_x,\theta_y)$ from which you can obtain estimators of both parameters.
Comment: The fascinating thing is that they are not symmetrical, as shown by my "answer".
Comment: @Xi'an Yes. This question is a part of Exercise 3.9 in [Shao Jun (2003)](http://link.springer.com/10.1007/b97553). I added the source in my question.
Comment: @whuber Thanks a lot! Yes, parameter of $Z$, i.e., $\theta$ is a symmetric function of the parameters $\theta_x$ and $\theta_y$. But, I think, it may not be sufficient to show that the unbiased estimator doesn't exist. Because, $\Delta$ contains the information of $I(\theta_x \ge \theta_y)$.
Comment: @whuber But I just find some consistent estimators, $S_1$ and $S_2$, as shown in my attempt.
Comment: @Xi'an Thanks! I will have a try. But, intuitively, $\max\{X_i, Y_i\}$ and $\min\{X_i, Y_i\}$ are symmetrical. Why could $\max\{X_i, Y_i\}$ lead to an answer?
Answer: Changing the question in two different ways allows for some answers:

If $\theta_x$ and $\theta_y$ are rate rather than scale parameters,
$$
\frac{n-1}{n} \frac{\sum_{i=1}^n (1-\Delta_i)}{\sum_{i=1} Z_i} - \frac{n-1}{n} \frac{\sum_{i=1}^n \Delta_i}{\sum_{i=1} Z_i}\tag{1}
$$
is an unbiased estimator of $1/\theta_x - 1/\theta_y$ and since it only depends on $\mathbf T$, it is the UMVUE.

If instead $Z=\max\{X,Y\}$, with $\theta_x$ and $\theta_y$  scale parameters, the conditional distribution of $Z$ conditional on $\Delta=1$. Since
$$\mathbb P(\Delta=1)=\frac{\theta_x}{\theta_x+\theta_y}$$
we have
\begin{align}
\mathbb P(Z\le z|\Delta=1)&=\frac{\theta_x+\theta_y}{\theta_x}\mathbb P(Z\le z,\Delta=1)\\
&=\frac{\theta_x+\theta_y}{\theta_x}\mathbb P(X\le z,X>Y)\\
&=\frac{\theta_x+\theta_y}{\theta_x}\int_0^z\int_0^x \frac1{\theta_x\theta_y}
\exp\{-x/\theta_x-y/\theta_y\}\text dx\text dy\\
&=\frac{\theta_x+\theta_y}{\theta_x}\int_0^z(1-\exp\{-x/\theta_y\})\frac{\exp\{-x/\theta_x\}}{\theta_x}\text dx\\
&=\frac{\theta_x+\theta_y}{\theta_x}[1-\exp\{-z/\theta_x\}]-\\
&\qquad\frac{\theta_x+\theta_y}{\theta_x}(\theta_x^{-1}+\theta_y^{-1})^{-1}
[1-\exp\{-z(\theta_x^{-1}+\theta_y^{-1})\}]\\
&=\frac{\theta_x+\theta_y}{\theta_x}[1-\exp\{-z/\theta_x\}]-
\frac{\theta_y}{\theta_x}[1-\exp\{-z(\theta_x+\theta_y)/\theta_x\theta_y\}]
\end{align}
This is a signed mixture of two Exponential distributions
$$\frac{\theta_x+\theta_y}{\theta_x}\mathcal Exp(\theta_x)-\frac{\theta_y}{\theta_x}\mathcal Exp(\theta_x\theta_y/(\theta_x+\theta_y))$$ which is illustrated by the fit in the following graphs:

based on $n=10^6$ simulations from $\mathcal Exp(10)$ and $\mathcal Exp(1/10)$ samples. This distribution has mean
\begin{align}\mathbb E[Z\le z|\Delta=1]
&=\frac{\theta_x+\theta_y}{\theta_x}\theta_x-\frac{\theta_y}{\theta_x}\frac{\theta_x\theta_y}{\theta_x+\theta_y}\\
&=\theta_x+\theta_y\left[1-\frac{\theta_y}{\theta_x+\theta_y}\right]\\
&=\theta_x+\frac{\theta_y\theta_y}{\theta_x+\theta_y}\end{align}
The second term above is symmetric in $(\theta_x,\theta_y)$. Therefore,
$$\mathbb E[Z\le z|\Delta=1]-\mathbb E[Z\le z|\Delta=0]=\theta_x-\theta_y$$
which leads immediately to an unbiased estimator based on $(\mathbf X,\boldsymbol \Delta)$:
$$\dfrac{\sum_{i=1}^n Z_i\Delta_i}{\sum_{i=1}^n\Delta_i}-
\dfrac{\sum_{i=1}^n Z_i\{1-\Delta_i\}}{\sum_{i=1}^n\{1-\Delta_i\}}\tag{2}$$
although I cannot tell about about (2) being UMVUE as the $Z_i$'s are not from an exponential family.
Comment: Thank you very much for your serious reply. This is very useful. I think this answer temporarily ends my question until there is a clearer conclusion, for example, some negative proofs show that the unbiased estimation does not exist.


Nesting with SASS does not seem to work for me?

Question: So I have been trying to get SASS to work for a project, but for some reason the nesting does not want to work for me?
When I move the snippets for the .header-menu outside of the nest it works perfectyl fine, just not nested?

This is the code for the index.html:

<!DOCTYPE html>

    <meta charset="UTF-8">
    <title>Portfolio</title>
    <link rel="stylesheet" href="../stylesheets/scss/style.scss">

hallo dit is een test

This is the code for the Header file:

<!DOCTYPE html>

    <link rel="stylesheet" href="../stylesheets/scss/style.scss">

Pointbreak

Who am I?

My work

Contact

this is the style.scss, note that neither of the '&-menu' nor '.header-menu' works:

.header {
  background-color: white;

  &-menu {
    background-color: red;
  }

  .header-menu {
    background-color: orange;
  }
}

.homepage {
  background-color: lightgray;
}

and lastly the compiled CSS code:

.header {
  background-color: white;
}
.header-menu {
  background-color: red;
}
.header .header-menu {
  background-color: orange;
}

.homepage {
  background-color: lightgray;
}

/*# sourceMappingURL=style.css.map */

I hope I have supplied enough information, if not please let me know.
Diorcula

EDIT
  hereby i supply an image of my chrome webdev tools Network tab:

Also the version of SASS i use is: 1.25.0
  and the version of NPM is: 6.13.0
Comment: In addition to the questions above, are you seeing the compiled CSS file loaded properly into your webpage? (see the Network tab in DevTools to be sure)
Comment: In short, what you want is `.header .header-menu` compiled instead of `.header-menu`?
Comment: Is there a style overriding what you put in? Do you have another CSS file that may be causing this? This could also be a cache issue.
Comment: @Azametzin in short what I want is to be able to nest my styling, since the div "header-menu" is inside the div: "header" and i want to be able to layout my styling the same way so if i have more divs inside "header" i can easily add the syling for them to de header div. if this clarifies some
Comment: @disinfor no i have already checked that en emptied my cache, but no difference what so ever
Comment: @chriskirknielsen i will post an edit for this in the question with an image, but everything is fine there as far is i can notice
Comment: I voted to close this question, because it's a typo situation.
Answer: Answer
So after a good night sleep i found the asnwer,
you guys were all right in some way and it encouraged me to look somewhere else.
The problem was that i was linking the wrong stylesheet, that i found out only after looking at the Network requests in the DevTools.
There i saw that it was loading the style.scss file, while the browser cannot read this of course. it should have been the CSS file.

So i changed the folder and file from:
<link rel="stylesheet" href="../stylesheets/scss/style.scss">

To:
<link rel="stylesheet" href="../stylesheets/css/style.css">

Comment: Glad you figured it out!
Answer: You can place another & at beginning of &-menu to nest it inside .header.
.header {
  background-color: white;

  & &-menu {
    background-color: red;
  }

  .header-menu {
    background-color: orange;
  }
}

Compiled CSS:
.header {
  background-color: white;
}
.header .header-menu {
  background-color: red;
}
.header .header-menu {
  background-color: orange;
}

Comment: Yes, this question needs more details.
Comment: OP doesn't have to nest it. The compiled code they provided *should* work as expected. Especially with such a simple layout. I suspect there is something else going on..maybe an overriding style or a typo in the real code.
Comment: @Azametzin what details would you like to have more to be able to help? maybe i can provide them.


What is the fourier transform of this function?

Question: With
$$ f(x) = \frac{1}{p} e^{-\pi x^2/p^2} $$
and $p>0$, I got an answer of $\displaystyle e^{-\pi p^2u^2}$.
I just wanted to make sure I got the right answer. If I didn't, I will work through the problem and try again. Thanks.
Comment: Hi, I checked your function on the Wolfram Alpha. It seems the answer is little bit different. Please check the following link http://bit.ly/Z4KgM8 Good luck.
Comment: @Jdbaba: you do realize his problem is using $\pi$ and not $p*i$, right? :-)
Comment: Plus I tried a fourier transform I already knew on this calculator. It gave me a bizarre answer.
Comment: Note: unless you tell it $p>0$, it will make assumptions for the general case.
Comment: How do you tell it that p > 0? Where would I put it at?
Comment: Using the scaling property, is the answer I got above correct? Assuming you just use the scaling property and the fact that the Fourier transform of $e^{-\pi x^2}$ is $e^{-\pi u^2}$.
Comment: @CameronGarney If you think Wolfram|Alpha is giving you bizarre answers for transforms you know it's possible that you're using different conventions for the transform.
Answer: Yes, the answer is correctly derived from the scaling property of the Fourier transform. The function $\exp(-\pi^2 x^2/p^2)$ is $\exp(-\pi x^2)$ scaled by $1/p$. Therefore, the transform scales by $p$ and acquires a factor of $p$, becoming $p\exp(-\pi^2 p^2 x^2)$. Then divide by $p$ throughout.


ASP.NET Core and View conflict resolution

Question: I'm trying to build a plugin system for ASP.NET Core application. I have a folder inside the app called 'Plugins'.
In general, a plugin looks like a folder containing two files: Plugin.dll and Plugin.Views.dll
The app scans this folder and loads these assemblies
foreach (var ext in extensionManager.Extensions)
{
    mvcBuilder.AddApplicationPart(ext.Assembly);
    if (ext.ViewsAssembly != null)
    {
        mvcBuilder.AddApplicationPart(ext.ViewsAssembly);
    }
}

If these plugins have ViewComponents with the same name I get an error. Model from Plugin1 may be passed into Plugin2's Razor View.
The model item passed into the ViewDataDictionary is of type 'Plugin1.Models.MyModel',
but this ViewDataDictionary instance requires a model item of type 'Plugin2.Models.MyModel'

How can I resolve this conflict?
Answer:
The model item passed into the ViewDataDictionary is of type
'Plugin1.Models.MyModel',  but this ViewDataDictionary instance
requires a model item of type 'Plugin2.Models.MyModel'

You can try to use the full name Plugin2.Models.MyModel if this ViewDataDictionary instance requires a model item of type Plugin2.Models.MyModel.So that it will not pass Plugin1.Models.MyModel to this ViewDataDictionary.
Comment: How is it supposed to work this way? The problem is not that I pass the model instance of the wrong type. The problem is that ASP.NET Core finds the wrong View (cshtml file) because they have the same name.
Answer: I solved the issue by adding this Target to my plugins' .csproj files:
<Target Name="UpdateTargetPath" BeforeTargets="AssignRazorGenerateTargetPaths">
  <ItemGroup>
    <RazorGenerate Link="$(TargetName)\%(RazorGenerate.RelativeDir)%(RazorGenerate.FileName)%(RazorGenerate.Extension)" />
  </ItemGroup>
</Target>

I took this answer as a basis. I also delete the Include attribute from the RazorGenerate tag because it duplicates RazorCompiledAttribute in the resulting assembly.
On the host app's side, I extended view location formats with:
services.Configure<RazorViewEngineOptions>(opts =>
{
    var pluginName = ext.Assembly.GetName().Name;
    opts.ViewLocationFormats.Add($"/{pluginName}/Views/Shared/{{0}}.cshtml");
    opts.ViewLocationFormats.Add($"/{pluginName}/{{1}}/Views/{{0}}.cshtml");
});

In the plugin I must specify the fully qualified path to the view:
return View($"/{this.GetType().Assembly.GetName().Name}/Views/Path/To/MyView.cshtml", model);


Independent events iff $P(A\cap B)=P(A)P(B)$

Question: My teacher and wikipedia say that events $A$ and $B$ are independent if and only if $P(A\cap B)=P(A)P(B)$. But if one of $P(A)$ or $P(B)$ is 0, $P(A\cap B)=P(A) P(B)$ doesn't mean on does affect another. For example, pick a random number in $[0,1]$, let $A$ be the number is $0$, let $B$ be the number is in $[0,0.5)$. It is obvious $P(A)=0$ and $P(B)=0.5$. So $P(A \cap B)=0$. But if $A$ happens, $B$ must happen. Is it right that events $A$ and $B$ are independent if and only if $P(A\cap B)=P(A)P(B)$?
Comment: That's where this "official" definition doesn't agree with intuitive, since it implies that $A$ is independent of $A$ if $P(A)=0,1$. These are borderline cases which don't affect the big picture.
Answer: The definition is correct in the case $P(A)=0$ (or $P(B)=0$), only if the event
$A$ (or $B$) is impossible.
As you have shown, the definition breaks down for events with $P(A)=0$, which can occur.
Answer: A mistake in your argument as far as I understand-
If you are picking a random number in a continues range of [0,1], the probability of getting an exact number is zero as the number of options is infinite, so your sample space is infinite. While it is mathematically correct, it makes no sense as such.
However, let's consider the conjecture A and B are independent if and only if P(A∩B)=P(A)*P(B).
If P(A) or P(B) is 0, then that it means it is an impossible event that will never occur, say P(Sun rises from the north). While let B be a possible event like the sun seemed orange in the evening today, so P(Sun was orange in the evening)!=0.
Now, P(A∩B) means that the sun should be both rising in the north and be orange in the evening, which is an impossibility as the sun cannot rise in the north, so naturally P(A∩B)=0, even though only P(A) was zero.
Answer: Actually, that is the definition of independent. Then again, $P(B\mid A)$ is not $=1$ ("if $A$ happens, $B$ must happen"), it is not even defined.
Comment: Why shouldn't we *define* $P(B|A)$ as $0$ or $1$ depending on whether  $B\cap A=\emptyset$ or $B^c\cap A=\emptyset$? That would completely agree with intuition and won't upset anything.


Html/Css/Js: Display text before  tag

Question: This is a rather simple question, but i cant get to the right solution.
I am working on a legend for my leaflet map, I got this far:

However I would like to display the 0 before the color block and only the 4 afer the color block.
I am creating the colors with i-tags. The whole JS code looks like this:
function getColor(d)
            {
              return   d > 4  ?  '#045a8d' : //4
                       d > 3  ?  '#2b8cbe' : //3
                       d > 2  ?  '#74a9cf' : //2
                       d > 1  ?  '#bdc9e1' : //1
                                  '#f1eef6';
}
    ...

    grades = [0, 1, 2, 3, 4];

...

div.innerHTML += '0 ';

     for (var i = 0; i < grades.length; i++) {
      div.innerHTML += ' ' + (!grades[i + 1] ? grades[i] : '');}

CSS:
.legend {
    line-height: 18px;
    color: #555;
}
.legend i {
    width: 18px;
    height: 18px;
    float: left;
    margin-right: 0px;
    opacity: 0.7;
}

Any suggestions, on how I can display the 0 before the colors? I bet its quite easy, but all I tried didnt work so far.
Comment: http://jsfiddle.net/0tLoL5v2/
Answer: Because the i's are floating left they are moving the 0 over to the right. If you look at http://jsfiddle.net/73k05k7u/ I have put the 0 and 1 into a span and floated them left as well. So now it all displays inline. I also took the call to add the 4 out of the loop as you can just do it when the loop has completed. Makes it a little more readable and less comparisons required. NB best practise you should build up a string and set the innerHTML property just once.
// CSS
.legend span{
    float:left;

}

// JS
div.innerHTML += '0 ';

 for (var i = 0; i < grades.length; i++) {
  div.innerHTML += ' ';
 }
div.innerHTML = div.innerHTML +  '' +  (grades.length -1)+  '';

Html/Css/Js: Display text before  tag


Game Theory - First move vs second move advantage?

Question: This question came up in a lunchtime discussion with coworkers. None of us are professional mathematicians or teachers of math, and we weren't sure how to get the answer.  I apologize in advance if my question is not rigorous or uses the wrong terminology.
Is there any game (like NIM, etc) where the player making the second move has an advantage?
Additional question:  Can anyone give me an example of such a game?
Comment: Consider any nontrivial NIM position. If it's a win for the second player, there's your example. If it's a win for the first player, make a winning move for the first player; the resulting position is your example. Or take $n\times n$ *misère* hex (variant of [hex](http://en.wikipedia.org/wiki/Hex_(board_game)) where the player who connects, **loses**); if $n$ is odd, the second player wins.
Comment: What is NIM?...
Comment: @SujaanKunalan http://en.wikipedia.org/wiki/Nim
Answer: I'm sure there's plenty of practical solutions out there.    Here's a trivial solution that proves the existence of such games:
Let's say we play a game where starting from 0, each person gets to add a number from 1 to 9 to the running total.  The winner is the person who makes the total be ten.
In this case, the second player ALWAYS wins, because they just pick 10 minus the number the first person picked.
Comment: no problem.  A big part of studying games like this is to determine if there's a dominant auto-winning strategy for player 1,  or for player 2.    THen if there isn't, see if one side or the other has an edge
Comment: Oops! I should have asked for an example!  Thank you very much!
Answer: Consider the chess position with white king on a5, black king on c4, white pawn on b4 and black pawn on b5. The player on turn loses.
Comment: In my limited understanding, white has a slight advantage in general, being the first player.
Comment: @SteveED But in this situation, whoever's turn it is to move loses.  This type of situation is known as [Zugzwang](http://en.wikipedia.org/wiki/Zugzwang).
Answer: Consider any game along the lines of tic-tac-toe, where two players compete to form  certain configurations, except that, opposite to tic-tac-toe, the player who forms one of the specified configurations is the loser.  It should be clear that it is generally advantageous to move last in such a game.
For a specific example, consider the game of Sim. The board is six dots. Two players, Red and Blue, take turns.  A turn consists of a player connecting two not-connected dots, with a line of that player's color.  A player who completes a triangle of their own color loses immediately.
It's easy to see that this game cannot be a first-player win, by an argument very similar to usual strategy-stealing argument: in summary, if the first-player had a winning strategy, the second player could claim the win by ignoring the actual first player's move, pretending to be the first player, and using the hypothetical first-player strategy.  The extra first-player move on the board can't hurt them, and might help.   Once one shows that Sim never ends in a tie, this completes the proof that the game is a forced win for the second player to move, although the second player's actual winning strategy is quite intricate.
Comment: For the modified strategy-stealing argument to work, you have to show that moving is never advantageous (compared to not moving).
Answer: A simple example is Nim with two equal piles.  In this game, the second player has the advantage.  The advantage to moving second is that you can mimic whatever your opponent does to one pile on the other pile.  Thus, he'll have to clear one of the piles first, and then you'll clear the second pile and win.


Does Symantec Endpoint Protection create a AD user called "symantec"?

Question: I found this Administrator user called "symantec" in my AD and i wanted to know if the recently installed SEP (Symantec Endpoint Protection) product created it? Does anyone know if SEP needs to create a user in the Administrators group for its normal operation?
Explanation in to how SEP authenticates on the domain would also be helpful.
Answer: Here's Symantec's document re: Active Directory integration: http://service1.symantec.com/SUPPORT/ent-security.nsf/docid/2007092721431648  When you talk about "how SEP authenticates on the domain", I'm going to assume you're referring to SEP's access to the directory to perform its cruddy "synchronization" of OUs of AD into its own database. When add a "Directory Server", you will enter a username and password used to bind to the LDAP server. The account used here does not need "Domain Admin" or any other high level of privileges. The stock permissions on an Active Directory permit a non-privileged account to perform the LDAP query necessary to return user, computer, and OU objects. Unless you've made heavy modifications to your AD's stock permissions, you won't need this account to be an "Administrator".
The account used for directory service access is not created by the product's installer automatically. I'd turn on "Advanced Features" in Active Directory Users and Computers and examine the "Object" tab of the "Symantec" user you found to try and pinpoint when it was created to figure out where it came from.
My condolences to you for having to deal with SEP. We had some awful experiences with it and are transitioning Customers away from Symantec. At this point, I wouldn't even recommend SEP to terrorists, thieves, or other malcontents. It's just that bad.
Comment: Heh heh... Maybe it'll be better for you. It was *awful* for us and our Customers.
Comment: thanx for the helpful info. i didnt realise this product was so bad.


Trying to select Radio Button in IE11 with Excel VBA

Question: I've been trying to select 1 of 2 radio buttons in IE11 using Excel VBA.
Here is the HTML:

<FORM method=post name=ChangeAirportForm action=/mas/ChangeAirportAction.do>

Airport Site Code
Airport Site Name

<INPUT style="BORDER-TOP: 0px; BORDER-RIGHT: 0px; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px" CHECKED type=radio value=1 name=airport>
DMK
Donmueang

<INPUT style="BORDER-TOP: 0px; BORDER-RIGHT: 0px; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px" type=radio value=4 name=airport>
BKK
Suvarnabhumi

</FORM>

The radio button I wish to select is the type=radio value=4 name=airport
Sub select_radio_button()

    Dim sUrl As String: sUrl = xxxxx
    Dim oIE As New SHDocVw.InternetExplorer

    oIE.Visible = True
    oIE.Navigate sUrl

    Dim oIEdoc As Object
    Set oIEdoc = oIE.Document

    Dim oColl as Object
    Set oColl = oIEdoc.getElementsByTagName("input")

    Dim obj as Object

    For Each obj in oColl
        If obj.getAttribute("type") = "radio" And obj.getAttribute("value") = 4 Then obj.Click
    Next obj

End Sub

Answer: You said that your attempt is not working. I am not sure what exactly is not working as you did not provide any detailed information about it.
I tried to test the code on my side and it works fine. It selects the correct radio button.
I have not modified anything in your code. I just tried to run it.
Output:

I suggest again try to test the issue on your side. If still issue persists then please try to provide detailed information about the issue.
Try to inform us what OS build and which version of the Excel you are using? Inform us, if you are getting any error or warning messages. It may help us to understand the issue in a better way.


Can one average "close" smooth functions?

Question: Suppose $M$ is a connected, smooth, second-countable manifold.
Let $U \subset M^n$ be some neighbourhood of the diagonal. We will call a function $a: U \times \Delta_n \rightarrow M$ an "averaging operator of order n" if $a|_{U \times v_i} = \pi_i$, where $v_i$ denotes the i-th vertex of $\Delta_n$.
Intuitively, $a$ should tell us how to take a weighted average of "close" functions.
Does every $M$ admit a smooth averaging operator of order $n$, for some $U$ and all $n$?
(I am trying to prove that smooth functions are dense in $Hom(M,N)$ without embedding $N$ into any $\mathbb{R}^n$ and the above result would greatly help me.)
Comment: $\Delta_n$ is standard $n$-simplex?
Comment: Yes, it is the standard n-simplex as a submanifold of R^n.
Comment: I would remark that this question has been posted even on MathOverflow. There, until now it has received three interesting answers. Cf. http://mathoverflow.net/questions/81105/can-one-approximate-close-smooth-functions
Answer: The answer given by Sergei Ivanov  on MathOverflow was to use

the barycenter with respect to a Riemannian metric on $M$. For $x_1,\dots, x_n\in M$ and $(m_1,\dots ,m_n)\in \Delta_n$, define the barycenter as a point where the function
  $x\mapsto \sum m_i\operatorname{dist}(x,x_i)^2$ attains its minimum. Since the square of the Riemannian distance is smooth near the diagonal, and in normal coordinates it has the same first and second derivatives at the diagonal as the Euclidean counterpart, an easy application of the implicit function theorem shows that the barycenter is well-defined and depends smoothly on its arguments in a neighborhood of the diagonal.


Amazon SQS - FIFO Queue message request, inconsistent receives

Question: I have a FIFO SQS queue, with visibility time of 30 seconds.
The requirement is to read messages as Quickly as possible and clear the queue.
I have code in JAVA in a fashion shown below ( this is just a representation of idea only, not complete code ):
<code>//keep getting messages from FIFO and process them ASAP
while(true)
{
     List<Message> messages =
     sqsclient.receiveMessage(receiveMessageRequest).getMessages();
    //my logic/code here to process these messages and delete them ASAP
}
</code>
In the while loop as soon as the messages are received, they are processed and removed from the queue.
But, many times the receiveMessageRequest does not give me messages (returns zero messages).
Also, the messages limitation is only 10 at a time during receive from SQS, which is already an issue, but due to these zero receives, the queues are piling up.
I have no clue why this is happening. The documentation exactly is not clear on this part (or Am I missing in terms of the configuration of the queue?)
Please help!
Note:
1. My FIFO Queue always has messages in this scenario, so there is no case of Queue having zero messages and receive request returning zero
2. The processing and delete times are also Less than the visibility timeout.
Thanks.
Update:
I have started running multiple consumers for processing the FIFO queue. Clearly, one consumer is not coping up with the inflow of messages. I shall update in few days how multiple consumers are performing. Thanks
Comment: @John Thanks for replying.
Yes. I have tried long polling, similar behavior. It does not always get me messages even if the queue has more than 5000 messages.

I am attempting multiple consumers right now. But I wanted to in general understand the behavior
Comment: Have you considered using multiple threads/clients to consume messages in parallel? Might you be hitting the limit of 300 transactions per second (TPS) for FIFO queues? Have you considered using **Long Polling** (Receive Message Wait Time), which will only return a zero-message response after a designated time period (eg 20 seconds)?
Comment: How many messages are currently showing as **in flight**?  A FIFO queue requires that you handle each message correctly, and if you don't, they'll show up "in flight" and -- by design -- SQS waits for you to act on them or for their visibility timeout to expire.  Check this?
Comment: Hi Michael, the In-Flight are almost always zero, that means they are getting processed and deleted.
Answer: You have to first make sure that all messages you received are deleted within VisibilityTimeout. If you are using DeleteMessageBatch for deletion make sure that all 10 messages are deleted.
Also, how did you queue messages when you enqueue them?
Order of messages are guaranteed only in a single message group.
This also means that if you set the same group id to all messages, you are limited to a single consumer so that order of messages are preserved for sure. Even if use multiple consumers, all messages that belong to a same group becomes invisible to other consumers until visibility timeout expires.
Comment: What are "other" consumers...same SQS Client in loop is considered a single consumer or multiple different ones for each iteration?


How to view blocks with Text Overlay on hover?

Question: I'm working on a Drupal 7 site and I want to achieve similar thing (view blocks with Text Overlay on hover) shown here. http://ibakatv.com/ under the following blocks (sub sections):
Basically I would like to show text upon mouse hover just like what is shown on the above website.

MOVIE TRAILERS
TRENDING MOVIES ..
LATEST MOVIES etc etc

Also, can someone help how to achieve those view blocks with the navigation as listed above? Do you know this was done? I looked at BX Slider, but I'm unable to achieve it.
Answer: Your question appears to be a variation of Create a simple Text over Image Overlay on Hover with Drupal 7 and Views. If you also install/enable the Link module, the node title shown over the image can be a hyperlink to the node also.
Especially this part in it seems to be what you're looking for (be it with some minor variations):

Create a view 'Overlay'. Create a page which shows content of type 'overlay-image'. It shows an unformatted list of fields. Save and edit. On the edit page, add the fields 'Content: Image' and 'Content: Link' to the fields and exclude them from display.  For the last field add 'Global: custom text'. In the text field, write:

[field_image][field_link]

Curious to hear if this somehow will help ...


Change server manager rdp connecting port (azure)

Question: I have been trying to establish a remote desktop connection to a azure server using the server manager that is included in the rsat. But I havent find a way to connect to the server because my server isnt using the port 3389.
¿There is a way to change the default conecting rdp port in the server manager?
Answer: Change the azure RDP endpoint with public port ANY PORT you want to connect and private port 3389. You should be able to connect RDP using the public port (of course after you allow that port in your local machine's firewall)
Comment: the problem is that server manager always will try to connect to the  azure vm with the port 3389, but the rdp port en azure are randomly assigned. so i need to configure server manager to connect to the "ANY PORT" that i have selected
Comment: try using ip:port when you insert server


Calculating the volume of a cone given the surface and $s$

Question: I've been struggling with this for so long and I never got a chance to ask my teacher how to solve it.
If the surface of the cone is $360\pi$ and $s = 26 \text{cm}$, calculate the volume of that cone.I found the solution but there is no explanation, somehow you need to get to squared binomial and I'm not sure why.
Formula for the cone volume: $V = \frac13\cdot\pi\cdot r^2\cdot H$
Formula for the cone surface: $P = \pi\cdot r\cdot(r+s)$
Comment: "You don't know what s is?But isn't math the same in every country?..." A cone is a cone in every country but the signification of $s$ may be different from one teacher to another or from one book to another... E.g. the wikipedia article about cone don't use $s$ in any dimension of the cone: http://en.wikipedia.org/wiki/Cone
Comment: What is the shape of your cup? and what is $s$?
Comment: You don't know what s is?But isn't math the same in every country?small s is this http://profesorka.files.wordpress.com/2013/06/slika321.gif (not the entire green triangle but the line on the right that goes from bottom to the top, s is actually the side of the cone, so everything except the base is actually s, except the height of course).Anyway there isn't any shape mentioned so i guess it's just a regular cone, keep in mind that this is from the 9th (and last) year of elementary school so we probably haven't done every shape of cones.
Comment: Math is the same in every country but $s$ is not the same in every context.
Answer: First off, write the formula for the cone volume, and the formula for the cone surface. Edit your question with them, and I will edit my answer to help you further.

EDIT:
Using the formula for $P$, can you extract what $r$ is? (hint: yes you can) Then, once you have $r$, you can calculate $V=\frac13 \pi r^2 H$, as long as you can calculate $H$ from $r$ and $s$ (which you can, using a very famous theorem).
Comment: Edited --------
Comment: @user3711671 And I edited my answer.
Answer: $SA = \pi rs + \pi r^2$. Thus: $360\pi = \pi 26r + \pi r^2 \to r^2 + 26r = 360 \to (r+13)^2 = 23^2 \to r = 10$. Then $h = \sqrt{s^2 - r^2} = \sqrt{26^2 - 10^2} = 24$. We can now find $V$, and $V = \dfrac{\pi r^2h}{3} = \dfrac{\pi 10^2\cdot 24}{3} = 800\pi$
Comment: Way to go, you solved the whole task for the OP. Don't you think he would learn more if he only recieved hints, so that he could solve it on his own?
Comment: I found the same thing in solutions, but where did π disappear after the first arrow?By the way 5xum i tried to do it the same way you told me few months ago and I am asking this because of the 1st sentence in this comment.
Comment: But there are 2 pis on the right side and only 1 on the left, so shouldn't there still be 1 pi left?
Comment: @user3711671 if $\pi\cdot (a+b) = \pi\cdot c$, then $a+b = c$.
Comment: Thanks, I can't believe how i missed that.This doesn't seem difficult if you have at least some basic math skills but it's interesting how this task is marked with the 'difficult' mark in our book.


In Exact Matching in Causal Inference, why is it that that $P(X_i=x\mid Z_i = 1)= P(X_i=x\mid Z_i = 0)$ where $X,Z$ are the covariates and treatment?

Question: In Exact Matching in Causal Inference, I read that because we assume exact matches, then exact balance occurs in the distribution of the covariates. It is then often stated that if $X,Z$ are the covariates and treatment, respectively,
$$
P(X_i=x\mid Z_i = 1)= P(X_i=x\mid Z_i = 0)
$$
for all units $i$ in a population.
I am wondering why this is the case. In which sense does exact balance imply such a condition holding on the conditional distributions?
A reference is in pg. 173 here.
Comment: Please give proper citation to what you read, with a quote of the relevant material.  May we assume that $Z_i$ is binary?
Comment: Suppose all the treated observations are male and all the control observations are female. How can you do exact matching in that case?
Comment: It implies that $P(X_i=F\mid Z_i = 1)= 0 \ne P(X_i=F\mid Z_i = 0)=1$.
Comment: @ Ben, Yes, I am assuming $Z_i$ is binary. I have added the citation.
Comment: For matching on gender, I would assume that we cannot find such exact matching pairs? Does that imply the equation above does not hold?
Comment: Does this imply the probability here is the sample proportion? I had assumed the conditional probability might be the underlying population distribution for the covariates. Is such an assumption wrong?
Answer: Exact matching means that for each unit with some covariate value $x$ in the treated group (i.e., $Z=1$), one (assuming 1:1 matching) unit with the same covariate value $x$ in the control group (i.e., $Z=0$) is selected to be part of the matched sample. Therefore, the empirical distribution of the covariate in the treated group is identical to the empirical distribution of the covariate in the control group.
If $P(X_i=x|Z_i=z)$ is taken to mean that the probability that a random individual $i$ drawn from the group $Z=z$ has covariate value $x$, then, because the proportion of individuals in each treatment group with that level of the covariate is the same, these probabilities will be equal in the groups.
Consider the example with gender (as mentioned in the comments). Let's say initially your treated group is 30% men and 70% women. Exact matching involves creating a matched control group from a pool of potential controls whereby each unit in the treated group is matched to a control unit with the same covariate value. So, after exact matching, we have a matched control group that is also 30% men and 70% women. The probability of randomly drawing a man from the treated group is equal to the probability of randomly drawing a man from the control group. Or, said another way, the probability that any individual is a man in the treated group is equal to the probability that any individual is a man in the control group. This is precisely what your original statement says.
Comment: Thank you, this clarifies things. I originally kept thinking that if the conditional probabilities were the same, it implied a 50-50 % split. However, I see that with your 30-70 example, it is not the same, and that the idea is to keep the treated/control groups the same in probability. Thank you!


How to solve the following multi-variable integral?

Question: How can I solve it?
click here to see the question
Answer: Use Fubini's theorem, first integrate with respect to $x$ and then with respect to $y$.
On integrating with respect to $x$ and substituting the limits, the function reduces to $\arctan(y)$. Then integrate by parts with respect to y.
Comment: Can you provide the detail process of integrating with respect to x? I just cannot solve this part.
Comment: The derivative of arctan(xy) is just the equation you have.


How to show Content Titles only in Entity Reference drop down list, but restrict general access to the Content Type?

Question: Drupal 7.25
I have a list of "Locations" (content type) and need people to select an item from this list when they register on the site.
However, I do not want anonymous or authenticated users to view the detailed contents of these locations.
When I restrict the permissions on the content type, this removes all the values from the entity reference list for anonymous users when they try and register.
So is there an easy way to show ONLY the content Title field in the list, without people being able to then see all the other fields for the content type?
Thanks for any help!
Answer: OK, so the only way I found to do this was install the field_permisssions module and restrict access to all the custom fields for specific roles.
Not ideal, but achieves the objectives. There are a lot of fields and it took quite a while. Also need to remember to restrict fields when creating new ones.


SQL Server 2014 - SQL Case statement on columns

Question: This is the table I have :

For every unique TID, there are 2 records. For a unique TID if both records in a field is populated I want the name of the field. For example, for T01 : Field2 and Field4 have both records populated.
My current approach is I create a column with comma separated values with the field names :
INSERT INTO TEMP
SELECT *,
       (CASE WHEN COUNT(IIF(Field1 IS NOT NULL,1,NULL)) = 2 THEN 'FIELD1' ELSE 'NO' END) + ',' +
       (CASE WHEN COUNT(IIF(Field2 IS NOT NULL,1,NULL)) = 2 THEN 'FIELD2' ELSE 'NO' END) + ',' +
       (CASE WHEN COUNT(IIF(Field3 IS NOT NULL,1,NULL)) = 2 THEN 'FIELD3' ELSE 'NO' END) + ',' +
       (CASE WHEN COUNT(IIF(Field4 IS NOT NULL,1,NULL)) = 2 THEN 'FIELD4' ELSE 'NO' END) AS ATTR
FROM ORIGINAL_TABLE;

I then convert the comma separated column into multiple records :
SELECT *, S.ITEMS as ATTRIBUTES
FROM TEMP
CROSS APPLY DBO.SPLIT(ATTR, ',') S
WHERE S.ITEMS NOT LIKE '%NO%'

Consider T101 of the result obtained from above command,  This gives me the output :

Edit : Apologies. It should be Field2 instead of Field1.
This does give me information on the fields for every unique TID that follows the condition but I want it to be more specific. I run this for very big data with over 100 columns so this approach is slow.
Is there a way to get this? Where I display just the fields that satisfy the condition and their values for both records in T101.

Edit : Apologies. It should be Field2 instead of Field1 in the table.
I am fairly new to SQL, any help would be much appreciated!
Comment: what basis you are selecting field1 and field4 only?
Comment: Every unique TID has two records. In case of T101 as well. Field2 and Field4 both have not null values in both their records for T101
Comment: Field2 is also not null for T01 ...so why do you eliminate it from resultset?
Comment: do you need fields name or data as you shown in last table dialgram?
Comment: My apologies. It should be Field2 and Field4 in the resulting table.
Comment: I would like the data as shown in the last table. But for the time being my method helps me find the field names. I was wondering if there is a way in which I can get the data as seen in the last table.
Comment: okay let me try
Comment: Also I would like to know if there is a better way in getting the field names as well. Since my approach is very slow for large number of records.
Answer: Your question is rather complicated, and I'm not 100% sure what you really want.  But based on:

For a unique TID if both records in a field is populated I want the name of the field.

You can unpivot and aggregate.  Assuming that your columns all have a similar data type, you can use:
SELECT t.tId, v.fieldname
FROM ORIGINAL_TABLE t CROSS APPLY
     (VALUES ('Field1', Field1),
             ('Field2', Field2),
             ('Field3', Field3),
             ('Field4', Field4)
     ) v(fieldname, val)
GROUP BY t.tID, v.fieldname
HAVING COUNT(*) = COUNT(v.val)  -- all populated

Comment: But I want only the fields where both the records for T101 is not null. This statement gives me all the field names.
Comment: @dithyasridharan . . . The `having` clause should be doing that.  You could replace it with `count(v.val) = 2` if you wanted to ensure exactly two records.  I used `count(*)` instead so it would scale to any number of records for each id.


Does drupal_http_request ever cache results?

Question: Does drupal_http_request ever cache results?
I am making a request that looks something like:
$url = "http://www.example.com/some/rest/service?" . drupal_http_build_query(array(
    "id" => 1234,
));

$options = array(
    "headers" => array(
        "Pragma" => "no-cache",
        "Cache-Control" => "no-cache",
    ),
);

$response = drupal_http_request($url, $options);

The problem is that I am getting back some cached results.  I am not looking for ways to cachebust this request; I am trying to rule out Drupal caching this internally so I can work with the far end to see why their Varnish is being weird.
Answer: No, drupal_http_request() is not doing any kind of caching. If the results are cached then it's either the server or some intermediary system, e.g. a proxy.
Comment: See also http://stackoverflow.com/questions/9285640/does-phps-http-stream-wrapper-cache-files-details
Comment: Thanks, wasn't totally sure about the PHP streams backend that drupal_http_request() uses for the actual requests.


Evaluating the limit: $\lim\limits_{x\to \pi} \frac{\sin x}{π-x}$

Question: $$\lim_{x \to \pi} \frac{\sin x}{\pi-x}$$
Book answer: $1$
My answer: $0$
Attempt:
Let $x = \pi + h$ where $h\to0$
$\displaystyle{\lim_{h\to0} \frac{\sin (\pi+h)}{\pi-(\pi+h)}}$
$\displaystyle{=\lim_{h\to0} \frac{\sin (\pi+h)}{-h}}$
$\displaystyle{=-h\lim_{h\to0} \sin (\pi+h)}$
$\displaystyle{=0 \cdot \sin (\pi+0)=0}$
Comment: @projectilemotion Yep. The development by the OP was misleading. But the recent edits by Andrew Tawfeek completely hide this fact.
Comment: No, you dropped a $\pi+$.
Answer: This is opposite to the derivative of $sin$ at $\pi.$
$lim_{x\rightarrow \pi}{{sin(x)-sin(\pi)}\over{x-\pi}}=sin'(\pi)=cos(\pi)=-1$.
Answer: An easy (and obvious) substitution is $y = \pi - x$, so the limit becomes $lim_{y \to 0}\frac{\sin(\pi- y)}{y} =\lim_{y \to 0}\frac{\sin y}{y} = 1$.
You can also use your substitution, which would make the limit $\lim_{h \to 0}\frac{\sin(\pi+ h)}{-h}=\lim_{h \to 0}\frac{-\sin h}{-h} = \lim_{h \to 0}\frac{\sin h}{h}=1 $. Same answer, just one more step.
Answer: Hint by Dr. Graubner :
$ \sin(x) = \sin(π-x).$
$\lim_{x \rightarrow π} \frac{\sin(x)}{π-x} =$
$\lim_{x \rightarrow π} \frac{\sin(π-x)}{π-x}.$
Set $y:= π-x :$
$\lim_{y \rightarrow 0} \frac{\sin(y)}{y} = 1.$
Answer: HINT: write $$\frac{-\sin(x-\pi)}{x-\pi}$$


Enviado dados via GET e POST com Java Script

Question: Pessoal veja se alguém pode ajudar
Tenho uma variável chamada "ssId" onde tem uma informação que para enviar para um arquivo php, alguém pode me ajudar como fazer?

function chamarSS(ssId ){
    if(ssId){
       console.log("SS: " + ssId);
    }
}
<a href="javascript:;" id="ssId"  onclick="chamarSS('<?php echo $obj->SS; ?>');">DADOS
Answer: Cara não é nada recomendado você usar JavaScript para transporte de dados, é muito explicito e é algo muito perigoso, se você estiver trabalhando com dados importantes que podem colocar em risco perca financeira ou até extravio de alguma coisa, recomento utilizar PHP muito mais seguro.
Mas assim para você fazer uma GET
Você pode usar tanto o getJSON(Jquery) AJAX(Jquery)
function recViaCep(){
  $.ajax({
    url: "https://viacep.com.br/ws/"+ $("#cep").val()+"/json/",
    type: "GET",
    dataType: 'json',
    success: function(response){
      dados = response;
      $('#logradouro').val(dados.logradouro.toUpperCase());
      $('#bairro').val(dados.bairro.toUpperCase());
      $('#cidade').val(dados.localidade.toUpperCase());
      $('#estado').val(dados.uf.toUpperCase());
      initMap();
      $("#nomeRegristro").val($("#CNPJCPF").val() + " - " + $("#nomeAnalista").val())
    }
});

}
Nesse exemplo estou fazendo a requisição de um JSON por AJAX, que para devidos fins não vão colocar em risco minha empresa, portanto vê o que você precisa fazer!!
$.getJSON("demo_ajax_json.js", function(result){
    $.each(result, function(i, field){
      $("div").append(field + " ");
    });
  });
Já aqui é um exemplo de requisição por JSON
Como eu disse, tenha cuidado com o método post, o JS não vai deixar seus dados seguros


Pair-cluster across many variables, respecting pre-existing grouping variable

Question: I have a tibble with an id column, a G grouping variable, and 300 numeric variables.
I want a method that clusters the raws to the point that each row is matched/paired in a cluster with another within each grouping variable.
This should be a 1kNN. Spare raws in odd groups can be left out of the clusters.
So, if in a group there are 4 raws, then there will be 2 clusters of 2. If there are 5 raws, then 2 clusters of 2 and a spare raw.
I think I like the Mahalanobis distance for clustering but I am open to an alternative proposal.
I think that a diagnostic variable with the intra-cluster Mahalanobis could help, too.
Technically speaking, MatchIt does something very similar, over-imposing a binary classification to the raws. I don't want the need of such classification.
Example:
tibble(
  id = c(1:8),
  g = rep(c("A","B"),4),
  v1 = rnorm(8),
  v2 = rnorm(8),
  v3 = rnorm(8)
) -> obs

How ideally would look
obs %>%
  mutate(cluster = sample(c(1:2),replace = F) %>% rep(2),
         .by = g) %>%
  mutate(pair = str_c(g,cluster)) %>%
  arrange(pair)

Answer: This is called non-bipartite matching. The nbpMatching package implements it.
You can also do a greedy version of it yourself, which seeks pairs with the closest distance first. First, create an NxN distance matrix, and then find the closest pair and record it. Deny the ability of those units to be in future pairs. Repeat until all units have been matched. Here is some code that does this using the Mahalanobis distance.
obs$pair <- NA

#Create distance matrix of variables
d <- MatchIt::mahalanobis_dist(~v1 + v2 + v3, data = obs)

#Deny matches that belong to different clusters
d[!outer(obs$g, obs$g, "==")] <- Inf

#Deny self-matching
diag(d) <- Inf

k <- 1
repeat {
  min_pos <- arrayInd(which.min(d), dim(d))

  if (!is.finite(d[min_pos])) break

  obs$pair[drop(min_pos)] <- k
  d[drop(min_pos),] <- Inf
  d[,drop(min_pos)] <- Inf
  k <- k + 1
}

You can also do this more efficiently by splitting the problem into smaller pieces (i.e., within groups instead of denying cross-group matches).


trying to debug my python code but settrace not executing

Question: I already have python 2.7 installed on windows but whenever i run my code this line doesn't work , the debug process is not executed !!
sys.settrace(traceit)

Here is the code
import sys
import pyreadline

def remove_html_markup(s):
tag = False
quote = False
out = ""

for c in s:
    if c == '<' and not quote:
        tag = True
    elif c == '>' and not quote:
        tag = False
    elif c == '"' or c == "'" and tag:
        quote = not quote
    elif not tag:
        out = out + c
return out

def main():
    print remove_html_markup('xyz')
    print remove_html_markup('"foo"')
    print remove_html_markup("'foo'")

breakpoints = {9: True}
stepping = False

def debug(command, my_locals):
    global stepping
    global breakpoints

    if command.find(' ') > 0:
        arg = command.split(' ')[1]
    else:
        arg = None

    if command.startswith('s'):  # step
        stepping = True
        return True
    elif command.startswith('c'):  # continue
        stepping = False
        return True
    elif command.startswith('p'):    # print
        stepping = False
        return True

    elif command.startswith('q'):  # quit
        sys.exit(0)
    else:
        print "No such command", repr(command)

    return False

commands = ["p", "s", "p tag", "p foo", "q"]

def input_command():
    # command = raw_input("(my-spyder) ")
    global commands
    command = commands.pop(0)
    return command

def traceit(frame, event, trace_arg):
    global stepping

    if event == 'line':
        if stepping or breakpoints.has_key(frame.f_lineno):
            resume = False
            while not resume:
                print event, frame.f_lineno, frame.f_code.co_name, frame.f_locals
                command = input_command()
                resume = debug(command, frame.f_locals)
    return traceit

sys.settrace(traceit)
main()
sys.settrace(None)

The output should be
line 9 remove_html_markup {'s': 'xyz'}
line 10 remove_html_markup {'s': 'xyz', 'tag': False}
line 11 remove_html_markup {'quote': False, 's': 'xyz', 'tag': False}
line 13 remove_html_markup {'quote': False, 's': 'xyz', 'tag': False, 'out': ''}
line 14 remove_html_markup {'quote': False, 's': 'xyz', 'tag': False, 'c': 'x', 'out': ''}

but it returns
xyz
foo
'foo'

I need to know how to fix this problem , i'm new to debugging and i really need to learn debugging to improve my skills and reduce time taken to fix bugs
Comment: i think you want to use `import pdb...pdb.set_trace()`
Comment: I appreciate your answer , it's just i'm taking the (Software Debugging) course on udacity and they used sys module to debug i just need to know why it doesn't work
Answer: After trying so hard , i realized that my Python 2.7.5 didn't work , when i updated it to 2.7.14 but the same happened , then i realized that at the top of my code there was this line
#!/usr/bin/env python

Since i was using windows this line of code shouldn't even exist so once i removed it things went so great and the code worked !


Open source file manager for use with custom API - not file system

Question: I have a .Net MVC/Web API application which uses CK Editor as the rich text editor. I want to allow my users to upload files and use them in the rich text editor controls.
I know there are plenty of open source web file managers out there but all of the ones I have looked at rely on a file system for file storage.
My application uses Azure blob storage and each user has a container which they can upload to. I have an API which can upload files and also retrieve a list of files which are returned as JSON.
Is there any open source file manager which can be configured to work with this? I can adjust my server side API to work with whatever client I can find.
Thanks
Answer: You can try RichFilemanager. It is highly customizable and you can implement your own connector to work with Azure Blob storage.
Answer:
I have a .Net MVC/Web API application which uses CK Editor as the rich text editor. I want to allow my users to upload files and use them in the rich text editor controls.

AFAIK, the Open Source version of CKEditor does not support File upload and management with CKFinder. For CKFinder 3, it supports cloud storage (Amazon, Dropbox, Azure Blob Storage, etc.). For CKFinder 3 ASP.NET Connector Azure Backend, you could refer to here.
I assumed that you could leverage Ueditor and modify the controller.ashx from .NET backend to implement your file processing against azure blob storage by yourself.
Additionally, If you just want to provide the feature for your users to manage the uploaded files, you could use Microsoft Azure Storage Explorer and generate the SAS token against the blob container for each of your user, then the users could use the sas token via Azure Storage Explorer to manage the files.
Answer: You can try @opuscapita/filemanager
https://github.com/OpusCapita/filemanager